diff options
author | Sami Merilä <sami.merila@nokia.com> | 2009-11-03 12:02:03 (GMT) |
---|---|---|
committer | Sami Merilä <sami.merila@nokia.com> | 2009-11-03 12:02:03 (GMT) |
commit | dc89c842779f87ce69882ba54fa8d5bb79e0edbd (patch) | |
tree | 7d13c2ff7d67c1151e5d8623f503410e62f8e791 /src/gui/styles/qs60style.cpp | |
parent | cb396cf4851b961fb42e21866d7467efb3642a04 (diff) | |
download | Qt-dc89c842779f87ce69882ba54fa8d5bb79e0edbd.zip Qt-dc89c842779f87ce69882ba54fa8d5bb79e0edbd.tar.gz Qt-dc89c842779f87ce69882ba54fa8d5bb79e0edbd.tar.bz2 |
QS60Style: impossible to open menu from styled QToolButton
QS60Style ignores toolButton's menu indicator rect. This means that the
button's menu cannot be triggered by the user, as the style does not
draw the indicator at all.
With this fix, style calculates a rect (including margins) for menu
indicator and draws that (arrow down) into toolButton (by making the
button bevel larger).
Task-number: QTBUG-5266
Reviewed-by: Alessandro Portale
Diffstat (limited to 'src/gui/styles/qs60style.cpp')
-rw-r--r-- | src/gui/styles/qs60style.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 949dfcb..350a8e6 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -994,6 +994,10 @@ void QS60Style::drawComplexControl(ComplexControl control, const QStyleOptionCom if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { const State bflags = toolBtn->state; const QRect button(subControlRect(control, toolBtn, SC_ToolButton, widget)); + QRect menuRect = QRect(); + if (toolBtn->subControls & SC_ToolButtonMenu) + menuRect = subControlRect(control, toolBtn, SC_ToolButtonMenu, widget); + QStyleOptionToolButton toolButton = *toolBtn; if (sub&SC_ToolButton) { @@ -1006,7 +1010,7 @@ void QS60Style::drawComplexControl(ComplexControl control, const QStyleOptionCom toolBar = qobject_cast<QToolBar *>(widget->parentWidget()); if (bflags & (State_Sunken | State_On | State_Raised)) { - tool.rect = button; + tool.rect = button.unite(menuRect); tool.state = bflags; // todo: I'd like to move extension button next to where last button is @@ -1061,6 +1065,12 @@ void QS60Style::drawComplexControl(ComplexControl control, const QStyleOptionCom } else { drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); } + + if (toolButton.subControls & SC_ToolButtonMenu) { + tool.rect = menuRect; + tool.state = bflags; + drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget); + } } } @@ -2232,7 +2242,6 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti // todo: items are below with #ifdefs "just in case". in final version, remove all non-required cases case PE_FrameLineEdit: - case PE_IndicatorButtonDropDown: case PE_IndicatorDockWidgetResizeHandle: case PE_PanelTipLabel: case PE_PanelScrollAreaCorner: @@ -2561,6 +2570,29 @@ QRect QS60Style::subControlRect(ComplexControl control, const QStyleOptionComple } } break; + case CC_ToolButton: + if (const QStyleOptionToolButton *toolButton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { + const int indicatorRect = pixelMetric(PM_MenuButtonIndicator, toolButton, widget) + + 2*pixelMetric(PM_ButtonMargin, toolButton, widget); + ret = toolButton->rect; + const bool popup = (toolButton->features & + (QStyleOptionToolButton::MenuButtonPopup | QStyleOptionToolButton::PopupDelay)) + == QStyleOptionToolButton::MenuButtonPopup; + switch (scontrol) { + case SC_ToolButton: + if (popup) + ret.adjust(0, 0, -indicatorRect, 0); + break; + case SC_ToolButtonMenu: + if (popup) + ret.adjust(ret.width() - indicatorRect, ret.height() - indicatorRect, 0, 0); + break; + default: + break; + } + ret = visualRect(toolButton->direction, toolButton->rect, ret); + } + break; default: ret = QCommonStyle::subControlRect(control, option, scontrol, widget); } |