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 "hbstyle_p.h" |
32 #include <hbstyle.h> |
33 #include <hbstyle.h> |
33 #include <hbinstance.h> |
34 #include <hbinstance.h> |
34 #include <hbtheme.h> |
35 #include <hbtheme.h> |
35 #include <hbtooltip.h> |
36 #include <hbtooltip.h> |
36 #include <hbwidgetfeedback.h> |
37 #include <hbwidgetfeedback.h> |
37 #include <hbgraphicsscene.h> |
38 #include <hbgraphicsscene.h> |
|
39 #include <hbtoucharea.h> |
|
40 #include <hbslider.h> |
38 #include <QGraphicsItem> |
41 #include <QGraphicsItem> |
39 #include <QGraphicsSceneMouseEvent> |
42 #include <QGraphicsSceneMouseEvent> |
40 #ifdef HB_GESTURE_FW |
43 #ifdef HB_GESTURE_FW |
41 #include "hbtapgesture.h" |
44 #include "hbtapgesture.h" |
42 #include "hbpangesture.h" |
45 #include "hbpangesture.h" |
|
46 #include "hbtapandholdgesture.h" |
|
47 |
43 #endif |
48 #endif |
44 |
49 |
45 #ifdef HB_EFFECTS |
50 #ifdef HB_EFFECTS |
46 #include "hbeffect.h" |
51 #include "hbeffect.h" |
47 #include "hbeffectinternal_p.h" |
52 #include "hbeffectinternal_p.h" |
60 majorTickInterval( 0 ),// major tick interval |
65 majorTickInterval( 0 ),// major tick interval |
61 minorTickInterval( 0 ),// minor tick interval |
66 minorTickInterval( 0 ),// minor tick interval |
62 groove( 0 ), //slider groove |
67 groove( 0 ), //slider groove |
63 progressGroove( 0 ),//progress mask top of groove |
68 progressGroove( 0 ),//progress mask top of groove |
64 displayCurrValueToolTip( true ), // holds whether to show current value tooltip or not |
69 displayCurrValueToolTip( true ), // holds whether to show current value tooltip or not |
65 toolTipAlignment( Qt::AlignTop|Qt::AlignRight ), // tooltip alignment |
70 toolTipAlignment( Qt::AlignTop ), // tooltip alignment |
66 groovePressed( false ), // hold whether groove is pressed or not |
71 groovePressed( false ), // hold whether groove is pressed or not |
67 setDefault( false ), // holds whther default value for track press is set |
72 setDefault( false ), // holds whther default value for track press is set |
68 previousValue( 0 ), // default value for track press |
73 previousValue( 0 ), // default value for track press |
69 trackHandlingEnable( false ),// this variable holds whether track will be interective or not |
74 trackHandlingEnable( false ),// this variable holds whether track will be interective or not |
70 handleMoving( false ), |
75 handleMoving( false ), |
71 grooveTouchArea ( 0 ), |
76 grooveTouchArea ( 0 ), |
72 enableProgressTrack ( true ), |
77 enableProgressTrack ( true ), |
73 userDefinedTooltipAlign ( false ) |
78 userDefinedTooltipAlign ( false ), |
|
79 tooltipArea(0), |
|
80 tooltipBorderHeight( 0 ) |
74 { |
81 { |
75 |
82 |
76 majorLabel.clear(); |
83 majorLabel.clear(); |
77 minorLabel.clear(); |
84 minorLabel.clear(); |
78 |
85 |
96 |
103 |
97 q->enableTrackEventHandling( true ); |
104 q->enableTrackEventHandling( true ); |
98 |
105 |
99 // creating handle |
106 // creating handle |
100 handle = createHandle(); |
107 handle = createHandle(); |
101 if(handle) { |
108 if (handle) { |
102 HbStyle::setItemName( handle, "handle" ); |
109 HbStyle::setItemName( handle, "handle" ); |
103 } |
110 } |
104 #if defined( QT_KEYPAD_NAVIGATION ) && !defined( Q_OS_SYMBIAN ) |
111 #if defined( QT_KEYPAD_NAVIGATION ) && !defined( Q_OS_SYMBIAN ) |
105 q->setFocusPolicy( Qt::FocusPolicy( ( qApp->style( ) )->styleHint( QStyle::SH_Button_FocusPolicy ) ) ); |
112 q->setFocusPolicy( Qt::FocusPolicy( ( qApp->style( ) )->styleHint( QStyle::SH_Button_FocusPolicy ) ) ); |
106 #endif |
113 #endif |
107 groove = createGroove(); |
114 groove = createGroove(); |
108 if(groove) { |
115 if (groove) { |
109 HbStyle::setItemName( groove, "groove" ); |
116 HbStyle::setItemName( groove, "groove" ); |
110 } |
117 } |
111 #ifdef HB_GESTURE_FW |
118 #ifdef HB_GESTURE_FW |
112 q->setFiltersChildEvents(true) ; |
119 q->setFiltersChildEvents(true) ; |
113 #endif |
120 #endif |
114 |
121 |
115 //filled item top of groove |
122 //filled item top of groove |
116 if ( enableProgressTrack ) { |
123 if ( enableProgressTrack ) { |
117 progressGroove = createProgressGroove(); |
124 progressGroove = createProgressGroove(); |
118 if(progressGroove) { |
125 if (progressGroove) { |
119 HbStyle::setItemName( progressGroove, "progressgroove"); |
126 HbStyle::setItemName( progressGroove, "progressgroove"); |
120 } |
127 } |
121 } |
128 } |
|
129 tooltipArea = new HbTouchArea(q); |
122 q->connect( hbInstance->theme( ), SIGNAL( changed( ) ), q, SLOT( updateTheme( ) ) ); |
130 q->connect( hbInstance->theme( ), SIGNAL( changed( ) ), q, SLOT( updateTheme( ) ) ); |
123 q->connect( q , SIGNAL( actionTriggered( int ) ), q , SLOT( showToolTip( ) ) ); |
131 // q->connect( q , SIGNAL( actionTriggered( int ) ), q , SLOT( showToolTip( ) ) ); |
124 q->connect( q , SIGNAL( sliderReleased( ) ), q , SLOT( hideToolTip( ) ) ); |
132 q->connect( q , SIGNAL( sliderReleased( ) ), q , SLOT( hideToolTip( ) ) ); |
125 #if defined( QT_KEYPAD_NAVIGATION ) && !defined( Q_OS_SYMBIAN ) |
133 #if defined( QT_KEYPAD_NAVIGATION ) && !defined( Q_OS_SYMBIAN ) |
126 q->setFlags( QGraphicsItem::ItemIsFocusable ); |
134 q->setFlags( QGraphicsItem::ItemIsFocusable ); |
127 #endif |
135 #endif |
128 } |
136 } |
129 |
137 |
130 |
138 int HbSliderControlPrivate::calculateSliderPosition(QPointF relativePos) |
|
139 { |
|
140 Q_Q (HbSliderControl); |
|
141 qreal span = 0; |
|
142 qreal handlePos = 0; |
|
143 QRectF bounds = q->boundingRect( ); |
|
144 QRectF handleBounds = handle->boundingRect( ); |
|
145 bounds.adjust( 0, 0, -handleBounds.width( ), -handleBounds.height( ) ); |
|
146 // calculate handle position and span |
|
147 switch ( q->orientation( ) ) { |
|
148 case Qt::Horizontal: |
|
149 handlePos = relativePos.x( ) - handleBounds.width( ) / 2; |
|
150 span = bounds.width( ); |
|
151 break; |
|
152 case Qt::Vertical: |
|
153 handlePos = relativePos.y( ) - handleBounds.height( ) / 2; |
|
154 span = bounds.height( ); |
|
155 break; |
|
156 default: |
|
157 break; |
|
158 } |
|
159 HbStyleOptionSlider opt; |
|
160 q->initStyleOption( &opt ); |
|
161 int pressValue = QStyle::sliderValueFromPosition( opt.minimum, opt.maximum, |
|
162 static_cast<int>( handlePos ),static_cast<int>( span ),opt.upsideDown ); |
|
163 return pressValue; |
|
164 |
|
165 |
|
166 } |
131 |
167 |
132 /*! |
168 /*! |
133 \internal |
169 \internal |
134 This is used to create the handle, it is virtual and can be overridden to create different handle. |
170 This is used to create the handle, it is virtual and can be overridden to create different handle. |
135 */ |
171 */ |
145 This is used to create the groove.It can be overrideen by derived class |
181 This is used to create the groove.It can be overrideen by derived class |
146 */ |
182 */ |
147 QGraphicsItem *HbSliderControlPrivate::createGroove() |
183 QGraphicsItem *HbSliderControlPrivate::createGroove() |
148 { |
184 { |
149 Q_Q( HbSliderControl ); |
185 Q_Q( HbSliderControl ); |
150 QGraphicsItem *groove = qgraphicsitem_cast<QGraphicsItem*>( q->style( )->createPrimitive( |
186 QGraphicsItem *groove = qgraphicsitem_cast<QGraphicsItem*>( HbStylePrivate::createPrimitive( |
151 HbStyle::P_Slider_groove, q ) ); |
187 HbStylePrivate::P_Slider_groove, q ) ); |
152 return groove; |
188 return groove; |
153 } |
189 } |
154 /*! |
190 /*! |
155 \internal |
191 \internal |
156 This is used to create the masked progress groove.This can be overrideen by derived class |
192 This is used to create the masked progress groove.This can be overrideen by derived class |
157 */ |
193 */ |
158 QGraphicsItem *HbSliderControlPrivate::createProgressGroove() |
194 QGraphicsItem *HbSliderControlPrivate::createProgressGroove() |
159 { |
195 { |
160 Q_Q( HbSliderControl ); |
196 Q_Q( HbSliderControl ); |
161 QGraphicsItem *proggroove = qgraphicsitem_cast<QGraphicsItem*>( q->style( )->createPrimitive( |
197 QGraphicsItem *proggroove = qgraphicsitem_cast<QGraphicsItem*>( HbStylePrivate::createPrimitive( |
162 HbStyle::P_Slider_progressgroove, q ) );//comes on top of groove |
198 HbStylePrivate::P_Slider_progressgroove, q ) );//comes on top of groove |
163 return proggroove; |
199 return proggroove; |
164 } |
200 } |
165 |
201 |
166 /*! |
202 /*! |
167 This api adjust the handle within slider area |
203 This api adjust the handle within slider area |
635 if ( !eventRect.contains( event->scenePos( ) ) ) { |
680 if ( !eventRect.contains( event->scenePos( ) ) ) { |
636 event->ignore( ); |
681 event->ignore( ); |
637 return; |
682 return; |
638 } |
683 } |
639 event->accept( ); |
684 event->accept( ); |
640 if( d->onHandle( event->scenePos( ) ) ) { |
685 if ( d->onHandle( event->scenePos( ) ) ) { |
641 HbWidgetFeedback::triggered( this, Hb::InstantPressed, Hb::ModifierSliderHandle ); |
686 HbWidgetFeedback::triggered( this, Hb::InstantPressed, Hb::ModifierSliderHandle ); |
642 setSliderDown( true ); |
687 setSliderDown( true ); |
643 d->handle->updatePrimitives( ); |
688 d->handle->updatePrimitives( ); |
644 d->handleMoving = true; |
689 d->handleMoving = true; |
645 } |
690 } |
646 else { |
691 else { |
647 // effect |
692 // effect |
648 #ifdef HB_EFFECTS |
693 #ifdef HB_EFFECTS |
649 if( d->grooveTouchArea->sceneBoundingRect( ).contains( event->scenePos( ) ) ) { |
694 if ( d->grooveTouchArea->sceneBoundingRect( ).contains( event->scenePos( ) ) ) { |
650 if( orientation( ) == Qt::Horizontal ) { |
695 if ( orientation( ) == Qt::Horizontal ) { |
651 // effect for horizontal track press |
696 // effect for horizontal track press |
652 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_h_trackpress", "h_trackpress" ); |
697 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_h_trackpress", "h_trackpress" ); |
653 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "h_trackrpress" ); |
698 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "h_trackrpress" ); |
654 } |
699 } |
655 else { |
700 else { |
679 initStyleOption( &opt ); |
724 initStyleOption( &opt ); |
680 // calculate pixel value for event position |
725 // calculate pixel value for event position |
681 int pressValue = QStyle::sliderValueFromPosition( opt.minimum, opt.maximum, |
726 int pressValue = QStyle::sliderValueFromPosition( opt.minimum, opt.maximum, |
682 static_cast<int>( handlePos ),static_cast<int>( span ),opt.upsideDown ); |
727 static_cast<int>( handlePos ),static_cast<int>( span ),opt.upsideDown ); |
683 //update the groove and touch item |
728 //update the groove and touch item |
684 style( )->updatePrimitive( d->groove, HbStyle::P_Slider_groove, &opt ); |
729 HbStylePrivate::updatePrimitive( d->groove, HbStylePrivate::P_Slider_groove, &opt ); |
685 // if default is set then do not increment or decrement slider value |
730 // if default is set then do not increment or decrement slider value |
686 // just set default value to slider |
731 // just set default value to slider |
687 if ( d->setDefault ) { |
732 if ( d->setDefault ) { |
688 setValue( d->previousValue ); |
733 setValue( d->previousValue ); |
689 if ( pressValue > value( ) ) { |
734 if ( pressValue > value( ) ) { |
778 */ |
823 */ |
779 #ifdef HB_GESTURE_FW |
824 #ifdef HB_GESTURE_FW |
780 void HbSliderControl::gestureEvent(QGestureEvent *event) |
825 void HbSliderControl::gestureEvent(QGestureEvent *event) |
781 { |
826 { |
782 Q_D(HbSliderControl); |
827 Q_D(HbSliderControl); |
783 if(HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) { |
828 if ( HbTapAndHoldGesture *tapandHold = qobject_cast<HbTapAndHoldGesture *> ( event->gesture( Qt::TapAndHoldGesture ) ) ) { |
784 if( d->onHandle( event->mapToGraphicsScene(tap->position( ) ) ) ){ |
829 if (tapandHold->state() == Qt::GestureStarted) { |
|
830 QPointF relativePos = mapFromScene( event->mapToGraphicsScene(tapandHold->position( ) ) ); |
|
831 int pressValue = d->calculateSliderPosition( relativePos ); |
|
832 setToolTip(QString::number( pressValue ) ); |
|
833 QRectF handleRect=d->handle->boundingRect(); |
|
834 QRectF tooltipRect = handleRect; |
|
835 QRectF touchPointRect=handleRect; |
|
836 if (orientation() == Qt::Horizontal) { |
|
837 touchPointRect.moveCenter(QPointF( boundingRect().width()/2,boundingRect( ).height()/2 ) ); |
|
838 touchPointRect.moveLeft(relativePos.rx() - touchPointRect.width( )/2); |
|
839 |
|
840 } else { |
|
841 touchPointRect.moveCenter(QPointF( boundingRect().width()/2,boundingRect( ).height()/2 ) ); |
|
842 touchPointRect.moveTop( relativePos.ry() - touchPointRect.height()/2 ); |
|
843 } |
|
844 tooltipRect.setHeight ( d->tooltipBorderHeight); |
|
845 tooltipRect.moveBottom( touchPointRect.top() ); |
|
846 tooltipRect.moveLeft (touchPointRect.left( ) ); |
|
847 d->tooltipArea->setGeometry(tooltipRect); |
|
848 d->tooltipArea->setGeometry(tooltipRect); |
|
849 d->tooltipArea->update(); |
|
850 if ( d->displayCurrValueToolTip ) { |
|
851 HbToolTip::showText( toolTip( ) , d->tooltipArea, d->toolTipAlignment ); |
|
852 } |
|
853 |
|
854 return; |
|
855 } |
|
856 } |
|
857 if ( HbTapGesture *tap = qobject_cast<HbTapGesture *> (event->gesture( Qt::TapGesture ) )) { |
|
858 if ( d->onHandle( event->mapToGraphicsScene(tap->position( ) ) ) ) { |
785 event->ignore(); |
859 event->ignore(); |
786 return; |
860 return; |
787 } |
861 } |
788 switch(tap->state()) { |
862 switch( tap->state( ) ) { |
789 case Qt::GestureStarted: { |
863 case Qt::GestureStarted: { |
790 QRectF eventRect = d->grooveTouchArea->sceneBoundingRect( ); |
864 QRectF eventRect = d->grooveTouchArea->sceneBoundingRect( ); |
791 if ( !d->trackHandlingEnable || maximum( ) == minimum( ) || |
865 if ( !d->trackHandlingEnable || maximum( ) == minimum( ) || |
792 !eventRect.contains( event->mapToGraphicsScene(tap->position( ) ) ) ){ |
866 !eventRect.contains( event->mapToGraphicsScene(tap->position( ) ) ) ) { |
793 event->ignore( ); |
867 event->ignore( ); |
794 return; |
868 return; |
795 } |
869 } |
796 |
870 |
797 #if defined( QT_KEYPAD_NAVIGATION ) && !defined( Q_OS_SYMBIAN ) |
871 #if defined( QT_KEYPAD_NAVIGATION ) && !defined( Q_OS_SYMBIAN ) |
800 } |
874 } |
801 #endif |
875 #endif |
802 event->accept( ); |
876 event->accept( ); |
803 // effect |
877 // effect |
804 #ifdef HB_EFFECTS |
878 #ifdef HB_EFFECTS |
805 if( orientation( ) == Qt::Horizontal ) { |
879 if ( orientation( ) == Qt::Horizontal ) { |
806 // effect for horizontal track press |
880 // effect for horizontal track press |
807 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_h_trackpress", "h_trackpress" ); |
881 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_h_trackpress", "h_trackpress" ); |
808 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "h_trackrpress" ); |
882 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "h_trackrpress" ); |
809 } |
883 } else { |
810 else { |
|
811 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_v_trackpress", "v_trackpress" ); |
884 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_v_trackpress", "v_trackpress" ); |
812 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "v_trackpress" ); |
885 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "v_trackpress" ); |
813 } |
886 } |
814 |
887 |
815 #endif |
888 #endif |
816 HbStyleOptionSlider opt; |
889 HbStyleOptionSlider opt; |
817 d->groovePressed = true; |
890 d->groovePressed = true; |
818 initStyleOption( &opt ); |
891 initStyleOption( &opt ); |
819 style( )->updatePrimitive( d->groove, HbStyle::P_Slider_groove, &opt ); |
892 HbStylePrivate::updatePrimitive( d->groove, HbStylePrivate::P_Slider_groove, &opt ); |
820 HbWidgetFeedback::triggered( this, Hb::InstantPressed ); |
893 HbWidgetFeedback::triggered( this, Hb::InstantPressed ); |
821 } |
894 } |
822 break; |
895 break; |
823 case Qt::GestureFinished:{ |
896 case Qt::GestureFinished:{ |
824 if ( !d->trackHandlingEnable ) { |
897 if ( !d->trackHandlingEnable ) { |
825 event->ignore( ); |
898 event->ignore( ); |
826 return; |
899 return; |
827 } |
900 } |
828 qreal handlePos = 0; |
|
829 qreal span = 0; |
|
830 QRectF bounds = boundingRect( ); |
|
831 QRectF handleBounds = d->handle->boundingRect( ); |
|
832 bounds.adjust( 0, 0, -handleBounds.width( ), -handleBounds.height( ) ); |
|
833 QPointF relativePos = mapFromScene( event->mapToGraphicsScene(tap->position( ) ) ); |
901 QPointF relativePos = mapFromScene( event->mapToGraphicsScene(tap->position( ) ) ); |
834 // calculate handle position and span |
902 int pressValue = d->calculateSliderPosition (relativePos); |
835 switch ( orientation( ) ) { |
|
836 case Qt::Horizontal: |
|
837 handlePos = relativePos.x( ) - handleBounds.width( ) / 2; |
|
838 span = bounds.width( ); |
|
839 break; |
|
840 case Qt::Vertical: |
|
841 handlePos = relativePos.y( ) - handleBounds.height( ) / 2; |
|
842 span = bounds.height( ); |
|
843 break; |
|
844 default: |
|
845 break; |
|
846 } |
|
847 HbStyleOptionSlider opt; |
|
848 initStyleOption( &opt ); |
|
849 |
|
850 int pressValue = QStyle::sliderValueFromPosition( opt.minimum, opt.maximum, |
|
851 static_cast<int>( handlePos ),static_cast<int>( span ),opt.upsideDown ); |
|
852 |
|
853 |
|
854 // if default is set then don't increment or decrement slider value |
903 // if default is set then don't increment or decrement slider value |
855 // just set default value to slider |
904 // just set default value to slider |
856 setSliderPosition( pressValue ); |
905 setSliderPosition( pressValue ); |
857 triggerAction( SliderMove ); |
906 triggerAction( SliderMove ); |
858 setRepeatAction( SliderNoAction, pressValue ); |
907 setRepeatAction( SliderNoAction, pressValue ); |
859 HbWidgetFeedback::triggered( this, Hb::InstantReleased ); |
908 HbWidgetFeedback::triggered( this, Hb::InstantReleased ); |
860 if ( d->groovePressed ) { |
909 if ( d->groovePressed ) { |
861 #ifdef HB_EFFECTS |
910 #ifdef HB_EFFECTS |
862 if( orientation( ) == Qt::Horizontal ) { |
911 if ( orientation( ) == Qt::Horizontal ) { |
863 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_h_trackrelease", "h_trackrelease" ); |
912 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_h_trackrelease", "h_trackrelease" ); |
864 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "h_trackrelease" ); |
913 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "h_trackrelease" ); |
865 } else { |
914 } else { |
866 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_v_trackrelease", "v_trackrelease" ); |
915 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_v_trackrelease", "v_trackrelease" ); |
867 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "v_trackrelease" ); |
916 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "v_trackrelease" ); |
869 #endif |
918 #endif |
870 HbStyleOptionSlider opt; |
919 HbStyleOptionSlider opt; |
871 d->groovePressed = false; |
920 d->groovePressed = false; |
872 initStyleOption( &opt ); |
921 initStyleOption( &opt ); |
873 // update primitive from press to normal |
922 // update primitive from press to normal |
874 style( )->updatePrimitive( d->groove, HbStyle::P_Slider_groove, &opt ); |
923 HbStylePrivate::updatePrimitive( d->groove, HbStylePrivate::P_Slider_groove, &opt ); |
875 } |
924 } |
876 } |
925 } |
877 break; |
926 break; |
878 |
927 |
879 case Qt::GestureCanceled: { |
928 case Qt::GestureCanceled: { |
880 if ( d->groovePressed ) { |
929 if ( d->groovePressed ) { |
881 #ifdef HB_EFFECTS |
930 #ifdef HB_EFFECTS |
882 if( orientation( ) == Qt::Horizontal ) { |
931 if ( orientation( ) == Qt::Horizontal ) { |
883 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_h_trackrelease", "h_trackrelease" ); |
932 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_h_trackrelease", "h_trackrelease" ); |
884 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "h_trackrelease" ); |
933 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "h_trackrelease" ); |
885 } else { |
934 } else { |
886 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_v_trackrelease", "v_trackrelease" ); |
935 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_v_trackrelease", "v_trackrelease" ); |
887 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "v_trackrelease" ); |
936 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "v_trackrelease" ); |
889 #endif |
938 #endif |
890 HbStyleOptionSlider opt; |
939 HbStyleOptionSlider opt; |
891 d->groovePressed = false; |
940 d->groovePressed = false; |
892 initStyleOption( &opt ); |
941 initStyleOption( &opt ); |
893 // update primitive from press to normal |
942 // update primitive from press to normal |
894 style( )->updatePrimitive( d->groove, HbStyle::P_Slider_groove, &opt ); |
943 HbStylePrivate::updatePrimitive( d->groove, HbStylePrivate::P_Slider_groove, &opt ); |
895 } |
944 } |
896 } |
945 } |
897 break; |
946 break; |
898 |
947 |
899 default: |
948 default: |
900 break; |
949 break; |
901 } |
950 } |
902 } |
951 } |
903 if (HbPanGesture *panGesture = qobject_cast<HbPanGesture*>(event->gesture(Qt::PanGesture))) { |
952 if ( HbPanGesture *panGesture = qobject_cast<HbPanGesture*> (event->gesture(Qt::PanGesture) ) ) { |
904 switch(panGesture->state( )) { |
953 switch(panGesture->state( ) ) { |
905 case Qt::GestureStarted: |
954 case Qt::GestureStarted: |
906 case Qt::GestureUpdated:{ |
955 case Qt::GestureUpdated:{ |
907 QPointF startPoint = event->mapToGraphicsScene(panGesture->offset()+panGesture->startPos( ) ); |
956 QPointF startPoint = event->mapToGraphicsScene(panGesture->offset()+panGesture->startPos( ) ); |
908 //if the position is on thumb , then start moving the thumb |
957 //if the position is on thumb , then start moving the thumb |
909 if( ( d->onHandle( startPoint) && d->grooveTouchArea->sceneBoundingRect( ).contains( startPoint))||isSliderDown( ) ) { |
958 if ( ( d->onHandle( startPoint) && d->grooveTouchArea->sceneBoundingRect( ).contains( startPoint) )||isSliderDown( ) ) { |
910 qreal handlePos = 0; |
959 QPointF relativePos = mapFromScene( event->mapToGraphicsScene(panGesture->startPos( ) + panGesture->offset() ) ); |
911 qreal span = 0; |
960 int pressValue = d->calculateSliderPosition (relativePos); |
912 QRectF bounds = boundingRect( ); |
|
913 QRectF handleBounds = d->handle->boundingRect( ); |
|
914 bounds.adjust( 0, 0, -handleBounds.width( ), -handleBounds.height( ) ); |
|
915 QPointF relativePos = mapFromScene( event->mapToGraphicsScene(panGesture->startPos( ) + panGesture->offset()) ); |
|
916 // calculate handle position and span |
|
917 switch ( orientation( ) ) { |
|
918 case Qt::Horizontal: |
|
919 handlePos = relativePos.x( ) - handleBounds.width( ) / 2; |
|
920 span = bounds.width( ); |
|
921 break; |
|
922 case Qt::Vertical: |
|
923 handlePos = relativePos.y( ) - handleBounds.height( ) / 2; |
|
924 span = bounds.height( ); |
|
925 break; |
|
926 default: |
|
927 break; |
|
928 } |
|
929 HbStyleOptionSlider opt; |
|
930 initStyleOption( &opt ); |
|
931 |
|
932 int pressValue = QStyle::sliderValueFromPosition( opt.minimum, opt.maximum, |
|
933 static_cast<int>( handlePos ),static_cast<int>( span ),opt.upsideDown ); |
|
934 setRepeatAction( SliderNoAction,static_cast<int>( pressValue ) ); |
961 setRepeatAction( SliderNoAction,static_cast<int>( pressValue ) ); |
935 setSliderDown( true ); |
962 setSliderDown( true ); |
936 setSliderPosition( pressValue ); |
963 setSliderPosition( pressValue ); |
|
964 setToolTip( QString::number( pressValue ) ); |
937 showToolTip( ); |
965 showToolTip( ); |
938 d->groovePressed = false; |
966 d->groovePressed = false; |
939 updatePrimitives(); |
967 updatePrimitives(); |
940 d->handleMoving = true ; |
968 d->handleMoving = true ; |
941 break; |
969 break; |
942 } else if(d->grooveTouchArea->sceneBoundingRect().contains(startPoint) ){ |
970 } else if (d->grooveTouchArea->sceneBoundingRect().contains(startPoint) ) { |
|
971 QPointF relativePos = mapFromScene( event->mapToGraphicsScene(panGesture->startPos( ) + panGesture->offset() ) ); |
|
972 int pressValue = d->calculateSliderPosition (relativePos); |
|
973 setToolTip( QString::number( pressValue ) ); |
|
974 QRectF handleRect=d->handle->boundingRect(); |
|
975 QRectF tooltipRect = handleRect; |
|
976 QRectF touchPointRect=handleRect; |
|
977 if (orientation() == Qt::Horizontal) { |
|
978 touchPointRect.moveCenter(QPointF( boundingRect().width()/2,boundingRect( ).height()/2 ) ); |
|
979 touchPointRect.moveLeft(relativePos.rx() - touchPointRect.width( )/2); |
|
980 } else { |
|
981 touchPointRect.moveCenter(QPointF( boundingRect().width()/2,boundingRect( ).height()/2 ) ); |
|
982 touchPointRect.moveTop( relativePos.ry() - touchPointRect.height()/2 ); |
|
983 } |
|
984 tooltipRect.setHeight ( d->tooltipBorderHeight); |
|
985 tooltipRect.moveBottom( touchPointRect.top() ); |
|
986 tooltipRect.moveLeft (touchPointRect.left( ) ); |
|
987 d->tooltipArea->setGeometry(tooltipRect); |
|
988 d->tooltipArea->setGeometry(tooltipRect); |
|
989 d->tooltipArea->update(); |
|
990 if ( d->displayCurrValueToolTip ) { |
|
991 HbToolTip::showText( toolTip( ) , d->tooltipArea, d->toolTipAlignment ); |
|
992 } |
|
993 d->groovePressed = true; |
943 HbStyleOptionSlider opt; |
994 HbStyleOptionSlider opt; |
944 d->groovePressed = true; |
|
945 initStyleOption( &opt ); |
995 initStyleOption( &opt ); |
946 style( )->updatePrimitive( d->groove, HbStyle::P_Slider_groove, &opt ); |
996 HbStylePrivate::updatePrimitive( d->groove, HbStylePrivate::P_Slider_groove, &opt ); |
947 HbWidgetFeedback::triggered( this, Hb::InstantPressed ); |
|
948 event->ignore(); |
997 event->ignore(); |
|
998 QPointF diffOffset = panGesture->offset() - panGesture->lastOffset(); |
|
999 if (orientation() == Qt::Horizontal) { |
|
1000 if (qAbs(diffOffset.x() ) < qAbs(diffOffset.y())) { |
|
1001 HbAbstractSliderControl::gestureEvent(event); |
|
1002 |
|
1003 } |
|
1004 } else { |
|
1005 if (qAbs(diffOffset.y() ) < qAbs(diffOffset.x())) { |
|
1006 HbAbstractSliderControl::gestureEvent(event); |
|
1007 } |
|
1008 } |
|
1009 |
949 break; |
1010 break; |
950 } else { |
1011 } else { |
951 setSliderDown( false ); |
1012 setSliderDown( false ); |
952 d->groovePressed = false; |
1013 d->groovePressed = false; |
953 updatePrimitives( ); |
1014 updatePrimitives( ); |
959 |
1020 |
960 } |
1021 } |
961 break; |
1022 break; |
962 case Qt::GestureFinished: |
1023 case Qt::GestureFinished: |
963 case Qt::GestureCanceled: { |
1024 case Qt::GestureCanceled: { |
|
1025 QPointF startPoint = event->mapToGraphicsScene(panGesture->offset()+panGesture->startPos( ) ); |
964 setSliderDown( false ); |
1026 setSliderDown( false ); |
965 d->groovePressed = false; |
1027 d->groovePressed = false; |
966 updatePrimitives( ); |
1028 updatePrimitives( ); |
967 d->handle->updatePrimitives(); |
1029 d->handle->updatePrimitives(); |
968 d->handleMoving = false; |
1030 if( d->handleMoving ) { |
969 int pressValue = sliderPosition(); |
1031 HbWidgetFeedback::triggered(this, Hb::InstantReleased, Hb::ModifierSliderHandle); |
970 setRepeatAction( SliderNoAction,static_cast<int>( pressValue ) ); |
1032 d->handleMoving = false; |
|
1033 } |
|
1034 if (d->grooveTouchArea->sceneBoundingRect().contains(startPoint) ) { |
|
1035 QPointF relativePos = mapFromScene( event->mapToGraphicsScene(panGesture->startPos( ) + panGesture->offset() ) ); |
|
1036 int pressValue = d->calculateSliderPosition (relativePos); |
|
1037 setRepeatAction( SliderNoAction,static_cast<int>( pressValue ) ); |
|
1038 setSliderPosition( pressValue ); |
|
1039 setToolTip( QString::number( pressValue ) ); |
|
1040 showToolTip( ); |
|
1041 HbWidgetFeedback::triggered( this, Hb::InstantReleased ); |
|
1042 } |
971 event->ignore(); |
1043 event->ignore(); |
972 HbAbstractSliderControl::gestureEvent(event); |
1044 HbAbstractSliderControl::gestureEvent(event); |
973 } |
1045 } |
974 break; |
1046 break; |
975 default: |
1047 default: |
1021 */ |
1093 */ |
1022 void HbSliderControl::resizeEvent( QGraphicsSceneResizeEvent *event ) |
1094 void HbSliderControl::resizeEvent( QGraphicsSceneResizeEvent *event ) |
1023 { |
1095 { |
1024 Q_D( HbSliderControl ); |
1096 Q_D( HbSliderControl ); |
1025 QGraphicsWidget::resizeEvent( event ); |
1097 QGraphicsWidget::resizeEvent( event ); |
1026 // for Bug Fix::Ticks are not getting updated after |
|
1027 // element is added to slider |
|
1028 updatePrimitives( ); |
1098 updatePrimitives( ); |
1029 repolish(); |
|
1030 d->adjustHandle( ); |
1099 d->adjustHandle( ); |
1031 } |
1100 } |
1032 /*! |
1101 /*! |
1033 reimp |
1102 reimp |
1034 |
1103 |
1035 */ |
1104 */ |
1036 void HbSliderControl::polish( HbStyleParameters& params ) |
1105 void HbSliderControl::polish( HbStyleParameters& params ) |
1037 { |
1106 { |
1038 Q_D( HbSliderControl ); |
1107 Q_D( HbSliderControl ); |
|
1108 params.addParameter("tooltip-border-height"); |
1039 HbStyleOptionSlider option; |
1109 HbStyleOptionSlider option; |
1040 initStyleOption( &option ); |
1110 initStyleOption( &option ); |
1041 HbAbstractSliderControl::polish( params ); |
1111 HbAbstractSliderControl::polish( params ); |
1042 d->adjustHandle( ); |
1112 d->adjustHandle( ); |
1043 updatePrimitives( ); |
1113 updatePrimitives( ); |
|
1114 d->tooltipBorderHeight = params.value("tooltip-border-height").toReal(); |
|
1115 |
1044 } |
1116 } |
1045 |
1117 |
1046 /*! |
1118 /*! |
1047 |
1119 |
1048 */ |
1120 */ |
1320 if ( d->trackHandlingEnable == enable ) { |
1379 if ( d->trackHandlingEnable == enable ) { |
1321 return; |
1380 return; |
1322 } |
1381 } |
1323 if ( enable ) { |
1382 if ( enable ) { |
1324 //creating groove touch area |
1383 //creating groove touch area |
1325 d->grooveTouchArea = qgraphicsitem_cast<QGraphicsItem*>( style( )->createPrimitive( |
1384 d->grooveTouchArea = qgraphicsitem_cast<QGraphicsItem*>( HbStylePrivate::createPrimitive( |
1326 HbStyle::P_SliderElement_touchgroove, this ) ); |
1385 HbStylePrivate::P_SliderElement_touchgroove, this ) ); |
1327 if ( d->grooveTouchArea ) { |
1386 if ( d->grooveTouchArea ) { |
1328 HbStyle::setItemName( d->grooveTouchArea, "groovetoucharea" ); |
1387 HbStyle::setItemName( d->grooveTouchArea, "groovetoucharea" ); |
1329 } |
1388 } |
1330 if(QGraphicsObject *touchArea = d->grooveTouchArea->toGraphicsObject()) { |
1389 if(QGraphicsObject *touchArea = d->grooveTouchArea->toGraphicsObject()) { |
1331 |
1390 |
1332 #ifdef HB_GESTURE_FW |
1391 #ifdef HB_GESTURE_FW |
1333 ungrabGesture(Qt::TapGesture); |
1392 ungrabGesture(Qt::TapGesture); |
1334 ungrabGesture(Qt::PanGesture); |
1393 ungrabGesture(Qt::PanGesture); |
|
1394 ungrabGesture(Qt::TapAndHoldGesture); |
1335 touchArea->grabGesture(Qt::TapGesture); |
1395 touchArea->grabGesture(Qt::TapGesture); |
|
1396 touchArea->grabGesture(Qt::TapAndHoldGesture); |
1336 touchArea->grabGesture(Qt::PanGesture); |
1397 touchArea->grabGesture(Qt::PanGesture); |
1337 #endif |
1398 #endif |
1338 } |
1399 } |
1339 } |
1400 } |
1340 d->trackHandlingEnable = enable ; |
1401 d->trackHandlingEnable = enable ; |