diff --git a/GUI/View/Instrument/InstrumentLibraryEditor.cpp b/GUI/View/Instrument/InstrumentLibraryEditor.cpp index 5d72e4bec43431eaf0cb8c2eecb1eddef4b5c0e4..2887391b1434d5e86736296c96aec4bcbea2e5dd 100644 --- a/GUI/View/Instrument/InstrumentLibraryEditor.cpp +++ b/GUI/View/Instrument/InstrumentLibraryEditor.cpp @@ -188,11 +188,11 @@ void InstrumentLibraryEditor::createWidgetsForCurrentInstrument() QWidget* w = new QWidget(m_ui->scrollArea); auto* layout = new QVBoxLayout(w); - auto* g = new QGroupBox(m_ui->scrollArea); - g->setTitle(QString("Information (%1 instrument)").arg(currentInstrument->instrumentType())); - - auto* formLayout = new QFormLayout(g); - formLayout->setSpacing(8); + auto title = QString("Summary (%1 instrument)").arg(currentInstrument->instrumentType()); + auto* g = new CollapsibleGroupBox(title, m_ui->scrollArea, currentInstrument->expandInfo); + g->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + auto* formLayout = new QFormLayout; + g->body()->setLayout(formLayout); layout->addWidget(g); auto* nameEdit = new QLineEdit(g); @@ -203,7 +203,7 @@ void InstrumentLibraryEditor::createWidgetsForCurrentInstrument() auto* descriptionEdit = new QTextEdit(g); descriptionEdit->setMinimumWidth(300); - descriptionEdit->setMaximumHeight(100); + descriptionEdit->setFixedHeight(60); // TODO replace by 2*line_height descriptionEdit->setAcceptRichText(false); descriptionEdit->setTabChangesFocus(true); descriptionEdit->setPlainText(currentInstrument->description()); @@ -212,8 +212,6 @@ void InstrumentLibraryEditor::createWidgetsForCurrentInstrument() onInstrumentDescriptionEdited(descriptionEdit->toPlainText()); }); - GroupBoxCollapser::installIntoGroupBox(g); - auto* ec = m_instrumentLibrary->editController(); if (auto* sp = dynamic_cast<SpecularInstrumentItem*>(currentInstrument)) { auto* editor = new SpecularInstrumentEditor(m_ui->scrollArea, sp, ec); 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