2012-01-20 15:57:21 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-01-20 15:57:21 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
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
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
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>
|
2013-07-10 15:21:36 +00:00
|
|
|
#include <QtGui/QScreen>
|
|
|
|
#include <QtGui/QCursor>
|
2015-02-23 16:01:24 +00:00
|
|
|
#include <QtGui/QFont>
|
2014-06-20 08:55:18 +00:00
|
|
|
#include <QtGui/QPalette>
|
2015-02-23 16:01:24 +00:00
|
|
|
#include <QtGui/QStyleHints>
|
2018-03-05 09:18:35 +00:00
|
|
|
#include <qpa/qplatformintegration.h>
|
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
|
|
|
|
2018-03-05 09:18:35 +00:00
|
|
|
#include <private/qguiapplication_p.h>
|
|
|
|
|
2014-04-10 09:39:05 +00:00
|
|
|
#if defined(Q_OS_QNX)
|
|
|
|
#include <QOpenGLContext>
|
|
|
|
#endif
|
|
|
|
|
2014-09-09 08:06:45 +00:00
|
|
|
#include <QtGui/private/qopenglcontext_p.h>
|
|
|
|
|
2012-01-20 15:57:21 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
2013-09-25 14:28:24 +00:00
|
|
|
#include "tst_qcoreapplication.h"
|
|
|
|
|
2013-07-10 15:21:36 +00:00
|
|
|
enum { spacing = 50, windowSize = 200 };
|
|
|
|
|
2013-09-25 14:28:24 +00:00
|
|
|
class tst_QGuiApplication: public tst_QCoreApplication
|
2012-01-20 15:57:21 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
2015-09-09 12:45:18 +00:00
|
|
|
void initTestCase();
|
2014-07-24 13:11:27 +00:00
|
|
|
void cleanup();
|
2012-06-23 12:08:25 +00:00
|
|
|
void displayName();
|
2015-08-13 14:37:07 +00:00
|
|
|
void desktopFileName();
|
2014-01-30 20:59:41 +00:00
|
|
|
void firstWindowTitle();
|
2014-04-04 17:28:43 +00:00
|
|
|
void windowIcon();
|
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();
|
2014-06-20 08:55:18 +00:00
|
|
|
void palette();
|
2017-09-27 09:51:58 +00:00
|
|
|
void font();
|
2012-04-04 18:41:50 +00:00
|
|
|
void modalWindow();
|
2012-05-14 14:58:26 +00:00
|
|
|
void quitOnLastWindowClosed();
|
2017-02-22 14:38:33 +00:00
|
|
|
void quitOnLastWindowClosedMulti();
|
|
|
|
void dontQuitOnLastWindowClosed();
|
2012-09-26 12:15:39 +00:00
|
|
|
void genericPluginsAndWindowSystemEvents();
|
2014-06-20 08:28:01 +00:00
|
|
|
void layoutDirection();
|
2014-09-09 08:06:45 +00:00
|
|
|
void globalShareContext();
|
2015-03-28 20:03:29 +00:00
|
|
|
void testSetPaletteAttribute();
|
2015-02-23 16:01:24 +00:00
|
|
|
|
2015-02-24 08:35:56 +00:00
|
|
|
void staticFunctions();
|
|
|
|
|
2015-02-23 16:01:24 +00:00
|
|
|
void settableStyleHints_data();
|
|
|
|
void settableStyleHints(); // Needs to run last as it changes style hints.
|
2012-01-20 15:57:21 +00:00
|
|
|
};
|
|
|
|
|
2015-09-09 12:45:18 +00:00
|
|
|
void tst_QGuiApplication::initTestCase()
|
|
|
|
{
|
|
|
|
#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
|
|
|
|
if ((QString::compare(QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME),
|
|
|
|
QStringLiteral("eglfs"), Qt::CaseInsensitive) == 0) ||
|
|
|
|
(QString::compare(QString::fromLatin1(qgetenv("QT_QPA_PLATFORM")),
|
|
|
|
QStringLiteral("eglfs"), Qt::CaseInsensitive) == 0)) {
|
|
|
|
// Set env variables to disable input and cursor because eglfs is single fullscreen window
|
|
|
|
// and trying to initialize input and cursor will crash test.
|
|
|
|
qputenv("QT_QPA_EGLFS_DISABLE_INPUT", "1");
|
|
|
|
qputenv("QT_QPA_EGLFS_HIDECURSOR", "1");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-07-24 13:11:27 +00:00
|
|
|
void tst_QGuiApplication::cleanup()
|
|
|
|
{
|
|
|
|
QVERIFY(QGuiApplication::allWindows().isEmpty());
|
|
|
|
}
|
|
|
|
|
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);
|
2016-05-14 09:43:04 +00:00
|
|
|
QSignalSpy spy(&app, &QGuiApplication::applicationDisplayNameChanged);
|
|
|
|
|
2012-06-23 12:08:25 +00:00
|
|
|
QCOMPARE(::qAppName(), QString::fromLatin1("tst_qguiapplication"));
|
|
|
|
QCOMPARE(QGuiApplication::applicationName(), QString::fromLatin1("tst_qguiapplication"));
|
|
|
|
QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("tst_qguiapplication"));
|
2016-05-14 09:43:04 +00:00
|
|
|
|
|
|
|
QGuiApplication::setApplicationName("The Core Application");
|
|
|
|
QCOMPARE(QGuiApplication::applicationName(), QString::fromLatin1("The Core Application"));
|
|
|
|
QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The Core Application"));
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
2012-06-23 12:08:25 +00:00
|
|
|
QGuiApplication::setApplicationDisplayName("The GUI Application");
|
|
|
|
QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The GUI Application"));
|
2016-05-14 09:43:04 +00:00
|
|
|
QCOMPARE(spy.count(), 2);
|
|
|
|
|
|
|
|
QGuiApplication::setApplicationName("The Core Application 2");
|
|
|
|
QCOMPARE(QGuiApplication::applicationName(), QString::fromLatin1("The Core Application 2"));
|
|
|
|
QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The GUI Application"));
|
|
|
|
QCOMPARE(spy.count(), 2);
|
|
|
|
|
|
|
|
QGuiApplication::setApplicationDisplayName("The GUI Application 2");
|
|
|
|
QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The GUI Application 2"));
|
|
|
|
QCOMPARE(spy.count(), 3);
|
2012-06-23 12:08:25 +00:00
|
|
|
}
|
|
|
|
|
2015-08-13 14:37:07 +00:00
|
|
|
void tst_QGuiApplication::desktopFileName()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
|
|
|
char *argv[] = { const_cast<char*>("tst_qguiapplication") };
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
|
|
|
|
QCOMPARE(QGuiApplication::desktopFileName(), QString());
|
|
|
|
|
|
|
|
QGuiApplication::setDesktopFileName("io.qt.QGuiApplication.desktop");
|
|
|
|
QCOMPARE(QGuiApplication::desktopFileName(), QString::fromLatin1("io.qt.QGuiApplication.desktop"));
|
|
|
|
|
|
|
|
QGuiApplication::setDesktopFileName(QString());
|
|
|
|
QCOMPARE(QGuiApplication::desktopFileName(), QString());
|
|
|
|
}
|
|
|
|
|
2014-01-30 20:59:41 +00:00
|
|
|
void tst_QGuiApplication::firstWindowTitle()
|
|
|
|
{
|
|
|
|
int argc = 3;
|
|
|
|
char *argv[] = { const_cast<char*>("tst_qguiapplication"), const_cast<char*>("-qwindowtitle"), const_cast<char*>("User Title") };
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
QWindow window;
|
|
|
|
window.setTitle("Application Title");
|
|
|
|
window.show();
|
|
|
|
QCOMPARE(window.title(), QString("User Title"));
|
|
|
|
}
|
|
|
|
|
2014-04-04 17:28:43 +00:00
|
|
|
void tst_QGuiApplication::windowIcon()
|
|
|
|
{
|
|
|
|
int argc = 3;
|
|
|
|
char *argv[] = { const_cast<char*>("tst_qguiapplication"), const_cast<char*>("-qwindowicon"), const_cast<char*>(":/icons/usericon.png") };
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
QIcon appIcon(":/icons/appicon.png");
|
|
|
|
app.setWindowIcon(appIcon);
|
|
|
|
|
|
|
|
QWindow window;
|
|
|
|
window.show();
|
|
|
|
|
|
|
|
QIcon userIcon(":/icons/usericon.png");
|
|
|
|
// Comparing icons is hard. cacheKey() differs because the icon was independently loaded.
|
|
|
|
// So we use availableSizes, after making sure that the app and user icons do have different sizes.
|
|
|
|
QVERIFY(userIcon.availableSizes() != appIcon.availableSizes());
|
|
|
|
QCOMPARE(window.icon().availableSizes(), userIcon.availableSizes());
|
|
|
|
}
|
|
|
|
|
2012-01-20 15:57:21 +00:00
|
|
|
class DummyWindow : public QWindow
|
|
|
|
{
|
|
|
|
public:
|
2019-06-05 10:58:54 +00:00
|
|
|
DummyWindow() : m_focusObject(nullptr) {}
|
2012-01-20 15:57:21 +00:00
|
|
|
|
|
|
|
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;
|
2019-06-05 10:58:54 +00:00
|
|
|
QGuiApplication app(argc, nullptr);
|
2012-01-20 15:57:21 +00:00
|
|
|
|
2018-03-05 09:18:35 +00:00
|
|
|
if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))
|
|
|
|
QSKIP("QWindow::requestActivate() is not supported.");
|
2014-08-21 10:37:26 +00:00
|
|
|
|
2012-01-20 15:57:21 +00:00
|
|
|
QObject obj1, obj2, obj3;
|
2013-07-10 15:21:36 +00:00
|
|
|
const QRect screenGeometry = QGuiApplication::primaryScreen()->availableVirtualGeometry();
|
|
|
|
|
2012-01-20 15:57:21 +00:00
|
|
|
DummyWindow window1;
|
2014-04-10 09:39:05 +00:00
|
|
|
#if defined(Q_OS_QNX)
|
|
|
|
window1.setSurfaceType(QSurface::OpenGLSurface);
|
|
|
|
#endif
|
2013-07-10 15:21:36 +00:00
|
|
|
window1.resize(windowSize, windowSize);
|
|
|
|
window1.setTitle(QStringLiteral("focusObject:window1"));
|
|
|
|
window1.setFramePosition(QPoint(screenGeometry.left() + spacing, screenGeometry.top() + spacing));
|
2012-01-20 15:57:21 +00:00
|
|
|
DummyWindow window2;
|
2013-07-10 15:21:36 +00:00
|
|
|
window2.resize(windowSize, windowSize);
|
|
|
|
window2.setFramePosition(QPoint(screenGeometry.left() + 2 * spacing + windowSize, screenGeometry.top() + spacing));
|
|
|
|
window2.setTitle(QStringLiteral("focusObject:window2"));
|
|
|
|
|
2012-01-20 15:57:21 +00:00
|
|
|
window1.show();
|
|
|
|
|
2014-04-10 09:39:05 +00:00
|
|
|
#if defined(Q_OS_QNX) // We either need to create a eglSurface or a create a backing store
|
|
|
|
// and then post the window in order for screen to show the window
|
|
|
|
QOpenGLContext context;
|
|
|
|
context.create();
|
|
|
|
context.makeCurrent(&window1);
|
2017-09-08 16:42:25 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window1)); // Buffer swap only succeeds with exposed window
|
2014-04-10 09:39:05 +00:00
|
|
|
context.swapBuffers(&window1);
|
|
|
|
#endif
|
|
|
|
|
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
|
Rename all QWindow properties that have "window" in them
windowTitle, windowModality, windowIcon and so on are named that way
to be similar to the ones in QWidget. However QQuickWindow inherits
all of the declared properties, and we would like to have shorter
property names in QML. If you are working with a Window then it's
obvious the title property is the window title. Unfortunately,
there must be patches in many other modules which depend on this one.
In order to avoid the need to merge them all at the same time,
there is also patch https://codereview.qt-project.org/#change,39001
which temporarily adds backwards-compatible accessors, which can be
removed after the other modules are able to build without them.
We should not rename windowState to state, because in QML, state
usually drives the state machine for animation transitions etc.
(although QWindow is not an Item, a user might get confused about it).
Related patches are
https://codereview.qt-project.org/#change,39001
https://codereview.qt-project.org/#change,37764
https://codereview.qt-project.org/#change,37765
https://codereview.qt-project.org/#change,37766
https://codereview.qt-project.org/#change,37762
Change-Id: Ie4424ec15fbdef6b29b137f90a2ae33f173edd21
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
2012-10-22 10:47:34 +00:00
|
|
|
window1.requestActivate();
|
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;
|
2019-06-05 10:58:54 +00:00
|
|
|
QGuiApplication app(argc, nullptr);
|
2012-01-27 10:49:34 +00:00
|
|
|
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;
|
2019-06-05 10:58:54 +00:00
|
|
|
window1 = nullptr;
|
|
|
|
window2 = nullptr;
|
2012-01-27 10:49:34 +00:00
|
|
|
QVERIFY(!app.allWindows().contains(window2));
|
|
|
|
QVERIFY(!app.allWindows().contains(window1));
|
|
|
|
QCOMPARE(app.allWindows().count(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QGuiApplication::topLevelWindows()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-06-05 10:58:54 +00:00
|
|
|
QGuiApplication app(argc, nullptr);
|
2012-01-27 10:49:34 +00:00
|
|
|
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;
|
2019-06-05 10:58:54 +00:00
|
|
|
window1 = nullptr;
|
|
|
|
window2 = nullptr;
|
2012-01-27 10:49:34 +00:00
|
|
|
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:
|
2019-06-05 10:58:54 +00:00
|
|
|
ShowCloseShowWindow(bool showAgain, QWindow *parent = nullptr)
|
2012-02-11 00:10:07 +00:00
|
|
|
: 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;
|
2019-06-05 10:58:54 +00:00
|
|
|
QGuiApplication app(argc, nullptr);
|
2013-07-10 15:21:36 +00:00
|
|
|
const QRect screenGeometry = QGuiApplication::primaryScreen()->availableVirtualGeometry();
|
|
|
|
|
|
|
|
QScopedPointer<QWindow> window1(new ShowCloseShowWindow(false));
|
|
|
|
window1->resize(windowSize, windowSize);
|
|
|
|
window1->setFramePosition(QPoint(screenGeometry.left() + spacing, screenGeometry.top() + spacing));
|
|
|
|
window1->setTitle(QStringLiteral("abortQuitOnShow:window1"));
|
2012-02-11 00:10:07 +00:00
|
|
|
window1->show();
|
|
|
|
QCOMPARE(app.exec(), 0);
|
|
|
|
|
2013-07-10 15:21:36 +00:00
|
|
|
QScopedPointer<QWindow> window2(new ShowCloseShowWindow(true));
|
|
|
|
window2->setTitle(QStringLiteral("abortQuitOnShow:window2"));
|
|
|
|
window2->resize(windowSize, windowSize);
|
|
|
|
window2->setFramePosition(QPoint(screenGeometry.left() + 2 * spacing + windowSize, screenGeometry.top() + spacing));
|
2012-02-11 00:10:07 +00:00
|
|
|
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:
|
2019-06-05 10:58:54 +00:00
|
|
|
FocusChangeWindow() : QWindow(), windowDuringFocusAboutToChange(nullptr), windowDuringFocusOut(nullptr) {}
|
2012-03-01 14:54:50 +00:00
|
|
|
|
|
|
|
QWindow *windowDuringFocusAboutToChange;
|
|
|
|
QWindow *windowDuringFocusOut;
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QGuiApplication::changeFocusWindow()
|
|
|
|
{
|
2018-05-09 05:15:41 +00:00
|
|
|
#ifdef Q_OS_WINRT
|
|
|
|
QSKIP("WinRt does not support multiple native windows.");
|
|
|
|
#endif
|
2012-03-01 14:54:50 +00:00
|
|
|
int argc = 0;
|
2019-06-05 10:58:54 +00:00
|
|
|
QGuiApplication app(argc, nullptr);
|
2014-08-21 10:37:26 +00:00
|
|
|
|
2018-03-05 09:18:35 +00:00
|
|
|
if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))
|
|
|
|
QSKIP("QWindow::requestActivate() is not supported.");
|
2014-08-21 10:37:26 +00:00
|
|
|
|
2013-07-10 15:21:36 +00:00
|
|
|
const QRect screenGeometry = QGuiApplication::primaryScreen()->availableVirtualGeometry();
|
2012-03-01 14:54:50 +00:00
|
|
|
|
|
|
|
// focus is changed between FocusAboutToChange and FocusChanged
|
2013-07-10 15:21:36 +00:00
|
|
|
FocusChangeWindow window1;
|
2014-04-10 09:39:05 +00:00
|
|
|
#if defined(Q_OS_QNX)
|
|
|
|
window1.setSurfaceType(QSurface::OpenGLSurface);
|
|
|
|
#endif
|
2013-07-10 15:21:36 +00:00
|
|
|
window1.resize(windowSize, windowSize);
|
|
|
|
window1.setFramePosition(QPoint(screenGeometry.left() + spacing, screenGeometry.top() + spacing));
|
|
|
|
window1.setTitle(QStringLiteral("changeFocusWindow:window1"));
|
2012-03-01 14:54:50 +00:00
|
|
|
window1.show();
|
2014-04-10 09:39:05 +00:00
|
|
|
#if defined(Q_OS_QNX) // We either need to create a eglSurface or a create a backing store
|
|
|
|
// and then post the window in order for screen to show the window
|
|
|
|
QOpenGLContext context;
|
|
|
|
context.create();
|
|
|
|
context.makeCurrent(&window1);
|
2017-09-08 16:42:25 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window1)); // Buffer swap only succeeds with exposed window
|
2014-04-10 09:39:05 +00:00
|
|
|
context.swapBuffers(&window1);
|
|
|
|
#endif
|
2013-07-10 15:21:36 +00:00
|
|
|
FocusChangeWindow window2;
|
2014-04-10 09:39:05 +00:00
|
|
|
#if defined(Q_OS_QNX)
|
|
|
|
window2.setSurfaceType(QSurface::OpenGLSurface);
|
|
|
|
#endif
|
2013-07-10 15:21:36 +00:00
|
|
|
window2.resize(windowSize, windowSize);
|
|
|
|
window2.setFramePosition(QPoint(screenGeometry.left() + 2 * spacing + windowSize, screenGeometry.top() + spacing));
|
|
|
|
window2.setTitle(QStringLiteral("changeFocusWindow:window2"));
|
2012-03-01 14:54:50 +00:00
|
|
|
window2.show();
|
2014-04-10 09:39:05 +00:00
|
|
|
#if defined(Q_OS_QNX) // We either need to create a eglSurface or a create a backing store
|
|
|
|
// and then post the window in order for screen to show the window
|
|
|
|
context.makeCurrent(&window2);
|
2017-09-08 16:42:25 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window2)); // Buffer swap only succeeds with exposed window
|
2014-04-10 09:39:05 +00:00
|
|
|
context.swapBuffers(&window2);
|
|
|
|
#endif
|
2012-07-20 10:49:12 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window1));
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window2));
|
Rename all QWindow properties that have "window" in them
windowTitle, windowModality, windowIcon and so on are named that way
to be similar to the ones in QWidget. However QQuickWindow inherits
all of the declared properties, and we would like to have shorter
property names in QML. If you are working with a Window then it's
obvious the title property is the window title. Unfortunately,
there must be patches in many other modules which depend on this one.
In order to avoid the need to merge them all at the same time,
there is also patch https://codereview.qt-project.org/#change,39001
which temporarily adds backwards-compatible accessors, which can be
removed after the other modules are able to build without them.
We should not rename windowState to state, because in QML, state
usually drives the state machine for animation transitions etc.
(although QWindow is not an Item, a user might get confused about it).
Related patches are
https://codereview.qt-project.org/#change,39001
https://codereview.qt-project.org/#change,37764
https://codereview.qt-project.org/#change,37765
https://codereview.qt-project.org/#change,37766
https://codereview.qt-project.org/#change,37762
Change-Id: Ie4424ec15fbdef6b29b137f90a2ae33f173edd21
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
2012-10-22 10:47:34 +00:00
|
|
|
window1.requestActivate();
|
2012-03-01 14:54:50 +00:00
|
|
|
QTRY_COMPARE(app.focusWindow(), &window1);
|
|
|
|
|
Rename all QWindow properties that have "window" in them
windowTitle, windowModality, windowIcon and so on are named that way
to be similar to the ones in QWidget. However QQuickWindow inherits
all of the declared properties, and we would like to have shorter
property names in QML. If you are working with a Window then it's
obvious the title property is the window title. Unfortunately,
there must be patches in many other modules which depend on this one.
In order to avoid the need to merge them all at the same time,
there is also patch https://codereview.qt-project.org/#change,39001
which temporarily adds backwards-compatible accessors, which can be
removed after the other modules are able to build without them.
We should not rename windowState to state, because in QML, state
usually drives the state machine for animation transitions etc.
(although QWindow is not an Item, a user might get confused about it).
Related patches are
https://codereview.qt-project.org/#change,39001
https://codereview.qt-project.org/#change,37764
https://codereview.qt-project.org/#change,37765
https://codereview.qt-project.org/#change,37766
https://codereview.qt-project.org/#change,37762
Change-Id: Ie4424ec15fbdef6b29b137f90a2ae33f173edd21
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
2012-10-22 10:47:34 +00:00
|
|
|
window2.requestActivate();
|
2012-03-01 14:54:50 +00:00
|
|
|
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;
|
2019-06-05 10:58:54 +00:00
|
|
|
QGuiApplication app(argc, nullptr);
|
2013-07-10 15:21:36 +00:00
|
|
|
const QRect screenGeometry = QGuiApplication::primaryScreen()->availableVirtualGeometry();
|
|
|
|
|
|
|
|
QScopedPointer<QWindow> window(new QWindow);
|
|
|
|
window->resize(windowSize, windowSize);
|
|
|
|
window->setFramePosition(QPoint(screenGeometry.left() + spacing, screenGeometry.top() + spacing));
|
|
|
|
window->setTitle(QStringLiteral("keyboardModifiers"));
|
2012-03-22 16:43:25 +00:00
|
|
|
|
|
|
|
window->show();
|
2013-07-10 15:21:36 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window.data()));
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
|
|
|
|
|
|
|
// mouse events
|
|
|
|
QPoint center = window->geometry().center();
|
2013-07-10 15:21:36 +00:00
|
|
|
QTest::mouseEvent(QTest::MousePress, window.data(), Qt::LeftButton, Qt::NoModifier, center);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
2013-07-10 15:21:36 +00:00
|
|
|
QTest::mouseEvent(QTest::MouseRelease, window.data(), Qt::LeftButton, Qt::NoModifier, center);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
2013-07-10 15:21:36 +00:00
|
|
|
QTest::mouseEvent(QTest::MousePress, window.data(), Qt::RightButton, Qt::ControlModifier, center);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
2013-07-10 15:21:36 +00:00
|
|
|
QTest::mouseEvent(QTest::MouseRelease, window.data(), Qt::RightButton, Qt::ControlModifier, center);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
|
|
|
|
|
|
|
// shortcut events
|
2015-09-04 15:56:24 +00:00
|
|
|
QTest::keyEvent(QTest::Shortcut, window.data(), Qt::Key_5, Qt::MetaModifier);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::MetaModifier);
|
2015-09-04 15:56:24 +00:00
|
|
|
QTest::keyEvent(QTest::Shortcut, window.data(), Qt::Key_Period, Qt::NoModifier);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
2015-09-04 15:56:24 +00:00
|
|
|
QTest::keyEvent(QTest::Shortcut, window.data(), Qt::Key_0, Qt::ControlModifier);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
|
|
|
|
|
|
|
// key events
|
2013-07-10 15:21:36 +00:00
|
|
|
QTest::keyEvent(QTest::Press, window.data(), Qt::Key_C);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
2013-07-10 15:21:36 +00:00
|
|
|
QTest::keyEvent(QTest::Release, window.data(), Qt::Key_C);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
|
|
|
|
2013-07-10 15:21:36 +00:00
|
|
|
QTest::keyEvent(QTest::Press, window.data(), Qt::Key_U, Qt::ControlModifier);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
2013-07-10 15:21:36 +00:00
|
|
|
QTest::keyEvent(QTest::Release, window.data(), Qt::Key_U, Qt::ControlModifier);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
|
|
|
|
2013-07-10 15:21:36 +00:00
|
|
|
QTest::keyEvent(QTest::Press, window.data(), Qt::Key_T);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
2013-07-10 15:21:36 +00:00
|
|
|
QTest::keyEvent(QTest::Release, window.data(), Qt::Key_T);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
|
|
|
|
2013-07-10 15:21:36 +00:00
|
|
|
QTest::keyEvent(QTest::Press, window.data(), Qt::Key_E, Qt::ControlModifier);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
2013-07-10 15:21:36 +00:00
|
|
|
QTest::keyEvent(QTest::Release, window.data(), Qt::Key_E, Qt::ControlModifier);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
|
|
|
|
|
|
|
|
// wheel events
|
|
|
|
QPoint global = window->mapToGlobal(center);
|
|
|
|
QPoint delta(0, 1);
|
2013-07-10 15:21:36 +00:00
|
|
|
QWindowSystemInterface::handleWheelEvent(window.data(), 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);
|
2013-07-10 15:21:36 +00:00
|
|
|
QWindowSystemInterface::handleWheelEvent(window.data(), 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);
|
2013-07-10 15:21:36 +00:00
|
|
|
QWindowSystemInterface::handleWheelEvent(window.data(), 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());
|
2013-07-10 15:21:36 +00:00
|
|
|
QTest::touchEvent(window.data(), touchDevice).press(1, center).release(1, center);
|
2012-03-22 16:43:25 +00:00
|
|
|
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
window->close();
|
|
|
|
}
|
2012-03-01 14:54:50 +00:00
|
|
|
|
2014-06-20 08:55:18 +00:00
|
|
|
void tst_QGuiApplication::palette()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
|
|
|
char *argv[] = { const_cast<char*>("tst_qguiapplication") };
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
QSignalSpy signalSpy(&app, SIGNAL(paletteChanged(QPalette)));
|
|
|
|
|
|
|
|
QPalette oldPalette = QGuiApplication::palette();
|
|
|
|
QPalette newPalette = QPalette(Qt::red);
|
|
|
|
|
|
|
|
QGuiApplication::setPalette(newPalette);
|
|
|
|
QCOMPARE(QGuiApplication::palette(), newPalette);
|
|
|
|
QCOMPARE(signalSpy.count(), 1);
|
|
|
|
QCOMPARE(signalSpy.at(0).at(0), QVariant(newPalette));
|
|
|
|
|
|
|
|
QGuiApplication::setPalette(oldPalette);
|
|
|
|
QCOMPARE(QGuiApplication::palette(), oldPalette);
|
|
|
|
QCOMPARE(signalSpy.count(), 2);
|
|
|
|
QCOMPARE(signalSpy.at(1).at(0), QVariant(oldPalette));
|
|
|
|
|
|
|
|
QGuiApplication::setPalette(oldPalette);
|
|
|
|
QCOMPARE(QGuiApplication::palette(), oldPalette);
|
|
|
|
QCOMPARE(signalSpy.count(), 2);
|
|
|
|
}
|
|
|
|
|
2017-09-27 09:51:58 +00:00
|
|
|
void tst_QGuiApplication::font()
|
|
|
|
{
|
|
|
|
int argc = 1;
|
|
|
|
char *argv[] = { const_cast<char*>("tst_qguiapplication") };
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
QSignalSpy signalSpy(&app, SIGNAL(fontChanged(QFont)));
|
|
|
|
|
|
|
|
QFont oldFont = QGuiApplication::font();
|
|
|
|
QFont newFont = QFont("BogusFont", 33);
|
|
|
|
|
|
|
|
QGuiApplication::setFont(newFont);
|
|
|
|
QCOMPARE(QGuiApplication::font(), newFont);
|
|
|
|
QCOMPARE(signalSpy.count(), 1);
|
|
|
|
QCOMPARE(signalSpy.at(0).at(0), QVariant(newFont));
|
|
|
|
|
|
|
|
QGuiApplication::setFont(oldFont);
|
|
|
|
QCOMPARE(QGuiApplication::font(), oldFont);
|
|
|
|
QCOMPARE(signalSpy.count(), 2);
|
|
|
|
QCOMPARE(signalSpy.at(1).at(0), QVariant(oldFont));
|
|
|
|
|
|
|
|
QGuiApplication::setFont(oldFont);
|
|
|
|
QCOMPARE(QGuiApplication::font(), oldFont);
|
|
|
|
QCOMPARE(signalSpy.count(), 2);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-06-05 10:58:54 +00:00
|
|
|
inline explicit BlockableWindow(QWindow *parent = nullptr)
|
2013-07-16 11:11:06 +00:00
|
|
|
: QWindow(parent), blocked(false), leaves(0), enters(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()
|
|
|
|
{
|
2018-05-09 05:15:41 +00:00
|
|
|
#ifdef Q_OS_WINRT
|
|
|
|
QSKIP("WinRt does not support multiple native windows.");
|
|
|
|
#endif
|
2012-04-04 18:41:50 +00:00
|
|
|
int argc = 0;
|
2019-06-05 10:58:54 +00:00
|
|
|
QGuiApplication app(argc, nullptr);
|
2013-07-10 15:21:36 +00:00
|
|
|
const QRect screenGeometry = QGuiApplication::primaryScreen()->availableVirtualGeometry();
|
|
|
|
|
|
|
|
int x = screenGeometry.left() + spacing;
|
|
|
|
int y = screenGeometry.top() + spacing;
|
|
|
|
|
|
|
|
QScopedPointer<BlockableWindow> window1(new BlockableWindow);
|
|
|
|
window1->setTitle(QStringLiteral("window1"));
|
|
|
|
window1->resize(windowSize, windowSize);
|
|
|
|
window1->setFramePosition(QPoint(x, y));
|
2013-07-16 11:11:06 +00:00
|
|
|
BlockableWindow *childWindow1 = new BlockableWindow(window1.data());
|
|
|
|
childWindow1->resize(windowSize / 2, windowSize / 2);
|
2013-07-10 15:21:36 +00:00
|
|
|
x += spacing + windowSize;
|
|
|
|
|
|
|
|
QScopedPointer<BlockableWindow> window2(new BlockableWindow);
|
|
|
|
window2->setTitle(QStringLiteral("window2"));
|
2013-07-16 14:03:13 +00:00
|
|
|
window2->setFlags(window2->flags() & Qt::Tool); // QTBUG-32433, don't be fooled by unusual window flags.
|
2013-07-10 15:21:36 +00:00
|
|
|
window2->resize(windowSize, windowSize);
|
|
|
|
window2->setFramePosition(QPoint(x, y));
|
|
|
|
x += spacing + windowSize;
|
|
|
|
|
|
|
|
QScopedPointer<BlockableWindow> windowModalWindow1(new BlockableWindow);
|
|
|
|
windowModalWindow1->setTitle(QStringLiteral("windowModalWindow1"));
|
|
|
|
windowModalWindow1->setTransientParent(window1.data());
|
Rename all QWindow properties that have "window" in them
windowTitle, windowModality, windowIcon and so on are named that way
to be similar to the ones in QWidget. However QQuickWindow inherits
all of the declared properties, and we would like to have shorter
property names in QML. If you are working with a Window then it's
obvious the title property is the window title. Unfortunately,
there must be patches in many other modules which depend on this one.
In order to avoid the need to merge them all at the same time,
there is also patch https://codereview.qt-project.org/#change,39001
which temporarily adds backwards-compatible accessors, which can be
removed after the other modules are able to build without them.
We should not rename windowState to state, because in QML, state
usually drives the state machine for animation transitions etc.
(although QWindow is not an Item, a user might get confused about it).
Related patches are
https://codereview.qt-project.org/#change,39001
https://codereview.qt-project.org/#change,37764
https://codereview.qt-project.org/#change,37765
https://codereview.qt-project.org/#change,37766
https://codereview.qt-project.org/#change,37762
Change-Id: Ie4424ec15fbdef6b29b137f90a2ae33f173edd21
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
2012-10-22 10:47:34 +00:00
|
|
|
windowModalWindow1->setModality(Qt::WindowModal);
|
2013-07-10 15:21:36 +00:00
|
|
|
windowModalWindow1->resize(windowSize, windowSize);
|
|
|
|
windowModalWindow1->setFramePosition(QPoint(x, y));
|
|
|
|
x += spacing + windowSize;
|
2012-04-04 18:41:50 +00:00
|
|
|
|
2013-07-10 15:21:36 +00:00
|
|
|
QScopedPointer<BlockableWindow> windowModalWindow2(new BlockableWindow);
|
|
|
|
windowModalWindow2->setTitle(QStringLiteral("windowModalWindow2"));
|
|
|
|
windowModalWindow2->setTransientParent(windowModalWindow1.data());
|
Rename all QWindow properties that have "window" in them
windowTitle, windowModality, windowIcon and so on are named that way
to be similar to the ones in QWidget. However QQuickWindow inherits
all of the declared properties, and we would like to have shorter
property names in QML. If you are working with a Window then it's
obvious the title property is the window title. Unfortunately,
there must be patches in many other modules which depend on this one.
In order to avoid the need to merge them all at the same time,
there is also patch https://codereview.qt-project.org/#change,39001
which temporarily adds backwards-compatible accessors, which can be
removed after the other modules are able to build without them.
We should not rename windowState to state, because in QML, state
usually drives the state machine for animation transitions etc.
(although QWindow is not an Item, a user might get confused about it).
Related patches are
https://codereview.qt-project.org/#change,39001
https://codereview.qt-project.org/#change,37764
https://codereview.qt-project.org/#change,37765
https://codereview.qt-project.org/#change,37766
https://codereview.qt-project.org/#change,37762
Change-Id: Ie4424ec15fbdef6b29b137f90a2ae33f173edd21
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
2012-10-22 10:47:34 +00:00
|
|
|
windowModalWindow2->setModality(Qt::WindowModal);
|
2013-07-10 15:21:36 +00:00
|
|
|
windowModalWindow2->resize(windowSize, windowSize);
|
|
|
|
windowModalWindow2->setFramePosition(QPoint(x, y));
|
|
|
|
x = screenGeometry.left() + spacing;
|
|
|
|
y += spacing + windowSize;
|
2012-04-04 18:41:50 +00:00
|
|
|
|
2013-07-10 15:21:36 +00:00
|
|
|
QScopedPointer<BlockableWindow> applicationModalWindow1(new BlockableWindow);
|
|
|
|
applicationModalWindow1->setTitle(QStringLiteral("applicationModalWindow1"));
|
Rename all QWindow properties that have "window" in them
windowTitle, windowModality, windowIcon and so on are named that way
to be similar to the ones in QWidget. However QQuickWindow inherits
all of the declared properties, and we would like to have shorter
property names in QML. If you are working with a Window then it's
obvious the title property is the window title. Unfortunately,
there must be patches in many other modules which depend on this one.
In order to avoid the need to merge them all at the same time,
there is also patch https://codereview.qt-project.org/#change,39001
which temporarily adds backwards-compatible accessors, which can be
removed after the other modules are able to build without them.
We should not rename windowState to state, because in QML, state
usually drives the state machine for animation transitions etc.
(although QWindow is not an Item, a user might get confused about it).
Related patches are
https://codereview.qt-project.org/#change,39001
https://codereview.qt-project.org/#change,37764
https://codereview.qt-project.org/#change,37765
https://codereview.qt-project.org/#change,37766
https://codereview.qt-project.org/#change,37762
Change-Id: Ie4424ec15fbdef6b29b137f90a2ae33f173edd21
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
2012-10-22 10:47:34 +00:00
|
|
|
applicationModalWindow1->setModality(Qt::ApplicationModal);
|
2013-07-10 15:21:36 +00:00
|
|
|
applicationModalWindow1->resize(windowSize, windowSize);
|
|
|
|
applicationModalWindow1->setFramePosition(QPoint(x, y));
|
|
|
|
|
|
|
|
#ifndef QT_NO_CURSOR // Get the mouse cursor out of the way since we are manually sending enter/leave.
|
|
|
|
QCursor::setPos(QPoint(x + 2 * spacing + windowSize, y));
|
|
|
|
#endif
|
2012-04-04 18:41:50 +00:00
|
|
|
|
|
|
|
// show the 2 windows, nothing is blocked
|
|
|
|
window1->show();
|
|
|
|
window2->show();
|
2013-07-10 15:21:36 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window1.data()));
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window2.data()));
|
2019-06-05 10:58:54 +00:00
|
|
|
QCOMPARE(app.modalWindow(), static_cast<QWindow *>(nullptr));
|
2012-04-04 18:41:50 +00:00
|
|
|
QCOMPARE(window1->blocked, 0);
|
2013-07-16 11:11:06 +00:00
|
|
|
QCOMPARE(childWindow1->blocked, 0);
|
2012-04-04 18:41:50 +00:00
|
|
|
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
|
2013-07-10 15:21:36 +00:00
|
|
|
QWindowSystemInterface::handleEnterEvent(window1.data());
|
2012-10-30 08:21:36 +00:00
|
|
|
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();
|
2013-07-10 15:21:36 +00:00
|
|
|
QCOMPARE(app.modalWindow(), applicationModalWindow1.data());
|
2012-04-04 18:41:50 +00:00
|
|
|
QCOMPARE(window1->blocked, 1);
|
2013-07-16 11:11:06 +00:00
|
|
|
QCOMPARE(childWindow1->blocked, 1); // QTBUG-32242, blocked status needs to be set on children as well.
|
2012-04-04 18:41:50 +00:00
|
|
|
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
|
2013-07-10 15:21:36 +00:00
|
|
|
QWindowSystemInterface::handleEnterEvent(window2.data());
|
2012-10-30 08:21:36 +00:00
|
|
|
QGuiApplication::processEvents();
|
2013-07-10 15:21:36 +00:00
|
|
|
QWindowSystemInterface::handleLeaveEvent(window2.data());
|
2012-10-30 08:21:36 +00:00
|
|
|
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();
|
2019-06-05 10:58:54 +00:00
|
|
|
QCOMPARE(app.modalWindow(), static_cast<QWindow *>(nullptr));
|
2012-04-04 18:41:50 +00:00
|
|
|
QCOMPARE(window1->blocked, 0);
|
2013-07-16 11:11:06 +00:00
|
|
|
QCOMPARE(childWindow1->blocked, 0); // QTBUG-32242, blocked status needs to be set on children as well.
|
2012-04-04 18:41:50 +00:00
|
|
|
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
|
2013-07-10 15:21:36 +00:00
|
|
|
QWindowSystemInterface::handleEnterEvent(window2.data());
|
2012-10-30 08:21:36 +00:00
|
|
|
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();
|
2013-07-10 15:21:36 +00:00
|
|
|
QCOMPARE(app.modalWindow(), windowModalWindow1.data());
|
2012-04-04 18:41:50 +00:00
|
|
|
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();
|
2013-07-10 15:21:36 +00:00
|
|
|
QCOMPARE(app.modalWindow(), windowModalWindow2.data());
|
2012-04-04 18:41:50 +00:00
|
|
|
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();
|
2013-07-10 15:21:36 +00:00
|
|
|
QCOMPARE(app.modalWindow(), windowModalWindow2.data());
|
2012-04-04 18:41:50 +00:00
|
|
|
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();
|
2019-06-05 10:58:54 +00:00
|
|
|
QCOMPARE(app.modalWindow(), static_cast<QWindow *>(nullptr));
|
2012-04-04 18:41:50 +00:00
|
|
|
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();
|
2013-07-10 15:21:36 +00:00
|
|
|
QCOMPARE(app.modalWindow(), windowModalWindow1.data());
|
2012-04-04 18:41:50 +00:00
|
|
|
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();
|
2013-07-10 15:21:36 +00:00
|
|
|
QCOMPARE(app.modalWindow(), windowModalWindow2.data());
|
2012-04-04 18:41:50 +00:00
|
|
|
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();
|
2013-07-10 15:21:36 +00:00
|
|
|
QCOMPARE(app.modalWindow(), applicationModalWindow1.data());
|
2012-04-04 18:41:50 +00:00
|
|
|
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();
|
2013-07-10 15:21:36 +00:00
|
|
|
QCOMPARE(app.modalWindow(), windowModalWindow2.data());
|
2012-04-04 18:41:50 +00:00
|
|
|
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();
|
2013-07-10 15:21:36 +00:00
|
|
|
QCOMPARE(app.modalWindow(), windowModalWindow1.data());
|
2012-04-04 18:41:50 +00:00
|
|
|
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();
|
2019-06-05 10:58:54 +00:00
|
|
|
QCOMPARE(app.modalWindow(), static_cast<QWindow *>(nullptr));
|
2012-04-04 18:41:50 +00:00
|
|
|
QCOMPARE(window1->blocked, 0);
|
|
|
|
QCOMPARE(window2->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow1->blocked, 0);
|
|
|
|
QCOMPARE(windowModalWindow2->blocked, 0);
|
|
|
|
QCOMPARE(applicationModalWindow1->blocked, 0);
|
|
|
|
|
|
|
|
window2->hide();
|
|
|
|
window1->hide();
|
|
|
|
}
|
|
|
|
|
2012-05-14 14:58:26 +00:00
|
|
|
void tst_QGuiApplication::quitOnLastWindowClosed()
|
|
|
|
{
|
2017-02-22 14:38:33 +00:00
|
|
|
int argc = 0;
|
2019-06-05 10:58:54 +00:00
|
|
|
QGuiApplication app(argc, nullptr);
|
2017-02-22 14:38:33 +00:00
|
|
|
const QRect screenGeometry = QGuiApplication::primaryScreen()->availableVirtualGeometry();
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QTimer timer;
|
|
|
|
timer.setInterval(100);
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QSignalSpy spyAboutToQuit(&app, &QCoreApplication::aboutToQuit);
|
|
|
|
QSignalSpy spyTimeout(&timer, &QTimer::timeout);
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QWindow mainWindow;
|
|
|
|
mainWindow.setTitle(QStringLiteral("quitOnLastWindowClosedMainWindow"));
|
|
|
|
mainWindow.resize(windowSize, windowSize);
|
|
|
|
mainWindow.setFramePosition(QPoint(screenGeometry.left() + spacing, screenGeometry.top() + spacing));
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QWindow dialog;
|
|
|
|
dialog.setTransientParent(&mainWindow);
|
|
|
|
dialog.setTitle(QStringLiteral("quitOnLastWindowClosedDialog"));
|
|
|
|
dialog.resize(windowSize, windowSize);
|
|
|
|
dialog.setFramePosition(QPoint(screenGeometry.left() + 2 * spacing + windowSize, screenGeometry.top() + spacing));
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QVERIFY(app.quitOnLastWindowClosed());
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
mainWindow.show();
|
|
|
|
dialog.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&dialog));
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
timer.start();
|
|
|
|
QTimer::singleShot(1000, &mainWindow, &QWindow::close); // This should quit the application
|
|
|
|
QTimer::singleShot(2000, &app, QCoreApplication::quit); // This makes sure we quit even if it didn't
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
app.exec();
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QCOMPARE(spyAboutToQuit.count(), 1);
|
|
|
|
// Should be around 10 if closing caused the quit
|
|
|
|
QVERIFY2(spyTimeout.count() < 15, QByteArray::number(spyTimeout.count()).constData());
|
|
|
|
}
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
void tst_QGuiApplication::quitOnLastWindowClosedMulti()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-06-05 10:58:54 +00:00
|
|
|
QGuiApplication app(argc, nullptr);
|
2017-02-22 14:38:33 +00:00
|
|
|
const QRect screenGeometry = QGuiApplication::primaryScreen()->availableVirtualGeometry();
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QTimer timer;
|
|
|
|
timer.setInterval(100);
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QSignalSpy spyAboutToQuit(&app, &QCoreApplication::aboutToQuit);
|
|
|
|
QSignalSpy spyTimeout(&timer, &QTimer::timeout);
|
2013-07-10 15:21:36 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QWindow mainWindow;
|
|
|
|
mainWindow.setTitle(QStringLiteral("quitOnLastWindowClosedMultiMainWindow"));
|
|
|
|
mainWindow.resize(windowSize, windowSize);
|
|
|
|
mainWindow.setFramePosition(QPoint(screenGeometry.left() + spacing, screenGeometry.top() + spacing));
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QWindow dialog;
|
|
|
|
dialog.setTitle(QStringLiteral("quitOnLastWindowClosedMultiDialog"));
|
|
|
|
dialog.resize(windowSize, windowSize);
|
|
|
|
dialog.setFramePosition(QPoint(screenGeometry.left() + 2 * spacing + windowSize, screenGeometry.top() + spacing));
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QVERIFY(!dialog.transientParent());
|
|
|
|
QVERIFY(app.quitOnLastWindowClosed());
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
mainWindow.show();
|
|
|
|
dialog.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&dialog));
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
timer.start();
|
|
|
|
QTimer::singleShot(1000, &mainWindow, &QWindow::close); // This should not quit the application
|
|
|
|
QTimer::singleShot(2000, &app, &QCoreApplication::quit);
|
2012-05-14 14:58:26 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
app.exec();
|
|
|
|
|
|
|
|
QCOMPARE(spyAboutToQuit.count(), 1);
|
|
|
|
// Should be around 20 if closing did not cause the quit
|
|
|
|
QVERIFY2(spyTimeout.count() > 15, QByteArray::number(spyTimeout.count()).constData());
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QGuiApplication::dontQuitOnLastWindowClosed()
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2019-06-05 10:58:54 +00:00
|
|
|
QGuiApplication app(argc, nullptr);
|
2017-02-22 14:38:33 +00:00
|
|
|
app.setQuitOnLastWindowClosed(false);
|
2013-08-20 07:12:40 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QTimer timer;
|
|
|
|
timer.setInterval(2000);
|
|
|
|
timer.setSingleShot(true);
|
|
|
|
QObject::connect(&timer, &QTimer::timeout, &app, &QCoreApplication::quit);
|
2013-08-20 07:12:40 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QSignalSpy spyLastWindowClosed(&app, &QGuiApplication::lastWindowClosed);
|
|
|
|
QSignalSpy spyTimeout(&timer, &QTimer::timeout);
|
2013-08-20 07:12:40 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QScopedPointer<QWindow> mainWindow(new QWindow);
|
2013-08-20 07:12:40 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
mainWindow->show();
|
2013-08-20 07:12:40 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QTimer::singleShot(1000, mainWindow.data(), &QWindow::close); // This should not quit the application
|
|
|
|
timer.start();
|
2013-08-20 07:12:40 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
app.exec();
|
2013-08-20 07:12:40 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
app.setQuitOnLastWindowClosed(true); // restore underlying static to default value
|
2013-08-20 07:12:40 +00:00
|
|
|
|
2017-02-22 14:38:33 +00:00
|
|
|
QCOMPARE(spyTimeout.count(), 1); // quit timer fired
|
|
|
|
QCOMPARE(spyLastWindowClosed.count(), 1); // lastWindowClosed emitted
|
2012-05-14 14:58:26 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2019-06-05 10:58:54 +00:00
|
|
|
return nullptr;
|
2012-09-26 12:15:39 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-04-30 12:13:22 +00:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
QStaticPlugin testPluginInfo(qt_plugin_instance, qt_plugin_query_metadata);
|
|
|
|
#else
|
2012-09-26 12:15:39 +00:00
|
|
|
QStaticPlugin testPluginInfo;
|
|
|
|
testPluginInfo.instance = qt_plugin_instance;
|
2013-08-22 11:16:34 +00:00
|
|
|
testPluginInfo.rawMetaData = qt_plugin_query_metadata;
|
2019-04-30 12:13:22 +00:00
|
|
|
#endif
|
2012-09-26 12:15:39 +00:00
|
|
|
qRegisterStaticPluginFunction(testPluginInfo);
|
|
|
|
int argc = 3;
|
2013-09-25 14:23:45 +00:00
|
|
|
char *argv[] = { const_cast<char*>(QTest::currentAppName()), const_cast<char*>("-plugin"), const_cast<char*>("testplugin") };
|
2012-09-26 12:15:39 +00:00
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
|
|
|
|
QVERIFY(QGuiApplication::primaryScreen());
|
2015-07-30 13:15:12 +00:00
|
|
|
QCOMPARE(QGuiApplication::primaryScreen()->orientation(), testOrientationToSend);
|
2012-09-26 12:15:39 +00:00
|
|
|
|
|
|
|
QCOMPARE(testReceiver.customEvents, 0);
|
|
|
|
QCoreApplication::sendPostedEvents(&testReceiver);
|
|
|
|
QCOMPARE(testReceiver.customEvents, 1);
|
|
|
|
}
|
|
|
|
|
2014-06-20 08:28:01 +00:00
|
|
|
Q_DECLARE_METATYPE(Qt::LayoutDirection)
|
|
|
|
void tst_QGuiApplication::layoutDirection()
|
|
|
|
{
|
|
|
|
qRegisterMetaType<Qt::LayoutDirection>();
|
|
|
|
|
|
|
|
Qt::LayoutDirection oldDirection = QGuiApplication::layoutDirection();
|
|
|
|
Qt::LayoutDirection newDirection = oldDirection == Qt::LeftToRight ? Qt::RightToLeft : Qt::LeftToRight;
|
|
|
|
|
|
|
|
QGuiApplication::setLayoutDirection(newDirection);
|
|
|
|
QCOMPARE(QGuiApplication::layoutDirection(), newDirection);
|
|
|
|
|
|
|
|
int argc = 1;
|
|
|
|
char *argv[] = { const_cast<char*>("tst_qguiapplication") };
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
QSignalSpy signalSpy(&app, SIGNAL(layoutDirectionChanged(Qt::LayoutDirection)));
|
|
|
|
|
|
|
|
QGuiApplication::setLayoutDirection(oldDirection);
|
|
|
|
QCOMPARE(QGuiApplication::layoutDirection(), oldDirection);
|
|
|
|
QCOMPARE(signalSpy.count(), 1);
|
|
|
|
QCOMPARE(signalSpy.at(0).at(0).toInt(), static_cast<int>(oldDirection));
|
|
|
|
|
|
|
|
QGuiApplication::setLayoutDirection(oldDirection);
|
|
|
|
QCOMPARE(QGuiApplication::layoutDirection(), oldDirection);
|
|
|
|
QCOMPARE(signalSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
2014-09-09 08:06:45 +00:00
|
|
|
void tst_QGuiApplication::globalShareContext()
|
|
|
|
{
|
|
|
|
#ifndef QT_NO_OPENGL
|
|
|
|
// Test that there is a global share context when requested.
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
|
|
|
int argc = 1;
|
|
|
|
char *argv[] = { const_cast<char*>("tst_qguiapplication") };
|
|
|
|
QScopedPointer<QGuiApplication> app(new QGuiApplication(argc, argv));
|
|
|
|
QOpenGLContext *ctx = qt_gl_global_share_context();
|
|
|
|
QVERIFY(ctx);
|
|
|
|
app.reset();
|
|
|
|
ctx = qt_gl_global_share_context();
|
|
|
|
QVERIFY(!ctx);
|
|
|
|
|
|
|
|
// Test that there is no global share context by default.
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, false);
|
|
|
|
app.reset(new QGuiApplication(argc, argv));
|
|
|
|
ctx = qt_gl_global_share_context();
|
|
|
|
QVERIFY(!ctx);
|
|
|
|
#else
|
|
|
|
QSKIP("No OpenGL support");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-03-28 20:03:29 +00:00
|
|
|
void tst_QGuiApplication::testSetPaletteAttribute()
|
|
|
|
{
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_SetPalette, false);
|
|
|
|
int argc = 1;
|
|
|
|
char *argv[] = { const_cast<char*>("tst_qguiapplication") };
|
|
|
|
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
|
|
|
|
QVERIFY(!QCoreApplication::testAttribute(Qt::AA_SetPalette));
|
|
|
|
QPalette palette;
|
2019-06-05 10:58:54 +00:00
|
|
|
palette.setColor(QPalette::WindowText, Qt::red);
|
2015-03-28 20:03:29 +00:00
|
|
|
QGuiApplication::setPalette(palette);
|
|
|
|
|
|
|
|
QVERIFY(QCoreApplication::testAttribute(Qt::AA_SetPalette));
|
|
|
|
}
|
|
|
|
|
2015-02-24 08:35:56 +00:00
|
|
|
// Test that static functions do not crash if there is no application instance.
|
|
|
|
void tst_QGuiApplication::staticFunctions()
|
|
|
|
{
|
|
|
|
QGuiApplication::setApplicationDisplayName(QString());
|
|
|
|
QGuiApplication::applicationDisplayName();
|
|
|
|
QGuiApplication::allWindows();
|
|
|
|
QGuiApplication::topLevelWindows();
|
|
|
|
QGuiApplication::topLevelAt(QPoint(0, 0));
|
|
|
|
QGuiApplication::setWindowIcon(QIcon());
|
|
|
|
QGuiApplication::windowIcon();
|
|
|
|
QGuiApplication::platformName();
|
|
|
|
QGuiApplication::modalWindow();
|
|
|
|
QGuiApplication::focusWindow();
|
|
|
|
QGuiApplication::focusObject();
|
|
|
|
QGuiApplication::primaryScreen();
|
|
|
|
QGuiApplication::screens();
|
|
|
|
QGuiApplication::overrideCursor();
|
|
|
|
QGuiApplication::setOverrideCursor(QCursor());
|
|
|
|
QGuiApplication::changeOverrideCursor(QCursor());
|
|
|
|
QGuiApplication::restoreOverrideCursor();
|
|
|
|
QGuiApplication::keyboardModifiers();
|
|
|
|
QGuiApplication::queryKeyboardModifiers();
|
|
|
|
QGuiApplication::mouseButtons();
|
|
|
|
QGuiApplication::setLayoutDirection(Qt::LeftToRight);
|
|
|
|
QGuiApplication::layoutDirection();
|
|
|
|
QGuiApplication::styleHints();
|
|
|
|
QGuiApplication::setDesktopSettingsAware(true);
|
|
|
|
QGuiApplication::desktopSettingsAware();
|
|
|
|
QGuiApplication::inputMethod();
|
|
|
|
QGuiApplication::platformNativeInterface();
|
|
|
|
QGuiApplication::platformFunction(QByteArrayLiteral("bla"));
|
|
|
|
QGuiApplication::setQuitOnLastWindowClosed(true);
|
|
|
|
QGuiApplication::quitOnLastWindowClosed();
|
|
|
|
QGuiApplication::applicationState();
|
2018-04-05 11:02:35 +00:00
|
|
|
|
|
|
|
QPixmap::defaultDepth();
|
2015-02-24 08:35:56 +00:00
|
|
|
}
|
|
|
|
|
2015-02-23 16:01:24 +00:00
|
|
|
void tst_QGuiApplication::settableStyleHints_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("appInstance");
|
|
|
|
QTest::newRow("app") << true;
|
|
|
|
QTest::newRow("no-app") << false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QGuiApplication::settableStyleHints()
|
|
|
|
{
|
|
|
|
QFETCH(bool, appInstance);
|
|
|
|
int argc = 0;
|
|
|
|
QScopedPointer<QGuiApplication> app;
|
|
|
|
if (appInstance)
|
2019-06-05 10:58:54 +00:00
|
|
|
app.reset(new QGuiApplication(argc, nullptr));
|
2015-02-23 16:01:24 +00:00
|
|
|
|
|
|
|
const int keyboardInputInterval = 555;
|
|
|
|
QGuiApplication::styleHints()->setKeyboardInputInterval(keyboardInputInterval);
|
|
|
|
QCOMPARE(QGuiApplication::styleHints()->keyboardInputInterval(), keyboardInputInterval);
|
|
|
|
}
|
|
|
|
|
2012-09-26 12:15:39 +00:00
|
|
|
QTEST_APPLESS_MAIN(tst_QGuiApplication)
|