Cocoa: Set correct child window geometry.
authorMorten Sorvig <morten.sorvig@nokia.com>
Wed, 26 Oct 2011 10:35:52 +0000 (12:35 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 27 Oct 2011 07:38:26 +0000 (09:38 +0200)
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>
src/plugins/platforms/cocoa/qcocoahelpers.h
src/plugins/platforms/cocoa/qcocoahelpers.mm
src/plugins/platforms/cocoa/qcocoawindow.h
src/plugins/platforms/cocoa/qcocoawindow.mm

index 3c1c065..57eaa2f 100644 (file)
@@ -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
 
index 113415f..9777e0c 100644 (file)
@@ -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());
+}
+
index 23aab63..4b9232d 100644 (file)
@@ -79,7 +79,6 @@ public:
 protected:
     void determineWindowClass();
     NSWindow *createWindow();
-    NSRect globalGeometry(const QRect localWindowGeometry) const;
     QRect windowGeometry() const;
     QCocoaWindow *parentCocoaWindow() const;
 
index e587b05..091c265 100644 (file)
@@ -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
 {