Commit fe69e859 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE #219] gl widget dock windows now have a contex menu providing color...

[CHANGE #219] gl widget dock windows now have a contex menu providing color change, reset and camera presets
parent 534d75dc
......@@ -23,4 +23,4 @@
# systems refuse to accept these arbitrary version strings.
# The current version string:
VERSION=1.3.0+hgX
VERSION=1.3.1+hgX
This diff is collapsed.
......@@ -60,4 +60,6 @@
#include "moduleDefault.xpm"
#include "ColorWheel.xpm"
#endif // WICONS_H
......@@ -181,6 +181,12 @@ void WMainWindow::setupGUI()
m_iconManager.addIcon( std::string( "video" ), video_xpm );
m_iconManager.addIcon( std::string( "image" ), image_xpm );
m_iconManager.addIcon( std::string( "preferences" ), preferences_xpm );
m_iconManager.addIcon( std::string( "colorwheel" ), ColorWheel_xpm );
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 );
try
{
......@@ -270,17 +276,10 @@ void WMainWindow::setupGUI()
m_permanentToolBar = new WQtToolBar( "Standard Toolbar", this );
addToolBar( Qt::TopToolBarArea, m_permanentToolBar );
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 );
m_loadButton = new QAction( m_iconManager.getIcon( "load" ), "Load Dataset or Project", m_permanentToolBar );
m_loadButton->setShortcut( QKeySequence( QKeySequence::Open ) );
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 ) );
m_saveAction = new QAction( m_iconManager.getIcon( "saveProject" ), "Save Project", m_permanentToolBar );
connect( m_loadButton, SIGNAL( triggered( bool ) ), this, SLOT( openLoadDialog() ) );
......@@ -326,15 +325,11 @@ 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* bgColorMenu = new QMenu( "Background Colors" );
bgColorMenu->addAction( mainGLDock->getGLWidget()->getBackgroundColorAction() );
m_viewAction = new QAction( "View", this );
m_viewMenu = m_menuBar->addMenu( "View" );
m_viewMenu->addAction( hideMenuAction );
m_viewMenu->addSeparator();
m_viewMenu->addAction( showNavWidgets );
m_viewMenu->addMenu( bgColorMenu );
m_viewMenu->addSeparator();
m_viewMenu->addMenu( m_permanentToolBar->getStyleMenu() );
m_viewAction->setMenu( m_viewMenu );
......@@ -355,50 +350,14 @@ void WMainWindow::setupGUI()
m_settingsMenu->addMenu( logLevels );
m_settingsAction->setMenu( m_settingsMenu );
// a separate menu for some presets
QMenu* cameraPresetMenu = m_cameraMenu->addMenu( "Presets" );
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
// 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 ).
// By additionally adding the action to the main window, we ensure the action can be triggered even if the menu bar is hidden.
QAction* tmpAction = cameraPresetMenu->addAction( m_iconManager.getIcon( "sagittal icon" ), "Left", this, SLOT( setPresetViewLeft() ),
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_L ) );
tmpAction->setIconVisibleInMenu( true );
this->addAction( tmpAction );
tmpAction = cameraPresetMenu->addAction( m_iconManager.getIcon( "sagittal icon" ), "Right", this, SLOT( setPresetViewRight() ),
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_R ) );
tmpAction->setIconVisibleInMenu( true );
this->addAction( tmpAction );
tmpAction = cameraPresetMenu->addAction( m_iconManager.getIcon( "axial icon" ), "Superior", this, SLOT( setPresetViewSuperior() ),
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_S ) );
tmpAction->setIconVisibleInMenu( true );
this->addAction( tmpAction );
tmpAction = cameraPresetMenu->addAction( m_iconManager.getIcon( "axial icon" ), "Inferior", this, SLOT( setPresetViewInferior() ),
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_I ) );
tmpAction->setIconVisibleInMenu( true );
this->addAction( tmpAction );
tmpAction = cameraPresetMenu->addAction( m_iconManager.getIcon( "coronal icon" ), "Anterior", this, SLOT( setPresetViewAnterior() ),
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_A ) );
tmpAction->setIconVisibleInMenu( true );
this->addAction( tmpAction );
tmpAction = cameraPresetMenu->addAction( m_iconManager.getIcon( "coronal icon" ), "Posterior", this, SLOT( setPresetViewPosterior() ),
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_P ) );
tmpAction->setIconVisibleInMenu( true );
this->addAction( tmpAction );
resetButton->setMenu( cameraPresetMenu );
resetButton->setMenu( m_mainGLWidget->getCameraPresetsMenu() );
m_cameraMenu->addMenu( m_mainGLWidget->getCameraPresetsMenu() );
m_helpAction = new QAction( "Help", this );
m_helpMenu = m_menuBar->addMenu( "Help" );
......@@ -440,10 +399,6 @@ void WMainWindow::setupGUI()
m_navSagittal->getGLWidget()->setCameraManipulator( WQtGLWidget::NO_OP );
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() );
}
}
......@@ -776,60 +731,6 @@ void WMainWindow::openOpenWalnutHelpDialog()
#endif
}
void WMainWindow::setPresetViewLeft()
{
boost::shared_ptr< WGEViewer > viewer;
viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "Main View" );
osg::ref_ptr<osgGA::TrackballManipulator> cm = osg::dynamic_pointer_cast<osgGA::TrackballManipulator>( viewer->getCameraManipulator() );
osg::Quat q( 0.5, -0.5, -0.5, 0.5 );
cm->setRotation( q );
}
void WMainWindow::setPresetViewRight()
{
boost::shared_ptr< WGEViewer > viewer;
viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "Main View" );
osg::ref_ptr<osgGA::TrackballManipulator> cm = osg::dynamic_pointer_cast<osgGA::TrackballManipulator>( viewer->getCameraManipulator() );
osg::Quat q( -0.5, -0.5, -0.5, -0.5 );
cm->setRotation( q );
}
void WMainWindow::setPresetViewSuperior()
{
boost::shared_ptr< WGEViewer > viewer;
viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "Main View" );
osg::ref_ptr<osgGA::TrackballManipulator> cm = osg::dynamic_pointer_cast<osgGA::TrackballManipulator>( viewer->getCameraManipulator() );
osg::Quat q( 0., 0., 0., 1 );
cm->setRotation( q );
}
void WMainWindow::setPresetViewInferior()
{
boost::shared_ptr< WGEViewer > viewer;
viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "Main View" );
osg::ref_ptr<osgGA::TrackballManipulator> cm = osg::dynamic_pointer_cast<osgGA::TrackballManipulator>( viewer->getCameraManipulator() );
osg::Quat q( 0., -1., 0., 0. );
cm->setRotation( q );
}
void WMainWindow::setPresetViewAnterior()
{
boost::shared_ptr< WGEViewer > viewer;
viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "Main View" );
osg::ref_ptr<osgGA::TrackballManipulator> cm = osg::dynamic_pointer_cast<osgGA::TrackballManipulator>( viewer->getCameraManipulator() );
osg::Quat q( 0., -0.707107, -0.707107, 0. );
cm->setRotation( q );
}
void WMainWindow::setPresetViewPosterior()
{
boost::shared_ptr< WGEViewer > viewer;
viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "Main View" );
osg::ref_ptr<osgGA::TrackballManipulator> cm = osg::dynamic_pointer_cast<osgGA::TrackballManipulator>( viewer->getCameraManipulator() );
osg::Quat q( 0.707107, 0., 0., 0.707107 );
cm->setRotation( q );
}
void WMainWindow::openNotImplementedDialog()
{
QMessageBox::information( this, "Not yet implemented!",
......
......@@ -283,36 +283,6 @@ public slots:
*/
void openOpenWalnutHelpDialog();
/**
* 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();
/**
* Gets called when a menu entry that has no functionality yet is activated.
*/
......
......@@ -95,6 +95,11 @@ WMainWindow* WQt4Gui::getMainWindow()
return m_mainWindow;
}
WIconManager* WQt4Gui::getIconManager()
{
return getMainWindow()->getIconManager();
}
void WQt4Gui::deferredLoad()
{
m_deferredLoadMutex.lock();
......
......@@ -41,6 +41,8 @@
#include "core/gui/WGUI.h"
#include "WIconManager.h"
class WMainWindow;
class WKernel;
......@@ -186,6 +188,13 @@ public:
*/
static QSettings& getSettings();
/**
* Get the icon manager of this gui instance.
*
* \return the icon manager.
*/
static WIconManager* getIconManager();
/**
* Returns the option map for the current instance of this GUI. This can be useful to parse further commandline parameters
*
......
......@@ -22,9 +22,12 @@
//
//---------------------------------------------------------------------------
#include <QtGui/QAction>
#include <QtGui/QDockWidget>
#include <QtGui/QVBoxLayout>
#include "WQt4Gui.h"
#include "WQtGLDockWidget.h"
#include "WQtGLDockWidget.moc"
......@@ -56,6 +59,25 @@ WQtGLDockWidget::WQtGLDockWidget( QString viewTitle, QString dockTitle, QWidget*
// we need to know whether the dock is visible or not
connect( this, SIGNAL( visibilityChanged( bool ) ), this, SLOT( handleVisibilityChange( bool ) ) );
// create the dock widget context menu
// important: do not use this menu for the m_panel widget but ensure the right click event to be sent to the widget
m_panel->setContextMenuPolicy( Qt::PreventContextMenu );
setContextMenuPolicy( Qt::ActionsContextMenu );
// reset the scene
QAction* resetButton = new QAction( WQt4Gui::getIconManager()->getIcon( "view" ), "Reset", this );
connect( resetButton, SIGNAL( triggered( bool ) ), m_glWidget.get(), SLOT( reset() ) );
addAction( resetButton );
// camera presets
QAction* camPresets = new QAction( WQt4Gui::getIconManager()->getIcon( "view" ), "Camera Presets", this );
camPresets->setMenu( getGLWidget()->getCameraPresetsMenu() );
addAction( camPresets );
// change background color
addAction( getGLWidget()->getBackgroundColorAction() );
}
WQtGLDockWidget::~WQtGLDockWidget()
......
......@@ -46,6 +46,7 @@
#include "core/graphicsEngine/WGraphicsEngineMode.h"
#include "core/kernel/WKernel.h"
#include "WQt4Gui.h"
#include "WQtGLScreenCapture.h"
#include "events/WRenderedFrameEvent.h"
#include "events/WEventTypes.h"
......@@ -106,7 +107,7 @@ WQtGLWidget::WQtGLWidget( std::string nameOfViewer, QWidget* parent, WGECamera::
// set bg color
updateViewerBackground();
// this action manages the above settings
m_changeBGColorAction = new QAction( QString::fromStdString( nameOfViewer ), parent );
m_changeBGColorAction = new QAction( WQt4Gui::getIconManager()->getIcon( "colorwheel" ), "Change Background Color", parent );
connect( m_changeBGColorAction, SIGNAL( triggered( bool ) ), this, SLOT( changeBGColor() ) );
// enable throwing of wanted
......@@ -117,6 +118,31 @@ WQtGLWidget::WQtGLWidget( std::string nameOfViewer, QWidget* parent, WGECamera::
false );
connect( m_allowThrowSetting, SIGNAL( change( bool ) ), this, SLOT( updateThrowing() ) );
updateThrowing();
// a separate menu for some presets
m_cameraPresetMenu = new QMenu( "Camera Presets" );
// 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 ).
// By additionally adding the action to the main window, we ensure the action can be triggered even if the menu bar is hidden.
QAction* tmpAction = m_cameraPresetMenu->addAction( WQt4Gui::getIconManager()->getIcon( "sagittal icon" ), "Left", this, SLOT( setPresetViewLeft() ),
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_L ) );
tmpAction->setIconVisibleInMenu( true );
tmpAction = m_cameraPresetMenu->addAction( WQt4Gui::getIconManager()->getIcon( "sagittal icon" ), "Right", this, SLOT( setPresetViewRight() ),
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_R ) );
tmpAction->setIconVisibleInMenu( true );
tmpAction = m_cameraPresetMenu->addAction( WQt4Gui::getIconManager()->getIcon( "axial icon" ), "Superior", this, SLOT( setPresetViewSuperior() ),
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_S ) );
tmpAction->setIconVisibleInMenu( true );
tmpAction = m_cameraPresetMenu->addAction( WQt4Gui::getIconManager()->getIcon( "axial icon" ), "Inferior", this, SLOT( setPresetViewInferior() ),
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_I ) );
tmpAction->setIconVisibleInMenu( true );
tmpAction = m_cameraPresetMenu->addAction( WQt4Gui::getIconManager()->getIcon( "coronal icon" ), "Anterior", this, SLOT( setPresetViewAnterior() ),
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_A ) );
tmpAction->setIconVisibleInMenu( true );
tmpAction = m_cameraPresetMenu->addAction( WQt4Gui::getIconManager()->getIcon( "coronal icon" ), "Posterior", this, SLOT( setPresetViewPosterior() ),
QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_P ) );
tmpAction->setIconVisibleInMenu( true );
}
WQtGLWidget::~WQtGLWidget()
......@@ -400,3 +426,97 @@ WQtGLScreenCapture* WQtGLWidget::getScreenCapture( WMainWindow* parent ) const
return sc;
}
void WQtGLWidget::setPresetViewLeft()
{
osg::ref_ptr<osgGA::TrackballManipulator> cm = osg::dynamic_pointer_cast<osgGA::TrackballManipulator>( m_Viewer->getCameraManipulator() );
osg::Quat q( 0.5, -0.5, -0.5, 0.5 );
// is it a trackball manipulator?
if( cm )
{
cm->setRotation( q );
}
else
{
wlog::warn( "WQtGLWidget(" + m_Viewer->getName() + ")" ) << "GL Widget does not use a TrackballManipulator. Preset cannot be used.";
}
}
void WQtGLWidget::setPresetViewRight()
{
osg::ref_ptr<osgGA::TrackballManipulator> cm = osg::dynamic_pointer_cast<osgGA::TrackballManipulator>( m_Viewer->getCameraManipulator() );
osg::Quat q( -0.5, -0.5, -0.5, -0.5 );
// is it a trackball manipulator?
if( cm )
{
cm->setRotation( q );
}
else
{
wlog::warn( "WQtGLWidget(" + m_Viewer->getName() + ")" ) << "GL Widget does not use a TrackballManipulator. Preset cannot be used.";
}
}
void WQtGLWidget::setPresetViewSuperior()
{
osg::ref_ptr<osgGA::TrackballManipulator> cm = osg::dynamic_pointer_cast<osgGA::TrackballManipulator>( m_Viewer->getCameraManipulator() );
osg::Quat q( 0., 0., 0., 1 );
// is it a trackball manipulator?
if( cm )
{
cm->setRotation( q );
}
else
{
wlog::warn( "WQtGLWidget(" + m_Viewer->getName() + ")" ) << "GL Widget does not use a TrackballManipulator. Preset cannot be used.";
}
}
void WQtGLWidget::setPresetViewInferior()
{
osg::ref_ptr<osgGA::TrackballManipulator> cm = osg::dynamic_pointer_cast<osgGA::TrackballManipulator>( m_Viewer->getCameraManipulator() );
osg::Quat q( 0., -1., 0., 0. );
// is it a trackball manipulator?
if( cm )
{
cm->setRotation( q );
}
else
{
wlog::warn( "WQtGLWidget(" + m_Viewer->getName() + ")" ) << "GL Widget does not use a TrackballManipulator. Preset cannot be used.";
}
}
void WQtGLWidget::setPresetViewAnterior()
{
osg::ref_ptr<osgGA::TrackballManipulator> cm = osg::dynamic_pointer_cast<osgGA::TrackballManipulator>( m_Viewer->getCameraManipulator() );
osg::Quat q( 0., -0.707107, -0.707107, 0. );
// is it a trackball manipulator?
if( cm )
{
cm->setRotation( q );
}
else
{
wlog::warn( "WQtGLWidget(" + m_Viewer->getName() + ")" ) << "GL Widget does not use a TrackballManipulator. Preset cannot be used.";
}
}
void WQtGLWidget::setPresetViewPosterior()
{
osg::ref_ptr<osgGA::TrackballManipulator> cm = osg::dynamic_pointer_cast<osgGA::TrackballManipulator>( m_Viewer->getCameraManipulator() );
osg::Quat q( 0.707107, 0., 0., 0.707107 );
// is it a trackball manipulator?
if( cm )
{
cm->setRotation( q );
}
else
{
wlog::warn( "WQtGLWidget(" + m_Viewer->getName() + ")" ) << "GL Widget does not use a TrackballManipulator. Preset cannot be used.";
}
}
QMenu* WQtGLWidget::getCameraPresetsMenu()
{
return m_cameraPresetMenu;
}
......@@ -32,6 +32,7 @@
#include <QtCore/QTimer>
#include <QtGui/QWidget>
#include <QtGui/QMenu>
#include <QtOpenGL/QGLWidget>
#include <QtOpenGL/QGLFormat>
......@@ -145,6 +146,13 @@ public:
*/
WQtGLScreenCapture* getScreenCapture( WMainWindow* parent ) const;
/**
* The presets menu.
*
* \return the menu
*/
QMenu* getCameraPresetsMenu();
signals:
/**
......@@ -158,6 +166,36 @@ public slots:
*/
void reset();
/**
* 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();
protected:
/**
* The viewer to the scene.
......@@ -308,6 +346,11 @@ private:
*/
void notifyFirstRenderedFrame();
/**
* Camera menu
*/
QMenu* m_cameraPresetMenu;
private slots:
/**
* Function to handle updates in the setting \ref m_allowThrowSetting.
......
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