src/hbwidgets/sliders/hbslidercontrol.cpp
changeset 6 c3690ec91ef8
parent 3 11d3954df52a
child 7 923ff622b8b9
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    27 #include "hbslidercontrol_p_p.h"
    27 #include "hbslidercontrol_p_p.h"
    28 #include "hbabstractslidercontrol_p.h"
    28 #include "hbabstractslidercontrol_p.h"
    29 #include "hbsliderhandle_p.h"
    29 #include "hbsliderhandle_p.h"
    30 #include "hbstyleoptionslider_p.h"
    30 #include "hbstyleoptionslider_p.h"
    31 #include "hbslidertickmarkslabel_p.h"
    31 #include "hbslidertickmarkslabel_p.h"
    32 #include "hbslidertickmarkslabel_p.h"
       
    33 #include <hbstyle.h>
    32 #include <hbstyle.h>
    34 #include <hbinstance.h>
    33 #include <hbinstance.h>
    35 #include <hbtheme.h>
    34 #include <hbtheme.h>
    36 #include <hbtooltip.h>
    35 #include <hbtooltip.h>
    37 #include <hbwidgetfeedback.h>
    36 #include <hbwidgetfeedback.h>
    94 void HbSliderControlPrivate::init( )
    93 void HbSliderControlPrivate::init( )
    95 {
    94 {
    96     Q_Q( HbSliderControl );
    95     Q_Q( HbSliderControl );
    97    
    96    
    98     q->enableTrackEventHandling( true );
    97     q->enableTrackEventHandling( true );
    99 #ifdef HB_GESTURE_FW
    98    
   100     q->grabGesture(Qt::TapGesture);
       
   101     q->grabGesture(Qt::PanGesture,Qt::ReceivePartialGestures);
       
   102     q->setFiltersChildEvents(true) ;
       
   103 #endif    
       
   104     // creating handle
    99     // creating handle
   105     handle = createHandle();
   100     handle = createHandle();
   106     if(handle) {
   101     if(handle) {
   107         HbStyle::setItemName( handle, "handle" );
   102         HbStyle::setItemName( handle, "handle" );
   108     }
   103     } 
   109     q->setFocusPolicy( Qt::FocusPolicy( ( qApp->style( ) )->styleHint( QStyle::SH_Button_FocusPolicy ) ) );
   104     q->setFocusPolicy( Qt::FocusPolicy( ( qApp->style( ) )->styleHint( QStyle::SH_Button_FocusPolicy ) ) );
   110     //creating groove
       
   111     groove = createGroove();
   105     groove = createGroove();
   112     if(groove) {
   106     if(groove) {
   113         HbStyle::setItemName( groove, "groove" );
   107         HbStyle::setItemName( groove, "groove" );
   114     }
   108     }
       
   109 #ifdef HB_GESTURE_FW
       
   110     q->setFiltersChildEvents(true) ;
       
   111 #endif
       
   112 
   115     //filled item top of groove
   113     //filled item top of groove
   116     if ( enableProgressTrack ) {
   114     if ( enableProgressTrack ) {
   117         progressGroove = createProgressGroove();
   115         progressGroove = createProgressGroove();
   118         if(progressGroove) {
   116         if(progressGroove) {
   119             HbStyle::setItemName( progressGroove, "progressgroove");
   117             HbStyle::setItemName( progressGroove, "progressgroove");
   127 
   125 
   128 
   126 
   129 
   127 
   130 /*!
   128 /*!
   131   \internal
   129   \internal
   132   This is used to create the handle, is virtual and can be overridden to create different handle.
   130   This is used to create the handle, it is virtual and can be overridden to create different handle.
   133   */
   131   */
   134 HbSliderHandle *HbSliderControlPrivate::createHandle()
   132 HbSliderHandle *HbSliderControlPrivate::createHandle()
   135 {
   133 {
   136     Q_Q( HbSliderControl );
   134     Q_Q( HbSliderControl );
   137     HbSliderHandle *handle = new HbSliderHandle( q );
   135     HbSliderHandle *handle = new HbSliderHandle( q );
   138     return handle;
   136     return handle;
   139 }
   137 }
   140 
   138 
   141 /*!
   139 /*!
   142   \internal
   140   \internal
   143   This is used to create the groove. can be overrideen by derived class
   141   This is used to create the groove.It can be overrideen by derived class
   144   */
   142   */
   145 QGraphicsItem *HbSliderControlPrivate::createGroove()
   143 QGraphicsItem *HbSliderControlPrivate::createGroove()
   146 {
   144 {
   147     Q_Q( HbSliderControl );
   145     Q_Q( HbSliderControl );
   148     QGraphicsItem *groove = qgraphicsitem_cast<QGraphicsItem*>( q->style( )->createPrimitive(
   146     QGraphicsItem *groove = qgraphicsitem_cast<QGraphicsItem*>( q->style( )->createPrimitive(
   149         HbStyle::P_Slider_groove, q ) );
   147         HbStyle::P_Slider_groove, q ) );
   150     return groove;
   148     return groove;
   151 }
   149 }
   152 /*!
   150 /*!
   153   \internal
   151   \internal
   154   This is used to create the masked progress groove. can be overrideen by derived class
   152   This is used to create the masked progress groove.This can be overrideen by derived class
   155   */
   153   */
   156 QGraphicsItem *HbSliderControlPrivate::createProgressGroove()
   154 QGraphicsItem *HbSliderControlPrivate::createProgressGroove()
   157 {
   155 {
   158     Q_Q( HbSliderControl );
   156     Q_Q( HbSliderControl );
   159     QGraphicsItem *proggroove = qgraphicsitem_cast<QGraphicsItem*>( q->style( )->createPrimitive(
   157     QGraphicsItem *proggroove = qgraphicsitem_cast<QGraphicsItem*>( q->style( )->createPrimitive(
   202         q->style( )->updatePrimitive( progressGroove, HbStyle::P_Slider_progressgroove, &opt );
   200         q->style( )->updatePrimitive( progressGroove, HbStyle::P_Slider_progressgroove, &opt );
   203     }
   201     }
   204 }
   202 }
   205 
   203 
   206 /*!
   204 /*!
   207    This api returns true if pos in on handle rect
   205    This api returns true if pos in on handle boundingRect
   208 */
   206 */
   209 bool HbSliderControlPrivate::onHandle( QPointF pos )
   207 bool HbSliderControlPrivate::onHandle( QPointF pos )
   210 {
   208 {
   211     Q_Q( HbSliderControl );
   209     Q_Q( HbSliderControl );
   212     QRectF handleRect = handle->touchItem->sceneBoundingRect( );
   210     QRectF handleRect = handle->touchItem->sceneBoundingRect( );
   441 
   439 
   442     case 3: If some tickmarkitems to be drawn without labelItem in the middle,
   440     case 3: If some tickmarkitems to be drawn without labelItem in the middle,
   443     specify empty string ( "" ) for that item  in the string list.
   441     specify empty string ( "" ) for that item  in the string list.
   444 
   442 
   445     case 4: if both major & minor tickinterval are same,then only majortickLabel
   443     case 4: if both major & minor tickinterval are same,then only majortickLabel
   446     strings are taken into account for drawing the labelItem
   444     strings are taken into account for drawing the labelItem.
       
   445 
       
   446     case 5: If you want to remove the majorticklabel from the slider, pass the empty
       
   447     stringlist as the argument
   447 
   448 
   448     \sa majorTickLabels( )
   449     \sa majorTickLabels( )
   449 */
   450 */
   450 void HbSliderControl::setMajorTickLabels( const QStringList &majorTickLabels )
   451 void HbSliderControl::setMajorTickLabels( const QStringList &majorTickLabels )
   451 {
   452 {
   507         }
   508         }
   508     }
   509     }
   509 }
   510 }
   510 
   511 
   511 /*!
   512 /*!
   512     This will enable/disable current value diplay as tooltip
   513     This will enable/disable current value display as tooltip
   513     on thumb drag
   514     on thumb drag
   514 */
   515 */
   515  void HbSliderControl::setToolTipVisible( bool value )
   516  void HbSliderControl::setToolTipVisible( bool value )
   516  {
   517  {
   517     Q_D( HbSliderControl );
   518     Q_D( HbSliderControl );
   675         // calculate pixel value for event position
   676         // calculate pixel value for event position
   676         int pressValue = QStyle::sliderValueFromPosition( opt.minimum, opt.maximum,
   677         int pressValue = QStyle::sliderValueFromPosition( opt.minimum, opt.maximum,
   677             static_cast<int>( handlePos ),static_cast<int>( span ),opt.upsideDown );
   678             static_cast<int>( handlePos ),static_cast<int>( span ),opt.upsideDown );
   678         //update the groove and touch item
   679         //update the groove and touch item
   679         style( )->updatePrimitive( d->groove, HbStyle::P_Slider_groove, &opt );  
   680         style( )->updatePrimitive( d->groove, HbStyle::P_Slider_groove, &opt );  
   680         // if default is set then dont increment or decrement slider value
   681         // if default is set then do not increment or decrement slider value
   681         // just set default value to slider
   682         // just set default value to slider
   682         if ( d->setDefault ) {
   683         if ( d->setDefault ) {
   683             setValue( d->previousValue );
   684             setValue( d->previousValue );
   684             if ( pressValue > value( ) ) {
   685             if ( pressValue > value( ) ) {
   685                 setRepeatAction( SliderSingleStepAdd, pressValue );
   686                 setRepeatAction( SliderSingleStepAdd, pressValue );
   765 #else
   766 #else
   766     Q_UNUSED(event);
   767     Q_UNUSED(event);
   767 #endif 
   768 #endif 
   768 }
   769 }
   769 
   770 
   770 
   771 /*!
       
   772   reimp
       
   773 
       
   774 */
   771 #ifdef HB_GESTURE_FW
   775 #ifdef HB_GESTURE_FW
   772 void HbSliderControl::gestureEvent(QGestureEvent *event)
   776 void HbSliderControl::gestureEvent(QGestureEvent *event)
   773 {
   777 {
   774     Q_D(HbSliderControl);
   778     Q_D(HbSliderControl);
   775     if(HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   779     if(HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   841 
   845 
   842             int pressValue = QStyle::sliderValueFromPosition( opt.minimum, opt.maximum,
   846             int pressValue = QStyle::sliderValueFromPosition( opt.minimum, opt.maximum,
   843                 static_cast<int>( handlePos ),static_cast<int>( span ),opt.upsideDown );
   847                 static_cast<int>( handlePos ),static_cast<int>( span ),opt.upsideDown );
   844 
   848 
   845 
   849 
   846             // if default is set then dont increment or decrement slider value
   850             // if default is set then don't increment or decrement slider value
   847             // just set default value to slider
   851             // just set default value to slider
   848             setSliderPosition( pressValue );
   852             setSliderPosition( pressValue );
   849             triggerAction( SliderMove );
   853             triggerAction( SliderMove );
   850             setRepeatAction( SliderNoAction, pressValue );
   854             setRepeatAction( SliderNoAction, pressValue );
   851             HbWidgetFeedback::triggered( this, Hb::InstantReleased );
   855             HbWidgetFeedback::triggered( this, Hb::InstantReleased );
   895     if (HbPanGesture *panGesture = qobject_cast<HbPanGesture*>(event->gesture(Qt::PanGesture))) {
   899     if (HbPanGesture *panGesture = qobject_cast<HbPanGesture*>(event->gesture(Qt::PanGesture))) {
   896         switch(panGesture->state( )) {
   900         switch(panGesture->state( )) {
   897             case Qt::GestureStarted: 
   901             case Qt::GestureStarted: 
   898             case Qt::GestureUpdated:{
   902             case Qt::GestureUpdated:{
   899                 QPointF startPoint = event->mapToGraphicsScene(panGesture->offset()+panGesture->startPos( ) );
   903                 QPointF startPoint = event->mapToGraphicsScene(panGesture->offset()+panGesture->startPos( ) );
       
   904 				//if the position is on thumb , then start moving the thumb
   900                 if( ( d->onHandle( startPoint) && d->grooveTouchArea->sceneBoundingRect( ).contains( startPoint))||isSliderDown( ) ) {
   905                 if( ( d->onHandle( startPoint) && d->grooveTouchArea->sceneBoundingRect( ).contains( startPoint))||isSliderDown( ) ) {
   901                     qreal handlePos = 0;
   906                     qreal handlePos = 0;
   902                     qreal span = 0;
   907                     qreal span = 0;
   903                     QRectF bounds = boundingRect( );
   908                     QRectF bounds = boundingRect( );
   904                     QRectF handleBounds = d->handle->boundingRect( );
   909                     QRectF handleBounds = d->handle->boundingRect( );
   955                 setSliderDown( false );
   960                 setSliderDown( false );
   956                 d->groovePressed = false;
   961                 d->groovePressed = false;
   957                 updatePrimitives( );
   962                 updatePrimitives( );
   958                 d->handle->updatePrimitives();
   963                 d->handle->updatePrimitives();
   959                 d->handleMoving = false;
   964                 d->handleMoving = false;
       
   965 				int pressValue = sliderPosition();
       
   966                 setRepeatAction( SliderNoAction,static_cast<int>( pressValue ) );
   960                 event->ignore();
   967                 event->ignore();
   961                 HbAbstractSliderControl::gestureEvent(event);
   968                 HbAbstractSliderControl::gestureEvent(event);
   962             }
   969             }
   963             break;
   970             break;
   964             default:
   971             default:
  1062     option->handleRect = d->handle->boundingRect( );
  1069     option->handleRect = d->handle->boundingRect( );
  1063     QRectF bounds = boundingRect( );
  1070     QRectF bounds = boundingRect( );
  1064     QRectF handleBounds = d->handle->boundingRect( );
  1071     QRectF handleBounds = d->handle->boundingRect( );
  1065     qreal span = 0;
  1072     qreal span = 0;
  1066     if ( orientation( ) == Qt::Horizontal ) {
  1073     if ( orientation( ) == Qt::Horizontal ) {
  1067         bounds.adjust( 0, 0, -handleBounds.width( )/2, 0 );
  1074         bounds.adjust( 0, 0, -handleBounds.width( ), 0 );
  1068         // calculating span
  1075         // calculating span
  1069         span = bounds.width( );
  1076         span = bounds.width( );
  1070     } else {
  1077     } else {
  1071         bounds.adjust( 0, 0, 0, -handleBounds.height( )/2 );
  1078         bounds.adjust( 0, 0, 0, -handleBounds.height( ) );
  1072         // calculating span
  1079         // calculating span
  1073         span = bounds.height( );
  1080         span = bounds.height( );
  1074     }
  1081     }
  1075     option->span = span;
  1082     option->span = span;
  1076 }
  1083 }
  1262     HbAbstractSliderControl::setSliderPosition( value );
  1269     HbAbstractSliderControl::setSliderPosition( value );
  1263     d->displayCurrValueToolTip =  b;
  1270     d->displayCurrValueToolTip =  b;
  1264 }
  1271 }
  1265 
  1272 
  1266 /*!
  1273 /*!
  1267   snapp slider values
  1274   snap to slider values
  1268 */
  1275 */
  1269 void HbSliderControl::updateSliderPosToTick( )  
  1276 void HbSliderControl::updateSliderPosToTick( )  
  1270 {
  1277 {
  1271     Q_D( HbSliderControl );       
  1278     Q_D( HbSliderControl );       
  1272     int nearbyTick = d->getNearbyTick( );
  1279     int nearbyTick = d->getNearbyTick( );
  1314 
  1321 
  1315 #ifdef HB_GESTURE_FW
  1322 #ifdef HB_GESTURE_FW
  1316             ungrabGesture(Qt::TapGesture);
  1323             ungrabGesture(Qt::TapGesture);
  1317             ungrabGesture(Qt::PanGesture);
  1324             ungrabGesture(Qt::PanGesture);
  1318             touchArea->grabGesture(Qt::TapGesture);
  1325             touchArea->grabGesture(Qt::TapGesture);
  1319             touchArea->grabGesture(Qt::PanGesture,Qt::ReceivePartialGestures);
  1326             touchArea->grabGesture(Qt::PanGesture);
  1320 #endif 
  1327 #endif 
  1321         }
  1328         }
  1322     }
  1329     }
  1323     d->trackHandlingEnable = enable ;
  1330     d->trackHandlingEnable = enable ;
  1324 }
  1331 }
  1340 {
  1347 {
  1341     Q_D( HbSliderControl );
  1348     Q_D( HbSliderControl );
  1342     return d->handle->size( ) ;
  1349     return d->handle->size( ) ;
  1343 }
  1350 }
  1344 
  1351 
       
  1352 /*!
       
  1353  fills the track upto the current value if \a trackVisible is true
       
  1354  */ 
  1345 
  1355 
  1346 void HbSliderControl::setTrackFilled(bool trackVisible )
  1356 void HbSliderControl::setTrackFilled(bool trackVisible )
  1347 {
  1357 {
  1348     
  1358     
  1349     Q_D( HbSliderControl );
  1359     Q_D( HbSliderControl );
  1364         }
  1374         }
  1365     }
  1375     }
  1366 
  1376 
  1367 }
  1377 }
  1368 
  1378 
  1369 
  1379 /*!
       
  1380  Returns whether the track is filled upto the current value or not
       
  1381  */ 
  1370 bool HbSliderControl::isTrackFilled() const
  1382 bool HbSliderControl::isTrackFilled() const
  1371 {
  1383 {
  1372     Q_D( const HbSliderControl );
  1384     Q_D( const HbSliderControl );
  1373     return d->enableProgressTrack;
  1385     return d->enableProgressTrack;
  1374 }
  1386 }