From b5ae9d8efec8e71ca52db7a142195c2ee37e68f9 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 22 Sep 2014 16:50:19 +0200 Subject: QMacStyle: Improvements to some buttons on Yosemite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Radio button, checkbox and non-editable combobox, in normal, small and mini sizes, and only in the inactive state. This commit amends 982b9b7ec2441103b100. Task-number: QTBUG-40833 Change-Id: If3f2bb215e9b8966cbf15f08fa252feb92483c7b Reviewed-by: Morten Johan Sørvig --- src/widgets/styles/qmacstyle_mac.mm | 78 ++++++++++++++++++++++++++-------- src/widgets/styles/qmacstyle_mac_p_p.h | 2 +- 2 files changed, 62 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index c7b9186e34..60e18eae5a 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -1738,11 +1738,13 @@ ThemeDrawState QMacStylePrivate::getDrawState(QStyle::State flags) return tds; } -NSView *QMacStylePrivate::buttonOfKind(ThemeButtonKind kind) const +NSView *QMacStylePrivate::buttonOfKind(ThemeButtonKind kind, QPoint *offset) const { NSView *bv = buttons[kind]; if (!bv) { - if (kind == kThemePopupButton) + if (kind == kThemePopupButton + || kind == kThemePopupButtonSmall + || kind == kThemePopupButtonMini) bv = [[NSPopUpButton alloc] init]; else if (kind == kThemeComboBox) bv = [[NSComboBox alloc] init]; @@ -1782,25 +1784,61 @@ NSView *QMacStylePrivate::buttonOfKind(ThemeButtonKind kind) const break; } -// if (kind == kThemePushButtonSmall -// || kind == kThemePopupButtonSmall -// || kind == kThemeCheckBoxSmall -// || kind == kThemeRadioButtonSmall) -// bc.controlSize = NSSmallControlSize; -// else if (kind == kThemePushButtonMini -// || kind == kThemePopupButtonMini -// || kind == kThemeCheckBoxMini -// || kind == kThemeRadioButtonMini) -// bc.controlSize = NSMiniControlSize; - if ([bv isKindOfClass:[NSButton class]]) { NSButton *bc = (NSButton *)bv; bc.title = nil; + + NSCell *bcell = bc.cell; + switch (kind) { + case kThemePushButtonSmall: + case kThemePopupButtonSmall: + case kThemeCheckBoxSmall: + case kThemeRadioButtonSmall: + bcell.controlSize = NSSmallControlSize; + break; + case kThemePushButtonMini: + case kThemePopupButtonMini: + case kThemeCheckBoxMini: + case kThemeRadioButtonMini: + bcell.controlSize = NSMiniControlSize; + break; + default: + break; + } } const_cast(this)->buttons.insert(kind, bv); } + if (offset) { + switch (kind) { + case kThemeRadioButton: + offset->setY(2); + break; + case kThemeRadioButtonSmall: + *offset = QPoint(-1, 2); + break; + case kThemeRadioButtonMini: + offset->setY(2); + break; + case kThemePopupButtonSmall: + case kThemeCheckBox: + offset->setY(1); + break; + case kThemeCheckBoxSmall: + offset->setX(-1); + break; + case kThemeCheckBoxMini: + *offset = QPoint(7, 5); + break; + case kThemePopupButtonMini: + *offset = QPoint(2, -1); + break; + default: + break; + } + } + return bv; } @@ -1917,14 +1955,20 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD } pm = QPixmap::fromImage(image); } else if ((usingYosemiteOrLater && combo && !editableCombo) || button) { - NSButton *bc = (NSButton *)buttonOfKind(bdi->kind); + QPoint offset; + NSButton *bc = (NSButton *)buttonOfKind(bdi->kind, &offset); [bc highlight:pressed]; bc.enabled = bdi->state != kThemeStateUnavailable && bdi->state != kThemeStateUnavailableInactive; + bc.allowsMixedState = YES; bc.state = bdi->value == kThemeButtonOn ? NSOnState : bdi->value == kThemeButtonMixed ? NSMixedState : NSOffState; - p->translate(0, 1); - drawNSViewInRect(bc, opt->rect, p); - p->translate(0, -1); + // The view frame may differ from what we pass to HITheme + QRect rect = opt->rect; + if (bdi->kind == kThemePopupButtonMini) + rect.adjust(0, 0, -5, 0); + p->translate(offset); + drawNSViewInRect(bc, rect, p); + p->translate(-offset); return; } else if (usingYosemiteOrLater && editableCombo) { QImage image = activePixmap.toImage(); diff --git a/src/widgets/styles/qmacstyle_mac_p_p.h b/src/widgets/styles/qmacstyle_mac_p_p.h index 3bbff61340..e4aad113d0 100644 --- a/src/widgets/styles/qmacstyle_mac_p_p.h +++ b/src/widgets/styles/qmacstyle_mac_p_p.h @@ -195,7 +195,7 @@ public: void setAutoDefaultButton(QObject *button) const; - NSView *buttonOfKind(ThemeButtonKind kind) const; + NSView *buttonOfKind(ThemeButtonKind kind, QPoint *offset) const; void drawNSViewInRect(NSView *view, const QRect &rect, QPainter *p) const; void resolveCurrentNSView(QWindow *window); -- cgit v1.2.3