Commit a8d7afa7 authored by Mike Kremer's avatar Mike Kremer
Browse files

Added context menu to stereo mode button in toolbar.

TODO: Update the current viewports after having changed the settings.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@7564 383ad7c9-94d9-4d36-a494-682f7c89f535
parent cad47166
...@@ -115,6 +115,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -115,6 +115,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
snapshotCounter_(0), snapshotCounter_(0),
stackMenu_(0), stackMenu_(0),
helpWidget_(0), helpWidget_(0),
stereoSettingsWidget_(0),
aboutWidget_(0), aboutWidget_(0),
optionsWidget_(0), optionsWidget_(0),
plugins_(_plugins), plugins_(_plugins),
...@@ -334,7 +335,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -334,7 +335,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
viewerToolbar_->setAllowedAreas(Qt::AllToolBarAreas); viewerToolbar_->setAllowedAreas(Qt::AllToolBarAreas);
viewerToolbar_->setIconSize(QSize(20,20)); viewerToolbar_->setIconSize(QSize(20,20));
viewerToolbar_->setObjectName(tr("ViewerToolbar")); viewerToolbar_->setObjectName(tr("ViewerToolbar"));
slotAddToolbar(viewerToolbar_); slotAddToolbar(viewerToolbar_);
moveButton_ = new QToolButton( viewerToolbar_ ); moveButton_ = new QToolButton( viewerToolbar_ );
...@@ -432,13 +433,17 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -432,13 +433,17 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
stereoButton_->setMaximumSize( 32, 32 ); stereoButton_->setMaximumSize( 32, 32 );
stereoButton_->setCheckable( true ); stereoButton_->setCheckable( true );
stereoButton_->setToolTip(tr( "Toggle stereo viewing")); stereoButton_->setToolTip(tr( "Toggle stereo viewing"));
// We want a custom context menu
stereoButton_->setContextMenuPolicy(Qt::CustomContextMenu);
stereoButton_->setWhatsThis(tr( stereoButton_->setWhatsThis(tr(
"Toggle stereo mode<br><br>" "Toggle stereo mode<br><br>"
"Use this button to switch between stereo " "Use this button to switch between stereo "
"and mono view. To use this feature you need " "and mono view. To use this feature you need "
"a stereo capable graphics card and a stereo " "a stereo capable graphics card and a stereo "
"display/projection system.")); "display/projection system."));
connect( stereoButton_,SIGNAL( clicked() ), this , SLOT( slotToggleStereoMode() ) ); connect( stereoButton_, SIGNAL( clicked() ), this , SLOT( slotToggleStereoMode() ) );
// Custom context menu
connect( stereoButton_, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(stereoButtonContextMenu(const QPoint &)));
viewerToolbar_->addWidget( stereoButton_ )->setText( tr("Stereo")); viewerToolbar_->addWidget( stereoButton_ )->setText( tr("Stereo"));
} }
...@@ -461,7 +466,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -461,7 +466,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
vmChangeButton_ = new QPushButton(tr("Change View Mode")); vmChangeButton_ = new QPushButton(tr("Change View Mode"));
QPushButton* vmEditButton = new QPushButton(tr("Edit View Modes")); QPushButton* vmEditButton = new QPushButton(tr("Edit View Modes"));
hLayout->addWidget(vmChangeButton_); hLayout->addWidget(vmChangeButton_);
hLayout->addWidget(vmEditButton); hLayout->addWidget(vmEditButton);
gb->setLayout (hLayout); gb->setLayout (hLayout);
...@@ -517,6 +522,13 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -517,6 +522,13 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() ); setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
// Create stereo settings widget
stereoSettingsWidget_ = new StereoSettingsWidget(this);
// Make it look like a dialog
stereoSettingsWidget_->setWindowFlags(Qt::Popup);
// Connect Ok button to local slot
connect(stereoSettingsWidget_->confirmButton, SIGNAL(pressed()),
this, SLOT(slotApplyStereoSettings()));
} }
...@@ -823,8 +835,8 @@ CoreWidget::updateRecent() ...@@ -823,8 +835,8 @@ CoreWidget::updateRecent()
QVector< OpenFlipper::Options::RecentFile > recentFiles = OpenFlipper::Options::recentFiles(); QVector< OpenFlipper::Options::RecentFile > recentFiles = OpenFlipper::Options::recentFiles();
for (int i = 0 ; i < recentFiles.size() ; ++i ) { for (int i = 0 ; i < recentFiles.size() ; ++i ) {
QString path = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator(); QString path = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
QFileInfo fi(recentFiles[i].filename); QFileInfo fi(recentFiles[i].filename);
if (fi.suffix() == "ini") if (fi.suffix() == "ini")
path += "Settings-Icon.png"; path += "Settings-Icon.png";
......
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
#include <OpenFlipper/widgets/loggerWidget/loggerWidget.hh> #include <OpenFlipper/widgets/loggerWidget/loggerWidget.hh>
#include <OpenFlipper/widgets/optionsWidget/optionsWidget.hh> #include <OpenFlipper/widgets/optionsWidget/optionsWidget.hh>
#include <OpenFlipper/widgets/helpWidget/helpWidget.hh> #include <OpenFlipper/widgets/helpWidget/helpWidget.hh>
#include <OpenFlipper/widgets/stereoSettingsWidget/stereoSettingsWidget.hh>
#include <OpenFlipper/Core/PluginInfo.hh> #include <OpenFlipper/Core/PluginInfo.hh>
...@@ -102,23 +103,23 @@ ...@@ -102,23 +103,23 @@
* *
*/ */
struct ViewMode{ struct ViewMode{
/// Name of the View Mode /// Name of the View Mode
QString name; QString name;
/// Icon of the View Mode /// Icon of the View Mode
/// TODO Specify size for Icons /// TODO Specify size for Icons
QString icon; QString icon;
/// Is this a user defined custom view mode or a plugin generated one /// Is this a user defined custom view mode or a plugin generated one
bool custom; bool custom;
/// List of Visible Toolboxes in this view mode /// List of Visible Toolboxes in this view mode
QStringList visibleToolboxes; QStringList visibleToolboxes;
/// List of Toolbars in this view mode /// List of Toolbars in this view mode
QStringList visibleToolbars; QStringList visibleToolbars;
/// List of context Menus in this view mode /// List of context Menus in this view mode
QStringList visibleContextMenus; QStringList visibleContextMenus;
}; };
...@@ -403,19 +404,19 @@ public: ...@@ -403,19 +404,19 @@ public:
/// Add or change Toolboxes for a ViewMode (_custom == userdefined viewMode) /// Add or change Toolboxes for a ViewMode (_custom == userdefined viewMode)
void slotAddViewModeToolboxes(QString _mode, bool _custom, QStringList _usedWidgets); void slotAddViewModeToolboxes(QString _mode, bool _custom, QStringList _usedWidgets);
/// Add or change Toolbars for a ViewMode (non-userdefined viewMode) /// Add or change Toolbars for a ViewMode (non-userdefined viewMode)
void slotAddViewModeToolbars(QString _mode, QStringList _usedToolbars); void slotAddViewModeToolbars(QString _mode, QStringList _usedToolbars);
/// Add or change Toolbars for a ViewMode (_custom == userdefined viewMode) /// Add or change Toolbars for a ViewMode (_custom == userdefined viewMode)
void slotAddViewModeToolbars(QString _mode, bool _custom, QStringList _usedToolbars); void slotAddViewModeToolbars(QString _mode, bool _custom, QStringList _usedToolbars);
/// Completly configure a view mode ( set toolbars, toolboxes ... ) /// Completly configure a view mode ( set toolbars, toolboxes ... )
void slotAddViewModeComplete(QString _mode , bool _custom, QStringList _toolboxes, QStringList _toolbars); void slotAddViewModeComplete(QString _mode , bool _custom, QStringList _toolboxes, QStringList _toolbars);
/// Sets the Icon for a given View Mode (non-userdefined viewMode) /// Sets the Icon for a given View Mode (non-userdefined viewMode)
void slotSetViewModeIcon(QString _mode, QString _iconName); void slotSetViewModeIcon(QString _mode, QString _iconName);
/// Sets the Icon for a given View Mode (_custom == userdefined viewMode) /// Sets the Icon for a given View Mode (_custom == userdefined viewMode)
void slotSetViewModeIcon(QString _mode, bool _custom, QString _iconName); void slotSetViewModeIcon(QString _mode, bool _custom, QString _iconName);
...@@ -432,7 +433,7 @@ public: ...@@ -432,7 +433,7 @@ public:
/// Show a dialog in which the viewMode can be edited /// Show a dialog in which the viewMode can be edited
void slotViewModeDialog(); void slotViewModeDialog();
/// Show a dialog in which the viewMode can be changed /// Show a dialog in which the viewMode can be changed
void slotViewChangeDialog(); void slotViewChangeDialog();
...@@ -492,7 +493,7 @@ public: ...@@ -492,7 +493,7 @@ public:
/// Widget for toolBox /// Widget for toolBox
QWidget* toolBoxArea_; QWidget* toolBoxArea_;
/// Button to change viewModes /// Button to change viewModes
QPushButton* vmChangeButton_; QPushButton* vmChangeButton_;
...@@ -800,6 +801,25 @@ public: ...@@ -800,6 +801,25 @@ public:
/** @} */ /** @} */
//===========================================================================
/** @name Stereo View Mode
* @{ */
//===========================================================================
public slots:
/// Creates custom context menu for stereo viewer settings
void stereoButtonContextMenu(const QPoint& _pos);
/// Is called if the user has changed stereo settings
void slotApplyStereoSettings();
private:
/// Widget to change stereo settings
StereoSettingsWidget* stereoSettingsWidget_;
/** @} */
//=========================================================================== //===========================================================================
/** @name About System /** @name About System
* @{ */ * @{ */
...@@ -982,16 +1002,16 @@ public: ...@@ -982,16 +1002,16 @@ public:
/// When using first person mode move backward /// When using first person mode move backward
void moveBack(); void moveBack();
/// When using first person mode move forward /// When using first person mode move forward
void moveForward(); void moveForward();
/// When using first person mode strafe to the left /// When using first person mode strafe to the left
void strafeLeft(); void strafeLeft();
/// When using first person mode strafe to the right /// When using first person mode strafe to the right
void strafeRight(); void strafeRight();
private : private :
bool stereoActive_; bool stereoActive_;
......
...@@ -93,7 +93,7 @@ void CoreWidget::slotAddViewModeToolboxes(QString _mode, QStringList _usedWidget ...@@ -93,7 +93,7 @@ void CoreWidget::slotAddViewModeToolboxes(QString _mode, QStringList _usedWidget
void CoreWidget::slotAddViewModeToolboxes(QString _mode, bool _custom, QStringList _usedWidgets){ void CoreWidget::slotAddViewModeToolboxes(QString _mode, bool _custom, QStringList _usedWidgets){
int id = -1; int id = -1;
// Check if it already exists // Check if it already exists
for ( int i = 0 ; i < viewModes_.size(); i++) { for ( int i = 0 ; i < viewModes_.size(); i++) {
if ( viewModes_[i]->name == _mode ) { if ( viewModes_[i]->name == _mode ) {
...@@ -101,14 +101,14 @@ void CoreWidget::slotAddViewModeToolboxes(QString _mode, bool _custom, QStringLi ...@@ -101,14 +101,14 @@ void CoreWidget::slotAddViewModeToolboxes(QString _mode, bool _custom, QStringLi
break; break;
} }
} }
ViewMode* vm = 0; ViewMode* vm = 0;
if ( id == -1 ) { if ( id == -1 ) {
vm = new ViewMode(); vm = new ViewMode();
vm->name = _mode; vm->name = _mode;
vm->custom = _custom; vm->custom = _custom;
vm->icon = "Unknown.png"; vm->icon = "Unknown.png";
if (_custom) { if (_custom) {
viewModes_.push_back(vm); viewModes_.push_back(vm);
} else { } else {
...@@ -120,11 +120,11 @@ void CoreWidget::slotAddViewModeToolboxes(QString _mode, bool _custom, QStringLi ...@@ -120,11 +120,11 @@ void CoreWidget::slotAddViewModeToolboxes(QString _mode, bool _custom, QStringLi
break; break;
} }
viewModes_.insert(i,vm); viewModes_.insert(i,vm);
} }
} else { } else {
vm = viewModes_[id]; vm = viewModes_[id];
} }
vm->visibleToolboxes = _usedWidgets; vm->visibleToolboxes = _usedWidgets;
initViewModes(); initViewModes();
...@@ -136,7 +136,7 @@ void CoreWidget::slotAddViewModeToolbars(QString _mode, QStringList _usedToolbar ...@@ -136,7 +136,7 @@ void CoreWidget::slotAddViewModeToolbars(QString _mode, QStringList _usedToolbar
void CoreWidget::slotAddViewModeToolbars(QString _mode, bool _custom, QStringList _usedToolbars) { void CoreWidget::slotAddViewModeToolbars(QString _mode, bool _custom, QStringList _usedToolbars) {
int id = -1; int id = -1;
// Check if it already exists // Check if it already exists
for ( int i = 0 ; i < viewModes_.size(); i++) { for ( int i = 0 ; i < viewModes_.size(); i++) {
if ( viewModes_[i]->name == _mode ) { if ( viewModes_[i]->name == _mode ) {
...@@ -144,14 +144,14 @@ void CoreWidget::slotAddViewModeToolbars(QString _mode, bool _custom, QStringLis ...@@ -144,14 +144,14 @@ void CoreWidget::slotAddViewModeToolbars(QString _mode, bool _custom, QStringLis
break; break;
} }
} }
ViewMode* vm = 0; ViewMode* vm = 0;
if ( id == -1 ) { if ( id == -1 ) {
vm = new ViewMode(); vm = new ViewMode();
vm->name = _mode; vm->name = _mode;
vm->custom = _custom; vm->custom = _custom;
vm->icon = "Unknown.png"; vm->icon = "Unknown.png";
if (_custom) { if (_custom) {
viewModes_.push_back(vm); viewModes_.push_back(vm);
} else { } else {
...@@ -163,13 +163,13 @@ void CoreWidget::slotAddViewModeToolbars(QString _mode, bool _custom, QStringLis ...@@ -163,13 +163,13 @@ void CoreWidget::slotAddViewModeToolbars(QString _mode, bool _custom, QStringLis
break; break;
} }
viewModes_.insert(i,vm); viewModes_.insert(i,vm);
} }
} else { } else {
vm = viewModes_[id]; vm = viewModes_[id];
} }
vm->visibleToolbars = _usedToolbars; vm->visibleToolbars = _usedToolbars;
initViewModes(); initViewModes();
} }
...@@ -180,9 +180,9 @@ void CoreWidget::slotSetViewModeIcon(QString _mode, QString _iconName) { ...@@ -180,9 +180,9 @@ void CoreWidget::slotSetViewModeIcon(QString _mode, QString _iconName) {
/// Sets the Icon for a given View Mode /// Sets the Icon for a given View Mode
void CoreWidget::slotSetViewModeIcon(QString _mode, bool _custom, QString _iconName) { void CoreWidget::slotSetViewModeIcon(QString _mode, bool _custom, QString _iconName) {
int id = -1; int id = -1;
// Check if it already exists // Check if it already exists
for ( int i = 0 ; i < viewModes_.size(); i++) { for ( int i = 0 ; i < viewModes_.size(); i++) {
if ( viewModes_[i]->name == _mode ) { if ( viewModes_[i]->name == _mode ) {
...@@ -190,14 +190,14 @@ void CoreWidget::slotSetViewModeIcon(QString _mode, bool _custom, QString _iconN ...@@ -190,14 +190,14 @@ void CoreWidget::slotSetViewModeIcon(QString _mode, bool _custom, QString _iconN
break; break;
} }
} }
ViewMode* vm = 0; ViewMode* vm = 0;
if ( id == -1 ) { if ( id == -1 ) {
vm = new ViewMode(); vm = new ViewMode();
vm->name = _mode; vm->name = _mode;
vm->custom = _custom; vm->custom = _custom;
vm->icon = _iconName; vm->icon = _iconName;
if (_custom) { if (_custom) {
viewModes_.push_back(vm); viewModes_.push_back(vm);
} else { } else {
...@@ -209,14 +209,14 @@ void CoreWidget::slotSetViewModeIcon(QString _mode, bool _custom, QString _iconN ...@@ -209,14 +209,14 @@ void CoreWidget::slotSetViewModeIcon(QString _mode, bool _custom, QString _iconN
break; break;
} }
viewModes_.insert(i,vm); viewModes_.insert(i,vm);
} }
} else { } else {
vm = viewModes_[id]; vm = viewModes_[id];
} }
vm->icon = _iconName; vm->icon = _iconName;
initViewModes(); initViewModes();
} }
/// Remove a viewMode /// Remove a viewMode
...@@ -266,20 +266,20 @@ void CoreWidget::slotViewModeDialog(){ ...@@ -266,20 +266,20 @@ void CoreWidget::slotViewModeDialog(){
widget->show( OpenFlipper::Options::defaultToolboxMode() ); widget->show( OpenFlipper::Options::defaultToolboxMode() );
} }
void CoreWidget::slotViewChangeDialog() { void CoreWidget::slotViewChangeDialog() {
//init widget //init widget
static viewModeChangeWidget* modeChangeWidget = 0; static viewModeChangeWidget* modeChangeWidget = 0;
if ( !modeChangeWidget ){ if ( !modeChangeWidget ){
modeChangeWidget = new viewModeChangeWidget(viewModes_, this); modeChangeWidget = new viewModeChangeWidget(viewModes_, this);
modeChangeWidget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() ); modeChangeWidget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
connect(modeChangeWidget, SIGNAL(changeView(QString, QStringList, QStringList)), this, SLOT(slotChangeView(QString, QStringList, QStringList)) ); connect(modeChangeWidget, SIGNAL(changeView(QString, QStringList, QStringList)), this, SLOT(slotChangeView(QString, QStringList, QStringList)) );
} }
// Make it look like a dialog // Make it look like a dialog
modeChangeWidget->setWindowFlags(Qt::Popup); modeChangeWidget->setWindowFlags(Qt::Popup);
modeChangeWidget->show( OpenFlipper::Options::defaultToolboxMode() ); modeChangeWidget->show( OpenFlipper::Options::defaultToolboxMode() );
// Move it to the position of the push button // Move it to the position of the push button
QPoint posButton = vmChangeButton_->mapToGlobal(vmChangeButton_->pos()); QPoint posButton = vmChangeButton_->mapToGlobal(vmChangeButton_->pos());
modeChangeWidget->move( posButton); modeChangeWidget->move( posButton);
...@@ -315,23 +315,62 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolboxWidgets, QStr ...@@ -315,23 +315,62 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolboxWidgets, QStr
plugins_[p].toolbars[j].second->show(); plugins_[p].toolbars[j].second->show();
else else
plugins_[p].toolbars[j].second->hide(); plugins_[p].toolbars[j].second->hide();
// Check the Main Toolbar: // Check the Main Toolbar:
if ( _toolbars.contains(tr("Main Toolbar")) ) if ( _toolbars.contains(tr("Main Toolbar")) )
mainToolbar_->show(); mainToolbar_->show();
else else
mainToolbar_->hide(); mainToolbar_->hide();
// Check the Main Toolbar: // Check the Main Toolbar:
if ( _toolbars.contains(tr("Viewer Toolbar")) ) if ( _toolbars.contains(tr("Viewer Toolbar")) )
viewerToolbar_->show(); viewerToolbar_->show();
else else
viewerToolbar_->hide(); viewerToolbar_->hide();
if (_mode != "") if (_mode != "")
OpenFlipper::Options::defaultToolboxMode(_mode); OpenFlipper::Options::defaultToolboxMode(_mode);
} }
void CoreWidget::stereoButtonContextMenu(const QPoint& _pos) {
// Set values:
stereoSettingsWidget_->stereoOpengl->setChecked(OpenFlipper::Options::stereoMode() == OpenFlipper::Options::OpenGL);
stereoSettingsWidget_->stereoAnaglyph->setChecked(OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphRedCyan);
stereoSettingsWidget_->stereoCustomAnaglyph->setChecked(OpenFlipper::Options::stereoMode() == OpenFlipper::Options::AnaglyphCustom);
stereoSettingsWidget_->stereoPhilips->setChecked(OpenFlipper::Options::stereoMode() == OpenFlipper::Options::Philips);
stereoSettingsWidget_->eyeDistance->setValue(OpenFlipper::Options::eyeDistance());
stereoSettingsWidget_->focalDistance->setValue(OpenFlipper::Options::focalDistance() * 1000);
// Move widget to the position of the cursor
stereoSettingsWidget_->move(stereoButton_->mapToGlobal(_pos));
// Show widget
stereoSettingsWidget_->show();
}
void CoreWidget::slotApplyStereoSettings() {
// Hide widget
stereoSettingsWidget_->hide();
// Update values
if (stereoSettingsWidget_->stereoCustomAnaglyph->isChecked()) {
OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphCustom);
} else if (stereoSettingsWidget_->stereoAnaglyph->isChecked()) {
OpenFlipper::Options::stereoMode(OpenFlipper::Options::AnaglyphRedCyan);
} else if (stereoSettingsWidget_->stereoPhilips->isChecked()) {
OpenFlipper::Options::stereoMode(OpenFlipper::Options::Philips);
} else {
OpenFlipper::Options::stereoMode(OpenFlipper::Options::OpenGL);
}
OpenFlipper::Options::eyeDistance(stereoSettingsWidget_->eyeDistance->value());
OpenFlipper::Options::focalDistance(
(float)stereoSettingsWidget_->focalDistance->value() / 1000);
// TODO: We should force an update of the viewports here
}
#include "stereoSettingsWidget.hh"
#include <OpenFlipper/common/GlobalOptions.hh>
StereoSettingsWidget::StereoSettingsWidget(QWidget* _parent) : QWidget(_parent) {
setupUi(this);
}
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *