2012-01-20 15:57:21 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2012-09-19 12:28:29 +00:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2012-01-20 15:57:21 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
2012-01-20 15:57:21 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2012-01-20 15:57:21 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3.0 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU General Public License version 3.0 requirements will be
|
|
|
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
2012-01-20 15:57:21 +00:00
|
|
|
**
|
2012-01-24 06:17:24 +00:00
|
|
|
**
|
2012-01-20 15:57:21 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
#include <QtGui/QGuiApplication>
|
2012-01-27 10:49:34 +00:00
|
|
|
#include <QtGui/QWindow>
|
2012-07-26 11:23:28 +00:00
|
|
|
#include <qpa/qwindowsysteminterface.h>
|
2012-09-26 12:15:39 +00:00
|
|
|
#include <qgenericplugin.h>
|
2012-07-26 16:48:56 +00:00
|
|
|
|
2012-01-20 15:57:21 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
class tst_QGuiApplication: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
2012-06-23 12:08:25 +00:00
|
|
|
void displayName();
|
2012-01-20 15:57:21 +00:00
|
|
|
void focusObject();
|
2012-01-27 10:49:34 +00:00
|
|
|
void allWindows();
|
|
|
|
void topLevelWindows();
|
2012-02-11 00:10:07 +00:00
|
|
|
void abortQuitOnShow();
|
2012-03-01 14:54:50 +00:00
|
|
|
void changeFocusWindow();
|
2012-03-22 16:43:25 +00:00
|
|
|
void keyboardModifiers();
|
2012-04-04 18:41:50 +00:00
|
|
|
void modalWindow();
|
2012-05-14 14:58:26 +00:00
|
|
|
void quitOnLastWindowClosed();
|
2012-09-26 12:15:39 +00:00
|
|
|
void genericPluginsAndWindowSystemEvents();
|
2012-01-20 15:57:21 +00:00
|
|
|
};
|
|
|
|
|
2012-06-23 12:08:25 +00:00
|
|
|
void tst_QGuiApplication::displayName()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
|
|
|
char *argv[] = { const_cast<char*>("tst_qguiapplication") };
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
QCOMPARE(::qAppName(), QString::fromLatin1("tst_qguiapplication"));
|
|
|
|
QCOMPARE(QGuiApplication::applicationName(), QString::fromLatin1("tst_qguiapplication"));
|
|
|
|
QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("tst_qguiapplication"));
|
|
|
|
QGuiApplication::setApplicationDisplayName("The GUI Application");
|
|
|
|
QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The GUI Application"));
|
|
|
|
}
|
|
|
|
|
2012-01-20 15:57:21 +00:00
|
|
|
class DummyWindow : public QWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DummyWindow() : m_focusObject(0) {}
|
|
|
|
|
|
|
|
virtual QObject *focusObject() const
|
|
|
|
{
|
|
|
|
return m_focusObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setFocusObject(QObject *object)
|
|
|
|
{
|
|
|
|
m_focusObject = object;
|
|
|
|
emit focusObjectChanged(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
QObject *m_focusObject;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void tst_QGuiApplication::focusObject()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
QGuiApplication app(argc, 0);
|
|
|
|
|
|
|
|
QObject obj1, obj2, obj3;
|
|
|
|
DummyWindow window1;
|
|
|
|
DummyWindow window2;
|
|
|
|
window1.show();
|
|
|
|
|
2012-10-16 09:02:34 +00:00
|
|
|
QSignalSpy spy(&app, SIGNAL(focusObjectChanged(QObject*)));
|
2012-01-20 15:57:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
// verify active window focus propagates to qguiapplication
|
|
|
|
window1.requestActivateWindow();
|
2012-07-20 10:49:12 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(&window1));
|
|
|
|
QCOMPARE(app.focusWindow(), &window1);
|
2012-01-20 15:57:21 +00:00
|
|
|
|
|
|
|
window1.setFocusObject(&obj1);
|
|
|
|
QCOMPARE(app.focusObject(), &obj1);
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
|
|
|
spy.clear();
|
|
|
|
window1.setFocusObject(&obj2);
|
|
|
|
QCOMPARE(app.focusObject(), &obj2);
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
|
|
|
spy.clear();
|
|
|
|
window2.setFocusObject(&obj3);
|
|
|
|
QCOMPARE(app.focusObject(), &obj2); // not yet changed
|
|
|
|
window2.show();
|
2012-07-20 10:49:12 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window2));
|
2012-01-20 15:57:21 +00:00
|
|
|
QTRY_COMPARE(app.focusWindow(), &window2);
|
|
|
|
QCOMPARE(app.focusObject(), &obj3);
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
|
|
|
// focus change on unfocused window does not show
|
|
|
|
spy.clear();
|
|
|
|
window1.setFocusObject(&obj1);
|
|
|
|
QCOMPARE(spy.count(), 0);
|
|
|
|
QCOMPARE(app.focusObject(), &obj3);
|
|
|
|
}
|
|
|
|
|
2012-01-27 10:49:34 +00:00
|
|
|
void tst_QGuiApplication::allWindows()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
QGuiApplication app(argc, 0);
|
|
|
|
QWindow *window1 = new QWindow;
|
|
|
|
QWindow *window2 = new QWindow(window1);
|
|
|
|
QVERIFY(app.allWindows().contains(window1));
|
|
|
|
QVERIFY(app.allWindows().contains(window2));
|
|
|
|
QCOMPARE(app.allWindows().count(), 2);
|
|
|
|
delete window1;
|
|
|
|
window1 = 0;
|
|
|
|
window2 = 0;
|
|
|
|
QVERIFY(!app.allWindows().contains(window2));
|
|
|
|
QVERIFY(!app.allWindows().contains(window1));
|
|
|
|
QCOMPARE(app.allWindows().count(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QGuiApplication::topLevelWindows()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
QGuiApplication app(argc, 0);
|
|
|
|
QWindow *window1 = new QWindow;
|
|
|
|
QWindow *window2 = new QWindow(window1);
|
|
|
|
QVERIFY(app.topLevelWindows().contains(window1));
|
|
|
|
QVERIFY(!app.topLevelWindows().contains(window2));
|
|
|
|
QCOMPARE(app.topLevelWindows().count(), 1);
|
|
|
|
delete window1;
|
|
|
|
window1 = 0;
|
|
|
|
window2 = 0;
|
|
|
|
QVERIFY(!app.topLevelWindows().contains(window2));
|
|
|
|
QVERIFY(!app.topLevelWindows().contains(window1));
|
|
|
|
QCOMPARE(app.topLevelWindows().count(), 0);
|
|
|
|
}
|
2012-01-20 15:57:21 +00:00
|
|
|
|
2012-02-11 00:10:07 +00:00
|
|
|
class ShowCloseShowWindow : public QWindow
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
ShowCloseShowWindow(bool showAgain, QWindow *parent = 0)
|
|
|
|
: QWindow(parent), showAgain(showAgain)
|
|
|
|
{
|
|
|
|
QTimer::singleShot(0, this, SLOT(doClose()));
|
|
|
|
QTimer::singleShot(500, this, SLOT(exitApp()));
|
|
|
|
}
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void doClose() {
|
|
|
|
close();
|
|
|
|
if (showAgain)
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void exitApp() {
|
|
|
|
qApp->exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool showAgain;
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QGuiApplication::abortQuitOnShow()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
QGuiApplication app(argc, 0);
|
|
|
|
QWindow *window1 = new ShowCloseShowWindow(false);
|
|
|
|
window1->show();
|
|
|
|
QCOMPARE(app.exec(), 0);
|
|
|
|
|
|
|
|
QWindow *window2 = new ShowCloseShowWindow(true);
|
|
|
|
window2->show();
|
|
|
|
QCOMPARE(app.exec(), 1);
|
|
|
|
}
|
|
|
|
|
2012-03-01 14:54:50 +00:00
|
|
|
|
|
|
|
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();
|
2012-07-20 10:49:12 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window1));
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window2));
|
2012-03-01 14:54:50 +00:00
|
|
|
window1.requestActivateWindow();
|
|
|
|
QTRY_COMPARE(app.focusWindow(), &window1);
|
|
|
|
|
|
|
|
window2.requestActivateWindow();
|
|
|
|
QTRY_COMPARE(app.focusWindow(), &window2);
|
|
|
|
QCOMPARE(window1.windowDuringFocusAboutToChange, &window1);
|
|
|
|
QCOMPARE(window1.windowDuringFocusOut, &window2);
|
|
|
|
}
|
|
|
|
|
2012-03-22 16:43:25 +00:00
|
|
|
void tst_QGuiApplication::keyboardModifiers()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
QGuiApplication app(argc, 0);
|
|
|
|
|
|
|
|
QWindow *window = new QWindow;
|
|
|
|
window->show();
|
2012-07-20 10:49:12 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
|
|
|
|
|
|
|
// mouse events
|
|
|
|
QPoint center = window->geometry().center();
|
|
|
|
QTest::mouseEvent(QTest::MousePress, window, Qt::LeftButton, Qt::NoModifier, center);
|
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
|
|
|
QTest::mouseEvent(QTest::MouseRelease, window, Qt::LeftButton, Qt::NoModifier, center);
|
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
|
|
|
QTest::mouseEvent(QTest::MousePress, window, Qt::RightButton, Qt::ControlModifier, center);
|
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
|
|
|
QTest::mouseEvent(QTest::MouseRelease, window, Qt::RightButton, Qt::ControlModifier, center);
|
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
|
|
|
|
|
|
|
// shortcut events
|
2012-09-27 08:37:30 +00:00
|
|
|
QWindowSystemInterface::tryHandleShortcutEvent(window, Qt::Key_5, Qt::MetaModifier);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::MetaModifier);
|
2012-09-27 08:37:30 +00:00
|
|
|
QWindowSystemInterface::tryHandleShortcutEvent(window, Qt::Key_Period, Qt::NoModifier);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
2012-09-27 08:37:30 +00:00
|
|
|
QWindowSystemInterface::tryHandleShortcutEvent(window, Qt::Key_0, Qt::ControlModifier);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
|
|
|
|
|
|
|
// key events
|
|
|
|
QTest::keyEvent(QTest::Press, window, Qt::Key_C);
|
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
|
|
|
QTest::keyEvent(QTest::Release, window, Qt::Key_C);
|
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
|
|
|
|
|
|
|
QTest::keyEvent(QTest::Press, window, Qt::Key_U, Qt::ControlModifier);
|
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
|
|
|
QTest::keyEvent(QTest::Release, window, Qt::Key_U, Qt::ControlModifier);
|
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
|
|
|
|
|
|
|
QTest::keyEvent(QTest::Press, window, Qt::Key_T);
|
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
|
|
|
QTest::keyEvent(QTest::Release, window, Qt::Key_T);
|
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
|
|
|
|
|
|
|
QTest::keyEvent(QTest::Press, window, Qt::Key_E, Qt::ControlModifier);
|
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
|
|
|
QTest::keyEvent(QTest::Release, window, Qt::Key_E, Qt::ControlModifier);
|
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
|
|
|
|
|
|
|
// wheel events
|
|
|
|
QPoint global = window->mapToGlobal(center);
|
|
|
|
QPoint delta(0, 1);
|
|
|
|
QWindowSystemInterface::handleWheelEvent(window, center, global, delta, delta, Qt::NoModifier);
|
2012-07-23 14:56:11 +00:00
|
|
|
QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
|
|
|
QWindowSystemInterface::handleWheelEvent(window, center, global, delta, delta, Qt::AltModifier);
|
2012-07-23 14:56:11 +00:00
|
|
|
QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::AltModifier);
|
|
|
|
QWindowSystemInterface::handleWheelEvent(window, center, global, delta, delta, Qt::ControlModifier);
|
2012-07-23 14:56:11 +00:00
|
|
|
QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
|
|
|
|
|
|
|
// touch events
|
|
|
|
QList<const QTouchDevice *> touchDevices = QTouchDevice::devices();
|
|
|
|
if (!touchDevices.isEmpty()) {
|
|
|
|
QTouchDevice *touchDevice = const_cast<QTouchDevice *>(touchDevices.first());
|
|
|
|
QTest::touchEvent(window, touchDevice).press(1, center).release(1, center);
|
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
window->close();
|
|
|
|
delete window;
|
|
|
|
}
|
2012-03-01 14:54:50 +00:00
|
|
|
|
2012-04-04 18:41:50 +00:00
|
|
|
class BlockableWindow : public QWindow
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
int blocked;
|
2012-10-30 08:21:36 +00:00
|
|
|
int leaves;
|
|
|
|
int enters;
|
2012-04-04 18:41:50 +00:00
|
|
|
|
|
|
|
inline BlockableWindow()
|
2012-10-30 08:21:36 +00:00
|
|
|
: QWindow(), blocked(false), enters(0), leaves(0) {}
|
2012-04-04 18:41:50 +00:00
|
|
|
|
|
|
|
bool event(QEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::WindowBlocked:
|
|
|
|
++blocked;
|
|
|
|
break;
|
|
|
|
case QEvent::WindowUnblocked:
|
|
|
|
--blocked;
|
|
|
|
break;
|
2012-10-30 08:21:36 +00:00
|
|
|
case QEvent::Leave:
|
|
|
|
leaves++;
|
|
|
|
break;
|
|
|
|
case QEvent::Enter:
|
|
|
|
enters++;
|
|
|
|
break;
|
2012-04-04 18:41:50 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return QWindow::event(e);
|
|
|
|
}
|
2012-10-30 08:21:36 +00:00
|
|
|
|
|
|
|
void resetCounts()
|
|
|
|
{
|
|
|
|
leaves = 0;
|
|
|
|
enters = 0;
|
|
|
|
}
|
2012-04-04 18:41:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QGuiApplication::modalWindow()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
QGuiApplication app(argc, 0);
|
|
|
|
|
|
|
|
BlockableWindow *window1 = new BlockableWindow;
|
|
|
|
|
|
|
|
BlockableWindow *window2 = new BlockableWindow;
|
|
|
|
|
|
|
|
BlockableWindow *windowModalWindow1 = new BlockableWindow;
|
|
|
|
windowModalWindow1->setTransientParent(window1);
|
|
|
|
windowModalWindow1->setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
|
|
BlockableWindow *windowModalWindow2 = new BlockableWindow;
|
|
|
|
windowModalWindow2->setTransientParent(windowModalWindow1);
|
|
|
|
windowModalWindow2->setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
|
|
BlockableWindow *applicationModalWindow1 = new BlockableWindow;
|
|
|
|
applicationModalWindow1->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
|
|
|
// show the 2 windows, nothing is blocked
|
|
|
|
window1->show();
|
|
|
|
window2->show();
|
2012-07-20 10:49:12 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window1));
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window2));
|
2012-04-04 18:41:50 +00:00
|
|
|
QCOMPARE(app.modalWindow(), static_cast<QWindow *>(0));
|
|
|
|
QCOMPARE(window1->blocked, 0);
|
|
|
|
QCOMPARE(window2->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow2->blocked, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->blocked, 0);
|
|
|
|
|
2012-10-30 08:21:36 +00:00
|
|
|
// enter mouse in window1
|
|
|
|
QWindowSystemInterface::handleEnterEvent(window1);
|
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QCOMPARE(window1->enters, 1);
|
|
|
|
QCOMPARE(window1->leaves, 0);
|
|
|
|
|
2012-04-04 18:41:50 +00:00
|
|
|
// show applicationModalWindow1, everything is blocked
|
|
|
|
applicationModalWindow1->show();
|
|
|
|
QCOMPARE(app.modalWindow(), applicationModalWindow1);
|
|
|
|
QCOMPARE(window1->blocked, 1);
|
|
|
|
QCOMPARE(window2->blocked, 1);
|
|
|
|
QCOMPARE(windowModalWindow1->blocked, 1);
|
|
|
|
QCOMPARE(windowModalWindow2->blocked, 1);
|
|
|
|
QCOMPARE(applicationModalWindow1->blocked, 0);
|
|
|
|
|
2012-10-30 08:21:36 +00:00
|
|
|
// opening modal causes leave for previously entered window, but not others
|
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QCOMPARE(window1->enters, 1);
|
|
|
|
QCOMPARE(window1->leaves, 1);
|
|
|
|
QCOMPARE(window2->enters, 0);
|
|
|
|
QCOMPARE(window2->leaves, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->enters, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->leaves, 0);
|
|
|
|
window1->resetCounts();
|
|
|
|
|
|
|
|
// Try entering/leaving blocked window2 - no events should reach it
|
|
|
|
QWindowSystemInterface::handleEnterEvent(window2);
|
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QWindowSystemInterface::handleLeaveEvent(window2);
|
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QCOMPARE(window2->enters, 0);
|
|
|
|
QCOMPARE(window2->leaves, 0);
|
|
|
|
|
2012-04-04 18:41:50 +00:00
|
|
|
// everything is unblocked when applicationModalWindow1 is hidden
|
|
|
|
applicationModalWindow1->hide();
|
|
|
|
QCOMPARE(app.modalWindow(), static_cast<QWindow *>(0));
|
|
|
|
QCOMPARE(window1->blocked, 0);
|
|
|
|
QCOMPARE(window2->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow2->blocked, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->blocked, 0);
|
|
|
|
|
2012-10-30 08:21:36 +00:00
|
|
|
// Enter window2 - should not be blocked
|
|
|
|
QWindowSystemInterface::handleEnterEvent(window2);
|
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QCOMPARE(window2->enters, 1);
|
|
|
|
QCOMPARE(window2->leaves, 0);
|
|
|
|
|
2012-04-04 18:41:50 +00:00
|
|
|
// show the windowModalWindow1, only window1 is blocked
|
|
|
|
windowModalWindow1->show();
|
|
|
|
QCOMPARE(app.modalWindow(), windowModalWindow1);
|
|
|
|
QCOMPARE(window1->blocked, 1);
|
|
|
|
QCOMPARE(window2->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow2->blocked, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->blocked, 0);
|
|
|
|
|
2012-10-30 08:21:36 +00:00
|
|
|
// opening window modal window doesn't cause leave for unblocked window
|
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QCOMPARE(window1->enters, 0);
|
|
|
|
QCOMPARE(window1->leaves, 0);
|
|
|
|
QCOMPARE(window2->enters, 1);
|
|
|
|
QCOMPARE(window2->leaves, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->enters, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->leaves, 0);
|
|
|
|
|
2012-04-04 18:41:50 +00:00
|
|
|
// show the windowModalWindow2, windowModalWindow1 is blocked as well
|
|
|
|
windowModalWindow2->show();
|
|
|
|
QCOMPARE(app.modalWindow(), windowModalWindow2);
|
|
|
|
QCOMPARE(window1->blocked, 1);
|
|
|
|
QCOMPARE(window2->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->blocked, 1);
|
|
|
|
QCOMPARE(windowModalWindow2->blocked, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->blocked, 0);
|
|
|
|
|
|
|
|
// hide windowModalWindow1, nothing is unblocked
|
|
|
|
windowModalWindow1->hide();
|
|
|
|
QCOMPARE(app.modalWindow(), windowModalWindow2);
|
|
|
|
QCOMPARE(window1->blocked, 1);
|
|
|
|
QCOMPARE(window2->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->blocked, 1);
|
|
|
|
QCOMPARE(windowModalWindow2->blocked, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->blocked, 0);
|
|
|
|
|
|
|
|
// hide windowModalWindow2, windowModalWindow1 and window1 are unblocked
|
|
|
|
windowModalWindow2->hide();
|
|
|
|
QCOMPARE(app.modalWindow(), static_cast<QWindow *>(0));
|
|
|
|
QCOMPARE(window1->blocked, 0);
|
|
|
|
QCOMPARE(window2->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow2->blocked, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->blocked, 0);
|
|
|
|
|
|
|
|
// show windowModalWindow1 again, window1 is blocked
|
|
|
|
windowModalWindow1->show();
|
|
|
|
QCOMPARE(app.modalWindow(), windowModalWindow1);
|
|
|
|
QCOMPARE(window1->blocked, 1);
|
|
|
|
QCOMPARE(window2->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow2->blocked, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->blocked, 0);
|
|
|
|
|
|
|
|
// show windowModalWindow2 again, windowModalWindow1 is also blocked
|
|
|
|
windowModalWindow2->show();
|
|
|
|
QCOMPARE(app.modalWindow(), windowModalWindow2);
|
|
|
|
QCOMPARE(window1->blocked, 1);
|
|
|
|
QCOMPARE(window2->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->blocked, 1);
|
|
|
|
QCOMPARE(windowModalWindow2->blocked, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->blocked, 0);
|
|
|
|
|
|
|
|
// show applicationModalWindow1, everything is blocked
|
|
|
|
applicationModalWindow1->show();
|
|
|
|
QCOMPARE(app.modalWindow(), applicationModalWindow1);
|
|
|
|
QCOMPARE(window1->blocked, 1);
|
|
|
|
QCOMPARE(window2->blocked, 1);
|
|
|
|
QCOMPARE(windowModalWindow1->blocked, 1);
|
|
|
|
QCOMPARE(windowModalWindow2->blocked, 1);
|
|
|
|
QCOMPARE(applicationModalWindow1->blocked, 0);
|
|
|
|
|
2012-10-30 08:21:36 +00:00
|
|
|
// window2 gets finally the leave
|
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QCOMPARE(window1->enters, 0);
|
|
|
|
QCOMPARE(window1->leaves, 0);
|
|
|
|
QCOMPARE(window2->enters, 1);
|
|
|
|
QCOMPARE(window2->leaves, 1);
|
|
|
|
QCOMPARE(windowModalWindow1->enters, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->leaves, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->enters, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->leaves, 0);
|
|
|
|
|
2012-04-04 18:41:50 +00:00
|
|
|
// hide applicationModalWindow1, windowModalWindow1 and window1 are blocked
|
|
|
|
applicationModalWindow1->hide();
|
|
|
|
QCOMPARE(app.modalWindow(), windowModalWindow2);
|
|
|
|
QCOMPARE(window1->blocked, 1);
|
|
|
|
QCOMPARE(window2->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->blocked, 1);
|
|
|
|
QCOMPARE(windowModalWindow2->blocked, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->blocked, 0);
|
|
|
|
|
|
|
|
// hide windowModalWindow2, window1 is blocked
|
|
|
|
windowModalWindow2->hide();
|
|
|
|
QCOMPARE(app.modalWindow(), windowModalWindow1);
|
|
|
|
QCOMPARE(window1->blocked, 1);
|
|
|
|
QCOMPARE(window2->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow2->blocked, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->blocked, 0);
|
|
|
|
|
|
|
|
// hide windowModalWindow1, everything is unblocked
|
|
|
|
windowModalWindow1->hide();
|
|
|
|
QCOMPARE(app.modalWindow(), static_cast<QWindow *>(0));
|
|
|
|
QCOMPARE(window1->blocked, 0);
|
|
|
|
QCOMPARE(window2->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow2->blocked, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->blocked, 0);
|
|
|
|
|
|
|
|
window2->hide();
|
|
|
|
window1->hide();
|
|
|
|
|
|
|
|
delete applicationModalWindow1;
|
|
|
|
delete windowModalWindow2;
|
|
|
|
delete windowModalWindow1;
|
|
|
|
delete window2;
|
|
|
|
delete window1;
|
|
|
|
}
|
|
|
|
|
2012-05-14 14:58:26 +00:00
|
|
|
void tst_QGuiApplication::quitOnLastWindowClosed()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
QGuiApplication app(argc, 0);
|
|
|
|
|
|
|
|
QTimer timer;
|
|
|
|
timer.setInterval(100);
|
|
|
|
|
|
|
|
QSignalSpy spy(&app, SIGNAL(aboutToQuit()));
|
|
|
|
QSignalSpy spy2(&timer, SIGNAL(timeout()));
|
|
|
|
|
|
|
|
QPointer<QWindow> mainWindow = new QWindow;
|
|
|
|
QPointer<QWindow> dialog = new QWindow;
|
|
|
|
|
|
|
|
dialog->setTransientParent(mainWindow);
|
|
|
|
|
|
|
|
QVERIFY(app.quitOnLastWindowClosed());
|
|
|
|
|
|
|
|
mainWindow->show();
|
|
|
|
dialog->show();
|
|
|
|
|
|
|
|
timer.start();
|
|
|
|
QTimer::singleShot(1000, mainWindow, SLOT(close())); // This should quit the application
|
|
|
|
QTimer::singleShot(2000, &app, SLOT(quit())); // This makes sure we quit even if it didn't
|
|
|
|
|
|
|
|
app.exec();
|
|
|
|
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
QVERIFY(spy2.count() < 15); // Should be around 10 if closing caused the quit
|
|
|
|
}
|
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
QGuiApplication app(argc, 0);
|
|
|
|
|
|
|
|
QTimer timer;
|
|
|
|
timer.setInterval(100);
|
|
|
|
|
|
|
|
QSignalSpy spy(&app, SIGNAL(aboutToQuit()));
|
|
|
|
QSignalSpy spy2(&timer, SIGNAL(timeout()));
|
|
|
|
|
|
|
|
QPointer<QWindow> mainWindow = new QWindow;
|
|
|
|
QPointer<QWindow> dialog = new QWindow;
|
|
|
|
|
|
|
|
QVERIFY(!dialog->transientParent());
|
|
|
|
QVERIFY(app.quitOnLastWindowClosed());
|
|
|
|
|
|
|
|
mainWindow->show();
|
|
|
|
dialog->show();
|
|
|
|
|
|
|
|
timer.start();
|
|
|
|
QTimer::singleShot(1000, mainWindow, SLOT(close())); // This should not quit the application
|
|
|
|
QTimer::singleShot(2000, &app, SLOT(quit()));
|
|
|
|
|
|
|
|
app.exec();
|
|
|
|
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
QVERIFY(spy2.count() > 15); // Should be around 20 if closing did not cause the quit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-26 12:15:39 +00:00
|
|
|
static Qt::ScreenOrientation testOrientationToSend = Qt::PrimaryOrientation;
|
|
|
|
|
|
|
|
class TestPlugin : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
TestPlugin()
|
|
|
|
{
|
|
|
|
QScreen* screen = QGuiApplication::primaryScreen();
|
|
|
|
// Make sure the orientation we want to send doesn't get filtered out.
|
|
|
|
screen->setOrientationUpdateMask(screen->orientationUpdateMask() | testOrientationToSend);
|
|
|
|
QWindowSystemInterface::handleScreenOrientationChange(screen, testOrientationToSend);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class TestPluginFactory : public QGenericPlugin
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QGenericPluginFactoryInterface" FILE "testplugin.json")
|
|
|
|
public:
|
|
|
|
QObject* create(const QString &key, const QString &)
|
|
|
|
{
|
|
|
|
if (key == "testplugin")
|
|
|
|
return new TestPlugin;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class TestEventReceiver : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
int customEvents;
|
|
|
|
|
|
|
|
TestEventReceiver()
|
|
|
|
: customEvents(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual void customEvent(QEvent *)
|
|
|
|
{
|
|
|
|
customEvents++;
|
|
|
|
}
|
|
|
|
};
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2012-01-20 15:57:21 +00:00
|
|
|
#include "tst_qguiapplication.moc"
|
2012-09-26 12:15:39 +00:00
|
|
|
|
|
|
|
void tst_QGuiApplication::genericPluginsAndWindowSystemEvents()
|
|
|
|
{
|
|
|
|
testOrientationToSend = Qt::InvertedLandscapeOrientation;
|
|
|
|
|
|
|
|
TestEventReceiver testReceiver;
|
|
|
|
QCoreApplication::postEvent(&testReceiver, new QEvent(QEvent::User));
|
|
|
|
QCOMPARE(testReceiver.customEvents, 0);
|
|
|
|
|
|
|
|
QStaticPlugin testPluginInfo;
|
|
|
|
testPluginInfo.instance = qt_plugin_instance;
|
|
|
|
testPluginInfo.metaData = qt_plugin_query_metadata;
|
|
|
|
qRegisterStaticPluginFunction(testPluginInfo);
|
|
|
|
int argc = 3;
|
|
|
|
char *argv[] = { const_cast<char*>("tst_qguiapplication"), const_cast<char*>("-plugin"), const_cast<char*>("testplugin") };
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
|
|
|
|
QVERIFY(QGuiApplication::primaryScreen());
|
|
|
|
QVERIFY(QGuiApplication::primaryScreen()->orientation() == testOrientationToSend);
|
|
|
|
|
|
|
|
QCOMPARE(testReceiver.customEvents, 0);
|
|
|
|
QCoreApplication::sendPostedEvents(&testReceiver);
|
|
|
|
QCOMPARE(testReceiver.customEvents, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_APPLESS_MAIN(tst_QGuiApplication)
|