src/hbcore/gui/hbtoolbar.cpp
changeset 1 f7ac710697a9
parent 0 16d8024aca5e
child 2 06ff229162e9
equal deleted inserted replaced
0:16d8024aca5e 1:f7ac710697a9
    47 #include <QDebug>
    47 #include <QDebug>
    48 #include <QGesture>
    48 #include <QGesture>
    49 
    49 
    50 #ifdef HB_EFFECTS
    50 #ifdef HB_EFFECTS
    51 #include "hbeffectinternal_p.h"
    51 #include "hbeffectinternal_p.h"
    52 #define HB_TOOLBAR_ITEM_TYPE "HB_TOOLBAR"
       
    53 #endif
    52 #endif
    54 
    53 
    55 /*!
    54 /*!
    56     @stable
    55     @beta
    57     @hbcore
    56     @hbcore
    58     \class HbToolBar
    57     \class HbToolBar
    59     \brief HbToolBar is a toolbar decorator.
    58     \brief HbToolBar is a toolbar decorator.
    60 
    59 
    61     The HbToolBar class represents an HbView toolbar. It provides the interface for adding actions
    60     The HbToolBar class represents an HbView toolbar. It provides the interface for adding actions
    89     : HbWidget(*new HbToolBarPrivate, parent)
    88     : HbWidget(*new HbToolBarPrivate, parent)
    90 {
    89 {
    91     Q_D(HbToolBar);
    90     Q_D(HbToolBar);
    92     d->q_ptr = this;
    91     d->q_ptr = this;
    93     d->init();
    92     d->init();
       
    93     setFlag(QGraphicsItem::ItemIsPanel);
       
    94 
    94 }
    95 }
    95 
    96 
    96 /*!
    97 /*!
    97     Protected constructor.
    98     Protected constructor.
    98 */
    99 */
   231     d->setOrientation ( orientation );
   232     d->setOrientation ( orientation );
   232     d->minimumToolButtonSize = QSizeF();
   233     d->minimumToolButtonSize = QSizeF();
   233 }
   234 }
   234 
   235 
   235 /*!
   236 /*!
   236     \deprecated HbToolBar::unsetOrientation()is deprecated.
   237     \deprecated HbToolBar::unsetOrientation()
       
   238             is deprecated.
   237  */
   239  */
   238 void HbToolBar::unsetOrientation()
   240 void HbToolBar::unsetOrientation()
   239 {
   241 {
   240     //Q_D(HbToolBar);
   242     //Q_D(HbToolBar);
   241 
   243 
   308 {
   310 {
   309     Q_D(HbToolBar);
   311     Q_D(HbToolBar);
   310     if (event->type() == QEvent::LayoutDirectionChange) {
   312     if (event->type() == QEvent::LayoutDirectionChange) {
   311         d->updateToolBarExtensions();
   313         d->updateToolBarExtensions();
   312         d->updateButtonsLayoutDirection();
   314         d->updateButtonsLayoutDirection();
       
   315     }
       
   316 
       
   317     if (event->type() == QEvent::ParentChange && parentItem()) {
       
   318         setPos(-1000, -1000);   // Not very nice workaround to toolbar flicker problem.
       
   319                                 // We will find a better solution later.
   313     }
   320     }
   314 
   321 
   315     QGraphicsWidget::changeEvent(event);
   322     QGraphicsWidget::changeEvent(event);
   316 }
   323 }
   317 
   324 
   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"