Commit 5d73cabc authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - now most settings use the new WSettingAction class which provides easy...

[ADD] - now most settings use the new WSettingAction class which provides easy to use QActions for each binary setting.
parent 45025ee2
......@@ -142,7 +142,7 @@ std::vector< boost::filesystem::path > WPathHelper::getAllModulePaths()
paths.push_back( getModulePath() );
// the environment variable stores the additional paths
std::string additionalPaths( getenv( "OW_MODULE_PATH" ) );
std::string additionalPaths( getenv( "OW_MODULE_PATH" ) ? getenv( "OW_MODULE_PATH" ) : "" );
// separate list of additional paths:
typedef boost::tokenizer< boost::char_separator< char > > tokenizer;
......
......@@ -76,6 +76,7 @@
#include "WQtNavGLWidget.h"
#include "WQtGLDockWidget.h"
#include "WQt4Gui.h"
#include "WSettingAction.h"
#include "WMainWindow.h"
#include "WMainWindow.moc"
......@@ -95,6 +96,43 @@ WMainWindow::~WMainWindow()
void WMainWindow::setupGUI()
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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
);
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",
"Multi-threaded Views",
"If enabled, the graphic windows are rendered in different threads. This can speed-up "
"rendering on machines with multiple cores.",
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() );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// GUI setup
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
m_iconManager.addIcon( std::string( "load" ), fileopen_xpm );
m_iconManager.addIcon( std::string( "loadProject" ), projOpen_xpm );
m_iconManager.addIcon( std::string( "saveProject" ), projSave_xpm );
......@@ -187,8 +225,9 @@ void WMainWindow::setupGUI()
m_menuBar = new QMenuBar( this );
// hide menu?
bool hideMenu = WQt4Gui::getSettings().value( "qt4gui/hideMenu", false ).toBool();
m_menuBar->setVisible( !hideMenu );
m_menuBar->setVisible( hideMenuAction->get() );
connect( hideMenuAction, SIGNAL( change( bool ) ), m_menuBar, SLOT( setVisible( bool ) ) );
addAction( hideMenuAction );
QMenu* fileMenu = m_menuBar->addMenu( "File" );
......@@ -209,21 +248,25 @@ void WMainWindow::setupGUI()
// This QAction stuff is quite ugly and complicated some times ... There is no nice constructor which takes name, slot keysequence and so on
// directly -> set shortcuts, and some further properties using QAction's interface
QMenu* viewMenu = m_menuBar->addMenu( "View" );
viewMenu->addAction( "Show Menubar", this, SLOT( showMenuBar() ), QKeySequence( Qt::CTRL + Qt::Key_M ) );
viewMenu->addAction( "Show Statusbar", this, SLOT( showStatusBar() ) );
viewMenu->addAction( hideMenuAction );
viewMenu->addSeparator();
viewMenu->addAction( "Show Navigation Views", this, SLOT( showNavViews() ) );
viewMenu->addAction( showNavWidgets );
viewMenu->addSeparator();
viewMenu->addMenu( m_permanentToolBar->getStyleMenu() );
// Camera menu
QMenu* bgColorMenu = new QMenu( "Background Colors" );
bgColorMenu->addAction( mainGLDock->getGLWidget()->getBackgroundColorAction() );
QMenu* cameraMenu = m_menuBar->addMenu( "Camera" );
cameraMenu->addAction( "Set Background Color", this, SLOT( setBGColor() ) );
cameraMenu->addAction( "Allow Camera Throwing", this, SLOT( setAllowThrow() ) );
cameraMenu->addAction( mainGLDock->getGLWidget()->getThrowingSetting() );
cameraMenu->addMenu( bgColorMenu );
cameraMenu->addSeparator();
QMenu* settingsMenu = m_menuBar->addMenu( "Settings" );
settingsMenu->addAction( "Enable Auto-Display", this, SLOT( setAutoDisplay() ) );
settingsMenu->addAction( m_autoDisplaySetting );
settingsMenu->addAction( mtViews );
settingsMenu->addAction( "Log Level", this, SLOT( setLogLevel() ) );
// a separate menu for some presets
QMenu* cameraPresetMenu = cameraMenu->addMenu( "Presets" );
......@@ -281,8 +324,7 @@ void WMainWindow::setupGUI()
// initially 3 navigation views
{
bool hideNavWidget = WQt4Gui::getSettings().value( "qt4gui/hideNavigationWidgets", false ).toBool();
if( !hideNavWidget )
if( showNavWidgets->get() )
{
m_navAxial = boost::shared_ptr< WQtNavGLWidget >( new WQtNavGLWidget( "Axial View", "Axial View", this, "Axial Slice",
m_mainGLWidget.get() ) );
......@@ -299,6 +341,10 @@ void WMainWindow::setupGUI()
m_mainGLWidget.get() ) );
m_navSagittal->setFeatures( QDockWidget::AllDockWidgetFeatures );
m_glDock->addDockWidget( Qt::LeftDockWidgetArea, m_navSagittal.get() );
bgColorMenu->addAction( m_navAxial->getGLWidget()->getBackgroundColorAction() );
bgColorMenu->addAction( m_navCoronal->getGLWidget()->getBackgroundColorAction() );
bgColorMenu->addAction( m_navSagittal->getGLWidget()->getBackgroundColorAction() );
}
}
......@@ -378,7 +424,7 @@ void WMainWindow::moduleSpecificSetup( boost::shared_ptr< WModule > module )
// 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.
bool useAutoDisplay = WQt4Gui::getSettings().value( "qt4gui/useAutoDisplay", true ).toBool();
bool useAutoDisplay = m_autoDisplaySetting->get();
if( useAutoDisplay && module->getType() == MODULE_DATA )
{
WLogger::getLogger()->addLogMessage( "Auto Display active and Data module added. The proper module will be added.",
......
......@@ -40,6 +40,7 @@
#include "WIconManager.h"
#include "WQtToolBar.h"
#include "WQtGLWidget.h"
#include "WSettingAction.h"
#include "networkEditor/WQtNetworkEditor.h"
#include "commandPrompt/WQtCommandPromptToolbar.h"
......@@ -336,6 +337,11 @@ private:
* Saves the current window states and geometries to a file.
*/
void saveWindowState();
/**
* The action controlling the auto-display feature.
*/
WSettingAction* m_autoDisplaySetting;
};
#endif // WMAINWINDOW_H
......@@ -167,10 +167,6 @@ int WQt4Gui::run()
// startup graphics engine
m_ge = WGraphicsEngine::getGraphicsEngine();
// enable multithreading if wanted
bool multiThreadedViewers = WQt4Gui::getSettings().value( "qt4gui/ge/multiThreadedViewer", false ).toBool();
m_ge->setMultiThreadedViews( multiThreadedViewers );
// and startup kernel
m_kernel = boost::shared_ptr< WKernel >( WKernel::instance( m_ge, shared_from_this() ) );
m_kernel->run();
......
......@@ -26,6 +26,7 @@
#include <iostream>
#include <QtGui/QKeyEvent>
#include <QtGui/QColorDialog>
#include "WQtGLWidget.h"
#include "WQtGLWidget.moc"
......@@ -40,6 +41,7 @@
#include "core/graphicsEngine/WGraphicsEngine.h"
#include "core/kernel/WKernel.h"
#include "WSettingAction.h"
#include "WMainWindow.h"
#ifndef __APPLE__
......@@ -92,18 +94,19 @@ WQtGLWidget::WQtGLWidget( std::string nameOfViewer, QWidget* parent, WGECamera::
#endif
// set bg color
double bgR = WMainWindow::getSettings().value( "qt4gui/glBGColor/r", 1.0 ).toDouble();
double bgG = WMainWindow::getSettings().value( "qt4gui/glBGColor/g", 1.0 ).toDouble();
double bgB = WMainWindow::getSettings().value( "qt4gui/glBGColor/b", 1.0 ).toDouble();
m_Viewer->setBgColor( WColor( bgR, bgG, bgB, 1.0 ) );
updateViewerBackground();
// this action manages the above settings
m_changeBGColorAction = new QAction( QString::fromStdString( nameOfViewer ), parent );
connect( m_changeBGColorAction, SIGNAL( triggered( bool ) ), this, SLOT( changeBGColor() ) );
// enable throwing of wanted
bool allowThrow = WMainWindow::getSettings().value( "qt4gui/ge/allowThrow", false ).toBool();
WGEZoomTrackballManipulator* manipulator = dynamic_cast< WGEZoomTrackballManipulator* >( m_Viewer->getCameraManipulator().get() );
if( manipulator )
{
manipulator->setThrow( allowThrow );
}
m_allowThrowSetting = new WSettingAction( parent, std::string( "qt4gui/" ) + nameOfViewer + std::string( "/allowThrow" ),
"Camera Throwing",
"If enabled, the camera can be thrown. Try it by dragging the camera. The camera then continues "
"the movement.",
false );
connect( m_allowThrowSetting, SIGNAL( change( bool ) ), this, SLOT( updateThrowing() ) );
updateThrowing();
}
WQtGLWidget::~WQtGLWidget()
......@@ -310,3 +313,39 @@ const QGLFormat WQtGLWidget::getDefaultFormat()
return format;
}
void WQtGLWidget::updateThrowing()
{
WGEZoomTrackballManipulator* manipulator = dynamic_cast< WGEZoomTrackballManipulator* >( m_Viewer->getCameraManipulator().get() );
if( manipulator )
{
manipulator->setThrow( m_allowThrowSetting->get() );
}
}
WSettingAction* WQtGLWidget::getThrowingSetting() const
{
return m_allowThrowSetting;
}
QAction* WQtGLWidget::getBackgroundColorAction() const
{
return m_changeBGColorAction;
}
void WQtGLWidget::updateViewerBackground()
{
QColor bg = WMainWindow::getSettings().value( QString( "qt4gui/" ) + QString::fromStdString( m_nameOfViewer ) + QString( "/BGColor" ),
QColor( 255, 255, 255, 255 ) ).value< QColor >();
m_Viewer->setBgColor( WColor( bg.redF(), bg.greenF(), bg.blueF(), 1.0 ) );
}
void WQtGLWidget::changeBGColor()
{
QColor bgOld = WMainWindow::getSettings().value( QString( "qt4gui/" ) + QString::fromStdString( m_nameOfViewer ) + QString( "/BGColor" ),
QColor( 255, 255, 255, 255 ) ).value< QColor >();
QColor bg = QColorDialog::getColor( bgOld, this );
WMainWindow::getSettings().setValue( QString( "qt4gui/" ) + QString::fromStdString( m_nameOfViewer ) + QString( "/BGColor" ), bg );
updateViewerBackground();
}
......@@ -39,6 +39,8 @@
#include "core/graphicsEngine/WGECamera.h"
#include "core/graphicsEngine/WGEViewer.h"
class WSettingAction;
/**
* A widget containing an open gl display area. This initializes OpenGL context and adds a view to the
* engine.
......@@ -115,6 +117,20 @@ public:
*/
static const QGLFormat getDefaultFormat();
/**
* Returns the setting for throwing.
*
* \return the setting
*/
WSettingAction* getThrowingSetting() const;
/**
* Returns the action used to configure the background color of this widget.
*
* \return the action.
*/
QAction* getBackgroundColorAction() const;
public slots:
/**
* Resets the contained view using the installed manipulator.
......@@ -243,6 +259,32 @@ private:
* This flag is set to true if the first paint call occured. See the paint method for details.
*/
bool m_firstPaint;
/**
* The setting specifying whether the viewer's camera can be thrown.
*/
WSettingAction* m_allowThrowSetting;
/**
* Action to trigger some colordialog for background-color-selection.
*/
QAction* m_changeBGColorAction;
private slots:
/**
* Function to handle updates in the setting \ref m_allowThrowSetting.
*/
void updateThrowing();
/**
* Asks user for a new color for this widget.
*/
void changeBGColor();
/**
* Updates the color of this widget according to the current settings.
*/
void updateViewerBackground();
};
#endif // WQTGLWIDGET_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// 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.
//
// OpenWalnut is distributed in the hope that it will be useful,
// 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
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WMainWindow.h"
#include "WSettingAction.h"
#include "WSettingAction.moc"
WSettingAction::WSettingAction( QObject* parent, std::string settingName, std::string actionName, std::string tooltip, bool defaultValue,
bool showRestartInfo, const QKeySequence& shortcut ):
QAction( QString::fromStdString( actionName ), parent ),
m_settingName( QString::fromStdString( settingName ) ),
m_showRestartInfo( showRestartInfo )
{
// set the user-specified shortcut
QList<QKeySequence> shortcuts;
shortcuts.push_back( shortcut );
setShortcuts( shortcuts );
// binary action
setCheckable( true );
setToolTip( QString::fromStdString( tooltip ) );
// set with current value
setChecked( WQt4Gui::getSettings().value( QString::fromStdString( settingName), defaultValue ).toBool() );
// handle the change
connect( this, SIGNAL( toggled( bool ) ), this, SLOT( stateChange( bool ) ) );
}
WSettingAction::~WSettingAction()
{
}
bool WSettingAction::get() const
{
return isChecked();
}
void WSettingAction::stateChange( bool state )
{
// store the value
WQt4Gui::getSettings().setValue( m_settingName, state );
// does this setting require restart?
if( m_showRestartInfo )
{
QMessageBox::information( WQt4Gui::getMainWindow(), QString( "Restart required" ), QString( "This setting is applied after restart." ) );
}
emit change( state );
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// 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.
//
// OpenWalnut is distributed in the hope that it will be useful,
// 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
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WSETTINGACTION_H
#define WSETTINGACTION_H
#include <QtGui/QAction>
#include <QtGui/QMessageBox>
#include "WQt4Gui.h"
class WMainWindow;
/**
* Class to handle a certain setting with an action. The action is associated with a QSettings value. Please note, that this class is not able to
* handle async changes in the QSettings object. So, try to avoid multiple actions for one setting.
*/
class WSettingAction: public QAction
{
Q_OBJECT
public:
/**
* Constructs an action which handles a certain setting.
*
* \param parent the parent handling this
* \param settingName the name of the setting to handle
* \param actionName the name of the action
* \param defaultValue the default if setting not existing
* \param tooltip the tooltip text
* \param showRestartInfo if true, info dialog is shown which says that a restart is needed
* \param shortcut the shortcut keysequence
*/
WSettingAction( QObject* parent, std::string settingName, std::string actionName, std::string tooltip, bool defaultValue,
bool showRestartInfo = false, const QKeySequence& shortcut = 0 );
/**
* Destructor.
*/
virtual ~WSettingAction();
/**
* Gets the current state.
*
* \return state
*/
bool get() const;
signals:
/**
* This signal is emitted if this setting changes.
*
* \param value the new setting value.
*/
void change( bool value );
protected:
private:
/**
* The name of the setting handled here.
*/
QString m_settingName;
/**
* If true, a change of the setting causes an restart notification dialog.
*/
bool m_showRestartInfo;
private slots:
/**
* The state has changed by the action. Handled here.
*
* \param state the state
*/
void stateChange( bool state );
};
#endif // WSETTINGACTION_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment