Cocoa: Make sure modal windows get correct geometry on show

beginModalSessionForWindow will center the window and ignore
the set geometry. So to workaround this it checks the new value
against the old one and moves it back if need be.

Change-Id: I38bc74c04138992f2e0570fca666414025aeeba8
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
This commit is contained in:
Andy Shaw 2014-05-19 19:58:35 +02:00 committed by The Qt Project
parent f7af9fb632
commit 5d48eb8bbc
2 changed files with 18 additions and 1 deletions

View File

@ -622,7 +622,8 @@ NSModalSession QCocoaEventDispatcherPrivate::currentModalSession()
if (!info.session) {
QCocoaAutoReleasePool pool;
NSWindow *nswindow = static_cast<QCocoaWindow *>(info.window->handle())->nativeWindow();
QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(info.window->handle());
NSWindow *nswindow = cocoaWindow->nativeWindow();
if (!nswindow)
continue;
@ -630,7 +631,10 @@ NSModalSession QCocoaEventDispatcherPrivate::currentModalSession()
QBoolBlocker block1(blockSendPostedEvents, true);
info.nswindow = nswindow;
[(NSWindow*) info.nswindow retain];
QRect rect = cocoaWindow->geometry();
info.session = [NSApp beginModalSessionForWindow:nswindow];
if (rect != cocoaWindow->geometry())
cocoaWindow->setGeometry(rect);
}
currentModalSessionCached = info.session;
cleanupModalSessionsNeeded = false;

View File

@ -92,6 +92,7 @@ private slots:
void modalDialogClosingOneOfTwoModal();
void modalWithChildWindow();
void modalWindowModallity();
void modalWindowPosition();
void initTestCase()
{
@ -1429,6 +1430,18 @@ void tst_QWindow::modalWindowModallity()
}
void tst_QWindow::modalWindowPosition()
{
QWindow window;
window.setGeometry(QRect(100, 100, 400, 400));
// Allow for any potential resizing due to constraints
QRect origGeo = window.geometry();
window.setModality(Qt::WindowModal);
window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window));
QCOMPARE(window.geometry(), origGeo);
}
#include <tst_qwindow.moc>
QTEST_MAIN(tst_QWindow)