src/hbcore/decorators/hbtitlepane.cpp
changeset 28 b7da29130b0e
parent 23 e6ad4ef83b23
child 30 80e4d18b72f5
--- a/src/hbcore/decorators/hbtitlepane.cpp	Thu Sep 02 20:44:51 2010 +0300
+++ b/src/hbcore/decorators/hbtitlepane.cpp	Fri Sep 17 08:32:10 2010 +0300
@@ -54,8 +54,8 @@
 */
 
 HbTitlePanePrivate::HbTitlePanePrivate() :
-    mText(), mTextItem(0), mToggled(false), mIcon(0), mMode(QIcon::Normal), mTouchArea(0),
-    mMargueeAnimation(false)
+    mText(), mTextItem(0), mIcon(0), mMode(QIcon::Normal), mTouchArea(0), mMargueeAnimation(false),
+    mTapStarted(false), mSwipeStarted(false)
 {
 
 }
@@ -73,11 +73,6 @@
     q->setText(HbApplication::applicationName());
 }
 
-void HbTitlePanePrivate::toggle(bool on)
-{
-    mToggled = on;
-}
-
 void HbTitlePanePrivate::createPrimitives()
 {
     Q_Q(HbTitlePane);
@@ -102,6 +97,96 @@
     HbStylePrivate::updatePrimitive(mTouchArea, HbStylePrivate::P_TitlePane_toucharea, &option);
 }
 
+void HbTitlePanePrivate::handleTap(HbTapGesture *tap)
+{
+    Q_Q(HbTitlePane);
+    switch (tap->state()) {
+    case Qt::GestureStarted:
+        if (q->scene()) {
+            q->scene()->setProperty(HbPrivate::OverridingGesture.latin1(), Qt::TapGesture);
+            tap->setProperty(HbPrivate::ThresholdRect.latin1(), q->mapRectToScene(q->boundingRect()).toRect());
+        }
+        mMode = QIcon::Active;
+        updatePrimitives();
+#ifdef HB_EFFECTS
+        HbEffect::start(q, "decorator", "pressed");
+#endif
+        HbWidgetFeedback::triggered(q, Hb::InstantPressed);
+        mTapStarted = true;
+        break;
+
+    case Qt::GestureCanceled: 
+        cancelTap();
+        break;
+
+    case Qt::GestureFinished: {
+        if (q->scene()) {
+            q->scene()->setProperty(HbPrivate::OverridingGesture.latin1(), QVariant());
+        }
+        mMode = QIcon::Selected;
+        updatePrimitives();
+#ifdef HB_EFFECTS
+        HbEffect::start(q, "decorator", "latched");
+#endif
+        HbWidgetFeedback::triggered(q, Hb::InstantReleased);
+        QPointF launchPos(q->scenePos().x() + q->boundingRect().width() / 2 + 3, 
+                          q->scenePos().y() + q->boundingRect().height());
+        emit q->launchPopup(launchPos);
+        mTapStarted = false;
+        break;
+    }
+    default:
+        mTapStarted = false;
+        break;
+    }
+}
+
+void HbTitlePanePrivate::handleSwipe(HbSwipeGesture *swipe)
+{
+    Q_Q(HbTitlePane);
+    HbWidgetFeedback::triggered(q, Hb::InstantFlicked);
+
+    switch (swipe->state()) {
+    case Qt::GestureStarted:
+        mSwipeStarted = true;
+        break;
+
+    case (Qt::GestureFinished):
+        if (swipe->sceneHorizontalDirection() == QSwipeGesture::Right) {
+            emit q->swipeRight();
+        } else if (swipe->sceneHorizontalDirection() == QSwipeGesture::Left) {
+            emit q->swipeLeft();
+        }
+
+        if (mMode != QIcon::Normal) {
+            mMode = QIcon::Normal;
+            updatePrimitives();
+        }
+        mSwipeStarted = false;
+        break;
+
+    default:
+        mSwipeStarted = false;
+        break;
+    }
+}
+
+void HbTitlePanePrivate::cancelTap()
+{
+    Q_Q(HbTitlePane);
+
+    if (q->scene()) {
+        q->scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
+    }
+    HbWidgetFeedback::triggered(q, Hb::InstantReleased);
+
+    if (mMode != QIcon::Normal) {
+        mMode = QIcon::Normal;
+        updatePrimitives();
+    }
+    mTapStarted = false;
+}
+
 // ======== MEMBER FUNCTIONS ========
 
 /*
@@ -113,6 +198,7 @@
 {
     Q_D(HbTitlePane);
     d->init();
+    setFlag(QGraphicsItem::ItemHasNoContents, true);
 }
 
 HbTitlePane::HbTitlePane(HbTitlePanePrivate &dd, QGraphicsItem *parent)
@@ -120,6 +206,7 @@
 {
     Q_D(HbTitlePane);
     d->init();
+    setFlag(QGraphicsItem::ItemHasNoContents, true);
 }
 
 /*
@@ -217,7 +304,6 @@
 void HbTitlePane::gestureEvent(QGestureEvent *event)
 {
     Q_D(HbTitlePane);
-
     if (mainWindow() && mainWindow()->currentView()) {
         if (mainWindow()->currentView()->menu()->isEmpty()) {
             return;
@@ -228,76 +314,15 @@
     HbSwipeGesture *swipe = qobject_cast<HbSwipeGesture*>(event->gesture(Qt::SwipeGesture));
 
     if (tap) {
-        switch(tap->state()) {
-        case Qt::GestureStarted: {
-                if (scene()) {
-                    scene()->setProperty(HbPrivate::OverridingGesture.latin1(),Qt::TapGesture);
-                    tap->setProperty(HbPrivate::ThresholdRect.latin1(), mapRectToScene(boundingRect()).toRect());
-                }
-                d->mMode = QIcon::Active;
-                updatePrimitives();
-#ifdef HB_EFFECTS
-                HbEffect::start(this, "decorator", "pressed");
-#endif
-                HbWidgetFeedback::triggered(this, Hb::InstantPressed);
-                d->toggle(true);
-                break;
-            }
-        case Qt::GestureCanceled: {
-                if (scene()) {
-                    scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
-                }
-                HbWidgetFeedback::triggered(this, Hb::InstantReleased);
-
-                if (d->mMode != QIcon::Normal) {
-                    d->mMode = QIcon::Normal;
-                    updatePrimitives();
-                }
-                d->toggle(false);
-
-                break;
-            }
-        case Qt::GestureFinished: {
-                if (scene()) {
-                    scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
-                }
-                d->mMode = QIcon::Selected;
-                updatePrimitives();
-#ifdef HB_EFFECTS
-                HbEffect::start(this, "decorator", "latched");
-#endif
-                if (d->mToggled) {
-                    HbWidgetFeedback::triggered(this, Hb::InstantReleased);
-                }
-                HbWidgetFeedback::triggered(this, Hb::InstantClicked);
-                QPointF launchPos(scenePos().x() + boundingRect().width() / 2 + 3, scenePos().y() + boundingRect().height());
-                emit launchPopup(launchPos);
-                break;
-            }
-        default:
-            break;
+        if (!(d->mSwipeStarted && tap->state() == Qt::GestureFinished)) {
+            d->handleTap(tap);
         }
-    } else if(swipe) {
-        HbWidgetFeedback::triggered(this, Hb::InstantFlicked);
-
-        switch (swipe->state()) {
-        case (Qt::GestureFinished): {
-                if(swipe->sceneHorizontalDirection() == QSwipeGesture::Right) {
-                    emit swipeRight();
-                } else if(swipe->sceneHorizontalDirection() == QSwipeGesture::Left) {
-                    emit swipeLeft();
-                }
-
-                if(d->mMode != QIcon::Normal) {
-                    d->toggle(false);
-                    d->mMode = QIcon::Normal;
-                    updatePrimitives();
-                }
-                break;
-            }
-        default:
-            break;
+    }
+    if (swipe) {
+        if (swipe->state() == Qt::GestureStarted && d->mTapStarted) {
+             d->cancelTap();
         }
+        d->handleSwipe(swipe);
     }
 }