Commit 1d8c70c3 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE #312] merged different options of WGEViewer into properties for a more unified interface.

parent 29e255c8
......@@ -112,6 +112,24 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int
// add the stats handler
m_View->addEventHandler( new osgViewer::StatsHandler );
// Properties of the view. Collects props of the effects and similar
m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "The view's properties" ) );
m_bgColor = m_properties->addProperty( "Background Color", "Default background color if not overwritten by a camera effect.",
defaultColor::WHITE,
boost::bind( &WGEViewer::updateBgColor, this ) );
m_throwing = m_properties->addProperty( "Throwing", "If checked, you can grab the scene and throw it. It will keep the rotation impulse.",
false,
boost::bind( &WGEViewer::updateThrowing, this ) );
WPropGroup effects = m_properties->addPropertyGroup( "Camera Effects", "Several effects that to not depend on any scene content." );
effects->addProperty( m_effectHorizon->getProperties() );
effects->addProperty( m_effectVignette->getProperties() );
effects->addProperty( m_effectImageOverlay->getProperties() );
// apply the above default
updateThrowing();
updateBgColor();
}
catch( ... )
{
......@@ -175,9 +193,28 @@ osg::ref_ptr< WGEGroupNode > WGEViewer::getScene()
return m_scene;
}
void WGEViewer::updateThrowing()
{
WGEZoomTrackballManipulator* manipulator = dynamic_cast< WGEZoomTrackballManipulator* >( getCameraManipulator().get() );
if( manipulator )
{
manipulator->setThrow( m_throwing->get() );
}
}
void WGEViewer::updateBgColor()
{
m_View->getCamera()->setClearColor( m_bgColor->get() );
}
void WGEViewer::setBgColor( const WColor& bgColor )
{
m_View->getCamera()->setClearColor( bgColor );
m_bgColor->set( bgColor );
}
WColor WGEViewer::getBgColor() const
{
return m_bgColor->get();
}
void WGEViewer::paint()
......@@ -331,3 +368,8 @@ WGEViewerEffectVignette::ConstSPtr WGEViewer::getVignette() const
{
return m_effectVignette;
}
WProperties::SPtr WGEViewer::getProperties() const
{
return m_properties;
}
......@@ -194,6 +194,13 @@ public:
*/
void setBgColor( const WColor& bgColor );
/**
* Returns the current default background color. This color is only visible if no camera effect overrides it.
*
* \return The color.
*/
WColor getBgColor() const;
/**
* Getter for the pick handler
*
......@@ -286,6 +293,13 @@ public:
*/
WGEViewerEffectVignette::ConstSPtr getVignette() const;
/**
* Return a pointer to the properties object of the view.
*
* \return the properties.
*/
WProperties::SPtr getProperties() const;
protected:
/**
* The OpenSceneGraph view used in this (Composite)Viewer.
......@@ -401,7 +415,31 @@ protected:
* Image overlay effect.
*/
WGEViewerEffectImageOverlay::SPtr m_effectImageOverlay;
/**
* The property object for the view.
*/
WProperties::SPtr m_properties;
private:
/**
* The default clear color (bg color).
*/
WPropColor m_bgColor;
/**
* The switch to enable the throw- functionality of some OSG manipulators.
*/
WPropBool m_throwing;
/**
* Update the default clear color (bg color). Called by the m_bgColor property.
*/
void updateBgColor();
/**
* Update throw setting of the manipulator (if supported).
*/
void updateThrowing();
};
#endif // WGEVIEWER_H
......@@ -83,7 +83,7 @@ public:
*/
boost::shared_ptr< WGEViewer > createViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int x, int y,
int width, int height, WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC,
WColor bgColor = WColor( 0.9, 0.9, 0.9, 1.0 ) );
WColor bgColor = WColor( 1.0, 1.0, 1.0, 1.0 ) );
/**
* Closes a viewer and deletes it from the list of viewers.
......
......@@ -76,15 +76,8 @@ WQtGLDockWidget::WQtGLDockWidget( QString viewTitle, QString dockTitle, QWidget*
// all view docks have a screen capture object
m_screenCapture = new WQtGLScreenCapture( this );
// get the viewer background effect
WGEViewerEffect::SPtr bkEffect = m_glWidget->getViewer()->getBackground();
WGEViewerEffect::SPtr vignetteEffect = m_glWidget->getViewer()->getVignette();
WGEViewerEffect::SPtr overlayEffect = m_glWidget->getViewer()->getImageOverlay();
// create property widgets for each effect
QWidget* bkWidget = WQtPropertyGroupWidget::createPropertyGroupBox( bkEffect->getProperties() );
QWidget* vignetteWidget = WQtPropertyGroupWidget::createPropertyGroupBox( vignetteEffect->getProperties() );
QWidget* overlayWidget = WQtPropertyGroupWidget::createPropertyGroupBox( overlayEffect->getProperties() );
QWidget* viewPropsWidget = WQtPropertyGroupWidget::createPropertyGroupBox( m_glWidget->getViewer()->getProperties() );
// create container for all the config widgets
QWidget* viewConfigWidget = new QWidget();
......@@ -99,9 +92,7 @@ WQtGLDockWidget::WQtGLDockWidget( QString viewTitle, QString dockTitle, QWidget*
viewConfigWidget->setSizePolicy( sizePolicy );
// add the property widgets to container
viewConfigLayout->addWidget( bkWidget );
viewConfigLayout->addWidget( vignetteWidget );
viewConfigLayout->addWidget( overlayWidget );
viewConfigLayout->addWidget( viewPropsWidget );
// Create the toolbutton and the menu containing the config widgets
QWidgetAction* viewerConfigWidgetAction = new QWidgetAction( this );
......@@ -130,24 +121,10 @@ WQtGLDockWidget::WQtGLDockWidget( QString viewTitle, QString dockTitle, QWidget*
presetBtn->setMenu( getGLWidget()->getCameraPresetsMenu() );
presetBtn->setPopupMode( QToolButton::MenuButtonPopup );
QToolButton* settingsBtn = new QToolButton( parent );
settingsBtn->setPopupMode( QToolButton::InstantPopup );
settingsBtn->setIcon( WQt4Gui::getMainWindow()->getIconManager()->getIcon( "configure" ) );
settingsBtn->setToolTip( "Settings" );
QMenu* settingsMenu = new QMenu( parent );
settingsBtn->setMenu( settingsMenu );
// throwing
settingsMenu->addAction( getGLWidget()->getThrowingSetting() );
// change background color
settingsMenu->addAction( getGLWidget()->getBackgroundColorAction() );
// add them to the title
addTitleButton( screenShotBtn );
addTitleButton( presetBtn );
addTitleButton( viewerConfigBtn );
addTitleButton( settingsBtn );
}
WQtGLDockWidget::~WQtGLDockWidget()
......
......@@ -104,21 +104,6 @@ WQtGLWidget::WQtGLWidget( std::string nameOfViewer, QWidget* parent, WGECamera::
m_Viewer->isFrameRendered()->getCondition()->subscribeSignal( boost::bind( &WQtGLWidget::notifyFirstRenderedFrame, this ) );
// set bg color
updateViewerBackground();
// this action manages the above settings
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
m_allowThrowSetting = new WSettingAction( parent, std::string( "qt4gui/" ) + nameOfViewer + std::string( "/allowThrow" ),
"Camera Throwing",
"If enabled, the camera can be thrown. Try it by dragging the camera. "
"The camera then continues the movement.",
false );
connect( m_allowThrowSetting, SIGNAL( change( bool ) ), this, SLOT( updateThrowing() ) );
updateThrowing();
m_cameraResetAction = new QAction( WQt4Gui::getIconManager()->getIcon( "view" ), "Reset", this );
connect( m_cameraResetAction, SIGNAL( triggered( bool ) ), this, SLOT( reset() ) );
m_cameraResetAction->setToolTip( "Reset view" );
......@@ -408,42 +393,6 @@ const QGLFormat WQtGLWidget::getDefaultFormat()
return format;
}
void WQtGLWidget::updateThrowing()
{
WGEZoomTrackballManipulator* manipulator = dynamic_cast< WGEZoomTrackballManipulator* >( m_Viewer->getCameraManipulator().get() );
if( manipulator )
{
manipulator->setThrow( m_allowThrowSetting->get() );
}
}
WSettingAction* WQtGLWidget::getThrowingSetting() const
{
return m_allowThrowSetting;
}
QAction* WQtGLWidget::getBackgroundColorAction() const
{
return m_changeBGColorAction;
}
void WQtGLWidget::updateViewerBackground()
{
QColor bg = WMainWindow::getSettings().value( QString( "qt4gui/" ) + QString::fromStdString( m_nameOfViewer ) + QString( "/BGColor" ),
QColor( 255, 255, 255, 255 ) ).value< QColor >();
m_Viewer->setBgColor( WColor( bg.redF(), bg.greenF(), bg.blueF(), 1.0 ) );
}
void WQtGLWidget::changeBGColor()
{
QColor bgOld = WMainWindow::getSettings().value( QString( "qt4gui/" ) + QString::fromStdString( m_nameOfViewer ) + QString( "/BGColor" ),
QColor( 255, 255, 255, 255 ) ).value< QColor >();
QColor bg = QColorDialog::getColor( bgOld, this );
WMainWindow::getSettings().setValue( QString( "qt4gui/" ) + QString::fromStdString( m_nameOfViewer ) + QString( "/BGColor" ), bg );
updateViewerBackground();
}
void WQtGLWidget::notifyFirstRenderedFrame()
{
QCoreApplication::postEvent( this, new WRenderedFrameEvent() );
......
......@@ -124,20 +124,6 @@ public:
*/
static const QGLFormat getDefaultFormat();
/**
* Returns the setting for throwing.
*
* \return the setting
*/
WSettingAction* getThrowingSetting() const;
/**
* Returns the action used to configure the background color of this widget.
*
* \return the action.
*/
QAction* getBackgroundColorAction() const;
/**
* The presets menu.
*
......@@ -335,16 +321,6 @@ private:
*/
bool m_firstPaint;
/**
* The setting specifying whether the viewer's camera can be thrown.
*/
WSettingAction* m_allowThrowSetting;
/**
* Action to trigger some colordialog for background-color-selection.
*/
QAction* m_changeBGColorAction;
/**
* Called by the WGEViewer to notify about the first frame rendered
*/
......@@ -364,22 +340,6 @@ private:
* Camera reset.
*/
QAction* m_cameraResetAction;
private slots:
/**
* Function to handle updates in the setting \ref m_allowThrowSetting.
*/
void updateThrowing();
/**
* Asks user for a new color for this widget.
*/
void changeBGColor();
/**
* Updates the color of this widget according to the current settings.
*/
void updateViewerBackground();
};
#endif // WQTGLWIDGET_H
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