Remove compatibility code paths for macOS < 10.10 and iOS < 8.0

Change-Id: I11bec0efc2b4d86adf64a58990260fee70f050ac
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Jake Petroules 2016-09-23 16:15:36 -07:00
parent 747e569597
commit 6b7e633248
7 changed files with 75 additions and 232 deletions

View File

@ -40,61 +40,16 @@
#include "qoperatingsystemversion_p.h" #include "qoperatingsystemversion_p.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#ifdef Q_OS_IOS
#import <UIKit/UIKit.h>
#endif
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
typedef qint16 (*GestaltFunction)(quint32 selector, qint32 *response);
QOperatingSystemVersion QOperatingSystemVersion::current() QOperatingSystemVersion QOperatingSystemVersion::current()
{ {
NSOperatingSystemVersion osv = NSProcessInfo.processInfo.operatingSystemVersion;
QOperatingSystemVersion v; QOperatingSystemVersion v;
v.m_os = currentType(); v.m_os = currentType();
v.m_major = -1; v.m_major = osv.majorVersion;
v.m_minor = -1; v.m_minor = osv.minorVersion;
v.m_micro = -1; v.m_micro = osv.patchVersion;
#if QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_10, __IPHONE_8_0) || defined(Q_OS_TVOS) || defined(Q_OS_WATCHOS)
if ([NSProcessInfo instancesRespondToSelector:@selector(operatingSystemVersion)]) {
NSOperatingSystemVersion osv = NSProcessInfo.processInfo.operatingSystemVersion;
v.m_major = osv.majorVersion;
v.m_minor = osv.minorVersion;
v.m_micro = osv.patchVersion;
return v;
}
#endif
// Use temporary variables so we can return 0.0.0 (unknown version)
// in case of an error partway through determining the OS version
qint32 major = 0, minor = 0, patch = 0;
#if QT_MACOS_IOS_DEPLOYMENT_TARGET_BELOW(__MAC_10_10, __IPHONE_8_0)
#if defined(Q_OS_IOS)
@autoreleasepool {
NSArray *parts = [UIDevice.currentDevice.systemVersion componentsSeparatedByString:@"."];
major = parts.count > 0 ? [[parts objectAtIndex:0] intValue] : 0;
minor = parts.count > 1 ? [[parts objectAtIndex:1] intValue] : 0;
patch = parts.count > 2 ? [[parts objectAtIndex:2] intValue] : 0;
}
#elif defined(Q_OS_MACOS)
static GestaltFunction pGestalt = 0;
if (!pGestalt) {
CFBundleRef b = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.CoreServices"));
pGestalt = reinterpret_cast<GestaltFunction>(CFBundleGetFunctionPointerForName(b,
CFSTR("Gestalt")));
}
if (!pGestalt)
return v;
if (pGestalt('sys1', &major) != 0)
return v;
if (pGestalt('sys2', &minor) != 0)
return v;
if (pGestalt('sys3', &patch) != 0)
return v;
#endif
#endif
v.m_major = major;
v.m_minor = minor;
v.m_micro = patch;
return v; return v;
} }

View File

@ -119,8 +119,8 @@ mac {
osx: LIBS_PRIVATE += -framework CoreServices -framework AppKit osx: LIBS_PRIVATE += -framework CoreServices -framework AppKit
uikit { ios|tvos {
# We need UIKit for UIDevice # We need UIKit for UIApplication in qeventdispatcher_cf.mm
LIBS_PRIVATE += -framework UIKit LIBS_PRIVATE += -framework UIKit
} }

View File

@ -107,29 +107,6 @@ QImage qt_mac_toQImage(CGImageRef image)
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
QT_END_NAMESPACE
@interface NSGraphicsContext (QtAdditions)
+ (NSGraphicsContext *)qt_graphicsContextWithCGContext:(CGContextRef)graphicsPort flipped:(BOOL)initialFlippedState;
@end
@implementation NSGraphicsContext (QtAdditions)
+ (NSGraphicsContext *)qt_graphicsContextWithCGContext:(CGContextRef)graphicsPort flipped:(BOOL)initialFlippedState
{
#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_10, __IPHONE_NA)
if (QT_PREPEND_NAMESPACE(QOperatingSystemVersion::current()) >= QT_PREPEND_NAMESPACE(QOperatingSystemVersion::OSXYosemite))
return [self graphicsContextWithCGContext:graphicsPort flipped:initialFlippedState];
#endif
return [self graphicsContextWithGraphicsPort:graphicsPort flipped:initialFlippedState];
}
@end
QT_BEGIN_NAMESPACE
static NSImage *qt_mac_cgimage_to_nsimage(CGImageRef image) static NSImage *qt_mac_cgimage_to_nsimage(CGImageRef image)
{ {
NSImage *newImage = [[NSImage alloc] initWithCGImage:image size:NSZeroSize]; NSImage *newImage = [[NSImage alloc] initWithCGImage:image size:NSZeroSize];
@ -178,7 +155,7 @@ QPixmap qt_mac_toQPixmap(const NSImage *image, const QSizeF &size)
QMacCGContext ctx(&pixmap); QMacCGContext ctx(&pixmap);
if (!ctx) if (!ctx)
return QPixmap(); return QPixmap();
NSGraphicsContext *gc = [NSGraphicsContext qt_graphicsContextWithCGContext:ctx flipped:YES]; NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:ctx flipped:YES];
if (!gc) if (!gc)
return QPixmap(); return QPixmap();
[NSGraphicsContext saveGraphicsState]; [NSGraphicsContext saveGraphicsState];

Binary file not shown.

Before

Width:  |  Height:  |  Size: 356 B

View File

@ -6,7 +6,4 @@
<file>images/waitcursor.png</file> <file>images/waitcursor.png</file>
<file>images/sizeallcursor.png</file> <file>images/sizeallcursor.png</file>
</qresource> </qresource>
<qresource prefix="/qt-project.org/mac/style">
<file>images/leopard-unified-toolbar-on.png</file>
</qresource>
</RCC> </RCC>

View File

@ -407,10 +407,11 @@ qreal QIOSScreen::devicePixelRatio() const
Qt::ScreenOrientation QIOSScreen::nativeOrientation() const Qt::ScreenOrientation QIOSScreen::nativeOrientation() const
{ {
CGRect nativeBounds = CGRect nativeBounds =
#if !defined(Q_OS_TVOS) && QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_8_0) #if defined(Q_OS_IOS)
QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::IOS, 8) ? m_uiScreen.nativeBounds : m_uiScreen.nativeBounds;
#endif #else
m_uiScreen.bounds; m_uiScreen.bounds;
#endif
// All known iOS devices have a native orientation of portrait, but to // All known iOS devices have a native orientation of portrait, but to
// be on the safe side we compare the width and height of the bounds. // be on the safe side we compare the width and height of the bounds.

View File

@ -1313,8 +1313,6 @@ void QMacStylePrivate::initComboboxBdi(const QStyleOptionComboBox *combo, HIThem
bdi->adornment = kThemeAdornmentFocus; bdi->adornment = kThemeAdornmentFocus;
if (combo->activeSubControls & QStyle::SC_ComboBoxArrow) if (combo->activeSubControls & QStyle::SC_ComboBoxArrow)
bdi->state = kThemeStatePressed; bdi->state = kThemeStatePressed;
else if (tds == kThemeStateInactive && QOperatingSystemVersion::current() < QOperatingSystemVersion::OSXYosemite)
bdi->state = kThemeStateActive;
else else
bdi->state = tds; bdi->state = tds;
@ -1635,7 +1633,7 @@ void QMacStylePrivate::getSliderInfo(QStyle::ComplexControl cc, const QStyleOpti
|| slider->tickPosition == QSlider::TicksBothSides; || slider->tickPosition == QSlider::TicksBothSides;
tdi->bounds = qt_hirectForQRect(slider->rect); tdi->bounds = qt_hirectForQRect(slider->rect);
if (isScrollbar || QOperatingSystemVersion::current() < QOperatingSystemVersion::OSXYosemite) { if (isScrollbar) {
tdi->min = slider->minimum; tdi->min = slider->minimum;
tdi->max = slider->maximum; tdi->max = slider->maximum;
tdi->value = slider->sliderPosition; tdi->value = slider->sliderPosition;
@ -1947,7 +1945,6 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD
const bool button = opt->type == QStyleOption::SO_Button; const bool button = opt->type == QStyleOption::SO_Button;
const bool viewItem = opt->type == QStyleOption::SO_ViewItem; const bool viewItem = opt->type == QStyleOption::SO_ViewItem;
const bool pressed = bdi->state == kThemeStatePressed; const bool pressed = bdi->state == kThemeStatePressed;
const bool usingYosemiteOrLater = QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite;
if (button && pressed) { if (button && pressed) {
if (bdi->kind == kThemePushButton) { if (bdi->kind == kThemePushButton) {
@ -1986,7 +1983,7 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD
HIRect newRect = CGRectMake(xoff, yoff, macRect.size.width, macRect.size.height); HIRect newRect = CGRectMake(xoff, yoff, macRect.size.width, macRect.size.height);
if (button && pressed) if (button && pressed)
bdi->state = kThemeStateActive; bdi->state = kThemeStateActive;
else if (usingYosemiteOrLater && viewItem) else if (viewItem)
bdi->state = kThemeStateInactive; bdi->state = kThemeStateInactive;
HIThemeDrawButton(&newRect, bdi, cg, kHIThemeOrientationNormal, 0); HIThemeDrawButton(&newRect, bdi, cg, kHIThemeOrientationNormal, 0);
} }
@ -1994,34 +1991,7 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD
if (!combo && !button && bdi->value == kThemeButtonOff) { if (!combo && !button && bdi->value == kThemeButtonOff) {
pm = activePixmap; pm = activePixmap;
} else if (!usingYosemiteOrLater && (combo || button)) { } else if ((combo && !editableCombo) || button) {
QImage image = activePixmap.toImage();
for (int y = 0; y < height; ++y) {
QRgb *scanLine = reinterpret_cast<QRgb *>(image.scanLine(y));
for (int x = 0; x < width; ++x) {
QRgb &pixel = scanLine[x];
int darkest = qRed(pixel);
int mid = qGreen(pixel);
int lightest = qBlue(pixel);
if (darkest > mid)
qSwap(darkest, mid);
if (mid > lightest)
qSwap(mid, lightest);
if (darkest > mid)
qSwap(darkest, mid);
int gray = (mid + 2 * lightest) / 3;
if (pressed)
gray *= 0.88;
pixel = qRgba(gray, gray, gray, qAlpha(pixel));
}
}
pm = QPixmap::fromImage(image);
} else if ((usingYosemiteOrLater && combo && !editableCombo) || button) {
QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi->kind); QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi->kind);
NSButton *bc = (NSButton *)cocoaControl(cw); NSButton *bc = (NSButton *)cocoaControl(cw);
[bc highlight:pressed]; [bc highlight:pressed];
@ -2035,7 +2005,7 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD
rect.adjust(0, 0, -5, 0); rect.adjust(0, 0, -5, 0);
drawNSViewInRect(cw, bc, rect, p); drawNSViewInRect(cw, bc, rect, p);
return; return;
} else if (usingYosemiteOrLater && (editableCombo || viewItem)) { } else if (editableCombo || viewItem) {
QImage image = activePixmap.toImage(); QImage image = activePixmap.toImage();
for (int y = 0; y < height; ++y) { for (int y = 0; y < height; ++y) {
@ -3593,7 +3563,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
QWindow *window = w && w->window() ? w->window()->windowHandle() : QWindow *window = w && w->window() ? w->window()->windowHandle() :
QStyleHelper::styleObjectWindow(opt->styleObject); QStyleHelper::styleObjectWindow(opt->styleObject);
const_cast<QMacStylePrivate *>(d)->resolveCurrentNSView(window); const_cast<QMacStylePrivate *>(d)->resolveCurrentNSView(window);
const bool usingYosemiteOrLater = QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite;
switch (ce) { switch (ce) {
case CE_HeaderSection: case CE_HeaderSection:
if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
@ -3814,10 +3783,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
// takes precedence over a normal default button // takes precedence over a normal default button
if (btn->features & QStyleOptionButton::AutoDefaultButton if (btn->features & QStyleOptionButton::AutoDefaultButton
&& opt->state & State_Active && opt->state & State_HasFocus) { && opt->state & State_Active && opt->state & State_HasFocus) {
if (usingYosemiteOrLater) d->autoDefaultButton = opt->styleObject;
d->autoDefaultButton = opt->styleObject;
else
d->setAutoDefaultButton(opt->styleObject);
} else if (d->autoDefaultButton == opt->styleObject) { } else if (d->autoDefaultButton == opt->styleObject) {
d->setAutoDefaultButton(0); d->setAutoDefaultButton(0);
} }
@ -3825,8 +3791,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
if (!d->autoDefaultButton) { if (!d->autoDefaultButton) {
if (btn->features & QStyleOptionButton::DefaultButton && opt->state & State_Active) { if (btn->features & QStyleOptionButton::DefaultButton && opt->state & State_Active) {
d->defaultButton = opt->styleObject; d->defaultButton = opt->styleObject;
if (!usingYosemiteOrLater && !d->animation(opt->styleObject))
d->startAnimation(new QStyleAnimation(opt->styleObject));
} else if (d->defaultButton == opt->styleObject) { } else if (d->defaultButton == opt->styleObject) {
if (QStyleAnimation *animation = d->animation(opt->styleObject)) { if (QStyleAnimation *animation = d->animation(opt->styleObject)) {
animation->updateTarget(); animation->updateTarget();
@ -3847,42 +3811,18 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
HIThemeButtonDrawInfo bdi; HIThemeButtonDrawInfo bdi;
d->initHIThemePushButton(btn, w, tds, &bdi); d->initHIThemePushButton(btn, w, tds, &bdi);
if (usingYosemiteOrLater) { if (!hasMenu) {
if (!hasMenu) { // HITheme is not drawing a nice focus frame around buttons.
// HITheme is not drawing a nice focus frame around buttons. // We'll do it ourselves further down.
// We'll do it ourselves further down. bdi.adornment &= ~kThemeAdornmentFocus;
bdi.adornment &= ~kThemeAdornmentFocus;
// We can't rely on an animation existing to test for the default look. That means a bit // We can't rely on an animation existing to test for the default look. That means a bit
// more logic (notice that the logic is slightly different for the bevel and the label). // more logic (notice that the logic is slightly different for the bevel and the label).
if (tds == kThemeStateActive if (tds == kThemeStateActive
&& (btn->features & QStyleOptionButton::DefaultButton && (btn->features & QStyleOptionButton::DefaultButton
|| (btn->features & QStyleOptionButton::AutoDefaultButton || (btn->features & QStyleOptionButton::AutoDefaultButton
&& d->autoDefaultButton == btn->styleObject))) && d->autoDefaultButton == btn->styleObject)))
bdi.adornment |= kThemeAdornmentDefault; bdi.adornment |= kThemeAdornmentDefault;
}
} else {
// the default button animation is paused meanwhile any button
// is pressed or an auto-default button is animated instead
if (QStyleAnimation *defaultAnimation = d->animation(d->defaultButton)) {
if (d->pressedButton || d->autoDefaultButton) {
if (defaultAnimation->state() == QStyleAnimation::Running) {
defaultAnimation->pause();
defaultAnimation->updateTarget();
}
} else if (defaultAnimation->state() == QStyleAnimation::Paused) {
defaultAnimation->resume();
}
}
if (!d->pressedButton) {
QStyleAnimation* animation = d->animation(opt->styleObject);
if (animation && animation->state() == QStyleAnimation::Running) {
bdi.adornment |= kThemeAdornmentDefault;
bdi.animation.time.start = d->defaultButtonStart;
bdi.animation.time.current = CFAbsoluteTimeGetCurrent();
}
}
} }
// Unlike Carbon, we want the button to always be drawn inside its bounds. // Unlike Carbon, we want the button to always be drawn inside its bounds.
@ -3900,7 +3840,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
newRect.size.width -= QMacStylePrivate::PushButtonRightOffset - 4; newRect.size.width -= QMacStylePrivate::PushButtonRightOffset - 4;
} }
if (hasMenu && usingYosemiteOrLater && bdi.kind != kThemeBevelButton) { if (hasMenu && bdi.kind != kThemeBevelButton) {
QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi.kind); QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi.kind);
cw.first = QCocoaPullDownButton; cw.first = QCocoaPullDownButton;
NSPopUpButton *pdb = (NSPopUpButton *)d->cocoaControl(cw); NSPopUpButton *pdb = (NSPopUpButton *)d->cocoaControl(cw);
@ -3914,7 +3854,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
else else
HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0); HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0);
if (usingYosemiteOrLater && btn->state & State_HasFocus) { if (btn->state & State_HasFocus) {
CGRect focusRect = newRect; CGRect focusRect = newRect;
if (bdi.kind == kThemePushButton) if (bdi.kind == kThemePushButton)
focusRect.size.height += 1; // Another thing HITheme and Cocoa seem to disagree about. focusRect.size.height += 1; // Another thing HITheme and Cocoa seem to disagree about.
@ -3944,7 +3884,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
d->drawFocusRing(p, focusTargetRect.adjusted(-hMargin, -vMargin, hMargin, vMargin), hMargin, vMargin, radius); d->drawFocusRing(p, focusTargetRect.adjusted(-hMargin, -vMargin, hMargin, vMargin), hMargin, vMargin, radius);
} }
if (hasMenu && (!usingYosemiteOrLater || bdi.kind == kThemeBevelButton)) { if (hasMenu && bdi.kind == kThemeBevelButton) {
int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w); int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w);
QRect ir = btn->rect; QRect ir = btn->rect;
int arrowXOffset = bdi.kind == kThemePushButton ? 6 : int arrowXOffset = bdi.kind == kThemePushButton ? 6 :
@ -3985,7 +3925,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
bool hasIcon = !btn.icon.isNull(); bool hasIcon = !btn.icon.isNull();
bool hasText = !btn.text.isEmpty(); bool hasText = !btn.text.isEmpty();
if (!hasMenu && QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite) { if (!hasMenu) {
if (tds == kThemeStatePressed if (tds == kThemeStatePressed
|| (tds == kThemeStateActive || (tds == kThemeStateActive
&& ((btn.features & QStyleOptionButton::DefaultButton && !d->autoDefaultButton) && ((btn.features & QStyleOptionButton::DefaultButton && !d->autoDefaultButton)
@ -4089,11 +4029,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
QStyleOptionComboBox comboCopy = *cb; QStyleOptionComboBox comboCopy = *cb;
comboCopy.direction = Qt::LeftToRight; comboCopy.direction = Qt::LeftToRight;
if (opt->state & QStyle::State_Small)
comboCopy.rect.translate(0, w ? 0 : (QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite ? 0 : -2)); // Supports Qt Quick Controls
else if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXMavericks
&& QOperatingSystemVersion::current() < QOperatingSystemVersion::OSXYosemite)
comboCopy.rect.translate(0, 1);
QCommonStyle::drawControl(CE_ComboBoxLabel, &comboCopy, p, w); QCommonStyle::drawControl(CE_ComboBoxLabel, &comboCopy, p, w);
} }
break; break;
@ -4156,12 +4091,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
tdi.adornment = kHIThemeTabAdornmentNone; tdi.adornment = kHIThemeTabAdornmentNone;
tdi.kind = kHIThemeTabKindNormal; tdi.kind = kHIThemeTabKindNormal;
if (!usingYosemiteOrLater) {
if (!verticalTabs)
tabRect.setY(tabRect.y() - 1);
else
tabRect.setX(tabRect.x() - 1);
}
QStyleOptionTab::TabPosition tp = tabOpt->position; QStyleOptionTab::TabPosition tp = tabOpt->position;
QStyleOptionTab::SelectedPosition sp = tabOpt->selectedPosition; QStyleOptionTab::SelectedPosition sp = tabOpt->selectedPosition;
if (tabOpt->direction == Qt::RightToLeft && !verticalTabs) { if (tabOpt->direction == Qt::RightToLeft && !verticalTabs) {
@ -4225,15 +4154,13 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
QStyleOptionTab myTab = *tab; QStyleOptionTab myTab = *tab;
ThemeTabDirection ttd = getTabDirection(myTab.shape); ThemeTabDirection ttd = getTabDirection(myTab.shape);
bool verticalTabs = ttd == kThemeTabWest || ttd == kThemeTabEast; bool verticalTabs = ttd == kThemeTabWest || ttd == kThemeTabEast;
bool selected = (myTab.state & QStyle::State_Selected);
// Check to see if we use have the same as the system font // Check to see if we use have the same as the system font
// (QComboMenuItem is internal and should never be seen by the // (QComboMenuItem is internal and should never be seen by the
// outside world, unless they read the source, in which case, it's // outside world, unless they read the source, in which case, it's
// their own fault). // their own fault).
bool nonDefaultFont = p->font() != qt_app_fonts_hash()->value("QComboMenuItem"); bool nonDefaultFont = p->font() != qt_app_fonts_hash()->value("QComboMenuItem");
bool isSelectedAndNeedsShadow = selected && !usingYosemiteOrLater; if (verticalTabs || nonDefaultFont || !tab->icon.isNull()
if (isSelectedAndNeedsShadow || verticalTabs || nonDefaultFont || !tab->icon.isNull()
|| !myTab.leftButtonSize.isEmpty() || !myTab.rightButtonSize.isEmpty()) { || !myTab.leftButtonSize.isEmpty() || !myTab.rightButtonSize.isEmpty()) {
int heightOffset = 0; int heightOffset = 0;
if (verticalTabs) { if (verticalTabs) {
@ -4244,7 +4171,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
} }
myTab.rect.setHeight(myTab.rect.height() + heightOffset); myTab.rect.setHeight(myTab.rect.height() + heightOffset);
if (myTab.documentMode || isSelectedAndNeedsShadow) { if (myTab.documentMode) {
p->save(); p->save();
rotateTabPainter(p, myTab.shape, myTab.rect); rotateTabPainter(p, myTab.shape, myTab.rect);
@ -4633,7 +4560,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
tdi.value = pb->progress; tdi.value = pb->progress;
tdi.attributes = vertical ? 0 : kThemeTrackHorizontal; tdi.attributes = vertical ? 0 : kThemeTrackHorizontal;
if (isIndeterminate || (tdi.value < tdi.max && !usingYosemiteOrLater)) { if (isIndeterminate) {
if (QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject))) if (QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject)))
tdi.trackInfo.progress.phase = animation->animationStep(); tdi.trackInfo.progress.phase = animation->animationStep();
else if (opt->styleObject) else if (opt->styleObject)
@ -4715,8 +4642,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
HIThemeSplitterDrawInfo sdi; HIThemeSplitterDrawInfo sdi;
sdi.version = qt_mac_hitheme_version; sdi.version = qt_mac_hitheme_version;
sdi.state = tds; sdi.state = tds;
sdi.adornment = qt_mac_is_metal(w) || usingYosemiteOrLater ? sdi.adornment = kHIThemeSplitterAdornmentMetal;
kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone;
HIRect hirect = qt_hirectForQRect(opt->rect); HIRect hirect = qt_hirectForQRect(opt->rect);
HIThemeDrawPaneSplitter(&hirect, &sdi, cg, kHIThemeOrientationNormal); HIThemeDrawPaneSplitter(&hirect, &sdi, cg, kHIThemeOrientationNormal);
} else { } else {
@ -5266,7 +5192,6 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
QWindow *window = widget && widget->window() ? widget->window()->windowHandle() : QWindow *window = widget && widget->window() ? widget->window()->windowHandle() :
QStyleHelper::styleObjectWindow(opt->styleObject); QStyleHelper::styleObjectWindow(opt->styleObject);
const_cast<QMacStylePrivate *>(d)->resolveCurrentNSView(window); const_cast<QMacStylePrivate *>(d)->resolveCurrentNSView(window);
const bool usingYosemiteOrLater = QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite;
switch (cc) { switch (cc) {
case CC_Slider: case CC_Slider:
case CC_ScrollBar: case CC_ScrollBar:
@ -5511,7 +5436,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
} else { } else {
d->stopAnimation(opt->styleObject); d->stopAnimation(opt->styleObject);
if (usingYosemiteOrLater && cc == CC_Slider) { if (cc == CC_Slider) {
// Fix min and max positions. (See also getSliderInfo() // Fix min and max positions. (See also getSliderInfo()
// for the slider values adjustments.) // for the slider values adjustments.)
// HITheme seems to have forgotten how to render // HITheme seems to have forgotten how to render
@ -5574,22 +5499,20 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
if (cc == CC_Slider && slider->subControls & SC_SliderTickmarks) { if (cc == CC_Slider && slider->subControls & SC_SliderTickmarks) {
HIRect bounds; HIRect bounds;
if (usingYosemiteOrLater) { // As part of fixing the min and max positions,
// As part of fixing the min and max positions, // we need to adjust the tickmarks as well
// we need to adjust the tickmarks as well bounds = tdi.bounds;
bounds = tdi.bounds; if (slider->orientation == Qt::Horizontal) {
if (slider->orientation == Qt::Horizontal) { tdi.bounds.size.width += 2;
tdi.bounds.size.width += 2; tdi.bounds.origin.x -= 1;
tdi.bounds.origin.x -= 1; if (tdi.trackInfo.slider.thumbDir == kThemeThumbUpward)
if (tdi.trackInfo.slider.thumbDir == kThemeThumbUpward) tdi.bounds.origin.y -= 2;
tdi.bounds.origin.y -= 2; } else {
} else { tdi.bounds.size.height += 3;
tdi.bounds.size.height += 3; tdi.bounds.origin.y -= 3;
tdi.bounds.origin.y -= 3; tdi.bounds.origin.y += 1;
tdi.bounds.origin.y += 1; if (tdi.trackInfo.slider.thumbDir == kThemeThumbUpward) // pointing left
if (tdi.trackInfo.slider.thumbDir == kThemeThumbUpward) // pointing left tdi.bounds.origin.x -= 2;
tdi.bounds.origin.x -= 2;
}
} }
if (qt_mac_is_metal(widget)) { if (qt_mac_is_metal(widget)) {
@ -5613,10 +5536,9 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
cg, cg,
kHIThemeOrientationNormal); kHIThemeOrientationNormal);
tdi.trackInfo.slider.thumbDir = kThemeThumbUpward; tdi.trackInfo.slider.thumbDir = kThemeThumbUpward;
if (usingYosemiteOrLater) { // 10.10 and above need a slight shift
if (slider->orientation == Qt::Vertical) if (slider->orientation == Qt::Vertical)
tdi.bounds.origin.x -= 2; tdi.bounds.origin.x -= 2;
}
HIThemeDrawTrackTickMarks(&tdi, numMarks, HIThemeDrawTrackTickMarks(&tdi, numMarks,
cg, cg,
kHIThemeOrientationNormal); kHIThemeOrientationNormal);
@ -5628,11 +5550,10 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
kHIThemeOrientationNormal); kHIThemeOrientationNormal);
} }
if (usingYosemiteOrLater) tdi.bounds = bounds;
tdi.bounds = bounds;
} }
if (usingYosemiteOrLater && cc == CC_Slider) { if (cc == CC_Slider) {
// Still as part of fixing the min and max positions, // Still as part of fixing the min and max positions,
// we also adjust the knob position. We can do this // we also adjust the knob position. We can do this
// because it's rendered separately from the track. // because it's rendered separately from the track.
@ -5724,11 +5645,11 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
HIThemeButtonDrawInfo bdi; HIThemeButtonDrawInfo bdi;
d->initComboboxBdi(combo, &bdi, widget, tds); d->initComboboxBdi(combo, &bdi, widget, tds);
HIRect rect = qt_hirectForQRect(combo->rect); HIRect rect = qt_hirectForQRect(combo->rect);
if (combo->editable && usingYosemiteOrLater) if (combo->editable)
rect.origin.y += tds == kThemeStateInactive ? 1 : 2; rect.origin.y += tds == kThemeStateInactive ? 1 : 2;
if (tds != kThemeStateInactive) if (tds != kThemeStateInactive)
QMacStylePrivate::drawCombobox(rect, bdi, p); QMacStylePrivate::drawCombobox(rect, bdi, p);
else if (!widget && combo->editable && usingYosemiteOrLater) { else if (!widget && combo->editable) {
QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi.kind); QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi.kind);
NSView *cb = d->cocoaControl(cw); NSView *cb = d->cocoaControl(cw);
QRect r = combo->rect.adjusted(3, 0, 0, 0); QRect r = combo->rect.adjusted(3, 0, 0, 0);
@ -5910,31 +5831,23 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
drawToolbarButtonArrow(tb->rect, tds, cg); drawToolbarButtonArrow(tb->rect, tds, cg);
} }
if (tb->state & State_On) { if (tb->state & State_On) {
if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite) { QWindow *window = 0;
QWindow *window = 0; if (widget && widget->window())
if (widget && widget->window()) window = widget->window()->windowHandle();
window = widget->window()->windowHandle(); else if (opt->styleObject)
else if (opt->styleObject) window = opt->styleObject->property("_q_styleObjectWindow").value<QWindow *>();
window = opt->styleObject->property("_q_styleObjectWindow").value<QWindow *>();
NSView *view = window ? (NSView *)window->winId() : nil; NSView *view = window ? (NSView *)window->winId() : nil;
bool isKey = false; bool isKey = false;
if (view) if (view)
isKey = [view.window isKeyWindow]; isKey = [view.window isKeyWindow];
QBrush brush(isKey ? QColor(0, 0, 0, 28) QBrush brush(isKey ? QColor(0, 0, 0, 28)
: QColor(0, 0, 0, 21)); : QColor(0, 0, 0, 21));
QPainterPath path; QPainterPath path;
path.addRoundedRect(QRectF(tb->rect.x(), tb->rect.y(), tb->rect.width(), tb->rect.height() + 4), 4, 4); path.addRoundedRect(QRectF(tb->rect.x(), tb->rect.y(), tb->rect.width(), tb->rect.height() + 4), 4, 4);
p->setRenderHint(QPainter::Antialiasing); p->setRenderHint(QPainter::Antialiasing);
p->fillPath(path, brush); p->fillPath(path, brush);
} else {
static QPixmap pm(QLatin1String(":/qt-project.org/mac/style/images/leopard-unified-toolbar-on.png"));
p->save();
p->setRenderHint(QPainter::SmoothPixmapTransform);
QStyleHelper::drawBorderPixmap(pm, p, tb->rect, 2, 2, 2, 2);
p->restore();
}
} }
proxy()->drawControl(CE_ToolButtonLabel, opt, p, widget); proxy()->drawControl(CE_ToolButtonLabel, opt, p, widget);
} else { } else {
@ -6274,8 +6187,8 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op
switch (sc) { switch (sc) {
case SC_ComboBoxEditField:{ case SC_ComboBoxEditField:{
ret = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi); ret = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi);
if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::OSXYosemite) // 10.10 and above need a slight shift
ret.setHeight(ret.height() - 1); ret.setHeight(ret.height() - 1);
break; } break; }
case SC_ComboBoxArrow:{ case SC_ComboBoxArrow:{
ret = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi); ret = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi);
@ -6733,7 +6646,7 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
case CT_ComboBox: { case CT_ComboBox: {
sz.rwidth() += 50; sz.rwidth() += 50;
const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt); const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt);
if (QOperatingSystemVersion::current() < QOperatingSystemVersion::OSXYosemite || (cb && !cb->editable)) if (cb && !cb->editable)
sz.rheight() += 2; sz.rheight() += 2;
break; break;
} }