summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qwindowsysteminterface_qpa.cpp
diff options
context:
space:
mode:
authorMorten Johan Sorvig <morten.sorvig@nokia.com>2012-01-09 11:25:40 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-24 14:55:06 +0100
commit5a2efb490bc3549ef42420a0dafcf22072785e0d (patch)
tree5e0dc4396301e791fda198e9a11448532bc1aeec /src/gui/kernel/qwindowsysteminterface_qpa.cpp
parente8952aba2914722b0ad0e6f07e2193ead7f2e39d (diff)
QWheelEvent high-resolution delta support.
Support pixel-based deltas as well as sending dx and dy values in the same event. Keep source and behavior compatibility with Qt 4. New API: QPoint pixelDelta() const QPoint angleDelta() const Deprecate delta() and orientation(). Both pixel-based deltas and combined updates are necessary for smooth trackpad-based scrolling on OS X. Qt 4 compatible behavior is achieved by sending an extra wheel event in cases where the initial event has a combined dx and dy update. This extra event sends dx in delta() and orientation(), with pixelDelta() and angleDelta() set to null. Modify the Cocoa implementation to provide pixel deltas. It is expected that not all platforms can provide these. Angle deltas will always be available. Change-Id: I20c10f0df338ddcd6a3f7a4d40949ed5ae3b4795 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Diffstat (limited to 'src/gui/kernel/qwindowsysteminterface_qpa.cpp')
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa.cpp49
1 files changed, 47 insertions, 2 deletions
diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.cpp b/src/gui/kernel/qwindowsysteminterface_qpa.cpp
index e6c4454104..40a4ec07a6 100644
--- a/src/gui/kernel/qwindowsysteminterface_qpa.cpp
+++ b/src/gui/kernel/qwindowsysteminterface_qpa.cpp
@@ -189,8 +189,53 @@ void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local,
void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods)
{
- QWindowSystemInterfacePrivate::WheelEvent *e =
- new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, d, o, mods);
+ QPoint point = (o == Qt::Vertical) ? QPoint(0, d) : QPoint(d, 0);
+ handleWheelEvent(tlw, timestamp, local, global, point, point, mods);
+}
+
+void QWindowSystemInterface::handleWheelEvent(QWindow *w, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods)
+{
+ unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
+ handleWheelEvent(w, time, local, global, pixelDelta, angleDelta, mods);
+}
+
+void QWindowSystemInterface::handleWheelEvent(QWindow *tlw, ulong timestamp, const QPointF & local, const QPointF & global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods)
+{
+ // Qt 4 sends two separate wheel events for horizontal and vertical
+ // deltas. For Qt 5 we want to send the deltas in one event, but at the
+ // same time preserve source and behavior compatibility with Qt 4.
+ //
+ // In addition high-resolution pixel-based deltas are also supported.
+ // Platforms that does not support these may pass a null point here.
+ // Angle deltas must always be sent in addition to pixel deltas.
+ QWindowSystemInterfacePrivate::WheelEvent *e;
+
+ if (angleDelta.isNull())
+ return;
+
+ // Simple case: vertical deltas only:
+ if (angleDelta.y() != 0 && angleDelta.x() == 0) {
+ e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods);
+ QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
+ return;
+ }
+
+ // Simple case: horizontal deltas only:
+ if (angleDelta.y() == 0 && angleDelta.x() != 0) {
+ e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods);
+ QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
+ return;
+ }
+
+ // Both horizontal and vertical deltas: Send two wheel events.
+ // The first event contains the Qt 5 pixel and angle delta as points,
+ // and in addition the Qt 4 compatibility vertical angle delta.
+ e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods);
+ QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
+
+ // The second event contains null pixel and angle points and the
+ // Qt 4 compatibility horizontal angle delta.
+ e = new QWindowSystemInterfacePrivate::WheelEvent(tlw, timestamp, local, global, QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods);
QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
}