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>
This commit is contained in:
Jens Bache-Wiig 2012-11-01 11:47:37 +01:00 committed by The Qt Project
parent 8c15be7bb2
commit 70dea61670
3 changed files with 22 additions and 2 deletions

View File

@ -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;

View File

@ -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

View File

@ -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);
}