38 #include "hbeffect.h" |
40 #include "hbeffect.h" |
39 #include "hbeffectinternal_p.h" |
41 #include "hbeffectinternal_p.h" |
40 #define HB_PRGRESSSLIDERHANDLE_ITEM_TYPE "HB_PROGRESSSLIDERHANDLE" |
42 #define HB_PRGRESSSLIDERHANDLE_ITEM_TYPE "HB_PROGRESSSLIDERHANDLE" |
41 #endif |
43 #endif |
42 |
44 |
|
45 #ifdef HB_GESTURE_FW |
|
46 #include <hbtapgesture.h> |
|
47 #include <hbpangesture.h> |
|
48 #endif |
|
49 |
43 #define HandleMargin 0 |
50 #define HandleMargin 0 |
44 |
51 |
45 /*! |
52 /*! |
46 \reimp |
53 \reimp |
47 \fn int HbProgressSliderHandle::type() const |
54 \fn int HbProgressSliderHandle::type() const |
48 */ |
55 */ |
49 |
56 |
50 HbProgressSliderHandle::HbProgressSliderHandle(HbHandleParent *parent) |
57 HbProgressSliderHandle::HbProgressSliderHandle(HbHandleParent *parent) |
51 :HbWidget(parent->parentGraphicsItem()), |
58 :HbWidget(parent->parentGraphicsItem()), |
52 q(parent), |
59 q(parent), |
53 mThumbIcon(), |
60 mHandleIcon(), |
54 mPlayThumb(true), |
61 mPlayThumb(true), |
55 mThumbEnabled(false) |
62 mThumbEnabled(false) |
56 { |
63 { |
57 mFlags = 0; |
64 mFlags = 0; |
58 mFlags |= TextVisible; |
65 mFlags |= TextVisible; |
59 mHandleSize = QSizeF(0,0); |
66 mHandleSize = QSizeF(0,0); |
60 |
67 |
61 mSliderState = HbProgressSlider::SliderStatePlayNormal; |
68 mSliderHandleState = HbProgressSlider::SliderStatePlayNormal; |
62 HbStyle *style = static_cast<HbStyle*>(q->style()); |
69 HbStyle *style = static_cast<HbStyle*>(q->style()); |
63 |
70 |
64 mHandleItem = style->createPrimitive(HbStyle::P_ProgressSlider_handle,this); |
71 mHandleIconItem = style->createPrimitive(HbStyle::P_ProgressSliderHandle_icon,this); |
65 HbStyle::setItemName(mHandleItem , "handle"); |
|
66 |
|
67 mHandleIconItem = style->createPrimitive(HbStyle::P_ProgressSlider_handleicon,this); |
|
68 HbStyle::setItemName(mHandleIconItem , "icon"); |
72 HbStyle::setItemName(mHandleIconItem , "icon"); |
69 |
73 |
70 mTouchItem = style->createPrimitive(HbStyle::P_ProgressSliderHandle_toucharea, this); |
74 mTouchItem = style->createPrimitive(HbStyle::P_ProgressSliderHandle_toucharea, this); |
71 HbStyle::setItemName(mTouchItem , "toucharea"); |
75 HbStyle::setItemName(mTouchItem , "toucharea"); |
72 setProperty("state","normal"); |
76 setProperty("state","normal"); |
74 #ifdef HB_EFFECTS |
78 #ifdef HB_EFFECTS |
75 HbEffectInternal::add(HB_PRGRESSSLIDERHANDLE_ITEM_TYPE,"progressslider_handlepress", "progressslider_handlepress"); |
79 HbEffectInternal::add(HB_PRGRESSSLIDERHANDLE_ITEM_TYPE,"progressslider_handlepress", "progressslider_handlepress"); |
76 HbEffectInternal::add(HB_PRGRESSSLIDERHANDLE_ITEM_TYPE,"progressslider_handlerelease", "progressslider_handlerelease"); |
80 HbEffectInternal::add(HB_PRGRESSSLIDERHANDLE_ITEM_TYPE,"progressslider_handlerelease", "progressslider_handlerelease"); |
77 HbEffectInternal::add(HB_PRGRESSSLIDERHANDLE_ITEM_TYPE,"progressslider_handleoutofbound", "progressslider_handleoutofbound"); |
81 HbEffectInternal::add(HB_PRGRESSSLIDERHANDLE_ITEM_TYPE,"progressslider_handleoutofbound", "progressslider_handleoutofbound"); |
78 #endif |
82 #endif |
|
83 |
|
84 #ifdef HB_GESTURE_FW |
|
85 grabGesture(Qt::TapGesture); |
|
86 grabGesture(Qt::PanGesture); |
|
87 |
|
88 if(QGraphicsObject *touchArea = mTouchItem->toGraphicsObject()) { |
|
89 touchArea->grabGesture(Qt::TapGesture); |
|
90 touchArea->grabGesture(Qt::PanGesture); |
|
91 } |
|
92 #endif |
79 } |
93 } |
80 |
94 |
81 HbProgressSliderHandle::~HbProgressSliderHandle() |
95 HbProgressSliderHandle::~HbProgressSliderHandle() |
82 { |
96 { |
83 } |
97 } |
84 |
98 |
85 void HbProgressSliderHandle::setThumbIcon(const HbIcon& icon) |
99 void HbProgressSliderHandle::setHandleIcon(const HbIcon& icon) |
86 { |
100 { |
87 if(icon.isNull()) { |
101 if(icon.isNull()) { |
88 return; |
102 return; |
89 } |
103 } |
90 HbStyle *style = qobject_cast<HbStyle*>(q->style()); |
104 HbStyle *style = qobject_cast<HbStyle*>(q->style()); |
91 mThumbIcon= icon; |
105 mHandleIcon= icon; |
92 HbStyleOptionProgressBar option; |
106 |
93 option.handleRect = boundingRect(); |
107 HbStyleOptionProgressSliderHandle option; |
94 option.thumbIcon = mThumbIcon; |
108 initStyleOption(&option); |
95 style->updatePrimitive(mHandleIconItem,HbStyle::P_ProgressSlider_handleicon,&option); |
109 |
|
110 style->updatePrimitive(mHandleIconItem, HbStyle::P_ProgressSliderHandle_icon, &option); |
96 mThumbEnabled = true; |
111 mThumbEnabled = true; |
97 } |
112 } |
98 |
113 |
99 HbIcon HbProgressSliderHandle::thumbIcon() const |
114 HbIcon HbProgressSliderHandle::thumbIcon() const |
100 { |
115 { |
101 return mThumbIcon; |
116 return mHandleIcon; |
|
117 } |
|
118 |
|
119 void HbProgressSliderHandle::gestureEvent(QGestureEvent *event) |
|
120 { |
|
121 Q_UNUSED(event); |
|
122 // HbWidgetBase::gestureEvent() ignores, overriding to accept |
102 } |
123 } |
103 |
124 |
104 void HbProgressSliderHandle::mousePressEvent(QGraphicsSceneMouseEvent *event) |
125 void HbProgressSliderHandle::mousePressEvent(QGraphicsSceneMouseEvent *event) |
105 { |
126 { |
106 HbWidget::mousePressEvent(event); |
127 HbWidget::mousePressEvent(event); |
107 |
128 |
108 #ifdef HB_EFFECTS |
129 #ifdef HB_EFFECTS |
109 HbEffect::start(this, HB_PRGRESSSLIDERHANDLE_ITEM_TYPE, "progressslider_handlepress"); |
130 HbEffect::start(this, HB_PRGRESSSLIDERHANDLE_ITEM_TYPE, "progressslider_handlepress"); |
110 #endif |
131 #endif |
111 mFlags |= HbProgressSliderHandle::MousePressed; |
132 mFlags |= HbProgressSliderHandle::MousePressed; |
|
133 |
|
134 HbStyleOptionProgressSliderHandle option; |
|
135 initStyleOption(&option); |
|
136 option.pressedState = true; |
|
137 if (mHandleIconItem) { |
|
138 style()->updatePrimitive(mHandleIconItem, HbStyle::P_ProgressSliderHandle_icon, &option); |
|
139 } |
112 |
140 |
113 mMousePressPos = event->scenePos(); |
141 mMousePressPos = event->scenePos(); |
114 mItemPosAtPress = pos(); |
142 mItemPosAtPress = pos(); |
115 if(q->textVisible()) { |
143 if(q->textVisible()) { |
116 HbToolTip::showText(q->toolTipText(),this, QRectF(mItemPosAtPress,QSize(0,0)),q->textAlignment()); |
144 HbToolTip::showText(q->toolTipText(),this, QRectF(mItemPosAtPress,QSize(0,0)),q->textAlignment()); |
117 } |
145 } |
|
146 else { |
|
147 HbExtendedLocale locale; |
|
148 HbToolTip::showText(locale.toString(q->progressValue()),this, QRectF(mItemCurPos,QSize(0,0)),q->textAlignment()); |
|
149 } |
118 |
150 |
119 HbWidgetFeedback::triggered(q->parentGraphicsWidget(), Hb::InstantPressed, Hb::ModifierSliderHandle); |
151 HbWidgetFeedback::triggered(q->parentGraphicsWidget(), Hb::InstantPressed, Hb::ModifierSliderHandle); |
120 |
152 |
121 event->accept(); |
153 event->accept(); |
122 q->emitSliderPressed(); |
154 q->emitSliderPressed(); |
123 } |
155 } |
124 |
156 |
125 void HbProgressSliderHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
157 void HbProgressSliderHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
126 { |
158 { |
127 HbWidget::mouseReleaseEvent(event); |
159 HbWidget::mouseReleaseEvent(event); |
|
160 |
|
161 HbStyleOptionProgressSliderHandle option; |
|
162 initStyleOption(&option); |
|
163 option.pressedState = false; |
|
164 if (mHandleIconItem) { |
|
165 style()->updatePrimitive(mHandleIconItem, HbStyle::P_ProgressSliderHandle_icon, &option); |
|
166 } |
|
167 |
128 if (isHandleMoving()) { |
168 if (isHandleMoving()) { |
129 HbWidgetFeedback::continuousStopped(q->parentGraphicsWidget(), Hb::ContinuousDragged); |
169 HbWidgetFeedback::continuousStopped(q->parentGraphicsWidget(), Hb::ContinuousDragged); |
130 } |
170 } |
131 HbWidgetFeedback::triggered(q->parentGraphicsWidget(), Hb::InstantReleased, Hb::ModifierSliderHandle); |
171 HbWidgetFeedback::triggered(q->parentGraphicsWidget(), Hb::InstantReleased, Hb::ModifierSliderHandle); |
132 |
172 |
336 } |
381 } |
337 |
382 |
338 |
383 |
339 void HbProgressSliderHandle::updatePrimitives() |
384 void HbProgressSliderHandle::updatePrimitives() |
340 { |
385 { |
341 HbStyleOptionProgressBar option; |
386 HbStyleOptionProgressSliderHandle option; |
342 option.thumbIcon = mThumbIcon; |
387 initStyleOption(&option); |
343 option.sliderState = (HbStyleOptionProgressBar::SliderState) mSliderState; |
|
344 |
|
345 if (mHandleItem) { |
|
346 style()->updatePrimitive(mHandleItem, HbStyle::P_ProgressSlider_handle, &option); |
|
347 } |
|
348 |
388 |
349 if (mHandleIconItem) { |
389 if (mHandleIconItem) { |
350 style()->updatePrimitive(mHandleIconItem, HbStyle::P_ProgressSlider_handleicon, &option); |
390 style()->updatePrimitive(mHandleIconItem, HbStyle::P_ProgressSliderHandle_icon, &option); |
351 } |
391 } |
352 |
392 |
353 } |
393 } |
354 |
394 |
|
395 /*! |
|
396 Returns the pointer for \a primitive passed. |
|
397 Will return NULL if \a primitive passed is invalid |
|
398 */ |
|
399 QGraphicsItem* HbProgressSliderHandle::primitive(HbStyle::Primitive primitive) const |
|
400 { |
|
401 switch (primitive) { |
|
402 case HbStyle::P_ProgressSliderHandle_icon: |
|
403 return mHandleIconItem; |
|
404 case HbStyle::P_ProgressSliderHandle_toucharea: |
|
405 return mTouchItem; |
|
406 default: |
|
407 return 0; |
|
408 } |
|
409 } |
|
410 |
|
411 /*! |
|
412 Initializes \a option with the values from this HbProgressSliderHandle. |
|
413 This method is useful for subclasses when they need a HbStyleOptionProgressSliderHandle, |
|
414 but don't want to fill in all the information themselves. |
|
415 */ |
|
416 void HbProgressSliderHandle::initStyleOption(HbStyleOptionProgressSliderHandle *option) const |
|
417 { |
|
418 HbWidget::initStyleOption(option); |
|
419 option->handleIcon = mHandleIcon; |
|
420 option->pressedState = false; |
|
421 option->sliderHandleState = (HbStyleOptionProgressSliderHandle::SliderState) mSliderHandleState; |
|
422 } |
|
423 |