QMacStyle: checkbox, radio button are now HITheme-free
This also fixes focus ring thickness on retina displays except for radio button, for which we don't allocate enough space around. Instead of going down the push button madness we currently have, we leave it as is (i.e., slightly truncated) until we can come up with a more sane solution regarding focus rings. Change-Id: Icd4aa2e08c2558768c91efd7d119879e249b052f Reviewed-by: Jake Petroules <jake.petroules@qt.io>
This commit is contained in:
parent
909cac6174
commit
90c9370d50
@ -2311,7 +2311,7 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW
|
|||||||
|
|
||||||
case PM_CheckBoxLabelSpacing:
|
case PM_CheckBoxLabelSpacing:
|
||||||
case PM_RadioButtonLabelSpacing:
|
case PM_RadioButtonLabelSpacing:
|
||||||
ret = 2;
|
ret = 4;
|
||||||
break;
|
break;
|
||||||
case PM_MenuScrollerHeight:
|
case PM_MenuScrollerHeight:
|
||||||
ret = 15; // I hate having magic numbers in here...
|
ret = 15; // I hate having magic numbers in here...
|
||||||
@ -3253,49 +3253,37 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
|
|||||||
case PE_IndicatorViewItemCheck:
|
case PE_IndicatorViewItemCheck:
|
||||||
case PE_IndicatorRadioButton:
|
case PE_IndicatorRadioButton:
|
||||||
case PE_IndicatorCheckBox: {
|
case PE_IndicatorCheckBox: {
|
||||||
bool drawColorless = tds == kThemeStateInactive;
|
const bool isEnabled = opt->state & State_Enabled;
|
||||||
HIThemeButtonDrawInfo bdi;
|
const bool isPressed = opt->state & State_Sunken;
|
||||||
bdi.version = qt_mac_hitheme_version;
|
const bool isRadioButton = (pe == PE_IndicatorRadioButton);
|
||||||
bdi.state = tds;
|
const auto ct = isRadioButton ? QMacStylePrivate::Button_RadioButton : QMacStylePrivate::Button_CheckBox;
|
||||||
if (drawColorless)
|
const auto cs = d->effectiveAquaSizeConstrain(opt, w);
|
||||||
bdi.state = kThemeStateActive;
|
const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
|
||||||
bdi.adornment = kThemeDrawIndicatorOnly;
|
auto *tb = static_cast<NSButton *>(d->cocoaControl(cw));
|
||||||
if (opt->state & State_HasFocus)
|
tb.enabled = isEnabled;
|
||||||
bdi.adornment |= kThemeAdornmentFocus;
|
tb.state = (opt->state & State_NoChange) ? NSMixedState :
|
||||||
bool isRadioButton = (pe == PE_IndicatorRadioButton);
|
(opt->state & State_On) ? NSOnState : NSOffState;
|
||||||
switch (d->aquaSizeConstrain(opt, w)) {
|
[tb highlight:isPressed];
|
||||||
case QStyleHelper::SizeDefault:
|
d->drawNSViewInRect(cw, tb, opt->rect, p, w != nullptr, ^(CGContextRef ctx, const CGRect &rect) {
|
||||||
case QStyleHelper::SizeLarge:
|
CGContextTranslateCTM(ctx, 2, isRadioButton ? -2 : -1);
|
||||||
if (isRadioButton)
|
[tb.cell drawInteriorWithFrame:rect inView:tb];
|
||||||
bdi.kind = kThemeRadioButton;
|
if (opt->state & State_HasFocus) {
|
||||||
else
|
CGContextSetAlpha(ctx, 0.5);
|
||||||
bdi.kind = kThemeCheckBox;
|
CGContextSetStrokeColorWithColor(ctx, NSColor.keyboardFocusIndicatorColor.CGColor);
|
||||||
break;
|
CGContextSetLineWidth(ctx, 3.5);
|
||||||
case QStyleHelper::SizeMini:
|
CGContextSetLineJoin(ctx, kCGLineJoinRound);
|
||||||
if (isRadioButton)
|
if (isRadioButton) {
|
||||||
bdi.kind = kThemeMiniRadioButton;
|
const auto rbRect = CGRectOffset(CGRectInset(rect, 0.25, -0.25), -0.5, 0);
|
||||||
else
|
CGContextAddEllipseInRect(ctx, rbRect);
|
||||||
bdi.kind = kThemeMiniCheckBox;
|
} else {
|
||||||
break;
|
const auto cbRect = CGRectOffset(CGRectInset(rect, 1.25, 0.75), -0.5, 0);
|
||||||
case QStyleHelper::SizeSmall:
|
CGPathRef cbPath = CGPathCreateWithRoundedRect(cbRect, 4, 4, nullptr);
|
||||||
if (isRadioButton)
|
CGContextAddPath(ctx, cbPath);
|
||||||
bdi.kind = kThemeSmallRadioButton;
|
CFRelease(cbPath);
|
||||||
else
|
}
|
||||||
bdi.kind = kThemeSmallCheckBox;
|
CGContextStrokePath(ctx);
|
||||||
break;
|
}
|
||||||
}
|
});
|
||||||
if (opt->state & State_NoChange)
|
|
||||||
bdi.value = kThemeButtonMixed;
|
|
||||||
else if (opt->state & State_On)
|
|
||||||
bdi.value = kThemeButtonOn;
|
|
||||||
else
|
|
||||||
bdi.value = kThemeButtonOff;
|
|
||||||
CGRect macRect = opt->rect.toCGRect();
|
|
||||||
const QMacStylePrivate::CocoaControl cw = QMacStylePrivate::cocoaControlFromHIThemeButtonKind(bdi.kind);
|
|
||||||
if (!drawColorless)
|
|
||||||
HIThemeDrawButton(&macRect, &bdi, cg, kHIThemeOrientationNormal, 0);
|
|
||||||
else
|
|
||||||
d->drawColorlessButton(macRect, &bdi, cw, p, opt);
|
|
||||||
break; }
|
break; }
|
||||||
case PE_FrameFocusRect:
|
case PE_FrameFocusRect:
|
||||||
// Use the our own focus widget stuff.
|
// Use the our own focus widget stuff.
|
||||||
|
Loading…
Reference in New Issue
Block a user