summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorMikhail Svetkin <mikhail.svetkin@qt.io>2018-05-28 15:45:43 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2018-05-31 15:49:50 +0000
commitc9d593d431e6f0e2d761b842f61ba25ea48d8fa1 (patch)
treeca259396233d17e165e8b1749640266f70b00ffb /src/plugins/platforms/cocoa
parent78ac98a590b4458dd2e1b8522e1aca75ead7d527 (diff)
macOS: minor refactoring in mouse handlers for nsview/systemtrayicon
Use new helper functions for mouse events Change-Id: I01e83a228deb16cbdb1d7c8c628a92d48055ee2b Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qcocoahelpers.mm15
-rw-r--r--src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm10
-rw-r--r--src/plugins/platforms/cocoa/qnsview_mouse.mm31
3 files changed, 33 insertions, 23 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm
index 12be222ab3..7ba7908d27 100644
--- a/src/plugins/platforms/cocoa/qcocoahelpers.mm
+++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm
@@ -287,12 +287,25 @@ Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum)
and "no button". Only NSEvents that describes mouse press/release/dragging
events (e.g NSEventTypeOtherMouseDown) will contain a valid
button number.
+
+ \note Wacom tablet might not return the correct button number for NSEvent buttonNumber
+ on right clicks. Decide here that the button is the "right" button.
*/
Qt::MouseButton cocoaButton2QtButton(NSEvent *event)
{
- if (event.type == NSMouseMoved)
+ switch (event.type) {
+ case NSMouseMoved:
return Qt::NoButton;
+ case NSRightMouseUp:
+ case NSRightMouseDown:
+ case NSRightMouseDragged:
+ return Qt::RightButton;
+
+ default:
+ break;
+ }
+
return cocoaButton2QtButton(event.buttonNumber);
}
diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
index 773f4b833f..0158895441 100644
--- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
+++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
@@ -296,7 +296,7 @@ QT_END_NAMESPACE
[self setNeedsDisplay:YES];
}
-- (void)mousePressed:(NSEvent *)mouseEvent button:(Qt::MouseButton)mouseButton
+- (void)mousePressed:(NSEvent *)mouseEvent
{
down = YES;
int clickCount = [mouseEvent clickCount];
@@ -306,13 +306,13 @@ QT_END_NAMESPACE
[self menuTrackingDone:nil];
[parent doubleClickSelector:self];
} else {
- [parent triggerSelector:self button:mouseButton];
+ [parent triggerSelector:self button:cocoaButton2QtButton(mouseEvent)];
}
}
- (void)mouseDown:(NSEvent *)mouseEvent
{
- [self mousePressed:mouseEvent button:Qt::LeftButton];
+ [self mousePressed:mouseEvent];
}
- (void)mouseUp:(NSEvent *)mouseEvent
@@ -323,7 +323,7 @@ QT_END_NAMESPACE
- (void)rightMouseDown:(NSEvent *)mouseEvent
{
- [self mousePressed:mouseEvent button:Qt::RightButton];
+ [self mousePressed:mouseEvent];
}
- (void)rightMouseUp:(NSEvent *)mouseEvent
@@ -334,7 +334,7 @@ QT_END_NAMESPACE
- (void)otherMouseDown:(NSEvent *)mouseEvent
{
- [self mousePressed:mouseEvent button:cocoaButton2QtButton([mouseEvent buttonNumber])];
+ [self mousePressed:mouseEvent];
}
- (void)otherMouseUp:(NSEvent *)mouseEvent
diff --git a/src/plugins/platforms/cocoa/qnsview_mouse.mm b/src/plugins/platforms/cocoa/qnsview_mouse.mm
index 34ac1126ad..1f04c40f8e 100644
--- a/src/plugins/platforms/cocoa/qnsview_mouse.mm
+++ b/src/plugins/platforms/cocoa/qnsview_mouse.mm
@@ -211,12 +211,12 @@
buttons, button, eventType, modifiers);
}
-- (bool)handleMouseDownEvent:(NSEvent *)theEvent withButton:(int)buttonNumber
+- (bool)handleMouseDownEvent:(NSEvent *)theEvent
{
if ([self isTransparentForUserInput])
return false;
- Qt::MouseButton button = cocoaButton2QtButton(buttonNumber);
+ const auto button = cocoaButton2QtButton(theEvent);
QPointF qtWindowPoint;
QPointF qtScreenPoint;
@@ -241,12 +241,12 @@
return true;
}
-- (bool)handleMouseDraggedEvent:(NSEvent *)theEvent withButton:(int)buttonNumber
+- (bool)handleMouseDraggedEvent:(NSEvent *)theEvent
{
if ([self isTransparentForUserInput])
return false;
- Qt::MouseButton button = cocoaButton2QtButton(buttonNumber);
+ const auto button = cocoaButton2QtButton(theEvent);
// Forward the event to the next responder if Qt did not accept the
// corresponding mouse down for this button
@@ -257,12 +257,12 @@
return true;
}
-- (bool)handleMouseUpEvent:(NSEvent *)theEvent withButton:(int)buttonNumber
+- (bool)handleMouseUpEvent:(NSEvent *)theEvent
{
if ([self isTransparentForUserInput])
return false;
- Qt::MouseButton button = cocoaButton2QtButton(buttonNumber);
+ auto button = cocoaButton2QtButton(theEvent);
// Forward the event to the next responder if Qt did not accept the
// corresponding mouse down for this button
@@ -353,59 +353,56 @@
- (void)mouseDragged:(NSEvent *)theEvent
{
- const bool accepted = [self handleMouseDraggedEvent:theEvent withButton:[theEvent buttonNumber]];
+ const bool accepted = [self handleMouseDraggedEvent:theEvent];
if (!accepted)
[super mouseDragged:theEvent];
}
- (void)mouseUp:(NSEvent *)theEvent
{
- const bool accepted = [self handleMouseUpEvent:theEvent withButton:[theEvent buttonNumber]];
+ const bool accepted = [self handleMouseUpEvent:theEvent];
if (!accepted)
[super mouseUp:theEvent];
}
- (void)rightMouseDown:(NSEvent *)theEvent
{
- // Wacom tablet might not return the correct button number for NSEvent buttonNumber
- // on right clicks. Decide here that the button is the "right" button and forward
- // the button number to the mouse (and tablet) handler.
- const bool accepted = [self handleMouseDownEvent:theEvent withButton:1];
+ const bool accepted = [self handleMouseDownEvent:theEvent];
if (!accepted)
[super rightMouseDown:theEvent];
}
- (void)rightMouseDragged:(NSEvent *)theEvent
{
- const bool accepted = [self handleMouseDraggedEvent:theEvent withButton:1];
+ const bool accepted = [self handleMouseDraggedEvent:theEvent];
if (!accepted)
[super rightMouseDragged:theEvent];
}
- (void)rightMouseUp:(NSEvent *)theEvent
{
- const bool accepted = [self handleMouseUpEvent:theEvent withButton:1];
+ const bool accepted = [self handleMouseUpEvent:theEvent];
if (!accepted)
[super rightMouseUp:theEvent];
}
- (void)otherMouseDown:(NSEvent *)theEvent
{
- const bool accepted = [self handleMouseDownEvent:theEvent withButton:[theEvent buttonNumber]];
+ const bool accepted = [self handleMouseDownEvent:theEvent];
if (!accepted)
[super otherMouseDown:theEvent];
}
- (void)otherMouseDragged:(NSEvent *)theEvent
{
- const bool accepted = [self handleMouseDraggedEvent:theEvent withButton:[theEvent buttonNumber]];
+ const bool accepted = [self handleMouseDraggedEvent:theEvent];
if (!accepted)
[super otherMouseDragged:theEvent];
}
- (void)otherMouseUp:(NSEvent *)theEvent
{
- const bool accepted = [self handleMouseUpEvent:theEvent withButton:[theEvent buttonNumber]];
+ const bool accepted = [self handleMouseUpEvent:theEvent];
if (!accepted)
[super otherMouseUp:theEvent];
}