QMacStyle: Refactor QMacStylePrivate::cocoaControl()
That switch following the if looked a bit corny. Also made cocoaCells hash mutable to get rid of the const_cast(this) in QMSP::cocoaCell(). Change-Id: I4facec827409314cf1214152c19efb9688715eb2 Reviewed-by: Jake Petroules <jake.petroules@qt.io>
This commit is contained in:
parent
bccbb52b7a
commit
475243a746
@ -1922,85 +1922,85 @@ static QCocoaWidget cocoaWidgetFromHIThemeButtonKind(ThemeButtonKind kind)
|
|||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static NSButton *makeButton(NSButtonType type, NSBezelStyle style)
|
||||||
|
{
|
||||||
|
NSButton *b = [[NSButton alloc] init];
|
||||||
|
b.title = @"";
|
||||||
|
b.buttonType = type;
|
||||||
|
b.bezelStyle = style;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
NSView *QMacStylePrivate::cocoaControl(QCocoaWidget widget) const
|
NSView *QMacStylePrivate::cocoaControl(QCocoaWidget widget) const
|
||||||
{
|
{
|
||||||
NSView *bv = cocoaControls[widget];
|
NSView *bv = cocoaControls.value(widget, nil);
|
||||||
if (!bv) {
|
|
||||||
|
|
||||||
if (widget.first == QCocoaPopupButton
|
if (!bv) {
|
||||||
|| widget.first == QCocoaPullDownButton)
|
switch (widget.first) {
|
||||||
bv = [[NSPopUpButton alloc] init];
|
case QCocoaCheckBox:
|
||||||
else if (widget.first == QCocoaComboBox)
|
bv = makeButton(NSSwitchButton, NSRegularSquareBezelStyle);
|
||||||
|
break;
|
||||||
|
case QCocoaDisclosureButton:
|
||||||
|
bv = makeButton(NSOnOffButton, NSDisclosureBezelStyle);
|
||||||
|
break;
|
||||||
|
case QCocoaPopupButton:
|
||||||
|
case QCocoaPullDownButton: {
|
||||||
|
NSPopUpButton *bc = [[NSPopUpButton alloc] init];
|
||||||
|
bc.title = @"";
|
||||||
|
if (widget.first == QCocoaPullDownButton)
|
||||||
|
bc.pullsDown = YES;
|
||||||
|
bv = bc;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QCocoaPushButton:
|
||||||
|
bv = makeButton(NSMomentaryLightButton, NSRoundedBezelStyle);
|
||||||
|
break;
|
||||||
|
case QCocoaRadioButton:
|
||||||
|
bv = makeButton(NSRadioButton, NSRegularSquareBezelStyle);
|
||||||
|
break;
|
||||||
|
case QCocoaComboBox:
|
||||||
bv = [[NSComboBox alloc] init];
|
bv = [[NSComboBox alloc] init];
|
||||||
else if (widget.first == QCocoaProgressIndicator)
|
break;
|
||||||
|
case QCocoaProgressIndicator:
|
||||||
bv = [[NSProgressIndicator alloc] init];
|
bv = [[NSProgressIndicator alloc] init];
|
||||||
else if (widget.first == QCocoaIndeterminateProgressIndicator)
|
break;
|
||||||
|
case QCocoaIndeterminateProgressIndicator:
|
||||||
bv = [[QIndeterminateProgressIndicator alloc] init];
|
bv = [[QIndeterminateProgressIndicator alloc] init];
|
||||||
else if (widget.first == QCocoaHorizontalScroller)
|
break;
|
||||||
|
case QCocoaHorizontalScroller:
|
||||||
bv = [[NSScroller alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)];
|
bv = [[NSScroller alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)];
|
||||||
else if (widget.first == QCocoaVerticalScroller)
|
break;
|
||||||
|
case QCocoaVerticalScroller:
|
||||||
// Cocoa sets the orientation from the view's frame
|
// Cocoa sets the orientation from the view's frame
|
||||||
// at construction time, and it cannot be changed later.
|
// at construction time, and it cannot be changed later.
|
||||||
bv = [[NSScroller alloc] initWithFrame:NSMakeRect(0, 0, 20, 200)];
|
bv = [[NSScroller alloc] initWithFrame:NSMakeRect(0, 0, 20, 200)];
|
||||||
else if (widget.first == QCocoaHorizontalSlider)
|
break;
|
||||||
|
case QCocoaHorizontalSlider:
|
||||||
bv = [[NSSlider alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)];
|
bv = [[NSSlider alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)];
|
||||||
else if (widget.first == QCocoaVerticalSlider)
|
break;
|
||||||
|
case QCocoaVerticalSlider:
|
||||||
// Cocoa sets the orientation from the view's frame
|
// Cocoa sets the orientation from the view's frame
|
||||||
// at construction time, and it cannot be changed later.
|
// at construction time, and it cannot be changed later.
|
||||||
bv = [[NSSlider alloc] initWithFrame:NSMakeRect(0, 0, 20, 200)];
|
bv = [[NSSlider alloc] initWithFrame:NSMakeRect(0, 0, 20, 200)];
|
||||||
else
|
|
||||||
bv = [[NSButton alloc] init];
|
|
||||||
|
|
||||||
switch (widget.first) {
|
|
||||||
case QCocoaDisclosureButton: {
|
|
||||||
NSButton *bc = (NSButton *)bv;
|
|
||||||
bc.buttonType = NSOnOffButton;
|
|
||||||
bc.bezelStyle = NSDisclosureBezelStyle;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case QCocoaCheckBox: {
|
|
||||||
NSButton *bc = (NSButton *)bv;
|
|
||||||
bc.buttonType = NSSwitchButton;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QCocoaRadioButton: {
|
|
||||||
NSButton *bc = (NSButton *)bv;
|
|
||||||
bc.buttonType = NSRadioButton;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QCocoaPushButton: {
|
|
||||||
NSButton *bc = (NSButton *)bv;
|
|
||||||
bc.buttonType = NSMomentaryLightButton;
|
|
||||||
bc.bezelStyle = NSRoundedBezelStyle;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QCocoaPullDownButton: {
|
|
||||||
NSPopUpButton *bc = (NSPopUpButton *)bv;
|
|
||||||
bc.pullsDown = YES;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([bv isKindOfClass:[NSButton class]]) {
|
|
||||||
NSButton *bc = (NSButton *)bv;
|
|
||||||
bc.title = @"";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([bv isKindOfClass:[NSControl class]]) {
|
if ([bv isKindOfClass:[NSControl class]]) {
|
||||||
NSCell *bcell = [(NSControl *)bv cell];
|
auto *ctrl = static_cast<NSControl *>(bv);
|
||||||
switch (widget.second) {
|
switch (widget.second) {
|
||||||
case QStyleHelper::SizeSmall:
|
case QStyleHelper::SizeSmall:
|
||||||
bcell.controlSize = NSSmallControlSize;
|
ctrl.controlSize = NSSmallControlSize;
|
||||||
break;
|
break;
|
||||||
case QStyleHelper::SizeMini:
|
case QStyleHelper::SizeMini:
|
||||||
bcell.controlSize = NSMiniControlSize;
|
ctrl.controlSize = NSMiniControlSize;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if ([bv isKindOfClass:[NSProgressIndicator class]]) {
|
} else if (widget.first == QCocoaProgressIndicator ||
|
||||||
|
widget.first == QCocoaIndeterminateProgressIndicator) {
|
||||||
auto *pi = static_cast<NSProgressIndicator *>(bv);
|
auto *pi = static_cast<NSProgressIndicator *>(bv);
|
||||||
pi.indeterminate = (widget.first == QCocoaIndeterminateProgressIndicator);
|
pi.indeterminate = (widget.first == QCocoaIndeterminateProgressIndicator);
|
||||||
switch (widget.second) {
|
switch (widget.second) {
|
||||||
@ -2015,7 +2015,7 @@ NSView *QMacStylePrivate::cocoaControl(QCocoaWidget widget) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const_cast<QMacStylePrivate *>(this)->cocoaControls.insert(widget, bv);
|
cocoaControls.insert(widget, bv);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bv;
|
return bv;
|
||||||
@ -2051,7 +2051,7 @@ NSCell *QMacStylePrivate::cocoaCell(QCocoaWidget widget) const
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const_cast<QMacStylePrivate *>(this)->cocoaCells.insert(widget, cell);
|
cocoaCells.insert(widget, cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cell;
|
return cell;
|
||||||
|
@ -283,8 +283,8 @@ public:
|
|||||||
mutable QPointer<QFocusFrame> focusWidget;
|
mutable QPointer<QFocusFrame> focusWidget;
|
||||||
QT_MANGLE_NAMESPACE(NotificationReceiver) *receiver;
|
QT_MANGLE_NAMESPACE(NotificationReceiver) *receiver;
|
||||||
NSView *backingStoreNSView;
|
NSView *backingStoreNSView;
|
||||||
QHash<QCocoaWidget, NSView *> cocoaControls;
|
mutable QHash<QCocoaWidget, NSView *> cocoaControls;
|
||||||
QHash<QCocoaWidget, NSCell *> cocoaCells;
|
mutable QHash<QCocoaWidget, NSCell *> cocoaCells;
|
||||||
|
|
||||||
QFont smallSystemFont;
|
QFont smallSystemFont;
|
||||||
QFont miniSystemFont;
|
QFont miniSystemFont;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user