WMainWindow.cpp 9.1 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>
26 27
#include <string>
#include <vector>
28

29 30
#include <boost/thread.hpp>

31
#include <QtGui/QApplication>
32
#include <QtGui/QMainWindow>
wiebel's avatar
wiebel committed
33
#include <QtGui/QDockWidget>
34
#include <QtGui/QFileDialog>
35
#include <QtGui/QSlider>
36
#include <QtGui/QShortcut>
37 38
#include <QtGui/QVBoxLayout>

39 40
#include "WMainWindow.h"
#include "WQtGLWidget.h"
41
#include "../../kernel/WKernel.h"
ebaum's avatar
ebaum committed
42

43
#include "WQtNavGLWidget.h"
wiebel's avatar
wiebel committed
44

45
#include "../icons/WIcons.h"
46

47
WMainWindow::WMainWindow( boost::program_options::variables_map guiConfiguration ) :
48
    QMainWindow(),
49 50
    m_iconManager(),
    m_propertyManager()
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
51
{
52
    setupGUI( guiConfiguration );
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
53
}
54

55
WMainWindow::~WMainWindow()
56 57 58 59
{
}


60
void WMainWindow::setupGUI( boost::program_options::variables_map guiConfiguration )
61
{
62
    m_iconManager.addIcon( std::string( "logo" ), logoIcon_xpm );
63

64
    if( objectName().isEmpty() )
65
    {
66
        setObjectName( QString::fromUtf8( "MainWindow" ) );
67
    }
68 69 70
    resize( 946, 632 );
    setWindowIcon( m_iconManager.getIcon( "logo" ) );
    setWindowTitle( QApplication::translate( "MainWindow", "OpenWalnut", 0, QApplication::UnicodeUTF8 ) );
71

72
    m_centralwidget = new QWidget( this );
73
    m_centralwidget->setObjectName( QString::fromUtf8( "centralwidget" ) );
74
    setCentralWidget( m_centralwidget );
75

76
    m_mainGLWidget = boost::shared_ptr< WQtGLWidget >( new WQtGLWidget( "main", this, WGECamera::ORTHOGRAPHIC ) );
77 78
    m_mainGLWidget->initialize();
    setCentralWidget( m_mainGLWidget.get() );
wiebel's avatar
wiebel committed
79

80 81 82 83 84 85 86 87 88 89 90 91 92 93
    // initially 3 views
    m_navAxial = boost::shared_ptr< WQtNavGLWidget >( new WQtNavGLWidget( "axial", this, 160, "axialPos" ) );
    addDockWidget( Qt::LeftDockWidgetArea, m_navAxial.get() );

    m_navCoronal = boost::shared_ptr< WQtNavGLWidget >( new WQtNavGLWidget( "coronal", this, 200, "coronalPos" ) );
    addDockWidget( Qt::LeftDockWidgetArea, m_navCoronal.get() );

    m_navSagittal = boost::shared_ptr< WQtNavGLWidget >( new WQtNavGLWidget( "sagittal", this, 160, "sagittalPos" ) );
    addDockWidget( Qt::LeftDockWidgetArea, m_navSagittal.get() );

    connect( m_navAxial.get(), SIGNAL( navSliderValueChanged( QString, int ) ), &m_propertyManager, SLOT( slotIntChanged( QString, int ) ) );
    connect( m_navCoronal.get(), SIGNAL( navSliderValueChanged( QString, int ) ), &m_propertyManager, SLOT( slotIntChanged( QString, int ) ) );
    connect( m_navSagittal.get(), SIGNAL( navSliderValueChanged( QString, int ) ), &m_propertyManager, SLOT( slotIntChanged( QString, int ) ) );

94 95 96 97 98 99
    if( guiConfiguration.count( "ge.bgColor.r" ) && guiConfiguration.count( "ge.bgColor.g" ) && guiConfiguration.count( "ge.bgColor.b" ) )
    {
        WColor bgColor( guiConfiguration["ge.bgColor.r"].as< float >(),
                        guiConfiguration["ge.bgColor.g"].as< float >(),
                        guiConfiguration["ge.bgColor.b"].as< float >() );
        m_mainGLWidget->setBgColor( bgColor );
100 101 102
        m_navAxial->getGLWidget()->setBgColor( bgColor );
        m_navCoronal->getGLWidget()->setBgColor( bgColor );
        m_navSagittal->getGLWidget()->setBgColor( bgColor );
103 104
    }

105
    m_datasetBrowser = new WQtDatasetBrowser();
106
    addDockWidget( Qt::RightDockWidgetArea, m_datasetBrowser );
107
    m_datasetBrowser->addSubject( "subject1" );
108

109
    connect( m_datasetBrowser, SIGNAL( dataSetBrowserEvent( QString, bool ) ), &m_propertyManager, SLOT( slotBoolChanged( QString, bool ) ) );
110

111
    setupToolBar();
112
}
113

114
void WMainWindow::setupToolBar()
115
{
116
    m_toolBar = new WQtRibbonMenu( this );
117

118 119 120
    m_iconManager.addIcon( std::string( "quit" ), quit_xpm );
    m_iconManager.addIcon( std::string( "save" ), disc_xpm );
    m_iconManager.addIcon( std::string( "load" ), fileopen_xpm );
121 122

    m_toolBar->addTab( QString( "File" ) );
123 124 125
    m_toolBar->addPushButton( QString( "buttonLoad" ), QString( "File" ), m_iconManager.getIcon( "load" ), QString( "Load" ) );
    m_toolBar->addPushButton( QString( "buttonSave" ), QString( "File" ), m_iconManager.getIcon( "save" ), QString( "Save" ) );
    m_toolBar->addPushButton( QString( "buttonQuit" ), QString( "File" ), m_iconManager.getIcon( "quit" ), QString( "Exit" ) );
126

127 128 129 130
    // the parent (this) will take care for deleting the shortcut
    QShortcut* shortcut = new QShortcut( QKeySequence( tr( "Ctrl+Q", "File|Exit" ) ), this );
    connect( shortcut, SIGNAL( activated() ), this, SLOT( close() ) );

131
    connect( m_toolBar->getButton( QString( "buttonQuit" ) ), SIGNAL( pressed() ), this, SLOT( close() ) );
132 133 134 135 136
    connect( m_toolBar->getButton( QString( "buttonLoad" ) ), SIGNAL( pressed() ), this, SLOT( openLoadDialog() ) );

    m_toolBar->addTab( QString( "Modules" ) );
    m_toolBar->addTab( QString( "Help" ) );

137 138 139
    m_iconManager.addIcon( std::string( "axial" ), axial_xpm );
    m_iconManager.addIcon( std::string( "coronal" ), cor_xpm );
    m_iconManager.addIcon( std::string( "sagittal" ), sag_xpm );
140

141 142 143
    m_toolBar->addPushButton( QString( "showAxial" ), QString( "Modules" ), m_iconManager.getIcon( "axial" ) );
    m_toolBar->addPushButton( QString( "showCoronal" ), QString( "Modules" ), m_iconManager.getIcon( "coronal" ) );
    m_toolBar->addPushButton( QString( "showSagittal" ), QString( "Modules" ), m_iconManager.getIcon( "sagittal" ) );
144 145 146 147 148 149 150 151 152 153 154 155 156 157

    m_toolBar->getButton( QString( "showAxial" ) )->setMaximumSize( 24, 24 );
    m_toolBar->getButton( QString( "showCoronal" ) )->setMaximumSize( 24, 24 );
    m_toolBar->getButton( QString( "showSagittal" ) )->setMaximumSize( 24, 24 );

    m_toolBar->getButton( QString( "showAxial" ) )->setCheckable( true );
    m_toolBar->getButton( QString( "showCoronal" ) )->setCheckable( true );
    m_toolBar->getButton( QString( "showSagittal" ) )->setCheckable( true );

    m_toolBar->getButton( QString( "showAxial" ) )->setChecked( true );
    m_toolBar->getButton( QString( "showCoronal" ) )->setChecked( true );
    m_toolBar->getButton( QString( "showSagittal" ) )->setChecked( true );

    connect( m_toolBar->getButton( QString( "showAxial" ) ),
158
            SIGNAL( pushButtonToggled( QString, bool ) ), &m_propertyManager, SLOT( slotBoolChanged( QString, bool ) ) );
159
    connect( m_toolBar->getButton( QString( "showCoronal" ) ),
160
            SIGNAL( pushButtonToggled( QString, bool ) ), &m_propertyManager, SLOT( slotBoolChanged( QString, bool ) ) );
161
    connect( m_toolBar->getButton( QString( "showSagittal" ) ),
162
            SIGNAL( pushButtonToggled( QString, bool ) ), &m_propertyManager, SLOT( slotBoolChanged( QString, bool ) ) );
163

164
    addToolBar( Qt::TopToolBarArea, m_toolBar );
wiebel's avatar
wiebel committed
165
}
166

167

168
WQtDatasetBrowser* WMainWindow::getDatasetBrowser()
169
{
170
    return m_datasetBrowser;
171
}
172

173 174 175 176
WQtRibbonMenu* WMainWindow::getToolBar()
{
    return m_toolBar;
}
177

178
void WMainWindow::openLoadDialog()
179
{
180 181
    QFileDialog fd;
    fd.setFileMode( QFileDialog::ExistingFiles );
wiebel's avatar
wiebel committed
182 183 184 185 186 187 188

    QStringList filters;
    filters << "Any files (*)"
            << "EEG files (*.cnt *.edf)"
            << "NIfTI (*.nii *.nii.gz)"
            << "VTK (*.vtk)";
    fd.setNameFilters( filters );
189 190 191 192 193 194 195 196 197 198 199 200 201 202
    fd.setViewMode( QFileDialog::Detail );
    QStringList fileNames;
    if ( fd.exec() )
    {
        fileNames = fd.selectedFiles();
    }

    std::vector< std::string >stdFileNames;

    QStringList::const_iterator constIterator;
    for ( constIterator = fileNames.constBegin(); constIterator != fileNames.constEnd(); ++constIterator )
    {
        stdFileNames.push_back( ( *constIterator ).toLocal8Bit().constData() );
    }
203 204
    m_loaderSignal( stdFileNames );
}
205

206 207 208 209 210
boost::signal1< void, std::vector< std::string > >* WMainWindow::getLoaderSignal()
{
    return &m_loaderSignal;
}

211
WPropertyManager*  WMainWindow::getPropertyManager()
212
{
213 214 215 216 217 218
    return &m_propertyManager;
}

WIconManager*  WMainWindow::getIconManager()
{
    return &m_iconManager;
219
}
220 221 222 223 224 225 226 227 228 229

void WMainWindow::closeEvent( QCloseEvent* e )
{
    // use some "Really Close?" Dialog here
    bool reallyClose = true;


    // handle close event
    if ( reallyClose )
    {
230 231
        // signal everybody to shut down properly.
        WKernel::getRunningKernel()->finalize();
232 233 234 235

        // now nobody acesses the osg anymore
        // clean up gl widgets
        m_mainGLWidget->close();
236

237 238 239
        m_navAxial->close();
        m_navCoronal->close();
        m_navSagittal->close();
240 241 242 243 244 245 246 247 248 249

        // finally close
        e->accept();
    }
    else
    {
        e->ignore();
    }
}