diff options
author | Pekka Vuorela <pekka.ta.vuorela@nokia.com> | 2012-03-01 16:54:50 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-22 16:13:21 +0100 |
commit | 7e90df7bf5aafd09ea5ed8bcc370db6a8912d173 (patch) | |
tree | af527348997c94a4b7362e99a0a4aecfaf144489 /tests/auto/gui/kernel/qguiapplication | |
parent | 045c79f5ed6960109f9ebf76775fa1289c5080b0 (diff) |
FocusAboutToChange event to be send before focus changes
Focus change happen as: FocusAboutToChange event -> focus change
-> FocusOut event -> FocusIn event.
Input method need to have focus when calling commit(). Notification
on focus about to be lost allows QWindow implementations to commit in
time.
Also changes QWidget documentation to match code reality.
Change-Id: I17a8a374a33dd700909f79e370b42348869261a6
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'tests/auto/gui/kernel/qguiapplication')
-rw-r--r-- | tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 7664706b93..0c009ec155 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -54,6 +54,7 @@ private slots: void allWindows(); void topLevelWindows(); void abortQuitOnShow(); + void changeFocusWindow(); }; class DummyWindow : public QWindow @@ -195,5 +196,49 @@ void tst_QGuiApplication::abortQuitOnShow() QCOMPARE(app.exec(), 1); } + +class FocusChangeWindow: public QWindow +{ +protected: + virtual bool event(QEvent *ev) + { + if (ev->type() == QEvent::FocusAboutToChange) + windowDuringFocusAboutToChange = qGuiApp->focusWindow(); + return QWindow::event(ev); + } + + virtual void focusOutEvent(QFocusEvent *) + { + windowDuringFocusOut = qGuiApp->focusWindow(); + } + +public: + FocusChangeWindow() : QWindow(), windowDuringFocusAboutToChange(0), windowDuringFocusOut(0) {} + + QWindow *windowDuringFocusAboutToChange; + QWindow *windowDuringFocusOut; +}; + +void tst_QGuiApplication::changeFocusWindow() +{ + int argc = 0; + QGuiApplication app(argc, 0); + + // focus is changed between FocusAboutToChange and FocusChanged + FocusChangeWindow window1, window2; + window1.show(); + window2.show(); + QTest::qWaitForWindowShown(&window1); + QTest::qWaitForWindowShown(&window2); + window1.requestActivateWindow(); + QTRY_COMPARE(app.focusWindow(), &window1); + + window2.requestActivateWindow(); + QTRY_COMPARE(app.focusWindow(), &window2); + QCOMPARE(window1.windowDuringFocusAboutToChange, &window1); + QCOMPARE(window1.windowDuringFocusOut, &window2); +} + + QTEST_APPLESS_MAIN(tst_QGuiApplication) #include "tst_qguiapplication.moc" |