src/hbwidgets/sliders/hbratingslider.cpp
changeset 28 b7da29130b0e
parent 23 e6ad4ef83b23
equal deleted inserted replaced
23:e6ad4ef83b23 28:b7da29130b0e
    54     mFrame(0),
    54     mFrame(0),
    55     mTrack(0),
    55     mTrack(0),
    56     mLayoutItem(0),
    56     mLayoutItem(0),
    57     mUnratedIconName(""),
    57     mUnratedIconName(""),
    58     mTouchArea(0),
    58     mTouchArea(0),
    59     mRatedIconName("")
    59     mRatedIconName(""),
       
    60     mToolTipText(""),
       
    61     mToolTipArea(0)
    60 {    
    62 {    
    61 }
    63 }
    62 
    64 
    63 HbRatingSliderPrivate::~HbRatingSliderPrivate()
    65 HbRatingSliderPrivate::~HbRatingSliderPrivate()
    64 {
    66 {
   475         
   477         
   476         QRectF rect = d->mTouchArea->boundingRect();
   478         QRectF rect = d->mTouchArea->boundingRect();
   477         int rating=0;
   479         int rating=0;
   478         if(rect.contains(xVal,0 )) {
   480         if(rect.contains(xVal,0 )) {
   479             rating = d->calculateProgressValue(xVal);
   481             rating = d->calculateProgressValue(xVal);
   480             if(!toolTip().isNull()) {
   482             if(!mToolTipText.isNull()) {
   481                 HbToolTip::showText(toolTip(),this);
   483                 HbToolTip::showText(mToolTipText,this);
   482             }    
   484             }    
   483             setCurrentRating(rating);
   485             setCurrentRating(rating);
   484             emit ratingChanged (d->mCurrentValue);
   486             emit ratingChanged (d->mCurrentValue);
   485             event->accept();
   487             event->accept();
   486         }
   488         }
   517         
   519         
   518         QRectF rect = d->mTouchArea->boundingRect();
   520         QRectF rect = d->mTouchArea->boundingRect();
   519         int rating=0;
   521         int rating=0;
   520         if(rect.contains(xVal,0 )) {
   522         if(rect.contains(xVal,0 )) {
   521             rating = d->calculateProgressValue(xVal);
   523             rating = d->calculateProgressValue(xVal);
   522             if(!toolTip().isNull()) {
   524             if(!mToolTipText.isNull()) {
   523                 HbToolTip::showText(toolTip(),this);
   525                 HbToolTip::showText(mToolTipText,this);
   524             }    
   526             }    
   525             setCurrentRating(rating);
   527             setCurrentRating(rating);
   526             if(d->mCurrentValue) {
   528             if(d->mCurrentValue) {
   527                 emit ratingDone (d->mCurrentValue);
   529                 emit ratingDone (d->mCurrentValue);
   528             }
   530             }
   553     if ( (!isEnabled()) || (d->mReadOnly)) {
   555     if ( (!isEnabled()) || (d->mReadOnly)) {
   554         event->ignore();
   556         event->ignore();
   555         return;
   557         return;
   556     }
   558     }
   557     if(event->gesture(Qt::TapGesture)) {
   559     if(event->gesture(Qt::TapGesture)) {
   558             HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
   560         HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
   559             switch(tap->state()) {
   561         switch(tap->state()) {
   560             case Qt::GestureStarted:
   562             case Qt::GestureStarted:
   561                 {
   563             {
   562                 qreal xVal = mapFromScene(event->mapToGraphicsScene(tap->position( ))).x();
   564                 qreal xVal = mapFromScene(event->mapToGraphicsScene(tap->position( ))).x();
   563                 int rating = d->calculateProgressValue(xVal);
   565                 int rating = d->calculateProgressValue(xVal);
   564                 if(rating == -1) {
   566                 if(rating == -1) {
       
   567                     event->ignore();
   565                     return;
   568                     return;
   566                 }
   569                 }
   567                 if(d->mReadOnly) {    
   570                 if(d->mReadOnly) {    
   568                     event->ignore();
   571                     event->ignore();
   569                     return;
   572                     return;
   570                 }
   573                 }            
   571                 QRectF rect = d->mTouchArea->boundingRect();
   574                 QRectF rect = d->mTouchArea->boundingRect();
   572                 if(rect.contains(xVal,0 )) {
   575                 if(rect.contains(xVal,0 )) {
   573                     HbWidgetFeedback::triggered(this, Hb::InstantPressed);
   576                     HbWidgetFeedback::triggered(this, Hb::InstantPressed);
   574                     d->mMousePressed = true;
   577                     d->mMousePressed = true;
   575                     updatePrimitives();
   578                     updatePrimitives();
   576                     rating = d->calculateProgressValue(xVal);
   579                     rating = d->calculateProgressValue(xVal);
   577                     setCurrentRating(rating);
   580                     setCurrentRating(rating);
       
   581                     emit ratingChanged (d->mCurrentValue);
       
   582                     if(!d->mToolTipArea)
       
   583                         d->mToolTipArea = new HbTouchArea(d->mFrame);
       
   584                     d->mToolTipArea->setPos(xVal,0);
       
   585                     d->mToolTipArea->setSize(QSize(1,1));
       
   586                     if(!d->mToolTipText.isNull()) {
       
   587                         HbToolTip::showText(d->mToolTipText,d->mToolTipArea);
       
   588                     }
   578                     event->accept();
   589                     event->accept();
   579                 }
   590                 }
   580                 else {
   591                 else {
   581                     event->ignore();
   592                     event->ignore();
   582                 }
   593                 }                
   583                 
   594             }
   584                 }
   595             break;
   585                 break;
       
   586  
   596  
   587             case Qt::GestureFinished: // Reset state 
   597             case Qt::GestureFinished: // Reset state 
   588                 {
   598             {
   589             qreal xVal = mapFromScene(event->mapToGraphicsScene(tap->position( ))).x();
   599                 qreal xVal = mapFromScene(event->mapToGraphicsScene(tap->position( ))).x();
   590             QRectF rect = d->mTouchArea->boundingRect();
   600                 QRectF rect = d->mTouchArea->boundingRect();
   591             int rating=0;
   601                 int rating=0;
   592             if(rect.contains(xVal,0 )) {
   602                 if(rect.contains(xVal,0 )) {
   593                 if(d->mReadOnly) {
   603                     if(d->mReadOnly) {
   594                     event->ignore();
   604                         event->ignore();
   595                     return;
   605                         return;
   596                 }
   606                     }
   597 
   607                     
   598                 if(!d->mMousePressed){
   608                     if(!d->mMousePressed){
   599                     return;
   609                         event->ignore();
   600                 }
   610                         return;
   601 
   611                     }
   602                 if(xVal <0) {    
   612                     if(xVal <0) {    
   603                     setCurrentRating(0);
   613                         setCurrentRating(0);
   604                     emit ratingDone (d->mCurrentValue);
   614                         emit ratingDone (d->mCurrentValue);
   605                     return;
   615                         return;
   606                 }
   616                     }
   607 
   617                     rating = d->calculateProgressValue(xVal);
   608                rating = d->calculateProgressValue(xVal);
   618                     setCurrentRating(rating);
   609         
   619                     HbWidgetFeedback::triggered(this, Hb::InstantReleased);
   610                if(!toolTip().isNull()) {
   620                     if(d->mCurrentValue) {
   611                     HbToolTip::showText(toolTip(),this);
   621                         emit ratingDone (d->mCurrentValue);
   612                 }    
   622                     }
   613                 setCurrentRating(rating);
   623                     event->accept();
   614                 HbWidgetFeedback::triggered(this, Hb::InstantReleased);
   624                     d->mMousePressed = false;
   615                 if(d->mCurrentValue) {
   625                     updatePrimitives();
   616                     emit ratingDone (d->mCurrentValue);
   626                 }            
   617                 }
   627                 else {
   618 
   628                         d->mMousePressed = false;
   619                 event->accept();
   629                         updatePrimitives();
   620                 d->mMousePressed = false;
   630                         if(xVal <rect.x() )  {
   621                 updatePrimitives();
   631                             setCurrentRating(0);
   622             }            
   632                             emit ratingDone (d->mCurrentValue);
   623             else {
   633                         }
   624 
       
   625                 d->mMousePressed = false;
       
   626                 updatePrimitives();
       
   627 
       
   628                 if(xVal <rect.x() )  {
       
   629 
       
   630                     setCurrentRating(0);
       
   631                     emit ratingDone (d->mCurrentValue);
       
   632                 }
       
   633             
   634             
   634             }
   635                     }        
   635             
       
   636 
       
   637 
       
   638 
       
   639             }
   636             }
   640             break;
   637             break;
   641             default: break;
   638             default: break;
   642             } 
   639             } 
   643     }else if(event->gesture(Qt::PanGesture)) {
   640     }
   644                 HbPanGesture *pan = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture));
   641     else if(event->gesture(Qt::PanGesture)) {
   645                 switch(pan->state()) {
   642         HbPanGesture *pan = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture));
   646                     case Qt::GestureUpdated:
   643         switch(pan->state()) {
   647                         {
   644             case Qt::GestureUpdated:
   648                         if(!d->mMousePressed) {
   645             {
   649                             return;
   646                 if(!d->mMousePressed) {
       
   647                     return;
       
   648                 }
       
   649                 qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x();
       
   650                 QRectF rect = d->mTouchArea->boundingRect();
       
   651                 int rating=0;
       
   652                 if(rect.contains(xVal,0 )) {
       
   653                     if(d->mReadOnly) {
       
   654                         event->ignore();
       
   655                         return;
       
   656                     }
       
   657                     if(xVal <0) {    
       
   658                         setCurrentRating(0);
       
   659                         return;
       
   660                     }
       
   661 
       
   662                     rating = d->calculateProgressValue(xVal);
       
   663                     if(!d->mToolTipArea)
       
   664                         d->mToolTipArea = new HbTouchArea(d->mFrame); //Need to show the tooltip at the touch point
       
   665                     if(rating!=-1) {
       
   666                         d->mToolTipArea->setPos(xVal,0);
       
   667                         d->mToolTipArea->setSize(QSize(1,1));
       
   668                         if(!d->mToolTipText.isNull()) {
       
   669                             HbToolTip::showText(d->mToolTipText,d->mToolTipArea);
   650                         }
   670                         }
   651                         qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x();
   671                     }
   652                             QRectF rect = d->mTouchArea->boundingRect();
   672                     setCurrentRating(rating);
   653                             int rating=0;
   673                     HbWidgetFeedback::continuousTriggered(this, Hb::ContinuousDragged);
   654                             if(rect.contains(xVal,0 )) {
   674                     emit ratingChanged (d->mCurrentValue);
   655                                 if(d->mReadOnly) {
   675                     event->accept();
   656                                 event->ignore();
   676                 }
   657                                 return;
   677                 else {
   658                             }
   678                      setCurrentRating(0);
   659                             
   679                 }
   660                             if(xVal <0) {    
   680             }
   661                                 setCurrentRating(0);
   681             break;
   662                                 return;
   682             case Qt::GestureFinished: // Reset state 
   663                             }
   683             {                          
   664 
   684                 qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x();
   665                                 rating = d->calculateProgressValue(xVal);
   685                 QRectF rect = d->mTouchArea->boundingRect();
   666                                 
   686                 d->mMousePressed = false;
   667                                 if(!toolTip().isNull()) {
   687                 updatePrimitives();
   668                                     HbToolTip::showText(toolTip(),this);
   688                 int rating=0;
   669                                 }    
   689                 if(rect.contains(xVal,0 )) {
   670                                 setCurrentRating(rating);
   690                     if(d->mReadOnly) {
   671                                 HbWidgetFeedback::continuousTriggered(this, Hb::ContinuousDragged);
   691                         event->ignore();
   672                                 emit ratingChanged (d->mCurrentValue);
   692                         return;
   673                                 event->accept();
   693                      }
   674                             }
   694                  }
   675                             else {
   695                  if(xVal <0) {    
   676                                 setCurrentRating(0);
   696                      setCurrentRating(0);
   677                             }
   697                      emit ratingDone (d->mCurrentValue);
   678                         }
   698                      return;
   679                         break;
   699                  }
   680                     case Qt::GestureFinished: // Reset state 
   700                  rating = d->calculateProgressValue(xVal);
   681                     {                          
   701                  setCurrentRating(rating);
   682                          qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x();
   702                  HbWidgetFeedback::triggered(this, Hb::InstantReleased);
   683                          QRectF rect = d->mTouchArea->boundingRect();
   703                  if(d->mCurrentValue) {
   684                          d->mMousePressed = false;
   704                     emit ratingDone (d->mCurrentValue);
   685                          updatePrimitives();
   705                  }                       
   686                          int rating=0;
   706                  event->accept();
   687                          if(rect.contains(xVal,0 )) {
       
   688                             if(d->mReadOnly) {
       
   689                                event->ignore();
       
   690                                return;
       
   691                              }
       
   692                          }
       
   693 
       
   694                          if(xVal <0) {    
       
   695                             setCurrentRating(0);
       
   696                             emit ratingDone (d->mCurrentValue);
       
   697                             return;
       
   698                           }
       
   699 
       
   700                           rating = d->calculateProgressValue(xVal);
       
   701                           setCurrentRating(rating);
       
   702                           HbWidgetFeedback::triggered(this, Hb::InstantReleased);
       
   703                           if(d->mCurrentValue) {
       
   704                              emit ratingDone (d->mCurrentValue);
       
   705                            }                       
       
   706                            event->accept();
       
   707                         
   707                         
   708                       }
   708             }
   709                      
   709             break;
   710                     
   710             default:
   711                     default:
   711                 break;
   712                       break;
   712         }
   713                 }
       
   714     }
   713     }
   715 }
   714 }
   716 #endif 
   715 #endif 
   717 
   716 
   718 /*!
   717 /*!
   726     d->createLookupTable();
   725     d->createLookupTable();
   727 }
   726 }
   728 /*!
   727 /*!
   729     \reimp
   728     \reimp
   730  */
   729  */
       
   730 
       
   731 void HbRatingSlider::setToolTipText(const QString tooltip)
       
   732 {
       
   733     Q_D(HbRatingSlider);
       
   734     d->mToolTipText = tooltip;
       
   735 }
       
   736 QString HbRatingSlider::toolTipText() const
       
   737 {
       
   738     Q_D(const HbRatingSlider);
       
   739     return d->mToolTipText;
       
   740 }
   731 void HbRatingSlider::initStyleOption(HbStyleOption *hboption) const
   741 void HbRatingSlider::initStyleOption(HbStyleOption *hboption) const
   732 {
   742 {
   733     Q_D( const HbRatingSlider );
   743     Q_D( const HbRatingSlider );
   734      HbWidget::initStyleOption(hboption); 
   744      HbWidget::initStyleOption(hboption); 
   735     HbStyleOptionRatingSlider *option = 0;
   745     HbStyleOptionRatingSlider *option = 0;