This commit is contained in:
kleuter 2019-01-18 22:09:44 +01:00
parent 8bcce4b6dc
commit 5da9c781f2

View File

@ -130,6 +130,7 @@
#include <QtWidgets/qgraphicsview.h> #include <QtWidgets/qgraphicsview.h>
#endif #endif
#include <QtCore/qvariant.h> #include <QtCore/qvariant.h>
#include <QtCore/qvarlengtharray.h>
#include <private/qstylehelper_p.h> #include <private/qstylehelper_p.h>
#include <private/qstyleanimation_p.h> #include <private/qstyleanimation_p.h>
#include <qpa/qplatformfontdatabase.h> #include <qpa/qplatformfontdatabase.h>
@ -314,6 +315,26 @@ static QLinearGradient titlebarGradientInactive()
return qt_mac_applicationIsInDarkMode() ? darkGradient : lightGradient; return qt_mac_applicationIsInDarkMode() ? darkGradient : lightGradient;
} }
static void clipTabBarFrame(const QStyleOption *option, const QMacStyle *style, CGContextRef ctx)
{
Q_ASSERT(option);
Q_ASSERT(style);
Q_ASSERT(ctx);
if (qt_mac_applicationIsInDarkMode()) {
QTabWidget *tabWidget = qobject_cast<QTabWidget *>(option->styleObject);
Q_ASSERT(tabWidget);
const QRect tabBarRect = style->subElementRect(QStyle::SE_TabWidgetTabBar, option, tabWidget).adjusted(2, 2, -3, -2);
const QRegion clipPath = QRegion(option->rect) - tabBarRect;
QVarLengthArray<CGRect, 3> cgRects;
for (const QRect &qtRect : clipPath)
cgRects.push_back(qtRect.toCGRect());
if (cgRects.size())
CGContextClipToRects(ctx, &cgRects[0], size_t(cgRects.size()));
}
}
static const QColor titlebarSeparatorLineActive(111, 111, 111); static const QColor titlebarSeparatorLineActive(111, 111, 111);
static const QColor titlebarSeparatorLineInactive(131, 131, 131); static const QColor titlebarSeparatorLineInactive(131, 131, 131);
static const QColor darkModeSeparatorLine(88, 88, 88); static const QColor darkModeSeparatorLine(88, 88, 88);
@ -2789,6 +2810,9 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w
case SH_SpinBox_ButtonsInsideFrame: case SH_SpinBox_ButtonsInsideFrame:
ret = false; ret = false;
break; break;
case SH_Table_GridLineColor:
ret = int(qt_mac_toQColor(NSColor.gridColor).rgb());
break;
default: default:
ret = QCommonStyle::styleHint(sh, opt, w, hret); ret = QCommonStyle::styleHint(sh, opt, w, hret);
break; break;
@ -2973,6 +2997,8 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
// QDarkNSBox, of type NSBoxCustom. Its appearance is close enough to the real thing so // QDarkNSBox, of type NSBoxCustom. Its appearance is close enough to the real thing so
// we can use this for now. // we can use this for now.
d->drawNSViewInRect(box, opt->rect, p, ^(CGContextRef ctx, const CGRect &rect) { d->drawNSViewInRect(box, opt->rect, p, ^(CGContextRef ctx, const CGRect &rect) {
if (QTabWidget *tabWidget = qobject_cast<QTabWidget *>(opt->styleObject))
clipTabBarFrame(opt, this, ctx);
CGContextTranslateCTM(ctx, 0, rect.origin.y + rect.size.height); CGContextTranslateCTM(ctx, 0, rect.origin.y + rect.size.height);
CGContextScaleCTM(ctx, 1, -1); CGContextScaleCTM(ctx, 1, -1);
if (QOperatingSystemVersion::current() < QOperatingSystemVersion::MacOSMojave if (QOperatingSystemVersion::current() < QOperatingSystemVersion::MacOSMojave
@ -3226,7 +3252,13 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
break; break;
case PE_IndicatorTabClose: { case PE_IndicatorTabClose: {
// Make close button visible only on the hovered tab. // Make close button visible only on the hovered tab.
if (QTabBar *tabBar = qobject_cast<QTabBar*>(w->parentWidget())) { QTabBar *tabBar = qobject_cast<QTabBar*>(w->parentWidget());
if (!tabBar) {
// QStyleSheetStyle instead of CloseButton (which has
// a QTabBar as a parent widget) uses the QTabBar itself:
tabBar = qobject_cast<QTabBar *>(const_cast<QWidget*>(w));
}
if (tabBar) {
const bool documentMode = tabBar->documentMode(); const bool documentMode = tabBar->documentMode();
const QTabBarPrivate *tabBarPrivate = static_cast<QTabBarPrivate *>(QObjectPrivate::get(tabBar)); const QTabBarPrivate *tabBarPrivate = static_cast<QTabBarPrivate *>(QObjectPrivate::get(tabBar));
const int hoveredTabIndex = tabBarPrivate->hoveredTabIndex(); const int hoveredTabIndex = tabBarPrivate->hoveredTabIndex();
@ -3690,6 +3722,12 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
// inFrame:withView:], -[drawRect:] or anything in between. Besides, // inFrame:withView:], -[drawRect:] or anything in between. Besides,
// there's no public API do draw the pressed state, AFAICS. We'll use // there's no public API do draw the pressed state, AFAICS. We'll use
// a push NSButton instead and clip the CGContext. // a push NSButton instead and clip the CGContext.
// NOTE/TODO: this is not true. On 10.13 NSSegmentedControl works with
// some (black?) magic/magic dances, on 10.14 it simply works (was
// it fixed in AppKit?). But, indeed, we cannot make a tab 'pressed'
// with NSSegmentedControl (only selected), so we stay with buttons
// (mixing buttons and NSSegmentedControl for such a simple thing
// is too much work).
const auto cs = d->effectiveAquaSizeConstrain(opt, w); const auto cs = d->effectiveAquaSizeConstrain(opt, w);
// Extra hacks to get the proper pressed appreance when not selected or selected and inactive // Extra hacks to get the proper pressed appreance when not selected or selected and inactive