summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <qt-info@nokia.com>2010-10-04 13:10:25 (GMT)
committerAndy Shaw <qt-info@nokia.com>2010-10-04 13:10:25 (GMT)
commita636fa9006b7f4cb898cdeec38a99c994fd9259e (patch)
tree474cd85aade64e791c21bdc81ce77b462137d427
parentd203e7d078cc2bb43ccb32282f40cedbffee4095 (diff)
downloadQt-a636fa9006b7f4cb898cdeec38a99c994fd9259e.zip
Qt-a636fa9006b7f4cb898cdeec38a99c994fd9259e.tar.gz
Qt-a636fa9006b7f4cb898cdeec38a99c994fd9259e.tar.bz2
Ensure that the underline is only drawn when expected for an accel
On Mac, the underline for an accel should not be drawn at all as this is not part of the style guidelines. This ensures that it is not drawn. Autotest included which required a change to drawItemText() to go via the proxy as well so that the autotest would be useful too. Task-number: QTBUG-14172 Reviewed-by: Richard
-rw-r--r--src/gui/styles/qmacstyle_mac.mm10
-rw-r--r--tests/auto/qstyle/tst_qstyle.cpp51
2 files changed, 57 insertions, 4 deletions
diff --git a/src/gui/styles/qmacstyle_mac.mm b/src/gui/styles/qmacstyle_mac.mm
index 671a888..fb31ae4 100644
--- a/src/gui/styles/qmacstyle_mac.mm
+++ b/src/gui/styles/qmacstyle_mac.mm
@@ -3336,6 +3336,8 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
if (needText) {
QPalette pal = tb->palette;
QPalette::ColorRole role = QPalette::NoRole;
+ if (!proxy()->styleHint(SH_UnderlineShortcut, tb, w))
+ alignment |= Qt::TextHideMnemonic;
if (down)
cr.translate(shiftX, shiftY);
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5
@@ -3353,13 +3355,13 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
role = QPalette::HighlightedText;
}
}
- drawItemText(p, cr, alignment, pal,
- tb->state & State_Enabled, tb->text, role);
+ proxy()->drawItemText(p, cr, alignment, pal,
+ tb->state & State_Enabled, tb->text, role);
if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_5 &&
(tb->state & State_Sunken)) {
// Draw a "drop shadow" in earlier versions.
- drawItemText(p, cr.adjusted(0, 1, 0, 1), alignment,
- tb->palette, tb->state & State_Enabled, tb->text);
+ proxy()->drawItemText(p, cr.adjusted(0, 1, 0, 1), alignment,
+ tb->palette, tb->state & State_Enabled, tb->text);
}
}
} else {
diff --git a/tests/auto/qstyle/tst_qstyle.cpp b/tests/auto/qstyle/tst_qstyle.cpp
index a76c82d..ba24225 100644
--- a/tests/auto/qstyle/tst_qstyle.cpp
+++ b/tests/auto/qstyle/tst_qstyle.cpp
@@ -53,6 +53,7 @@
#include <qscrollbar.h>
#include <qprogressbar.h>
#include <qtoolbutton.h>
+#include <qtoolbar.h>
#include <qplastiquestyle.h>
#include <qwindowsstyle.h>
@@ -146,6 +147,7 @@ private slots:
void pixelMetric();
void progressBarChangeStyle();
void defaultFont();
+ void testDrawingShortcuts();
private:
void lineUpLayoutTest(QStyle *);
QWidget *testWidget;
@@ -781,5 +783,54 @@ void tst_QStyle::defaultFont()
qApp->setFont(defaultFont);
}
+class DrawTextStyle : public QProxyStyle
+{
+ Q_OBJECT
+public:
+ DrawTextStyle(QStyle *base = 0) : QProxyStyle(), alignment(0) { setBaseStyle(base); }
+ void drawItemText(QPainter *painter, const QRect &rect,
+ int flags, const QPalette &pal, bool enabled,
+ const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const
+ {
+ DrawTextStyle *that = (DrawTextStyle *)this;
+ that->alignment = flags;
+ QProxyStyle::drawItemText(painter, rect, flags, pal, enabled, text, textRole);
+ }
+ int alignment;
+};
+
+void tst_QStyle::testDrawingShortcuts()
+{
+ {
+ QWidget w;
+ QToolButton *tb = new QToolButton(&w);
+ tb->setText("&abc");
+ DrawTextStyle *dts = new DrawTextStyle;
+ w.show();
+ tb->setStyle(dts);
+ QPixmap::grabWidget(tb);
+ QStyleOptionToolButton sotb;
+ sotb.initFrom(tb);
+ bool showMnemonic = dts->styleHint(QStyle::SH_UnderlineShortcut, &sotb, tb);
+ QVERIFY(dts->alignment & (showMnemonic ? Qt::TextShowMnemonic : Qt::TextHideMnemonic));
+ delete dts;
+ }
+ {
+ QToolBar w;
+ QToolButton *tb = new QToolButton(&w);
+ tb->setText("&abc");
+ DrawTextStyle *dts = new DrawTextStyle;
+ w.addWidget(tb);
+ w.show();
+ tb->setStyle(dts);
+ QPixmap::grabWidget(tb);
+ QStyleOptionToolButton sotb;
+ sotb.initFrom(tb);
+ bool showMnemonic = dts->styleHint(QStyle::SH_UnderlineShortcut, &sotb, tb);
+ QVERIFY(dts->alignment & (showMnemonic ? Qt::TextShowMnemonic : Qt::TextHideMnemonic));
+ delete dts;
+ }
+}
+
QTEST_MAIN(tst_QStyle)
#include "tst_qstyle.moc"