diff options
author | Morten Sorvig <morten.sorvig@nokia.com> | 2011-10-26 12:35:52 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-27 09:38:26 +0200 |
commit | 3849455ee791d6f5cd4b87253732827d40e5d28a (patch) | |
tree | e4882153eb7b03db3fffbeec9fedd03fbc16c31b /src/plugins | |
parent | db44fdf4d65493706dc9a0aaf5e58729dc7867f9 (diff) |
Cocoa: Set correct child window geometry.
Remote globalGeometry which was completely wrong,
replace with flipRect which converts from Qt
screen coordinates to OS X screen coordinates.
Change-Id: Ie560cb7c2266fe779da8a44a35596d2d12af77f5
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.mm | 7 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 36 |
4 files changed, 14 insertions, 31 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index 3c1c0655f8..57eaa2f54d 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -104,6 +104,7 @@ inline NSPoint qt_mac_flipPoint(const QPoint &p) inline NSPoint qt_mac_flipPoint(const QPointF &p) { return NSMakePoint(p.x(), qt_mac_flipYCoordinate(p.y())); } +NSRect qt_mac_flipRect(const QRect &rect, QWindow *window); #endif //QCOCOAHELPERS_H diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 113415f480..9777e0c473 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -450,3 +450,10 @@ QString qt_mac_applicationName() return appName; } +NSRect qt_mac_flipRect(const QRect &rect, QWindow *window) +{ + QPlatformScreen *onScreen = QPlatformScreen::platformScreenForWindow(window); + int flippedY = onScreen->geometry().height() - rect.y() - rect.height(); + return NSMakeRect(rect.x(), flippedY, rect.width(), rect.height()); +} + diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index 23aab63b75..4b9232d670 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -79,7 +79,6 @@ public: protected: void determineWindowClass(); NSWindow *createWindow(); - NSRect globalGeometry(const QRect localWindowGeometry) const; QRect windowGeometry() const; QCocoaWindow *parentCocoaWindow() const; diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index e587b05dec..091c2651dd 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -94,10 +94,13 @@ QCocoaWindow::~QCocoaWindow() void QCocoaWindow::setGeometry(const QRect &rect) { + if (geometry() == rect) + return; QPlatformWindow::setGeometry(rect); - NSRect bounds = globalGeometry(rect); - [[m_nsWindow contentView]setFrameSize:bounds.size]; + NSRect bounds = qt_mac_flipRect(rect, window()); + + [[m_nsWindow contentView] setFrameSize:bounds.size]; [m_nsWindow setContentSize : bounds.size]; [m_nsWindow setFrameOrigin : bounds.origin]; @@ -310,7 +313,7 @@ NSWindow * QCocoaWindow::createWindow() wattr |= QtMacCustomizeWindow; } */ - NSRect frame = globalGeometry(window()->geometry()); + NSRect frame = qt_mac_flipRect(window()->geometry(), window()); QCocoaAutoReleasePool pool; NSWindow *window; @@ -362,33 +365,6 @@ NSWindow * QCocoaWindow::createWindow() //qt_syncCocoaTitleBarButtons(window, widget); return window; } - -// Calculate the global screen geometry for the given local geometry, which -// might be in the parent window coordinate system. -NSRect QCocoaWindow::globalGeometry(const QRect localGeometry) const -{ - QRect finalGeometry = localGeometry; - - if (QCocoaWindow *parent = parentCocoaWindow()) { - QRect parentGeometry = parent->windowGeometry(); - finalGeometry.adjust(parentGeometry.x(), parentGeometry.y(), parentGeometry.x(), parentGeometry.y()); - - // Qt child window geometry assumes that the origin is at the - // top-left of the content area of the parent window. The title - // bar is not a part of this content area, but is still included - // in the NSWindow height. Move the child window down to account - // for this if the parent window has a title bar. - const int titlebarHeight = 22; - if (!(window()->windowFlags() & Qt::FramelessWindowHint)) - finalGeometry.adjust(0, titlebarHeight, 0, titlebarHeight); - } - - // The final "y invert" to get OS X global geometry: - QPlatformScreen *onScreen = QPlatformScreen::platformScreenForWindow(window()); - int flippedY = onScreen->geometry().height() - finalGeometry.y() - finalGeometry.height(); - return NSMakeRect(finalGeometry.x(), flippedY, finalGeometry.width(), finalGeometry.height()); -} - // Returns the current global screen geometry for the nswindow associated with this window. QRect QCocoaWindow::windowGeometry() const { |