summaryrefslogtreecommitdiffstats
path: root/src/plugins/styles/mac
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-08-15 13:09:55 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-08-15 16:53:19 +0200
commitc7ec7cd2a1ae9bec31113fae1f1e549b2bf98e0b (patch)
treefc81fba4e7815ea061da277cf3bcf3102866932f /src/plugins/styles/mac
parent7947032e2d1d68b2c0f79874db7adcf560851f29 (diff)
parent6132260da394a9627947f0fe6a279c20863b6ad2 (diff)
Merge branch 'wip/qt6' into wip/cmake
Diffstat (limited to 'src/plugins/styles/mac')
-rw-r--r--src/plugins/styles/mac/qmacstyle_mac.mm71
1 files changed, 55 insertions, 16 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm
index 85bf71be3f..968ca68619 100644
--- a/src/plugins/styles/mac/qmacstyle_mac.mm
+++ b/src/plugins/styles/mac/qmacstyle_mac.mm
@@ -75,6 +75,8 @@
#include <QtWidgets/qwizard.h>
#endif
+#include <cmath>
+
QT_USE_NAMESPACE
static QWindow *qt_getWindow(const QWidget *widget)
@@ -456,6 +458,37 @@ static bool setupSlider(NSSlider *slider, const QStyleOptionSlider *sl)
return true;
}
+static void fixStaleGeometry(NSSlider *slider)
+{
+ // If it's later fixed in AppKit, this function is not needed.
+ // On macOS Mojave we suddenly have NSSliderCell with a cached
+ // (and stale) geometry, thus its -drawKnob, -drawBarInside:flipped:,
+ // -drawTickMarks fail to render the slider properly. Setting the number
+ // of tickmarks triggers an update in geometry.
+
+ Q_ASSERT(slider);
+
+ if (QOperatingSystemVersion::current() < QOperatingSystemVersion::MacOSMojave)
+ return;
+
+ NSSliderCell *cell = slider.cell;
+ const NSRect barRect = [cell barRectFlipped:NO];
+ const NSSize sliderSize = slider.frame.size;
+ CGFloat difference = 0.;
+ if (slider.vertical)
+ difference = std::abs(sliderSize.height - barRect.size.height);
+ else
+ difference = std::abs(sliderSize.width - barRect.size.width);
+
+ if (difference > 6.) {
+ // Stale ...
+ const auto nOfTicks = slider.numberOfTickMarks;
+ // Non-zero, different from nOfTicks to force update
+ slider.numberOfTickMarks = nOfTicks + 10;
+ slider.numberOfTickMarks = nOfTicks;
+ }
+}
+
static bool isInMacUnifiedToolbarArea(QWindow *window, int windowY)
{
QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
@@ -2083,10 +2116,9 @@ void QMacStyle::unpolish(QWidget* w)
#if QT_CONFIG(menu)
qobject_cast<QMenu*>(w) &&
#endif
- !w->testAttribute(Qt::WA_SetPalette)) {
- QPalette pal = qApp->palette(w);
- w->setPalette(pal);
- w->setAttribute(Qt::WA_SetPalette, false);
+ !w->testAttribute(Qt::WA_SetPalette))
+ {
+ w->setPalette(QPalette());
w->setWindowOpacity(1.0);
}
@@ -2102,9 +2134,9 @@ void QMacStyle::unpolish(QWidget* w)
#if QT_CONFIG(tabbar)
if (qobject_cast<QTabBar*>(w)) {
if (!w->testAttribute(Qt::WA_SetFont))
- w->setFont(qApp->font(w));
+ w->setFont(QFont());
if (!w->testAttribute(Qt::WA_SetPalette))
- w->setPalette(qApp->palette(w));
+ w->setPalette(QPalette());
}
#endif
@@ -5241,9 +5273,20 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
}
d->drawNSViewInRect(slider, opt->rect, p, ^(CGContextRef ctx, const CGRect &rect) {
- if (isHorizontal && sl->upsideDown) {
- CGContextTranslateCTM(ctx, rect.size.width, 0);
- CGContextScaleCTM(ctx, -1, 1);
+
+ // Since the GC is flipped, upsideDown means *not* inverted when vertical.
+ const bool verticalFlip = !isHorizontal && !sl->upsideDown; // FIXME: && !isSierraOrLater
+
+ if (isHorizontal) {
+ if (sl->upsideDown) {
+ CGContextTranslateCTM(ctx, rect.size.width, rect.origin.y);
+ CGContextScaleCTM(ctx, -1, 1);
+ } else {
+ CGContextTranslateCTM(ctx, 0, rect.origin.y);
+ }
+ } else if (verticalFlip) {
+ CGContextTranslateCTM(ctx, rect.origin.x, rect.size.height);
+ CGContextScaleCTM(ctx, 1, -1);
}
if (hasDoubleTicks) {
@@ -5254,9 +5297,6 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
CGContextTranslateCTM(ctx, 1, 0);
}
- // Since the GC is flipped, upsideDown means *not* inverted when vertical.
- const bool verticalFlip = !isHorizontal && !sl->upsideDown; // FIXME: && !isSierraOrLater
-
#if 0
// FIXME: Sadly, this part doesn't work. It seems to somehow polute the
// NSSlider's internal state and, when we need to use the "else" part,
@@ -5276,6 +5316,8 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
#endif
{
[slider calcSize];
+ if (!hasDoubleTicks)
+ fixStaleGeometry(slider);
NSSliderCell *cell = slider.cell;
const int numberOfTickMarks = slider.numberOfTickMarks;
@@ -5285,10 +5327,10 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
const CGRect barRect = [cell barRectFlipped:hasTicks];
if (drawBar) {
+ [cell drawBarInside:barRect flipped:!verticalFlip];
// This ain't HIG kosher: force unfilled bar look.
if (hasDoubleTicks)
slider.numberOfTickMarks = numberOfTickMarks;
- [cell drawBarInside:barRect flipped:!verticalFlip];
}
if (hasTicks && drawTicks) {
@@ -5318,9 +5360,6 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
// This ain't HIG kosher: force round knob look.
if (hasDoubleTicks)
slider.numberOfTickMarks = 0;
- // Draw the knob in the symmetrical position instead of flipping.
- if (verticalFlip)
- slider.intValue = slider.maxValue - slider.intValue + slider.minValue;
[cell drawKnob];
}
}