From dd7cae4e370972ed616a14b9c291f2df39c1b3d2 Mon Sep 17 00:00:00 2001 From: Stephane Albert <stephane.albert@c-s.fr> Date: Wed, 4 Mar 2015 18:19:11 +0100 Subject: [PATCH] ENH: Implemented ShaderWidget; refined ImageSettings. --- .../Common/Core/mvdImageSettingsInterface.cxx | 9 ++ Code/Common/Core/mvdImageSettingsInterface.h | 2 + Code/Common/Gui/mvdShaderWidget.cxx | 86 ++++++++++++++++++- Code/Common/Gui/mvdShaderWidget.h | 18 +++- Code/Common/Gui/mvdShaderWidget.ui | 66 +++++--------- 5 files changed, 134 insertions(+), 47 deletions(-) diff --git a/Code/Common/Core/mvdImageSettingsInterface.cxx b/Code/Common/Core/mvdImageSettingsInterface.cxx index 98c0e41361..2cc84d8473 100644 --- a/Code/Common/Core/mvdImageSettingsInterface.cxx +++ b/Code/Common/Core/mvdImageSettingsInterface.cxx @@ -87,6 +87,15 @@ ImageSettingsInterface { delete m_Settings; m_Settings = settings; + + virtual_SetSettings( settings ); +} + +/*****************************************************************************/ +void +ImageSettingsInterface +::virtual_SetSettings( ImageSettings * ) +{ } /*****************************************************************************/ diff --git a/Code/Common/Core/mvdImageSettingsInterface.h b/Code/Common/Core/mvdImageSettingsInterface.h index 04977aae44..d0e087a2bb 100644 --- a/Code/Common/Core/mvdImageSettingsInterface.h +++ b/Code/Common/Core/mvdImageSettingsInterface.h @@ -117,6 +117,8 @@ private: /** */ void SetSettings( ImageSettings * ); + /** */ + virtual void virtual_SetSettings( ImageSettings * ); // // Private attributes. diff --git a/Code/Common/Gui/mvdShaderWidget.cxx b/Code/Common/Gui/mvdShaderWidget.cxx index 50aee505cb..7abb69d0e1 100644 --- a/Code/Common/Gui/mvdShaderWidget.cxx +++ b/Code/Common/Gui/mvdShaderWidget.cxx @@ -29,6 +29,7 @@ // // System includes (sorted by alphabetic order) +#include <cassert> // // ITK includes (sorted by alphabetic order) @@ -38,6 +39,9 @@ // // Monteverdi includes (sorted by alphabetic order) +#include "Core/mvdAlgorithm.h" +#include "Core/mvdImageSettings.h" + namespace mvd { @@ -66,9 +70,17 @@ namespace mvd ShaderWidget ::ShaderWidget( QWidget * parent, Qt::WindowFlags flags ): QWidget( parent, flags ), - m_UI( new mvd::Ui::ShaderWidget() ) + m_UI( new mvd::Ui::ShaderWidget() ), + m_Settings( NULL ) { m_UI->setupUi( this ); + + for( int i=0; i<ImageSettings::EFFECT_COUNT; ++i ) + m_UI->effectComboBox->addItem( ImageSettings::EFFECT_NAME[ i ] ); + + m_UI->valueLineEdit->setValidator( + new QDoubleValidator( m_UI->valueLineEdit ) + ); } /*******************************************************************************/ @@ -79,8 +91,80 @@ ShaderWidget m_UI = NULL; } +/*******************************************************************************/ +void +ShaderWidget +::virtual_SetSettings( ImageSettings * settings ) +{ + assert( m_UI!=NULL ); + + m_UI->effectComboBox->setEnabled( settings!=NULL ); + m_UI->sizeLabel->setEnabled( settings!=NULL ); + m_UI->sizeSpinBox->setEnabled( settings!=NULL && settings->HasSize() ); + m_UI->valueLabel->setEnabled( settings!=NULL ); + m_UI->valueLineEdit->setEnabled( settings!=NULL && settings->HasValue() ); + + if( settings!=NULL ) + { + for( int i=0; i<m_UI->effectComboBox->count(); ++i ) + if( QString::compare( ImageSettings::EFFECT_NAME[ i ], + m_UI->effectComboBox->itemText( i ) )==0 ) + { + m_UI->effectComboBox->setCurrentIndex( i ); + + break; + } + + m_UI->sizeSpinBox->setValue( settings->GetSize() ); + m_UI->valueLineEdit->setText( ToQString( settings->GetValue() ) ); + } +} + /*******************************************************************************/ /* SLOTS */ /*******************************************************************************/ +void +ShaderWidget +::on_effectComboBox_currentIndexChanged( const QString & text ) +{ + for( int i=0; i<ImageSettings::EFFECT_COUNT; ++i ) + if( QString::compare( text, ImageSettings::EFFECT_NAME[ i ] )==0 ) + { + assert( m_Settings!=NULL ); + + m_Settings->SetEffect( static_cast< ImageSettings::Effect >( i ) ); + + m_UI->sizeSpinBox->setEnabled( m_Settings->HasSize() ); + m_UI->valueLineEdit->setEnabled( m_Settings->HasValue() ); + + return; + } +} + +/*******************************************************************************/ +void +ShaderWidget +::on_sizeSpinBox_valueChanged( int value ) +{ + assert( m_Settings!=NULL ); + assert( m_Settings->HasSize() ); + + m_Settings->SetSize( value ); +} + +/*******************************************************************************/ +void +ShaderWidget +::on_valueLineEdit_textChanged( const QString & text ) +{ + assert( m_Settings!=NULL ); + assert( m_Settings->HasValue() ); + + bool isOk = true; + + m_Settings->SetValue( text.toDouble( &isOk ) ); + + assert( isOk ); +} } // end namespace 'mvd' diff --git a/Code/Common/Gui/mvdShaderWidget.h b/Code/Common/Gui/mvdShaderWidget.h index e4b55e63f0..9ffada5ed5 100644 --- a/Code/Common/Gui/mvdShaderWidget.h +++ b/Code/Common/Gui/mvdShaderWidget.h @@ -44,6 +44,7 @@ // // Monteverdi includes (sorted by alphabetic order) +#include "Core/mvdImageSettingsInterface.h" /*****************************************************************************/ @@ -65,6 +66,7 @@ namespace Ui class ShaderWidget; }; +class ImageSettings; /*****************************************************************************/ /* CLASS DEFINITION SECTION */ @@ -76,7 +78,8 @@ class ShaderWidget; * widget class. */ class Monteverdi2_EXPORT ShaderWidget : - public QWidget + public QWidget, + public ImageSettingsInterface { /*-[ QOBJECT SECTION ]-----------------------------------------------------*/ @@ -95,6 +98,10 @@ public: /** \brief Destructor. */ virtual ~ShaderWidget(); + /** + */ + void SetSettings( ImageSettings ); + /*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/ // @@ -123,6 +130,9 @@ protected: // Private methods. private: + /** */ + virtual void virtual_SetSettings( ImageSettings * ); + // // Private attributes. private: @@ -131,11 +141,17 @@ private: */ Ui::ShaderWidget * m_UI; + /** */ + ImageSettings * m_Settings; + /*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/ // // Slots. private slots: + void on_effectComboBox_currentIndexChanged( const QString & ); + void on_sizeSpinBox_valueChanged( int ); + void on_valueLineEdit_textChanged( const QString & ); }; } // end namespace 'mvd' diff --git a/Code/Common/Gui/mvdShaderWidget.ui b/Code/Common/Gui/mvdShaderWidget.ui index cb1fa50505..7bdfc6e1d1 100644 --- a/Code/Common/Gui/mvdShaderWidget.ui +++ b/Code/Common/Gui/mvdShaderWidget.ui @@ -21,75 +21,51 @@ <number>1</number> </property> <item> - <widget class="QComboBox" name="comboBox"> + <widget class="QComboBox" name="effectComboBox"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="insertPolicy"> <enum>QComboBox::InsertAlphabetically</enum> </property> - <item> - <property name="text"> - <string>Chessboard</string> - </property> - </item> - <item> - <property name="text"> - <string>Gradient</string> - </property> - </item> - <item> - <property name="text"> - <string>Local constrast</string> - </property> - </item> - <item> - <property name="text"> - <string>Local translucency</string> - </property> - </item> - <item> - <property name="text"> - <string>Normal</string> - </property> - </item> - <item> - <property name="text"> - <string>Spectral angle</string> - </property> - </item> - <item> - <property name="text"> - <string>Swipe (horizontal)</string> - </property> - </item> - <item> - <property name="text"> - <string>Swipe (vertical)</string> - </property> - </item> </widget> </item> <item> - <widget class="QLabel" name="label"> + <widget class="QLabel" name="sizeLabel"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="text"> <string>Size:</string> </property> </widget> </item> <item> - <widget class="QSpinBox" name="spinBox"> + <widget class="QSpinBox" name="sizeSpinBox"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="value"> <number>16</number> </property> </widget> </item> <item> - <widget class="QLabel" name="label_2"> + <widget class="QLabel" name="valueLabel"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="text"> <string>Value:</string> </property> </widget> </item> <item> - <widget class="QLineEdit" name="lineEdit"/> + <widget class="QLineEdit" name="valueLineEdit"> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> </item> </layout> </widget> -- GitLab