BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ActionFactory.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Util/ActionFactory.cpp
6 //! @brief Implements class ActionFactory
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #include "GUI/Util/ActionFactory.h"
16 #include <QAction>
17 
18 QAction* ActionFactory::createRemoveAction(QObject* parent, const QString& what,
19  std::function<void()> slot)
20 {
21  auto* removeAction = new QAction(parent);
22  removeAction->setText("Remove");
23  removeAction->setIcon(QIcon(":/images/delete.svg"));
24  removeAction->setIconText("Remove");
25  removeAction->setToolTip("Remove " + what);
26 
27  if (slot)
28  QObject::connect(removeAction, &QAction::triggered, slot);
29 
30  return removeAction;
31 }
32 
33 QAction* ActionFactory::createShowInRealSpaceAction(QObject* parent, const QString& what,
34  std::function<void()> slot)
35 {
36  auto* action = new QAction(parent);
37  action->setText("Show in Real Space (3D) view");
38  action->setIcon(QIcon(":/SampleDesigner/images/rotate-3d.svg"));
39  action->setIconText("3D");
40  action->setToolTip("Show " + what + " in Real Space (3D) view");
41 
42  if (slot)
43  QObject::connect(action, &QAction::triggered, slot);
44 
45  return action;
46 }
47 
48 QAction* ActionFactory::createTogglePropertiesPanelAction(QObject* parent, QWidget* toggledWidget)
49 {
50  auto* action = new QAction(parent);
51  action->setText("Properties");
52  action->setIcon(QIcon(":/images/dock-right.svg"));
53  action->setToolTip("Toggle properties panel");
54  action->setCheckable(true);
55 
56  if (toggledWidget)
57  QObject::connect(action, &QAction::triggered, toggledWidget, &QWidget::setVisible);
58 
59  return action;
60 }
Defines class ActionFactory.
static QAction * createShowInRealSpaceAction(QObject *parent, const QString &what, std::function< void()> slot=nullptr)
Create "show in RealSpace" action.
static QAction * createRemoveAction(QObject *parent, const QString &what, std::function< void()> slot=nullptr)
Create "remove" action.
static QAction * createTogglePropertiesPanelAction(QObject *parent, QWidget *toggledWidget=nullptr)
Create "toggle properties panel" action.