src/hbwidgets/sliders/hbratingslider.cpp
changeset 2 06ff229162e9
parent 1 f7ac710697a9
child 3 11d3954df52a
equal deleted inserted replaced
1:f7ac710697a9 2:06ff229162e9
    25 
    25 
    26 
    26 
    27 #include <hbratingslider.h>
    27 #include <hbratingslider.h>
    28 #include "hbratingslider_p.h"
    28 #include "hbratingslider_p.h"
    29 #include <hbtooltip.h>
    29 #include <hbtooltip.h>
    30 #include <hbstyleoptionratingslider.h>
    30 #include <hbstyleoptionratingslider_p.h>
    31 #include <QGraphicsItem>
    31 #include <QGraphicsItem>
    32 #include <QGraphicsSceneMouseEvent>
    32 #include <QGraphicsSceneMouseEvent>
    33 #include <hbtoucharea.h>
    33 #include <hbtoucharea.h>
    34 
    34 
    35 #ifdef HB_GESTURE_FW
    35 #ifdef HB_GESTURE_FW
    44 
    44 
    45 #endif
    45 #endif
    46 #define MAX_NUMBER_OF_ICONS 10
    46 #define MAX_NUMBER_OF_ICONS 10
    47 
    47 
    48 HbRatingSliderPrivate::HbRatingSliderPrivate():
    48 HbRatingSliderPrivate::HbRatingSliderPrivate():
    49 	mMousePressed(false),
    49     mMousePressed(false),
    50 	mLookupValues(0),
    50     mLookupValues(0),
    51 	mReadOnly(false),
    51     mReadOnly(false),
    52 	mNumberOfIcons(5),
    52     mNumberOfIcons(5),
    53 	mStepCount(5),
    53     mStepCount(5),
    54 	mCurrentValue(0),
    54     mCurrentValue(0),
    55 	mFrame(0),
    55     mFrame(0),
    56 	mTrack(0),
    56     mTrack(0),
    57 	mLayoutItem(0),
    57     mLayoutItem(0),
    58 	mUnratedIconName(""),
    58     mUnratedIconName(""),
    59 	mTouchArea(0),
    59     mTouchArea(0),
    60 	mRatedIconName("")
    60     mRatedIconName("")
    61 {	
    61 {    
    62 }
    62 }
    63 
    63 
    64 HbRatingSliderPrivate::~HbRatingSliderPrivate()
    64 HbRatingSliderPrivate::~HbRatingSliderPrivate()
    65 {
    65 {
    66 	if(mLookupValues) {
    66     if(mLookupValues) {
    67 		delete [] mLookupValues;
    67         delete [] mLookupValues;
    68 	}
    68     }
    69 }
    69 }
    70 
    70 
    71 
    71 
    72 void HbRatingSliderPrivate::init()
    72 void HbRatingSliderPrivate::init()
    73 {
    73 {
    74 	Q_Q(HbRatingSlider);
    74     Q_Q(HbRatingSlider);
    75 	mLayoutItem = q->style()->createPrimitive(HbStyle::P_RatingSlider_layout,q);
    75     mLayoutItem = q->style()->createPrimitive(HbStyle::P_RatingSlider_layout,q);
    76     mFrame = q->style()->createPrimitive(HbStyle::P_RatingSlider_frame,mLayoutItem);
    76     mFrame = q->style()->createPrimitive(HbStyle::P_RatingSlider_frame,mLayoutItem);
    77     mTrack = q->style()->createPrimitive(HbStyle::P_RatingSlider_track,mFrame);
    77     mTrack = q->style()->createPrimitive(HbStyle::P_RatingSlider_track,mFrame);
    78     mTouchArea = q->style()->createPrimitive(HbStyle::P_RatingSlider_toucharea, q);
    78     mTouchArea = q->style()->createPrimitive(HbStyle::P_RatingSlider_toucharea, q);
    79 
    79 
    80 	q->updatePrimitives();
    80     q->updatePrimitives();
    81 
    81 
    82 	#ifdef HB_EFFECTS
    82     #ifdef HB_EFFECTS
    83     HbEffectInternal::add(HB_RATINGSLIDER_ITEM_TYPE,"ratingslider_appear", "ratingslider_appear");
    83     HbEffectInternal::add(HB_RATINGSLIDER_ITEM_TYPE,"ratingslider_appear", "ratingslider_appear");
    84     HbEffectInternal::add(HB_RATINGSLIDER_ITEM_TYPE,"ratingslider_disappear", "ratingslider_disappear");
    84     HbEffectInternal::add(HB_RATINGSLIDER_ITEM_TYPE,"ratingslider_disappear", "ratingslider_disappear");
    85     #endif
    85     #endif
    86 
    86 
    87     #ifdef HB_GESTURE_FW
    87     #ifdef HB_GESTURE_FW
    96 
    96 
    97 }
    97 }
    98 
    98 
    99 void HbRatingSliderPrivate::createLookupTable()
    99 void HbRatingSliderPrivate::createLookupTable()
   100 {
   100 {
   101 	if(mLookupValues) {
   101     if(mLookupValues) {
   102 		delete [] mLookupValues;
   102         delete [] mLookupValues;
   103 		mLookupValues=0;
   103         mLookupValues=0;
   104 	}
   104     }
   105 	
   105     
   106 	mLookupValues = new int[mStepCount];
   106     mLookupValues = new int[mStepCount];
   107 	qreal width = mFrame->boundingRect().width();
   107     qreal width = mFrame->boundingRect().width();
   108 	int bandWidth =(int) (width/mStepCount);
   108     int bandWidth =(int) (width/mStepCount);
   109 		
   109         
   110 	for(int i=0;i < mStepCount;i++) {
   110     for(int i=0;i < mStepCount;i++) {
   111 		mLookupValues[i] = bandWidth*(i+1);
   111         mLookupValues[i] = bandWidth*(i+1);
   112 	}
   112     }
   113 }
   113 }
   114 
   114 
   115 int HbRatingSliderPrivate::calculateProgressValue(qreal pos)
   115 int HbRatingSliderPrivate::calculateProgressValue(qreal pos)
   116 {
   116 {
   117 	Q_Q(HbRatingSlider);
   117     Q_Q(HbRatingSlider);
   118 	
   118     
   119 	int count=0;
   119     int count=0;
   120 	for(count=0;count< mStepCount ;count++) {
   120     for(count=0;count< mStepCount ;count++) {
   121 		if(pos <= mLookupValues[count])
   121         if(pos <= mLookupValues[count])
   122 				break;
   122                 break;
   123 	}
   123     }
   124 	if(q->layoutDirection() == Qt::RightToLeft) {
   124     if(q->layoutDirection() == Qt::RightToLeft) {
   125 		
   125         
   126 		count = mStepCount -count;
   126         count = mStepCount -count;
   127 	}
   127     }
   128 	else {
   128     else {
   129         
   129         
   130 		count++;
   130         count++;
   131 	}
   131     }
   132 
   132 
   133 	if (pos > mLookupValues[mStepCount-1]) {
   133     if (pos > mLookupValues[mStepCount-1]) {
   134 		return -1;
   134         return -1;
   135 	}
   135     }
   136 	
   136     
   137 	return count;
   137     return count;
   138 	
   138     
   139 }
   139 }
   140 
   140 
   141 /*!
   141 /*!
   142     \class HbRatingSlider
   142     \class HbRatingSlider
   143     \brief A control for user to do rating.
   143     \brief A control for user to do rating.
   144 
   144 
   145     This is a general rating widget where user will be able to do different 
   145     This is a general rating widget where user will be able to do different 
   146 	ratings for things like Music ,Video etc. 
   146     ratings for things like Music ,Video etc. 
   147 
   147 
   148 	By default there are 5 ratings ( 5 stars ). This can be configured also.
   148     By default there are 5 ratings ( 5 stars ). This can be configured also.
   149 	The interval , number of icons etc can be configured.
   149     The interval , number of icons etc can be configured.
   150 
   150 
   151 	Apart from rating the this can used for showing cumulative rating also.
   151     Apart from rating the this can used for showing cumulative rating also.
   152 
   152 
   153     example code example:
   153     example code example:
   154     \code
   154     \code
   155     HbRatingSlider *object = new HbRatingSlider(parent);
   155     HbRatingSlider *object = new HbRatingSlider(parent);
   156     \endcode
   156     \endcode
   157 
   157 
   158     The below  code can be used to show some rating e.g. 2.5/5
   158     The below  code can be used to show some rating e.g. 2.5/5
   159 	by default the  stepcount =5
   159     by default the  stepcount =5
   160     
   160     
   161 	\code
   161     \code
   162 	HbRatingSlider *slider = new HbRatingSlider();
   162     HbRatingSlider *slider = new HbRatingSlider();
   163 	slider->setStepCount(100); //5 *20//
   163     slider->setStepCount(100); //5 *20//
   164 	slider->setCurrentRating(50); //2.5*20 it shows 50 / 100 which is same as 2.5/5
   164     slider->setCurrentRating(50); //2.5*20 it shows 50 / 100 which is same as 2.5/5
   165     \endcode
   165     \endcode
   166 	
   166     
   167 	This will show as 2.5/5. Now if one the same ratingslider 
   167     This will show as 2.5/5. Now if one the same ratingslider 
   168 	if the Application wants to configure a rating slider with range 1-5
   168     if the Application wants to configure a rating slider with range 1-5
   169 	on emitting the signal rating changed it can set to 
   169     on emitting the signal rating changed it can set to 
   170 	slider->setStepCount(5);
   170     slider->setStepCount(5);
   171 	slider->setCurrentRating(0)
   171     slider->setCurrentRating(0)
   172 	
   172     
   173 	When the rating is done it emits a signal called ratingDone and when rating is 
   173     When the rating is done it emits a signal called ratingDone and when rating is 
   174 	changed by the user by draging the pointer ratingChanged signal is emitted.   
   174     changed by the user by draging the pointer ratingChanged signal is emitted.   
   175 	
   175     
   176  */
   176  */
   177 
   177 
   178 
   178 
   179 
   179 
   180 /*!
   180 /*!
   181     @beta
   181     @beta
   182 	Constructor of  RatingSlider.
   182     Constructor of  RatingSlider.
   183     \param parent. Parent widget
   183     \param parent. Parent widget
   184 
   184 
   185 */
   185 */
   186 
   186 
   187 HbRatingSlider::HbRatingSlider(QGraphicsItem *parent) :
   187 HbRatingSlider::HbRatingSlider(QGraphicsItem *parent) :
   193 }
   193 }
   194 
   194 
   195 
   195 
   196 /*!
   196 /*!
   197     @beta
   197     @beta
   198 	Constructor of  RatingSlider.
   198     Constructor of  RatingSlider.
   199     \param parent. Parent widget
   199     \param parent. Parent widget
   200 */
   200 */
   201 HbRatingSlider::HbRatingSlider(HbRatingSliderPrivate &dd,QGraphicsItem *parent) : 
   201 HbRatingSlider::HbRatingSlider(HbRatingSliderPrivate &dd,QGraphicsItem *parent) : 
   202     HbWidget( dd,parent)
   202     HbWidget( dd,parent)
   203 {
   203 {
   223     \sa readOnly()
   223     \sa readOnly()
   224 */
   224 */
   225 
   225 
   226 void HbRatingSlider::setReadOnly(bool value)
   226 void HbRatingSlider::setReadOnly(bool value)
   227 {
   227 {
   228 	Q_D(HbRatingSlider);
   228     Q_D(HbRatingSlider);
   229 	d->mReadOnly = value;
   229     d->mReadOnly = value;
   230 }
   230 }
   231 
   231 
   232 /*!	
   232 /*!    
   233 	
   233     
   234 	@beta  
   234     @beta  
   235     Sets the number of icons. In a Rating scenario you may have number of repeated icons. This API can be used to set 
   235     Sets the number of icons. In a Rating scenario you may have number of repeated icons. This API can be used to set 
   236 	the number of icons required. For Example the default image is "*" and you have 5 stars. You can set the number of 
   236     the number of icons required. For Example the default image is "*" and you have 5 stars. You can set the number of 
   237 	stars  using this. By default this value is 5.
   237     stars  using this. By default this value is 5.
   238 
   238 
   239     \param number. A value between 1 and 10 
   239     \param number. A value between 1 and 10 
   240 
   240 
   241     \sa numberOfIcons()
   241     \sa numberOfIcons()
   242 */
   242 */
   243 
   243 
   244 void HbRatingSlider::setNumberOfIcons(int number)
   244 void HbRatingSlider::setNumberOfIcons(int number)
   245 {
   245 {
   246 	Q_D(HbRatingSlider);
   246     Q_D(HbRatingSlider);
   247 	if ( (number <= 0) || (number > MAX_NUMBER_OF_ICONS) ){
   247     if ( (number <= 0) || (number > MAX_NUMBER_OF_ICONS) ){
   248 		return;
   248         return;
   249 	}
   249     }
   250 	d->mNumberOfIcons = number;
   250     d->mNumberOfIcons = number;
   251 	updatePrimitives();
   251     updatePrimitives();
   252 	d->createLookupTable();
   252     d->createLookupTable();
   253 }
   253 }
   254 
   254 
   255 
   255 
   256 /*!		
   256 /*!        
   257 	@beta  
   257     @beta  
   258     Returns the number of icons set.
   258     Returns the number of icons set.
   259 
   259 
   260     \sa setNumberOfIcons()
   260     \sa setNumberOfIcons()
   261 */
   261 */
   262 
   262 
   263 int HbRatingSlider::numberOfIcons() const
   263 int HbRatingSlider::numberOfIcons() const
   264 {
   264 {
   265 	Q_D(const HbRatingSlider);
   265     Q_D(const HbRatingSlider);
   266 	return d->mNumberOfIcons;
   266     return d->mNumberOfIcons;
   267 }
   267 }
   268 
   268 
   269 /*!
   269 /*!
   270     @beta
   270     @beta
   271     Sets the step count for the rating slider. If the number of icons is 5 and step count is 10 then it is possible to have 10 ratings.
   271     Sets the step count for the rating slider. If the number of icons is 5 and step count is 10 then it is possible to have 10 ratings.
   272 	one rating will be half star (by default). If the number of icons is 5 and step count is 5 then 5 ratings are possible. In this 
   272     one rating will be half star (by default). If the number of icons is 5 and step count is 5 then 5 ratings are possible. In this 
   273 	case one rating will be one complete star. By default this value is 5.
   273     case one rating will be one complete star. By default this value is 5.
   274 	
   274     
   275 	\param count. A value between 1 and 100. This can be considerd as the maximum rating possible. 
   275     \param count. A value between 1 and 100. This can be considerd as the maximum rating possible. 
   276 
   276 
   277     \sa numberOfIcons()
   277     \sa numberOfIcons()
   278 
   278 
   279 */
   279 */
   280 void HbRatingSlider::setStepCount(int count)
   280 void HbRatingSlider::setStepCount(int count)
   281 {
   281 {
   282 	Q_D(HbRatingSlider);
   282     Q_D(HbRatingSlider);
   283 	if( (count <= 0) || (count > 100) ) {
   283     if( (count <= 0) || (count > 100) ) {
   284 		return;
   284         return;
   285 	}
   285     }
   286 	d->mStepCount = count;
   286     d->mStepCount = count;
   287 	d->createLookupTable();	
   287     d->createLookupTable();    
   288 	
   288     
   289 	HbStyleOptionRatingSlider option;
   289     HbStyleOptionRatingSlider option;
   290     initStyleOption(&option);
   290     initStyleOption(&option);
   291 	if (d->mTrack) {
   291     if (d->mTrack) {
   292            style()->updatePrimitive(d->mTrack, HbStyle::P_RatingSlider_track, &option);
   292            style()->updatePrimitive(d->mTrack, HbStyle::P_RatingSlider_track, &option);
   293     }
   293     }
   294 
   294 
   295 }
   295 }
   296 
   296 
   297 /*!
   297 /*!
   298     @beta
   298     @beta
   299     Returns the step count.
   299     Returns the step count.
   300 
   300 
   301 */	
   301 */    
   302 int HbRatingSlider::stepCount() const
   302 int HbRatingSlider::stepCount() const
   303 {
   303 {
   304 	Q_D(const HbRatingSlider);
   304     Q_D(const HbRatingSlider);
   305 	return d->mStepCount;
   305     return d->mStepCount;
   306 }
   306 }
   307 
   307 
   308 /*!
   308 /*!
   309     @beta
   309     @beta
   310     Returns the read only flag of the Rating slider
   310     Returns the read only flag of the Rating slider
   311 */
   311 */
   312 bool HbRatingSlider::isReadOnly() const
   312 bool HbRatingSlider::isReadOnly() const
   313 {
   313 {
   314 	Q_D(const HbRatingSlider);
   314     Q_D(const HbRatingSlider);
   315 	return d->mReadOnly;
   315     return d->mReadOnly;
   316 }
   316 }
   317 
   317 
   318 /*!
   318 /*!
   319     @beta
   319     @beta
   320     It sets the current rating value.
   320     It sets the current rating value.
   321 	\param count. A value between 1 and stepcount. 
   321     \param count. A value between 1 and stepcount. 
   322 	\sa currentRating()
   322     \sa currentRating()
   323 
   323 
   324 */
   324 */
   325 void  HbRatingSlider::setCurrentRating(int rating)
   325 void  HbRatingSlider::setCurrentRating(int rating)
   326 {
   326 {
   327 	Q_D(HbRatingSlider);
   327     Q_D(HbRatingSlider);
   328 	if( rating >d->mStepCount ) {
   328     if( rating >d->mStepCount ) {
   329 		rating = d->mStepCount;
   329         rating = d->mStepCount;
   330 	}
   330     }
   331 	if( (rating == d->mCurrentValue) || (rating < 0) ) {
   331     if( (rating == d->mCurrentValue) || (rating < 0) ) {
   332 		return;
   332         return;
   333 	}
   333     }
   334 
   334 
   335 	d->mCurrentValue = rating;
   335     d->mCurrentValue = rating;
   336 	
   336     
   337 	HbStyleOptionRatingSlider option;
   337     HbStyleOptionRatingSlider option;
   338     initStyleOption(&option);
   338     initStyleOption(&option);
   339 	if (d->mTrack) {
   339     if (d->mTrack) {
   340            style()->updatePrimitive(d->mTrack, HbStyle::P_RatingSlider_track, &option);
   340            style()->updatePrimitive(d->mTrack, HbStyle::P_RatingSlider_track, &option);
   341     }
   341     }
   342 }
   342 }
   343 
   343 
   344 /*!
   344 /*!
   345     @beta
   345     @beta
   346     Returns the the current rating value.
   346     Returns the the current rating value.
   347 */
   347 */
   348 int HbRatingSlider::currentRating() const
   348 int HbRatingSlider::currentRating() const
   349 {
   349 {
   350 	Q_D(const HbRatingSlider);
   350     Q_D(const HbRatingSlider);
   351 	return d->mCurrentValue;
   351     return d->mCurrentValue;
   352 }
   352 }
   353 
   353 
   354 /*!
   354 /*!
   355     @beta
   355     @beta
   356     
   356     
   357 	It sets the unrated graphics name.This is the graphics shown when rating slider is displayed.
   357     It sets the unrated graphics name.This is the graphics shown when rating slider is displayed.
   358 	the grpahics can be a single star kind of or multi star image. If it is single star then use setNumberOfIcons for 
   358     the grpahics can be a single star kind of or multi star image. If it is single star then use setNumberOfIcons for 
   359 	setting number of stars.
   359     setting number of stars.
   360 	
   360     
   361 	\param name. The graphics name along with the path. 
   361     \param name. The graphics name along with the path. 
   362 	\sa unRatedIconName()
   362     \sa unRatedIconName()
   363 */
   363 */
   364 void HbRatingSlider::setUnRatedIconName(const QString name)
   364 void HbRatingSlider::setUnRatedIconName(const QString name)
   365 {
   365 {
   366 	Q_D(HbRatingSlider);
   366     Q_D(HbRatingSlider);
   367 	if(d->mUnratedIconName != name) {
   367     if(d->mUnratedIconName != name) {
   368 		d->mUnratedIconName =name;
   368         d->mUnratedIconName =name;
   369 
   369 
   370 		HbStyleOptionRatingSlider option;
   370         HbStyleOptionRatingSlider option;
   371 		initStyleOption(&option);
   371         initStyleOption(&option);
   372 		updatePrimitives();
   372         updatePrimitives();
   373 	}
   373     }
   374 	
   374     
   375 }
   375 }
   376 
   376 
   377 /*!
   377 /*!
   378     @beta
   378     @beta
   379     Returns the unrated graphics name .
   379     Returns the unrated graphics name .
   380 */
   380 */
   381 QString HbRatingSlider::unRatedIconName() const
   381 QString HbRatingSlider::unRatedIconName() const
   382 {
   382 {
   383 	Q_D(const HbRatingSlider);
   383     Q_D(const HbRatingSlider);
   384 	return d->mUnratedIconName;
   384     return d->mUnratedIconName;
   385 
   385 
   386 }
   386 }
   387 
   387 
   388 /*!
   388 /*!
   389     @beta
   389     @beta
   390     
   390     
   391 	It sets the rated graphics name.This is the graphics shown when rating is on going.
   391     It sets the rated graphics name.This is the graphics shown when rating is on going.
   392 	the grpahics can be a single star kind of or multi star image. If it is single star then use setNumberOfIcons for 
   392     the grpahics can be a single star kind of or multi star image. If it is single star then use setNumberOfIcons for 
   393 	setting number of stars.
   393     setting number of stars.
   394 	
   394     
   395 	\param name. The graphics name along with the path. 
   395     \param name. The graphics name along with the path. 
   396 	\sa unRatedIconName()
   396     \sa unRatedIconName()
   397 */
   397 */
   398 void HbRatingSlider::setRatedIconName(const QString name)
   398 void HbRatingSlider::setRatedIconName(const QString name)
   399 {
   399 {
   400 	Q_D(HbRatingSlider);
   400     Q_D(HbRatingSlider);
   401 	if(d->mRatedIconName != name) {
   401     if(d->mRatedIconName != name) {
   402 		d->mRatedIconName = name;
   402         d->mRatedIconName = name;
   403 		HbStyleOptionRatingSlider option;
   403         HbStyleOptionRatingSlider option;
   404 		initStyleOption(&option);
   404         initStyleOption(&option);
   405 		updatePrimitives();
   405         updatePrimitives();
   406 	}
   406     }
   407 }
   407 }
   408 
   408 
   409 /*!
   409 /*!
   410     @beta
   410     @beta
   411     Returns the rated graphics name .
   411     Returns the rated graphics name .
   412 */
   412 */
   413 QString HbRatingSlider::ratedIconName() const 
   413 QString HbRatingSlider::ratedIconName() const 
   414 {
   414 {
   415 	Q_D(const HbRatingSlider);
   415     Q_D(const HbRatingSlider);
   416 	return d->mRatedIconName;
   416     return d->mRatedIconName;
   417 }
   417 }
   418 
   418 
   419 #ifndef HB_GESTURE_FW
   419 #ifndef HB_GESTURE_FW
   420 /*!
   420 /*!
   421     \reimp
   421     \reimp
   422 */
   422 */
   423 void HbRatingSlider::mousePressEvent(QGraphicsSceneMouseEvent *event) 
   423 void HbRatingSlider::mousePressEvent(QGraphicsSceneMouseEvent *event) 
   424 {
   424 {
   425 	
   425     
   426     Q_D(HbRatingSlider);
   426     Q_D(HbRatingSlider);
   427 	if(d->mTouchArea->isUnderMouse()) {
   427     if(d->mTouchArea->isUnderMouse()) {
   428 
   428 
   429 		if(d->mReadOnly) {	
   429         if(d->mReadOnly) {    
   430 			event->ignore();
   430             event->ignore();
   431 			return;
   431             return;
   432 		}
   432         }
   433 		d->mMousePressed = true;
   433         d->mMousePressed = true;
   434 		event->accept();
   434         event->accept();
   435 
   435 
   436 	}
   436     }
   437 
   437 
   438 }
   438 }
   439 /*!
   439 /*!
   440     \reimp
   440     \reimp
   441 */
   441 */
   442 void HbRatingSlider::mouseMoveEvent ( QGraphicsSceneMouseEvent * event ) 
   442 void HbRatingSlider::mouseMoveEvent ( QGraphicsSceneMouseEvent * event ) 
   443 {
   443 {
   444     Q_D(HbRatingSlider);
   444     Q_D(HbRatingSlider);
   445 
   445 
   446 	if(!d->mMousePressed) {
   446     if(!d->mMousePressed) {
   447 		return;
   447         return;
   448 	}
   448     }
   449 	QPointF layoutItemPos = d->mLayoutItem->pos();
   449     QPointF layoutItemPos = d->mLayoutItem->pos();
   450     QPointF frameItemPos = d->mFrame->pos();   
   450     QPointF frameItemPos = d->mFrame->pos();   
   451 	qreal xVal = event->pos().x() - layoutItemPos.x()+ frameItemPos.x();
   451     qreal xVal = event->pos().x() - layoutItemPos.x()+ frameItemPos.x();
   452 	if(d->mTouchArea->isUnderMouse()) {
   452     if(d->mTouchArea->isUnderMouse()) {
   453 			
   453             
   454 		if(d->mReadOnly) {
   454         if(d->mReadOnly) {
   455 			event->ignore();
   455             event->ignore();
   456 			return;
   456             return;
   457 		}
   457         }
   458 		
   458         
   459 		if(xVal <0) {	
   459         if(xVal <0) {    
   460 			setCurrentRating(0);
   460             setCurrentRating(0);
   461 			return;
   461             return;
   462 		}
   462         }
   463 		
   463         
   464 		QRectF rect = d->mTouchArea->boundingRect();
   464         QRectF rect = d->mTouchArea->boundingRect();
   465 		int rating=0;
   465         int rating=0;
   466 		if(rect.contains(xVal,0 )) {
   466         if(rect.contains(xVal,0 )) {
   467 			rating = d->calculateProgressValue(xVal);
   467             rating = d->calculateProgressValue(xVal);
   468 			if(toolTip() != QString()) {
   468             if(toolTip() != QString()) {
   469 				HbToolTip::showText(toolTip(),this);
   469                 HbToolTip::showText(toolTip(),this);
   470 			}	
   470             }    
   471 			setCurrentRating(rating);
   471             setCurrentRating(rating);
   472 			emit ratingChanged (d->mCurrentValue);
   472             emit ratingChanged (d->mCurrentValue);
   473 			event->accept();
   473             event->accept();
   474 		}
   474         }
   475 		
   475         
   476 
   476 
   477 	}
   477     }
   478 	else {
   478     else {
   479 			setCurrentRating(0);
   479             setCurrentRating(0);
   480 		}
   480         }
   481 
   481 
   482 }
   482 }
   483 /*!
   483 /*!
   484     \reimp
   484     \reimp
   485 */
   485 */
   486 void HbRatingSlider::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) 
   486 void HbRatingSlider::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) 
   487 {
   487 {
   488     Q_D(HbRatingSlider);
   488     Q_D(HbRatingSlider);
   489    
   489    
   490 	QPointF layoutItemPos = d->mLayoutItem->pos();
   490     QPointF layoutItemPos = d->mLayoutItem->pos();
   491     QPointF frameItemPos = d->mFrame->pos();
   491     QPointF frameItemPos = d->mFrame->pos();
   492 
   492 
   493     qreal xVal = event->pos().x() - layoutItemPos.x()+ frameItemPos.x();
   493     qreal xVal = event->pos().x() - layoutItemPos.x()+ frameItemPos.x();
   494 	if(d->mTouchArea->isUnderMouse()) {
   494     if(d->mTouchArea->isUnderMouse()) {
   495 			
   495             
   496 		if(d->mReadOnly) {
   496         if(d->mReadOnly) {
   497 			event->ignore();
   497             event->ignore();
   498 			return;
   498             return;
   499 		}
   499         }
   500 		
   500         
   501 		if(xVal <0) {	
   501         if(xVal <0) {    
   502 			setCurrentRating(0);
   502             setCurrentRating(0);
   503 			return;
   503             return;
   504 		}
   504         }
   505 		
   505         
   506 		QRectF rect = d->mTouchArea->boundingRect();
   506         QRectF rect = d->mTouchArea->boundingRect();
   507 		int rating=0;
   507         int rating=0;
   508 		if(rect.contains(xVal,0 )) {
   508         if(rect.contains(xVal,0 )) {
   509 			rating = d->calculateProgressValue(xVal);
   509             rating = d->calculateProgressValue(xVal);
   510 			if(toolTip() != QString()) {
   510             if(toolTip() != QString()) {
   511 				HbToolTip::showText(toolTip(),this);
   511                 HbToolTip::showText(toolTip(),this);
   512 			}	
   512             }    
   513 			setCurrentRating(rating);
   513             setCurrentRating(rating);
   514 			if(d->mCurrentValue) {
   514             if(d->mCurrentValue) {
   515 			    emit ratingDone (d->mCurrentValue);
   515                 emit ratingDone (d->mCurrentValue);
   516 			}
   516             }
   517 			event->accept();
   517             event->accept();
   518 			d->mMousePressed = false;
   518             d->mMousePressed = false;
   519 		}
   519         }
   520 	
   520     
   521 	}		
   521     }        
   522 }
   522 }
   523 #else
   523 #else
   524 void HbRatingSlider::mousePressEvent(QGraphicsSceneMouseEvent *event)
   524 void HbRatingSlider::mousePressEvent(QGraphicsSceneMouseEvent *event)
   525 {
   525 {
   526     Q_UNUSED(event)
   526     Q_UNUSED(event)
   533     Q_D (HbRatingSlider);
   533     Q_D (HbRatingSlider);
   534     if(event->gesture(Qt::TapGesture)) {
   534     if(event->gesture(Qt::TapGesture)) {
   535             HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
   535             HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
   536             switch(tap->state()) {
   536             switch(tap->state()) {
   537             case Qt::GestureStarted:
   537             case Qt::GestureStarted:
   538 				{
   538                 {
   539 				qreal xVal = mapFromScene(event->mapToGraphicsScene(tap->position( ))).x();
   539                 qreal xVal = mapFromScene(event->mapToGraphicsScene(tap->position( ))).x();
   540 				int rating = d->calculateProgressValue(xVal);
   540                 int rating = d->calculateProgressValue(xVal);
   541 				if(rating == -1) {
   541                 if(rating == -1) {
   542 					return;
   542                     return;
   543 				}
   543                 }
   544                 if(d->mReadOnly) {	
   544                 if(d->mReadOnly) {    
   545                     event->ignore();
   545                     event->ignore();
   546                     return;
   546                     return;
   547                 }
   547                 }
   548 
   548 
   549                 d->mMousePressed = true;
   549                 d->mMousePressed = true;
   550                 event->accept();
   550                 event->accept();
   551 				}
   551                 }
   552                 break;
   552                 break;
   553  
   553  
   554             case Qt::GestureFinished: // Reset state 
   554             case Qt::GestureFinished: // Reset state 
   555                 {
   555                 {
   556             qreal xVal = mapFromScene(event->mapToGraphicsScene(tap->position( ))).x();
   556             qreal xVal = mapFromScene(event->mapToGraphicsScene(tap->position( ))).x();
   560                 if(d->mReadOnly) {
   560                 if(d->mReadOnly) {
   561                     event->ignore();
   561                     event->ignore();
   562                     return;
   562                     return;
   563                 }
   563                 }
   564 
   564 
   565 				if(!d->mMousePressed){
   565                 if(!d->mMousePressed){
   566 					return;
   566                     return;
   567 				}
   567                 }
   568 
   568 
   569                 if(xVal <0) {	
   569                 if(xVal <0) {    
   570                     setCurrentRating(0);
   570                     setCurrentRating(0);
   571 					emit ratingDone (d->mCurrentValue);
   571                     emit ratingDone (d->mCurrentValue);
   572                     return;
   572                     return;
   573                 }
   573                 }
   574 
   574 
   575                rating = d->calculateProgressValue(xVal);
   575                rating = d->calculateProgressValue(xVal);
   576 		
   576         
   577 			   if(toolTip() != QString()) {
   577                if(toolTip() != QString()) {
   578                     HbToolTip::showText(toolTip(),this);
   578                     HbToolTip::showText(toolTip(),this);
   579                 }	
   579                 }    
   580                 setCurrentRating(rating);
   580                 setCurrentRating(rating);
   581                 if(d->mCurrentValue) {
   581                 if(d->mCurrentValue) {
   582                     emit ratingDone (d->mCurrentValue);
   582                     emit ratingDone (d->mCurrentValue);
   583                 }
   583                 }
   584                 event->accept();
   584                 event->accept();
   592                 HbPanGesture *pan = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture));
   592                 HbPanGesture *pan = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture));
   593                 switch(pan->state()) {
   593                 switch(pan->state()) {
   594                     case Qt::GestureUpdated:
   594                     case Qt::GestureUpdated:
   595                         {
   595                         {
   596                         if(!d->mMousePressed) {
   596                         if(!d->mMousePressed) {
   597 		                    return;
   597                             return;
   598 	                    }
   598                         }
   599                         qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x();
   599                         qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x();
   600 		                    QRectF rect = d->mTouchArea->boundingRect();
   600                             QRectF rect = d->mTouchArea->boundingRect();
   601 		                    int rating=0;
   601                             int rating=0;
   602 		                    if(rect.contains(xVal,0 )) {
   602                             if(rect.contains(xVal,0 )) {
   603                                 if(d->mReadOnly) {
   603                                 if(d->mReadOnly) {
   604 			                    event->ignore();
   604                                 event->ignore();
   605 			                    return;
   605                                 return;
   606 		                    }
   606                             }
   607                     		
   607                             
   608 		                    if(xVal <0) {	
   608                             if(xVal <0) {    
   609 			                    setCurrentRating(0);
   609                                 setCurrentRating(0);
   610 								return;
   610                                 return;
   611 		                    }
   611                             }
   612 
   612 
   613 			                    rating = d->calculateProgressValue(xVal);
   613                                 rating = d->calculateProgressValue(xVal);
   614 								
   614                                 
   615 			                    if(toolTip() != QString()) {
   615                                 if(toolTip() != QString()) {
   616 				                    HbToolTip::showText(toolTip(),this);
   616                                     HbToolTip::showText(toolTip(),this);
   617 			                    }	
   617                                 }    
   618 			                    setCurrentRating(rating);
   618                                 setCurrentRating(rating);
   619 			                    emit ratingChanged (d->mCurrentValue);
   619                                 emit ratingChanged (d->mCurrentValue);
   620 			                    event->accept();
   620                                 event->accept();
   621 		                    }
   621                             }
   622 	                        else {
   622                             else {
   623 			                    setCurrentRating(0);
   623                                 setCurrentRating(0);
   624 		                    }
   624                             }
   625                         }
   625                         }
   626                         break;
   626                         break;
   627 				    case Qt::GestureFinished: // Reset state 
   627                     case Qt::GestureFinished: // Reset state 
   628 					{						  
   628                     {                          
   629 						 qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x();
   629                          qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x();
   630                          QRectF rect = d->mTouchArea->boundingRect();
   630                          QRectF rect = d->mTouchArea->boundingRect();
   631                          int rating=0;
   631                          int rating=0;
   632                          if(rect.contains(xVal,0 )) {
   632                          if(rect.contains(xVal,0 )) {
   633                             if(d->mReadOnly) {
   633                             if(d->mReadOnly) {
   634                                event->ignore();
   634                                event->ignore();
   635                                return;
   635                                return;
   636                              }
   636                              }
   637 						}
   637                         }
   638 
   638 
   639 						if(!d->mMousePressed) {
   639                         if(!d->mMousePressed) {
   640 							 return;
   640                              return;
   641 						}
   641                         }
   642 
   642 
   643                        if(xVal <0) {	
   643                        if(xVal <0) {    
   644                           setCurrentRating(0);
   644                           setCurrentRating(0);
   645 						  emit ratingDone (d->mCurrentValue);
   645                           emit ratingDone (d->mCurrentValue);
   646                           return;
   646                           return;
   647                         }
   647                         }
   648 
   648 
   649                         rating = d->calculateProgressValue(xVal);
   649                         rating = d->calculateProgressValue(xVal);
   650 					    setCurrentRating(rating);
   650                         setCurrentRating(rating);
   651                         if(d->mCurrentValue) {
   651                         if(d->mCurrentValue) {
   652                            emit ratingDone (d->mCurrentValue);
   652                            emit ratingDone (d->mCurrentValue);
   653                         }
   653                         }
   654 					    d->mMousePressed = false;
   654                         d->mMousePressed = false;
   655                         event->accept();
   655                         event->accept();
   656 					 }
   656                      }
   657                      default:
   657                      default:
   658                      break;
   658                      break;
   659                 }
   659                 }
   660     }
   660     }
   661 }
   661 }
   664 /*!
   664 /*!
   665     \reimp
   665     \reimp
   666 */
   666 */
   667 void HbRatingSlider::setGeometry(const QRectF & rect)
   667 void HbRatingSlider::setGeometry(const QRectF & rect)
   668 {
   668 {
   669 	Q_D(HbRatingSlider);
   669     Q_D(HbRatingSlider);
   670 	HbWidget::setGeometry(rect);
   670     HbWidget::setGeometry(rect);
   671 	updatePrimitives();
   671     updatePrimitives();
   672 	d->createLookupTable();
   672     d->createLookupTable();
   673 }
   673 }
   674 
   674 
   675 void HbRatingSlider::initStyleOption(HbStyleOption *hboption) const
   675 void HbRatingSlider::initStyleOption(HbStyleOption *hboption) const
   676 {
   676 {
   677 	Q_D( const HbRatingSlider );
   677     Q_D( const HbRatingSlider );
   678 	 HbWidget::initStyleOption(hboption); 
   678      HbWidget::initStyleOption(hboption); 
   679     HbStyleOptionRatingSlider *option = 0;
   679     HbStyleOptionRatingSlider *option = 0;
   680     if ((option = qstyleoption_cast< HbStyleOptionRatingSlider *>(hboption)) != 0) {
   680     if ((option = qstyleoption_cast< HbStyleOptionRatingSlider *>(hboption)) != 0) {
   681 		option->noOfStars = d->mNumberOfIcons;
   681         option->noOfStars = d->mNumberOfIcons;
   682 		option->noOfIntervals = d->mStepCount;
   682         option->noOfIntervals = d->mStepCount;
   683 		option->unRatedGraphicsName = d->mUnratedIconName;
   683         option->unRatedGraphicsName = d->mUnratedIconName;
   684 		option->ratedGraphicsName = d->mRatedIconName;
   684         option->ratedGraphicsName = d->mRatedIconName;
   685 		option->progressValue = d->mCurrentValue;
   685         option->progressValue = d->mCurrentValue;
   686 	}
   686     }
   687 }
   687 }
   688 
   688 
   689 /*!
   689 /*!
   690 
   690 
   691     \deprecated HbRatingSlider::primitive(HbStyle::Primitive)
   691     \deprecated HbRatingSlider::primitive(HbStyle::Primitive)
   696     primitives are P_RatingSlider_frame,P_RatingSlider_track and P_RatingSlider_layout.
   696     primitives are P_RatingSlider_frame,P_RatingSlider_track and P_RatingSlider_layout.
   697 
   697 
   698 */
   698 */
   699 QGraphicsItem* HbRatingSlider::primitive(HbStyle::Primitive primitive) const
   699 QGraphicsItem* HbRatingSlider::primitive(HbStyle::Primitive primitive) const
   700 {
   700 {
   701 	Q_D(const HbRatingSlider);
   701     Q_D(const HbRatingSlider);
   702     switch (primitive) {
   702     switch (primitive) {
   703         case HbStyle::P_RatingSlider_frame:
   703         case HbStyle::P_RatingSlider_frame:
   704             return d->mFrame;
   704             return d->mFrame;
   705         case HbStyle::P_RatingSlider_track:
   705         case HbStyle::P_RatingSlider_track:
   706             return d->mTrack;  
   706             return d->mTrack;  
   707 		case HbStyle::P_RatingSlider_layout:
   707         case HbStyle::P_RatingSlider_layout:
   708 			return d->mLayoutItem;
   708             return d->mLayoutItem;
   709          default:
   709          default:
   710             return 0;
   710             return 0;
   711     }
   711     }
   712 }
   712 }
   713 
   713 
   714 void HbRatingSlider::changeEvent(QEvent *event)
   714 void HbRatingSlider::changeEvent(QEvent *event)
   715 {
   715 {
   716     HbWidget::changeEvent(event);
   716     HbWidget::changeEvent(event);
   717     switch (event->type()) {
   717     switch (event->type()) {
   718     case QEvent::LayoutDirectionChange:
   718     case QEvent::LayoutDirectionChange:
   719 		updatePrimitives();
   719         updatePrimitives();
   720         break;
   720         break;
   721     default:
   721     default:
   722         break;
   722         break;
   723     }
   723     }
   724 }
   724 }
   725 void HbRatingSlider::updatePrimitives()
   725 void HbRatingSlider::updatePrimitives()
   726 {
   726 {
   727 	Q_D(HbRatingSlider);
   727     Q_D(HbRatingSlider);
   728 	HbStyleOptionRatingSlider option;
   728     HbStyleOptionRatingSlider option;
   729     initStyleOption(&option);
   729     initStyleOption(&option);
   730 	if (d->mFrame) {
   730     if (d->mFrame) {
   731             style()->updatePrimitive(d->mFrame, HbStyle::P_RatingSlider_frame, &option);
   731             style()->updatePrimitive(d->mFrame, HbStyle::P_RatingSlider_frame, &option);
   732     }
   732     }
   733   
   733   
   734     if (d->mTrack) {
   734     if (d->mTrack) {
   735            style()->updatePrimitive(d->mTrack, HbStyle::P_RatingSlider_track, &option);
   735            style()->updatePrimitive(d->mTrack, HbStyle::P_RatingSlider_track, &option);
   736     }
   736     }
   737 
   737 
   738 	if (d->mTouchArea) {
   738     if (d->mTouchArea) {
   739         style()->updatePrimitive(d->mTouchArea, HbStyle::P_CheckBox_toucharea, &option);
   739         style()->updatePrimitive(d->mTouchArea, HbStyle::P_CheckBox_toucharea, &option);
   740     }
   740     }
   741 	
   741     
   742 }
   742 }
   743 
   743 
   744 QVariant HbRatingSlider::itemChange(GraphicsItemChange change, const QVariant &value)
   744 QVariant HbRatingSlider::itemChange(GraphicsItemChange change, const QVariant &value)
   745 {
   745 {
   746     if(change == ItemVisibleHasChanged && value.toBool()){
   746     if(change == ItemVisibleHasChanged && value.toBool()){
   750     if(change == QGraphicsItem::ItemVisibleChange){
   750     if(change == QGraphicsItem::ItemVisibleChange){
   751         if(value.toBool()) {
   751         if(value.toBool()) {
   752 
   752 
   753             HbEffect::start(this, HB_RATINGSLIDER_ITEM_TYPE, "ratingslider_appear");
   753             HbEffect::start(this, HB_RATINGSLIDER_ITEM_TYPE, "ratingslider_appear");
   754         }
   754         }
   755 		else
   755         else
   756 		{
   756         {
   757 			 HbEffect::start(this, HB_RATINGSLIDER_ITEM_TYPE, "ratingslider_disappear");
   757              HbEffect::start(this, HB_RATINGSLIDER_ITEM_TYPE, "ratingslider_disappear");
   758 		}
   758         }
   759 	}
   759     }
   760 
   760 
   761 #endif//HB_EFFECTS
   761 #endif//HB_EFFECTS
   762 
   762 
   763    return HbWidget::itemChange(change,value);
   763    return HbWidget::itemChange(change,value);
   764 }
   764 }