From 70dea61670d0f66482442b41549de8ee19474fa6 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Thu, 1 Nov 2012 11:47:37 +0100 Subject: Make ToolButton work with Macstyle for components MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We needed a new helper function for this. The widget cast was breaking desktop components. By using accessible role, we can make it work for both use cases without depending on the widget. Change-Id: Ic854dc45a4e5b7a50c5be701e903d58a4a914ee5 Reviewed-by: Jan Arve Sæther Reviewed-by: Jens Bache-Wiig --- src/widgets/styles/qmacstyle_mac.mm | 5 +++-- src/widgets/styles/qstylehelper.cpp | 17 +++++++++++++++++ src/widgets/styles/qstylehelper_p.h | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index b0a43c563c..83895b64b0 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -5434,7 +5434,8 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex case CC_ToolButton: if (const QStyleOptionToolButton *tb = qstyleoption_cast(opt)) { - if (widget && qobject_cast(widget->parentWidget())) { + + if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar)) { if (tb->subControls & SC_ToolButtonMenu) { QStyleOption arrowOpt(0); arrowOpt.rect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget); @@ -6030,7 +6031,7 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op break; case CC_ToolButton: ret = QCommonStyle::subControlRect(cc, opt, sc, widget); - if (sc == SC_ToolButtonMenu && widget && !qobject_cast(widget->parentWidget())) { + if (sc == SC_ToolButtonMenu && !QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar)) { ret.adjust(-1, 0, 0, 0); } break; diff --git a/src/widgets/styles/qstylehelper.cpp b/src/widgets/styles/qstylehelper.cpp index e23db2b637..8d67683eae 100644 --- a/src/widgets/styles/qstylehelper.cpp +++ b/src/widgets/styles/qstylehelper.cpp @@ -86,6 +86,23 @@ qreal dpiScaled(qreal value) #endif } +// Searches for an ancestor of a particular accessible role +bool hasAncestor(QObject *obj, QAccessible::Role role) +{ + bool found = false; +#ifndef QT_NO_ACCESSIBILITY + QObject *parent = obj ? obj->parent() : 0; + while (parent && !found) { + QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(parent); + if (iface && iface->role() == role) + found = true; + delete iface; + parent = parent->parent(); + } +#endif // QT_NO_ACCESSIBILITY + return found; +} + #ifndef QT_NO_DIAL diff --git a/src/widgets/styles/qstylehelper_p.h b/src/widgets/styles/qstylehelper_p.h index e47722bd9f..ab6a97e59a 100644 --- a/src/widgets/styles/qstylehelper_p.h +++ b/src/widgets/styles/qstylehelper_p.h @@ -44,6 +44,7 @@ #include #include #include +#include #ifndef QSTYLEHELPER_P_H #define QSTYLEHELPER_P_H @@ -81,6 +82,7 @@ namespace QStyleHelper void drawBorderPixmap(const QPixmap &pixmap, QPainter *painter, const QRect &rect, int left = 0, int top = 0, int right = 0, int bottom = 0); + bool hasAncestor(QObject *obj, QAccessible::Role role); } -- cgit v1.2.3