--- a/src/hbwidgets/sliders/hbratingslider.cpp Thu Sep 02 20:44:51 2010 +0300
+++ b/src/hbwidgets/sliders/hbratingslider.cpp Fri Sep 17 08:32:10 2010 +0300
@@ -56,7 +56,9 @@
mLayoutItem(0),
mUnratedIconName(""),
mTouchArea(0),
- mRatedIconName("")
+ mRatedIconName(""),
+ mToolTipText(""),
+ mToolTipArea(0)
{
}
@@ -477,8 +479,8 @@
int rating=0;
if(rect.contains(xVal,0 )) {
rating = d->calculateProgressValue(xVal);
- if(!toolTip().isNull()) {
- HbToolTip::showText(toolTip(),this);
+ if(!mToolTipText.isNull()) {
+ HbToolTip::showText(mToolTipText,this);
}
setCurrentRating(rating);
emit ratingChanged (d->mCurrentValue);
@@ -519,8 +521,8 @@
int rating=0;
if(rect.contains(xVal,0 )) {
rating = d->calculateProgressValue(xVal);
- if(!toolTip().isNull()) {
- HbToolTip::showText(toolTip(),this);
+ if(!mToolTipText.isNull()) {
+ HbToolTip::showText(mToolTipText,this);
}
setCurrentRating(rating);
if(d->mCurrentValue) {
@@ -555,19 +557,20 @@
return;
}
if(event->gesture(Qt::TapGesture)) {
- HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
- switch(tap->state()) {
+ HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
+ switch(tap->state()) {
case Qt::GestureStarted:
- {
+ {
qreal xVal = mapFromScene(event->mapToGraphicsScene(tap->position( ))).x();
int rating = d->calculateProgressValue(xVal);
if(rating == -1) {
+ event->ignore();
return;
}
if(d->mReadOnly) {
event->ignore();
return;
- }
+ }
QRectF rect = d->mTouchArea->boundingRect();
if(rect.contains(xVal,0 )) {
HbWidgetFeedback::triggered(this, Hb::InstantPressed);
@@ -575,142 +578,138 @@
updatePrimitives();
rating = d->calculateProgressValue(xVal);
setCurrentRating(rating);
+ emit ratingChanged (d->mCurrentValue);
+ if(!d->mToolTipArea)
+ d->mToolTipArea = new HbTouchArea(d->mFrame);
+ d->mToolTipArea->setPos(xVal,0);
+ d->mToolTipArea->setSize(QSize(1,1));
+ if(!d->mToolTipText.isNull()) {
+ HbToolTip::showText(d->mToolTipText,d->mToolTipArea);
+ }
event->accept();
}
else {
event->ignore();
- }
-
- }
- break;
+ }
+ }
+ break;
case Qt::GestureFinished: // Reset state
- {
- qreal xVal = mapFromScene(event->mapToGraphicsScene(tap->position( ))).x();
- QRectF rect = d->mTouchArea->boundingRect();
- int rating=0;
- if(rect.contains(xVal,0 )) {
- if(d->mReadOnly) {
- event->ignore();
- return;
- }
-
- if(!d->mMousePressed){
- return;
- }
-
- if(xVal <0) {
- setCurrentRating(0);
- emit ratingDone (d->mCurrentValue);
- return;
- }
-
- rating = d->calculateProgressValue(xVal);
-
- if(!toolTip().isNull()) {
- HbToolTip::showText(toolTip(),this);
- }
- setCurrentRating(rating);
- HbWidgetFeedback::triggered(this, Hb::InstantReleased);
- if(d->mCurrentValue) {
- emit ratingDone (d->mCurrentValue);
- }
-
- event->accept();
- d->mMousePressed = false;
- updatePrimitives();
- }
- else {
-
- d->mMousePressed = false;
- updatePrimitives();
-
- if(xVal <rect.x() ) {
-
- setCurrentRating(0);
- emit ratingDone (d->mCurrentValue);
- }
+ {
+ qreal xVal = mapFromScene(event->mapToGraphicsScene(tap->position( ))).x();
+ QRectF rect = d->mTouchArea->boundingRect();
+ int rating=0;
+ if(rect.contains(xVal,0 )) {
+ if(d->mReadOnly) {
+ event->ignore();
+ return;
+ }
+
+ if(!d->mMousePressed){
+ event->ignore();
+ return;
+ }
+ if(xVal <0) {
+ setCurrentRating(0);
+ emit ratingDone (d->mCurrentValue);
+ return;
+ }
+ rating = d->calculateProgressValue(xVal);
+ setCurrentRating(rating);
+ HbWidgetFeedback::triggered(this, Hb::InstantReleased);
+ if(d->mCurrentValue) {
+ emit ratingDone (d->mCurrentValue);
+ }
+ event->accept();
+ d->mMousePressed = false;
+ updatePrimitives();
+ }
+ else {
+ d->mMousePressed = false;
+ updatePrimitives();
+ if(xVal <rect.x() ) {
+ setCurrentRating(0);
+ emit ratingDone (d->mCurrentValue);
+ }
- }
-
-
-
-
+ }
}
break;
default: break;
}
- }else if(event->gesture(Qt::PanGesture)) {
- HbPanGesture *pan = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture));
- switch(pan->state()) {
- case Qt::GestureUpdated:
- {
- if(!d->mMousePressed) {
- return;
- }
- qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x();
- QRectF rect = d->mTouchArea->boundingRect();
- int rating=0;
- if(rect.contains(xVal,0 )) {
- if(d->mReadOnly) {
- event->ignore();
- return;
- }
-
- if(xVal <0) {
- setCurrentRating(0);
- return;
- }
+ }
+ else if(event->gesture(Qt::PanGesture)) {
+ HbPanGesture *pan = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture));
+ switch(pan->state()) {
+ case Qt::GestureUpdated:
+ {
+ if(!d->mMousePressed) {
+ return;
+ }
+ qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x();
+ QRectF rect = d->mTouchArea->boundingRect();
+ int rating=0;
+ if(rect.contains(xVal,0 )) {
+ if(d->mReadOnly) {
+ event->ignore();
+ return;
+ }
+ if(xVal <0) {
+ setCurrentRating(0);
+ return;
+ }
- rating = d->calculateProgressValue(xVal);
-
- if(!toolTip().isNull()) {
- HbToolTip::showText(toolTip(),this);
- }
- setCurrentRating(rating);
- HbWidgetFeedback::continuousTriggered(this, Hb::ContinuousDragged);
- emit ratingChanged (d->mCurrentValue);
- event->accept();
- }
- else {
- setCurrentRating(0);
- }
+ rating = d->calculateProgressValue(xVal);
+ if(!d->mToolTipArea)
+ d->mToolTipArea = new HbTouchArea(d->mFrame); //Need to show the tooltip at the touch point
+ if(rating!=-1) {
+ d->mToolTipArea->setPos(xVal,0);
+ d->mToolTipArea->setSize(QSize(1,1));
+ if(!d->mToolTipText.isNull()) {
+ HbToolTip::showText(d->mToolTipText,d->mToolTipArea);
}
- break;
- case Qt::GestureFinished: // Reset state
- {
- qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x();
- QRectF rect = d->mTouchArea->boundingRect();
- d->mMousePressed = false;
- updatePrimitives();
- int rating=0;
- if(rect.contains(xVal,0 )) {
- if(d->mReadOnly) {
- event->ignore();
- return;
- }
- }
-
- if(xVal <0) {
- setCurrentRating(0);
- emit ratingDone (d->mCurrentValue);
- return;
- }
-
- rating = d->calculateProgressValue(xVal);
- setCurrentRating(rating);
- HbWidgetFeedback::triggered(this, Hb::InstantReleased);
- if(d->mCurrentValue) {
- emit ratingDone (d->mCurrentValue);
- }
- event->accept();
+ }
+ setCurrentRating(rating);
+ HbWidgetFeedback::continuousTriggered(this, Hb::ContinuousDragged);
+ emit ratingChanged (d->mCurrentValue);
+ event->accept();
+ }
+ else {
+ setCurrentRating(0);
+ }
+ }
+ break;
+ case Qt::GestureFinished: // Reset state
+ {
+ qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x();
+ QRectF rect = d->mTouchArea->boundingRect();
+ d->mMousePressed = false;
+ updatePrimitives();
+ int rating=0;
+ if(rect.contains(xVal,0 )) {
+ if(d->mReadOnly) {
+ event->ignore();
+ return;
+ }
+ }
+ if(xVal <0) {
+ setCurrentRating(0);
+ emit ratingDone (d->mCurrentValue);
+ return;
+ }
+ rating = d->calculateProgressValue(xVal);
+ setCurrentRating(rating);
+ HbWidgetFeedback::triggered(this, Hb::InstantReleased);
+ if(d->mCurrentValue) {
+ emit ratingDone (d->mCurrentValue);
+ }
+ event->accept();
- }
-
-
- default:
- break;
- }
+ }
+ break;
+ default:
+ break;
+ }
}
}
#endif
@@ -728,6 +727,17 @@
/*!
\reimp
*/
+
+void HbRatingSlider::setToolTipText(const QString tooltip)
+{
+ Q_D(HbRatingSlider);
+ d->mToolTipText = tooltip;
+}
+QString HbRatingSlider::toolTipText() const
+{
+ Q_D(const HbRatingSlider);
+ return d->mToolTipText;
+}
void HbRatingSlider::initStyleOption(HbStyleOption *hboption) const
{
Q_D( const HbRatingSlider );