From: adv Date: Mon, 29 Mar 2010 07:27:54 +0000 (+0000) Subject: Introduce slider preference item X-Git-Tag: V5_1_4a1~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7254f9dd0bb5f3406d0f2491e74d8e4a8681c75b;p=modules%2Fgui.git Introduce slider preference item --- diff --git a/src/Qtx/QtxPagePrefMgr.cxx b/src/Qtx/QtxPagePrefMgr.cxx index 6fb5b4359..674f59119 100644 --- a/src/Qtx/QtxPagePrefMgr.cxx +++ b/src/Qtx/QtxPagePrefMgr.cxx @@ -44,6 +44,7 @@ #include #include #include +#include #include @@ -2210,6 +2211,201 @@ void QtxPagePrefEditItem::updateEditor() myEditor->setValidator( val ); } +/*! + \class QtxPagePrefSliderItem +*/ + +/*! + \brief Constructor. + + Creates preference item with slider widget + + \param title preference item title + \param parent parent preference item + \param sect resource file section associated with the preference item + \param param resource file parameter associated with the preference item +*/ +QtxPagePrefSliderItem::QtxPagePrefSliderItem( const QString& title, QtxPreferenceItem* parent, + const QString& sect, const QString& param ) +: QtxPageNamedPrefItem( title, parent, sect, param ) +{ + setControl( mySlider = new QSlider( Qt::Horizontal ) ); + mySlider->setTickPosition( QSlider::TicksBothSides ); + + updateSlider(); +} + +/*! + \brief Destructor. +*/ +QtxPagePrefSliderItem::~QtxPagePrefSliderItem() +{ +} + +/*! + \brief Get slider preference item step value. + \return slider single step value + \sa setSingleStep() +*/ +int QtxPagePrefSliderItem::singleStep() const +{ + return mySlider->singleStep(); +} + +/*! + \brief Get slider preference item step value. + \return slider page step value + \sa setPageStep() +*/ +int QtxPagePrefSliderItem::pageStep() const +{ + return mySlider->pageStep(); +} + +/*! + \brief Get slider preference item minimum value. + \return slider minimum value + \sa setMinimum() +*/ +int QtxPagePrefSliderItem::minimum() const +{ + return mySlider->minimum(); +} + +/*! + \brief Get slider preference item maximum value. + \return slider maximum value + \sa setMaximum() +*/ +int QtxPagePrefSliderItem::maximum() const +{ + return mySlider->maximum(); +} + +/*! + \brief Set slider preference item step value. + \param step new slider single step value + \sa step() +*/ +void QtxPagePrefSliderItem::setSingleStep( const int& step ) +{ + mySlider->setSingleStep( step ); +} + +/*! + \brief Set slider preference item step value. + \param step new slider single step value + \sa step() +*/ +void QtxPagePrefSliderItem::setPageStep( const int& step ) +{ + mySlider->setPageStep( step ); +} + +/*! + \brief Set slider preference item minimum value. + \param min new slider minimum value + \sa minimum() +*/ +void QtxPagePrefSliderItem::setMinimum( const int& min ) +{ + mySlider->setMinimum( min ); +} + +/*! + \brief Set slider preference item maximum value. + \param min new slider maximum value + \sa maximum() +*/ +void QtxPagePrefSliderItem::setMaximum( const int& max ) +{ + mySlider->setMaximum( max ); +} + +/*! + \brief Store preference item to the resource manager. + \sa retrieve() +*/ +void QtxPagePrefSliderItem::store() +{ + setInteger( mySlider->value() ); +} + +/*! + \brief Retrieve preference item from the resource manager. + \sa store() +*/ +void QtxPagePrefSliderItem::retrieve() +{ + mySlider->setValue( getInteger( mySlider->value() ) ); +} + +/*! + \brief Get preference item option value. + \param name option name + \return property value or null integer if option is not set + \sa setOptionValue() +*/ +QVariant QtxPagePrefSliderItem::optionValue( const QString& name ) const +{ + if ( name == "minimum" || name == "min" ) + return minimum(); + else if ( name == "maximum" || name == "max" ) + return maximum(); + else if ( name == "single_step" ) + return singleStep(); + else if ( name == "page_step" ) + return pageStep(); + else + return QtxPageNamedPrefItem::optionValue( name ); +} + +/*! + \brief Set preference item option value. + \param name option name + \param val new property value + \sa optionValue() +*/ +void QtxPagePrefSliderItem::setOptionValue( const QString& name, const QVariant& val ) +{ + if ( val.canConvert( QVariant::Int ) ) + { + if ( name == "minimum" || name == "min" ) + setMinimum( val.toInt() ); + else if ( name == "maximum" || name == "max" ) + setMaximum( val.toInt() ); + else if ( name == "single_step" ) + setSingleStep( val.toInt() ); + else if ( name == "page_step" ) + setPageStep( val.toInt() ); + else + QtxPageNamedPrefItem::setOptionValue( name, val ); + } + else + QtxPageNamedPrefItem::setOptionValue( name, val ); +} + +/*! + \brief Update slider widget. +*/ +void QtxPagePrefSliderItem::updateSlider() +{ + int val = mySlider->value(); + int stp = singleStep(); + int ptp = pageStep(); + int min = minimum(); + int max = maximum(); + + control()->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); + mySlider->setFocusPolicy(Qt::StrongFocus); + + mySlider->setValue( val ); + setSingleStep( stp ); + setPageStep( ptp ); + setMinimum( min ); + setMaximum( max ); +} + /*! \class QtxPagePrefSelectItem \brief GUI implementation of the resources selector item diff --git a/src/Qtx/QtxPagePrefMgr.h b/src/Qtx/QtxPagePrefMgr.h index bbc634240..bd785c716 100644 --- a/src/Qtx/QtxPagePrefMgr.h +++ b/src/Qtx/QtxPagePrefMgr.h @@ -51,6 +51,7 @@ class QListWidget; class QFileDialog; class QDateTimeEdit; class QStackedWidget; +class QSlider; class QTX_EXPORT QtxPagePrefMgr : public QFrame, public QtxPreferenceMgr { @@ -418,6 +419,37 @@ private: QLineEdit* myEditor; }; +class QTX_EXPORT QtxPagePrefSliderItem : public QtxPageNamedPrefItem +{ +public: + QtxPagePrefSliderItem( const QString&, QtxPreferenceItem* = 0, + const QString& = QString(), const QString& = QString() ); + virtual ~QtxPagePrefSliderItem(); + + int singleStep() const; + int pageStep() const; + int minimum() const; + int maximum() const; + + void setSingleStep( const int& ); + void setPageStep( const int& ); + void setMinimum( const int& ); + void setMaximum( const int& ); + + virtual void store(); + virtual void retrieve(); + +protected: + virtual QVariant optionValue( const QString& ) const; + virtual void setOptionValue( const QString&, const QVariant& ); + +private: + void updateSlider(); + +private: + QSlider* mySlider; +}; + class QTX_EXPORT QtxPagePrefSelectItem : public QtxPageNamedPrefItem { public: diff --git a/src/SUIT/SUIT_PreferenceMgr.cxx b/src/SUIT/SUIT_PreferenceMgr.cxx index 512fdafa0..9d21a2fcf 100644 --- a/src/SUIT/SUIT_PreferenceMgr.cxx +++ b/src/SUIT/SUIT_PreferenceMgr.cxx @@ -132,6 +132,9 @@ int SUIT_PreferenceMgr::addItem( const QString& title, const int pId, case Integer: item = new QtxPagePrefEditItem( QtxPagePrefEditItem::Integer, title, parent, sect, param ); break; + case Slider: + item = new QtxPagePrefSliderItem( title, parent, sect, param ); + break; case GroupBox: item = new QtxPagePrefGroupItem( title, parent, sect, param ); break; diff --git a/src/SUIT/SUIT_PreferenceMgr.h b/src/SUIT/SUIT_PreferenceMgr.h index f6987252f..8c9458e3c 100644 --- a/src/SUIT/SUIT_PreferenceMgr.h +++ b/src/SUIT/SUIT_PreferenceMgr.h @@ -39,7 +39,7 @@ class SUIT_EXPORT SUIT_PreferenceMgr : public QtxPagePrefMgr public: typedef enum { Auto, Space, Bool, Color, String, Selector, DblSpin, IntSpin, Double, Integer, - GroupBox, Tab, Frame, Font, DirList, File } PrefItemType; + GroupBox, Tab, Frame, Font, DirList, File, Slider } PrefItemType; public: SUIT_PreferenceMgr( QtxResourceMgr*, QWidget* = 0 );