diff options
author | Nathan Collins <nathan.collins@kdab.com> | 2018-05-14 19:22:22 +0100 |
---|---|---|
committer | Nathan Collins <nathan.collins@kdab.com> | 2018-05-24 09:44:16 +0000 |
commit | 2d1e1f569b6de3edacd828c5e2452cfe1040192c (patch) | |
tree | 386323de4f021d9601925504ff06520bd5048529 /src | |
parent | cb3e85fc9a4992ee2af4e4c2bfa9f76bcdf7955c (diff) |
Apply Qt::ControlModifier to all spin box interactions
A step modifier already existed when scrolling with the
Qt::ControlModifier held. This patch applies this functionality to
other methods of stepping a spin box.
Holding the modifier increases the step rate when:
- scrolling;
- pressing the up/down keys;
- pressing the spin box up/down buttons.
[ChangeLog][QtWidgets][QAbstractSpinBox] The Qt::ControlModifier
increases the number of steps a QAbstractSpinBox takes for the
following interactions: scrolling, up/down keyboard keys and the spin
box buttons. Previously, Qt::ControlModifier only affected scrolling.
Task-number: QTBUG-67380
Change-Id: Icc8754d5c007da0771bfaef113603a2f334dd494
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/widgets/qabstractspinbox.cpp | 38 | ||||
-rw-r--r-- | src/widgets/widgets/qabstractspinbox_p.h | 1 |
2 files changed, 33 insertions, 6 deletions
diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index d2cbd9d456..71603ceb57 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -100,6 +100,12 @@ QT_BEGIN_NAMESPACE integer value to signify how many steps were taken. E.g. Pressing Qt::Key_Down will trigger a call to stepBy(-1). + When the user triggers a step whilst holding the Qt::ControlModifier, + QAbstractSpinBox steps by 10 instead of making a single step. This + step modifier affects wheel events, key events and interaction with + the spinbox buttons. Note that on macOS, Control corresponds to the + Command key. + QAbstractSpinBox also provide a virtual function stepEnabled() to determine whether stepping up/down is allowed at any point. This function returns a bitset of StepEnabled. @@ -1015,6 +1021,8 @@ void QAbstractSpinBox::keyPressEvent(QKeyEvent *event) const bool up = (event->key() == Qt::Key_PageUp || event->key() == Qt::Key_Up); if (!(stepEnabled() & (up ? StepUpEnabled : StepDownEnabled))) return; + if (!isPgUpOrDown && (event->modifiers() & d->stepModifier)) + steps *= 10; if (!up) steps *= -1; if (style()->styleHint(QStyle::SH_SpinBox_AnimateButton, 0, this)) { @@ -1141,11 +1149,24 @@ void QAbstractSpinBox::keyReleaseEvent(QKeyEvent *event) void QAbstractSpinBox::wheelEvent(QWheelEvent *event) { Q_D(QAbstractSpinBox); +#ifdef Q_OS_MACOS + // If the event comes from a real mouse wheel, rather than a track pad + // (Qt::MouseEventSynthesizedBySystem), the shift modifier changes the + // scroll orientation to horizontal. + // Convert horizontal events back to vertical whilst shift is held. + if ((event->modifiers() & Qt::ShiftModifier) + && event->source() == Qt::MouseEventNotSynthesized) { + d->wheelDeltaRemainder += event->angleDelta().x(); + } else { + d->wheelDeltaRemainder += event->angleDelta().y(); + } +#else d->wheelDeltaRemainder += event->angleDelta().y(); +#endif const int steps = d->wheelDeltaRemainder / 120; d->wheelDeltaRemainder -= steps * 120; if (stepEnabled() & (steps > 0 ? StepUpEnabled : StepDownEnabled)) - stepBy(event->modifiers() & Qt::ControlModifier ? steps * 10 : steps); + stepBy(event->modifiers() & d->stepModifier ? steps * 10 : steps); event->accept(); } #endif @@ -1245,18 +1266,19 @@ void QAbstractSpinBox::timerEvent(QTimerEvent *event) } if (doStep) { + const bool increaseStepRate = QGuiApplication::keyboardModifiers() & d->stepModifier; const StepEnabled st = stepEnabled(); if (d->buttonState & Up) { if (!(st & StepUpEnabled)) { d->reset(); } else { - stepBy(1); + stepBy(increaseStepRate ? 10 : 1); } } else if (d->buttonState & Down) { if (!(st & StepDownEnabled)) { d->reset(); } else { - stepBy(-1); + stepBy(increaseStepRate ? -10 : -1); } } return; @@ -1384,8 +1406,9 @@ QAbstractSpinBoxPrivate::QAbstractSpinBoxPrivate() cachedState(QValidator::Invalid), pendingEmit(false), readOnly(false), wrapping(false), ignoreCursorPositionChanged(false), frame(true), accelerate(false), keyboardTracking(true), cleared(false), ignoreUpdateEdit(false), correctionMode(QAbstractSpinBox::CorrectToPreviousValue), - acceleration(0), hoverControl(QStyle::SC_None), buttonSymbols(QAbstractSpinBox::UpDownArrows), validator(0), - showGroupSeparator(0), wheelDeltaRemainder(0) + stepModifier(Qt::ControlModifier), acceleration(0), hoverControl(QStyle::SC_None), + buttonSymbols(QAbstractSpinBox::UpDownArrows), validator(0), showGroupSeparator(0), + wheelDeltaRemainder(0) { } @@ -1636,7 +1659,10 @@ void QAbstractSpinBoxPrivate::updateState(bool up, bool fromKeyboard /* = false : QAbstractSpinBox::StepDownEnabled))) { spinClickThresholdTimerId = q->startTimer(spinClickThresholdTimerInterval); buttonState = (up ? Up : Down) | (fromKeyboard ? Keyboard : Mouse); - q->stepBy(up ? 1 : -1); + int steps = up ? 1 : -1; + if (QGuiApplication::keyboardModifiers() & stepModifier) + steps *= 10; + q->stepBy(steps); #ifndef QT_NO_ACCESSIBILITY QAccessibleValueChangeEvent event(q, value); QAccessible::updateAccessibility(&event); diff --git a/src/widgets/widgets/qabstractspinbox_p.h b/src/widgets/widgets/qabstractspinbox_p.h index b8bc088160..fce88e43f4 100644 --- a/src/widgets/widgets/qabstractspinbox_p.h +++ b/src/widgets/widgets/qabstractspinbox_p.h @@ -146,6 +146,7 @@ public: uint ignoreUpdateEdit : 1; QAbstractSpinBox::CorrectionMode correctionMode; QAbstractSpinBox::StepType stepType = QAbstractSpinBox::StepType::DefaultStepType; + Qt::KeyboardModifier stepModifier = Qt::ControlModifier; int acceleration; QStyle::SubControl hoverControl; QRect hoverRect; |