132 << HbSlider::DecreaseElement |
140 << HbSlider::DecreaseElement |
133 << HbSlider::IconElement; |
141 << HbSlider::IconElement; |
134 if( currentValueVisible ) |
142 if( currentValueVisible ) |
135 elements<<HbSlider::TextElement; |
143 elements<<HbSlider::TextElement; |
136 setElements( elements ); |
144 setElements( elements ); |
|
145 #ifdef HB_GESTURE_FW |
|
146 q->grabGesture(Qt::TapGesture); |
|
147 #endif |
137 // create element because HbSlider will not create element for NULL Icon |
148 // create element because HbSlider will not create element for NULL Icon |
138 // and volume slider Icon is set in style |
149 // and volume slider Icon is set in style |
139 if ( !elementItemMap.contains(HbSlider::IncreaseElement) ) { |
150 if ( !elementItemMap.contains(HbSlider::IncreaseElement) ) { |
140 elementItemMap [HbSlider::IncreaseElement].item = |
151 elementItemMap [HbSlider::IncreaseElement].item = |
141 q->style( )->createPrimitive( HbStyle::P_SliderElement_increase, q); |
152 HbStylePrivate::createPrimitive( HbStylePrivate::P_SliderElement_increase, q); |
142 HbStyle::setItemName( elementItemMap [HbSlider::IncreaseElement].item, "increment-icon" ); |
153 HbStyle::setItemName( elementItemMap [HbSlider::IncreaseElement].item, "increment-icon" ); |
143 elementItemMap[HbSlider::IncreaseElement].type = HbStyle::P_SliderElement_increase; |
154 elementItemMap[HbSlider::IncreaseElement].type = HbStylePrivate::P_SliderElement_increase; |
144 elementItemMap [HbSlider::IncreaseElement].touchItem = q->style( )->createPrimitive( HbStyle::P_SliderElement_touchincrease, q ); |
155 elementItemMap [HbSlider::IncreaseElement].touchItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_SliderElement_touchincrease, q ); |
145 // create touch area for increment |
156 // create touch area for increment |
146 HbStyle::setItemName( elementItemMap [HbSlider::IncreaseElement].touchItem, "increment-icon-toucharea" ); |
157 HbStyle::setItemName( elementItemMap [HbSlider::IncreaseElement].touchItem, "increment-icon-toucharea" ); |
147 } |
158 } |
148 |
159 |
149 if ( !elementItemMap.contains(HbSlider::DecreaseElement) ) { |
160 if ( !elementItemMap.contains(HbSlider::DecreaseElement) ) { |
150 elementItemMap[HbSlider::DecreaseElement].item = |
161 elementItemMap[HbSlider::DecreaseElement].item = |
151 q->style( )->createPrimitive( HbStyle::P_SliderElement_decrease, q ); |
162 HbStylePrivate::createPrimitive( HbStylePrivate::P_SliderElement_decrease, q ); |
152 elementItemMap[HbSlider::DecreaseElement].type = HbStyle::P_SliderElement_decrease; |
163 elementItemMap[HbSlider::DecreaseElement].type = HbStylePrivate::P_SliderElement_decrease; |
153 HbStyle::setItemName( elementItemMap[HbSlider::DecreaseElement].item, "decrement-icon" ); |
164 HbStyle::setItemName( elementItemMap[HbSlider::DecreaseElement].item, "decrement-icon" ); |
154 |
165 |
155 // create touch area for decrement |
166 // create touch area for decrement |
156 elementItemMap[HbSlider::DecreaseElement].touchItem = q->style( )->createPrimitive( HbStyle::P_SliderElement_touchdecrease, q ) ; |
167 elementItemMap[HbSlider::DecreaseElement].touchItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_SliderElement_touchdecrease, q ) ; |
157 HbStyle::setItemName( elementItemMap[HbSlider::DecreaseElement].touchItem, "decrement-icon-toucharea" ); |
168 HbStyle::setItemName( elementItemMap[HbSlider::DecreaseElement].touchItem, "decrement-icon-toucharea" ); |
158 } |
169 } |
159 if( !elementItemMap.contains(HbSlider::IconElement) ) { |
170 if( !elementItemMap.contains(HbSlider::IconElement) ) { |
160 elementItemMap[HbSlider::IconElement].item = q->style( )->createPrimitive( HbStyle::P_SliderElement_icon,q ); |
171 elementItemMap[HbSlider::IconElement].item = HbStylePrivate::createPrimitive( HbStylePrivate::P_SliderElement_icon,q ); |
161 elementItemMap[HbSlider::IconElement].type = HbStyle::P_SliderElement_icon; |
172 elementItemMap[HbSlider::IconElement].type = HbStylePrivate::P_SliderElement_icon; |
162 HbStyle::setItemName( elementItemMap[HbSlider::IconElement].item, "icon-icon" ); |
173 HbStyle::setItemName( elementItemMap[HbSlider::IconElement].item, "icon-icon" ); |
163 // creating a dummy button , because slider icon |
174 // creating a dummy button , because slider icon |
164 // need to emit all signal which is emitted by button |
175 // need to emit all signal which is emitted by button |
165 // there is no need for touch item for slider icon because |
176 // there is no need for touch item for slider icon because |
166 // button can act as touch area |
177 // button can act as touch area |
179 } |
190 } |
180 |
191 |
181 HbStyleOptionSlider option; |
192 HbStyleOptionSlider option; |
182 q->initStyleOption( &option ); |
193 q->initStyleOption( &option ); |
183 option.sliderElementIcon = icons.value( HbSlider::IncreaseElement ); |
194 option.sliderElementIcon = icons.value( HbSlider::IncreaseElement ); |
184 q->style( )->updatePrimitive( elementItemMap [HbSlider::IncreaseElement].item,HbStyle::P_SliderElement_increase,&option ); |
195 HbStylePrivate::updatePrimitive( elementItemMap [HbSlider::IncreaseElement].item,HbStylePrivate::P_SliderElement_increase,&option ); |
185 option.sliderElementIcon = icons.value( HbSlider::DecreaseElement ); |
196 option.sliderElementIcon = icons.value( HbSlider::DecreaseElement ); |
186 q->style( )->updatePrimitive( elementItemMap[HbSlider::DecreaseElement].item,HbStyle::P_SliderElement_decrease,&option ); |
197 HbStylePrivate::updatePrimitive( elementItemMap[HbSlider::DecreaseElement].item,HbStylePrivate::P_SliderElement_decrease,&option ); |
187 option.sliderElementIcon = icons.value( HbSlider::IconElement ); |
198 option.sliderElementIcon = icons.value( HbSlider::IconElement ); |
188 q->style( )->updatePrimitive( elementItemMap[HbSlider::IconElement].item,elementItemMap[HbSlider::IconElement].type,&option ); |
199 HbStylePrivate::updatePrimitive( elementItemMap[HbSlider::IconElement].item,elementItemMap[HbSlider::IconElement].type,&option ); |
189 q->setIconCheckable( true ); |
200 q->setIconCheckable( true ); |
190 q->setFlags( QGraphicsItem::ItemIsFocusable ); |
201 q->setFlags( QGraphicsItem::ItemIsFocusable ); |
191 q->setProperty("changeincrementState" ,false); |
202 q->setProperty("changeincrementState" ,false); |
192 q->setProperty("changedecrementState" ,false); |
203 q->setProperty("changedecrementState" ,false); |
193 q->setProperty("state", "normal"); |
204 q->setProperty("state", "normal"); |
242 q->setValue( previousValue ); |
253 q->setValue( previousValue ); |
243 } |
254 } |
244 option.state&= ~( QStyle::State_Sunken ); |
255 option.state&= ~( QStyle::State_Sunken ); |
245 } |
256 } |
246 option.sliderElementIcon = icons.value( HbSlider::IconElement ); |
257 option.sliderElementIcon = icons.value( HbSlider::IconElement ); |
247 q->style( )->updatePrimitive( elementItemMap[HbSlider::IconElement].item,HbStyle::P_SliderElement_icon,&option ); |
258 HbStylePrivate::updatePrimitive( elementItemMap[HbSlider::IconElement].item,HbStylePrivate::P_SliderElement_icon,&option ); |
248 q->setProperty("changeincrementState" ,false); |
259 q->setProperty("changeincrementState" ,false); |
249 q->setProperty("changedecrementState" ,false); |
260 q->setProperty("changedecrementState" ,false); |
250 q->setProperty("state", "normal"); |
261 q->setProperty("state", "normal"); |
251 |
262 if ( q->value( ) == q->minimum( ) && !q->isIconChecked( ) ) { |
|
263 q->setIconChecked ( true); |
|
264 } |
252 } |
265 } |
253 |
266 |
254 |
267 |
255 /*! |
268 /*! |
256 The orientation is \b Qt::Vertical and the slider contains increase, track, |
269 The orientation is \b Qt::Vertical and the slider contains increase, track, |
345 unmute the volume to previous store value in case unmute happens |
358 unmute the volume to previous store value in case unmute happens |
346 by clicking increment/decrement icon |
359 by clicking increment/decrement icon |
347 */ |
360 */ |
348 void HbVolumeSlider::mousePressEvent( QGraphicsSceneMouseEvent *event ) |
361 void HbVolumeSlider::mousePressEvent( QGraphicsSceneMouseEvent *event ) |
349 { |
362 { |
|
363 |
|
364 #ifndef HB_GESTURE_FW |
350 Q_D( HbVolumeSlider ); |
365 Q_D( HbVolumeSlider ); |
351 if( d->elementItemMap.contains(HbSlider::IncreaseElement) ) { |
366 if( d->elementItemMap.contains(HbSlider::IncreaseElement) ) { |
352 if ( d->elementItemMap[HbSlider::IncreaseElement].touchItem->isUnderMouse( ) ) { |
367 if ( d->elementItemMap[HbSlider::IncreaseElement].touchItem->isUnderMouse( ) ) { |
353 d->pressOnIncrement = true; |
368 d->pressOnIncrement = true; |
354 HbWidgetFeedback::triggered( d->sliderControl, Hb::InstantPressed, Hb::ModifierSliderElement ); |
369 HbWidgetFeedback::triggered( d->sliderControl, Hb::InstantPressed, Hb::ModifierSliderElement ); |
392 setProperty("state", "pressed"); |
407 setProperty("state", "pressed"); |
393 return; |
408 return; |
394 } |
409 } |
395 } |
410 } |
396 HbSlider::mousePressEvent( event ); |
411 HbSlider::mousePressEvent( event ); |
|
412 #else |
|
413 Q_UNUSED(event) |
|
414 #endif |
397 } |
415 } |
398 |
416 |
399 /*! |
417 /*! |
400 \reimp |
418 \reimp |
401 stop the timer and change image for increment element /decrement element |
419 stop the timer and change image for increment element /decrement element |
402 */ |
420 */ |
403 void HbVolumeSlider::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) |
421 void HbVolumeSlider::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) |
404 { |
422 { |
|
423 #ifndef HB_GESTURE_FW |
405 Q_D( HbVolumeSlider ); |
424 Q_D( HbVolumeSlider ); |
406 HbSlider::mouseReleaseEvent( event ); |
425 HbSlider::mouseReleaseEvent( event ); |
407 d->stopRepeatAction( ); |
426 d->stopRepeatAction( ); |
408 setProperty("changeincrementState" ,false); |
427 setProperty("changeincrementState" ,false); |
409 setProperty("changedecrementState" ,false); |
428 setProperty("changedecrementState" ,false); |
410 setProperty("state", "normal"); |
429 setProperty("state", "normal"); |
|
430 #else |
|
431 Q_UNUSED(event) |
|
432 #endif |
411 } |
433 } |
412 |
434 |
413 /*! |
435 /*! |
414 \reimp |
436 \reimp |
415 */ |
437 */ |
451 { |
473 { |
452 Q_D( HbVolumeSlider ); |
474 Q_D( HbVolumeSlider ); |
453 d->sliderControl->setFocus( ); |
475 d->sliderControl->setFocus( ); |
454 } |
476 } |
455 |
477 |
|
478 /*! |
|
479 \reimp |
|
480 */ |
|
481 void HbVolumeSlider::gestureEvent(QGestureEvent *event) |
|
482 { |
|
483 Q_D(HbVolumeSlider); |
|
484 //consume the event if gesture is on increment or decrement, |
|
485 //if the slide ris muted and then on pressing on icrement/decrement value consider previous value as well |
|
486 if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) { |
|
487 QPointF pos = event->mapToGraphicsScene(tap->position()); |
|
488 bool consumeEvent = false; |
|
489 switch( tap->state( ) ) { |
|
490 case Qt::GestureStarted: { |
|
491 if ( d->elementItemMap.contains (HbSlider::IncreaseElement ) ) { |
|
492 if (d->elementItemMap[HbSlider::IncreaseElement].touchItem ) { |
|
493 if (d->elementItemMap[HbSlider::IncreaseElement].touchItem->sceneBoundingRect().contains(pos)) { |
|
494 consumeEvent = true; |
|
495 d->pressOnIncrement = true; |
|
496 HbWidgetFeedback::triggered( d->sliderControl, Hb::InstantPressed, Hb::ModifierSliderElement ); |
|
497 event->accept( ); |
|
498 // if volume was mute |
|
499 if( isIconChecked( ) ){ |
|
500 // take to previous value and increase one step |
|
501 setValue( d->previousValue+singleStep( ) ); |
|
502 // start timer for repeat action |
|
503 d->sliderControl->setRepeatAction( |
|
504 HbAbstractSliderControl::SliderSingleStepAdd, d->sliderControl->maximum( ) ); |
|
505 } else {// simply increase by one step |
|
506 d->startIncrementing( ); |
|
507 } |
|
508 setProperty("changeincrementState" ,true); |
|
509 setProperty("changedecrementState" ,false); |
|
510 setProperty("state", "pressed"); |
|
511 } |
|
512 } |
|
513 } |
|
514 if ( d->elementItemMap.contains (HbSlider::DecreaseElement ) ) { |
|
515 if (d->elementItemMap[HbSlider::DecreaseElement].touchItem ) { |
|
516 if (d->elementItemMap[HbSlider::DecreaseElement].touchItem->sceneBoundingRect().contains(pos)) { |
|
517 consumeEvent = true; |
|
518 d->pressOnIncrement = false; |
|
519 HbWidgetFeedback::triggered( d->sliderControl, Hb::InstantPressed, Hb::ModifierSliderElement ); |
|
520 event->accept( ); |
|
521 if( isIconChecked( ) ){ |
|
522 //set value to previous value and decrement by one step |
|
523 setValue( d->previousValue-singleStep( ) ); |
|
524 if( value( )==minimum( ) ){ |
|
525 d->previousValue = value( ); |
|
526 setIconEnabled( false ); |
|
527 } |
|
528 //start timer for repeat action |
|
529 d->sliderControl->setRepeatAction( |
|
530 HbAbstractSliderControl::SliderSingleStepSub, d->sliderControl->minimum( ) ); |
|
531 } else { |
|
532 d->startDecrementing( ); |
|
533 } |
|
534 setProperty("changeincrementState" ,false); |
|
535 setProperty("changedecrementState" ,true); |
|
536 setProperty("state", "pressed"); |
|
537 |
|
538 } |
|
539 } |
|
540 } |
|
541 } |
|
542 break; |
|
543 case Qt::GestureCanceled: |
|
544 case Qt::GestureFinished: |
|
545 setProperty("changeincrementState" ,false); |
|
546 setProperty("changedecrementState" ,false); |
|
547 setProperty("state", "normal"); |
|
548 consumeEvent = true; |
|
549 HbSlider::gestureEvent(event); |
|
550 break; |
|
551 default: |
|
552 break; |
|
553 } |
|
554 if(!consumeEvent) { |
|
555 event->ignore(); |
|
556 HbSlider::gestureEvent(event); |
|
557 } |
|
558 |
|
559 |
|
560 } |
|
561 |
|
562 } |
|
563 |
456 #include "moc_hbvolumeslider_p.cpp" |
564 #include "moc_hbvolumeslider_p.cpp" |
457 |
565 |
458 |
566 |
459 |
567 |