diff --git a/GUI/View/Widget/GroupBoxes.cpp b/GUI/View/Widget/GroupBoxes.cpp index 6b2de2202ac709010abaf4388eed6cd086f1e0c8..17b33997723204f56e99dad4f602e36e88492ddd 100644 --- a/GUI/View/Widget/GroupBoxes.cpp +++ b/GUI/View/Widget/GroupBoxes.cpp @@ -119,103 +119,3 @@ void CollapsibleGroupBox::setExpanded(bool expanded) if (m_toggleButton->isChecked() != expanded) m_toggleButton->click(); } - -// ************************************************************************************************ -// class GroupBoxCollapser -// ************************************************************************************************ - -GroupBoxCollapser* GroupBoxCollapser::installIntoGroupBox(QGroupBox* groupBox) -{ - return new GroupBoxCollapser(groupBox); -} - -GroupBoxCollapser* GroupBoxCollapser::installIntoGroupBox2(QGroupBox* groupBox, bool& expanded) -{ - auto* result = new GroupBoxCollapser(groupBox); - connect(result, &GroupBoxCollapser::toggled, [&expanded](bool b) { expanded = b; }); - return result; -} - -GroupBoxCollapser* GroupBoxCollapser::findInstalledCollapser(QGroupBox* groupBox) -{ - if (groupBox == nullptr) - return nullptr; - return groupBox->findChild<GroupBoxCollapser*>(); -} - -void GroupBoxCollapser::setTitle(const QString& title) -{ - m_toggleButton->setText(title); -} - -void GroupBoxCollapser::addTitleAction(QAction* action) -{ - auto* btn = new QToolButton(m_titleWidget); - btn->setToolButtonStyle(Qt::ToolButtonIconOnly); - btn->setDefaultAction(action); - if (action->menu() != nullptr) - btn->setPopupMode(QToolButton::InstantPopup); - - m_titleLayout->addWidget(btn); - - connect(action, &QAction::changed, [=]() { btn->setVisible(action->isVisible()); }); -} - -void GroupBoxCollapser::addTitleWidget(QWidget* widget) -{ - m_titleLayout->addWidget(widget); -} - -QWidget* GroupBoxCollapser::contentArea() const -{ - return m_contentArea; -} - -GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) - : QObject(groupBox) -{ - m_toggleButton = new QToolButton(groupBox); - m_toggleButton->setObjectName("GroupBoxToggler"); - m_toggleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - m_toggleButton->setCheckable(true); - m_toggleButton->setText(groupBox->title()); - m_toggleButton->setArrowType(Qt::ArrowType::DownArrow); - m_toggleButton->setChecked(true); - m_toggleButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding); - - m_titleLayout = new QHBoxLayout; - m_titleLayout->setSpacing(3); - m_titleLayout->setAlignment(Qt::AlignVCenter); - m_titleLayout->addWidget(m_toggleButton); - - m_titleWidget = new QWidget(groupBox); - m_titleWidget->setObjectName("GroupBoxTitleWidget"); - m_titleWidget->setAttribute(Qt::WA_StyledBackground, true); - m_titleWidget->setLayout(m_titleLayout); - - m_contentArea = new QWidget(groupBox); - m_contentArea->setObjectName("ContentArea"); - m_contentArea->setLayout(groupBox->layout()); - - auto* mainLayout = new QVBoxLayout; - mainLayout->setSpacing(0); - mainLayout->setMenuBar(m_titleWidget); - mainLayout->addWidget(m_contentArea); - - groupBox->setTitle(""); // title has been read above - groupBox->setLayout(mainLayout); // overwrites layout that has been read above - - connect(m_toggleButton, &QAbstractButton::clicked, this, &GroupBoxCollapser::toggle, - Qt::UniqueConnection); -} - -void GroupBoxCollapser::toggle(bool checked) -{ - m_toggleButton->setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow); - - if (m_toggleButton->isChecked()) - m_contentArea->show(); - else - m_contentArea->hide(); - emit toggled(m_toggleButton->isChecked()); -} diff --git a/GUI/View/Widget/GroupBoxes.h b/GUI/View/Widget/GroupBoxes.h index e44a8f4a90a24a8e0f0dadd96efaf5ca87adac40..a1e5cbef8072e615469e2f42a18a6fbefd6e1fe1 100644 --- a/GUI/View/Widget/GroupBoxes.h +++ b/GUI/View/Widget/GroupBoxes.h @@ -51,52 +51,4 @@ private: QWidget* m_body; }; - -//! Add-on to group boxes to make them collapsible. -//! -//! Also adds the possibility to show toolbuttons or widgets in the group box's title. -//! This add-on takes the layout (plus the contained widgets) of a given group box and moves it into -//! a newly created content area widget. A title widget will be added, and the original group box -//! title will be hidden. -//! -//! To support style sheets, the custom bool property "collapsible" will be added to the group box -//! an set to true. -class GroupBoxCollapser : public QObject { - Q_OBJECT -public: - static GroupBoxCollapser* installIntoGroupBox(QGroupBox* groupBox); - static GroupBoxCollapser* installIntoGroupBox2(QGroupBox* groupBox, bool& expanded); - static GroupBoxCollapser* findInstalledCollapser(QGroupBox* groupBox); - - //! Set the title of the group box. Do not use the method groupBox->setTitle() any more once the - //! add-on is installed. - void setTitle(const QString& title); - - //! Add a tool button to the title bar, connected to the given action - void addTitleAction(QAction* action); - - //! Add a widget to the title bar. - void addTitleWidget(QWidget* widget); - - //! The content area, to which the found group box content has been moved when the add-on has - //! been installed. - QWidget* contentArea() const; - - //! Expand/collapse the content area - void setExpanded(bool expanded = true); - -signals: - void toggled(bool b); - -private: - GroupBoxCollapser(QGroupBox* groupBox); - void toggle(bool checked); - - QWidget* m_titleWidget; //!< widget used to present the new groupbox title - QHBoxLayout* m_titleLayout; //!< layout in the title widget - QToolButton* m_toggleButton; //!< button to toggle between collapsed/expanded - QWidget* m_contentArea; //!< widget to where the original group box content has been moved -}; - - #endif // BORNAGAIN_GUI_VIEW_WIDGET_GROUPBOXES_H