37 #include <hbwidgetfeedback.h> |
37 #include <hbwidgetfeedback.h> |
38 #include <QGraphicsItem> |
38 #include <QGraphicsItem> |
39 #include <QGraphicsSceneEvent> |
39 #include <QGraphicsSceneEvent> |
40 #include <QGraphicsScene> |
40 #include <QGraphicsScene> |
41 #include <QDebug> |
41 #include <QDebug> |
42 |
42 #ifdef HB_GESTURE_FW |
|
43 #include <hbtapgesture.h> |
|
44 #endif |
43 #ifdef HB_EFFECTS |
45 #ifdef HB_EFFECTS |
44 #include "hbeffect.h" |
46 #include "hbeffect.h" |
45 #include "hbeffectinternal_p.h" |
47 #include "hbeffectinternal_p.h" |
46 #define HB_SLIDER_TYPE "HB_SLIDER" |
48 #define HB_SLIDER_TYPE "HB_SLIDER" |
47 #endif |
49 #endif |
87 slider->setElementIcons( map ); |
89 slider->setElementIcons( map ); |
88 \endcode |
90 \endcode |
89 |
91 |
90 \image html verticalslider.png A Custom vertical slider with all elements. |
92 \image html verticalslider.png A Custom vertical slider with all elements. |
91 |
93 |
92 order in which HbSlider::SliderElement are inserted into QList doesnt matter. |
94 order in which HbSlider::SliderElement are inserted into QList does not matter. |
93 |
95 |
94 HbSlider provides methods for controlling tickmarks. You can use |
96 HbSlider provides methods for controlling tickmarks. You can use |
95 setTickPosition( ) to indicate where you want the tickmarks to be, |
97 setTickPosition( ) to indicate where you want the tickmarks to be, |
96 setMajorTickInterval( ) and setMinorTickInterval( ) to indicate how |
98 setMajorTickInterval( ) and setMinorTickInterval( ) to indicate how |
97 many of them you want. The current set tick position and intervals |
99 many of them you want. The current set tick position and intervals |
274 q->connect( sliderControl, SIGNAL( rangeChanged( int, int ) ), q, SIGNAL( rangeChanged( int, int ) ) ); |
276 q->connect( sliderControl, SIGNAL( rangeChanged( int, int ) ), q, SIGNAL( rangeChanged( int, int ) ) ); |
275 setElements( QList<HbSlider::SliderElement>( ) << HbSlider::TrackElement ); |
277 setElements( QList<HbSlider::SliderElement>( ) << HbSlider::TrackElement ); |
276 HbStyle::setItemName( q,"this" ); |
278 HbStyle::setItemName( q,"this" ); |
277 q->setFlags( QGraphicsItem::ItemIsFocusable ); |
279 q->setFlags( QGraphicsItem::ItemIsFocusable ); |
278 q->setProperty("TickLabelPresent",false); |
280 q->setProperty("TickLabelPresent",false); |
|
281 #ifdef HB_GESTURE_FW |
|
282 q->grabGesture(Qt::TapGesture); |
|
283 #endif |
279 } |
284 } |
280 |
285 |
281 void HbSliderPrivate::setElements( QList<HbSlider::SliderElement> elementList) |
286 void HbSliderPrivate::setElements( QList<HbSlider::SliderElement> elementList) |
282 { |
287 { |
283 Q_Q( HbSlider); |
288 Q_Q( HbSlider); |
284 bool oldElementRemoved = false; |
289 bool oldElementRemoved = false; |
285 foreach(HbSlider::SliderElement element,elements){ |
290 foreach(const HbSlider::SliderElement &element,elements){ |
286 if(!elementList.contains(element)&& elementItemMap.contains(element)) { |
291 if(!elementList.contains(element)&& elementItemMap.contains(element)) { |
287 delete elementItemMap[element].item; |
292 delete elementItemMap[element].item; |
288 delete elementItemMap[element].touchItem; |
293 delete elementItemMap[element].touchItem; |
289 elementItemMap.remove(element); |
294 elementItemMap.remove(element); |
290 oldElementRemoved = true; |
295 oldElementRemoved = true; |
413 elementWidget( element ); |
420 elementWidget( element ); |
414 } |
421 } |
415 } |
422 } |
416 |
423 |
417 /*! |
424 /*! |
|
425 \internal |
418 This Api will start incrementing slider value by step size |
426 This Api will start incrementing slider value by step size |
419 till the time stopReapetAction( ) is not being called or slider |
427 till the time stopReapetAction( ) is not being called or slider |
420 value becomes maximum( ) |
428 value becomes maximum( ) |
421 */ |
429 */ |
422 void HbSliderPrivate::startIncrementing( ) |
430 void HbSliderPrivate::startIncrementing( ) |
430 // start timer to increase slider value by step |
438 // start timer to increase slider value by step |
431 sliderControl->setRepeatAction( HbAbstractSliderControl::SliderSingleStepAdd,sliderControl->maximum( ) ); |
439 sliderControl->setRepeatAction( HbAbstractSliderControl::SliderSingleStepAdd,sliderControl->maximum( ) ); |
432 } |
440 } |
433 |
441 |
434 /*! |
442 /*! |
|
443 \internal |
435 This Api will start decrementing slider value by step size |
444 This Api will start decrementing slider value by step size |
436 till the time stopReapetAction( ) is not being called or slider |
445 till the time stopReapetAction( ) is not being called or slider |
437 value becomes minimum( ) |
446 value becomes minimum( ) |
438 */ |
447 */ |
439 void HbSliderPrivate::startDecrementing( ) |
448 void HbSliderPrivate::startDecrementing( ) |
445 sliderControl->triggerAction( HbAbstractSliderControl::SliderSingleStepSub ); |
454 sliderControl->triggerAction( HbAbstractSliderControl::SliderSingleStepSub ); |
446 sliderControl->setRepeatAction( HbAbstractSliderControl::SliderSingleStepSub,sliderControl->minimum( ) ); |
455 sliderControl->setRepeatAction( HbAbstractSliderControl::SliderSingleStepSub,sliderControl->minimum( ) ); |
447 } |
456 } |
448 |
457 |
449 /*! |
458 /*! |
|
459 \internal |
450 stops the reapeating action |
460 stops the reapeating action |
451 reapeat action can be increase slider value by step or decrease slider value by step |
461 reapeat action can be increase slider value by step or decrease slider value by step |
452 */ |
462 */ |
453 void HbSliderPrivate::stopRepeatAction( ) |
463 void HbSliderPrivate::stopRepeatAction( ) |
454 { |
464 { |
455 sliderControl->setRepeatAction( HbAbstractSliderControl::SliderNoAction ); |
465 sliderControl->setRepeatAction( HbAbstractSliderControl::SliderNoAction ); |
456 } |
466 } |
457 |
467 |
458 |
468 |
459 void HbSliderPrivate::setTickLabelPresentProperty( ) |
469 /*! |
460 { |
470 \internal |
461 Q_Q ( HbSlider ); |
471 creates either left tickmarks or right tickmarks or both based on tickposition of slider |
462 if (q->majorTickInterval( ) > 0 && q->tickPosition( ) !=Hb::NoSliderTicks && |
472 */ |
463 (q->majorTickLabels().length() > 0 || |
|
464 (q->minorTickInterval() > 0 && q->minorTickLabels( ).length() > 0))) { |
|
465 if(!q->property("TickLabelPresent").toBool()){ |
|
466 q->setProperty("TickLabelPresent",true); |
|
467 q->repolish( ); |
|
468 } |
|
469 } else { |
|
470 if( q->property("TickLabelPresent").toBool()){ |
|
471 q->setProperty("TickLabelPresent",false); |
|
472 q->repolish( ); |
|
473 } |
|
474 } |
|
475 |
|
476 } |
|
477 |
|
478 |
|
479 |
|
480 |
473 |
481 void HbSliderPrivate::createTickMarks( ) |
474 void HbSliderPrivate::createTickMarks( ) |
482 { |
475 { |
483 Q_Q ( HbSlider); |
476 Q_Q ( HbSlider); |
484 bool modified = false; |
477 bool modified = false; |
635 Updates tick and Label. |
635 Updates tick and Label. |
636 */ |
636 */ |
637 void HbSliderPrivate::updateTickMarks( ) |
637 void HbSliderPrivate::updateTickMarks( ) |
638 { |
638 { |
639 if (tickmarksLeft) { |
639 if (tickmarksLeft) { |
|
640 tickmarksLeft->createTicks(); |
640 tickmarksLeft->updateTicks(); |
641 tickmarksLeft->updateTicks(); |
641 } |
642 } |
642 if (tickmarksRight) { |
643 if (tickmarksRight) { |
|
644 tickmarksRight->createTicks(); |
643 tickmarksRight->updateTicks(); |
645 tickmarksRight->updateTicks(); |
644 } |
646 } |
645 } |
647 } |
646 |
648 |
647 |
649 |
660 } |
662 } |
661 |
663 |
662 |
664 |
663 /*! |
665 /*! |
664 \internal |
666 \internal |
665 Updates tick and Label. |
667 deletes slidertickmarks. |
666 */ |
668 */ |
667 void HbSliderPrivate::deleteTickMarks( ) |
669 void HbSliderPrivate::deleteTickMarks( ) |
668 { |
670 { |
669 Q_Q ( HbSlider ); |
|
670 bool deleted = false; |
|
671 if (tickmarksLeft) { |
671 if (tickmarksLeft) { |
|
672 HbStyle::setItemName(tickmarksLeft,QString()); |
672 delete tickmarksLeft; |
673 delete tickmarksLeft; |
673 tickmarksLeft = 0; |
674 tickmarksLeft = 0; |
674 deleted = true; |
|
675 } |
675 } |
676 if (tickmarksRight) { |
676 if (tickmarksRight) { |
|
677 HbStyle::setItemName(tickmarksRight,QString()); |
677 delete tickmarksRight; |
678 delete tickmarksRight; |
678 tickmarksRight = 0; |
679 tickmarksRight = 0; |
679 deleted = true; |
680 } |
680 } |
|
681 if ( deleted ) { |
|
682 q->repolish( ); |
|
683 } |
|
684 |
|
685 } |
681 } |
686 |
682 |
687 |
683 |
688 /*! |
684 /*! |
689 \internal |
685 \internal |
690 Updates tick and Label. |
686 deletes ticklabels. |
691 */ |
687 */ |
692 void HbSliderPrivate::deleteTickLabels( ) |
688 void HbSliderPrivate::deleteTickLabels( ) |
693 { |
689 { |
694 |
|
695 Q_Q(HbSlider); |
|
696 bool deleted = false; |
|
697 if (tickmarkslabelLeft) { |
690 if (tickmarkslabelLeft) { |
|
691 HbStyle::setItemName(tickmarkslabelLeft,QString()); |
698 delete tickmarkslabelLeft; |
692 delete tickmarkslabelLeft; |
699 tickmarkslabelLeft = 0; |
693 tickmarkslabelLeft = 0; |
700 deleted = true; |
|
701 |
|
702 } |
694 } |
703 if (tickmarkslabelRight) { |
695 if (tickmarkslabelRight) { |
|
696 HbStyle::setItemName(tickmarkslabelRight,QString()); |
704 delete tickmarkslabelRight; |
697 delete tickmarkslabelRight; |
705 tickmarkslabelRight = 0; |
698 tickmarkslabelRight = 0; |
706 deleted = true; |
699 } |
707 } |
|
708 if (deleted) { |
|
709 q->repolish( ); |
|
710 } |
|
711 |
|
712 } |
700 } |
713 |
701 |
714 #ifdef HB_EFFECTS |
702 #ifdef HB_EFFECTS |
715 |
703 |
716 /*! |
704 /*! |
|
705 \internal |
717 start effect for on icon press |
706 start effect for on icon press |
718 */ |
707 */ |
719 void HbSliderPrivate::_q_startIconPressedEffect( ) |
708 void HbSliderPrivate::_q_startIconPressedEffect( ) |
720 { |
709 { |
721 HbEffectInternal::add( HB_SLIDER_TYPE,"slidericon_press", "iconpressed" ); |
710 HbEffectInternal::add( HB_SLIDER_TYPE,"slidericon_press", "iconpressed" ); |
722 HbEffect::start( elementItemMap[HbSlider::IconElement].item, HB_SLIDER_TYPE, "iconpressed" ); |
711 HbEffect::start( elementItemMap[HbSlider::IconElement].item, HB_SLIDER_TYPE, "iconpressed" ); |
723 } |
712 } |
724 |
713 |
725 /*! |
714 /*! |
|
715 \internal |
726 start effect on icon release |
716 start effect on icon release |
727 */ |
717 */ |
728 void HbSliderPrivate::_q_startIconReleasedEffect( ) |
718 void HbSliderPrivate::_q_startIconReleasedEffect( ) |
729 { |
719 { |
730 HbEffectInternal::add( HB_SLIDER_TYPE,"slidericon_release", "iconrelease" ); |
720 HbEffectInternal::add( HB_SLIDER_TYPE,"slidericon_release", "iconrelease" ); |
809 */ |
799 */ |
810 QList<QVariant> HbSlider::sliderElements() const |
800 QList<QVariant> HbSlider::sliderElements() const |
811 { |
801 { |
812 Q_D( const HbSlider ); |
802 Q_D( const HbSlider ); |
813 QList<QVariant> elementList; |
803 QList<QVariant> elementList; |
814 foreach(HbSlider::SliderElement element,d->elements){ |
804 foreach(const HbSlider::SliderElement &element,d->elements){ |
815 elementList.append ( QVariant ( element ) ); |
805 elementList.append ( QVariant ( element ) ); |
816 } |
806 } |
817 return elementList; |
807 return elementList; |
818 } |
808 } |
819 |
809 |
841 */ |
831 */ |
842 void HbSlider::setSliderElements(const QList<QVariant> &elementlist) |
832 void HbSlider::setSliderElements(const QList<QVariant> &elementlist) |
843 { |
833 { |
844 Q_D( HbSlider ); |
834 Q_D( HbSlider ); |
845 QList<HbSlider::SliderElement> elements; |
835 QList<HbSlider::SliderElement> elements; |
846 foreach ( QVariant elementVar , elementlist ) { |
836 foreach (const QVariant &elementVar , elementlist ) { |
847 elements.append( static_cast<HbSlider::SliderElement>(elementVar.toInt())); |
837 elements.append( static_cast<HbSlider::SliderElement>(elementVar.toInt())); |
848 } |
838 } |
849 d->setElements( elements ); |
839 d->setElements( elements ); |
850 } |
840 } |
851 |
841 |
861 "IconElement" for icon element |
851 "IconElement" for icon element |
862 |
852 |
863 Eg Usage: |
853 Eg Usage: |
864 HbSlider slider; |
854 HbSlider slider; |
865 QMap<QString , QVariant> map; |
855 QMap<QString , QVariant> map; |
866 map.insert(QString("IncreaseElement") , QVariant(":/unittest_hbslider/star_on.png")); |
856 map.insert(QString("IncreaseElement") , QVariant("example1.png")); |
867 map.insert(QString("DecreaseElement") , QVariant(":/unittest_hbslider/star_on.png")); |
857 map.insert(QString("DecreaseElement") , QVariant("example2.png")); |
868 slider.setElementIcons( map ); |
858 slider.setElementIcons( map ); |
869 |
859 |
870 \warning Setting icon to a non-existing element has no effect. |
860 \warning Setting icon to a non-existing element has no effect. |
871 |
861 |
872 \sa elementIcons() setSliderElements() setElementIcon() |
862 \sa elementIcons() setSliderElements() setElementIcon() |
1535 */ |
1525 */ |
1536 void HbSlider::setTickPosition( Hb::SliderTickPositions position ) |
1526 void HbSlider::setTickPosition( Hb::SliderTickPositions position ) |
1537 { |
1527 { |
1538 Q_D( HbSlider ); |
1528 Q_D( HbSlider ); |
1539 d->sliderControl->setTickPosition( position ); |
1529 d->sliderControl->setTickPosition( position ); |
1540 d->setTickLabelPresentProperty( ); |
|
1541 d->createTickMarks( ); |
1530 d->createTickMarks( ); |
1542 d->createTickLabels( ); |
1531 d->createTickLabels( ); |
|
1532 d->updateTickMarks( ); |
|
1533 d->updateTickLabels( ); |
1543 } |
1534 } |
1544 |
1535 |
1545 /*! |
1536 /*! |
1546 @beta |
1537 @beta |
1547 Returns the SnappingMode of the slider. |
1538 Returns the SnappingMode of the slider. |
1731 case 3: If some tickmarkitems to be drawn without labelItem in the middle, |
1720 case 3: If some tickmarkitems to be drawn without labelItem in the middle, |
1732 specify empty string ( "" ) for that item in the string list. |
1721 specify empty string ( "" ) for that item in the string list. |
1733 |
1722 |
1734 case 4: if both major & minor tickinterval are same,then only majortickLabel |
1723 case 4: if both major & minor tickinterval are same,then only majortickLabel |
1735 strings are taken into account for drawing the labelItem |
1724 strings are taken into account for drawing the labelItem |
|
1725 |
|
1726 case 5: If you want to remove the whole tickLabel then set the empty string as the argument. |
|
1727 |
|
1728 Note:: if the major tickinterval of the slider is very small, the tick labels may overlap, |
|
1729 application needs to take care of this. |
1736 |
1730 |
1737 \sa majorTickLabels( ) |
1731 \sa majorTickLabels( ) |
1738 */ |
1732 */ |
1739 void HbSlider::setMajorTickLabels( const QStringList &majorTickLabels ) |
1733 void HbSlider::setMajorTickLabels( const QStringList &majorTickLabels ) |
1740 { |
1734 { |
1762 } |
1755 } |
1763 |
1756 |
1764 /*! |
1757 /*! |
1765 @beta |
1758 @beta |
1766 Sets the minor ticklabels of the slider. |
1759 Sets the minor ticklabels of the slider. |
1767 see setMajorTickLabels for detailed description |
1760 see setMajorTickLabels for detailed description. |
|
1761 Note:: if the minor tickinterval of the slider is very small, the tick labels may overlap, |
|
1762 application needs to take care of this. |
|
1763 |
1768 |
1764 |
1769 \sa minorTickLabels( ),setMajorTickLabels( ) |
1765 \sa minorTickLabels( ),setMajorTickLabels( ) |
1770 */ |
1766 */ |
1771 void HbSlider::setMinorTickLabels( const QStringList &minorTickLabels ) |
1767 void HbSlider::setMinorTickLabels( const QStringList &minorTickLabels ) |
1772 { |
1768 { |
1773 Q_D( HbSlider ); |
1769 Q_D( HbSlider ); |
1774 d->sliderControl->setMinorTickLabels( minorTickLabels ); |
1770 d->sliderControl->setMinorTickLabels( minorTickLabels ); |
1775 d->updateTickLabels( ); |
1771 d->updateTickLabels( ); |
1776 d->setTickLabelPresentProperty( ); |
|
1777 } |
1772 } |
1778 |
1773 |
1779 |
1774 |
1780 /*! |
1775 /*! |
1781 |
1776 |
1811 return d->elementItemMap[HbSlider::DecreaseElement].item; |
1806 return d->elementItemMap[HbSlider::DecreaseElement].item; |
1812 } |
1807 } |
1813 break; |
1808 break; |
1814 case HbStyle::P_Slider_groove: |
1809 case HbStyle::P_Slider_groove: |
1815 return HbSliderControlPrivate::d_ptr( d->sliderControl )->groove; |
1810 return HbSliderControlPrivate::d_ptr( d->sliderControl )->groove; |
|
1811 case HbStyle::P_SliderElement_touchgroove: |
|
1812 return HbSliderControlPrivate::d_ptr( d->sliderControl )->grooveTouchArea; |
1816 |
1813 |
1817 case HbStyle::P_SliderElement_touchhandle: |
1814 case HbStyle::P_SliderElement_touchhandle: |
1818 return HbSliderControlPrivate::d_ptr( d->sliderControl )->handle->primitive( |
1815 return HbSliderControlPrivate::d_ptr( d->sliderControl )->handle->primitive( |
1819 HbStyle::P_SliderElement_touchhandle ); |
1816 HbStyle::P_SliderElement_touchhandle ); |
1820 |
1817 |
1922 } |
1919 } |
1923 d->stopRepeatAction( ); |
1920 d->stopRepeatAction( ); |
1924 } |
1921 } |
1925 |
1922 |
1926 /*! |
1923 /*! |
|
1924 reimp |
|
1925 |
|
1926 */ |
|
1927 |
|
1928 void HbSlider::gestureEvent(QGestureEvent *event) |
|
1929 { |
|
1930 Q_D(HbSlider); |
|
1931 //consume the event if gesture is on increment or decrement,It is being handled in mouse press and mouse release |
|
1932 //If it is on mute/control igonore the gesture as they are handled separately by HbAbstractButton and HbSlidercontrol classes |
|
1933 if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) { |
|
1934 QPointF pos = event->mapToGraphicsScene(tap->position()); |
|
1935 bool consumeEvent = false; |
|
1936 if ( d->elementItemMap.contains (HbSlider::IncreaseElement ) ) { |
|
1937 if (d->elementItemMap[HbSlider::IncreaseElement].touchItem ) { |
|
1938 if (d->elementItemMap[HbSlider::IncreaseElement].touchItem->sceneBoundingRect().contains(pos)) { |
|
1939 consumeEvent = true; |
|
1940 } |
|
1941 } |
|
1942 } |
|
1943 if ( d->elementItemMap.contains (HbSlider::DecreaseElement ) ) { |
|
1944 if (d->elementItemMap[HbSlider::DecreaseElement].touchItem ) { |
|
1945 if (d->elementItemMap[HbSlider::DecreaseElement].touchItem->sceneBoundingRect().contains(pos)) { |
|
1946 consumeEvent = true; |
|
1947 } |
|
1948 } |
|
1949 } |
|
1950 |
|
1951 if(!consumeEvent) { |
|
1952 event->ignore(); |
|
1953 HbWidget::gestureEvent(event); |
|
1954 } |
|
1955 } |
|
1956 |
|
1957 } |
|
1958 |
|
1959 /*! |
1927 \reimp |
1960 \reimp |
1928 |
1961 |
1929 This api update the primitive when ever item enable has changed |
1962 This api update the primitive when ever item enable has changed |
1930 */ |
1963 */ |
1931 QVariant HbSlider::itemChange( GraphicsItemChange change, const QVariant &value ) |
1964 QVariant HbSlider::itemChange( GraphicsItemChange change, const QVariant &value ) |