27 #include "../../cpp_simshell/common/InstallDirs.h"
35 #include <QDockWidget>
45 :
QMenuBar(parent), m_parent(parent), m_view(view),
46 m_panels(panels), m_undo_stack(undoStack)
48 assert(parent !=
nullptr &&
"The parent isn't initialized.");
49 assert(view !=
nullptr &&
"The view isn't initialized.");
50 assert(panels !=
nullptr &&
"The panels isn't initialized.");
51 assert(undoStack !=
nullptr &&
"The undo stack isn't initialized.");
60 m_node_mode->setChecked(m_view->
GetMode() == Mode::NODE);
61 m_edge_mode->setChecked(m_view->
GetMode() == Mode::EDGE);
62 m_cell_mode->setChecked(m_view->
GetMode() == Mode::CELL);
65 void EditorActions::Initialize()
68 m_menu_project =
new QMenu(
"&Project",
this);
69 m_menu_edit =
new QMenu(
"&Edit",
this);
70 m_menu_view =
new QMenu(
"&View",
this);
75 m_new_tissue =
new QAction(
"&New", m_menu_project);
76 m_new_tissue->setShortcut(QKeySequence(
"Ctrl+N"));
77 m_new_tissue->setStatusTip(
"Creates a new tissue");
78 connect(m_new_tissue, SIGNAL(triggered()), m_parent, SLOT(NewLeaf()));
81 m_open_tissue =
new QAction(
"&Open", m_menu_project);
82 m_open_tissue->setShortcut(QKeySequence(
"Ctrl+O"));
83 m_open_tissue->setStatusTip(
"Opens an existing project");
84 connect(m_open_tissue, SIGNAL(triggered()), m_parent, SLOT(OpenLeaf()));
87 m_save_tissue =
new QAction(
"&Save", m_menu_project);
88 m_save_tissue->setShortcut(QKeySequence(
"Ctrl+S"));
89 m_save_tissue->setStatusTip(
"Saves the current project");
90 m_save_tissue->setEnabled(
false);
91 connect(m_save_tissue, SIGNAL(triggered()), m_parent, SLOT(SaveLeaf()));
94 m_close_tissue =
new QAction(
"&Close", m_menu_project);
95 m_close_tissue->setStatusTip(
"Closes the current project");
96 m_close_tissue->setEnabled(
false);
97 connect(m_close_tissue, SIGNAL(triggered()), m_parent, SLOT(CloseLeaf()));
100 m_quit =
new QAction(
"&Quit", m_menu_project);
101 m_quit->setShortcut(QKeySequence(
"Ctrl+Q"));
102 m_quit->setStatusTip(
"Quits the program");
103 connect(m_quit, SIGNAL(triggered()), m_parent, SLOT(close()));
108 QMenu* menuMode =
new QMenu(
"&Mode", m_menu_edit);
111 m_node_mode =
new QAction(
"&Node", menuMode);
112 m_node_mode->setShortcut(QKeySequence(
"Ctrl+1"));
113 m_node_mode->setStatusTip(
"Set editing mode to 'Node'");
114 m_node_mode->setEnabled(
false);
115 m_node_mode->setCheckable(
true);
116 connect(m_node_mode, SIGNAL(triggered()), m_parent, SLOT(SetNodeMode()));
117 menuMode->addAction(m_node_mode);
120 m_edge_mode =
new QAction(
"&Edge", menuMode);
121 m_edge_mode->setShortcut(QKeySequence(
"Ctrl+2"));
122 m_edge_mode->setStatusTip(
"Set editing mode to 'Edge'");
123 m_edge_mode->setEnabled(
false);
124 m_edge_mode->setCheckable(
true);
125 connect(m_edge_mode, SIGNAL(triggered()), m_parent, SLOT(SetEdgeMode()));
126 menuMode->addAction(m_edge_mode);
129 m_cell_mode =
new QAction(
"&Cell", menuMode);
130 m_cell_mode->setShortcut(QKeySequence(
"Ctrl+3"));
131 m_cell_mode->setStatusTip(
"Set editing mode to 'Cell'");
132 m_cell_mode->setEnabled(
false);
133 m_cell_mode->setCheckable(
true);
134 connect(m_cell_mode, SIGNAL(triggered()), m_parent, SLOT(SetCellMode()));
135 menuMode->addAction(m_cell_mode);
158 m_delete_item =
new QAction(
"&Delete", m_menu_edit);
159 m_delete_item->setShortcut(QKeySequence(
"Ctrl+D"));
160 m_delete_item->setStatusTip(
"Delete the selected item");
161 connect(m_delete_item, SIGNAL(triggered()), m_view, SLOT(DeleteItem()));
162 m_delete_item->setEnabled(
false);
165 m_split_edge =
new QAction(
"&Split edge", m_menu_edit);
166 m_split_edge->setShortcut(QKeySequence(
"Ctrl+B"));
167 m_split_edge->setStatusTip(
"Split the selected edge");
168 connect(m_split_edge, SIGNAL(triggered()), m_view, SLOT(SplitEdge()));
169 m_split_edge->setEnabled(
false);
172 m_split_cell =
new QAction(
"&Split cell", m_menu_edit);
173 m_split_cell->setShortcut(QKeySequence(
"Ctrl+B"));
174 m_split_cell->setStatusTip(
"Split the selected cell");
175 connect(m_split_cell, SIGNAL(triggered()), m_view, SLOT(SplitCell()));
176 m_split_cell->setEnabled(
false);
179 m_create_cell =
new QAction(
"&Create cell", m_menu_edit);
180 m_create_cell->setShortcut(QKeySequence(
"Ctrl+A"));
181 m_create_cell->setStatusTip(
"Create a cell with the selected endpoints");
182 m_create_cell->setEnabled(
false);
183 connect(m_create_cell, SIGNAL(triggered()), m_view, SLOT(CreateCell()));
186 m_copy_attributes =
new QAction(
"&Copy attributes", m_menu_edit);
187 m_copy_attributes->setShortcut(QKeySequence(
"Ctrl+C"));
188 m_copy_attributes->setStatusTip(
"Copy attributes to the selected items from ...");
189 m_copy_attributes->setEnabled(
false);
190 connect(m_copy_attributes, SIGNAL(triggered()), m_view, SLOT(CopyAttributes()));
193 m_undo =
new QAction(
"&Undo", m_menu_edit);
194 m_undo->setShortcut(QKeySequence(
"Ctrl+z"));
195 m_undo->setStatusTip(
"Undo the last action");
196 m_undo->setEnabled(
false);
197 connect(m_undo, SIGNAL(triggered()), m_parent, SLOT(Undo()));
200 m_redo =
new QAction(
"&Redo", m_menu_edit);
201 m_redo->setShortcut(QKeySequence(
"Ctrl+Shift+z"));
202 m_redo->setStatusTip(
"Redo the last action");
203 m_redo->setEnabled(
false);
204 connect(m_redo, SIGNAL(triggered()), m_parent, SLOT(Redo()));
211 m_show_attribute_panel->setStatusTip(
"Show the attribute panel");
212 m_show_attribute_panel->setEnabled(
false);
217 m_show_geometric_panel->setStatusTip(
"Show the geometric panel");
218 m_show_geometric_panel->setEnabled(
false);
223 m_show_parameters_panel->setStatusTip(
"Show the parameters panel");
224 m_show_parameters_panel->setEnabled(
false);
227 m_transparent_cells =
new QAction(
"&Transparent cells", m_menu_view);
228 m_transparent_cells->setStatusTip(
"Set background of cells transparent");
229 m_transparent_cells->setCheckable(
true);
230 m_transparent_cells->setEnabled(
false);
231 connect(m_transparent_cells, SIGNAL(toggled(
bool)), m_view, SLOT(SetTransparentCells(
bool)));
234 m_set_background =
new QAction(
"&Set background...", m_menu_view);
235 m_set_background->setStatusTip(
"Set background image");
236 m_set_background->setEnabled(
false);
237 connect(m_set_background, SIGNAL(triggered()), m_view, SLOT(SetBackground()));
240 m_set_display_mode =
new QAction(
"&Set color scheme ...", m_menu_view);
241 m_set_display_mode->setStatusTip(
"Set the color scheme for cells in display mode");
242 m_set_display_mode->setEnabled(
false);
243 connect(m_set_display_mode, SIGNAL(triggered()), m_view, SLOT(SetDisplayModePreferences()));
247 m_cancel =
new QAction(
"&Cancel", m_parent);
248 m_cancel->setStatusTip(
"Cancel the current action");
249 m_cancel->setEnabled(
false);
250 connect(m_cancel, SIGNAL(triggered()), m_view, SLOT(CancelAction()));
255 m_menu_project->addAction(m_new_tissue);
256 m_menu_project->addAction(m_open_tissue);
257 m_menu_project->addAction(m_save_tissue);
258 m_menu_project->addAction(m_close_tissue);
259 m_menu_project->addAction(m_quit);
260 addMenu(m_menu_project);
263 m_menu_edit->addMenu(menuMode);
265 m_menu_edit->addAction(m_delete_item);
266 m_menu_edit->addAction(m_split_edge);
267 m_menu_edit->addAction(m_split_cell);
268 m_menu_edit->addAction(m_create_cell);
269 m_menu_edit->addAction(m_copy_attributes);
270 m_menu_edit->addAction(m_undo);
271 m_menu_edit->addAction(m_redo);
272 addMenu(m_menu_edit);
275 m_menu_view->addAction(m_show_attribute_panel);
276 m_menu_view->addAction(m_show_geometric_panel);
277 m_menu_view->addAction(m_show_parameters_panel);
278 m_menu_view->addAction(m_transparent_cells);
279 m_menu_view->addAction(m_set_background);
280 m_menu_view->addAction(m_set_display_mode);
281 addMenu(m_menu_view);
284 QToolBar* toolBar =
new QToolBar(
"Toolbar");
289 QIcon cancelIcon(QString::fromStdString(
InstallDirs::GetDataDir() +
"/icons/Tango/22x22/actions/process-stop.png"));
291 toolBar->addAction(m_node_mode);
292 toolBar->addAction(m_edge_mode);
293 toolBar->addAction(m_cell_mode);
294 toolBar->addAction(m_cancel);
296 m_node_mode->setIcon(nodeIcon);
297 m_edge_mode->setIcon(edgeIcon);
298 m_cell_mode->setIcon(cellIcon);
299 m_cancel->setIcon(cancelIcon);
302 spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
303 toolBar->addWidget(spacer);
306 m_parent->addToolBar(toolBar);
311 assert((m_view->
GetMode() == Mode::NODE
312 || m_view->
GetMode() == Mode::EDGE || m_view->
GetMode() == Mode::CELL)
313 &&
"This mode isn't allowed.");
316 m_split_edge->setEnabled(count == 1 && m_view->
GetMode() == Mode::EDGE);
317 m_split_cell->setEnabled(count == 2
319 m_create_cell->setEnabled(count == 2
321 m_copy_attributes->setEnabled(count > 0
322 && (m_view->
GetMode() == Mode::CELL
323 || m_view->
GetMode() == Mode::EDGE || m_view->
GetMode() == Mode::NODE));
328 m_new_tissue->setEnabled(
true);
329 m_open_tissue->setEnabled(
true);
330 m_save_tissue->setEnabled(
true);
331 m_close_tissue->setEnabled(
true);
333 m_node_mode->setEnabled(
true);
334 m_edge_mode->setEnabled(
true);
335 m_cell_mode->setEnabled(
true);
336 m_undo->setEnabled(
false);
337 m_redo->setEnabled(
false);
339 m_show_attribute_panel->setEnabled(
true);
340 m_show_geometric_panel->setEnabled(
true);
341 m_show_parameters_panel->setEnabled(
true);
342 m_transparent_cells->setEnabled(
true);
343 m_set_background->setEnabled(
true);
344 m_set_display_mode->setEnabled(
true);
349 m_save_tissue->setEnabled(
false);
350 m_close_tissue->setEnabled(
false);
352 m_node_mode->setEnabled(
false);
353 m_edge_mode->setEnabled(
false);
354 m_cell_mode->setEnabled(
false);
356 m_delete_item->setEnabled(
false);
357 m_split_edge->setEnabled(
false);
358 m_split_cell->setEnabled(
false);
359 m_create_cell->setEnabled(
false);
360 m_copy_attributes->setEnabled(
false);
362 m_undo->setEnabled(
false);
363 m_redo->setEnabled(
false);
365 m_cancel->setEnabled(
false);
367 m_show_attribute_panel->setEnabled(
false);
368 m_show_geometric_panel->setEnabled(
false);
369 m_show_parameters_panel->setEnabled(
false);
370 m_transparent_cells->setEnabled(
false);
371 m_set_background->setEnabled(
false);
372 m_set_display_mode->setEnabled(
false);
379 bool modesEnabled = (m_view->
GetMode() == Mode::DISPLAY
380 || m_view->
GetMode() == Mode::NODE || m_view->
GetMode() == Mode::EDGE
381 || m_view->
GetMode() == Mode::CELL || m_view->
GetMode() == Mode::NONE);
383 m_node_mode->setEnabled(modesEnabled);
384 m_edge_mode->setEnabled(modesEnabled);
385 m_cell_mode->setEnabled(modesEnabled);
387 m_delete_item->setEnabled(
false);
388 m_split_edge->setEnabled(
false);
389 m_split_cell->setEnabled(
false);
390 m_create_cell->setEnabled(
false);
391 m_copy_attributes->setEnabled(
false);
394 m_undo->setEnabled(m_view->
GetMode() != Mode::CELL_CREATE
395 && m_view->
GetMode() != Mode::CELL_SLICE && m_undo_stack->
CanUndo());
396 m_redo->setEnabled(m_view->
GetMode() != Mode::CELL_CREATE
397 && m_view->
GetMode() != Mode::CELL_SLICE && m_undo_stack->
CanRedo());
399 m_cancel->setEnabled(m_view->
GetMode() == Mode::CELL_COPY
400 || m_view->
GetMode() == Mode::CELL_CREATE || m_view->
GetMode() == Mode::CELL_SLICE
401 || m_view->
GetMode() == Mode::EDGE_COPY || m_view->
GetMode() == Mode::NODE_COPY);
406 m_undo->setEnabled(m_undo_stack->
CanUndo());
407 m_redo->setEnabled(m_undo_stack->
CanRedo());
412 m_menu_project->menuAction()->setVisible(visible);
413 m_menu_edit->menuAction()->setVisible(visible);
414 m_menu_view->menuAction()->setVisible(visible);
static std::string GetDataDir()
Utility method: get name of the directory for data files.
see the online Qt documentation
Namespace for SimPT tissue editor package.
bool SelectedIsAtBoundary() const
Checks whether the selected (editable) items are at the boundary of the cell complex.
The graphical view on the tissue.
EnabledActions interface.
Interface for PTreePanels.
Interface for the TissueEditor.
Gui::PTreeContainer * ParametersPanel() const
Get the parameters panel.
void FixToggle()
Fix the toggles of the modes.
Interface for EditorActions.
void ModeChanged()
The mode has been changed.
EditorActions(TissueEditor *parent, TissueGraphicsView *view, PTreePanels *panels, UndoStack *undoStack)
Constructor.
Main GUI class for cell editor.
void Show(bool visible)
Show or hide the menubar.
bool SelectedIsDeletable() const
Checks whether the selected (editable) items are deletable.
bool SelectedIsSplitable() const
Checks whether two selected nodes can split a single cell.
see the online Qt documentation
Interface for SelectByIDWidget.
Undo Stack for actions performed on a tissue.
Manages the attribute and geometric ptree panel for a given tissue.
void ItemsSelected(unsigned int count)
Number of items that were selected.
QDockWidget * GetDock() const
Get the associated dock widget, containing the ptree editor.
Interface for PTreeEditorWindow.
Interface for GraphicsView of tissue.
bool CanUndo() const
True if the current action can be undone.
virtual ~EditorActions()
Destructor.
void LeafOpened()
A tissue has been opened.
see the online Qt documentation
Interface for Compressor.
void LeafClosed()
The tissue has been closed.
SelectByIDWidget * GetSelectByIDWidget() const
Returns the widget for selecting items by ID.
void Modified()
The tissue has been modified.
Gui::PTreeContainer * AttributePanel() const
Get the attribute panel.
bool CanRedo() const
True if the current action can be redone.
Mode GetMode() const
Returns the current mode.
Gui::PTreeContainer * GeometricPanel() const
Get the geometric panel.
Interface for PTreeContainer.