summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets/qabstractslider.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets/qabstractslider.cpp')
-rw-r--r--src/gui/widgets/qabstractslider.cpp69
1 files changed, 40 insertions, 29 deletions
diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp
index 2874647..73c17db 100644
--- a/src/gui/widgets/qabstractslider.cpp
+++ b/src/gui/widgets/qabstractslider.cpp
@@ -214,8 +214,8 @@ QT_BEGIN_NAMESPACE
*/
QAbstractSliderPrivate::QAbstractSliderPrivate()
- : minimum(0), maximum(99), singleStep(1), pageStep(10),
- value(0), position(0), pressValue(-1), offset_accumulated(0), tracking(true),
+ : minimum(0), maximum(99), pageStep(10), value(0), position(0), pressValue(-1),
+ singleStep(1), offset_accumulated(0), tracking(true),
blocktracking(false), pressed(false),
invertedAppearance(false), invertedControls(false),
orientation(Qt::Horizontal), repeatAction(QAbstractSlider::SliderNoAction)
@@ -688,51 +688,62 @@ void QAbstractSlider::sliderChange(SliderChange)
update();
}
-
-/*!
- \reimp
-*/
-#ifndef QT_NO_WHEELEVENT
-void QAbstractSlider::wheelEvent(QWheelEvent * e)
+bool QAbstractSliderPrivate::scrollByDelta(Qt::Orientation orientation, Qt::KeyboardModifiers modifiers, int delta)
{
- Q_D(QAbstractSlider);
- e->ignore();
-
+ Q_Q(QAbstractSlider);
int stepsToScroll = 0;
- qreal offset = qreal(e->delta()) / 120;
+ // in Qt scrolling to the right gives negative values.
+ if (orientation == Qt::Horizontal)
+ delta = -delta;
+ qreal offset = qreal(delta) / 120;
- if ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::ShiftModifier)) {
+ if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) {
// Scroll one page regardless of delta:
- stepsToScroll = qBound(-d->pageStep, int(offset * d->pageStep), d->pageStep);
- d->offset_accumulated = 0;
+ stepsToScroll = qBound(-pageStep, int(offset * pageStep), pageStep);
+ offset_accumulated = 0;
} else {
// Calculate how many lines to scroll. Depending on what delta is (and
// offset), we might end up with a fraction (e.g. scroll 1.3 lines). We can
// only scroll whole lines, so we keep the reminder until next event.
- qreal stepsToScrollF = offset * QApplication::wheelScrollLines() * d->effectiveSingleStep();
+ qreal stepsToScrollF = offset * QApplication::wheelScrollLines() * effectiveSingleStep();
// Check if wheel changed direction since last event:
- if (d->offset_accumulated != 0 && (offset / d->offset_accumulated) < 0)
- d->offset_accumulated = 0;
+ if (offset_accumulated != 0 && (offset / offset_accumulated) < 0)
+ offset_accumulated = 0;
- d->offset_accumulated += stepsToScrollF;
- stepsToScroll = qBound(-d->pageStep, int(d->offset_accumulated), d->pageStep);
- d->offset_accumulated -= int(d->offset_accumulated);
+ offset_accumulated += stepsToScrollF;
+ stepsToScroll = qBound(-pageStep, int(offset_accumulated), pageStep);
+ offset_accumulated -= int(offset_accumulated);
if (stepsToScroll == 0)
- return;
+ return false;
}
- if (d->invertedControls)
+ if (invertedControls)
stepsToScroll = -stepsToScroll;
- int prevValue = d->value;
- d->position = d->overflowSafeAdd(stepsToScroll); // value will be updated by triggerAction()
- triggerAction(SliderMove);
+ int prevValue = value;
+ position = overflowSafeAdd(stepsToScroll); // value will be updated by triggerAction()
+ q->triggerAction(QAbstractSlider::SliderMove);
+
+ if (prevValue == value) {
+ offset_accumulated = 0;
+ return false;
+ }
+ return true;
+}
- if (prevValue == d->value)
- d->offset_accumulated = 0;
- else
+/*!
+ \reimp
+*/
+#ifndef QT_NO_WHEELEVENT
+void QAbstractSlider::wheelEvent(QWheelEvent * e)
+{
+ Q_D(QAbstractSlider);
+ e->ignore();
+ int delta = e->delta();
+ if (d->scrollByDelta(e->orientation(), e->modifiers(), delta))
e->accept();
}
+
#endif
#ifdef QT_KEYPAD_NAVIGATION
/*!