diff options
Diffstat (limited to 'src/gui/kernel/qcocoaview_mac.mm')
-rw-r--r-- | src/gui/kernel/qcocoaview_mac.mm | 35 |
1 files 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 <qdebug.h> +@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); |