: 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();
}
return mySlider->maximum();
}
+/*!
+ \brief Get the list of the icons associated with the selection widget items
+ \return list of icons
+ \sa setIcons()
+*/
+QList<QIcon> QtxPagePrefSliderItem::icons() const
+{
+ return myIcons;
+}
+
/*!
\brief Set slider preference item step value.
\param step new slider single step value
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<QIcon>& icns )
+{
+ if ( icns.isEmpty() )
+ return;
+ myIcons = icns;
+
+ QSize maxsize(0, 0);
+ for ( QList<QIcon>::const_iterator it = myIcons.begin(); it != myIcons.end(); ++it ) {
+ if ( (*it).isNull() ) continue;
+ maxsize = maxsize.expandedTo( (*it).availableSizes().first() );
+ }
+ myLabel->setFixedSize( maxsize );
+
+ updateSlider();
}
/*!
return singleStep();
else if ( name == "page_step" )
return pageStep();
+ else if ( name == "icons" || name == "pixmaps" )
+ {
+ QList<QVariant> lst;
+ QList<QIcon> ics = icons();
+ for ( QList<QIcon>::const_iterator it = ics.begin(); it != ics.end(); ++it )
+ lst.append( *it );
+ return lst;
+ }
else
return QtxPageNamedPrefItem::optionValue( name );
}
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.
*/
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<QIcon> lst;
+ QList<QVariant> varList = var.toList();
+ for ( QList<QVariant>::const_iterator it = varList.begin(); it != varList.end(); ++it )
+ {
+ if ( (*it).canConvert<QIcon>() )
+ lst.append( (*it).value<QIcon>() );
+ else if ( (*it).canConvert<QPixmap>() )
+ lst.append( (*it).value<QPixmap>() );
+ else
+ lst.append( QIcon() );
+ }
+ setIcons( lst );
}
/*!
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() );
int pageStep() const;
int minimum() const;
int maximum() const;
+ QList<QIcon> icons() const;
void setSingleStep( const int& );
void setPageStep( const int& );
void setMinimum( const int& );
void setMaximum( const int& );
+ void setIcons( const QList<QIcon>& );
virtual void store();
virtual void retrieve();
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<QIcon> myIcons;
};
class QTX_EXPORT QtxPagePrefSelectItem : public QtxPageNamedPrefItem