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>
bb10
Morten Sorvig 2011-10-26 12:35:52 +02:00 committed by Qt by Nokia
parent db44fdf4d6
commit 3849455ee7
4 changed files with 14 additions and 31 deletions

View 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

View 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());
}

View File

@ -79,7 +79,6 @@ public:
protected:
void determineWindowClass();
NSWindow *createWindow();
NSRect globalGeometry(const QRect localWindowGeometry) const;
QRect windowGeometry() const;
QCocoaWindow *parentCocoaWindow() const;

View 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
{