diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2014-03-14 15:21:13 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-20 22:13:07 +0100 |
commit | b76612979cd4afb67a2c09d5668fbc53f3fcc64b (patch) | |
tree | 9ea89dc5f9eabd48feafeb4ec09218ee43ab21a0 | |
parent | 3b8b47db6aaeb333f106cff57cc712b01d828302 (diff) |
Cocoa: Fix geometry for embedded QWindows.
Report for correct geometry for QMacNativeWidget
and other QWindows that are embedded in a NSView
hierarchy. This also makes mapFrom/ToGlobal work.
The implementation is different than for the other
cases: Add a QCoocaWindow::geometry() overload and
query the geometry there, instead of using a geometry
change notification which sets the geometry on the
QWindow.
Task-number: QTBUG-36322
Change-Id: Iab5f0c96b89610c8a4b4a7de49887b0683d551dd
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index 96df3f4c59..6e1f00eebe 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -142,6 +142,7 @@ public: ~QCocoaWindow(); void setGeometry(const QRect &rect); + QRect geometry() const; void setCocoaGeometry(const QRect &rect); void clipChildWindows(); void clipWindow(const NSRect &clipRect); diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index bbd5dd7311..c7fba4eef0 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -462,6 +462,22 @@ void QCocoaWindow::setGeometry(const QRect &rectIn) setCocoaGeometry(rect); } +QRect QCocoaWindow::geometry() const +{ + // QWindows that are embedded in a NSView hiearchy may be considered + // top-level from Qt's point of view but are not from Cocoa's point + // of view. Embedded QWindows get global (screen) geometry. + if (m_contentViewIsEmbedded) { + NSPoint windowPoint = [m_contentView convertPoint:NSMakePoint(0, 0) toView:nil]; + NSPoint screenPoint = [[m_contentView window] convertBaseToScreen:windowPoint]; // ### use convertRectToScreen after 10.6 removal + QPoint position = qt_mac_flipPoint(screenPoint).toPoint(); + QSize size = qt_mac_toQRect([m_contentView bounds]).size(); + return QRect(position, size); + } + + return QPlatformWindow::geometry(); +} + void QCocoaWindow::setCocoaGeometry(const QRect &rect) { QCocoaAutoReleasePool pool; |