summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2014-09-08 16:22:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@digia.com>2014-09-23 11:35:30 +0200
commitdfb4af1fd34a163495790a7896acafa56b86a8f1 (patch)
tree81d6d9a5b941aaa2f69d2fb0c178abcaf51d222f
parente8ef241d0f35704433ba331dee9578190a5c98a6 (diff)
Fix spin box with fine grained wheel events
Only step the value in the spin box when we have accumulated one wheel tick worth of wheel delta. Also fixes the obsolete contructors of QWheelEvent so they set the non obsolete properties. Change-Id: Ic6ea4b37afa8eec85a6ca7bdc0d919bf8fb02608 Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
-rw-r--r--src/gui/kernel/qevent.cpp11
-rw-r--r--src/widgets/widgets/qabstractspinbox.cpp7
-rw-r--r--src/widgets/widgets/qabstractspinbox_p.h1
-rw-r--r--tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp32
4 files changed, 48 insertions, 3 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 958df48f17..57c9da2dda 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -642,6 +642,10 @@ QWheelEvent::QWheelEvent(const QPointF &pos, int delta,
: QInputEvent(Wheel, modifiers), p(pos), qt4D(delta), qt4O(orient), mouseState(buttons)
{
g = QCursor::pos();
+ if (orient == Qt::Vertical)
+ angleD = QPoint(0, delta);
+ else
+ angleD = QPoint(delta, 0);
}
/*!
@@ -670,7 +674,12 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
Qt::Orientation orient)
: QInputEvent(Wheel, modifiers), p(pos), g(globalPos), qt4D(delta), qt4O(orient), mouseState(buttons)
-{}
+{
+ if (orient == Qt::Vertical)
+ angleD = QPoint(0, delta);
+ else
+ angleD = QPoint(delta, 0);
+}
/*!
Constructs a wheel event object.
diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp
index 4aed153932..0d8c7957e2 100644
--- a/src/widgets/widgets/qabstractspinbox.cpp
+++ b/src/widgets/widgets/qabstractspinbox.cpp
@@ -1100,7 +1100,10 @@ void QAbstractSpinBox::keyReleaseEvent(QKeyEvent *event)
#ifndef QT_NO_WHEELEVENT
void QAbstractSpinBox::wheelEvent(QWheelEvent *event)
{
- const int steps = (event->delta() > 0 ? 1 : -1);
+ Q_D(QAbstractSpinBox);
+ d->wheelDeltaRemainder += event->angleDelta().y();
+ const int steps = d->wheelDeltaRemainder / 120;
+ d->wheelDeltaRemainder -= steps * 120;
if (stepEnabled() & (steps > 0 ? StepUpEnabled : StepDownEnabled))
stepBy(event->modifiers() & Qt::ControlModifier ? steps * 10 : steps);
event->accept();
@@ -1344,7 +1347,7 @@ QAbstractSpinBoxPrivate::QAbstractSpinBoxPrivate()
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)
+ showGroupSeparator(0), wheelDeltaRemainder(0)
{
}
diff --git a/src/widgets/widgets/qabstractspinbox_p.h b/src/widgets/widgets/qabstractspinbox_p.h
index da9f1d9757..055fe92591 100644
--- a/src/widgets/widgets/qabstractspinbox_p.h
+++ b/src/widgets/widgets/qabstractspinbox_p.h
@@ -151,6 +151,7 @@ public:
QAbstractSpinBox::ButtonSymbols buttonSymbols;
QSpinBoxValidator *validator;
uint showGroupSeparator : 1;
+ int wheelDeltaRemainder;
};
class QSpinBoxValidator : public QValidator
diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp
index 350ae23d8a..ac76c44b9b 100644
--- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp
+++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp
@@ -82,6 +82,12 @@ public:
{
return QSpinBox::valueFromText(text);
}
+#ifndef QT_NO_WHEELEVENT
+ void wheelEvent(QWheelEvent *event)
+ {
+ QSpinBox::wheelEvent(event);
+ }
+#endif
QLineEdit *lineEdit() const { return QSpinBox::lineEdit(); }
};
@@ -148,6 +154,8 @@ private slots:
void setGroupSeparatorShown_data();
void setGroupSeparatorShown();
+ void wheelEvents();
+
public slots:
void valueChangedHelper(const QString &);
void valueChangedHelper(int);
@@ -1190,5 +1198,29 @@ void tst_QSpinBox::setGroupSeparatorShown()
QCOMPARE(spinBox.value()+1000, 33000);
}
+void tst_QSpinBox::wheelEvents()
+{
+#ifndef QT_NO_WHEELEVENT
+ SpinBox spinBox;
+ spinBox.setRange(-20, 20);
+ spinBox.setValue(0);
+
+ QWheelEvent wheelUp(QPointF(), QPointF(), QPoint(), QPoint(0, 120), 120, Qt::Vertical, Qt::NoButton, Qt::NoModifier);
+ spinBox.wheelEvent(&wheelUp);
+ QCOMPARE(spinBox.value(), 1);
+
+ QWheelEvent wheelDown(QPointF(), QPointF(), QPoint(), QPoint(0, -120), -120, Qt::Vertical, Qt::NoButton, Qt::NoModifier);
+ spinBox.wheelEvent(&wheelDown);
+ spinBox.wheelEvent(&wheelDown);
+ QCOMPARE(spinBox.value(), -1);
+
+ QWheelEvent wheelHalfUp(QPointF(), QPointF(), QPoint(), QPoint(0, 60), 60, Qt::Vertical, Qt::NoButton, Qt::NoModifier);
+ spinBox.wheelEvent(&wheelHalfUp);
+ QCOMPARE(spinBox.value(), -1);
+ spinBox.wheelEvent(&wheelHalfUp);
+ QCOMPARE(spinBox.value(), 0);
+#endif
+}
+
QTEST_MAIN(tst_QSpinBox)
#include "tst_qspinbox.moc"