From 34737b642ee0e4a151d4f3925eb135354567990d Mon Sep 17 00:00:00 2001 From: ana Date: Wed, 12 May 2010 12:02:00 +0000 Subject: [PATCH] Implement icons for slider preference item --- src/Qtx/QtxPagePrefMgr.cxx | 91 +++++++++++++++++++++++++++++++++++++- src/Qtx/QtxPagePrefMgr.h | 12 ++++- 2 files changed, 100 insertions(+), 3 deletions(-) diff --git a/src/Qtx/QtxPagePrefMgr.cxx b/src/Qtx/QtxPagePrefMgr.cxx index e19f581c7..98940ab20 100644 --- a/src/Qtx/QtxPagePrefMgr.cxx +++ b/src/Qtx/QtxPagePrefMgr.cxx @@ -2228,8 +2228,16 @@ QtxPagePrefSliderItem::QtxPagePrefSliderItem( const QString& title, QtxPreferenc : QtxPageNamedPrefItem( title, parent, sect, param ) { setControl( mySlider = new QSlider( Qt::Horizontal ) ); + widget()->layout()->addWidget( myLabel = new QLabel( ) ); + + setMinimum( 0 ); + setMaximum( 0 ); + setSingleStep( 1 ); + setPageStep( 1 ); + mySlider->setTickPosition( QSlider::TicksBothSides ); - + + connect (mySlider, SIGNAL(valueChanged(int)), this, SLOT(setIcon(int))); updateSlider(); } @@ -2280,6 +2288,16 @@ int QtxPagePrefSliderItem::maximum() const return mySlider->maximum(); } +/*! + \brief Get the list of the icons associated with the selection widget items + \return list of icons + \sa setIcons() +*/ +QList QtxPagePrefSliderItem::icons() const +{ + return myIcons; +} + /*! \brief Set slider preference item step value. \param step new slider single step value @@ -2308,16 +2326,39 @@ void QtxPagePrefSliderItem::setPageStep( const int& step ) void QtxPagePrefSliderItem::setMinimum( const int& min ) { mySlider->setMinimum( min ); + setIcon( mySlider->value() ); } /*! \brief Set slider preference item maximum value. - \param min new slider maximum value + \param max new slider maximum value \sa maximum() */ void QtxPagePrefSliderItem::setMaximum( const int& max ) { mySlider->setMaximum( max ); + setIcon( mySlider->value() ); +} + +/*! + \brief Set the list of the icons to the selection widget items + \param icns new list of icons + \sa icons() +*/ +void QtxPagePrefSliderItem::setIcons( const QList& icns ) +{ + if ( icns.isEmpty() ) + return; + myIcons = icns; + + QSize maxsize(0, 0); + for ( QList::const_iterator it = myIcons.begin(); it != myIcons.end(); ++it ) { + if ( (*it).isNull() ) continue; + maxsize = maxsize.expandedTo( (*it).availableSizes().first() ); + } + myLabel->setFixedSize( maxsize ); + + updateSlider(); } /*! @@ -2354,6 +2395,14 @@ QVariant QtxPagePrefSliderItem::optionValue( const QString& name ) const return singleStep(); else if ( name == "page_step" ) return pageStep(); + else if ( name == "icons" || name == "pixmaps" ) + { + QList lst; + QList ics = icons(); + for ( QList::const_iterator it = ics.begin(); it != ics.end(); ++it ) + lst.append( *it ); + return lst; + } else return QtxPageNamedPrefItem::optionValue( name ); } @@ -2379,10 +2428,21 @@ void QtxPagePrefSliderItem::setOptionValue( const QString& name, const QVariant& else QtxPageNamedPrefItem::setOptionValue( name, val ); } + else if ( name == "icons" || name == "pixmaps" ) + setIcons( val ); else QtxPageNamedPrefItem::setOptionValue( name, val ); } +void QtxPagePrefSliderItem::setIcon( int pos ) +{ + int index = pos - mySlider->minimum(); + if ( !myIcons.isEmpty() && index >= 0 && index < myIcons.size() && !myIcons[index].isNull() ) + myLabel->setPixmap( myIcons[index].pixmap( myIcons[index].availableSizes().first() ) ); + else + myLabel->clear(); +} + /*! \brief Update slider widget. */ @@ -2402,6 +2462,33 @@ void QtxPagePrefSliderItem::updateSlider() setPageStep( ptp ); setMinimum( min ); setMaximum( max ); + + myLabel->setVisible( !myIcons.empty() ); + widget()->layout()->setSpacing( !myIcons.empty() ? 6 : 0 ); +} + +/*! + \brief Set the list of the icons from the resource manager. + \param var new icons list + \internal +*/ +void QtxPagePrefSliderItem::setIcons( const QVariant& var ) +{ + if ( var.type() != QVariant::List ) + return; + + QList lst; + QList varList = var.toList(); + for ( QList::const_iterator it = varList.begin(); it != varList.end(); ++it ) + { + if ( (*it).canConvert() ) + lst.append( (*it).value() ); + else if ( (*it).canConvert() ) + lst.append( (*it).value() ); + else + lst.append( QIcon() ); + } + setIcons( lst ); } /*! diff --git a/src/Qtx/QtxPagePrefMgr.h b/src/Qtx/QtxPagePrefMgr.h index 25ec149b9..5501fdf23 100644 --- a/src/Qtx/QtxPagePrefMgr.h +++ b/src/Qtx/QtxPagePrefMgr.h @@ -417,8 +417,10 @@ private: QLineEdit* myEditor; }; -class QTX_EXPORT QtxPagePrefSliderItem : public QtxPageNamedPrefItem +class QTX_EXPORT QtxPagePrefSliderItem : public QObject,public QtxPageNamedPrefItem { + Q_OBJECT + public: QtxPagePrefSliderItem( const QString&, QtxPreferenceItem* = 0, const QString& = QString(), const QString& = QString() ); @@ -428,11 +430,13 @@ public: int pageStep() const; int minimum() const; int maximum() const; + QList icons() const; void setSingleStep( const int& ); void setPageStep( const int& ); void setMinimum( const int& ); void setMaximum( const int& ); + void setIcons( const QList& ); virtual void store(); virtual void retrieve(); @@ -441,11 +445,17 @@ protected: virtual QVariant optionValue( const QString& ) const; virtual void setOptionValue( const QString&, const QVariant& ); +private slots: + void setIcon( int ); + private: void updateSlider(); + void setIcons( const QVariant& ); private: QSlider* mySlider; + QLabel* myLabel; + QList myIcons; }; class QTX_EXPORT QtxPagePrefSelectItem : public QtxPageNamedPrefItem -- 2.39.2