20 ** |
20 ** |
21 ** If you have questions regarding the use of this file, please contact |
21 ** If you have questions regarding the use of this file, please contact |
22 ** Nokia at developer.feedback@nokia.com. |
22 ** Nokia at developer.feedback@nokia.com. |
23 ** |
23 ** |
24 ****************************************************************************/ |
24 ****************************************************************************/ |
25 |
25 #include "hbratingslider_p.h" |
26 |
|
27 #include <hbratingslider.h> |
26 #include <hbratingslider.h> |
28 #include "hbratingslider_p.h" |
|
29 #include <hbtooltip.h> |
27 #include <hbtooltip.h> |
30 #include <hbstyleoptionratingslider_p.h> |
28 #include <hbstyleoptionratingslider_p.h> |
31 #include <QGraphicsItem> |
29 #include <QGraphicsItem> |
32 #include <QGraphicsSceneMouseEvent> |
30 #include <QGraphicsSceneMouseEvent> |
33 #include <hbtoucharea.h> |
31 #include <hbtoucharea.h> |
|
32 #include <hbwidgetfeedback.h> |
34 |
33 |
35 #ifdef HB_GESTURE_FW |
34 #ifdef HB_GESTURE_FW |
36 #include <hbtapgesture.h> |
35 #include <hbtapgesture.h> |
37 #include <hbpangesture.h> |
36 #include <hbpangesture.h> |
38 #endif |
37 #endif |
138 |
137 |
139 } |
138 } |
140 |
139 |
141 /*! |
140 /*! |
142 \class HbRatingSlider |
141 \class HbRatingSlider |
143 \brief A control for user to do rating. |
142 \brief This is a widget that enables a user to rate contents like videos , music etc. |
144 |
143 \image html ratingslider.png "A Rating Slider with rating done" |
145 This is a general rating widget where user will be able to do different |
144 |
146 ratings for things like Music ,Video etc. |
145 The default version of Rating Slider contains 5 repeated icons drawn side by side, using a single themed graphics. |
147 |
146 The application can replace the themed graphic with a custom graphic. |
148 By default there are 5 ratings ( 5 stars ). This can be configured also. |
147 The custom graphics should contain only one icon (eg one star) which will be multipled by the API \a setNumberOfIcons(). |
149 The interval , number of icons etc can be configured. |
148 By default it is 5 and maximum number of icons are 10. |
150 |
149 |
151 Apart from rating the this can used for showing cumulative rating also. |
150 Along with the rating Rating Slider can be used to show the cumulative rating also. |
152 |
151 |
153 example code example: |
152 To use HbRatingSlider with default settings it just needs to be created. |
|
153 example code: |
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 HbRatingSlider emits below signals |
159 by default the stepcount =5 |
159 |
160 |
160 void ratingDone(int ratingValue); |
|
161 void ratingChanged(int ratingValue); |
|
162 |
|
163 ratingDone is emitted when the user does the rating and releases the finger. |
|
164 ratingChanged is emitted when the user presses and drags the finger on Rating Slider. |
|
165 |
|
166 To use HbRatingSlider with default settings it just needs to be created. |
|
167 example code: |
|
168 \code |
|
169 HbMainWindow window; |
|
170 HbRatingSlider *rs = new HbRatingSlider(); |
|
171 window.addView(rs); |
|
172 \endcode |
|
173 |
|
174 HbRatingSlider supports integer ratings.But using the API \a setStepCount() fraction ratings can also be |
|
175 shown on Rating Slider |
|
176 |
|
177 The below code can be used to show some rating e.g. 2.5/5 |
161 \code |
178 \code |
|
179 //2.5/5 can be set as 25/50 |
162 HbRatingSlider *slider = new HbRatingSlider(); |
180 HbRatingSlider *slider = new HbRatingSlider(); |
163 slider->setStepCount(100); //5 *20// |
181 slider->setStepCount(50); //5 *10// |
164 slider->setCurrentRating(50); //2.5*20 it shows 50 / 100 which is same as 2.5/5 |
182 slider->setCurrentRating(25); //2.5*10 it shows 25/50 which is same as 2.5/5 |
165 \endcode |
183 \endcode |
166 |
184 |
167 This will show as 2.5/5. Now if one the same ratingslider |
185 This will show as 2.5/5. Now if on the same ratingslider |
168 if the Application wants to configure a rating slider with range 1-5 |
186 the Application wants to configure a Rating Slider with range 1-5 |
169 on emitting the signal rating changed it can set to |
187 on emitting the signal rating changed it can set to 5. |
170 slider->setStepCount(5); |
|
171 slider->setCurrentRating(0) |
|
172 |
|
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. |
|
175 |
|
176 */ |
188 */ |
177 |
189 |
178 |
190 |
179 |
191 /*! |
180 /*! |
192 @beta |
181 @beta |
193 Constructs a Rating Slider bar with the given parent. |
182 Constructor of RatingSlider. |
194 \param parent Parent Item. |
183 \param parent. Parent widget |
195 |
184 |
196 */ |
185 */ |
197 |
|
198 |
|
199 |
186 |
200 |
187 HbRatingSlider::HbRatingSlider(QGraphicsItem *parent) : |
201 HbRatingSlider::HbRatingSlider(QGraphicsItem *parent) : |
188 HbWidget(*new HbRatingSliderPrivate,parent) |
202 HbWidget(*new HbRatingSliderPrivate,parent) |
189 { |
203 { |
190 Q_D( HbRatingSlider ); |
204 Q_D( HbRatingSlider ); |
463 |
475 |
464 QRectF rect = d->mTouchArea->boundingRect(); |
476 QRectF rect = d->mTouchArea->boundingRect(); |
465 int rating=0; |
477 int rating=0; |
466 if(rect.contains(xVal,0 )) { |
478 if(rect.contains(xVal,0 )) { |
467 rating = d->calculateProgressValue(xVal); |
479 rating = d->calculateProgressValue(xVal); |
468 if(toolTip() != QString()) { |
480 if(!toolTip().isNull()) { |
469 HbToolTip::showText(toolTip(),this); |
481 HbToolTip::showText(toolTip(),this); |
470 } |
482 } |
471 setCurrentRating(rating); |
483 setCurrentRating(rating); |
472 emit ratingChanged (d->mCurrentValue); |
484 emit ratingChanged (d->mCurrentValue); |
473 event->accept(); |
485 event->accept(); |
505 |
517 |
506 QRectF rect = d->mTouchArea->boundingRect(); |
518 QRectF rect = d->mTouchArea->boundingRect(); |
507 int rating=0; |
519 int rating=0; |
508 if(rect.contains(xVal,0 )) { |
520 if(rect.contains(xVal,0 )) { |
509 rating = d->calculateProgressValue(xVal); |
521 rating = d->calculateProgressValue(xVal); |
510 if(toolTip() != QString()) { |
522 if(!toolTip().isNull()) { |
511 HbToolTip::showText(toolTip(),this); |
523 HbToolTip::showText(toolTip(),this); |
512 } |
524 } |
513 setCurrentRating(rating); |
525 setCurrentRating(rating); |
514 if(d->mCurrentValue) { |
526 if(d->mCurrentValue) { |
515 emit ratingDone (d->mCurrentValue); |
527 emit ratingDone (d->mCurrentValue); |
516 } |
528 } |
517 event->accept(); |
529 event->accept(); |
518 d->mMousePressed = false; |
530 d->mMousePressed = false; |
519 } |
531 } |
|
532 updatePrimitives(); |
520 |
533 |
521 } |
534 } |
522 } |
535 } |
523 #else |
536 #else |
|
537 /*! |
|
538 \reimp |
|
539 */ |
524 void HbRatingSlider::mousePressEvent(QGraphicsSceneMouseEvent *event) |
540 void HbRatingSlider::mousePressEvent(QGraphicsSceneMouseEvent *event) |
525 { |
541 { |
526 Q_UNUSED(event) |
542 Q_UNUSED(event) |
527 } |
543 } |
528 #endif |
544 #endif |
529 |
545 |
530 #ifdef HB_GESTURE_FW |
546 #ifdef HB_GESTURE_FW |
|
547 /*! |
|
548 \reimp |
|
549 */ |
531 void HbRatingSlider::gestureEvent(QGestureEvent *event) |
550 void HbRatingSlider::gestureEvent(QGestureEvent *event) |
532 { |
551 { |
533 Q_D (HbRatingSlider); |
552 Q_D (HbRatingSlider); |
534 if(event->gesture(Qt::TapGesture)) { |
553 if(event->gesture(Qt::TapGesture)) { |
535 HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture)); |
554 HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture)); |
572 return; |
601 return; |
573 } |
602 } |
574 |
603 |
575 rating = d->calculateProgressValue(xVal); |
604 rating = d->calculateProgressValue(xVal); |
576 |
605 |
577 if(toolTip() != QString()) { |
606 if(!toolTip().isNull()) { |
578 HbToolTip::showText(toolTip(),this); |
607 HbToolTip::showText(toolTip(),this); |
579 } |
608 } |
580 setCurrentRating(rating); |
609 setCurrentRating(rating); |
|
610 HbWidgetFeedback::triggered(this, Hb::InstantReleased); |
581 if(d->mCurrentValue) { |
611 if(d->mCurrentValue) { |
582 emit ratingDone (d->mCurrentValue); |
612 emit ratingDone (d->mCurrentValue); |
583 } |
613 } |
|
614 |
584 event->accept(); |
615 event->accept(); |
585 d->mMousePressed = false; |
616 d->mMousePressed = false; |
586 } |
617 updatePrimitives(); |
|
618 } |
|
619 else { |
|
620 |
|
621 d->mMousePressed = false; |
|
622 updatePrimitives(); |
|
623 |
|
624 if(xVal <rect.x() ) { |
|
625 |
|
626 setCurrentRating(0); |
|
627 emit ratingDone (d->mCurrentValue); |
|
628 } |
|
629 |
|
630 } |
|
631 |
|
632 |
|
633 |
|
634 |
587 } |
635 } |
588 break; |
636 break; |
589 default: break; |
637 default: break; |
590 } |
638 } |
591 }else if(event->gesture(Qt::PanGesture)) { |
639 }else if(event->gesture(Qt::PanGesture)) { |
626 break; |
675 break; |
627 case Qt::GestureFinished: // Reset state |
676 case Qt::GestureFinished: // Reset state |
628 { |
677 { |
629 qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x(); |
678 qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x(); |
630 QRectF rect = d->mTouchArea->boundingRect(); |
679 QRectF rect = d->mTouchArea->boundingRect(); |
|
680 d->mMousePressed = false; |
|
681 updatePrimitives(); |
631 int rating=0; |
682 int rating=0; |
632 if(rect.contains(xVal,0 )) { |
683 if(rect.contains(xVal,0 )) { |
633 if(d->mReadOnly) { |
684 if(d->mReadOnly) { |
634 event->ignore(); |
685 event->ignore(); |
635 return; |
686 return; |
636 } |
687 } |
637 } |
688 } |
638 |
689 |
639 if(!d->mMousePressed) { |
690 if(xVal <0) { |
640 return; |
691 setCurrentRating(0); |
641 } |
692 emit ratingDone (d->mCurrentValue); |
642 |
693 return; |
643 if(xVal <0) { |
694 } |
644 setCurrentRating(0); |
695 |
645 emit ratingDone (d->mCurrentValue); |
696 rating = d->calculateProgressValue(xVal); |
646 return; |
697 setCurrentRating(rating); |
647 } |
698 HbWidgetFeedback::triggered(this, Hb::InstantReleased); |
648 |
699 if(d->mCurrentValue) { |
649 rating = d->calculateProgressValue(xVal); |
700 emit ratingDone (d->mCurrentValue); |
650 setCurrentRating(rating); |
701 } |
651 if(d->mCurrentValue) { |
702 event->accept(); |
652 emit ratingDone (d->mCurrentValue); |
703 |
653 } |
704 } |
654 d->mMousePressed = false; |
705 |
655 event->accept(); |
706 |
656 } |
707 default: |
657 default: |
708 break; |
658 break; |
|
659 } |
709 } |
660 } |
710 } |
661 } |
711 } |
662 #endif |
712 #endif |
663 |
713 |
708 return d->mLayoutItem; |
762 return d->mLayoutItem; |
709 default: |
763 default: |
710 return 0; |
764 return 0; |
711 } |
765 } |
712 } |
766 } |
713 |
767 /*! |
|
768 \reimp |
|
769 */ |
714 void HbRatingSlider::changeEvent(QEvent *event) |
770 void HbRatingSlider::changeEvent(QEvent *event) |
715 { |
771 { |
716 HbWidget::changeEvent(event); |
772 HbWidget::changeEvent(event); |
717 switch (event->type()) { |
773 switch (event->type()) { |
718 case QEvent::LayoutDirectionChange: |
774 case QEvent::LayoutDirectionChange: |
719 updatePrimitives(); |
775 updatePrimitives(); |
720 break; |
776 break; |
|
777 case QEvent::EnabledChange: |
|
778 updatePrimitives(); |
|
779 break; |
721 default: |
780 default: |
722 break; |
781 break; |
723 } |
782 } |
724 } |
783 } |
|
784 /*! |
|
785 \reimp |
|
786 */ |
725 void HbRatingSlider::updatePrimitives() |
787 void HbRatingSlider::updatePrimitives() |
726 { |
788 { |
727 Q_D(HbRatingSlider); |
789 Q_D(HbRatingSlider); |
728 HbStyleOptionRatingSlider option; |
790 HbStyleOptionRatingSlider option; |
729 initStyleOption(&option); |
791 initStyleOption(&option); |