25 |
25 |
26 #include "hbpushbutton.h" |
26 #include "hbpushbutton.h" |
27 #include "hbpushbutton_p.h" |
27 #include "hbpushbutton_p.h" |
28 #include "hbstyle.h" |
28 #include "hbstyle.h" |
29 #include "hbstyleoptionpushbutton.h" |
29 #include "hbstyleoptionpushbutton.h" |
30 #include "hbgesturefilter.h" |
|
31 #include "hbgesture.h" |
|
32 #include "hbframedrawerpool_p.h" |
30 #include "hbframedrawerpool_p.h" |
33 #include "hbnamespace.h" |
31 #include "hbnamespace.h" |
34 #ifdef HB_EFFECTS |
32 #ifdef HB_EFFECTS |
35 #include "hbeffect.h" |
33 #include "hbeffect.h" |
36 #include "hbeffectinternal_p.h" |
34 #include "hbeffectinternal_p.h" |
|
35 #endif |
|
36 |
|
37 #ifdef HB_GESTURE_FW |
|
38 #include <hbtapgesture.h> |
37 #endif |
39 #endif |
38 |
40 |
39 #include <QGraphicsSceneMouseEvent> |
41 #include <QGraphicsSceneMouseEvent> |
40 #include <QTimer> |
42 #include <QTimer> |
41 #include <QGraphicsItem> |
43 #include <QGraphicsItem> |
131 iconItem(0), |
133 iconItem(0), |
132 frameItem(0), |
134 frameItem(0), |
133 focusItem(0), |
135 focusItem(0), |
134 orientation(Qt::Vertical), |
136 orientation(Qt::Vertical), |
135 backgroundFrameDrawer(0), |
137 backgroundFrameDrawer(0), |
136 gestureFilter(0), |
|
137 gestureLongpressed(0), |
|
138 longPressTimer(0), |
138 longPressTimer(0), |
139 textAlignment(Qt::AlignHCenter | Qt::AlignVCenter ), |
139 textAlignment(Qt::AlignHCenter | Qt::AlignVCenter ), |
140 additionalTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter ), |
140 additionalTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter ), |
141 stretched(false), |
141 stretched(false), |
142 navigationKeyPress(false), |
142 navigationKeyPress(false), |
203 iconItem = 0; |
200 iconItem = 0; |
204 } |
201 } |
205 |
202 |
206 if( !touchArea ) { |
203 if( !touchArea ) { |
207 touchArea = q->style()->createPrimitive( HbStyle::P_PushButton_toucharea, q ); |
204 touchArea = q->style()->createPrimitive( HbStyle::P_PushButton_toucharea, q ); |
|
205 if(QGraphicsObject *ta = qgraphicsitem_cast<QGraphicsObject*>(touchArea)) { |
|
206 ta->grabGesture(Qt::TapGesture); |
|
207 q->ungrabGesture(Qt::TapGesture); |
|
208 } else { |
|
209 q->grabGesture(Qt::TapGesture); |
|
210 } |
208 } |
211 } |
209 |
212 |
210 if( !focusItem ) { |
213 if( !focusItem ) { |
211 focusItem = q->style()->createPrimitive(HbStyle::P_PushButton_focus, q); |
214 focusItem = q->style()->createPrimitive(HbStyle::P_PushButton_focus, q); |
212 //focus primitive is will not be visible by default, |
215 //focus primitive is will not be visible by default, |
213 //only in case of keyboard focus events it will be Visible. |
216 //only in case of keyboard focus events it will be Visible. |
214 focusItem->setVisible( false ); |
217 focusItem->setVisible( false ); |
215 } |
218 } |
216 } |
219 } |
217 |
220 |
218 /* |
221 |
219 initGesture. |
|
220 */ |
|
221 void HbPushButtonPrivate::initGesture() |
|
222 { |
|
223 Q_Q(HbPushButton); |
|
224 // Create gesture filter |
|
225 gestureFilter = new HbGestureSceneFilter( Qt::LeftButton, q ); |
|
226 // Add gestures for longpress |
|
227 gestureLongpressed = new HbGesture( HbGesture::longpress,5 ); |
|
228 gestureFilter->addGesture( gestureLongpressed ); |
|
229 |
|
230 // scene event filter for gesture can be installed |
|
231 // if widget is already added to scene |
|
232 if (q->scene()) { |
|
233 q->installSceneEventFilter(gestureFilter); |
|
234 if (touchArea) { |
|
235 touchArea->installSceneEventFilter(gestureFilter); |
|
236 } |
|
237 } |
|
238 |
|
239 } |
|
240 |
222 |
241 void HbPushButtonPrivate::_q_handleLongPress(QPointF point) |
223 void HbPushButtonPrivate::_q_handleLongPress(QPointF point) |
242 { |
224 { |
243 Q_Q(HbPushButton); |
225 Q_Q(HbPushButton); |
244 if(!longPress){ |
226 if(!longPress){ |
272 HbPushButton::HbPushButton( QGraphicsItem *parent ) |
252 HbPushButton::HbPushButton( QGraphicsItem *parent ) |
273 : HbAbstractButton( *new HbPushButtonPrivate, parent ) |
253 : HbAbstractButton( *new HbPushButtonPrivate, parent ) |
274 { |
254 { |
275 Q_D(HbPushButton); |
255 Q_D(HbPushButton); |
276 d->initialize(); |
256 d->initialize(); |
277 connect( d->gestureLongpressed, SIGNAL(longPress(QPointF)), |
257 |
278 this, SLOT(_q_handleLongPress(QPointF))); |
|
279 setProperty("state", "normal"); |
258 setProperty("state", "normal"); |
280 |
259 |
281 } |
260 } |
282 |
261 |
283 /*! |
262 /*! |
326 Q_D(HbPushButton); |
303 Q_D(HbPushButton); |
327 d->icon = icon; |
304 d->icon = icon; |
328 d->text = text; |
305 d->text = text; |
329 d->initialize(); |
306 d->initialize(); |
330 d->orientation = orientation; |
307 d->orientation = orientation; |
331 connect( d->gestureLongpressed, SIGNAL(longPress(QPointF)), |
308 |
332 this, SLOT(_q_handleLongPress(QPointF)) ); |
|
333 setProperty("state", "normal"); |
309 setProperty("state", "normal"); |
334 |
310 |
335 } |
311 } |
336 |
312 |
337 /*! |
313 /*! |
338 Destructs the push button. |
314 Destructs the push button. |
339 */ |
315 */ |
340 HbPushButton::~HbPushButton() |
316 HbPushButton::~HbPushButton() |
341 { |
317 { |
342 Q_D(HbPushButton); |
318 |
343 if( d->gestureFilter ) { |
|
344 removeSceneEventFilter( d->gestureFilter ); |
|
345 } |
|
346 } |
319 } |
347 |
320 |
348 /*! |
321 /*! |
349 @beta |
322 @beta |
350 Sets the \a background of the button. |
323 Sets the \a background of the button. |
769 \internal |
746 \internal |
770 */ |
747 */ |
771 HbPushButton::HbPushButton(HbPushButtonPrivate &dd, QGraphicsItem * parent) : |
748 HbPushButton::HbPushButton(HbPushButtonPrivate &dd, QGraphicsItem * parent) : |
772 HbAbstractButton(dd, parent) |
749 HbAbstractButton(dd, parent) |
773 { |
750 { |
774 Q_D(HbPushButton); |
|
775 d->initGesture(); |
|
776 connect( d->gestureLongpressed, SIGNAL(longPress(QPointF)), |
|
777 this, SLOT(_q_handleLongPress(QPointF)) ); |
|
778 } |
751 } |
779 |
752 |
780 /*! |
753 /*! |
781 Initializes \a option with the values from this HbPushButton. |
754 Initializes \a option with the values from this HbPushButton. |
782 This method is useful for subclasses when they need a HbStyleOptionPushButton, |
755 This method is useful for subclasses when they need a HbStyleOptionPushButton, |
887 if ( hitButton(event->pos()) ){ |
861 if ( hitButton(event->pos()) ){ |
888 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" ); |
862 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" ); |
889 } |
863 } |
890 #endif |
864 #endif |
891 setProperty("state", "pressed"); |
865 setProperty("state", "pressed"); |
892 } |
866 #else |
893 |
867 Q_UNUSED(event) |
|
868 #endif |
|
869 } |
|
870 |
|
871 #ifndef HB_GESTURE_FW |
894 /*! |
872 /*! |
895 \reimp |
873 \reimp |
896 */ |
874 */ |
897 void HbPushButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
875 void HbPushButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
898 { |
876 { |
922 initStyleOption( &buttonOption ); |
900 initStyleOption( &buttonOption ); |
923 if( d->frameItem ){ |
901 if( d->frameItem ){ |
924 style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption ); |
902 style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption ); |
925 } |
903 } |
926 if (d->down) { |
904 if (d->down) { |
927 setProperty("state", "pressed"); |
905 setProperty("state", "pressed"); |
928 } else { |
906 } else { |
929 setProperty("state", "normal"); |
907 setProperty("state", "normal"); |
930 } |
908 } |
931 } |
909 } |
|
910 #endif |
|
911 |
|
912 |
|
913 #ifdef HB_GESTURE_FW |
|
914 void HbPushButton::gestureEvent(QGestureEvent *event) |
|
915 { |
|
916 Q_D(HbPushButton); |
|
917 if(HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) { |
|
918 switch(tap->state()) { |
|
919 case Qt::GestureStarted:{ |
|
920 #ifdef HB_EFFECTS |
|
921 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" ); |
|
922 #endif |
|
923 if(d->checkable && !d->checked){ |
|
924 setProperty("state", "latched"); |
|
925 }else if(!d->checkable){ |
|
926 setProperty("state", "pressed"); |
|
927 } |
|
928 } |
|
929 break; |
|
930 case Qt::GestureUpdated: |
|
931 if(tap->tapStyleHint() == HbTapGesture::TapAndHold) { |
|
932 d->longPress = true; |
|
933 emit longPress(event->mapToGraphicsScene(tap->position())); |
|
934 } |
|
935 break; |
|
936 case Qt::GestureCanceled: |
|
937 setProperty("state", "normal"); |
|
938 break; |
|
939 case Qt::GestureFinished:{ |
|
940 #ifdef HB_EFFECTS |
|
941 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "released" ); |
|
942 #endif |
|
943 if( d->checkable && !d->checked){ |
|
944 setProperty("state", "latched"); |
|
945 }else { |
|
946 setProperty("state", "normal"); |
|
947 } |
|
948 |
|
949 } |
|
950 break; |
|
951 default: |
|
952 break; |
|
953 } |
|
954 } |
|
955 |
|
956 HbAbstractButton::gestureEvent(event); |
|
957 |
|
958 } |
|
959 #endif |
932 |
960 |
933 |
961 |
934 /*! |
962 /*! |
935 \reimp |
963 \reimp |
936 */ |
964 */ |
990 /*! |
1018 /*! |
991 \reimp |
1019 \reimp |
992 */ |
1020 */ |
993 QVariant HbPushButton::itemChange(GraphicsItemChange change, const QVariant &value) |
1021 QVariant HbPushButton::itemChange(GraphicsItemChange change, const QVariant &value) |
994 { |
1022 { |
995 Q_D(HbPushButton); |
|
996 |
|
997 switch ( change ) { |
1023 switch ( change ) { |
998 case ItemEnabledHasChanged: |
1024 case ItemEnabledHasChanged: |
999 case ItemVisibleChange: { |
1025 case ItemVisibleChange: { |
1000 updatePrimitives( ); |
1026 updatePrimitives( ); |
1001 } |
1027 } |
1002 break; |
1028 break; |
1003 case ItemSceneHasChanged: { |
1029 case ItemSceneHasChanged: { |
1004 // scene event filter for gestures can be installed |
|
1005 // once the widget has been added to the scene |
|
1006 if(!value.isNull() && d->gestureFilter) { |
|
1007 installSceneEventFilter(d->gestureFilter); |
|
1008 if (d->touchArea) { |
|
1009 d->touchArea->installSceneEventFilter(d->gestureFilter); |
|
1010 } |
|
1011 } |
|
1012 updatePrimitives(); |
1030 updatePrimitives(); |
1013 } |
1031 } |
1014 break; |
1032 break; |
1015 default: |
1033 default: |
1016 break; |
1034 break; |