24 ****************************************************************************/ |
24 ****************************************************************************/ |
25 |
25 |
26 #include "hbsliderhandle_p.h" |
26 #include "hbsliderhandle_p.h" |
27 #include "hbslidercontrol_p.h" |
27 #include "hbslidercontrol_p.h" |
28 #include "hbslidercontrol_p_p.h" |
28 #include "hbslidercontrol_p_p.h" |
|
29 #include "hbstyle_p.h" |
29 #include <hbwidgetfeedback.h> |
30 #include <hbwidgetfeedback.h> |
30 #include <hbstyle.h> |
31 #include <hbstyle.h> |
31 #include <hbstyleoptionslider_p.h> |
32 #include <hbstyleoptionslider_p.h> |
32 #include <QGraphicsSceneMouseEvent> |
33 #include <QGraphicsSceneMouseEvent> |
33 #include <QGraphicsScene> |
34 #include <QGraphicsScene> |
60 handleDragPos(0), |
61 handleDragPos(0), |
61 touchItem(0), |
62 touchItem(0), |
62 mHandleItem(0) |
63 mHandleItem(0) |
63 { |
64 { |
64 // create handle icon item |
65 // create handle icon item |
65 gItem = slider->style()->createPrimitive(HbStyle::P_Slider_thumb, this); |
66 gItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_Slider_thumb, this); |
66 HbStyle::setItemName(gItem , "icon"); |
67 HbStyle::setItemName(gItem , "icon"); |
67 setFiltersChildEvents(true) ; |
68 setFiltersChildEvents(true) ; |
68 |
69 |
69 // create touch area for handle |
70 // create touch area for handle |
70 touchItem = slider->style()->createPrimitive(HbStyle::P_SliderElement_touchhandle, this); |
71 touchItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_SliderElement_touchhandle, this); |
71 HbStyle::setItemName(touchItem , "toucharea"); |
72 HbStyle::setItemName(touchItem , "toucharea"); |
72 |
73 |
73 setZValue(slider->zValue() + 1); |
74 setZValue(slider->zValue() + 1); |
74 #ifdef HB_GESTURE_FW |
75 #ifdef HB_GESTURE_FW |
75 grabGesture(Qt::TapGesture); |
76 grabGesture(Qt::TapGesture); |
131 HbStyleOptionSlider opt; |
132 HbStyleOptionSlider opt; |
132 sliderControl->initStyleOption(&opt); |
133 sliderControl->initStyleOption(&opt); |
133 if( scene()){ |
134 if( scene()){ |
134 if (true == sliderControl->isSliderDown()){ |
135 if (true == sliderControl->isSliderDown()){ |
135 opt.state |= QStyle::State_Sunken; |
136 opt.state |= QStyle::State_Sunken; |
136 sliderControl->style()->updatePrimitive( |
137 HbStylePrivate::updatePrimitive( |
137 sliderControl->primitive(HbStyle::P_Slider_groove), HbStyle::P_Slider_groove, &opt); |
138 sliderControl->primitive((HbStyle::Primitive)HbStylePrivate::P_Slider_groove), HbStylePrivate::P_Slider_groove, &opt); |
138 } else { |
139 } else { |
139 opt.state &= ~QStyle::State_Sunken; |
140 opt.state &= ~QStyle::State_Sunken; |
140 } |
141 } |
141 } else { |
142 } else { |
142 opt.state &= ~QStyle::State_Sunken; |
143 opt.state &= ~QStyle::State_Sunken; |
143 } |
144 } |
144 |
145 |
145 opt.boundingRect=boundingRect(); |
146 opt.boundingRect=boundingRect(); |
146 sliderControl->style()->updatePrimitive(gItem, HbStyle::P_Slider_thumb, &opt); |
147 HbStylePrivate::updatePrimitive(gItem, HbStylePrivate::P_Slider_thumb, &opt); |
147 } |
148 } |
148 |
149 |
149 void HbSliderHandle::setHandleItem(QGraphicsItem *item) |
150 void HbSliderHandle::setHandleItem(QGraphicsItem *item) |
150 { |
151 { |
151 if(!item) { |
152 if(!item) { |
158 |
159 |
159 setHandlesChildEvents(false); |
160 setHandlesChildEvents(false); |
160 |
161 |
161 mHandleItem = item; |
162 mHandleItem = item; |
162 mHandleItem->setParentItem(this); |
163 mHandleItem->setParentItem(this); |
163 sliderControl->style()->setItemName(mHandleItem,"widget"); |
164 HbStyle::setItemName(mHandleItem,"widget"); |
164 //((QGraphicsWidget*)mHandleItem)->setGeometry(gItem->geometry());//TODO:geometry from css |
165 //((QGraphicsWidget*)mHandleItem)->setGeometry(gItem->geometry());//TODO:geometry from css |
165 |
166 |
166 if(scene()) { |
167 if(scene()) { |
167 mHandleItem->removeSceneEventFilter(this); |
168 mHandleItem->removeSceneEventFilter(this); |
168 mHandleItem->installSceneEventFilter(this); |
169 mHandleItem->installSceneEventFilter(this); |
412 HbEffect::start(gItem, HB_SLIDERHANDLE_TYPE, "h_outofbound"); |
413 HbEffect::start(gItem, HB_SLIDERHANDLE_TYPE, "h_outofbound"); |
413 } |
414 } |
414 #endif |
415 #endif |
415 sliderBounds.adjust(0, 0, -handleBounds.width(), 0); |
416 sliderBounds.adjust(0, 0, -handleBounds.width(), 0); |
416 span = sliderBounds.width(); |
417 span = sliderBounds.width(); |
417 sliderPos = relativePos.rx(); |
418 sliderPos = static_cast<int>(relativePos.x()); |
418 sliderPos-=handleBounds.width()/2; |
419 sliderPos-= static_cast<int>(handleBounds.width()/2); |
419 } else { |
420 } else { |
420 #ifdef HB_EFFECTS |
421 #ifdef HB_EFFECTS |
421 if( sliderBounds.topLeft().y() > relativePos.ry() || |
422 if( sliderBounds.topLeft().y() > relativePos.ry() || |
422 sliderBounds.bottomRight().y() < relativePos.ry()) { |
423 sliderBounds.bottomRight().y() < relativePos.ry()) { |
423 HbEffect::start(gItem, HB_SLIDERHANDLE_TYPE, "v_outofbound"); |
424 HbEffect::start(gItem, HB_SLIDERHANDLE_TYPE, "v_outofbound"); |
424 } |
425 } |
425 #endif |
426 #endif |
426 sliderBounds.adjust(0, 0, 0, -handleBounds.height()); |
427 sliderBounds.adjust(0, 0, 0, -handleBounds.height()); |
427 span = sliderBounds.height(); |
428 span = sliderBounds.height(); |
428 sliderPos = relativePos.ry(); |
429 sliderPos = static_cast<int>(relativePos.y()); |
429 sliderPos -= handleBounds.height() / 2; |
430 sliderPos -= static_cast<int>(handleBounds.height()/2); |
430 |
431 |
431 } |
432 } |
432 int pressValue= QStyle::sliderValueFromPosition(opt.minimum, opt.maximum, |
433 int pressValue= QStyle::sliderValueFromPosition(opt.minimum, opt.maximum, |
433 sliderPos, static_cast<int>(span),opt.upsideDown); |
434 sliderPos, static_cast<int>(span),opt.upsideDown); |
434 sliderControl->setSliderPosition(pressValue); |
435 sliderControl->setSliderPosition(pressValue); |
472 HbStyleOptionSlider opt; |
473 HbStyleOptionSlider opt; |
473 sliderControl->initStyleOption(&opt); |
474 sliderControl->initStyleOption(&opt); |
474 if( scene()){ |
475 if( scene()){ |
475 if (true == sliderControl->isSliderDown()){ |
476 if (true == sliderControl->isSliderDown()){ |
476 opt.state |= QStyle::State_Sunken; |
477 opt.state |= QStyle::State_Sunken; |
477 sliderControl->style()->updatePrimitive( |
478 HbStylePrivate::updatePrimitive( |
478 sliderControl->primitive(HbStyle::P_Slider_groove), HbStyle::P_Slider_groove, &opt); |
479 sliderControl->primitive((HbStyle::Primitive)HbStylePrivate::P_Slider_groove), HbStylePrivate::P_Slider_groove, &opt); |
479 } else { |
480 } else { |
480 opt.state &= ~QStyle::State_Sunken; |
481 opt.state &= ~QStyle::State_Sunken; |
481 } |
482 } |
482 } else { |
483 } else { |
483 opt.state &= ~QStyle::State_Sunken; |
484 opt.state &= ~QStyle::State_Sunken; |
484 } |
485 } |
485 |
486 |
486 opt.boundingRect=boundingRect(); |
487 opt.boundingRect=boundingRect(); |
487 sliderControl->style()->updatePrimitive(gItem, HbStyle::P_Slider_thumb, &opt); |
488 HbStylePrivate::updatePrimitive(gItem, HbStylePrivate::P_Slider_thumb, &opt); |
488 sliderControl->style()->updatePrimitive(touchItem , HbStyle::P_SliderElement_touchhandle ,&opt); |
489 HbStylePrivate::updatePrimitive(touchItem , HbStylePrivate::P_SliderElement_touchhandle ,&opt); |
489 sliderControl->update(boundingRect()); |
490 sliderControl->update(boundingRect()); |
490 } |
491 } |
491 |
492 |
492 /*! |
493 /*! |
493 reimp |
494 reimp |
494 |
495 |
495 */ |
496 */ |
496 QGraphicsItem * HbSliderHandle::primitive(HbStyle::Primitive primitive) const |
497 QGraphicsItem * HbSliderHandle::primitive(HbStyle::Primitive primitive) const |
497 { |
498 { |
498 switch (primitive) { |
499 switch (primitive) { |
499 case HbStyle::P_Slider_thumb: |
500 case HbStylePrivate::P_Slider_thumb: |
500 return gItem; |
501 return gItem; |
501 case HbStyle::P_SliderElement_touchhandle: |
502 case HbStylePrivate::P_SliderElement_touchhandle: |
502 return touchItem; |
503 return touchItem; |
503 default: |
504 default: |
504 return NULL; |
505 return NULL; |
505 } |
506 } |
506 } |
507 } |