Skip to content

Commit

Permalink
Added runtime stereo selection to settings dialog and at plugin start
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Bernasocchi authored and pka committed Jul 5, 2011
1 parent 55e7f21 commit d571f0f
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 41 deletions.
105 changes: 74 additions & 31 deletions src/plugins/globe/globe_plugin_dialog.cpp
Expand Up @@ -31,11 +31,18 @@
#include <QStringList>
#include <QVariant>

#include <osgViewer/Viewer>

//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 ) );

earthFile = settings.value( "/Plugin-Globe/earthFile", QgsApplication::pkgDataPath() + "/globe/globe.earth" ).toString();
inputEarthFile->setText( earthFile );
}

//destructor
Expand All @@ -44,19 +51,64 @@ QgsGlobePluginDialog::~QgsGlobePluginDialog()
}

QString QgsGlobePluginDialog::openFile()
{
QSettings sets;
{
QString path = QFileDialog::getOpenFileName( this,
tr( "Open Earthfile" ),
"/home",
tr( "Earthfiles (*.earth)" ) );
tr( "Open earth file" ),
earthFile,
tr( "Earth files (*.earth)" ) );

return path;
}

void QgsGlobePluginDialog::setStereoMode()
{
if("OFF" == stereoMode)
{
osg::DisplaySettings::instance()->setStereo( false );
}
else if("ADVANCED" == stereoMode)
{
//osg::DisplaySettings::instance()->set
}
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
{
showMessageBox("This stereo mode has not been implemented yet. Defaulting to ANAGLYPHIC");
}
}
}

void QgsGlobePluginDialog::setEarthFile()
{
showMessageBox("TODO: set earth file to " + earthFile);
}

void QgsGlobePluginDialog::restartGlobe()
{
//showMessageBox("TODO: restart globe");
}

bool QgsGlobePluginDialog::globeRunning()
{
//TODO: method that tells if the globe plugin is running
return true;
}

void QgsGlobePluginDialog::on_buttonBox_accepted()
{
/*
*
// Validate input settings
QString srcUrl( inputSrcDataset->text() );
QString srcLayer( comboSrcLayer->currentText() );
Expand Down Expand Up @@ -138,6 +190,13 @@ void QgsGlobePluginDialog::on_buttonBox_accepted()
// Close dialog box
*/
setStereoMode();
setEarthFile();

if ( globeRunning() )
{
restartGlobe();
}
accept();
}

Expand All @@ -146,48 +205,32 @@ void QgsGlobePluginDialog::on_buttonBox_rejected()
reject();
}

void QgsGlobePluginDialog::on_comboStereo_currentIndexChanged( int stereoMode )
void QgsGlobePluginDialog::on_comboStereoMode_currentIndexChanged( QString mode )
{
QMessageBox msgBox;
msgBox.setText("stereo mode changed");
msgBox.exec();
//showText("stereo mode changed");
/*
// Select destination data format
QString frmtCode = comboDstFormats->currentText();
mDstFormat = mFrmts.find( frmtCode );
resetDstUi();
*/
stereoMode = mode;
settings.setValue( "/Plugin-Globe/stereoMode", stereoMode );
}

void QgsGlobePluginDialog::on_buttonSelectEarthfile_clicked()
void QgsGlobePluginDialog::on_buttonSelectEarthFile_clicked()
{
QMessageBox msgBox;
msgBox.setText("select file");
msgBox.exec();
/*
QSettings settings;
QString src;

src = openFile();

inputSrcDataset->setText( src );
inputEarthFile->setText( src );

if ( !src.isEmpty() )
{
QMessageBox msgBox;
msgBox.setText(src);
msgBox.exec();
//showText( src.toString() );
earthFile = src;
settings.setValue( "/Plugin-Globe/earthFile", earthFile );
}
*/

}

/*void QgsGlobePluginDialog::showText(QString text)
void QgsGlobePluginDialog::showMessageBox( QString text )
{
QMessageBox msgBox;
msgBox.setText(text);
msgBox.exec();
}
*/

14 changes: 11 additions & 3 deletions src/plugins/globe/globe_plugin_dialog.h
Expand Up @@ -20,6 +20,7 @@

#include <ui_globe_plugin_dialog_guibase.h>
#include <QDialog>
#include <QSettings>
#include "qgscontexthelp.h"

class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBase
Expand All @@ -31,14 +32,21 @@ class QgsGlobePluginDialog:public QDialog, private Ui::QgsGlobePluginDialogGuiBa
~QgsGlobePluginDialog();

private:
QString stereoMode;
QString earthFile;
QString openFile();
void showText( int text);
QSettings settings;
void setStereoMode();
void setEarthFile();
void restartGlobe();
bool globeRunning();
void showMessageBox( QString text);

private slots:
void on_buttonBox_accepted();
void on_buttonBox_rejected();
void on_buttonSelectEarthfile_clicked();
void on_comboStereo_currentIndexChanged( int stereoMode );
void on_buttonSelectEarthFile_clicked();
void on_comboStereoMode_currentIndexChanged( QString mode );
};

#endif // QGIS_GLOBE_PLUGIN_DIALOG_H
14 changes: 7 additions & 7 deletions src/plugins/globe/globe_plugin_dialog_guibase.ui
Expand Up @@ -44,7 +44,7 @@
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLineEdit" name="inputEarthfileDataset">
<widget class="QLineEdit" name="inputEarthFile">
<property name="minimumSize">
<size>
<width>200</width>
Expand All @@ -54,7 +54,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="buttonSelectEarthfile">
<widget class="QPushButton" name="buttonSelectEarthFile">
<property name="text">
<string>Browse</string>
</property>
Expand All @@ -76,7 +76,7 @@
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0" colspan="2">
<widget class="QComboBox" name="comboStereo">
<widget class="QComboBox" name="comboStereoMode">
<property name="minimumSize">
<size>
<width>300</width>
Expand All @@ -98,7 +98,7 @@
</item>
<item>
<property name="text">
<string>CHECKERBOARD</string>
<string>VERTICAL_SPLIT</string>
</property>
</item>
</widget>
Expand All @@ -117,9 +117,9 @@
</widget>
<layoutdefault spacing="6" margin="11"/>
<tabstops>
<tabstop>inputEarthfileDataset</tabstop>
<tabstop>buttonSelectEarthfile</tabstop>
<tabstop>comboStereo</tabstop>
<tabstop>inputEarthFile</tabstop>
<tabstop>buttonSelectEarthFile</tabstop>
<tabstop>comboStereoMode</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
Expand Down
39 changes: 39 additions & 0 deletions src/plugins/globe/qgsosgviewer.cpp
Expand Up @@ -20,11 +20,13 @@

#include <osgViewer/ViewerEventHandlers>

#include <QString>

QgsGLWidgetAdapter::QgsGLWidgetAdapter( QWidget * parent, const char * name, const QGLWidget * shareWidget, WindowFlags f):
QGLWidget(parent, shareWidget, f)
{
_gw = new osgViewer::GraphicsWindowEmbedded(0,0,width(),height());
setStereoMode();
setFocusPolicy(Qt::ClickFocus);
setMouseTracking ( true );
}
Expand Down Expand Up @@ -82,3 +84,40 @@ void QgsGLWidgetAdapter::wheelEvent(QWheelEvent *event)
{
_gw->getEventQueue()->mouseScroll((event->delta()>0) ? osgGA::GUIEventAdapter::SCROLL_DOWN : osgGA::GUIEventAdapter::SCROLL_UP);
}

void QgsGLWidgetAdapter::setStereoMode()
{
//TODO: maybe consolidate this method somewhere else since it is repeated in globe_plugin_dialog.cpp

//osg::DisplaySettings::instance()->setStereo( (bool) settings.value( "/Plugin-Globe/stereo", 0 ).toInt() );
//osg::DisplaySettings::instance()->setStereoMode( (osg::DisplaySettings::StereoMode) settings.value( "/Plugin-Globe/stereoMode", 1 ).toInt());

QString stereoMode;
stereoMode = settings.value( "/Plugin-Globe/stereoMode", "OFF" ).toString();

if("OFF" == stereoMode)
{
osg::DisplaySettings::instance()->setStereo( false );
}
else if("ADVANCED" == stereoMode)
{
//osg::DisplaySettings::instance()->set
}
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
{
//should never get here
}
}
}
6 changes: 6 additions & 0 deletions src/plugins/globe/qgsosgviewer.h
Expand Up @@ -25,6 +25,7 @@
#include <QtOpenGL/QGLWidget>
#include <QtGui/QKeyEvent>
#include <QtCore/QTimer>
#include <QSettings>

using Qt::WindowFlags;

Expand All @@ -51,6 +52,11 @@ class QgsGLWidgetAdapter : public QGLWidget
virtual void wheelEvent( QWheelEvent * event );

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

private:

QSettings settings;
void setStereoMode();
};


Expand Down

0 comments on commit d571f0f

Please sign in to comment.