Ensure ctrl + click sends a right mouse button press in Cocoa
authorAndy Shaw <andy.shaw@digia.com>
Mon, 3 Dec 2012 21:03:53 +0000 (22:03 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 4 Dec 2012 14:31:55 +0000 (15:31 +0100)
Since Mac's typically just have one button for their mice then pressing
Control then clicking the button should end it as a right mouse button
event.

Task-number: QTBUG-28350
Change-Id: Iabcac5b315c36cb8cd062c27d7b1506bc066f5bb
Reviewed-by: Liang Qi <liang.qi@digia.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
src/plugins/platforms/cocoa/qnsview.h
src/plugins/platforms/cocoa/qnsview.mm

index f93fd86..9cdfe6f 100644 (file)
@@ -66,6 +66,7 @@ QT_END_NAMESPACE
     QString m_composingText;
     bool m_sendKeyEvent;
     QStringList *currentCustomDragTypes;
+    bool m_sendUpAsRightButton;
     Qt::KeyboardModifiers currentWheelModifiers;
     bool m_subscribesForGlobalFrameNotifications;
 }
index b608989..eea65cf 100644 (file)
@@ -84,6 +84,7 @@ static QTouchDevice *touchDevice = 0;
         m_sendKeyEvent = false;
         m_subscribesForGlobalFrameNotifications = false;
         currentCustomDragTypes = 0;
+        m_sendUpAsRightButton = false;
 
         if (!touchDevice) {
             touchDevice = new QTouchDevice;
@@ -427,6 +428,7 @@ static QTouchDevice *touchDevice = 0;
 
 - (void)mouseDown:(NSEvent *)theEvent
 {
+    m_sendUpAsRightButton = false;
     if (m_platformWindow->m_activePopupWindow) {
         QWindowSystemInterface::handleCloseEvent(m_platformWindow->m_activePopupWindow);
         QWindowSystemInterface::flushWindowSystemEvents();
@@ -438,7 +440,12 @@ static QTouchDevice *touchDevice = 0;
             [inputManager handleMouseEvent:theEvent];
         }
     } else {
-        m_buttons |= Qt::LeftButton;
+        if ([self convertKeyModifiers:[theEvent modifierFlags]] & Qt::MetaModifier) {
+            m_buttons |= Qt::RightButton;
+            m_sendUpAsRightButton = true;
+        } else {
+            m_buttons |= Qt::LeftButton;
+        }
         [self handleMouseEvent:theEvent];
     }
 }
@@ -452,7 +459,12 @@ static QTouchDevice *touchDevice = 0;
 
 - (void)mouseUp:(NSEvent *)theEvent
 {
-    m_buttons &= QFlag(~int(Qt::LeftButton));
+    if (m_sendUpAsRightButton) {
+        m_buttons &= QFlag(~int(Qt::RightButton));
+        m_sendUpAsRightButton = false;
+    } else {
+        m_buttons &= QFlag(~int(Qt::LeftButton));
+    }
     [self handleMouseEvent:theEvent];
 }