Introducing SH_SpinBox_ButtonsInsideFrame

This is currently only used in QMacStyle since,
on macOS, the spin-box buttons are always beside
the line-edit. Hence, there is no need to tamper
with the line-edit frame.

Change-Id: I8ccfbab547fccae89a8ddeaeb7005cb17d5951e6
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
This commit is contained in:
Gabriel de Dietrich 2018-01-24 17:13:24 -08:00
parent 3d29a0dd74
commit 80515c811a
5 changed files with 26 additions and 37 deletions

View File

@ -2387,14 +2387,6 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW
break; break;
case PM_SpinBoxFrameWidth: case PM_SpinBoxFrameWidth:
ret = qt_mac_aqua_get_metric(EditTextFrameOutset); ret = qt_mac_aqua_get_metric(EditTextFrameOutset);
switch (d->aquaSizeConstrain(opt, widget)) {
case QStyleHelper::SizeMini:
ret += 1;
break;
default:
ret += 2;
break;
}
break; break;
case PM_ButtonShiftHorizontal: case PM_ButtonShiftHorizontal:
case PM_ButtonShiftVertical: case PM_ButtonShiftVertical:
@ -3001,6 +2993,9 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w
case SH_ComboBox_AllowWheelScrolling: case SH_ComboBox_AllowWheelScrolling:
ret = false; ret = false;
break; break;
case SH_SpinBox_ButtonsInsideFrame:
ret = false;
break;
default: default:
ret = QCommonStyle::styleHint(sh, opt, w, hret); ret = QCommonStyle::styleHint(sh, opt, w, hret);
break; break;
@ -4157,16 +4152,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, w); const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, w);
const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, opt, w); const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, opt, w);
if (ct == QMacStylePrivate::Box) { if (ct == QMacStylePrivate::Box) {
auto frameRect = opt->rect; d->drawFocusRing(p, opt->rect, hMargin, vMargin);
if (ffw && ffw->inherits("QLineEdit")
&& ffw->parentWidget()
&& ffw->parentWidget()->inherits("QAbstractSpinBox")) {
// See CC_SpinBox case for drawComplexControl
const int frame_size = qt_mac_aqua_get_metric(EditTextFrameOutset);
frameRect = frameRect.adjusted(-frame_size, -frame_size, +frame_size, +frame_size);
}
d->drawFocusRing(p, frameRect, hMargin, vMargin);
} else if (ffw) { } else if (ffw) {
const auto cs = ffw->testAttribute(Qt::WA_MacMiniSize) ? QStyleHelper::SizeMini : const auto cs = ffw->testAttribute(Qt::WA_MacMiniSize) ? QStyleHelper::SizeMini :
ffw->testAttribute(Qt::WA_MacSmallSize) ? QStyleHelper::SizeSmall : ffw->testAttribute(Qt::WA_MacSmallSize) ? QStyleHelper::SizeSmall :
@ -5444,9 +5430,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
case CC_SpinBox: case CC_SpinBox:
if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) { if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
const int frame_size = qt_mac_aqua_get_metric(EditTextFrameOutset); const auto lineEditRect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget);
const auto lineEditRect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget)
.adjusted(-frame_size, -frame_size, +frame_size, +frame_size);
QStyleOptionFrame frame; QStyleOptionFrame frame;
static_cast<QStyleOption &>(frame) = *opt; static_cast<QStyleOption &>(frame) = *opt;
frame.rect = lineEditRect; frame.rect = lineEditRect;
@ -6175,9 +6159,9 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op
case CC_SpinBox: case CC_SpinBox:
if (const QStyleOptionSpinBox *spin = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { if (const QStyleOptionSpinBox *spin = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
QStyleHelper::WidgetSizePolicy aquaSize = d->effectiveAquaSizeConstrain(spin, widget); QStyleHelper::WidgetSizePolicy aquaSize = d->effectiveAquaSizeConstrain(spin, widget);
const auto fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, spin, widget);
int spinner_w; int spinner_w;
int spinBoxSep; int spinBoxSep;
int fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, spin, widget);
switch (aquaSize) { switch (aquaSize) {
case QStyleHelper::SizeLarge: case QStyleHelper::SizeLarge:
spinner_w = 14; spinner_w = 14;
@ -6240,16 +6224,11 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op
break; break;
} }
case SC_SpinBoxEditField: case SC_SpinBoxEditField:
if (spin->buttonSymbols == QAbstractSpinBox::NoButtons) { ret = spin->rect.adjusted(fw, fw, -fw, -fw);
ret.setRect(fw, fw, if (spin->buttonSymbols != QAbstractSpinBox::NoButtons) {
spin->rect.width() - fw * 2, ret.setWidth(spin->rect.width() - spinBoxSep - spinner_w);
spin->rect.height() - fw * 2); ret = visualRect(spin->direction, spin->rect, ret);
} else {
ret.setRect(fw, fw,
spin->rect.width() - fw * 2 - spinBoxSep - spinner_w,
spin->rect.height() - fw * 2);
} }
ret = visualRect(spin->direction, spin->rect, ret);
break; break;
default: default:
ret = QCommonStyle::subControlRect(cc, spin, sc, widget); ret = QCommonStyle::subControlRect(cc, spin, sc, widget);
@ -6286,10 +6265,8 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
#if QT_CONFIG(spinbox) #if QT_CONFIG(spinbox)
case CT_SpinBox: case CT_SpinBox:
if (const QStyleOptionSpinBox *vopt = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { if (const QStyleOptionSpinBox *vopt = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
// Add button + frame widths const int buttonWidth = 20; // FIXME Use subControlRect()
int buttonWidth = 20; sz += QSize(buttonWidth, -3);
int fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, vopt, widget);
sz += QSize(buttonWidth + 2*fw, 2*fw - 3);
} }
break; break;
#endif #endif

View File

@ -5303,6 +5303,9 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget
case SH_ComboBox_AllowWheelScrolling: case SH_ComboBox_AllowWheelScrolling:
ret = true; ret = true;
break; break;
case SH_SpinBox_ButtonsInsideFrame:
ret = true;
break;
default: default:
ret = 0; ret = 0;
break; break;

View File

@ -1997,6 +1997,10 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
This is on by default in all styles except the Mac style. This is on by default in all styles except the Mac style.
This enum value has been introduced in Qt 5.10. This enum value has been introduced in Qt 5.10.
\value SH_SpinBox_ButtonsInsideFrame
Determnines if the spin box buttons are inside the line edit frame.
This enum value has been introduced in Qt 5.11.
\sa styleHint() \sa styleHint()
*/ */

View File

@ -740,6 +740,7 @@ public:
SH_TitleBar_ShowToolTipsOnButtons, SH_TitleBar_ShowToolTipsOnButtons,
SH_Widget_Animation_Duration, SH_Widget_Animation_Duration,
SH_ComboBox_AllowWheelScrolling, SH_ComboBox_AllowWheelScrolling,
SH_SpinBox_ButtonsInsideFrame,
// Add new style hint values here // Add new style hint values here
SH_CustomBase = 0xf0000000 SH_CustomBase = 0xf0000000

View File

@ -691,7 +691,7 @@ void QAbstractSpinBox::setLineEdit(QLineEdit *lineEdit)
if (d->edit->parent() != this) if (d->edit->parent() != this)
d->edit->setParent(this); d->edit->setParent(this);
d->edit->setFrame(false); d->edit->setFrame(!style()->styleHint(QStyle::SH_SpinBox_ButtonsInsideFrame, nullptr, this));
d->edit->setFocusProxy(this); d->edit->setFocusProxy(this);
d->edit->setAcceptDrops(false); d->edit->setAcceptDrops(false);
@ -823,6 +823,8 @@ void QAbstractSpinBox::changeEvent(QEvent *event)
d->spinClickTimerInterval = style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, 0, this); d->spinClickTimerInterval = style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, 0, this);
d->spinClickThresholdTimerInterval = d->spinClickThresholdTimerInterval =
style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatThreshold, 0, this); style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatThreshold, 0, this);
if (d->edit)
d->edit->setFrame(!style()->styleHint(QStyle::SH_SpinBox_ButtonsInsideFrame, nullptr, this));
d->reset(); d->reset();
d->updateEditFieldGeometry(); d->updateEditFieldGeometry();
break; break;
@ -1649,7 +1651,9 @@ void QAbstractSpinBox::initStyleOption(QStyleOptionSpinBox *option) const
option->initFrom(this); option->initFrom(this);
option->activeSubControls = QStyle::SC_None; option->activeSubControls = QStyle::SC_None;
option->buttonSymbols = d->buttonSymbols; option->buttonSymbols = d->buttonSymbols;
option->subControls = QStyle::SC_SpinBoxFrame | QStyle::SC_SpinBoxEditField; option->subControls = QStyle::SC_SpinBoxEditField;
if (!style()->styleHint(QStyle::SH_SpinBox_ButtonsInsideFrame, nullptr, this))
option->subControls |= QStyle::SC_SpinBoxFrame;
if (d->buttonSymbols != QAbstractSpinBox::NoButtons) { if (d->buttonSymbols != QAbstractSpinBox::NoButtons) {
option->subControls |= QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown; option->subControls |= QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown;
if (d->buttonState & Up) { if (d->buttonState & Up) {