369 } |
376 } |
370 |
377 |
371 /*! |
378 /*! |
372 \reimp |
379 \reimp |
373 */ |
380 */ |
374 void HbToolBar::gestureEvent(QGestureEvent *event) |
381 void HbToolBar::gestureEvent(QGestureEvent *) |
375 { |
382 { |
376 Q_D(HbToolBar); |
383 |
377 if (QPanGesture *panGesture = qobject_cast<QPanGesture*>(event->gesture(Qt::PanGesture))) { |
384 } |
378 QPointF scenePoint = event->mapToGraphicsScene(panGesture->hotSpot()); |
385 |
379 if (panGesture->state() == Qt::GestureStarted) { |
386 void HbToolBar::updatePrimitives() |
380 foreach (HbToolButton *button, d->mVisibleToolButtons) { |
387 { |
381 if (button->isDown()) { |
388 Q_D(HbToolBar); |
382 d->mPressedDownButton = button; |
389 for (int i = 0; i < d->mVisibleToolButtons.count(); i++) { |
383 break; |
390 d->mVisibleToolButtons.at(i)->updatePrimitives(); |
384 } |
391 } |
385 } |
392 if (d->moreExtensionButton) { |
386 if (d->moreExtensionButton && d->moreExtensionButton->isDown()) { |
393 d->moreExtensionButton->updatePrimitives(); |
387 d->mPressedDownButton = d->moreExtensionButton; |
|
388 } |
|
389 } else if (panGesture->state() == Qt::GestureUpdated) { |
|
390 if (mapRectToScene(boundingRect()).contains(scenePoint)) { |
|
391 // moving inside the tool bar |
|
392 if (!d->mPressedDownButton || |
|
393 !mapRectToScene(d->mPressedDownButton->geometry()).contains(scenePoint)) { |
|
394 if (d->mPressedDownButton) { |
|
395 // lift it up and try to find some other button |
|
396 d->mPressedDownButton->setDown(false); |
|
397 d->mPreviouslyPressedDownButton = d->mPressedDownButton; |
|
398 d->mPressedDownButton = 0; |
|
399 } |
|
400 |
|
401 // Find the pressed button |
|
402 foreach (HbToolButton *button, d->mVisibleToolButtons) { |
|
403 if (button->action()->isEnabled() && |
|
404 mapRectToScene(button->geometry()).contains(scenePoint)) { |
|
405 d->mPressedDownButton = button; |
|
406 HbWidgetFeedback::triggered(button, Hb::InstantDraggedOver); |
|
407 button->setDown(true); |
|
408 break; |
|
409 } |
|
410 } |
|
411 if (d->moreExtensionButton && d->moreExtensionButton->isVisible() && |
|
412 mapRectToScene(d->moreExtensionButton->geometry()).contains(scenePoint)) { |
|
413 d->mPressedDownButton = d->moreExtensionButton; |
|
414 HbWidgetFeedback::triggered(d->moreExtensionButton, Hb::InstantDraggedOver); |
|
415 d->moreExtensionButton->setDown(true); |
|
416 } |
|
417 } |
|
418 } else { |
|
419 // moving outside the tool bar |
|
420 |
|
421 // if a button is pressed down, lift it. |
|
422 if (d->mPressedDownButton) { |
|
423 d->mPressedDownButton->setDown(false); |
|
424 d->mPressedDownButton = 0; |
|
425 d->mPreviouslyPressedDownButton = d->mPressedDownButton; |
|
426 } |
|
427 } |
|
428 } else if (panGesture->state() == Qt::GestureFinished) { |
|
429 if (d->mPressedDownButton && !d->mPreviouslyPressedDownButton) { |
|
430 // Generate tap gesture to the button |
|
431 QGesture *gesture = new QTapGesture(); |
|
432 gesture->setHotSpot(panGesture->hotSpot()); |
|
433 QList<QGesture *> list; |
|
434 list.append(gesture); |
|
435 QGestureEvent *event = new QGestureEvent(list); |
|
436 QCoreApplication::sendEvent(d->mPressedDownButton, event); |
|
437 d->mPressedDownButton = 0; |
|
438 } else if (d->mPressedDownButton) { |
|
439 d->mPressedDownButton->setDown(false); |
|
440 HbWidgetFeedback::triggered( d->mPressedDownButton, Hb::InstantClicked ); |
|
441 } |
|
442 d->mPreviouslyPressedDownButton = 0; |
|
443 } |
|
444 event->accept(panGesture); |
|
445 } else { |
|
446 event->ignore(); |
|
447 } |
394 } |
448 } |
395 } |
449 |
396 |
450 #include "moc_hbtoolbar.cpp" |
397 #include "moc_hbtoolbar.cpp" |