WMainWindow.h 11.6 KB
Newer Older
1 2
//---------------------------------------------------------------------------
//
3
// Project: OpenWalnut ( http://www.openwalnut.org )
4
//
5 6
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
wiebel's avatar
wiebel committed
7
//
wiebel's avatar
wiebel committed
8
// This file is part of OpenWalnut.
wiebel's avatar
wiebel committed
9
//
wiebel's avatar
wiebel committed
10
// OpenWalnut is free software: you can redistribute it and/or modify
wiebel's avatar
wiebel committed
11 12 13 14
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
wiebel's avatar
wiebel committed
15
// OpenWalnut is distributed in the hope that it will be useful,
wiebel's avatar
wiebel committed
16 17 18 19 20
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
wiebel's avatar
wiebel committed
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
wiebel's avatar
wiebel committed
22
//
23
//---------------------------------------------------------------------------
wiebel's avatar
wiebel committed
24

25 26
#ifndef WMAINWINDOW_H
#define WMAINWINDOW_H
27

28
#include <map>
29 30
#include <string>
#include <vector>
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
31

Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
32
#include <boost/signals2/signal.hpp>
33
#include <boost/thread.hpp>
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
34

35
#include <QtGui/QMainWindow>
36
#include <QtGui/QSplashScreen>
37
#include <QtCore/QSettings>
38

Mathias Goldau's avatar
Mathias Goldau committed
39
#include "WIconManager.h"
40
#include "WQtToolBar.h"
41
#include "WQtGLWidget.h"
42
#include "WSettingAction.h"
43
#include "networkEditor/WQtNetworkEditor.h"
44
#include "commandPrompt/WQtCommandPromptToolbar.h"
45

46
// forward declarations
47
class QMenuBar;
48 49 50 51 52 53
class WModule;
class WProjectFileIO;
class WQtCombinerToolbar;
class WQtControlPanel;
class WQtCustomDockWidget;
class WQtNavGLWidget;
54
class WQtGLDockWidget;
55
class WQtPropertyBoolAction;
56 57
class WPropertyBase;
class WQtControlPanel;
58
class WQtGLScreenCapture;
59

60
/**
Mathias Goldau's avatar
Mathias Goldau committed
61
 * This class contains the main window and the layout of the widgets within the window.
wiebel's avatar
wiebel committed
62
 * \ingroup gui
63
 */
64
class WMainWindow : public QMainWindow
65
{
66 67
    Q_OBJECT

68
public:
69
    /**
70 71 72
     * Constructor of the main window.
     *
     * \param splash the splash screen currently show. This windows later handles its close stuff.
73
     */
74
    explicit WMainWindow( QSplashScreen* splash );
75 76 77 78 79

    /**
     * Destructor. Stores window state.
     */
    virtual ~WMainWindow();
wiebel's avatar
wiebel committed
80

81 82 83
    /**
     * Set up all widgets menus an buttons in the main window.
     */
84
    void setupGUI();
wiebel's avatar
wiebel committed
85

86
    /**
87 88 89
     * Returns a pointer to the network editor object.
     *
     * \return the network editor instance
90 91
     */
    WQtNetworkEditor* getNetworkEditor();
92

93
    /**
94 95 96
     * Returns a pointer to the control panel object.
     *
     * \return the control panel instance
97
     */
98
    WQtControlPanel* getControlPanel();
99

100 101
    /**
     * Return icon manager
102 103
     *
     * \return the icon manager instance
104 105 106
     */
    WIconManager* getIconManager();

107
    /**
schurade's avatar
schurade committed
108
     * Returns a pointer to a signal object which signals a list of filenames to load
109
     *
schurade's avatar
schurade committed
110
     * \return the signal
111
     */
schurade's avatar
schurade committed
112 113
    boost::signals2::signal1< void, std::vector< std::string > >* getLoaderSignal();

114 115 116 117 118 119 120 121 122
    /**
     * Searches for a custom dock widget with a given name and returns it, if
     * found.
     *
     * \param name the name of the widget
     * \returns a shared pointer to the widget or NULL if not found
     */
    boost::shared_ptr< WQtCustomDockWidget > getCustomDockWidget( std::string name );

123
    /**
124 125 126 127
     * Close one of the custom dock widget saved in the map of customDockWidgets. This method is thread-safe and ensures that the widget is
     * closed in the GUI thread. NEVER call this in the GUI thread. It will block the GUI.
     *
     * \note the widget might not be closed after this call. The widget is usage counted.
128 129 130 131 132
     *
     * \param title the title of the widget to close
     */
    void closeCustomDockWidget( std::string title );

133
    /**
134
     * This method removes the old compatibles toolbar and sets the specified one.
135
     *
136
     * \param toolbar the toolbar to set. If NULL, the toolbar gets reset.
137
     */
138
    void setCompatiblesToolbar( WQtCombinerToolbar* toolbar = NULL );
139

140 141 142 143 144 145 146
    /**
     * This method returns the a pointer to the current compatibles toolbar.
     *
     * \return a pointer to the current compatibles toolbar.
     */
    WQtCombinerToolbar* getCompatiblesToolbar();

147 148 149 150 151 152 153
    /**
     * Returns the settings object.
     *
     * \return settings object.
     */
    static QSettings& getSettings();

154 155 156 157 158 159 160 161 162 163 164 165 166
    /**
     * Forces the main gl widget to have the desired size. This is mainly useful for screenshots and similar.
     *
     * \param w width
     * \param h height
     */
    void forceMainGLWidgetSize( size_t w, size_t h );

    /**
     * Restores the main GL widget size if it was fixed with forceMainGLWidgetSize() previously.
     */
    void restoreMainGLWidgetSize();

167 168 169 170 171 172 173
    /**
     * Get the current splash screen
     *
     * \return the splash screen. Might be closed.
     */
    QSplashScreen* getSplash() const;

174
protected:
175 176 177 178 179 180
    /**
     * Setup the GUI by handling special modules. NavSlices for example setup several toolbar buttons.
     *
     * \param module the module to setup the GUI for.
     */
    void moduleSpecificSetup( boost::shared_ptr< WModule > module );
181 182 183 184 185 186
    /**
     * Cleanup the GUI by handling special modules. NavSlices for example remove several toolbar buttons.
     *
     * \param module the module to setup the GUI for.
     */
    void moduleSpecificCleanup( boost::shared_ptr< WModule > module );
187

188 189
    /**
     * We want to react on close events.
190
     *
191 192
     * \param e the close event.
     */
193
    virtual void closeEvent( QCloseEvent* e );
194

195 196
    /**
     * Handle custom events.
197
     * Currently only WOpenCustomDockWidgetEvent.
198 199 200 201 202
     *
     * \param event the custom event
     */
    virtual void customEvent( QEvent* event );

203 204 205 206 207 208 209 210 211 212 213
    /**
     * Custom event dispatcher. Gets called by QT's Event system every time an event got sent to this widget. This event handler
     * processes several custom events, like WModuleAssocEvent.
     *
     * \note QT Doc says: use event() for custom events.
     * \param event the event that got transmitted.
     *
     * \return true if the event got handled properly.
     */
    virtual bool event( QEvent* event );

214 215 216 217
    /**
     * Called for each project save request.
     *
     * \param writer the list of writers to use.
218 219
     *
     * \returns true if saving was successful
220
     */
221
    virtual bool projectSave( const std::vector< boost::shared_ptr< WProjectFileIO > >& writer );
222

223
    /**
224 225
     * drag and drop implementation for loading files
     * \param event the event to handle
226 227 228 229
     */
    void dropEvent( QDropEvent* event );

    /**
230 231
     * drag and drop implementation for loading files
     * \param event the event to handle
232 233 234 235
     */
     void dragMoveEvent( QDragMoveEvent* event );

    /**
236 237
     * drag and drop implementation for loading files
     * \param event the event to handle
238 239 240
     */
     void dragEnterEvent( QDragEnterEvent* event );

241
public slots:
242
    /**
243
     * gets called when menu option or toolbar button load is activated
244
     */
245 246
    void openLoadDialog();

247 248 249 250 251
    /**
     * gets called when menu entry "About OpenWalnut" is activated
     */
    void openAboutDialog();

252 253 254 255 256 257
    /**
     * Gets called when menu entry "About Qt" is activated
     */
    void openAboutQtDialog();

    /**
258
     * Gets called when menu entry "OpenWalnut Help" is activated
259
     */
260
    void openOpenWalnutHelpDialog();
261

262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
    /**
     * Sets the left preset view of the main viewer.
     */
    void setPresetViewLeft();

    /**
     * Sets the right preset view of the main viewer.
     */
    void setPresetViewRight();

    /**
     * Sets the superior preset view of the main viewer.
     */
    void setPresetViewSuperior();

    /**
     * Sets the inferior preset view of the main viewer.
     */
    void setPresetViewInferior();

    /**
     * Sets the anterior preset view of the main viewer.
     */
    void setPresetViewAnterior();

    /**
     * Sets the posterior preset view of the main viewer.
     */
    void setPresetViewPosterior();

292 293 294 295 296
    /**
     * Gets called when a menu entry that has no functionality yet is activated.
     */
    void openNotImplementedDialog();

schurade's avatar
schurade committed
297 298 299 300 301
    /**
     * gets called when the button new roi is pressed
     */
    void newRoi();

302 303 304 305 306
    /**
     * Gets called whenever the user presses the project button.
     */
    void projectLoad();

307 308 309
    /**
     * Gets called whenever the user presses the project save button.
     */
310
    bool projectSaveAll();
311 312 313 314

    /**
     * Gets called by the save menu to only save the camera settings
     */
315
    bool projectSaveCameraOnly();
316 317 318 319

    /**
     * Gets called by the save menu to only save the ROI settings
     */
320
    bool projectSaveROIOnly();
321

322 323 324
    /**
     * Gets called by the save menu to only save the Module settings
     */
325
    bool projectSaveModuleOnly();
326

327
    /**
328 329 330
     * Is able to handle updates in the log-level setting.
     *
     * \param logLevel the new loglevel to set
331
     */
332
    void handleLogLevelUpdate( unsigned int logLevel );
333

334
private:
335 336 337 338 339
    /**
     * The splash screen object opened on startup.
     */
    QSplashScreen* m_splash;

340
    /**
341
     * The currently set compatibles toolbar
342
     */
343
    WQtCombinerToolbar* m_currentCompatiblesToolbar;
344

schurade's avatar
schurade committed
345
    WIconManager m_iconManager; //!< manager to provide icons in the gui thread
346

347 348 349
    QMenuBar* m_menuBar; //!< The main menu bar of the GUI.

    WQtToolBar* m_permanentToolBar; //!< The permanent toolbar of the main window.
wiebel's avatar
wiebel committed
350

351
    QAction* m_loadButton; //!< the load Data Button
352

353
    WQtControlPanel* m_controlPanel; //!< control panel
wiebel's avatar
wiebel committed
354

355 356
    WQtNetworkEditor* m_networkEditor; //!< network editor

357 358
    WQtCommandPromptToolbar* m_commandPrompt; //!< command prompt

359
    boost::shared_ptr< WQtGLWidget > m_mainGLWidget; //!< the main GL widget of the GUI
360 361
    WQtGLScreenCapture* m_mainGLWidgetScreenCapture; //!< screen recorder in m_mainGLWidget

362 363 364
    boost::shared_ptr< WQtNavGLWidget > m_navAxial; //!< the axial view widget GL widget of the GUI
    boost::shared_ptr< WQtNavGLWidget > m_navCoronal; //!< the coronal view widget GL widget of the GUI
    boost::shared_ptr< WQtNavGLWidget > m_navSagittal; //!< the sgittal view widget GL widget of the GUI
365
    QMainWindow* m_glDock;  //!< the dock that is used for gl widgets
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
366
    QDockWidget* m_dummyWidget; //!< The dummywidget serves as spacer in the dockwidget area;
367

368 369 370 371 372 373 374 375 376 377
    /**
     * All registered WQtCustomDockWidgets.
     */
    std::map< std::string, boost::shared_ptr< WQtCustomDockWidget > > m_customDockWidgets;

    /**
     * Mutex used to lock the map of WQtCustomDockWidgets.
     */
    boost::mutex m_customDockWidgetsLock;

schurade's avatar
schurade committed
378
    boost::signals2::signal1< void, std::vector< std::string > > m_loaderSignal; //!< boost signal for open file dialog
379

380 381 382 383 384
    /**
     * Combine a module with a prototype only if the module is available. Else, nothing happens.
     *
     * \param module the module to be combined.
     * \param proto the prototype to combine with the module.
385
     * \param onlyOnce if true, it is ensured that only one module is in the container.
386
     */
387
    void autoAdd( boost::shared_ptr< WModule > module, std::string proto, bool onlyOnce = false );
388

389 390 391 392 393 394 395 396 397
    /**
     * Loads the window states and geometries from a file.
     */
    void restoreSavedState();

    /**
     * Saves the current window states and geometries to a file.
     */
    void saveWindowState();
398 399 400 401 402

    /**
     * The action controlling the auto-display feature.
     */
    WSettingAction* m_autoDisplaySetting;
403 404 405 406 407 408

private slots:
    /**
     * Handles some special GL vendors and shows the user a dialog.
     */
    void handleGLVendor();
409 410 411 412 413

    /**
     * Shows startup info messages
     */
    void handleStartMessages();
414 415 416 417 418

    /**
     * Finally closes the splash screen.
     */
    void closeSplash();
419 420
};

421
#endif  // WMAINWINDOW_H