diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-09-11 23:32:32 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-09-11 23:32:32 -0400 |
| commit | 9c59c739d4ef9a4479ac849badc998b200fddb13 (patch) | |
| tree | 11f5e8fb13644d82f5df6abdce36984180d374dc /src | |
| parent | 61956802b1bc42c4878944ddd22514578c188e86 (diff) | |
moved ExpanderWidget to uibase
Diffstat (limited to 'src')
| -rw-r--r-- | src/expanderwidget.cpp | 81 | ||||
| -rw-r--r-- | src/expanderwidget.h | 51 |
2 files changed, 0 insertions, 132 deletions
diff --git a/src/expanderwidget.cpp b/src/expanderwidget.cpp deleted file mode 100644 index a9d045a5..00000000 --- a/src/expanderwidget.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "expanderwidget.h" - -ExpanderWidget::ExpanderWidget() - : m_button(nullptr), m_content(nullptr), opened_(false) -{ -} - -ExpanderWidget::ExpanderWidget(QToolButton* button, QWidget* content) - : ExpanderWidget() -{ - set(button, content); -} - -void ExpanderWidget::set(QToolButton* button, QWidget* content, bool o) -{ - m_button = button; - m_content = content; - - m_button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - QObject::connect(m_button, &QToolButton::clicked, [&]{ toggle(); }); - - toggle(o); -} - -void ExpanderWidget::toggle() -{ - if (opened()) { - toggle(false); - } - else { - toggle(true); - } -} - -void ExpanderWidget::toggle(bool b) -{ - if (b) { - m_button->setArrowType(Qt::DownArrow); - m_content->show(); - } else { - m_button->setArrowType(Qt::RightArrow); - m_content->hide(); - } - - // the state has to be remembered instead of using m_content's visibility - // because saving the state in saveConflictExpandersState() happens after the - // dialog is closed, which marks all the widgets hidden - opened_ = b; -} - -bool ExpanderWidget::opened() const -{ - return opened_; -} - -QByteArray ExpanderWidget::saveState() const -{ - QByteArray result; - QDataStream stream(&result, QIODevice::WriteOnly); - - stream << opened(); - - return result; -} - -void ExpanderWidget::restoreState(const QByteArray& a) -{ - QDataStream stream(a); - - bool opened = false; - stream >> opened; - - if (stream.status() == QDataStream::Ok) { - toggle(opened); - } -} - -QToolButton* ExpanderWidget::button() const -{ - return m_button; -} diff --git a/src/expanderwidget.h b/src/expanderwidget.h deleted file mode 100644 index 99b2d303..00000000 --- a/src/expanderwidget.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef EXPANDERWIDGET_H -#define EXPANDERWIDGET_H - -#include <QToolButton> - -/* Takes a QToolButton and a widget and creates an expandable widget. -**/ -class ExpanderWidget -{ -public: - /** empty expander, use set() - **/ - ExpanderWidget(); - - /** see set() - **/ - ExpanderWidget(QToolButton* button, QWidget* content); - - /** @brief sets the button and content widgets to use - * the button will be given an arrow icon, clicking it will toggle the - * visibility of the given widget - * @param button the button that toggles the content - * @param content the widget that will be shown or hidden - * @param opened initial state, defaults to closed - **/ - void set(QToolButton* button, QWidget* content, bool opened=false); - - /** either opens or closes the expander depending on the current state - **/ - void toggle(); - - /** sets the current state of the expander - **/ - void toggle(bool b); - - /** returns whether the expander is currently opened - **/ - bool opened() const; - - QByteArray saveState() const; - void restoreState(const QByteArray& a); - - QToolButton* button() const; - -private: - QToolButton* m_button; - QWidget* m_content; - bool opened_; -}; - -#endif // EXPANDERWIDGET_H |
