From 43a7d3ff9c66f3ebb7cac702805b7076f9b5f7b2 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 21 Sep 2009 09:37:27 +0200 Subject: Mac, Cocoa: add support for device pixel scrolling (wheel event) This patch makes use of the rather hidden API on Mac for accessing the new mouse wheel event type. This will make scrolling with Mighty Mouse or TrackPad look much more slick. Rev-By: prasanth --- src/gui/kernel/qcocoaview_mac.mm | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index 7693ca7..4ebf8a9 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -63,6 +63,11 @@ #include +@interface NSEvent (DeviceDelta) + - (float)deviceDeltaX; + - (float)deviceDeltaY; + - (float)deviceDeltaZ; +@end QT_BEGIN_NAMESPACE @@ -776,17 +781,27 @@ extern "C" { Qt::MouseButton buttons = cocoaButton2QtButton([theEvent buttonNumber]); bool wheelOK = false; Qt::KeyboardModifiers keyMods = qt_cocoaModifiers2QtModifiers([theEvent modifierFlags]); - QWidget *widgetToGetMouse = qwidget; - - // Mouse wheel deltas seem to tick in at increments of 0.1. Qt widgets - // expect the delta to be a multiple of 120. - const int ScrollFactor = 10 * 120; - // The qMax(...) factor reduces the - // acceleration for large wheel deltas. - int deltaX = [theEvent deltaX] * ScrollFactor * qMax(0.6, 1.1 - qAbs([theEvent deltaX])); - int deltaY = [theEvent deltaY] * ScrollFactor * qMax(0.6, 1.1 - qAbs([theEvent deltaY])); - int deltaZ = [theEvent deltaZ] * ScrollFactor * qMax(0.6, 1.1 - qAbs([theEvent deltaZ])); + int deltaX = 0; + int deltaY = 0; + int deltaZ = 0; + + const EventRef carbonEvent = (EventRef)[theEvent eventRef]; + const UInt32 carbonEventKind = carbonEvent ? ::GetEventKind(carbonEvent) : 0; + if (carbonEventKind == kEventMouseScroll) { + // The mouse device containts pixel scroll + // wheel support (Mighty Mouse, Trackpad) + deltaX = (int)[theEvent deviceDeltaX] * 120; + deltaY = (int)[theEvent deviceDeltaY] * 120; + deltaZ = (int)[theEvent deviceDeltaZ] * 120; + } else { // carbonEventKind == kEventMouseWheelMoved + // Mouse wheel deltas seem to tick in at increments of 0.1. + // Qt widgets expect the delta to be a multiple of 120. + const int scrollFactor = 10 * 120; + deltaX = [theEvent deltaX] * scrollFactor * qMax(0.6, 1.1 - qAbs([theEvent deltaX])); + deltaY = [theEvent deltaY] * scrollFactor * qMax(0.6, 1.1 - qAbs([theEvent deltaY])); + deltaZ = [theEvent deltaZ] * scrollFactor * qMax(0.6, 1.1 - qAbs([theEvent deltaZ])); + } if (deltaX != 0) { QWheelEvent qwe(qlocal, qglobal, deltaX, buttons, keyMods, Qt::Horizontal); -- cgit v0.12