summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2013-12-16 23:03:30 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-12 01:25:41 +0100
commitb3d642e71e1b1083e5f17872614da2cbf38e8fbe (patch)
treef05585b60bb0dd12905a4e6971aafedd1e392b17
parent055591750aaccab9e764eb7348968d9716dd4f47 (diff)
Mac: Update unified toolbar drawing code.
Fill the toolbar background with transparent pixels to allow the view background to shine through. Draw a separator line using HITheme. Task-number: QTBUG-34411 Change-Id: I57732564a67a5a9d1eb7fd9038382b2b65be50a4 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
-rw-r--r--src/widgets/styles/qmacstyle_mac.mm40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm
index 93a72980c9..8c00f06a4f 100644
--- a/src/widgets/styles/qmacstyle_mac.mm
+++ b/src/widgets/styles/qmacstyle_mac.mm
@@ -679,6 +679,18 @@ bool qt_macWindowIsTextured(const QWidget *window)
return false;
}
+static bool qt_macWindowMainWindow(const QWidget *window)
+{
+ if (QWindow *w = window->windowHandle()) {
+ if (w->handle()) {
+ if (NSWindow *nswindow = static_cast<NSWindow*>(QGuiApplication::platformNativeInterface()->nativeResourceForWindow(QByteArrayLiteral("nswindow"), w))) {
+ return [nswindow isMainWindow];
+ }
+ }
+ }
+ return false;
+}
+
/*****************************************************************************
QMacCGStyle globals
*****************************************************************************/
@@ -4438,12 +4450,34 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
}
break;
case CE_ToolBar: {
- // For unified tool bars, draw nothing.
- if (w) {
+ const QStyleOptionToolBar *toolBar = qstyleoption_cast<const QStyleOptionToolBar *>(opt);
+
+ // Unified title and toolbar drawing. In this mode the cocoa platform plugin will
+ // fill the top toolbar area part with a background gradient that "unifies" with
+ // the title bar. The following code fills the toolBar area with transparent pixels
+ // to make that gradient visible.
+ if (w) {
if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(w->window())) {
- if (mainWindow->unifiedTitleAndToolBarOnMac())
+ if (toolBar && toolBar->toolBarArea == Qt::TopToolBarArea && mainWindow->unifiedTitleAndToolBarOnMac()) {
+
+ // fill with transparent pixels.
+ p->save();
+ p->setCompositionMode(QPainter::CompositionMode_Source);
+ p->fillRect(opt->rect, Qt::transparent);
+ p->restore();
+
+ // drow horizontal sepearator line at toolBar bottom.
+ SInt32 margin;
+ GetThemeMetric(kThemeMetricSeparatorSize, &margin);
+ CGRect separatorRect = CGRectMake(opt->rect.left(), opt->rect.bottom(), opt->rect.width(), margin);
+ HIThemeSeparatorDrawInfo separatorDrawInfo;
+ separatorDrawInfo.version = 0;
+ separatorDrawInfo.state = qt_macWindowMainWindow(mainWindow) ? kThemeStateActive : kThemeStateInactive;
+ QMacCGContext cg(p);
+ HIThemeDrawSeparator(&separatorRect, &separatorDrawInfo, cg, kHIThemeOrientationNormal);
break;
}
+ }
}
// draw background gradient