QMacStyle: Improvements to some buttons on Yosemite

Radio button, checkbox and non-editable combobox, in normal,
small and mini sizes, and only in the inactive state.

This commit amends 982b9b7ec2.

Task-number: QTBUG-40833
Change-Id: If3f2bb215e9b8966cbf15f08fa252feb92483c7b
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
bb10
Gabriel de Dietrich 2014-09-22 16:50:19 +02:00
parent 3b3ecb79a6
commit b5ae9d8efe
2 changed files with 62 additions and 18 deletions

View File

@ -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<QMacStylePrivate *>(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();

View File

@ -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);