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,
snapshotCounter_(0),
stackMenu_(0),
helpWidget_(0),
stereoSettingsWidget_(0),
aboutWidget_(0),
optionsWidget_(0),
plugins_(_plugins),
......@@ -334,7 +335,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
viewerToolbar_->setAllowedAreas(Qt::AllToolBarAreas);
viewerToolbar_->setIconSize(QSize(20,20));
viewerToolbar_->setObjectName(tr("ViewerToolbar"));
slotAddToolbar(viewerToolbar_);
moveButton_ = new QToolButton( viewerToolbar_ );
......@@ -432,13 +433,17 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
stereoButton_->setMaximumSize( 32, 32 );
stereoButton_->setCheckable( true );
stereoButton_->setToolTip(tr( "Toggle stereo viewing"));
// We want a custom context menu
stereoButton_->setContextMenuPolicy(Qt::CustomContextMenu);
stereoButton_->setWhatsThis(tr(
"Toggle stereo mode<br><br>"
"Use this button to switch between stereo "
"and mono view. To use this feature you need "
"a stereo capable graphics card and a stereo "
"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"));
}
......@@ -461,7 +466,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
vmChangeButton_ = new QPushButton(tr("Change View Mode"));
QPushButton* vmEditButton = new QPushButton(tr("Edit View Modes"));
hLayout->addWidget(vmChangeButton_);
hLayout->addWidget(vmEditButton);
gb->setLayout (hLayout);
......@@ -517,6 +522,13 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
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()
QVector< OpenFlipper::Options::RecentFile > recentFiles = OpenFlipper::Options::recentFiles();
for (int i = 0 ; i < recentFiles.size() ; ++i ) {
QString path = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
QFileInfo fi(recentFiles[i].filename);
QFileInfo fi(recentFiles[i].filename);
if (fi.suffix() == "ini")
path += "Settings-Icon.png";
......
......@@ -89,6 +89,7 @@
#include <OpenFlipper/widgets/loggerWidget/loggerWidget.hh>
#include <OpenFlipper/widgets/optionsWidget/optionsWidget.hh>
#include <OpenFlipper/widgets/helpWidget/helpWidget.hh>
#include <OpenFlipper/widgets/stereoSettingsWidget/stereoSettingsWidget.hh>
#include <OpenFlipper/Core/PluginInfo.hh>
......@@ -102,23 +103,23 @@
*
*/
struct ViewMode{
/// Name of the View Mode
QString name;
/// Icon of the View Mode
/// TODO Specify size for Icons
QString icon;
/// Is this a user defined custom view mode or a plugin generated one
bool custom;
/// List of Visible Toolboxes in this view mode
QStringList visibleToolboxes;
/// List of Toolbars in this view mode
QStringList visibleToolbars;
/// List of context Menus in this view mode
QStringList visibleContextMenus;
};
......@@ -403,19 +404,19 @@ public:
/// Add or change Toolboxes for a ViewMode (_custom == userdefined viewMode)
void slotAddViewModeToolboxes(QString _mode, bool _custom, QStringList _usedWidgets);
/// 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)
void slotAddViewModeToolbars(QString _mode, bool _custom, QStringList _usedToolbars);
/// Completly configure a view mode ( set toolbars, toolboxes ... )
void slotAddViewModeComplete(QString _mode , bool _custom, QStringList _toolboxes, QStringList _toolbars);
/// Sets the Icon for a given View Mode (non-userdefined viewMode)
void slotSetViewModeIcon(QString _mode, QString _iconName);
/// Sets the Icon for a given View Mode (_custom == userdefined viewMode)
void slotSetViewModeIcon(QString _mode, bool _custom, QString _iconName);
......@@ -432,7 +433,7 @@ public:
/// Show a dialog in which the viewMode can be edited
void slotViewModeDialog();
/// Show a dialog in which the viewMode can be changed
void slotViewChangeDialog();
......@@ -492,7 +493,7 @@ public:
/// Widget for toolBox
QWidget* toolBoxArea_;
/// Button to change viewModes
QPushButton* vmChangeButton_;
......@@ -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
* @{ */
......@@ -982,16 +1002,16 @@ public:
/// When using first person mode move backward
void moveBack();
/// When using first person mode move forward
void moveForward();
/// When using first person mode strafe to the left
void strafeLeft();
/// When using first person mode strafe to the right
void strafeRight();
private :
bool stereoActive_;
......
......@@ -93,7 +93,7 @@ void CoreWidget::slotAddViewModeToolboxes(QString _mode, QStringList _usedWidget
void CoreWidget::slotAddViewModeToolboxes(QString _mode, bool _custom, QStringList _usedWidgets){
int id = -1;
// Check if it already exists
for ( int i = 0 ; i < viewModes_.size(); i++) {
if ( viewModes_[i]->name == _mode ) {
......@@ -101,14 +101,14 @@ void CoreWidget::slotAddViewModeToolboxes(QString _mode, bool _custom, QStringLi
break;
}
}
ViewMode* vm = 0;
if ( id == -1 ) {
vm = new ViewMode();
vm->name = _mode;
vm->custom = _custom;
vm->icon = "Unknown.png";
if (_custom) {
viewModes_.push_back(vm);
} else {
......@@ -120,11 +120,11 @@ void CoreWidget::slotAddViewModeToolboxes(QString _mode, bool _custom, QStringLi
break;
}
viewModes_.insert(i,vm);
}
}
} else {
vm = viewModes_[id];
}
vm->visibleToolboxes = _usedWidgets;
initViewModes();
......@@ -136,7 +136,7 @@ void CoreWidget::slotAddViewModeToolbars(QString _mode, QStringList _usedToolbar
void CoreWidget::slotAddViewModeToolbars(QString _mode, bool _custom, QStringList _usedToolbars) {
int id = -1;
// Check if it already exists
for ( int i = 0 ; i < viewModes_.size(); i++) {
if ( viewModes_[i]->name == _mode ) {
......@@ -144,14 +144,14 @@ void CoreWidget::slotAddViewModeToolbars(QString _mode, bool _custom, QStringLis
break;
}
}
ViewMode* vm = 0;
if ( id == -1 ) {
vm = new ViewMode();
vm->name = _mode;
vm->custom = _custom;
vm->icon = "Unknown.png";
if (_custom) {
viewModes_.push_back(vm);
} else {
......@@ -163,13 +163,13 @@ void CoreWidget::slotAddViewModeToolbars(QString _mode, bool _custom, QStringLis
break;
}
viewModes_.insert(i,vm);
}
}
} else {
vm = viewModes_[id];
}
vm->visibleToolbars = _usedToolbars;
initViewModes();
}
......@@ -180,9 +180,9 @@ void CoreWidget::slotSetViewModeIcon(QString _mode, QString _iconName) {
/// Sets the Icon for a given View Mode
void CoreWidget::slotSetViewModeIcon(QString _mode, bool _custom, QString _iconName) {
int id = -1;
// Check if it already exists
for ( int i = 0 ; i < viewModes_.size(); i++) {
if ( viewModes_[i]->name == _mode ) {
......@@ -190,14 +190,14 @@ void CoreWidget::slotSetViewModeIcon(QString _mode, bool _custom, QString _iconN
break;
}
}
ViewMode* vm = 0;
if ( id == -1 ) {
vm = new ViewMode();
vm->name = _mode;
vm->custom = _custom;
vm->icon = _iconName;
if (_custom) {
viewModes_.push_back(vm);
} else {
......@@ -209,14 +209,14 @@ void CoreWidget::slotSetViewModeIcon(QString _mode, bool _custom, QString _iconN
break;
}
viewModes_.insert(i,vm);
}
}
} else {
vm = viewModes_[id];
}
vm->icon = _iconName;
initViewModes();
initViewModes();
}
/// Remove a viewMode
......@@ -266,20 +266,20 @@ void CoreWidget::slotViewModeDialog(){
widget->show( OpenFlipper::Options::defaultToolboxMode() );
}
void CoreWidget::slotViewChangeDialog() {
void CoreWidget::slotViewChangeDialog() {
//init widget
static viewModeChangeWidget* modeChangeWidget = 0;
if ( !modeChangeWidget ){
modeChangeWidget = new viewModeChangeWidget(viewModes_, this);
modeChangeWidget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
connect(modeChangeWidget, SIGNAL(changeView(QString, QStringList, QStringList)), this, SLOT(slotChangeView(QString, QStringList, QStringList)) );
}
// Make it look like a dialog
modeChangeWidget->setWindowFlags(Qt::Popup);
modeChangeWidget->show( OpenFlipper::Options::defaultToolboxMode() );
modeChangeWidget->show( OpenFlipper::Options::defaultToolboxMode() );
// Move it to the position of the push button
QPoint posButton = vmChangeButton_->mapToGlobal(vmChangeButton_->pos());
modeChangeWidget->move( posButton);
......@@ -315,23 +315,62 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolboxWidgets, QStr
plugins_[p].toolbars[j].second->show();
else
plugins_[p].toolbars[j].second->hide();
// Check the Main Toolbar:
// Check the Main Toolbar:
if ( _toolbars.contains(tr("Main Toolbar")) )
mainToolbar_->show();
else
mainToolbar_->hide();
// Check the Main Toolbar:
// Check the Main Toolbar:
if ( _toolbars.contains(tr("Viewer Toolbar")) )
viewerToolbar_->show();
else
viewerToolbar_->hide();
viewerToolbar_->hide();
if (_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 *
* 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 with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper 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 LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 83 $ *
* $Author: kremer $ *
* $Date: 2009-02-27 17:31:45 +0100 (Fr, 27. Feb 2009) $ *
* *
\*===========================================================================*/
/*
* stereoSettingsWidget.hh
*
* Created on: Nov 9, 2009
* Author: kremer
*/
#include "ui_stereoSettingsWidget.hh"
#include <QtGui>
class StereoSettingsWidget : public QWidget, public Ui::StereoSettingsWidget
{
Q_OBJECT
public:
StereoSettingsWidget(QWidget *parent = 0);
};
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>StereoSettingsWidget</class>
<widget class="QWidget" name="StereoSettingsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>496</width>
<height>304</height>
</rect>
</property>
<property name="windowTitle">
<string>Stereo Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Stereo Mode</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_14">
<item>
<widget class="QRadioButton" name="stereoOpengl">
<property name="text">
<string>OpenGL stereo buffers</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="stereoAnaglyph">
<property name="text">
<string>Red/Cyan Anaglyph</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="stereoCustomAnaglyph">
<property name="text">
<string>Custom Anaglyph</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="stereoPhilips">
<property name="text">
<string>Philips Stereo Mode (For 3D autostereoskopic displays)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
<string>View properties</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<layout class="QVBoxLayout" name="verticalLayout_18">
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>Eye distance:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Focal distance:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_20">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<widget class="QDoubleSpinBox" name="eyeDistance">
<property name="decimals">
<number>4</number>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
<widget class="QLabel" name="label_13">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">