summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@nokia.com>2009-10-07 12:46:43 (GMT)
committerRichard Moe Gustavsen <richard.gustavsen@nokia.com>2009-10-08 11:36:15 (GMT)
commit52aaffaf17c4d1bf11a469fe3cc692c3bea6cfe2 (patch)
tree76434af5e55d8488d107c9f8b10df41e64deb278
parent8050a8ea1b30b0d35fc20e9d09ff48c242a924cd (diff)
downloadQt-52aaffaf17c4d1bf11a469fe3cc692c3bea6cfe2.zip
Qt-52aaffaf17c4d1bf11a469fe3cc692c3bea6cfe2.tar.gz
Qt-52aaffaf17c4d1bf11a469fe3cc692c3bea6cfe2.tar.bz2
Carbon: better wheel acceleration patch
It turns out that scrolling appears to be slow when using non-mac mice with the carbon build. This patch introduces a an acceleration algorithm that closer resembles the one used by Cocoa. Rev-By: prasanth
-rw-r--r--src/gui/kernel/qapplication_mac.mm26
-rw-r--r--src/gui/widgets/qabstractslider.cpp3
2 files changed, 23 insertions, 6 deletions
diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm
index a95ae9d..f9c8aa3 100644
--- a/src/gui/kernel/qapplication_mac.mm
+++ b/src/gui/kernel/qapplication_mac.mm
@@ -1708,12 +1708,30 @@ QApplicationPrivate::globalEventProcessor(EventHandlerCallRef er, EventRef event
sizeof(axis), 0, &axis);
// The 'new' event has acceleration applied by the OS, while the old (on
- // Carbon only), has not. So we introduce acceleration here to be consistent:
- int scrollFactor = 120 * qMin(5, qAbs(mdelt));
+ // Carbon only), has not. So we introduce acceleration here to be consistent.
+ // The acceleration is trying to respect both pixel based and line scrolling,
+ // which turns out to be rather difficult.
+ int linesToScroll = mdelt > 0 ? 1 : -1;
+ static QTime t;
+ int elapsed = t.elapsed();
+ t.restart();
+ if (elapsed < 20)
+ linesToScroll *= 120;
+ else if (elapsed < 30)
+ linesToScroll *= 60;
+ else if (elapsed < 50)
+ linesToScroll *= 30;
+ else if (elapsed < 100)
+ linesToScroll *= 6;
+ else if (elapsed < 200)
+ linesToScroll *= 3;
+ else if (elapsed < 300)
+ linesToScroll *= 2;
+
if (axis == kEventMouseWheelAxisX)
- wheel_deltaX = mdelt * scrollFactor;
+ wheel_deltaX = linesToScroll * 120;
else
- wheel_deltaY = mdelt * scrollFactor;
+ wheel_deltaY = linesToScroll * 120;
}
}
diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp
index 19a8b63..588a48e 100644
--- a/src/gui/widgets/qabstractslider.cpp
+++ b/src/gui/widgets/qabstractslider.cpp
@@ -715,8 +715,7 @@ void QAbstractSlider::wheelEvent(QWheelEvent * e)
#else
stepsToScroll = int(d->offset_accumulated) * QApplication::wheelScrollLines() * d->singleStep;
#endif
- if (qAbs(stepsToScroll) > d->pageStep)
- stepsToScroll = currentOffset > 0 ? d->pageStep : -d->pageStep;
+ stepsToScroll = qBound(-d->pageStep, stepsToScroll, d->pageStep);
}
if (d->invertedControls)