32 #include "hbslidercontrol_p.h" |
32 #include "hbslidercontrol_p.h" |
33 #include "hbstyleoptionslider_p.h" |
33 #include "hbstyleoptionslider_p.h" |
34 #include <QGraphicsSceneEvent> |
34 #include <QGraphicsSceneEvent> |
35 #include <QGraphicsScene> |
35 #include <QGraphicsScene> |
36 #include <hbwidgetfeedback.h> |
36 #include <hbwidgetfeedback.h> |
|
37 #ifdef HB_GESTURE_FW |
|
38 #include <hbtapgesture.h> |
|
39 #endif |
|
40 #ifdef HB_EFFECTS |
|
41 #include "hbeffect.h" |
|
42 #include "hbeffectinternal_p.h" |
|
43 #define HB_SLIDER_TYPE "HB_SLIDER" |
|
44 #endif |
37 |
45 |
38 /*! |
46 /*! |
39 Example usage: |
47 Example usage: |
40 \code |
48 \code |
41 HbSlider *slider = new HbSlider(Qt::Horizontal); |
49 HbSlider *slider = new HbSlider(Qt::Horizontal); |
132 << HbSlider::DecreaseElement |
140 << HbSlider::DecreaseElement |
133 << HbSlider::IconElement; |
141 << HbSlider::IconElement; |
134 if( currentValueVisible ) |
142 if( currentValueVisible ) |
135 elements<<HbSlider::TextElement; |
143 elements<<HbSlider::TextElement; |
136 setElements( elements ); |
144 setElements( elements ); |
|
145 #ifdef HB_GESTURE_FW |
|
146 q->grabGesture(Qt::TapGesture); |
|
147 #endif |
137 // create element because HbSlider will not create element for NULL Icon |
148 // create element because HbSlider will not create element for NULL Icon |
138 // and volume slider Icon is set in style |
149 // and volume slider Icon is set in style |
139 if ( !elementItemMap.contains(HbSlider::IncreaseElement) ) { |
150 if ( !elementItemMap.contains(HbSlider::IncreaseElement) ) { |
140 elementItemMap [HbSlider::IncreaseElement].item = |
151 elementItemMap [HbSlider::IncreaseElement].item = |
141 HbStylePrivate::createPrimitive( HbStylePrivate::P_SliderElement_increase, q); |
152 HbStylePrivate::createPrimitive( HbStylePrivate::P_SliderElement_increase, q); |
345 unmute the volume to previous store value in case unmute happens |
356 unmute the volume to previous store value in case unmute happens |
346 by clicking increment/decrement icon |
357 by clicking increment/decrement icon |
347 */ |
358 */ |
348 void HbVolumeSlider::mousePressEvent( QGraphicsSceneMouseEvent *event ) |
359 void HbVolumeSlider::mousePressEvent( QGraphicsSceneMouseEvent *event ) |
349 { |
360 { |
|
361 |
|
362 #ifndef HB_GESTURE_FW |
350 Q_D( HbVolumeSlider ); |
363 Q_D( HbVolumeSlider ); |
351 if( d->elementItemMap.contains(HbSlider::IncreaseElement) ) { |
364 if( d->elementItemMap.contains(HbSlider::IncreaseElement) ) { |
352 if ( d->elementItemMap[HbSlider::IncreaseElement].touchItem->isUnderMouse( ) ) { |
365 if ( d->elementItemMap[HbSlider::IncreaseElement].touchItem->isUnderMouse( ) ) { |
353 d->pressOnIncrement = true; |
366 d->pressOnIncrement = true; |
354 HbWidgetFeedback::triggered( d->sliderControl, Hb::InstantPressed, Hb::ModifierSliderElement ); |
367 HbWidgetFeedback::triggered( d->sliderControl, Hb::InstantPressed, Hb::ModifierSliderElement ); |
392 setProperty("state", "pressed"); |
405 setProperty("state", "pressed"); |
393 return; |
406 return; |
394 } |
407 } |
395 } |
408 } |
396 HbSlider::mousePressEvent( event ); |
409 HbSlider::mousePressEvent( event ); |
|
410 #else |
|
411 Q_UNUSED(event) |
|
412 #endif |
397 } |
413 } |
398 |
414 |
399 /*! |
415 /*! |
400 \reimp |
416 \reimp |
401 stop the timer and change image for increment element /decrement element |
417 stop the timer and change image for increment element /decrement element |
402 */ |
418 */ |
403 void HbVolumeSlider::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) |
419 void HbVolumeSlider::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) |
404 { |
420 { |
|
421 #ifndef HB_GESTURE_FW |
405 Q_D( HbVolumeSlider ); |
422 Q_D( HbVolumeSlider ); |
406 HbSlider::mouseReleaseEvent( event ); |
423 HbSlider::mouseReleaseEvent( event ); |
407 d->stopRepeatAction( ); |
424 d->stopRepeatAction( ); |
408 setProperty("changeincrementState" ,false); |
425 setProperty("changeincrementState" ,false); |
409 setProperty("changedecrementState" ,false); |
426 setProperty("changedecrementState" ,false); |
410 setProperty("state", "normal"); |
427 setProperty("state", "normal"); |
|
428 #else |
|
429 Q_UNUSED(event) |
|
430 #endif |
411 } |
431 } |
412 |
432 |
413 /*! |
433 /*! |
414 \reimp |
434 \reimp |
415 */ |
435 */ |
451 { |
471 { |
452 Q_D( HbVolumeSlider ); |
472 Q_D( HbVolumeSlider ); |
453 d->sliderControl->setFocus( ); |
473 d->sliderControl->setFocus( ); |
454 } |
474 } |
455 |
475 |
|
476 /*! |
|
477 \reimp |
|
478 */ |
|
479 void HbVolumeSlider::gestureEvent(QGestureEvent *event) |
|
480 { |
|
481 Q_D(HbVolumeSlider); |
|
482 //consume the event if gesture is on increment or decrement, |
|
483 //if the slide ris muted and then on pressing on icrement/decrement value consider previous value as well |
|
484 if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) { |
|
485 QPointF pos = event->mapToGraphicsScene(tap->position()); |
|
486 bool consumeEvent = false; |
|
487 switch( tap->state( ) ) { |
|
488 case Qt::GestureStarted: { |
|
489 if ( d->elementItemMap.contains (HbSlider::IncreaseElement ) ) { |
|
490 if (d->elementItemMap[HbSlider::IncreaseElement].touchItem ) { |
|
491 if (d->elementItemMap[HbSlider::IncreaseElement].touchItem->sceneBoundingRect().contains(pos)) { |
|
492 consumeEvent = true; |
|
493 d->pressOnIncrement = true; |
|
494 HbWidgetFeedback::triggered( d->sliderControl, Hb::InstantPressed, Hb::ModifierSliderElement ); |
|
495 event->accept( ); |
|
496 // if volume was mute |
|
497 if( isIconChecked( ) ){ |
|
498 // take to previous value and increase one step |
|
499 setValue( d->previousValue+singleStep( ) ); |
|
500 // start timer for repeat action |
|
501 d->sliderControl->setRepeatAction( |
|
502 HbAbstractSliderControl::SliderSingleStepAdd, d->sliderControl->maximum( ) ); |
|
503 } else {// simply increase by one step |
|
504 d->startIncrementing( ); |
|
505 } |
|
506 setProperty("changeincrementState" ,true); |
|
507 setProperty("changedecrementState" ,false); |
|
508 setProperty("state", "pressed"); |
|
509 } |
|
510 } |
|
511 } |
|
512 if ( d->elementItemMap.contains (HbSlider::DecreaseElement ) ) { |
|
513 if (d->elementItemMap[HbSlider::DecreaseElement].touchItem ) { |
|
514 if (d->elementItemMap[HbSlider::DecreaseElement].touchItem->sceneBoundingRect().contains(pos)) { |
|
515 consumeEvent = true; |
|
516 d->pressOnIncrement = false; |
|
517 HbWidgetFeedback::triggered( d->sliderControl, Hb::InstantPressed, Hb::ModifierSliderElement ); |
|
518 event->accept( ); |
|
519 if( isIconChecked( ) ){ |
|
520 //set value to previous value and decrement by one step |
|
521 setValue( d->previousValue-singleStep( ) ); |
|
522 if( value( )==minimum( ) ){ |
|
523 d->previousValue = value( ); |
|
524 setIconEnabled( false ); |
|
525 } |
|
526 //start timer for repeat action |
|
527 d->sliderControl->setRepeatAction( |
|
528 HbAbstractSliderControl::SliderSingleStepSub, d->sliderControl->minimum( ) ); |
|
529 } else { |
|
530 d->startDecrementing( ); |
|
531 } |
|
532 setProperty("changeincrementState" ,false); |
|
533 setProperty("changedecrementState" ,true); |
|
534 setProperty("state", "pressed"); |
|
535 |
|
536 } |
|
537 } |
|
538 } |
|
539 } |
|
540 break; |
|
541 case Qt::GestureCanceled: |
|
542 case Qt::GestureFinished: |
|
543 setProperty("changeincrementState" ,false); |
|
544 setProperty("changedecrementState" ,false); |
|
545 setProperty("state", "normal"); |
|
546 consumeEvent = true; |
|
547 HbSlider::gestureEvent(event); |
|
548 break; |
|
549 default: |
|
550 break; |
|
551 } |
|
552 if(!consumeEvent) { |
|
553 event->ignore(); |
|
554 HbSlider::gestureEvent(event); |
|
555 } |
|
556 |
|
557 |
|
558 } |
|
559 |
|
560 } |
|
561 |
456 #include "moc_hbvolumeslider_p.cpp" |
562 #include "moc_hbvolumeslider_p.cpp" |
457 |
563 |
458 |
564 |
459 |
565 |