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:
parent
3d29a0dd74
commit
80515c811a
@ -2387,14 +2387,6 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW
|
||||
break;
|
||||
case PM_SpinBoxFrameWidth:
|
||||
ret = qt_mac_aqua_get_metric(EditTextFrameOutset);
|
||||
switch (d->aquaSizeConstrain(opt, widget)) {
|
||||
case QStyleHelper::SizeMini:
|
||||
ret += 1;
|
||||
break;
|
||||
default:
|
||||
ret += 2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case PM_ButtonShiftHorizontal:
|
||||
case PM_ButtonShiftVertical:
|
||||
@ -3001,6 +2993,9 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w
|
||||
case SH_ComboBox_AllowWheelScrolling:
|
||||
ret = false;
|
||||
break;
|
||||
case SH_SpinBox_ButtonsInsideFrame:
|
||||
ret = false;
|
||||
break;
|
||||
default:
|
||||
ret = QCommonStyle::styleHint(sh, opt, w, hret);
|
||||
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 vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, opt, w);
|
||||
if (ct == QMacStylePrivate::Box) {
|
||||
auto frameRect = opt->rect;
|
||||
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);
|
||||
d->drawFocusRing(p, opt->rect, hMargin, vMargin);
|
||||
} else if (ffw) {
|
||||
const auto cs = ffw->testAttribute(Qt::WA_MacMiniSize) ? QStyleHelper::SizeMini :
|
||||
ffw->testAttribute(Qt::WA_MacSmallSize) ? QStyleHelper::SizeSmall :
|
||||
@ -5444,9 +5430,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
|
||||
case CC_SpinBox:
|
||||
if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
|
||||
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)
|
||||
.adjusted(-frame_size, -frame_size, +frame_size, +frame_size);
|
||||
const auto lineEditRect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget);
|
||||
QStyleOptionFrame frame;
|
||||
static_cast<QStyleOption &>(frame) = *opt;
|
||||
frame.rect = lineEditRect;
|
||||
@ -6175,9 +6159,9 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op
|
||||
case CC_SpinBox:
|
||||
if (const QStyleOptionSpinBox *spin = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
|
||||
QStyleHelper::WidgetSizePolicy aquaSize = d->effectiveAquaSizeConstrain(spin, widget);
|
||||
const auto fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, spin, widget);
|
||||
int spinner_w;
|
||||
int spinBoxSep;
|
||||
int fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, spin, widget);
|
||||
switch (aquaSize) {
|
||||
case QStyleHelper::SizeLarge:
|
||||
spinner_w = 14;
|
||||
@ -6240,16 +6224,11 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op
|
||||
break;
|
||||
}
|
||||
case SC_SpinBoxEditField:
|
||||
if (spin->buttonSymbols == QAbstractSpinBox::NoButtons) {
|
||||
ret.setRect(fw, fw,
|
||||
spin->rect.width() - fw * 2,
|
||||
spin->rect.height() - fw * 2);
|
||||
} else {
|
||||
ret.setRect(fw, fw,
|
||||
spin->rect.width() - fw * 2 - spinBoxSep - spinner_w,
|
||||
spin->rect.height() - fw * 2);
|
||||
}
|
||||
ret = spin->rect.adjusted(fw, fw, -fw, -fw);
|
||||
if (spin->buttonSymbols != QAbstractSpinBox::NoButtons) {
|
||||
ret.setWidth(spin->rect.width() - spinBoxSep - spinner_w);
|
||||
ret = visualRect(spin->direction, spin->rect, ret);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ret = QCommonStyle::subControlRect(cc, spin, sc, widget);
|
||||
@ -6286,10 +6265,8 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
|
||||
#if QT_CONFIG(spinbox)
|
||||
case CT_SpinBox:
|
||||
if (const QStyleOptionSpinBox *vopt = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
|
||||
// Add button + frame widths
|
||||
int buttonWidth = 20;
|
||||
int fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, vopt, widget);
|
||||
sz += QSize(buttonWidth + 2*fw, 2*fw - 3);
|
||||
const int buttonWidth = 20; // FIXME Use subControlRect()
|
||||
sz += QSize(buttonWidth, -3);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
@ -5303,6 +5303,9 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget
|
||||
case SH_ComboBox_AllowWheelScrolling:
|
||||
ret = true;
|
||||
break;
|
||||
case SH_SpinBox_ButtonsInsideFrame:
|
||||
ret = true;
|
||||
break;
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
|
@ -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 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()
|
||||
*/
|
||||
|
||||
|
@ -740,6 +740,7 @@ public:
|
||||
SH_TitleBar_ShowToolTipsOnButtons,
|
||||
SH_Widget_Animation_Duration,
|
||||
SH_ComboBox_AllowWheelScrolling,
|
||||
SH_SpinBox_ButtonsInsideFrame,
|
||||
// Add new style hint values here
|
||||
|
||||
SH_CustomBase = 0xf0000000
|
||||
|
@ -691,7 +691,7 @@ void QAbstractSpinBox::setLineEdit(QLineEdit *lineEdit)
|
||||
if (d->edit->parent() != 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->setAcceptDrops(false);
|
||||
|
||||
@ -823,6 +823,8 @@ void QAbstractSpinBox::changeEvent(QEvent *event)
|
||||
d->spinClickTimerInterval = style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, 0, this);
|
||||
d->spinClickThresholdTimerInterval =
|
||||
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->updateEditFieldGeometry();
|
||||
break;
|
||||
@ -1649,7 +1651,9 @@ void QAbstractSpinBox::initStyleOption(QStyleOptionSpinBox *option) const
|
||||
option->initFrom(this);
|
||||
option->activeSubControls = QStyle::SC_None;
|
||||
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) {
|
||||
option->subControls |= QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown;
|
||||
if (d->buttonState & Up) {
|
||||
|
Loading…
Reference in New Issue
Block a user