Skip to content
Permalink
Browse files

Handle screen distance stereo setting

  • Loading branch information
pka committed Nov 21, 2010
1 parent 0f85a6c commit cb6593716dfa546d7423eaa3d31aa35bce1b8278
@@ -164,7 +164,7 @@ void GlobePlugin::settings()
{
if (mSettingsDialog.exec())
{
viewer.QgsGLWidgetAdapter::setStereoMode(mSettingsDialog.stereoMode);
//viewer stereo settings set by mSettingsDialog and stored in QSettings
}
}

@@ -32,16 +32,16 @@
#include <QStringList>
#include <QVariant>

#include <osgViewer/Viewer>
#include <osg/DisplaySettings>

//constructor
QgsGlobePluginDialog::QgsGlobePluginDialog( QWidget* parent, Qt::WFlags fl )
: QDialog( parent, fl )
{
setupUi( this );
stereoMode = settings.value( "/Plugin-Globe/stereoMode", "OFF" ).toString();
comboStereoMode->setCurrentIndex( comboStereoMode->findText( stereoMode ) );
//showMessageBox("constructor " + stereoMode);
getStereoConfig(); //default values from OSG
loadStereoConfig();
setStereoConfig(); //overwrite with values from QSettings
}

//destructor
@@ -72,6 +72,8 @@ bool QgsGlobePluginDialog::globeRunning()

void QgsGlobePluginDialog::on_buttonBox_accepted()
{
setStereoConfig();
saveStereoConfig();
/*
*
// Validate input settings
@@ -170,7 +172,6 @@ void QgsGlobePluginDialog::on_buttonBox_rejected()

void QgsGlobePluginDialog::on_comboStereoMode_currentIndexChanged( QString mode )
{
stereoMode = mode;
//showMessageBox("index_changed " + stereoMode);
}

@@ -180,3 +181,70 @@ void QgsGlobePluginDialog::showMessageBox( QString text )
msgBox.setText(text);
msgBox.exec();
}

void QgsGlobePluginDialog::getStereoConfig()
{
//stereoMode ignored

screenDistance->setValue( osg::DisplaySettings::instance()->getScreenDistance() );
}

void QgsGlobePluginDialog::setStereoConfig()
{
//http://www.openscenegraph.org/projects/osg/wiki/Support/UserGuides/StereoConfig
//http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a00181.html

QString stereoMode = comboStereoMode->currentText();
if("OFF" == stereoMode)
{
osg::DisplaySettings::instance()->setStereo( false );
}
else
{
osg::DisplaySettings::instance()->setStereo( true );

if("ANAGLYPHIC" == stereoMode)
{
osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::ANAGLYPHIC );
}
else if("VERTICAL_SPLIT" == stereoMode)
{
osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::VERTICAL_SPLIT );
}
else if("HORIZONTAL_SPLIT" == stereoMode)
{
osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::HORIZONTAL_SPLIT );
}
else if("QUAD_BUFFER" == stereoMode)
{
osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::QUAD_BUFFER );
}
else
{
//should never get here
QMessageBox msgBox;
msgBox.setText("This stereo mode has not been implemented yet. Defaulting to ANAGLYPHIC");
msgBox.exec();
}
}

osg::DisplaySettings::instance()->setScreenDistance( screenDistance->value() );
}

void QgsGlobePluginDialog::loadStereoConfig()
{
if ( settings.contains( "/Plugin-Globe/stereoMode" ) )
{
comboStereoMode->setCurrentIndex( comboStereoMode->findText( settings.value( "/Plugin-Globe/stereoMode" ).toString() ) );
}
if ( settings.contains( "/Plugin-Globe/screenDistance" ) )
{
screenDistance->setValue( settings.value( "/Plugin-Globe/screenDistance" ).toDouble() );
}
}

void QgsGlobePluginDialog::saveStereoConfig()
{
settings.setValue( "/Plugin-Globe/stereoMode", comboStereoMode->currentText() );
settings.setValue( "/Plugin-Globe/screenDistance", screenDistance->value() );
}
@@ -30,16 +30,22 @@ class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBa
public:
QgsGlobePluginDialog( QWidget * parent = 0, Qt::WFlags fl = 0 );
~QgsGlobePluginDialog();
QString stereoMode;

private:
QString earthFile;
QString openFile();
QSettings settings;
void setStereoMode();
void restartGlobe();
bool globeRunning();
void showMessageBox( QString text);
//! Init dialog from osg/DisplaySettings
void getStereoConfig();
//! Set osg/DisplaySettings
void setStereoConfig();
//! Init dialog from settings
void loadStereoConfig();
//! Save settings
void saveStereoConfig();

private slots:
void on_buttonBox_accepted();
@@ -34,7 +34,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="elevation">
<attribute name="title">
@@ -212,15 +212,15 @@
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>SCREEN_DISTANCE</string>
<string>Screen distance</string>
</property>
<property name="buddy">
<cstring>xxxx</cstring>
<cstring>screenDistance</cstring>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QDoubleSpinBox" name="xxxx"/>
<widget class="QDoubleSpinBox" name="screenDistance"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
@@ -28,7 +28,6 @@ QgsGLWidgetAdapter::QgsGLWidgetAdapter( QWidget * parent, const char * name, con
QGLWidget(parent, shareWidget, f)
{
_gw = new osgViewer::GraphicsWindowEmbedded(0,0,width(),height());
setStereoMode();
setFocusPolicy(Qt::ClickFocus);
setMouseTracking ( true );
}
@@ -86,46 +85,3 @@ void QgsGLWidgetAdapter::wheelEvent(QWheelEvent *event)
{
_gw->getEventQueue()->mouseScroll((event->delta()>0) ? osgGA::GUIEventAdapter::SCROLL_DOWN : osgGA::GUIEventAdapter::SCROLL_UP);
}

void QgsGLWidgetAdapter::setStereoMode()
{
setStereoMode(settings.value( "/Plugin-Globe/stereoMode", "OFF" ).toString());
}

void QgsGLWidgetAdapter::setStereoMode(QString stereoMode)
{
settings.setValue( "/Plugin-Globe/stereoMode", stereoMode );
if("OFF" == stereoMode)
{
osg::DisplaySettings::instance()->setStereo( false );
}
else
{
osg::DisplaySettings::instance()->setStereo( true );

if("ANAGLYPHIC" == stereoMode)
{
osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::ANAGLYPHIC );
}
else if("VERTICAL_SPLIT" == stereoMode)
{
osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::VERTICAL_SPLIT );
}
else if("HORIZONTAL_SPLIT" == stereoMode)
{
osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::HORIZONTAL_SPLIT );
}
else if("QUAD_BUFFER" == stereoMode)
{
osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::QUAD_BUFFER );
}
else
{
//should never get here
settings.setValue( "/Plugin-Globe/stereoMode", "ANAGLYPHIC" );
QMessageBox msgBox;
msgBox.setText("This stereo mode has not been implemented yet. Defaulting to ANAGLYPHIC");
msgBox.exec();
}
}
}
@@ -20,12 +20,10 @@
#define QGS_OSG_VIEWER_H

#include <osgViewer/Viewer>
#include <osgViewer/CompositeViewer>

#include <QtOpenGL/QGLWidget>
#include <QtGui/QKeyEvent>
#include <QtCore/QTimer>
#include <QSettings>

using Qt::WindowFlags;

@@ -39,9 +37,6 @@ class QgsGLWidgetAdapter : public QGLWidget

osgViewer::GraphicsWindow* getGraphicsWindow() { return _gw.get(); }
const osgViewer::GraphicsWindow* getGraphicsWindow() const { return _gw.get(); }

void setStereoMode();
void setStereoMode(QString stereoMode);

protected:

@@ -56,9 +51,6 @@ class QgsGLWidgetAdapter : public QGLWidget

osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> _gw;

private:

QSettings settings;
};


0 comments on commit cb65937

Please sign in to comment.
You can’t perform that action at this time.