WMainWindow.cpp 51.2 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 24
//---------------------------------------------------------------------------

25
#include <iostream>
Mathias Goldau's avatar
Mathias Goldau committed
26
#include <map>
27 28
#include <string>
#include <vector>
29

30
#include <boost/thread.hpp>
31
#include <boost/regex.hpp>
32

33
#include <QtGui/QApplication>
34
#include <QtGui/QCloseEvent>
wiebel's avatar
wiebel committed
35
#include <QtGui/QDockWidget>
36
#include <QtGui/QFileDialog>
37
#include <QtGui/QIcon>
Mathias Goldau's avatar
Mathias Goldau committed
38 39
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
40
#include <QtGui/QMessageBox>
41
#include <QtGui/QTextEdit>
42
#include <QtGui/QShortcut>
Mathias Goldau's avatar
Mathias Goldau committed
43
#include <QtGui/QSlider>
44
#include <QtGui/QVBoxLayout>
45
#include <QtGui/QWidget>
46
#include <QtCore/QSettings>
47
#include <QtGui/QInputDialog>
48

49 50 51 52
#ifndef QT4GUI_NOWEBKIT
    #include <QtWebKit/QWebView>
#endif

53 54
#include "WVersion.h"   // NOTE: this file is auto-generated by CMAKE

55 56 57
#include "../icons/WIcons.xpm"
#include "controlPanel/WPropertyBoolWidget.h"
#include "controlPanel/WQtControlPanel.h"
58 59 60
#include "core/common/WColor.h"
#include "core/common/WIOTools.h"
#include "core/common/WPathHelper.h"
61
#include "core/common/WProjectFileIO.h"
62 63 64 65 66
#include "core/dataHandler/WDataSetFibers.h"
#include "core/dataHandler/WDataSetSingle.h"
#include "core/dataHandler/WEEG2.h"
#include "core/graphicsEngine/WGEZoomTrackballManipulator.h"
#include "core/graphicsEngine/WROIBox.h"
67
#include "core/kernel/WDataModule.h"
68 69 70 71 72 73 74
#include "core/kernel/WKernel.h"
#include "core/kernel/WModule.h"
#include "core/kernel/WModuleCombiner.h"
#include "core/kernel/WModuleCombinerTypes.h"
#include "core/kernel/WProjectFile.h"
#include "core/kernel/WROIManager.h"
#include "core/kernel/WSelectionManager.h"
Mathias Goldau's avatar
Mathias Goldau committed
75 76 77
#include "events/WEventTypes.h"
#include "events/WModuleCrashEvent.h"
#include "events/WModuleReadyEvent.h"
78
#include "events/WModuleRemovedEvent.h"
79
#include "events/WOpenCustomDockWidgetEvent.h"
80
#include "events/WCloseCustomDockWidgetEvent.h"
Sebastian Eichelbaum's avatar
[MERGE]  
Sebastian Eichelbaum committed
81
#include "guiElements/WQtPropertyBoolAction.h"
82
#include "WQt4Gui.h"
83
#include "WQtCombinerToolbar.h"
Mathias Goldau's avatar
Mathias Goldau committed
84
#include "WQtCustomDockWidget.h"
85
#include "WQtGLDockWidget.h"
86
#include "WQtNavGLWidget.h"
87
#include "WSettingAction.h"
88
#include "WSettingMenu.h"
89
#include "WQtMessageDialog.h"
90
#include "WQtGLScreenCapture.h"
Mathias Goldau's avatar
Mathias Goldau committed
91 92

#include "WMainWindow.h"
93
#include "WMainWindow.moc"
94

95
WMainWindow::WMainWindow( QSplashScreen* splash ):
96
    QMainWindow(),
97
    m_splash( splash ),
98
    m_currentCompatiblesToolbar( NULL ),
99
    m_iconManager()
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
100
{
101
    setAcceptDrops( true ); // enable drag and drop events
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
102
}
103

104 105 106 107 108
WMainWindow::~WMainWindow()
{
    // cleanup
}

109
void WMainWindow::setupGUI()
110
{
111 112
    wlog::info( "WMainWindow" ) << "Setting up GUI";

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Setting setup
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    WSettingAction* hideMenuAction = new WSettingAction( this, "qt4gui/showMenu",
                                                               "Show Menubar",
                                                               "Allows you to hide the menu. Can be restored using CTRL-M.",
                                                               true,
                                                               false,
                                                               QKeySequence( Qt::CTRL + Qt::Key_M ) );

    WSettingAction* showNavWidgets = new WSettingAction( this, "qt4gui/showNavigationWidgets",
                                                               "Show Navigation Views",
                                                               "Disables the navigation views completely. This can lead to a speed-up and is "
                                                               "recommended for those who do not need them.",
                                                               true,
                                                               true    // this requires a restart
                                                       );
131 132 133
    WSettingAction* showNetworkEditor = new WSettingAction( this, "qt4gui/showNetworkEditor",
                                                               "Show Network Editor",
                                                               "Show the network editor allowing you to manipulate the module graph graphically?",
134
                                                               true,
135 136
                                                               true    // this requires a restart
                                                       );
137 138 139 140 141 142
    m_autoDisplaySetting = new WSettingAction( this, "qt4gui/useAutoDisplay",
                                                     "Auto-Display",
                                                     "If enabled, the best matching module is automatically added if some data was loaded.",
                                                     true );

    WSettingAction* mtViews = new WSettingAction( this, "qt4gui/ge/multiThreadedViewer",
Alexander Wiebel's avatar
Alexander Wiebel committed
143
                                                        "Multi-Threaded Views",
144
                                                        "If enabled, the graphic windows are rendered in different threads. This can speed-up "
145
                                                        "rendering on machines with multiple cores. WARNING: can lead to crashes sometimes.",
146 147 148 149 150 151
                                                        false,
                                                        true // require restart
                                                );
    // NOTE: the multi-threading feature needs to be activated BEFORE the first viewer is created. To ensure this we do it here.
    WGraphicsEngine::getGraphicsEngine()->setMultiThreadedViews( mtViews->get() );

152 153 154 155 156 157 158 159 160
    // set the log-level setting.
    // NOTE: see WQt4Gui which reads the setting.
    QList< QString > logOptions;
    logOptions.push_back( "Debug" );
    logOptions.push_back( "Info" );
    logOptions.push_back( "Warning" );
    logOptions.push_back( "Error" );
    WSettingMenu* logLevels = new WSettingMenu( this, "qt4gui/logLevel",
                                                      "Log-Level",
161
                                                      "Allows one to set the log verbosity.",
162 163 164 165 166
                                                      1,    // info is the default
                                                      logOptions
                                              );
    connect( logLevels, SIGNAL( change( unsigned int ) ), this, SLOT( handleLogLevelUpdate( unsigned int ) ) );

167 168 169 170
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // GUI setup
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////

171
    m_iconManager.addIcon( std::string( "load" ), fileopen_xpm );
172
    m_iconManager.addIcon( std::string( "loadProject" ), projOpen_xpm );
173
    m_iconManager.addIcon( std::string( "saveProject" ), projSave_xpm );
Mathias Goldau's avatar
Mathias Goldau committed
174
    m_iconManager.addIcon( std::string( "logo" ), openwalnut_32x32_xpm );
175
    m_iconManager.addIcon( std::string( "help" ), question_xpm );
176
    m_iconManager.addIcon( std::string( "quit" ), quit_xpm );
177 178 179
    m_iconManager.addIcon( std::string( "moduleBusy" ), moduleBusy_xpm );
    m_iconManager.addIcon( std::string( "moduleCrashed" ), moduleCrashed_xpm );
    m_iconManager.addIcon( std::string( "remove" ), remove_xpm );
180
    m_iconManager.addIcon( std::string( "config" ), preferences_system_xpm );
181
    m_iconManager.addIcon( std::string( "view" ), camera_xpm );
182
    m_iconManager.addIcon( std::string( "missingModule" ), QuestionMarks_xpm );
183 184
    m_iconManager.addIcon( std::string( "none" ), empty_xpm );
    m_iconManager.addIcon( std::string( "DefaultModuleIcon" ), moduleDefault_xpm );
185 186 187
    m_iconManager.addIcon( std::string( "video" ), video_xpm );
    m_iconManager.addIcon( std::string( "image" ), image_xpm );
    m_iconManager.addIcon( std::string( "preferences" ), preferences_xpm );
188

189
    if( objectName().isEmpty() )
190
    {
191
        setObjectName( QString::fromUtf8( "MainWindow" ) );
192
    }
193 194 195

    // NOTE: this only is an initial size. The state reloaded from QSettings will set it to the value the user had last session.
    resize( 800, 600 );
196
    setWindowIcon( m_iconManager.getIcon( "logo" ) );
197 198
    std::string windowHeading =  std::string( "OpenWalnut " ) + std::string( W_VERSION );
    setWindowTitle( QApplication::translate( "MainWindow", windowHeading.c_str(), 0, QApplication::UnicodeUTF8 ) );
199

200 201
    setDockOptions( QMainWindow::AnimatedDocks |  QMainWindow::AllowNestedDocks | QMainWindow::AllowTabbedDocks );

202
    //network Editor
203 204 205 206 207 208
    m_networkEditor = NULL;
    if( showNetworkEditor->get() )
    {
        m_networkEditor = new WQtNetworkEditor( this );
        m_networkEditor->setFeatures( QDockWidget::AllDockWidgetFeatures );
    }
209

210 211 212 213
    // the control panel instance is needed for the menu
    m_controlPanel = new WQtControlPanel( this );
    m_controlPanel->setFeatures( QDockWidget::AllDockWidgetFeatures );
    m_controlPanel->addSubject( "Default Subject" );
214

215 216
    // add all docks
    addDockWidget( Qt::RightDockWidgetArea, m_controlPanel->getModuleDock() );
217 218 219 220
    if( m_networkEditor )
    {
        addDockWidget( Qt::RightDockWidgetArea, m_networkEditor );
    }
221

222
    addDockWidget( Qt::RightDockWidgetArea, m_controlPanel->getColormapperDock() );
223
    addDockWidget( Qt::RightDockWidgetArea, m_controlPanel->getRoiDock() );
224 225

    // tabify those panels by default
226 227 228 229
    if( m_networkEditor )
    {
        tabifyDockWidget( m_networkEditor, m_controlPanel->getModuleDock() );
    }
230
    tabifyDockWidget( m_controlPanel->getModuleDock(), m_controlPanel->getColormapperDock() );
231
    tabifyDockWidget( m_controlPanel->getColormapperDock(), m_controlPanel->getRoiDock() );
232

233
    m_glDock = new QMainWindow();
234
    m_glDock->setObjectName( "GLDock" );
235 236 237
    m_glDock->setDockOptions( QMainWindow::AnimatedDocks |  QMainWindow::AllowNestedDocks | QMainWindow::AllowTabbedDocks );
    m_glDock->setDocumentMode( true );
    setCentralWidget( m_glDock );
238
    WQtGLDockWidget* mainGLDock = new WQtGLDockWidget( "Main View", "3D View", m_glDock );
239 240
    mainGLDock->getGLWidget()->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_mainGLWidget = mainGLDock->getGLWidget();
241
    m_mainGLWidgetScreenCapture = m_mainGLWidget->getScreenCapture( this );
242
    m_glDock->addDockWidget( Qt::RightDockWidgetArea, mainGLDock );
243
    addDockWidget( Qt::RightDockWidgetArea, m_mainGLWidgetScreenCapture );
244
    tabifyDockWidget( m_controlPanel->getRoiDock(), m_mainGLWidgetScreenCapture );
245
    connect( m_mainGLWidget.get(), SIGNAL( renderedFirstFrame() ), this, SLOT( handleGLVendor() ) );
246

247 248 249 250 251
    addDockWidget( Qt::RightDockWidgetArea, m_controlPanel );

    // by default, the module editor should be in front
    m_controlPanel->getModuleDock()->raise();

252 253
    // NOTE: we abuse the gl widgets first frame event to handle startup news.
    connect( m_mainGLWidget.get(), SIGNAL( renderedFirstFrame() ), this, SLOT( handleStartMessages() ) );
254
    connect( m_mainGLWidget.get(), SIGNAL( renderedFirstFrame() ), this, SLOT( closeSplash() ) );
255

256
    m_permanentToolBar = new WQtToolBar( "Standard Toolbar", this );
257
    addToolBar( Qt::TopToolBarArea, m_permanentToolBar );
258 259 260 261 262 263 264

    m_iconManager.addIcon( std::string( "ROI icon" ), box_xpm );
    m_iconManager.addIcon( std::string( "Reset icon" ), o_xpm );
    m_iconManager.addIcon( std::string( "axial icon" ), axial_xpm );
    m_iconManager.addIcon( std::string( "coronal icon" ), cor_xpm );
    m_iconManager.addIcon( std::string( "sagittal icon" ), sag_xpm );

265 266
    m_loadButton = new QAction( m_iconManager.getIcon( "load" ), "Load Dataset", m_permanentToolBar );
    m_loadButton->setShortcut( QKeySequence(  QKeySequence::Open ) );
267 268 269
    QAction* roiButton = new QAction( m_iconManager.getIcon( "ROI icon" ), "ROI", m_permanentToolBar );
    QAction* resetButton = new QAction( m_iconManager.getIcon( "view" ), "Reset", m_permanentToolBar );
    resetButton->setShortcut( QKeySequence( Qt::Key_Escape ) );
270 271
    QAction* projectLoadButton = new QAction( m_iconManager.getIcon( "loadProject" ), "Load Project", m_permanentToolBar );
    QAction* projectSaveButton = new QAction( m_iconManager.getIcon( "saveProject" ), "Save Project", m_permanentToolBar );
272
    projectLoadButton->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_O ) );
273 274 275 276 277 278 279

    connect( m_loadButton, SIGNAL(  triggered( bool ) ), this, SLOT( openLoadDialog() ) );
    connect( resetButton, SIGNAL(  triggered( bool ) ), m_mainGLWidget.get(), SLOT( reset() ) );
    connect( roiButton, SIGNAL(  triggered( bool ) ), this, SLOT( newRoi() ) );
    connect( projectLoadButton, SIGNAL(  triggered( bool ) ), this, SLOT( projectLoad() ) );
    connect( projectSaveButton, SIGNAL( triggered( bool ) ), this, SLOT( projectSaveAll() ) );

280
    m_loadButton->setToolTip( "Load a dataset from file" );
281
    resetButton->setToolTip( "Reset main view" );
282
    roiButton->setToolTip( "Create new ROI" );
283 284
    projectLoadButton->setToolTip( "Load a project from file" );
    projectSaveButton->setToolTip( "Save current project to file" );
285 286 287

    // we want the upper most tree item to be selected. This helps to make the always compatible modules
    // show up in the tool bar from the beginning. And ... it doesn't hurt.
288
    m_controlPanel->selectUpperMostEntry();
289

Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
290 291 292 293
    // NOTE: Please be aware that not every menu needs a shortcut key. If you add a shortcut, you should use one of the
    // QKeySequence::StandardKey defaults and avoid ambiguities like Ctrl-C for the configure dialog is not the best choice as Ctrl-C, for the
    // most users is the Copy shortcut.

294
    m_menuBar = new QMenuBar( this );
295 296

    // hide menu?
297 298 299
    m_menuBar->setVisible( hideMenuAction->get() );
    connect( hideMenuAction, SIGNAL( change( bool ) ), m_menuBar, SLOT( setVisible( bool ) ) );
    addAction( hideMenuAction );
300

301
    QMenu* fileMenu = m_menuBar->addMenu( "File" );
302

303
    fileMenu->addAction( m_loadButton );
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
304
    fileMenu->addSeparator();
305
    fileMenu->addAction( projectLoadButton );
306 307
    QMenu* saveMenu = fileMenu->addMenu( m_iconManager.getIcon( "saveProject" ), "Save Project" );
    saveMenu->addAction( "Save Project", this, SLOT( projectSaveAll() ), QKeySequence::Save );
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
308 309 310
    saveMenu->addAction( "Save Modules Only", this, SLOT( projectSaveModuleOnly() ) );
    saveMenu->addAction( "Save Camera Only", this, SLOT( projectSaveCameraOnly() ) );
    saveMenu->addAction( "Save ROIs Only", this, SLOT( projectSaveROIOnly() ) );
311 312
    projectSaveButton->setMenu( saveMenu );

313 314 315
    // TODO(all): If all distributions provide a newer QT version we should use QKeySequence::Quit here
    //fileMenu->addAction( m_iconManager.getIcon( "quit" ), "Quit", this, SLOT( close() ), QKeySequence( QKeySequence::Quit ) );
    fileMenu->addAction( m_iconManager.getIcon( "quit" ), "Quit", this, SLOT( close() ),  QKeySequence( Qt::CTRL + Qt::Key_Q ) );
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
316

Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
317
    // This QAction stuff is quite ugly and complicated some times ... There is no nice constructor which takes name, slot keysequence and so on
318 319
    // directly -> set shortcuts, and some further properties using QAction's interface
    QMenu* viewMenu = m_menuBar->addMenu( "View" );
320
    viewMenu->addAction( hideMenuAction );
321
    viewMenu->addSeparator();
322
    viewMenu->addAction( showNavWidgets );
323
    viewMenu->addAction( showNetworkEditor );
324 325 326 327
    viewMenu->addSeparator();
    viewMenu->addMenu( m_permanentToolBar->getStyleMenu() );

    // Camera menu
328 329 330
    QMenu* bgColorMenu = new QMenu( "Background Colors" );
    bgColorMenu->addAction( mainGLDock->getGLWidget()->getBackgroundColorAction() );

331
    QMenu* cameraMenu = m_menuBar->addMenu( "Camera" );
332 333
    cameraMenu->addAction( mainGLDock->getGLWidget()->getThrowingSetting() );
    cameraMenu->addMenu( bgColorMenu );
334 335 336
    cameraMenu->addSeparator();

    QMenu* settingsMenu = m_menuBar->addMenu( "Settings" );
337
    settingsMenu->addAction( m_autoDisplaySetting );
338
    settingsMenu->addAction( m_controlPanel->getModuleConfig().getConfigureAction() );
339
    settingsMenu->addSeparator();
340
    settingsMenu->addAction( mtViews );
341
    settingsMenu->addSeparator();
342
    settingsMenu->addMenu( logLevels );
343 344 345

    // a separate menu for some presets
    QMenu* cameraPresetMenu = cameraMenu->addMenu( "Presets" );
346

347 348 349 350 351
    QAction* controlPanelTrigger = m_controlPanel->toggleViewAction();
    QList< QKeySequence > controlPanelShortcut;
    controlPanelShortcut.append( QKeySequence( Qt::Key_F9 ) );
    controlPanelTrigger->setShortcuts( controlPanelShortcut );
    this->addAction( controlPanelTrigger );  // this enables the action even if the menu bar is invisible
352

Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
353 354 355
    // NOTE: the shortcuts for these view presets should be chosen carefully. Most keysequences have another meaning in the most applications
    // so the user may get confused. It is also not a good idea to take letters as they might be used by OpenSceneGraph widget ( like "S" for
    // statistics ).
356
    // By additionally adding the action to the main window, we ensure the action can be triggered even if the menu bar is hidden.
357
    QAction* tmpAction = cameraPresetMenu->addAction( m_iconManager.getIcon( "sagittal icon" ), "Left", this, SLOT( setPresetViewLeft() ),
358
                                             QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_L ) );
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
359
    tmpAction->setIconVisibleInMenu( true );
360 361
    this->addAction( tmpAction );

362 363
    tmpAction = cameraPresetMenu->addAction( m_iconManager.getIcon( "sagittal icon" ), "Right", this, SLOT( setPresetViewRight() ),
                                       QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_R ) );
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
364
    tmpAction->setIconVisibleInMenu( true );
365 366
    this->addAction( tmpAction );

367 368
    tmpAction = cameraPresetMenu->addAction( m_iconManager.getIcon( "axial icon" ), "Superior", this, SLOT( setPresetViewSuperior() ),
                                       QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_S ) );
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
369
    tmpAction->setIconVisibleInMenu( true );
370 371
    this->addAction( tmpAction );

372 373
    tmpAction = cameraPresetMenu->addAction( m_iconManager.getIcon( "axial icon" ), "Inferior", this, SLOT( setPresetViewInferior() ),
                                       QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_I ) );
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
374
    tmpAction->setIconVisibleInMenu( true );
375 376
    this->addAction( tmpAction );

377 378
    tmpAction = cameraPresetMenu->addAction( m_iconManager.getIcon( "coronal icon" ), "Anterior", this, SLOT( setPresetViewAnterior() ),
                                       QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_A ) );
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
379
    tmpAction->setIconVisibleInMenu( true );
380 381
    this->addAction( tmpAction );

382 383
    tmpAction = cameraPresetMenu->addAction( m_iconManager.getIcon( "coronal icon" ), "Posterior", this, SLOT( setPresetViewPosterior() ),
                                       QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_P ) );
Mathias Goldau's avatar
[MERGE]  
Mathias Goldau committed
384
    tmpAction->setIconVisibleInMenu( true );
385 386
    this->addAction( tmpAction );

387
    resetButton->setMenu( cameraPresetMenu );
388

389
    QMenu* helpMenu = m_menuBar->addMenu( "Help" );
390
    helpMenu->addAction( m_iconManager.getIcon( "help" ), "OpenWalnut Help", this, SLOT( openOpenWalnutHelpDialog() ),
391 392 393 394
                         QKeySequence( QKeySequence::HelpContents ) );
    helpMenu->addSeparator();
    helpMenu->addAction( m_iconManager.getIcon( "logo" ), "About OpenWalnut", this, SLOT( openAboutDialog() ) );
    helpMenu->addAction( "About Qt", this, SLOT( openAboutQtDialog() ) );
395

396 397
    setMenuBar( m_menuBar );

398 399
    // initially 3 navigation views
    {
400
        if( showNavWidgets->get() )
401
        {
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
402
            m_navAxial = boost::shared_ptr< WQtNavGLWidget >( new WQtNavGLWidget( "Axial View", "Axial View", this, "Axial Slice",
403
                                                                                  m_mainGLWidget.get() ) );
404
            m_navAxial->setFeatures( QDockWidget::AllDockWidgetFeatures );
405
            m_navAxial->setSliderProperty( WKernel::getRunningKernel()->getSelectionManager()->getPropAxialPos() );
406
            m_navAxial->getGLWidget()->setCameraManipulator( WQtGLWidget::NO_OP );
407

408
            m_glDock->addDockWidget( Qt::LeftDockWidgetArea, m_navAxial.get() );
409

410 411
            m_navCoronal = boost::shared_ptr< WQtNavGLWidget >( new WQtNavGLWidget( "Coronal View", "Coronal View", this, "Coronal Slice",
                                                                                    m_mainGLWidget.get() ) );
412
            m_navCoronal->setFeatures( QDockWidget::AllDockWidgetFeatures );
413
            m_navCoronal->setSliderProperty( WKernel::getRunningKernel()->getSelectionManager()->getPropCoronalPos() );
414
            m_navCoronal->getGLWidget()->setCameraManipulator( WQtGLWidget::NO_OP );
415

416
            m_glDock->addDockWidget( Qt::LeftDockWidgetArea, m_navCoronal.get() );
417

ledig's avatar
ledig committed
418
            m_navSagittal =
419 420
                boost::shared_ptr< WQtNavGLWidget >( new WQtNavGLWidget( "Sagittal View", "Sagittal View", this, "Sagittal Slice",
                                                                         m_mainGLWidget.get() ) );
421
            m_navSagittal->setFeatures( QDockWidget::AllDockWidgetFeatures );
422
            m_navSagittal->setSliderProperty( WKernel::getRunningKernel()->getSelectionManager()->getPropSagittalPos() );
423
            m_navSagittal->getGLWidget()->setCameraManipulator( WQtGLWidget::NO_OP );
424

425
            m_glDock->addDockWidget( Qt::LeftDockWidgetArea, m_navSagittal.get() );
426

427 428 429
            bgColorMenu->addAction( m_navAxial->getGLWidget()->getBackgroundColorAction() );
            bgColorMenu->addAction( m_navCoronal->getGLWidget()->getBackgroundColorAction() );
            bgColorMenu->addAction( m_navSagittal->getGLWidget()->getBackgroundColorAction() );
430 431 432
        }
    }

433 434 435
    // create the show/hide actions using the selection manager's props
    WQtPropertyBoolAction* showAxial = new WQtPropertyBoolAction( WKernel::getRunningKernel()->getSelectionManager()->getPropAxialShow(),
                                                                  m_permanentToolBar );
436
    showAxial->setToolTip( "Toggle axial slice" );
437 438 439 440 441
    showAxial->setText( "Toggle Axial Slice" );
    showAxial->setIcon( m_iconManager.getIcon( "axial icon" ) );

    WQtPropertyBoolAction* showCoronal = new WQtPropertyBoolAction( WKernel::getRunningKernel()->getSelectionManager()->getPropCoronalShow(),
                                                                    m_permanentToolBar );
442
    showCoronal->setToolTip( "Toggle coronal slice" );
443 444 445 446 447
    showCoronal->setText( "Toggle Coronal Slice" );
    showCoronal->setIcon( m_iconManager.getIcon( "coronal icon" ) );

    WQtPropertyBoolAction* showSagittal = new WQtPropertyBoolAction( WKernel::getRunningKernel()->getSelectionManager()->getPropSagittalShow(),
                                                                     m_permanentToolBar );
448
    showSagittal->setToolTip( "Toggle sagittal slice" );
449 450 451
    showSagittal->setText( "Toggle Sagittal Slice" );
    showSagittal->setIcon( m_iconManager.getIcon( "sagittal icon" ) );

452
    // Temporarily disabled. We need a proper command prompt implementation first.
453
    // create command prompt toolbar
454 455 456
    // m_commandPrompt = new WQtCommandPromptToolbar( "Command Prompt", this );
    // addToolBar( Qt::TopToolBarArea, m_commandPrompt );
    // this->addAction( m_commandPrompt->toggleViewAction() );  // this enables the action even if the menu bar is invisible
457

458
    // setup permanent toolbar
459
    m_permanentToolBar->addAction( m_loadButton );
460
    m_permanentToolBar->addSeparator();
461 462
    m_permanentToolBar->addAction( projectLoadButton );
    m_permanentToolBar->addAction( projectSaveButton );
463
    m_permanentToolBar->addSeparator();
464 465
    m_permanentToolBar->addAction( m_mainGLWidgetScreenCapture->getScreenshotTrigger() );
    m_permanentToolBar->addSeparator();
466 467
    m_permanentToolBar->addAction( resetButton );
    m_permanentToolBar->addAction( roiButton );
468
    m_permanentToolBar->addSeparator();
469 470 471 472
    m_permanentToolBar->addAction( showAxial );
    m_permanentToolBar->addAction( showCoronal );
    m_permanentToolBar->addAction( showSagittal );
    m_permanentToolBar->addSeparator();
473

474 475
    // after creating the GUI, restore its saved state
    restoreSavedState();
476
}
477

478
void WMainWindow::autoAdd( boost::shared_ptr< WModule > module, std::string proto, bool onlyOnce )
479
{
480 481 482 483 484 485
    // if only one module should be added, and there already is one --- skip.
    if( onlyOnce && !WKernel::getRunningKernel()->getRootContainer()->getModules( proto ).empty() )
    {
        return;
    }

486
    // get the prototype.
Alexander Wiebel's avatar
Alexander Wiebel committed
487
    if( !WKernel::getRunningKernel()->getRootContainer()->applyModule( module, proto, true ) )
488 489 490 491 492 493
    {
        WLogger::getLogger()->addLogMessage( "Auto Display active but module " + proto + " could not be added.",
                                             "GUI", LL_ERROR );
    }
}

494
void WMainWindow::moduleSpecificCleanup( boost::shared_ptr< WModule > /* module */ )
495
{
496
    // called for each removed module. Use this to undo modifications done due to added modules (moduleSpecificSetup)
497 498
}

499 500
void WMainWindow::moduleSpecificSetup( boost::shared_ptr< WModule > module )
{
501 502 503 504
    // Add all special handlings here. This method is called whenever a module is marked "ready". You can set up the gui for special modules,
    // load certain modules for datasets and so on.

    // The Data Modules also play an special role. To have modules being activated when certain data got loaded, we need to hook it up here.
505
    bool useAutoDisplay = m_autoDisplaySetting->get();
Alexander Wiebel's avatar
Alexander Wiebel committed
506
    if( useAutoDisplay && module->getType() == MODULE_DATA )
507 508 509 510 511 512
    {
        WLogger::getLogger()->addLogMessage( "Auto Display active and Data module added. The proper module will be added.",
                                             "GUI", LL_DEBUG );

        // data modules contain an member denoting the real data type. Currently we only have one data module and a not very modulated data
        // structures.
513
        boost::shared_ptr< WDataModule > dataModule = boost::shared_static_cast< WDataModule >( module );
514 515

        // grab data and identify type
Alexander Wiebel's avatar
Alexander Wiebel committed
516
        if( dataModule->getDataSet()->isA< WDataSetSingle >() && dataModule->getDataSet()->isTexture() )
517 518 519
        {
            // it is a dataset single
            // load a nav slice module if a WDataSetSingle is available!?
520
            autoAdd( module, "Navigation Slices", true );
521
        }
Alexander Wiebel's avatar
Alexander Wiebel committed
522
        else if( dataModule->getDataSet()->isA< WDataSetFibers >() )
523 524
        {
            // it is a fiber dataset -> add the FiberDisplay module
525
            autoAdd( module, "Fiber Display" );
526
        }
Alexander Wiebel's avatar
Alexander Wiebel committed
527
        else if( dataModule->getDataSet()->isA< WEEG2 >() )
528
        {
529
            // it is a eeg dataset -> add the eegView module
530 531 532
            autoAdd( module, "EEG View" );
        }
    }
wiebel's avatar
wiebel committed
533
}
534

535 536
void WMainWindow::setCompatiblesToolbar( WQtCombinerToolbar* toolbar )
{
Alexander Wiebel's avatar
Alexander Wiebel committed
537
    if( m_currentCompatiblesToolbar )
538 539 540 541 542
    {
        delete m_currentCompatiblesToolbar;
    }
    m_currentCompatiblesToolbar = toolbar;

Alexander Wiebel's avatar
Alexander Wiebel committed
543
    if( !toolbar )
544 545 546
    {
        // ok, reset the toolbar
        // So create a dummy to permanently reserve the space
547
        m_currentCompatiblesToolbar = new WQtCombinerToolbar( this );
548 549
    }

550 551 552 553 554
    // we want to keep the tool-button styles in sync
    m_currentCompatiblesToolbar->setToolButtonStyle( m_permanentToolBar->toolButtonStyle() );
    connect( m_permanentToolBar, SIGNAL( toolButtonStyleChanged( Qt::ToolButtonStyle ) ),
             m_currentCompatiblesToolbar, SLOT( setToolButtonStyle( Qt::ToolButtonStyle ) ) );

555
    // and the position of the toolbar
556
    addToolBar( Qt::TopToolBarArea, m_currentCompatiblesToolbar );
557
}
558

559 560 561 562 563
WQtCombinerToolbar* WMainWindow::getCompatiblesToolbar()
{
    return m_currentCompatiblesToolbar;
}

564
WQtControlPanel* WMainWindow::getControlPanel()
565
{
566
    return m_controlPanel;
567
}
568

569 570 571 572 573
WQtNetworkEditor* WMainWindow::getNetworkEditor()
{
    return m_networkEditor;
}

574
bool WMainWindow::projectSave( const std::vector< boost::shared_ptr< WProjectFileIO > >& writer )
575 576 577 578
{
    QFileDialog fd;
    fd.setWindowTitle( "Save Project as" );
    fd.setFileMode( QFileDialog::AnyFile );
579
    fd.setAcceptMode( QFileDialog::AcceptSave );
580

581 582
    // My Mac OSX Lion automatically appends .owproj to the file name
    // if no extension is given.
583
    QStringList filters;
584
    filters << "Project File (*.owproj *.owp)";
585 586
    fd.setNameFilters( filters );
    fd.setViewMode( QFileDialog::Detail );
587
    QStringList filenames;
Alexander Wiebel's avatar
Alexander Wiebel committed
588
    if( fd.exec() )
589
    {
590
        filenames = fd.selectedFiles();
591
    }
592 593 594 595
    else
    {
        return false; // the user canceled, no files, so nothing saved
    }
596

597
    bool success = true;
598
    QStringList::const_iterator constIterator;
599
    for( constIterator = filenames.constBegin(); constIterator != filenames.constEnd(); ++constIterator )
600
    {
601
        std::string filename = ( *constIterator ).toStdString();
602

603
        // append owp if suffix is not present, yet
604 605
        if( filename.rfind( ".owp" ) != filename.size() - 4
         && filename.rfind( ".owproj" ) != filename.size() - 7 )
606 607 608 609
        {
            filename += ".owp";
        }

610
        boost::shared_ptr< WProjectFile > proj = boost::shared_ptr< WProjectFile >(
611
                new WProjectFile( filename )
612 613
        );

614 615 616
        try
        {
            // This call is synchronous.
Alexander Wiebel's avatar
Alexander Wiebel committed
617
            if( writer.empty() )
618 619 620 621 622 623 624
            {
                proj->save();
            }
            else
            {
                proj->save( writer );
            }
625 626 627 628 629 630 631
        }
        catch( const std::exception& e )
        {
            QString title = "Problem while saving project file.";
            QString message = "<b>Problem while saving project file.</b><br/><br/><b>File:  </b>" + ( *constIterator ) +
                              "<br/><b>Message:  </b>" + QString::fromStdString( e.what() );
            QMessageBox::critical( this, title, message );
632
            success = false;
633
        }
634
    }
635
    return success;
636 637
}

638
bool WMainWindow::projectSaveAll()
639 640 641
{
    std::vector< boost::shared_ptr< WProjectFileIO > > w;
    // an empty list equals "all"
642
    return projectSave( w );
643 644
}

645
bool WMainWindow::projectSaveCameraOnly()
646 647 648
{
    std::vector< boost::shared_ptr< WProjectFileIO > > w;
    w.push_back( WProjectFile::getCameraWriter() );
649
    return projectSave( w );
650 651
}

652
bool WMainWindow::projectSaveROIOnly()
653 654 655
{
    std::vector< boost::shared_ptr< WProjectFileIO > > w;
    w.push_back( WProjectFile::getROIWriter() );
656
    return projectSave( w );
657 658
}

659
bool WMainWindow::projectSaveModuleOnly()
660 661 662
{
    std::vector< boost::shared_ptr< WProjectFileIO > > w;
    w.push_back( WProjectFile::getModuleWriter() );
663
    return projectSave( w );
664 665
}

666 667 668 669 670 671
void WMainWindow::projectLoad()
{
    QFileDialog fd;
    fd.setFileMode( QFileDialog::ExistingFiles );

    QStringList filters;
672
    filters << "Simple Project File (*.owproj *.owp)"
673 674 675
            << "Any files (*)";
    fd.setNameFilters( filters );
    fd.setViewMode( QFileDialog::Detail );
676
    QStringList filenames;
Alexander Wiebel's avatar
Alexander Wiebel committed
677
    if( fd.exec() )
678
    {
679
        filenames = fd.selectedFiles();
680 681 682
    }

    QStringList::const_iterator constIterator;
683
    for( constIterator = filenames.constBegin(); constIterator != filenames.constEnd(); ++constIterator )
684
    {
685 686
        boost::shared_ptr< WProjectFile > proj = boost::shared_ptr< WProjectFile >(
                new WProjectFile( ( *constIterator ).toStdString() )
687
        );
688 689

        // This call is asynchronous. It parses the file and the starts a thread to actually do all the stuff
690
        proj->load();
691 692 693
    }
}

694
void WMainWindow::openLoadDialog()
695
{
696 697
    QFileDialog fd;
    fd.setFileMode( QFileDialog::ExistingFiles );
wiebel's avatar
wiebel committed
698 699

    QStringList filters;
700 701
    filters << "Known file types (*.cnt *.edf *.asc *.nii *.nii.gz *.fib)"
            << "EEG files (*.cnt *.edf *.asc)"
wiebel's avatar
wiebel committed
702
            << "NIfTI (*.nii *.nii.gz)"
703 704
            << "Fibers (*.fib)"
            << "Any files (*)";
wiebel's avatar
wiebel committed
705
    fd.setNameFilters( filters );
706
    fd.setViewMode( QFileDialog::Detail );
707
    QStringList filenames;
Alexander Wiebel's avatar
Alexander Wiebel committed
708
    if( fd.exec() )
709
    {
710
        filenames = fd.selectedFiles();
711 712
    }

713
    std::vector< std::string > stdFilenames;