BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MaskEditorToolbar.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Mask/MaskEditorToolbar.cpp
6 //! @brief Implements class MaskEditorToolbar
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include "Base/Util/Assert.h"
19 #include <QButtonGroup>
20 #include <QLabel>
21 #include <QRadioButton>
22 #include <QStyle>
23 #include <QToolButton>
24 #include <QVariant>
25 
27  : QToolBar(parent)
28  , m_editorActions(editorActions)
29  , m_activityButtonGroup(new QButtonGroup(this))
30  , m_maskValueGroup(new QButtonGroup(this))
31 {
33  setProperty("_q_custom_style_disabled", QVariant(true));
34 
36  // setup_maskvalue_group();
40 
41 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
42  connect(m_activityButtonGroup, &QButtonGroup::idClicked, this,
44  connect(m_maskValueGroup, &QButtonGroup::idClicked, this,
46 #else
47  connect(m_activityButtonGroup,
48  static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), this,
50  connect(m_maskValueGroup,
51  static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), this,
53 #endif
54 
56 }
57 
58 //! Handles ZOOM requests from MaskGraphicsView while user press and holds
59 //! space bar. As soon as space bar is released, activity is returned to previous state.
60 void MaskEditorToolbar::onChangeActivityRequest(MaskEditorFlags::Activity value)
61 {
62  if (value == MaskEditorFlags::PREVIOUS_MODE)
64  else {
66  setCurrentActivity(value);
67  }
69 }
70 
72 {
73  Q_UNUSED(value);
75 }
76 
78 {
79  Q_UNUSED(value);
80  emit maskValueChanged(MaskEditorFlags::MaskValue(value));
81 }
82 
84 {
86 }
87 
89 {
91 }
92 
94 {
95  auto* panButton = new QToolButton(this);
96  panButton->setIcon(QIcon(":/images/hand-right.svg"));
97  panButton->setToolTip("Pan/zoom mode (space)");
98  panButton->setCheckable(true);
99  panButton->setChecked(true);
100  addWidget(panButton);
101 
102  auto* resetViewButton = new QToolButton(this);
103  resetViewButton->setIcon(QIcon(":/images/camera-metering-center.svg"));
104  resetViewButton->setToolTip("Reset pan/zoom to initial state");
105  addWidget(resetViewButton);
106  connect(resetViewButton, &QToolButton::clicked, m_editorActions,
108 
109  add_separator();
110 
111  auto* selectionButton = new QToolButton(this);
112  selectionButton->setIcon(QIcon(":/Mask/images/maskeditor_arrow.svg"));
113  selectionButton->setToolTip("Select/modify mask");
114  selectionButton->setCheckable(true);
115  addWidget(selectionButton);
116 
118  m_activityButtonGroup->addButton(selectionButton, MaskEditorFlags::SELECTION_MODE);
119 }
120 
122 {
123  addWidget(new QLabel(" "));
124 
125  auto* maskTrueButton = new QRadioButton(this);
126  maskTrueButton->setText("masked");
127  maskTrueButton->setToolTip("Set mask to True (area is excluded from the simulation)");
128  maskTrueButton->setCheckable(true);
129  maskTrueButton->setChecked(true);
130  addWidget(maskTrueButton);
131 
132  addWidget(new QLabel(" "));
133 
134  auto* maskFalseButton = new QRadioButton(this);
135  maskFalseButton->setToolTip("Set mask to False (area stays in the simulation)");
136  maskFalseButton->setCheckable(true);
137  maskFalseButton->setText("active");
138  addWidget(maskFalseButton);
139 
140  m_maskValueGroup->addButton(maskTrueButton, MaskEditorFlags::MASK_ON);
141  m_maskValueGroup->addButton(maskFalseButton, MaskEditorFlags::MASK_OFF);
142 }
143 
145 {
146  auto* roiButton = new QToolButton(this);
147  roiButton->setIcon(QIcon(":/Mask/images/maskeditor_roi.svg"));
148  roiButton->setToolTip("Create region of interest");
149  roiButton->setCheckable(true);
150  addWidget(roiButton);
151 
152  auto* rectangleButton = new QToolButton(this);
153  rectangleButton->setIcon(QIcon(":/Mask/images/maskeditor_rectangle.svg"));
154  rectangleButton->setToolTip("Create rectangle mask");
155  rectangleButton->setCheckable(true);
156  addWidget(rectangleButton);
157 
158  auto* polygonButton = new QToolButton(this);
159  polygonButton->setIcon(QIcon(":/Mask/images/maskeditor_polygon.svg"));
160  polygonButton->setToolTip("Create polygon mask");
161  polygonButton->setCheckable(true);
162  addWidget(polygonButton);
163 
164  auto* verticalLineButton = new QToolButton(this);
165  verticalLineButton->setIcon(QIcon(":/Mask/images/maskeditor_verticalline.svg"));
166  verticalLineButton->setToolTip("Create vertical line mask");
167  verticalLineButton->setCheckable(true);
168  addWidget(verticalLineButton);
169 
170  auto* horizontalLineButton = new QToolButton(this);
171  horizontalLineButton->setIcon(QIcon(":/Mask/images/maskeditor_horizontalline.svg"));
172  horizontalLineButton->setToolTip("Create horizontal line mask");
173  horizontalLineButton->setCheckable(true);
174  addWidget(horizontalLineButton);
175 
176  auto* ellipseButton = new QToolButton(this);
177  ellipseButton->setIcon(QIcon(":/Mask/images/maskeditor_ellipse.svg"));
178  ellipseButton->setToolTip("Create ellipse mask");
179  ellipseButton->setCheckable(true);
180  addWidget(ellipseButton);
181 
182  // QToolButton *maskAllButton = new QToolButton(this);
183  // maskAllButton->setIcon(QIcon(":/Mask/images/maskeditor_maskall.svg"));
184  // maskAllButton->setToolTip("Create masked area covering whole detector plane\n"
185  // "Will be placed beneath all masks. Only one instance is
186  // allowed.");
187  // maskAllButton->setCheckable(true);
188  // addWidget(maskAllButton);
189 
190  m_activityButtonGroup->addButton(roiButton, MaskEditorFlags::ROI_MODE);
191  m_activityButtonGroup->addButton(rectangleButton, MaskEditorFlags::RECTANGLE_MODE);
192  m_activityButtonGroup->addButton(polygonButton, MaskEditorFlags::POLYGON_MODE);
193  m_activityButtonGroup->addButton(verticalLineButton, MaskEditorFlags::VERTICAL_LINE_MODE);
194  m_activityButtonGroup->addButton(horizontalLineButton, MaskEditorFlags::HORIZONTAL_LINE_MODE);
195  m_activityButtonGroup->addButton(ellipseButton, MaskEditorFlags::ELLIPSE_MODE);
196  // m_activityButtonGroup->addButton(maskAllButton, MaskEditorFlags::MASKALL_MODE);
197  add_separator();
198 }
199 
201 {
202  ASSERT(m_editorActions);
203  addAction(m_editorActions->bringToFrontAction());
204  addAction(m_editorActions->sendToBackAction());
205  add_separator();
206 }
207 
209 {
210  auto* presentationButton = new QToolButton(this);
211  presentationButton->setIcon(QIcon(":/Mask/images/maskeditor_lightbulb.svg"));
212  presentationButton->setToolTip("Press and hold to see mask results.");
213  addWidget(presentationButton);
214 
215  connect(presentationButton, &QToolButton::pressed, this,
217  connect(presentationButton, &QToolButton::released, this,
219 
220  auto* propertyPanelButton = new QToolButton(this);
221  propertyPanelButton->setIcon(QIcon(":/Mask/images/maskeditor_toolpanel.svg"));
222  propertyPanelButton->setToolTip("Open panel with additional properties");
223  addWidget(propertyPanelButton);
224 
225  connect(propertyPanelButton, &QToolButton::clicked, m_editorActions,
227  add_separator();
228 }
229 
231 {
232  addWidget(new QLabel(" "));
233  addSeparator();
234  addWidget(new QLabel(" "));
235 }
236 
237 MaskEditorFlags::Activity MaskEditorToolbar::currentActivity() const
238 {
240 }
241 
242 void MaskEditorToolbar::setCurrentActivity(MaskEditorFlags::Activity value)
243 {
244  m_activityButtonGroup->button(value)->setChecked(true);
245 }
Defines class MaskEditorActions.
Defines class MaskEditorToolbar.
Defines actions for MaskEditor which are related to selected MaskItem (toggle mask value,...
void propertyPanelRequest()
QAction * bringToFrontAction()
QAction * sendToBackAction()
void maskValueChanged(MaskEditorFlags::MaskValue)
QButtonGroup * m_activityButtonGroup
void setCurrentActivity(MaskEditorFlags::Activity value)
MaskEditorActions * m_editorActions
MaskEditorFlags::Activity currentActivity() const
MaskEditorFlags::Activity m_previousActivity
void onMaskValueGroupChange(int value)
void activityModeChanged(MaskEditorFlags::Activity)
void onChangeActivityRequest(MaskEditorFlags::Activity value)
Handles ZOOM requests from MaskGraphicsView while user press and holds space bar. As soon as space ba...
void onActivityGroupChange(int value)
QButtonGroup * m_maskValueGroup
MaskEditorToolbar(MaskEditorActions *editorActions, QWidget *parent=nullptr)
void presentationTypeRequest(MaskEditorFlags::PresentationType)
Defines namespace GUI::Constants.
const int toolbar_icon_size