diff options
author | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2009-09-30 06:52:50 (GMT) |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2009-10-01 12:52:40 (GMT) |
commit | 45f095b8970dc3c1b6f6e97fa2323654ba848288 (patch) | |
tree | 73e1c8d019ebbc3cb2b6bd4e20f209a9e73e7287 /src/gui/widgets | |
parent | df7669b7f41f4284e297c0e8d56b3d71019625d0 (diff) | |
download | Qt-45f095b8970dc3c1b6f6e97fa2323654ba848288.zip Qt-45f095b8970dc3c1b6f6e97fa2323654ba848288.tar.gz Qt-45f095b8970dc3c1b6f6e97fa2323654ba848288.tar.bz2 |
Fix: Abstract slider does not understand wheel events properly
A wheel event contain delta values that describe the rotation
angle the wheel was rotated (in 1/8 of a degree).
For some mouse devices (thinking of mac mighty mouse/trackpad)
the resolution is better than the standard 15 degrees. The Qt
docs describe how to deal with this. But abstract scrollbar does
did follow this recipe, but it does now with this patch.
Reb-By: prasanth
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/qabstractslider.cpp | 39 | ||||
-rw-r--r-- | src/gui/widgets/qabstractslider_p.h | 1 | ||||
-rw-r--r-- | src/gui/widgets/qtextedit.cpp | 5 |
3 files changed, 22 insertions, 23 deletions
diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp index a50c105..c3289b4 100644 --- a/src/gui/widgets/qabstractslider.cpp +++ b/src/gui/widgets/qabstractslider.cpp @@ -215,7 +215,8 @@ QT_BEGIN_NAMESPACE QAbstractSliderPrivate::QAbstractSliderPrivate() : minimum(0), maximum(99), singleStep(1), pageStep(10), - value(0), position(0), pressValue(-1), tracking(true), blocktracking(false), pressed(false), + value(0), position(0), pressValue(-1), offset_accumulated(0), tracking(true), + blocktracking(false), pressed(false), invertedAppearance(false), invertedControls(false), orientation(Qt::Horizontal), repeatAction(QAbstractSlider::SliderNoAction) { @@ -691,38 +692,30 @@ void QAbstractSlider::wheelEvent(QWheelEvent * e) e->ignore(); if (e->orientation() != d->orientation && !rect().contains(e->pos())) return; - static qreal offset = 0; - static QAbstractSlider *offset_owner = 0; - if (offset_owner != this){ - offset_owner = this; - offset = 0; - } - // On Mac/Cocoa, always scroll one step. The mouse wheel acceleration - // is higher than on other systems, so this works well in practice. -#ifdef QT_MAC_USE_COCOA - int step = 1; -#else int step = qMin(QApplication::wheelScrollLines() * d->singleStep, d->pageStep); -#endif if ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::ShiftModifier)) step = d->pageStep; - int currentOffset = qRound(qreal(e->delta()) * step / 120); - if (currentOffset == 0) - currentOffset = (e->delta() < 0 ? -1 : 1); - offset += currentOffset; - if (d->invertedControls) - offset = -offset; + qreal currentOffset = qreal(e->delta()) * step / 120; + d->offset_accumulated += d->invertedControls ? -currentOffset : currentOffset; - int prevValue = d->value; - d->position = d->overflowSafeAdd(int(offset)); // value will be updated by triggerAction() + if (int(d->offset_accumulated) == 0) { + // QAbstractSlider works on integer values. So if the accumulated + // offset is less than +/- 1, we need to wait until we get more + // wheel events (this means that the wheel resolution is higher than + // 15 degrees, e.g. when using mac mighty mouse/trackpad): + return; + } + int prevValue = d->value; + d->position = d->overflowSafeAdd(int(d->offset_accumulated)); // value will be updated by triggerAction() triggerAction(SliderMove); + if (prevValue == d->value) { - offset = 0; + d->offset_accumulated = 0; } else { - offset -= int(offset); + d->offset_accumulated -= int(d->offset_accumulated); e->accept(); } } diff --git a/src/gui/widgets/qabstractslider_p.h b/src/gui/widgets/qabstractslider_p.h index 071b8df..9324d44 100644 --- a/src/gui/widgets/qabstractslider_p.h +++ b/src/gui/widgets/qabstractslider_p.h @@ -69,6 +69,7 @@ public: void setSteps(int single, int page); int minimum, maximum, singleStep, pageStep, value, position, pressValue; + float offset_accumulated; uint tracking : 1; uint blocktracking :1; uint pressed : 1; diff --git a/src/gui/widgets/qtextedit.cpp b/src/gui/widgets/qtextedit.cpp index dc78fd5..3fe9bb4 100644 --- a/src/gui/widgets/qtextedit.cpp +++ b/src/gui/widgets/qtextedit.cpp @@ -174,8 +174,13 @@ void QTextEditPrivate::init(const QString &html) if (!html.isEmpty()) control->setHtml(html); +#ifdef Q_OS_MAC + hbar->setSingleStep(1); + vbar->setSingleStep(1); +#else hbar->setSingleStep(20); vbar->setSingleStep(20); +#endif viewport->setBackgroundRole(QPalette::Base); q->setAcceptDrops(true); |