diff --git a/GUI/View/Instrument/DistributionEditor.cpp b/GUI/View/Instrument/DistributionEditor.cpp index 5fcceec603d8e5c1ff87a3bb5429327a90537f23..311ef00c81e6d521369b20ac8ba37d1d19e9bfba 100644 --- a/GUI/View/Instrument/DistributionEditor.cpp +++ b/GUI/View/Instrument/DistributionEditor.cpp @@ -20,8 +20,6 @@ #include "GUI/Support/XML/Streamer.h" #include "GUI/View/Instrument/DistributionForms.h" #include "GUI/View/Instrument/DistributionPlot.h" -#include "GUI/View/Instrument/EditDistributionDialog.h" -#include "GUI/View/PropertyEditor/GroupInfoBox.h" #include "GUI/View/Tool/GroupBoxCollapser.h" #include "GUI/View/Tool/WidgetUtils.h" #include <QComboBox> @@ -115,7 +113,6 @@ DistributionEditor::DistributionEditor(const QString& title, GUI::ID::Distributions distributions, QWidget* parent, BeamDistributionItem* item) : QGroupBox(title, parent) - , m_title(title) { setProperty("subgroup", true); // for stylesheet addressing auto* hLayout = new QHBoxLayout(this); @@ -144,11 +141,6 @@ void DistributionEditor::updateData() m_selector->refresh(); } -void DistributionEditor::showDialog() -{ - showEditDistributionDialog(m_selector, m_title); -} - void DistributionEditor::updatePlot() { auto* d = m_selector->item()->distribution(); @@ -156,31 +148,3 @@ void DistributionEditor::updatePlot() m_plot->setItem(d); m_plot->plotItem(); } - -//-------------------------------------------------------------------------------------------------- -// free functions -//-------------------------------------------------------------------------------------------------- - -void showEditDistributionDialog(DistributionSelector* selector, const QString& title) -{ - BeamDistributionItem* item = selector->item(); - if (!item) - return; - - const QByteArray backup = GUI::Util::createBackup(item); - bool modifiedInDialog = false; - - EditDistributionDialog dialog(item, title, selector->meanConfig(), selector->distributions(), - selector); - - QObject::connect(&dialog, &EditDistributionDialog::distributionChanged, - [&] { modifiedInDialog = true; }); - if (dialog.exec() != QDialog::Accepted) - GUI::Util::restoreBackup(item, backup); - else { - if (modifiedInDialog) { - selector->refresh(); - selector->distributionChanged(); - } - } -} diff --git a/GUI/View/Instrument/DistributionEditor.h b/GUI/View/Instrument/DistributionEditor.h index a2928e972090983f9f22591601ae28bad70c4552..1d2e4268078da4870d8f0c9e4085184bf0615108 100644 --- a/GUI/View/Instrument/DistributionEditor.h +++ b/GUI/View/Instrument/DistributionEditor.h @@ -91,17 +91,11 @@ public: signals: void distributionChanged(); -private slots: - void showDialog(); +private: void updatePlot(); -private: - QString m_title; DistributionSelector* m_selector; DistributionPlot* m_plot; }; -/// utility function to show the EditDistributionDialog for a selector -void showEditDistributionDialog(DistributionSelector* selector, const QString& title); - #endif // BORNAGAIN_GUI_VIEW_INSTRUMENT_DISTRIBUTIONEDITOR_H diff --git a/GUI/View/Instrument/EditDistributionDialog.cpp b/GUI/View/Instrument/EditDistributionDialog.cpp deleted file mode 100644 index c4e93a0d8725f8e7be0071092fe1cb77ea8525aa..0000000000000000000000000000000000000000 --- a/GUI/View/Instrument/EditDistributionDialog.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/Instrument/EditDistributionDialog.cpp -//! @brief Implements class EditDistributionDialog -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "GUI/View/Instrument/EditDistributionDialog.h" -#include "GUI/Model/Device/BeamDistributionItem.h" -#include "GUI/View/Instrument/DistributionEditor.h" -#include "GUI/View/Instrument/DistributionPlot.h" - -#include <QDialogButtonBox> -#include <QSplitter> -#include <QVBoxLayout> - -EditDistributionDialog::EditDistributionDialog(BeamDistributionItem* item, const QString& title, - const std::optional<MeanConfig>& mean_config, - GUI::ID::Distributions distributions, - QWidget* parent, Qt::WindowFlags f) - : QDialog(parent, f) - , m_item(item) -{ - setMinimumSize(256, 256); - resize(800, 480); - setWindowTitle(title); - - auto* layout = new QVBoxLayout(this); - - auto* splitter = new QSplitter(this); - layout->addWidget(splitter); - - m_plot = new DistributionPlot(this); - m_plot->setItem(m_item->distribution()); - splitter->addWidget(m_plot); - - m_selector = new DistributionSelector(mean_config, distributions, this, m_item); - splitter->addWidget(m_selector); - - splitter->setSizes({500, 300}); - - auto* bbox = new QDialogButtonBox(this); - bbox->addButton(QDialogButtonBox::Ok); - bbox->addButton(QDialogButtonBox::Cancel); - connect(bbox, &QDialogButtonBox::accepted, this, &QDialog::accept); - connect(bbox, &QDialogButtonBox::rejected, this, &QDialog::close); - layout->addWidget(bbox); - - setSizeGripEnabled(true); - - connect(m_selector, &DistributionSelector::distributionChanged, this, - &EditDistributionDialog::updatePlot); - connect(m_selector, &DistributionSelector::distributionChanged, this, - &EditDistributionDialog::distributionChanged); -} - -void EditDistributionDialog::updatePlot() -{ - // no need to update the selector because that's the only widget which changes the item - m_plot->setItem(m_item->distribution()); - m_plot->plotItem(); -} diff --git a/GUI/View/Instrument/EditDistributionDialog.h b/GUI/View/Instrument/EditDistributionDialog.h deleted file mode 100644 index 02536694c8ea7408959065cea1fc55f0d6a651de..0000000000000000000000000000000000000000 --- a/GUI/View/Instrument/EditDistributionDialog.h +++ /dev/null @@ -1,49 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/Instrument/EditDistributionDialog.h -//! @brief Defines class EditDistributionDialog -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#ifndef BORNAGAIN_GUI_VIEW_INSTRUMENT_EDITDISTRIBUTIONDIALOG_H -#define BORNAGAIN_GUI_VIEW_INSTRUMENT_EDITDISTRIBUTIONDIALOG_H - -#include "GUI/View/Tool/ID.h" -#include <QDialog> -#include <optional> - -class DistributionPlot; -class DistributionSelector; -class BeamDistributionItem; -struct MeanConfig; - -//! The dialog which shows an editor to change parameters of DistributionItem -class EditDistributionDialog : public QDialog { - Q_OBJECT - -public: - EditDistributionDialog(BeamDistributionItem* item, const QString& title, - const std::optional<MeanConfig>& mean_config, - GUI::ID::Distributions distributions, QWidget* parent = nullptr, - Qt::WindowFlags f = Qt::WindowFlags()); - -signals: - void distributionChanged(); - -private slots: - void updatePlot(); - -private: - DistributionPlot* m_plot; - DistributionSelector* m_selector; - BeamDistributionItem* m_item; -}; - -#endif // BORNAGAIN_GUI_VIEW_INSTRUMENT_EDITDISTRIBUTIONDIALOG_H diff --git a/GUI/View/PropertyEditor/GroupInfoBox.cpp b/GUI/View/PropertyEditor/GroupInfoBox.cpp deleted file mode 100644 index 4713b4df7d29a72462d2a567371adfb247e89f77..0000000000000000000000000000000000000000 --- a/GUI/View/PropertyEditor/GroupInfoBox.cpp +++ /dev/null @@ -1,102 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/PropertyEditor/GroupInfoBox.cpp -//! @brief Implements class GroupInfoBox -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "GUI/View/PropertyEditor/GroupInfoBox.h" -#include <QApplication> -#include <QMouseEvent> -#include <QPainter> -#include <QPixmap> -#include <QPushButton> -#include <QStyleOptionGroupBox> -#include <QStylePainter> -#include <QToolTip> -#include <iostream> - -namespace { - -int imageWidth = 16; -int imageheigth = 16; -int offset_of_tooltip_position = 20; -int offset_of_icon_position = 24; - -} // namespace - -GroupInfoBox::GroupInfoBox(QWidget* parent) - : QGroupBox(parent) - , m_xImage(0) - , m_yImage(0) -{ - init_box(); -} - -GroupInfoBox::GroupInfoBox(const QString& title, QWidget* parent) - : QGroupBox(title, parent) - , m_title(title) -{ - init_box(); -} - -void GroupInfoBox::setButtonToolTip(const QString& text) -{ - m_toolTipText = text; -} - -void GroupInfoBox::mousePressEvent(QMouseEvent* e) -{ - if (e->button() == Qt::LeftButton) { - QStyleOptionGroupBox option; - initStyleOption(&option); - QRect buttonArea(m_xImage, m_yImage, imageWidth, imageheigth); - if (buttonArea.contains(e->pos())) - emit clicked(true); - } -} - -void GroupInfoBox::mouseMoveEvent(QMouseEvent* event) -{ - QRect buttonArea(m_xImage, m_yImage, imageWidth, imageheigth); - - if (buttonArea.contains(event->pos())) { - QToolTip::showText( - this->mapToGlobal(QPoint(m_xImage + offset_of_tooltip_position, m_yImage)), - m_toolTipText); - } -} - -void GroupInfoBox::init_box() -{ - setMouseTracking(true); - m_toolTipText = "Gives access to the extended distribution viewer."; -} - -void GroupInfoBox::paintEvent(QPaintEvent*) -{ - QStylePainter paint(this); - QStyleOptionGroupBox option; - initStyleOption(&option); - paint.drawComplexControl(QStyle::CC_GroupBox, option); - - m_xImage = this->geometry().topRight().x() - offset_of_icon_position; - m_yImage = 0; - - // draw groupbox -#ifdef Q_OS_LINUX - const int shift = 3; -#else - const int shift = 1; -#endif - - paint.drawItemPixmap(option.rect.adjusted(0, shift, 0, 0), Qt::AlignTop | Qt::AlignRight, - QPixmap(":/images/magnifier.png")); -} diff --git a/GUI/View/PropertyEditor/GroupInfoBox.h b/GUI/View/PropertyEditor/GroupInfoBox.h deleted file mode 100644 index a3710f2da311e631adf7a19db0799ba556ddb3e8..0000000000000000000000000000000000000000 --- a/GUI/View/PropertyEditor/GroupInfoBox.h +++ /dev/null @@ -1,44 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/PropertyEditor/GroupInfoBox.h -//! @brief Defines class GroupInfoBox -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#ifndef BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_GROUPINFOBOX_H -#define BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_GROUPINFOBOX_H - -#include <QGroupBox> - -//! The class which extends QGroupBox with clickable icon next to the label -class GroupInfoBox : public QGroupBox { - Q_OBJECT - -public: - GroupInfoBox(QWidget* parent = nullptr); - GroupInfoBox(const QString& title, QWidget* parent = nullptr); - - void setButtonToolTip(const QString& text); - -protected: - void mousePressEvent(QMouseEvent* e) override; - void paintEvent(QPaintEvent*) override; - void mouseMoveEvent(QMouseEvent* event) override; - -private: - void init_box(); - - QString m_title; - QString m_toolTipText; - int m_xImage; - int m_yImage; -}; - -#endif // BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_GROUPINFOBOX_H