diff options
author | Morten Johan Sorvig <morten.sorvig@nokia.com> | 2012-03-16 16:19:13 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-19 11:52:10 +0100 |
commit | fb4c976a0e0b5c6b8dfb7d7c35fe8e6772d4a876 (patch) | |
tree | ec3741e12e1f629e2d4033cbf3045df7677cc9a0 /src | |
parent | d6ebb3db16a11eb7c266419f0a7e19b9ceb0f7d9 (diff) |
Cocoa: Send keyboard modifiers with wheel events.
Read and save the modifiers at the beginning of the
event stream to keep the event interpretation constant
for the entire event stream.
Change-Id: I66046dea8f8fd3ff2f88c48da5f076377bda32dd
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview.mm | 26 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview.h b/src/plugins/platforms/cocoa/qnsview.h index f09c9331f6..2b7caae688 100644 --- a/src/plugins/platforms/cocoa/qnsview.h +++ b/src/plugins/platforms/cocoa/qnsview.h @@ -61,6 +61,7 @@ QT_END_NAMESPACE QString m_composingText; bool m_keyEventsAccepted; QStringList *currentCustomDragTypes; + Qt::KeyboardModifiers currentWheelModifiers; } - (id)init; diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 3a697a3602..ed67fd50fc 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -545,7 +545,31 @@ static QTouchDevice *touchDevice = 0; NSTimeInterval timestamp = [theEvent timestamp]; ulong qt_timestamp = timestamp * 1000; - QWindowSystemInterface::handleWheelEvent(m_window, qt_timestamp, qt_windowPoint, qt_windowPoint, pixelDelta, angleDelta); + // Set keyboard modifiers depending on event phase. A two-finger trackpad flick + // generates a stream of scroll events. We want the keyboard modifier state to + // be the state at the beginning of the flick in order to avoid changing the + // interpretation of the events mid-stream. One example of this happening would + // be when pressing cmd after scrolling in Qt Creator: not taking the phase into + // account causes the end of the event stream to be interpreted as font size changes. + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 + if ([theEvent respondsToSelector:@selector(scrollingDeltaX)]) { + NSEventPhase phase = [theEvent phase]; + if (phase == NSEventPhaseBegan) { + currentWheelModifiers = [self convertKeyModifiers:[theEvent modifierFlags]]; + } + + QWindowSystemInterface::handleWheelEvent(m_window, qt_timestamp, qt_windowPoint, qt_windowPoint, pixelDelta, angleDelta, currentWheelModifiers); + + if (phase == NSEventPhaseEnded || phase == NSEventPhaseCancelled) { + currentWheelModifiers = Qt::NoModifier; + } + } +#else + QWindowSystemInterface::handleWheelEvent(m_window, qt_timestamp, qt_windowPoint, qt_windowPoint, pixelDelta, angleDelta, + [self convertKeyModifiers:[theEvent modifierFlags]]); +#endif + } #endif //QT_NO_WHEELEVENT |