--- a/src/hbwidgets/sliders/hbprogressslider.cpp Mon Apr 19 14:02:13 2010 +0300
+++ b/src/hbwidgets/sliders/hbprogressslider.cpp Mon May 03 12:48:33 2010 +0300
@@ -26,9 +26,10 @@
#include <hbprogressslider.h>
#include "hbprogressslider_p.h"
-#include <hbstyleoptionprogressbar.h>
+#include <hbstyleoptionprogressslider.h>
#include <hbtooltip.h>
#include <hbwidgetfeedback.h>
+#include "hbglobal_p.h"
#include <QGraphicsSceneMouseEvent>
#include <QApplication>
@@ -41,14 +42,14 @@
HbProgressSliderPrivate::HbProgressSliderPrivate()
{
- downState=false;
+ mDownState=false;
handle = 0;
mSliderValue = 0;
thumbIcon = HbIcon();
state = HbProgressSlider::SliderStatePlayNormal;
+ mHandlePath = QString();
}
-
HbProgressSliderPrivate::~HbProgressSliderPrivate()
{
if (handle) {
@@ -56,18 +57,62 @@
}
}
+void HbProgressSliderPrivate::setProgressValue(int value)
+{
+ Q_Q(HbProgressSlider);
+ if (mProgressValue == value) {
+ return;
+ }
+ if (value >= mMaximum) {
+ value = mMaximum;
+#ifdef HB_EFFECTS
+ // HbEffect::start(mTrack, HB_PRGRESSSLIDER_ITEM_TYPE, "progressbar_progress_complete");
+#endif
+ }
+ else if (value < mMinimum) {
+ value = mMinimum;
+ }
+
+ mProgressValue=value;
+
+ //redraw track
+ HbStyleOptionProgressSlider sliderOption;
+ q->initStyleOption(&sliderOption);
+ if(mTrack) {
+ q->style()->updatePrimitive(mTrack, HbStyle::P_ProgressSlider_track, &sliderOption);
+ }
+
+ emit q->valueChanged(value);
+}
+
+void HbProgressSliderPrivate::setEnableFlag(bool flag)
+{
+ Q_Q(HbProgressSlider);
+ if(!flag) {
+ q->setProgressValue(q->minimum());
+ q->setSliderValue(q->minimum());
+ }
+}
void HbProgressSliderPrivate::init()
{
Q_Q(HbProgressSlider);
- mSliderGraphicItem = q->style()->createPrimitive(HbStyle::P_ProgressBar_slidertrack,mFrame);
- // Show the touch area which is created in ProgressBar//
- mTouchAreaItem = q->style()->createPrimitive(HbStyle::P_ProgressBar_toucharea,q);
- mFrame->setZValue(mTouchAreaItem->zValue()+1);
+
+ mSliderGraphicItem = q->style()->createPrimitive(HbStyle::P_ProgressSlider_slidertrack,mFrame);
+ // Show the touch area which is created in ProgressBar//
+ mTouchAreaItem = q->style()->createPrimitive(HbStyle::P_ProgressSlider_toucharea,q);
+ mFrame->setZValue(mTouchAreaItem->zValue()+1);
+
#ifdef HB_EFFECTS
HbEffectInternal::add(HB_PRGRESSSLIDER_ITEM_TYPE,"progressslider_trackpress", "progressslider_trackpress");
HbEffectInternal::add(HB_PRGRESSSLIDER_ITEM_TYPE,"progressslider_trackrelease", "progressslider_trackrelease");
#endif
+
+ q->grabGesture(Qt::TapGesture);
+
+ if(QGraphicsObject *touchArea = mTouchAreaItem->toGraphicsObject()) {
+ touchArea->grabGesture(Qt::TapGesture);
+ }
}
void HbProgressSliderPrivate::emitSliderPressed()
@@ -76,7 +121,6 @@
emit q->sliderPressed();
}
-
void HbProgressSliderPrivate::emitSliderReleased()
{
Q_Q(HbProgressSlider);
@@ -152,18 +196,6 @@
return mOrientation;
}
-void HbProgressSliderPrivate::updateMaskWidth(qreal width)
-{
- Q_Q( HbProgressSlider );
- HbStyleOptionProgressBar progressBarOption;
- q->initStyleOption(&progressBarOption);
- progressBarOption.maskWidth = width;
-
- if(mTrack) {
- q->style()->updatePrimitive(mTrack, HbStyle::P_ProgressBar_slidertrack, &progressBarOption);
- }
-}
-
void HbProgressSliderPrivate::setRange(int minimum, int maximum)
{
Q_Q( HbProgressSlider );
@@ -183,16 +215,40 @@
progressValue as the buffered amount.
HbProgressSlider is derived from HbProgressBar so it supports all the features supported by HbProgressBar.
- infinite and rating progress bar feature is disabled in HbProgressSlider.
- \sa HbProgressBar
+
+ HbProgressSlider emits below signals
+
+ void sliderPressed();
+ void sliderReleased();
+ void sliderMoved(int value);
+
+ sliderPressed is emits when the track is pressed.
+ sliderReleased is emits when the track is released.
+ sliderMoved is emits when the handle is moved in any direction.
+
+
+ sample code showing how this can be connected. If the Application has different use case based on
+ Slider press and slider release they can customize the behaviour.
+
+ \code
+ HbProgressSlider *object = new HbProgressSlider(parent);
+ connect(mySlider,SIGNAL(sliderMoved(int)), mySlider ,SLOT(setSliderValue(int)));
+ \endcode
+
*/
+
+/*!
+ @beta
+ Constructs a progressslider with a parent.
+*/
+
HbProgressSlider::HbProgressSlider(QGraphicsItem *parent) :
HbProgressBar(*new HbProgressSliderPrivate,HbProgressBar::SimpleProgressBar,parent)
{
Q_D( HbProgressSlider );
d->q_ptr = this;
d->init();
-
+ setMinMaxTextVisible(true);
setFocusPolicy(Qt::FocusPolicy(qApp->style()->styleHint(QStyle::SH_Button_FocusPolicy)));
d->handle =new HbProgressSliderHandle(d);
@@ -200,9 +256,9 @@
d->handle->setVisible(false);
}
if(d->mOrientation == Qt::Horizontal){
- qreal x = boundingRect().height();
- qreal y = d->handle->size().height();
- qreal a = qreal (x-y)/2;
+ qreal x = boundingRect().height();
+ qreal y = d->handle->size().height();
+ qreal a = qreal (x-y)/2;
d->handle->setPos(0,a);
}
@@ -214,7 +270,7 @@
/*!
@beta
- Constructs a progressslider of a given \a parent.
+ Constructs a progressslider with a parent.
*/
HbProgressSlider::HbProgressSlider(HbProgressSliderPrivate &dd,QGraphicsItem *parent) :
HbProgressBar( dd,HbProgressBar::SimpleProgressBar,parent)
@@ -222,11 +278,11 @@
Q_D( HbProgressSlider );
d->init();
- setFocusPolicy(Qt::FocusPolicy(qApp->style()->styleHint(QStyle::SH_Button_FocusPolicy)));
+ setFocusPolicy(Qt::FocusPolicy(qApp->style()->styleHint(QStyle::SH_Button_FocusPolicy)));
d->handle =new HbProgressSliderHandle(d);
- d->handle->setZValue(1010);
+ d->handle->setZValue(1010);
if(d->mOrientation == Qt::Horizontal){
- qreal posY = qreal (boundingRect().height()-d->handle->size().height())/2;
+ qreal posY = qreal (boundingRect().height()-d->handle->size().height())/2;
d->handle->setPos(0,posY);
}
else{
@@ -250,7 +306,9 @@
The progress slider forces the value to be within the legal range: \b
minimum <= \c value <= \b maximum.
- \sa value()
+ \param value slider value.
+
+ \sa sliderValue()
*/
void HbProgressSlider::setSliderValue(int value)
{
@@ -268,13 +326,11 @@
}
d->mSliderValue = value;
- HbStyleOptionProgressBar progressBarOption;
- initStyleOption(&progressBarOption);
+ HbStyleOptionProgressSlider option;
+ initStyleOption(&option);
+
if (d->mSliderGraphicItem) {
- style()->updatePrimitive(d->mSliderGraphicItem, HbStyle::P_ProgressBar_slidertrack, &progressBarOption);
- /* if( value == d->mMaximum ) {
- d->handle->changeIcon();
- }*/
+ style()->updatePrimitive(d->mSliderGraphicItem, HbStyle::P_ProgressSlider_slidertrack, &option);
}
d->handle->setHandlePosForValue(sliderValue());
}
@@ -296,7 +352,7 @@
/*!
@beta
- Returns \c true whether the slider is pressed down.
+ Returns true of false depending on whether the slider is pressed down or not.
*/
bool HbProgressSlider::isSliderDown() const
@@ -308,7 +364,12 @@
/*!
@beta
- Sets the inverted appearance flag.
+ Sets the inverted appearence of the slider.
+ If inverted the slider increases from right to left.
+
+ \param inverted true or false
+
+ \sa invertedAppearance()
*/
void HbProgressSlider::setInvertedAppearance(bool inverted)
{
@@ -321,26 +382,30 @@
}
-/*!
- Sets the Icon for the progressslider thumb.
+/*!
+ \deprecated HbProgressSlider::setThumbIcon(const HbIcon&)
+ is deprecated. Use setHandleIcon instead of this
- \deprecated HbProgressSlider::setThumbIcon(const HbIcon&)
- is deprecated.
+ Sets the Icon for the progressslider thumb.
*/
void HbProgressSlider::setThumbIcon(const HbIcon &icon)
{
+ HB_DEPRECATED("HbProgressSlider::setThumbIcon is deprecated.");
+
Q_D( HbProgressSlider );
- d->handle->setThumbIcon(icon);
+ d->handle->setHandleIcon(icon);
}
/*!
- Returns the Icon for the progressslider thumb.
-
\deprecated HbProgressSlider::thumbIcon() const
is deprecated.
+
+ Returns the Icon for the progressslider thumb.
*/
HbIcon HbProgressSlider::thumbIcon() const
{
+ HB_DEPRECATED("HbProgressSlider::thumbIcon is deprecated.");
+
Q_D( const HbProgressSlider );
return d->handle->thumbIcon();
}
@@ -349,9 +414,15 @@
{
Q_D(HbProgressSlider);
if(flags().testFlag(ItemIsFocusable)) {
+ d->mDownState = true;
+ HbStyleOptionProgressSlider option;
+ initStyleOption(&option);
+ if (d->mFrame) {
+ style()->updatePrimitive(d->mFrame, HbStyle::P_ProgressSlider_frame, &option);
+ }
qreal temp = event->scenePos().x();
if((d->mMinMaxTextVisible) && (d->mMinMaxTextAlignment== Qt::AlignCenter)) {
- temp -= d->mMinTextItem->boundingRect().width();
+ temp -= d->mMinTextItem->boundingRect().width();
}
if( (temp > d->handle->pos().x()) && (temp < (d->handle->boundingRect().width()+d->handle->pos().x())) ) {
event->ignore();
@@ -361,19 +432,26 @@
HbWidgetFeedback::triggered(this, Hb::InstantPressed);
d->handle->handleTrackPress(event);
event->accept();
- #ifdef HB_EFFECTS
- HbEffect::start(this, HB_PRGRESSSLIDER_ITEM_TYPE, "progressslider_trackpress");
+ #ifdef HB_EFFECTS
+ HbEffect::start(this, HB_PRGRESSSLIDER_ITEM_TYPE, "progressslider_trackpress");
#endif
} else {
event->ignore();
}
}
-
void HbProgressSlider::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(HbProgressSlider);
if(flags().testFlag(ItemIsFocusable)) {
+ d->mDownState = false;
+
+ HbStyleOptionProgressSlider option;
+ initStyleOption(&option);
+ if (d->mFrame) {
+ style()->updatePrimitive(d->mFrame, HbStyle::P_ProgressSlider_frame, &option);
+ }
+
HbWidgetFeedback::triggered(this, Hb::InstantReleased);
d->handle->handleTrackRelease(event);
event->accept();
@@ -383,7 +461,6 @@
} else {
event->ignore();
}
-
}
void HbProgressSlider::setGeometry(const QRectF & rect)
@@ -394,47 +471,60 @@
updatePrimitives();
}
-
-void HbProgressSlider::initStyleOption(HbStyleOption *hboption) const
+/*!
+ Initializes \a option with the values from this HbProgressSlider.
+ This method is useful for subclasses when they need a HbStyleOptionProgressSlider,
+ but don't want to fill in all the information themselves.
+ */
+void HbProgressSlider::initStyleOption( HbStyleOptionProgressSlider *option ) const
{
- Q_ASSERT(hboption);
Q_D(const HbProgressSlider);
- HbProgressBar::initStyleOption(hboption);
- HbStyleOptionProgressBar *option = 0;
- if ((option = qstyleoption_cast< HbStyleOptionProgressBar *>(hboption)) != 0){
- option->secondoryType = true;
- option->sliderValue = d->mSliderValue;
- option->inverted = d->mInvertedAppearance;
- option->maximum = d->mMaximum;
- option->minimum = d->mMinimum;
- }
+ HbProgressBar::initStyleOption(option);
+
+ option->secondaryType = true;
+ option->progressSliderValue = d->mSliderValue;
+ option->pressedState = d->mDownState;
}
-
void HbProgressSlider::updatePrimitives()
{
- HbProgressBar::updatePrimitives();
-
Q_D(HbProgressSlider);
if(isVisible()){
d->mWaitTrack->setVisible(false);
d->mTrack->setVisible(true);
- HbStyleOptionProgressBar progressBarOption;
- initStyleOption(&progressBarOption);
+
+ HbStyleOptionProgressSlider option;
+ initStyleOption(&option);
+
if (d->mSliderGraphicItem) {
- style()->updatePrimitive(d->mSliderGraphicItem, HbStyle::P_ProgressBar_slidertrack, &progressBarOption);
+ style()->updatePrimitive(d->mSliderGraphicItem, HbStyle::P_ProgressSlider_slidertrack, &option);
}
if(d->handle)
d->handle->setHandlePosForValue(sliderValue());
+
+ if (d->mFrame) {
+ style()->updatePrimitive(d->mFrame, HbStyle::P_ProgressSlider_frame, &option);
+ }
+
+ if (d->mTrack) {
+ style()->updatePrimitive(d->mTrack, HbStyle::P_ProgressSlider_track, &option);
+ }
+
+ if(d->mMinTextItem && d->mMinMaxTextVisible) {
+ style()->updatePrimitive(d->mMinTextItem,HbStyle::P_ProgressBar_mintext,&option);
+ }
+
+ if(d->mMaxTextItem && d->mMinMaxTextVisible) {
+ style()->updatePrimitive(d->mMaxTextItem,HbStyle::P_ProgressBar_maxtext,&option);
+ }
}
-
}
void HbProgressSlider::showEvent( QShowEvent * event )
{
- Q_D(const HbProgressSlider);
- if(d->mTouchAreaItem && scene()) {
+ Q_D(const HbProgressSlider);
+ if(d->mTouchAreaItem && scene()) {
d->mTouchAreaItem->removeSceneEventFilter(this);
d->mTouchAreaItem->installSceneEventFilter(this);
}
@@ -448,7 +538,6 @@
if(value.toInt() & ItemIsFocusable) {
if(!flags().testFlag(ItemIsFocusable) && d->handle) {
d->handle->setVisible(true);
-
}
} else {
if(flags().testFlag(ItemIsFocusable) && d->handle) {
@@ -463,76 +552,89 @@
bool HbProgressSlider::sceneEventFilter(QGraphicsItem *obj,QEvent *event)
{
Q_D(HbProgressSlider);
- if( obj == d->mTouchAreaItem) {
+ if( obj == d->mTouchAreaItem) {
if (!isEnabled() ) {
return false;
}
- if (event->type() == QEvent::GraphicsSceneMousePress){
- mousePressEvent((QGraphicsSceneMouseEvent *) event);
+ if (event->type() == QEvent::GraphicsSceneMousePress){
+ mousePressEvent((QGraphicsSceneMouseEvent *) event);
return true;
- }
- else if (event->type() == QEvent::GraphicsSceneMouseRelease){
- mouseReleaseEvent((QGraphicsSceneMouseEvent *) event);
+ }
+ else if (event->type() == QEvent::GraphicsSceneMouseRelease){
+ mouseReleaseEvent((QGraphicsSceneMouseEvent *) event);
return true;
- }
- }
- return false;
+ }
+ }
+ return false;
}
/*!
- set the tooltip text .
-
\deprecated HbProgressSlider::setHandleToolTip(const QString&)
is deprecated. Please use HbProgressSlider::setSliderToolTip(const QString &text) instead.
+ set the tooltip text .
+
\sa handleToolTip()
*/
void HbProgressSlider::setHandleToolTip(const QString &text)
{
+ HB_DEPRECATED("HbProgressSlider::setHandleToolTip is deprecated. Use HbProgressSlider::setSliderToolTip(const QString &text) instead.");
+
setSliderToolTip(text);
}
/*!
- Returns the current tooltip text value.
-
\deprecated HbProgressSlider::handleToolTip() const
is deprecated. Please use HbProgressSlider::sliderToolTip() const instead.
+ Returns the current tooltip text value.
+
\sa setHandleToolTip()
*/
QString HbProgressSlider::handleToolTip() const
{
+ HB_DEPRECATED("HbProgressSlider::handleToolTip is deprecated. Use HbProgressSlider::sliderToolTip() instead.");
+
return sliderToolTip();
}
/*!
- Sets the state of the handle as normal play,pressed play,normal pause,pressed pause etc.
-
\deprecated HbProgressSlider::setHandleState(HbProgressSlider::HandleState)
is deprecated. Please use HbProgressSlider::setSliderState(HbProgressSlider::SliderState state) instead.
+ Sets the state of the handle as normal play,pressed play,normal pause,pressed pause etc.
*/
void HbProgressSlider::setHandleState(HbProgressSlider::HandleState state)
{
+ HB_DEPRECATED("HbProgressSlider::setHandleState is deprecated. Use HbProgressSlider::setSliderState instead.");
+
setSliderState((HbProgressSlider::SliderState)state);
}
+
/*!
- Returns the state of the handle.
\deprecated HbProgressSlider::handleState() const
is deprecated. Please use HbProgressSlider::sliderState() const instead.
+
+ Returns the state of the handle.
*/
HbProgressSlider::HandleState HbProgressSlider::handleState() const
{
+ HB_DEPRECATED("HbProgressSlider::handleState is deprecated. Use HbProgressSlider::handleState() instead.");
+
return (HbProgressSlider::HandleState)sliderState();
}
/*!
@beta
+ Sets the tooltip for the handle. By default it shows the slider value.
+ If the Application wants to configure this they use setSliderToolTip for
+ setting the new tooltip text.
- Sets the tooltip text .
+ \param text tooltip text
+
\sa sliderToolTip()
*/
void HbProgressSlider::setSliderToolTip(const QString &text)
@@ -555,62 +657,90 @@
}
/*!
- @beta
-
- Sets the state of the handle as SliderStatePlayNormal, SliderStatePlayPressed,
- SliderStatePauseNormal, SliderStatePausePressed.
+ \deprecated HbProgressSlider::setSliderState(HbProgressSlider::SliderState)
+ is deprecated.
- \sa sliderState()
-
+ Sets the state of the handle as normal play,pressed play,normal pause,pressed pause etc.
*/
void HbProgressSlider::setSliderState(HbProgressSlider::SliderState state)
{
- Q_D(HbProgressSlider);
- if(d->state != state) {
- d->state = state;
- if (d->handle) {
- d->handle->mSliderState = state;
+ Q_D(HbProgressSlider);
+ if(d->state != state) {
+ d->state = state;
+ if (d->handle) {
+ d->handle->mSliderHandleState = state;
- switch(d->handle->mSliderState) {
-
+ switch(d->handle->mSliderHandleState) {
case HbProgressSlider::SliderStatePlayNormal:
d->handle->setProperty("state","normal");
break;
-
case HbProgressSlider::SliderStatePlayPressed:
d->handle->setProperty("state","pressed");
break;
-
case HbProgressSlider::SliderStatePauseNormal:
d->handle->setProperty("state","normal");
break;
-
case HbProgressSlider::SliderStatePausePressed:
d->handle->setProperty("state","pressed");
break;
+ default:
+ break;
}
- d->handle->updatePrimitives();
-
- }
- }
+ d->handle->updatePrimitives();
+
+ }
+ }
+}
+/*!
+ \deprecated HbProgressSlider::sliderState() const
+ is deprecated.
+
+ Sets the state of the handle as normal play,pressed play,normal pause,pressed pause etc.
+*/
+HbProgressSlider::SliderState HbProgressSlider::sliderState() const
+{
+ Q_D(const HbProgressSlider);
+ return d->state;
}
+
+/*!
+ @beta
+ Sets the icon for handle. By default it has theme based icon. Application
+ can configure this icon via this API
+
+ \param handlePath path of the graphics
+
+ \sa handleIcon()
+*/
+void HbProgressSlider::setHandleIcon(const QString& handlePath )
+{
+
+ Q_D( HbProgressSlider );
+ if(handlePath != d->mHandlePath) {
+ d->mHandlePath =handlePath;
+ d->handle->setHandleIcon(HbIcon(handlePath));
+ }
+}
+
/*!
@beta
- Returns the state of the handle.
+ Returns the icon handle path
- \sa setSliderState()
+ \sa setHandleIcon()
*/
-HbProgressSlider::SliderState HbProgressSlider::sliderState() const
+QString HbProgressSlider::handleIcon() const
{
- Q_D(const HbProgressSlider);
- return d->state;
-
+ Q_D(const HbProgressSlider);
+ return d->mHandlePath;
}
+/*!
-/*!
+ \deprecated HbProgressSlider::primitive(HbStyle::Primitive)
+ is deprecated.
+
Returns the pointer for \a primitive passed.
Will return NULL if \a primitive passed is invalid
*/
@@ -619,11 +749,19 @@
Q_D(const HbProgressSlider);
switch (primitive) {
- case HbStyle::P_ProgressBar_slidertrack:
+ case HbStyle::P_ProgressSlider_frame:
+ return d->mFrame;
+ case HbStyle::P_ProgressSlider_track:
+ return d->mTrack;
+ case HbStyle::P_ProgressSlider_slidertrack:
return d->mSliderGraphicItem;
- case HbStyle::P_ProgressBar_toucharea:
- return d->mTouchAreaItem;
+ case HbStyle::P_ProgressSlider_toucharea:
+ return d->mTouchAreaItem;
+ case HbStyle::P_ProgressSliderHandle_icon:
+ case HbStyle::P_ProgressSliderHandle_toucharea:
+ return d->handle->primitive(primitive);
default:
return 0;
}
}
+