BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
layereditortoolbar.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/layereditor/layereditortoolbar.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
18 #include <QAction>
19 #include <QMenu>
20 #include <QToolButton>
21 
22 namespace gui2 {
23 
25  : QToolBar(parent)
26 {
28 
29  auto layer_menu = create_layer_menu(actions);
30 
31  auto add_layer_button = new QToolButton;
32  add_layer_button->setText("Add");
33  add_layer_button->setToolTip(
34  "Adds a new single layer (default) or new layer-repeater after currently selected.\nIf "
35  "nothing is selected, appends to the end. Click and hold to see possible choices.");
36  add_layer_button->setPopupMode(QToolButton::MenuButtonPopup);
37  add_layer_button->setIcon(QIcon(":/icons/plus-circle-outline.svg"));
38  add_layer_button->setMenu(layer_menu);
39  add_layer_button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
40  addWidget(add_layer_button);
41  m_toolbarWidgets.insert(std::pair<std::string, QWidget*>("Add", add_layer_button));
42  connect(add_layer_button, &QToolButton::clicked,
43  [layer_menu]() { layer_menu->defaultAction()->triggered(); });
44 
45  auto action = new QAction("Clone", this);
46  action->setIcon(QIcon(":/icons/plus-circle-multiple-outline.svg"));
47  action->setToolTip("Clones selected layer");
48  connect(action, &QAction::triggered, actions, &LayerEditorActions::onClone);
49  addAction(action);
50  m_toolbarWidgets.insert(std::pair<std::string, QWidget*>("Clone", widgetForAction(action)));
51 
52  action = new QAction("Remove", this);
53  action->setIcon(QIcon(":/icons/beaker-remove-outline.svg"));
54  action->setToolTip("Removes selected layer");
55  connect(action, &QAction::triggered, actions, &LayerEditorActions::onRemove);
56  addAction(action);
57  m_toolbarWidgets.insert(std::pair<std::string, QWidget*>("Remove", widgetForAction(action)));
58 
59  addSeparator();
60 
61  action = new QAction("Up", this);
62  action->setIcon(QIcon(":/icons/arrow-up-circle-outline.svg"));
63  action->setToolTip("Moves selected layer up");
64  connect(action, &QAction::triggered, actions, &LayerEditorActions::onMoveUp);
65  addAction(action);
66  m_toolbarWidgets.insert(std::pair<std::string, QWidget*>("Up", widgetForAction(action)));
67 
68  action = new QAction("Down", this);
69  action->setIcon(QIcon(":/icons/arrow-down-circle-outline.svg"));
70  action->setToolTip("Moves selected layer down");
71  connect(action, &QAction::triggered, actions, &LayerEditorActions::onMoveDown);
72  addAction(action);
73  m_toolbarWidgets.insert(std::pair<std::string, QWidget*>("Down", widgetForAction(action)));
74 
75  m_toolbarWidgets["Add"]->setEnabled(true);
76  m_toolbarWidgets["Clone"]->setEnabled(true);
77  m_toolbarWidgets["Remove"]->setEnabled(true);
78  m_toolbarWidgets["Up"]->setEnabled(false);
79  m_toolbarWidgets["Down"]->setEnabled(false);
80 }
81 
82 //! Creates menu to add layer and layer-repeater.
83 
85 {
86  auto result = new QMenu("Add", this);
87  result->setToolTipsVisible(true);
88  result->menuAction()->setToolTip("Adds a single layer or layer-repeater.");
89  result->setIcon(QIcon(":/icons/plus-circle-outline.svg"));
90 
91  // add layer action
92  auto action = result->addAction("Adds a single layer");
93  action->setIcon(QIcon(":/icons/layers-outline.svg"));
94  action->setToolTip("Adds a new layer after selected one");
95  connect(action, &QAction::triggered, editor_actions, &LayerEditorActions::onAddLayer);
96  result->setDefaultAction(action);
97 
98  // add layer repeater action
99  action = result->addAction("Adds layer repeater");
100  action->setIcon(QIcon(":/icons/layers-triple-outline.svg"));
101  action->setToolTip("Adds a new layer-repeater after selected one.\n"
102  "Layer repeater allows to repeat it content (i.e. bi-layer) "
103  "certain amount of times");
104  connect(action, &QAction::triggered, editor_actions, &LayerEditorActions::onAddMultiLayer);
105 
106  return result;
107 }
108 
109 //! Handle the QToolButtons for their enabled state depending on what is selected
110 void LayerEditorToolBar::updateToolButtonStates(bool first_present, bool last_present)
111 {
112  m_toolbarWidgets["Add"]->setEnabled(true);
113  m_toolbarWidgets["Clone"]->setEnabled(true);
114  m_toolbarWidgets["Remove"]->setEnabled(true);
115  m_toolbarWidgets["Up"]->setEnabled((!first_present) ? (true) : (false));
116  m_toolbarWidgets["Down"]->setEnabled((!last_present) ? (true) : (false));
117 }
118 
119 } // namespace gui2
Handles user actions applied to layer tree.
void onAddLayer()
Adds layer after selected item. If more than one item is selected, adds after the last one.
void updateToolButtonStates(bool first_present, bool last_present)
Handle the QToolButtons for their enabled state depending on what is selected.
std::map< std::string, QWidget * > m_toolbarWidgets
QMenu * create_layer_menu(LayerEditorActions *editor_actions)
Creates menu to add layer and layer-repeater.
LayerEditorToolBar(LayerEditorActions *actions, QWidget *parent=nullptr)
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
DAREFLCORE_EXPORT void SetToolBarStyleTextBesides(QToolBar *toolbar)
Set common style for a toolbar.
Definition: styleutils.cpp:39
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20