168 mFlags &= ~HbProgressSliderHandle::MousePressed; |
169 mFlags &= ~HbProgressSliderHandle::MousePressed; |
169 mFlags &=~HandleMoving; |
170 mFlags &=~HandleMoving; |
170 event->accept(); |
171 event->accept(); |
171 setHandlePosForValue(q->progressValue()); |
172 setHandlePosForValue(q->progressValue()); |
172 q->emitSliderReleased(); |
173 q->emitSliderReleased(); |
173 } |
174 #else |
174 |
175 Q_UNUSED(event) |
175 void HbProgressSliderHandle::handleTrackRelease(QGraphicsSceneMouseEvent * event) |
176 #endif |
176 { |
|
177 Q_UNUSED(event); |
|
178 setHandlePosForValue(q->progressValue()); |
|
179 } |
|
180 |
|
181 void HbProgressSliderHandle::handleTrackPress(QGraphicsSceneMouseEvent * event) |
|
182 { |
|
183 QPointF newPos = q->parentGraphicsItem()->mapFromScene(event->scenePos()); |
|
184 if((newPos.x() >= q->boundingRect().x()) && (newPos.x() <= q->boundingRect().width())) { |
|
185 if(q->orientation() == Qt::Horizontal){ |
|
186 mItemCurPos = QPointF(newPos.x() - boundingRect().width()/2, pos().y()); |
|
187 } |
|
188 else{ |
|
189 mItemCurPos = QPointF(pos().x(), newPos.y()-boundingRect().height()/2); |
|
190 } |
|
191 |
|
192 mItemCurPos = normalizedPos(mItemCurPos,false); |
|
193 setPos(mItemCurPos); |
|
194 processItemChange(mItemCurPos); |
|
195 } |
|
196 } |
177 } |
197 |
178 |
198 void HbProgressSliderHandle::mouseMoveEvent ( QGraphicsSceneMouseEvent * event ) |
179 void HbProgressSliderHandle::mouseMoveEvent ( QGraphicsSceneMouseEvent * event ) |
199 { |
180 { |
|
181 #ifndef HB_GESTURE_FW |
200 HbWidget::mouseMoveEvent(event); |
182 HbWidget::mouseMoveEvent(event); |
201 mFlags |=HandleMoving; |
183 mFlags |=HandleMoving; |
202 QPointF scenePos = event->scenePos(); |
184 QPointF scenePos = event->scenePos(); |
203 if(q->orientation() == Qt::Horizontal){ |
185 if(q->orientation() == Qt::Horizontal){ |
204 mItemCurPos = QPointF((event->scenePos().x() - mMousePressPos.x()) + mItemPosAtPress.x(), pos().y()); |
186 mItemCurPos = QPointF((event->scenePos().x() - mMousePressPos.x()) + mItemPosAtPress.x(), pos().y()); |
239 HbExtendedLocale locale; |
221 HbExtendedLocale locale; |
240 HbProgressSlider *slider = (HbProgressSlider*)q->parentGraphicsWidget(); |
222 HbProgressSlider *slider = (HbProgressSlider*)q->parentGraphicsWidget(); |
241 HbToolTip::showText(locale.toString(slider->sliderValue()),this, QRectF(mItemCurPos,QSize(0,0)),q->textAlignment()); |
223 HbToolTip::showText(locale.toString(slider->sliderValue()),this, QRectF(mItemCurPos,QSize(0,0)),q->textAlignment()); |
242 |
224 |
243 } |
225 } |
|
226 #else |
|
227 Q_UNUSED(event) |
|
228 #endif |
|
229 } |
|
230 |
|
231 void HbProgressSliderHandle::handleTrackRelease(QGestureEvent *event) |
|
232 { |
|
233 Q_UNUSED(event); |
|
234 setHandlePosForValue(q->progressValue()); |
|
235 } |
|
236 |
|
237 void HbProgressSliderHandle::handleTrackPress(QGestureEvent *event) |
|
238 { |
|
239 HbTapGesture *gesture = static_cast<HbTapGesture *>(event->gesture(Qt::TapGesture)); |
|
240 QPointF newPos = q->parentGraphicsItem()->mapFromScene(event->mapToGraphicsScene(gesture->position())); |
|
241 |
|
242 //QPointF newPos = q->parentGraphicsItem()->mapFromScene(event->scenePos()); |
|
243 if((newPos.x() >= q->boundingRect().x()) && (newPos.x() <= q->boundingRect().width())) { |
|
244 if(q->orientation() == Qt::Horizontal){ |
|
245 mItemCurPos = QPointF(newPos.x() - boundingRect().width()/2, pos().y()); |
|
246 } |
|
247 else{ |
|
248 mItemCurPos = QPointF(pos().x(), newPos.y()-boundingRect().height()/2); |
|
249 } |
|
250 |
|
251 mItemCurPos = normalizedPos(mItemCurPos,false); |
|
252 setPos(mItemCurPos); |
|
253 processItemChange(mItemCurPos); |
|
254 } |
|
255 } |
|
256 |
|
257 |
|
258 /*! |
|
259 reimp |
|
260 |
|
261 */ |
|
262 void HbProgressSliderHandle::gestureEvent(QGestureEvent *event) |
|
263 { |
|
264 if(HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) { |
|
265 switch(tap->state()) { |
|
266 case Qt::GestureStarted: { |
|
267 mMousePressPos = mapFromScene(event->mapToGraphicsScene(tap->position( ))); |
|
268 if(q->textVisible()) { // User called it |
|
269 if(!q->toolTipText().isNull()) { |
|
270 HbToolTip::showText(q->toolTipText(),this, QRectF(mMousePressPos,QSize(0,0)),q->textAlignment()); |
|
271 } |
|
272 } |
|
273 else { // show default |
|
274 HbExtendedLocale locale; |
|
275 HbProgressSlider *slider = (HbProgressSlider*)q->parentGraphicsWidget(); |
|
276 HbToolTip::showText(locale.toString(slider->sliderValue()),this, QRectF(mMousePressPos,QSize(0,0)),q->textAlignment()); |
|
277 } |
|
278 #ifdef HB_EFFECTS |
|
279 HbEffect::start(this, HB_PRGRESSSLIDERHANDLE_ITEM_TYPE, "progressslider_handlepress"); |
|
280 #endif |
|
281 mFlags |= HbProgressSliderHandle::MousePressed; |
|
282 HbStyleOptionProgressSliderHandle option; |
|
283 initStyleOption(&option); |
|
284 option.pressedState = true; |
|
285 if (mHandleIconItem) { |
|
286 HbStylePrivate::updatePrimitive(mHandleIconItem, HbStylePrivate::P_ProgressSliderHandle_icon, &option); |
|
287 } |
|
288 mMousePressPos = mapFromScene(event->mapToGraphicsScene(tap->position( ))); |
|
289 HbWidgetFeedback::triggered(q->parentGraphicsWidget(), Hb::InstantPressed, Hb::ModifierSliderHandle); |
|
290 event->accept(); |
|
291 |
|
292 q->emitSliderPressed(); |
|
293 } |
|
294 break; |
|
295 case Qt::GestureFinished:{ |
|
296 HbStyleOptionProgressSliderHandle option; |
|
297 initStyleOption(&option); |
|
298 option.pressedState = false; |
|
299 if (mHandleIconItem) { |
|
300 HbStylePrivate::updatePrimitive(mHandleIconItem, HbStylePrivate::P_ProgressSliderHandle_icon, &option); |
|
301 } |
|
302 if (isHandleMoving()) { |
|
303 HbWidgetFeedback::continuousStopped(q->parentGraphicsWidget(), Hb::ContinuousDragged); |
|
304 } |
|
305 HbWidgetFeedback::triggered(q->parentGraphicsWidget(), Hb::InstantReleased, Hb::ModifierSliderHandle); |
|
306 #ifdef HB_EFFECTS |
|
307 HbEffect::start(this, HB_PRGRESSSLIDERHANDLE_ITEM_TYPE, "progressslider_handlerelease"); |
|
308 #endif |
|
309 mFlags &= ~HbProgressSliderHandle::MousePressed; |
|
310 mFlags &=~HandleMoving; |
|
311 event->accept(); |
|
312 setHandlePosForValue(q->progressValue()); |
|
313 q->emitSliderReleased(); |
|
314 } |
|
315 break; |
|
316 default: |
|
317 break; |
|
318 } |
|
319 } |
|
320 if (HbPanGesture *panGesture = qobject_cast<HbPanGesture*>(event->gesture(Qt::PanGesture))) { |
|
321 switch(panGesture->state( )) { |
|
322 case Qt::GestureStarted: |
|
323 case Qt::GestureUpdated:{ |
|
324 mFlags |=HandleMoving; |
|
325 QPointF scenePos =mapToParent( mapFromScene(panGesture->sceneOffset( )+panGesture->sceneStartPos( ))); |
|
326 if(scenePos.x() == oldCord.x()) { |
|
327 return; |
|
328 } |
|
329 oldCord = scenePos; |
|
330 //if(q->orientation() == Qt::Horizontal){ |
|
331 mItemCurPos = QPointF((scenePos.x() - mMousePressPos.x()), pos().y()); |
|
332 HbWidgetFeedback::continuousTriggered(qobject_cast<HbWidget*>(q->parentGraphicsWidget()), Hb::ContinuousDragged); |
|
333 if(mItemCurPos.x()+boundingRect().width() < q->boundingRect().width() && mItemCurPos.x()>q->boundingRect().topLeft().x() ){ |
|
334 setPos(mItemCurPos); |
|
335 //} |
|
336 //else{ |
|
337 // processItemChange(mItemCurPos); |
|
338 //} |
|
339 } |
|
340 if (!mTouchItem->boundingRect().contains(parentItem()->mapFromScene(scenePos))) { |
|
341 #ifdef HB_EFFECTS |
|
342 HbEffect::start(this, HB_PRGRESSSLIDERHANDLE_ITEM_TYPE, "progressslider_handleoutofbound"); |
|
343 #endif |
|
344 } |
|
345 event->accept(); |
|
346 if(q->textVisible()) { // User called it |
|
347 if(q->toolTipText().isNull()) { |
|
348 // Dont show any tooltip. |
|
349 } |
|
350 else { |
|
351 HbToolTip::showText(q->toolTipText(),this, QRectF(mItemCurPos,QSize(0,0)),q->textAlignment()); |
|
352 } |
|
353 } |
|
354 else { // show default |
|
355 HbExtendedLocale locale; |
|
356 HbProgressSlider *slider = (HbProgressSlider*)q->parentGraphicsWidget(); |
|
357 HbToolTip::showText(locale.toString(slider->sliderValue()),this, QRectF(mItemCurPos,QSize(0,0)),q->textAlignment()); |
|
358 } |
|
359 q->emitSliderMoved(pointToValue(mItemCurPos)); |
|
360 } |
|
361 break; |
|
362 case Qt::GestureFinished: |
|
363 case Qt::GestureCanceled: { |
|
364 HbStyleOptionProgressSliderHandle option; |
|
365 option.pressedState = false; |
|
366 initStyleOption(&option); |
|
367 if (mHandleIconItem) { |
|
368 HbStylePrivate::updatePrimitive(mHandleIconItem, HbStylePrivate::P_ProgressSliderHandle_icon, &option); |
|
369 } |
|
370 if (isHandleMoving()) { |
|
371 HbWidgetFeedback::continuousStopped(q->parentGraphicsWidget(), Hb::ContinuousDragged); |
|
372 } |
|
373 else { |
|
374 HbWidgetFeedback::triggered(q->parentGraphicsWidget(), Hb::InstantReleased, Hb::ModifierSliderHandle); |
|
375 } |
|
376 #ifdef HB_EFFECTS |
|
377 HbEffect::start(this, HB_PRGRESSSLIDERHANDLE_ITEM_TYPE, "progressslider_handlerelease"); |
|
378 #endif |
|
379 mFlags &= ~HbProgressSliderHandle::MousePressed; |
|
380 mFlags &=~HandleMoving; |
|
381 event->accept(); |
|
382 setHandlePosForValue(q->progressValue()); |
|
383 q->emitSliderReleased(); |
|
384 } |
|
385 break; |
|
386 default: |
|
387 break; |
|
388 } |
|
389 } |
|
390 |
244 } |
391 } |
245 |
392 |
246 int HbProgressSliderHandle::pointToValue(QPointF point) const |
393 int HbProgressSliderHandle::pointToValue(QPointF point) const |
247 { |
394 { |
248 QRectF rect = q->boundingRect(); |
395 QRectF rect = q->boundingRect(); |
249 qreal effectiveWidth; |
396 qreal effectiveWidth; |
250 point = normalizedPos(point,q->invertedAppearance()); |
397 point = normalizedPos(point,q->invertedAppearance()); |
251 qreal givenPixel; |
398 qreal givenPixel; |
252 if(q->orientation() == Qt::Horizontal){ |
399 |
253 effectiveWidth = rect.width() - boundingRect().width(); |
400 effectiveWidth = rect.width() - boundingRect().width(); |
254 givenPixel = point.x(); |
401 givenPixel = point.x(); |
255 } |
402 |
256 else{ |
|
257 effectiveWidth = rect.height() - boundingRect().height(); |
|
258 givenPixel = effectiveWidth-point.y(); |
|
259 } |
|
260 |
|
261 qreal tickPerPixel = (qreal)(q->maximum()-q->minimum())/effectiveWidth; |
403 qreal tickPerPixel = (qreal)(q->maximum()-q->minimum())/effectiveWidth; |
262 qreal tickForGivenPixel = givenPixel * tickPerPixel; |
404 qreal tickForGivenPixel = givenPixel * tickPerPixel; |
263 tickForGivenPixel = qRound(tickForGivenPixel); |
405 tickForGivenPixel = qRound(tickForGivenPixel); |
264 |
406 |
265 int value; |
407 int value; |
283 { |
425 { |
284 QRectF r1 = q->boundingRect(); |
426 QRectF r1 = q->boundingRect(); |
285 QRectF r2 = boundingRect(); |
427 QRectF r2 = boundingRect(); |
286 |
428 |
287 qreal width; |
429 qreal width; |
288 if(q->orientation()== Qt::Horizontal){ |
430 width = r1.width() - r2.width(); |
289 width = r1.width() - r2.width(); |
|
290 |
|
291 } |
|
292 else{ |
|
293 width = r1.height() - r2.height(); |
|
294 |
|
295 } |
|
296 if(q->maximum() != q->minimum()){ |
431 if(q->maximum() != q->minimum()){ |
297 qreal pixelpertick = width/(qreal)(q->maximum()-q->minimum()); |
432 qreal pixelpertick = width/(qreal)(q->maximum()-q->minimum()); |
298 qreal noOfTicks = qreal(value - q->minimum()); |
433 qreal noOfTicks = qreal(value - q->minimum()); |
299 qreal xpos = noOfTicks * pixelpertick; |
434 qreal xpos = noOfTicks * pixelpertick; |
300 if(q->orientation() == Qt::Horizontal){ |
435 return QPointF(xpos, r1.top()); |
301 return QPointF(xpos, r1.top()); |
|
302 } |
|
303 else{ |
|
304 return QPointF(r1.left(),width-xpos); |
|
305 } |
|
306 } |
436 } |
307 else{ |
437 else{ |
308 return QPointF(0,0); |
438 return QPointF(0,0); |
309 } |
439 } |
310 } |
440 } |
311 |
441 |
312 QPointF HbProgressSliderHandle::normalizedPos(const QPointF& pos,bool inverted) const |
442 QPointF HbProgressSliderHandle::normalizedPos(const QPointF& pos,bool inverted) const |
313 { |
443 { |
314 Q_UNUSED(inverted); |
444 Q_UNUSED(inverted); |
|
445 |
315 QPointF newPos = pos; |
446 QPointF newPos = pos; |
316 if(q->orientation() == Qt::Horizontal){ |
447 |
317 if (newPos.x() < HandleMargin) { |
448 if (newPos.x() < HandleMargin) { |
318 newPos.setX( HandleMargin ); |
449 newPos.setX( HandleMargin ); |
319 } |
450 } |
320 |
451 |
321 if (newPos.x() > q->boundingRect().width() - boundingRect().width() - HandleMargin) { |
452 if (newPos.x() > q->boundingRect().width() - boundingRect().width() - HandleMargin) { |
322 newPos.setX(q->boundingRect().width() - boundingRect().width() - HandleMargin); |
453 newPos.setX(q->boundingRect().width() - boundingRect().width() - HandleMargin); |
323 } |
454 } |
324 } |
455 |
325 else{ |
|
326 if (newPos.y() < HandleMargin) { |
|
327 newPos.setY( HandleMargin ); |
|
328 } |
|
329 |
|
330 if (newPos.y() > q->boundingRect().height() - boundingRect().height() - HandleMargin) { |
|
331 newPos.setY(q->boundingRect().height() - boundingRect().height() - HandleMargin); |
|
332 } |
|
333 } |
|
334 return newPos; |
456 return newPos; |
335 } |
457 } |
336 |
458 |
337 bool HbProgressSliderHandle::isHandlePressed() const |
459 bool HbProgressSliderHandle::isHandlePressed() const |
338 { |
460 { |