diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-01-21 17:57:54 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-21 17:57:54 +0100 |
commit | 46791c08e17740418cc701b8862a980c0f711b87 (patch) | |
tree | bedba63fc48b80c2a2df54ea91c3f35398953aac /src/widgets/styles | |
parent | b8a38a6737acd670d92197ca5b009590d9fd8a9c (diff) | |
parent | 9033977d3971db5352a2bb51052a723a2ac57a8f (diff) | |
download | qtbase-46791c08e17740418cc701b8862a980c0f711b87.tar.gz |
Merge "Merge remote-tracking branch 'origin/stable' into dev" into refs/staging/dev
Diffstat (limited to 'src/widgets/styles')
-rw-r--r-- | src/widgets/styles/qcommonstyle.cpp | 5 | ||||
-rw-r--r-- | src/widgets/styles/qmacstyle_mac.mm | 79 |
2 files changed, 47 insertions, 37 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index a9f1c3bbbc..2d7107598f 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -838,7 +838,10 @@ QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItem *option, int break; case QStyleOptionViewItem::Top: case QStyleOptionViewItem::Bottom: - bounds.setWidth(wrapText ? option->decorationSize.width() : QFIXED_MAX); + if (wrapText) + bounds.setWidth(bounds.isValid() ? bounds.width() - 2 * textMargin : option->decorationSize.width()); + else + bounds.setWidth(QFIXED_MAX); break; default: break; diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 5db4801c37..d13339b555 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 *****************************************************************************/ @@ -2425,11 +2437,6 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW break; case PM_ToolBarFrameWidth: ret = 1; - if (widget) { - if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(widget->parent())) - if (mainWindow->unifiedTitleAndToolBarOnMac()) - ret = 0; - } break; case PM_ScrollView_ScrollBarOverlap: #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 @@ -3008,23 +3015,19 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai if (opt->state & State_Horizontal) { while (y < opt->rect.height() - RectHeight - 5) { path.moveTo(x, y); - path.addRect(x, y, RectHeight, RectHeight); + path.addEllipse(x, y, RectHeight, RectHeight); y += 6; } } else { while (x < opt->rect.width() - RectHeight - 5) { path.moveTo(x, y); - path.addRect(x, y, RectHeight, RectHeight); + path.addEllipse(x, y, RectHeight, RectHeight); x += 6; } } p->setPen(Qt::NoPen); - QColor dark = opt->palette.dark().color(); - dark.setAlphaF(0.75); - QColor light = opt->palette.light().color(); - light.setAlphaF(0.6); - p->fillPath(path, light); - p->translate(1, 1); + QColor dark = opt->palette.dark().color().darker(); + dark.setAlphaF(0.50); p->fillPath(path, dark); p->restore(); @@ -3437,14 +3440,8 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter if (tb->toolButtonStyle != Qt::ToolButtonIconOnly) { needText = true; if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) { - QMainWindow *mw = w ? qobject_cast<QMainWindow *>(w->window()) : 0; - if (mw && mw->unifiedTitleAndToolBarOnMac()) { - pr.setHeight(pixmap.size().height() / pixmap.devicePixelRatio()); - cr.adjust(0, pr.bottom() + 1, 0, 1); - } else { - pr.setHeight(pixmap.size().height() / pixmap.devicePixelRatio() + 6); - cr.adjust(0, pr.bottom(), 0, -3); - } + pr.setHeight(pixmap.size().height() / pixmap.devicePixelRatio() + 6); + cr.adjust(0, pr.bottom(), 0, -3); alignment |= Qt::AlignCenter; } else { pr.setWidth(pixmap.width() / pixmap.devicePixelRatio() + 8); @@ -4442,12 +4439,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 @@ -6241,18 +6260,6 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, } break; case CT_ToolButton: - if (widget && qobject_cast<const QToolBar *>(widget->parentWidget())) { - if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(widget->parent())) { - if (mainWindow->unifiedTitleAndToolBarOnMac()) { - sz.rwidth() += 4; - if (sz.height() <= 32) { - // Workaround strange HIToolBar bug when getting constraints. - sz.rheight() += 1; - } - return sz; - } - } - } sz.rwidth() += 10; sz.rheight() += 10; return sz; |