From b3d642e71e1b1083e5f17872614da2cbf38e8fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 16 Dec 2013 23:03:30 +0100 Subject: 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 --- src/widgets/styles/qmacstyle_mac.mm | 40 ++++++++++++++++++++++++++++++++++--- 1 file 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(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(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(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 -- cgit v1.2.3