OpenWalnut  1.5.0dev
WMainWindow.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WMAINWINDOW_H
26 #define WMAINWINDOW_H
27 
28 #include <map>
29 #include <memory>
30 #include <string>
31 #include <vector>
32 
33 #include <QMainWindow>
34 #include <QSplashScreen>
35 #include <QtCore/QSettings>
36 #include <boost/signals2/signal.hpp>
37 #include <boost/thread.hpp>
38 
39 #include "WIconManager.h"
40 #include "WQtGLWidget.h"
41 #include "WQtMessageDock.h"
42 #include "WQtToolBar.h"
43 #include "WSettingAction.h"
44 #include "networkEditor/WQtNetworkEditor.h"
45 
46 // forward declarations
47 class QMenuBar;
48 class WModule;
49 class WProjectFileIO;
50 class WQtCombinerToolbar;
51 class WQtControlPanel;
52 class WQtCustomDockWidget;
53 class WQtNavGLWidget;
54 class WQtGLDockWidget;
56 class WPropertyBase;
57 class WQtControlPanel;
58 class WQtGLScreenCapture;
59 class WUIQtWidgetBase;
60 
61 /**
62  * This class contains the main window and the layout of the widgets within the window.
63  * \ingroup ui
64  */
65 class WMainWindow : public QMainWindow
66 {
67  Q_OBJECT
68 
69 public:
70  /**
71  * Constructor of the main window.
72  *
73  * \param splash the splash screen currently show. This windows later handles its close stuff.
74  */
75  explicit WMainWindow( QSplashScreen* splash );
76 
77  /**
78  * Destructor. Stores window state.
79  */
80  virtual ~WMainWindow();
81 
82  /**
83  * Set up all widgets menus an buttons in the main window.
84  */
85  void setupGUI();
86 
87  /**
88  * Returns a pointer to the network editor object.
89  *
90  * \return the network editor instance
91  */
93 
94  /**
95  * Returns a pointer to the control panel object.
96  *
97  * \return the control panel instance
98  */
100 
101  /**
102  * Return icon manager
103  *
104  * \return the icon manager instance
105  */
107 
108  /**
109  * Returns a pointer to a signal object which signals a list of filenames to load
110  *
111  * \return the signal
112  */
113  boost::signals2::signal< void( std::vector< std::string > ) >* getLoaderSignal();
114 
115  /**
116  * Searches for a custom dock widget with a given name and returns it, if
117  * found.
118  *
119  * \param name the name of the widget
120  * \returns a shared pointer to the widget or NULL if not found
121  */
122  std::shared_ptr< WQtCustomDockWidget > getCustomDockWidget( std::string name );
123 
124  /**
125  * Close one of the custom dock widget saved in the map of customDockWidgets. This method is thread-safe and ensures that the widget is
126  * closed in the GUI thread. NEVER call this in the GUI thread. It will block the GUI.
127  *
128  * \note the widget might not be closed after this call. The widget is usage counted.
129  *
130  * \param title the title of the widget to close
131  */
132  void closeCustomDockWidget( std::string title );
133 
134  /**
135  * This method removes the old compatibles toolbar and sets the specified one.
136  *
137  * \param toolbar the toolbar to set. If NULL, the toolbar gets reset.
138  */
139  void setCompatiblesToolbar( WQtCombinerToolbar* toolbar = NULL );
140 
141  /**
142  * This method returns the a pointer to the current compatibles toolbar.
143  *
144  * \return a pointer to the current compatibles toolbar.
145  */
147 
148  /**
149  * Returns the settings object.
150  *
151  * \return settings object.
152  */
153  static QSettings& getSettings();
154 
155  /**
156  * Set a setting specified by a key to a given value. Abbreviation for the lazy programmer as it ensures proper typecast of std::string to
157  * the QSettings types (QString and QVariant).
158  *
159  * \param key the key
160  * \param value the value
161  */
162  static void setSetting( std::string key, std::string value );
163 
164  /**
165  * Get the current splash screen
166  *
167  * \return the splash screen. Might be closed.
168  */
169  QSplashScreen* getSplash() const;
170 
171  /**
172  * Loads a given project asynchronously.
173  *
174  * \param filename the file to load.
175  */
176  void asyncProjectLoad( std::string filename );
177 
178  /**
179  * This method checks whether a given drop event is acceptable.
180  * Several widgets in the GUI should support drag and drop. Unfortunately, not all widgets automatically push these events to the MainWindow.
181  * This is especially the case for QGraphics* based classes.
182  *
183  * \param mimeData the mime info of the dragged thing
184  *
185  * \return true if acceptable.
186  */
187  static bool isDropAcceptable( const QMimeData* mimeData );
188 
189  /**
190  * Add the default OW menu to the given widget using addAction.
191  *
192  * \param widget the widget to add the menu to
193  */
194  void addGlobalMenu( QWidget* widget );
195 
196  /**
197  * Allows comfortable error reporting using popups.
198  *
199  * \param parent the parent widget for this popup
200  * \param title the title
201  * \param message the message
202  */
203  void reportError( QWidget* parent, QString title, QString message );
204 
205  /**
206  * Allows comfortable warning reporting using popups.
207  *
208  * \param parent the parent widget for this popup
209  * \param title the title
210  * \param message the message
211  */
212  void reportWarning( QWidget* parent, QString title, QString message );
213 
214  /**
215  * Allows comfortable info reporting using popups.
216  *
217  * \param parent the parent widget for this popup
218  * \param title the title
219  * \param message the message
220  */
221  void reportInfo( QWidget* parent, QString title, QString message );
222 
223  /**
224  * Return the message dock widget
225  *
226  * \return the message dock
227  */
228  const WQtMessageDock* getMessageDock() const;
229 
230  /**
231  * Return the message dock widget
232  *
233  * \return the message dock
234  */
236 
237  /**
238  * Register a custom widget. This is important as the main window needs to manage the close/delete of these widgets. Only call from withing
239  * the GUI thread.
240  *
241  * \param widget the widget.
242  */
243  void registerCustomWidget( WUIQtWidgetBase* widget );
244 
245  /**
246  * De-register a custom widget.
247  *
248  * \param widget the widget.
249  */
250  void deregisterCustomWidget( WUIQtWidgetBase* widget );
251 
252  /**
253  * The default dock area to use for adding custom docks.
254  *
255  * \return the dock area in \ref getDefaultCustomDockAreaWidget
256  */
257  Qt::DockWidgetArea getDefaultCustomDockArea() const;
258 
259  /**
260  * The Widget to add custom docks.
261  *
262  * \return the widget
263  */
265 
266 protected:
267  /**
268  * Setup the GUI by handling special modules. NavSlices for example setup several toolbar buttons.
269  *
270  * \param module the module to setup the GUI for.
271  */
272  void moduleSpecificSetup( std::shared_ptr< WModule > module );
273  /**
274  * Cleanup the GUI by handling special modules. NavSlices for example remove several toolbar buttons.
275  *
276  * \param module the module to setup the GUI for.
277  */
278  void moduleSpecificCleanup( std::shared_ptr< WModule > module );
279 
280  /**
281  * We want to react on close events.
282  *
283  * \param e the close event.
284  */
285  virtual void closeEvent( QCloseEvent* e );
286 
287  /**
288  * Handle custom events.
289  * Currently only WOpenCustomDockWidgetEvent.
290  *
291  * \param event the custom event
292  */
293  virtual void customEvent( QEvent* event );
294 
295  /**
296  * Custom event dispatcher. Gets called by QT's Event system every time an event got sent to this widget. This event handler
297  * processes several custom events, like WModuleAssocEvent.
298  *
299  * \note QT Doc says: use event() for custom events.
300  * \param event the event that got transmitted.
301  *
302  * \return true if the event got handled properly.
303  */
304  virtual bool event( QEvent* event );
305 
306  /**
307  * Called for each project save request.
308  *
309  * \param writer the list of writers to use.
310  *
311  * \returns true if saving was successful
312  */
313  virtual bool projectSave( const std::vector< std::shared_ptr< WProjectFileIO > >& writer );
314 
315  /**
316  * drag and drop implementation for loading files
317  * \param event the event to handle
318  */
319  void dropEvent( QDropEvent* event );
320 
321  /**
322  * drag and drop implementation for loading files
323  * \param event the event to handle
324  */
325  void dragMoveEvent( QDragMoveEvent* event );
326 
327  /**
328  * drag and drop implementation for loading files
329  * \param event the event to handle
330  */
331  void dragEnterEvent( QDragEnterEvent* event );
332 
333 public slots:
334  /**
335  * Slot handling the pressed new project button.
336  */
337  void newProject();
338  /**
339  * gets called when menu option or toolbar button load is activated
340  */
341  void openLoadDialog();
342 
343  /**
344  * gets called when menu entry "About OpenWalnut" is activated
345  */
346  void openAboutDialog();
347 
348  /**
349  * Gets called when menu entry "About Qt" is activated
350  */
351  void openAboutQtDialog();
352 
353  /**
354  * Gets called when menu entry "OpenWalnut Help" is activated
355  */
357 
358  /**
359  * Gets called when a menu entry that has no functionality yet is activated.
360  */
362 
363  /**
364  * gets called when the button new ROI is pressed
365  */
366  void newRoi();
367 
368  /**
369  * Gets called whenever the user presses the project save button.
370  */
371  bool projectSaveAll();
372 
373  /**
374  * Gets called by the save menu to only save the camera settings
375  */
376  bool projectSaveCameraOnly();
377 
378  /**
379  * Gets called by the save menu to only save the ROI settings
380  */
381  bool projectSaveROIOnly();
382 
383  /**
384  * Gets called by the save menu to only save the Module settings
385  */
386  bool projectSaveModuleOnly();
387 
388  /**
389  * Is able to handle updates in the log-level setting.
390  *
391  * \param logLevel the new loglevel to set
392  */
393  void handleLogLevelUpdate( unsigned int logLevel );
394 
395  /**
396  * Handles the given drop. Use this in conjunction with \ref isDropAcceptable.
397  *
398  * \param event the event to handle
399  */
400  void handleDrop( QDropEvent* event );
401 
402  /**
403  * Change visibility of the given widget. Useful as there is no toggleVisibility slot in Qt.
404  *
405  * \param who the widget to switch
406  */
407  void switchVisibility( QWidget* who );
408 
409 private:
410  /**
411  * The splash screen object opened on startup.
412  */
413  QSplashScreen* m_splash;
414 
415  /**
416  * The currently set compatibles toolbar
417  */
419 
420  WIconManager m_iconManager; //!< manager to provide icons in the gui thread
421 
422  QMenuBar* m_menuBar; //!< The main menu bar of the GUI.
423 
424  WQtToolBar* m_permanentToolBar; //!< The permanent toolbar of the main window.
425 
426  /**
427  * Message and log window
428  */
430 
431  // several menu items
432  QAction* m_newAction; //!< the new project button
433  QAction* m_loadButton; //!< the load button
434  QAction* m_quitAction; //!< quit OpenWalnut
435  QAction* m_saveAction; //!< the save menu
436  QMenu* m_saveMenu; //!< the menu using m_saveAction
437 
438  QMenu* m_viewMenu; //!< view and camera control menu
439 
440  QAction* m_settingsAction; //!< the settings
441  QMenu* m_settingsMenu; //!< the settings
442 
443  QAction* m_helpAction; //!< the help menu
444  QMenu* m_helpMenu; //!< the help menu
445 
446  WQtControlPanel* m_controlPanel; //!< control panel
447 
448  WQtNetworkEditor* m_networkEditor; //!< network editor
449 
450  WQtGLWidget* m_mainGLWidget; //!< the main GL widget of the GUI
451 
452  std::shared_ptr< WQtNavGLWidget > m_navAxial; //!< the axial view widget GL widget of the GUI
453  std::shared_ptr< WQtNavGLWidget > m_navCoronal; //!< the coronal view widget GL widget of the GUI
454  std::shared_ptr< WQtNavGLWidget > m_navSagittal; //!< the sgittal view widget GL widget of the GUI
455  QMainWindow* m_glDock; //!< the dock that is used for gl widgets
456  QDockWidget* m_dummyWidget; //!< The dummywidget serves as spacer in the dockwidget area;
457  WQtGLDockWidget* m_mainGLDock; //!< the dock containing the main gl widget
458 
459  /**
460  * Used to handle the two-stage close process.
461  */
463 
464  /**
465  * Flag whether the system is shutting down now.
466  */
468 
469  /**
470  * The thread responsible for doing stage 1 stuff.
471  */
473 
474  /**
475  * The actual thread function for m_closeStage1Thread.
476  */
477  void closeStage1Thread();
478 
479  /**
480  * The second stage function. Called by the finished closeStage1Thread function. Runs in GUI thread.
481  */
482  void closeStage2();
483 
484  /**
485  * Container for core/UI widgetd
486  */
487  typedef std::vector< WUIQtWidgetBase* > CustomWidgets;
488 
489  /**
490  * All registered widgets created by the core/UI api.
491  */
493 
494  boost::signals2::signal< void( std::vector< std::string > ) > m_loaderSignal; //!< boost signal for open file dialog
495 
496  /**
497  * Combine a module with a prototype only if the module is available. Else, nothing happens.
498  *
499  * \param module the module to be combined.
500  * \param proto the prototype to combine with the module.
501  * \param onlyOnce if true, it is ensured that only one module is in the container.
502  */
503  void autoAdd( std::shared_ptr< WModule > module, std::string proto, bool onlyOnce = false );
504 
505  /**
506  * Loads the window states and geometries from a file.
507  */
508  void restoreSavedState();
509 
510  /**
511  * Saves the current window states and geometries to a file.
512  */
513  void saveWindowState();
514 
515  /**
516  * The action for allowing editing min and max of sliders.
517  */
519 
520  /**
521  * Called whenever a async load has finished. Used by \ref asyncProjectLoad. It might be called from outside the GUI thread.
522  *
523  * \param file the filename
524  * \param errors the list of errors
525  * \param warnings the list of warnings
526  */
527  void slotLoadFinished( boost::filesystem::path file, std::vector< std::string > errors, std::vector< std::string > warnings );
528 
529 private slots:
530  /**
531  * Handles some special GL vendors and shows the user a dialog.
532  */
533  void handleGLVendor();
534 
535  /**
536  * Shows startup info messages
537  */
538  void handleStartMessages();
539 
540  /**
541  * Shows the welcome message.
542  *
543  * \param force if true, the dialog is shown even if the user said "do not show again".
544  */
545  void showWelcomeDialog( bool force = true );
546 
547  /**
548  * Finally closes the splash screen.
549  */
550  void closeSplash();
551 };
552 
553 #endif // WMAINWINDOW_H
Manages icon access.
Definition: WIconManager.h:41
This class contains the main window and the layout of the widgets within the window.
Definition: WMainWindow.h:66
WQtToolBar * m_permanentToolBar
The permanent toolbar of the main window.
Definition: WMainWindow.h:424
void handleDrop(QDropEvent *event)
Handles the given drop.
void showWelcomeDialog(bool force=true)
Shows the welcome message.
WThreadedRunner::SPtr m_closeStage1Thread
The thread responsible for doing stage 1 stuff.
Definition: WMainWindow.h:472
QAction * m_loadButton
the load button
Definition: WMainWindow.h:433
WSettingAction * m_sliderMinMaxEditSetting
The action for allowing editing min and max of sliders.
Definition: WMainWindow.h:518
void deregisterCustomWidget(WUIQtWidgetBase *widget)
De-register a custom widget.
WQtControlPanel * getControlPanel()
Returns a pointer to the control panel object.
void openAboutDialog()
gets called when menu entry "About OpenWalnut" is activated
QAction * m_settingsAction
the settings
Definition: WMainWindow.h:440
std::shared_ptr< WQtNavGLWidget > m_navAxial
the axial view widget GL widget of the GUI
Definition: WMainWindow.h:452
bool projectSaveCameraOnly()
Gets called by the save menu to only save the camera settings.
void closeCustomDockWidget(std::string title)
Close one of the custom dock widget saved in the map of customDockWidgets.
bool projectSaveAll()
Gets called whenever the user presses the project save button.
std::shared_ptr< WQtNavGLWidget > m_navCoronal
the coronal view widget GL widget of the GUI
Definition: WMainWindow.h:453
void saveWindowState()
Saves the current window states and geometries to a file.
QAction * m_quitAction
quit OpenWalnut
Definition: WMainWindow.h:434
QMenu * m_viewMenu
view and camera control menu
Definition: WMainWindow.h:438
QSplashScreen * getSplash() const
Get the current splash screen.
QMenu * m_settingsMenu
the settings
Definition: WMainWindow.h:441
WQtGLDockWidget * m_mainGLDock
the dock containing the main gl widget
Definition: WMainWindow.h:457
void handleGLVendor()
Handles some special GL vendors and shows the user a dialog.
void openOpenWalnutHelpDialog()
Gets called when menu entry "OpenWalnut Help" is activated.
void closeStage2()
The second stage function.
void moduleSpecificCleanup(std::shared_ptr< WModule > module)
Cleanup the GUI by handling special modules.
void handleLogLevelUpdate(unsigned int logLevel)
Is able to handle updates in the log-level setting.
void setupGUI()
Set up all widgets menus an buttons in the main window.
QSplashScreen * m_splash
The splash screen object opened on startup.
Definition: WMainWindow.h:413
static bool isDropAcceptable(const QMimeData *mimeData)
This method checks whether a given drop event is acceptable.
void moduleSpecificSetup(std::shared_ptr< WModule > module)
Setup the GUI by handling special modules.
void newRoi()
gets called when the button new ROI is pressed
QAction * m_newAction
the new project button
Definition: WMainWindow.h:432
WQtMessageDock * m_messageDock
Message and log window.
Definition: WMainWindow.h:429
void registerCustomWidget(WUIQtWidgetBase *widget)
Register a custom widget.
void openLoadDialog()
gets called when menu option or toolbar button load is activated
WIconManager * getIconManager()
Return icon manager.
void closeStage1Thread()
The actual thread function for m_closeStage1Thread.
WQtControlPanel * m_controlPanel
control panel
Definition: WMainWindow.h:446
QMainWindow * m_glDock
the dock that is used for gl widgets
Definition: WMainWindow.h:455
virtual void customEvent(QEvent *event)
Handle custom events.
QMainWindow * getDefaultCustomDockAreaWidget() const
The Widget to add custom docks.
QMenu * m_saveMenu
the menu using m_saveAction
Definition: WMainWindow.h:436
bool projectSaveROIOnly()
Gets called by the save menu to only save the ROI settings.
void dropEvent(QDropEvent *event)
drag and drop implementation for loading files
void reportWarning(QWidget *parent, QString title, QString message)
Allows comfortable warning reporting using popups.
bool projectSaveModuleOnly()
Gets called by the save menu to only save the Module settings.
QMenu * m_helpMenu
the help menu
Definition: WMainWindow.h:444
WSharedSequenceContainer< CustomWidgets > m_customWidgets
All registered widgets created by the core/UI api.
Definition: WMainWindow.h:492
void dragEnterEvent(QDragEnterEvent *event)
drag and drop implementation for loading files
bool m_closeFirstStage
Used to handle the two-stage close process.
Definition: WMainWindow.h:462
void setCompatiblesToolbar(WQtCombinerToolbar *toolbar=NULL)
This method removes the old compatibles toolbar and sets the specified one.
void addGlobalMenu(QWidget *widget)
Add the default OW menu to the given widget using addAction.
void slotLoadFinished(boost::filesystem::path file, std::vector< std::string > errors, std::vector< std::string > warnings)
Called whenever a async load has finished.
bool m_closeInProgress
Flag whether the system is shutting down now.
Definition: WMainWindow.h:467
QDockWidget * m_dummyWidget
The dummywidget serves as spacer in the dockwidget area;.
Definition: WMainWindow.h:456
void reportInfo(QWidget *parent, QString title, QString message)
Allows comfortable info reporting using popups.
virtual ~WMainWindow()
Destructor.
Qt::DockWidgetArea getDefaultCustomDockArea() const
The default dock area to use for adding custom docks.
void closeSplash()
Finally closes the splash screen.
void asyncProjectLoad(std::string filename)
Loads a given project asynchronously.
void reportError(QWidget *parent, QString title, QString message)
Allows comfortable error reporting using popups.
virtual bool projectSave(const std::vector< std::shared_ptr< WProjectFileIO > > &writer)
Called for each project save request.
static void setSetting(std::string key, std::string value)
Set a setting specified by a key to a given value.
WQtNetworkEditor * m_networkEditor
network editor
Definition: WMainWindow.h:448
std::shared_ptr< WQtCustomDockWidget > getCustomDockWidget(std::string name)
Searches for a custom dock widget with a given name and returns it, if found.
boost::signals2::signal< void(std::vector< std::string >) > * getLoaderSignal()
Returns a pointer to a signal object which signals a list of filenames to load.
std::shared_ptr< WQtNavGLWidget > m_navSagittal
the sgittal view widget GL widget of the GUI
Definition: WMainWindow.h:454
WQtGLWidget * m_mainGLWidget
the main GL widget of the GUI
Definition: WMainWindow.h:450
std::vector< WUIQtWidgetBase * > CustomWidgets
Container for core/UI widgetd.
Definition: WMainWindow.h:487
WQtCombinerToolbar * getCompatiblesToolbar()
This method returns the a pointer to the current compatibles toolbar.
void restoreSavedState()
Loads the window states and geometries from a file.
QAction * m_saveAction
the save menu
Definition: WMainWindow.h:435
WQtCombinerToolbar * m_currentCompatiblesToolbar
The currently set compatibles toolbar.
Definition: WMainWindow.h:418
virtual void closeEvent(QCloseEvent *e)
We want to react on close events.
void openNotImplementedDialog()
Gets called when a menu entry that has no functionality yet is activated.
void handleStartMessages()
Shows startup info messages.
const WQtMessageDock * getMessageDock() const
Return the message dock widget.
static QSettings & getSettings()
Returns the settings object.
QAction * m_helpAction
the help menu
Definition: WMainWindow.h:443
boost::signals2::signal< void(std::vector< std::string >) > m_loaderSignal
boost signal for open file dialog
Definition: WMainWindow.h:494
QMenuBar * m_menuBar
The main menu bar of the GUI.
Definition: WMainWindow.h:422
void newProject()
Slot handling the pressed new project button.
void openAboutQtDialog()
Gets called when menu entry "About Qt" is activated.
WIconManager m_iconManager
manager to provide icons in the gui thread
Definition: WMainWindow.h:420
void dragMoveEvent(QDragMoveEvent *event)
drag and drop implementation for loading files
WQtNetworkEditor * getNetworkEditor()
Returns a pointer to the network editor object.
void switchVisibility(QWidget *who)
Change visibility of the given widget.
void autoAdd(std::shared_ptr< WModule > module, std::string proto, bool onlyOnce=false)
Combine a module with a prototype only if the module is available.
virtual bool event(QEvent *event)
Custom event dispatcher.
WMainWindow(QSplashScreen *splash)
Constructor of the main window.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
A base class for all parts of OpenWalnut which can be serialized to a project file.
Abstract base class for all properties.
Definition: WPropertyBase.h:48
This is a toolbar.
container widget for a tree widget with context menu and some control widgets
Dock widget containing only a GLWidget.
This class is a screen recorder adapter in QT.
A widget containing an open gl display area.
Definition: WQtGLWidget.h:54
Dock widget for showing messages and logs.
container widget to hold as GL widget and a slider
Container widget to hold the WQtNetworkScene.
Implements a property action for WPropBool.
This is a toolbar.
Definition: WQtToolBar.h:39
Class to handle a certain setting with an action.
std::shared_ptr< WThreadedRunner > SPtr
Abbreviation to a shared_ptr to this type.
Implementation of WUIWidgetBase.