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>
This commit is contained in:
Mikhail Svetkin 2018-05-28 15:45:43 +02:00 committed by Edward Welbourne
parent 78ac98a590
commit c9d593d431
3 changed files with 33 additions and 23 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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];
}