src/hbwidgets/sliders/hbratingslider.cpp
changeset 6 c3690ec91ef8
parent 5 627c4a0fd0e7
child 7 923ff622b8b9
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    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 
    26 
       
    27 #include <hbratingslider.h>
    26 #include <hbratingslider.h>
    28 #include "hbratingslider_p.h"
    27 #include "hbratingslider_p.h"
    29 #include <hbtooltip.h>
    28 #include <hbtooltip.h>
    30 #include <hbstyleoptionratingslider_p.h>
    29 #include <hbstyleoptionratingslider_p.h>
    31 #include <QGraphicsItem>
    30 #include <QGraphicsItem>
   442             event->ignore();
   441             event->ignore();
   443             return;
   442             return;
   444         }
   443         }
   445         d->mMousePressed = true;
   444         d->mMousePressed = true;
   446         event->accept();
   445         event->accept();
       
   446         updatePrimitives();
   447 
   447 
   448     }
   448     }
   449 
   449 
   450 }
   450 }
   451 /*!
   451 /*!
   475         
   475         
   476         QRectF rect = d->mTouchArea->boundingRect();
   476         QRectF rect = d->mTouchArea->boundingRect();
   477         int rating=0;
   477         int rating=0;
   478         if(rect.contains(xVal,0 )) {
   478         if(rect.contains(xVal,0 )) {
   479             rating = d->calculateProgressValue(xVal);
   479             rating = d->calculateProgressValue(xVal);
   480             if(toolTip() != QString()) {
   480             if(!toolTip().isNull()) {
   481                 HbToolTip::showText(toolTip(),this);
   481                 HbToolTip::showText(toolTip(),this);
   482             }    
   482             }    
   483             setCurrentRating(rating);
   483             setCurrentRating(rating);
   484             emit ratingChanged (d->mCurrentValue);
   484             emit ratingChanged (d->mCurrentValue);
   485             event->accept();
   485             event->accept();
   517         
   517         
   518         QRectF rect = d->mTouchArea->boundingRect();
   518         QRectF rect = d->mTouchArea->boundingRect();
   519         int rating=0;
   519         int rating=0;
   520         if(rect.contains(xVal,0 )) {
   520         if(rect.contains(xVal,0 )) {
   521             rating = d->calculateProgressValue(xVal);
   521             rating = d->calculateProgressValue(xVal);
   522             if(toolTip() != QString()) {
   522             if(!toolTip().isNull()) {
   523                 HbToolTip::showText(toolTip(),this);
   523                 HbToolTip::showText(toolTip(),this);
   524             }    
   524             }    
   525             setCurrentRating(rating);
   525             setCurrentRating(rating);
   526             if(d->mCurrentValue) {
   526             if(d->mCurrentValue) {
   527                 emit ratingDone (d->mCurrentValue);
   527                 emit ratingDone (d->mCurrentValue);
   528             }
   528             }
   529             event->accept();
   529             event->accept();
   530             d->mMousePressed = false;
   530             d->mMousePressed = false;
   531         }
   531         }
       
   532         updatePrimitives();
   532     
   533     
   533     }        
   534     }        
   534 }
   535 }
   535 #else
   536 #else
   536 /*!
   537 /*!
   561                 }
   562                 }
   562                 if(d->mReadOnly) {    
   563                 if(d->mReadOnly) {    
   563                     event->ignore();
   564                     event->ignore();
   564                     return;
   565                     return;
   565                 }
   566                 }
   566 
   567                 QRectF rect = d->mTouchArea->boundingRect();
   567                 d->mMousePressed = true;
   568                 if(rect.contains(xVal,0 )) {
   568                 event->accept();
   569                     d->mMousePressed = true;
       
   570                     updatePrimitives();
       
   571                     rating = d->calculateProgressValue(xVal);
       
   572                     setCurrentRating(rating);
       
   573                     event->accept();
       
   574                 }
       
   575                 else {
       
   576                     event->ignore();
       
   577                 }
       
   578                 
   569                 }
   579                 }
   570                 break;
   580                 break;
   571  
   581  
   572             case Qt::GestureFinished: // Reset state 
   582             case Qt::GestureFinished: // Reset state 
   573                 {
   583                 {
   590                     return;
   600                     return;
   591                 }
   601                 }
   592 
   602 
   593                rating = d->calculateProgressValue(xVal);
   603                rating = d->calculateProgressValue(xVal);
   594         
   604         
   595                if(toolTip() != QString()) {
   605                if(!toolTip().isNull()) {
   596                     HbToolTip::showText(toolTip(),this);
   606                     HbToolTip::showText(toolTip(),this);
   597                 }    
   607                 }    
   598                 setCurrentRating(rating);
   608                 setCurrentRating(rating);
   599                 if(d->mCurrentValue) {
   609                 if(d->mCurrentValue) {
   600                     emit ratingDone (d->mCurrentValue);
   610                     emit ratingDone (d->mCurrentValue);
   601                 }
   611                 }
   602                 event->accept();
   612                 event->accept();
   603                 d->mMousePressed = false;
   613                 d->mMousePressed = false;
   604                 }
   614                 updatePrimitives();
       
   615             }            
       
   616             else {
       
   617 
       
   618                 d->mMousePressed = false;
       
   619                 updatePrimitives();
       
   620 
       
   621                 if(xVal <rect.x() )  {
       
   622 
       
   623                     setCurrentRating(0);
       
   624                     emit ratingDone (d->mCurrentValue);
       
   625                 }
       
   626             
       
   627             }
       
   628             
       
   629 
       
   630 
       
   631 
   605             }
   632             }
   606             break;
   633             break;
   607             default: break;
   634             default: break;
   608             } 
   635             } 
   609     }else if(event->gesture(Qt::PanGesture)) {
   636     }else if(event->gesture(Qt::PanGesture)) {
   628                                 return;
   655                                 return;
   629                             }
   656                             }
   630 
   657 
   631                                 rating = d->calculateProgressValue(xVal);
   658                                 rating = d->calculateProgressValue(xVal);
   632                                 
   659                                 
   633                                 if(toolTip() != QString()) {
   660                                 if(!toolTip().isNull()) {
   634                                     HbToolTip::showText(toolTip(),this);
   661                                     HbToolTip::showText(toolTip(),this);
   635                                 }    
   662                                 }    
   636                                 setCurrentRating(rating);
   663                                 setCurrentRating(rating);
   637                                 emit ratingChanged (d->mCurrentValue);
   664                                 emit ratingChanged (d->mCurrentValue);
   638                                 event->accept();
   665                                 event->accept();
   644                         break;
   671                         break;
   645                     case Qt::GestureFinished: // Reset state 
   672                     case Qt::GestureFinished: // Reset state 
   646                     {                          
   673                     {                          
   647                          qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x();
   674                          qreal xVal = mapFromScene(event->mapToGraphicsScene( pan->startPos()+pan->offset())).x();
   648                          QRectF rect = d->mTouchArea->boundingRect();
   675                          QRectF rect = d->mTouchArea->boundingRect();
       
   676                          d->mMousePressed = false;
       
   677                          updatePrimitives();
   649                          int rating=0;
   678                          int rating=0;
   650                          if(rect.contains(xVal,0 )) {
   679                          if(rect.contains(xVal,0 )) {
   651                             if(d->mReadOnly) {
   680                             if(d->mReadOnly) {
   652                                event->ignore();
   681                                event->ignore();
   653                                return;
   682                                return;
   654                              }
   683                              }
   655                         }
   684                          }
   656 
   685 
   657                         if(!d->mMousePressed) {
   686                          if(xVal <0) {    
   658                              return;
   687                             setCurrentRating(0);
   659                         }
   688                             emit ratingDone (d->mCurrentValue);
   660 
   689                             return;
   661                        if(xVal <0) {    
   690                           }
   662                           setCurrentRating(0);
   691 
   663                           emit ratingDone (d->mCurrentValue);
   692                           rating = d->calculateProgressValue(xVal);
   664                           return;
   693                           setCurrentRating(rating);
   665                         }
   694                           if(d->mCurrentValue) {
   666 
   695                              emit ratingDone (d->mCurrentValue);
   667                         rating = d->calculateProgressValue(xVal);
   696                            }                       
   668                         setCurrentRating(rating);
   697                            event->accept();
   669                         if(d->mCurrentValue) {
   698                         
   670                            emit ratingDone (d->mCurrentValue);
   699                       }
   671                         }
   700                      
   672                         d->mMousePressed = false;
   701 					
   673                         event->accept();
   702 					default:
   674                      }
   703                       break;
   675                      default:
       
   676                      break;
       
   677                 }
   704                 }
   678     }
   705     }
   679 }
   706 }
   680 #endif 
   707 #endif 
   681 
   708 
   701         option->noOfStars = d->mNumberOfIcons;
   728         option->noOfStars = d->mNumberOfIcons;
   702         option->noOfIntervals = d->mStepCount;
   729         option->noOfIntervals = d->mStepCount;
   703         option->unRatedGraphicsName = d->mUnratedIconName;
   730         option->unRatedGraphicsName = d->mUnratedIconName;
   704         option->ratedGraphicsName = d->mRatedIconName;
   731         option->ratedGraphicsName = d->mRatedIconName;
   705         option->progressValue = d->mCurrentValue;
   732         option->progressValue = d->mCurrentValue;
       
   733         option->disableState = !isEnabled();
       
   734         option->pressedState = d->mMousePressed;
   706     }
   735     }
   707 }
   736 }
   708 
   737 
   709 /*!
   738 /*!
   710 
   739 
   738     HbWidget::changeEvent(event);
   767     HbWidget::changeEvent(event);
   739     switch (event->type()) {
   768     switch (event->type()) {
   740     case QEvent::LayoutDirectionChange:
   769     case QEvent::LayoutDirectionChange:
   741         updatePrimitives();
   770         updatePrimitives();
   742         break;
   771         break;
       
   772     case QEvent::EnabledChange:
       
   773          updatePrimitives();
       
   774           break;
   743     default:
   775     default:
   744         break;
   776         break;
   745     }
   777     }
   746 }
   778 }
   747 /*!
   779 /*!