summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJens Bache-Wiig <jens.bache-wiig@digia.com>2012-11-01 11:47:37 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-01 20:17:57 +0100
commit70dea61670d0f66482442b41549de8ee19474fa6 (patch)
tree042c35790dd59ee7d5986594c0c4b41baafba9ed /src
parent8c15be7bb2488a17b2c2f62e2d2a7ed01dd331d6 (diff)
Make ToolButton work with Macstyle for components
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 <jan-arve.saether@digia.com> Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/styles/qmacstyle_mac.mm5
-rw-r--r--src/widgets/styles/qstylehelper.cpp17
-rw-r--r--src/widgets/styles/qstylehelper_p.h2
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<const QStyleOptionToolButton *>(opt)) {
- if (widget && qobject_cast<QToolBar *>(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<QToolBar*>(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 <QtCore/qstring.h>
#include <QtGui/qpolygon.h>
#include <QtCore/qstringbuilder.h>
+#include <QtGui/qaccessible.h>
#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);
}