src/hbcore/gui/hbtoolbutton.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 7 923ff622b8b9
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
9:730c025d4b77 15:f378acbc9cfb
    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),
   233 QSizeF HbToolButtonPrivate::getMinimumSize()
   241 QSizeF HbToolButtonPrivate::getMinimumSize()
   234 {
   242 {
   235     Q_Q(HbToolButton);
   243     Q_Q(HbToolButton);
   236     mRepolishRequested = true;
   244     mRepolishRequested = true;
   237     polishPending = false;
   245     polishPending = false;
   238     q->updateGeometry();
       
   239     QSizeF size = q->minimumSize();
       
   240     //Workaround (causing extra polish)
   246     //Workaround (causing extra polish)
   241     mSizeHintPolish = false;
   247     mSizeHintPolish = false;
   242     //workaround ends
   248     //workaround ends
       
   249     q->updateGeometry();
       
   250     QCoreApplication::sendPostedEvents(q, QEvent::LayoutRequest);
       
   251     QSizeF size = q->minimumSize();
   243     return size;
   252     return size;
   244 }
   253 }
   245 
   254 
   246 void HbToolButtonPrivate::_q_actionTriggered()
   255 void HbToolButtonPrivate::_q_actionTriggered()
   247 {
   256 {
   248     Q_Q(HbToolButton);
   257     Q_Q(HbToolButton);
   249     emit q->triggered(action);
   258     // Only emit triggered signal for HbActions, not QActions.
       
   259     // triggered(QAction*) requires an API change we don't want to do right now.
       
   260     HbAction *hbAction = qobject_cast<HbAction *>(action);
       
   261     if (hbAction)
       
   262         emit q->triggered(hbAction);
   250 }
   263 }
   251 
   264 
   252 void HbToolButtonPrivate::_q_actionChanged()
   265 void HbToolButtonPrivate::_q_actionChanged()
   253 {
   266 {
   254     Q_Q(HbToolButton);
   267     Q_Q(HbToolButton);
   255     if (!action->icon().isNull()) {
   268     HbAction *hbAction = qobject_cast<HbAction *>(action);
       
   269     if ((hbAction && !hbAction->icon().isNull()) || !action->icon().isNull()) {
   256         if (orientation == Qt::Horizontal) {
   270         if (orientation == Qt::Horizontal) {
   257             buttonStyle = HbToolButton::ToolButtonIcon;
   271             buttonStyle = HbToolButton::ToolButtonIcon;
   258         } else if (!action->text().isEmpty()) {
   272         } else if (!action->text().isEmpty()) {
   259             buttonStyle = HbToolButton::ToolButtonTextAndIcon;
   273             buttonStyle = HbToolButton::ToolButtonTextAndIcon;
   260         } else {
   274         } else {
   263     } else {
   277     } else {
   264         buttonStyle = HbToolButton::ToolButtonText;
   278         buttonStyle = HbToolButton::ToolButtonText;
   265     }
   279     }
   266     // action text/icon may have changed,            
   280     // action text/icon may have changed,            
   267     if (polished) {
   281     if (polished) {
   268         q->repolish();
   282         q->repolish();        
       
   283         QCoreApplication::sendPostedEvents(q, QEvent::Polish);
   269     }
   284     }
   270 }
   285 }
   271 
   286 
   272 void HbToolButtonPrivate::showToolTip()
   287 void HbToolButtonPrivate::showToolTip()
   273 {
   288 {
   312     \sa setAction()
   327     \sa setAction()
   313  */
   328  */
   314 HbAction *HbToolButton::action() const
   329 HbAction *HbToolButton::action() const
   315 {
   330 {
   316     Q_D(const HbToolButton);
   331     Q_D(const HbToolButton);
   317     return d->action;
   332     return qobject_cast<HbAction *>(d->action);
   318 }
   333 }
   319 
   334 
   320 /*!
   335 /*!
   321     Sets the \a action of the button.
   336     Sets the \a action of the button.
   322 
   337 
   334     if (d->action) {
   349     if (d->action) {
   335         disconnect(d->action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
   350         disconnect(d->action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
   336         disconnect(d->action, SIGNAL(changed()), this, SLOT(_q_actionChanged()));
   351         disconnect(d->action, SIGNAL(changed()), this, SLOT(_q_actionChanged()));
   337     }
   352     }
   338 
   353 
   339     HbAction *oldAction = d->action;
   354     QAction *oldAction = d->action;
   340     d->action = action;
   355     d->action = action;
   341     if (d->action) {
   356     if (d->action) {
   342         connect(action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
   357         connect(action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
   343         connect(action, SIGNAL(changed()), this, SLOT(_q_actionChanged()));
   358         connect(action, SIGNAL(changed()), this, SLOT(_q_actionChanged()));
   344     }
   359     }
   478     if (d->textItem) {
   493     if (d->textItem) {
   479         style()->updatePrimitive(d->textItem, HbStyle::P_ToolButton_text, &option);
   494         style()->updatePrimitive(d->textItem, HbStyle::P_ToolButton_text, &option);
   480     }
   495     }
   481     if (d->iconItem) {
   496     if (d->iconItem) {
   482         style()->updatePrimitive(d->iconItem, HbStyle::P_ToolButton_icon, &option);
   497         style()->updatePrimitive(d->iconItem, HbStyle::P_ToolButton_icon, &option);
   483         if (d->action && d->action->icon().flags() & HbIcon::Colorized) {
   498         HbAction *hbAction = qobject_cast<HbAction *>(d->action);
   484             static_cast<HbIconItem *>(d->iconItem)->setFlags(HbIcon::Colorized);            
   499         if (hbAction) {
   485         }
   500             if (hbAction->icon().flags() & HbIcon::Colorized) {
   486         if (d->action && d->action->icon().mirroringMode() != HbIcon::Default) {
   501                 static_cast<HbIconItem *>(d->iconItem)->setFlags(HbIcon::Colorized);
   487             HbIconItem *iconItem = static_cast<HbIconItem *>(d->iconItem);
   502             }
   488             iconItem->setMirroringMode( d->action->icon().mirroringMode() );
   503             if (hbAction->icon().mirroringMode() != HbIcon::Default) {
   489         }
   504                 HbIconItem *iconItem = static_cast<HbIconItem *>(d->iconItem);
   490 
   505                 iconItem->setMirroringMode( hbAction->icon().mirroringMode() );
       
   506             }
       
   507         }
   491 
   508 
   492     }
   509     }
   493 }
   510 }
   494 
   511 
   495 /*!
   512 /*!
   516         }
   533         }
   517     }
   534     }
   518 
   535 
   519     if (d->action) {
   536     if (d->action) {
   520         option->text = d->action->text();
   537         option->text = d->action->text();
   521         option->icon = d->action->icon();        
   538         HbAction *hbAction = qobject_cast<HbAction*>(d->action);
       
   539         if (hbAction)
       
   540             option->icon = hbAction->icon();
       
   541         else
       
   542             option->icon = d->action->icon();
       
   543 
   522         option->isToolBarExtension = d->toolbarExtensionFrame;
   544         option->isToolBarExtension = d->toolbarExtensionFrame;
   523     }
   545     }
   524 }
   546 }
   525 
   547 
   526 /*!
   548 /*!
   539     Q_D(HbToolButton);
   561     Q_D(HbToolButton);
   540     QGraphicsWidget::resizeEvent(event);
   562     QGraphicsWidget::resizeEvent(event);
   541     if (event->newSize() !=  event->oldSize() && d->polished && isVisible()) {
   563     if (event->newSize() !=  event->oldSize() && d->polished && isVisible()) {
   542         updatePrimitives();
   564         updatePrimitives();
   543     }
   565     }
   544     if (action() && action()->toolBarExtension()) {
   566     HbAction *hbAction = qobject_cast<HbAction *>(d->action);
   545         HbToolBarExtensionPrivate::d_ptr(action()->toolBarExtension())->placeToolBarExtension();
   567     if ( hbAction && hbAction->toolBarExtension()) {
       
   568         HbToolBarExtensionPrivate::d_ptr(hbAction->toolBarExtension())->placeToolBarExtension();
   546     }
   569     }
   547 }
   570 }
   548 
   571 
   549 /*!
   572 /*!
   550     \reimp
   573     \reimp
   554     Q_D(HbToolButton);
   577     Q_D(HbToolButton);
   555     HbAbstractButton::nextCheckState();
   578     HbAbstractButton::nextCheckState();
   556     if (!d->action) {
   579     if (!d->action) {
   557         return;
   580         return;
   558     }
   581     }
   559     if ( d->action->toolBarExtension() ) {
   582     HbAction *hbAction = qobject_cast<HbAction *>(d->action);
   560         HbToolBarExtensionPrivate::d_ptr(d->action->toolBarExtension())->mExtendedButton = this;
   583     if ( hbAction && hbAction->toolBarExtension() ) {
   561         d->action->toolBarExtension()->show();
   584         HbToolBarExtensionPrivate::d_ptr(hbAction->toolBarExtension())->mExtendedButton = this;
       
   585         hbAction->toolBarExtension()->show();
   562     }
   586     }
   563 
   587 
   564     d->action->trigger();
   588     d->action->trigger();
   565 }
   589 }
   566 
   590