QGuiApplicationPrivate::updateBlockedStatus(): Recurse over children.

Task-number: QTBUG-32242

Change-Id: Ia43257a998507b9a367f41dc2395ab92cc89a118
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
This commit is contained in:
Friedemann Kleint 2013-07-16 13:11:06 +02:00 committed by The Qt Project
parent e89547fff4
commit aab50ad061
2 changed files with 21 additions and 9 deletions

View File

@ -477,18 +477,25 @@ QWindow *QGuiApplication::modalWindow()
return QGuiApplicationPrivate::self->modalWindowList.first();
}
static void updateBlockedStatusRecursion(QWindow *window, bool shouldBeBlocked)
{
QWindowPrivate *p = qt_window_private(window);
if (p->blockedByModalWindow != shouldBeBlocked) {
p->blockedByModalWindow = shouldBeBlocked;
QEvent e(shouldBeBlocked ? QEvent::WindowBlocked : QEvent::WindowUnblocked);
QGuiApplication::sendEvent(window, &e);
foreach (QObject *c, window->children())
if (c->isWindowType())
updateBlockedStatusRecursion(static_cast<QWindow *>(c), shouldBeBlocked);
}
}
void QGuiApplicationPrivate::updateBlockedStatus(QWindow *window)
{
bool shouldBeBlocked = false;
if ((window->type() & Qt::Popup) != Qt::Popup && !self->modalWindowList.isEmpty())
shouldBeBlocked = self->isWindowBlocked(window);
if (shouldBeBlocked != window->d_func()->blockedByModalWindow) {
QEvent e(shouldBeBlocked ? QEvent::WindowBlocked : QEvent::WindowUnblocked);
window->d_func()->blockedByModalWindow = shouldBeBlocked;
QGuiApplication::sendEvent(window, &e);
}
updateBlockedStatusRecursion(window, shouldBeBlocked);
}
void QGuiApplicationPrivate::showModalWindow(QWindow *modal)

View File

@ -372,8 +372,8 @@ public:
int leaves;
int enters;
inline BlockableWindow()
: QWindow(), blocked(false), leaves(0), enters(0) {}
inline explicit BlockableWindow(QWindow *parent = 0)
: QWindow(parent), blocked(false), leaves(0), enters(0) {}
bool event(QEvent *e)
{
@ -416,6 +416,8 @@ void tst_QGuiApplication::modalWindow()
window1->setTitle(QStringLiteral("window1"));
window1->resize(windowSize, windowSize);
window1->setFramePosition(QPoint(x, y));
BlockableWindow *childWindow1 = new BlockableWindow(window1.data());
childWindow1->resize(windowSize / 2, windowSize / 2);
x += spacing + windowSize;
QScopedPointer<BlockableWindow> window2(new BlockableWindow);
@ -458,6 +460,7 @@ void tst_QGuiApplication::modalWindow()
QVERIFY(QTest::qWaitForWindowExposed(window2.data()));
QCOMPARE(app.modalWindow(), static_cast<QWindow *>(0));
QCOMPARE(window1->blocked, 0);
QCOMPARE(childWindow1->blocked, 0);
QCOMPARE(window2->blocked, 0);
QCOMPARE(windowModalWindow1->blocked, 0);
QCOMPARE(windowModalWindow2->blocked, 0);
@ -473,6 +476,7 @@ void tst_QGuiApplication::modalWindow()
applicationModalWindow1->show();
QCOMPARE(app.modalWindow(), applicationModalWindow1.data());
QCOMPARE(window1->blocked, 1);
QCOMPARE(childWindow1->blocked, 1); // QTBUG-32242, blocked status needs to be set on children as well.
QCOMPARE(window2->blocked, 1);
QCOMPARE(windowModalWindow1->blocked, 1);
QCOMPARE(windowModalWindow2->blocked, 1);
@ -500,6 +504,7 @@ void tst_QGuiApplication::modalWindow()
applicationModalWindow1->hide();
QCOMPARE(app.modalWindow(), static_cast<QWindow *>(0));
QCOMPARE(window1->blocked, 0);
QCOMPARE(childWindow1->blocked, 0); // QTBUG-32242, blocked status needs to be set on children as well.
QCOMPARE(window2->blocked, 0);
QCOMPARE(windowModalWindow1->blocked, 0);
QCOMPARE(windowModalWindow2->blocked, 0);