src/hbcore/gui/hbtoolbutton.cpp
changeset 6 c3690ec91ef8
parent 2 06ff229162e9
child 7 923ff622b8b9
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    40 
    40 
    41 #include "hbglobal_p.h" // remove when removing HB_DEPRECATED
    41 #include "hbglobal_p.h" // remove when removing HB_DEPRECATED
    42 
    42 
    43 #include <QGraphicsSceneHelpEvent>
    43 #include <QGraphicsSceneHelpEvent>
    44 #include <QGraphicsSceneMouseEvent>
    44 #include <QGraphicsSceneMouseEvent>
       
    45 #include <QCoreApplication>
    45 
    46 
    46 /*!
    47 /*!
    47     @stable
    48     @stable
    48     @hbcore
    49     @hbcore
    49     \class HbToolButton
    50     \class HbToolButton
   117 
   118 
   118 /*!
   119 /*!
   119     \reimp
   120     \reimp
   120     \fn int HbToolButton::type() const
   121     \fn int HbToolButton::type() const
   121  */
   122  */
       
   123 
       
   124 /*!
       
   125   \primitives
       
   126   \primitive{background} HbFrameItem representing the background frame of the button.
       
   127   \primitive{icon} HbIconItem representing the icon of the button.
       
   128   \primitive{text} HbTextItem representing button text.
       
   129   */
   122 
   130 
   123 HbToolButtonPrivate::HbToolButtonPrivate() :
   131 HbToolButtonPrivate::HbToolButtonPrivate() :
   124     action(0),
   132     action(0),
   125     textItem(0),
   133     textItem(0),
   126     iconItem(0),
   134     iconItem(0),
   244 }
   252 }
   245 
   253 
   246 void HbToolButtonPrivate::_q_actionTriggered()
   254 void HbToolButtonPrivate::_q_actionTriggered()
   247 {
   255 {
   248     Q_Q(HbToolButton);
   256     Q_Q(HbToolButton);
   249     emit q->triggered(action);
   257     // Only emit triggered signal for HbActions, not QActions.
       
   258     // triggered(QAction*) requires an API change we don't want to do right now.
       
   259     HbAction *hbAction = qobject_cast<HbAction *>(action);
       
   260     if (hbAction)
       
   261         emit q->triggered(hbAction);
   250 }
   262 }
   251 
   263 
   252 void HbToolButtonPrivate::_q_actionChanged()
   264 void HbToolButtonPrivate::_q_actionChanged()
   253 {
   265 {
   254     Q_Q(HbToolButton);
   266     Q_Q(HbToolButton);
   255     if (!action->icon().isNull()) {
   267     HbAction *hbAction = qobject_cast<HbAction *>(action);
       
   268     if ((hbAction && !hbAction->icon().isNull()) || !action->icon().isNull()) {
   256         if (orientation == Qt::Horizontal) {
   269         if (orientation == Qt::Horizontal) {
   257             buttonStyle = HbToolButton::ToolButtonIcon;
   270             buttonStyle = HbToolButton::ToolButtonIcon;
   258         } else if (!action->text().isEmpty()) {
   271         } else if (!action->text().isEmpty()) {
   259             buttonStyle = HbToolButton::ToolButtonTextAndIcon;
   272             buttonStyle = HbToolButton::ToolButtonTextAndIcon;
   260         } else {
   273         } else {
   263     } else {
   276     } else {
   264         buttonStyle = HbToolButton::ToolButtonText;
   277         buttonStyle = HbToolButton::ToolButtonText;
   265     }
   278     }
   266     // action text/icon may have changed,            
   279     // action text/icon may have changed,            
   267     if (polished) {
   280     if (polished) {
   268         q->repolish();
   281         q->repolish();        
       
   282         QCoreApplication::sendPostedEvents(q, QEvent::Polish);
   269     }
   283     }
   270 }
   284 }
   271 
   285 
   272 void HbToolButtonPrivate::showToolTip()
   286 void HbToolButtonPrivate::showToolTip()
   273 {
   287 {
   312     \sa setAction()
   326     \sa setAction()
   313  */
   327  */
   314 HbAction *HbToolButton::action() const
   328 HbAction *HbToolButton::action() const
   315 {
   329 {
   316     Q_D(const HbToolButton);
   330     Q_D(const HbToolButton);
   317     return d->action;
   331     return qobject_cast<HbAction *>(d->action);
   318 }
   332 }
   319 
   333 
   320 /*!
   334 /*!
   321     Sets the \a action of the button.
   335     Sets the \a action of the button.
   322 
   336 
   334     if (d->action) {
   348     if (d->action) {
   335         disconnect(d->action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
   349         disconnect(d->action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
   336         disconnect(d->action, SIGNAL(changed()), this, SLOT(_q_actionChanged()));
   350         disconnect(d->action, SIGNAL(changed()), this, SLOT(_q_actionChanged()));
   337     }
   351     }
   338 
   352 
   339     HbAction *oldAction = d->action;
   353     QAction *oldAction = d->action;
   340     d->action = action;
   354     d->action = action;
   341     if (d->action) {
   355     if (d->action) {
   342         connect(action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
   356         connect(action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
   343         connect(action, SIGNAL(changed()), this, SLOT(_q_actionChanged()));
   357         connect(action, SIGNAL(changed()), this, SLOT(_q_actionChanged()));
   344     }
   358     }
   478     if (d->textItem) {
   492     if (d->textItem) {
   479         style()->updatePrimitive(d->textItem, HbStyle::P_ToolButton_text, &option);
   493         style()->updatePrimitive(d->textItem, HbStyle::P_ToolButton_text, &option);
   480     }
   494     }
   481     if (d->iconItem) {
   495     if (d->iconItem) {
   482         style()->updatePrimitive(d->iconItem, HbStyle::P_ToolButton_icon, &option);
   496         style()->updatePrimitive(d->iconItem, HbStyle::P_ToolButton_icon, &option);
   483         if (d->action && d->action->icon().flags() & HbIcon::Colorized) {
   497         HbAction *hbAction = qobject_cast<HbAction *>(d->action);
   484             static_cast<HbIconItem *>(d->iconItem)->setFlags(HbIcon::Colorized);            
   498         if (hbAction) {
   485         }
   499             if (hbAction->icon().flags() & HbIcon::Colorized) {
   486         if (d->action && d->action->icon().mirroringMode() != HbIcon::Default) {
   500                 static_cast<HbIconItem *>(d->iconItem)->setFlags(HbIcon::Colorized);
   487             HbIconItem *iconItem = static_cast<HbIconItem *>(d->iconItem);
   501             }
   488             iconItem->setMirroringMode( d->action->icon().mirroringMode() );
   502             if (hbAction->icon().mirroringMode() != HbIcon::Default) {
   489         }
   503                 HbIconItem *iconItem = static_cast<HbIconItem *>(d->iconItem);
   490 
   504                 iconItem->setMirroringMode( hbAction->icon().mirroringMode() );
       
   505             }
       
   506         }
   491 
   507 
   492     }
   508     }
   493 }
   509 }
   494 
   510 
   495 /*!
   511 /*!
   516         }
   532         }
   517     }
   533     }
   518 
   534 
   519     if (d->action) {
   535     if (d->action) {
   520         option->text = d->action->text();
   536         option->text = d->action->text();
   521         option->icon = d->action->icon();        
   537         HbAction *hbAction = qobject_cast<HbAction*>(d->action);
       
   538         if (hbAction)
       
   539             option->icon = hbAction->icon();
       
   540         else
       
   541             option->icon = d->action->icon();
       
   542 
   522         option->isToolBarExtension = d->toolbarExtensionFrame;
   543         option->isToolBarExtension = d->toolbarExtensionFrame;
   523     }
   544     }
   524 }
   545 }
   525 
   546 
   526 /*!
   547 /*!
   539     Q_D(HbToolButton);
   560     Q_D(HbToolButton);
   540     QGraphicsWidget::resizeEvent(event);
   561     QGraphicsWidget::resizeEvent(event);
   541     if (event->newSize() !=  event->oldSize() && d->polished && isVisible()) {
   562     if (event->newSize() !=  event->oldSize() && d->polished && isVisible()) {
   542         updatePrimitives();
   563         updatePrimitives();
   543     }
   564     }
   544     if (action() && action()->toolBarExtension()) {
   565     HbAction *hbAction = qobject_cast<HbAction *>(d->action);
   545         HbToolBarExtensionPrivate::d_ptr(action()->toolBarExtension())->placeToolBarExtension();
   566     if ( hbAction && hbAction->toolBarExtension()) {
       
   567         HbToolBarExtensionPrivate::d_ptr(hbAction->toolBarExtension())->placeToolBarExtension();
   546     }
   568     }
   547 }
   569 }
   548 
   570 
   549 /*!
   571 /*!
   550     \reimp
   572     \reimp
   554     Q_D(HbToolButton);
   576     Q_D(HbToolButton);
   555     HbAbstractButton::nextCheckState();
   577     HbAbstractButton::nextCheckState();
   556     if (!d->action) {
   578     if (!d->action) {
   557         return;
   579         return;
   558     }
   580     }
   559     if ( d->action->toolBarExtension() ) {
   581     HbAction *hbAction = qobject_cast<HbAction *>(d->action);
   560         HbToolBarExtensionPrivate::d_ptr(d->action->toolBarExtension())->mExtendedButton = this;
   582     if ( hbAction && hbAction->toolBarExtension() ) {
   561         d->action->toolBarExtension()->show();
   583         HbToolBarExtensionPrivate::d_ptr(hbAction->toolBarExtension())->mExtendedButton = this;
       
   584         hbAction->toolBarExtension()->show();
   562     }
   585     }
   563 
   586 
   564     d->action->trigger();
   587     d->action->trigger();
   565 }
   588 }
   566 
   589