BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
gui2::LayerEditorToolBar Class Reference

Layer editor toolbar. More...

Inheritance diagram for gui2::LayerEditorToolBar:
[legend]
Collaboration diagram for gui2::LayerEditorToolBar:
[legend]

Public Member Functions

 LayerEditorToolBar (LayerEditorActions *actions, QWidget *parent=nullptr)
 
 ~LayerEditorToolBar ()=default
 
void updateToolButtonStates (bool first_present, bool last_present)
 Handle the QToolButtons for their enabled state depending on what is selected. More...
 

Private Member Functions

QMenu * create_layer_menu (LayerEditorActions *editor_actions)
 Creates menu to add layer and layer-repeater. More...
 

Private Attributes

std::map< std::string, QWidget * > m_toolbarWidgets
 

Detailed Description

Layer editor toolbar.

Definition at line 30 of file layereditortoolbar.h.

Constructor & Destructor Documentation

◆ LayerEditorToolBar()

gui2::LayerEditorToolBar::LayerEditorToolBar ( LayerEditorActions actions,
QWidget *  parent = nullptr 
)

Definition at line 24 of file layereditortoolbar.cpp.

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 }
std::map< std::string, QWidget * > m_toolbarWidgets
QMenu * create_layer_menu(LayerEditorActions *editor_actions)
Creates menu to add layer and layer-repeater.
DAREFLCORE_EXPORT void SetToolBarStyleTextBesides(QToolBar *toolbar)
Set common style for a toolbar.
Definition: styleutils.cpp:39

References create_layer_menu(), m_toolbarWidgets, gui2::LayerEditorActions::onClone(), gui2::LayerEditorActions::onMoveDown(), gui2::LayerEditorActions::onMoveUp(), gui2::LayerEditorActions::onRemove(), and gui2::StyleUtils::SetToolBarStyleTextBesides().

Here is the call graph for this function:

◆ ~LayerEditorToolBar()

gui2::LayerEditorToolBar::~LayerEditorToolBar ( )
default

Member Function Documentation

◆ create_layer_menu()

QMenu * gui2::LayerEditorToolBar::create_layer_menu ( LayerEditorActions editor_actions)
private

Creates menu to add layer and layer-repeater.

Definition at line 84 of file layereditortoolbar.cpp.

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 }
void onAddLayer()
Adds layer after selected item. If more than one item is selected, adds after the last one.

References gui2::LayerEditorActions::onAddLayer(), and gui2::LayerEditorActions::onAddMultiLayer().

Referenced by LayerEditorToolBar().

Here is the call graph for this function:

◆ updateToolButtonStates()

void gui2::LayerEditorToolBar::updateToolButtonStates ( bool  first_present,
bool  last_present 
)

Handle the QToolButtons for their enabled state depending on what is selected.

Definition at line 110 of file layereditortoolbar.cpp.

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 }

References m_toolbarWidgets.

Member Data Documentation

◆ m_toolbarWidgets

std::map<std::string, QWidget*> gui2::LayerEditorToolBar::m_toolbarWidgets
private

Definition at line 41 of file layereditortoolbar.h.

Referenced by LayerEditorToolBar(), and updateToolButtonStates().


The documentation for this class was generated from the following files: