summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorTimur Pocheptsov <Timur.Pocheptsov@digia.com>2014-10-16 12:53:04 +0200
committerTimur Pocheptsov <Timur.Pocheptsov@digia.com>2014-10-21 07:36:34 +0200
commitae5f3df59b37e0ce8aaef27dc1e02f40def340ae (patch)
treea067b24dae1edc1fcc7aa7e067d3a6c02b870507 /src/plugins/platforms/cocoa
parenta6ebc9b34ab7e463dac758e465f930e285003d2a (diff)
OS X - unified toolbar and AA_NativeWindows
In some cases QToolBar creates a child window (a child borderless NSWindow) placed on top of the toolbar's main window. As a result it's not possible to drag this main window using its toolbar - the window "jumps" on the screen. The reason is quite subtle - QNSView -handleMouseEvent: uses [NSEvent mouseLocation] and this location is invalid: - we have an NSWindow (parent) - we have a child NSWindow ([parent addChildWindow:child ....] - we handle drag event in a child window - we move a parent window as a result of drag event - Cocoa also moves a child window for us - when handling the next drag event, location [NSEvent mouseLocation] differs from the real event's location. Task-number: QTBUG-40106 Change-Id: Ic68cb92ab4233a1e0746b478820c1e33fd37a462 Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index 06680228bc..6234c0dcbe 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -686,7 +686,23 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil;
m_platformWindow->m_forwardWindow = 0;
}
- [targetView convertFromScreen:[NSEvent mouseLocation] toWindowPoint:&qtWindowPoint andScreenPoint:&qtScreenPoint];
+ NSPoint globalPos = [NSEvent mouseLocation];
+
+ if ([self.window parentWindow]
+ && (theEvent.type == NSLeftMouseDragged || theEvent.type == NSLeftMouseUp)) {
+ // QToolBar can be implemented as a child window on top of its main window
+ // (with a borderless NSWindow). If an option "unified toolbar" set on the main window,
+ // it's possible to drag such a window using this toolbar.
+ // While handling mouse drag events, QToolBar moves the window (QWidget::move).
+ // In such a combination [NSEvent mouseLocation] is very different from the
+ // real event location and as a result a window will move chaotically.
+ NSPoint winPoint = [theEvent locationInWindow];
+ NSRect tmpRect = NSMakeRect(winPoint.x, winPoint.y, 1., 1.);
+ tmpRect = [[theEvent window] convertRectToScreen:tmpRect];
+ globalPos = tmpRect.origin;
+ }
+
+ [targetView convertFromScreen:globalPos toWindowPoint:&qtWindowPoint andScreenPoint:&qtScreenPoint];
ulong timestamp = [theEvent timestamp] * 1000;
QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();