src/hbcore/decorators/hbtitlepane.cpp
changeset 28 b7da29130b0e
parent 23 e6ad4ef83b23
child 30 80e4d18b72f5
equal deleted inserted replaced
23:e6ad4ef83b23 28:b7da29130b0e
    52     The HbTitlePane class represents title pane on each application. It provides an interface for
    52     The HbTitlePane class represents title pane on each application. It provides an interface for
    53     setting text, font alignment and options menu.
    53     setting text, font alignment and options menu.
    54 */
    54 */
    55 
    55 
    56 HbTitlePanePrivate::HbTitlePanePrivate() :
    56 HbTitlePanePrivate::HbTitlePanePrivate() :
    57     mText(), mTextItem(0), mToggled(false), mIcon(0), mMode(QIcon::Normal), mTouchArea(0),
    57     mText(), mTextItem(0), mIcon(0), mMode(QIcon::Normal), mTouchArea(0), mMargueeAnimation(false),
    58     mMargueeAnimation(false)
    58     mTapStarted(false), mSwipeStarted(false)
    59 {
    59 {
    60 
    60 
    61 }
    61 }
    62 
    62 
    63 void HbTitlePanePrivate::delayedConstruction()
    63 void HbTitlePanePrivate::delayedConstruction()
    69     Q_Q(HbTitlePane);
    69     Q_Q(HbTitlePane);
    70 
    70 
    71     createPrimitives();
    71     createPrimitives();
    72     q->setAcceptedMouseButtons(Qt::LeftButton);
    72     q->setAcceptedMouseButtons(Qt::LeftButton);
    73     q->setText(HbApplication::applicationName());
    73     q->setText(HbApplication::applicationName());
    74 }
       
    75 
       
    76 void HbTitlePanePrivate::toggle(bool on)
       
    77 {
       
    78     mToggled = on;
       
    79 }
    74 }
    80 
    75 
    81 void HbTitlePanePrivate::createPrimitives()
    76 void HbTitlePanePrivate::createPrimitives()
    82 {
    77 {
    83     Q_Q(HbTitlePane);
    78     Q_Q(HbTitlePane);
   100     HbStylePrivate::updatePrimitive(mTextItem, HbStylePrivate::P_TitlePane_text, &option);
    95     HbStylePrivate::updatePrimitive(mTextItem, HbStylePrivate::P_TitlePane_text, &option);
   101     HbStylePrivate::updatePrimitive(mIcon, HbStylePrivate::P_TitlePane_icon, &option);
    96     HbStylePrivate::updatePrimitive(mIcon, HbStylePrivate::P_TitlePane_icon, &option);
   102     HbStylePrivate::updatePrimitive(mTouchArea, HbStylePrivate::P_TitlePane_toucharea, &option);
    97     HbStylePrivate::updatePrimitive(mTouchArea, HbStylePrivate::P_TitlePane_toucharea, &option);
   103 }
    98 }
   104 
    99 
       
   100 void HbTitlePanePrivate::handleTap(HbTapGesture *tap)
       
   101 {
       
   102     Q_Q(HbTitlePane);
       
   103     switch (tap->state()) {
       
   104     case Qt::GestureStarted:
       
   105         if (q->scene()) {
       
   106             q->scene()->setProperty(HbPrivate::OverridingGesture.latin1(), Qt::TapGesture);
       
   107             tap->setProperty(HbPrivate::ThresholdRect.latin1(), q->mapRectToScene(q->boundingRect()).toRect());
       
   108         }
       
   109         mMode = QIcon::Active;
       
   110         updatePrimitives();
       
   111 #ifdef HB_EFFECTS
       
   112         HbEffect::start(q, "decorator", "pressed");
       
   113 #endif
       
   114         HbWidgetFeedback::triggered(q, Hb::InstantPressed);
       
   115         mTapStarted = true;
       
   116         break;
       
   117 
       
   118     case Qt::GestureCanceled: 
       
   119         cancelTap();
       
   120         break;
       
   121 
       
   122     case Qt::GestureFinished: {
       
   123         if (q->scene()) {
       
   124             q->scene()->setProperty(HbPrivate::OverridingGesture.latin1(), QVariant());
       
   125         }
       
   126         mMode = QIcon::Selected;
       
   127         updatePrimitives();
       
   128 #ifdef HB_EFFECTS
       
   129         HbEffect::start(q, "decorator", "latched");
       
   130 #endif
       
   131         HbWidgetFeedback::triggered(q, Hb::InstantReleased);
       
   132         QPointF launchPos(q->scenePos().x() + q->boundingRect().width() / 2 + 3, 
       
   133                           q->scenePos().y() + q->boundingRect().height());
       
   134         emit q->launchPopup(launchPos);
       
   135         mTapStarted = false;
       
   136         break;
       
   137     }
       
   138     default:
       
   139         mTapStarted = false;
       
   140         break;
       
   141     }
       
   142 }
       
   143 
       
   144 void HbTitlePanePrivate::handleSwipe(HbSwipeGesture *swipe)
       
   145 {
       
   146     Q_Q(HbTitlePane);
       
   147     HbWidgetFeedback::triggered(q, Hb::InstantFlicked);
       
   148 
       
   149     switch (swipe->state()) {
       
   150     case Qt::GestureStarted:
       
   151         mSwipeStarted = true;
       
   152         break;
       
   153 
       
   154     case (Qt::GestureFinished):
       
   155         if (swipe->sceneHorizontalDirection() == QSwipeGesture::Right) {
       
   156             emit q->swipeRight();
       
   157         } else if (swipe->sceneHorizontalDirection() == QSwipeGesture::Left) {
       
   158             emit q->swipeLeft();
       
   159         }
       
   160 
       
   161         if (mMode != QIcon::Normal) {
       
   162             mMode = QIcon::Normal;
       
   163             updatePrimitives();
       
   164         }
       
   165         mSwipeStarted = false;
       
   166         break;
       
   167 
       
   168     default:
       
   169         mSwipeStarted = false;
       
   170         break;
       
   171     }
       
   172 }
       
   173 
       
   174 void HbTitlePanePrivate::cancelTap()
       
   175 {
       
   176     Q_Q(HbTitlePane);
       
   177 
       
   178     if (q->scene()) {
       
   179         q->scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
       
   180     }
       
   181     HbWidgetFeedback::triggered(q, Hb::InstantReleased);
       
   182 
       
   183     if (mMode != QIcon::Normal) {
       
   184         mMode = QIcon::Normal;
       
   185         updatePrimitives();
       
   186     }
       
   187     mTapStarted = false;
       
   188 }
       
   189 
   105 // ======== MEMBER FUNCTIONS ========
   190 // ======== MEMBER FUNCTIONS ========
   106 
   191 
   107 /*
   192 /*
   108     Constructs a vertical title pane with \a parent.
   193     Constructs a vertical title pane with \a parent.
   109  */
   194  */
   111 HbTitlePane::HbTitlePane(QGraphicsItem *parent)
   196 HbTitlePane::HbTitlePane(QGraphicsItem *parent)
   112     : HbWidget(*new HbTitlePanePrivate, parent)
   197     : HbWidget(*new HbTitlePanePrivate, parent)
   113 {
   198 {
   114     Q_D(HbTitlePane);
   199     Q_D(HbTitlePane);
   115     d->init();
   200     d->init();
       
   201     setFlag(QGraphicsItem::ItemHasNoContents, true);
   116 }
   202 }
   117 
   203 
   118 HbTitlePane::HbTitlePane(HbTitlePanePrivate &dd, QGraphicsItem *parent)
   204 HbTitlePane::HbTitlePane(HbTitlePanePrivate &dd, QGraphicsItem *parent)
   119     : HbWidget(dd, parent)
   205     : HbWidget(dd, parent)
   120 {
   206 {
   121     Q_D(HbTitlePane);
   207     Q_D(HbTitlePane);
   122     d->init();
   208     d->init();
       
   209     setFlag(QGraphicsItem::ItemHasNoContents, true);
   123 }
   210 }
   124 
   211 
   125 /*
   212 /*
   126     Destructor
   213     Destructor
   127  */
   214  */
   215 }
   302 }
   216 
   303 
   217 void HbTitlePane::gestureEvent(QGestureEvent *event)
   304 void HbTitlePane::gestureEvent(QGestureEvent *event)
   218 {
   305 {
   219     Q_D(HbTitlePane);
   306     Q_D(HbTitlePane);
   220 
       
   221     if (mainWindow() && mainWindow()->currentView()) {
   307     if (mainWindow() && mainWindow()->currentView()) {
   222         if (mainWindow()->currentView()->menu()->isEmpty()) {
   308         if (mainWindow()->currentView()->menu()->isEmpty()) {
   223             return;
   309             return;
   224         }
   310         }
   225     }
   311     }
   226 
   312 
   227     HbTapGesture *tap = qobject_cast<HbTapGesture*>(event->gesture(Qt::TapGesture));
   313     HbTapGesture *tap = qobject_cast<HbTapGesture*>(event->gesture(Qt::TapGesture));
   228     HbSwipeGesture *swipe = qobject_cast<HbSwipeGesture*>(event->gesture(Qt::SwipeGesture));
   314     HbSwipeGesture *swipe = qobject_cast<HbSwipeGesture*>(event->gesture(Qt::SwipeGesture));
   229 
   315 
   230     if (tap) {
   316     if (tap) {
   231         switch(tap->state()) {
   317         if (!(d->mSwipeStarted && tap->state() == Qt::GestureFinished)) {
   232         case Qt::GestureStarted: {
   318             d->handleTap(tap);
   233                 if (scene()) {
   319         }
   234                     scene()->setProperty(HbPrivate::OverridingGesture.latin1(),Qt::TapGesture);
   320     }
   235                     tap->setProperty(HbPrivate::ThresholdRect.latin1(), mapRectToScene(boundingRect()).toRect());
   321     if (swipe) {
   236                 }
   322         if (swipe->state() == Qt::GestureStarted && d->mTapStarted) {
   237                 d->mMode = QIcon::Active;
   323              d->cancelTap();
   238                 updatePrimitives();
   324         }
   239 #ifdef HB_EFFECTS
   325         d->handleSwipe(swipe);
   240                 HbEffect::start(this, "decorator", "pressed");
       
   241 #endif
       
   242                 HbWidgetFeedback::triggered(this, Hb::InstantPressed);
       
   243                 d->toggle(true);
       
   244                 break;
       
   245             }
       
   246         case Qt::GestureCanceled: {
       
   247                 if (scene()) {
       
   248                     scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
       
   249                 }
       
   250                 HbWidgetFeedback::triggered(this, Hb::InstantReleased);
       
   251 
       
   252                 if (d->mMode != QIcon::Normal) {
       
   253                     d->mMode = QIcon::Normal;
       
   254                     updatePrimitives();
       
   255                 }
       
   256                 d->toggle(false);
       
   257 
       
   258                 break;
       
   259             }
       
   260         case Qt::GestureFinished: {
       
   261                 if (scene()) {
       
   262                     scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
       
   263                 }
       
   264                 d->mMode = QIcon::Selected;
       
   265                 updatePrimitives();
       
   266 #ifdef HB_EFFECTS
       
   267                 HbEffect::start(this, "decorator", "latched");
       
   268 #endif
       
   269                 if (d->mToggled) {
       
   270                     HbWidgetFeedback::triggered(this, Hb::InstantReleased);
       
   271                 }
       
   272                 HbWidgetFeedback::triggered(this, Hb::InstantClicked);
       
   273                 QPointF launchPos(scenePos().x() + boundingRect().width() / 2 + 3, scenePos().y() + boundingRect().height());
       
   274                 emit launchPopup(launchPos);
       
   275                 break;
       
   276             }
       
   277         default:
       
   278             break;
       
   279         }
       
   280     } else if(swipe) {
       
   281         HbWidgetFeedback::triggered(this, Hb::InstantFlicked);
       
   282 
       
   283         switch (swipe->state()) {
       
   284         case (Qt::GestureFinished): {
       
   285                 if(swipe->sceneHorizontalDirection() == QSwipeGesture::Right) {
       
   286                     emit swipeRight();
       
   287                 } else if(swipe->sceneHorizontalDirection() == QSwipeGesture::Left) {
       
   288                     emit swipeLeft();
       
   289                 }
       
   290 
       
   291                 if(d->mMode != QIcon::Normal) {
       
   292                     d->toggle(false);
       
   293                     d->mMode = QIcon::Normal;
       
   294                     updatePrimitives();
       
   295                 }
       
   296                 break;
       
   297             }
       
   298         default:
       
   299             break;
       
   300         }
       
   301     }
   326     }
   302 }
   327 }
   303 
   328 
   304 /*
   329 /*
   305     \reimp
   330     \reimp