diff -r 923ff622b8b9 -r 4633027730f5 src/hbcore/gui/hbtoolbutton.cpp --- a/src/hbcore/gui/hbtoolbutton.cpp Tue Jul 06 14:36:53 2010 +0300 +++ b/src/hbcore/gui/hbtoolbutton.cpp Wed Aug 18 10:05:37 2010 +0300 @@ -31,6 +31,7 @@ #include "hbtoolbarextension_p.h" #include "hbaction.h" #include "hbaction_p.h" +#include "hbstyle_p.h" #include #include "hbcolorscheme.h" #include "hbtextitem.h" @@ -64,9 +65,6 @@ construct tool buttons directly in the same way as any other widget, and arrange them alongside other widgets in layouts. - The style of a tool button is adjustable with setToolButtonStyle(). - By default a tool button shows only an icon. - A tool button's background is set as HbIcon. This makes it possible to specify different images for the normal and pressed states. @@ -81,36 +79,6 @@ */ /*! - \enum HbToolButton::ToolButtonStyle - \deprecated HbToolButton::ToolButtonStyle - - This enum defines available tool button styles. - - The tool button style describes how the button's text and icon should be displayed. - */ - -/*! - \var HbToolButton::ToolButtonIcon - \deprecated HbToolButton::ToolButtonIcon - - Only display the icon. - */ - -/*! - \var HbToolButton::ToolButtonText - \deprecated HbToolButton::ToolButtonText - - Only display the text. - */ - -/*! - \var HbToolButton::ToolButtonTextAndIcon - \deprecated HbToolButton::ToolButtonTextAndIcon - - Display both text and icon. - */ - -/*! \fn void HbToolButton::triggered(HbAction *action) This signal is emitted when the \a action is triggered. @@ -135,7 +103,6 @@ frameItem(0), customBackground(), backgroundVisible(true), - buttonStyle(HbToolButton::ToolButtonIcon), toolBarPosition(HbStyleOptionToolButton::TB_None), orientation(Qt::Vertical), mDialogToolBar(false), @@ -153,31 +120,18 @@ Q_Q(HbToolButton); if (backgroundVisible) { if (!frameItem){ - frameItem = q->style()->createPrimitive(HbStyle::P_ToolButton_frame, q); + frameItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_ToolButton_frame, q); } } else if (frameItem) { delete frameItem; frameItem = 0; } - - if (action && !action->text().isEmpty()) { - if (!textItem) { - textItem = static_cast(q->style()->createPrimitive(HbStyle::P_ToolButton_text, q)); - textItem->setTextWrapping(Hb::TextWordWrap); - } - textItem->setVisible(buttonStyle & HbToolButton::ToolButtonText); - } else if (textItem) { - delete textItem; - textItem = 0; - } - - if (action && (buttonStyle & HbToolButton::ToolButtonIcon)) { - if (!iconItem) { - iconItem = q->style()->createPrimitive(HbStyle::P_ToolButton_icon, q); - } - } else if (iconItem){ - delete iconItem; - iconItem = 0; + if (!textItem) { + textItem = static_cast(HbStylePrivate::createPrimitive(HbStylePrivate::P_ToolButton_text, q)); + textItem->setTextWrapping(Hb::TextWordWrap); + } // I dare you to optimize this + if (!iconItem) { + iconItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_ToolButton_icon, q); } } @@ -185,10 +139,8 @@ { if (this->orientation != orientation) { this->orientation = orientation; - Q_Q(HbToolButton); - if (q->isVisible() && polished) { - q->repolish(); - } + Q_Q(HbToolButton); + q->repolish(); } } @@ -233,9 +185,7 @@ { Q_Q(HbToolButton); q->setProperty(name, value); - if (q->isVisible() && polished) { - q->repolish(); - } + q->repolish(); } QSizeF HbToolButtonPrivate::getMinimumSize() @@ -247,7 +197,6 @@ mSizeHintPolish = false; //workaround ends q->updateGeometry(); - QCoreApplication::sendPostedEvents(q, QEvent::LayoutRequest); QSizeF size = q->minimumSize(); return size; } @@ -266,21 +215,24 @@ { Q_Q(HbToolButton); HbAction *hbAction = qobject_cast(action); + int currentProperty = q->property(BUTTONSTYLE).toInt(); if ((hbAction && !hbAction->icon().isNull()) || !action->icon().isNull()) { if (orientation == Qt::Horizontal) { - buttonStyle = HbToolButton::ToolButtonIcon; + q->setProperty(BUTTONSTYLE, HbToolButtonPrivate::ToolButtonIcon); } else if (!action->text().isEmpty()) { - buttonStyle = HbToolButton::ToolButtonTextAndIcon; + q->setProperty(BUTTONSTYLE, HbToolButtonPrivate::ToolButtonTextAndIcon); } else { - buttonStyle = HbToolButton::ToolButtonIcon; + q->setProperty(BUTTONSTYLE, HbToolButtonPrivate::ToolButtonIcon); } } else { - buttonStyle = HbToolButton::ToolButtonText; + q->setProperty(BUTTONSTYLE, HbToolButtonPrivate::ToolButtonText); } - // action text/icon may have changed, - if (polished) { - q->repolish(); - QCoreApplication::sendPostedEvents(q, QEvent::Polish); + // action text/icon may have changed, + q->prepareGeometryChange(); + if (currentProperty != q->property(BUTTONSTYLE).toInt()) + q->repolish(); + else if (polished) { + q->updatePrimitives(); } } @@ -357,13 +309,12 @@ connect(action, SIGNAL(triggered()), this, SLOT(_q_actionTriggered())); connect(action, SIGNAL(changed()), this, SLOT(_q_actionChanged())); } - + // If action was null then there is a chance that the iconitem is not yet created. + // If the new action is null then we may need to get rid of the icon completely. + if ((!oldAction && action) || (oldAction && !action)) { + repolish(); // will call createPrimitives() + } if (isVisible() && d->polished) { - // If action was null then there is a chance that the iconitem is not yet created. - // If the new action is null then we may need to get rid of the icon completely. - if ((!oldAction && action) || (oldAction && !action)) { - repolish(); // will call createPrimitives() - } updatePrimitives(); } } @@ -390,49 +341,6 @@ } } -/*! - \deprecated HbToolButton::toolButtonStyle() const - is deprecated. - - @beta - Returns the tool button style. - - The default value is \b HbToolButton::ToolButtonIcon. - - \sa setToolButtonStyle() - */ -HbToolButton::ToolButtonStyle HbToolButton::toolButtonStyle() const -{ - HB_DEPRECATED("HbToolButton::toolButtonStyle() is deprecated."); - - Q_D(const HbToolButton); - return d->buttonStyle; -} - -/*! - \deprecated HbToolButton::setToolButtonStyle(HbToolButton::ToolButtonStyle) - is deprecated. - - @beta - Sets the tool button style. - - \sa toolButtonStyle() - */ -void HbToolButton::setToolButtonStyle(HbToolButton::ToolButtonStyle style) -{ - HB_DEPRECATED("HbToolButton::setToolButtonStyle(HbToolButton::ToolButtonStyle style) is deprecated."); - - Q_D(HbToolButton); - if (d->buttonStyle != style) { - d->buttonStyle = style; - - // action text/icon may have changed, - // primitives might need to be created/cleaned up - if (size() != QSize(0, 0)) { - repolish(); - } - } -} /*! @@ -445,11 +353,11 @@ { Q_D(const HbToolButton); switch (primitive) { - case HbStyle::P_ToolButton_frame: + case HbStylePrivate::P_ToolButton_frame: return d->frameItem; - case HbStyle::P_ToolButton_icon: + case HbStylePrivate::P_ToolButton_icon: return d->iconItem; - case HbStyle::P_ToolButton_text: + case HbStylePrivate::P_ToolButton_text: return d->textItem; default: return 0; @@ -488,24 +396,33 @@ initStyleOption(&option); setProperty("dialogtoolbar", d->mDialogToolBar); if (d->frameItem) { - style()->updatePrimitive(d->frameItem, HbStyle::P_ToolButton_frame, &option); + HbStylePrivate::updatePrimitive(d->frameItem, HbStylePrivate::P_ToolButton_frame, &option); } if (d->textItem) { - style()->updatePrimitive(d->textItem, HbStyle::P_ToolButton_text, &option); + bool itemHasNoContents = false; + if (option.text.isEmpty() || option.text.isNull() || + (property(BUTTONSTYLE).toInt() == HbToolButtonPrivate::ToolButtonIcon)) { + itemHasNoContents = true; + } + d->textItem->setFlag(QGraphicsItem::ItemHasNoContents, itemHasNoContents); + if(!itemHasNoContents) + HbStylePrivate::updatePrimitive(d->textItem, HbStylePrivate::P_ToolButton_text, &option); } if (d->iconItem) { - style()->updatePrimitive(d->iconItem, HbStyle::P_ToolButton_icon, &option); - HbAction *hbAction = qobject_cast(d->action); - if (hbAction) { - if (hbAction->icon().flags() & HbIcon::Colorized) { + bool itemHasNoContents = false; + if (option.icon.isNull() || (property(BUTTONSTYLE).toInt() == HbToolButtonPrivate::ToolButtonText)) { + itemHasNoContents = true; + } else { + HbStylePrivate::updatePrimitive(d->iconItem, HbStylePrivate::P_ToolButton_icon, &option); + if (option.icon.flags() & HbIcon::Colorized) { static_cast(d->iconItem)->setFlags(HbIcon::Colorized); } - if (hbAction->icon().mirroringMode() != HbIcon::Default) { + if (option.icon.mirroringMode() != HbIcon::Default) { HbIconItem *iconItem = static_cast(d->iconItem); - iconItem->setMirroringMode( hbAction->icon().mirroringMode() ); + iconItem->setMirroringMode( option.icon.mirroringMode() ); } } - + d->iconItem->setFlag(QGraphicsItem::ItemHasNoContents, itemHasNoContents); } }