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>
bb10
Morten Johan Sørvig 2013-12-16 23:03:30 +01:00 committed by The Qt Project
parent 055591750a
commit b3d642e71e
1 changed files with 37 additions and 3 deletions

View File

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