summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/kernel.pri185
-rw-r--r--src/gui/kernel/qaction.cpp288
-rw-r--r--src/gui/kernel/qaction.h69
-rw-r--r--src/gui/kernel/qaction_p.h49
-rw-r--r--src/gui/kernel/qactiongroup.cpp58
-rw-r--r--src/gui/kernel/qactiongroup.h48
-rw-r--r--src/gui/kernel/qactiongroup_p.h42
-rw-r--r--src/gui/kernel/qclipboard.cpp73
-rw-r--r--src/gui/kernel/qclipboard.h40
-rw-r--r--src/gui/kernel/qcursor.cpp94
-rw-r--r--src/gui/kernel/qcursor.h59
-rw-r--r--src/gui/kernel/qcursor_p.h40
-rw-r--r--src/gui/kernel/qdnd.cpp42
-rw-r--r--src/gui/kernel/qdnd_p.h42
-rw-r--r--src/gui/kernel/qdrag.cpp49
-rw-r--r--src/gui/kernel/qdrag.h40
-rw-r--r--src/gui/kernel/qevent.cpp2433
-rw-r--r--src/gui/kernel/qevent.h879
-rw-r--r--src/gui/kernel/qevent_p.h131
-rw-r--r--src/gui/kernel/qeventpoint.cpp619
-rw-r--r--src/gui/kernel/qeventpoint.h142
-rw-r--r--src/gui/kernel/qeventpoint_p.h141
-rw-r--r--src/gui/kernel/qgenericplugin.cpp42
-rw-r--r--src/gui/kernel/qgenericplugin.h40
-rw-r--r--src/gui/kernel/qgenericpluginfactory.cpp51
-rw-r--r--src/gui/kernel/qgenericpluginfactory.h40
-rw-r--r--src/gui/kernel/qguiapplication.cpp1718
-rw-r--r--src/gui/kernel/qguiapplication.h58
-rw-r--r--src/gui/kernel/qguiapplication_p.h233
-rw-r--r--src/gui/kernel/qguiapplication_platform.h68
-rw-r--r--src/gui/kernel/qguivariant.cpp341
-rw-r--r--src/gui/kernel/qhighdpiscaling.cpp728
-rw-r--r--src/gui/kernel/qhighdpiscaling_p.h192
-rw-r--r--src/gui/kernel/qinputdevice.cpp231
-rw-r--r--src/gui/kernel/qinputdevice.h65
-rw-r--r--src/gui/kernel/qinputdevice_p.h72
-rw-r--r--src/gui/kernel/qinputdevicemanager.cpp46
-rw-r--r--src/gui/kernel/qinputdevicemanager_p.h48
-rw-r--r--src/gui/kernel/qinputdevicemanager_p_p.h40
-rw-r--r--src/gui/kernel/qinputmethod.cpp62
-rw-r--r--src/gui/kernel/qinputmethod.h43
-rw-r--r--src/gui/kernel/qinputmethod_p.h40
-rw-r--r--src/gui/kernel/qinternalmimedata.cpp84
-rw-r--r--src/gui/kernel/qinternalmimedata_p.h44
-rw-r--r--src/gui/kernel/qkeymapper.cpp123
-rw-r--r--src/gui/kernel/qkeymapper_p.h74
-rw-r--r--src/gui/kernel/qkeysequence.cpp387
-rw-r--r--src/gui/kernel/qkeysequence.h62
-rw-r--r--src/gui/kernel/qkeysequence_p.h55
-rw-r--r--src/gui/kernel/qoffscreensurface.cpp149
-rw-r--r--src/gui/kernel/qoffscreensurface.h52
-rw-r--r--src/gui/kernel/qoffscreensurface_p.h59
-rw-r--r--src/gui/kernel/qoffscreensurface_platform.h41
-rw-r--r--src/gui/kernel/qopenglcontext.cpp161
-rw-r--r--src/gui/kernel/qopenglcontext.h49
-rw-r--r--src/gui/kernel/qopenglcontext_p.h54
-rw-r--r--src/gui/kernel/qopenglcontext_platform.h84
-rw-r--r--src/gui/kernel/qpaintdevicewindow.cpp70
-rw-r--r--src/gui/kernel/qpaintdevicewindow.h44
-rw-r--r--src/gui/kernel/qpaintdevicewindow_p.h47
-rw-r--r--src/gui/kernel/qpalette.cpp377
-rw-r--r--src/gui/kernel/qpalette.h82
-rw-r--r--src/gui/kernel/qpalette_p.h77
-rw-r--r--src/gui/kernel/qpixelformat.cpp42
-rw-r--r--src/gui/kernel/qpixelformat.h207
-rw-r--r--src/gui/kernel/qplatformclipboard.cpp40
-rw-r--r--src/gui/kernel/qplatformclipboard.h40
-rw-r--r--src/gui/kernel/qplatformcursor.cpp46
-rw-r--r--src/gui/kernel/qplatformcursor.h40
-rw-r--r--src/gui/kernel/qplatformdialoghelper.cpp179
-rw-r--r--src/gui/kernel/qplatformdialoghelper.h99
-rw-r--r--src/gui/kernel/qplatformdrag.cpp40
-rw-r--r--src/gui/kernel/qplatformdrag.h40
-rw-r--r--src/gui/kernel/qplatformgraphicsbuffer.cpp46
-rw-r--r--src/gui/kernel/qplatformgraphicsbuffer.h40
-rw-r--r--src/gui/kernel/qplatformgraphicsbufferhelper.cpp52
-rw-r--r--src/gui/kernel/qplatformgraphicsbufferhelper.h40
-rw-r--r--src/gui/kernel/qplatforminputcontext.cpp157
-rw-r--r--src/gui/kernel/qplatforminputcontext.h48
-rw-r--r--src/gui/kernel/qplatforminputcontext_p.h40
-rw-r--r--src/gui/kernel/qplatforminputcontextfactory.cpp81
-rw-r--r--src/gui/kernel/qplatforminputcontextfactory_p.h43
-rw-r--r--src/gui/kernel/qplatforminputcontextplugin.cpp42
-rw-r--r--src/gui/kernel/qplatforminputcontextplugin_p.h40
-rw-r--r--src/gui/kernel/qplatformintegration.cpp140
-rw-r--r--src/gui/kernel/qplatformintegration.h70
-rw-r--r--src/gui/kernel/qplatformintegrationfactory.cpp83
-rw-r--r--src/gui/kernel/qplatformintegrationfactory_p.h40
-rw-r--r--src/gui/kernel/qplatformintegrationplugin.cpp48
-rw-r--r--src/gui/kernel/qplatformintegrationplugin.h40
-rw-r--r--src/gui/kernel/qplatformkeymapper.cpp38
-rw-r--r--src/gui/kernel/qplatformkeymapper.h36
-rw-r--r--src/gui/kernel/qplatformmenu.cpp44
-rw-r--r--src/gui/kernel/qplatformmenu.h49
-rw-r--r--src/gui/kernel/qplatformmenu_p.h55
-rw-r--r--src/gui/kernel/qplatformnativeinterface.cpp46
-rw-r--r--src/gui/kernel/qplatformnativeinterface.h40
-rw-r--r--src/gui/kernel/qplatformoffscreensurface.cpp40
-rw-r--r--src/gui/kernel/qplatformoffscreensurface.h59
-rw-r--r--src/gui/kernel/qplatformopenglcontext.cpp56
-rw-r--r--src/gui/kernel/qplatformopenglcontext.h65
-rw-r--r--src/gui/kernel/qplatformscreen.cpp117
-rw-r--r--src/gui/kernel/qplatformscreen.h49
-rw-r--r--src/gui/kernel/qplatformscreen_p.h82
-rw-r--r--src/gui/kernel/qplatformservices.cpp66
-rw-r--r--src/gui/kernel/qplatformservices.h60
-rw-r--r--src/gui/kernel/qplatformsessionmanager.cpp52
-rw-r--r--src/gui/kernel/qplatformsessionmanager.h44
-rw-r--r--src/gui/kernel/qplatformsharedgraphicscache.cpp62
-rw-r--r--src/gui/kernel/qplatformsharedgraphicscache.h40
-rw-r--r--src/gui/kernel/qplatformsurface.cpp51
-rw-r--r--src/gui/kernel/qplatformsurface.h42
-rw-r--r--src/gui/kernel/qplatformsystemtrayicon.cpp42
-rw-r--r--src/gui/kernel/qplatformsystemtrayicon.h45
-rw-r--r--src/gui/kernel/qplatformtheme.cpp246
-rw-r--r--src/gui/kernel/qplatformtheme.h85
-rw-r--r--src/gui/kernel/qplatformtheme_p.h42
-rw-r--r--src/gui/kernel/qplatformthemefactory.cpp91
-rw-r--r--src/gui/kernel/qplatformthemefactory_p.h40
-rw-r--r--src/gui/kernel/qplatformthemeplugin.cpp42
-rw-r--r--src/gui/kernel/qplatformthemeplugin.h40
-rw-r--r--src/gui/kernel/qplatformwindow.cpp140
-rw-r--r--src/gui/kernel/qplatformwindow.h45
-rw-r--r--src/gui/kernel/qplatformwindow_p.h149
-rw-r--r--src/gui/kernel/qpointingdevice.cpp613
-rw-r--r--src/gui/kernel/qpointingdevice.h97
-rw-r--r--src/gui/kernel/qpointingdevice_p.h95
-rw-r--r--src/gui/kernel/qrasterwindow.cpp58
-rw-r--r--src/gui/kernel/qrasterwindow.h41
-rw-r--r--src/gui/kernel/qscreen.cpp277
-rw-r--r--src/gui/kernel/qscreen.h57
-rw-r--r--src/gui/kernel/qscreen_p.h74
-rw-r--r--src/gui/kernel/qscreen_platform.h61
-rw-r--r--src/gui/kernel/qsessionmanager.cpp53
-rw-r--r--src/gui/kernel/qsessionmanager.h40
-rw-r--r--src/gui/kernel/qsessionmanager_p.h44
-rw-r--r--src/gui/kernel/qshapedpixmapdndwindow.cpp50
-rw-r--r--src/gui/kernel/qshapedpixmapdndwindow_p.h40
-rw-r--r--src/gui/kernel/qshortcut.cpp279
-rw-r--r--src/gui/kernel/qshortcut.h114
-rw-r--r--src/gui/kernel/qshortcut_p.h48
-rw-r--r--src/gui/kernel/qshortcutmap.cpp319
-rw-r--r--src/gui/kernel/qshortcutmap_p.h42
-rw-r--r--src/gui/kernel/qsimpledrag.cpp56
-rw-r--r--src/gui/kernel/qsimpledrag_p.h40
-rw-r--r--src/gui/kernel/qstylehints.cpp124
-rw-r--r--src/gui/kernel/qstylehints.h75
-rw-r--r--src/gui/kernel/qstylehints_p.h54
-rw-r--r--src/gui/kernel/qsurface.cpp55
-rw-r--r--src/gui/kernel/qsurface.h45
-rw-r--r--src/gui/kernel/qsurfaceformat.cpp171
-rw-r--r--src/gui/kernel/qsurfaceformat.h70
-rw-r--r--src/gui/kernel/qt_gui_pch.h41
-rw-r--r--src/gui/kernel/qtestsupport_gui.cpp171
-rw-r--r--src/gui/kernel/qtestsupport_gui.h90
-rw-r--r--src/gui/kernel/qtguiglobal.h55
-rw-r--r--src/gui/kernel/qtguiglobal_p.h40
-rw-r--r--src/gui/kernel/qwindow.cpp679
-rw-r--r--src/gui/kernel/qwindow.h78
-rw-r--r--src/gui/kernel/qwindow_p.h80
-rw-r--r--src/gui/kernel/qwindowdefs.h45
-rw-r--r--src/gui/kernel/qwindowdefs_win.h40
-rw-r--r--src/gui/kernel/qwindowsysteminterface.cpp794
-rw-r--r--src/gui/kernel/qwindowsysteminterface.h114
-rw-r--r--src/gui/kernel/qwindowsysteminterface_p.h176
165 files changed, 9759 insertions, 11655 deletions
diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri
deleted file mode 100644
index e653adab9c..0000000000
--- a/src/gui/kernel/kernel.pri
+++ /dev/null
@@ -1,185 +0,0 @@
-# Qt kernel module
-
-# Only used on platforms with CONFIG += precompile_header
-PRECOMPILED_HEADER = kernel/qt_gui_pch.h
-
-
-KERNEL_P= kernel
-HEADERS += \
- kernel/qtguiglobal.h \
- kernel/qtguiglobal_p.h \
- kernel/qgenericpluginfactory.h \
- kernel/qgenericplugin.h \
- kernel/qwindowsysteminterface.h \
- kernel/qwindowsysteminterface_p.h \
- kernel/qplatformintegration.h \
- kernel/qplatformscreen.h \
- kernel/qplatformscreen_p.h \
- kernel/qplatforminputcontext.h \
- kernel/qplatforminputcontext_p.h \
- kernel/qplatforminputcontextfactory_p.h \
- kernel/qplatforminputcontextplugin_p.h \
- kernel/qplatformintegrationfactory_p.h \
- kernel/qplatformintegrationplugin.h \
- kernel/qplatformtheme.h \
- kernel/qplatformtheme_p.h \
- kernel/qplatformthemefactory_p.h \
- kernel/qplatformthemeplugin.h \
- kernel/qplatformwindow.h \
- kernel/qplatformoffscreensurface.h \
- kernel/qplatformwindow_p.h \
- kernel/qplatformcursor.h \
- kernel/qplatformclipboard.h \
- kernel/qplatformnativeinterface.h \
- kernel/qplatformmenu.h \
- kernel/qsurfaceformat.h \
- kernel/qguiapplication.h \
- kernel/qguiapplication_p.h \
- kernel/qwindow_p.h \
- kernel/qwindow.h \
- kernel/qoffscreensurface.h \
- kernel/qplatformsurface.h \
- kernel/qsurface.h \
- kernel/qclipboard.h \
- kernel/qcursor.h \
- kernel/qcursor_p.h \
- kernel/qevent.h \
- kernel/qevent_p.h \
- kernel/qinputdevice.h \
- kernel/qinputdevice_p.h \
- kernel/qinputmethod.h \
- kernel/qinputmethod_p.h \
- kernel/qinternalmimedata_p.h \
- kernel/qkeymapper_p.h \
- kernel/qpalette.h \
- kernel/qsessionmanager.h \
- kernel/qsessionmanager_p.h \
- kernel/qwindowdefs.h \
- kernel/qscreen.h \
- kernel/qscreen_p.h \
- kernel/qstylehints.h \
- kernel/qpointingdevice.h \
- kernel/qpointingdevice_p.h \
- kernel/qplatformsharedgraphicscache.h \
- kernel/qplatformdialoghelper.h \
- kernel/qplatformservices.h \
- kernel/qplatformsystemtrayicon.h \
- kernel/qplatformsessionmanager.h \
- kernel/qpixelformat.h \
- kernel/qpaintdevicewindow.h \
- kernel/qpaintdevicewindow_p.h \
- kernel/qrasterwindow.h \
- kernel/qplatformgraphicsbuffer.h \
- kernel/qplatformgraphicsbufferhelper.h \
- kernel/qinputdevicemanager_p.h \
- kernel/qinputdevicemanager_p_p.h \
- kernel/qhighdpiscaling_p.h \
- kernel/qtestsupport_gui.h
-
-SOURCES += \
- kernel/qgenericpluginfactory.cpp \
- kernel/qgenericplugin.cpp \
- kernel/qwindowsysteminterface.cpp \
- kernel/qplatforminputcontextfactory.cpp \
- kernel/qplatforminputcontextplugin.cpp \
- kernel/qplatforminputcontext.cpp \
- kernel/qplatformintegration.cpp \
- kernel/qplatformscreen.cpp \
- kernel/qplatformintegrationfactory.cpp \
- kernel/qplatformintegrationplugin.cpp \
- kernel/qplatformtheme.cpp \
- kernel/qplatformthemefactory.cpp \
- kernel/qplatformthemeplugin.cpp \
- kernel/qplatformwindow.cpp \
- kernel/qplatformoffscreensurface.cpp \
- kernel/qplatformcursor.cpp \
- kernel/qplatformclipboard.cpp \
- kernel/qplatformnativeinterface.cpp \
- kernel/qsessionmanager.cpp \
- kernel/qsurfaceformat.cpp \
- kernel/qguiapplication.cpp \
- kernel/qwindow.cpp \
- kernel/qoffscreensurface.cpp \
- kernel/qplatformsurface.cpp \
- kernel/qsurface.cpp \
- kernel/qclipboard.cpp \
- kernel/qcursor.cpp \
- kernel/qevent.cpp \
- kernel/qinputdevice.cpp \
- kernel/qinputmethod.cpp \
- kernel/qinternalmimedata.cpp \
- kernel/qkeymapper.cpp \
- kernel/qpalette.cpp \
- kernel/qguivariant.cpp \
- kernel/qscreen.cpp \
- kernel/qstylehints.cpp \
- kernel/qpointingdevice.cpp \
- kernel/qplatformsharedgraphicscache.cpp \
- kernel/qplatformdialoghelper.cpp \
- kernel/qplatformservices.cpp \
- kernel/qplatformsystemtrayicon.cpp \
- kernel/qplatformsessionmanager.cpp \
- kernel/qplatformmenu.cpp \
- kernel/qpixelformat.cpp \
- kernel/qpaintdevicewindow.cpp \
- kernel/qrasterwindow.cpp \
- kernel/qplatformgraphicsbuffer.cpp \
- kernel/qplatformgraphicsbufferhelper.cpp \
- kernel/qinputdevicemanager.cpp \
- kernel/qhighdpiscaling.cpp \
- kernel/qtestsupport_gui.cpp
-
-qtConfig(action) {
- HEADERS += \
- kernel/qaction.h \
- kernel/qaction_p.h \
- kernel/qactiongroup.h \
- kernel/qactiongroup_p.h
-
- SOURCES += \
- kernel/qactiongroup.cpp \
- kernel/qaction.cpp
-}
-
-qtConfig(draganddrop) {
- HEADERS += \
- kernel/qdnd_p.h \
- kernel/qdrag.h \
- kernel/qplatformdrag.h \
- kernel/qshapedpixmapdndwindow_p.h \
- kernel/qsimpledrag_p.h
-
- SOURCES += \
- kernel/qdnd.cpp \
- kernel/qdrag.cpp \
- kernel/qplatformdrag.cpp \
- kernel/qshapedpixmapdndwindow.cpp \
- kernel/qsimpledrag.cpp
-}
-
-qtConfig(opengl) {
- HEADERS += \
- kernel/qplatformopenglcontext.h \
- kernel/qopenglcontext.h \
- kernel/qopenglcontext_p.h \
- kernel/qopenglcontext_platform.h \
-
- SOURCES += \
- kernel/qplatformopenglcontext.cpp \
- kernel/qopenglcontext.cpp
-}
-
-qtConfig(shortcut) {
- HEADERS += \
- kernel/qshortcut.h \
- kernel/qshortcut_p.h \
- kernel/qshortcutmap_p.h \
- kernel/qkeysequence.h \
- kernel/qkeysequence_p.h
- SOURCES += \
- kernel/qshortcut.cpp \
- kernel/qshortcutmap.cpp \
- kernel/qkeysequence.cpp
-}
-
-win32:HEADERS+=kernel/qwindowdefs_win.h
diff --git a/src/gui/kernel/qaction.cpp b/src/gui/kernel/qaction.cpp
index 99a614ddd9..c67cfd53b1 100644
--- a/src/gui/kernel/qaction.cpp
+++ b/src/gui/kernel/qaction.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qaction.h"
#include "qactiongroup.h"
@@ -59,14 +23,16 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
/*
internal: guesses a descriptive text from a text suited for a menu entry
*/
static QString qt_strippedText(QString s)
{
- s.remove(QLatin1String("..."));
+ s.remove("..."_L1);
for (int i = 0; i < s.size(); ++i) {
- if (s.at(i) == QLatin1Char('&'))
+ if (s.at(i) == u'&')
s.remove(i, 1);
}
return s.trimmed();
@@ -115,44 +81,28 @@ void QActionPrivate::sendDataChanged()
void QActionPrivate::redoGrab(QShortcutMap &map)
{
Q_Q(QAction);
- if (shortcutId)
- map.removeShortcut(shortcutId, q);
- if (shortcut.isEmpty())
- return;
- shortcutId = map.addShortcut(q, shortcut, shortcutContext, contextMatcher());
- if (!enabled)
- map.setShortcutEnabled(false, shortcutId, q);
- if (!autorepeat)
- map.setShortcutAutoRepeat(false, shortcutId, q);
-}
-
-void QActionPrivate::redoGrabAlternate(QShortcutMap &map)
-{
- Q_Q(QAction);
- for(int i = 0; i < alternateShortcutIds.count(); ++i) {
- if (const int id = alternateShortcutIds.at(i))
+ for (int id : std::as_const(shortcutIds)) {
+ if (id)
map.removeShortcut(id, q);
}
- alternateShortcutIds.clear();
- if (alternateShortcuts.isEmpty())
- return;
- for(int i = 0; i < alternateShortcuts.count(); ++i) {
- const QKeySequence& alternate = alternateShortcuts.at(i);
- if (!alternate.isEmpty())
- alternateShortcutIds.append(map.addShortcut(q, alternate, shortcutContext, contextMatcher()));
+
+ shortcutIds.clear();
+ for (const QKeySequence &shortcut : std::as_const(shortcuts)) {
+ if (!shortcut.isEmpty())
+ shortcutIds.append(map.addShortcut(q, shortcut, shortcutContext, contextMatcher()));
else
- alternateShortcutIds.append(0);
+ shortcutIds.append(0);
}
if (!enabled) {
- for(int i = 0; i < alternateShortcutIds.count(); ++i) {
- const int id = alternateShortcutIds.at(i);
- map.setShortcutEnabled(false, id, q);
+ for (int id : std::as_const(shortcutIds)) {
+ if (id)
+ map.setShortcutEnabled(false, id, q);
}
}
if (!autorepeat) {
- for(int i = 0; i < alternateShortcutIds.count(); ++i) {
- const int id = alternateShortcutIds.at(i);
- map.setShortcutAutoRepeat(false, id, q);
+ for (int id : std::as_const(shortcutIds)) {
+ if (id)
+ map.setShortcutAutoRepeat(false, id, q);
}
}
}
@@ -160,10 +110,8 @@ void QActionPrivate::redoGrabAlternate(QShortcutMap &map)
void QActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map)
{
Q_Q(QAction);
- if (shortcutId)
- map.setShortcutEnabled(enable, shortcutId, q);
- for(int i = 0; i < alternateShortcutIds.count(); ++i) {
- if (const int id = alternateShortcutIds.at(i))
+ for (int id : std::as_const(shortcutIds)) {
+ if (id)
map.setShortcutEnabled(enable, id, q);
}
}
@@ -202,17 +150,18 @@ QObject *QActionPrivate::menu() const
user interface used, it is useful to represent each command as
an \e action.
- Actions can be added to menus and toolbars, and will
- automatically keep them in sync. For example, in a word processor,
- if the user presses a Bold toolbar button, the Bold menu item
+ Actions can be added to user interface elements such as menus and toolbars,
+ and will automatically keep the UI in sync. For example, in a word
+ processor, if the user presses a Bold toolbar button, the Bold menu item
will automatically be checked.
- A QAction may contain an icon, menu text, a shortcut, status text,
- "What's This?" text, and a tooltip. Most of these can be set in
- the constructor. They can also be set independently with
- setIcon(), setText(), setIconText(), setShortcut(),
- setStatusTip(), setWhatsThis(), and setToolTip(). For menu items,
- it is possible to set an individual font with setFont().
+ A QAction may contain an icon, descriptive text, icon text, a keyboard
+ shortcut, status text, "What's This?" text, and a tooltip. All properties
+ can be set independently with setIcon(), setText(), setIconText(),
+ setShortcut(), setStatusTip(), setWhatsThis(), and setToolTip(). Icon and
+ text, as the two most important properties, can also be set in the
+ constructor. It's possible to set an individual font with setFont(), which
+ e.g. menus respect when displaying the action as a menu item.
We recommend that actions are created as children of the window
they are used in. In most cases actions will be children of
@@ -222,9 +171,7 @@ QObject *QActionPrivate::menu() const
Once a QAction has been created, it should be added to the relevant
menu and toolbar, then connected to the slot which will perform
- the action. For example:
-
- \snippet mainwindows/application/mainwindow.cpp 19
+ the action.
Actions are added to widgets using QWidget::addAction() or
QGraphicsWidget::addAction(). Note that an action must be added to a
@@ -237,7 +184,7 @@ QObject *QActionPrivate::menu() const
use as menu items.
- \sa QMenu, QToolBar, {Application Example}
+ \sa QMenu, QToolBar
*/
/*!
@@ -290,13 +237,11 @@ QAction::QAction(QObject *parent)
parent is an action group the action will be automatically
inserted into the group.
- The action uses a stripped version of \a text (e.g. "\&Menu
- Option..." becomes "Menu Option") as descriptive text for
- tool buttons. You can override this by setting a specific
- description with setText(). The same text will be used for
- tooltips unless you specify a different text using
- setToolTip().
+ A stripped version of \a text (for example, "\&Menu Option..." becomes
+ "Menu Option") will be used for tooltips and icon text unless you specify a
+ different text using setToolTip() or setIconText(), respectively.
+ \sa text
*/
QAction::QAction(const QString &text, QObject *parent)
: QAction(parent)
@@ -310,12 +255,11 @@ QAction::QAction(const QString &text, QObject *parent)
parent. If \a parent is an action group the action will be
automatically inserted into the group.
- The action uses a stripped version of \a text (e.g. "\&Menu
- Option..." becomes "Menu Option") as descriptive text for
- tool buttons. You can override this by setting a specific
- description with setText(). The same text will be used for
- tooltips unless you specify a different text using
- setToolTip().
+ A stripped version of \a text (for example, "\&Menu Option..." becomes
+ "Menu Option") will be used for tooltips and icon text unless you specify a
+ different text using setToolTip() or setIconText(), respectively.
+
+ \sa text, icon
*/
QAction::QAction(const QIcon &icon, const QString &text, QObject *parent)
: QAction(text, parent)
@@ -344,44 +288,36 @@ QAction::QAction(QActionPrivate &dd, QObject *parent)
Valid keycodes for this property can be found in \l Qt::Key and
\l Qt::Modifier. There is no default shortcut key.
*/
-void QAction::setShortcut(const QKeySequence &shortcut)
-{
- QAPP_CHECK("setShortcut");
- Q_D(QAction);
- if (d->shortcut == shortcut)
- return;
+/*!
+ Sets \a shortcut as the sole shortcut that triggers the action.
- d->shortcut = shortcut;
- d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap);
- d->sendDataChanged();
+ \sa shortcut, setShortcuts()
+*/
+void QAction::setShortcut(const QKeySequence &shortcut)
+{
+ if (shortcut.isEmpty())
+ setShortcuts({});
+ else
+ setShortcuts({ shortcut });
}
/*!
Sets \a shortcuts as the list of shortcuts that trigger the
action. The first element of the list is the primary shortcut.
- \sa shortcut
+ \sa shortcut, setShortcut()
*/
void QAction::setShortcuts(const QList<QKeySequence> &shortcuts)
{
+ QAPP_CHECK("setShortcuts");
Q_D(QAction);
- QList <QKeySequence> listCopy = shortcuts;
-
- QKeySequence primary;
- if (!listCopy.isEmpty())
- primary = listCopy.takeFirst();
-
- if (d->shortcut == primary && d->alternateShortcuts == listCopy)
+ if (d->shortcuts == shortcuts)
return;
- QAPP_CHECK("setShortcuts");
-
- d->shortcut = primary;
- d->alternateShortcuts = listCopy;
+ d->shortcuts = shortcuts;
d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap);
- d->redoGrabAlternate(QGuiApplicationPrivate::instance()->shortcutMap);
d->sendDataChanged();
}
@@ -407,7 +343,9 @@ void QAction::setShortcuts(QKeySequence::StandardKey key)
QKeySequence QAction::shortcut() const
{
Q_D(const QAction);
- return d->shortcut;
+ if (d->shortcuts.isEmpty())
+ return QKeySequence();
+ return d->shortcuts.first();
}
/*!
@@ -419,12 +357,7 @@ QKeySequence QAction::shortcut() const
QList<QKeySequence> QAction::shortcuts() const
{
Q_D(const QAction);
- QList <QKeySequence> shortcuts;
- if (!d->shortcut.isEmpty())
- shortcuts << d->shortcut;
- if (!d->alternateShortcuts.isEmpty())
- shortcuts << d->alternateShortcuts;
- return shortcuts;
+ return d->shortcuts;
}
/*!
@@ -442,7 +375,6 @@ void QAction::setShortcutContext(Qt::ShortcutContext context)
QAPP_CHECK("setShortcutContext");
d->shortcutContext = context;
d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap);
- d->redoGrabAlternate(QGuiApplicationPrivate::instance()->shortcutMap);
d->sendDataChanged();
}
@@ -469,7 +401,6 @@ void QAction::setAutoRepeat(bool on)
QAPP_CHECK("setAutoRepeat");
d->autorepeat = on;
d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap);
- d->redoGrabAlternate(QGuiApplicationPrivate::instance()->shortcutMap);
d->sendDataChanged();
}
@@ -522,10 +453,11 @@ QAction::~QAction()
if (d->group)
d->group->removeAction(this);
#if QT_CONFIG(shortcut)
- if (d->shortcutId && qApp) {
- QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(d->shortcutId, this);
- for (int id : qAsConst(d->alternateShortcutIds))
- QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(id, this);
+ if (qApp) {
+ for (int id : std::as_const(d->shortcutIds)) {
+ if (id)
+ QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(id, this);
+ }
}
#endif
}
@@ -541,13 +473,13 @@ QAction::~QAction()
void QAction::setActionGroup(QActionGroup *group)
{
Q_D(QAction);
- if(group == d->group)
+ if (group == d->group)
return;
- if(d->group)
+ if (d->group)
d->group->removeAction(this);
d->group = group;
- if(group)
+ if (group)
group->addAction(this);
d->sendDataChanged();
}
@@ -570,7 +502,7 @@ QActionGroup *QAction::actionGroup() const
\sa QWidget::addAction(), QGraphicsWidget::addAction()
*/
-QVector<QObject*> QAction::associatedObjects() const
+QList<QObject*> QAction::associatedObjects() const
{
Q_D(const QAction);
return d->associatedObjects;
@@ -578,14 +510,14 @@ QVector<QObject*> QAction::associatedObjects() const
/*!
\fn QWidget *QAction::parentWidget() const
- \obsolete Use parent() with qobject_cast() instead.
+ \deprecated [6.0] Use parent() with qobject_cast() instead.
Returns the parent widget.
*/
/*!
\fn QList<QWidget*> QAction::associatedWidgets() const
- \obsolete Use associatedObjects() with qobject_cast() instead.
+ \deprecated [6.0] Use associatedObjects() with qobject_cast() instead.
Returns a list of widgets this action has been added to.
@@ -594,7 +526,7 @@ QVector<QObject*> QAction::associatedObjects() const
/*!
\fn QList<QWidget*> QAction::associatedGraphicsWidgets() const
- \obsolete Use associatedObjects() with qobject_cast() instead.
+ \deprecated [6.0] Use associatedObjects() with qobject_cast() instead.
Returns a list of graphics widgets this action has been added to.
@@ -666,6 +598,14 @@ bool QAction::isSeparator() const
by using setText(), the action's description icon text will be
used as text. There is no default text.
+ Certain UI elements, such as menus or buttons, can use '&' in front of a
+ character to automatically create a mnemonic (a shortcut) for that
+ character. For example, "&File" for a menu will create the shortcut
+ \uicontrol Alt+F, which will open the File menu. "E&xit" will create the
+ shortcut \uicontrol Alt+X for a button, or in a menu allow navigating to
+ the menu item by pressing "x". (use '&&' to display an actual ampersand).
+ The widget might consume and perform an action on a given shortcut.
+
\sa iconText
*/
void QAction::setText(const QString &text)
@@ -682,9 +622,9 @@ QString QAction::text() const
{
Q_D(const QAction);
QString s = d->text;
- if(s.isEmpty()) {
+ if (s.isEmpty()) {
s = d->iconText;
- s.replace(QLatin1Char('&'), QLatin1String("&&"));
+ s.replace(u'&', "&&"_L1);
}
return s;
}
@@ -1050,18 +990,30 @@ bool QAction::isEnabled() const
void QAction::setVisible(bool b)
{
Q_D(QAction);
- if (b == d->visible && b != d->forceInvisible)
+ if (b != d->forceInvisible)
return;
- QAPP_CHECK("setVisible");
d->forceInvisible = !b;
- d->visible = b;
- bool enabled = d->visible;
- if (enabled && d->explicitEnabled)
- enabled = d->explicitEnabledValue;
- if (!d->setEnabled(enabled, false))
- d->sendDataChanged();
+ if (b && d->group && !d->group->isVisible())
+ return;
+ d->setVisible(b);
}
+void QActionPrivate::setVisible(bool b)
+{
+ Q_Q(QAction);
+ if (b == visible)
+ return;
+ QAPP_CHECK("setVisible");
+ visible = b;
+ bool enable = visible;
+ if (enable && explicitEnabled)
+ enable = explicitEnabledValue;
+ QPointer guard(q);
+ if (!setEnabled(enable, false))
+ sendDataChanged();
+ if (guard)
+ emit q->visibleChanged();
+}
bool QAction::isVisible() const
{
@@ -1076,14 +1028,14 @@ bool QAction::event(QEvent *e)
{
Q_D(QAction);
if (e->type() == QEvent::ActionChanged) {
- for (auto object : qAsConst(d->associatedObjects))
+ for (auto object : std::as_const(d->associatedObjects))
QCoreApplication::sendEvent(object, e);
}
#if QT_CONFIG(shortcut)
if (e->type() == QEvent::Shortcut) {
QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
- Q_ASSERT_X(se->key() == d_func()->shortcut || d_func()->alternateShortcuts.contains(se->key()),
+ Q_ASSERT_X(d_func()->shortcutIds.contains(se->shortcutId()),
"QAction::event",
"Received shortcut event from incorrect shortcut");
if (se->isAmbiguous())
@@ -1108,7 +1060,7 @@ QVariant QAction::data() const
}
/*!
- Sets the action's internal data to the given \a userData.
+ Sets the action's internal data to the given \a data.
\sa data()
*/
@@ -1130,9 +1082,12 @@ void QAction::setData(const QVariant &data)
void QAction::activate(ActionEvent event)
{
Q_D(QAction);
- if(event == Trigger) {
+ if (event == Trigger) {
+ // Ignore even explicit triggers when explicitly disabled
+ if ((d->explicitEnabled && !d->explicitEnabledValue) || (d->group && !d->group->isEnabled()))
+ return;
QPointer<QObject> guard = this;
- if(d->checkable) {
+ if (d->checkable) {
// the checked action of an exclusive group may not be unchecked
if (d->checked && (d->group
&& d->group->exclusionPolicy() == QActionGroup::ExclusionPolicy::Exclusive
@@ -1145,7 +1100,7 @@ void QAction::activate(ActionEvent event)
}
if (!guard.isNull())
emit triggered(d->checked);
- } else if(event == Hover) {
+ } else if (event == Hover) {
emit hovered();
}
}
@@ -1240,14 +1195,13 @@ QAction::MenuRole QAction::menuRole() const
/*!
\fn QMenu *QAction::menu() const
- \obsolete
Returns the menu contained by this action.
In widget applications, actions that contain menus can be used to create menu
items with submenus, or inserted into toolbars to create buttons with popup menus.
- \sa QMenu::addAction()
+ \sa QMenu::addAction(), QMenu::menuInAction()
*/
QObject* QAction::menuObject() const
{
@@ -1257,7 +1211,6 @@ QObject* QAction::menuObject() const
/*!
\fn void QAction::setMenu(QMenu *menu)
- \obsolete
Sets the menu contained by this action to the specified \a menu.
*/
@@ -1277,7 +1230,7 @@ void QAction::setMenuObject(QObject *object)
The default is to follow whether the Qt::AA_DontShowIconsInMenus attribute
is set for the application. Explicitly settings this property overrides
- the presence (or abscence) of the attribute.
+ the presence (or absence) of the attribute.
For example:
\snippet code/src_gui_kernel_qaction.cpp 0
@@ -1316,8 +1269,7 @@ bool QAction::isIconVisibleInMenu() const
shown via a context menu, when it is false, it is not shown.
The default is to follow whether the Qt::AA_DontShowShortcutsInContextMenus attribute
- is set for the application, falling back to the widget style hint.
- Explicitly setting this property overrides the presence (or abscence) of the attribute.
+ is set for the application. Explicitly setting this property overrides the attribute.
\sa shortcut, QCoreApplication::setAttribute()
*/
@@ -1338,10 +1290,8 @@ void QAction::setShortcutVisibleInContextMenu(bool visible)
bool QAction::isShortcutVisibleInContextMenu() const
{
Q_D(const QAction);
- if (d->shortcutVisibleInContextMenu == -1) {
- return !QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus)
- && QGuiApplication::styleHints()->showShortcutsInContextMenus();
- }
+ if (d->shortcutVisibleInContextMenu == -1)
+ return !QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus);
return d->shortcutVisibleInContextMenu;
}
@@ -1358,8 +1308,8 @@ Q_GUI_EXPORT QDebug operator<<(QDebug d, const QAction *action)
if (action->isCheckable())
d << " checked=" << action->isChecked();
#if QT_CONFIG(shortcut)
- if (!action->shortcut().isEmpty())
- d << " shortcut=" << action->shortcut();
+ if (!action->shortcuts().isEmpty())
+ d << " shortcuts=" << action->shortcuts();
#endif
d << " menuRole=";
QtDebugUtils::formatQEnum(d, action->menuRole());
diff --git a/src/gui/kernel/qaction.h b/src/gui/kernel/qaction.h
index 8466bc41f7..d805599138 100644
--- a/src/gui/kernel/qaction.h
+++ b/src/gui/kernel/qaction.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QACTION_H
#define QACTION_H
@@ -47,6 +11,7 @@
#include <QtGui/qicon.h>
#include <QtCore/qstring.h>
#include <QtCore/qvariant.h>
+#include <QtCore/qobject.h>
QT_REQUIRE_CONFIG(action);
@@ -55,10 +20,10 @@ QT_BEGIN_NAMESPACE
class QActionEvent;
class QActionGroup;
class QActionPrivate;
+class QMenu;
#if QT_DEPRECATED_SINCE(6,0)
class QWidget;
class QGraphicsWidget;
-class QMenu;
#endif
class Q_GUI_EXPORT QAction : public QObject
@@ -68,7 +33,8 @@ class Q_GUI_EXPORT QAction : public QObject
Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged FINAL)
Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled)
- Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged RESET resetEnabled FINAL)
+ Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged
+ RESET resetEnabled FINAL)
Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY changed)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY changed)
Q_PROPERTY(QString iconText READ iconText WRITE setIconText NOTIFY changed)
@@ -78,14 +44,17 @@ class Q_GUI_EXPORT QAction : public QObject
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed)
#if QT_CONFIG(shortcut)
Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut NOTIFY changed)
- Q_PROPERTY(Qt::ShortcutContext shortcutContext READ shortcutContext WRITE setShortcutContext NOTIFY changed)
+ Q_PROPERTY(Qt::ShortcutContext shortcutContext READ shortcutContext WRITE setShortcutContext
+ NOTIFY changed)
Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY changed)
#endif // QT_CONFIG(shortcut)
- Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY changed)
+ Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
Q_PROPERTY(MenuRole menuRole READ menuRole WRITE setMenuRole NOTIFY changed)
- Q_PROPERTY(bool iconVisibleInMenu READ isIconVisibleInMenu WRITE setIconVisibleInMenu NOTIFY changed)
- Q_PROPERTY(bool shortcutVisibleInContextMenu READ isShortcutVisibleInContextMenu WRITE setShortcutVisibleInContextMenu NOTIFY changed)
- Q_PROPERTY(Priority priority READ priority WRITE setPriority)
+ Q_PROPERTY(bool iconVisibleInMenu READ isIconVisibleInMenu WRITE setIconVisibleInMenu
+ NOTIFY changed)
+ Q_PROPERTY(bool shortcutVisibleInContextMenu READ isShortcutVisibleInContextMenu
+ WRITE setShortcutVisibleInContextMenu NOTIFY changed)
+ Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY changed)
public:
// note this is copied into qplatformmenu.h, which must stay in sync
@@ -105,7 +74,7 @@ public:
QList<QObject *> associatedObjects() const;
#if QT_DEPRECATED_SINCE(6,0)
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
QWidget *parentWidget() const;
QList<QWidget*> associatedWidgets() const;
QList<QGraphicsWidget*> associatedGraphicsWidgets() const;
@@ -115,6 +84,7 @@ public:
QWidget, QMenu, and QGraphicsWidget can be expected to be fully defined.
*/
template<typename T = QWidget*>
+ QT_DEPRECATED_VERSION_X_6_0("Use parent() with qobject_cast() instead")
T parentWidget() const
{
auto result = parent();
@@ -124,6 +94,7 @@ public:
}
template<typename T = QWidget*>
+ QT_DEPRECATED_VERSION_X_6_0("Use associatedObjects() with qobject_cast() instead")
QList<T> associatedWidgets() const
{
QList<T> result;
@@ -133,6 +104,7 @@ public:
return result;
}
template<typename T = QGraphicsWidget*>
+ QT_DEPRECATED_VERSION_X_6_0("Use associatedObjects() with qobject_cast() instead")
QList<T> associatedGraphicsWidgets() const
{
QList<T> result;
@@ -206,8 +178,7 @@ public:
void setMenuRole(MenuRole menuRole);
MenuRole menuRole() const;
-#if QT_DEPRECATED_SINCE(6,0)
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
QMenu *menu() const;
void setMenu(QMenu *menu);
#else
@@ -222,7 +193,6 @@ public:
setMenuObject(m);
}
#endif
-#endif
void setIconVisibleInMenu(bool visible);
bool isIconVisibleInMenu() const;
@@ -250,6 +220,7 @@ Q_SIGNALS:
void changed();
void enabledChanged(bool enabled);
void checkableChanged(bool checkable);
+ void visibleChanged();
void triggered(bool checked = false);
void hovered();
void toggled(bool);
diff --git a/src/gui/kernel/qaction_p.h b/src/gui/kernel/qaction_p.h
index 3e137a09d6..e79cc26b4d 100644
--- a/src/gui/kernel/qaction_p.h
+++ b/src/gui/kernel/qaction_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QACTION_P_H
#define QACTION_P_H
@@ -57,6 +21,8 @@
#if QT_CONFIG(shortcut)
# include <QtGui/private/qshortcutmap_p.h>
#endif
+
+#include <QtCore/qpointer.h>
#include "private/qobject_p.h"
QT_REQUIRE_CONFIG(action);
@@ -84,6 +50,7 @@ public:
}
bool setEnabled(bool enable, bool byGroup);
+ void setVisible(bool b);
QPointer<QActionGroup> group;
QString text;
@@ -93,8 +60,7 @@ public:
QString statustip;
QString whatsthis;
#if QT_CONFIG(shortcut)
- QKeySequence shortcut;
- QList<QKeySequence> alternateShortcuts;
+ QList<QKeySequence> shortcuts;
#endif
QVariant userData;
@@ -103,8 +69,7 @@ public:
virtual void setMenu(QObject *menu);
#if QT_CONFIG(shortcut)
- int shortcutId = 0;
- QList<int> alternateShortcutIds;
+ QList<int> shortcutIds;
Qt::ShortcutContext shortcutContext = Qt::WindowShortcut;
uint autorepeat : 1;
#endif
diff --git a/src/gui/kernel/qactiongroup.cpp b/src/gui/kernel/qactiongroup.cpp
index 6e2efdb74b..7fb5b4ad46 100644
--- a/src/gui/kernel/qactiongroup.cpp
+++ b/src/gui/kernel/qactiongroup.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qactiongroup.h"
@@ -169,10 +133,8 @@ QAction *QActionGroup::addAction(QAction* a)
QObject::connect(a, &QAction::hovered, this, &QActionGroup::_q_actionHovered);
}
a->d_func()->setEnabled(d->enabled, true);
- if (!a->d_func()->forceInvisible) {
- a->setVisible(d->visible);
- a->d_func()->forceInvisible = false;
- }
+ if (!a->d_func()->forceInvisible)
+ a->d_func()->setVisible(d->visible);
if (a->isChecked())
d->current = a;
QActionGroup *oldGroup = a->d_func()->group;
@@ -315,7 +277,7 @@ void QActionGroup::setEnabled(bool b)
{
Q_D(QActionGroup);
d->enabled = b;
- for (auto action : qAsConst(d->actions)) {
+ for (auto action : std::as_const(d->actions)) {
action->d_func()->setEnabled(b, true);
}
}
@@ -349,11 +311,9 @@ void QActionGroup::setVisible(bool b)
{
Q_D(QActionGroup);
d->visible = b;
- for (auto action : qAsConst(d->actions)) {
- if (!action->d_func()->forceInvisible) {
- action->setVisible(b);
- action->d_func()->forceInvisible = false;
- }
+ for (auto action : std::as_const(d->actions)) {
+ if (!action->d_func()->forceInvisible)
+ action->d_func()->setVisible(b);
}
}
@@ -364,3 +324,5 @@ bool QActionGroup::isVisible() const
}
QT_END_NAMESPACE
+
+#include "moc_qactiongroup.cpp"
diff --git a/src/gui/kernel/qactiongroup.h b/src/gui/kernel/qactiongroup.h
index c485654d08..d0830aeccb 100644
--- a/src/gui/kernel/qactiongroup.h
+++ b/src/gui/kernel/qactiongroup.h
@@ -1,44 +1,8 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGUIACTIONGROUP_H
-#define QGUIACTIONGROUP_H
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QACTIONGROUP_H
+#define QACTIONGROUP_H
#include <QtGui/qtguiglobal.h>
#include <QtGui/qaction.h>
@@ -107,4 +71,4 @@ private:
QT_END_NAMESPACE
-#endif // QGUIACTIONGROUP_H
+#endif // QACTIONGROUP_H
diff --git a/src/gui/kernel/qactiongroup_p.h b/src/gui/kernel/qactiongroup_p.h
index 4b503783ed..ba939a2b10 100644
--- a/src/gui/kernel/qactiongroup_p.h
+++ b/src/gui/kernel/qactiongroup_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QGUIACTIONGROUP_P_H
#define QGUIACTIONGROUP_P_H
@@ -57,6 +21,8 @@
#if QT_CONFIG(shortcut)
# include <QtGui/private/qshortcutmap_p.h>
#endif
+
+#include <QtCore/qpointer.h>
#include "private/qobject_p.h"
QT_REQUIRE_CONFIG(action);
diff --git a/src/gui/kernel/qclipboard.cpp b/src/gui/kernel/qclipboard.cpp
index eb6c2af6d1..6a36862a04 100644
--- a/src/gui/kernel/qclipboard.cpp
+++ b/src/gui/kernel/qclipboard.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qclipboard.h"
@@ -54,6 +18,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
/*!
\class QClipboard
\brief The QClipboard class provides access to the window system clipboard.
@@ -83,7 +49,7 @@ QT_BEGIN_NAMESPACE
A typical example of the use of these functions follows:
- \snippet droparea.cpp 0
+ \snippet droparea/droparea.cpp 0
\section1 Notes for X11 Users
@@ -137,6 +103,10 @@ QT_BEGIN_NAMESPACE
\endlist
+ \section1 Notes for Android Users
+
+ On Android only these mime types are supported: text/plain, text/html, and text/uri-list.
+
\sa QGuiApplication
*/
@@ -270,23 +240,27 @@ QString QClipboard::text(QString &subtype, Mode mode) const
const QStringList formats = data->formats();
if (subtype.isEmpty()) {
- if (formats.contains(QLatin1String("text/plain")))
- subtype = QLatin1String("plain");
+ if (formats.contains("text/plain"_L1))
+ subtype = "plain"_L1;
else {
- for (int i = 0; i < formats.size(); ++i)
- if (formats.at(i).startsWith(QLatin1String("text/"))) {
- subtype = formats.at(i).mid(5);
+ for (const auto &format : formats) {
+ if (format.startsWith("text/"_L1)) {
+ subtype = format.sliced(5);
break;
}
+ }
if (subtype.isEmpty())
return QString();
}
- } else if (!formats.contains(QLatin1String("text/") + subtype)) {
+ } else if (!formats.contains("text/"_L1 + subtype)) {
return QString();
}
- const QByteArray rawData = data->data(QLatin1String("text/") + subtype);
- return qFromUtfEncoded(rawData);
+ const QByteArray rawData = data->data("text/"_L1 + subtype);
+ auto encoding = QStringConverter::encodingForData(rawData);
+ if (!encoding)
+ encoding = QStringConverter::Utf8;
+ return QStringDecoder(*encoding).decode(rawData);
}
/*!
@@ -579,12 +553,13 @@ void QClipboard::emitChanged(Mode mode)
case FindBuffer:
emit findBufferChanged();
break;
- default:
- break;
}
+
emit changed(mode);
}
QT_END_NAMESPACE
+#include "moc_qclipboard.cpp"
+
#endif // QT_NO_CLIPBOARD
diff --git a/src/gui/kernel/qclipboard.h b/src/gui/kernel/qclipboard.h
index e91444d3dc..42b8bad026 100644
--- a/src/gui/kernel/qclipboard.h
+++ b/src/gui/kernel/qclipboard.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QCLIPBOARD_H
#define QCLIPBOARD_H
diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp
index 7ebf59290c..8e7747559a 100644
--- a/src/gui/kernel/qcursor.cpp
+++ b/src/gui/kernel/qcursor.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qcursor.h"
@@ -150,7 +114,7 @@ QT_BEGIN_NAMESPACE
\li Qt::DragLinkCursor \li \c dnd-link or \c link
\endtable
- \sa QWidget, {fowler}{GUI Design Handbook: Cursors}
+ \sa QWidget
*/
/*!
@@ -251,7 +215,8 @@ void QCursor::setPos(QScreen *screen, int x, int y)
{
if (screen) {
if (QPlatformCursor *cursor = screen->handle()->cursor()) {
- const QPoint devicePos = QHighDpi::toNativePixels(QPoint(x, y), screen);
+ const QPoint pos(x, y);
+ const QPoint devicePos = QHighDpi::toNativePixels(pos, screen->virtualSiblingAt(pos));
// Need to check, since some X servers generate null mouse move
// events, causing looping in applications which call setPos() on
// every mouse move event.
@@ -325,7 +290,7 @@ QDataStream &operator<<(QDataStream &s, const QCursor &c)
if (isPixmap)
s << c.pixmap();
else
- s << c.bitmap(Qt::ReturnByValue) << c.mask(Qt::ReturnByValue);
+ s << c.bitmap() << c.mask();
s << c.hotSpot();
}
return s;
@@ -474,14 +439,12 @@ QCursor::QCursor()
QCursor::QCursor(Qt::CursorShape shape)
: d(nullptr)
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
setShape(shape);
}
/*!
- \fn bool operator==(const QCursor &lhs, const QCursor &rhs)
- \relates QCursor
+ \fn bool QCursor::operator==(const QCursor &lhs, const QCursor &rhs)
\since 5.10
Equality operator. Returns \c true if \a lhs and \a rhs
@@ -519,8 +482,7 @@ bool operator==(const QCursor &lhs, const QCursor &rhs) noexcept
}
/*!
- \fn bool operator!=(const QCursor &lhs, const QCursor &rhs)
- \relates QCursor
+ \fn bool QCursor::operator!=(const QCursor &lhs, const QCursor &rhs)
\since 5.10
Inequality operator. Returns the equivalent of !(\a lhs == \a rhs).
@@ -529,15 +491,13 @@ bool operator==(const QCursor &lhs, const QCursor &rhs) noexcept
*/
/*!
- Returns the cursor shape identifier. The return value is one of
- the \l Qt::CursorShape enum values (cast to an int).
+ Returns the cursor shape identifier.
\sa setShape()
*/
Qt::CursorShape QCursor::shape() const
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
return d->cshape;
}
@@ -550,8 +510,7 @@ Qt::CursorShape QCursor::shape() const
*/
void QCursor::setShape(Qt::CursorShape shape)
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
QCursorData *c = uint(shape) <= Qt::LastCursor ? qt_cursorTable[shape] : nullptr;
if (!c)
c = qt_cursorTable[0];
@@ -568,7 +527,7 @@ void QCursor::setShape(Qt::CursorShape shape)
/*!
\fn QBitmap QCursor::bitmap(Qt::ReturnByValueConstant) const
\since 5.15
- \obsolete Use the overload without argument instead.
+ \deprecated Use the overload without argument instead.
Returns the cursor bitmap, or a null bitmap if it is one of the
standard cursors.
@@ -585,8 +544,7 @@ void QCursor::setShape(Qt::CursorShape shape)
*/
QBitmap QCursor::bitmap() const
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
if (d->bm)
return *(d->bm);
return QBitmap();
@@ -595,7 +553,7 @@ QBitmap QCursor::bitmap() const
/*!
\fn QBitmap QCursor::mask(Qt::ReturnByValueConstant) const
\since 5.15
- \obsolete Use the overload without argument instead.
+ \deprecated Use the overload without argument instead.
Returns the cursor bitmap mask, or a null bitmap if it is one of the
standard cursors.
@@ -612,8 +570,7 @@ QBitmap QCursor::bitmap() const
*/
QBitmap QCursor::mask() const
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
if (d->bmm)
return *(d->bmm);
return QBitmap();
@@ -626,8 +583,7 @@ QBitmap QCursor::mask() const
QPixmap QCursor::pixmap() const
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
return d->pixmap;
}
@@ -638,8 +594,7 @@ QPixmap QCursor::pixmap() const
QPoint QCursor::hotSpot() const
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
return QPoint(d->hx, d->hy);
}
@@ -649,8 +604,7 @@ QPoint QCursor::hotSpot() const
QCursor::QCursor(const QCursor &c)
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
d = c.d;
d->ref.ref();
}
@@ -673,8 +627,7 @@ QCursor::~QCursor()
QCursor &QCursor::operator=(const QCursor &c)
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
if (c.d)
c.d->ref.ref();
if (d && !d->ref.deref())
@@ -688,7 +641,7 @@ QCursor &QCursor::operator=(const QCursor &c)
*/
QCursor::operator QVariant() const
{
- return QVariant(QMetaType::QCursor, this);
+ return QVariant::fromValue(*this);
}
#ifndef QT_NO_DEBUG_STREAM
@@ -721,7 +674,7 @@ QCursorData::~QCursorData()
/*! \internal */
void QCursorData::cleanup()
{
- if(!QCursorData::initialized)
+ if (!QCursorData::initialized)
return;
for (int shape = 0; shape <= Qt::LastCursor; ++shape) {
@@ -745,8 +698,7 @@ void QCursorData::initialize()
QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY, qreal devicePixelRatio)
{
- if (!QCursorData::initialized)
- QCursorData::initialize();
+ QCursorData::initialize();
if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {
qWarning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
QCursorData *c = qt_cursorTable[0];
diff --git a/src/gui/kernel/qcursor.h b/src/gui/kernel/qcursor.h
index 21ea13c0d7..3aeef52094 100644
--- a/src/gui/kernel/qcursor.h
+++ b/src/gui/kernel/qcursor.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QCURSOR_H
#define QCURSOR_H
@@ -83,25 +47,26 @@ public:
QCursor();
QCursor(Qt::CursorShape shape);
QCursor(const QBitmap &bitmap, const QBitmap &mask, int hotX=-1, int hotY=-1);
- QCursor(const QPixmap &pixmap, int hotX=-1, int hotY=-1);
+ explicit QCursor(const QPixmap &pixmap, int hotX=-1, int hotY=-1);
QCursor(const QCursor &cursor);
~QCursor();
QCursor &operator=(const QCursor &cursor);
- QCursor(QCursor &&other) noexcept : d(other.d) { other.d = nullptr; }
- inline QCursor &operator=(QCursor &&other) noexcept
- { swap(other); return *this; }
+ QCursor(QCursor &&other) noexcept : d(std::exchange(other.d, nullptr)) {}
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCursor)
- void swap(QCursor &other) noexcept { qSwap(d, other.d); }
+ void swap(QCursor &other) noexcept { qt_ptr_swap(d, other.d); }
operator QVariant() const;
Qt::CursorShape shape() const;
void setShape(Qt::CursorShape newShape);
-#if QT_DEPRECATED_SINCE(6, 6)
+#if QT_DEPRECATED_SINCE(6, 0)
+ QT_DEPRECATED_VERSION_X_6_0("Use the overload without argument instead.")
QBitmap bitmap(Qt::ReturnByValueConstant) const { return bitmap(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use the overload without argument instead.")
QBitmap mask(Qt::ReturnByValueConstant) const { return mask(); }
-#endif // QT_DEPRECATED_SINCE(6, 6)
+#endif // QT_DEPRECATED_SINCE(6, 0)
QBitmap bitmap() const;
QBitmap mask() const;
@@ -117,13 +82,11 @@ public:
private:
friend Q_GUI_EXPORT bool operator==(const QCursor &lhs, const QCursor &rhs) noexcept;
+ friend inline bool operator!=(const QCursor &lhs, const QCursor &rhs) noexcept { return !(lhs == rhs); }
QCursorData *d;
};
Q_DECLARE_SHARED(QCursor)
-Q_GUI_EXPORT bool operator==(const QCursor &lhs, const QCursor &rhs) noexcept;
-inline bool operator!=(const QCursor &lhs, const QCursor &rhs) noexcept { return !(lhs == rhs); }
-
/*****************************************************************************
QCursor stream functions
*****************************************************************************/
diff --git a/src/gui/kernel/qcursor_p.h b/src/gui/kernel/qcursor_p.h
index 37245a793f..52ea15b59a 100644
--- a/src/gui/kernel/qcursor_p.h
+++ b/src/gui/kernel/qcursor_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QCURSOR_P_H
#define QCURSOR_P_H
diff --git a/src/gui/kernel/qdnd.cpp b/src/gui/kernel/qdnd.cpp
index fe766c900e..248a1e83ed 100644
--- a/src/gui/kernel/qdnd.cpp
+++ b/src/gui/kernel/qdnd.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdnd_p.h"
@@ -123,3 +87,5 @@ Qt::DropAction QDragManager::drag(QDrag *o)
}
QT_END_NAMESPACE
+
+#include "moc_qdnd_p.cpp"
diff --git a/src/gui/kernel/qdnd_p.h b/src/gui/kernel/qdnd_p.h
index abb30986a5..b5a2e015f4 100644
--- a/src/gui/kernel/qdnd_p.h
+++ b/src/gui/kernel/qdnd_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDND_P_H
#define QDND_P_H
@@ -63,6 +27,8 @@
#include "private/qobject_p.h"
#include "QtGui/qbackingstore.h"
+#include <QtCore/qpointer.h>
+
QT_REQUIRE_CONFIG(draganddrop);
QT_BEGIN_NAMESPACE
diff --git a/src/gui/kernel/qdrag.cpp b/src/gui/kernel/qdrag.cpp
index d6dfc6387c..4e707e4915 100644
--- a/src/gui/kernel/qdrag.cpp
+++ b/src/gui/kernel/qdrag.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qdrag.h>
#include "private/qguiapplication_p.h"
@@ -45,6 +9,8 @@
#include <qpoint.h>
#include "qdnd_p.h"
+#include <QtCore/qpointer.h>
+
QT_BEGIN_NAMESPACE
/*!
@@ -99,9 +65,8 @@ QT_BEGIN_NAMESPACE
\l{QWidget::mouseMoveEvent()}{mouseMoveEvent()} to check whether a QDrag is
required.
- \sa {Drag and Drop}, QClipboard, QMimeData, QMacPasteboardMime,
- {Draggable Icons Example}, {Draggable Text Example}, {Drop Site Example},
- {Fridge Magnets Example}
+ \sa {Drag and Drop}, QClipboard, QMimeData, {Draggable Icons Example},
+ {Draggable Text Example}, {Drop Site Example}
*/
/*!
@@ -393,3 +358,5 @@ void QDrag::cancel()
*/
QT_END_NAMESPACE
+
+#include "moc_qdrag.cpp"
diff --git a/src/gui/kernel/qdrag.h b/src/gui/kernel/qdrag.h
index eaa677b50d..65314fd20c 100644
--- a/src/gui/kernel/qdrag.h
+++ b/src/gui/kernel/qdrag.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDRAG_H
#define QDRAG_H
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 0655a97012..d8c11d72a6 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -1,65 +1,59 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qevent.h"
+
#include "qcursor.h"
#include "private/qguiapplication_p.h"
#include "private/qinputdevice_p.h"
#include "private/qpointingdevice_p.h"
#include "qpa/qplatformintegration.h"
#include "private/qevent_p.h"
+#include "private/qeventpoint_p.h"
+
#include "qfile.h"
#include "qhashfunctions.h"
#include "qmetaobject.h"
#include "qmimedata.h"
#include "qevent_p.h"
#include "qmath.h"
+#include "qloggingcategory.h"
+#include "qpointer.h"
#if QT_CONFIG(draganddrop)
#include <qpa/qplatformdrag.h>
#include <private/qdnd_p.h>
#endif
+#if QT_CONFIG(shortcut)
+#include <private/qshortcut_p.h>
+#endif
+
#include <private/qdebug_p.h>
+#define Q_IMPL_POINTER_EVENT(Class) \
+ Class::Class(const Class &) = default; \
+ Class::~Class() = default; \
+ Class* Class::clone() const \
+ { \
+ auto c = new Class(*this); \
+ for (auto &point : c->m_points) \
+ QMutableEventPoint::detach(point); \
+ QEvent *e = c; \
+ /* check that covariant return is safe to add */ \
+ Q_ASSERT(reinterpret_cast<quintptr>(c) == reinterpret_cast<quintptr>(e)); \
+ return c; \
+ }
+
+
+
QT_BEGIN_NAMESPACE
+static_assert(sizeof(QMutableTouchEvent) == sizeof(QTouchEvent));
+static_assert(sizeof(QMutableSinglePointEvent) == sizeof(QSinglePointEvent));
+static_assert(sizeof(QMouseEvent) == sizeof(QSinglePointEvent));
+static_assert(sizeof(QVector2D) == sizeof(quint64));
+
/*!
\class QEnterEvent
\ingroup events
@@ -73,70 +67,70 @@ QT_BEGIN_NAMESPACE
*/
/*!
- Constructs an enter event object.
+ Constructs an enter event object originating from \a device.
The points \a localPos, \a scenePos and \a globalPos specify the
mouse cursor's position relative to the receiving widget or item,
window, and screen or desktop, respectively.
*/
-
-QEnterEvent::QEnterEvent(const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos)
- : QEvent(QEvent::Enter)
- , l(localPos)
- , s(scenePos)
- , g(globalPos)
+QEnterEvent::QEnterEvent(const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos, const QPointingDevice *device)
+ : QSinglePointEvent(QEvent::Enter, device, localPos, scenePos, globalPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier)
{
}
-/*!
- \internal
-*/
-QEnterEvent::~QEnterEvent()
-{
-}
+Q_IMPL_POINTER_EVENT(QEnterEvent)
/*!
\fn QPoint QEnterEvent::globalPos() const
+ \deprecated [6.0] Use globalPosition() instead.
Returns the global position of the mouse cursor \e{at the time of the event}.
*/
/*!
\fn int QEnterEvent::globalX() const
+ \deprecated [6.0] Use globalPosition().x() instead.
Returns the global position on the X-axis of the mouse cursor \e{at the time of the event}.
*/
/*!
\fn int QEnterEvent::globalY() const
+ \deprecated [6.0] Use globalPosition().y() instead.
Returns the global position on the Y-axis of the mouse cursor \e{at the time of the event}.
*/
/*!
\fn QPointF QEnterEvent::localPos() const
+ \deprecated [6.0] Use position() instead.
Returns the mouse cursor's position relative to the receiving widget.
*/
/*!
\fn QPoint QEnterEvent::pos() const
+ \deprecated [6.0] Use position().toPoint() instead.
Returns the position of the mouse cursor relative to the receiving widget.
*/
/*!
\fn QPointF QEnterEvent::screenPos() const
+ \deprecated [6.0] Use globalPosition() instead.
Returns the position of the mouse cursor relative to the receiving screen.
*/
/*!
\fn QPointF QEnterEvent::windowPos() const
+ \deprecated [6.0] Use scenePosition() instead.
Returns the position of the mouse cursor relative to the receiving window.
*/
/*!
\fn int QEnterEvent::x() const
+ \deprecated [6.0] Use position().x() instead.
Returns the x position of the mouse cursor relative to the receiving widget.
*/
/*!
\fn int QEnterEvent::y() const
+ \deprecated [6.0] Use position().y() instead.
Returns the y position of the mouse cursor relative to the receiving widget.
*/
@@ -154,27 +148,24 @@ QEnterEvent::~QEnterEvent()
\internal
*/
QInputEvent::QInputEvent(Type type, const QInputDevice *dev, Qt::KeyboardModifiers modifiers)
- : QEvent(type), m_dev(dev), modState(modifiers), ts(0)
+ : QEvent(type, QEvent::InputEventTag{}), m_dev(dev), m_modState(modifiers), m_reserved(0)
{}
/*!
\internal
*/
-QInputEvent::~QInputEvent()
-{
-}
-
-QPointerEvent::QPointerEvent(QEvent::Type type, const QPointingDevice *dev, Qt::KeyboardModifiers modifiers)
- : QInputEvent(type, dev, modifiers)
-{
-
-}
+QInputEvent::QInputEvent(QEvent::Type type, QEvent::PointerEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers)
+ : QEvent(type, QEvent::PointerEventTag{}), m_dev(dev), m_modState(modifiers), m_reserved(0)
+{}
-const QPointingDevice *QPointerEvent::pointingDevice() const
-{
- return static_cast<const QPointingDevice *>(m_dev);
-}
+/*!
+ \internal
+*/
+QInputEvent::QInputEvent(QEvent::Type type, QEvent::SinglePointEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers)
+ : QEvent(type, QEvent::SinglePointEventTag{}), m_dev(dev), m_modState(modifiers), m_reserved(0)
+{}
+Q_IMPL_EVENT_COMMON(QInputEvent)
/*!
\fn QInputDevice *QInputEvent::device() const
@@ -188,6 +179,8 @@ const QPointingDevice *QPointerEvent::pointingDevice() const
Thus \c {mouseEvent.source()->type() != QInputDevice::DeviceType::Mouse}
is one possible replacement for the Qt 5 expression
\c {mouseEvent.source() == Qt::MouseEventSynthesizedByQt}.
+
+ \sa QPointerEvent::pointingDevice()
*/
/*!
@@ -213,14 +206,14 @@ const QPointingDevice *QPointerEvent::pointingDevice() const
*/
/*!
- \fn ulong QInputEvent::timestamp() const
+ \fn quint64 QInputEvent::timestamp() const
Returns the window system's timestamp for this event.
It will normally be in milliseconds since some arbitrary point
in time, such as the time when the system was started.
*/
-/*! \fn void QInputEvent::setTimestamp(ulong atimestamp)
+/*! \fn void QInputEvent::setTimestamp(quint64 atimestamp)
\internal
@@ -228,12 +221,406 @@ const QPointingDevice *QPointerEvent::pointingDevice() const
*/
/*!
+ \class QPointerEvent
+ \since 6.0
+ \inmodule QtGui
+
+ \brief A base class for pointer events.
+*/
+
+/*!
+ \fn qsizetype QPointerEvent::pointCount() const
+
+ Returns the number of points in this pointer event.
+*/
+
+/*!
+ Returns a QEventPoint reference for the point at index \a i.
+*/
+QEventPoint &QPointerEvent::point(qsizetype i)
+{
+ return m_points[i];
+}
+
+/*!
+ \fn const QList<QEventPoint> &QPointerEvent::points() const
+
+ Returns a list of points in this pointer event.
+*/
+
+/*!
\fn QPointingDevice::PointerType QPointerEvent::pointerType() const
Returns the type of point that generated the event.
*/
/*!
+ \internal
+*/
+QPointerEvent::QPointerEvent(QEvent::Type type, const QPointingDevice *dev,
+ Qt::KeyboardModifiers modifiers, const QList<QEventPoint> &points)
+ : QInputEvent(type, QEvent::PointerEventTag{}, dev, modifiers), m_points(points)
+{
+}
+
+/*!
+ \internal
+*/
+QPointerEvent::QPointerEvent(QEvent::Type type, QEvent::SinglePointEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers)
+ : QInputEvent(type, QEvent::SinglePointEventTag{}, dev, modifiers)
+{
+}
+
+Q_IMPL_POINTER_EVENT(QPointerEvent);
+
+/*!
+ Returns the point whose \l {QEventPoint::id()}{id} matches the given \a id,
+ or \c nullptr if no such point is found.
+*/
+QEventPoint *QPointerEvent::pointById(int id)
+{
+ for (auto &p : m_points) {
+ if (p.id() == id)
+ return &p;
+ }
+ return nullptr;
+}
+
+/*!
+ Returns \c true if every point in points() has either an exclusiveGrabber()
+ or one or more passiveGrabbers().
+*/
+bool QPointerEvent::allPointsGrabbed() const
+{
+ for (const auto &p : points()) {
+ if (!exclusiveGrabber(p) && passiveGrabbers(p).isEmpty())
+ return false;
+ }
+ return true;
+}
+
+/*!
+ Returns \c true if isPointAccepted() is \c true for every point in
+ points(); otherwise \c false.
+*/
+bool QPointerEvent::allPointsAccepted() const
+{
+ for (const auto &p : points()) {
+ if (!p.isAccepted())
+ return false;
+ }
+ return true;
+}
+
+/*!
+ \reimp
+*/
+void QPointerEvent::setAccepted(bool accepted)
+{
+ QEvent::setAccepted(accepted);
+ for (auto &p : m_points)
+ p.setAccepted(accepted);
+}
+
+/*!
+ Returns the source device from which this event originates.
+
+ This is the same as QInputEvent::device() but typecast for convenience.
+*/
+const QPointingDevice *QPointerEvent::pointingDevice() const
+{
+ return static_cast<const QPointingDevice *>(m_dev);
+}
+
+/*! \internal
+ Sets the timestamp for this event and its points().
+*/
+void QPointerEvent::setTimestamp(quint64 timestamp)
+{
+ QInputEvent::setTimestamp(timestamp);
+ for (auto &p : m_points)
+ QMutableEventPoint::setTimestamp(p, timestamp);
+}
+
+/*!
+ Returns the object which has been set to receive all future update events
+ and the release event containing the given \a point.
+
+ It's mainly for use in Qt Quick at this time.
+*/
+QObject *QPointerEvent::exclusiveGrabber(const QEventPoint &point) const
+{
+ Q_ASSERT(pointingDevice());
+ auto persistentPoint = QPointingDevicePrivate::get(pointingDevice())->queryPointById(point.id());
+ if (Q_UNLIKELY(!persistentPoint)) {
+ qWarning() << "point is not in activePoints" << point;
+ return nullptr;
+ }
+ return persistentPoint->exclusiveGrabber;
+}
+
+/*!
+ Informs the delivery logic that the given \a exclusiveGrabber is to
+ receive all future update events and the release event containing
+ the given \a point, and that delivery to other items can be skipped.
+
+ It's mainly for use in Qt Quick at this time.
+*/
+void QPointerEvent::setExclusiveGrabber(const QEventPoint &point, QObject *exclusiveGrabber)
+{
+ Q_ASSERT(pointingDevice());
+ auto devPriv = QPointingDevicePrivate::get(const_cast<QPointingDevice *>(pointingDevice()));
+ devPriv->setExclusiveGrabber(this, point, exclusiveGrabber);
+}
+
+/*!
+ Returns the list of objects that have been requested to receive all
+ future update events and the release event containing the given \a point.
+
+ It's only for use by \l {Qt Quick Input Handlers}.
+
+ \sa QPointerEvent::addPassiveGrabber()
+*/
+QList<QPointer<QObject> > QPointerEvent::passiveGrabbers(const QEventPoint &point) const
+{
+ Q_ASSERT(pointingDevice());
+ auto persistentPoint = QPointingDevicePrivate::get(pointingDevice())->queryPointById(point.id());
+ if (Q_UNLIKELY(!persistentPoint)) {
+ qWarning() << "point is not in activePoints" << point;
+ return {};
+ }
+ return persistentPoint->passiveGrabbers;
+}
+
+/*!
+ Informs the delivery logic that the given \a grabber is to receive all
+ future update events and the release event containing the given \a point,
+ regardless where else those events may be delivered.
+
+ It's only for use by \l {Qt Quick Input Handlers}.
+
+ Returns \c false if \a grabber was already added, \c true otherwise.
+*/
+bool QPointerEvent::addPassiveGrabber(const QEventPoint &point, QObject *grabber)
+{
+ Q_ASSERT(pointingDevice());
+ auto devPriv = QPointingDevicePrivate::get(const_cast<QPointingDevice *>(pointingDevice()));
+ return devPriv->addPassiveGrabber(this, point, grabber);
+}
+
+/*!
+ Removes the passive \a grabber from the given \a point if it was previously added.
+ Returns \c true if it had been a passive grabber before, \c false if not.
+
+ It's only for use by \l {Qt Quick Input Handlers}.
+
+ \sa QPointerEvent::addPassiveGrabber()
+*/
+bool QPointerEvent::removePassiveGrabber(const QEventPoint &point, QObject *grabber)
+{
+ Q_ASSERT(pointingDevice());
+ auto devPriv = QPointingDevicePrivate::get(const_cast<QPointingDevice *>(pointingDevice()));
+ return devPriv->removePassiveGrabber(this, point, grabber);
+}
+
+/*!
+ Removes all passive grabbers from the given \a point.
+
+ It's only for use by \l {Qt Quick Input Handlers}.
+
+ \sa QPointerEvent::addPassiveGrabber()
+*/
+void QPointerEvent::clearPassiveGrabbers(const QEventPoint &point)
+{
+ Q_ASSERT(pointingDevice());
+ auto devPriv = QPointingDevicePrivate::get(const_cast<QPointingDevice *>(pointingDevice()));
+ devPriv->clearPassiveGrabbers(this, point);
+}
+
+/*!
+ \class QSinglePointEvent
+ \since 6.0
+ \inmodule QtGui
+
+ \brief A base class for pointer events containing a single point, such as
+ mouse events.
+*/
+
+/*! \fn Qt::MouseButton QSinglePointEvent::button() const
+
+ Returns the button that caused the event.
+
+ The returned value is always Qt::NoButton for mouse move events, as
+ well as \l TabletMove, \l TabletEnterProximity, and
+ \l TabletLeaveProximity events.
+
+ \sa buttons()
+*/
+
+/*! \fn Qt::MouseButtons QSinglePointEvent::buttons() const
+
+ Returns the button state when the event was generated.
+
+ The button state is a combination of Qt::LeftButton, Qt::RightButton,
+ and Qt::MiddleButton using the OR operator.
+
+ For mouse move or \l TabletMove events, this is all buttons that are
+ pressed down.
+
+ For mouse press, double click, or \l TabletPress events, this includes
+ the button that caused the event.
+
+ For mouse release or \l TabletRelease events, this excludes the button
+ that caused the event.
+
+ \sa button()
+*/
+
+/*! \fn QPointF QSinglePointEvent::position() const
+
+ Returns the position of the point in this event, relative to the widget or
+ item that received the event.
+
+ If you move your widgets around in response to mouse events, use
+ globalPosition() instead.
+
+ \sa globalPosition()
+*/
+
+/*! \fn QPointF QSinglePointEvent::scenePosition() const
+
+ Returns the position of the point in this event, relative to the window or
+ scene.
+
+ \sa QEventPoint::scenePosition
+*/
+
+/*! \fn QPointF QSinglePointEvent::globalPosition() const
+
+ Returns the position of the point in this event on the screen or virtual
+ desktop.
+
+ \note The global position of a mouse pointer is recorded \e{at the time
+ of the event}. This is important on asynchronous window systems
+ such as X11; whenever you move your widgets around in response to
+ mouse events, globalPosition() can differ a lot from the current
+ cursor position returned by QCursor::pos().
+
+ \sa position()
+*/
+
+/*!
+ \internal
+*/
+QSinglePointEvent::QSinglePointEvent(QEvent::Type type, const QPointingDevice *dev,
+ const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
+ Qt::MouseButton button, Qt::MouseButtons buttons,
+ Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source)
+ : QPointerEvent(type, QEvent::SinglePointEventTag{}, dev, modifiers),
+ m_button(button),
+ m_mouseState(buttons),
+ m_source(source),
+ m_reserved(0), m_reserved2(0),
+ m_doubleClick(false), m_phase(0), m_invertedScrolling(0)
+{
+ bool isPress = (button != Qt::NoButton && (button | buttons) == buttons);
+ bool isWheel = (type == QEvent::Type::Wheel);
+ auto devPriv = QPointingDevicePrivate::get(const_cast<QPointingDevice *>(pointingDevice()));
+ auto epd = devPriv->pointById(0);
+ QEventPoint &p = epd->eventPoint;
+ Q_ASSERT(p.device() == dev);
+ // p is a reference to a non-detached instance that lives in QPointingDevicePrivate::activePoints.
+ // Update persistent info in that instance.
+ if (isPress || isWheel)
+ QMutableEventPoint::setGlobalLastPosition(p, globalPos);
+ else
+ QMutableEventPoint::setGlobalLastPosition(p, p.globalPosition());
+ QMutableEventPoint::setGlobalPosition(p, globalPos);
+ if (isWheel && p.state() != QEventPoint::State::Updated)
+ QMutableEventPoint::setGlobalPressPosition(p, globalPos);
+ if (type == MouseButtonDblClick)
+ QMutableEventPoint::setState(p, QEventPoint::State::Stationary);
+ else if (button == Qt::NoButton || isWheel)
+ QMutableEventPoint::setState(p, QEventPoint::State::Updated);
+ else if (isPress)
+ QMutableEventPoint::setState(p, QEventPoint::State::Pressed);
+ else
+ QMutableEventPoint::setState(p, QEventPoint::State::Released);
+ QMutableEventPoint::setScenePosition(p, scenePos);
+ // Now detach, and update the detached instance with ephemeral state.
+ QMutableEventPoint::detach(p);
+ QMutableEventPoint::setPosition(p, localPos);
+ m_points.append(p);
+}
+
+/*! \internal
+ Constructs a single-point event with the given \a point, which must be an instance
+ (or copy of one) that already exists in QPointingDevicePrivate::activePoints.
+ Unlike the other constructor, it does not modify the given \a point in any way.
+ This is useful when synthesizing a QMouseEvent from one point taken from a QTouchEvent, for example.
+
+ \sa QMutableSinglePointEvent()
+*/
+QSinglePointEvent::QSinglePointEvent(QEvent::Type type, const QPointingDevice *dev, const QEventPoint &point,
+ Qt::MouseButton button, Qt::MouseButtons buttons,
+ Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source)
+ : QPointerEvent(type, QEvent::SinglePointEventTag{}, dev, modifiers),
+ m_button(button),
+ m_mouseState(buttons),
+ m_source(source),
+ m_reserved(0), m_reserved2(0),
+ m_doubleClick(false), m_phase(0), m_invertedScrolling(0)
+{
+ m_points << point;
+}
+
+Q_IMPL_POINTER_EVENT(QSinglePointEvent)
+
+/*!
+ Returns \c true if this event represents a \l {button()}{button} being pressed.
+*/
+bool QSinglePointEvent::isBeginEvent() const
+{
+ // A double-click event does not begin a sequence: it comes after a press event,
+ // and while it tells which button caused the double-click, it doesn't represent
+ // a change of button state. So it's an update event.
+ return m_button != Qt::NoButton && m_mouseState.testFlag(m_button)
+ && type() != QEvent::MouseButtonDblClick;
+}
+
+/*!
+ Returns \c true if this event does not include a change in \l {buttons()}{button state}.
+*/
+bool QSinglePointEvent::isUpdateEvent() const
+{
+ // A double-click event is an update event even though it tells which button
+ // caused the double-click, because a MouseButtonPress event was sent right before it.
+ return m_button == Qt::NoButton || type() == QEvent::MouseButtonDblClick;
+}
+
+/*!
+ Returns \c true if this event represents a \l {button()}{button} being released.
+*/
+bool QSinglePointEvent::isEndEvent() const
+{
+ return m_button != Qt::NoButton && !m_mouseState.testFlag(m_button);
+}
+
+/*!
+ \property QSinglePointEvent::exclusivePointGrabber
+ \brief the object that will receive future updates
+
+ The exclusive grabber is an object that has chosen to receive all future
+ update events and the release event containing the same point that this
+ event carries.
+
+ Setting the exclusivePointGrabber property is a convenience equivalent to:
+ \code
+ setExclusiveGrabber(points().first(), exclusiveGrabber);
+ \endcode
+*/
+
+/*!
\class QMouseEvent
\ingroup events
\inmodule QtGui
@@ -282,8 +669,11 @@ const QPointingDevice *QPointerEvent::pointingDevice() const
QCursor::pos()
*/
+#if QT_DEPRECATED_SINCE(6, 4)
/*!
- Constructs a mouse event object.
+ \deprecated [6.4] Use another constructor instead (global position is required).
+
+ Constructs a mouse event object originating from \a device.
The \a type parameter must be one of QEvent::MouseButtonPress,
QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
@@ -303,18 +693,20 @@ const QPointingDevice *QPointerEvent::pointingDevice() const
position explicitly.
*/
QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton button,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
- : QPointerEvent(type, QPointingDevice::primaryPointingDevice(), modifiers),
- l(localPos), w(localPos), b(button), mouseState(buttons), caps(0)
-{
-#ifndef QT_NO_CURSOR
- g = QCursor::pos();
+ Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, const QPointingDevice *device)
+ : QSinglePointEvent(type, device, localPos, localPos,
+#ifdef QT_NO_CURSOR
+ localPos,
+#else
+ QCursor::pos(),
#endif
+ button, buttons, modifiers)
+{
}
-
+#endif
/*!
- Constructs a mouse event object.
+ Constructs a mouse event object originating from \a device.
The \a type parameter must be QEvent::MouseButtonPress,
QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
@@ -333,39 +725,12 @@ QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton but
*/
QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &globalPos,
Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers)
- : QMouseEvent(type, localPos, localPos, globalPos, button, buttons, modifiers)
-{}
-
-/*!
- Constructs a mouse event object.
-
- The \a type parameter must be QEvent::MouseButtonPress,
- QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
- or QEvent::MouseMove.
-
- The points \a localPos, \a scenePos and \a globalPos specify the
- mouse cursor's position relative to the receiving widget or item,
- window, and screen or desktop, respectively.
-
- The \a button that caused the event is
- given as a value from the \l Qt::MouseButton enum. If the event \a
- type is \l MouseMove, the appropriate button for this event is
- Qt::NoButton. \a buttons is the state of all buttons at the
- time of the event, \a modifiers the state of all keyboard
- modifiers.
-
-*/
-QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
- Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers)
- : QPointerEvent(type, QPointingDevice::primaryPointingDevice(), modifiers),
- l(localPos), w(scenePos), g(globalPos), b(button), mouseState(buttons), caps(0)
-{}
+ Qt::KeyboardModifiers modifiers, const QPointingDevice *device)
+ : QMouseEvent(type, localPos, localPos, globalPos, button, buttons, modifiers, device)
+{
+}
/*!
- \since 5.6
-
Constructs a mouse event object.
The \a type parameter must be QEvent::MouseButtonPress,
@@ -381,62 +746,81 @@ QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &scen
the appropriate button for this event is Qt::NoButton. \a buttons
is the state of all buttons at the time of the event, \a modifiers
is the state of all keyboard modifiers.
-
- The source of the event is specified by \a source.
-
*/
-QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
+QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF &localPos,
+ const QPointF &scenePos, const QPointF &globalPos,
Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source)
- : QMouseEvent(type, localPos, scenePos, globalPos, button, buttons, modifiers)
+ Qt::KeyboardModifiers modifiers, const QPointingDevice *device)
+ : QSinglePointEvent(type, device, localPos, scenePos, globalPos, button, buttons, modifiers)
{
- QGuiApplicationPrivate::setMouseEventSource(this, source);
}
-/*!
- \internal
-*/
-QMouseEvent::~QMouseEvent()
+QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF &localPos, const QPointF &windowPos,
+ const QPointF &globalPos, Qt::MouseButton button, Qt::MouseButtons buttons,
+ Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source,
+ const QPointingDevice *device)
+ : QSinglePointEvent(type, device, localPos, windowPos, globalPos, button, buttons, modifiers, source)
{
}
+Q_IMPL_POINTER_EVENT(QMouseEvent)
+
/*!
- \since 5.3
+ \fn Qt::MouseEventSource QMouseEvent::source() const
+ \since 5.3
+ \deprecated [6.0] Use pointingDevice() instead.
- Returns information about the mouse event source.
+ Returns information about the mouse event source.
- The mouse event source can be used to distinguish between genuine
- and artificial mouse events. The latter are events that are
- synthesized from touch events by the operating system or Qt itself.
+ The mouse event source can be used to distinguish between genuine
+ and artificial mouse events. The latter are events that are
+ synthesized from touch events by the operating system or Qt itself.
+ This enum tells you from where it was synthesized; but often
+ it's more useful to know from which device it was synthesized,
+ so try to use pointingDevice() instead.
- \note Many platforms provide no such information. On such platforms
- \l Qt::MouseEventNotSynthesized is returned always.
+ \note Many platforms provide no such information. On such platforms
+ \l Qt::MouseEventNotSynthesized is returned always.
- \sa Qt::MouseEventSource
- \sa QGraphicsSceneMouseEvent::source()
- */
+ \sa Qt::MouseEventSource
+ \sa QGraphicsSceneMouseEvent::source()
+
+ \note In Qt 5-based code, source() was often used to attempt to distinguish
+ mouse events from an actual mouse vs. those that were synthesized because
+ some legacy QQuickItem or QWidget subclass did not react to a QTouchEvent.
+ However, you could not tell whether it was synthesized from a QTouchEvent
+ or a QTabletEvent, and other information was lost. pointingDevice()
+ tells you the specific device that it came from, so you might check
+ \c {pointingDevice()->type()} or \c {pointingDevice()->capabilities()} to
+ decide how to react to this event. But it's even better to react to the
+ original event rather than handling only mouse events.
+*/
+// Note: the docs mention 6.0 as a deprecation version. That is correct and
+// intended, because we want our users to stop using it! Internally we will
+// deprecate it when we port our code away from using it.
Qt::MouseEventSource QMouseEvent::source() const
{
- return QGuiApplicationPrivate::mouseEventSource(this);
+ return Qt::MouseEventSource(m_source);
}
/*!
- \since 5.3
+ \since 5.3
- Returns the mouse event flags.
+ Returns the mouse event flags.
- The mouse event flags provide additional information about a mouse event.
+ The mouse event flags provide additional information about a mouse event.
- \sa Qt::MouseEventFlag
- \sa QGraphicsSceneMouseEvent::flags()
- */
+ \sa Qt::MouseEventFlag
+ \sa QGraphicsSceneMouseEvent::flags()
+*/
Qt::MouseEventFlags QMouseEvent::flags() const
{
- return QGuiApplicationPrivate::mouseEventFlags(this);
+ return (m_doubleClick ? Qt::MouseEventCreatedDoubleClick : Qt::NoMouseEventFlag);
}
/*!
\fn QPointF QMouseEvent::localPos() const
+ \deprecated [6.0] Use position() instead.
\since 5.0
@@ -464,6 +848,7 @@ Qt::MouseEventFlags QMouseEvent::flags() const
/*!
\fn QPointF QMouseEvent::windowPos() const
+ \deprecated [6.0] Use scenePosition() instead.
\since 5.0
@@ -479,6 +864,7 @@ Qt::MouseEventFlags QMouseEvent::flags() const
/*!
\fn QPointF QMouseEvent::screenPos() const
+ \deprecated [6.0] Use globalPosition() instead.
\since 5.0
@@ -490,6 +876,7 @@ Qt::MouseEventFlags QMouseEvent::flags() const
/*!
\fn QPoint QMouseEvent::pos() const
+ \deprecated [6.0] Use position() instead.
Returns the position of the mouse cursor, relative to the widget
that received the event.
@@ -503,6 +890,7 @@ Qt::MouseEventFlags QMouseEvent::flags() const
/*!
\fn QPoint QMouseEvent::globalPos() const
+ \deprecated [6.0] Use globalPosition().toPoint() instead.
Returns the global position of the mouse cursor \e{at the time
of the event}. This is important on asynchronous window systems
@@ -516,6 +904,7 @@ Qt::MouseEventFlags QMouseEvent::flags() const
/*!
\fn int QMouseEvent::x() const
+ \deprecated [6.0] Use position().x() instead.
Returns the x position of the mouse cursor, relative to the
widget that received the event.
@@ -525,6 +914,7 @@ Qt::MouseEventFlags QMouseEvent::flags() const
/*!
\fn int QMouseEvent::y() const
+ \deprecated [6.0] Use position().y() instead.
Returns the y position of the mouse cursor, relative to the
widget that received the event.
@@ -534,6 +924,7 @@ Qt::MouseEventFlags QMouseEvent::flags() const
/*!
\fn int QMouseEvent::globalX() const
+ \deprecated [6.0] Use globalPosition().x() instead.
Returns the global x position of the mouse cursor at the time of
the event.
@@ -543,6 +934,7 @@ Qt::MouseEventFlags QMouseEvent::flags() const
/*!
\fn int QMouseEvent::globalY() const
+ \deprecated [6.0] Use globalPosition().y() instead.
Returns the global y position of the mouse cursor at the time of
the event.
@@ -551,31 +943,6 @@ Qt::MouseEventFlags QMouseEvent::flags() const
*/
/*!
- \fn Qt::MouseButton QMouseEvent::button() const
-
- Returns the button that caused the event.
-
- Note that the returned value is always Qt::NoButton for mouse
- move events.
-
- \sa buttons(), Qt::MouseButton
-*/
-
-/*!
- \fn Qt::MouseButton QMouseEvent::buttons() const
-
- Returns the button state when the event was generated. The button
- state is a combination of Qt::LeftButton, Qt::RightButton,
- Qt::MidButton using the OR operator. For mouse move events,
- this is all buttons that are pressed down. For mouse press and
- double click events this includes the button that caused the
- event. For mouse release events this excludes the button that
- caused the event.
-
- \sa button(), Qt::MouseButton
-*/
-
-/*!
\class QHoverEvent
\ingroup events
\inmodule QtGui
@@ -625,6 +992,7 @@ Qt::MouseEventFlags QMouseEvent::flags() const
/*!
\fn QPoint QHoverEvent::pos() const
+ \deprecated [6.0] Use position().toPoint() instead.
Returns the position of the mouse cursor, relative to the widget
that received the event.
@@ -650,6 +1018,7 @@ Qt::MouseEventFlags QMouseEvent::flags() const
/*!
\fn const QPointF &QHoverEvent::posF() const
+ \deprecated [6.0] Use position() instead.
Returns the position of the mouse cursor, relative to the widget
that received the event.
@@ -674,27 +1043,45 @@ Qt::MouseEventFlags QMouseEvent::flags() const
*/
/*!
- Constructs a hover event object.
+ Constructs a hover event object originating from \a device.
The \a type parameter must be QEvent::HoverEnter,
QEvent::HoverLeave, or QEvent::HoverMove.
- The \a pos is the current mouse cursor's position relative to the
- receiving widget, while \a oldPos is its previous such position.
+ The \a scenePos is the current mouse cursor's position relative to the
+ receiving window or scene, \a oldPos is its previous such position, and
+ \a globalPos is the mouse position in absolute coordinates.
\a modifiers hold the state of all keyboard modifiers at the time
of the event.
*/
-QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers)
- : QInputEvent(type, QPointingDevice::primaryPointingDevice(), modifiers), p(pos), op(oldPos)
+QHoverEvent::QHoverEvent(Type type, const QPointF &scenePos, const QPointF &globalPos, const QPointF &oldPos,
+ Qt::KeyboardModifiers modifiers, const QPointingDevice *device)
+ : QSinglePointEvent(type, device, scenePos, scenePos, globalPos, Qt::NoButton, Qt::NoButton, modifiers), m_oldPos(oldPos)
{
}
+#if QT_DEPRECATED_SINCE(6, 3)
/*!
- \internal
+ \deprecated [6.3] Use the other constructor instead (global position is required).
+
+ Constructs a hover event object originating from \a device.
+
+ The \a type parameter must be QEvent::HoverEnter,
+ QEvent::HoverLeave, or QEvent::HoverMove.
+
+ The \a pos is the current mouse cursor's position relative to the
+ receiving widget, while \a oldPos is its previous such position.
+ \a modifiers hold the state of all keyboard modifiers at the time
+ of the event.
*/
-QHoverEvent::~QHoverEvent()
+QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos,
+ Qt::KeyboardModifiers modifiers, const QPointingDevice *device)
+ : QSinglePointEvent(type, device, pos, pos, pos, Qt::NoButton, Qt::NoButton, modifiers), m_oldPos(oldPos)
{
}
+#endif
+
+Q_IMPL_POINTER_EVENT(QHoverEvent)
#if QT_CONFIG(wheelevent)
/*!
@@ -712,9 +1099,9 @@ QHoverEvent::~QHoverEvent()
degrees. These values are always provided. pixelDelta() returns
the deltas in screen pixels, and is available on platforms that
have high-resolution trackpads, such as \macos. If that is the
- case, source() will return Qt::MouseEventSynthesizedBySystem.
+ case, device()->type() will return QInputDevice::DeviceType::Touchpad.
- The functions pos() and globalPos() return the mouse cursor's
+ The functions position() and globalPosition() return the mouse cursor's
location at the time of the event.
A wheel event contains a special accept flag that indicates
@@ -738,20 +1125,18 @@ QHoverEvent::~QHoverEvent()
*/
/*!
- \fn Qt::MouseButtons QWheelEvent::buttons() const
-
- Returns the mouse state when the event occurred.
-*/
-
-/*!
\fn Qt::MouseEventSource QWheelEvent::source() const
\since 5.5
+ \deprecated [6.0] Use pointingDevice() instead.
Returns information about the wheel event source.
The source can be used to distinguish between events that come from a mouse
with a physical wheel and events that are generated by some other means,
such as a flick gesture on a touchpad.
+ This enum tells you from where it was synthesized; but often
+ it's more useful to know from which device it was synthesized,
+ so try to use pointingDevice() instead.
\note Many platforms provide no such information. On such platforms
\l Qt::MouseEventNotSynthesized is returned always.
@@ -799,36 +1184,54 @@ QHoverEvent::~QHoverEvent()
The mouse and keyboard states at the time of the event are specified by
\a buttons and \a modifiers.
- The scrolling phase of the event is specified by \a phase.
-
- If the wheel event comes from a physical mouse wheel, \a source is set to
- Qt::MouseEventNotSynthesized. If it comes from a gesture detected by the
- operating system, or from a non-mouse hardware device, such that \a
- pixelDelta is directly related to finger movement, \a source is set to
- Qt::MouseEventSynthesizedBySystem. If it comes from Qt, source would be set
- to Qt::MouseEventSynthesizedByQt.
+ The scrolling phase of the event is specified by \a phase, and the
+ \a source indicates whether this is a genuine or artificial (synthesized)
+ event.
If the system is configured to invert the delta values delivered with the
event (such as natural scrolling of the touchpad on macOS), \a inverted
should be \c true. Otherwise, \a inverted is \c false
- \sa position(), globalPosition(), angleDelta(), pixelDelta(), phase(), inverted(), source()
+ The device from which the wheel event originated is specified by \a device.
+
+ \sa position(), globalPosition(), angleDelta(), pixelDelta(), phase(), inverted(), device()
*/
-QWheelEvent::QWheelEvent(QPointF pos, QPointF globalPos, QPoint pixelDelta, QPoint angleDelta,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase,
- bool inverted, Qt::MouseEventSource source)
- : QPointerEvent(Wheel, QPointingDevice::primaryPointingDevice(), modifiers),
- p(pos), g(globalPos), pixelD(pixelDelta), angleD(angleDelta),
- mouseState(buttons), src(source), ph(phase), invertedScrolling(inverted)
+QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta,
+ Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase,
+ bool inverted, Qt::MouseEventSource source, const QPointingDevice *device)
+ : QSinglePointEvent(Wheel, device, pos, pos, globalPos, Qt::NoButton, buttons, modifiers, source),
+ m_pixelDelta(pixelDelta), m_angleDelta(angleDelta)
{
+ m_phase = phase;
+ m_invertedScrolling = inverted;
}
+Q_IMPL_POINTER_EVENT(QWheelEvent)
+
/*!
- \internal
+ Returns \c true if this event's phase() is Qt::ScrollBegin.
*/
-QWheelEvent::~QWheelEvent()
+bool QWheelEvent::isBeginEvent() const
{
+ return m_phase == Qt::ScrollBegin;
}
+
+/*!
+ Returns \c true if this event's phase() is Qt::ScrollUpdate or Qt::ScrollMomentum.
+*/
+bool QWheelEvent::isUpdateEvent() const
+{
+ return m_phase == Qt::ScrollUpdate || m_phase == Qt::ScrollMomentum;
+}
+
+/*!
+ Returns \c true if this event's phase() is Qt::ScrollEnd.
+*/
+bool QWheelEvent::isEndEvent() const
+{
+ return m_phase == Qt::ScrollEnd;
+}
+
#endif // QT_CONFIG(wheelevent)
/*!
@@ -848,7 +1251,7 @@ QWheelEvent::~QWheelEvent()
\li scrolling is about to begin, but the distance did not yet change (Qt::ScrollBegin),
\li or scrolling has ended and the distance did not change anymore (Qt::ScrollEnd).
\endlist
- \note On X11 this value is driver specific and unreliable, use angleDelta() instead
+ \note On X11 this value is driver-specific and unreliable, use angleDelta() instead.
*/
/*!
@@ -890,31 +1293,6 @@ QWheelEvent::~QWheelEvent()
*/
/*!
- \fn QPoint QWheelEvent::position() const
- \since 5.14
-
- Returns the position of the mouse cursor relative to the widget
- or item that received the event.
-
- If you move your widgets around in response to mouse events,
- use globalPosition() instead of this function.
-
- \sa globalPosition()
-*/
-
-/*!
- \fn QPoint QWheelEvent::globalPosition() const
-
- Returns the global position of the mouse pointer \e{at the time
- of the event}. This is important on asynchronous window systems
- such as X11; whenever you move your widgets around in response to
- mouse events, globalPosition() can differ a lot from the current
- cursor position returned by QCursor::pos().
-
- \sa position()
-*/
-
-/*!
\fn Qt::ScrollPhase QWheelEvent::phase() const
\since 5.2
@@ -969,10 +1347,10 @@ QWheelEvent::~QWheelEvent()
in the event.
*/
QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text,
- bool autorep, ushort count)
- : QInputEvent(type, QInputDevice::primaryKeyboard(), modifiers), txt(text), k(key),
- nScanCode(0), nVirtualKey(0), nModifiers(0),
- c(count), autor(autorep)
+ bool autorep, quint16 count)
+ : QInputEvent(type, QInputDevice::primaryKeyboard(), modifiers), m_text(text), m_key(key),
+ m_scanCode(0), m_virtualKey(0), m_nativeModifiers(0),
+ m_count(count), m_autoRepeat(autorep)
{
if (type == QEvent::ShortcutOverride)
ignore();
@@ -998,36 +1376,27 @@ QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const
*/
QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
- const QString &text, bool autorep, ushort count)
- : QInputEvent(type, QInputDevice::primaryKeyboard(), modifiers), txt(text), k(key),
- nScanCode(nativeScanCode), nVirtualKey(nativeVirtualKey), nModifiers(nativeModifiers),
- c(count), autor(autorep)
+ const QString &text, bool autorep, quint16 count, const QInputDevice *device)
+ : QInputEvent(type, device, modifiers), m_text(text), m_key(key),
+ m_scanCode(nativeScanCode), m_virtualKey(nativeVirtualKey), m_nativeModifiers(nativeModifiers),
+ m_count(count), m_autoRepeat(autorep)
{
if (type == QEvent::ShortcutOverride)
ignore();
}
-/*!
- \internal
-*/
-QKeyEvent::~QKeyEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QKeyEvent)
/*!
- \fn quint32 QKeyEvent::nativeScanCode() const
- \since 4.2
-
- Returns the native scan code of the key event. If the key event
- does not contain this data 0 is returned.
+ \fn quint32 QKeyEvent::nativeScanCode() const
+ \since 4.2
- Note: The native scan code may be 0, even if the key event contains
- extended information.
+ Returns the native scan code of the key event. If the key event
+ does not contain this data 0 is returned.
- Note: On \macos, this function is not useful, because there is no
- way to get the scan code from the system APIs. The function always
- returns 1 (or 0 in the case explained above).
+ \note The native scan code may be 0, even if the key event contains
+ extended information.
*/
/*!
@@ -1037,7 +1406,7 @@ QKeyEvent::~QKeyEvent()
Returns the native virtual key, or key sym of the key event.
If the key event does not contain this data 0 is returned.
- Note: The native virtual key may be 0, even if the key event contains extended information.
+ \note The native virtual key may be 0, even if the key event contains extended information.
*/
/*!
@@ -1047,7 +1416,7 @@ QKeyEvent::~QKeyEvent()
Returns the native modifiers of a key event.
If the key event does not contain this data 0 is returned.
- Note: The native modifiers may be 0, even if the key event contains extended information.
+ \note The native modifiers may be 0, even if the key event contains extended information.
*/
/*!
@@ -1074,12 +1443,13 @@ QKeyEvent::~QKeyEvent()
Returns the Unicode text that this key generated.
- Return values when modifier keys such as
- Shift, Control, Alt, and Meta are pressed
- differ among platforms and could return an empty string.
+ The text is not limited to the printable range of Unicode
+ code points, and may include control characters or characters
+ from other Unicode categories, including QChar::Other_PrivateUse.
- \note \l key() will always return a valid value,
- independent of modifier keys.
+ The text may also be empty, for example when modifier keys such as
+ Shift, Control, Alt, and Meta are pressed (depending on the platform).
+ The key() function will always return a valid value.
\sa Qt::WA_KeyCompression
*/
@@ -1110,6 +1480,15 @@ Qt::KeyboardModifiers QKeyEvent::modifiers() const
return QInputEvent::modifiers();
}
+/*!
+ \fn QKeyCombination QKeyEvent::keyCombination() const
+
+ Returns a QKeyCombination object containing both the key() and
+ the modifiers() carried by this event.
+
+ \since 6.0
+*/
+
#if QT_CONFIG(shortcut)
/*!
\fn bool QKeyEvent::matches(QKeySequence::StandardKey key) const
@@ -1182,12 +1561,7 @@ QFocusEvent::QFocusEvent(Type type, Qt::FocusReason reason)
: QEvent(type), m_reason(reason)
{}
-/*!
- \internal
-*/
-QFocusEvent::~QFocusEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QFocusEvent)
/*!
Returns the reason for this focus event.
@@ -1260,12 +1634,7 @@ QPaintEvent::QPaintEvent(const QRect &paintRect)
{}
-/*!
- \internal
-*/
-QPaintEvent::~QPaintEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QPaintEvent)
/*!
\fn const QRect &QPaintEvent::rect() const
@@ -1304,15 +1673,10 @@ QPaintEvent::~QPaintEvent()
\a pos and \a oldPos respectively.
*/
QMoveEvent::QMoveEvent(const QPoint &pos, const QPoint &oldPos)
- : QEvent(Move), p(pos), oldp(oldPos)
+ : QEvent(Move), m_pos(pos), m_oldPos(oldPos)
{}
-/*!
- \internal
-*/
-QMoveEvent::~QMoveEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QMoveEvent)
/*!
\fn const QPoint &QMoveEvent::pos() const
@@ -1335,12 +1699,16 @@ QMoveEvent::~QMoveEvent()
\ingroup events
- Expose events are sent to windows when an area of the window is invalidated,
- for example when window exposure in the windowing system changes.
+ Expose events are sent to windows when they move between the un-exposed and
+ exposed states.
- A Window with a client area that is completely covered by another window, or
- is otherwise not visible may be considered obscured by Qt and may in such
- cases not receive expose events.
+ An exposed window is potentially visible to the user. If the window is moved
+ off screen, is made totally obscured by another window, is minimized, or
+ similar, an expose event is sent to the window, and isExposed() might
+ change to false.
+
+ Expose events should not be used to paint. Handle QPaintEvent
+ instead.
The event handler QWindow::exposeEvent() receives expose events.
*/
@@ -1351,16 +1719,11 @@ QMoveEvent::~QMoveEvent()
*/
QExposeEvent::QExposeEvent(const QRegion &exposeRegion)
: QEvent(Expose)
- , rgn(exposeRegion)
+ , m_region(exposeRegion)
{
}
-/*!
- \internal
-*/
-QExposeEvent::~QExposeEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QExposeEvent)
/*!
\class QPlatformSurfaceEvent
@@ -1404,15 +1767,11 @@ QPlatformSurfaceEvent::QPlatformSurfaceEvent(SurfaceEventType surfaceEventType)
{
}
-/*!
- \internal
-*/
-QPlatformSurfaceEvent::~QPlatformSurfaceEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QPlatformSurfaceEvent)
/*!
\fn const QRegion &QExposeEvent::region() const
+ \deprecated [6.0] Use QPaintEvent instead.
Returns the window area that has been exposed. The region is given in local coordinates.
*/
@@ -1436,15 +1795,10 @@ QPlatformSurfaceEvent::~QPlatformSurfaceEvent()
size and \a oldSize respectively.
*/
QResizeEvent::QResizeEvent(const QSize &size, const QSize &oldSize)
- : QEvent(Resize), s(size), olds(oldSize)
+ : QEvent(Resize), m_size(size), m_oldSize(oldSize)
{}
-/*!
- \internal
-*/
-QResizeEvent::~QResizeEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QResizeEvent)
/*!
\fn const QSize &QResizeEvent::size() const
@@ -1486,10 +1840,6 @@ QResizeEvent::~QResizeEvent()
special handling, you should reimplement the event handler and
ignore() the event.
- The \l{mainwindows/application#close event handler}{closeEvent() in the
- Application example} shows a close event handler that
- asks whether to save a document before closing.
-
If you want the widget to be deleted when it is closed, create it
with the Qt::WA_DeleteOnClose flag. This is very useful for
independent top-level windows in a multi-window application.
@@ -1519,11 +1869,7 @@ QCloseEvent::QCloseEvent()
: QEvent(Close)
{}
-/*! \internal
-*/
-QCloseEvent::~QCloseEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QCloseEvent)
/*!
\class QIconDragEvent
@@ -1552,10 +1898,7 @@ QIconDragEvent::QIconDragEvent()
: QEvent(IconDrag)
{ ignore(); }
-/*! \internal */
-QIconDragEvent::~QIconDragEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QIconDragEvent)
/*!
\class QContextMenuEvent
@@ -1572,11 +1915,6 @@ QIconDragEvent::~QIconDragEvent()
When this event occurs it is customary to show a QMenu with a
context menu, if this is relevant to the context.
-
- Context menu events contain a special accept flag that indicates
- whether the receiver accepted the event. If the event handler does
- not accept the event then, if possible, whatever triggered the event will be
- handled as a regular input event.
*/
#ifndef QT_NO_CONTEXTMENU
@@ -1589,34 +1927,19 @@ QIconDragEvent::~QIconDragEvent()
The \a pos parameter specifies the mouse position relative to the
receiving widget. \a globalPos is the mouse position in absolute
- coordinates.
-*/
-QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos)
- : QContextMenuEvent(reason, pos, globalPos, Qt::NoModifier)
-{}
-
-/*!
- Constructs a context menu event object with the accept parameter
- flag set to false.
-
- The \a reason parameter must be QContextMenuEvent::Mouse or
- QContextMenuEvent::Keyboard.
-
- The \a pos parameter specifies the mouse position relative to the
- receiving widget. \a globalPos is the mouse position in absolute
coordinates. The \a modifiers holds the keyboard modifiers.
*/
QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
Qt::KeyboardModifiers modifiers)
- : QInputEvent(ContextMenu, QPointingDevice::primaryPointingDevice(), modifiers), p(pos), gp(globalPos), reas(reason)
+ : QInputEvent(ContextMenu, QPointingDevice::primaryPointingDevice(), modifiers), m_pos(pos), m_globalPos(globalPos), m_reason(reason)
{}
+Q_IMPL_EVENT_COMMON(QContextMenuEvent)
-/*! \internal */
-QContextMenuEvent::~QContextMenuEvent()
-{
-}
+#if QT_DEPRECATED_SINCE(6, 4)
/*!
+ \deprecated [6.4] Use the other constructor instead (global position is required).
+
Constructs a context menu event object with the accept parameter
flag set to false.
@@ -1631,12 +1954,13 @@ QContextMenuEvent::~QContextMenuEvent()
position explicitly.
*/
QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
- : QInputEvent(ContextMenu, QInputDevice::primaryKeyboard()), p(pos), reas(reason)
+ : QInputEvent(ContextMenu, QInputDevice::primaryKeyboard()), m_pos(pos), m_reason(reason)
{
#ifndef QT_NO_CURSOR
- gp = QCursor::pos();
+ m_globalPos = QCursor::pos();
#endif
}
+#endif
/*!
\fn const QPoint &QContextMenuEvent::pos() const
@@ -1771,7 +2095,7 @@ QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
has to be inserted to the widgets text directly before the preedit
string.
- If the commitString() should replace parts of the of the text in
+ If the commitString() should replace parts of the text in
the editor, replacementLength() will contain the number of
characters to be replaced. replacementStart() contains the position
at which characters are to be replaced relative from the start of
@@ -1907,7 +2231,7 @@ QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
\sa setCommitString()
*/
QInputMethodEvent::QInputMethodEvent()
- : QEvent(QEvent::InputMethod), replace_from(0), replace_length(0)
+ : QEvent(QEvent::InputMethod), m_replacementStart(0), m_replacementLength(0)
{
}
@@ -1922,23 +2246,12 @@ QInputMethodEvent::QInputMethodEvent()
\sa preeditString(), attributes()
*/
QInputMethodEvent::QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes)
- : QEvent(QEvent::InputMethod), preedit(preeditText), attrs(attributes),
- replace_from(0), replace_length(0)
-{
-}
-
-/*!
- Constructs a copy of \a other.
-*/
-QInputMethodEvent::QInputMethodEvent(const QInputMethodEvent &other)
- : QEvent(QEvent::InputMethod), preedit(other.preedit), attrs(other.attrs),
- commit(other.commit), replace_from(other.replace_from), replace_length(other.replace_length)
+ : QEvent(QEvent::InputMethod), m_preedit(preeditText), m_attributes(attributes),
+ m_replacementStart(0), m_replacementLength(0)
{
}
-QInputMethodEvent::~QInputMethodEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QInputMethodEvent)
/*!
Sets the commit string to \a commitString.
@@ -1948,7 +2261,7 @@ QInputMethodEvent::~QInputMethodEvent()
result of the input operations and has to be inserted to the
widgets text directly before the preedit string.
- If the commit string should replace parts of the of the text in
+ If the commit string should replace parts of the text in
the editor, \a replaceLength specifies the number of
characters to be replaced. \a replaceFrom specifies the position
at which characters are to be replaced relative from the start of
@@ -1958,9 +2271,9 @@ QInputMethodEvent::~QInputMethodEvent()
*/
void QInputMethodEvent::setCommitString(const QString &commitString, int replaceFrom, int replaceLength)
{
- commit = commitString;
- replace_from = replaceFrom;
- replace_length = replaceLength;
+ m_commit = commitString;
+ m_replacementStart = replaceFrom;
+ m_replacementLength = replaceLength;
}
/*!
@@ -2045,12 +2358,7 @@ QInputMethodQueryEvent::QInputMethodQueryEvent(Qt::InputMethodQueries queries)
{
}
-/*!
- \internal
- */
-QInputMethodQueryEvent::~QInputMethodQueryEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QInputMethodQueryEvent)
/*!
Sets property \a query to \a value.
@@ -2127,11 +2435,6 @@ QVariant QInputMethodQueryEvent::value(Qt::InputMethodQuery query) const
If the tablet events are rejected, the synthetic mouse events may be
compressed for efficiency.
- New in Qt 5.4: QTabletEvent includes all information available from the
- device, including \l QTabletEvent::buttons(). Previously it was not
- possible to accept all tablet events and also know which stylus buttons
- were pressed.
-
Note that pressing the stylus button while the stylus hovers over the
tablet will generate a button press on some types of tablets, while on
other types it will be necessary to press the stylus against the tablet
@@ -2159,15 +2462,7 @@ QVariant QInputMethodQueryEvent::value(Qt::InputMethodQuery query) const
The \a pos parameter indicates where the event occurred in the widget;
\a globalPos is the corresponding position in absolute coordinates.
- \a pressure gives the pressure exerted on the \a device.
-
- \a deviceType, of type \l QInputDevice::DeviceType,
- indicates the type of stylus or other tool the event comes from.
-
- \a pointerType should be one of QPointingDevice::PointerType::Pen or
- QPointingDevice::PointerType::Eraser, depending on which end of the
- stylus the event comes from; or QPointingDevice::PointerType::Cursor
- if \a deviceType is QInputDevice::DeviceType::Puck.
+ \a pressure gives the pressure exerted on the device \a dev.
\a xTilt and \a yTilt give the device's degree of tilt from the
x and y axes respectively.
@@ -2175,8 +2470,6 @@ QVariant QInputMethodQueryEvent::value(Qt::InputMethodQuery query) const
\a keyState specifies which keyboard modifiers are pressed (e.g.,
\uicontrol{Ctrl}).
- The \a uniqueID parameter gives the serial number of the current tool.
-
The \a z parameter gives the Z coordinate of the device on the tablet;
this is usually given by a wheel on a 4D mouse. If the device does not
support a Z-axis (i.e. \l QPointingDevice::capabilities() does not include
@@ -2201,70 +2494,23 @@ QVariant QInputMethodQueryEvent::value(Qt::InputMethodQuery query) const
\sa pos(), globalPos(), device(), pressure(), xTilt(), yTilt(), uniqueId(), rotation(),
tangentialPressure(), z()
*/
-QTabletEvent::QTabletEvent(Type type, const QPointF &pos, const QPointF &globalPos,
- int deviceType, int pointerType, // TODO use the enums rather than int
- qreal pressure, int xTilt, int yTilt, qreal tangentialPressure,
- qreal rotation, int z, Qt::KeyboardModifiers keyState, qint64 uniqueID,
- Qt::MouseButton button, Qt::MouseButtons buttons)
- : QTabletEvent(type,
- QPointingDevice::tabletDevice(QInputDevice::DeviceType(deviceType),
- QPointingDevice::PointerType(pointerType),
- QPointingDeviceUniqueId::fromNumericId(uniqueID)),
- pos, globalPos, pressure, xTilt, yTilt, tangentialPressure,
- rotation, z, keyState, button, buttons)
-{
- Q_ASSERT(m_dev);
-}
-
QTabletEvent::QTabletEvent(Type type, const QPointingDevice *dev, const QPointF &pos, const QPointF &globalPos,
- qreal pressure, int xTilt, int yTilt,
- qreal tangentialPressure, qreal rotation, int z,
+ qreal pressure, float xTilt, float yTilt,
+ float tangentialPressure, qreal rotation, float z,
Qt::KeyboardModifiers keyState,
Qt::MouseButton button, Qt::MouseButtons buttons)
- : QPointerEvent(type, dev, keyState),
- mPos(pos),
- mGPos(globalPos),
- mXT(xTilt),
- mYT(yTilt),
- mZ(z),
- mPress(pressure),
- mTangential(tangentialPressure),
- mRot(rotation),
- mButton(button),
- mButtons(buttons)
+ : QSinglePointEvent(type, dev, pos, pos, globalPos, button, buttons, keyState),
+ m_tangential(tangentialPressure),
+ m_xTilt(xTilt),
+ m_yTilt(yTilt),
+ m_z(z)
{
+ QEventPoint &p = point(0);
+ QMutableEventPoint::setPressure(p, pressure);
+ QMutableEventPoint::setRotation(p, rotation);
}
-/*!
- \internal
-*/
-QTabletEvent::~QTabletEvent()
-{
-}
-
-/*!
- \fn Qt::MouseButton QTabletEvent::button() const
-
- Returns the button that caused the event.
-
- Note that the returned value is always Qt::NoButton for \l TabletMove,
- \l TabletEnterProximity and \l TabletLeaveProximity events.
-
- \sa buttons(), Qt::MouseButton
-*/
-
-/*!
- \fn Qt::MouseButtons QTabletEvent::buttons() const
-
- Returns the button state when the event was generated. The button state is
- a combination of buttons from the \l Qt::MouseButton enum using the OR
- operator. For \l TabletMove events, this is all buttons that are pressed
- down. For \l TabletPress events this includes the button that caused the
- event. For \l TabletRelease events this excludes the button that caused the
- event.
-
- \sa button(), Qt::MouseButton
-*/
+Q_IMPL_POINTER_EVENT(QTabletEvent)
/*!
\fn qreal QTabletEvent::tangentialPressure() const
@@ -2275,6 +2521,8 @@ QTabletEvent::~QTabletEvent()
direction from the neutrual position. If the device does not support
tangential pressure, this value is always 0.0.
+ \note The value is stored as a single-precision float.
+
\sa pressure()
*/
@@ -2299,7 +2547,7 @@ QTabletEvent::~QTabletEvent()
*/
/*!
- \fn int QTabletEvent::xTilt() const
+ \fn qreal QTabletEvent::xTilt() const
Returns the angle between the device (a pen, for example) and the
perpendicular in the direction of the x axis.
@@ -2308,22 +2556,27 @@ QTabletEvent::~QTabletEvent()
\image qtabletevent-tilt.png
+ \note The value is stored as a single-precision float.
+
\sa yTilt()
*/
/*!
- \fn int QTabletEvent::yTilt() const
+ \fn qreal QTabletEvent::yTilt() const
Returns the angle between the device (a pen, for example) and the
perpendicular in the direction of the y axis.
Positive values are towards the bottom of the tablet. The angle is
within the range -60 to +60 degrees.
+ \note The value is stored as a single-precision float.
+
\sa xTilt()
*/
/*!
\fn QPoint QTabletEvent::pos() const
+ \deprecated [6.0] Use position().toPoint() instead.
Returns the position of the device, relative to the widget that
received the event.
@@ -2336,6 +2589,7 @@ QTabletEvent::~QTabletEvent()
/*!
\fn int QTabletEvent::x() const
+ \deprecated [6.0] Use position().x() instead.
Returns the x position of the device, relative to the widget that
received the event.
@@ -2345,6 +2599,7 @@ QTabletEvent::~QTabletEvent()
/*!
\fn int QTabletEvent::y() const
+ \deprecated [6.0] Use position().y() instead.
Returns the y position of the device, relative to the widget that
received the event.
@@ -2353,17 +2608,20 @@ QTabletEvent::~QTabletEvent()
*/
/*!
- \fn int QTabletEvent::z() const
+ \fn qreal QTabletEvent::z() const
Returns the z position of the device. Typically this is represented by a
wheel on a 4D Mouse. If the device does not support a Z-axis, this value is
always zero. This is \b not the same as pressure.
+ \note The value is stored as a single-precision float.
+
\sa pressure()
*/
/*!
\fn QPoint QTabletEvent::globalPos() const
+ \deprecated [6.0] Use globalPosition().toPoint() instead.
Returns the global position of the device \e{at the time of the
event}. This is important on asynchronous windows systems like X11;
@@ -2376,6 +2634,7 @@ QTabletEvent::~QTabletEvent()
/*!
\fn int QTabletEvent::globalX() const
+ \deprecated [6.0] Use globalPosition().x() instead.
Returns the global x position of the mouse pointer at the time of
the event.
@@ -2385,6 +2644,7 @@ QTabletEvent::~QTabletEvent()
/*!
\fn int QTabletEvent::globalY() const
+ \deprecated [6.0] Use globalPosition().y() instead.
Returns the global y position of the tablet device at the time of
the event.
@@ -2394,6 +2654,7 @@ QTabletEvent::~QTabletEvent()
/*!
\fn qint64 QTabletEvent::uniqueId() const
+ \deprecated [6.0] Use pointingDevice().uniqueId() instead.
Returns a unique ID for the current device, making it possible
to differentiate between multiple devices being used at the same
@@ -2417,6 +2678,7 @@ QTabletEvent::~QTabletEvent()
/*!
\fn const QPointF &QTabletEvent::posF() const
+ \deprecated [6.0] Use position() instead.
Returns the position of the device, relative to the widget that
received the event.
@@ -2429,7 +2691,7 @@ QTabletEvent::~QTabletEvent()
/*!
\fn const QPointF &QTabletEvent::globalPosF() const
-
+ \deprecated [6.0] Use globalPosition() instead.
Returns the global position of the device \e{at the time of the
event}. This is important on asynchronous windows systems like X11;
whenever you move your widgets around in response to mouse events,
@@ -2450,8 +2712,10 @@ QTabletEvent::~QTabletEvent()
\ingroup events
Native gesture events are generated by the operating system, typically by
- interpreting touch events. Gesture events are high-level events such
- as zoom or rotate.
+ interpreting trackpad touch events. Gesture events are high-level events
+ such as zoom, rotate or pan. Several types hold incremental values: that is,
+ value() and delta() provide the difference from the previous event to the
+ current event.
\table
\header
@@ -2461,7 +2725,7 @@ QTabletEvent::~QTabletEvent()
\row
\li Qt::ZoomNativeGesture
\li Magnification delta in percent.
- \li \macos: Two-finger pinch.
+ \li \macos and Wayland: Two-finger pinch.
\row
\li Qt::SmartZoomNativeGesture
\li Boolean magnification state.
@@ -2469,10 +2733,17 @@ QTabletEvent::~QTabletEvent()
\row
\li Qt::RotateNativeGesture
\li Rotation delta in degrees.
- \li \macos: Two-finger rotate.
+ \li \macos and Wayland: Two-finger rotate.
+ \row
+ \li Qt::SwipeNativeGesture
+ \li Swipe angle in degrees.
+ \li \macos: Configurable in trackpad settings.
+ \row
+ \li Qt::PanNativeGesture
+ \li Displacement delta in pixels.
+ \li Wayland: Three or more fingers moving as a group, in any direction.
\endtable
-
In addition, BeginNativeGesture and EndNativeGesture are sent before and after
gesture event streams:
@@ -2482,10 +2753,26 @@ QTabletEvent::~QTabletEvent()
ZoomNativeGesture
EndNativeGesture
- \sa Qt::NativeGestureType, QGestureEvent
+ The event stream may include interleaved gestures of different types:
+ for example the two-finger pinch gesture generates a stream of Zoom and
+ Rotate events, and PanNativeGesture may sometimes be interleaved with
+ those, depending on the platform.
+
+ Other types are standalone events: SmartZoomNativeGesture and
+ SwipeNativeGesture occur only once each time the gesture is detected.
+
+ \note On a touchpad, moving two fingers as a group (the two-finger flick gesture)
+ is usually reserved for scrolling; in that case, Qt generates QWheelEvents.
+ This is the reason that three or more fingers are needed to generate a
+ PanNativeGesture.
+
+ \sa Qt::NativeGestureType, QGestureEvent, QWheelEvent
*/
+#if QT_DEPRECATED_SINCE(6, 2)
/*!
+ \deprecated [6.2] Use the other constructor, because \a intValue is no longer stored separately.
+
Constructs a native gesture event of type \a type originating from \a device.
The points \a localPos, \a scenePos and \a globalPos specify the
@@ -2494,25 +2781,60 @@ QTabletEvent::~QTabletEvent()
\a realValue is the \macos event parameter, \a sequenceId and \a intValue are the Windows event parameters.
\since 5.10
+
+ \note It's not possible to store realValue and \a intValue simultaneously:
+ one or the other must be zero. If \a realValue == 0 and \a intValue != 0,
+ it is stored in the same variable, such that value() returns the value
+ given as \a intValue.
*/
QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *device,
- const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
- qreal realValue, ulong sequenceId, quint64 intValue)
- : QPointerEvent(QEvent::NativeGesture, device), mGestureType(type),
- mLocalPos(localPos), mScenePos(scenePos), mGlobalPos(globalPos), mRealValue(realValue),
- mSequenceId(sequenceId), mIntValue(intValue)
+ const QPointF &localPos, const QPointF &scenePos,
+ const QPointF &globalPos, qreal realValue, quint64 sequenceId,
+ quint64 intValue)
+ : QSinglePointEvent(QEvent::NativeGesture, device, localPos, scenePos, globalPos, Qt::NoButton,
+ Qt::NoButton, Qt::NoModifier),
+ m_sequenceId(sequenceId), m_realValue(realValue), m_gestureType(type)
{
+ if (qIsNull(realValue) && intValue != 0)
+ m_realValue = intValue;
}
-
-QNativeGestureEvent::~QNativeGestureEvent()
- = default;
+#endif // deprecated
/*!
- \fn const QPointingDevice *QNativeGestureEvent::device() const
- \since 5.10
+ Constructs a native gesture event of type \a type originating from \a device
+ describing a gesture at \a scenePos in which \a fingerCount fingers are involved.
+
+ The points \a localPos, \a scenePos and \a globalPos specify the gesture
+ position relative to the receiving widget or item, window, and screen or
+ desktop, respectively.
- Returns the device.
+ \a value has a gesture-dependent interpretation: for RotateNativeGesture or
+ SwipeNativeGesture, it's an angle in degrees. For ZoomNativeGesture,
+ \a value is an incremental scaling factor, usually much less than 1,
+ indicating that the target item should have its scale adjusted like this:
+ item.scale = item.scale * (1 + event.value)
+
+ For PanNativeGesture, \a delta gives the distance in pixels that the
+ viewport, widget or item should be moved or panned.
+
+ \note The \a delta is stored in single precision (QVector2D), so \l delta()
+ may return slightly different values in some cases. This is subject to change
+ in future versions of Qt.
+
+ \since 6.2
*/
+QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *device, int fingerCount,
+ const QPointF &localPos, const QPointF &scenePos,
+ const QPointF &globalPos, qreal value, const QPointF &delta,
+ quint64 sequenceId)
+ : QSinglePointEvent(QEvent::NativeGesture, device, localPos, scenePos, globalPos, Qt::NoButton,
+ Qt::NoButton, Qt::NoModifier),
+ m_sequenceId(sequenceId), m_delta(delta), m_realValue(value), m_gestureType(type), m_fingerCount(fingerCount)
+{
+ Q_ASSERT(fingerCount < 16); // we store it in 4 bits unsigned
+}
+
+Q_IMPL_POINTER_EVENT(QNativeGestureEvent)
/*!
\fn QNativeGestureEvent::gestureType() const
@@ -2522,19 +2844,40 @@ QNativeGestureEvent::~QNativeGestureEvent()
*/
/*!
+ \fn QNativeGestureEvent::fingerCount() const
+ \since 6.2
+
+ Returns the number of fingers participating in the gesture, if known.
+ When gestureType() is Qt::BeginNativeGesture or Qt::EndNativeGesture, often
+ this information is unknown, and fingerCount() returns \c 0.
+*/
+
+/*!
\fn QNativeGestureEvent::value() const
\since 5.2
Returns the gesture value. The value should be interpreted based on the
- gesture type. For example, a Zoom gesture provides a scale factor while a Rotate
+ gesture type. For example, a Zoom gesture provides a scale factor delta while a Rotate
gesture provides a rotation delta.
\sa QNativeGestureEvent, gestureType()
*/
/*!
+ \fn QNativeGestureEvent::delta() const
+ \since 6.2
+
+ Returns the distance moved since the previous event, in pixels.
+ A Pan gesture provides the distance in pixels by which the target widget,
+ item or viewport contents should be moved.
+
+ \sa QPanGesture::delta()
+*/
+
+/*!
\fn QPoint QNativeGestureEvent::globalPos() const
\since 5.2
+ \deprecated [6.0] Use globalPosition().toPoint() instead.
Returns the position of the gesture as a QPointF in screen coordinates
*/
@@ -2542,6 +2885,7 @@ QNativeGestureEvent::~QNativeGestureEvent()
/*!
\fn QPoint QNativeGestureEvent::pos() const
\since 5.2
+ \deprecated [6.0] Use position().toPoint() instead.
Returns the position of the mouse cursor, relative to the widget
or item that received the event.
@@ -2550,6 +2894,7 @@ QNativeGestureEvent::~QNativeGestureEvent()
/*!
\fn QPointF QNativeGestureEvent::localPos() const
\since 5.2
+ \deprecated [6.0] Use position() instead.
Returns the position of the gesture as a QPointF, relative to the
widget or item that received the event.
@@ -2558,6 +2903,7 @@ QNativeGestureEvent::~QNativeGestureEvent()
/*!
\fn QPointF QNativeGestureEvent::screenPos() const
\since 5.2
+ \deprecated [6.0] Use globalPosition() instead.
Returns the position of the gesture as a QPointF in screen coordinates.
*/
@@ -2565,6 +2911,7 @@ QNativeGestureEvent::~QNativeGestureEvent()
/*!
\fn QPointF QNativeGestureEvent::windowPos() const
\since 5.2
+ \deprecated [6.0] Use scenePosition() instead.
Returns the position of the gesture as a QPointF, relative to the
window that received the event.
@@ -2587,15 +2934,10 @@ QNativeGestureEvent::~QNativeGestureEvent()
QDragMoveEvent::QDragMoveEvent(const QPoint& pos, Qt::DropActions actions, const QMimeData *data,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
: QDropEvent(pos, actions, data, buttons, modifiers, type)
- , rect(pos, QSize(1, 1))
+ , m_rect(pos, QSize(1, 1))
{}
-/*!
- Destroys the event.
-*/
-QDragMoveEvent::~QDragMoveEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QDragMoveEvent)
/*!
\fn void QDragMoveEvent::accept(const QRect &rectangle)
@@ -2699,19 +3041,16 @@ QDragMoveEvent::~QDragMoveEvent()
*/
QDropEvent::QDropEvent(const QPointF& pos, Qt::DropActions actions, const QMimeData *data,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
- : QEvent(type), p(pos), mouseState(buttons),
- modState(modifiers), act(actions),
- mdata(data)
+ : QEvent(type), m_pos(pos), m_mouseState(buttons),
+ m_modState(modifiers), m_actions(actions),
+ m_data(data)
{
- default_action = QGuiApplicationPrivate::platformIntegration()->drag()->defaultAction(act, modifiers);
- drop_action = default_action;
+ m_defaultAction = m_dropAction =
+ QGuiApplicationPrivate::platformIntegration()->drag()->defaultAction(m_actions, modifiers);
ignore();
}
-/*! \internal */
-QDropEvent::~QDropEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QDropEvent)
/*!
@@ -2735,31 +3074,56 @@ QObject* QDropEvent::source() const
void QDropEvent::setDropAction(Qt::DropAction action)
{
- if (!(action & act) && action != Qt::IgnoreAction)
- action = default_action;
- drop_action = action;
+ if (!(action & m_actions) && action != Qt::IgnoreAction)
+ action = m_defaultAction;
+ m_dropAction = action;
}
/*!
\fn QPoint QDropEvent::pos() const
+ \deprecated [6.0] Use position().toPoint() instead.
Returns the position where the drop was made.
*/
/*!
\fn const QPointF& QDropEvent::posF() const
+ \deprecated [6.0] Use position() instead.
+
+ Returns the position where the drop was made.
+*/
+
+/*!
+ \fn QPointF QDropEvent::position() const
+ \since 6.0
Returns the position where the drop was made.
*/
/*!
\fn Qt::MouseButtons QDropEvent::mouseButtons() const
+ \deprecated [6.0] Use buttons() instead.
- Returns the mouse buttons that are pressed..
+ Returns the mouse buttons that are pressed.
+*/
+
+/*!
+ \fn Qt::MouseButtons QDropEvent::buttons() const
+ \since 6.0
+
+ Returns the mouse buttons that are pressed.
*/
/*!
\fn Qt::KeyboardModifiers QDropEvent::keyboardModifiers() const
+ \deprecated [6.0] Use modifiers() instead.
+
+ Returns the modifier keys that are pressed.
+*/
+
+/*!
+ \fn Qt::KeyboardModifiers QDropEvent::modifiers() const
+ \since 6.0
Returns the modifier keys that are pressed.
*/
@@ -2852,11 +3216,7 @@ QDragEnterEvent::QDragEnterEvent(const QPoint& point, Qt::DropActions actions, c
: QDragMoveEvent(point, actions, data, buttons, modifiers, DragEnter)
{}
-/*! \internal
-*/
-QDragEnterEvent::~QDragEnterEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QDragEnterEvent)
/*!
\class QDragMoveEvent
@@ -2910,11 +3270,8 @@ QDragLeaveEvent::QDragLeaveEvent()
: QEvent(DragLeave)
{}
-/*! \internal
-*/
-QDragLeaveEvent::~QDragLeaveEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QDragLeaveEvent)
+
#endif // QT_CONFIG(draganddrop)
/*!
@@ -2943,7 +3300,7 @@ QDragLeaveEvent::~QDragLeaveEvent()
\sa pos(), globalPos()
*/
QHelpEvent::QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos)
- : QEvent(type), p(pos), gp(globalPos)
+ : QEvent(type), m_pos(pos), m_globalPos(globalPos)
{}
/*!
@@ -2996,11 +3353,7 @@ QHelpEvent::QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos)
\sa pos(), globalX(), globalY()
*/
-/*! \internal
-*/
-QHelpEvent::~QHelpEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QHelpEvent)
#ifndef QT_NO_STATUSTIP
@@ -3052,14 +3405,10 @@ QHelpEvent::~QHelpEvent()
\sa tip()
*/
QStatusTipEvent::QStatusTipEvent(const QString &tip)
- : QEvent(StatusTip), s(tip)
+ : QEvent(StatusTip), m_tip(tip)
{}
-/*! \internal
-*/
-QStatusTipEvent::~QStatusTipEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QStatusTipEvent)
/*!
\fn QString QStatusTipEvent::tip() const
@@ -3092,14 +3441,10 @@ QStatusTipEvent::~QStatusTipEvent()
\sa href()
*/
QWhatsThisClickedEvent::QWhatsThisClickedEvent(const QString &href)
- : QEvent(WhatsThisClicked), s(href)
+ : QEvent(WhatsThisClicked), m_href(href)
{}
-/*! \internal
-*/
-QWhatsThisClickedEvent::~QWhatsThisClickedEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QWhatsThisClickedEvent)
/*!
\fn QString QWhatsThisClickedEvent::href() const
@@ -3138,14 +3483,10 @@ QWhatsThisClickedEvent::~QWhatsThisClickedEvent()
action \a before. If \a before is \nullptr, the action is appended.
*/
QActionEvent::QActionEvent(int type, QAction *action, QAction *before)
- : QEvent(static_cast<QEvent::Type>(type)), act(action), bef(before)
+ : QEvent(static_cast<QEvent::Type>(type)), m_action(action), m_before(before)
{}
-/*! \internal
-*/
-QActionEvent::~QActionEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QActionEvent)
/*!
\fn QAction *QActionEvent::action() const
@@ -3195,11 +3536,7 @@ QHideEvent::QHideEvent()
: QEvent(Hide)
{}
-/*! \internal
-*/
-QHideEvent::~QHideEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QHideEvent)
/*!
\class QShowEvent
@@ -3225,11 +3562,7 @@ QShowEvent::QShowEvent()
: QEvent(Show)
{}
-/*! \internal
-*/
-QShowEvent::~QShowEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QShowEvent)
/*!
\class QFileOpenEvent
@@ -3260,10 +3593,15 @@ QShowEvent::~QShowEvent()
\snippet qfileopenevent/Info.plist Custom Info.plist
- The following implementation of a QApplication subclass prints the path to
- the file that was, for example, dropped on the Dock icon of the application.
+ The following implementation of a QApplication subclass shows how to handle
+ QFileOpenEvent to open the file that was, for example, dropped on the Dock
+ icon of the application.
\snippet qfileopenevent/main.cpp QApplication subclass
+
+ Note how \c{QFileOpenEvent::file()} is not guaranteed to be the name of a
+ local file that can be opened using QFile. The contents of the string depend
+ on the source application.
*/
/*!
@@ -3272,7 +3610,7 @@ QShowEvent::~QShowEvent()
Constructs a file open event for the given \a file.
*/
QFileOpenEvent::QFileOpenEvent(const QString &file)
- : QEvent(FileOpen), f(file), m_url(QUrl::fromLocalFile(file))
+ : QEvent(FileOpen), m_file(file), m_url(QUrl::fromLocalFile(file))
{
}
@@ -3282,33 +3620,32 @@ QFileOpenEvent::QFileOpenEvent(const QString &file)
Constructs a file open event for the given \a url.
*/
QFileOpenEvent::QFileOpenEvent(const QUrl &url)
- : QEvent(FileOpen), f(url.toLocalFile()), m_url(url)
+ : QEvent(FileOpen), m_file(url.toLocalFile()), m_url(url)
{
}
-
-/*! \internal
-*/
-QFileOpenEvent::~QFileOpenEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QFileOpenEvent)
/*!
\fn QString QFileOpenEvent::file() const
- Returns the file that is being opened.
+ Returns the name of the file that the application should open.
+
+ This is not guaranteed to be the path to a local file.
*/
/*!
\fn QUrl QFileOpenEvent::url() const
- Returns the url that is being opened.
+ Returns the url that the application should open.
\since 4.6
*/
+#if QT_DEPRECATED_SINCE(6, 6)
/*!
\fn bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
+ \deprecated [6.6] interpret the string returned by file()
Opens a QFile on the \a file referenced by this event in the mode specified
by \a flags. Returns \c true if successful; otherwise returns \c false.
@@ -3320,9 +3657,10 @@ QFileOpenEvent::~QFileOpenEvent()
*/
bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
{
- file.setFileName(f);
+ file.setFileName(m_file);
return file.open(flags);
}
+#endif
#ifndef QT_NO_TOOLBAR
/*!
@@ -3346,14 +3684,10 @@ bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
Construct a QToolBarChangeEvent given the current button state in \a state.
*/
QToolBarChangeEvent::QToolBarChangeEvent(bool t)
- : QEvent(ToolBarChange), tog(t)
+ : QEvent(ToolBarChange), m_toggle(t)
{}
-/*! \internal
-*/
-QToolBarChangeEvent::~QToolBarChangeEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QToolBarChangeEvent)
/*!
\fn bool QToolBarChangeEvent::toggle() const
@@ -3378,21 +3712,40 @@ QToolBarChangeEvent::~QToolBarChangeEvent()
Constructs a shortcut event for the given \a key press,
associated with the QShortcut ID \a id.
+ \deprecated use the other constructor
+
\a ambiguous specifies whether there is more than one QShortcut
for the same key sequence.
*/
QShortcutEvent::QShortcutEvent(const QKeySequence &key, int id, bool ambiguous)
- : QEvent(Shortcut), sequence(key), ambig(ambiguous), sid(id)
+ : QEvent(Shortcut), m_sequence(key), m_shortcutId(id), m_ambiguous(ambiguous)
{
}
/*!
- Destroys the event object.
+ Constructs a shortcut event for the given \a key press,
+ associated with the QShortcut \a shortcut.
+ \since 6.5
+
+ \a ambiguous specifies whether there is more than one QShortcut
+ for the same key sequence.
*/
-QShortcutEvent::~QShortcutEvent()
+QShortcutEvent::QShortcutEvent(const QKeySequence &key, const QShortcut *shortcut, bool ambiguous)
+ : QEvent(Shortcut), m_sequence(key), m_shortcutId(0), m_ambiguous(ambiguous)
{
+ if (shortcut) {
+ auto priv = static_cast<const QShortcutPrivate *>(QShortcutPrivate::get(shortcut));
+ auto index = priv->sc_sequences.indexOf(key);
+ if (index < 0) {
+ qWarning() << "Given QShortcut does not contain key-sequence " << key;
+ return;
+ }
+ m_shortcutId = priv->sc_ids[index];
+ }
}
+Q_IMPL_EVENT_COMMON(QShortcutEvent)
+
#endif // QT_CONFIG(shortcut)
#ifndef QT_NO_DEBUG_STREAM
@@ -3404,7 +3757,7 @@ static inline void formatTouchEvent(QDebug d, const QTouchEvent &t)
d << " device: " << t.device()->name();
d << " states: ";
QtDebugUtils::formatQFlags(d, t.touchPointStates());
- d << ", " << t.touchPoints().size() << " points: " << t.touchPoints() << ')';
+ d << ", " << t.points().size() << " points: " << t.points() << ')';
}
static void formatUnicodeString(QDebug d, const QString &s)
@@ -3418,6 +3771,13 @@ static void formatUnicodeString(QDebug d, const QString &s)
d << Qt::dec << '"';
}
+static QDebug operator<<(QDebug dbg, const QInputMethodEvent::Attribute &attr)
+{
+ dbg << "[type= " << attr.type << ", start=" << attr.start << ", length=" << attr.length
+ << ", value=" << attr.value << ']';
+ return dbg;
+}
+
static inline void formatInputMethodEvent(QDebug d, const QInputMethodEvent *e)
{
d << "QInputMethodEvent(";
@@ -3433,15 +3793,15 @@ static inline void formatInputMethodEvent(QDebug d, const QInputMethodEvent *e)
d << ", replacementStart=" << e->replacementStart() << ", replacementLength="
<< e->replacementLength();
}
- if (const int attributeCount = e->attributes().size()) {
+ const auto attributes = e->attributes();
+ auto it = attributes.cbegin();
+ const auto end = attributes.cend();
+ if (it != end) {
d << ", attributes= {";
- for (int a = 0; a < attributeCount; ++a) {
- const QInputMethodEvent::Attribute &at = e->attributes().at(a);
- if (a)
- d << ',';
- d << "[type= " << at.type << ", start=" << at.start << ", length=" << at.length
- << ", value=" << at.value << ']';
- }
+ d << *it;
+ ++it;
+ for (; it != end; ++it)
+ d << ',' << *it;
d << '}';
}
d << ')';
@@ -3621,45 +3981,61 @@ static void formatTabletEvent(QDebug d, const QTabletEvent *e)
d << eventClassName(type) << '(';
QtDebugUtils::formatQEnum(d, type);
- d << ", deviceType=";
- QtDebugUtils::formatQEnum(d, e->deviceType());
- d << ", pointerType=";
- QtDebugUtils::formatQEnum(d, e->pointerType());
- d << ", uniqueId=" << e->uniqueId()
- << ", pos=" << e->position()
- << ", z=" << e->z()
- << ", xTilt=" << e->xTilt()
- << ", yTilt=" << e->yTilt()
- << ", ";
+ d << ' ';
QtDebugUtils::formatQFlags(d, e->buttons());
+ d << " pos=";
+ QtDebugUtils::formatQPoint(d, e->position());
+ d << " z=" << e->z()
+ << " xTilt=" << e->xTilt()
+ << " yTilt=" << e->yTilt();
if (type == QEvent::TabletPress || type == QEvent::TabletMove)
- d << ", pressure=" << e->pressure();
+ d << " pressure=" << e->pressure();
if (e->device()->hasCapability(QInputDevice::Capability::Rotation))
- d << ", rotation=" << e->rotation();
+ d << " rotation=" << e->rotation();
if (e->deviceType() == QInputDevice::DeviceType::Airbrush)
- d << ", tangentialPressure=" << e->tangentialPressure();
+ d << " tangentialPressure=" << e->tangentialPressure();
+ d << " dev=" << e->device() << ')';
}
# endif // QT_CONFIG(tabletevent)
-QDebug operator<<(QDebug dbg, const QTouchEvent::TouchPoint &tp)
+QDebug operator<<(QDebug dbg, const QEventPoint *tp)
+{
+ if (!tp) {
+ dbg << "QEventPoint(0x0)";
+ return dbg;
+ }
+ return operator<<(dbg, *tp);
+}
+
+QDebug operator<<(QDebug dbg, const QEventPoint &tp)
{
QDebugStateSaver saver(dbg);
dbg.nospace();
- dbg << "TouchPoint(" << Qt::hex << tp.id() << Qt::dec << " (";
+ dbg << "QEventPoint(id=" << tp.id() << " ts=" << tp.timestamp();
+ dbg << " pos=";
QtDebugUtils::formatQPoint(dbg, tp.position());
- dbg << ") ";
+ dbg << " scn=";
+ QtDebugUtils::formatQPoint(dbg, tp.scenePosition());
+ dbg << " gbl=";
+ QtDebugUtils::formatQPoint(dbg, tp.globalPosition());
+ dbg << ' ';
QtDebugUtils::formatQEnum(dbg, tp.state());
- dbg << " pressure " << tp.pressure() << " ellipse ("
- << tp.ellipseDiameters().width() << " x " << tp.ellipseDiameters().height()
- << " angle " << tp.rotation() << ") vel (";
+ if (!qFuzzyIsNull(tp.pressure()) && !qFuzzyCompare(tp.pressure(), 1))
+ dbg << " pressure=" << tp.pressure();
+ if (!tp.ellipseDiameters().isEmpty() || !qFuzzyIsNull(tp.rotation())) {
+ dbg << " ellipse=("
+ << tp.ellipseDiameters().width() << "x" << tp.ellipseDiameters().height()
+ << " \u2221 " << tp.rotation() << ')';
+ }
+ dbg << " vel=";
QtDebugUtils::formatQPoint(dbg, tp.velocity().toPointF());
- dbg << ") start (";
+ dbg << " press=";
QtDebugUtils::formatQPoint(dbg, tp.pressPosition());
- dbg << ") last (";
- QtDebugUtils::formatQPoint(dbg, tp.lastPos());
- dbg << ") delta (";
- QtDebugUtils::formatQPoint(dbg, tp.position() - tp.lastPos());
+ dbg << " last=";
+ QtDebugUtils::formatQPoint(dbg, tp.lastPosition());
+ dbg << " \u0394 ";
+ QtDebugUtils::formatQPoint(dbg, tp.position() - tp.lastPosition());
dbg << ')';
return dbg;
}
@@ -3674,9 +4050,10 @@ QDebug operator<<(QDebug dbg, const QEvent *e)
}
// More useful event output could be added here
const QEvent::Type type = e->type();
+ bool isMouse = false;
switch (type) {
case QEvent::Expose:
- dbg << "QExposeEvent(" << static_cast<const QExposeEvent *>(e)->region() << ')';
+ dbg << "QExposeEvent()";
break;
case QEvent::Paint:
dbg << "QPaintEvent(" << static_cast<const QPaintEvent *>(e)->region() << ')';
@@ -3689,28 +4066,42 @@ QDebug operator<<(QDebug dbg, const QEvent *e)
case QEvent::NonClientAreaMouseMove:
case QEvent::NonClientAreaMouseButtonRelease:
case QEvent::NonClientAreaMouseButtonDblClick:
+ isMouse = true;
+ Q_FALLTHROUGH();
+ case QEvent::HoverEnter:
+ case QEvent::HoverMove:
+ case QEvent::HoverLeave:
{
- const QMouseEvent *me = static_cast<const QMouseEvent*>(e);
- const Qt::MouseButton button = me->button();
- const Qt::MouseButtons buttons = me->buttons();
- dbg << "QMouseEvent(";
+ const QSinglePointEvent *spe = static_cast<const QSinglePointEvent*>(e);
+ const Qt::MouseButton button = spe->button();
+ const Qt::MouseButtons buttons = spe->buttons();
+ dbg << eventClassName(type) << '(';
QtDebugUtils::formatQEnum(dbg, type);
- if (type != QEvent::MouseMove && type != QEvent::NonClientAreaMouseMove) {
- dbg << ", ";
- QtDebugUtils::formatQEnum(dbg, button);
+ if (isMouse) {
+ if (type != QEvent::MouseMove && type != QEvent::NonClientAreaMouseMove) {
+ dbg << ' ';
+ QtDebugUtils::formatQEnum(dbg, button);
+ }
+ if (buttons && button != buttons) {
+ dbg << " btns=";
+ QtDebugUtils::formatQFlags(dbg, buttons);
+ }
}
- if (buttons && button != buttons) {
- dbg << ", buttons=";
- QtDebugUtils::formatQFlags(dbg, buttons);
+ QtDebugUtils::formatNonNullQFlags(dbg, ", ", spe->modifiers());
+ dbg << " pos=";
+ QtDebugUtils::formatQPoint(dbg, spe->position());
+ dbg << " scn=";
+ QtDebugUtils::formatQPoint(dbg, spe->scenePosition());
+ dbg << " gbl=";
+ QtDebugUtils::formatQPoint(dbg, spe->globalPosition());
+ dbg << " dev=" << spe->device() << ')';
+ if (isMouse) {
+ auto src = static_cast<const QMouseEvent*>(e)->source();
+ if (src != Qt::MouseEventNotSynthesized) {
+ dbg << " source=";
+ QtDebugUtils::formatQEnum(dbg, src);
+ }
}
- QtDebugUtils::formatNonNullQFlags(dbg, ", ", me->modifiers());
- dbg << ", localPos=";
- QtDebugUtils::formatQPoint(dbg, me->position());
- dbg << ", screenPos=";
- QtDebugUtils::formatQPoint(dbg, me->globalPosition());
- QtDebugUtils::formatNonNullQEnum(dbg, ", ", me->source());
- QtDebugUtils::formatNonNullQFlags(dbg, ", flags=", me->flags());
- dbg << ')';
}
break;
# if QT_CONFIG(wheelevent)
@@ -3737,6 +4128,10 @@ QDebug operator<<(QDebug dbg, const QEvent *e)
dbg << ", text=" << ke->text();
if (ke->isAutoRepeat())
dbg << ", autorepeat, count=" << ke->count();
+ if (dbg.verbosity() > QDebug::DefaultVerbosity) {
+ dbg << ", nativeScanCode=" << ke->nativeScanCode();
+ dbg << ", nativeVirtualKey=" << ke->nativeVirtualKey();
+ }
dbg << ')';
}
break;
@@ -3807,9 +4202,15 @@ QDebug operator<<(QDebug dbg, const QEvent *e)
const QNativeGestureEvent *ne = static_cast<const QNativeGestureEvent *>(e);
dbg << "QNativeGestureEvent(";
QtDebugUtils::formatQEnum(dbg, ne->gestureType());
- dbg << ", localPos=";
+ dbg << ", fingerCount=" << ne->fingerCount() << ", localPos=";
QtDebugUtils::formatQPoint(dbg, ne->position());
- dbg << ", value=" << ne->value() << ')';
+ if (!qIsNull(ne->value()))
+ dbg << ", value=" << ne->value();
+ if (!ne->delta().isNull()) {
+ dbg << ", delta=";
+ QtDebugUtils::formatQPoint(dbg, ne->delta());
+ }
+ dbg << ')';
}
break;
# endif // !QT_NO_GESTURES
@@ -3897,6 +4298,8 @@ QDebug operator<<(QDebug dbg, const QEvent *e)
/*!
\fn int QShortcutEvent::shortcutId() const
+ \deprecated
+
Returns the ID of the QShortcut object for which this event was
generated.
@@ -3928,8 +4331,8 @@ QDebug operator<<(QDebug dbg, const QEvent *e)
/*! \internal
*/
-QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates s, bool isOverride)
- : QEvent(WindowStateChange), ostate(s), m_override(isOverride)
+QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates oldState, bool isOverride)
+ : QEvent(WindowStateChange), m_oldStates(oldState), m_override(isOverride)
{
}
@@ -3940,11 +4343,7 @@ bool QWindowStateChangeEvent::isOverride() const
return m_override;
}
-/*! \internal
-*/
-QWindowStateChangeEvent::~QWindowStateChangeEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QWindowStateChangeEvent)
/*!
@@ -3990,15 +4389,18 @@ QWindowStateChangeEvent::~QWindowStateChangeEvent()
gestures. Whenever such a decision is made (the gesture is recognized), the clients will be
notified with a QEvent::TouchCancel event so they can update their state accordingly.
- The touchPoints() function returns a list of all touch points contained in the event. Note that
- this list may be empty, for example in case of a QEvent::TouchCancel event. Information about
- each touch point can be retrieved using the QTouchEvent::TouchPoint class. The
- Qt::TouchPointState enum describes the different states that a touch point may have.
+ The pointCount() and point() functions can be used to access and iterate individual
+ touch points.
+
+ The points() function returns a list of all touch points contained in the event.
+ Note that this list may be empty, for example in case of a QEvent::TouchCancel event.
+ Each point is an instance of the QEventPoint class. The QEventPoint::State enum
+ describes the different states that a touch point may have.
- \note The list of touchPoints() will never be partial: A touch event will always contain a touch
- point for each existing physical touch contacts targetting the window or widget to which the
+ \note The list of points() will never be partial: A touch event will always contain a touch
+ point for each existing physical touch contacts targeting the window or widget to which the
event is sent. For instance, assuming that all touches target the same window or widget, an
- event with a condition of touchPoints().count()==2 is guaranteed to imply that the number of
+ event with a condition of points().count()==2 is guaranteed to imply that the number of
fingers touching the touchscreen or touchpad is exactly two.
\section1 Event Delivery and Propagation
@@ -4071,618 +4473,95 @@ QWindowStateChangeEvent::~QWindowStateChangeEvent()
\endlist
- \sa QTouchEvent::TouchPoint, Qt::TouchPointState, Qt::WA_AcceptTouchEvents,
+ \sa QEventPoint, QEventPoint::State, Qt::WA_AcceptTouchEvents,
QGraphicsItem::acceptTouchEvents()
*/
/*!
- Constructs a QTouchEvent with the given \a eventType, \a device, and
- \a touchPoints. The \a touchPointStates and \a modifiers
- are the current touch point states and keyboard modifiers at the time of
- the event.
+ Constructs a QTouchEvent with the given \a eventType, \a device,
+ \a touchPoints, and current keyboard \a modifiers at the time of the event.
*/
+
QTouchEvent::QTouchEvent(QEvent::Type eventType,
const QPointingDevice *device,
Qt::KeyboardModifiers modifiers,
- Qt::TouchPointStates touchPointStates,
- const QList<QTouchEvent::TouchPoint> &touchPoints)
- : QPointerEvent(eventType, device, modifiers),
- _window(nullptr),
- _target(nullptr),
- _touchPointStates(touchPointStates),
- _touchPoints(touchPoints)
-{ }
-
-/*!
- Destroys the QTouchEvent.
-*/
-QTouchEvent::~QTouchEvent()
-{ }
-
-/*! \fn QWindow *QTouchEvent::window() const
-
- Returns the window on which the event occurred. Useful for doing
- global-local mapping on data like rawScreenPositions() which,
- for performance reasons, only stores the global positions in the
- touch event.
-*/
-
-/*! \fn QObject *QTouchEvent::target() const
-
- Returns the target object within the window on which the event occurred.
- This is typically a QWidget or a QQuickItem. May be 0 when no specific target is available.
-*/
-
-/*! \fn QTouchEvent::TouchPoint::TouchPoint(TouchPoint &&other)
-
- Move-constructs a TouchPoint instance, making it point to the same
- object that \a other was pointing to.
-*/
-
-/*! \fn Qt::TouchPointStates QTouchEvent::touchPointStates() const
-
- Returns a bitwise OR of all the touch point states for this event.
-*/
-
-/*! \fn const QList<QTouchEvent::TouchPoint> &QTouchEvent::touchPoints() const
-
- Returns the list of touch points contained in the touch event.
-*/
-
-/*! \fn QPointingDevice* QTouchEvent::device() const
-
- Returns the touch device from which this touch event originates.
-*/
-
-/*! \fn void QTouchEvent::setWindow(QWindow *window)
-
- \internal
-
- Sets the window for this event.
-*/
-
-/*! \fn void QTouchEvent::setTarget(QObject *target)
-
- \internal
-
- Sets the target within the window (typically a widget) for this event.
-*/
-
-/*! \fn void QTouchEvent::setTouchPoints(const QList<QTouchEvent::TouchPoint> &touchPoints)
-
- \internal
-
- Sets the list of touch points for this event.
-*/
-
-/*! \class QTouchEvent::TouchPoint
- \brief The TouchPoint class provides information about a touch point in a QTouchEvent.
- \since 4.6
- \inmodule QtGui
-
- \image touchpoint-metrics.png
-*/
-
-/*! \enum TouchPoint::InfoFlag
-
- The values of this enum describe additional information about a touch point.
-
- \value Pen Indicates that the contact has been made by a designated pointing device (e.g. a pen) instead of a finger.
- \value Token Indicates that the contact has been made by a fiducial object (e.g. a knob or other token) instead of a finger.
-*/
-
-/*!
- \internal
-
- Constructs a QTouchEvent::TouchPoint for use in a QTouchEvent.
-*/
-QTouchEvent::TouchPoint::TouchPoint(int id)
- : d(new QTouchEventTouchPointPrivate(id))
-{ }
-
-/*!
- \fn QTouchEvent::TouchPoint::TouchPoint(const QTouchEvent::TouchPoint &other)
- \internal
-
- Constructs a copy of \a other.
-*/
-QTouchEvent::TouchPoint::TouchPoint(const QTouchEvent::TouchPoint &other)
- : d(other.d)
-{
- d->ref.ref();
-}
-
-/*!
- \internal
-
- Destroys the QTouchEvent::TouchPoint.
-*/
-QTouchEvent::TouchPoint::~TouchPoint()
-{
- if (d && !d->ref.deref())
- delete d;
-}
-
-/*!
- Returns the id number of this touch point.
-
- Do not assume that id numbers start at zero or that they are sequential.
- Such an assumption is often false due to the way the underlying drivers work.
-*/
-int QTouchEvent::TouchPoint::id() const
-{
- return d->id;
-}
-
-/*!
- \since 5.8
- Returns the unique ID of this touch point or token, if any.
-
- It is normally invalid (see \l {QPointingDeviceUniqueId::isValid()} {isValid()}),
- because touchscreens cannot uniquely identify fingers. But when the
- \l {TouchPoint::InfoFlag} {Token} flag is set, it is expected to uniquely
- identify a specific token (fiducial object).
-
- \sa flags
-*/
-QPointingDeviceUniqueId QTouchEvent::TouchPoint::uniqueId() const
-{
- return d->uniqueId;
-}
-
-/*!
- Returns the current state of this touch point.
-*/
-Qt::TouchPointState QTouchEvent::TouchPoint::state() const
-{
- return Qt::TouchPointState(int(d->state));
-}
-
-/*!
- \fn QPointF QTouchEvent::pos() const
- \deprecated in Qt 6.0. Use position() instead.
-
- Returns the position of this touch point, relative to the widget
- or item that received the event.
-
- \sa startPos(), lastPos(), screenPos(), scenePos(), normalizedPos()
-*/
-
-/*!
- Returns the position of this touch point, relative to the widget
- or item that received the event.
-
- \sa startPos(), lastPos(), screenPos(), scenePos(), normalizedPos()
-*/
-QPointF QTouchEvent::TouchPoint::position() const
-{
- return d->pos;
-}
-
-/*!
- \fn QPointF QTouchEvent::scenePos() const
- \deprecated in Qt 6.0. Use scenePosition() instead.
-*/
-
-/*!
- Returns the position of this touch point relative to the window or scene.
-
- The scene position is the position relative to QQuickWindow if handled in QQuickItem::event(),
- in QGraphicsScene coordinates if handled by an override of QGraphicsItem::touchEvent(),
- or the window position in widget applications.
-
- \sa scenePressPosition(), position(), globalPosition()
-*/
-QPointF QTouchEvent::TouchPoint::scenePosition() const
-{
- return d->scenePos;
-}
-
-/*!
- \fn QPointF QTouchEvent::screenPos() const
- \deprecated in Qt 6.0. Use globalPosition() instead.
-*/
-
-/*!
- Returns the position of this touch point on the screen or virtual desktop.
-
- \sa globalPressPosition(), position(), scenePosition()
-*/
-QPointF QTouchEvent::TouchPoint::globalPosition() const
-{
- return d->screenPos;
-}
-
-/*!
- \deprecated in Qt 6.0. Use globalPosition() instead.
-
- Returns the normalized position of this touch point.
-
- The coordinates are normalized to the size of the touch device,
- i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
-
- \sa startNormalizedPos(), lastNormalizedPos(), pos()
-*/
-QPointF QTouchEvent::TouchPoint::normalizedPos() const
-{
- return d->normalizedPos;
-}
-
-/*!
- \fn QPointF QTouchEvent::startPos() const
- \deprecated in Qt 6.0. Use pressPosition() instead.
-*/
-
-/*!
- Returns the position at which this touch point was pressed, relative to the
- widget or item that received the event.
-
- \sa position()
-*/
-QPointF QTouchEvent::TouchPoint::pressPosition() const
-{
- return d->startPos;
-}
-
-/*!
- \fn QPointF QTouchEvent::sceneStartPos() const
- \deprecated in Qt 6.0. Use scenePressPosition() instead.
-*/
-
-/*!
- Returns the scene position at which this touch point was pressed.
-
- The scene position is the position relative to QQuickWindow if handled in QQuickItem::event(),
- in QGraphicsScene coordinates if handled by an override of QGraphicsItem::touchEvent(),
- or the window position in widget applications.
-
- \sa scenePosition(), pressPosition(), globalPressPosition()
-*/
-QPointF QTouchEvent::TouchPoint::scenePressPosition() const
-{
- return d->startScenePos;
-}
-
-/*!
- \fn QPointF QTouchEvent::startScreenPos() const
- \deprecated in Qt 6.0. Use globalPressPosition() instead.
-*/
-
-/*!
- Returns the starting screen position of this touch point.
-
- \sa globalPosition(), pressPosition(), scenePressPosition()
-*/
-QPointF QTouchEvent::TouchPoint::globalPressPosition() const
+ const QList<QEventPoint> &touchPoints)
+ : QPointerEvent(eventType, device, modifiers, touchPoints),
+ m_target(nullptr)
{
- return d->startScreenPos;
-}
-
-/*!
- \deprecated in Qt 6.0. Use globalPressPosition() instead.
- Returns the normalized press position of this touch point.
-
- The coordinates are normalized to the size of the touch device,
- i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
-
- \sa normalizedPos(), lastNormalizedPos()
-*/
-QPointF QTouchEvent::TouchPoint::startNormalizedPos() const
-{
- return d->startNormalizedPos;
+ for (QEventPoint &point : m_points) {
+ m_touchPointStates |= point.state();
+ QMutableEventPoint::setDevice(point, device);
+ }
}
+#if QT_DEPRECATED_SINCE(6, 0)
/*!
- Returns the position of this touch point from the previous touch
- event, relative to the widget or QGraphicsItem that received the event.
+ \deprecated [6.0] Use another constructor.
- \sa pos(), startPos()
+ Constructs a QTouchEvent with the given \a eventType, \a device, and
+ \a touchPoints. The \a touchPointStates and \a modifiers are the current
+ touch point states and keyboard modifiers at the time of the event.
*/
-QPointF QTouchEvent::TouchPoint::lastPos() const
+QTouchEvent::QTouchEvent(QEvent::Type eventType,
+ const QPointingDevice *device,
+ Qt::KeyboardModifiers modifiers,
+ QEventPoint::States touchPointStates,
+ const QList<QEventPoint> &touchPoints)
+ : QPointerEvent(eventType, device, modifiers, touchPoints),
+ m_target(nullptr),
+ m_touchPointStates(touchPointStates)
{
- return d->lastPos;
+ for (QEventPoint &point : m_points)
+ QMutableEventPoint::setDevice(point, device);
}
+#endif // QT_DEPRECATED_SINCE(6, 0)
-/*!
- Returns the scene position of this touch point from the previous
- touch event.
-
- The scene position is the position in QGraphicsScene coordinates
- if the QTouchEvent is handled by a QGraphicsItem::touchEvent()
- reimplementation, and identical to the screen position for
- widgets.
-
- \sa scenePos(), startScenePos()
-*/
-QPointF QTouchEvent::TouchPoint::lastScenePos() const
-{
- return d->lastScenePos;
-}
+Q_IMPL_POINTER_EVENT(QTouchEvent)
/*!
- Returns the screen position of this touch point from the previous
- touch event.
-
- \sa screenPos(), startScreenPos()
+ Returns true if this event includes at least one newly-pressed touchpoint.
*/
-QPointF QTouchEvent::TouchPoint::lastScreenPos() const
+bool QTouchEvent::isBeginEvent() const
{
- return d->lastScreenPos;
+ return m_touchPointStates.testFlag(QEventPoint::State::Pressed);
}
/*!
- Returns the normalized position of this touch point from the
- previous touch event.
-
- The coordinates are normalized to the size of the touch device,
- i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
-
- \sa normalizedPos(), startNormalizedPos()
+ Returns true if this event does not include newly-pressed or newly-released
+ touchpoints.
*/
-QPointF QTouchEvent::TouchPoint::lastNormalizedPos() const
+bool QTouchEvent::isUpdateEvent() const
{
- return d->lastNormalizedPos;
+ return !m_touchPointStates.testFlag(QEventPoint::State::Pressed) &&
+ !m_touchPointStates.testFlag(QEventPoint::State::Released);
}
/*!
- Returns the pressure of this touch point. The return value is in
- the range 0.0 to 1.0.
+ Returns true if this event includes at least one newly-released touchpoint.
*/
-qreal QTouchEvent::TouchPoint::pressure() const
+bool QTouchEvent::isEndEvent() const
{
- return d->pressure;
+ return m_touchPointStates.testFlag(QEventPoint::State::Released);
}
-/*!
- \since 5.8
- Returns the angular orientation of this touch point. The return value is in degrees,
- where zero (the default) indicates the finger or token is pointing upwards,
- a negative angle means it's rotated to the left, and a positive angle means
- it's rotated to the right. Most touchscreens do not detect rotation, so
- zero is the most common value.
-*/
-qreal QTouchEvent::TouchPoint::rotation() const
-{
- return d->rotation;
-}
+/*! \fn QObject *QTouchEvent::target() const
-/*!
- \since 5.9
- Returns the width and height of the bounding ellipse of this touch point.
- The return value is in logical pixels. Most touchscreens do not detect the
- shape of the contact point, so a null size is the most common value.
- In other cases the diameters may be nonzero and equal (the ellipse is
- approximated as a circle).
+ Returns the target object within the window on which the event occurred.
+ This is typically a QWidget or a QQuickItem. May be 0 when no specific target is available.
*/
-QSizeF QTouchEvent::TouchPoint::ellipseDiameters() const
-{
- return d->ellipseDiameters;
-}
-
-/*!
- Returns a velocity vector for this touch point.
- The vector is in the screen's coordinate system, using pixels per seconds for the magnitude.
- \note The returned vector is only valid if the touch device's capabilities include QPointingDevice::Velocity.
+/*! \fn QEventPoint::States QTouchEvent::touchPointStates() const
- \sa QPointingDevice::capabilities(), device()
+ Returns a bitwise OR of all the touch point states for this event.
*/
-QVector2D QTouchEvent::TouchPoint::velocity() const
-{
- return d->velocity;
-}
-
-/*!
- Returns additional information about the touch point.
-
- \sa QTouchEvent::TouchPoint::InfoFlags
- */
-QTouchEvent::TouchPoint::InfoFlags QTouchEvent::TouchPoint::flags() const
-{
- return d->flags;
-}
-
-/*!
- \since 5.0
- Returns the raw, unfiltered positions for the touch point. The positions are in native screen coordinates.
- To get local coordinates you can use mapFromGlobal() of the QWindow returned by QTouchEvent::window().
-
- \note Returns an empty vector if the touch device's capabilities do not include QPointingDevice::RawPositions.
-
- \note Native screen coordinates refer to the native orientation of the screen which, in case of
- mobile devices, is typically portrait. This means that on systems capable of screen orientation
- changes the positions in this list will not reflect the current orientation (unlike pos(),
- screenPos(), etc.) and will always be reported in the native orientation.
-
- \sa QPointingDevice::capabilities(), device(), window()
- */
-QVector<QPointF> QTouchEvent::TouchPoint::rawScreenPositions() const
-{
- return d->rawScreenPositions;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setId(int id)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->id = id;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setUniqueId(qint64 uid)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->uniqueId = QPointingDeviceUniqueId::fromNumericId(uid);
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setState(Qt::TouchPointStates state)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->state = state;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setPos(const QPointF &pos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->pos = pos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->scenePos = scenePos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->screenPos = screenPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setNormalizedPos(const QPointF &normalizedPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->normalizedPos = normalizedPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->startPos = startPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->startScenePos = startScenePos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->startScreenPos = startScreenPos;
-}
-/*! \internal */
-void QTouchEvent::TouchPoint::setStartNormalizedPos(const QPointF &startNormalizedPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->startNormalizedPos = startNormalizedPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->lastPos = lastPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastScenePos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->lastScenePos = lastScenePos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->lastScreenPos = lastScreenPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalizedPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->lastNormalizedPos = lastNormalizedPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setPressure(qreal pressure)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->pressure = pressure;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setRotation(qreal angle)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->rotation = angle;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setEllipseDiameters(const QSizeF &dia)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->ellipseDiameters = dia;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setVelocity(const QVector2D &v)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->velocity = v;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setRawScreenPositions(const QVector<QPointF> &positions)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->rawScreenPositions = positions;
-}
+/*! \fn const QList<QEventPoint> &QTouchEvent::touchPoints() const
+ \deprecated [6.0] Use points() instead.
-/*!
- \internal
-*/
-void QTouchEvent::TouchPoint::setFlags(InfoFlags flags)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->flags = flags;
-}
+ Returns a reference to the list of touch points contained in the touch event.
-/*!
- \fn QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::TouchPoint &other)
- \internal
- */
-
-/*!
- \fn QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(QTouchEvent::TouchPoint &&other)
- \internal
- */
-/*!
- \fn void QTouchEvent::TouchPoint::swap(TouchPoint &other);
- \internal
+ \sa QPointerEvent::point(), QPointerEvent::pointCount()
*/
/*!
@@ -4697,8 +4576,8 @@ void QTouchEvent::TouchPoint::setFlags(InfoFlags flags)
The object receiving this event should set viewportSize, maxContentPos and contentPos.
It also should accept this event to indicate that scrolling should be started.
- It is not guaranteed that a QScrollEvent will be sent after an acceepted
- QScrollPrepareEvent, e.g. in a case where the maximum content position is (0,0).
+ It is not guaranteed that a QScrollEvent will be sent after an accepted
+ QScrollPrepareEvent, e.g. in a case where the maximum content position is (0, 0).
\sa QScrollEvent, QScroller
*/
@@ -4712,47 +4591,30 @@ QScrollPrepareEvent::QScrollPrepareEvent(const QPointF &startPos)
{
}
-/*!
- Destroys QScrollEvent.
-*/
-QScrollPrepareEvent::~QScrollPrepareEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QScrollPrepareEvent)
/*!
+ \fn QPointF QScrollPrepareEvent::startPos() const
+
Returns the position of the touch or mouse event that started the scrolling.
*/
-QPointF QScrollPrepareEvent::startPos() const
-{
- return m_startPos;
-}
/*!
+ \fn QSizeF QScrollPrepareEvent::viewportSize() const
Returns size of the area that is to be scrolled as set by setViewportSize
\sa setViewportSize()
*/
-QSizeF QScrollPrepareEvent::viewportSize() const
-{
- return m_viewportSize;
-}
/*!
+ \fn QRectF QScrollPrepareEvent::contentPosRange() const
Returns the range of coordinates for the content as set by setContentPosRange().
*/
-QRectF QScrollPrepareEvent::contentPosRange() const
-{
- return m_contentPosRange;
-}
/*!
+ \fn QPointF QScrollPrepareEvent::contentPos() const
Returns the current position of the content as set by setContentPos.
*/
-QPointF QScrollPrepareEvent::contentPos() const
-{
- return m_contentPos;
-}
-
/*!
Sets the size of the area that is to be scrolled to \a size.
@@ -4827,33 +4689,26 @@ QScrollEvent::QScrollEvent(const QPointF &contentPos, const QPointF &overshootDi
{
}
-/*!
- Destroys QScrollEvent.
-*/
-QScrollEvent::~QScrollEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QScrollEvent)
/*!
+ \fn QPointF QScrollEvent::contentPos() const
+
Returns the new scroll position.
*/
-QPointF QScrollEvent::contentPos() const
-{
- return m_contentPos;
-}
/*!
+ \fn QPointF QScrollEvent::overshootDistance() const
+
Returns the new overshoot distance.
See QScroller for an explanation of the term overshoot.
\sa QScroller
*/
-QPointF QScrollEvent::overshootDistance() const
-{
- return m_overshoot;
-}
/*!
+ \fn QScrollEvent::ScrollState QScrollEvent::scrollState() const
+
Returns the current scroll state as a combination of ScrollStateFlag values.
ScrollStarted (or ScrollFinished) will be set, if this scroll event is the first (or last) event in a scrolling activity.
Please note that both values can be set at the same time, if the activity consists of a single QScrollEvent.
@@ -4861,10 +4716,6 @@ QPointF QScrollEvent::overshootDistance() const
A widget could for example revert selections when scrolling is started and stopped.
*/
-QScrollEvent::ScrollState QScrollEvent::scrollState() const
-{
- return m_state;
-}
/*!
Creates a new QScreenOrientationChangeEvent
@@ -4875,28 +4726,19 @@ QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(QScreen *screen, Qt
{
}
-/*!
- Destroys QScreenOrientationChangeEvent.
-*/
-QScreenOrientationChangeEvent::~QScreenOrientationChangeEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QScreenOrientationChangeEvent)
/*!
+ \fn QScreen *QScreenOrientationChangeEvent::screen() const
+
Returns the screen whose orientation changed.
*/
-QScreen *QScreenOrientationChangeEvent::screen() const
-{
- return m_screen;
-}
/*!
+ \fn Qt::ScreenOrientation QScreenOrientationChangeEvent::orientation() const
+
Returns the orientation of the screen.
*/
-Qt::ScreenOrientation QScreenOrientationChangeEvent::orientation() const
-{
- return m_orientation;
-}
/*!
Creates a new QApplicationStateChangeEvent.
@@ -4907,108 +4749,73 @@ QApplicationStateChangeEvent::QApplicationStateChangeEvent(Qt::ApplicationState
{
}
+Q_IMPL_EVENT_COMMON(QApplicationStateChangeEvent)
+
/*!
+ \fn Qt::ApplicationState QApplicationStateChangeEvent::applicationState() const
+
Returns the state of the application.
*/
-Qt::ApplicationState QApplicationStateChangeEvent::applicationState() const
-{
- return m_applicationState;
-}
/*!
- \class QPointingDeviceUniqueId
- \since 5.8
- \ingroup events
+ \class QChildWindowEvent
\inmodule QtGui
+ \since 6.7
+ \brief The QChildWindowEvent class contains event parameters for
+ child window changes.
- \brief QPointingDeviceUniqueId identifies a unique object, such as a tagged token
- or stylus, which is used with a pointing device.
-
- QPointingDeviceUniqueIds can be compared for equality, and can be used as keys in a QHash.
- You get access to the numerical ID via numericId(), if the device supports such IDs.
- For future extensions, though, you should not use that function, but compare objects
- of this type using the equality operator.
-
- This class is a thin wrapper around an integer ID. You pass it into and out of
- functions by value.
+ \ingroup events
- This type actively prevents you from holding it in a QList, because doing so would
- be very inefficient. Use a QVector instead, which has the same API as QList, but more
- efficient storage.
+ Child window events are sent to windows when children are
+ added or removed.
- \sa QTouchEvent::TouchPoint
+ In both cases you can only rely on the child being a QWindow
+ — not any subclass thereof. This is because in the
+ QEvent::ChildWindowAdded case the subclass is not yet fully
+ constructed, and in the QEvent::ChildWindowRemoved case it
+ might have already been destructed.
*/
/*!
- \fn QPointingDeviceUniqueId::QPointingDeviceUniqueId()
- Constructs an invalid unique pointer ID.
-*/
+ Constructs a child window event object of a particular \a type
+ for the \a childWindow.
-/*!
- Constructs a unique pointer ID from numeric ID \a id.
+ \a type can be QEvent::ChildWindowAdded or QEvent::ChildWindowRemoved.
+
+ \sa child()
*/
-QPointingDeviceUniqueId QPointingDeviceUniqueId::fromNumericId(qint64 id)
+QChildWindowEvent::QChildWindowEvent(Type type, QWindow *childWindow)
+ : QEvent(type), c(childWindow)
{
- QPointingDeviceUniqueId result;
- result.m_numericId = id;
- return result;
}
-/*!
- \fn bool QPointingDeviceUniqueId::isValid() const
-
- Returns whether this unique pointer ID is valid, that is, it represents an actual
- pointer.
-*/
+Q_IMPL_EVENT_COMMON(QChildWindowEvent)
/*!
- \property QPointingDeviceUniqueId::numericId
- \brief the numeric unique ID of the token represented by a touchpoint
-
- If the device provides a numeric ID, isValid() returns true, and this
- property provides the numeric ID;
- otherwise it is -1.
+ \fn QWindow *QChildWindowEvent::child() const
- You should not use the value of this property in portable code, but
- instead rely on equality to identify pointers.
-
- \sa isValid()
+ Returns the child window that was added or removed.
*/
-qint64 QPointingDeviceUniqueId::numericId() const noexcept
-{
- return m_numericId;
-}
-/*!
- \relates QPointingDeviceUniqueId
- \since 5.8
+QMutableTouchEvent::~QMutableTouchEvent()
+ = default;
- Returns whether the two unique pointer IDs \a lhs and \a rhs identify the same pointer
- (\c true) or not (\c false).
+/*! \internal
+ Add the given \a point.
*/
-bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept
+void QMutableTouchEvent::addPoint(const QEventPoint &point)
{
- return lhs.numericId() == rhs.numericId();
+ m_points.append(point);
+ auto &added = m_points.last();
+ if (!added.device())
+ QMutableEventPoint::setDevice(added, pointingDevice());
+ m_touchPointStates |= point.state();
}
-/*!
- \fn bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs)
- \relates QPointingDeviceUniqueId
- \since 5.8
-
- Returns whether the two unique pointer IDs \a lhs and \a rhs identify different pointers
- (\c true) or not (\c false).
-*/
-
-/*!
- \relates QPointingDeviceUniqueId
- \since 5.8
- Returns the hash value for \a key, using \a seed to seed the calculation.
-*/
-size_t qHash(QPointingDeviceUniqueId key, size_t seed) noexcept
-{
- return qHash(key.numericId(), seed);
-}
+QMutableSinglePointEvent::~QMutableSinglePointEvent()
+ = default;
QT_END_NAMESPACE
+
+#include "moc_qevent.cpp"
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index baf39439df..a24f0c471c 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -1,45 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QEVENT_H
#define QEVENT_H
+#if 0
+#pragma qt_class(QtEvents)
+#endif
+
#include <QtGui/qtguiglobal.h>
#include <QtCore/qcoreevent.h>
@@ -49,58 +17,156 @@
#include <QtCore/qstring.h>
#include <QtCore/qurl.h>
#include <QtCore/qvariant.h>
+#include <QtGui/qeventpoint.h>
#include <QtGui/qpointingdevice.h>
#include <QtGui/qregion.h>
-#include <QtGui/qvector2d.h>
#include <QtGui/qwindowdefs.h>
#if QT_CONFIG(shortcut)
# include <QtGui/qkeysequence.h>
#endif
+class tst_QEvent;
+
QT_BEGIN_NAMESPACE
class QFile;
class QAction;
-class QInputDevice;
-class QPointingDevice;
+class QMouseEvent;
+template <typename T> class QPointer;
+class QPointerEvent;
class QScreen;
+#if QT_CONFIG(shortcut)
+class QShortcut;
+#endif
+class QTabletEvent;
+class QTouchEvent;
#if QT_CONFIG(gestures)
class QGesture;
#endif
class Q_GUI_EXPORT QInputEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QInputEvent)
public:
explicit QInputEvent(Type type, const QInputDevice *m_dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
- ~QInputEvent();
+
const QInputDevice *device() const { return m_dev; }
QInputDevice::DeviceType deviceType() const { return m_dev ? m_dev->type() : QInputDevice::DeviceType::Unknown; }
- inline Qt::KeyboardModifiers modifiers() const { return modState; }
- inline void setModifiers(Qt::KeyboardModifiers amodifiers) { modState = amodifiers; }
- inline ulong timestamp() const { return ts; }
- inline void setTimestamp(ulong atimestamp) { ts = atimestamp; }
+ inline Qt::KeyboardModifiers modifiers() const { return m_modState; }
+ inline void setModifiers(Qt::KeyboardModifiers modifiers) { m_modState = modifiers; }
+ inline quint64 timestamp() const { return m_timeStamp; }
+ virtual void setTimestamp(quint64 timestamp) { m_timeStamp = timestamp; }
+
protected:
+ QInputEvent(Type type, PointerEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ QInputEvent(Type type, SinglePointEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+
const QInputDevice *m_dev = nullptr;
- Qt::KeyboardModifiers modState;
- ulong ts;
+ quint64 m_timeStamp = 0;
+ Qt::KeyboardModifiers m_modState = Qt::NoModifier;
+ // fill up to the closest 8-byte aligned size: 48
+ quint32 m_reserved = 0;
};
class Q_GUI_EXPORT QPointerEvent : public QInputEvent
{
+ Q_GADGET
+ Q_DECL_EVENT_COMMON(QPointerEvent)
public:
- explicit QPointerEvent(Type type, const QPointingDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ explicit QPointerEvent(Type type, const QPointingDevice *dev,
+ Qt::KeyboardModifiers modifiers = Qt::NoModifier, const QList<QEventPoint> &points = {});
+
const QPointingDevice *pointingDevice() const;
QPointingDevice::PointerType pointerType() const {
return pointingDevice() ? pointingDevice()->pointerType() : QPointingDevice::PointerType::Unknown;
}
+ void setTimestamp(quint64 timestamp) override;
+ qsizetype pointCount() const { return m_points.size(); }
+ QEventPoint &point(qsizetype i);
+ const QList<QEventPoint> &points() const { return m_points; }
+ QEventPoint *pointById(int id);
+ bool allPointsGrabbed() const;
+ virtual bool isBeginEvent() const { return false; }
+ virtual bool isUpdateEvent() const { return false; }
+ virtual bool isEndEvent() const { return false; }
+ bool allPointsAccepted() const;
+ virtual void setAccepted(bool accepted) override;
+ QObject *exclusiveGrabber(const QEventPoint &point) const;
+ void setExclusiveGrabber(const QEventPoint &point, QObject *exclusiveGrabber);
+ QList<QPointer <QObject>> passiveGrabbers(const QEventPoint &point) const;
+ void clearPassiveGrabbers(const QEventPoint &point);
+ bool addPassiveGrabber(const QEventPoint &point, QObject *grabber);
+ bool removePassiveGrabber(const QEventPoint &point, QObject *grabber);
+
+protected:
+ QPointerEvent(Type type, SinglePointEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+
+ QList<QEventPoint> m_points;
};
-class Q_GUI_EXPORT QEnterEvent : public QEvent
+class Q_GUI_EXPORT QSinglePointEvent : public QPointerEvent
{
+ Q_GADGET
+ Q_PROPERTY(QObject *exclusivePointGrabber READ exclusivePointGrabber
+ WRITE setExclusivePointGrabber)
+
+ Q_DECL_EVENT_COMMON(QSinglePointEvent)
public:
- QEnterEvent(const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos);
- ~QEnterEvent();
+ inline Qt::MouseButton button() const { return m_button; }
+ inline Qt::MouseButtons buttons() const { return m_mouseState; }
+
+ inline QPointF position() const
+ { Q_ASSERT(!m_points.isEmpty()); return m_points.first().position(); }
+ inline QPointF scenePosition() const
+ { Q_ASSERT(!m_points.isEmpty()); return m_points.first().scenePosition(); }
+ inline QPointF globalPosition() const
+ { Q_ASSERT(!m_points.isEmpty()); return m_points.first().globalPosition(); }
+
+ bool isBeginEvent() const override;
+ bool isUpdateEvent() const override;
+ bool isEndEvent() const override;
+
+ QObject *exclusivePointGrabber() const
+ { return QPointerEvent::exclusiveGrabber(points().first()); }
+ void setExclusivePointGrabber(QObject *exclusiveGrabber)
+ { QPointerEvent::setExclusiveGrabber(points().first(), exclusiveGrabber); }
+
+protected:
+ friend class ::tst_QEvent;
+ QSinglePointEvent(Type type, const QPointingDevice *dev, const QEventPoint &point,
+ Qt::MouseButton button, Qt::MouseButtons buttons,
+ Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source);
+ QSinglePointEvent(Type type, const QPointingDevice *dev, const QPointF &localPos,
+ const QPointF &scenePos, const QPointF &globalPos,
+ Qt::MouseButton button, Qt::MouseButtons buttons,
+ Qt::KeyboardModifiers modifiers,
+ Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
+
+ Qt::MouseButton m_button = Qt::NoButton;
+ Qt::MouseButtons m_mouseState = Qt::NoButton;
+ Qt::MouseEventSource m_source;
+ /*
+ Fill up to the next 8-byte aligned size: 88
+ We have 32bits left, use some for QSinglePointEvent subclasses so that
+ we don't end up with gaps.
+ */
+ // split this in two quint16; with a quint32, MSVC would 32-bit align it
+ quint16 m_reserved;
+ quint16 m_reserved2 : 11;
+ // for QMouseEvent
+ quint16 m_doubleClick : 1;
+ // for QWheelEvent
+ quint16 m_phase : 3;
+ quint16 m_invertedScrolling : 1;
+};
+
+class Q_GUI_EXPORT QEnterEvent : public QSinglePointEvent
+{
+ Q_DECL_EVENT_COMMON(QEnterEvent)
+public:
+ QEnterEvent(const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
#if QT_DEPRECATED_SINCE(6, 0)
#ifndef QT_NO_INTEGER_EVENT_COORDINATES
@@ -124,30 +190,30 @@ public:
QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
QPointF screenPos() const { return globalPosition(); }
#endif // QT_DEPRECATED_SINCE(6, 0)
-
- QPointF position() const { return l; }
- QPointF scenePosition() const { return s; }
- QPointF globalPosition() const { return g; }
-
-protected:
- QPointF l, s, g;
};
-class Q_GUI_EXPORT QMouseEvent : public QPointerEvent
+class Q_GUI_EXPORT QMouseEvent : public QSinglePointEvent
{
+ Q_DECL_EVENT_COMMON(QMouseEvent)
public:
+#if QT_DEPRECATED_SINCE(6, 4)
+ QT_DEPRECATED_VERSION_X_6_4("Use another constructor")
QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton button,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
+ Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
+#endif
QMouseEvent(Type type, const QPointF &localPos, const QPointF &globalPos,
Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers);
+ Qt::KeyboardModifiers modifiers,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
QMouseEvent(Type type, const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers);
+ Qt::KeyboardModifiers modifiers,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
QMouseEvent(Type type, const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source);
- ~QMouseEvent();
+ Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
#ifndef QT_NO_INTEGER_EVENT_COORDINATES
inline QPoint pos() const { return position().toPoint(); }
@@ -172,34 +238,23 @@ public:
QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
QPointF screenPos() const { return globalPosition(); }
#endif // QT_DEPRECATED_SINCE(6, 0)
-
- QPointF position() const { return l; }
- QPointF scenePosition() const { return w; }
- QPointF globalPosition() const { return g; }
-
- inline Qt::MouseButton button() const { return b; }
- inline Qt::MouseButtons buttons() const { return mouseState; }
-
- inline void setLocalPos(const QPointF &localPosition) { l = localPosition; }
-
Qt::MouseEventSource source() const;
Qt::MouseEventFlags flags() const;
-
-protected:
- QPointF l, w, g;
- Qt::MouseButton b;
- Qt::MouseButtons mouseState;
- int caps;
- QVector2D velocity;
-
- friend class QGuiApplicationPrivate;
};
-class Q_GUI_EXPORT QHoverEvent : public QInputEvent
+class Q_GUI_EXPORT QHoverEvent : public QSinglePointEvent
{
+ Q_DECL_EVENT_COMMON(QHoverEvent)
public:
- QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
- ~QHoverEvent();
+ QHoverEvent(Type type, const QPointF &scenePos, const QPointF &globalPos, const QPointF &oldPos,
+ Qt::KeyboardModifiers modifiers = Qt::NoModifier,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
+#if QT_DEPRECATED_SINCE(6, 3)
+ QT_DEPRECATED_VERSION_X_6_3("Use the other constructor")
+ QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos,
+ Qt::KeyboardModifiers modifiers = Qt::NoModifier,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
+#endif
#if QT_DEPRECATED_SINCE(6, 0)
#ifndef QT_NO_INTEGER_EVENT_COORDINATES
@@ -211,72 +266,65 @@ public:
inline QPointF posF() const { return position(); }
#endif // QT_DEPRECATED_SINCE(6, 0)
- // TODO deprecate when we figure out an actual replacement (point history?)
- inline QPoint oldPos() const { return op.toPoint(); }
- inline QPointF oldPosF() const { return op; }
+ bool isUpdateEvent() const override { return true; }
- QPointF position() const { return p; }
+ // TODO deprecate when we figure out an actual replacement (point history?)
+ inline QPoint oldPos() const { return m_oldPos.toPoint(); }
+ inline QPointF oldPosF() const { return m_oldPos; }
protected:
- QPointF p, op;
+ QPointF m_oldPos; // TODO remove?
};
#if QT_CONFIG(wheelevent)
-class Q_GUI_EXPORT QWheelEvent : public QPointerEvent
+class Q_GUI_EXPORT QWheelEvent : public QSinglePointEvent
{
+ Q_GADGET
+ Q_PROPERTY(const QPointingDevice *device READ pointingDevice)
+ Q_PROPERTY(QPoint pixelDelta READ pixelDelta)
+ Q_PROPERTY(QPoint angleDelta READ angleDelta)
+ Q_PROPERTY(Qt::ScrollPhase phase READ phase)
+ Q_PROPERTY(bool inverted READ inverted)
+
+ Q_DECL_EVENT_COMMON(QWheelEvent)
public:
enum { DefaultDeltasPerStep = 120 };
- QWheelEvent(QPointF pos, QPointF globalPos, QPoint pixelDelta, QPoint angleDelta,
+ QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase,
- bool inverted, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
- ~QWheelEvent();
-
-
- inline QPoint pixelDelta() const { return pixelD; }
- inline QPoint angleDelta() const { return angleD; }
-
- inline QPointF position() const { return p; }
- inline QPointF globalPosition() const { return g; }
+ bool inverted, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
- inline Qt::MouseButtons buttons() const { return mouseState; }
+ inline QPoint pixelDelta() const { return m_pixelDelta; }
+ inline QPoint angleDelta() const { return m_angleDelta; }
- inline Qt::ScrollPhase phase() const { return Qt::ScrollPhase(ph); }
- inline bool inverted() const { return invertedScrolling; }
+ inline Qt::ScrollPhase phase() const { return Qt::ScrollPhase(m_phase); }
+ inline bool inverted() const { return m_invertedScrolling; }
+ inline bool isInverted() const { return m_invertedScrolling; }
+ inline bool hasPixelDelta() const { return !m_pixelDelta.isNull(); }
- Qt::MouseEventSource source() const { return Qt::MouseEventSource(src); }
+ bool isBeginEvent() const override;
+ bool isUpdateEvent() const override;
+ bool isEndEvent() const override;
+ Qt::MouseEventSource source() const { return Qt::MouseEventSource(m_source); }
protected:
- QPointF p;
- QPointF g;
- QPoint pixelD;
- QPoint angleD;
- Qt::MouseButtons mouseState;
- uint src: 2;
- uint ph : 3;
- bool invertedScrolling : 1;
- int reserved : 26;
-
- friend class QApplication;
+ QPoint m_pixelDelta;
+ QPoint m_angleDelta;
};
#endif
#if QT_CONFIG(tabletevent)
-class Q_GUI_EXPORT QTabletEvent : public QPointerEvent
+class Q_GUI_EXPORT QTabletEvent : public QSinglePointEvent
{
- Q_GADGET
+ Q_DECL_EVENT_COMMON(QTabletEvent)
public:
- QTabletEvent(Type t, const QPointF &pos, const QPointF &globalPos,
- int deviceType, int pointerType, qreal pressure, int xTilt, int yTilt,
- qreal tangentialPressure, qreal rotation, int z,
- Qt::KeyboardModifiers keyState, qint64 uniqueID,
- Qt::MouseButton button, Qt::MouseButtons buttons);
- QTabletEvent(Type t, const QPointingDevice *dev, const QPointF &pos, const QPointF &globalPos,
- qreal pressure, int xTilt, int yTilt,
- qreal tangentialPressure, qreal rotation, int z,
+ QTabletEvent(Type t, const QPointingDevice *device,
+ const QPointF &pos, const QPointF &globalPos,
+ qreal pressure, float xTilt, float yTilt,
+ float tangentialPressure, qreal rotation, float z,
Qt::KeyboardModifiers keyState,
Qt::MouseButton button, Qt::MouseButtons buttons);
- ~QTabletEvent();
#if QT_DEPRECATED_SINCE(6, 0)
QT_DEPRECATED_VERSION_X_6_0("Use position()")
@@ -300,38 +348,48 @@ public:
inline qreal hiResGlobalX() const { return globalPosition().x(); }
QT_DEPRECATED_VERSION_X_6_0("use globalPosition().y()")
inline qreal hiResGlobalY() const { return globalPosition().y(); }
-#endif
- inline QPointF position() const { return mPos; }
- inline QPointF globalPosition() const { return mGPos; }
+ QT_DEPRECATED_VERSION_X_6_0("use pointingDevice().uniqueId()")
inline qint64 uniqueId() const { return pointingDevice() ? pointingDevice()->uniqueId().numericId() : -1; }
- inline qreal pressure() const { return mPress; }
- inline int z() const { return mZ; }
- inline qreal tangentialPressure() const { return mTangential; }
- inline qreal rotation() const { return mRot; }
- inline int xTilt() const { return mXT; }
- inline int yTilt() const { return mYT; }
- inline Qt::MouseButton button() const { return mButton; }
- inline Qt::MouseButtons buttons() const { return mButtons; }
+#endif
+ inline qreal pressure() const { Q_ASSERT(!points().isEmpty()); return points().first().pressure(); }
+ inline qreal rotation() const { Q_ASSERT(!points().isEmpty()); return points().first().rotation(); }
+ inline qreal z() const { return m_z; }
+ inline qreal tangentialPressure() const { return m_tangential; }
+ inline qreal xTilt() const { return m_xTilt; }
+ inline qreal yTilt() const { return m_yTilt; }
protected:
- QPointF mPos, mGPos;
- int mXT, mYT, mZ;
- qreal mPress, mTangential, mRot;
- // TODO refactor to parent class along with QMouseEvent's button storage
- Qt::MouseButton mButton;
- Qt::MouseButtons mButtons;
+ float m_tangential;
+ float m_xTilt;
+ float m_yTilt;
+ float m_z;
};
#endif // QT_CONFIG(tabletevent)
#if QT_CONFIG(gestures)
-class Q_GUI_EXPORT QNativeGestureEvent : public QPointerEvent
+class Q_GUI_EXPORT QNativeGestureEvent : public QSinglePointEvent
{
+ Q_DECL_EVENT_COMMON(QNativeGestureEvent)
public:
+#if QT_DEPRECATED_SINCE(6, 2)
+ QT_DEPRECATED_VERSION_X_6_2("Use the other constructor")
QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *dev, const QPointF &localPos, const QPointF &scenePos,
- const QPointF &globalPos, qreal value, ulong sequenceId, quint64 intArgument);
- ~QNativeGestureEvent();
- Qt::NativeGestureType gestureType() const { return mGestureType; }
- qreal value() const { return mRealValue; }
+ const QPointF &globalPos, qreal value, quint64 sequenceId, quint64 intArgument);
+#endif
+ QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *dev, int fingerCount,
+ const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
+ qreal value, const QPointF &delta, quint64 sequenceId = UINT64_MAX);
+
+ Qt::NativeGestureType gestureType() const { return m_gestureType; }
+ int fingerCount() const { return m_fingerCount; }
+ qreal value() const { return m_realValue; }
+ QPointF delta() const {
+#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
+ return m_delta.toPointF();
+#else
+ return m_delta;
+#endif
+ }
#if QT_DEPRECATED_SINCE(6, 0)
#ifndef QT_NO_INTEGER_EVENT_COORDINATES
@@ -348,61 +406,71 @@ public:
QPointF screenPos() const { return globalPosition(); }
#endif
- QPointF position() const { return mLocalPos; }
- QPointF scenePosition() const { return mScenePos; }
- QPointF globalPosition() const { return mGlobalPos; }
-
protected:
- Qt::NativeGestureType mGestureType;
- QPointF mLocalPos;
- QPointF mScenePos;
- QPointF mGlobalPos;
- qreal mRealValue;
- ulong mSequenceId;
- quint64 mIntValue;
+ quint64 m_sequenceId;
+#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
+ QVector2D m_delta;
+#else
+ QPointF m_delta;
+#endif
+ qreal m_realValue;
+ Qt::NativeGestureType m_gestureType;
+ quint32 m_fingerCount : 4;
+ quint32 m_reserved : 28;
};
#endif // QT_CONFIG(gestures)
class Q_GUI_EXPORT QKeyEvent : public QInputEvent
{
+ Q_DECL_EVENT_COMMON(QKeyEvent)
public:
QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text = QString(),
- bool autorep = false, ushort count = 1);
+ bool autorep = false, quint16 count = 1);
QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
- const QString &text = QString(), bool autorep = false, ushort count = 1);
- ~QKeyEvent();
+ const QString &text = QString(), bool autorep = false, quint16 count = 1,
+ const QInputDevice *device = QInputDevice::primaryKeyboard());
- int key() const { return k; }
+ int key() const { return m_key; }
#if QT_CONFIG(shortcut)
bool matches(QKeySequence::StandardKey key) const;
#endif
Qt::KeyboardModifiers modifiers() const;
- inline QString text() const { return txt; }
- inline bool isAutoRepeat() const { return autor; }
- inline int count() const { return int(c); }
+ QKeyCombination keyCombination() const
+ {
+ return QKeyCombination(modifiers(), Qt::Key(m_key));
+ }
+ inline QString text() const { return m_text; }
+ inline bool isAutoRepeat() const { return m_autoRepeat; }
+ inline int count() const { return int(m_count); }
+
+ inline quint32 nativeScanCode() const { return m_scanCode; }
+ inline quint32 nativeVirtualKey() const { return m_virtualKey; }
+ inline quint32 nativeModifiers() const { return m_nativeModifiers; }
- inline quint32 nativeScanCode() const { return nScanCode; }
- inline quint32 nativeVirtualKey() const { return nVirtualKey; }
- inline quint32 nativeModifiers() const { return nModifiers; }
+#if QT_CONFIG(shortcut)
+ friend inline bool operator==(QKeyEvent *e, QKeySequence::StandardKey key)
+ { return (e ? e->matches(key) : false); }
+ friend inline bool operator==(QKeySequence::StandardKey key, QKeyEvent *e)
+ { return (e ? e->matches(key) : false); }
+#endif // QT_CONFIG(shortcut)
protected:
- QString txt;
- int k;
- quint32 nScanCode;
- quint32 nVirtualKey;
- quint32 nModifiers;
- ushort c;
- ushort autor:1;
- // ushort reserved:15;
+ QString m_text;
+ int m_key;
+ quint32 m_scanCode;
+ quint32 m_virtualKey;
+ quint32 m_nativeModifiers;
+ quint16 m_count : 15;
+ quint16 m_autoRepeat : 1;
};
class Q_GUI_EXPORT QFocusEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QFocusEvent)
public:
explicit QFocusEvent(Type type, Qt::FocusReason reason=Qt::OtherFocusReason);
- ~QFocusEvent();
inline bool gotFocus() const { return type() == FocusIn; }
inline bool lostFocus() const { return type() == FocusOut; }
@@ -416,10 +484,10 @@ private:
class Q_GUI_EXPORT QPaintEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QPaintEvent)
public:
explicit QPaintEvent(const QRegion& paintRegion);
explicit QPaintEvent(const QRect &paintRect);
- ~QPaintEvent();
inline const QRect &rect() const { return m_rect; }
inline const QRegion &region() const { return m_region; }
@@ -432,31 +500,36 @@ protected:
class Q_GUI_EXPORT QMoveEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QMoveEvent)
public:
QMoveEvent(const QPoint &pos, const QPoint &oldPos);
- ~QMoveEvent();
- inline const QPoint &pos() const { return p; }
- inline const QPoint &oldPos() const { return oldp;}
+ inline const QPoint &pos() const { return m_pos; }
+ inline const QPoint &oldPos() const { return m_oldPos;}
protected:
- QPoint p, oldp;
+ QPoint m_pos, m_oldPos;
friend class QApplication;
};
class Q_GUI_EXPORT QExposeEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QExposeEvent)
public:
- explicit QExposeEvent(const QRegion &rgn);
- ~QExposeEvent();
+ explicit QExposeEvent(const QRegion &m_region);
- inline const QRegion &region() const { return rgn; }
+#if QT_DEPRECATED_SINCE(6, 0)
+ QT_DEPRECATED_VERSION_X_6_0("Handle QPaintEvent instead")
+ inline const QRegion &region() const { return m_region; }
+#endif
protected:
- QRegion rgn;
+ QRegion m_region;
+ friend class QWidgetWindow;
};
class Q_GUI_EXPORT QPlatformSurfaceEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QPlatformSurfaceEvent)
public:
enum SurfaceEventType {
SurfaceCreated,
@@ -464,7 +537,6 @@ public:
};
explicit QPlatformSurfaceEvent(SurfaceEventType surfaceEventType);
- ~QPlatformSurfaceEvent();
inline SurfaceEventType surfaceEventType() const { return m_surfaceEventType; }
@@ -474,81 +546,84 @@ protected:
class Q_GUI_EXPORT QResizeEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QResizeEvent)
public:
QResizeEvent(const QSize &size, const QSize &oldSize);
- ~QResizeEvent();
- inline const QSize &size() const { return s; }
- inline const QSize &oldSize()const { return olds;}
+ inline const QSize &size() const { return m_size; }
+ inline const QSize &oldSize()const { return m_oldSize;}
protected:
- QSize s, olds;
+ QSize m_size, m_oldSize;
friend class QApplication;
};
class Q_GUI_EXPORT QCloseEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QCloseEvent)
public:
QCloseEvent();
- ~QCloseEvent();
};
class Q_GUI_EXPORT QIconDragEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QIconDragEvent)
public:
QIconDragEvent();
- ~QIconDragEvent();
};
class Q_GUI_EXPORT QShowEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QShowEvent)
public:
QShowEvent();
- ~QShowEvent();
};
class Q_GUI_EXPORT QHideEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QHideEvent)
public:
QHideEvent();
- ~QHideEvent();
};
#ifndef QT_NO_CONTEXTMENU
class Q_GUI_EXPORT QContextMenuEvent : public QInputEvent
{
+ Q_DECL_EVENT_COMMON(QContextMenuEvent)
public:
enum Reason { Mouse, Keyboard, Other };
QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
- Qt::KeyboardModifiers modifiers);
- QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos);
+ Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+#if QT_DEPRECATED_SINCE(6, 4)
+ QT_DEPRECATED_VERSION_X_6_4("Use the other constructor")
QContextMenuEvent(Reason reason, const QPoint &pos);
- ~QContextMenuEvent();
+#endif
- inline int x() const { return p.x(); }
- inline int y() const { return p.y(); }
- inline int globalX() const { return gp.x(); }
- inline int globalY() const { return gp.y(); }
+ inline int x() const { return m_pos.x(); }
+ inline int y() const { return m_pos.y(); }
+ inline int globalX() const { return m_globalPos.x(); }
+ inline int globalY() const { return m_globalPos.y(); }
- inline const QPoint& pos() const { return p; }
- inline const QPoint& globalPos() const { return gp; }
+ inline const QPoint& pos() const { return m_pos; }
+ inline const QPoint& globalPos() const { return m_globalPos; }
- inline Reason reason() const { return Reason(reas); }
+ inline Reason reason() const { return Reason(m_reason); }
protected:
- QPoint p;
- QPoint gp;
- uint reas : 8;
+ QPoint m_pos;
+ QPoint m_globalPos;
+ uint m_reason : 8;
};
#endif // QT_NO_CONTEXTMENU
#ifndef QT_NO_INPUTMETHOD
class Q_GUI_EXPORT QInputMethodEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QInputMethodEvent)
public:
enum AttributeType {
TextFormat,
@@ -569,32 +644,42 @@ public:
};
QInputMethodEvent();
QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes);
- ~QInputMethodEvent();
void setCommitString(const QString &commitString, int replaceFrom = 0, int replaceLength = 0);
- inline const QList<Attribute> &attributes() const { return attrs; }
- inline const QString &preeditString() const { return preedit; }
+ inline const QList<Attribute> &attributes() const { return m_attributes; }
+ inline const QString &preeditString() const { return m_preedit; }
- inline const QString &commitString() const { return commit; }
- inline int replacementStart() const { return replace_from; }
- inline int replacementLength() const { return replace_length; }
+ inline const QString &commitString() const { return m_commit; }
+ inline int replacementStart() const { return m_replacementStart; }
+ inline int replacementLength() const { return m_replacementLength; }
- QInputMethodEvent(const QInputMethodEvent &other);
+ inline friend bool operator==(const QInputMethodEvent::Attribute &lhs,
+ const QInputMethodEvent::Attribute &rhs)
+ {
+ return lhs.type == rhs.type && lhs.start == rhs.start
+ && lhs.length == rhs.length && lhs.value == rhs.value;
+ }
+
+ inline friend bool operator!=(const QInputMethodEvent::Attribute &lhs,
+ const QInputMethodEvent::Attribute &rhs)
+ {
+ return !(lhs == rhs);
+ }
private:
- QString preedit;
- QList<Attribute> attrs;
- QString commit;
- int replace_from;
- int replace_length;
+ QString m_preedit;
+ QString m_commit;
+ QList<Attribute> m_attributes;
+ int m_replacementStart;
+ int m_replacementLength;
};
-Q_DECLARE_TYPEINFO(QInputMethodEvent::Attribute, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QInputMethodEvent::Attribute, Q_RELOCATABLE_TYPE);
class Q_GUI_EXPORT QInputMethodQueryEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QInputMethodQueryEvent)
public:
explicit QInputMethodQueryEvent(Qt::InputMethodQueries queries);
- ~QInputMethodQueryEvent();
Qt::InputMethodQueries queries() const { return m_queries; }
@@ -609,7 +694,7 @@ private:
friend QTypeInfo<QueryPair>;
QList<QueryPair> m_values;
};
-Q_DECLARE_TYPEINFO(QInputMethodQueryEvent::QueryPair, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QInputMethodQueryEvent::QueryPair, Q_RELOCATABLE_TYPE);
#endif // QT_NO_INPUTMETHOD
@@ -619,10 +704,10 @@ class QMimeData;
class Q_GUI_EXPORT QDropEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QDropEvent)
public:
QDropEvent(const QPointF& pos, Qt::DropActions actions, const QMimeData *data,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type = Drop);
- ~QDropEvent();
#if QT_DEPRECATED_SINCE(6, 0)
QT_DEPRECATED_VERSION_X_6_0("Use position().toPoint()")
@@ -635,184 +720,192 @@ public:
inline Qt::KeyboardModifiers keyboardModifiers() const { return modifiers(); }
#endif // QT_DEPRECATED_SINCE(6, 0)
- QPointF position() const { return p; }
- inline Qt::MouseButtons buttons() const { return mouseState; }
- inline Qt::KeyboardModifiers modifiers() const { return modState; }
+ QPointF position() const { return m_pos; }
+ inline Qt::MouseButtons buttons() const { return m_mouseState; }
+ inline Qt::KeyboardModifiers modifiers() const { return m_modState; }
- inline Qt::DropActions possibleActions() const { return act; }
- inline Qt::DropAction proposedAction() const { return default_action; }
- inline void acceptProposedAction() { drop_action = default_action; accept(); }
+ inline Qt::DropActions possibleActions() const { return m_actions; }
+ inline Qt::DropAction proposedAction() const { return m_defaultAction; }
+ inline void acceptProposedAction() { m_dropAction = m_defaultAction; accept(); }
- inline Qt::DropAction dropAction() const { return drop_action; }
+ inline Qt::DropAction dropAction() const { return m_dropAction; }
void setDropAction(Qt::DropAction action);
QObject* source() const;
- inline const QMimeData *mimeData() const { return mdata; }
+ inline const QMimeData *mimeData() const { return m_data; }
protected:
friend class QApplication;
- QPointF p;
- Qt::MouseButtons mouseState;
- Qt::KeyboardModifiers modState;
- Qt::DropActions act;
- Qt::DropAction drop_action;
- Qt::DropAction default_action;
- const QMimeData *mdata;
+ QPointF m_pos;
+ Qt::MouseButtons m_mouseState;
+ Qt::KeyboardModifiers m_modState;
+ Qt::DropActions m_actions;
+ Qt::DropAction m_dropAction;
+ Qt::DropAction m_defaultAction;
+ const QMimeData *m_data;
};
class Q_GUI_EXPORT QDragMoveEvent : public QDropEvent
{
+ Q_DECL_EVENT_COMMON(QDragMoveEvent)
public:
QDragMoveEvent(const QPoint &pos, Qt::DropActions actions, const QMimeData *data,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type = DragMove);
- ~QDragMoveEvent();
- inline QRect answerRect() const { return rect; }
+ inline QRect answerRect() const { return m_rect; }
inline void accept() { QDropEvent::accept(); }
inline void ignore() { QDropEvent::ignore(); }
- inline void accept(const QRect & r) { accept(); rect = r; }
- inline void ignore(const QRect & r) { ignore(); rect = r; }
+ inline void accept(const QRect & r) { accept(); m_rect = r; }
+ inline void ignore(const QRect & r) { ignore(); m_rect = r; }
protected:
- QRect rect;
+ QRect m_rect;
};
class Q_GUI_EXPORT QDragEnterEvent : public QDragMoveEvent
{
+ Q_DECL_EVENT_COMMON(QDragEnterEvent)
public:
QDragEnterEvent(const QPoint &pos, Qt::DropActions actions, const QMimeData *data,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
- ~QDragEnterEvent();
};
class Q_GUI_EXPORT QDragLeaveEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QDragLeaveEvent)
public:
QDragLeaveEvent();
- ~QDragLeaveEvent();
};
#endif // QT_CONFIG(draganddrop)
class Q_GUI_EXPORT QHelpEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QHelpEvent)
public:
QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos);
- ~QHelpEvent();
- inline int x() const { return p.x(); }
- inline int y() const { return p.y(); }
- inline int globalX() const { return gp.x(); }
- inline int globalY() const { return gp.y(); }
+ inline int x() const { return m_pos.x(); }
+ inline int y() const { return m_pos.y(); }
+ inline int globalX() const { return m_globalPos.x(); }
+ inline int globalY() const { return m_globalPos.y(); }
- inline const QPoint& pos() const { return p; }
- inline const QPoint& globalPos() const { return gp; }
+ inline const QPoint& pos() const { return m_pos; }
+ inline const QPoint& globalPos() const { return m_globalPos; }
private:
- QPoint p;
- QPoint gp;
+ QPoint m_pos;
+ QPoint m_globalPos;
};
#ifndef QT_NO_STATUSTIP
class Q_GUI_EXPORT QStatusTipEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QStatusTipEvent)
public:
explicit QStatusTipEvent(const QString &tip);
- ~QStatusTipEvent();
- inline QString tip() const { return s; }
+ inline QString tip() const { return m_tip; }
private:
- QString s;
+ QString m_tip;
};
#endif
#if QT_CONFIG(whatsthis)
class Q_GUI_EXPORT QWhatsThisClickedEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QWhatsThisClickedEvent)
public:
explicit QWhatsThisClickedEvent(const QString &href);
- ~QWhatsThisClickedEvent();
- inline QString href() const { return s; }
+ inline QString href() const { return m_href; }
private:
- QString s;
+ QString m_href;
};
#endif
#if QT_CONFIG(action)
class Q_GUI_EXPORT QActionEvent : public QEvent
{
- QAction *act, *bef;
+ Q_DECL_EVENT_COMMON(QActionEvent)
public:
QActionEvent(int type, QAction *action, QAction *before = nullptr);
- ~QActionEvent();
- inline QAction *action() const { return act; }
- inline QAction *before() const { return bef; }
+ inline QAction *action() const { return m_action; }
+ inline QAction *before() const { return m_before; }
+private:
+ QAction *m_action;
+ QAction *m_before;
};
#endif // QT_CONFIG(action)
class Q_GUI_EXPORT QFileOpenEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QFileOpenEvent)
public:
explicit QFileOpenEvent(const QString &file);
explicit QFileOpenEvent(const QUrl &url);
- ~QFileOpenEvent();
- inline QString file() const { return f; }
+ inline QString file() const { return m_file; }
QUrl url() const { return m_url; }
+#if QT_DEPRECATED_SINCE(6, 6)
+ QT_DEPRECATED_VERSION_X_6_6("Interpret the string returned by file()")
bool openFile(QFile &file, QIODevice::OpenMode flags) const;
+#endif
private:
- QString f;
+ QString m_file;
QUrl m_url;
};
#ifndef QT_NO_TOOLBAR
class Q_GUI_EXPORT QToolBarChangeEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QToolBarChangeEvent)
public:
explicit QToolBarChangeEvent(bool t);
- ~QToolBarChangeEvent();
- inline bool toggle() const { return tog; }
+ inline bool toggle() const { return m_toggle; }
private:
- uint tog : 1;
+ bool m_toggle;
};
#endif
#if QT_CONFIG(shortcut)
class Q_GUI_EXPORT QShortcutEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QShortcutEvent)
public:
+ // Note this is publicly deprecated, but should remain as internal constructor:
QShortcutEvent(const QKeySequence &key, int id, bool ambiguous = false);
- ~QShortcutEvent();
+ QShortcutEvent(const QKeySequence &key, const QShortcut *shortcut = nullptr, bool ambiguous = false);
- inline const QKeySequence &key() const { return sequence; }
- inline int shortcutId() const { return sid; }
- inline bool isAmbiguous() const { return ambig; }
+ inline const QKeySequence &key() const { return m_sequence; }
+ // Note this is publicly deprecated, but should remain as internal getter:
+ inline int shortcutId() const { return m_shortcutId; }
+ inline bool isAmbiguous() const { return m_ambiguous; }
protected:
- QKeySequence sequence;
- bool ambig;
- int sid;
+ QKeySequence m_sequence;
+ int m_shortcutId;
+ bool m_ambiguous;
};
#endif
class Q_GUI_EXPORT QWindowStateChangeEvent: public QEvent
{
+ Q_DECL_EVENT_COMMON(QWindowStateChangeEvent)
public:
- explicit QWindowStateChangeEvent(Qt::WindowStates aOldState, bool isOverride = false);
- ~QWindowStateChangeEvent();
+ explicit QWindowStateChangeEvent(Qt::WindowStates oldState, bool isOverride = false);
- inline Qt::WindowStates oldState() const { return ostate; }
+ inline Qt::WindowStates oldState() const { return m_oldStates; }
bool isOverride() const;
private:
- Qt::WindowStates ostate;
+ Qt::WindowStates m_oldStates;
bool m_override;
};
@@ -820,192 +913,68 @@ private:
Q_GUI_EXPORT QDebug operator<<(QDebug, const QEvent *);
#endif
-#if QT_CONFIG(shortcut)
-inline bool operator==(QKeyEvent *e, QKeySequence::StandardKey key){return (e ? e->matches(key) : false);}
-inline bool operator==(QKeySequence::StandardKey key, QKeyEvent *e){return (e ? e->matches(key) : false);}
-#endif // QT_CONFIG(shortcut)
-
-class QTouchEventTouchPointPrivate;
class Q_GUI_EXPORT QTouchEvent : public QPointerEvent
{
+ Q_DECL_EVENT_COMMON(QTouchEvent)
public:
- class Q_GUI_EXPORT TouchPoint
- {
- public:
- enum InfoFlag {
- Pen = 0x0001,
- Token = 0x0002
- };
-#ifndef Q_MOC_RUN
- // otherwise moc gives
- // Error: Meta object features not supported for nested classes
- Q_DECLARE_FLAGS(InfoFlags, InfoFlag)
-#endif
-
- explicit TouchPoint(int id = -1);
- TouchPoint(const TouchPoint &other);
- TouchPoint(TouchPoint &&other) noexcept
- : d(nullptr)
- { qSwap(d, other.d); }
- TouchPoint &operator=(TouchPoint &&other) noexcept
- { qSwap(d, other.d); return *this; }
- ~TouchPoint();
-
- TouchPoint &operator=(const TouchPoint &other)
- { if ( d != other.d ) { TouchPoint copy(other); swap(copy); } return *this; }
-
- void swap(TouchPoint &other) noexcept
- { qSwap(d, other.d); }
-
- int id() const;
- QPointingDeviceUniqueId uniqueId() const;
-
- Qt::TouchPointState state() const;
-
-#if QT_DEPRECATED_SINCE(6, 0)
- QT_DEPRECATED_VERSION_X_6_0("Use position()")
- QPointF pos() const { return position(); }
- QT_DEPRECATED_VERSION_X_6_0("Use pressPosition()")
- QPointF startPos() const { return pressPosition(); }
-
- QT_DEPRECATED_VERSION_X_6_0("Use scenePosition()")
- QPointF scenePos() const { return scenePosition(); }
- QT_DEPRECATED_VERSION_X_6_0("Use scenePressPosition()")
- QPointF startScenePos() const { return scenePressPosition(); }
-
- QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
- QPointF screenPos() const { return globalPosition(); }
- QT_DEPRECATED_VERSION_X_6_0("Use globalPressPosition()")
- QPointF startScreenPos() const { return globalPressPosition(); }
-#endif // QT_DEPRECATED_SINCE(6, 0)
-
- // TODO deprecate these after finding good replacements (use QPointingDevice::globalArea?)
- QPointF normalizedPos() const;
- QPointF startNormalizedPos() const;
-
- // TODO deprecate these after finding good replacements (store longer history perhaps?)
- QPointF lastPos() const;
- QPointF lastScenePos() const;
- QPointF lastScreenPos() const;
- QPointF lastNormalizedPos() const;
-
- QPointF position() const;
- QPointF pressPosition() const;
- QPointF scenePosition() const;
- QPointF scenePressPosition() const;
- QPointF globalPosition() const;
- QPointF globalPressPosition() const;
-
- qreal pressure() const;
- qreal rotation() const;
- QSizeF ellipseDiameters() const;
-
- QVector2D velocity() const;
- InfoFlags flags() const;
- QList<QPointF> rawScreenPositions() const;
-
- // internal
- // ### Qt 6: move private, rename appropriately, only friends can call them
-#if QT_DEPRECATED_SINCE(6, 0)
- void setId(int id);
- void setUniqueId(qint64 uid);
- void setState(Qt::TouchPointStates state);
- void setPos(const QPointF &pos);
- void setScenePos(const QPointF &scenePos);
- void setScreenPos(const QPointF &screenPos);
- void setNormalizedPos(const QPointF &normalizedPos);
- void setStartPos(const QPointF &startPos);
- void setStartScenePos(const QPointF &startScenePos);
- void setStartScreenPos(const QPointF &startScreenPos);
- void setStartNormalizedPos(const QPointF &startNormalizedPos);
- void setLastPos(const QPointF &lastPos);
- void setLastScenePos(const QPointF &lastScenePos);
- void setLastScreenPos(const QPointF &lastScreenPos);
- void setLastNormalizedPos(const QPointF &lastNormalizedPos);
- void setPressure(qreal pressure);
- void setRotation(qreal angle);
- void setEllipseDiameters(const QSizeF &dia);
- void setVelocity(const QVector2D &v);
- void setFlags(InfoFlags flags);
- void setRawScreenPositions(const QList<QPointF> &positions);
-#endif // QT_DEPRECATED_SINCE(6, 0)
-
- private:
- QTouchEventTouchPointPrivate *d;
- friend class QGuiApplication;
- friend class QGuiApplicationPrivate;
- friend class QApplication;
- friend class QApplicationPrivate;
- friend class QQuickPointerTouchEvent;
- friend class QQuickMultiPointTouchArea;
- };
+ using TouchPoint = QEventPoint; // source compat
explicit QTouchEvent(QEvent::Type eventType,
- const QPointingDevice *source = nullptr,
+ const QPointingDevice *device = nullptr,
Qt::KeyboardModifiers modifiers = Qt::NoModifier,
- Qt::TouchPointStates touchPointStates = Qt::TouchPointStates(),
- const QList<QTouchEvent::TouchPoint> &touchPoints = QList<QTouchEvent::TouchPoint>());
- ~QTouchEvent();
-
- inline QWindow *window() const { return _window; }
- inline QObject *target() const { return _target; }
- inline Qt::TouchPointStates touchPointStates() const { return _touchPointStates; }
- inline const QList<QTouchEvent::TouchPoint> &touchPoints() const { return _touchPoints; }
+ const QList<QEventPoint> &touchPoints = {});
+#if QT_DEPRECATED_SINCE(6, 0)
+ QT_DEPRECATED_VERSION_X_6_0("Use another constructor")
+ explicit QTouchEvent(QEvent::Type eventType,
+ const QPointingDevice *device,
+ Qt::KeyboardModifiers modifiers,
+ QEventPoint::States touchPointStates,
+ const QList<QEventPoint> &touchPoints = {});
+#endif
- // ### Qt 6: move private, rename appropriately, only friends can call them; or just let friends modify variables directly
+ inline QObject *target() const { return m_target; }
+ inline QEventPoint::States touchPointStates() const { return m_touchPointStates; }
#if QT_DEPRECATED_SINCE(6, 0)
- inline void setWindow(QWindow *awindow) { _window = awindow; }
- inline void setTarget(QObject *atarget) { _target = atarget; }
- inline void setTouchPoints(const QList<QTouchEvent::TouchPoint> &atouchPoints) { _touchPoints = atouchPoints; }
-#endif // QT_DEPRECATED_SINCE(6, 0)
+ QT_DEPRECATED_VERSION_X_6_0("Use points()")
+ const QList<QEventPoint> &touchPoints() const { return points(); }
+#endif
+ bool isBeginEvent() const override;
+ bool isUpdateEvent() const override;
+ bool isEndEvent() const override;
protected:
- QWindow *_window;
- QObject *_target;
- Qt::TouchPointStates _touchPointStates;
- QList<QTouchEvent::TouchPoint> _touchPoints;
-
- friend class QGuiApplication;
- friend class QGuiApplicationPrivate;
- friend class QApplication;
- friend class QApplicationPrivate;
-#ifndef QT_NO_GRAPHICSVIEW
- friend class QGraphicsScenePrivate; // direct access to _touchPoints
-#endif
+ QObject *m_target = nullptr;
+ QEventPoint::States m_touchPointStates = QEventPoint::State::Unknown;
+ quint32 m_reserved : 24;
};
-Q_DECLARE_TYPEINFO(QTouchEvent::TouchPoint, Q_MOVABLE_TYPE);
-Q_DECLARE_OPERATORS_FOR_FLAGS(QTouchEvent::TouchPoint::InfoFlags)
-
-#ifndef QT_NO_DEBUG_STREAM
-Q_GUI_EXPORT QDebug operator<<(QDebug, const QTouchEvent::TouchPoint &);
-#endif
class Q_GUI_EXPORT QScrollPrepareEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QScrollPrepareEvent)
public:
explicit QScrollPrepareEvent(const QPointF &startPos);
- ~QScrollPrepareEvent();
- QPointF startPos() const;
+ QPointF startPos() const { return m_startPos; }
- QSizeF viewportSize() const;
- QRectF contentPosRange() const;
- QPointF contentPos() const;
+ QSizeF viewportSize() const { return m_viewportSize; }
+ QRectF contentPosRange() const { return m_contentPosRange; }
+ QPointF contentPos() const { return m_contentPos; }
void setViewportSize(const QSizeF &size);
void setContentPosRange(const QRectF &rect);
void setContentPos(const QPointF &pos);
private:
- QPointF m_startPos;
- QSizeF m_viewportSize;
QRectF m_contentPosRange;
+ QSizeF m_viewportSize;
+ QPointF m_startPos;
QPointF m_contentPos;
};
class Q_GUI_EXPORT QScrollEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QScrollEvent)
public:
enum ScrollState
{
@@ -1015,11 +984,10 @@ public:
};
QScrollEvent(const QPointF &contentPos, const QPointF &overshoot, ScrollState scrollState);
- ~QScrollEvent();
- QPointF contentPos() const;
- QPointF overshootDistance() const;
- ScrollState scrollState() const;
+ QPointF contentPos() const { return m_contentPos; }
+ QPointF overshootDistance() const { return m_overshoot; }
+ ScrollState scrollState() const { return m_state; }
private:
QPointF m_contentPos;
@@ -1029,12 +997,12 @@ private:
class Q_GUI_EXPORT QScreenOrientationChangeEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QScreenOrientationChangeEvent)
public:
QScreenOrientationChangeEvent(QScreen *screen, Qt::ScreenOrientation orientation);
- ~QScreenOrientationChangeEvent();
- QScreen *screen() const;
- Qt::ScreenOrientation orientation() const;
+ QScreen *screen() const { return m_screen; }
+ Qt::ScreenOrientation orientation() const { return m_orientation; }
private:
QScreen *m_screen;
@@ -1043,14 +1011,27 @@ private:
class Q_GUI_EXPORT QApplicationStateChangeEvent : public QEvent
{
+ Q_DECL_EVENT_COMMON(QApplicationStateChangeEvent)
public:
explicit QApplicationStateChangeEvent(Qt::ApplicationState state);
- Qt::ApplicationState applicationState() const;
+
+ Qt::ApplicationState applicationState() const { return m_applicationState; }
private:
Qt::ApplicationState m_applicationState;
};
+class Q_GUI_EXPORT QChildWindowEvent : public QEvent
+{
+ Q_DECL_EVENT_COMMON(QChildWindowEvent)
+public:
+ explicit QChildWindowEvent(Type type, QWindow *childWindow);
+ QWindow *child() const { return c; }
+
+private:
+ QWindow *c;
+};
+
QT_END_NAMESPACE
#endif // QEVENT_H
diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h
index bfe0740ace..96ef8f123e 100644
--- a/src/gui/kernel/qevent_p.h
+++ b/src/gui/kernel/qevent_p.h
@@ -1,99 +1,68 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QEVENT_P_H
#define QEVENT_P_H
-#include <QtGui/private/qtguiglobal_p.h>
-#include <QtCore/qurl.h>
-#include <QtGui/qevent.h>
-#include <QtGui/private/qpointingdevice_p.h>
-
-QT_BEGIN_NAMESPACE
-
//
// W A R N I N G
// -------------
//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
-class QTouchEventTouchPointPrivate
+#include <QtGui/private/qtguiglobal_p.h>
+#include <QtCore/qurl.h>
+#include <QtGui/qevent.h>
+#include <QtGui/qwindow.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPointingDevice;
+
+class Q_GUI_EXPORT QMutableTouchEvent : public QTouchEvent
{
public:
- inline QTouchEventTouchPointPrivate(int id)
- : ref(1),
- id(id),
- state(Qt::TouchPointReleased),
- pressure(-1),
- rotation(0),
- ellipseDiameters(0, 0),
- stationaryWithModifiedProperty(false)
- { }
-
- inline QTouchEventTouchPointPrivate *detach()
- {
- QTouchEventTouchPointPrivate *d = new QTouchEventTouchPointPrivate(*this);
- d->ref.storeRelaxed(1);
- if (!this->ref.deref())
- delete this;
- return d;
- }
-
- QAtomicInt ref;
- int id;
- QPointingDeviceUniqueId uniqueId;
- Qt::TouchPointStates state;
- QPointF pos, scenePos, screenPos, normalizedPos,
- startPos, startScenePos, startScreenPos, startNormalizedPos,
- lastPos, lastScenePos, lastScreenPos, lastNormalizedPos;
- qreal pressure;
- qreal rotation;
- QSizeF ellipseDiameters;
- QVector2D velocity;
- QTouchEvent::TouchPoint::InfoFlags flags;
- bool stationaryWithModifiedProperty : 1;
- QList<QPointF> rawScreenPositions;
+ QMutableTouchEvent(QEvent::Type eventType = QEvent::TouchBegin,
+ const QPointingDevice *device = nullptr,
+ Qt::KeyboardModifiers modifiers = Qt::NoModifier,
+ const QList<QEventPoint> &touchPoints = QList<QEventPoint>()) :
+ QTouchEvent(eventType, device, modifiers, touchPoints) { }
+ ~QMutableTouchEvent() override;
+
+ static QMutableTouchEvent *from(QTouchEvent *e) { return static_cast<QMutableTouchEvent *>(e); }
+
+ static QMutableTouchEvent &from(QTouchEvent &e) { return static_cast<QMutableTouchEvent &>(e); }
+
+ void setTarget(QObject *target) { m_target = target; }
+
+ void addPoint(const QEventPoint &point);
+};
+
+class Q_GUI_EXPORT QMutableSinglePointEvent : public QSinglePointEvent
+{
+public:
+ QMutableSinglePointEvent(const QSinglePointEvent &other) : QSinglePointEvent(other) {}
+ QMutableSinglePointEvent(Type type = QEvent::None, const QPointingDevice *device = nullptr, const QEventPoint &point = QEventPoint(),
+ Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons buttons = Qt::NoButton,
+ Qt::KeyboardModifiers modifiers = Qt::NoModifier,
+ Qt::MouseEventSource source = Qt::MouseEventSynthesizedByQt) :
+ QSinglePointEvent(type, device, point, button, buttons, modifiers, source) { }
+ ~QMutableSinglePointEvent() override;
+
+ static QMutableSinglePointEvent *from(QSinglePointEvent *e) { return static_cast<QMutableSinglePointEvent *>(e); }
+
+ static QMutableSinglePointEvent &from(QSinglePointEvent &e) { return static_cast<QMutableSinglePointEvent &>(e); }
+
+ void setSource(Qt::MouseEventSource s) { m_source = s; }
+
+ bool isDoubleClick() { return m_doubleClick; }
+
+ void setDoubleClick(bool d = true) { m_doubleClick = d; }
};
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qeventpoint.cpp b/src/gui/kernel/qeventpoint.cpp
new file mode 100644
index 0000000000..66d4f44ea0
--- /dev/null
+++ b/src/gui/kernel/qeventpoint.cpp
@@ -0,0 +1,619 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qeventpoint.h"
+#include "private/qeventpoint_p.h"
+#include "private/qpointingdevice_p.h"
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(lcPointerVel, "qt.pointer.velocity")
+Q_LOGGING_CATEGORY(lcEPDetach, "qt.pointer.eventpoint.detach")
+
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QEventPointPrivate)
+
+/*! \class QEventPoint
+ \brief The QEventPoint class provides information about a point in a QPointerEvent.
+ \since 6.0
+ \inmodule QtGui
+*/
+
+/*!
+ \enum QEventPoint::State
+
+ Specifies the state of this event point.
+
+ \value Unknown
+ Unknown state.
+
+ \value Stationary
+ The event point did not move.
+
+ \value Pressed
+ The touch point or button is pressed.
+
+ \value Updated
+ The event point was updated.
+
+ \value Released
+ The touch point or button was released.
+*/
+
+/*!
+ \internal
+ Constructs an invalid event point with the given \a id and the \a device
+ from which it originated.
+
+ This acts as a default constructor in usages like QMap<int, QEventPoint>,
+ as in qgraphicsscene_p.h.
+*/
+QEventPoint::QEventPoint(int id, const QPointingDevice *device)
+ : d(new QEventPointPrivate(id, device)) {}
+
+/*!
+ Constructs an event point with the given \a pointId, \a state,
+ \a scenePosition and \a globalPosition.
+*/
+QEventPoint::QEventPoint(int pointId, State state, const QPointF &scenePosition, const QPointF &globalPosition)
+ : d(new QEventPointPrivate(pointId, state, scenePosition, globalPosition)) {}
+
+/*!
+ Constructs an event point by making a shallow copy of \a other.
+*/
+QEventPoint::QEventPoint(const QEventPoint &other) noexcept = default;
+
+/*!
+ Assigns \a other to this event point and returns a reference to this
+ event point.
+*/
+QEventPoint &QEventPoint::operator=(const QEventPoint &other) noexcept = default;
+
+/*!
+ \fn QEventPoint::QEventPoint(QEventPoint &&other) noexcept
+
+ Constructs an event point by moving \a other.
+*/
+
+/*!
+ \fn QEventPoint &QEventPoint::operator=(QEventPoint &&other) noexcept
+
+ Move-assigns \a other to this event point instance.
+*/
+
+/*!
+ Returns \c true if this event point is equal to \a other, otherwise
+ return \c false.
+*/
+bool QEventPoint::operator==(const QEventPoint &other) const noexcept
+{
+ if (d == other.d)
+ return true;
+ if (!d || !other.d)
+ return false;
+ return *d == *other.d;
+}
+
+/*!
+ \fn bool QEventPoint::operator!=(const QEventPoint &other) const noexcept
+
+ Returns \c true if this event point is not equal to \a other, otherwise
+ return \c false.
+*/
+
+/*!
+ Destroys the event point.
+*/
+QEventPoint::~QEventPoint() = default;
+
+/*! \fn QPointF QEventPoint::pos() const
+ \deprecated [6.0] Use position() instead.
+
+ Returns the position of this point, relative to the widget
+ or item that received the event.
+*/
+
+/*!
+ \property QEventPoint::position
+ \brief the position of this point.
+
+ The position is relative to the widget or item that received the event.
+*/
+QPointF QEventPoint::position() const
+{ return d ? d->pos : QPointF(); }
+
+/*!
+ \property QEventPoint::pressPosition
+ \brief the position at which this point was pressed.
+
+ The position is relative to the widget or item that received the event.
+
+ \sa position
+*/
+QPointF QEventPoint::pressPosition() const
+{ return d ? d->globalPressPos - d->globalPos + d->pos : QPointF(); }
+
+/*!
+ \property QEventPoint::grabPosition
+ \brief the position at which this point was grabbed.
+
+ The position is relative to the widget or item that received the event.
+
+ \sa position
+*/
+QPointF QEventPoint::grabPosition() const
+{ return d ? d->globalGrabPos - d->globalPos + d->pos : QPointF(); }
+
+/*!
+ \property QEventPoint::lastPosition
+ \brief the position of this point from the previous press or move event.
+
+ The position is relative to the widget or item that received the event.
+
+ \sa position, pressPosition
+*/
+QPointF QEventPoint::lastPosition() const
+{ return d ? d->globalLastPos - d->globalPos + d->pos : QPointF(); }
+
+/*!
+ \property QEventPoint::scenePosition
+ \brief the scene position of this point.
+
+ The scene position is the position relative to QQuickWindow if handled in QQuickItem::event(),
+ in QGraphicsScene coordinates if handled by an override of QGraphicsItem::touchEvent(),
+ or the window position in widget applications.
+
+ \sa scenePressPosition, position, globalPosition
+*/
+QPointF QEventPoint::scenePosition() const
+{ return d ? d->scenePos : QPointF(); }
+
+/*!
+ \property QEventPoint::scenePressPosition
+ \brief the scene position at which this point was pressed.
+
+ The scene position is the position relative to QQuickWindow if handled in QQuickItem::event(),
+ in QGraphicsScene coordinates if handled by an override of QGraphicsItem::touchEvent(),
+ or the window position in widget applications.
+
+ \sa scenePosition, pressPosition, globalPressPosition
+*/
+QPointF QEventPoint::scenePressPosition() const
+{ return d ? d->globalPressPos - d->globalPos + d->scenePos : QPointF(); }
+
+/*!
+ \property QEventPoint::sceneGrabPosition
+ \brief the scene position at which this point was grabbed.
+
+ The scene position is the position relative to QQuickWindow if handled in QQuickItem::event(),
+ in QGraphicsScene coordinates if handled by an override of QGraphicsItem::touchEvent(),
+ or the window position in widget applications.
+
+ \sa scenePosition, grabPosition, globalGrabPosition
+*/
+QPointF QEventPoint::sceneGrabPosition() const
+{ return d ? d->globalGrabPos - d->globalPos + d->scenePos : QPointF(); }
+
+/*!
+ \property QEventPoint::sceneLastPosition
+ \brief the scene position of this point from the previous press or move event.
+
+ The scene position is the position relative to QQuickWindow if handled in QQuickItem::event(),
+ in QGraphicsScene coordinates if handled by an override of QGraphicsItem::touchEvent(),
+ or the window position in widget applications.
+
+ \sa scenePosition, scenePressPosition
+*/
+QPointF QEventPoint::sceneLastPosition() const
+{ return d ? d->globalLastPos - d->globalPos + d->scenePos : QPointF(); }
+
+/*!
+ \property QEventPoint::globalPosition
+ \brief the global position of this point.
+
+ The global position is relative to the screen or virtual desktop.
+
+ \sa globalPressPosition, position, scenePosition
+*/
+QPointF QEventPoint::globalPosition() const
+{ return d ? d->globalPos : QPointF(); }
+
+/*!
+ \property QEventPoint::globalPressPosition
+ \brief the global position at which this point was pressed.
+
+ The global position is relative to the screen or virtual desktop.
+
+ \sa globalPosition, pressPosition, scenePressPosition
+*/
+QPointF QEventPoint::globalPressPosition() const
+{ return d ? d->globalPressPos : QPointF(); }
+
+/*!
+ \property QEventPoint::globalGrabPosition
+ \brief the global position at which this point was grabbed.
+
+ The global position is relative to the screen or virtual desktop.
+
+ \sa globalPosition, grabPosition, sceneGrabPosition
+*/
+QPointF QEventPoint::globalGrabPosition() const
+{ return d ? d->globalGrabPos : QPointF(); }
+
+/*!
+ \property QEventPoint::globalLastPosition
+ \brief the global position of this point from the previous press or move event.
+
+ The global position is relative to the screen or virtual desktop.
+
+ \sa globalPosition, lastPosition, sceneLastPosition
+*/
+QPointF QEventPoint::globalLastPosition() const
+{ return d ? d->globalLastPos : QPointF(); }
+
+/*!
+ \property QEventPoint::velocity
+ \brief a velocity vector, in units of pixels per second, in the coordinate.
+ system of the screen or desktop.
+
+ \note If the device's capabilities include QInputDevice::Velocity, it means
+ velocity comes from the operating system (perhaps the touch hardware or
+ driver provides it). But usually the \c Velocity capability is not set,
+ indicating that the velocity is calculated by Qt, using a simple Kalman
+ filter to provide a smoothed average velocity rather than an instantaneous
+ value. Effectively it tells how fast and in what direction the user has
+ been dragging this point over the last few events, with the most recent
+ event having the strongest influence.
+
+ \sa QInputDevice::capabilities(), QInputEvent::device()
+*/
+QVector2D QEventPoint::velocity() const
+{ return d ? d->velocity : QVector2D(); }
+
+/*!
+ \property QEventPoint::state
+ \brief the current state of the event point.
+*/
+QEventPoint::State QEventPoint::state() const
+{ return d ? d->state : QEventPoint::State::Unknown; }
+
+/*!
+ \property QEventPoint::device
+ \brief the pointing device from which this event point originates.
+*/
+const QPointingDevice *QEventPoint::device() const
+{ return d ? d->device : nullptr; }
+
+/*!
+ \property QEventPoint::id
+ \brief the ID number of this event point.
+
+ \note Do not assume that ID numbers start at zero or that they are
+ sequential. Such an assumption is often false due to the way
+ the underlying drivers work.
+*/
+int QEventPoint::id() const
+{ return d ? d->pointId : -1; }
+
+/*!
+ \property QEventPoint::uniqueId
+ \brief the unique ID of this point or token, if any.
+
+ It is often invalid (see \l {QPointingDeviceUniqueId::isValid()} {isValid()}),
+ because touchscreens cannot uniquely identify fingers.
+
+ When it comes from a QTabletEvent, it identifies the serial number of the
+ stylus in use.
+
+ It may identify a specific token (fiducial object) when the TUIO driver is
+ in use with a touchscreen that supports them.
+*/
+QPointingDeviceUniqueId QEventPoint::uniqueId() const
+{ return d ? d->uniqueId : QPointingDeviceUniqueId(); }
+
+/*!
+ \property QEventPoint::timestamp
+ \brief the most recent time at which this point was included in a QPointerEvent.
+
+ \sa QPointerEvent::timestamp()
+*/
+ulong QEventPoint::timestamp() const
+{ return d ? d->timestamp : 0; }
+
+/*!
+ \property QEventPoint::lastTimestamp
+ \brief the time from the previous QPointerEvent that contained this point.
+
+ \sa globalLastPosition
+*/
+ulong QEventPoint::lastTimestamp() const
+{ return d ? d->lastTimestamp : 0; }
+
+/*!
+ \property QEventPoint::pressTimestamp
+ \brief the most recent time at which this point was pressed.
+
+ \sa timestamp
+*/
+ulong QEventPoint::pressTimestamp() const
+{ return d ? d->pressTimestamp : 0; }
+
+/*!
+ \property QEventPoint::timeHeld
+ \brief the duration, in seconds, since this point was pressed and not released.
+
+ \sa pressTimestamp, timestamp
+*/
+qreal QEventPoint::timeHeld() const
+{ return d ? (d->timestamp - d->pressTimestamp) / qreal(1000) : 0.0; }
+
+/*!
+ \property QEventPoint::pressure
+ \brief the pressure of this point.
+
+ The return value is in the range \c 0.0 to \c 1.0.
+*/
+qreal QEventPoint::pressure() const
+{ return d ? d->pressure : 0.0; }
+
+/*!
+ \property QEventPoint::rotation
+ \brief the angular orientation of this point.
+
+ The return value is in degrees, where zero (the default) indicates the finger,
+ token or stylus is pointing upwards, a negative angle means it's rotated to the
+ left, and a positive angle means it's rotated to the right.
+ Most touchscreens do not detect rotation, so zero is the most common value.
+*/
+qreal QEventPoint::rotation() const
+{ return d ? d->rotation : 0.0; }
+
+/*!
+ \property QEventPoint::ellipseDiameters
+ \brief the width and height of the bounding ellipse of the touch point.
+
+ The return value is in logical pixels. Most touchscreens do not detect the
+ shape of the contact point, and no mice or tablet devices can detect it,
+ so a null size is the most common value. On some touchscreens the diameters
+ may be nonzero and always equal (the ellipse is approximated as a circle).
+*/
+QSizeF QEventPoint::ellipseDiameters() const
+{ return d ? d->ellipseDiameters : QSizeF(); }
+
+/*!
+ \property QEventPoint::accepted
+ \brief the accepted state of the event point.
+
+ In widget-based applications, this property is not used, as it's only meaningful
+ for a widget to accept or reject a complete QInputEvent.
+
+ In Qt Quick however, it's normal for an Item or Event Handler to accept
+ only the individual points in a QTouchEvent that are actually participating
+ in a gesture, while other points can be delivered to other items or
+ handlers. For the sake of consistency, that applies to any QPointerEvent;
+ and delivery is done only when all points in a QPointerEvent have been
+ accepted.
+
+ \sa QEvent::accepted
+*/
+void QEventPoint::setAccepted(bool accepted)
+{
+ if (d)
+ d->accept = accepted;
+}
+
+bool QEventPoint::isAccepted() const
+{ return d ? d->accept : false; }
+
+
+/*!
+ \fn QPointF QEventPoint::normalizedPos() const
+ \deprecated [6.0] Use normalizedPosition() instead.
+*/
+
+/*!
+ Returns the normalized position of this point.
+
+ The coordinates are calculated by transforming globalPosition() into the
+ space of QInputDevice::availableVirtualGeometry(), i.e. \c (0, 0) is the
+ top-left corner and \c (1, 1) is the bottom-right corner.
+
+ \sa globalPosition
+*/
+QPointF QEventPoint::normalizedPosition() const
+{
+ if (!d)
+ return {};
+
+ auto geom = d->device->availableVirtualGeometry();
+ if (geom.isNull())
+ return QPointF();
+ return (globalPosition() - geom.topLeft()) / geom.width();
+}
+
+#if QT_DEPRECATED_SINCE(6, 0)
+/*!
+ \deprecated [6.0] Use globalPressPosition() instead.
+
+ Returns the normalized press position of this point.
+*/
+QPointF QEventPoint::startNormalizedPos() const
+{
+ if (!d)
+ return {};
+
+ auto geom = d->device->availableVirtualGeometry();
+ if (geom.isNull())
+ return QPointF();
+ return (globalPressPosition() - geom.topLeft()) / geom.width();
+}
+
+/*!
+ \deprecated [6.0] Use globalLastPosition() instead.
+
+ Returns the normalized position of this point from the previous press or
+ move event.
+
+ The coordinates are normalized to QInputDevice::availableVirtualGeometry(),
+ i.e. \c (0, 0) is the top-left corner and \c (1, 1) is the bottom-right corner.
+
+ \sa normalizedPosition(), globalPressPosition()
+*/
+QPointF QEventPoint::lastNormalizedPos() const
+{
+ if (!d)
+ return {};
+
+ auto geom = d->device->availableVirtualGeometry();
+ if (geom.isNull())
+ return QPointF();
+ return (globalLastPosition() - geom.topLeft()) / geom.width();
+}
+#endif // QT_DEPRECATED_SINCE(6, 0)
+
+/*! \internal
+ This class is explicitly shared, which means if you construct an event and
+ then the point(s) that it holds are modified before the event is delivered,
+ the event will be seen to hold the modified points. The workaround is that
+ any code which modifies an eventpoint that could already be included in an
+ event, or code that wants to save an eventpoint for later, has
+ responsibility to detach before calling any setters, so as to hold and
+ modify an independent copy. (The independent copy can then be used in a
+ subsequent event.)
+*/
+void QMutableEventPoint::detach(QEventPoint &p)
+{
+ if (p.d)
+ p.d.detach();
+ else
+ p.d.reset(new QEventPointPrivate(-1, nullptr));
+}
+
+/*! \internal
+ Update \a target state from the \a other point, assuming that \a target
+ contains state from the previous event and \a other contains new
+ values that came in from a device.
+
+ That is: global position and other valuators will be updated, but
+ the following properties will not be updated:
+
+ \list
+ \li properties that are not likely to be set after a fresh touchpoint
+ has been received from a device
+ \li properties that should be persistent between events (such as grabbers)
+ \endlist
+*/
+void QMutableEventPoint::update(const QEventPoint &other, QEventPoint &target)
+{
+ detach(target);
+ setPressure(target, other.pressure());
+
+ switch (other.state()) {
+ case QEventPoint::State::Pressed:
+ setGlobalPressPosition(target, other.globalPosition());
+ setGlobalLastPosition(target, other.globalPosition());
+ if (target.pressure() < 0)
+ setPressure(target, 1);
+ break;
+
+ case QEventPoint::State::Released:
+ if (target.globalPosition() != other.globalPosition())
+ setGlobalLastPosition(target, target.globalPosition());
+ setPressure(target, 0);
+ break;
+
+ default: // update or stationary
+ if (target.globalPosition() != other.globalPosition())
+ setGlobalLastPosition(target, target.globalPosition());
+ if (target.pressure() < 0)
+ setPressure(target, 1);
+ break;
+ }
+
+ setState(target, other.state());
+ setPosition(target, other.position());
+ setScenePosition(target, other.scenePosition());
+ setGlobalPosition(target, other.globalPosition());
+ setEllipseDiameters(target, other.ellipseDiameters());
+ setRotation(target, other.rotation());
+ setVelocity(target, other.velocity());
+ setUniqueId(target, other.uniqueId()); // for TUIO
+}
+
+/*! \internal
+ Set the timestamp from the event that updated this point's positions,
+ and calculate a new value for velocity().
+
+ The velocity calculation is done here because none of the QPointerEvent
+ subclass constructors take the timestamp directly, and because
+ QGuiApplication traditionally constructs an event first and then sets its
+ timestamp (see for example QGuiApplicationPrivate::processMouseEvent()).
+
+ This function looks up the corresponding instance in QPointingDevicePrivate::activePoints,
+ and assumes that its timestamp() still holds the previous time when this point
+ was updated, its velocity() holds this point's last-known velocity, and
+ its globalPosition() and globalLastPosition() hold this point's current
+ and previous positions, respectively. We assume timestamps are in milliseconds.
+
+ The velocity calculation is skipped if the platform has promised to
+ provide velocities already by setting the QInputDevice::Velocity capability.
+*/
+void QMutableEventPoint::setTimestamp(QEventPoint &p, ulong t)
+{
+ // On mouse press, if the mouse has moved from its last-known location,
+ // QGuiApplicationPrivate::processMouseEvent() sends first a mouse move and
+ // then a press. Both events will get the same timestamp. So we need to set
+ // the press timestamp and position even when the timestamp isn't advancing,
+ // but skip setting lastTimestamp and velocity because those need a time delta.
+ if (p.d) {
+ if (p.state() == QEventPoint::State::Pressed) {
+ p.d->pressTimestamp = t;
+ p.d->globalPressPos = p.d->globalPos;
+ }
+ if (p.d->timestamp == t)
+ return;
+ }
+ detach(p);
+ if (p.device()) {
+ // get the persistent instance out of QPointingDevicePrivate::activePoints
+ // (which sometimes might be the same as this instance)
+ QEventPointPrivate *pd = QPointingDevicePrivate::get(
+ const_cast<QPointingDevice *>(p.d->device))->pointById(p.id())->eventPoint.d.get();
+ if (t > pd->timestamp) {
+ pd->lastTimestamp = pd->timestamp;
+ pd->timestamp = t;
+ if (p.state() == QEventPoint::State::Pressed)
+ pd->pressTimestamp = t;
+ if (pd->lastTimestamp > 0 && !p.device()->capabilities().testFlag(QInputDevice::Capability::Velocity)) {
+ // calculate instantaneous velocity according to time and distance moved since the previous point
+ QVector2D newVelocity = QVector2D(pd->globalPos - pd->globalLastPos) / (t - pd->lastTimestamp) * 1000;
+ // VERY simple kalman filter: does a weighted average
+ // where the older velocities get less and less significant
+ static const float KalmanGain = 0.7f;
+ pd->velocity = newVelocity * KalmanGain + pd->velocity * (1.0f - KalmanGain);
+ qCDebug(lcPointerVel) << "velocity" << newVelocity << "filtered" << pd->velocity <<
+ "based on movement" << pd->globalLastPos << "->" << pd->globalPos <<
+ "over time" << pd->lastTimestamp << "->" << pd->timestamp;
+ }
+ if (p.d != pd) {
+ p.d->lastTimestamp = pd->lastTimestamp;
+ p.d->velocity = pd->velocity;
+ }
+ }
+ }
+ p.d->timestamp = t;
+}
+
+/*!
+ \fn void QMutableEventPoint::setPosition(QPointF pos)
+ \internal
+
+ Sets the localized position.
+ Often events need to be localized before delivery to specific widgets or
+ items. This can be done directly, or in a copy (for which we have a copy
+ constructor), depending on whether the original point needs to be retained.
+ Usually it's calculated by mapping scenePosition() to the target anyway.
+*/
+
+QT_END_NAMESPACE
+
+#include "moc_qeventpoint.cpp"
diff --git a/src/gui/kernel/qeventpoint.h b/src/gui/kernel/qeventpoint.h
new file mode 100644
index 0000000000..518faecee2
--- /dev/null
+++ b/src/gui/kernel/qeventpoint.h
@@ -0,0 +1,142 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QEVENTPOINT_H
+#define QEVENTPOINT_H
+
+#include <QtGui/qtguiglobal.h>
+#include <QtGui/qvector2d.h>
+#include <QtGui/qpointingdevice.h>
+#include <QtCore/qshareddata.h>
+#include <QtCore/qmetatype.h>
+
+QT_BEGIN_NAMESPACE
+
+class QEventPointPrivate;
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QEventPointPrivate, Q_GUI_EXPORT)
+class QMutableEventPoint;
+
+class Q_GUI_EXPORT QEventPoint
+{
+ Q_GADGET
+ Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
+ Q_PROPERTY(const QPointingDevice *device READ device CONSTANT)
+ Q_PROPERTY(int id READ id CONSTANT)
+ Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId CONSTANT)
+ Q_PROPERTY(State state READ state CONSTANT)
+ Q_PROPERTY(ulong timestamp READ timestamp CONSTANT)
+ Q_PROPERTY(ulong pressTimestamp READ pressTimestamp CONSTANT)
+ Q_PROPERTY(ulong lastTimestamp READ lastTimestamp CONSTANT)
+ Q_PROPERTY(qreal timeHeld READ timeHeld CONSTANT)
+ Q_PROPERTY(qreal pressure READ pressure CONSTANT)
+ Q_PROPERTY(qreal rotation READ rotation CONSTANT)
+ Q_PROPERTY(QSizeF ellipseDiameters READ ellipseDiameters CONSTANT)
+ Q_PROPERTY(QVector2D velocity READ velocity CONSTANT)
+ Q_PROPERTY(QPointF position READ position CONSTANT)
+ Q_PROPERTY(QPointF pressPosition READ pressPosition CONSTANT)
+ Q_PROPERTY(QPointF grabPosition READ grabPosition CONSTANT)
+ Q_PROPERTY(QPointF lastPosition READ lastPosition CONSTANT)
+ Q_PROPERTY(QPointF scenePosition READ scenePosition CONSTANT)
+ Q_PROPERTY(QPointF scenePressPosition READ scenePressPosition CONSTANT)
+ Q_PROPERTY(QPointF sceneGrabPosition READ sceneGrabPosition CONSTANT)
+ Q_PROPERTY(QPointF sceneLastPosition READ sceneLastPosition CONSTANT)
+ Q_PROPERTY(QPointF globalPosition READ globalPosition CONSTANT)
+ Q_PROPERTY(QPointF globalPressPosition READ globalPressPosition CONSTANT)
+ Q_PROPERTY(QPointF globalGrabPosition READ globalGrabPosition CONSTANT)
+ Q_PROPERTY(QPointF globalLastPosition READ globalLastPosition CONSTANT)
+public:
+ enum State : quint8 {
+ Unknown = Qt::TouchPointUnknownState,
+ Stationary = Qt::TouchPointStationary,
+ Pressed = Qt::TouchPointPressed,
+ Updated = Qt::TouchPointMoved,
+ Released = Qt::TouchPointReleased
+ };
+ Q_DECLARE_FLAGS(States, State)
+ Q_FLAG(States)
+
+ explicit QEventPoint(int id = -1, const QPointingDevice *device = nullptr);
+ QEventPoint(int pointId, State state, const QPointF &scenePosition, const QPointF &globalPosition);
+ QEventPoint(const QEventPoint &other) noexcept;
+ QEventPoint &operator=(const QEventPoint &other) noexcept;
+ QEventPoint(QEventPoint && other) noexcept = default;
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QEventPoint)
+ bool operator==(const QEventPoint &other) const noexcept;
+ bool operator!=(const QEventPoint &other) const noexcept { return !operator==(other); }
+ ~QEventPoint();
+ inline void swap(QEventPoint &other) noexcept
+ { d.swap(other.d); }
+
+ QPointF position() const;
+ QPointF pressPosition() const;
+ QPointF grabPosition() const;
+ QPointF lastPosition() const;
+ QPointF scenePosition() const;
+ QPointF scenePressPosition() const;
+ QPointF sceneGrabPosition() const;
+ QPointF sceneLastPosition() const;
+ QPointF globalPosition() const;
+ QPointF globalPressPosition() const;
+ QPointF globalGrabPosition() const;
+ QPointF globalLastPosition() const;
+ QPointF normalizedPosition() const;
+
+#if QT_DEPRECATED_SINCE(6, 0)
+ // QEventPoint replaces QTouchEvent::TouchPoint, so we need all its old accessors, for now
+ QT_DEPRECATED_VERSION_X_6_0("Use position()")
+ QPointF pos() const { return position(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use pressPosition()")
+ QPointF startPos() const { return pressPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use scenePosition()")
+ QPointF scenePos() const { return scenePosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use scenePressPosition()")
+ QPointF startScenePos() const { return scenePressPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
+ QPointF screenPos() const { return globalPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use globalPressPosition()")
+ QPointF startScreenPos() const { return globalPressPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use globalPressPosition()")
+ QPointF startNormalizedPos() const;
+ QT_DEPRECATED_VERSION_X_6_0("Use normalizedPosition()")
+ QPointF normalizedPos() const { return normalizedPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use lastPosition()")
+ QPointF lastPos() const { return lastPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use sceneLastPosition()")
+ QPointF lastScenePos() const { return sceneLastPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use globalLastPosition()")
+ QPointF lastScreenPos() const { return globalLastPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use globalLastPosition()")
+ QPointF lastNormalizedPos() const;
+#endif // QT_DEPRECATED_SINCE(6, 0)
+ QVector2D velocity() const;
+ State state() const;
+ const QPointingDevice *device() const;
+ int id() const;
+ QPointingDeviceUniqueId uniqueId() const;
+ ulong timestamp() const;
+ ulong lastTimestamp() const;
+ ulong pressTimestamp() const;
+ qreal timeHeld() const;
+ qreal pressure() const;
+ qreal rotation() const;
+ QSizeF ellipseDiameters() const;
+
+ bool isAccepted() const;
+ void setAccepted(bool accepted = true);
+
+private:
+ QExplicitlySharedDataPointer<QEventPointPrivate> d;
+ friend class QMutableEventPoint;
+ friend class QPointerEvent;
+};
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_GUI_EXPORT QDebug operator<<(QDebug, const QEventPoint *);
+Q_GUI_EXPORT QDebug operator<<(QDebug, const QEventPoint &);
+#endif
+
+Q_DECLARE_SHARED(QEventPoint)
+
+QT_END_NAMESPACE
+
+#endif // QEVENTPOINT_H
diff --git a/src/gui/kernel/qeventpoint_p.h b/src/gui/kernel/qeventpoint_p.h
new file mode 100644
index 0000000000..c339c7e3e1
--- /dev/null
+++ b/src/gui/kernel/qeventpoint_p.h
@@ -0,0 +1,141 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QEVENTPOINT_P_H
+#define QEVENTPOINT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/private/qtguiglobal_p.h>
+#include <QtGui/qevent.h>
+
+#include <QtCore/qloggingcategory.h>
+#include <QtCore/qpointer.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(lcPointerVel);
+Q_DECLARE_LOGGING_CATEGORY(lcEPDetach);
+
+class QPointingDevice;
+
+class QEventPointPrivate : public QSharedData
+{
+public:
+ QEventPointPrivate(int id, const QPointingDevice *device)
+ : device(device), pointId(id) { }
+
+ QEventPointPrivate(int pointId, QEventPoint::State state, const QPointF &scenePosition, const QPointF &globalPosition)
+ : scenePos(scenePosition), globalPos(globalPosition), pointId(pointId), state(state)
+ {
+ if (state == QEventPoint::State::Released)
+ pressure = 0;
+ }
+ inline bool operator==(const QEventPointPrivate &other) const
+ {
+ return device == other.device
+ && window == other.window
+ && target == other.target
+ && pos == other.pos
+ && scenePos == other.scenePos
+ && globalPos == other.globalPos
+ && globalPressPos == other.globalPressPos
+ && globalGrabPos == other.globalGrabPos
+ && globalLastPos == other.globalLastPos
+ && pressure == other.pressure
+ && rotation == other.rotation
+ && ellipseDiameters == other.ellipseDiameters
+ && velocity == other.velocity
+ && timestamp == other.timestamp
+ && lastTimestamp == other.lastTimestamp
+ && pressTimestamp == other.pressTimestamp
+ && uniqueId == other.uniqueId
+ && pointId == other.pointId
+ && state == other.state;
+ }
+
+ const QPointingDevice *device = nullptr;
+ QPointer<QWindow> window;
+ QPointer<QObject> target;
+ QPointF pos, scenePos, globalPos,
+ globalPressPos, globalGrabPos, globalLastPos;
+ qreal pressure = 1;
+ qreal rotation = 0;
+ QSizeF ellipseDiameters = QSizeF(0, 0);
+ QVector2D velocity;
+ ulong timestamp = 0;
+ ulong lastTimestamp = 0;
+ ulong pressTimestamp = 0;
+ QPointingDeviceUniqueId uniqueId;
+ int pointId = -1;
+ QEventPoint::State state = QEventPoint::State::Unknown;
+ bool accept = false;
+};
+
+// Private subclasses to allow accessing and modifying protected variables.
+// These should NOT hold any extra state.
+
+class QMutableEventPoint
+{
+public:
+ static QEventPoint withTimeStamp(ulong timestamp, int pointId, QEventPoint::State state,
+ QPointF position, QPointF scenePosition, QPointF globalPosition)
+ {
+ QEventPoint p(pointId, state, scenePosition, globalPosition);
+ p.d->timestamp = timestamp;
+ p.d->pos = position;
+ return p;
+ }
+
+ static Q_GUI_EXPORT void update(const QEventPoint &from, QEventPoint &to);
+
+ static Q_GUI_EXPORT void detach(QEventPoint &p);
+
+#define TRIVIAL_SETTER(type, field, Field) \
+ static void set##Field (QEventPoint &p, type arg) { p.d->field = std::move(arg); } \
+ /* end */
+
+ TRIVIAL_SETTER(int, pointId, Id)
+ TRIVIAL_SETTER(const QPointingDevice *, device, Device)
+
+ // not trivial:
+ static Q_GUI_EXPORT void setTimestamp(QEventPoint &p, ulong t);
+
+ TRIVIAL_SETTER(ulong, pressTimestamp, PressTimestamp)
+ TRIVIAL_SETTER(QEventPoint::State, state, State)
+ TRIVIAL_SETTER(QPointingDeviceUniqueId, uniqueId, UniqueId)
+ TRIVIAL_SETTER(QPointF, pos, Position)
+ TRIVIAL_SETTER(QPointF, scenePos, ScenePosition)
+ TRIVIAL_SETTER(QPointF, globalPos, GlobalPosition)
+
+ TRIVIAL_SETTER(QPointF, globalPressPos, GlobalPressPosition)
+ TRIVIAL_SETTER(QPointF, globalGrabPos, GlobalGrabPosition)
+ TRIVIAL_SETTER(QPointF, globalLastPos, GlobalLastPosition)
+ TRIVIAL_SETTER(QSizeF, ellipseDiameters, EllipseDiameters)
+ TRIVIAL_SETTER(qreal, pressure, Pressure)
+ TRIVIAL_SETTER(qreal, rotation, Rotation)
+ TRIVIAL_SETTER(QVector2D, velocity, Velocity)
+
+ static QWindow *window(const QEventPoint &p) { return p.d->window.data(); }
+
+ TRIVIAL_SETTER(QWindow *, window, Window)
+
+ static QObject *target(const QEventPoint &p) { return p.d->target.data(); }
+
+ TRIVIAL_SETTER(QObject *, target, Target)
+
+#undef TRIVIAL_SETTER
+};
+
+QT_END_NAMESPACE
+
+#endif // QEVENTPOINT_P_H
diff --git a/src/gui/kernel/qgenericplugin.cpp b/src/gui/kernel/qgenericplugin.cpp
index a53b60b008..8411faeb1f 100644
--- a/src/gui/kernel/qgenericplugin.cpp
+++ b/src/gui/kernel/qgenericplugin.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qgenericplugin.h"
@@ -94,3 +58,5 @@ QGenericPlugin::~QGenericPlugin()
*/
QT_END_NAMESPACE
+
+#include "moc_qgenericplugin.cpp"
diff --git a/src/gui/kernel/qgenericplugin.h b/src/gui/kernel/qgenericplugin.h
index 69b4f29854..f76228dc8a 100644
--- a/src/gui/kernel/qgenericplugin.h
+++ b/src/gui/kernel/qgenericplugin.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QGENERICPLUGIN_H
#define QGENERICPLUGIN_H
diff --git a/src/gui/kernel/qgenericpluginfactory.cpp b/src/gui/kernel/qgenericpluginfactory.cpp
index 9f41b948c0..5ce13ad5e1 100644
--- a/src/gui/kernel/qgenericpluginfactory.cpp
+++ b/src/gui/kernel/qgenericpluginfactory.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qgenericpluginfactory.h"
@@ -46,9 +10,10 @@
QT_BEGIN_NAMESPACE
-Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
- (QGenericPluginFactoryInterface_iid,
- QLatin1String("/generic"), Qt::CaseInsensitive))
+using namespace Qt::StringLiterals;
+
+Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, gpLoader,
+ (QGenericPluginFactoryInterface_iid, "/generic"_L1, Qt::CaseInsensitive))
/*!
\class QGenericPluginFactory
@@ -69,7 +34,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
*/
QObject *QGenericPluginFactory::create(const QString& key, const QString &specification)
{
- return qLoadPlugin<QObject, QGenericPlugin>(loader(), key.toLower(), specification);
+ return qLoadPlugin<QObject, QGenericPlugin>(gpLoader(), key.toLower(), specification);
}
/*!
@@ -84,7 +49,7 @@ QStringList QGenericPluginFactory::keys()
typedef QMultiMap<int, QString> PluginKeyMap;
typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator;
- const PluginKeyMap keyMap = loader()->keyMap();
+ const PluginKeyMap keyMap = gpLoader()->keyMap();
const PluginKeyMapConstIterator cend = keyMap.constEnd();
for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it)
if (!list.contains(it.value()))
diff --git a/src/gui/kernel/qgenericpluginfactory.h b/src/gui/kernel/qgenericpluginfactory.h
index 9cc77a0590..710c983310 100644
--- a/src/gui/kernel/qgenericpluginfactory.h
+++ b/src/gui/kernel/qgenericpluginfactory.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QGENERICPLUGINFACTORY_H
#define QGENERICPLUGINFACTORY_H
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 97eb82a61c..636956aafa 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1,48 +1,15 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2016 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qguiapplication.h"
#include "private/qguiapplication_p.h"
+#include "private/qabstractfileiconprovider_p.h"
#include <qpa/qplatformintegrationfactory_p.h>
#include "private/qevent_p.h"
+#include "private/qeventpoint_p.h"
+#include "private/qiconloader_p.h"
#include "qfont.h"
#include "qpointingdevice.h"
#include <qpa/qplatformfontdatabase.h>
@@ -50,20 +17,24 @@
#include <qpa/qplatformnativeinterface.h>
#include <qpa/qplatformtheme.h>
#include <qpa/qplatformintegration.h>
+#include <qpa/qplatformkeymapper.h>
#include <QtCore/QAbstractEventDispatcher>
+#include <QtCore/QFileInfo>
#include <QtCore/QStandardPaths>
#include <QtCore/QVariant>
#include <QtCore/private/qcoreapplication_p.h>
#include <QtCore/private/qabstracteventdispatcher_p.h>
+#include <QtCore/private/qminimalflatset_p.h>
#include <QtCore/qmutex.h>
#include <QtCore/private/qthread_p.h>
#include <QtCore/private/qlocking_p.h>
+#include <QtCore/private/qflatmap_p.h>
#include <QtCore/qdir.h>
#include <QtCore/qlibraryinfo.h>
-#include <QtCore/qnumeric.h>
+#include <QtCore/private/qnumeric_p.h>
#include <QtDebug>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include "qaccessible.h"
#endif
#include <qpalette.h>
@@ -74,6 +45,7 @@
#include <QtGui/qgenericpluginfactory.h>
#include <QtGui/qstylehints.h>
+#include <QtGui/private/qstylehints_p.h>
#include <QtGui/qinputmethod.h>
#include <QtGui/qpixmapcache.h>
#include <qpa/qplatforminputcontext.h>
@@ -82,8 +54,11 @@
#include <qpa/qwindowsysteminterface.h>
#include <qpa/qwindowsysteminterface_p.h>
#include "private/qwindow_p.h"
+#include "private/qicon_p.h"
#include "private/qcursor_p.h"
-#include "private/qopenglcontext_p.h"
+#if QT_CONFIG(opengl)
+# include "private/qopenglcontext_p.h"
+#endif
#include "private/qinputdevicemanager_p.h"
#include "private/qinputmethod_p.h"
#include "private/qpointingdevice_p.h"
@@ -120,12 +95,21 @@
#include <emscripten.h>
#endif
+#if QT_CONFIG(vulkan)
+#include <private/qvulkandefaultinstance_p.h>
+#endif
+
#include <qtgui_tracepoints_p.h>
-#include <ctype.h>
+#include <private/qtools_p.h>
+
+#include <limits>
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+using namespace QtMiscUtils;
+
// Helper macro for static functions to check on the existence of the application class.
#define CHECK_QAPP_INSTANCE(...) \
if (Q_LIKELY(QCoreApplication::instance())) { \
@@ -135,93 +119,81 @@ QT_BEGIN_NAMESPACE
}
Q_CORE_EXPORT void qt_call_post_routines();
-Q_GUI_EXPORT bool qt_is_gui_used = true;
+Q_CONSTINIT Q_GUI_EXPORT bool qt_is_tty_app = false;
-Qt::MouseButtons QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
-Qt::KeyboardModifiers QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
+Q_CONSTINIT Qt::MouseButtons QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
+Q_CONSTINIT Qt::KeyboardModifiers QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
-QPointF QGuiApplicationPrivate::lastCursorPosition(qInf(), qInf());
+Q_CONSTINIT QGuiApplicationPrivate::QLastCursorPosition QGuiApplicationPrivate::lastCursorPosition;
-QWindow *QGuiApplicationPrivate::currentMouseWindow = nullptr;
+Q_CONSTINIT QWindow *QGuiApplicationPrivate::currentMouseWindow = nullptr;
-QString QGuiApplicationPrivate::styleOverride;
+Q_CONSTINIT QString QGuiApplicationPrivate::styleOverride;
-Qt::ApplicationState QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
+Q_CONSTINIT Qt::ApplicationState QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
-Qt::HighDpiScaleFactorRoundingPolicy QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy =
-#ifdef Q_OS_ANDROID
- // On Android, Qt has newer rounded the scale factor. Preserve
- // that behavior by disabling rounding by default.
+Q_CONSTINIT Qt::HighDpiScaleFactorRoundingPolicy QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy =
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
-#else
- Qt::HighDpiScaleFactorRoundingPolicy::Round;
-#endif
-bool QGuiApplicationPrivate::highDpiScalingUpdated = false;
-
-QPointer<QWindow> QGuiApplicationPrivate::currentDragWindow;
-QVector<QGuiApplicationPrivate::TabletPointData> QGuiApplicationPrivate::tabletDevicePoints;
+Q_CONSTINIT QPointer<QWindow> QGuiApplicationPrivate::currentDragWindow;
-QPlatformIntegration *QGuiApplicationPrivate::platform_integration = nullptr;
-QPlatformTheme *QGuiApplicationPrivate::platform_theme = nullptr;
+Q_CONSTINIT QList<QGuiApplicationPrivate::TabletPointData> QGuiApplicationPrivate::tabletDevicePoints; // TODO remove
-QList<QObject *> QGuiApplicationPrivate::generic_plugin_list;
+Q_CONSTINIT QPlatformIntegration *QGuiApplicationPrivate::platform_integration = nullptr;
+Q_CONSTINIT QPlatformTheme *QGuiApplicationPrivate::platform_theme = nullptr;
-#ifndef QT_NO_SESSIONMANAGER
-bool QGuiApplicationPrivate::is_fallback_session_management_enabled = true;
-#endif
+Q_CONSTINIT QList<QObject *> QGuiApplicationPrivate::generic_plugin_list;
enum ApplicationResourceFlags
{
ApplicationFontExplicitlySet = 0x2
};
-static unsigned applicationResourceFlags = 0;
+Q_CONSTINIT static unsigned applicationResourceFlags = 0;
-QIcon *QGuiApplicationPrivate::app_icon = nullptr;
+Q_CONSTINIT QIcon *QGuiApplicationPrivate::app_icon = nullptr;
-QString *QGuiApplicationPrivate::platform_name = nullptr;
-QString *QGuiApplicationPrivate::displayName = nullptr;
-QString *QGuiApplicationPrivate::desktopFileName = nullptr;
+Q_CONSTINIT QString *QGuiApplicationPrivate::platform_name = nullptr;
+Q_CONSTINIT QString *QGuiApplicationPrivate::displayName = nullptr;
+Q_CONSTINIT QString *QGuiApplicationPrivate::desktopFileName = nullptr;
-QPalette *QGuiApplicationPrivate::app_pal = nullptr; // default application palette
+Q_CONSTINIT QPalette *QGuiApplicationPrivate::app_pal = nullptr; // default application palette
-ulong QGuiApplicationPrivate::mousePressTime = 0;
-Qt::MouseButton QGuiApplicationPrivate::mousePressButton = Qt::NoButton;
-int QGuiApplicationPrivate::mousePressX = 0;
-int QGuiApplicationPrivate::mousePressY = 0;
+Q_CONSTINIT Qt::MouseButton QGuiApplicationPrivate::mousePressButton = Qt::NoButton;
-static int mouseDoubleClickDistance = -1;
-static int touchDoubleTapDistance = -1;
+Q_CONSTINIT static int mouseDoubleClickDistance = 0;
+Q_CONSTINIT static int touchDoubleTapDistance = 0;
-QWindow *QGuiApplicationPrivate::currentMousePressWindow = nullptr;
+Q_CONSTINIT QWindow *QGuiApplicationPrivate::currentMousePressWindow = nullptr;
-static Qt::LayoutDirection layout_direction = Qt::LayoutDirectionAuto;
-static bool force_reverse = false;
+Q_CONSTINIT static Qt::LayoutDirection layout_direction = Qt::LayoutDirectionAuto;
+Q_CONSTINIT static Qt::LayoutDirection effective_layout_direction = Qt::LeftToRight;
+Q_CONSTINIT static bool force_reverse = false;
-QGuiApplicationPrivate *QGuiApplicationPrivate::self = nullptr;
-QPointingDevice *QGuiApplicationPrivate::m_fakeTouchDevice = nullptr;
-int QGuiApplicationPrivate::m_fakeMouseSourcePointId = 0;
+Q_CONSTINIT QGuiApplicationPrivate *QGuiApplicationPrivate::self = nullptr;
+Q_CONSTINIT int QGuiApplicationPrivate::m_fakeMouseSourcePointId = -1;
#ifndef QT_NO_CLIPBOARD
-QClipboard *QGuiApplicationPrivate::qt_clipboard = nullptr;
+Q_CONSTINIT QClipboard *QGuiApplicationPrivate::qt_clipboard = nullptr;
#endif
-QList<QScreen *> QGuiApplicationPrivate::screen_list;
+Q_CONSTINIT QList<QScreen *> QGuiApplicationPrivate::screen_list;
+
+Q_CONSTINIT QWindowList QGuiApplicationPrivate::window_list;
+Q_CONSTINIT QWindow *QGuiApplicationPrivate::focus_window = nullptr;
-QWindowList QGuiApplicationPrivate::window_list;
-QWindow *QGuiApplicationPrivate::focus_window = nullptr;
+Q_CONSTINIT static QBasicMutex applicationFontMutex;
+Q_CONSTINIT QFont *QGuiApplicationPrivate::app_font = nullptr;
+Q_CONSTINIT QStyleHints *QGuiApplicationPrivate::styleHints = nullptr;
+Q_CONSTINIT bool QGuiApplicationPrivate::obey_desktop_settings = true;
-static QBasicMutex applicationFontMutex;
-QFont *QGuiApplicationPrivate::app_font = nullptr;
-QStyleHints *QGuiApplicationPrivate::styleHints = nullptr;
-bool QGuiApplicationPrivate::obey_desktop_settings = true;
+Q_CONSTINIT QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = nullptr;
-QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = nullptr;
+Q_CONSTINIT qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0;
-qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0;
+Q_CONSTINIT static qreal fontSmoothingGamma = 1.7;
-static qreal fontSmoothingGamma = 1.7;
+Q_CONSTINIT bool QGuiApplicationPrivate::quitOnLastWindowClosed = true;
extern void qRegisterGuiVariant();
#if QT_CONFIG(animation)
@@ -234,7 +206,7 @@ static bool qt_detectRTLLanguage()
(QGuiApplication::tr("QT_LAYOUT_DIRECTION",
"Translate this string to the string 'LTR' in left-to-right"
" languages or to 'RTL' in right-to-left languages (such as Hebrew"
- " and Arabic) to get proper widget layout.") == QLatin1String("RTL"));
+ " and Arabic) to get proper widget layout.") == "RTL"_L1);
}
static void initFontUnlocked()
@@ -264,7 +236,7 @@ static void initThemeHints()
static bool checkNeedPortalSupport()
{
#if QT_CONFIG(dbus)
- return !QStandardPaths::locate(QStandardPaths::RuntimeLocation, QLatin1String("flatpak-info")).isEmpty() || qEnvironmentVariableIsSet("SNAP");
+ return QFileInfo::exists("/.flatpak-info"_L1) || qEnvironmentVariableIsSet("SNAP");
#else
return false;
#endif // QT_CONFIG(dbus)
@@ -291,20 +263,20 @@ struct QWindowGeometrySpecification
static inline int nextGeometryToken(const QByteArray &a, int &pos, char *op)
{
*op = 0;
- const int size = a.size();
+ const qsizetype size = a.size();
if (pos >= size)
return -1;
*op = a.at(pos);
if (*op == '+' || *op == '-' || *op == 'x')
pos++;
- else if (isdigit(*op))
+ else if (isAsciiDigit(*op))
*op = 'x'; // If it starts with a digit, it is supposed to be a width specification.
else
return -1;
const int numberPos = pos;
- for ( ; pos < size && isdigit(a.at(pos)); ++pos) ;
+ for ( ; pos < size && isAsciiDigit(a.at(pos)); ++pos) ;
bool ok;
const int result = a.mid(numberPos, pos - numberPos).toInt(&ok);
@@ -473,7 +445,6 @@ static QWindowGeometrySpecification windowGeometrySpecification = Q_WINDOW_GEOME
postEvent(),
sendPostedEvents(),
removePostedEvents(),
- hasPendingEvents(),
notify().
\row
@@ -593,10 +564,12 @@ static QWindowGeometrySpecification windowGeometrySpecification = Q_WINDOW_GEOME
\list
\li \c {altgr}, detect the key \c {AltGr} found on some keyboards as
Qt::GroupSwitchModifier (since Qt 5.12).
- \li \c {darkmode=[1|2]} controls how Qt responds to the activation
+ \li \c {darkmode=[0|1|2]} controls how Qt responds to the activation
of the \e{Dark Mode for applications} introduced in Windows 10
1903 (since Qt 5.15).
+ A value of 0 disables dark mode support.
+
A value of 1 causes Qt to switch the window borders to black
when \e{Dark Mode for applications} is activated and no High
Contrast Theme is in use. This is intended for applications
@@ -608,19 +581,17 @@ static QWindowGeometrySpecification windowGeometrySpecification = Q_WINDOW_GEOME
experimental pending the introduction of new style that
properly adapts to dark mode.
+ As of Qt 6.5, the default value is 2; to disable dark mode
+ support, set the value to 0 or 1.
+
\li \c {dialogs=[xp|none]}, \c xp uses XP-style native dialogs and
\c none disables them.
- \li \c {dpiawareness=[0|1|2]} Sets the DPI awareness of the process
- (see \l{High DPI Displays}, since Qt 5.4).
\li \c {fontengine=freetype}, uses the FreeType font engine.
- \li \c {fontengine=directwrite}, uses the experimental DirectWrite
- font database and defaults to using the DirectWrite font
+ \li \c {fontengine=gdi}, uses the legacy GDI-based
+ font database and defaults to using the GDI font
engine (which is otherwise only used for some font types
- or font properties.) This affects font selection and aims
- to provide font naming more consistent with other platforms,
- but does not support all font formats, such as Postscript
- Type-1 or Microsoft FNT fonts.
+ or font properties.) (Since Qt 6.8).
\li \c {menus=[native|none]}, controls the use of native menus.
Native menus are implemented using Win32 API and are simpler than
@@ -634,7 +605,8 @@ static QWindowGeometrySpecification windowGeometrySpecification = Q_WINDOW_GEOME
\li \c {nocolorfonts} Turn off DirectWrite Color fonts
(since Qt 5.8).
- \li \c {nodirectwrite} Turn off DirectWrite fonts (since Qt 5.8).
+ \li \c {nodirectwrite} Turn off DirectWrite fonts (since Qt 5.8). This implicitly
+ also selects the GDI font engine.
\li \c {nomousefromtouch} Ignores mouse events synthesized
from touch events by the operating system.
@@ -662,9 +634,9 @@ static QWindowGeometrySpecification windowGeometrySpecification = Q_WINDOW_GEOME
#ifdef Q_QDOC
QGuiApplication::QGuiApplication(int &argc, char **argv)
#else
-QGuiApplication::QGuiApplication(int &argc, char **argv, int flags)
+QGuiApplication::QGuiApplication(int &argc, char **argv, int)
#endif
- : QCoreApplication(*new QGuiApplicationPrivate(argc, argv, flags))
+ : QCoreApplication(*new QGuiApplicationPrivate(argc, argv))
{
d_func()->init();
@@ -720,21 +692,16 @@ QGuiApplication::~QGuiApplication()
QGuiApplicationPrivate::desktopFileName = nullptr;
QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
- QGuiApplicationPrivate::lastCursorPosition = {qInf(), qInf()};
+ QGuiApplicationPrivate::lastCursorPosition.reset();
QGuiApplicationPrivate::currentMousePressWindow = QGuiApplicationPrivate::currentMouseWindow = nullptr;
QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
- QGuiApplicationPrivate::highDpiScalingUpdated = false;
+ QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy = Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
QGuiApplicationPrivate::currentDragWindow = nullptr;
QGuiApplicationPrivate::tabletDevicePoints.clear();
-#ifndef QT_NO_SESSIONMANAGER
- QGuiApplicationPrivate::is_fallback_session_management_enabled = true;
-#endif
- QGuiApplicationPrivate::mousePressTime = 0;
- QGuiApplicationPrivate::mousePressX = QGuiApplicationPrivate::mousePressY = 0;
}
-QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags)
- : QCoreApplicationPrivate(argc, argv, flags),
+QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv)
+ : QCoreApplicationPrivate(argc, argv),
inputMethod(nullptr),
lastTouchType(QEvent::TouchEnd),
ownGlobalShareContext(false)
@@ -783,13 +750,37 @@ QString QGuiApplication::applicationDisplayName()
}
/*!
+ Sets the application's badge to \a number.
+
+ Useful for providing feedback to the user about the number
+ of unread messages or similar.
+
+ The badge will be overlaid on the application's icon in the Dock
+ on \macos, the home screen icon on iOS, or the task bar on Windows
+ and Linux.
+
+ If the number is outside the range supported by the platform, the
+ number will be clamped to the supported range. If the number does
+ not fit within the badge, the number may be visually elided.
+
+ Setting the number to 0 will clear the badge.
+
+ \since 6.5
+ \sa applicationName
+*/
+void QGuiApplication::setBadgeNumber(qint64 number)
+{
+ QGuiApplicationPrivate::platformIntegration()->setApplicationBadge(number);
+}
+
+/*!
\property QGuiApplication::desktopFileName
\brief the base name of the desktop entry for this application
\since 5.7
- This is the file name, without the full path, of the desktop entry
- that represents this application according to the freedesktop desktop
- entry specification.
+ This is the file name, without the full path or the trailing ".desktop"
+ extension of the desktop entry that represents this application
+ according to the freedesktop desktop entry specification.
This property gives a precise indication of what desktop entry represents
the application and it is needed by the windowing system to retrieve
@@ -803,6 +794,15 @@ void QGuiApplication::setDesktopFileName(const QString &name)
if (!QGuiApplicationPrivate::desktopFileName)
QGuiApplicationPrivate::desktopFileName = new QString;
*QGuiApplicationPrivate::desktopFileName = name;
+ if (name.endsWith(QLatin1String(".desktop"))) { // ### Qt 7: remove
+ const QString filePath = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, name);
+ if (!filePath.isEmpty()) {
+ qWarning("QGuiApplication::setDesktopFileName: the specified desktop file name "
+ "ends with .desktop. For compatibility reasons, the .desktop suffix will "
+ "be removed. Please specify a desktop file name without .desktop suffix");
+ (*QGuiApplicationPrivate::desktopFileName).chop(8);
+ }
+ }
}
QString QGuiApplication::desktopFileName()
@@ -829,7 +829,7 @@ QWindow *QGuiApplication::modalWindow()
CHECK_QAPP_INSTANCE(nullptr)
if (QGuiApplicationPrivate::self->modalWindowList.isEmpty())
return nullptr;
- return QGuiApplicationPrivate::self->modalWindowList.first();
+ return QGuiApplicationPrivate::self->modalWindowList.constFirst();
}
static void updateBlockedStatusRecursion(QWindow *window, bool shouldBeBlocked)
@@ -880,7 +880,7 @@ void QGuiApplicationPrivate::showModalWindow(QWindow *modal)
}
}
- for (QWindow *window : qAsConst(QGuiApplicationPrivate::window_list)) {
+ for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
if (needsWindowBlockedEvent(window) && !window->d_func()->blockedByModalWindow)
updateBlockedStatus(window);
}
@@ -892,12 +892,23 @@ void QGuiApplicationPrivate::hideModalWindow(QWindow *window)
{
self->modalWindowList.removeAll(window);
- for (QWindow *window : qAsConst(QGuiApplicationPrivate::window_list)) {
+ for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
if (needsWindowBlockedEvent(window) && window->d_func()->blockedByModalWindow)
updateBlockedStatus(window);
}
}
+Qt::WindowModality QGuiApplicationPrivate::defaultModality() const
+{
+ return Qt::NonModal;
+}
+
+bool QGuiApplicationPrivate::windowNeverBlocked(QWindow *window) const
+{
+ Q_UNUSED(window);
+ return false;
+}
+
/*
Returns \c true if \a window is blocked by a modal window. If \a
blockingWindow is non-zero, *blockingWindow will be set to the blocking
@@ -905,55 +916,40 @@ void QGuiApplicationPrivate::hideModalWindow(QWindow *window)
*/
bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow) const
{
+ Q_ASSERT_X(window, Q_FUNC_INFO, "The window must not be null");
+
QWindow *unused = nullptr;
if (!blockingWindow)
blockingWindow = &unused;
+ *blockingWindow = nullptr;
- if (modalWindowList.isEmpty()) {
- *blockingWindow = nullptr;
+ if (modalWindowList.isEmpty() || windowNeverBlocked(window))
return false;
- }
- for (int i = 0; i < modalWindowList.count(); ++i) {
+ for (int i = 0; i < modalWindowList.size(); ++i) {
QWindow *modalWindow = modalWindowList.at(i);
// A window is not blocked by another modal window if the two are
// the same, or if the window is a child of the modal window.
- if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients)) {
- *blockingWindow = nullptr;
+ if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients))
return false;
- }
- Qt::WindowModality windowModality = modalWindow->modality();
- switch (windowModality) {
+ switch (modalWindow->modality() == Qt::NonModal ? defaultModality()
+ : modalWindow->modality()) {
case Qt::ApplicationModal:
- {
- if (modalWindow != window) {
- *blockingWindow = modalWindow;
- return true;
- }
- break;
- }
- case Qt::WindowModal:
- {
- QWindow *w = window;
+ *blockingWindow = modalWindow;
+ return true;
+ case Qt::WindowModal: {
+ // Find the nearest ancestor of window which is also an ancestor of modal window to
+ // determine if the modal window blocks the window.
+ auto *current = window;
do {
- QWindow *m = modalWindow;
- do {
- if (m == w) {
- *blockingWindow = m;
- return true;
- }
- QWindow *p = m->parent();
- if (!p)
- p = m->transientParent();
- m = p;
- } while (m);
- QWindow *p = w->parent();
- if (!p)
- p = w->transientParent();
- w = p;
- } while (w);
+ if (current->isAncestorOf(modalWindow, QWindow::IncludeTransients)) {
+ *blockingWindow = modalWindow;
+ return true;
+ }
+ current = current->parent(QWindow::IncludeTransients);
+ } while (current);
break;
}
default:
@@ -961,13 +957,14 @@ bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blocking
break;
}
}
- *blockingWindow = nullptr;
return false;
}
/*!
Returns the QWindow that receives events tied to focus,
such as key events.
+
+ \sa QWindow::requestActivate()
*/
QWindow *QGuiApplication::focusWindow()
{
@@ -1145,7 +1142,7 @@ qreal QGuiApplication::devicePixelRatio() const
return QGuiApplicationPrivate::m_maxDevicePixelRatio;
QGuiApplicationPrivate::m_maxDevicePixelRatio = 1.0; // make sure we never return 0.
- for (QScreen *screen : qAsConst(QGuiApplicationPrivate::screen_list))
+ for (QScreen *screen : std::as_const(QGuiApplicationPrivate::screen_list))
QGuiApplicationPrivate::m_maxDevicePixelRatio = qMax(QGuiApplicationPrivate::m_maxDevicePixelRatio, screen->devicePixelRatio());
return QGuiApplicationPrivate::m_maxDevicePixelRatio;
@@ -1183,9 +1180,6 @@ QWindow *QGuiApplication::topLevelAt(const QPoint &pos)
EGL and OpenGL ES 2.0 without an actual windowing system (like X11
or Wayland). For more information, see \l{EGLFS}.
\li \c ios (also used for tvOS)
- \li \c kms is an experimental platform plugin using kernel modesetting
- and \l{http://dri.freedesktop.org/wiki/DRM}{DRM} (Direct Rendering
- Manager).
\li \c linuxfb writes directly to the framebuffer. For more information,
see \l{LinuxFB}.
\li \c minimal is provided as an examples for developers who want to
@@ -1193,34 +1187,52 @@ QWindow *QGuiApplication::topLevelAt(const QPoint &pos)
run GUI applications in environments without a GUI, such as servers.
\li \c minimalegl is an example plugin.
\li \c offscreen
- \li \c openwfd
\li \c qnx
\li \c windows
- \li \c wayland is a platform plugin for modern Linux desktops and some
- embedded systems.
- \li \c xcb is the X11 plugin used on regular desktop Linux platforms.
+ \li \c wayland is a platform plugin for the Wayland display server protocol,
+ used on some Linux desktops and embedded systems.
+ \li \c xcb is a plugin for the X11 window system, used on some desktop Linux platforms.
\endlist
+ \note Calling this function without a QGuiApplication will return the default
+ platform name, if available. The default platform name is not affected by the
+ \c{-platform} command line option, or the \c QT_QPA_PLATFORM environment variable.
+
For more information about the platform plugins for embedded Linux devices,
see \l{Qt for Embedded Linux}.
*/
QString QGuiApplication::platformName()
{
- return QGuiApplicationPrivate::platform_name ?
- *QGuiApplicationPrivate::platform_name : QString();
+ if (!QGuiApplication::instance()) {
+#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
+ return QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME);
+#else
+ return QString();
+#endif
+ } else {
+ return QGuiApplicationPrivate::platform_name ?
+ *QGuiApplicationPrivate::platform_name : QString();
+ }
}
Q_LOGGING_CATEGORY(lcQpaPluginLoading, "qt.qpa.plugin");
+Q_LOGGING_CATEGORY(lcQpaTheme, "qt.qpa.theme");
+Q_LOGGING_CATEGORY(lcPtrDispatch, "qt.pointer.dispatch");
static void init_platform(const QString &pluginNamesWithArguments, const QString &platformPluginPath, const QString &platformThemeName, int &argc, char **argv)
{
- QStringList plugins = pluginNamesWithArguments.split(QLatin1Char(';'), Qt::SkipEmptyParts);
+ qCDebug(lcQpaPluginLoading) << "init_platform called with"
+ << "pluginNamesWithArguments" << pluginNamesWithArguments
+ << "platformPluginPath" << platformPluginPath
+ << "platformThemeName" << platformThemeName;
+
+ QStringList plugins = pluginNamesWithArguments.split(u';', Qt::SkipEmptyParts);
QStringList platformArguments;
QStringList availablePlugins = QPlatformIntegrationFactory::keys(platformPluginPath);
for (const auto &pluginArgument : plugins) {
// Split into platform name and arguments
- QStringList arguments = pluginArgument.split(QLatin1Char(':'), Qt::SkipEmptyParts);
+ QStringList arguments = pluginArgument.split(u':', Qt::SkipEmptyParts);
if (arguments.isEmpty())
continue;
const QString name = arguments.takeFirst().toLower();
@@ -1230,10 +1242,16 @@ static void init_platform(const QString &pluginNamesWithArguments, const QString
argumentsKey[0] = argumentsKey.at(0).toUpper();
arguments.append(QLibraryInfo::platformPluginArguments(argumentsKey));
+ qCDebug(lcQpaPluginLoading) << "Attempting to load Qt platform plugin" << name << "with arguments" << arguments;
+
// Create the platform integration.
QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, arguments, argc, argv, platformPluginPath);
if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
if (availablePlugins.contains(name)) {
+ if (name == QStringLiteral("xcb") && QVersionNumber::compare(QLibraryInfo::version(), QVersionNumber(6, 5, 0)) >= 0) {
+ qCWarning(lcQpaPluginLoading).nospace().noquote()
+ << "From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.";
+ }
qCInfo(lcQpaPluginLoading).nospace().noquote()
<< "Could not load the Qt platform plugin \"" << name << "\" in \""
<< QDir::toNativeSeparators(platformPluginPath) << "\" even though it was found.";
@@ -1243,6 +1261,7 @@ static void init_platform(const QString &pluginNamesWithArguments, const QString
<< QDir::toNativeSeparators(platformPluginPath) << "\"";
}
} else {
+ qCDebug(lcQpaPluginLoading) << "Successfully loaded Qt platform plugin" << name;
QGuiApplicationPrivate::platform_name = new QString(name);
platformArguments = arguments;
break;
@@ -1254,7 +1273,7 @@ static void init_platform(const QString &pluginNamesWithArguments, const QString
"Reinstalling the application may fix this problem.\n");
if (!availablePlugins.isEmpty())
- fatalMessage += QStringLiteral("\nAvailable platform plugins are: %1.\n").arg(availablePlugins.join(QLatin1String(", ")));
+ fatalMessage += "\nAvailable platform plugins are: %1.\n"_L1.arg(availablePlugins.join(", "_L1));
#if defined(Q_OS_WIN)
// Windows: Display message box unless it is a console application
@@ -1267,56 +1286,61 @@ static void init_platform(const QString &pluginNamesWithArguments, const QString
return;
}
- // Many platforms have created QScreens at this point. Finish initializing
- // QHighDpiScaling to be prepared for early calls to qt_defaultDpi().
- if (QGuiApplication::primaryScreen()) {
- QGuiApplicationPrivate::highDpiScalingUpdated = true;
- QHighDpiScaling::updateHighDpiScaling();
- }
-
// Create the platform theme:
// 1) Fetch the platform name from the environment if present.
QStringList themeNames;
- if (!platformThemeName.isEmpty())
+ if (!platformThemeName.isEmpty()) {
+ qCDebug(lcQpaTheme) << "Adding" << platformThemeName << "from environment to list of theme names";
themeNames.append(platformThemeName);
+ }
// 2) Special case - check whether it's a flatpak or snap app to use xdg-desktop-portal platform theme for portals support
if (checkNeedPortalSupport()) {
+ qCDebug(lcQpaTheme) << "Adding xdgdesktopportal to list of theme names";
themeNames.append(QStringLiteral("xdgdesktopportal"));
}
// 3) Ask the platform integration for a list of theme names
- themeNames += QGuiApplicationPrivate::platform_integration->themeNames();
+ const auto platformIntegrationThemeNames = QGuiApplicationPrivate::platform_integration->themeNames();
+ qCDebug(lcQpaTheme) << "Adding platform integration's theme names to list of theme names:" << platformIntegrationThemeNames;
+ themeNames += platformIntegrationThemeNames;
// 4) Look for a theme plugin.
- for (const QString &themeName : qAsConst(themeNames)) {
+ for (const QString &themeName : std::as_const(themeNames)) {
+ qCDebug(lcQpaTheme) << "Attempting to create platform theme" << themeName << "via QPlatformThemeFactory::create";
QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath);
- if (QGuiApplicationPrivate::platform_theme)
+ if (QGuiApplicationPrivate::platform_theme) {
+ qCDebug(lcQpaTheme) << "Successfully created platform theme" << themeName;
break;
+ }
}
// 5) If no theme plugin was found ask the platform integration to
// create a theme
if (!QGuiApplicationPrivate::platform_theme) {
- for (const QString &themeName : qAsConst(themeNames)) {
+ for (const QString &themeName : std::as_const(themeNames)) {
+ qCDebug(lcQpaTheme) << "Attempting to create platform theme" << themeName << "via createPlatformTheme";
QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
- if (QGuiApplicationPrivate::platform_theme)
+ if (QGuiApplicationPrivate::platform_theme) {
+ qCDebug(lcQpaTheme) << "Successfully created platform theme" << themeName;
break;
+ }
}
// No error message; not having a theme plugin is allowed.
}
// 6) Fall back on the built-in "null" platform theme.
- if (!QGuiApplicationPrivate::platform_theme)
+ if (!QGuiApplicationPrivate::platform_theme) {
+ qCDebug(lcQpaTheme) << "Failed to create platform theme; using \"null\" platform theme";
QGuiApplicationPrivate::platform_theme = new QPlatformTheme;
+ }
-#ifndef QT_NO_PROPERTIES
// Set arguments as dynamic properties on the native interface as
// boolean 'foo' or strings: 'foo=bar'
if (!platformArguments.isEmpty()) {
if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) {
- for (const QString &argument : qAsConst(platformArguments)) {
- const int equalsPos = argument.indexOf(QLatin1Char('='));
+ for (const QString &argument : std::as_const(platformArguments)) {
+ const qsizetype equalsPos = argument.indexOf(u'=');
const QByteArray name =
equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
const QVariant value =
@@ -1325,22 +1349,24 @@ static void init_platform(const QString &pluginNamesWithArguments, const QString
}
}
}
-#endif
- fontSmoothingGamma = QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
+ const auto platformIntegration = QGuiApplicationPrivate::platformIntegration();
+ fontSmoothingGamma = platformIntegration->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
+ QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus,
+ !QGuiApplication::styleHints()->showShortcutsInContextMenus());
}
static void init_plugins(const QList<QByteArray> &pluginList)
{
- for (int i = 0; i < pluginList.count(); ++i) {
+ for (int i = 0; i < pluginList.size(); ++i) {
QByteArray pluginSpec = pluginList.at(i);
- int colonPos = pluginSpec.indexOf(':');
+ qsizetype colonPos = pluginSpec.indexOf(':');
QObject *plugin;
if (colonPos < 0)
- plugin = QGenericPluginFactory::create(QLatin1String(pluginSpec), QString());
+ plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec), QString());
else
- plugin = QGenericPluginFactory::create(QLatin1String(pluginSpec.mid(0, colonPos)),
- QLatin1String(pluginSpec.mid(colonPos+1)));
+ plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec.mid(0, colonPos)),
+ QLatin1StringView(pluginSpec.mid(colonPos+1)));
if (plugin)
QGuiApplicationPrivate::generic_plugin_list.append(plugin);
else
@@ -1393,11 +1419,11 @@ void QGuiApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options)
QGuiApplication::tr("ID of the X11 Visual to use."), QStringLiteral("id")));
// Not using the "QStringList names" solution for those aliases, because it makes the first column too wide
options->append(QCommandLineOption(QStringLiteral("geometry"),
- QGuiApplication::tr("Alias for --windowgeometry."), QStringLiteral("geometry")));
+ QGuiApplication::tr("Alias for --qwindowgeometry."), QStringLiteral("geometry")));
options->append(QCommandLineOption(QStringLiteral("icon"),
- QGuiApplication::tr("Alias for --windowicon."), QStringLiteral("icon")));
+ QGuiApplication::tr("Alias for --qwindowicon."), QStringLiteral("icon")));
options->append(QCommandLineOption(QStringLiteral("title"),
- QGuiApplication::tr("Alias for --windowtitle."), QStringLiteral("title")));
+ QGuiApplication::tr("Alias for --qwindowtitle."), QStringLiteral("title")));
}
}
#endif // QT_CONFIG(commandlineparser)
@@ -1415,31 +1441,41 @@ void QGuiApplicationPrivate::createPlatformIntegration()
platformName = QT_QPA_DEFAULT_PLATFORM_NAME;
#endif
#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
- QByteArray sessionType = qgetenv("XDG_SESSION_TYPE");
- if (!sessionType.isEmpty()) {
- if (sessionType == QByteArrayLiteral("x11") && !platformName.contains(QByteArrayLiteral("xcb"))) {
- platformName = QByteArrayLiteral("xcb");
- } else if (sessionType == QByteArrayLiteral("wayland") && !platformName.contains(QByteArrayLiteral("wayland"))) {
- QByteArray currentDesktop = qgetenv("XDG_CURRENT_DESKTOP").toLower();
- QByteArray sessionDesktop = qgetenv("XDG_SESSION_DESKTOP").toLower();
- if (currentDesktop.contains("gnome") || sessionDesktop.contains("gnome")) {
- qInfo() << "Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome."
- << "Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.";
- } else {
- platformName = QByteArrayLiteral("wayland");
- }
- }
+ QList<QByteArray> platformArguments = platformName.split(':');
+ QByteArray platformPluginBase = platformArguments.first();
+
+ const bool hasWaylandDisplay = qEnvironmentVariableIsSet("WAYLAND_DISPLAY");
+ const bool isWaylandSessionType = qgetenv("XDG_SESSION_TYPE") == "wayland";
+
+ QVector<QByteArray> preferredPlatformOrder;
+ const bool defaultIsXcb = platformPluginBase == "xcb";
+ const QByteArray xcbPlatformName = defaultIsXcb ? platformName : "xcb";
+ if (qEnvironmentVariableIsSet("DISPLAY")) {
+ preferredPlatformOrder << xcbPlatformName;
+ if (defaultIsXcb)
+ platformName.clear();
}
-#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
- // Add it as fallback in case XDG_SESSION_TYPE is something wrong
- if (!platformName.contains(QT_QPA_DEFAULT_PLATFORM_NAME))
- platformName += QByteArrayLiteral(";" QT_QPA_DEFAULT_PLATFORM_NAME);
-#endif
+
+ const bool defaultIsWayland = !defaultIsXcb && platformPluginBase.startsWith("wayland");
+ const QByteArray waylandPlatformName = defaultIsWayland ? platformName : "wayland";
+ if (hasWaylandDisplay || isWaylandSessionType) {
+ preferredPlatformOrder.prepend(waylandPlatformName);
+
+ if (defaultIsWayland)
+ platformName.clear();
+ }
+
+ if (!platformName.isEmpty())
+ preferredPlatformOrder.append(platformName);
+
+ platformName = preferredPlatformOrder.join(';');
#endif
+ bool platformExplicitlySelected = false;
QByteArray platformNameEnv = qgetenv("QT_QPA_PLATFORM");
if (!platformNameEnv.isEmpty()) {
platformName = platformNameEnv;
+ platformExplicitlySelected = true;
}
QString platformThemeName = QString::fromLocal8Bit(qgetenv("QT_QPA_PLATFORMTHEME"));
@@ -1462,10 +1498,12 @@ void QGuiApplicationPrivate::createPlatformIntegration()
++arg;
if (strcmp(arg, "-platformpluginpath") == 0) {
if (++i < argc)
- platformPluginPath = QString::fromLocal8Bit(argv[i]);
+ platformPluginPath = QFile::decodeName(argv[i]);
} else if (strcmp(arg, "-platform") == 0) {
- if (++i < argc)
+ if (++i < argc) {
+ platformExplicitlySelected = true;
platformName = argv[i];
+ }
} else if (strcmp(arg, "-platformtheme") == 0) {
if (++i < argc)
platformThemeName = QString::fromLocal8Bit(argv[i]);
@@ -1477,7 +1515,7 @@ void QGuiApplicationPrivate::createPlatformIntegration()
firstWindowTitle = QString::fromLocal8Bit(argv[i]);
} else if (strcmp(arg, "-qwindowicon") == 0 || (xcbIsDefault && strcmp(arg, "-icon") == 0)) {
if (++i < argc) {
- icon = QString::fromLocal8Bit(argv[i]);
+ icon = QFile::decodeName(argv[i]);
}
} else {
argv[j++] = argv[i];
@@ -1489,7 +1527,11 @@ void QGuiApplicationPrivate::createPlatformIntegration()
argc = j;
}
- init_platform(QLatin1String(platformName), platformPluginPath, platformThemeName, argc, argv);
+ Q_UNUSED(platformExplicitlySelected);
+
+ init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
+ if (const QPlatformTheme *theme = platformTheme())
+ QStyleHintsPrivate::get(QGuiApplication::styleHints())->setColorScheme(theme->colorScheme());
if (!icon.isEmpty())
forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon);
@@ -1508,7 +1550,11 @@ void QGuiApplicationPrivate::createEventDispatcher()
if (platform_integration == nullptr)
createPlatformIntegration();
- // The platform integration should not mess with the event dispatcher
+ // The platform integration should not result in creating an event dispatcher
+ Q_ASSERT_X(!threadData.loadRelaxed()->eventDispatcher, "QGuiApplication",
+ "Creating the platform integration resulted in creating an event dispatcher");
+
+ // Nor should it mess with the QCoreApplication's event dispatcher
Q_ASSERT(!eventDispatcher);
eventDispatcher = platform_integration->createEventDispatcher();
@@ -1520,14 +1566,9 @@ void QGuiApplicationPrivate::eventDispatcherReady()
createPlatformIntegration();
platform_integration->initialize();
-
- // All platforms should have added screens at this point. Finish
- // QHighDpiScaling initialization if it has not been done so already.
- if (!QGuiApplicationPrivate::highDpiScalingUpdated)
- QHighDpiScaling::updateHighDpiScaling();
}
-void QGuiApplicationPrivate::init()
+void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::init()
{
Q_TRACE_SCOPE(QGuiApplicationPrivate_init);
@@ -1577,12 +1618,12 @@ void QGuiApplicationPrivate::init()
} else if (strncmp(arg, "-psn_", 5) == 0) {
// eat "-psn_xxxx" on Mac, which is passed when starting an app from Finder.
// special hack to change working directory (for an app bundle) when running from finder
- if (QDir::currentPath() == QLatin1String("/")) {
+ if (QDir::currentPath() == "/"_L1) {
QCFType<CFURLRef> bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle()));
QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL,
kCFURLPOSIXPathStyle));
- if (qbundlePath.endsWith(QLatin1String(".app")))
- QDir::setCurrent(qbundlePath.section(QLatin1Char('/'), 0, -2));
+ if (qbundlePath.endsWith(".app"_L1))
+ QDir::setCurrent(qbundlePath.section(u'/', 0, -2));
}
#endif
#ifndef QT_NO_SESSIONMANAGER
@@ -1590,7 +1631,7 @@ void QGuiApplicationPrivate::init()
++i;
if (argv[i] && *argv[i]) {
session_id = QString::fromLatin1(argv[i]);
- int p = session_id.indexOf(QLatin1Char('_'));
+ qsizetype p = session_id.indexOf(u'_');
if (p >= 0) {
session_key = session_id.mid(p +1);
session_id = session_id.left(p);
@@ -1686,8 +1727,8 @@ void QGuiApplicationPrivate::init()
Q_UNUSED(loadTestability);
#endif // QT_CONFIG(library)
- if (layout_direction == Qt::LayoutDirectionAuto || force_reverse)
- QGuiApplication::setLayoutDirection(qt_detectRTLLanguage() ? Qt::RightToLeft : Qt::LeftToRight);
+ // trigger changed signal and event delivery
+ QGuiApplication::setLayoutDirection(layout_direction);
if (!QGuiApplicationPrivate::displayName)
QObject::connect(q, &QGuiApplication::applicationNameChanged,
@@ -1701,7 +1742,7 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate()
is_app_closing = true;
is_app_running = false;
- for (int i = 0; i < generic_plugin_list.count(); ++i)
+ for (int i = 0; i < generic_plugin_list.size(); ++i)
delete generic_plugin_list.at(i);
generic_plugin_list.clear();
@@ -1713,7 +1754,7 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate()
QCursorData::cleanup();
#endif
- layout_direction = Qt::LeftToRight;
+ layout_direction = Qt::LayoutDirectionAuto;
cleanupThreadData();
@@ -1732,6 +1773,10 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate()
}
#endif
+#if QT_CONFIG(vulkan)
+ QVulkanDefaultInstance::cleanup();
+#endif
+
platform_integration->destroy();
delete platform_theme;
@@ -1756,7 +1801,7 @@ void restoreOverrideCursor();
static QFont font();
static QFont font(const QWidget*);
static QFont font(const char *className);
-static void setFont(const QFont &, const char* className = 0);
+static void setFont(const QFont &, const char *className = nullptr);
static QFontMetrics fontMetrics();
#ifndef QT_NO_CLIPBOARD
@@ -1766,7 +1811,7 @@ static QClipboard *clipboard();
/*!
Returns the current state of the modifier keys on the keyboard. The current
- state is updated sychronously as the event queue is emptied of events that
+ state is updated synchronously as the event queue is emptied of events that
will spontaneously change the keyboard state (QEvent::KeyPress and
QEvent::KeyRelease events).
@@ -1802,7 +1847,7 @@ Qt::KeyboardModifiers QGuiApplication::queryKeyboardModifiers()
{
CHECK_QAPP_INSTANCE(Qt::KeyboardModifiers{})
QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
- return pi->queryKeyboardModifiers();
+ return pi->keyMapper()->queryKeyboardModifiers();
}
/*!
@@ -1824,6 +1869,7 @@ Qt::MouseButtons QGuiApplication::mouseButtons()
}
/*!
+ \internal
Returns the platform's native interface, for platform specific
functionality.
*/
@@ -1834,6 +1880,7 @@ QPlatformNativeInterface *QGuiApplication::platformNativeInterface()
}
/*!
+ \internal
Returns a function pointer from the platformplugin matching \a function
*/
QFunctionPointer QGuiApplication::platformFunction(const QByteArray &function)
@@ -1858,9 +1905,10 @@ QFunctionPointer QGuiApplication::platformFunction(const QByteArray &function)
Generally, no user interaction can take place before calling exec().
- To make your application perform idle processing, e.g., executing a special
- function whenever there are no pending events, use a QTimer with 0 timeout.
- More advanced idle processing schemes can be achieved using processEvents().
+ To make your application perform idle processing, e.g., executing a
+ special function whenever there are no pending events, use a QChronoTimer
+ with 0ns timeout. More advanced idle processing schemes can be achieved
+ using processEvents().
We recommend that you connect clean-up code to the
\l{QCoreApplication::}{aboutToQuit()} signal, instead of putting it in your
@@ -1872,12 +1920,66 @@ QFunctionPointer QGuiApplication::platformFunction(const QByteArray &function)
*/
int QGuiApplication::exec()
{
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessible::setRootObject(qApp);
#endif
return QCoreApplication::exec();
}
+void QGuiApplicationPrivate::captureGlobalModifierState(QEvent *e)
+{
+ if (e->spontaneous()) {
+ // Capture the current mouse and keyboard states. Doing so here is
+ // required in order to support Qt Test synthesized events. Real mouse
+ // and keyboard state updates from the platform plugin are managed by
+ // QGuiApplicationPrivate::process(Mouse|Wheel|Key|Touch|Tablet)Event();
+ // ### FIXME: Qt Test should not call qapp->notify(), but rather route
+ // the events through the proper QPA interface. This is required to
+ // properly generate all other events such as enter/leave etc.
+ switch (e->type()) {
+ case QEvent::MouseButtonPress: {
+ QMouseEvent *me = static_cast<QMouseEvent *>(e);
+ QGuiApplicationPrivate::modifier_buttons = me->modifiers();
+ QGuiApplicationPrivate::mouse_buttons |= me->button();
+ break;
+ }
+ case QEvent::MouseButtonDblClick: {
+ QMouseEvent *me = static_cast<QMouseEvent *>(e);
+ QGuiApplicationPrivate::modifier_buttons = me->modifiers();
+ QGuiApplicationPrivate::mouse_buttons |= me->button();
+ break;
+ }
+ case QEvent::MouseButtonRelease: {
+ QMouseEvent *me = static_cast<QMouseEvent *>(e);
+ QGuiApplicationPrivate::modifier_buttons = me->modifiers();
+ QGuiApplicationPrivate::mouse_buttons &= ~me->button();
+ break;
+ }
+ case QEvent::KeyPress:
+ case QEvent::KeyRelease:
+ case QEvent::MouseMove:
+#if QT_CONFIG(wheelevent)
+ case QEvent::Wheel:
+#endif
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+#if QT_CONFIG(tabletevent)
+ case QEvent::TabletMove:
+ case QEvent::TabletPress:
+ case QEvent::TabletRelease:
+#endif
+ {
+ QInputEvent *ie = static_cast<QInputEvent *>(e);
+ QGuiApplicationPrivate::modifier_buttons = ie->modifiers();
+ break;
+ }
+ default:
+ break;
+ }
+ }
+}
+
/*! \reimp
*/
bool QGuiApplication::notify(QObject *object, QEvent *event)
@@ -1887,6 +1989,8 @@ bool QGuiApplication::notify(QObject *object, QEvent *event)
return true; // Platform plugin ate the event
}
+ QGuiApplicationPrivate::captureGlobalModifierState(event);
+
return QCoreApplication::notify(object, event);
}
@@ -1894,19 +1998,24 @@ bool QGuiApplication::notify(QObject *object, QEvent *event)
*/
bool QGuiApplication::event(QEvent *e)
{
- if(e->type() == QEvent::LanguageChange) {
- setLayoutDirection(qt_detectRTLLanguage()?Qt::RightToLeft:Qt::LeftToRight);
+ switch (e->type()) {
+ case QEvent::LanguageChange:
+ // if the layout direction was set explicitly, then don't override it here
+ if (layout_direction == Qt::LayoutDirectionAuto)
+ setLayoutDirection(layout_direction);
for (auto *topLevelWindow : QGuiApplication::topLevelWindows()) {
if (topLevelWindow->flags() != Qt::Desktop)
postEvent(topLevelWindow, new QEvent(QEvent::LanguageChange));
}
- } else if (e->type() == QEvent::ApplicationFontChange ||
- e->type() == QEvent::ApplicationPaletteChange) {
+ break;
+ case QEvent::ApplicationFontChange:
+ case QEvent::ApplicationPaletteChange:
for (auto *topLevelWindow : QGuiApplication::topLevelWindows()) {
if (topLevelWindow->flags() != Qt::Desktop)
postEvent(topLevelWindow, new QEvent(e->type()));
}
- } else if (e->type() == QEvent::Quit) {
+ break;
+ case QEvent::Quit:
// Close open windows. This is done in order to deliver de-expose
// events while the event loop is still running.
for (QWindow *topLevelWindow : QGuiApplication::topLevelWindows()) {
@@ -1918,8 +2027,10 @@ bool QGuiApplication::event(QEvent *e)
return true;
}
}
+ break;
+ default:
+ break;
}
-
return QCoreApplication::event(e);
}
@@ -1945,17 +2056,14 @@ bool QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(QWindow *window,
return platformWindow->windowEvent(event);
}
-#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool QGuiApplicationPrivate::processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result)
-#else
-bool QGuiApplicationPrivate::processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result)
-#endif
{
return window->nativeEvent(eventType, message, result);
}
-void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
+void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
{
+ Q_TRACE_PARAM_REPLACE(QWindowSystemInterfacePrivate::WindowSystemEvent *, int);
Q_TRACE_SCOPE(QGuiApplicationPrivate_processWindowSystemEvent, e->type);
switch(e->type) {
@@ -1980,8 +2088,8 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv
case QWindowSystemInterfacePrivate::Leave:
QGuiApplicationPrivate::processLeaveEvent(static_cast<QWindowSystemInterfacePrivate::LeaveEvent *>(e));
break;
- case QWindowSystemInterfacePrivate::ActivatedWindow:
- QGuiApplicationPrivate::processActivatedEvent(static_cast<QWindowSystemInterfacePrivate::ActivatedWindowEvent *>(e));
+ case QWindowSystemInterfacePrivate::FocusWindow:
+ QGuiApplicationPrivate::processFocusWindowEvent(static_cast<QWindowSystemInterfacePrivate::FocusWindowEvent *>(e));
break;
case QWindowSystemInterfacePrivate::WindowStateChanged:
QGuiApplicationPrivate::processWindowStateChangedEvent(static_cast<QWindowSystemInterfacePrivate::WindowStateChangedEvent *>(e));
@@ -1989,6 +2097,9 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv
case QWindowSystemInterfacePrivate::WindowScreenChanged:
QGuiApplicationPrivate::processWindowScreenChangedEvent(static_cast<QWindowSystemInterfacePrivate::WindowScreenChangedEvent *>(e));
break;
+ case QWindowSystemInterfacePrivate::WindowDevicePixelRatioChanged:
+ QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(static_cast<QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *>(e));
+ break;
case QWindowSystemInterfacePrivate::SafeAreaMarginsChanged:
QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(static_cast<QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *>(e));
break;
@@ -2030,6 +2141,9 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv
case QWindowSystemInterfacePrivate::Expose:
QGuiApplicationPrivate::processExposeEvent(static_cast<QWindowSystemInterfacePrivate::ExposeEvent *>(e));
break;
+ case QWindowSystemInterfacePrivate::Paint:
+ QGuiApplicationPrivate::processPaintEvent(static_cast<QWindowSystemInterfacePrivate::PaintEvent *>(e));
+ break;
case QWindowSystemInterfacePrivate::Tablet:
QGuiApplicationPrivate::processTabletEvent(
static_cast<QWindowSystemInterfacePrivate::TabletEvent *>(e));
@@ -2088,94 +2202,69 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
QEvent::Type type = QEvent::None;
Qt::MouseButton button = Qt::NoButton;
QWindow *window = e->window.data();
+ const QPointingDevice *device = static_cast<const QPointingDevice *>(e->device);
+ Q_ASSERT(device);
+ QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(const_cast<QPointingDevice*>(device));
bool positionChanged = QGuiApplicationPrivate::lastCursorPosition != e->globalPos;
bool mouseMove = false;
bool mousePress = false;
+ const QPointF lastGlobalPosition = QGuiApplicationPrivate::lastCursorPosition;
+ QPointF globalPoint = e->globalPos;
- if (e->enhancedMouseEvent()) {
- type = e->buttonType;
- button = e->button;
-
- if (type == QEvent::NonClientAreaMouseMove || type == QEvent::MouseMove)
- mouseMove = true;
- else if (type == QEvent::NonClientAreaMouseButtonPress || type == QEvent::MouseButtonPress)
- mousePress = true;
-
- if (!mouseMove && positionChanged) {
- QWindowSystemInterfacePrivate::MouseEvent moveEvent(window, e->timestamp,
- e->localPos, e->globalPos, e->buttons ^ button, e->modifiers, Qt::NoButton,
- e->nonClientArea ? QEvent::NonClientAreaMouseMove : QEvent::MouseMove,
- e->source, e->nonClientArea);
- if (e->synthetic())
- moveEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
- processMouseEvent(&moveEvent); // mouse move excluding state change
- processMouseEvent(e); // the original mouse event
- return;
- }
- } else {
- Qt::MouseButtons stateChange = e->buttons ^ mouse_buttons;
- if (positionChanged && (stateChange != Qt::NoButton)) {
- QWindowSystemInterfacePrivate::MouseEvent moveEvent(window, e->timestamp, e->localPos,
- e->globalPos, mouse_buttons, e->modifiers, Qt::NoButton, QEvent::None, e->source,
- e->nonClientArea);
- if (e->synthetic())
- moveEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
- processMouseEvent(&moveEvent); // mouse move excluding state change
- processMouseEvent(e); // the original mouse event
- return;
- }
+ if (qIsNaN(e->globalPos.x()) || qIsNaN(e->globalPos.y())) {
+ qWarning("QGuiApplicationPrivate::processMouseEvent: Got NaN in mouse position");
+ return;
+ }
- // In the compatibility path we deduce event type and button that caused the event
- if (positionChanged) {
- mouseMove = true;
- type = e->nonClientArea ? QEvent::NonClientAreaMouseMove : QEvent::MouseMove;
- } else {
- // Check to see if a new button has been pressed/released.
- for (uint mask = Qt::LeftButton; mask <= Qt::MaxMouseButton; mask <<= 1) {
- if (stateChange & mask) {
- button = Qt::MouseButton(mask);
- break;
- }
- }
- if (button == Qt::NoButton) {
- // Ignore mouse events that don't change the current state. This shouldn't
- // really happen, getting here can only mean that the stored button state
- // is out of sync with the actual physical button state.
- return;
- }
- if (button & e->buttons) {
- mousePress = true;
- type = e->nonClientArea ? QEvent::NonClientAreaMouseButtonPress
- : QEvent::MouseButtonPress;
- } else {
- type = e->nonClientArea ? QEvent::NonClientAreaMouseButtonRelease
- : QEvent::MouseButtonRelease;
- }
- }
+ type = e->buttonType;
+ button = e->button;
+
+ if (type == QEvent::NonClientAreaMouseMove || type == QEvent::MouseMove)
+ mouseMove = true;
+ else if (type == QEvent::NonClientAreaMouseButtonPress || type == QEvent::MouseButtonPress)
+ mousePress = true;
+
+ if (!mouseMove && positionChanged) {
+ QWindowSystemInterfacePrivate::MouseEvent moveEvent(window, e->timestamp,
+ e->localPos, e->globalPos, e->buttons ^ button, e->modifiers, Qt::NoButton,
+ e->nonClientArea ? QEvent::NonClientAreaMouseMove : QEvent::MouseMove,
+ e->source, e->nonClientArea);
+ if (e->synthetic())
+ moveEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
+ processMouseEvent(&moveEvent); // mouse move excluding state change
+ processMouseEvent(e); // the original mouse event
+ return;
+ }
+ if (type == QEvent::MouseMove && !positionChanged) {
+ // On Windows, and possibly other platforms, a touchpad can send a mouse move
+ // that does not change position, between a press and a release. This may
+ // confuse applications, so we always filter out these mouse events for
+ // consistent behavior among platforms.
+ return;
}
modifier_buttons = e->modifiers;
QPointF localPoint = e->localPos;
- QPointF globalPoint = e->globalPos;
bool doubleClick = false;
+ auto persistentEPD = devPriv->pointById(0);
if (mouseMove) {
QGuiApplicationPrivate::lastCursorPosition = globalPoint;
- const auto doubleClickDistance = e->source == Qt::MouseEventNotSynthesized ?
- mouseDoubleClickDistance : touchDoubleTapDistance;
- if (qAbs(globalPoint.x() - mousePressX) > doubleClickDistance ||
- qAbs(globalPoint.y() - mousePressY) > doubleClickDistance)
+ const auto doubleClickDistance = (e->device && e->device->type() == QInputDevice::DeviceType::Mouse ?
+ mouseDoubleClickDistance : touchDoubleTapDistance);
+ const auto pressPos = persistentEPD->eventPoint.globalPressPosition();
+ if (qAbs(globalPoint.x() - pressPos.x()) > doubleClickDistance ||
+ qAbs(globalPoint.y() - pressPos.y()) > doubleClickDistance)
mousePressButton = Qt::NoButton;
} else {
+ static unsigned long lastPressTimestamp = 0;
mouse_buttons = e->buttons;
if (mousePress) {
ulong doubleClickInterval = static_cast<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval());
- doubleClick = e->timestamp - mousePressTime < doubleClickInterval && button == mousePressButton;
- mousePressTime = e->timestamp;
+ doubleClick = e->timestamp - lastPressTimestamp
+ < doubleClickInterval && button == mousePressButton;
mousePressButton = button;
- const QPoint point = QGuiApplicationPrivate::lastCursorPosition.toPoint();
- mousePressX = point.x();
- mousePressY = point.y();
+ lastPressTimestamp = e ->timestamp;
}
}
@@ -2193,8 +2282,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
window = currentMousePressWindow;
currentMousePressWindow = nullptr;
}
- QPointF delta = globalPoint - globalPoint.toPoint();
- localPoint = window->mapFromGlobal(globalPoint.toPoint()) + delta;
+ localPoint = window->mapFromGlobal(globalPoint);
}
}
@@ -2208,16 +2296,24 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
const QPointF nativeLocalPoint = QHighDpi::toNativePixels(localPoint, screen);
const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen);
QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint,
- button, e->buttons, e->modifiers, e->source);
- ev.setTimestamp(e->timestamp);
+ button, e->buttons, e->modifiers, e->source, device);
+ // avoid incorrect velocity calculation: ev is in the native coordinate system,
+ // but we need to consistently use the logical coordinate system for velocity
+ // whenever QEventPoint::setTimestamp() is called
+ ev.QInputEvent::setTimestamp(e->timestamp);
cursor->pointerEvent(ev);
}
}
#endif
- QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source);
+ QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source, device);
+ Q_ASSERT(devPriv->pointById(0) == persistentEPD); // we don't expect reallocation in QPlatformCursor::pointerEvenmt()
+ // restore globalLastPosition to avoid invalidating the velocity calculations,
+ // because the QPlatformCursor mouse event above was in native coordinates
+ QMutableEventPoint::setGlobalLastPosition(persistentEPD->eventPoint, lastGlobalPosition);
+ persistentEPD = nullptr; // incoming and synth events can cause reallocation during delivery, so don't use this again
+ // ev now contains a detached copy of the QEventPoint from QPointingDevicePrivate::activePoints
ev.setTimestamp(e->timestamp);
-
if (window->d_func()->blockedByModalWindow && !qApp->d_func()->popupActive()) {
// a modal window is blocking this window, don't allow mouse events through
return;
@@ -2225,7 +2321,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
// QtBUG-25831, used to suppress delivery in qwidgetwindow.cpp
- setMouseEventFlags(&ev, ev.flags() | Qt::MouseEventCreatedDoubleClick);
+ QMutableSinglePointEvent::from(ev).setDoubleClick();
}
QGuiApplication::sendSpontaneousEvent(window, &ev);
@@ -2233,24 +2329,20 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
if (!e->synthetic() && !ev.isAccepted()
&& !e->nonClientArea
&& qApp->testAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents)) {
- if (!m_fakeTouchDevice) {
- m_fakeTouchDevice = new QPointingDevice;
- QWindowSystemInterface::registerInputDevice(m_fakeTouchDevice);
- }
QList<QWindowSystemInterface::TouchPoint> points;
QWindowSystemInterface::TouchPoint point;
point.id = 1;
- point.area = QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4);
+ point.area = QHighDpi::toNativePixels(QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4), window);
// only translate left button related events to
// avoid strange touch event sequences when several
// buttons are pressed
if (type == QEvent::MouseButtonPress && button == Qt::LeftButton) {
- point.state = Qt::TouchPointPressed;
+ point.state = QEventPoint::State::Pressed;
} else if (type == QEvent::MouseButtonRelease && button == Qt::LeftButton) {
- point.state = Qt::TouchPointReleased;
+ point.state = QEventPoint::State::Released;
} else if (type == QEvent::MouseMove && (e->buttons & Qt::LeftButton)) {
- point.state = Qt::TouchPointMoved;
+ point.state = QEventPoint::State::Updated;
} else {
return;
}
@@ -2258,10 +2350,10 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
points << point;
QEvent::Type type;
- QList<QTouchEvent::TouchPoint> touchPoints =
+ const QList<QEventPoint> &touchPoints =
QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
- QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, m_fakeTouchDevice, touchPoints, e->modifiers);
+ QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, device, touchPoints, e->modifiers);
fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
processTouchEvent(&fake);
}
@@ -2270,11 +2362,17 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
if (!e->window.isNull() || e->nullWindow()) { // QTBUG-36364, check if window closed in response to press
const QEvent::Type doubleClickType = e->nonClientArea ? QEvent::NonClientAreaMouseButtonDblClick : QEvent::MouseButtonDblClick;
QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint,
- button, e->buttons, e->modifiers, e->source);
+ button, e->buttons, e->modifiers, e->source, device);
dblClickEvent.setTimestamp(e->timestamp);
QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent);
}
}
+ if (type == QEvent::MouseButtonRelease && e->buttons == Qt::NoButton) {
+ if (auto *persistentEPD = devPriv->queryPointById(0)) {
+ ev.setExclusiveGrabber(persistentEPD->eventPoint, nullptr);
+ ev.clearPassiveGrabbers(persistentEPD->eventPoint);
+ }
+ }
}
void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e)
@@ -2286,10 +2384,8 @@ void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wh
if (e->nullWindow()) {
window = QGuiApplication::topLevelAt(globalPoint.toPoint());
- if (window) {
- QPointF delta = globalPoint - globalPoint.toPoint();
- localPoint = window->mapFromGlobal(globalPoint.toPoint()) + delta;
- }
+ if (window)
+ localPoint = window->mapFromGlobal(globalPoint);
}
if (!window)
@@ -2303,10 +2399,12 @@ void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wh
return;
}
- QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
- mouse_buttons, e->modifiers, e->phase, e->inverted, e->source);
- ev.setTimestamp(e->timestamp);
- QGuiApplication::sendSpontaneousEvent(window, &ev);
+ const QPointingDevice *device = static_cast<const QPointingDevice *>(e->device);
+ QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
+ mouse_buttons, e->modifiers, e->phase, e->inverted, e->source, device);
+ ev.setTimestamp(e->timestamp);
+ QGuiApplication::sendSpontaneousEvent(window, &ev);
+ e->eventAccepted = ev.isAccepted();
#else
Q_UNUSED(e);
#endif // QT_CONFIG(wheelevent)
@@ -2317,7 +2415,7 @@ void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyE
QWindow *window = e->window.data();
modifier_buttons = e->modifiers;
if (e->nullWindow()
-#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
+#ifdef Q_OS_ANDROID
|| e->key == Qt::Key_Back || e->key == Qt::Key_Menu
#endif
) {
@@ -2353,7 +2451,7 @@ void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyE
if (window && !window->d_func()->blockedByModalWindow)
QGuiApplication::sendSpontaneousEvent(window, &ev);
-#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
+#ifdef Q_OS_ANDROID
else
ev.setAccepted(false);
@@ -2383,7 +2481,19 @@ void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::En
currentMouseWindow = e->enter;
+ // TODO later: EnterEvent must report _which_ mouse entered the window; for now we assume primaryPointingDevice()
QEnterEvent event(e->localPos, e->localPos, e->globalPos);
+
+ // Since we don't always track mouse moves that occur outside a window, any residual velocity
+ // stored in the persistent QEventPoint may be inaccurate (especially in fast-moving autotests).
+ // Reset the Kalman filter so that the velocity of the first mouse event after entering the window
+ // will be based on a zero residual velocity (but the result can still be non-zero if the mouse
+ // moves to a different position from where this enter event occurred; tests often do that).
+ const QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(event.pointingDevice());
+ auto epd = devPriv->queryPointById(event.points().first().id());
+ Q_ASSERT(epd);
+ QMutableEventPoint::setVelocity(epd->eventPoint, {});
+
QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
}
@@ -2402,10 +2512,10 @@ void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::Le
QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
}
-void QGuiApplicationPrivate::processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *e)
+void QGuiApplicationPrivate::processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e)
{
QWindow *previous = QGuiApplicationPrivate::focus_window;
- QWindow *newFocus = e->activated.data();
+ QWindow *newFocus = e->focused.data();
if (previous == newFocus)
return;
@@ -2455,8 +2565,15 @@ void QGuiApplicationPrivate::processActivatedEvent(QWindowSystemInterfacePrivate
if (self) {
self->notifyActiveWindowChange(previous);
- if (previousFocusObject != qApp->focusObject())
+ if (previousFocusObject != qApp->focusObject() ||
+ // We are getting an activation change but there is no new focusObject, and we also
+ // don't have a previousFocusObject in the previously active window anymore. This can
+ // happen when window gets destroyed (see QWidgetWindow::focusObject returning nullptr
+ // when already in the QWidget destructor), so update the focusObject to avoid dangling
+ // pointers. See also QWidget::clearFocus(), which tries to cover for this as well.
+ (previous && previousFocusObject == nullptr && qApp->focusObject() == nullptr)) {
self->_q_updateFocusObject(qApp->focusObject());
+ }
}
emit qApp->focusWindowChanged(newFocus);
@@ -2468,32 +2585,46 @@ void QGuiApplicationPrivate::processActivatedEvent(QWindowSystemInterfacePrivate
void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *wse)
{
- if (QWindow *window = wse->window.data()) {
+ if (QWindow *window = wse->window.data()) {
+ QWindowPrivate *windowPrivate = qt_window_private(window);
+ const auto originalEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
+
+ windowPrivate->windowState = wse->newState;
+ const auto newEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
+ if (newEffectiveState != originalEffectiveState)
+ emit window->windowStateChanged(newEffectiveState);
+
+ windowPrivate->updateVisibility();
+
QWindowStateChangeEvent e(wse->oldState);
- window->d_func()->windowState = wse->newState;
QGuiApplication::sendSpontaneousEvent(window, &e);
}
}
void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *wse)
{
- if (QWindow *window = wse->window.data()) {
- if (window->screen() == wse->screen.data())
- return;
- if (QWindow *topLevelWindow = window->d_func()->topLevelWindow(QWindow::ExcludeTransients)) {
- if (QScreen *screen = wse->screen.data())
- topLevelWindow->d_func()->setTopLevelScreen(screen, false /* recreate */);
- else // Fall back to default behavior, and try to find some appropriate screen
- topLevelWindow->setScreen(nullptr);
- }
- // we may have changed scaling, so trigger resize event if needed
- if (window->handle()) {
- QWindowSystemInterfacePrivate::GeometryChangeEvent gce(window, QHighDpi::fromNativePixels(window->handle()->geometry(), window));
- processGeometryChangeEvent(&gce);
- }
+ QWindow *window = wse->window.data();
+ if (!window)
+ return;
+
+ if (window->screen() == wse->screen.data())
+ return;
+
+ if (QWindow *topLevelWindow = window->d_func()->topLevelWindow(QWindow::ExcludeTransients)) {
+ if (QScreen *screen = wse->screen.data())
+ topLevelWindow->d_func()->setTopLevelScreen(screen, false /* recreate */);
+ else // Fall back to default behavior, and try to find some appropriate screen
+ topLevelWindow->setScreen(nullptr);
}
}
+void QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *wde)
+{
+ if (wde->window.isNull())
+ return;
+ QWindowPrivate::get(wde->window)->updateDevicePixelRatio();
+}
+
void QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *wse)
{
if (wse->window.isNull())
@@ -2508,11 +2639,43 @@ void QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(QWindowSystemInt
void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce)
{
if (self)
- self->notifyThemeChanged();
- if (QWindow *window = tce->window.data()) {
- QEvent e(QEvent::ThemeChange);
- QGuiApplication::sendSpontaneousEvent(window, &e);
+ self->handleThemeChanged();
+
+ QIconPrivate::clearIconCache();
+
+ QStyleHintsPrivate::get(QGuiApplication::styleHints())->setColorScheme(colorScheme());
+
+ QEvent themeChangeEvent(QEvent::ThemeChange);
+ const QWindowList windows = tce->window ? QWindowList{tce->window} : window_list;
+ for (auto *window : windows)
+ QGuiApplication::sendSpontaneousEvent(window, &themeChangeEvent);
+}
+
+/*!
+ \internal
+ \brief QGuiApplicationPrivate::colorScheme
+ \return the platform theme's color scheme
+ or Qt::ColorScheme::Unknown if a platform theme cannot be established
+ */
+Qt::ColorScheme QGuiApplicationPrivate::colorScheme()
+{
+ return platformTheme() ? platformTheme()->colorScheme()
+ : Qt::ColorScheme::Unknown;
+}
+
+void QGuiApplicationPrivate::handleThemeChanged()
+{
+ updatePalette();
+
+ QIconLoader::instance()->updateSystemTheme();
+ QAbstractFileIconProviderPrivate::clearIconTypeCache();
+
+ if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
+ const auto locker = qt_scoped_lock(applicationFontMutex);
+ clearFontUnlocked();
+ initFontUnlocked();
}
+ initThemeHints();
}
void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e)
@@ -2571,8 +2734,10 @@ void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::Cl
{
if (e->window.isNull())
return;
- if (e->window.data()->d_func()->blockedByModalWindow) {
- // a modal window is blocking this window, don't allow close events through
+ if (e->window.data()->d_func()->blockedByModalWindow && !e->window.data()->d_func()->inClose) {
+ // a modal window is blocking this window, don't allow close events through, unless they
+ // originate from a call to QWindow::close.
+ e->eventAccepted = false;
return;
}
@@ -2675,12 +2840,14 @@ void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::T
}
}();
QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local,
- e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventSynthesizedByQt);
+ e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized, false, device);
mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
+ qCDebug(lcPtrDispatch) << "synthesizing mouse from tablet event" << mouseType
+ << e->local << button << e->buttons << e->modifiers;
processMouseEvent(&mouseEvent);
}
#else
- Q_UNUSED(e)
+ Q_UNUSED(e);
#endif
}
@@ -2694,7 +2861,7 @@ void QGuiApplicationPrivate::processTabletEnterProximityEvent(QWindowSystemInter
ev.setTimestamp(e->timestamp);
QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
#else
- Q_UNUSED(e)
+ Q_UNUSED(e);
#endif
}
@@ -2708,7 +2875,7 @@ void QGuiApplicationPrivate::processTabletLeaveProximityEvent(QWindowSystemInter
ev.setTimestamp(e->timestamp);
QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
#else
- Q_UNUSED(e)
+ Q_UNUSED(e);
#endif
}
@@ -2718,7 +2885,9 @@ void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate::
if (e->window.isNull())
return;
- QNativeGestureEvent ev(e->type, e->device, e->pos, e->pos, e->globalPos, e->realValue, e->sequenceId, e->intValue);
+ const QPointingDevice *device = static_cast<const QPointingDevice *>(e->device);
+ QNativeGestureEvent ev(e->type, device, e->fingerCount, e->pos, e->pos, e->globalPos, (e->intValue ? e->intValue : e->realValue),
+ e->delta, e->sequenceId);
ev.setTimestamp(e->timestamp);
QGuiApplication::sendSpontaneousEvent(e->window, &ev);
}
@@ -2751,42 +2920,31 @@ void QGuiApplicationPrivate::processContextMenuEvent(QWindowSystemInterfacePriva
}
#endif
-Q_GUI_EXPORT size_t qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k, size_t seed)
-{
- return (qHash(k.device) + k.touchPointId) ^ seed;
-}
-
-Q_GUI_EXPORT bool operator==(const QGuiApplicationPrivate::ActiveTouchPointsKey &a,
- const QGuiApplicationPrivate::ActiveTouchPointsKey &b)
-{
- return a.device == b.device
- && a.touchPointId == b.touchPointId;
-}
-
void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e)
{
- QGuiApplicationPrivate *d = self;
+ if (!QInputDevicePrivate::isRegistered(e->device))
+ return;
+
modifier_buttons = e->modifiers;
+ QPointingDevice *device = const_cast<QPointingDevice *>(static_cast<const QPointingDevice *>(e->device));
+ QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(device);
if (e->touchType == QEvent::TouchCancel) {
// The touch sequence has been canceled (e.g. by the compositor).
// Send the TouchCancel to all windows with active touches and clean up.
- QTouchEvent touchEvent(QEvent::TouchCancel, static_cast<const QPointingDevice *>(e->device), e->modifiers);
+ QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
touchEvent.setTimestamp(e->timestamp);
- QHash<ActiveTouchPointsKey, ActiveTouchPointsValue>::const_iterator it
- = self->activeTouchPoints.constBegin(), ite = self->activeTouchPoints.constEnd();
- QSet<QWindow *> windowsNeedingCancel;
- while (it != ite) {
- QWindow *w = it->window.data();
- if (w)
+ constexpr qsizetype Prealloc = decltype(devPriv->activePoints)::mapped_container_type::PreallocatedSize;
+ QMinimalVarLengthFlatSet<QWindow *, Prealloc> windowsNeedingCancel;
+
+ for (auto &epd : devPriv->activePoints.values()) {
+ if (QWindow *w = QMutableEventPoint::window(epd.eventPoint))
windowsNeedingCancel.insert(w);
- ++it;
- }
- for (QSet<QWindow *>::const_iterator winIt = windowsNeedingCancel.constBegin(),
- winItEnd = windowsNeedingCancel.constEnd(); winIt != winItEnd; ++winIt) {
- touchEvent.setWindow(*winIt);
- QGuiApplication::sendSpontaneousEvent(*winIt, &touchEvent);
}
+
+ for (QWindow *w : windowsNeedingCancel)
+ QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
+
if (!self->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
for (QHash<QWindow *, SynthesizedMouseData>::const_iterator synthIt = self->synthesizedMousePoints.constBegin(),
synthItEnd = self->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
@@ -2800,13 +2958,14 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
e->modifiers,
Qt::LeftButton,
QEvent::MouseButtonRelease,
- Qt::MouseEventSynthesizedByQt);
+ Qt::MouseEventNotSynthesized,
+ false,
+ device);
fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
processMouseEvent(&fake);
}
self->synthesizedMousePoints.clear();
}
- self->activeTouchPoints.clear();
self->lastTouchType = e->touchType;
return;
}
@@ -2817,244 +2976,177 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
self->lastTouchType = e->touchType;
- QWindow *window = e->window.data();
- typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints;
- QHash<QWindow *, StatesAndTouchPoints> windowsNeedingEvents;
- bool stationaryTouchPointChangedProperty = false;
-
- for (int i = 0; i < e->points.count(); ++i) {
- QTouchEvent::TouchPoint touchPoint = e->points.at(i);
- // explicitly detach from the original touch point that we got, so even
- // if the touchpoint structs are reused, we will make a copy that we'll
- // deliver to the user (which might want to store the struct for later use).
- touchPoint.d = touchPoint.d->detach();
+ QPointer<QWindow> window = e->window; // the platform hopefully tells us which window received the event
+ QVarLengthArray<QMutableTouchEvent, 2> touchEvents;
+ // For each temporary QEventPoint from the QPA TouchEvent:
+ // - update the persistent QEventPoint in QPointingDevicePrivate::activePoints with current values
+ // - determine which window to deliver it to
+ // - add it to the QTouchEvent instance for that window (QMutableTouchEvent::target() will be QWindow*, for now)
+ for (auto &tempPt : e->points) {
// update state
- QPointer<QWindow> w;
- QTouchEvent::TouchPoint previousTouchPoint;
- ActiveTouchPointsKey touchInfoKey(static_cast<const QPointingDevice *>(e->device), touchPoint.id());
- ActiveTouchPointsValue &touchInfo = d->activeTouchPoints[touchInfoKey];
- switch (touchPoint.state()) {
- case Qt::TouchPointPressed:
- if (e->device->type() == QInputDevice::DeviceType::TouchPad) {
- // on touch-pads, send all touch points to the same widget
- w = d->activeTouchPoints.isEmpty()
- ? QPointer<QWindow>()
- : d->activeTouchPoints.constBegin().value().window;
- }
-
- if (!w) {
- // determine which window this event will go to
- if (!window)
- window = QGuiApplication::topLevelAt(touchPoint.globalPosition().toPoint());
- if (!window)
- continue;
- w = window;
- }
+ auto epd = devPriv->pointById(tempPt.id());
+ auto &ep = epd->eventPoint;
+ epd->eventPoint.setAccepted(false);
+ switch (tempPt.state()) {
+ case QEventPoint::State::Pressed:
+ // On touchpads, send all touch points to the same window.
+ if (!window && e->device && e->device->type() == QInputDevice::DeviceType::TouchPad)
+ window = devPriv->firstActiveWindow();
+ // If the QPA event didn't tell us which window, find the one under the touchpoint position.
+ if (!window)
+ window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
+ QMutableEventPoint::setWindow(ep, window);
+ break;
- touchInfo.window = w;
- touchPoint.d->startScreenPos = touchPoint.globalPosition();
- touchPoint.d->lastScreenPos = touchPoint.globalPosition();
- touchPoint.d->startNormalizedPos = touchPoint.normalizedPos();
- touchPoint.d->lastNormalizedPos = touchPoint.normalizedPos();
- if (touchPoint.pressure() < qreal(0.))
- touchPoint.d->pressure = qreal(1.);
+ case QEventPoint::State::Released:
+ if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
+ qCDebug(lcPtrDispatch) << "delivering touch release to same window"
+ << QMutableEventPoint::window(ep) << "not" << window.data();
+ window = QMutableEventPoint::window(ep);
+ break;
- touchInfo.touchPoint = touchPoint;
+ default: // update or stationary
+ if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
+ qCDebug(lcPtrDispatch) << "delivering touch update to same window"
+ << QMutableEventPoint::window(ep) << "not" << window.data();
+ window = QMutableEventPoint::window(ep);
break;
+ }
+ // If we somehow still don't have a window, we can't deliver this touchpoint. (should never happen)
+ if (Q_UNLIKELY(!window)) {
+ qCWarning(lcPtrDispatch) << "skipping" << &tempPt << ": no target window";
+ continue;
+ }
+ QMutableEventPoint::update(tempPt, ep);
- case Qt::TouchPointReleased:
- w = touchInfo.window;
- if (!w)
- continue;
+ Q_ASSERT(window.data() != nullptr);
- previousTouchPoint = touchInfo.touchPoint;
- touchPoint.d->startScreenPos = previousTouchPoint.globalPressPosition();
- touchPoint.d->lastScreenPos = previousTouchPoint.globalPosition();
- touchPoint.d->startPos = previousTouchPoint.pressPosition();
- touchPoint.d->lastPos = previousTouchPoint.position();
- touchPoint.d->startNormalizedPos = previousTouchPoint.startNormalizedPos();
- touchPoint.d->lastNormalizedPos = previousTouchPoint.normalizedPos();
- if (touchPoint.pressure() < qreal(0.))
- touchPoint.d->pressure = qreal(0.);
+ // make the *scene* position the same as the *global* position
+ QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
- break;
+ // store the scene position as local position, for now
+ QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
- default:
- w = touchInfo.window;
- if (!w)
- continue;
+ // setTimeStamp has side effects, so we do it last
+ QMutableEventPoint::setTimestamp(ep, e->timestamp);
- previousTouchPoint = touchInfo.touchPoint;
- touchPoint.d->startScreenPos = previousTouchPoint.globalPressPosition();
- touchPoint.d->lastScreenPos = previousTouchPoint.globalPosition();
- touchPoint.d->startPos = previousTouchPoint.pressPosition();
- touchPoint.d->lastPos = previousTouchPoint.position();
- touchPoint.d->startNormalizedPos = previousTouchPoint.startNormalizedPos();
- touchPoint.d->lastNormalizedPos = previousTouchPoint.normalizedPos();
- if (touchPoint.pressure() < qreal(0.))
- touchPoint.d->pressure = qreal(1.);
-
- // Stationary points might not be delivered down to the receiving item
- // and get their position transformed, keep the old values instead.
- if (touchPoint.state() == Qt::TouchPointStationary) {
- if (touchInfo.touchPoint.velocity() != touchPoint.velocity()) {
- touchInfo.touchPoint.setVelocity(touchPoint.velocity());
- touchPoint.d->stationaryWithModifiedProperty = true;
- stationaryTouchPointChangedProperty = true;
- }
- if (!qFuzzyCompare(touchInfo.touchPoint.pressure(), touchPoint.pressure())) {
- touchInfo.touchPoint.setPressure(touchPoint.pressure());
- touchPoint.d->stationaryWithModifiedProperty = true;
- stationaryTouchPointChangedProperty = true;
- }
- } else {
- touchInfo.touchPoint = touchPoint;
+ // add the touchpoint to the event that will be delivered to the window
+ bool added = false;
+ for (QMutableTouchEvent &ev : touchEvents) {
+ if (ev.target() == window.data()) {
+ ev.addPoint(ep);
+ added = true;
+ break;
}
- break;
}
-
- Q_ASSERT(w.data() != nullptr);
-
- // make the *scene* functions return the same as the *screen* functions
- // Note: touchPoint is a reference to the one from activeTouchPoints,
- // so we can modify it as long as we're careful NOT to call setters and
- // otherwise NOT to cause the d-pointer to be detached.
- touchPoint.d->scenePos = touchPoint.globalPosition();
- touchPoint.d->startScenePos = touchPoint.globalPressPosition();
- touchPoint.d->lastScenePos = touchPoint.lastScreenPos();
-
- StatesAndTouchPoints &maskAndPoints = windowsNeedingEvents[w.data()];
- maskAndPoints.first |= touchPoint.state();
- maskAndPoints.second.append(touchPoint);
+ if (!added) {
+ QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
+ mte.setTimestamp(e->timestamp);
+ mte.setTarget(window.data());
+ touchEvents.append(mte);
+ }
}
- if (windowsNeedingEvents.isEmpty())
+ if (touchEvents.isEmpty())
return;
- QHash<QWindow *, StatesAndTouchPoints>::ConstIterator it = windowsNeedingEvents.constBegin();
- const QHash<QWindow *, StatesAndTouchPoints>::ConstIterator end = windowsNeedingEvents.constEnd();
- for (; it != end; ++it) {
- QWindow *w = it.key();
+ for (QMutableTouchEvent &touchEvent : touchEvents) {
+ QWindow *window = static_cast<QWindow *>(touchEvent.target());
QEvent::Type eventType;
- switch (it.value().first) {
- case Qt::TouchPointPressed:
+ switch (touchEvent.touchPointStates()) {
+ case QEventPoint::State::Pressed:
eventType = QEvent::TouchBegin;
break;
- case Qt::TouchPointReleased:
+ case QEventPoint::State::Released:
eventType = QEvent::TouchEnd;
break;
- case Qt::TouchPointStationary:
- // don't send the event if nothing changed
- if (!stationaryTouchPointChangedProperty)
- continue;
- Q_FALLTHROUGH();
default:
eventType = QEvent::TouchUpdate;
break;
}
- if (w->d_func()->blockedByModalWindow && !qApp->d_func()->popupActive()) {
+ if (window->d_func()->blockedByModalWindow && !qApp->d_func()->popupActive()) {
// a modal window is blocking this window, don't allow touch events through
- // QTBUG-37371 temporary fix; TODO: revisit in 5.4 when we have a forwarding solution
- if (eventType == QEvent::TouchEnd) {
+ // QTBUG-37371 temporary fix; TODO: revisit when we have a forwarding solution
+ if (touchEvent.type() == QEvent::TouchEnd) {
// but don't leave dangling state: e.g.
// QQuickWindowPrivate::itemForTouchPointId needs to be cleared.
- QTouchEvent touchEvent(QEvent::TouchCancel,
- static_cast<const QPointingDevice *>(e->device),
- e->modifiers);
+ QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
touchEvent.setTimestamp(e->timestamp);
- touchEvent.setWindow(w);
- QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
+ QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
}
continue;
}
- QTouchEvent touchEvent(eventType,
- static_cast<const QPointingDevice *>(e->device),
- e->modifiers,
- it.value().first, // state flags
- it.value().second); // list of touchpoints
- touchEvent.setTimestamp(e->timestamp);
- touchEvent.setWindow(w);
-
- const int pointCount = touchEvent.touchPoints().count();
- for (int i = 0; i < pointCount; ++i) {
- QTouchEvent::TouchPoint &touchPoint = touchEvent._touchPoints[i];
-
- // preserve the sub-pixel resolution
- const QPointF screenPos = touchPoint.globalPosition();
- const QPointF delta = screenPos - screenPos.toPoint();
-
- touchPoint.d->pos = w->mapFromGlobal(screenPos.toPoint()) + delta;
- if (touchPoint.state() == Qt::TouchPointPressed) {
- // touchPoint is actually a reference to one that is stored in activeTouchPoints,
- // and we are now going to store the startPos and lastPos there, for the benefit
- // of future moves and releases. It's important that the d-pointer is NOT detached.
- touchPoint.d->startPos = w->mapFromGlobal(touchPoint.globalPressPosition().toPoint()) + delta;
- touchPoint.d->lastPos = w->mapFromGlobal(touchPoint.lastScreenPos().toPoint()) + delta;
- }
- }
+ // Note: after the call to sendSpontaneousEvent, touchEvent.position() will have
+ // changed to reflect the local position inside the last (random) widget it tried
+ // to deliver the touch event to, and will therefore be invalid afterwards.
+ QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
- QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
if (!e->synthetic() && !touchEvent.isAccepted() && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
// exclude devices which generate their own mouse events
if (!(touchEvent.device()->capabilities().testFlag(QInputDevice::Capability::MouseEmulation))) {
- if (eventType == QEvent::TouchEnd)
- self->synthesizedMousePoints.clear();
-
- const QList<QTouchEvent::TouchPoint> &touchPoints = touchEvent.touchPoints();
- if (eventType == QEvent::TouchBegin)
- m_fakeMouseSourcePointId = touchPoints.first().id();
-
- const QEvent::Type mouseType = [&]() {
- switch (eventType) {
- case QEvent::TouchBegin: return QEvent::MouseButtonPress;
- case QEvent::TouchUpdate: return QEvent::MouseMove;
- case QEvent::TouchEnd: return QEvent::MouseButtonRelease;
- default: Q_UNREACHABLE();
- }
- }();
-
- Qt::MouseButton button = mouseType == QEvent::MouseMove ? Qt::NoButton : Qt::LeftButton;
- Qt::MouseButtons buttons = mouseType == QEvent::MouseButtonRelease ? Qt::NoButton : Qt::LeftButton;
-
- for (int i = 0; i < touchPoints.count(); ++i) {
- const QTouchEvent::TouchPoint &touchPoint = touchPoints.at(i);
- if (touchPoint.id() == m_fakeMouseSourcePointId) {
- if (eventType != QEvent::TouchEnd)
- self->synthesizedMousePoints.insert(w, SynthesizedMouseData(
- touchPoint.position(), touchPoint.globalPosition(), w));
+ QEvent::Type mouseEventType = QEvent::MouseMove;
+ Qt::MouseButton button = Qt::NoButton;
+ Qt::MouseButtons buttons = Qt::LeftButton;
+ if (eventType == QEvent::TouchBegin || m_fakeMouseSourcePointId < 0) {
+ m_fakeMouseSourcePointId = touchEvent.point(0).id();
+ qCDebug(lcPtrDispatch) << "synthesizing mouse events from touchpoint" << m_fakeMouseSourcePointId;
+ }
+ if (m_fakeMouseSourcePointId >= 0) {
+ const auto *touchPoint = touchEvent.pointById(m_fakeMouseSourcePointId);
+ if (touchPoint) {
+ switch (touchPoint->state()) {
+ case QEventPoint::State::Pressed:
+ mouseEventType = QEvent::MouseButtonPress;
+ button = Qt::LeftButton;
+ break;
+ case QEventPoint::State::Released:
+ mouseEventType = QEvent::MouseButtonRelease;
+ button = Qt::LeftButton;
+ buttons = Qt::NoButton;
+ Q_ASSERT(m_fakeMouseSourcePointId == touchPoint->id());
+ m_fakeMouseSourcePointId = -1;
+ break;
+ default:
+ break;
+ }
+ if (touchPoint->state() != QEventPoint::State::Released) {
+ self->synthesizedMousePoints.insert(window, SynthesizedMouseData(
+ touchPoint->position(), touchPoint->globalPosition(), window));
+ }
// All touch events that are not accepted by the application will be translated to
// left mouse button events instead (see AA_SynthesizeMouseForUnhandledTouchEvents docs).
- QWindowSystemInterfacePrivate::MouseEvent fake(w, e->timestamp,
- touchPoint.position(),
- touchPoint.globalPosition(),
+ // TODO why go through QPA? Why not just send a QMouseEvent right from here?
+ QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp,
+ window->mapFromGlobal(touchPoint->globalPosition().toPoint()),
+ touchPoint->globalPosition(),
buttons,
e->modifiers,
button,
- mouseType,
- Qt::MouseEventSynthesizedByQt);
+ mouseEventType,
+ Qt::MouseEventSynthesizedByQt,
+ false,
+ device);
fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
processMouseEvent(&fake);
- break;
}
}
+ if (eventType == QEvent::TouchEnd)
+ self->synthesizedMousePoints.clear();
}
}
}
- // Remove released points from the hash table only after the event is
- // delivered. When the receiver is a widget, QApplication will access
- // activeTouchPoints during delivery and therefore nothing can be removed
- // before sending the event.
- for (int i = 0; i < e->points.count(); ++i) {
- QTouchEvent::TouchPoint touchPoint = e->points.at(i);
- if (touchPoint.state() == Qt::TouchPointReleased)
- d->activeTouchPoints.remove(ActiveTouchPointsKey(static_cast<const QPointingDevice *>(e->device), touchPoint.id()));
+ // Remove released points from QPointingDevicePrivate::activePoints only after the event is
+ // delivered. Widgets and Qt Quick are allowed to access them at any time before this.
+ for (const QEventPoint &touchPoint : e->points) {
+ if (touchPoint.state() == QEventPoint::State::Released)
+ devPriv->removePointById(touchPoint.id());
}
}
@@ -3085,29 +3177,18 @@ void QGuiApplicationPrivate::processScreenGeometryChange(QWindowSystemInterfaceP
if (!e->screen)
return;
- QScreen *s = e->screen.data();
-
- bool geometryChanged = e->geometry != s->d_func()->geometry;
- s->d_func()->geometry = e->geometry;
+ {
+ QScreen *s = e->screen.data();
+ QScreenPrivate::UpdateEmitter updateEmitter(s);
- bool availableGeometryChanged = e->availableGeometry != s->d_func()->availableGeometry;
- s->d_func()->availableGeometry = e->availableGeometry;
+ // Note: The incoming geometries have already been scaled by QHighDpi
+ // in the QWSI layer, so we don't need to call updateGeometry() here.
+ s->d_func()->geometry = e->geometry;
+ s->d_func()->availableGeometry = e->availableGeometry;
- if (geometryChanged) {
- Qt::ScreenOrientation primaryOrientation = s->primaryOrientation();
s->d_func()->updatePrimaryOrientation();
-
- emit s->geometryChanged(s->geometry());
- emit s->physicalSizeChanged(s->physicalSize());
- emit s->physicalDotsPerInchChanged(s->physicalDotsPerInch());
- emit s->logicalDotsPerInchChanged(s->logicalDotsPerInch());
-
- if (s->primaryOrientation() != primaryOrientation)
- emit s->primaryOrientationChanged(s->primaryOrientation());
}
- s->d_func()->emitGeometryChangeSignals(geometryChanged, availableGeometryChanged);
-
resetCachedDevicePixelRatio();
}
@@ -3117,14 +3198,21 @@ void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystem
if (QCoreApplication::startingUp())
return;
+ QHighDpiScaling::updateHighDpiScaling();
+
if (!e->screen)
return;
- QScreen *s = e->screen.data();
- s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
+ {
+ QScreen *s = e->screen.data();
+ QScreenPrivate::UpdateEmitter updateEmitter(s);
+ s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
+ s->d_func()->updateGeometry();
+ }
- emit s->logicalDotsPerInchChanged(s->logicalDotsPerInch());
- s->d_func()->updateGeometriesWithSignals();
+ for (QWindow *window : QGuiApplication::allWindows())
+ if (window->screen() == e->screen)
+ QWindowPrivate::get(window)->updateDevicePixelRatio();
resetCachedDevicePixelRatio();
}
@@ -3169,13 +3257,72 @@ void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::E
p->resizeEventPending = false;
}
+ // FIXME: It would logically make sense to set this _after_ we've sent the
+ // expose event to the window, to mark that it now has received an expose.
+ // But some parts of Qt (mis)use this private member to check whether the
+ // window has been mapped yet, which they do in code that is triggered
+ // by the very same expose event we send below. To keep the code working
+ // we need to set the variable up front, until the code has been fixed.
p->receivedExpose = true;
}
+ // If the platform does not send paint events we need to synthesize them from expose events
+ const bool shouldSynthesizePaintEvents = !platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents);
+
+ const bool wasExposed = p->exposed;
p->exposed = e->isExposed && window->screen();
+ // We expect that the platform plugins send DevicePixelRatioChange events.
+ // As a fail-safe make a final check here to make sure the cached DPR value is
+ // always up to date before sending the expose event.
+ if (e->isExposed && !e->region.isEmpty()) {
+ const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio();
+ if (dprWasChanged)
+ qWarning() << "The cached device pixel ratio value was stale on window expose. "
+ << "Please file a QTBUG which explains how to reproduce.";
+ }
+
+ // We treat expose events for an already exposed window as paint events
+ if (wasExposed && p->exposed && shouldSynthesizePaintEvents) {
+ QPaintEvent paintEvent(e->region);
+ QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
+ if (paintEvent.isAccepted())
+ return; // No need to send expose
+
+ // The paint event was not accepted, so we fall through and send an expose
+ // event instead, to maintain compatibility for clients that haven't adopted
+ // paint events yet.
+ }
+
QExposeEvent exposeEvent(e->region);
QCoreApplication::sendSpontaneousEvent(window, &exposeEvent);
+ e->eventAccepted = exposeEvent.isAccepted();
+
+ // If the window was just exposed we also need to send a paint event,
+ // so that clients that implement paint events will draw something.
+ // Note that we we can not skip this based on the expose event being
+ // accepted, as clients may implement exposeEvent to track the state
+ // change, but without drawing anything.
+ if (!wasExposed && p->exposed && shouldSynthesizePaintEvents) {
+ QPaintEvent paintEvent(e->region);
+ QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
+ }
+}
+
+void QGuiApplicationPrivate::processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e)
+{
+ Q_ASSERT_X(platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents), "QGuiApplication",
+ "The platform sent paint events without claiming support for it in QPlatformIntegration::capabilities()");
+
+ if (!e->window)
+ return;
+
+ QPaintEvent paintEvent(e->region);
+ QCoreApplication::sendSpontaneousEvent(e->window, &paintEvent);
+
+ // We report back the accepted state to the platform, so that it can
+ // decide when the best time to send the fallback expose event is.
+ e->eventAccepted = paintEvent.isAccepted();
}
#if QT_CONFIG(draganddrop)
@@ -3276,7 +3423,7 @@ QClipboard * QGuiApplication::clipboard()
/*!
\since 5.4
\fn void QGuiApplication::paletteChanged(const QPalette &palette)
- \obsolete
+ \deprecated [6.0] Handle QEvent::ApplicationPaletteChange instead.
This signal is emitted when the \a palette of the application changes. Use
QEvent::ApplicationPaletteChanged instead.
@@ -3335,10 +3482,10 @@ bool QGuiApplicationPrivate::setPalette(const QPalette &palette)
// Resolve the palette against the theme palette, filling in
// any missing roles, while keeping the original resolve mask.
QPalette basePalette = qGuiApp ? qGuiApp->d_func()->basePalette() : Qt::gray;
- basePalette.resolve(0); // The base palette only contributes missing colors roles
+ basePalette.setResolveMask(0); // The base palette only contributes missing colors roles
QPalette resolvedPalette = palette.resolve(basePalette);
- if (app_pal && resolvedPalette == *app_pal && resolvedPalette.resolve() == app_pal->resolve())
+ if (app_pal && resolvedPalette == *app_pal && resolvedPalette.resolveMask() == app_pal->resolveMask())
return false;
if (!app_pal)
@@ -3346,7 +3493,7 @@ bool QGuiApplicationPrivate::setPalette(const QPalette &palette)
else
*app_pal = resolvedPalette;
- QCoreApplication::setAttribute(Qt::AA_SetPalette, app_pal->resolve() != 0);
+ QCoreApplication::setAttribute(Qt::AA_SetPalette, app_pal->resolveMask() != 0);
return true;
}
@@ -3360,11 +3507,13 @@ bool QGuiApplicationPrivate::setPalette(const QPalette &palette)
*/
QPalette QGuiApplicationPrivate::basePalette() const
{
- return platformTheme() ? *platformTheme()->palette() : Qt::gray;
+ const auto pf = platformTheme();
+ return pf && pf->palette() ? *pf->palette() : Qt::gray;
}
void QGuiApplicationPrivate::handlePaletteChanged(const char *className)
{
+#if QT_DEPRECATED_SINCE(6, 0)
if (!className) {
Q_ASSERT(app_pal);
QT_WARNING_PUSH
@@ -3372,6 +3521,9 @@ QT_WARNING_DISABLE_DEPRECATED
emit qGuiApp->paletteChanged(*QGuiApplicationPrivate::app_pal);
QT_WARNING_POP
}
+#else
+ Q_UNUSED(className);
+#endif // QT_DEPRECATED_SINCE(6, 0)
if (is_app_running && !is_app_closing) {
QEvent event(QEvent::ApplicationPaletteChange);
@@ -3387,7 +3539,7 @@ void QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(QWindow *window)
/*!
\since 5.11
\fn void QGuiApplication::fontChanged(const QFont &font)
- \obsolete
+ \deprecated [6.0] Handle QEvent::ApplicationFontChange instead.
This signal is emitted when the \a font of the application changes. Use
QEvent::ApplicationFontChanged instead.
@@ -3430,10 +3582,14 @@ void QGuiApplication::setFont(const QFont &font)
if (emitChange && qGuiApp) {
auto font = *QGuiApplicationPrivate::app_font;
locker.unlock();
+#if QT_DEPRECATED_SINCE(6, 0)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit qGuiApp->fontChanged(font);
QT_WARNING_POP
+#else
+ Q_UNUSED(font);
+#endif // QT_DEPRECATED_SINCE(6, 0)
QEvent event(QEvent::ApplicationFontChange);
QGuiApplication::sendEvent(qGuiApp, &event);
}
@@ -3466,8 +3622,16 @@ void QGuiApplicationPrivate::notifyLayoutDirectionChange()
}
}
-void QGuiApplicationPrivate::notifyActiveWindowChange(QWindow *)
+void QGuiApplicationPrivate::notifyActiveWindowChange(QWindow *prev)
{
+ if (prev) {
+ QEvent de(QEvent::WindowDeactivate);
+ QCoreApplication::sendEvent(prev, &de);
+ }
+ if (self->focus_window) {
+ QEvent ae(QEvent::WindowActivate);
+ QCoreApplication::sendEvent(focus_window, &ae);
+ }
}
/*!
@@ -3512,82 +3676,75 @@ void QGuiApplicationPrivate::notifyWindowIconChanged()
The default is \c true.
If this property is \c true, the applications quits when the last visible
- primary window (i.e. window with no parent) is closed.
+ \l{Primary and Secondary Windows}{primary window} (i.e. top level window
+ with no transient parent) is closed.
\sa quit(), QWindow::close()
*/
void QGuiApplication::setQuitOnLastWindowClosed(bool quit)
{
- QCoreApplication::setQuitLockEnabled(quit);
+ QGuiApplicationPrivate::quitOnLastWindowClosed = quit;
}
-
-
bool QGuiApplication::quitOnLastWindowClosed()
{
- return QCoreApplication::isQuitLockEnabled();
+ return QGuiApplicationPrivate::quitOnLastWindowClosed;
}
+void QGuiApplicationPrivate::maybeLastWindowClosed()
+{
+ if (!lastWindowClosed())
+ return;
+
+ if (in_exec)
+ emit q_func()->lastWindowClosed();
+
+ if (quitOnLastWindowClosed && canQuitAutomatically())
+ quitAutomatically();
+}
/*!
\fn void QGuiApplication::lastWindowClosed()
This signal is emitted from exec() when the last visible
- primary window (i.e. window with no parent) is closed.
+ \l{Primary and Secondary Windows}{primary window} (i.e.
+ top level window with no transient parent) is closed.
By default, QGuiApplication quits after this signal is emitted. This feature
can be turned off by setting \l quitOnLastWindowClosed to \c false.
- \sa QWindow::close(), QWindow::isTopLevel()
+ \sa QWindow::close(), QWindow::isTopLevel(), QWindow::transientParent()
*/
-void QGuiApplicationPrivate::emitLastWindowClosed()
-{
- if (qGuiApp && qGuiApp->d_func()->in_exec) {
- emit qGuiApp->lastWindowClosed();
- }
-}
-
-bool QGuiApplicationPrivate::shouldQuit()
-{
- const QWindowList processedWindows;
- return shouldQuitInternal(processedWindows);
-}
-
-bool QGuiApplicationPrivate::shouldQuitInternal(const QWindowList &processedWindows)
+bool QGuiApplicationPrivate::lastWindowClosed() const
{
- /* if there is no visible top-level window left, we allow the quit */
- QWindowList list = QGuiApplication::topLevelWindows();
- for (int i = 0; i < list.size(); ++i) {
- QWindow *w = list.at(i);
- if (processedWindows.contains(w))
+ for (auto *window : QGuiApplication::topLevelWindows()) {
+ auto *windowPrivate = qt_window_private(window);
+ if (!windowPrivate->participatesInLastWindowClosed())
continue;
- if (w->isVisible() && !w->transientParent())
+
+ if (windowPrivate->treatAsVisible())
return false;
- }
- return true;
+ }
+
+ return true;
}
-bool QGuiApplicationPrivate::tryCloseAllWindows()
+bool QGuiApplicationPrivate::canQuitAutomatically()
{
- return tryCloseRemainingWindows(QWindowList());
+ if (quitOnLastWindowClosed && !lastWindowClosed())
+ return false;
+
+ return QCoreApplicationPrivate::canQuitAutomatically();
}
-bool QGuiApplicationPrivate::tryCloseRemainingWindows(QWindowList processedWindows)
+void QGuiApplicationPrivate::quit()
{
- QWindowList list = QGuiApplication::topLevelWindows();
- for (int i = 0; i < list.size(); ++i) {
- QWindow *w = list.at(i);
- if (w->isVisible() && !processedWindows.contains(w)) {
- if (!w->close())
- return false;
- processedWindows.append(w);
- list = QGuiApplication::topLevelWindows();
- i = -1;
- }
- }
- return true;
+ if (auto *platformIntegration = QGuiApplicationPrivate::platformIntegration())
+ platformIntegration->quit();
+ else
+ QCoreApplicationPrivate::quit();
}
void QGuiApplicationPrivate::processApplicationTermination(QWindowSystemInterfacePrivate::WindowSystemEvent *windowSystemEvent)
@@ -3619,7 +3776,7 @@ Qt::ApplicationState QGuiApplication::applicationState()
Sets the high-DPI scale factor rounding policy for the application. The
\a policy decides how non-integer scale factors (such as Windows 150%) are
- handled, for applications that have AA_EnableHighDpiScaling enabled.
+ handled.
The two principal options are whether fractional scale factors should
be rounded to an integer or not. Keeping the scale factor as-is will
@@ -3632,17 +3789,16 @@ Qt::ApplicationState QGuiApplication::applicationState()
("small UI") or as 2x ("large UI"). See the Qt::HighDpiScaleFactorRoundingPolicy
enum for a complete list of all options.
- This function must be called before creating the application object,
- and can be overridden by setting the QT_SCALE_FACTOR_ROUNDING_POLICY
- environment variable. The QGuiApplication::highDpiScaleFactorRoundingPolicy()
+ This function must be called before creating the application object.
+ The QGuiApplication::highDpiScaleFactorRoundingPolicy()
accessor will reflect the environment, if set.
- The default value is Qt::HighDpiScaleFactorRoundingPolicy::Round.
- On Qt for Android the default is Qt::HighDpiScaleFactorRoundingPolicy::PassThrough,
- which preserves historical behavior from earlier Qt versions.
+ The default value is Qt::HighDpiScaleFactorRoundingPolicy::PassThrough.
*/
void QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy policy)
{
+ if (qApp)
+ qWarning("setHighDpiScaleFactorRoundingPolicy must be called before creating the QGuiApplication instance");
QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy = policy;
}
@@ -3691,57 +3847,6 @@ void QGuiApplicationPrivate::setApplicationState(Qt::ApplicationState state, boo
emit qApp->applicationStateChanged(applicationState);
}
-#ifndef QT_NO_SESSIONMANAGER
-// ### Qt6: consider removing the feature or making it less intrusive
-/*!
- \since 5.6
-
- Returns whether QGuiApplication will use fallback session management.
-
- The default is \c true.
-
- If this is \c true and the session manager allows user interaction,
- QGuiApplication will try to close toplevel windows after
- commitDataRequest() has been emitted. If a window cannot be closed, session
- shutdown will be canceled and the application will keep running.
-
- Fallback session management only benefits applications that have an
- "are you sure you want to close this window?" feature or other logic that
- prevents closing a toplevel window depending on certain conditions, and
- that do nothing to explicitly implement session management. In applications
- that \e do implement session management using the proper session management
- API, fallback session management interferes and may break session
- management logic.
-
- \warning If all windows \e are closed due to fallback session management
- and quitOnLastWindowClosed() is \c true, the application will quit before
- it is explicitly instructed to quit through the platform's session
- management protocol. That violation of protocol may prevent the platform
- session manager from saving application state.
-
- \sa setFallbackSessionManagementEnabled(),
- QSessionManager::allowsInteraction(), saveStateRequest(),
- commitDataRequest(), {Session Management}
-*/
-bool QGuiApplication::isFallbackSessionManagementEnabled()
-{
- return QGuiApplicationPrivate::is_fallback_session_management_enabled;
-}
-
-/*!
- \since 5.6
-
- Sets whether QGuiApplication will use fallback session management to
- \a enabled.
-
- \sa isFallbackSessionManagementEnabled()
-*/
-void QGuiApplication::setFallbackSessionManagementEnabled(bool enabled)
-{
- QGuiApplicationPrivate::is_fallback_session_management_enabled = enabled;
-}
-#endif // QT_NO_SESSIONMANAGER
-
/*!
\since 4.2
\fn void QGuiApplication::commitDataRequest(QSessionManager &manager)
@@ -3766,8 +3871,7 @@ void QGuiApplication::setFallbackSessionManagementEnabled(bool enabled)
\note You should use Qt::DirectConnection when connecting to this signal.
- \sa setFallbackSessionManagementEnabled(), isSessionRestored(),
- sessionId(), saveStateRequest(), {Session Management}
+ \sa isSessionRestored(), sessionId(), saveStateRequest(), {Session Management}
*/
/*!
@@ -3875,13 +3979,7 @@ void QGuiApplicationPrivate::commitData()
{
Q_Q(QGuiApplication);
is_saving_session = true;
-
emit q->commitDataRequest(*session_manager);
- if (is_fallback_session_management_enabled && session_manager->allowsInteraction()
- && !tryCloseAllWindows()) {
- session_manager->cancel();
- }
-
is_saving_session = false;
}
@@ -3921,7 +4019,8 @@ void QGuiApplication::sync()
\property QGuiApplication::layoutDirection
\brief the default layout direction for this application
- On system start-up, the default layout direction depends on the
+ On system start-up, or when the direction is explicitly set to
+ Qt::LayoutDirectionAuto, the default layout direction depends on the
application's language.
The notifier signal was introduced in Qt 5.4.
@@ -3931,11 +4030,15 @@ void QGuiApplication::sync()
void QGuiApplication::setLayoutDirection(Qt::LayoutDirection direction)
{
- if (layout_direction == direction || direction == Qt::LayoutDirectionAuto)
- return;
-
layout_direction = direction;
+ if (direction == Qt::LayoutDirectionAuto)
+ direction = qt_detectRTLLanguage() ? Qt::RightToLeft : Qt::LeftToRight;
+ // no change to the explicitly set or auto-detected layout direction
+ if (direction == effective_layout_direction)
+ return;
+
+ effective_layout_direction = direction;
if (qGuiApp) {
emit qGuiApp->layoutDirectionChanged(direction);
QGuiApplicationPrivate::self->notifyLayoutDirectionChange();
@@ -3944,10 +4047,15 @@ void QGuiApplication::setLayoutDirection(Qt::LayoutDirection direction)
Qt::LayoutDirection QGuiApplication::layoutDirection()
{
- // layout_direction is only ever Qt::LayoutDirectionAuto if setLayoutDirection
- // was never called, or called with Qt::LayoutDirectionAuto (which is a no-op).
- // In that case we return the default LeftToRight.
- return layout_direction == Qt::LayoutDirectionAuto ? Qt::LeftToRight : layout_direction;
+ /*
+ effective_layout_direction defaults to Qt::LeftToRight, and is updated with what is
+ auto-detected by a call to setLayoutDirection(Qt::LayoutDirectionAuto). This happens in
+ QGuiApplicationPrivate::init and when the language changes (or before if the application
+ calls the static function, but then no translators are installed so the auto-detection
+ always yields Qt::LeftToRight).
+ So we can be certain that it's always the right value.
+ */
+ return effective_layout_direction;
}
/*!
@@ -4054,7 +4162,7 @@ static inline void applyWindowCursor(const QList<QWindow *> &l)
Application cursors are stored on an internal stack. setOverrideCursor()
pushes the cursor onto the stack, and restoreOverrideCursor() pops the
- active cursor off the stack. changeOverrideCursor() changes the curently
+ active cursor off the stack. changeOverrideCursor() changes the currently
active application override cursor.
Every setOverrideCursor() must eventually be followed by a corresponding
@@ -4171,7 +4279,10 @@ QInputMethod *QGuiApplication::inputMethod()
/*!
\fn void QGuiApplication::fontDatabaseChanged()
- This signal is emitted when application fonts are loaded or removed.
+ This signal is emitted when the available fonts have changed.
+
+ This can happen when application fonts are added or removed, or when the
+ system fonts change.
\sa QFontDatabase::addApplicationFont(),
QFontDatabase::addApplicationFontFromData(),
@@ -4185,22 +4296,18 @@ QPixmap QGuiApplicationPrivate::getPixmapCursor(Qt::CursorShape cshape)
return QPixmap();
}
-void QGuiApplicationPrivate::notifyThemeChanged()
+QPoint QGuiApplicationPrivate::QLastCursorPosition::toPoint() const noexcept
{
- updatePalette();
-
- if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
- const auto locker = qt_scoped_lock(applicationFontMutex);
- clearFontUnlocked();
- initFontUnlocked();
- }
- initThemeHints();
+ // Guard against the default initialization of qInf() (avoid UB or SIGFPE in conversion).
+ if (Q_UNLIKELY(qIsInf(thePoint.x())))
+ return QPoint(std::numeric_limits<int>::max(), std::numeric_limits<int>::max());
+ return thePoint.toPoint();
}
#if QT_CONFIG(draganddrop)
void QGuiApplicationPrivate::notifyDragStarted(const QDrag *drag)
{
- Q_UNUSED(drag)
+ Q_UNUSED(drag);
}
#endif
@@ -4208,10 +4315,8 @@ void QGuiApplicationPrivate::notifyDragStarted(const QDrag *drag)
const QColorTrcLut *QGuiApplicationPrivate::colorProfileForA8Text()
{
#ifdef Q_OS_WIN
- if (!m_a8ColorProfile){
- QColorTrcLut *cs = QColorTrcLut::fromGamma(2.31); // This is a hard-coded thing for Windows text rendering
- m_a8ColorProfile.reset(cs);
- }
+ if (!m_a8ColorProfile)
+ m_a8ColorProfile = QColorTrcLut::fromGamma(2.31); // This is a hard-coded thing for Windows text rendering
return m_a8ColorProfile.get();
#else
return colorProfileForA32Text();
@@ -4220,10 +4325,8 @@ const QColorTrcLut *QGuiApplicationPrivate::colorProfileForA8Text()
const QColorTrcLut *QGuiApplicationPrivate::colorProfileForA32Text()
{
- if (!m_a32ColorProfile) {
- QColorTrcLut *cs = QColorTrcLut::fromGamma(fontSmoothingGamma);
- m_a32ColorProfile.reset(cs);
- }
+ if (!m_a32ColorProfile)
+ m_a32ColorProfile = QColorTrcLut::fromGamma(fontSmoothingGamma);
return m_a32ColorProfile.get();
}
@@ -4249,63 +4352,50 @@ enum MouseMasks {
MouseFlagsShift = 16
};
-int QGuiApplicationPrivate::mouseEventCaps(QMouseEvent *event)
+QInputDeviceManager *QGuiApplicationPrivate::inputDeviceManager()
{
- return event->caps & MouseCapsMask;
-}
+ Q_ASSERT(QGuiApplication::instance());
-QVector2D QGuiApplicationPrivate::mouseEventVelocity(QMouseEvent *event)
-{
- return event->velocity;
-}
+ if (!m_inputDeviceManager)
+ m_inputDeviceManager = new QInputDeviceManager(QGuiApplication::instance());
-void QGuiApplicationPrivate::setMouseEventCapsAndVelocity(QMouseEvent *event, int caps, const QVector2D &velocity)
-{
- Q_ASSERT(caps <= MouseCapsMask);
- event->caps &= ~MouseCapsMask;
- event->caps |= caps & MouseCapsMask;
- event->velocity = velocity;
+ return m_inputDeviceManager;
}
-Qt::MouseEventSource QGuiApplicationPrivate::mouseEventSource(const QMouseEvent *event)
-{
- return Qt::MouseEventSource((event->caps & MouseSourceMaskDst) >> MouseSourceShift);
-}
+/*!
+ \fn template <typename QNativeInterface> QNativeInterface *QGuiApplication::nativeInterface() const
-void QGuiApplicationPrivate::setMouseEventSource(QMouseEvent *event, Qt::MouseEventSource source)
-{
- // Mouse event synthesization status is encoded in the caps field because
- // QPointingDevice::Capability uses only 6 bits from it.
- int value = source;
- Q_ASSERT(value <= MouseSourceMaskSrc);
- event->caps &= ~MouseSourceMaskDst;
- event->caps |= (value & MouseSourceMaskSrc) << MouseSourceShift;
-}
+ Returns a native interface of the given type for the application.
-Qt::MouseEventFlags QGuiApplicationPrivate::mouseEventFlags(const QMouseEvent *event)
-{
- return Qt::MouseEventFlags((event->caps & MouseFlagsCapsMask) >> MouseFlagsShift);
-}
+ This function provides access to platform specific functionality
+ of QGuiApplication, as defined in the QNativeInterface namespace:
-void QGuiApplicationPrivate::setMouseEventFlags(QMouseEvent *event, Qt::MouseEventFlags flags)
-{
- // use the 0x00FF0000 byte from caps (containing up to 7 mouse event flags)
- unsigned int value = flags;
- Q_ASSERT(value <= Qt::MouseEventFlagMask);
- event->caps &= ~MouseFlagsCapsMask;
- event->caps |= (value & Qt::MouseEventFlagMask) << MouseFlagsShift;
-}
+ \annotatedlist native-interfaces-qguiapplication
-QInputDeviceManager *QGuiApplicationPrivate::inputDeviceManager()
+ If the requested interface is not available a \nullptr is returned.
+ */
+
+void *QGuiApplication::resolveInterface(const char *name, int revision) const
{
- Q_ASSERT(QGuiApplication::instance());
+ using namespace QNativeInterface;
+ using namespace QNativeInterface::Private;
- if (!m_inputDeviceManager)
- m_inputDeviceManager = new QInputDeviceManager(QGuiApplication::instance());
+ auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
+ Q_UNUSED(platformIntegration);
- return m_inputDeviceManager;
-}
+#if defined(Q_OS_WIN)
+ QT_NATIVE_INTERFACE_RETURN_IF(QWindowsApplication, platformIntegration);
+#endif
+#if QT_CONFIG(xcb)
+ QT_NATIVE_INTERFACE_RETURN_IF(QX11Application, platformNativeInterface());
+#endif
+#if QT_CONFIG(wayland)
+ QT_NATIVE_INTERFACE_RETURN_IF(QWaylandApplication, platformNativeInterface());
+#endif
-#include "moc_qguiapplication.cpp"
+ return QCoreApplication::resolveInterface(name, revision);
+}
QT_END_NAMESPACE
+
+#include "moc_qguiapplication.cpp"
diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h
index ac90e18ef9..14bce88c62 100644
--- a/src/gui/kernel/qguiapplication.h
+++ b/src/gui/kernel/qguiapplication.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QGUIAPPLICATION_H
#define QGUIAPPLICATION_H
@@ -73,11 +37,14 @@ class Q_GUI_EXPORT QGuiApplication : public QCoreApplication
{
Q_OBJECT
Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon)
- Q_PROPERTY(QString applicationDisplayName READ applicationDisplayName WRITE setApplicationDisplayName NOTIFY applicationDisplayNameChanged)
+ Q_PROPERTY(QString applicationDisplayName READ applicationDisplayName
+ WRITE setApplicationDisplayName NOTIFY applicationDisplayNameChanged)
Q_PROPERTY(QString desktopFileName READ desktopFileName WRITE setDesktopFileName)
- Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
+ Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection
+ NOTIFY layoutDirectionChanged)
Q_PROPERTY(QString platformName READ platformName STORED false)
- Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed)
+ Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed
+ WRITE setQuitOnLastWindowClosed)
Q_PROPERTY(QScreen *primaryScreen READ primaryScreen NOTIFY primaryScreenChanged STORED false)
public:
@@ -91,6 +58,8 @@ public:
static void setApplicationDisplayName(const QString &name);
static QString applicationDisplayName();
+ Q_SLOT void setBadgeNumber(qint64 number);
+
static void setDesktopFileName(const QString &name);
static QString desktopFileName();
@@ -168,11 +137,10 @@ public:
QString sessionId() const;
QString sessionKey() const;
bool isSavingSession() const;
-
- static bool isFallbackSessionManagementEnabled();
- static void setFallbackSessionManagementEnabled(bool);
#endif
+ QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QGuiApplication)
+
static void sync();
Q_SIGNALS:
void fontDatabaseChanged();
@@ -217,4 +185,6 @@ private:
QT_END_NAMESPACE
+#include <QtGui/qguiapplication_platform.h>
+
#endif // QGUIAPPLICATION_H
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index c5c4bd09d1..58c3f33394 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QGUIAPPLICATION_P_H
#define QGUIAPPLICATION_P_H
@@ -53,11 +17,15 @@
#include <QtGui/private/qtguiglobal_p.h>
#include <QtGui/qguiapplication.h>
+#include <QtGui/qicon.h>
+#include <QtCore/QHash>
#include <QtCore/QPointF>
-#include <QtCore/QSharedPointer>
#include <QtCore/private/qcoreapplication_p.h>
+#include <QtCore/qnativeinterface.h>
+#include <QtCore/private/qnativeinterface_p.h>
+#include <QtCore/private/qnumeric_p.h>
#include <QtCore/private/qthread_p.h>
#include <qpa/qwindowsysteminterface.h>
@@ -66,7 +34,9 @@
# include "private/qshortcutmap_p.h"
#endif
-#include <qicon.h>
+#include <QtCore/qpointer.h>
+
+#include <memory>
QT_BEGIN_NAMESPACE
@@ -89,7 +59,7 @@ class Q_GUI_EXPORT QGuiApplicationPrivate : public QCoreApplicationPrivate
{
Q_DECLARE_PUBLIC(QGuiApplication)
public:
- QGuiApplicationPrivate(int &argc, char **argv, int flags);
+ QGuiApplicationPrivate(int &argc, char **argv);
~QGuiApplicationPrivate();
void init();
@@ -104,11 +74,14 @@ public:
#if QT_CONFIG(commandlineparser)
void addQtOptions(QList<QCommandLineOption> *options) override;
#endif
- virtual bool shouldQuit() override;
+ bool canQuitAutomatically() override;
+ void quit() override;
- bool shouldQuitInternal(const QWindowList &processedWindows);
- virtual bool tryCloseAllWindows();
+ void maybeLastWindowClosed();
+ bool lastWindowClosed() const;
+ static bool quitOnLastWindowClosed;
+ static void captureGlobalModifierState(QEvent *e);
static Qt::KeyboardModifiers modifier_buttons;
static Qt::MouseButtons mouse_buttons;
@@ -142,9 +115,11 @@ public:
static void processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e);
static void processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e);
- static void processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *e);
+ static void processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e);
+
static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e);
static void processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e);
+ static void processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *e);
static void processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *e);
@@ -160,6 +135,7 @@ public:
static void processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce);
static void processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e);
+ static void processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e);
static void processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e);
@@ -185,11 +161,7 @@ public:
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
#endif
-#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result);
-#else
- static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result);
-#endif
static bool sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event);
@@ -205,8 +177,6 @@ public:
return alignment;
}
- static void emitLastWindowClosed();
-
QPixmap getPixmapCursor(Qt::CursorShape cshape);
void _q_updateFocusObject(QObject *object);
@@ -222,19 +192,53 @@ public:
static void showModalWindow(QWindow *window);
static void hideModalWindow(QWindow *window);
static void updateBlockedStatus(QWindow *window);
- virtual bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const;
+
+ virtual Qt::WindowModality defaultModality() const;
+ virtual bool windowNeverBlocked(QWindow *window) const;
+ bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const;
virtual bool popupActive() { return false; }
+ virtual bool closeAllPopups() { return false; }
- static ulong mousePressTime;
static Qt::MouseButton mousePressButton;
- static int mousePressX;
- static int mousePressY;
- static QPointF lastCursorPosition;
+ static struct QLastCursorPosition {
+ constexpr inline QLastCursorPosition() noexcept : thePoint(qt_inf(), qt_inf()) {}
+ constexpr inline Q_IMPLICIT QLastCursorPosition(QPointF p) noexcept : thePoint(p) {}
+ constexpr inline Q_IMPLICIT operator QPointF() const noexcept { return thePoint; }
+ constexpr inline qreal x() const noexcept{ return thePoint.x(); }
+ constexpr inline qreal y() const noexcept{ return thePoint.y(); }
+ Q_GUI_EXPORT QPoint toPoint() const noexcept;
+
+ constexpr void reset() noexcept { *this = QLastCursorPosition{}; }
+
+ // QGuiApplicationPrivate::lastCursorPosition is used for mouse-move detection
+ // but even QPointF's qFuzzCompare on doubles is too precise, and causes move-noise
+ // e.g. on macOS (see QTBUG-111170). So we specialize the equality operators here
+ // to use single-point precision.
+ friend constexpr bool operator==(const QLastCursorPosition &p1, const QPointF &p2) noexcept
+ {
+ return qFuzzyCompare(float(p1.x()), float(p2.x()))
+ && qFuzzyCompare(float(p1.y()), float(p2.y()));
+ }
+ friend constexpr bool operator!=(const QLastCursorPosition &p1, const QPointF &p2) noexcept
+ {
+ return !(p1 == p2);
+ }
+ friend constexpr bool operator==(const QPointF &p1, const QLastCursorPosition &p2) noexcept
+ {
+ return p2 == p1;
+ }
+ friend constexpr bool operator!=(const QPointF &p1, const QLastCursorPosition &p2) noexcept
+ {
+ return !(p2 == p1);
+ }
+
+ private:
+ QPointF thePoint;
+ } lastCursorPosition;
static QWindow *currentMouseWindow;
static QWindow *currentMousePressWindow;
static Qt::ApplicationState applicationState;
static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy;
- static bool highDpiScalingUpdated;
static QPointer<QWindow> currentDragWindow;
// TODO remove this: QPointingDevice can store what we need directly
@@ -277,7 +281,6 @@ public:
#endif
#ifndef QT_NO_SESSIONMANAGER
- static bool is_fallback_session_management_enabled;
QSessionManager *session_manager;
bool is_session_restored;
bool is_saving_session;
@@ -285,17 +288,6 @@ public:
void saveState();
#endif
- struct ActiveTouchPointsKey {
- ActiveTouchPointsKey(const QPointingDevice *dev, int id) : device(dev), touchPointId(id) { }
- const QPointingDevice *device;
- int touchPointId;
- };
- struct ActiveTouchPointsValue {
- QPointer<QWindow> window;
- QPointer<QObject> target;
- QTouchEvent::TouchPoint touchPoint;
- };
- QHash<ActiveTouchPointsKey, ActiveTouchPointsValue> activeTouchPoints;
QEvent::Type lastTouchType;
struct SynthesizedMouseData {
SynthesizedMouseData(const QPointF &p, const QPointF &sp, QWindow *w)
@@ -306,16 +298,6 @@ public:
};
QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
- static int mouseEventCaps(QMouseEvent *event);
- static QVector2D mouseEventVelocity(QMouseEvent *event);
- static void setMouseEventCapsAndVelocity(QMouseEvent *event, int caps, const QVector2D &velocity);
-
- static Qt::MouseEventSource mouseEventSource(const QMouseEvent *event);
- static void setMouseEventSource(QMouseEvent *event, Qt::MouseEventSource source);
-
- static Qt::MouseEventFlags mouseEventFlags(const QMouseEvent *event);
- static void setMouseEventFlags(QMouseEvent *event, Qt::MouseEventFlags flags);
-
static QInputDeviceManager *inputDeviceManager();
const QColorTrcLut *colorProfileForA8Text();
@@ -339,29 +321,32 @@ public:
virtual QShortcutPrivate *createShortcutPrivate() const;
#endif
+ static void updatePalette();
+
+ static Qt::ColorScheme colorScheme();
+
protected:
- virtual void notifyThemeChanged();
+ virtual void handleThemeChanged();
static bool setPalette(const QPalette &palette);
virtual QPalette basePalette() const;
virtual void handlePaletteChanged(const char *className = nullptr);
- bool tryCloseRemainingWindows(QWindowList processedWindows);
#if QT_CONFIG(draganddrop)
virtual void notifyDragStarted(const QDrag *);
#endif // QT_CONFIG(draganddrop)
private:
static void clearPalette();
- static void updatePalette();
friend class QDragManager;
static QGuiApplicationPrivate *self;
- static QPointingDevice *m_fakeTouchDevice;
static int m_fakeMouseSourcePointId;
- QSharedPointer<QColorTrcLut> m_a8ColorProfile;
- QSharedPointer<QColorTrcLut> m_a32ColorProfile;
+#ifdef Q_OS_WIN
+ std::shared_ptr<QColorTrcLut> m_a8ColorProfile;
+#endif
+ std::shared_ptr<QColorTrcLut> m_a32ColorProfile;
bool ownGlobalShareContext;
@@ -372,10 +357,82 @@ private:
static qreal m_maxDevicePixelRatio;
};
-Q_GUI_EXPORT size_t qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k, size_t seed = 0);
+// ----------------- QNativeInterface -----------------
+
+class QWindowsMimeConverter;
+
+namespace QNativeInterface::Private {
-Q_GUI_EXPORT bool operator==(const QGuiApplicationPrivate::ActiveTouchPointsKey &a,
- const QGuiApplicationPrivate::ActiveTouchPointsKey &b);
+#if defined(Q_OS_WIN) || defined(Q_QDOC)
+
+
+struct Q_GUI_EXPORT QWindowsApplication
+{
+ QT_DECLARE_NATIVE_INTERFACE(QWindowsApplication, 1, QGuiApplication)
+
+ enum WindowActivationBehavior {
+ DefaultActivateWindow,
+ AlwaysActivateWindow
+ };
+
+ enum TouchWindowTouchType {
+ NormalTouch = 0x00000000,
+ FineTouch = 0x00000001,
+ WantPalmTouch = 0x00000002
+ };
+
+ Q_DECLARE_FLAGS(TouchWindowTouchTypes, TouchWindowTouchType)
+
+ enum DarkModeHandlingFlag {
+ DarkModeWindowFrames = 0x1,
+ DarkModeStyle = 0x2
+ };
+
+ Q_DECLARE_FLAGS(DarkModeHandling, DarkModeHandlingFlag)
+
+ virtual void setTouchWindowTouchType(TouchWindowTouchTypes type) = 0;
+ virtual TouchWindowTouchTypes touchWindowTouchType() const = 0;
+
+ virtual WindowActivationBehavior windowActivationBehavior() const = 0;
+ virtual void setWindowActivationBehavior(WindowActivationBehavior behavior) = 0;
+
+ virtual void setHasBorderInFullScreenDefault(bool border) = 0;
+
+ virtual bool isTabletMode() const = 0;
+
+ virtual bool isWinTabEnabled() const = 0;
+ virtual bool setWinTabEnabled(bool enabled) = 0;
+
+ virtual bool isDarkMode() const = 0;
+
+ virtual DarkModeHandling darkModeHandling() const = 0;
+ virtual void setDarkModeHandling(DarkModeHandling handling) = 0;
+
+ virtual void registerMime(QWindowsMimeConverter *mime) = 0;
+ virtual void unregisterMime(QWindowsMimeConverter *mime) = 0;
+
+ virtual int registerMimeType(const QString &mime) = 0;
+
+ virtual HWND createMessageWindow(const QString &classNameTemplate,
+ const QString &windowName,
+ QFunctionPointer eventProc = nullptr) const = 0;
+
+ virtual bool asyncExpose() const = 0; // internal, used by Active Qt
+ virtual void setAsyncExpose(bool value) = 0;
+
+ virtual QVariant gpu() const = 0; // internal, used by qtdiag
+ virtual QVariant gpuList() const = 0;
+
+ virtual void populateLightSystemPalette(QPalette &pal) const = 0;
+};
+#endif // Q_OS_WIN
+
+} // QNativeInterface::Private
+
+#if defined(Q_OS_WIN)
+Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::TouchWindowTouchTypes)
+Q_DECLARE_OPERATORS_FOR_FLAGS(QNativeInterface::Private::QWindowsApplication::DarkModeHandling)
+#endif
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qguiapplication_platform.h b/src/gui/kernel/qguiapplication_platform.h
new file mode 100644
index 0000000000..545bf75c84
--- /dev/null
+++ b/src/gui/kernel/qguiapplication_platform.h
@@ -0,0 +1,68 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QGUIAPPLICATION_PLATFORM_H
+#define QGUIAPPLICATION_PLATFORM_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is part of the native interface APIs. Usage of
+// this API may make your code source and binary incompatible
+// with future versions of Qt.
+//
+
+#include <QtGui/qtguiglobal.h>
+
+#include <QtCore/qnativeinterface.h>
+#include <QtGui/qguiapplication.h>
+
+#if QT_CONFIG(xcb)
+typedef struct _XDisplay Display;
+struct xcb_connection_t;
+#endif
+
+#if QT_CONFIG(wayland)
+struct wl_display;
+struct wl_compositor;
+struct wl_seat;
+struct wl_keyboard;
+struct wl_pointer;
+struct wl_touch;
+#endif
+
+QT_BEGIN_NAMESPACE
+
+namespace QNativeInterface
+{
+
+#if QT_CONFIG(xcb) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QX11Application
+{
+ QT_DECLARE_NATIVE_INTERFACE(QX11Application, 1, QGuiApplication)
+ virtual Display *display() const = 0;
+ virtual xcb_connection_t *connection() const = 0;
+};
+#endif
+
+#if QT_CONFIG(wayland) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QWaylandApplication
+{
+ QT_DECLARE_NATIVE_INTERFACE(QWaylandApplication, 1, QGuiApplication)
+ virtual wl_display *display() const = 0;
+ virtual wl_compositor *compositor() const = 0;
+ virtual wl_seat *seat() const = 0;
+ virtual wl_keyboard *keyboard() const = 0;
+ virtual wl_pointer *pointer() const = 0;
+ virtual wl_touch *touch() const = 0;
+ virtual uint lastInputSerial() const = 0;
+ virtual wl_seat *lastInputSeat() const = 0;
+};
+#endif
+
+} // QNativeInterface
+
+QT_END_NAMESPACE
+
+#endif // QGUIAPPLICATION_PLATFORM_H
diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp
index 565e91d662..fe72e7782f 100644
--- a/src/gui/kernel/qguivariant.cpp
+++ b/src/gui/kernel/qguivariant.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Gui types
#include "qbitmap.h"
@@ -86,272 +50,95 @@
#include <float.h>
-#include "private/qvariant_p.h"
#include <private/qmetatype_p.h>
QT_BEGIN_NAMESPACE
-Q_CORE_EXPORT const QVariant::Handler *qcoreVariantHandler();
-
namespace {
-struct GuiTypesFilter {
- template<typename T>
- struct Acceptor {
- static const bool IsAccepted = QModulesPrivate::QTypeModuleInfo<T>::IsGui && QtMetaTypePrivate::TypeDefinition<T>::IsAvailable;
- };
-};
-// This class is a hack that customizes access to QPolygon and QPolygonF
-template<class Filter>
-class QGuiVariantIsNull : public QVariantIsNull<Filter> {
- typedef QVariantIsNull<Filter> Base;
-public:
- QGuiVariantIsNull(const QVariant::Private *d)
- : QVariantIsNull<Filter>(d)
- {}
- template<typename T>
- bool delegate(const T *p) { return Base::delegate(p); }
- bool delegate(const QPolygon*) { return v_cast<QPolygon>(Base::m_d)->isEmpty(); }
- bool delegate(const QPolygonF*) { return v_cast<QPolygonF>(Base::m_d)->isEmpty(); }
- bool delegate(const void *p) { return Base::delegate(p); }
-};
-static bool isNull(const QVariant::Private *d)
+// NOLINTNEXTLINE(cppcoreguidelines-virtual-class-destructor): this is not a base class
+static constexpr struct : QMetaTypeModuleHelper
{
- QGuiVariantIsNull<GuiTypesFilter> isNull(d);
- return QMetaTypeSwitcher::switcher<bool>(isNull, d->type().id(), nullptr);
-}
+#define QT_IMPL_METATYPEINTERFACE_GUI_TYPES(MetaTypeName, MetaTypeId, RealName) \
+ QT_METATYPE_INTERFACE_INIT(RealName),
-// This class is a hack that customizes access to QPixmap, QBitmap, QCursor and QIcon
-template<class Filter>
-class QGuiVariantComparator : public QVariantComparator<Filter> {
- typedef QVariantComparator<Filter> Base;
-public:
- QGuiVariantComparator(const QVariant::Private *a, const QVariant::Private *b)
- : QVariantComparator<Filter>(a, b)
- {}
- template<typename T>
- bool delegate(const T *p)
- {
- return Base::delegate(p);
- }
- bool delegate(const QPixmap*)
- {
- return v_cast<QPixmap>(Base::m_a)->cacheKey() == v_cast<QPixmap>(Base::m_b)->cacheKey();
- }
- bool delegate(const QBitmap*)
- {
- return v_cast<QBitmap>(Base::m_a)->cacheKey() == v_cast<QBitmap>(Base::m_b)->cacheKey();
- }
-#ifndef QT_NO_CURSOR
- bool delegate(const QCursor*)
- {
- return v_cast<QCursor>(Base::m_a)->shape() == v_cast<QCursor>(Base::m_b)->shape();
- }
-#endif
-#ifndef QT_NO_ICON
- bool delegate(const QIcon *)
- {
- return v_cast<QIcon>(Base::m_a)->cacheKey() == v_cast<QIcon>(Base::m_b)->cacheKey();
+ const QtPrivate::QMetaTypeInterface *interfaceForType(int type) const override {
+ switch (type) {
+ QT_FOR_EACH_STATIC_GUI_CLASS(QT_METATYPE_CONVERT_ID_TO_TYPE)
+ default: return nullptr;
+ }
}
-#endif
- bool delegate(const void *p) { return Base::delegate(p); }
-};
-
-static bool compare(const QVariant::Private *a, const QVariant::Private *b)
-{
- QGuiVariantComparator<GuiTypesFilter> comparator(a, b);
- return QMetaTypeSwitcher::switcher<bool>(comparator, a->type().id(), nullptr);
-}
+#undef QT_IMPL_METATYPEINTERFACE_GUI_TYPES
-static bool convert(const QVariant::Private *d, int t,
- void *result, bool *ok)
-{
- switch (t) {
- case QMetaType::QByteArray:
- if (d->type().id() == QMetaType::QColor) {
- const QColor *c = v_cast<QColor>(d);
- *static_cast<QByteArray *>(result) = c->name(c->alpha() != 255 ? QColor::HexArgb : QColor::HexRgb).toLatin1();
- return true;
- }
- break;
- case QMetaType::QString: {
- QString *str = static_cast<QString *>(result);
- switch (d->type().id()) {
+ bool convert(const void *from, int fromTypeId, void *to, int toTypeId) const override
+ {
+ Q_ASSERT(fromTypeId != toTypeId);
+
+ bool onlyCheck = (from == nullptr && to == nullptr);
+ // either two nullptrs from canConvert, or two valid pointers
+ Q_ASSERT(onlyCheck || (bool(from) && bool(to)));
+
+ using Int = int;
+ switch (makePair(toTypeId, fromTypeId)) {
+ QMETATYPE_CONVERTER(QByteArray, QColor,
+ result = source.name(source.alpha() != 255 ?
+ QColor::HexArgb : QColor::HexRgb).toLatin1();
+ return true;
+ );
+ QMETATYPE_CONVERTER(QColor, QByteArray,
+ result = QColor::fromString(QLatin1StringView(source));
+ return result.isValid();
+ );
+ QMETATYPE_CONVERTER(QString, QColor,
+ result = source.name(source.alpha() != 255 ?
+ QColor::HexArgb : QColor::HexRgb);
+ return true;
+ );
+ QMETATYPE_CONVERTER(QColor, QString,
+ result = QColor::fromString(source);
+ return result.isValid();
+ );
#if QT_CONFIG(shortcut)
- case QMetaType::QKeySequence:
- *str = (*v_cast<QKeySequence>(d)).toString(QKeySequence::NativeText);
- return true;
-#endif
- case QMetaType::QFont:
- *str = v_cast<QFont>(d)->toString();
- return true;
- case QMetaType::QColor: {
- const QColor *c = v_cast<QColor>(d);
- *str = c->name(c->alpha() != 255 ? QColor::HexArgb : QColor::HexRgb);
- return true;
- }
- default:
- break;
- }
- break;
- }
- case QMetaType::QPixmap:
- if (d->type().id() == QMetaType::QImage) {
- *static_cast<QPixmap *>(result) = QPixmap::fromImage(*v_cast<QImage>(d));
- return true;
- } else if (d->type().id() == QMetaType::QBitmap) {
- *static_cast<QPixmap *>(result) = *v_cast<QBitmap>(d);
- return true;
- } else if (d->type().id() == QMetaType::QBrush) {
- if (v_cast<QBrush>(d)->style() == Qt::TexturePattern) {
- *static_cast<QPixmap *>(result) = v_cast<QBrush>(d)->texture();
- return true;
- }
- }
- break;
- case QMetaType::QImage:
- if (d->type().id() == QMetaType::QPixmap) {
- *static_cast<QImage *>(result) = v_cast<QPixmap>(d)->toImage();
- return true;
- } else if (d->type().id() == QMetaType::QBitmap) {
- *static_cast<QImage *>(result) = v_cast<QBitmap>(d)->toImage();
- return true;
- }
- break;
- case QMetaType::QBitmap:
- if (d->type().id() == QMetaType::QPixmap) {
- *static_cast<QBitmap *>(result) = *v_cast<QPixmap>(d);
- return true;
- } else if (d->type().id() == QMetaType::QImage) {
- *static_cast<QBitmap *>(result) = QBitmap::fromImage(*v_cast<QImage>(d));
+ QMETATYPE_CONVERTER(QString, QKeySequence,
+ result = source.toString(QKeySequence::NativeText);
return true;
- }
- break;
-#if QT_CONFIG(shortcut)
- case QMetaType::Int:
- if (d->type().id() == QMetaType::QKeySequence) {
- const QKeySequence &seq = *v_cast<QKeySequence>(d);
- *static_cast<int *>(result) = seq.isEmpty() ? 0 : seq[0];
+ );
+ QMETATYPE_CONVERTER(QKeySequence, QString, result = source; return true;);
+ QMETATYPE_CONVERTER(Int, QKeySequence,
+ result = source.isEmpty() ? 0 : source[0].toCombined();
return true;
- }
- break;
+ );
+ QMETATYPE_CONVERTER(QKeySequence, Int, result = source; return true;);
#endif
- case QMetaType::QFont:
- if (d->type().id() == QMetaType::QString) {
- QFont *f = static_cast<QFont *>(result);
- f->fromString(*v_cast<QString>(d));
- return true;
- }
- break;
- case QMetaType::QColor:
- if (d->type().id() == QMetaType::QString) {
- static_cast<QColor *>(result)->setNamedColor(*v_cast<QString>(d));
- return static_cast<QColor *>(result)->isValid();
- } else if (d->type().id() == QMetaType::QByteArray) {
- static_cast<QColor *>(result)->setNamedColor(QLatin1String(*v_cast<QByteArray>(d)));
- return true;
- } else if (d->type().id() == QMetaType::QBrush) {
- if (v_cast<QBrush>(d)->style() == Qt::SolidPattern) {
- *static_cast<QColor *>(result) = v_cast<QBrush>(d)->color();
+ QMETATYPE_CONVERTER(QString, QFont, result = source.toString(); return true;);
+ QMETATYPE_CONVERTER(QFont, QString, return result.fromString(source););
+ QMETATYPE_CONVERTER(QPixmap, QImage, result = QPixmap::fromImage(source); return true;);
+ QMETATYPE_CONVERTER(QImage, QPixmap, result = source.toImage(); return true;);
+ QMETATYPE_CONVERTER(QPixmap, QBitmap, result = source; return true;);
+ QMETATYPE_CONVERTER(QBitmap, QPixmap, result = QBitmap::fromPixmap(source); return true;);
+ QMETATYPE_CONVERTER(QImage, QBitmap, result = source.toImage(); return true;);
+ QMETATYPE_CONVERTER(QBitmap, QImage, result = QBitmap::fromImage(source); return true;);
+ QMETATYPE_CONVERTER(QPixmap, QBrush, result = source.texture(); return true;);
+ QMETATYPE_CONVERTER(QBrush, QPixmap, result = source; return true;);
+ QMETATYPE_CONVERTER(QColor, QBrush,
+ if (source.style() == Qt::SolidPattern) {
+ result = source.color();
return true;
}
- }
- break;
- case QMetaType::QBrush:
- if (d->type().id() == QMetaType::QColor) {
- *static_cast<QBrush *>(result) = QBrush(*v_cast<QColor>(d));
- return true;
- } else if (d->type().id() == QMetaType::QPixmap) {
- *static_cast<QBrush *>(result) = QBrush(*v_cast<QPixmap>(d));
- return true;
- }
- break;
-#if QT_CONFIG(shortcut)
- case QMetaType::QKeySequence: {
- QKeySequence *seq = static_cast<QKeySequence *>(result);
- switch (d->type().id()) {
- case QMetaType::QString:
- *seq = QKeySequence(*v_cast<QString>(d));
- return true;
- case QMetaType::Int:
- *seq = QKeySequence(d->data.i);
- return true;
+ return false;
+ );
+ QMETATYPE_CONVERTER(QBrush, QColor, result = source; return true;);
default:
break;
}
- break;
- }
-#endif
-#ifndef QT_NO_ICON
- case QMetaType::QIcon: {
- if (ok)
- *ok = false;
return false;
}
-#endif
- default:
- break;
- }
- return qcoreVariantHandler()->convert(d, t, result, ok);
-}
-
-#if !defined(QT_NO_DEBUG_STREAM)
-static void streamDebug(QDebug dbg, const QVariant &v)
-{
- QVariant::Private *d = const_cast<QVariant::Private *>(&v.data_ptr());
- QVariantDebugStream<GuiTypesFilter> stream(dbg, d);
- QMetaTypeSwitcher::switcher<void>(stream, d->type().id(), nullptr);
-}
-#endif
-
-const QVariant::Handler qt_gui_variant_handler = {
- isNull,
- compare,
- convert,
-#if !defined(QT_NO_DEBUG_STREAM)
- streamDebug
-#else
- nullptr
-#endif
-};
-
-#define QT_IMPL_METATYPEINTERFACE_GUI_TYPES(MetaTypeName, MetaTypeId, RealName) \
- QT_METATYPE_INTERFACE_INIT(RealName),
-
-static const struct : QMetaTypeModuleHelper
-{
- QtPrivate::QMetaTypeInterface *interfaceForType(int type) const override {
- switch (type) {
- QT_FOR_EACH_STATIC_GUI_CLASS(QT_METATYPE_CONVERT_ID_TO_TYPE)
- default: return nullptr;
- }
- }
-#ifndef QT_NO_DATASTREAM
- bool save(QDataStream &stream, int type, const void *data) const override {
- switch (type) {
- QT_FOR_EACH_STATIC_GUI_CLASS(QT_METATYPE_DATASTREAM_SAVE)
- default: return false;
- }
- }
- bool load(QDataStream &stream, int type, void *data) const override {
- switch (type) {
- QT_FOR_EACH_STATIC_GUI_CLASS(QT_METATYPE_DATASTREAM_LOAD)
- default: return false;
- }
- }
-#endif
-
} qVariantGuiHelper;
-
-#undef QT_IMPL_METATYPEINTERFACE_GUI_TYPES
} // namespace used to hide QVariant handler
-extern Q_CORE_EXPORT const QMetaTypeModuleHelper *qMetaTypeGuiHelper;
-
void qRegisterGuiVariant()
{
- QVariantPrivate::registerHandler(QModulesPrivate::Gui, &qt_gui_variant_handler);
qMetaTypeGuiHelper = &qVariantGuiHelper;
}
Q_CONSTRUCTOR_FUNCTION(qRegisterGuiVariant)
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp
index 496cae7c26..a0e1b48dcb 100644
--- a/src/gui/kernel/qhighdpiscaling.cpp
+++ b/src/gui/kernel/qhighdpiscaling.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qhighdpiscaling_p.h"
#include "qguiapplication.h"
@@ -49,17 +13,13 @@
#include <QtCore/qmetaobject.h>
#include <algorithm>
+#include <optional>
QT_BEGIN_NAMESPACE
-Q_LOGGING_CATEGORY(lcScaling, "qt.scaling");
+Q_LOGGING_CATEGORY(lcHighDpi, "qt.highdpi");
#ifndef QT_NO_HIGHDPISCALING
-static const char legacyDevicePixelEnvVar[] = "QT_DEVICE_PIXEL_RATIO";
-
-// Note: QT_AUTO_SCREEN_SCALE_FACTOR is Done on X11, and should be kept
-// working as-is. It's Deprecated on all other platforms.
-static const char legacyAutoScreenEnvVar[] = "QT_AUTO_SCREEN_SCALE_FACTOR";
static const char enableHighDpiScalingEnvVar[] = "QT_ENABLE_HIGHDPI_SCALING";
static const char scaleFactorEnvVar[] = "QT_SCALE_FACTOR";
@@ -68,47 +28,38 @@ static const char scaleFactorRoundingPolicyEnvVar[] = "QT_SCALE_FACTOR_ROUNDING_
static const char dpiAdjustmentPolicyEnvVar[] = "QT_DPI_ADJUSTMENT_POLICY";
static const char usePhysicalDpiEnvVar[] = "QT_USE_PHYSICAL_DPI";
-// Per-screen scale factors for named screens set with QT_SCREEN_SCALE_FACTORS
-// are stored here. Use a global hash to keep the factor across screen
-// disconnect/connect cycles where the screen object may be deleted.
-typedef QHash<QString, qreal> QScreenScaleFactorHash;
-Q_GLOBAL_STATIC(QScreenScaleFactorHash, qNamedScreenScaleFactors);
+static std::optional<QString> qEnvironmentVariableOptionalString(const char *name)
+{
+ if (!qEnvironmentVariableIsSet(name))
+ return std::nullopt;
-// Reads and interprets the given environment variable as a bool,
-// returns the default value if not set.
-static bool qEnvironmentVariableAsBool(const char *name, bool defaultValue)
+ return std::optional(qEnvironmentVariable(name));
+}
+
+static std::optional<QByteArray> qEnvironmentVariableOptionalByteArray(const char *name)
+{
+ if (!qEnvironmentVariableIsSet(name))
+ return std::nullopt;
+
+ return std::optional(qgetenv(name));
+}
+
+static std::optional<int> qEnvironmentVariableOptionalInt(const char *name)
{
bool ok = false;
- int value = qEnvironmentVariableIntValue(name, &ok);
- return ok ? value > 0 : defaultValue;
+ const int value = qEnvironmentVariableIntValue(name, &ok);
+ auto opt = ok ? std::optional(value) : std::nullopt;
+ return opt;
}
-static inline qreal initialGlobalScaleFactor()
+static std::optional<qreal> qEnvironmentVariableOptionalReal(const char *name)
{
+ if (!qEnvironmentVariableIsSet(name))
+ return std::nullopt;
- qreal result = 1;
- if (qEnvironmentVariableIsSet(scaleFactorEnvVar)) {
- bool ok;
- const qreal f = qEnvironmentVariable(scaleFactorEnvVar).toDouble(&ok);
- if (ok && f > 0) {
- qCDebug(lcScaling) << "Apply " << scaleFactorEnvVar << f;
- result = f;
- }
- } else {
- // Check for deprecated environment variables.
- if (qEnvironmentVariableIsSet(legacyDevicePixelEnvVar)) {
- qWarning("Warning: %s is deprecated. Instead use:\n"
- " %s to enable platform plugin controlled per-screen factors.\n"
- " %s to set per-screen DPI.\n"
- " %s to set the application global scale factor.",
- legacyDevicePixelEnvVar, legacyAutoScreenEnvVar, screenFactorsEnvVar, scaleFactorEnvVar);
-
- int dpr = qEnvironmentVariableIntValue(legacyDevicePixelEnvVar);
- if (dpr > 0)
- result = dpr;
- }
- }
- return result;
+ bool ok = false;
+ const qreal value = qEnvironmentVariable(name).toDouble(&ok);
+ return ok ? std::optional(value) : std::nullopt;
}
/*!
@@ -121,8 +72,9 @@ static inline qreal initialGlobalScaleFactor()
\brief Collection of utility functions for UI scaling.
QHighDpiScaling implements utility functions for high-dpi scaling for use
- on operating systems that provide limited support for native scaling. In
- addition this functionality can be used for simulation and testing purposes.
+ on operating systems that provide limited support for native scaling, such
+ as Windows, X11, and Android. In addition this functionality can be used
+ for simulation and testing purposes.
The functions support scaling between the device independent coordinate
system used by Qt applications and the native coordinate system used by
@@ -152,14 +104,13 @@ static inline qreal initialGlobalScaleFactor()
pixels.
The devicePixelRatio seen by applications is the product of the Qt scale
- factor and the OS scale factor. The value of the scale factors may be 1,
- in which case two or more of the coordinate systems are equivalent. Platforms
- that (may) have an OS scale factor include \macos, iOS and Wayland.
+ factor and the OS scale factor (see QWindow::devicePixelRatio()). The value
+ of the scale factors may be 1, in which case two or more of the coordinate
+ systems are equivalent. Platforms that (may) have an OS scale factor include
+ macOS, iOS, Wayland, and Web(Assembly).
- Note that the functions in this file do not work with the OS scale factor
- directly and are limited to converting between device independent and native
- pixels. The OS scale factor is accounted for by QWindow::devicePixelRatio()
- and similar functions.
+ Note that the API implemented in this file do use the OS scale factor, and
+ is used for converting between device independent and native pixels only.
Configuration Examples:
@@ -172,7 +123,7 @@ static inline qreal initialGlobalScaleFactor()
| Display 100 x 100 |
-----------------------------------------------------
- 'Retina Device': Device Independent Pixels = Native Pixels
+ '2x Apple Device': Device Independent Pixels = Native Pixels
--------------------------------------------------- devicePixelRatio: 2
| Application / Qt Gui 100 x 100 |
| | Qt Scale Factor: 1
@@ -181,7 +132,7 @@ static inline qreal initialGlobalScaleFactor()
| Display 200 x 200 |
-----------------------------------------------------
- '2x Qt Scaling': Native Pixels = Device Pixels
+ 'Windows at 200%': Native Pixels = Device Pixels
--------------------------------------------------- devicePixelRatio: 2
| Application / Qt Gui 100 x 100 |
|---------------------------------------------------| Qt Scale Factor: 2
@@ -190,112 +141,123 @@ static inline qreal initialGlobalScaleFactor()
| Display 200 x 200 |
-----------------------------------------------------
- The Qt Scale Factor is the product of two sub-scale factors, which
- are independently either set or determined by the platform plugin.
- Several APIs are offered for this, targeting both developers and
- end users. All scale factors are of type qreal.
-
- 1) A global scale factor
- The QT_SCALE_FACTOR environment variable can be used to set
- a global scale factor for all windows in the process. This
- is useful for testing and debugging (you can simulate any
- devicePixelRatio without needing access to special hardware),
- and perhaps also for targeting a specific application to
- a specific display type (embedded use cases).
-
- 2) Per-screen scale factors
- Some platform plugins support providing a per-screen scale
- factor based on display density information. These platforms
- include X11, Windows, and Android.
-
- There are two APIs for enabling or disabling this behavior:
- - The QT_AUTO_SCREEN_SCALE_FACTOR environment variable.
- - The AA_EnableHighDpiScaling and AA_DisableHighDpiScaling
- application attributes
-
- Enabling either will make QHighDpiScaling call QPlatformScreen::pixelDensity()
- and use the value provided as the scale factor for the screen in
- question. Disabling is done on a 'veto' basis where either the
- environment or the application can disable the scaling. The intended use
- cases are 'My system is not providing correct display density
- information' and 'My application needs to work in display pixels',
- respectively.
-
- The QT_SCREEN_SCALE_FACTORS environment variable can be used to set the screen
- scale factors manually. Set this to a semicolon-separated
- list of scale factors (matching the order of QGuiApplications::screens()),
- or to a list of name=value pairs (where name matches QScreen::name()).
-
- Coordinate conversion functions must be used when writing code that passes
- geometry across the Qt Gui / Platform plugin boundary. The main conversion
- functions are:
- T toNativePixels(T, QWindow *)
- T fromNativePixels(T, QWindow*)
-
- The following classes in QtGui use native pixels, for the convenience of the
- platform plugins:
- QPlatformWindow
- QPlatformScreen
- QWindowSystemInterface (API only - Events are in device independent pixels)
-
- As a special consideration platform plugin code should be careful about
- calling QtGui geometry accessor functions:
- QRect r = window->geometry();
- Here the returned geometry is in device independent pixels. Add a conversion call:
- QRect r = QHighDpi::toNativePixels(window->geometry());
- (Avoiding calling QWindow and instead using the QPlatformWindow geometry
- might be a better course of action in this case.)
+ * Configuration
+
+ - Enabling: In Qt 6, high-dpi scaling (the functionality implemented in this file)
+ is always enabled. The Qt scale factor value is typically determined by the
+ QPlatformScreen implementation - see below.
+
+ There is one environment variable based opt-out option: set QT_ENABLE_HIGHDPI_SCALING=0.
+ Keep in mind that this does not affect the OS scale factor, which is controlled by
+ the operating system.
+
+ - Qt scale factor value: The Qt scale factor is the product of the screen scale
+ factor and the global scale factor, which are independently either set or determined
+ by the platform plugin. Several APIs are offered for this, targeting both developers
+ and end users. All scale factors are of type qreal.
+
+ 1) Per-screen scale factors
+
+ Per-screen scale factors are computed based on logical DPI provided by
+ by the platform plugin.
+
+ The platform plugin implements DPI accessor functions:
+ QDpi QPlatformScreen::logicalDpi()
+ QDpi QPlatformScreen::logicalBaseDpi()
+
+ QHighDpiScaling then computes the per-screen scale factor as follows:
+
+ factor = logicalDpi / logicalBaseDpi
+
+ Alternatively, QT_SCREEN_SCALE_FACTORS can be used to set the screen
+ scale factors.
+
+ 2) The global scale factor
+
+ The QT_SCALE_FACTOR environment variable can be used to set a global scale
+ factor which applies to all application windows. This allows developing and
+ testing at any DPR, independently of available hardware and without changing
+ global desktop settings.
+
+ - Rounding
+
+ Qt 6 does not round scale factors by default. Qt 5 rounds the screen scale factor
+ to the nearest integer (except for Qt on Android which does not round).
+
+ The rounding policy can be set by the application, or on the environment:
+
+ Application (C++): QGuiApplication::setHighDpiScaleFactorRoundingPolicy()
+ User (environment): QT_SCALE_FACTOR_ROUNDING_POLICY
+
+ Note that the OS scale factor, and global scale factors set with QT_SCALE_FACTOR
+ are never rounded by Qt.
+
+ * C++ API Overview
+
+ - Coordinate Conversion ("scaling")
+
+ The QHighDpi namespace provides several functions for converting geometry
+ between the device independent and native coordinate systems. These should
+ be used when calling "QPlatform*" API from QtGui. Callers are responsible
+ for selecting a function variant based on geometry type:
+
+ Type From Native To Native
+ local : QHighDpi::fromNativeLocalPosition() QHighDpi::toNativeLocalPosition()
+ global (screen) : QHighDpi::fromNativeGlobalPosition() QHighDpi::toNativeGlobalPosition()
+ QWindow::geometry() : QHighDpi::fromNativeWindowGeometry() QHighDpi::toNativeWindowGeometry()
+ sizes, margins, etc : QHighDpi::fromNativePixels() QHighDpi::toNativePixels()
+
+ The conversion functions take two arguments; the geometry and a context:
+
+ QSize nativeSize = toNativePixels(deviceIndependentSize, window);
+
+ The context is usually a QWindow instance, but can also be a QScreen instance,
+ or the corresponding QPlatform classes.
+
+ - Activation
+
+ QHighDpiScaling::isActive() returns true iff
+ Qt high-dpi scaling is enabled (e.g. with AA_EnableHighDpiScaling) AND
+ there is a Qt scale factor != 1
+
+ (the value of the OS scale factor does not affect this API)
+
+ - Calling QtGui from the platform plugins
+
+ Platform plugin code should be careful about calling QtGui geometry accessor
+ functions like geometry():
+
+ QRect r = window->geometry();
+
+ In this case the returned geometry is in the wrong coordinate system (device independent
+ instead of native pixels). Fix this by adding a conversion call:
+
+ QRect r = QHighDpi::toNativeWindowGeometry(window->geometry());
+
+ (Also consider if the call to QtGui is really needed - prefer calling QPlatform* API.)
*/
qreal QHighDpiScaling::m_factor = 1.0;
bool QHighDpiScaling::m_active = false; //"overall active" - is there any scale factor set.
-bool QHighDpiScaling::m_usePixelDensity = false; // use scale factor from platform plugin
-bool QHighDpiScaling::m_pixelDensityScalingActive = false; // pixel density scale factor > 1
+bool QHighDpiScaling::m_usePlatformPluginDpi = false; // use scale factor based on platform plugin DPI
+bool QHighDpiScaling::m_platformPluginDpiScalingActive = false; // platform plugin DPI gives a scale factor > 1
bool QHighDpiScaling::m_globalScalingActive = false; // global scale factor is active
bool QHighDpiScaling::m_screenFactorSet = false; // QHighDpiScaling::setScreenFactor has been used
-
-/*
- Initializes the QHighDpiScaling global variables. Called before the
- platform plugin is created.
-*/
-
-static inline bool usePixelDensity()
-{
- // Determine if we should set a scale factor based on the pixel density
- // reported by the platform plugin. There are several enablers and several
- // disablers. A single disable may veto all other enablers.
-
- // First, check of there is an explicit disable.
- if (QCoreApplication::testAttribute(Qt::AA_DisableHighDpiScaling))
- return false;
- bool screenEnvValueOk;
- const int screenEnvValue = qEnvironmentVariableIntValue(legacyAutoScreenEnvVar, &screenEnvValueOk);
- if (screenEnvValueOk && screenEnvValue < 1)
- return false;
- bool enableEnvValueOk;
- const int enableEnvValue = qEnvironmentVariableIntValue(enableHighDpiScalingEnvVar, &enableEnvValueOk);
- if (enableEnvValueOk && enableEnvValue < 1)
- return false;
-
- // Then return if there was an enable.
- return QCoreApplication::testAttribute(Qt::AA_EnableHighDpiScaling)
- || (screenEnvValueOk && screenEnvValue > 0)
- || (enableEnvValueOk && enableEnvValue > 0)
- || (qEnvironmentVariableIsSet(legacyDevicePixelEnvVar)
- && qEnvironmentVariable(legacyDevicePixelEnvVar).compare(QLatin1String("auto"), Qt::CaseInsensitive) == 0);
-}
+bool QHighDpiScaling::m_usePhysicalDpi = false;
+QVector<QHighDpiScaling::ScreenFactor> QHighDpiScaling::m_screenFactors;
+QHighDpiScaling::DpiAdjustmentPolicy QHighDpiScaling::m_dpiAdjustmentPolicy = QHighDpiScaling::DpiAdjustmentPolicy::Unset;
+QHash<QString, qreal> QHighDpiScaling::m_namedScreenScaleFactors; // Per-screen scale factors (screen name -> factor)
qreal QHighDpiScaling::rawScaleFactor(const QPlatformScreen *screen)
{
- // Determine if physical DPI should be used
- static const bool usePhysicalDpi = qEnvironmentVariableAsBool(usePhysicalDpiEnvVar, false);
-
// Calculate scale factor beased on platform screen DPI values
qreal factor;
QDpi platformBaseDpi = screen->logicalBaseDpi();
- if (usePhysicalDpi) {
- qreal platformPhysicalDpi = screen->screen()->physicalDotsPerInch();
- factor = qreal(platformPhysicalDpi) / qreal(platformBaseDpi.first);
+ if (QHighDpiScaling::m_usePhysicalDpi) {
+ QSize sz = screen->geometry().size();
+ QSizeF psz = screen->physicalSize();
+ qreal platformPhysicalDpi = ((sz.height() / psz.height()) + (sz.width() / psz.width())) * qreal(25.4 * 0.5);
+ factor = qRound(platformPhysicalDpi) / qreal(platformBaseDpi.first);
} else {
const QDpi platformLogicalDpi = QPlatformScreen::overrideDpi(screen->logicalDpi());
factor = qreal(platformLogicalDpi.first) / qreal(platformBaseDpi.first);
@@ -375,32 +337,9 @@ qreal QHighDpiScaling::roundScaleFactor(qreal rawFactor)
// sizes that are smaller than the ideal size, and opposite for rounding up.
// Rounding down is then preferable since "small UI" is a more acceptable
// high-DPI experience than "large UI".
- static auto scaleFactorRoundingPolicy = Qt::HighDpiScaleFactorRoundingPolicy::Unset;
-
- // Determine rounding policy
- if (scaleFactorRoundingPolicy == Qt::HighDpiScaleFactorRoundingPolicy::Unset) {
- // Check environment
- if (qEnvironmentVariableIsSet(scaleFactorRoundingPolicyEnvVar)) {
- QByteArray policyText = qgetenv(scaleFactorRoundingPolicyEnvVar);
- auto policyEnumValue = lookupScaleFactorRoundingPolicy(policyText);
- if (policyEnumValue != Qt::HighDpiScaleFactorRoundingPolicy::Unset) {
- scaleFactorRoundingPolicy = policyEnumValue;
- } else {
- auto values = joinEnumValues(std::begin(scaleFactorRoundingPolicyLookup),
- std::end(scaleFactorRoundingPolicyLookup));
- qWarning("Unknown scale factor rounding policy: %s. Supported values are: %s.",
- policyText.constData(), values.constData());
- }
- }
- // Check application object if no environment value was set.
- if (scaleFactorRoundingPolicy == Qt::HighDpiScaleFactorRoundingPolicy::Unset) {
- scaleFactorRoundingPolicy = QGuiApplication::highDpiScaleFactorRoundingPolicy();
- } else {
- // Make application setting reflect environment
- QGuiApplication::setHighDpiScaleFactorRoundingPolicy(scaleFactorRoundingPolicy);
- }
- }
+ Qt::HighDpiScaleFactorRoundingPolicy scaleFactorRoundingPolicy =
+ QGuiApplication::highDpiScaleFactorRoundingPolicy();
// Apply rounding policy.
qreal roundedFactor = rawFactor;
@@ -424,11 +363,9 @@ qreal QHighDpiScaling::roundScaleFactor(qreal rawFactor)
break;
}
- // Don't round down to to zero; clamp the minimum (rounded) factor to 1.
- // This is not a common case but can happen if a display reports a very
- // low DPI.
- if (scaleFactorRoundingPolicy != Qt::HighDpiScaleFactorRoundingPolicy::PassThrough)
- roundedFactor = qMax(roundedFactor, qreal(1));
+ // Clamp the minimum factor to 1. Qt does not currently render
+ // correctly with factors less than 1.
+ roundedFactor = qMax(roundedFactor, qreal(1));
return roundedFactor;
}
@@ -442,100 +379,154 @@ QDpi QHighDpiScaling::effectiveLogicalDpi(const QPlatformScreen *screen, qreal r
// with the rest of the UI. The amount of out-of-synch-ness depends on how
// well user code handles a non-standard DPI values, but since the
// adjustment is small (typically +/- 48 max) this might be OK.
- static auto dpiAdjustmentPolicy = DpiAdjustmentPolicy::Unset;
-
- // Determine adjustment policy.
- if (dpiAdjustmentPolicy == DpiAdjustmentPolicy::Unset) {
- if (qEnvironmentVariableIsSet(dpiAdjustmentPolicyEnvVar)) {
- QByteArray policyText = qgetenv(dpiAdjustmentPolicyEnvVar);
- auto policyEnumValue = lookupDpiAdjustmentPolicy(policyText);
- if (policyEnumValue != DpiAdjustmentPolicy::Unset) {
- dpiAdjustmentPolicy = policyEnumValue;
- } else {
- auto values = joinEnumValues(std::begin(dpiAdjustmentPolicyLookup),
- std::end(dpiAdjustmentPolicyLookup));
- qWarning("Unknown DPI adjustment policy: %s. Supported values are: %s.",
- policyText.constData(), values.constData());
- }
- }
- if (dpiAdjustmentPolicy == DpiAdjustmentPolicy::Unset)
- dpiAdjustmentPolicy = DpiAdjustmentPolicy::UpOnly;
- }
// Apply adjustment policy.
const QDpi baseDpi = screen->logicalBaseDpi();
const qreal dpiAdjustmentFactor = rawFactor / roundedFactor;
// Return the base DPI for cases where there is no adjustment
- if (dpiAdjustmentPolicy == DpiAdjustmentPolicy::Disabled)
+ if (QHighDpiScaling::m_dpiAdjustmentPolicy == DpiAdjustmentPolicy::Disabled)
return baseDpi;
- if (dpiAdjustmentPolicy == DpiAdjustmentPolicy::UpOnly && dpiAdjustmentFactor < 1)
+ if (QHighDpiScaling::m_dpiAdjustmentPolicy == DpiAdjustmentPolicy::UpOnly && dpiAdjustmentFactor < 1)
return baseDpi;
return QDpi(baseDpi.first * dpiAdjustmentFactor, baseDpi.second * dpiAdjustmentFactor);
}
+/*
+ Determine and apply global/initial configuration which do not depend on
+ having access to QScreen objects - this function is called before they
+ have been created. Screen-dependent configuration happens later in
+ updateHighDpiScaling().
+*/
void QHighDpiScaling::initHighDpiScaling()
{
- // Determine if there is a global scale factor set.
- m_factor = initialGlobalScaleFactor();
+ qCDebug(lcHighDpi) << "Initializing high-DPI scaling";
+
+ // Read environment variables
+ static const char* envDebugStr = "environment variable set:";
+ std::optional<int> envEnableHighDpiScaling = qEnvironmentVariableOptionalInt(enableHighDpiScalingEnvVar);
+ if (envEnableHighDpiScaling.has_value())
+ qCDebug(lcHighDpi) << envDebugStr << enableHighDpiScalingEnvVar << envEnableHighDpiScaling.value();
+
+ std::optional<qreal> envScaleFactor = qEnvironmentVariableOptionalReal(scaleFactorEnvVar);
+ if (envScaleFactor.has_value())
+ qCDebug(lcHighDpi) << envDebugStr << scaleFactorEnvVar << envScaleFactor.value();
+
+ std::optional<QString> envScreenFactors = qEnvironmentVariableOptionalString(screenFactorsEnvVar);
+ if (envScreenFactors.has_value())
+ qCDebug(lcHighDpi) << envDebugStr << screenFactorsEnvVar << envScreenFactors.value();
+
+ std::optional<int> envUsePhysicalDpi = qEnvironmentVariableOptionalInt(usePhysicalDpiEnvVar);
+ if (envUsePhysicalDpi.has_value())
+ qCDebug(lcHighDpi) << envDebugStr << usePhysicalDpiEnvVar << envUsePhysicalDpi.value();
+
+ std::optional<QByteArray> envScaleFactorRoundingPolicy = qEnvironmentVariableOptionalByteArray(scaleFactorRoundingPolicyEnvVar);
+ if (envScaleFactorRoundingPolicy.has_value())
+ qCDebug(lcHighDpi) << envDebugStr << scaleFactorRoundingPolicyEnvVar << envScaleFactorRoundingPolicy.value();
+
+ std::optional<QByteArray> envDpiAdjustmentPolicy = qEnvironmentVariableOptionalByteArray(dpiAdjustmentPolicyEnvVar);
+ if (envDpiAdjustmentPolicy.has_value())
+ qCDebug(lcHighDpi) << envDebugStr << dpiAdjustmentPolicyEnvVar << envDpiAdjustmentPolicy.value();
+
+ // High-dpi scaling is enabled by default; check for global disable.
+ m_usePlatformPluginDpi = envEnableHighDpiScaling.value_or(1) > 0;
+ m_platformPluginDpiScalingActive = false; // see updateHighDpiScaling()
+
+ // Check for glabal scale factor (different from 1)
+ m_factor = envScaleFactor.value_or(qreal(1));
m_globalScalingActive = !qFuzzyCompare(m_factor, qreal(1));
- m_usePixelDensity = usePixelDensity();
+ // Store the envScreenFactors string for later use. The string format
+ // supports using screen names, which means that screen DPI cannot
+ // be resolved at this point.
+ QString screenFactorsSpec = envScreenFactors.value_or(QString());
+ m_screenFactors = parseScreenScaleFactorsSpec(QStringView{screenFactorsSpec});
+ m_namedScreenScaleFactors.clear();
+
+ m_usePhysicalDpi = envUsePhysicalDpi.value_or(0) > 0;
+
+ // Resolve HighDpiScaleFactorRoundingPolicy to QGuiApplication::highDpiScaleFactorRoundingPolicy
+ if (envScaleFactorRoundingPolicy.has_value()) {
+ QByteArray policyText = envScaleFactorRoundingPolicy.value();
+ auto policyEnumValue = lookupScaleFactorRoundingPolicy(policyText);
+ if (policyEnumValue != Qt::HighDpiScaleFactorRoundingPolicy::Unset) {
+ QGuiApplication::setHighDpiScaleFactorRoundingPolicy(policyEnumValue);
+ } else {
+ auto values = joinEnumValues(std::begin(scaleFactorRoundingPolicyLookup),
+ std::end(scaleFactorRoundingPolicyLookup));
+ qWarning("Unknown scale factor rounding policy: %s. Supported values are: %s.",
+ policyText.constData(), values.constData());
+ }
+ }
+
+ // Resolve DpiAdjustmentPolicy to m_dpiAdjustmentPolicy
+ if (envDpiAdjustmentPolicy.has_value()) {
+ QByteArray policyText = envDpiAdjustmentPolicy.value();
+ auto policyEnumValue = lookupDpiAdjustmentPolicy(policyText);
+ if (policyEnumValue != DpiAdjustmentPolicy::Unset) {
+ QHighDpiScaling::m_dpiAdjustmentPolicy = policyEnumValue;
+ } else {
+ auto values = joinEnumValues(std::begin(dpiAdjustmentPolicyLookup),
+ std::end(dpiAdjustmentPolicyLookup));
+ qWarning("Unknown DPI adjustment policy: %s. Supported values are: %s.",
+ policyText.constData(), values.constData());
+ }
+ }
- m_pixelDensityScalingActive = false; //set in updateHighDpiScaling below
+ // Set initial active state
+ m_active = m_globalScalingActive || m_usePlatformPluginDpi;
- m_active = m_globalScalingActive || m_usePixelDensity;
+ qCDebug(lcHighDpi) << "Initialization done, high-DPI scaling is"
+ << (m_active ? "active" : "inactive");
}
+/*
+ Update configuration based on available screens and screen properties.
+ This function may be called whenever the screen configuration changed.
+*/
void QHighDpiScaling::updateHighDpiScaling()
{
- if (QCoreApplication::testAttribute(Qt::AA_DisableHighDpiScaling))
- return;
+ qCDebug(lcHighDpi) << "Updating high-DPI scaling";
- if (m_usePixelDensity && !m_pixelDensityScalingActive) {
+ // Apply screen factors from environment
+ if (m_screenFactors.size() > 0) {
+ qCDebug(lcHighDpi) << "Applying screen factors" << m_screenFactors;
+ int i = -1;
const auto screens = QGuiApplication::screens();
- for (QScreen *screen : screens) {
- if (!qFuzzyCompare(screenSubfactor(screen->handle()), qreal(1))) {
- m_pixelDensityScalingActive = true;
- break;
+ for (const auto &[name, rawFactor]: m_screenFactors) {
+ const qreal factor = roundScaleFactor(rawFactor);
+ ++i;
+ if (name.isNull()) {
+ if (i < screens.size())
+ setScreenFactor(screens.at(i), factor);
+ } else {
+ for (QScreen *screen : screens) {
+ if (screen->name() == name) {
+ setScreenFactor(screen, factor);
+ break;
+ }
+ }
}
}
}
- if (qEnvironmentVariableIsSet(screenFactorsEnvVar)) {
- int i = 0;
- const QString spec = qEnvironmentVariable(screenFactorsEnvVar);
- const auto specs = QStringView{spec}.split(u';');
- for (const auto &spec : specs) {
- int equalsPos = spec.lastIndexOf(QLatin1Char('='));
- qreal factor = 0;
- if (equalsPos > 0) {
- // support "name=factor"
- bool ok;
- const auto name = spec.left(equalsPos);
- factor = spec.mid(equalsPos + 1).toDouble(&ok);
- if (ok && factor > 0 ) {
- const auto screens = QGuiApplication::screens();
- for (QScreen *s : screens) {
- if (s->name() == name) {
- setScreenFactor(s, factor);
- break;
- }
- }
- }
- } else {
- // listing screens in order
- bool ok;
- factor = spec.toDouble(&ok);
- if (ok && factor > 0 && i < QGuiApplication::screens().count()) {
- QScreen *screen = QGuiApplication::screens().at(i);
- setScreenFactor(screen, factor);
- }
+
+ // Check if any screens (now) has a scale factor != 1 and set
+ // m_platformPluginDpiScalingActive if so.
+ if (m_usePlatformPluginDpi && !m_platformPluginDpiScalingActive ) {
+ const auto screens = QGuiApplication::screens();
+ for (QScreen *screen : screens) {
+ if (!qFuzzyCompare(screenSubfactor(screen->handle()), qreal(1))) {
+ m_platformPluginDpiScalingActive = true;
+ break;
}
- ++i;
}
}
- m_active = m_globalScalingActive || m_screenFactorSet || m_pixelDensityScalingActive;
+
+ m_active = m_globalScalingActive || m_screenFactorSet || m_platformPluginDpiScalingActive;
+
+ qCDebug(lcHighDpi) << "Update done, high-DPI scaling is"
+ << (m_active ? "active" : "inactive");
}
/*
@@ -543,17 +534,24 @@ void QHighDpiScaling::updateHighDpiScaling()
*/
void QHighDpiScaling::setGlobalFactor(qreal factor)
{
+ qCDebug(lcHighDpi) << "Setting global scale factor to" << factor;
+
if (qFuzzyCompare(factor, m_factor))
return;
if (!QGuiApplication::allWindows().isEmpty())
qWarning("QHighDpiScaling::setFactor: Should only be called when no windows exist.");
+ const auto screens = QGuiApplication::screens();
+
+ std::vector<QScreenPrivate::UpdateEmitter> updateEmitters;
+ for (QScreen *screen : screens)
+ updateEmitters.emplace_back(screen);
+
m_globalScalingActive = !qFuzzyCompare(factor, qreal(1));
m_factor = m_globalScalingActive ? factor : qreal(1);
- m_active = m_globalScalingActive || m_screenFactorSet || m_pixelDensityScalingActive;
- const auto screens = QGuiApplication::screens();
+ m_active = m_globalScalingActive || m_screenFactorSet || m_platformPluginDpiScalingActive ;
for (QScreen *screen : screens)
- screen->d_func()->updateHighDpi();
+ screen->d_func()->updateGeometry();
}
static const char scaleFactorProperty[] = "_q_scaleFactor";
@@ -563,22 +561,24 @@ static const char scaleFactorProperty[] = "_q_scaleFactor";
*/
void QHighDpiScaling::setScreenFactor(QScreen *screen, qreal factor)
{
+ qCDebug(lcHighDpi) << "Setting screen scale factor for" << screen << "to" << factor;
+
if (!qFuzzyCompare(factor, qreal(1))) {
m_screenFactorSet = true;
m_active = true;
}
+ QScreenPrivate::UpdateEmitter updateEmitter(screen);
+
// Prefer associating the factor with screen name over the object
// since the screen object may be deleted on screen disconnects.
const QString name = screen->name();
if (name.isEmpty())
screen->setProperty(scaleFactorProperty, QVariant(factor));
else
- qNamedScreenScaleFactors()->insert(name, factor);
+ QHighDpiScaling::m_namedScreenScaleFactors.insert(name, factor);
- // hack to force re-evaluation of screen geometry
- if (screen->handle())
- screen->d_func()->setPlatformScreen(screen->handle()); // updates geometries based on scale factor
+ screen->d_func()->updateGeometry();
}
QPoint QHighDpiScaling::mapPositionToNative(const QPoint &pos, const QPlatformScreen *platformScreen)
@@ -599,46 +599,6 @@ QPoint QHighDpiScaling::mapPositionFromNative(const QPoint &pos, const QPlatform
return (pos - topLeft) / scaleFactor + topLeft;
}
-QPoint QHighDpiScaling::mapPositionToGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window)
-{
- QPoint globalPosCandidate = pos + windowGlobalPosition;
- if (QGuiApplicationPrivate::screen_list.size() <= 1)
- return globalPosCandidate;
-
- // The global position may be outside device independent screen geometry
- // in cases where a window spans screens. Detect this case and map via
- // native coordinates to the correct screen.
- auto currentScreen = window->screen();
- if (currentScreen && !currentScreen->geometry().contains(globalPosCandidate)) {
- auto nativeGlobalPos = QHighDpi::toNativePixels(globalPosCandidate, currentScreen);
- if (auto actualPlatformScreen = currentScreen->handle()->screenForPosition(nativeGlobalPos))
- return QHighDpi::fromNativePixels(nativeGlobalPos, actualPlatformScreen->screen());
- }
-
- return globalPosCandidate;
-}
-
-QPoint QHighDpiScaling::mapPositionFromGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window)
-{
- QPoint windowPosCandidate = pos - windowGlobalPosition;
- if (QGuiApplicationPrivate::screen_list.size() <= 1 || window->handle() == nullptr)
- return windowPosCandidate;
-
- // Device independent global (screen) space may discontiguous when high-dpi scaling
- // is active. This means that the normal subtracting of the window global position from the
- // position-to-be-mapped may not work in cases where a window spans multiple screens.
- // Map both positions to native global space (using the correct screens), subtract there,
- // and then map the difference back using the scale factor for the window.
- QScreen *posScreen = QGuiApplication::screenAt(pos);
- if (posScreen && posScreen != window->screen()) {
- QPoint nativePos = QHighDpi::toNativePixels(pos, posScreen);
- QPoint windowNativePos = window->handle()->geometry().topLeft();
- return QHighDpi::fromNativeLocalPosition(nativePos - windowNativePos, window);
- }
-
- return windowPosCandidate;
-}
-
qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen)
{
auto factor = qreal(1.0);
@@ -661,13 +621,13 @@ qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen)
}
if (!screenPropertyUsed) {
- auto byNameIt = qNamedScreenScaleFactors()->constFind(screen->name());
- if ((screenPropertyUsed = byNameIt != qNamedScreenScaleFactors()->cend()))
+ auto byNameIt = QHighDpiScaling::m_namedScreenScaleFactors.constFind(screen->name());
+ if ((screenPropertyUsed = byNameIt != QHighDpiScaling::m_namedScreenScaleFactors.cend()))
factor = *byNameIt;
}
}
- if (!screenPropertyUsed && m_usePixelDensity)
+ if (!screenPropertyUsed && m_usePlatformPluginDpi)
factor = roundScaleFactor(rawScaleFactor(screen));
return factor;
@@ -679,7 +639,7 @@ QDpi QHighDpiScaling::logicalDpi(const QScreen *screen)
if (!screen || !screen->handle())
return QDpi(96, 96);
- if (!m_usePixelDensity) {
+ if (!m_usePlatformPluginDpi) {
const qreal screenScaleFactor = screenSubfactor(screen->handle());
const QDpi dpi = QPlatformScreen::overrideDpi(screen->handle()->logicalDpi());
return QDpi{ dpi.first / screenScaleFactor, dpi.second / screenScaleFactor };
@@ -690,37 +650,123 @@ QDpi QHighDpiScaling::logicalDpi(const QScreen *screen)
return effectiveLogicalDpi(screen->handle(), scaleFactor, roundedScaleFactor);
}
-QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QPlatformScreen *platformScreen, QPoint *nativePosition)
+// Returns the screen containing \a position, using \a guess as a starting point
+// for the search. \a guess might be nullptr. Returns nullptr if \a position is outside
+// of all screens.
+QScreen *QHighDpiScaling::screenForPosition(QHighDpiScaling::Point position, QScreen *guess)
{
+ if (position.kind == QHighDpiScaling::Point::Invalid)
+ return nullptr;
+
+ auto getPlatformScreenGuess = [](QScreen *maybeScreen) -> QPlatformScreen * {
+ if (maybeScreen)
+ return maybeScreen->handle();
+ if (QScreen *primary = QGuiApplication::primaryScreen())
+ return primary->handle();
+ return nullptr;
+ };
+
+ QPlatformScreen *platformGuess = getPlatformScreenGuess(guess);
+ if (!platformGuess)
+ return nullptr;
+
+ auto onScreen = [](QHighDpiScaling::Point position, const QPlatformScreen *platformScreen) -> bool {
+ return position.kind == Point::Native
+ ? platformScreen->geometry().contains(position.point)
+ : platformScreen->screen()->geometry().contains(position.point);
+ };
+
+ // is the guessed screen correct?
+ if (onScreen(position, platformGuess))
+ return platformGuess->screen();
+
+ // search sibling screens
+ const auto screens = platformGuess->virtualSiblings();
+ for (const QPlatformScreen *screen : screens) {
+ if (onScreen(position, screen))
+ return screen->screen();
+ }
+
+ return nullptr;
+}
+
+QVector<QHighDpiScaling::ScreenFactor> QHighDpiScaling::parseScreenScaleFactorsSpec(const QStringView &screenScaleFactors)
+{
+ QVector<QHighDpiScaling::ScreenFactor> screenFactors;
+
+ // The spec is _either_
+ // - a semicolon-separated ordered factor list: "1.5;2;3"
+ // - a semicolon-separated name=factor list: "foo=1.5;bar=2;baz=3"
+ const auto specs = screenScaleFactors.split(u';');
+ for (const auto &spec : specs) {
+ const qsizetype equalsPos = spec.lastIndexOf(u'=');
+ if (equalsPos == -1) {
+ // screens in order
+ bool ok;
+ const qreal factor = spec.toDouble(&ok);
+ if (ok && factor > 0) {
+ screenFactors.append(QHighDpiScaling::ScreenFactor(QString(), factor));
+ }
+ } else {
+ // "name=factor"
+ bool ok;
+ const qreal factor = spec.mid(equalsPos + 1).toDouble(&ok);
+ if (ok && factor > 0) {
+ screenFactors.append(QHighDpiScaling::ScreenFactor(spec.left(equalsPos).toString(), factor));
+ }
+ }
+ } // for (specs)
+
+ return screenFactors;
+}
+
+QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QPlatformScreen *platformScreen, QHighDpiScaling::Point position)
+{
+ Q_UNUSED(position)
if (!m_active)
return { qreal(1), QPoint() };
if (!platformScreen)
return { m_factor, QPoint() }; // the global factor
- const QPlatformScreen *actualScreen = nativePosition ?
- platformScreen->screenForPosition(*nativePosition) : platformScreen;
- return { m_factor * screenSubfactor(actualScreen), actualScreen->geometry().topLeft() };
+ return { m_factor * screenSubfactor(platformScreen), platformScreen->geometry().topLeft() };
}
-QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QScreen *screen, QPoint *nativePosition)
+QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QScreen *screen, QHighDpiScaling::Point position)
{
+ Q_UNUSED(position)
if (!m_active)
return { qreal(1), QPoint() };
if (!screen)
return { m_factor, QPoint() }; // the global factor
- return scaleAndOrigin(screen->handle(), nativePosition);
+ return scaleAndOrigin(screen->handle(), position);
}
-QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QWindow *window, QPoint *nativePosition)
+QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QWindow *window, QHighDpiScaling::Point position)
{
if (!m_active)
return { qreal(1), QPoint() };
+ // Determine correct screen; use the screen which contains the given
+ // position if a valid position is passed.
QScreen *screen = window ? window->screen() : QGuiApplication::primaryScreen();
- const bool searchScreen = !window || window->isTopLevel();
- return scaleAndOrigin(screen, searchScreen ? nativePosition : nullptr);
+ QScreen *overrideScreen = QHighDpiScaling::screenForPosition(position, screen);
+ QScreen *targetScreen = overrideScreen ? overrideScreen : screen;
+ return scaleAndOrigin(targetScreen, position);
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug debug, const QHighDpiScaling::ScreenFactor &factor)
+{
+ const QDebugStateSaver saver(debug);
+ debug.nospace();
+ if (!factor.name.isEmpty())
+ debug << factor.name << "=";
+ debug << factor.factor;
+ return debug;
}
+#endif
+
+#else // QT_NO_HIGHDPISCALING
-#else
QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QPlatformScreen *, QPoint *)
{
return { qreal(1), QPoint() };
@@ -735,5 +781,9 @@ QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QWindow *,
{
return { qreal(1), QPoint() };
}
-#endif //QT_NO_HIGHDPISCALING
+
+#endif // QT_NO_HIGHDPISCALING
+
QT_END_NAMESPACE
+
+#include "moc_qhighdpiscaling_p.cpp"
diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h
index dfacf2a4f3..189f31fd0a 100644
--- a/src/gui/kernel/qhighdpiscaling_p.h
+++ b/src/gui/kernel/qhighdpiscaling_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QHIGHDPISCALING_P_H
#define QHIGHDPISCALING_P_H
@@ -64,7 +28,7 @@
QT_BEGIN_NAMESPACE
-Q_DECLARE_LOGGING_CATEGORY(lcScaling);
+Q_DECLARE_LOGGING_CATEGORY(lcHighDpi);
class QScreen;
class QPlatformScreen;
@@ -96,45 +60,66 @@ public:
static bool isActive() { return m_active; }
+ struct Point {
+ enum Kind {
+ Invalid,
+ DeviceIndependent,
+ Native
+ };
+ Kind kind;
+ QPoint point;
+ };
+
struct ScaleAndOrigin
{
qreal factor;
QPoint origin;
};
- static ScaleAndOrigin scaleAndOrigin(const QPlatformScreen *platformScreen, QPoint *nativePosition = nullptr);
- static ScaleAndOrigin scaleAndOrigin(const QScreen *screen, QPoint *nativePosition = nullptr);
- static ScaleAndOrigin scaleAndOrigin(const QWindow *platformScreen, QPoint *nativePosition = nullptr);
+
+ static ScaleAndOrigin scaleAndOrigin(const QPlatformScreen *platformScreen, Point position = Point{ Point::Invalid, QPoint() });
+ static ScaleAndOrigin scaleAndOrigin(const QScreen *screen, Point position = Point{ Point::Invalid, QPoint() });
+ static ScaleAndOrigin scaleAndOrigin(const QWindow *platformScreen, Point position = Point{ Point::Invalid, QPoint() });
template<typename C>
- static qreal factor(C *context, QPoint *nativePosition = nullptr) {
- return scaleAndOrigin(context, nativePosition).factor;
+ static qreal factor(C *context) {
+ return scaleAndOrigin(context).factor;
}
static QPoint mapPositionFromNative(const QPoint &pos, const QPlatformScreen *platformScreen);
static QPoint mapPositionToNative(const QPoint &pos, const QPlatformScreen *platformScreen);
- static QPoint mapPositionToGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window);
- static QPoint mapPositionFromGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window);
static QDpi logicalDpi(const QScreen *screen);
+ static qreal roundScaleFactor(qreal rawFactor);
private:
+ struct ScreenFactor {
+ ScreenFactor(QString name, qreal factor)
+ :name(name), factor(factor) { }
+ QString name;
+ qreal factor;
+ };
+
static qreal rawScaleFactor(const QPlatformScreen *screen);
- static qreal roundScaleFactor(qreal rawFactor);
static QDpi effectiveLogicalDpi(const QPlatformScreen *screen, qreal rawFactor, qreal roundedFactor);
static qreal screenSubfactor(const QPlatformScreen *screen);
+ static QScreen *screenForPosition(Point position, QScreen *guess);
+ static QVector<QHighDpiScaling::ScreenFactor> parseScreenScaleFactorsSpec(const QStringView &screenScaleFactors);
static qreal m_factor;
static bool m_active;
- static bool m_usePixelDensity;
+ static bool m_usePlatformPluginDpi;
+ static bool m_platformPluginDpiScalingActive;
static bool m_globalScalingActive;
- static bool m_pixelDensityScalingActive;
static bool m_screenFactorSet;
- static QDpi m_logicalDpi;
+ static bool m_usePhysicalDpi;
+ static QVector<ScreenFactor> m_screenFactors;
+ static DpiAdjustmentPolicy m_dpiAdjustmentPolicy;
+ static QHash<QString, qreal> m_namedScreenScaleFactors;
+
+#ifndef QT_NO_DEBUG_STREAM
+ friend Q_GUI_EXPORT QDebug operator<<(QDebug, const ScreenFactor &);
+#endif
};
-// Coordinate system conversion functions:
-// QHighDpi::fromNativePixels : from physical(screen/backing) to logical pixels
-// QHighDpi::toNativePixels : from logical to physical pixels
-
namespace QHighDpi {
inline qreal scale(qreal value, qreal scaleFactor, QPointF /* origin */ = QPointF(0, 0))
@@ -179,20 +164,20 @@ inline QRectF scale(const QRectF &rect, qreal scaleFactor, QPoint origin = QPoin
inline QMargins scale(const QMargins &margins, qreal scaleFactor, QPoint origin = QPoint(0, 0))
{
- Q_UNUSED(origin)
+ Q_UNUSED(origin);
return QMargins(qRound(qreal(margins.left()) * scaleFactor), qRound(qreal(margins.top()) * scaleFactor),
qRound(qreal(margins.right()) * scaleFactor), qRound(qreal(margins.bottom()) * scaleFactor));
}
template<typename T>
-QList<T> scale(const QList<T> &vector, qreal scaleFactor, QPoint origin = QPoint(0, 0))
+QList<T> scale(const QList<T> &list, qreal scaleFactor, QPoint origin = QPoint(0, 0))
{
if (!QHighDpiScaling::isActive())
- return vector;
+ return list;
QList<T> scaled;
- scaled.reserve(vector.size());
- for (const T &item : vector)
+ scaled.reserve(list.size());
+ for (const T &item : list)
scaled.append(scale(item, scaleFactor, origin));
return scaled;
}
@@ -202,24 +187,32 @@ inline QRegion scale(const QRegion &region, qreal scaleFactor, QPoint origin = Q
if (!QHighDpiScaling::isActive())
return region;
- QRegion scaled;
- for (const QRect &rect : region)
- scaled += scale(rect, scaleFactor, origin);
- return scaled;
+ QRegion scaled = region.translated(-origin);
+ scaled = QTransform::fromScale(scaleFactor, scaleFactor).map(scaled);
+ return scaled.translated(origin);
}
template <typename T>
-inline QPoint position(T) { return QPoint(); }
-inline QPoint position(QPoint point) { return point; }
-inline QPoint position(QPointF point) { return point.toPoint(); }
-inline QPoint position(QRect rect) { return rect.center(); }
-inline QPoint position(QRectF rect) { return rect.center().toPoint(); }
+inline QHighDpiScaling::Point position(T, QHighDpiScaling::Point::Kind) {
+ return QHighDpiScaling::Point{ QHighDpiScaling::Point::Invalid, QPoint() };
+}
+inline QHighDpiScaling::Point position(QPoint point, QHighDpiScaling::Point::Kind kind) {
+ return QHighDpiScaling::Point{ kind, point };
+}
+inline QHighDpiScaling::Point position(QPointF point, QHighDpiScaling::Point::Kind kind) {
+ return QHighDpiScaling::Point{ kind, point.toPoint() };
+}
+inline QHighDpiScaling::Point position(QRect rect, QHighDpiScaling::Point::Kind kind) {
+ return QHighDpiScaling::Point{ kind, rect.topLeft() };
+}
+inline QHighDpiScaling::Point position(QRectF rect, QHighDpiScaling::Point::Kind kind) {
+ return QHighDpiScaling::Point{ kind, rect.topLeft().toPoint() };
+}
template <typename T, typename C>
T fromNativePixels(const T &value, const C *context)
{
- QPoint nativePosition = position(value);
- QHighDpiScaling::ScaleAndOrigin so = QHighDpiScaling::scaleAndOrigin(context, &nativePosition);
+ QHighDpiScaling::ScaleAndOrigin so = QHighDpiScaling::scaleAndOrigin(context);
return scale(value, qreal(1) / so.factor, so.origin);
}
@@ -242,6 +235,38 @@ T toNativeLocalPosition(const T &value, const C *context)
return scale(value, QHighDpiScaling::factor(context));
}
+template <typename T, typename C>
+T fromNativeGlobalPosition(const T &value, const C *context)
+{
+ QHighDpiScaling::ScaleAndOrigin so =
+ QHighDpiScaling::scaleAndOrigin(context, position(value, QHighDpiScaling::Point::Native));
+ return scale(value, qreal(1) / so.factor, so.origin);
+}
+
+template <typename T, typename C>
+T toNativeGlobalPosition(const T &value, const C *context)
+{
+ QHighDpiScaling::ScaleAndOrigin so =
+ QHighDpiScaling::scaleAndOrigin(context, position(value, QHighDpiScaling::Point::DeviceIndependent));
+ return scale(value, so.factor, so.origin);
+}
+
+template <typename T, typename C>
+T fromNativeWindowGeometry(const T &value, const C *context)
+{
+ QHighDpiScaling::ScaleAndOrigin so = QHighDpiScaling::scaleAndOrigin(context);
+ QPoint effectiveOrigin = (context && context->isTopLevel()) ? so.origin : QPoint(0,0);
+ return scale(value, qreal(1) / so.factor, effectiveOrigin);
+}
+
+template <typename T, typename C>
+T toNativeWindowGeometry(const T &value, const C *context)
+{
+ QHighDpiScaling::ScaleAndOrigin so = QHighDpiScaling::scaleAndOrigin(context);
+ QPoint effectiveOrigin = (context && context->isTopLevel()) ? so.origin : QPoint(0,0);
+ return scale(value, so.factor, effectiveOrigin);
+}
+
template <typename T>
inline T fromNative(const T &value, qreal scaleFactor, QPoint origin = QPoint(0, 0))
{
@@ -279,13 +304,9 @@ inline QRegion fromNativeLocalExposedRegion(const QRegion &pixelRegion, const QW
const qreal scaleFactor = QHighDpiScaling::factor(window);
QRegion pointRegion;
- for (const QRectF rect: pixelRegion) {
- const QPointF topLeftP = rect.topLeft() / scaleFactor;
- const QSizeF sizeP = rect.size() / scaleFactor;
- pointRegion += QRect(QPoint(qFloor(topLeftP.x()), qFloor(topLeftP.y())),
- QPoint(qCeil(topLeftP.x() + sizeP.width() - 1.0),
- qCeil(topLeftP.y() + sizeP.height() - 1.0)));
- }
+ for (const QRectF rect: pixelRegion)
+ pointRegion += QRectF(rect.topLeft() / scaleFactor, rect.size() / scaleFactor).toAlignedRect();
+
return pointRegion;
}
@@ -320,13 +341,16 @@ public:
static inline QPoint origin(const QPlatformScreen *) { return QPoint(); }
static inline QPoint mapPositionFromNative(const QPoint &pos, const QPlatformScreen *) { return pos; }
static inline QPoint mapPositionToNative(const QPoint &pos, const QPlatformScreen *) { return pos; }
- static inline QPoint mapPositionToGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window) { return pos; }
- static inline QPoint mapPositionFromGlobal(const QPoint &pos, const QPoint &windowGlobalPosition, const QWindow *window) { return pos; }
- static inline QDpi logicalDpi(const QScreen *screen) { return QDpi(-1,-1); }
+ static inline QPointF mapPositionToGlobal(const QPointF &pos, const QPoint &, const QWindow *) { return pos; }
+ static inline QPointF mapPositionFromGlobal(const QPointF &pos, const QPoint &, const QWindow *) { return pos; }
+ static inline QDpi logicalDpi(const QScreen *) { return QDpi(-1,-1); }
};
namespace QHighDpi {
template <typename T> inline
+ T scale(const T &value, ...) { return value; }
+
+ template <typename T> inline
T toNative(const T &value, ...) { return value; }
template <typename T> inline
T fromNative(const T &value, ...) { return value; }
@@ -335,6 +359,14 @@ namespace QHighDpi {
T fromNativeLocalPosition(const T &value, ...) { return value; }
template <typename T> inline
T toNativeLocalPosition(const T &value, ...) { return value; }
+ template <typename T, typename C> inline
+ T fromNativeGlobalPosition(const T &value, const C *) { return value; }
+ template <typename T, typename C> inline
+ T toNativeGlobalPosition(const T &value, const C *) { return value; }
+ template <typename T, typename C> inline
+ T fromNativeWindowGeometry(const T &value, const C *) { return value; }
+ template <typename T, typename C> inline
+ T toNativeWindowGeometry(const T &value, const C *) { return value; }
template <typename T> inline
T fromNativeLocalRegion(const T &value, ...) { return value; }
diff --git a/src/gui/kernel/qinputdevice.cpp b/src/gui/kernel/qinputdevice.cpp
index d64f2c4ddc..f7b216dcf0 100644
--- a/src/gui/kernel/qinputdevice.cpp
+++ b/src/gui/kernel/qinputdevice.cpp
@@ -1,54 +1,18 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qinputdevice.h"
#include "qinputdevice_p.h"
#include "qpointingdevice.h"
+#include "qwindowsysteminterface_p.h"
#include <QCoreApplication>
#include <QDebug>
-#include <QLoggingCategory>
#include <QMutex>
#include <QScreen>
QT_BEGIN_NAMESPACE
-Q_DECLARE_LOGGING_CATEGORY(lcQpaInputDevices)
+using namespace Qt::StringLiterals;
/*!
\class QInputDevice
@@ -68,10 +32,76 @@ Q_DECLARE_LOGGING_CATEGORY(lcQpaInputDevices)
*/
/*!
- Creates a new invalid input device instance.
+ \enum QInputDevice::Capability
+
+ Indicates what kind of information the input device or its driver can
+ provide.
+
+ \value None
+ No information about input device capabilities available.
+
+ \value Position
+ Indicates that position information is available, meaning that the
+ position() family of functions in the touch points return valid points.
+
+ \value Area
+ Indicates that touch area information is available, meaning that
+ QEventPoint::ellipseDiameters() in the touch points return valid
+ values.
+
+ \value Pressure
+ Indicates that pressure information is available, meaning that
+ QEventPoint::pressure() returns a valid value.
+
+ \value Velocity
+ Indicates that velocity information is available, meaning that
+ QEventPoint::velocity() returns a valid vector.
+
+ \value NormalizedPosition
+ Indicates that the normalized position is available, meaning that
+ QEventPoint::globalPosition() returns a valid value.
+
+ \value MouseEmulation
+ Indicates that the device synthesizes mouse events.
+
+ \value Scroll
+ Indicates that the device has a scroll capability.
+
+ \value [since 6.2] PixelScroll
+ Indicates that the device (usually a
+ \l {QInputDevice::DeviceType::TouchPad}{touchpad})
+ scrolls with \l {QWheelEvent::pixelDelta()}{pixel precision}.
+
+ \value Hover
+ Indicates that the device has a hover capability.
+
+ \value Rotation
+ Indicates that \l {QEventPoint::}{rotation} information is available.
+
+ \value XTilt
+ Indicates that \l {QTabletEvent::xTilt()}{tilt} information is
+ available for the X-axis.
+
+ \value YTilt
+ Indicates that \l {QTabletEvent::yTilt()}{tilt} information is
+ available for the Y-axis.
+
+ \value TangentialPressure
+ Indicates that \l {QTabletEvent::tangentialPressure()}
+ {tangential pressure} information is available.
+
+ \value ZPosition
+ Indicates that position information for the \l {QTabletEvent::z()}
+ {Z-axis} is available.
+
+ \value All
*/
-QInputDevice::QInputDevice()
- : QObject(*(new QInputDevicePrivate(QString(), -1, QInputDevice::DeviceType::Unknown)), nullptr)
+
+/*!
+ Creates a new invalid input device instance as a child of \a parent.
+*/
+QInputDevice::QInputDevice(QObject *parent)
+ : QObject(*(new QInputDevicePrivate(QString(), -1, QInputDevice::DeviceType::Unknown)), parent)
{
}
@@ -113,6 +143,29 @@ QInputDevice::QInputDevice(QInputDevicePrivate &d, QObject *parent)
}
/*!
+ Returns the region within the \l{QScreen::availableVirtualGeometry}{virtual desktop}
+ that this device can access.
+
+ For example a \l {QInputDevice::DeviceType}{TouchScreen} input
+ device is fixed in place upon a single physical screen, and usually
+ calibrated so that this area is the same as QScreen::geometry(); whereas a
+ \l {QInputDevice::DeviceType}{Mouse} can probably access all screens
+ on the virtual desktop. A Wacom graphics tablet may be configured in a way
+ that it's mapped to all screens, or only to the screen where the user
+ prefers to create drawings, or to the window in which drawing occurs.
+ A \l {QInputDevice::DeviceType}{Stylus} device that is integrated
+ with a touchscreen may be physically limited to that screen.
+
+ If the returned rectangle is \l {QRect::isNull()}{null}, it means this device
+ can access the entire virtual desktop.
+*/
+QRect QInputDevice::availableVirtualGeometry() const
+{
+ Q_D(const QInputDevice);
+ return d->availableVirtualGeometry;
+}
+
+/*!
Returns the device name.
This string may be empty. It is however useful on systems that have
@@ -152,14 +205,14 @@ bool QInputDevice::hasCapability(QInputDevice::Capability capability) const
}
/*!
- Returns the platform ID (for example xinput ID on the X11 platform).
+ Returns the platform specific system ID (for example xinput ID on the X11 platform).
- All platforms are expected to provide a unique ID for each device.
+ All platforms are expected to provide a unique system ID for each device.
*/
-qint64 QInputDevice::id() const
+qint64 QInputDevice::systemId() const
{
Q_D(const QInputDevice);
- return d->id;
+ return d->systemId;
}
/*!
@@ -177,14 +230,21 @@ QString QInputDevice::seatName() const
using InputDevicesList = QList<const QInputDevice *>;
Q_GLOBAL_STATIC(InputDevicesList, deviceList)
-static QBasicMutex devicesMutex;
+Q_CONSTINIT static QBasicMutex devicesMutex;
/*!
Returns a list of all registered input devices (keyboards and pointing devices).
+ \note The list of devices is not always complete on all platforms. So far,
+ the most-complete information is available on the \l {Qt for Linux/X11}{X11}
+ platform, at startup and in response to hot-plugging. Most other platforms
+ are only able to provide generic devices of various types, only after receiving
+ events from them; and most platforms do not tell Qt when a device is plugged in,
+ or when it is unplugged at runtime.
+
\note The returned list cannot be used to add new devices. To add a simulated
touch screen for an autotest, QTest::createTouchDevice() can be used.
- Platform plugins should call \l QWindowSystemInterface::registerInputDevice()
+ Platform plugins should call QWindowSystemInterface::registerInputDevice()
to add devices as they are discovered.
*/
QList<const QInputDevice *> QInputDevice::devices()
@@ -194,16 +254,37 @@ QList<const QInputDevice *> QInputDevice::devices()
}
/*!
+ \since 6.3
+
+ Returns a list of seat names for all registered input devices (keyboards and pointing devices).
+*/
+QStringList QInputDevice::seatNames()
+{
+ QMutexLocker locker(&devicesMutex);
+ const InputDevicesList devices = *deviceList();
+ locker.unlock();
+ QStringList result;
+ for (const QInputDevice *d : devices) {
+ if (!result.contains(d->seatName()))
+ result.append(d->seatName());
+ }
+
+ return result;
+}
+
+/*!
Returns the core or master keyboard on the given seat \a seatName.
*/
const QInputDevice *QInputDevice::primaryKeyboard(const QString& seatName)
{
QMutexLocker locker(&devicesMutex);
- InputDevicesList v = *deviceList();
+ const InputDevicesList devices = *deviceList();
locker.unlock();
const QInputDevice *ret = nullptr;
- for (const QInputDevice *d : v) {
- if (d->type() == DeviceType::Keyboard && d->seatName() == seatName) {
+ for (const QInputDevice *d : devices) {
+ if (d->type() != DeviceType::Keyboard)
+ continue;
+ if (seatName.isNull() || d->seatName() == seatName) {
// the master keyboard's parent is not another input device
if (!d->parent() || !qobject_cast<const QInputDevice *>(d->parent()))
return d;
@@ -215,7 +296,7 @@ const QInputDevice *QInputDevice::primaryKeyboard(const QString& seatName)
qCDebug(lcQpaInputDevices) << "no keyboards registered for seat" << seatName
<< "The platform plugin should have provided one via "
"QWindowSystemInterface::registerInputDevice(). Creating a default one for now.";
- ret = new QInputDevice(QLatin1String("core keyboard"), 0, DeviceType::Keyboard, seatName);
+ ret = new QInputDevice("core keyboard"_L1, 0, DeviceType::Keyboard, seatName, QCoreApplication::instance());
QInputDevicePrivate::registerDevice(ret);
return ret;
}
@@ -223,6 +304,9 @@ const QInputDevice *QInputDevice::primaryKeyboard(const QString& seatName)
return ret;
}
+QInputDevicePrivate::~QInputDevicePrivate()
+ = default;
+
/*!
\internal
Checks whether a matching device is already registered
@@ -242,17 +326,21 @@ bool QInputDevicePrivate::isRegistered(const QInputDevice *dev)
/*!
\internal
- Find the device with the given \a id, which must be unique.
+ Find the device with the given \a systemId (for example the xinput
+ device ID on X11), which is expected to be unique if nonzero.
+
+ If the \a systemId is not unique, this function returns the first one found.
- \note Use QPointingDevice::tabletDevice() if the device is a tablet
- or a tablet stylus; in that case, \a id is not unique.
+ \note Use QInputDevicePrivate::queryTabletDevice() if the device is a
+ tablet or a tablet stylus; in that case, \a id is not unique.
*/
-const QInputDevice *QInputDevicePrivate::fromId(qint64 id)
+const QInputDevice *QInputDevicePrivate::fromId(qint64 systemId)
{
QMutexLocker locker(&devicesMutex);
- for (const QInputDevice *dev : *deviceList())
- if (const_cast<QInputDevicePrivate *>(QInputDevicePrivate::get(dev))->id == id)
+ for (const QInputDevice *dev : *deviceList()) {
+ if (dev->systemId() == systemId)
return dev;
+ }
return nullptr;
}
@@ -273,28 +361,35 @@ void QInputDevicePrivate::unregisterDevice(const QInputDevice *dev)
bool QInputDevice::operator==(const QInputDevice &other) const
{
- return id() == other.id();
+ return systemId() == other.systemId();
}
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, const QInputDevice *device)
{
- const QInputDevicePrivate *d = QInputDevicePrivate::get(device);
- if (d->pointingDeviceType)
- return operator<<(debug, static_cast<const QPointingDevice *>(device));
QDebugStateSaver saver(debug);
debug.nospace();
debug.noquote();
+
debug << "QInputDevice(";
- if (device) {
- debug << '"' << device->name() << "\", type=" << device->type()
- << Qt::hex << ", ID=" << device->id() << ", seat='" << device->seatName() << "'";
- } else {
- debug << '0';
+ if (!device) {
+ debug << "0)";
+ return debug;
}
+
+ const QInputDevicePrivate *d = QInputDevicePrivate::get(device);
+
+ if (d->pointingDeviceType)
+ return operator<<(debug, static_cast<const QPointingDevice *>(device));
+
+ debug << "QInputDevice(";
+ debug << '"' << device->name() << "\", type=" << device->type()
+ << ", ID=" << device->systemId() << ", seat='" << device->seatName() << "'";
debug << ')';
return debug;
}
#endif // !QT_NO_DEBUG_STREAM
QT_END_NAMESPACE
+
+#include "moc_qinputdevice.cpp"
diff --git a/src/gui/kernel/qinputdevice.h b/src/gui/kernel/qinputdevice.h
index 5bff29f897..2b7ce32d86 100644
--- a/src/gui/kernel/qinputdevice.h
+++ b/src/gui/kernel/qinputdevice.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QINPUTDEVICE_H
#define QINPUTDEVICE_H
@@ -56,11 +20,13 @@ class Q_GUI_EXPORT QInputDevice : public QObject
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(DeviceType type READ type CONSTANT)
Q_PROPERTY(Capabilities capabilities READ capabilities CONSTANT)
- Q_PROPERTY(qint64 id READ id CONSTANT)
+ Q_PROPERTY(qint64 systemId READ systemId CONSTANT)
Q_PROPERTY(QString seatName READ seatName CONSTANT)
+ Q_PROPERTY(QRect availableVirtualGeometry READ availableVirtualGeometry
+ NOTIFY availableVirtualGeometryChanged)
public:
- enum class DeviceType : qint16 {
+ enum class DeviceType {
Unknown = 0x0000,
Mouse = 0x0001,
TouchScreen = 0x0002,
@@ -69,20 +35,20 @@ public:
Stylus = 0x0010,
Airbrush = 0x0020,
Keyboard = 0x1000,
- AllDevices = 0x7FFF
+ AllDevices = 0x7FFFFFFF
};
Q_DECLARE_FLAGS(DeviceTypes, DeviceType)
Q_FLAG(DeviceTypes)
- enum class Capability : qint32 {
+ enum class Capability {
None = 0,
Position = 0x0001,
Area = 0x0002,
Pressure = 0x0004,
Velocity = 0x0008,
- RawPositions = 0x0010,
NormalizedPosition = 0x0020,
MouseEmulation = 0x0040,
+ PixelScroll = 0x0080,
Scroll = 0x0100,
Hover = 0x0200,
Rotation = 0x0400,
@@ -95,25 +61,30 @@ public:
Q_DECLARE_FLAGS(Capabilities, Capability)
Q_FLAG(Capabilities)
- QInputDevice();
+ QInputDevice(QObject *parent = nullptr);
~QInputDevice();
- QInputDevice(const QString &name, qint64 id, DeviceType type,
+ QInputDevice(const QString &name, qint64 systemId, DeviceType type,
const QString &seatName = QString(), QObject *parent = nullptr);
QString name() const;
DeviceType type() const;
Capabilities capabilities() const;
bool hasCapability(Capability cap) const;
- qint64 id() const;
+ qint64 systemId() const;
QString seatName() const;
+ QRect availableVirtualGeometry() const;
+ static QStringList seatNames();
static QList<const QInputDevice *> devices();
static const QInputDevice *primaryKeyboard(const QString& seatName = QString());
bool operator==(const QInputDevice &other) const;
+Q_SIGNALS:
+ void availableVirtualGeometryChanged(QRect area);
+
protected:
- QInputDevice(QInputDevicePrivate &d, QObject *parent = nullptr);
+ QInputDevice(QInputDevicePrivate &d, QObject *parent);
Q_DISABLE_COPY_MOVE(QInputDevice)
};
diff --git a/src/gui/kernel/qinputdevice_p.h b/src/gui/kernel/qinputdevice_p.h
index 3115f6bf92..7f6ee258be 100644
--- a/src/gui/kernel/qinputdevice_p.h
+++ b/src/gui/kernel/qinputdevice_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QINPUTDEVICE_P_H
#define QINPUTDEVICE_P_H
@@ -61,33 +25,45 @@ class Q_GUI_EXPORT QInputDevicePrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QInputDevice)
public:
- QInputDevicePrivate(const QString &name, qint64 id, QInputDevice::DeviceType type,
+ QInputDevicePrivate(const QString &name, qint64 winSysId, QInputDevice::DeviceType type,
QInputDevice::Capabilities caps = QInputDevice::Capability::None,
const QString &seatName = QString())
- : name(name), seatName(seatName), id(id), capabilities(caps),
- deviceType(type), pointingDeviceType(false)
+ : name(name), seatName(seatName), systemId(winSysId), capabilities(caps),
+ deviceType(type)
{
// if the platform doesn't provide device IDs, make one up,
// but try to avoid clashing with OS-provided 32-bit IDs
static qint64 nextId = qint64(1) << 33;
- if (!id)
- id = nextId++;
+ if (!systemId)
+ systemId = nextId++;
}
+ ~QInputDevicePrivate() override;
QString name;
QString seatName;
QString busId;
- void *extra = nullptr; // The QPA plugin can store arbitrary device-specific data here
+ QRect availableVirtualGeometry;
void *qqExtra = nullptr; // Qt Quick can store arbitrary device-specific data here
- qint64 id = 0;
- qint32 capabilities = static_cast<qint32>(QInputDevice::Capability::None);
+ qint64 systemId = 0;
+ QInputDevice::Capabilities capabilities = QInputDevice::Capability::None;
QInputDevice::DeviceType deviceType = QInputDevice::DeviceType::Unknown;
- qint16 pointingDeviceType : 1; // actually bool, but pack with deviceType
+ bool pointingDeviceType = false;
static void registerDevice(const QInputDevice *dev);
static void unregisterDevice(const QInputDevice *dev);
static bool isRegistered(const QInputDevice *dev);
- static const QInputDevice *fromId(qint64 id); // window system ID (e.g. xinput id), not QPointingDeviceUniqueId
+ static const QInputDevice *fromId(qint64 systemId);
+
+ void setAvailableVirtualGeometry(QRect a)
+ {
+ if (a == availableVirtualGeometry)
+ return;
+
+ availableVirtualGeometry = a;
+ capabilities |= QInputDevice::Capability::NormalizedPosition;
+ Q_Q(QInputDevice);
+ Q_EMIT q->availableVirtualGeometryChanged(availableVirtualGeometry);
+ }
inline static QInputDevicePrivate *get(QInputDevice *q)
{
diff --git a/src/gui/kernel/qinputdevicemanager.cpp b/src/gui/kernel/qinputdevicemanager.cpp
index 11442407e1..72af92cf17 100644
--- a/src/gui/kernel/qinputdevicemanager.cpp
+++ b/src/gui/kernel/qinputdevicemanager.cpp
@@ -1,47 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qinputdevicemanager_p.h"
#include "qinputdevicemanager_p_p.h"
QT_BEGIN_NAMESPACE
+QT_IMPL_METATYPE_EXTERN_TAGGED(QInputDeviceManager::DeviceType, QInputDeviceManager__DeviceType)
+
/*!
\class QInputDeviceManager
\internal
@@ -67,6 +33,8 @@ QInputDeviceManager::QInputDeviceManager(QObject *parent)
qRegisterMetaType<DeviceType>();
}
+QInputDeviceManager::~QInputDeviceManager() = default;
+
int QInputDeviceManager::deviceCount(DeviceType type) const
{
Q_D(const QInputDeviceManager);
@@ -116,3 +84,5 @@ void QInputDeviceManager::setKeyboardModifiers(Qt::KeyboardModifiers mods)
}
QT_END_NAMESPACE
+
+#include "moc_qinputdevicemanager_p.cpp"
diff --git a/src/gui/kernel/qinputdevicemanager_p.h b/src/gui/kernel/qinputdevicemanager_p.h
index 1d20b102e3..9c34ece555 100644
--- a/src/gui/kernel/qinputdevicemanager_p.h
+++ b/src/gui/kernel/qinputdevicemanager_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QINPUTDEVICEMANAGER_P_H
#define QINPUTDEVICEMANAGER_P_H
@@ -74,7 +38,8 @@ public:
NumDeviceTypes
};
- QInputDeviceManager(QObject *parent = nullptr);
+ explicit QInputDeviceManager(QObject *parent = nullptr);
+ ~QInputDeviceManager() override;
int deviceCount(DeviceType type) const;
@@ -83,13 +48,14 @@ public:
Qt::KeyboardModifiers keyboardModifiers() const;
void setKeyboardModifiers(Qt::KeyboardModifiers mods);
-signals:
+Q_SIGNALS:
void deviceListChanged(QInputDeviceManager::DeviceType type);
void cursorPositionChangeRequested(const QPoint &pos);
};
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QInputDeviceManager::DeviceType)
+QT_DECL_METATYPE_EXTERN_TAGGED(QInputDeviceManager::DeviceType,
+ QInputDeviceManager__DeviceType, Q_GUI_EXPORT)
#endif // QINPUTDEVICEMANAGER_P_H
diff --git a/src/gui/kernel/qinputdevicemanager_p_p.h b/src/gui/kernel/qinputdevicemanager_p_p.h
index 82a86446a0..b43904aa67 100644
--- a/src/gui/kernel/qinputdevicemanager_p_p.h
+++ b/src/gui/kernel/qinputdevicemanager_p_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QINPUTDEVICEMANAGER_P_P_H
#define QINPUTDEVICEMANAGER_P_P_H
diff --git a/src/gui/kernel/qinputmethod.cpp b/src/gui/kernel/qinputmethod.cpp
index f5de06aea1..e37e85e246 100644
--- a/src/gui/kernel/qinputmethod.cpp
+++ b/src/gui/kernel/qinputmethod.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qinputmethod.h>
#include <private/qinputmethod_p.h>
@@ -426,13 +390,21 @@ QVariant QInputMethod::queryFocusObject(Qt::InputMethodQuery query, const QVaria
if (!focusObject)
return retval;
- bool newMethodWorks = QMetaObject::invokeMethod(focusObject, "inputMethodQuery",
- Qt::DirectConnection,
- Q_RETURN_ARG(QVariant, retval),
- Q_ARG(Qt::InputMethodQuery, query),
- Q_ARG(QVariant, argument));
- if (newMethodWorks)
- return retval;
+ static const char *signature = "inputMethodQuery(Qt::InputMethodQuery,QVariant)";
+ const bool newMethodSupported = focusObject->metaObject()->indexOfMethod(signature) != -1;
+ if (newMethodSupported) {
+ const bool ok = QMetaObject::invokeMethod(focusObject, "inputMethodQuery",
+ Qt::DirectConnection,
+ Q_RETURN_ARG(QVariant, retval),
+ Q_ARG(Qt::InputMethodQuery, query),
+ Q_ARG(QVariant, argument));
+ Q_ASSERT(ok);
+ if (retval.isValid())
+ return retval;
+
+ // If the new API didn't have an answer to the query, we fall
+ // back to use the old event-based API.
+ }
QInputMethodQueryEvent queryEvent(query);
QCoreApplication::sendEvent(focusObject, &queryEvent);
diff --git a/src/gui/kernel/qinputmethod.h b/src/gui/kernel/qinputmethod.h
index 8f5eca3886..dfddc9b7c7 100644
--- a/src/gui/kernel/qinputmethod.h
+++ b/src/gui/kernel/qinputmethod.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QINPUTMETHOD_H
#define QINPUTMETHOD_H
@@ -58,7 +22,8 @@ class Q_GUI_EXPORT QInputMethod : public QObject
Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
Q_PROPERTY(QRectF anchorRectangle READ anchorRectangle NOTIFY anchorRectangleChanged)
Q_PROPERTY(QRectF keyboardRectangle READ keyboardRectangle NOTIFY keyboardRectangleChanged)
- Q_PROPERTY(QRectF inputItemClipRectangle READ inputItemClipRectangle NOTIFY inputItemClipRectangleChanged)
+ Q_PROPERTY(QRectF inputItemClipRectangle READ inputItemClipRectangle
+ NOTIFY inputItemClipRectangleChanged)
Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged)
Q_PROPERTY(bool animating READ isAnimating NOTIFY animatingChanged)
Q_PROPERTY(QLocale locale READ locale NOTIFY localeChanged)
diff --git a/src/gui/kernel/qinputmethod_p.h b/src/gui/kernel/qinputmethod_p.h
index 5657edeb4e..9191813b44 100644
--- a/src/gui/kernel/qinputmethod_p.h
+++ b/src/gui/kernel/qinputmethod_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QINPUTMETHOD_P_H
#define QINPUTMETHOD_P_H
diff --git a/src/gui/kernel/qinternalmimedata.cpp b/src/gui/kernel/qinternalmimedata.cpp
index d5cdc743ee..d33402703e 100644
--- a/src/gui/kernel/qinternalmimedata.cpp
+++ b/src/gui/kernel/qinternalmimedata.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qinternalmimedata_p.h"
@@ -46,15 +10,17 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
static QStringList imageMimeFormats(const QList<QByteArray> &imageFormats)
{
QStringList formats;
formats.reserve(imageFormats.size());
for (const auto &format : imageFormats)
- formats.append(QLatin1String("image/") + QLatin1String(format.toLower()));
+ formats.append("image/"_L1 + QLatin1StringView(format.toLower()));
//put png at the front because it is best
- int pngIndex = formats.indexOf(QLatin1String("image/png"));
+ const qsizetype pngIndex = formats.indexOf("image/png"_L1);
if (pngIndex != -1 && pngIndex != 0)
formats.move(pngIndex, 0);
@@ -83,7 +49,7 @@ QInternalMimeData::~QInternalMimeData()
bool QInternalMimeData::hasFormat(const QString &mimeType) const
{
bool foundFormat = hasFormat_sys(mimeType);
- if (!foundFormat && mimeType == QLatin1String("application/x-qt-image")) {
+ if (!foundFormat && mimeType == "application/x-qt-image"_L1) {
QStringList imageFormats = imageReadMimeFormats();
for (int i = 0; i < imageFormats.size(); ++i) {
if ((foundFormat = hasFormat_sys(imageFormats.at(i))))
@@ -96,11 +62,11 @@ bool QInternalMimeData::hasFormat(const QString &mimeType) const
QStringList QInternalMimeData::formats() const
{
QStringList realFormats = formats_sys();
- if (!realFormats.contains(QLatin1String("application/x-qt-image"))) {
+ if (!realFormats.contains("application/x-qt-image"_L1)) {
QStringList imageFormats = imageReadMimeFormats();
for (int i = 0; i < imageFormats.size(); ++i) {
if (realFormats.contains(imageFormats.at(i))) {
- realFormats += QLatin1String("application/x-qt-image");
+ realFormats += "application/x-qt-image"_L1;
break;
}
}
@@ -108,27 +74,27 @@ QStringList QInternalMimeData::formats() const
return realFormats;
}
-QVariant QInternalMimeData::retrieveData(const QString &mimeType, QVariant::Type type) const
+QVariant QInternalMimeData::retrieveData(const QString &mimeType, QMetaType type) const
{
QVariant data = retrieveData_sys(mimeType, type);
- if (mimeType == QLatin1String("application/x-qt-image")) {
- if (data.isNull() || (data.userType() == QMetaType::QByteArray && data.toByteArray().isEmpty())) {
+ if (mimeType == "application/x-qt-image"_L1) {
+ if (data.isNull() || (data.metaType().id() == QMetaType::QByteArray && data.toByteArray().isEmpty())) {
// try to find an image
QStringList imageFormats = imageReadMimeFormats();
for (int i = 0; i < imageFormats.size(); ++i) {
data = retrieveData_sys(imageFormats.at(i), type);
- if (data.isNull() || (data.userType() == QMetaType::QByteArray && data.toByteArray().isEmpty()))
+ if (data.isNull() || (data.metaType().id() == QMetaType::QByteArray && data.toByteArray().isEmpty()))
continue;
break;
}
}
- int typeId = type;
+ int typeId = type.id();
// we wanted some image type, but all we got was a byte array. Convert it to an image.
- if (data.userType() == QMetaType::QByteArray
+ if (data.metaType().id() == QMetaType::QByteArray
&& (typeId == QMetaType::QImage || typeId == QMetaType::QPixmap || typeId == QMetaType::QBitmap))
data = QImage::fromData(data.toByteArray());
- } else if (mimeType == QLatin1String("application/x-color") && data.userType() == QMetaType::QByteArray) {
+ } else if (mimeType == "application/x-color"_L1 && data.metaType().id() == QMetaType::QByteArray) {
QColor c;
QByteArray ba = data.toByteArray();
if (ba.size() == 8) {
@@ -141,7 +107,7 @@ QVariant QInternalMimeData::retrieveData(const QString &mimeType, QVariant::Type
} else {
qWarning("Qt: Invalid color format");
}
- } else if (data.userType() != int(type) && data.userType() == QMetaType::QByteArray) {
+ } else if (data.metaType() != type && data.metaType().id() == QMetaType::QByteArray) {
// try to use mime data's internal conversion stuf.
QInternalMimeData *that = const_cast<QInternalMimeData *>(this);
that->setData(mimeType, data.toByteArray());
@@ -160,7 +126,7 @@ bool QInternalMimeData::canReadData(const QString &mimeType)
QStringList QInternalMimeData::formatsHelper(const QMimeData *data)
{
QStringList realFormats = data->formats();
- if (realFormats.contains(QLatin1String("application/x-qt-image"))) {
+ if (realFormats.contains("application/x-qt-image"_L1)) {
// add all supported image formats
QStringList imageFormats = imageWriteMimeFormats();
for (int i = 0; i < imageFormats.size(); ++i) {
@@ -176,14 +142,14 @@ bool QInternalMimeData::hasFormatHelper(const QString &mimeType, const QMimeData
bool foundFormat = data->hasFormat(mimeType);
if (!foundFormat) {
- if (mimeType == QLatin1String("application/x-qt-image")) {
+ if (mimeType == "application/x-qt-image"_L1) {
// check all supported image formats
QStringList imageFormats = imageWriteMimeFormats();
for (int i = 0; i < imageFormats.size(); ++i) {
if ((foundFormat = data->hasFormat(imageFormats.at(i))))
break;
}
- } else if (mimeType.startsWith(QLatin1String("image/"))) {
+ } else if (mimeType.startsWith("image/"_L1)) {
return data->hasImage() && imageWriteMimeFormats().contains(mimeType);
}
}
@@ -193,7 +159,7 @@ bool QInternalMimeData::hasFormatHelper(const QString &mimeType, const QMimeData
QByteArray QInternalMimeData::renderDataHelper(const QString &mimeType, const QMimeData *data)
{
QByteArray ba;
- if (mimeType == QLatin1String("application/x-color")) {
+ if (mimeType == "application/x-color"_L1) {
/* QMimeData can only provide colors as QColor or the name
of a color as a QByteArray or a QString. So we need to do
the conversion to application/x-color here.
@@ -215,17 +181,17 @@ QByteArray QInternalMimeData::renderDataHelper(const QString &mimeType, const QM
} else {
ba = data->data(mimeType);
if (ba.isEmpty()) {
- if (mimeType == QLatin1String("application/x-qt-image") && data->hasImage()) {
+ if (mimeType == "application/x-qt-image"_L1 && data->hasImage()) {
QImage image = qvariant_cast<QImage>(data->imageData());
QBuffer buf(&ba);
buf.open(QBuffer::WriteOnly);
// would there not be PNG ??
image.save(&buf, "PNG");
- } else if (mimeType.startsWith(QLatin1String("image/")) && data->hasImage()) {
+ } else if (mimeType.startsWith("image/"_L1) && data->hasImage()) {
QImage image = qvariant_cast<QImage>(data->imageData());
QBuffer buf(&ba);
buf.open(QBuffer::WriteOnly);
- image.save(&buf, mimeType.mid(mimeType.indexOf(QLatin1Char('/')) + 1).toLatin1().toUpper());
+ image.save(&buf, mimeType.mid(mimeType.indexOf(u'/') + 1).toLatin1().toUpper());
}
}
}
@@ -233,3 +199,5 @@ QByteArray QInternalMimeData::renderDataHelper(const QString &mimeType, const QM
}
QT_END_NAMESPACE
+
+#include "moc_qinternalmimedata_p.cpp"
diff --git a/src/gui/kernel/qinternalmimedata_p.h b/src/gui/kernel/qinternalmimedata_p.h
index aa5e896323..ce4cfaa72d 100644
--- a/src/gui/kernel/qinternalmimedata_p.h
+++ b/src/gui/kernel/qinternalmimedata_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QINTERNALMIMEDATA_P_H
#define QINTERNALMIMEDATA_P_H
@@ -81,11 +45,11 @@ public:
static QByteArray renderDataHelper(const QString &mimeType, const QMimeData *data);
protected:
- QVariant retrieveData(const QString &mimeType, QVariant::Type type) const override;
+ QVariant retrieveData(const QString &mimeType, QMetaType type) const override;
virtual bool hasFormat_sys(const QString &mimeType) const = 0;
virtual QStringList formats_sys() const = 0;
- virtual QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const = 0;
+ virtual QVariant retrieveData_sys(const QString &mimeType, QMetaType type) const = 0;
};
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qkeymapper.cpp b/src/gui/kernel/qkeymapper.cpp
index 274574f561..4ceb508465 100644
--- a/src/gui/kernel/qkeymapper.cpp
+++ b/src/gui/kernel/qkeymapper.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qguiapplication.h"
@@ -45,6 +9,7 @@
#include <private/qguiapplication_p.h>
#include <qpa/qplatformintegration.h>
+#include <qpa/qplatformkeymapper.h>
QT_BEGIN_NAMESPACE
@@ -59,8 +24,7 @@ QT_BEGIN_NAMESPACE
/*!
Constructs a new key mapper.
*/
-QKeyMapper::QKeyMapper()
- : QObject(*new QKeyMapperPrivate, nullptr)
+QKeyMapper::QKeyMapper() : QObject()
{
}
@@ -71,36 +35,34 @@ QKeyMapper::~QKeyMapper()
{
}
-QList<int> QKeyMapper::possibleKeys(QKeyEvent *e)
+QList<QKeyCombination> QKeyMapper::possibleKeys(const QKeyEvent *e)
{
- QList<int> result;
+ qCDebug(lcQpaKeyMapper).verbosity(3) << "Computing possible key combinations for" << e;
- if (!e->nativeScanCode()) {
+ const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
+ const auto *platformKeyMapper = platformIntegration->keyMapper();
+ QList<QKeyCombination> result = platformKeyMapper->possibleKeyCombinations(e);
+
+ if (result.isEmpty()) {
if (e->key() && (e->key() != Qt::Key_unknown))
- result << int(e->key() + e->modifiers());
+ result << e->keyCombination();
else if (!e->text().isEmpty())
- result << int(e->text().at(0).unicode() + e->modifiers());
- return result;
+ result << (Qt::Key(e->text().at(0).unicode()) | e->modifiers());
}
- return instance()->d_func()->possibleKeys(e);
-}
-
-extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); // in qapplication_*.cpp
-void QKeyMapper::changeKeyboard()
-{
- instance()->d_func()->clearMappings();
-
- // ## TODO: Support KeyboardLayoutChange on QPA
-#if 0
- // inform all toplevel widgets of the change
- QEvent e(QEvent::KeyboardLayoutChange);
- QWidgetList list = QApplication::topLevelWidgets();
- for (int i = 0; i < list.size(); ++i) {
- QWidget *w = list.at(i);
- qt_sendSpontaneousEvent(w, &e);
+#if QT_CONFIG(shortcut)
+ if (lcQpaKeyMapper().isDebugEnabled()) {
+ qCDebug(lcQpaKeyMapper) << "Resulting possible key combinations:";
+ for (auto keyCombination : result) {
+ auto keySequence = QKeySequence(keyCombination);
+ qCDebug(lcQpaKeyMapper).verbosity(0) << "\t-"
+ << keyCombination << "/" << keySequence << "/"
+ << qUtf8Printable(keySequence.toString(QKeySequence::NativeText));
+ }
}
#endif
+
+ return result;
}
Q_GLOBAL_STATIC(QKeyMapper, keymapper)
@@ -113,37 +75,18 @@ QKeyMapper *QKeyMapper::instance()
return keymapper();
}
-QKeyMapperPrivate *qt_keymapper_private()
+void *QKeyMapper::resolveInterface(const char *name, int revision) const
{
- return QKeyMapper::instance()->d_func();
-}
-
-QKeyMapperPrivate::QKeyMapperPrivate()
-{
- keyboardInputLocale = QLocale::system();
- keyboardInputDirection = keyboardInputLocale.textDirection();
-}
+ Q_UNUSED(name); Q_UNUSED(revision);
+ using namespace QNativeInterface::Private;
-QKeyMapperPrivate::~QKeyMapperPrivate()
-{
- // clearMappings();
-}
-
-void QKeyMapperPrivate::clearMappings()
-{
-}
+#if QT_CONFIG(evdev)
+ QT_NATIVE_INTERFACE_RETURN_IF(QEvdevKeyMapper, QGuiApplicationPrivate::platformIntegration());
+#endif
-QList<int> QKeyMapperPrivate::possibleKeys(QKeyEvent *e)
-{
- QList<int> result = QGuiApplicationPrivate::platformIntegration()->possibleKeys(e);
- if (!result.isEmpty())
- return result;
-
- if (e->key() && (e->key() != Qt::Key_unknown))
- result << int(e->key() + e->modifiers());
- else if (!e->text().isEmpty())
- result << int(e->text().at(0).unicode() + e->modifiers());
- return result;
+ return nullptr;
}
QT_END_NAMESPACE
+
+#include "moc_qkeymapper_p.cpp"
diff --git a/src/gui/kernel/qkeymapper_p.h b/src/gui/kernel/qkeymapper_p.h
index fd53747fdd..1a6a9a608f 100644
--- a/src/gui/kernel/qkeymapper_p.h
+++ b/src/gui/kernel/qkeymapper_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QKEYMAPPER_P_H
#define QKEYMAPPER_P_H
@@ -57,10 +21,10 @@
#include <qlocale.h>
#include <qevent.h>
+#include <QtCore/qnativeinterface.h>
QT_BEGIN_NAMESPACE
-class QKeyMapperPrivate;
class Q_GUI_EXPORT QKeyMapper : public QObject
{
Q_OBJECT
@@ -69,33 +33,29 @@ public:
~QKeyMapper();
static QKeyMapper *instance();
- static void changeKeyboard();
- static QList<int> possibleKeys(QKeyEvent *e);
+ static QList<QKeyCombination> possibleKeys(const QKeyEvent *e);
+
+ QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QKeyMapper)
private:
- friend QKeyMapperPrivate *qt_keymapper_private();
- Q_DECLARE_PRIVATE(QKeyMapper)
Q_DISABLE_COPY_MOVE(QKeyMapper)
};
-struct KeyboardLayoutItem;
-class QKeyEvent;
-
-class QKeyMapperPrivate : public QObjectPrivate
-{
- Q_DECLARE_PUBLIC(QKeyMapper)
-public:
- QKeyMapperPrivate();
- ~QKeyMapperPrivate();
+// ----------------- QNativeInterface -----------------
- void clearMappings();
- QList<int> possibleKeys(QKeyEvent *e);
+namespace QNativeInterface::Private {
- QLocale keyboardInputLocale;
- Qt::LayoutDirection keyboardInputDirection;
+#if QT_CONFIG(evdev) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QEvdevKeyMapper
+{
+ QT_DECLARE_NATIVE_INTERFACE(QEvdevKeyMapper, 1, QKeyMapper)
+ virtual void loadKeymap(const QString &filename) = 0;
+ virtual void switchLang() = 0;
};
+#endif
+
+} // QNativeInterface::Private
-QKeyMapperPrivate *qt_keymapper_private(); // from qkeymapper.cpp
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp
index 92737db8d3..0529d940d2 100644
--- a/src/gui/kernel/qkeysequence.cpp
+++ b/src/gui/kernel/qkeysequence.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qkeysequence.h"
#include "qkeysequence_p.h"
@@ -49,30 +13,32 @@
#endif
#include "qvariant.h"
-#if defined(Q_OS_MACX)
+#if defined(Q_OS_APPLE)
#include <QtCore/private/qcore_mac_p.h>
#endif
#include <algorithm>
+#include <q20algorithm.h>
QT_BEGIN_NAMESPACE
-#if defined(Q_OS_MACOS) || defined(Q_CLANG_QDOC)
-static bool qt_sequence_no_mnemonics = true;
-struct MacSpecialKey {
+using namespace Qt::StringLiterals;
+
+#if defined(Q_OS_APPLE) || defined(Q_QDOC)
+Q_CONSTINIT static bool qt_sequence_no_mnemonics = true;
+struct AppleSpecialKey {
int key;
- ushort macSymbol;
+ ushort appleSymbol;
};
// Unicode code points for the glyphs associated with these keys
// Defined by Carbon headers but not anywhere in Cocoa
-static const int kShiftUnicode = 0x21E7;
-static const int kControlUnicode = 0x2303;
-static const int kOptionUnicode = 0x2325;
-static const int kCommandUnicode = 0x2318;
+static constexpr int kShiftUnicode = 0x21E7;
+static constexpr int kControlUnicode = 0x2303;
+static constexpr int kOptionUnicode = 0x2325;
+static constexpr int kCommandUnicode = 0x2318;
-static const int NumEntries = 21;
-static const MacSpecialKey entries[NumEntries] = {
+static constexpr AppleSpecialKey entries[] = {
{ Qt::Key_Escape, 0x238B },
{ Qt::Key_Tab, 0x21E5 },
{ Qt::Key_Backtab, 0x21E4 },
@@ -80,6 +46,7 @@ static const MacSpecialKey entries[NumEntries] = {
{ Qt::Key_Return, 0x21B5 },
{ Qt::Key_Enter, 0x2324 },
{ Qt::Key_Delete, 0x2326 },
+ { Qt::Key_Clear, 0x2327 },
{ Qt::Key_Home, 0x2196 },
{ Qt::Key_End, 0x2198 },
{ Qt::Key_Left, 0x2190 },
@@ -93,43 +60,48 @@ static const MacSpecialKey entries[NumEntries] = {
{ Qt::Key_Meta, kControlUnicode },
{ Qt::Key_Alt, kOptionUnicode },
{ Qt::Key_CapsLock, 0x21EA },
+ { Qt::Key_Eject, 0x23CF },
};
-static bool operator<(const MacSpecialKey &entry, int key)
+static constexpr bool operator<(const AppleSpecialKey &lhs, const AppleSpecialKey &rhs)
+{
+ return lhs.key < rhs.key;
+}
+
+static constexpr bool operator<(const AppleSpecialKey &lhs, int rhs)
{
- return entry.key < key;
+ return lhs.key < rhs;
}
-static bool operator<(int key, const MacSpecialKey &entry)
+static constexpr bool operator<(int lhs, const AppleSpecialKey &rhs)
{
- return key < entry.key;
+ return lhs < rhs.key;
}
-static const MacSpecialKey * const MacSpecialKeyEntriesEnd = entries + NumEntries;
+static_assert(q20::is_sorted(std::begin(entries), std::end(entries)));
-QChar qt_macSymbolForQtKey(int key)
+static QChar appleSymbolForQtKey(int key)
{
- const MacSpecialKey *i = std::lower_bound(entries, MacSpecialKeyEntriesEnd, key);
- if ((i == MacSpecialKeyEntriesEnd) || (key < *i))
+ const auto i = std::lower_bound(std::begin(entries), std::end(entries), key);
+ if (i == std::end(entries) || key < *i)
return QChar();
- ushort macSymbol = i->macSymbol;
+ ushort appleSymbol = i->appleSymbol;
if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)
- && (macSymbol == kControlUnicode || macSymbol == kCommandUnicode)) {
- if (macSymbol == kControlUnicode)
- macSymbol = kCommandUnicode;
+ && (appleSymbol == kControlUnicode || appleSymbol == kCommandUnicode)) {
+ if (appleSymbol == kControlUnicode)
+ appleSymbol = kCommandUnicode;
else
- macSymbol = kControlUnicode;
+ appleSymbol = kControlUnicode;
}
- return QChar(macSymbol);
+ return QChar(appleSymbol);
}
-static int qtkeyForMacSymbol(const QChar ch)
+static int qtkeyForAppleSymbol(const QChar ch)
{
const ushort unicode = ch.unicode();
- for (int i = 0; i < NumEntries; ++i) {
- const MacSpecialKey &entry = entries[i];
- if (entry.macSymbol == unicode) {
+ for (const AppleSpecialKey &entry : entries) {
+ if (entry.appleSymbol == unicode) {
int key = entry.key;
if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)
&& (unicode == kControlUnicode || unicode == kCommandUnicode)) {
@@ -145,7 +117,7 @@ static int qtkeyForMacSymbol(const QChar ch)
}
#else
-static bool qt_sequence_no_mnemonics = false;
+Q_CONSTINIT static bool qt_sequence_no_mnemonics = false;
#endif
/*!
@@ -192,9 +164,10 @@ void Q_GUI_EXPORT qt_set_sequence_auto_mnemonic(bool b) { qt_sequence_no_mnemoni
for users of different languages. Translations are made in the
"QShortcut" context.
\li For hard-coded shortcuts, integer key codes can be specified with
- a combination of values defined by the Qt::Key and Qt::Modifier enum
- values. Each key code consists of a single Qt::Key value and zero or
- more modifiers, such as Qt::SHIFT, Qt::CTRL, Qt::ALT and Qt::META.
+ a combination of values defined by the Qt::Key and Qt::KeyboardModifier
+ enum values. Each key code consists of a single Qt::Key value and zero
+ or more modifiers, such as Qt::ShiftModifier, Qt::ControlModifier,
+ Qt::AltModifier and Qt::MetaModifier.
\endlist
For example, \uicontrol{Ctrl P} might be a sequence used as a shortcut for
@@ -218,7 +191,7 @@ void Q_GUI_EXPORT qt_set_sequence_auto_mnemonic(bool b) { qt_sequence_no_mnemoni
QKeySequence objects can be cast to a QString to obtain a human-readable
translated version of the sequence. Similarly, the toString() function
- produces human-readable strings for use in menus. On \macos, the
+ produces human-readable strings for use in menus. On Apple platforms, the
appropriate symbols are used to describe keyboard shortcuts using special
keys on the Macintosh keyboard.
@@ -226,12 +199,12 @@ void Q_GUI_EXPORT qt_set_sequence_auto_mnemonic(bool b) { qt_sequence_no_mnemoni
code point of the character; for example, 'A' gives the same key sequence
as Qt::Key_A.
- \note On \macos, references to "Ctrl", Qt::CTRL, Qt::Key_Control
+ \note On Apple platforms, references to "Ctrl", Qt::CTRL, Qt::Key_Control
and Qt::ControlModifier correspond to the \uicontrol Command keys on the
Macintosh keyboard, and references to "Meta", Qt::META, Qt::Key_Meta and
- Qt::MetaModifier correspond to the \uicontrol Control keys. Developers on
- \macos can use the same shortcut descriptions across all platforms,
- and their applications will automatically work as expected on \macos.
+ Qt::MetaModifier correspond to the \uicontrol Control keys. In effect,
+ developers can use the same shortcut descriptions across all platforms,
+ and their applications will automatically work as expected on Apple platforms.
\section1 Standard Shortcuts
@@ -240,21 +213,21 @@ void Q_GUI_EXPORT qt_set_sequence_auto_mnemonic(bool b) { qt_sequence_no_mnemoni
setting up actions in a typical application. The table below shows
some common key sequences that are often used for these standard
shortcuts by applications on four widely-used platforms. Note
- that on \macos, the \uicontrol Ctrl value corresponds to the \uicontrol
+ that on Apple platforms, the \uicontrol Ctrl value corresponds to the \uicontrol
Command keys on the Macintosh keyboard, and the \uicontrol Meta value
corresponds to the \uicontrol Control keys.
\table
- \header \li StandardKey \li Windows \li \macos \li KDE Plasma \li GNOME
+ \header \li StandardKey \li Windows \li Apple platforms \li KDE Plasma \li GNOME
\row \li HelpContents \li F1 \li Ctrl+? \li F1 \li F1
\row \li WhatsThis \li Shift+F1 \li Shift+F1 \li Shift+F1 \li Shift+F1
\row \li Open \li Ctrl+O \li Ctrl+O \li Ctrl+O \li Ctrl+O
\row \li Close \li Ctrl+F4, Ctrl+W \li Ctrl+W, Ctrl+F4 \li Ctrl+W \li Ctrl+W
\row \li Save \li Ctrl+S \li Ctrl+S \li Ctrl+S \li Ctrl+S
\row \li Quit \li \li Ctrl+Q \li Ctrl+Q \li Ctrl+Q
- \row \li SaveAs \li \li Ctrl+Shift+S \li \li Ctrl+Shift+S
+ \row \li SaveAs \li Ctrl+Shift+S \li Ctrl+Shift+S \li Ctrl+Shift+S \li Ctrl+Shift+S
\row \li New \li Ctrl+N \li Ctrl+N \li Ctrl+N \li Ctrl+N
- \row \li Delete \li Del \li Del, Meta+D \li Del, Ctrl+D \li Del, Ctrl+D
+ \row \li Delete \li Del \li Forward Delete, Meta+D \li Del, Ctrl+D \li Del, Ctrl+D
\row \li Cut \li Ctrl+X, Shift+Del \li Ctrl+X, Meta+K \li Ctrl+X, F20, Shift+Del \li Ctrl+X, F20, Shift+Del
\row \li Copy \li Ctrl+C, Ctrl+Ins \li Ctrl+C \li Ctrl+C, F16, Ctrl+Ins \li Ctrl+C, F16, Ctrl+Ins
\row \li Paste \li Ctrl+V, Shift+Ins \li Ctrl+V, Meta+Y \li Ctrl+V, F18, Shift+Ins \li Ctrl+V, F18, Shift+Ins
@@ -314,7 +287,7 @@ void Q_GUI_EXPORT qt_set_sequence_auto_mnemonic(bool b) { qt_sequence_no_mnemoni
\row \li DeleteCompleteLine \li (none) \li (none) \li Ctrl+U \li Ctrl+U
\row \li InsertParagraphSeparator \li Enter \li Enter \li Enter \li Enter
\row \li InsertLineSeparator \li Shift+Enter \li Meta+Enter, Meta+O \li Shift+Enter \li Shift+Enter
- \row \li Backspace \li (none) \li Meta+H \li (none) \li (none)
+ \row \li Backspace \li (none) \li Delete, Meta+H \li (none) \li (none)
\row \li Cancel \li Escape \li Escape, Ctrl+. \li Escape \li Escape
\endtable
@@ -401,7 +374,7 @@ void Q_GUI_EXPORT qt_set_sequence_auto_mnemonic(bool b) { qt_sequence_no_mnemoni
\enum QKeySequence::SequenceFormat
\value NativeText The key sequence as a platform specific string.
- This means that it will be shown translated and on the Mac it will
+ This means that it will be shown translated and on Apple platforms it will
resemble a key sequence from the menu bar. This enum is best used when you
want to display the string to the user.
@@ -410,7 +383,7 @@ void Q_GUI_EXPORT qt_set_sequence_auto_mnemonic(bool b) { qt_sequence_no_mnemoni
similar to the native text on Windows and X11.
*/
-static const struct {
+static constexpr struct {
int key;
const char name[25];
} keyname[] = {
@@ -699,9 +672,13 @@ static const struct {
{ Qt::Key_TouchpadToggle, QT_TRANSLATE_NOOP("QShortcut", "Touchpad Toggle") },
{ Qt::Key_TouchpadOn, QT_TRANSLATE_NOOP("QShortcut", "Touchpad On") },
{ Qt::Key_TouchpadOff, QT_TRANSLATE_NOOP("QShortcut", "Touchpad Off") },
+ { Qt::Key_Shift, QT_TRANSLATE_NOOP("QShortcut", "Shift") },
+ { Qt::Key_Control, QT_TRANSLATE_NOOP("QShortcut", "Control") },
+ { Qt::Key_Alt, QT_TRANSLATE_NOOP("QShortcut", "Alt") },
+ { Qt::Key_Meta, QT_TRANSLATE_NOOP("QShortcut", "Meta") },
};
-static Q_CONSTEXPR int numKeyNames = sizeof keyname / sizeof *keyname;
+static constexpr int numKeyNames = sizeof keyname / sizeof *keyname;
/*!
\enum QKeySequence::StandardKey
@@ -733,7 +710,7 @@ static Q_CONSTEXPR int numKeyNames = sizeof keyname / sizeof *keyname;
\value InsertLineSeparator Insert a new line.
\value InsertParagraphSeparator Insert a new paragraph.
\value Italic Italic text.
- \value MoveToEndOfBlock Move cursor to end of block. This shortcut is only used on the \macos.
+ \value MoveToEndOfBlock Move cursor to end of block. This shortcut is only used on Apple platforms.
\value MoveToEndOfDocument Move cursor to end of document.
\value MoveToEndOfLine Move cursor to end of line.
\value MoveToNextChar Move cursor to next character.
@@ -744,7 +721,7 @@ static Q_CONSTEXPR int numKeyNames = sizeof keyname / sizeof *keyname;
\value MoveToPreviousLine Move cursor to previous line.
\value MoveToPreviousPage Move cursor to previous page.
\value MoveToPreviousWord Move cursor to previous word.
- \value MoveToStartOfBlock Move cursor to start of a block. This shortcut is only used on \macos.
+ \value MoveToStartOfBlock Move cursor to start of a block. This shortcut is only used on Apple platforms.
\value MoveToStartOfDocument Move cursor to start of document.
\value MoveToStartOfLine Move cursor to start of line.
\value New Create new document.
@@ -762,7 +739,7 @@ static Q_CONSTEXPR int numKeyNames = sizeof keyname / sizeof *keyname;
\value Save Save document.
\value SelectAll Select all text.
\value Deselect Deselect text. Since 5.1
- \value SelectEndOfBlock Extend selection to the end of a text block. This shortcut is only used on \macos.
+ \value SelectEndOfBlock Extend selection to the end of a text block. This shortcut is only used on Apple platforms.
\value SelectEndOfDocument Extend selection to end of document.
\value SelectEndOfLine Extend selection to end of line.
\value SelectNextChar Extend selection to next character.
@@ -773,7 +750,7 @@ static Q_CONSTEXPR int numKeyNames = sizeof keyname / sizeof *keyname;
\value SelectPreviousLine Extend selection to previous line.
\value SelectPreviousPage Extend selection to previous page.
\value SelectPreviousWord Extend selection to previous word.
- \value SelectStartOfBlock Extend selection to the start of a text block. This shortcut is only used on \macos.
+ \value SelectStartOfBlock Extend selection to the start of a text block. This shortcut is only used on Apple platforms.
\value SelectStartOfDocument Extend selection to start of document.
\value SelectStartOfLine Extend selection to start of line.
\value Underline Underline text.
@@ -807,8 +784,8 @@ QKeySequence::QKeySequence(StandardKey key)
{
const QList <QKeySequence> bindings = keyBindings(key);
//pick only the first/primary shortcut from current bindings
- if (bindings.size() > 0) {
- d = bindings.first().d;
+ if (!bindings.isEmpty()) {
+ d = bindings.constFirst().d;
d->ref.ref();
}
else
@@ -821,7 +798,7 @@ QKeySequence::QKeySequence(StandardKey key)
*/
QKeySequence::QKeySequence()
{
- static QKeySequencePrivate shared_empty;
+ Q_CONSTINIT static QKeySequencePrivate shared_empty;
d = &shared_empty;
d->ref.ref();
}
@@ -857,8 +834,8 @@ static_assert(QKeySequencePrivate::MaxKeyCount == 4, "Change docs and ctor impl
\a k3 and \a k4.
The key codes are listed in Qt::Key and can be combined with
- modifiers (see Qt::Modifier) such as Qt::SHIFT, Qt::CTRL,
- Qt::ALT, or Qt::META.
+ modifiers (see Qt::KeyboardModifier) such as Qt::ShiftModifier,
+ Qt::ControlModifier, Qt::AltModifier, or Qt::MetaModifier.
*/
QKeySequence::QKeySequence(int k1, int k2, int k3, int k4)
{
@@ -870,6 +847,17 @@ QKeySequence::QKeySequence(int k1, int k2, int k3, int k4)
}
/*!
+ Constructs a key sequence with up to 4 keys \a k1, \a k2,
+ \a k3 and \a k4.
+
+ \sa QKeyCombination
+*/
+QKeySequence::QKeySequence(QKeyCombination k1, QKeyCombination k2, QKeyCombination k3, QKeyCombination k4)
+ : QKeySequence(k1.toCombined(), k2.toCombined(), k3.toCombined(), k4.toCombined())
+{
+}
+
+/*!
Copy constructor. Makes a copy of \a keysequence.
*/
QKeySequence::QKeySequence(const QKeySequence& keysequence)
@@ -908,11 +896,11 @@ QKeySequence::~QKeySequence()
delivery.
*/
-void QKeySequence::setKey(int key, int index)
+void QKeySequence::setKey(QKeyCombination key, int index)
{
Q_ASSERT_X(index >= 0 && index < QKeySequencePrivate::MaxKeyCount, "QKeySequence::setKey", "index out of range");
qAtomicDetach(d);
- d->key[index] = key;
+ d->key[index] = key.toCombined();
}
static_assert(QKeySequencePrivate::MaxKeyCount == 4, "Change docs below");
@@ -943,31 +931,26 @@ bool QKeySequence::isEmpty() const
For example, mnemonic("E&xit") returns \c{Qt::ALT+Qt::Key_X},
mnemonic("&Quit") returns \c{ALT+Key_Q}, and mnemonic("Quit")
returns an empty QKeySequence.
-
- We provide a \l{accelerators.html}{list of common mnemonics}
- in English. At the time of writing, Microsoft and Open Group do
- not appear to have issued equivalent recommendations for other
- languages.
*/
QKeySequence QKeySequence::mnemonic(const QString &text)
{
QKeySequence ret;
- if(qt_sequence_no_mnemonics)
+ if (qt_sequence_no_mnemonics)
return ret;
bool found = false;
- int p = 0;
+ qsizetype p = 0;
while (p >= 0) {
- p = text.indexOf(QLatin1Char('&'), p) + 1;
- if (p <= 0 || p >= (int)text.length())
+ p = text.indexOf(u'&', p) + 1;
+ if (p <= 0 || p >= (int)text.size())
break;
- if (text.at(p) != QLatin1Char('&')) {
+ if (text.at(p) != u'&') {
QChar c = text.at(p);
if (c.isPrint()) {
if (!found) {
c = c.toUpper();
- ret = QKeySequence(c.unicode() + Qt::ALT);
+ ret = QKeySequence(QKeyCombination(Qt::ALT, Qt::Key(c.unicode())));
#ifdef QT_NO_DEBUG
return ret;
#else
@@ -1010,22 +993,22 @@ int QKeySequence::assign(const QString &ks, QKeySequence::SequenceFormat format)
{
QString keyseq = ks;
int n = 0;
- int p = 0, diff = 0;
+ qsizetype p = 0, diff = 0;
// Run through the whole string, but stop
// if we have MaxKeyCount keys before the end.
- while (keyseq.length() && n < QKeySequencePrivate::MaxKeyCount) {
+ while (keyseq.size() && n < QKeySequencePrivate::MaxKeyCount) {
// We MUST use something to separate each sequence, and space
// does not cut it, since some of the key names have space
// in them.. (Let's hope no one translate with a comma in it:)
- p = keyseq.indexOf(QLatin1Char(','));
+ p = keyseq.indexOf(u',');
if (-1 != p) {
- if (p == keyseq.count() - 1) { // Last comma 'Ctrl+,'
+ if (p == keyseq.size() - 1) { // Last comma 'Ctrl+,'
p = -1;
} else {
- if (QLatin1Char(',') == keyseq.at(p+1)) // e.g. 'Ctrl+,, Shift+,,'
+ if (u',' == keyseq.at(p+1)) // e.g. 'Ctrl+,, Shift+,,'
p++;
- if (QLatin1Char(' ') == keyseq.at(p+1)) { // Space after comma
+ if (u' ' == keyseq.at(p+1)) { // Space after comma
diff = 1;
p++;
} else {
@@ -1033,9 +1016,9 @@ int QKeySequence::assign(const QString &ks, QKeySequence::SequenceFormat format)
}
}
}
- QString part = keyseq.left(-1 == p ? keyseq.length() : p - diff);
- keyseq = keyseq.right(-1 == p ? 0 : keyseq.length() - (p + 1));
- d->key[n] = QKeySequencePrivate::decodeString(std::move(part), format);
+ QString part = keyseq.left(-1 == p ? keyseq.size() : p - diff);
+ keyseq = keyseq.right(-1 == p ? 0 : keyseq.size() - (p + 1));
+ d->key[n] = QKeySequencePrivate::decodeString(std::move(part), format).toCombined();
++n;
}
return n;
@@ -1048,20 +1031,12 @@ struct QModifKeyName {
int qt_key;
QString name;
};
-Q_DECLARE_TYPEINFO(QModifKeyName, Q_MOVABLE_TYPE);
-
-Q_GLOBAL_STATIC(QVector<QModifKeyName>, globalModifs)
-Q_GLOBAL_STATIC(QVector<QModifKeyName>, globalPortableModifs)
+Q_DECLARE_TYPEINFO(QModifKeyName, Q_RELOCATABLE_TYPE);
-/*!
- Constructs a single key from the string \a str.
-*/
-int QKeySequence::decodeString(const QString &str)
-{
- return QKeySequencePrivate::decodeString(str, NativeText);
-}
+Q_GLOBAL_STATIC(QList<QModifKeyName>, globalModifs)
+Q_GLOBAL_STATIC(QList<QModifKeyName>, globalPortableModifs)
-int QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceFormat format)
+QKeyCombination QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceFormat format)
{
Q_ASSERT(!accel.isEmpty());
@@ -1069,11 +1044,11 @@ int QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceForma
accel = std::move(accel).toLower();
bool nativeText = (format == QKeySequence::NativeText);
- QVector<QModifKeyName> *gmodifs;
+ QList<QModifKeyName> *gmodifs;
if (nativeText) {
gmodifs = globalModifs();
if (gmodifs->isEmpty()) {
-#if defined(Q_OS_MACX)
+#if defined(Q_OS_APPLE)
const bool dontSwap = qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
if (dontSwap)
*gmodifs << QModifKeyName(Qt::META, QChar(kCommandUnicode));
@@ -1086,36 +1061,36 @@ int QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceForma
*gmodifs << QModifKeyName(Qt::META, QChar(kControlUnicode));
*gmodifs << QModifKeyName(Qt::SHIFT, QChar(kShiftUnicode));
#endif
- *gmodifs << QModifKeyName(Qt::CTRL, QLatin1String("ctrl+"))
- << QModifKeyName(Qt::SHIFT, QLatin1String("shift+"))
- << QModifKeyName(Qt::ALT, QLatin1String("alt+"))
- << QModifKeyName(Qt::META, QLatin1String("meta+"))
- << QModifKeyName(Qt::KeypadModifier, QLatin1String("num+"));
+ *gmodifs << QModifKeyName(Qt::CTRL, u"ctrl+"_s)
+ << QModifKeyName(Qt::SHIFT, u"shift+"_s)
+ << QModifKeyName(Qt::ALT, u"alt+"_s)
+ << QModifKeyName(Qt::META, u"meta+"_s)
+ << QModifKeyName(Qt::KeypadModifier, u"num+"_s);
}
} else {
gmodifs = globalPortableModifs();
if (gmodifs->isEmpty()) {
- *gmodifs << QModifKeyName(Qt::CTRL, QLatin1String("ctrl+"))
- << QModifKeyName(Qt::SHIFT, QLatin1String("shift+"))
- << QModifKeyName(Qt::ALT, QLatin1String("alt+"))
- << QModifKeyName(Qt::META, QLatin1String("meta+"))
- << QModifKeyName(Qt::KeypadModifier, QLatin1String("num+"));
+ *gmodifs << QModifKeyName(Qt::CTRL, u"ctrl+"_s)
+ << QModifKeyName(Qt::SHIFT, u"shift+"_s)
+ << QModifKeyName(Qt::ALT, u"alt+"_s)
+ << QModifKeyName(Qt::META, u"meta+"_s)
+ << QModifKeyName(Qt::KeypadModifier, u"num+"_s);
}
}
- QVector<QModifKeyName> modifs;
+ QList<QModifKeyName> modifs;
if (nativeText) {
- modifs << QModifKeyName(Qt::CTRL, QCoreApplication::translate("QShortcut", "Ctrl").toLower().append(QLatin1Char('+')))
- << QModifKeyName(Qt::SHIFT, QCoreApplication::translate("QShortcut", "Shift").toLower().append(QLatin1Char('+')))
- << QModifKeyName(Qt::ALT, QCoreApplication::translate("QShortcut", "Alt").toLower().append(QLatin1Char('+')))
- << QModifKeyName(Qt::META, QCoreApplication::translate("QShortcut", "Meta").toLower().append(QLatin1Char('+')))
- << QModifKeyName(Qt::KeypadModifier, QCoreApplication::translate("QShortcut", "Num").toLower().append(QLatin1Char('+')));
+ modifs << QModifKeyName(Qt::CTRL, QCoreApplication::translate("QShortcut", "Ctrl").toLower().append(u'+'))
+ << QModifKeyName(Qt::SHIFT, QCoreApplication::translate("QShortcut", "Shift").toLower().append(u'+'))
+ << QModifKeyName(Qt::ALT, QCoreApplication::translate("QShortcut", "Alt").toLower().append(u'+'))
+ << QModifKeyName(Qt::META, QCoreApplication::translate("QShortcut", "Meta").toLower().append(u'+'))
+ << QModifKeyName(Qt::KeypadModifier, QCoreApplication::translate("QShortcut", "Num").toLower().append(u'+'));
}
modifs += *gmodifs; // Test non-translated ones last
QString sl = accel;
-#if defined(Q_OS_MACX)
+#if defined(Q_OS_APPLE)
for (int i = 0; i < modifs.size(); ++i) {
const QModifKeyName &mkf = modifs.at(i);
if (sl.contains(mkf.name)) {
@@ -1128,9 +1103,9 @@ int QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceForma
return Qt::Key_unknown;
#endif
- int i = 0;
- int lastI = 0;
- while ((i = sl.indexOf(QLatin1Char('+'), i + 1)) != -1) {
+ qsizetype i = 0;
+ qsizetype lastI = 0;
+ while ((i = sl.indexOf(u'+', i + 1)) != -1) {
const QStringView sub = QStringView{sl}.mid(lastI, i - lastI + 1);
// If we get here the shortcuts contains at least one '+'. We break up
// along the following strategy:
@@ -1141,9 +1116,9 @@ int QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceForma
// except for a single '+' at the end of the string.
// Only '+' can have length 1.
- if (sub.length() == 1) {
+ if (sub.size() == 1) {
// Make sure we only encounter a single '+' at the end of the accel
- if (accel.lastIndexOf(QLatin1Char('+')) != accel.length()-1)
+ if (accel.lastIndexOf(u'+') != accel.size()-1)
return Qt::Key_unknown;
} else {
// Identify the modifier
@@ -1163,15 +1138,15 @@ int QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceForma
lastI = i + 1;
}
- int p = accel.lastIndexOf(QLatin1Char('+'), accel.length() - 2); // -2 so that Ctrl++ works
+ qsizetype p = accel.lastIndexOf(u'+', accel.size() - 2); // -2 so that Ctrl++ works
QStringView accelRef(accel);
- if(p > 0)
+ if (p > 0)
accelRef = accelRef.mid(p + 1);
int fnum = 0;
- if (accelRef.length() == 1) {
-#if defined(Q_OS_MACX)
- int qtKey = qtkeyForMacSymbol(accelRef.at(0));
+ if (accelRef.size() == 1) {
+#if defined(Q_OS_APPLE)
+ int qtKey = qtkeyForAppleSymbol(accelRef.at(0));
if (qtKey != -1) {
ret |= qtKey;
} else
@@ -1179,10 +1154,10 @@ int QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceForma
{
ret |= accelRef.at(0).toUpper().unicode();
}
- } else if (accelRef.at(0) == QLatin1Char('f') && (fnum = accelRef.mid(1).toInt()) >= 1 && fnum <= 35) {
+ } else if (accelRef.at(0) == u'f' && (fnum = accelRef.mid(1).toInt()) >= 1 && fnum <= 35) {
ret |= Qt::Key_F1 + fnum - 1;
} else {
- // For NativeText, check the traslation table first,
+ // For NativeText, check the translation table first,
// if we don't find anything then try it out with just the untranlated stuff.
// PortableText will only try the untranlated table.
bool found = false;
@@ -1206,17 +1181,7 @@ int QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceForma
if (!found)
return Qt::Key_unknown;
}
- return ret;
-}
-
-/*!
- Creates a shortcut string for \a key. For example,
- Qt::CTRL+Qt::Key_O gives "Ctrl+O". The strings, "Ctrl", "Shift", etc. are
- translated (using QObject::tr()) in the "QShortcut" context.
- */
-QString QKeySequence::encodeString(int key)
-{
- return QKeySequencePrivate::encodeString(key, NativeText);
+ return QKeyCombination::fromCombined(ret);
}
static inline void addKey(QString &str, const QString &theKey, QKeySequence::SequenceFormat format)
@@ -1226,34 +1191,38 @@ static inline void addKey(QString &str, const QString &theKey, QKeySequence::Seq
//: Key separator in shortcut string
str += QCoreApplication::translate("QShortcut", "+");
} else {
- str += QLatin1Char('+');
+ str += u'+';
}
}
str += theKey;
}
-QString QKeySequencePrivate::encodeString(int key, QKeySequence::SequenceFormat format)
+QString QKeySequencePrivate::encodeString(QKeyCombination keyCombination, QKeySequence::SequenceFormat format)
{
bool nativeText = (format == QKeySequence::NativeText);
QString s;
+ const auto key = keyCombination.key();
+
// Handle -1 (Invalid Key) and Qt::Key_unknown gracefully
- if (key == -1 || key == Qt::Key_unknown)
+ if (keyCombination.toCombined() == -1 || key == Qt::Key_unknown)
return s;
-#if defined(Q_OS_MACX)
+ const auto modifiers = keyCombination.keyboardModifiers();
+
+#if defined(Q_OS_APPLE)
if (nativeText) {
- // On OS X the order (by default) is Meta, Alt, Shift, Control.
+ // On Apple platforms the order (by default) is Meta, Alt, Shift, Control.
// If the AA_MacDontSwapCtrlAndMeta is enabled, then the order
- // is Ctrl, Alt, Shift, Meta. The macSymbolForQtKey does this swap
+ // is Ctrl, Alt, Shift, Meta. The appleSymbolForQtKey helper does this swap
// for us, which means that we have to adjust our order here.
// The upshot is a lot more infrastructure to keep the number of
// if tests down and the code relatively clean.
- static const int ModifierOrder[] = { Qt::META, Qt::ALT, Qt::SHIFT, Qt::CTRL, 0 };
- static const int QtKeyOrder[] = { Qt::Key_Meta, Qt::Key_Alt, Qt::Key_Shift, Qt::Key_Control, 0 };
- static const int DontSwapModifierOrder[] = { Qt::CTRL, Qt::ALT, Qt::SHIFT, Qt::META, 0 };
- static const int DontSwapQtKeyOrder[] = { Qt::Key_Control, Qt::Key_Alt, Qt::Key_Shift, Qt::Key_Meta, 0 };
+ static constexpr int ModifierOrder[] = { Qt::META, Qt::ALT, Qt::SHIFT, Qt::CTRL, 0 };
+ static constexpr int QtKeyOrder[] = { Qt::Key_Meta, Qt::Key_Alt, Qt::Key_Shift, Qt::Key_Control, 0 };
+ static constexpr int DontSwapModifierOrder[] = { Qt::CTRL, Qt::ALT, Qt::SHIFT, Qt::META, 0 };
+ static constexpr int DontSwapQtKeyOrder[] = { Qt::Key_Control, Qt::Key_Alt, Qt::Key_Shift, Qt::Key_Meta, 0 };
const int *modifierOrder;
const int *qtkeyOrder;
if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
@@ -1265,33 +1234,33 @@ QString QKeySequencePrivate::encodeString(int key, QKeySequence::SequenceFormat
}
for (int i = 0; modifierOrder[i] != 0; ++i) {
- if (key & modifierOrder[i])
- s += qt_macSymbolForQtKey(qtkeyOrder[i]);
+ if (modifiers & modifierOrder[i])
+ s += appleSymbolForQtKey(qtkeyOrder[i]);
}
} else
#endif
{
// On other systems the order is Meta, Control, Alt, Shift
- if ((key & Qt::META) == Qt::META)
+ if (modifiers & Qt::MetaModifier)
s = nativeText ? QCoreApplication::translate("QShortcut", "Meta") : QString::fromLatin1("Meta");
- if ((key & Qt::CTRL) == Qt::CTRL)
+ if (modifiers & Qt::ControlModifier)
addKey(s, nativeText ? QCoreApplication::translate("QShortcut", "Ctrl") : QString::fromLatin1("Ctrl"), format);
- if ((key & Qt::ALT) == Qt::ALT)
+ if (modifiers & Qt::AltModifier)
addKey(s, nativeText ? QCoreApplication::translate("QShortcut", "Alt") : QString::fromLatin1("Alt"), format);
- if ((key & Qt::SHIFT) == Qt::SHIFT)
+ if (modifiers & Qt::ShiftModifier)
addKey(s, nativeText ? QCoreApplication::translate("QShortcut", "Shift") : QString::fromLatin1("Shift"), format);
}
- if ((key & Qt::KeypadModifier) == Qt::KeypadModifier)
+ if (modifiers & Qt::KeypadModifier)
addKey(s, nativeText ? QCoreApplication::translate("QShortcut", "Num") : QString::fromLatin1("Num"), format);
- QString p = keyName(key, format);
+ QString keyName = QKeySequencePrivate::keyName(key, format);
-#if defined(Q_OS_MACOS)
+#if defined(Q_OS_APPLE)
if (nativeText)
- s += p;
+ s += keyName;
else
#endif
- addKey(s, p, format);
+ addKey(s, keyName, format);
return s;
}
@@ -1303,10 +1272,9 @@ QString QKeySequencePrivate::encodeString(int key, QKeySequence::SequenceFormat
This static method is used by encodeString() and by the D-Bus menu exporter.
*/
-QString QKeySequencePrivate::keyName(int key, QKeySequence::SequenceFormat format)
+QString QKeySequencePrivate::keyName(Qt::Key key, QKeySequence::SequenceFormat format)
{
bool nativeText = (format == QKeySequence::NativeText);
- key &= ~(Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier | Qt::KeypadModifier);
QString p;
if (key && key < Qt::Key_Escape && key != Qt::Key_Space) {
@@ -1321,9 +1289,9 @@ QString QKeySequencePrivate::keyName(int key, QKeySequence::SequenceFormat forma
: QString::fromLatin1("F%1").arg(key - Qt::Key_F1 + 1);
} else if (key) {
int i=0;
-#if defined(Q_OS_MACX)
+#if defined(Q_OS_APPLE)
if (nativeText) {
- QChar ch = qt_macSymbolForQtKey(key);
+ QChar ch = appleSymbolForQtKey(key);
if (!ch.isNull())
p = ch;
else
@@ -1331,7 +1299,7 @@ QString QKeySequencePrivate::keyName(int key, QKeySequence::SequenceFormat forma
} else
#endif
{
-#if defined(Q_OS_MACX)
+#if defined(Q_OS_APPLE)
NonSymbol:
#endif
while (i < numKeyNames) {
@@ -1377,8 +1345,8 @@ QKeySequence::SequenceMatch QKeySequence::matches(const QKeySequence &seq) const
SequenceMatch match = (userN == seqN ? ExactMatch : PartialMatch);
for (uint i = 0; i < userN; ++i) {
- int userKey = (*this)[i],
- sequenceKey = seq[i];
+ QKeyCombination userKey = (*this)[i],
+ sequenceKey = seq[i];
if (userKey != sequenceKey)
return NoMatch;
}
@@ -1390,17 +1358,17 @@ QKeySequence::SequenceMatch QKeySequence::matches(const QKeySequence &seq) const
*/
QKeySequence::operator QVariant() const
{
- return QVariant(QMetaType::QKeySequence, this);
+ return QVariant::fromValue(*this);
}
/*!
Returns a reference to the element at position \a index in the key
sequence. This can only be used to read an element.
*/
-int QKeySequence::operator[](uint index) const
+QKeyCombination QKeySequence::operator[](uint index) const
{
Q_ASSERT_X(index < QKeySequencePrivate::MaxKeyCount, "QKeySequence::operator[]", "index out of range");
- return d->key[index];
+ return QKeyCombination::fromCombined(d->key[index]);
}
@@ -1444,6 +1412,7 @@ bool QKeySequence::operator==(const QKeySequence &other) const
/*!
\since 5.6
+ \relates QKeySequence
Calculates the hash value of \a key, using
\a seed to seed the calculation.
@@ -1520,7 +1489,7 @@ bool QKeySequence::isDetached() const
If the key sequence has no keys, an empty string is returned.
- On \macos, the string returned resembles the sequence that is
+ On Apple platforms, the string returned resembles the sequence that is
shown in the menu bar if \a format is
QKeySequence::NativeText; otherwise, the string uses the
"portable" format, suitable for writing to a file.
@@ -1534,10 +1503,10 @@ QString QKeySequence::toString(SequenceFormat format) const
// look like our latin case on Windows and X11
int end = count();
for (int i = 0; i < end; ++i) {
- finalString += d->encodeString(d->key[i], format);
- finalString += QLatin1String(", ");
+ finalString += d->encodeString(QKeyCombination::fromCombined(d->key[i]), format);
+ finalString += ", "_L1;
}
- finalString.truncate(finalString.length() - 2);
+ finalString.truncate(finalString.size() - 2);
return finalString;
}
@@ -1565,8 +1534,8 @@ QList<QKeySequence> QKeySequence::listFromString(const QString &str, SequenceFor
{
QList<QKeySequence> result;
- const QStringList strings = str.split(QLatin1String("; "));
- result.reserve(strings.count());
+ const QStringList strings = str.split("; "_L1);
+ result.reserve(strings.size());
for (const QString &string : strings) {
result << fromString(string, format);
}
@@ -1588,9 +1557,9 @@ QString QKeySequence::listToString(const QList<QKeySequence> &list, SequenceForm
for (const QKeySequence &sequence : list) {
result += sequence.toString(format);
- result += QLatin1String("; ");
+ result += "; "_L1;
}
- result.truncate(result.length() - 2);
+ result.truncate(result.size() - 2);
return result;
}
@@ -1669,3 +1638,5 @@ QDebug operator<<(QDebug dbg, const QKeySequence &p)
*/
QT_END_NAMESPACE
+
+#include "moc_qkeysequence.cpp"
diff --git a/src/gui/kernel/qkeysequence.h b/src/gui/kernel/qkeysequence.h
index 8b7ff12bed..4dae26a755 100644
--- a/src/gui/kernel/qkeysequence.h
+++ b/src/gui/kernel/qkeysequence.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QKEYSEQUENCE_H
#define QKEYSEQUENCE_H
@@ -53,12 +17,12 @@ class QKeySequence;
/*****************************************************************************
QKeySequence stream functions
*****************************************************************************/
-#if !defined(QT_NO_DATASTREAM) || defined(Q_CLANG_QDOC)
+#if !defined(QT_NO_DATASTREAM) || defined(Q_QDOC)
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &in, const QKeySequence &ks);
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &out, QKeySequence &ks);
#endif
-#if defined(Q_CLANG_QDOC)
+#if defined(Q_QDOC)
void qt_set_sequence_auto_mnemonic(bool b);
#endif
@@ -151,10 +115,15 @@ public:
NativeText,
PortableText
};
+ Q_ENUM(SequenceFormat)
QKeySequence();
QKeySequence(const QString &key, SequenceFormat format = NativeText);
QKeySequence(int k1, int k2 = 0, int k3 = 0, int k4 = 0);
+ QKeySequence(QKeyCombination k1,
+ QKeyCombination k2 = QKeyCombination::fromCombined(0),
+ QKeyCombination k3 = QKeyCombination::fromCombined(0),
+ QKeyCombination k4 = QKeyCombination::fromCombined(0));
QKeySequence(const QKeySequence &ks);
QKeySequence(StandardKey key);
~QKeySequence();
@@ -167,6 +136,7 @@ public:
PartialMatch,
ExactMatch
};
+ Q_ENUM(SequenceMatch);
QString toString(SequenceFormat format = PortableText) const;
static QKeySequence fromString(const QString &str, SequenceFormat format = PortableText);
@@ -179,10 +149,10 @@ public:
static QList<QKeySequence> keyBindings(StandardKey key);
operator QVariant() const;
- int operator[](uint i) const;
+ QKeyCombination operator[](uint i) const;
QKeySequence &operator=(const QKeySequence &other);
- QKeySequence &operator=(QKeySequence &&other) noexcept { swap(other); return *this; }
- void swap(QKeySequence &other) noexcept { qSwap(d, other.d); }
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QKeySequence)
+ void swap(QKeySequence &other) noexcept { qt_ptr_swap(d, other.d); }
bool operator==(const QKeySequence &other) const;
inline bool operator!= (const QKeySequence &other) const
@@ -197,11 +167,9 @@ public:
bool isDetached() const;
private:
- static int decodeString(const QString &ks);
- static QString encodeString(int key);
int assign(const QString &str);
int assign(const QString &str, SequenceFormat format);
- void setKey(int key, int index);
+ void setKey(QKeyCombination key, int index);
QKeySequencePrivate *d;
@@ -218,7 +186,7 @@ public:
Q_DECLARE_SHARED(QKeySequence)
-#if !defined(QT_NO_DEBUG_STREAM) || defined(Q_CLANG_QDOC)
+#if !defined(QT_NO_DEBUG_STREAM) || defined(Q_QDOC)
Q_GUI_EXPORT QDebug operator<<(QDebug, const QKeySequence &);
#endif
diff --git a/src/gui/kernel/qkeysequence_p.h b/src/gui/kernel/qkeysequence_p.h
index 8c59505561..8b98e3778a 100644
--- a/src/gui/kernel/qkeysequence_p.h
+++ b/src/gui/kernel/qkeysequence_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QKEYSEQUENCE_P_H
#define QKEYSEQUENCE_P_H
@@ -64,18 +28,15 @@ struct QKeyBinding
{
QKeySequence::StandardKey standardKey;
uchar priority;
- uint shortcut;
+ QKeyCombination shortcut;
uint platform;
};
class QKeySequencePrivate
{
public:
- enum { MaxKeyCount = 4 }; // also used in QKeySequenceEdit
- inline QKeySequencePrivate() : ref(1)
- {
- std::fill_n(key, uint(MaxKeyCount), 0);
- }
+ static constexpr int MaxKeyCount = 4 ; // also used in QKeySequenceEdit
+ constexpr QKeySequencePrivate() : ref(1), key{} {}
inline QKeySequencePrivate(const QKeySequencePrivate &copy) : ref(1)
{
std::copy(copy.key, copy.key + MaxKeyCount,
@@ -83,10 +44,10 @@ public:
}
QAtomicInt ref;
int key[MaxKeyCount];
- static QString encodeString(int key, QKeySequence::SequenceFormat format);
+ static QString encodeString(QKeyCombination keyCombination, QKeySequence::SequenceFormat format);
// used in dbusmenu
- Q_GUI_EXPORT static QString keyName(int key, QKeySequence::SequenceFormat format);
- static int decodeString(QString accel, QKeySequence::SequenceFormat format);
+ Q_GUI_EXPORT static QString keyName(Qt::Key key, QKeySequence::SequenceFormat format);
+ static QKeyCombination decodeString(QString accel, QKeySequence::SequenceFormat format);
};
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qoffscreensurface.cpp b/src/gui/kernel/qoffscreensurface.cpp
index c74fe0b3a1..02e606658a 100644
--- a/src/gui/kernel/qoffscreensurface.cpp
+++ b/src/gui/kernel/qoffscreensurface.cpp
@@ -1,48 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qoffscreensurface.h"
#include "qguiapplication_p.h"
#include "qscreen.h"
#include "qplatformintegration.h"
-#include "qplatformoffscreensurface.h"
+#include "qoffscreensurface_p.h"
#include "qwindow.h"
#include "qplatformwindow.h"
@@ -50,6 +14,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
/*!
\class QOffscreenSurface
\inmodule QtGui
@@ -91,36 +57,6 @@ QT_BEGIN_NAMESPACE
native surface. For the use cases of QOffscreenSurface (rendering to FBOs, texture
upload) this is not a problem.
*/
-class Q_GUI_EXPORT QOffscreenSurfacePrivate : public QObjectPrivate
-{
- Q_DECLARE_PUBLIC(QOffscreenSurface)
-
-public:
- QOffscreenSurfacePrivate()
- : QObjectPrivate()
- , surfaceType(QSurface::OpenGLSurface)
- , platformOffscreenSurface(nullptr)
- , offscreenWindow(nullptr)
- , requestedFormat(QSurfaceFormat::defaultFormat())
- , screen(nullptr)
- , size(1, 1)
- , nativeHandle(nullptr)
- {
- }
-
- ~QOffscreenSurfacePrivate()
- {
- }
-
- QSurface::SurfaceType surfaceType;
- QPlatformOffscreenSurface *platformOffscreenSurface;
- QWindow *offscreenWindow;
- QSurfaceFormat requestedFormat;
- QScreen *screen;
- QSize size;
- void *nativeHandle;
-};
-
/*!
\since 5.10
@@ -148,19 +84,6 @@ QOffscreenSurface::QOffscreenSurface(QScreen *targetScreen, QObject *parent)
}
/*!
- Creates an offscreen surface for the \a targetScreen.
-
- The underlying platform surface is not created until create() is called.
-
- \sa setScreen(), create()
-*/
-QOffscreenSurface::QOffscreenSurface(QScreen *targetScreen)
- : QOffscreenSurface(targetScreen, nullptr)
-{
-}
-
-
-/*!
Destroys the offscreen surface.
*/
QOffscreenSurface::~QOffscreenSurface()
@@ -205,7 +128,7 @@ void QOffscreenSurface::create()
// violate the minimum title bar width on the platform.
d->offscreenWindow->setFlags(d->offscreenWindow->flags()
| Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
- d->offscreenWindow->setObjectName(QLatin1String("QOffscreenSurface"));
+ d->offscreenWindow->setObjectName("QOffscreenSurface"_L1);
// Remove this window from the global list since we do not want it to be destroyed when closing the app.
// The QOffscreenSurface has to be usable even after exiting the event loop.
QGuiApplicationPrivate::window_list.removeOne(d->offscreenWindow);
@@ -241,14 +164,12 @@ void QOffscreenSurface::destroy()
delete d->offscreenWindow;
d->offscreenWindow = nullptr;
}
-
- d->nativeHandle = nullptr;
}
/*!
Returns \c true if this offscreen surface is valid; otherwise returns \c false.
- The offscreen surface is valid if the platform resources have been successfuly allocated.
+ The offscreen surface is valid if the platform resources have been successfully allocated.
\sa create()
*/
@@ -357,26 +278,6 @@ void QOffscreenSurface::setScreen(QScreen *newScreen)
}
/*!
- Sets the native handle to which the offscreen surface is connected to \a handle.
-
- The native handle will be resolved in the create() function. Calling
- this function after create() will not re-create a native surface.
-
- \note The interpretation of the native handle is platform specific. Only
- some platforms will support adopting native handles of offscreen surfaces
- and platforms that do not implement this support will ignore the handle.
-
- \since 5.9
- \sa nativeHandle()
-*/
-
-void QOffscreenSurface::setNativeHandle(void *handle)
-{
- Q_D(QOffscreenSurface);
- d->nativeHandle = handle;
-}
-
-/*!
Called when the offscreen surface's screen is destroyed.
\internal
@@ -408,17 +309,17 @@ QPlatformOffscreenSurface *QOffscreenSurface::handle() const
}
/*!
- Returns an optional native handle to which the offscreen surface is connected.
+ \fn template <typename QNativeInterface> QNativeInterface *QOffscreenSurface::nativeInterface() const
- \since 5.9
- \sa setNativeHandle()
-*/
+ Returns a native interface of the given type for the surface.
-void *QOffscreenSurface::nativeHandle() const
-{
- Q_D(const QOffscreenSurface);
- return d->nativeHandle;
-}
+ This function provides access to platform specific functionality
+ of QOffScreenSurface, as defined in the QNativeInterface namespace:
+
+ \annotatedlist native-interfaces-qoffscreensurface
+
+ If the requested interface is not available a \nullptr is returned.
+*/
/*!
Returns the platform surface corresponding to the offscreen surface.
@@ -434,4 +335,22 @@ QPlatformSurface *QOffscreenSurface::surfaceHandle() const
return d->platformOffscreenSurface;
}
+using namespace QNativeInterface;
+
+void *QOffscreenSurface::resolveInterface(const char *name, int revision) const
+{
+ Q_UNUSED(name); Q_UNUSED(revision);
+
+ Q_D(const QOffscreenSurface);
+ Q_UNUSED(d);
+
+#if defined(Q_OS_ANDROID)
+ QT_NATIVE_INTERFACE_RETURN_IF(QAndroidOffscreenSurface, d->platformOffscreenSurface);
+#endif
+
+ return nullptr;
+}
+
QT_END_NAMESPACE
+
+#include "moc_qoffscreensurface.cpp"
diff --git a/src/gui/kernel/qoffscreensurface.h b/src/gui/kernel/qoffscreensurface.h
index cfdcd758ec..410b6d2b61 100644
--- a/src/gui/kernel/qoffscreensurface.h
+++ b/src/gui/kernel/qoffscreensurface.h
@@ -1,49 +1,14 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QOFFSCREENSURFACE_H
#define QOFFSCREENSURFACE_H
#include <QtGui/qtguiglobal.h>
#include <QtCore/QObject>
+#include <QtCore/qnativeinterface.h>
#include <QtGui/qsurface.h>
-Q_MOC_INCLUDE(<QScreen>)
+Q_MOC_INCLUDE(<QtGui/qscreen.h>)
QT_BEGIN_NAMESPACE
@@ -58,9 +23,7 @@ class Q_GUI_EXPORT QOffscreenSurface : public QObject, public QSurface
Q_DECLARE_PRIVATE(QOffscreenSurface)
public:
- // ### Qt 6: merge overloads
- explicit QOffscreenSurface(QScreen *screen, QObject *parent);
- explicit QOffscreenSurface(QScreen *screen = nullptr);
+ explicit QOffscreenSurface(QScreen *screen = nullptr, QObject *parent = nullptr);
~QOffscreenSurface();
SurfaceType surfaceType() const override;
@@ -81,8 +44,7 @@ public:
QPlatformOffscreenSurface *handle() const;
- void *nativeHandle() const;
- void setNativeHandle(void *handle);
+ QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QOffscreenSurface)
Q_SIGNALS:
void screenChanged(QScreen *screen);
@@ -99,4 +61,6 @@ private:
QT_END_NAMESPACE
+#include <QtGui/qoffscreensurface_platform.h>
+
#endif // QOFFSCREENSURFACE_H
diff --git a/src/gui/kernel/qoffscreensurface_p.h b/src/gui/kernel/qoffscreensurface_p.h
new file mode 100644
index 0000000000..3de4b5e17a
--- /dev/null
+++ b/src/gui/kernel/qoffscreensurface_p.h
@@ -0,0 +1,59 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QOFFSCREENSURFACE_P_H
+#define QOFFSCREENSURFACE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qplatformoffscreensurface.h"
+
+#include <private/qwindow_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_GUI_EXPORT QOffscreenSurfacePrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QOffscreenSurface)
+
+public:
+ QOffscreenSurfacePrivate()
+ : QObjectPrivate()
+ , surfaceType(QSurface::OpenGLSurface)
+ , platformOffscreenSurface(nullptr)
+ , offscreenWindow(nullptr)
+ , requestedFormat(QSurfaceFormat::defaultFormat())
+ , screen(nullptr)
+ , size(1, 1)
+ {
+ }
+
+ ~QOffscreenSurfacePrivate()
+ {
+ }
+
+ static QOffscreenSurfacePrivate *get(QOffscreenSurface *surface)
+ {
+ return surface ? surface->d_func() : nullptr;
+ }
+
+ QSurface::SurfaceType surfaceType;
+ QPlatformOffscreenSurface *platformOffscreenSurface;
+ QWindow *offscreenWindow;
+ QSurfaceFormat requestedFormat;
+ QScreen *screen;
+ QSize size;
+};
+
+QT_END_NAMESPACE
+
+#endif // QOFFSCREENSURFACE_P_H
diff --git a/src/gui/kernel/qoffscreensurface_platform.h b/src/gui/kernel/qoffscreensurface_platform.h
new file mode 100644
index 0000000000..33e72c7e17
--- /dev/null
+++ b/src/gui/kernel/qoffscreensurface_platform.h
@@ -0,0 +1,41 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QOFFSCREENSURFACE_PLATFORM_H
+#define QOFFSCREENSURFACE_PLATFORM_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is part of the native interface APIs. Usage of
+// this API may make your code source and binary incompatible
+// with future versions of Qt.
+//
+
+#include <QtGui/qtguiglobal.h>
+#include <QtGui/qoffscreensurface.h>
+#include <QtCore/qnativeinterface.h>
+
+#if defined(Q_OS_ANDROID)
+struct ANativeWindow;
+#endif
+
+QT_BEGIN_NAMESPACE
+
+namespace QNativeInterface {
+
+#if defined(Q_OS_ANDROID) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QAndroidOffscreenSurface
+{
+ QT_DECLARE_NATIVE_INTERFACE(QAndroidOffscreenSurface, 1, QOffscreenSurface)
+ static QOffscreenSurface *fromNative(ANativeWindow *nativeSurface);
+ virtual ANativeWindow *nativeSurface() const = 0;
+};
+#endif
+
+} // QNativeInterface
+
+QT_END_NAMESPACE
+
+#endif // QOFFSCREENSURFACE_PLATFORM_H
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp
index 51bf5cf336..02781f4aa0 100644
--- a/src/gui/kernel/qopenglcontext.cpp
+++ b/src/gui/kernel/qopenglcontext.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qpa/qplatformopenglcontext.h>
#include <qpa/qplatformintegration.h>
@@ -78,7 +42,7 @@ static QOpenGLContext *global_share_context = nullptr;
#ifndef QT_NO_DEBUG
QHash<QOpenGLContext *, bool> QOpenGLContextPrivate::makeCurrentTracker;
-QMutex QOpenGLContextPrivate::makeCurrentTrackerMutex;
+Q_CONSTINIT QMutex QOpenGLContextPrivate::makeCurrentTrackerMutex;
#endif
/*!
@@ -105,6 +69,7 @@ QOpenGLContext *qt_gl_global_share_context()
/*!
\class QOpenGLContext
+ \ingroup painting-3D
\inmodule QtGui
\since 5.0
\brief The QOpenGLContext class represents a native OpenGL context, enabling
@@ -173,6 +138,22 @@ QOpenGLContext *qt_gl_global_share_context()
application is portable between different platforms. However, if you use
QOpenGLFunctions::glBindFramebuffer(), this is done automatically for you.
+ \warning WebAssembly
+
+ We recommend that only one QOpenGLContext is made current with a QSurface,
+ for the entire lifetime of the QSurface. Should more than once context be used,
+ it is important to understand that multiple QOpenGLContext instances may be
+ backed by the same native context underneath with the WebAssembly platform.
+ Therefore, calling makeCurrent() with the same QSurface on two QOpenGLContext
+ objects may not switch to a different native context in the second call. As
+ a result, any OpenGL state changes done after the second makeCurrent() may
+ alter the state of the first QOpenGLContext as well, as they are all backed
+ by the same native context.
+
+ \note This means that when targeting WebAssembly with existing OpenGL-based
+ Qt code, some porting may be required to cater to these limitations.
+
+
\sa QOpenGLFunctions, QOpenGLBuffer, QOpenGLShaderProgram, QOpenGLFramebufferObject
*/
@@ -347,12 +328,14 @@ void QOpenGLContextPrivate::_q_screenDestroyed(QObject *object)
}
/*!
- \fn T QOpenGLContext::platformInterface<T>()
+ \fn template <typename QNativeInterface> QNativeInterface *QOpenGLContext::nativeInterface() const
- Returns a platform interface of type T for the context.
+ Returns a native interface of the given type for the context.
This function provides access to platform specific functionality
- of QOpenGLContext, as defined in the QPlatformInterface namespace.
+ of QOpenGLContext, as defined in the QNativeInterface namespace:
+
+ \annotatedlist native-interfaces-qopenglcontext
If the requested interface is not available a \nullptr is returned.
*/
@@ -394,6 +377,10 @@ bool QOpenGLContext::create()
return isValid();
}
+QOpenGLContextPrivate::~QOpenGLContextPrivate()
+{
+}
+
void QOpenGLContextPrivate::adopt(QPlatformOpenGLContext *context)
{
Q_Q(QOpenGLContext);
@@ -429,30 +416,47 @@ void QOpenGLContextPrivate::adopt(QPlatformOpenGLContext *context)
void QOpenGLContext::destroy()
{
Q_D(QOpenGLContext);
+
+ // Notify that the native context and the QPlatformOpenGLContext are going
+ // to go away.
if (d->platformGLContext)
emit aboutToBeDestroyed();
- if (QOpenGLContext::currentContext() == this)
- doneCurrent();
- if (d->shareGroup)
- d->shareGroup->d_func()->removeContext(this);
- d->shareGroup = nullptr;
- delete d->platformGLContext;
- d->platformGLContext = nullptr;
- delete d->functions;
- d->functions = nullptr;
+ // Invoke callbacks for helpers and invalidate.
if (d->textureFunctionsDestroyCallback) {
d->textureFunctionsDestroyCallback();
d->textureFunctionsDestroyCallback = nullptr;
}
d->textureFunctions = nullptr;
+ delete d->versionFunctions;
+ d->versionFunctions = nullptr;
+
if (d->vaoHelperDestroyCallback) {
Q_ASSERT(d->vaoHelper);
d->vaoHelperDestroyCallback(d->vaoHelper);
d->vaoHelperDestroyCallback = nullptr;
}
d->vaoHelper = nullptr;
+
+ // Tear down function wrappers.
+ delete d->versionFunctions;
+ d->versionFunctions = nullptr;
+
+ delete d->functions;
+ d->functions = nullptr;
+
+ // Clean up and destroy the native context machinery.
+ if (QOpenGLContext::currentContext() == this)
+ doneCurrent();
+
+ if (d->shareGroup)
+ d->shareGroup->d_func()->removeContext(this);
+
+ d->shareGroup = nullptr;
+
+ delete d->platformGLContext;
+ d->platformGLContext = nullptr;
}
/*!
@@ -464,6 +468,11 @@ void QOpenGLContext::destroy()
If you wish to make the context current in order to do clean-up, make sure
to only connect to the signal using a direct connection.
+
+ \note In Qt for Python, this signal will not be received when emitted
+ from the destructor of QOpenGLWidget or QOpenGLWindow due to the Python
+ instance already being destroyed. We recommend doing cleanups
+ in QWidget::hideEvent() instead.
*/
/*!
@@ -707,7 +716,8 @@ bool QOpenGLContext::makeCurrent(QSurface *surface)
|| qstrcmp(rendererString, "GC800 core") == 0
|| qstrcmp(rendererString, "GC1000 core") == 0
|| strstr(rendererString, "GC2000") != nullptr
- || qstrcmp(rendererString, "Immersion.16") == 0;
+ || qstrcmp(rendererString, "Immersion.16") == 0
+ || qstrncmp(rendererString, "Apple Mx", 7) == 0;
}
needsWorkaroundSet = true;
}
@@ -777,12 +787,6 @@ void QOpenGLContext::swapBuffers(QSurface *surface)
return;
}
- if (surface->surfaceClass() == QSurface::Window
- && !qt_window_private(static_cast<QWindow *>(surface))->receivedExpose)
- {
- qWarning("QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined");
- }
-
QPlatformSurface *surfaceHandle = surface->surfaceHandle();
if (!surfaceHandle)
return;
@@ -1034,6 +1038,9 @@ QOpenGLContextGroup *QOpenGLContextGroup::currentContextGroup()
return current ? current->shareGroup() : nullptr;
}
+QOpenGLContextGroupPrivate::~QOpenGLContextGroupPrivate()
+ = default;
+
void QOpenGLContextGroupPrivate::addContext(QOpenGLContext *ctx)
{
const auto locker = qt_scoped_lock(m_mutex);
@@ -1175,6 +1182,10 @@ void QOpenGLSharedResource::free()
\inmodule QtGui
*/
+
+QOpenGLSharedResourceGuard::~QOpenGLSharedResourceGuard()
+ = default;
+
void QOpenGLSharedResourceGuard::freeResource(QOpenGLContext *context)
{
if (m_id) {
@@ -1247,14 +1258,14 @@ void QOpenGLMultiGroupSharedResource::insert(QOpenGLContext *context, QOpenGLSha
QOpenGLSharedResource *QOpenGLMultiGroupSharedResource::value(QOpenGLContext *context)
{
QOpenGLContextGroup *group = context->shareGroup();
- return group->d_func()->m_resources.value(this, 0);
+ return group->d_func()->m_resources.value(this, nullptr);
}
QList<QOpenGLSharedResource *> QOpenGLMultiGroupSharedResource::resources() const
{
QList<QOpenGLSharedResource *> result;
for (QList<QOpenGLContextGroup *>::const_iterator it = m_groups.constBegin(); it != m_groups.constEnd(); ++it) {
- QOpenGLSharedResource *resource = (*it)->d_func()->m_resources.value(const_cast<QOpenGLMultiGroupSharedResource *>(this), 0);
+ QOpenGLSharedResource *resource = (*it)->d_func()->m_resources.value(const_cast<QOpenGLMultiGroupSharedResource *>(this), nullptr);
if (resource)
result << resource;
}
@@ -1274,6 +1285,9 @@ void QOpenGLMultiGroupSharedResource::cleanup(QOpenGLContextGroup *group, QOpenG
m_groups.removeOne(group);
}
+QOpenGLContextVersionFunctionHelper::~QOpenGLContextVersionFunctionHelper()
+ = default;
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, const QOpenGLContext *ctx)
{
@@ -1313,6 +1327,31 @@ QDebug operator<<(QDebug debug, const QOpenGLContextGroup *cg)
}
#endif // QT_NO_DEBUG_STREAM
-#include "moc_qopenglcontext.cpp"
+using namespace QNativeInterface;
+
+void *QOpenGLContext::resolveInterface(const char *name, int revision) const
+{
+ Q_UNUSED(name); Q_UNUSED(revision);
+
+ auto *platformContext = handle();
+ Q_UNUSED(platformContext);
+
+#if defined(Q_OS_MACOS)
+ QT_NATIVE_INTERFACE_RETURN_IF(QCocoaGLContext, platformContext);
+#endif
+#if defined(Q_OS_WIN)
+ QT_NATIVE_INTERFACE_RETURN_IF(QWGLContext, platformContext);
+#endif
+#if QT_CONFIG(xcb_glx_plugin)
+ QT_NATIVE_INTERFACE_RETURN_IF(QGLXContext, platformContext);
+#endif
+#if QT_CONFIG(egl)
+ QT_NATIVE_INTERFACE_RETURN_IF(QEGLContext, platformContext);
+#endif
+
+ return nullptr;
+}
QT_END_NAMESPACE
+
+#include "moc_qopenglcontext.cpp"
diff --git a/src/gui/kernel/qopenglcontext.h b/src/gui/kernel/qopenglcontext.h
index 24adb1910b..ca2d4a8903 100644
--- a/src/gui/kernel/qopenglcontext.h
+++ b/src/gui/kernel/qopenglcontext.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QOPENGLCONTEXT_H
#define QOPENGLCONTEXT_H
@@ -45,8 +9,10 @@
#ifndef QT_NO_OPENGL
#include <QtCore/qnamespace.h>
-#include <QtCore/QObject>
-#include <QtCore/QScopedPointer>
+#include <QtCore/qobject.h>
+#include <QtCore/qscopedpointer.h>
+#include <QtCore/qset.h>
+#include <QtCore/qnativeinterface.h>
#include <QtGui/QSurfaceFormat>
@@ -152,8 +118,7 @@ public:
static bool supportsThreadedOpenGL();
static QOpenGLContext *globalShareContext();
- template <typename T>
- T *platformInterface() const;
+ QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QOpenGLContext)
Q_SIGNALS:
void aboutToBeDestroyed();
diff --git a/src/gui/kernel/qopenglcontext_p.h b/src/gui/kernel/qopenglcontext_p.h
index b3c0658d60..a0e8eda679 100644
--- a/src/gui/kernel/qopenglcontext_p.h
+++ b/src/gui/kernel/qopenglcontext_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QOPENGLCONTEXT_P_H
#define QOPENGLCONTEXT_P_H
@@ -110,6 +74,7 @@ public:
, m_func(func)
{
}
+ ~QOpenGLSharedResourceGuard() override;
GLuint id() const { return m_id; }
@@ -135,6 +100,7 @@ public:
, m_refs(0)
{
}
+ ~QOpenGLContextGroupPrivate() override;
void addContext(QOpenGLContext *ctx);
void removeContext(QOpenGLContext *ctx);
@@ -174,7 +140,7 @@ public:
// Have to use our own mutex here, not the group's, since
// m_groups has to be protected too against any concurrent access.
QMutexLocker locker(&m_mutex);
- T *resource = static_cast<T *>(group->d_func()->m_resources.value(this, 0));
+ T *resource = static_cast<T *>(group->d_func()->m_resources.value(this, nullptr));
if (!resource) {
resource = new T(context);
insert(context, resource);
@@ -196,7 +162,7 @@ class QOpenGLVertexArrayObjectHelper;
class Q_GUI_EXPORT QOpenGLContextVersionFunctionHelper
{
public:
- virtual ~QOpenGLContextVersionFunctionHelper() {}
+ virtual ~QOpenGLContextVersionFunctionHelper();
};
class Q_GUI_EXPORT QOpenGLContextPrivate : public QObjectPrivate
@@ -226,13 +192,7 @@ public:
requestedFormat = QSurfaceFormat::defaultFormat();
}
- ~QOpenGLContextPrivate()
- {
- //do not delete the QOpenGLContext handle here as it is deleted in
- //QWidgetPrivate::deleteTLSysExtra()
-
- delete versionFunctions;
- }
+ ~QOpenGLContextPrivate() override;
void adopt(QPlatformOpenGLContext *);
diff --git a/src/gui/kernel/qopenglcontext_platform.h b/src/gui/kernel/qopenglcontext_platform.h
index 25be8623c6..1f84cf6ce3 100644
--- a/src/gui/kernel/qopenglcontext_platform.h
+++ b/src/gui/kernel/qopenglcontext_platform.h
@@ -1,106 +1,90 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QOPENGLCONTEXT_PLATFORM_H
#define QOPENGLCONTEXT_PLATFORM_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is part of the native interface APIs. Usage of
+// this API may make your code source and binary incompatible
+// with future versions of Qt.
+//
+
#ifndef QT_NO_OPENGL
#include <QtGui/qtguiglobal.h>
#include <QtGui/qopenglcontext.h>
#include <QtGui/qwindowdefs.h>
+#include <QtCore/qnativeinterface.h>
+
#if defined(Q_OS_MACOS)
Q_FORWARD_DECLARE_OBJC_CLASS(NSOpenGLContext);
#endif
-#if defined(Q_OS_LINUX)
+#if QT_CONFIG(xcb_glx_plugin)
struct __GLXcontextRec; typedef struct __GLXcontextRec *GLXContext;
#endif
#if QT_CONFIG(egl)
typedef void *EGLContext;
typedef void *EGLDisplay;
+typedef void *EGLConfig;
+#endif
+
+#if !defined(Q_OS_MACOS) && defined(Q_QDOC)
+typedef void *NSOpenGLContext;
#endif
QT_BEGIN_NAMESPACE
-namespace QPlatformInterface {
+namespace QNativeInterface {
-#if defined(Q_OS_MACOS)
+#if defined(Q_OS_MACOS) || defined(Q_QDOC)
struct Q_GUI_EXPORT QCocoaGLContext
{
- QT_DECLARE_PLATFORM_INTERFACE(QCocoaGLContext)
- static QOpenGLContext *fromNative(QT_IGNORE_DEPRECATIONS(NSOpenGLContext) *, QOpenGLContext *shareContext = nullptr);
+ QT_DECLARE_NATIVE_INTERFACE(QCocoaGLContext, 1, QOpenGLContext)
+ static QOpenGLContext *fromNative(QT_IGNORE_DEPRECATIONS(NSOpenGLContext) *context, QOpenGLContext *shareContext = nullptr);
virtual QT_IGNORE_DEPRECATIONS(NSOpenGLContext) *nativeContext() const = 0;
};
#endif
-#if defined(Q_OS_WIN)
+#if defined(Q_OS_WIN) || defined(Q_QDOC)
struct Q_GUI_EXPORT QWGLContext
{
- QT_DECLARE_PLATFORM_INTERFACE(QWGLContext)
+ QT_DECLARE_NATIVE_INTERFACE(QWGLContext, 1, QOpenGLContext)
static HMODULE openGLModuleHandle();
static QOpenGLContext *fromNative(HGLRC context, HWND window, QOpenGLContext *shareContext = nullptr);
virtual HGLRC nativeContext() const = 0;
};
#endif
-#if defined(Q_OS_LINUX)
+#if QT_CONFIG(xcb_glx_plugin) || defined(Q_QDOC)
struct Q_GUI_EXPORT QGLXContext
{
- QT_DECLARE_PLATFORM_INTERFACE(QGLXContext)
+ QT_DECLARE_NATIVE_INTERFACE(QGLXContext, 1, QOpenGLContext)
static QOpenGLContext *fromNative(GLXContext configBasedContext, QOpenGLContext *shareContext = nullptr);
static QOpenGLContext *fromNative(GLXContext visualBasedContext, void *visualInfo, QOpenGLContext *shareContext = nullptr);
virtual GLXContext nativeContext() const = 0;
};
#endif
-#if QT_CONFIG(egl)
+#if QT_CONFIG(egl) || defined(Q_QDOC)
struct Q_GUI_EXPORT QEGLContext
{
- QT_DECLARE_PLATFORM_INTERFACE(QEGLContext)
+ QT_DECLARE_NATIVE_INTERFACE(QEGLContext, 1, QOpenGLContext)
static QOpenGLContext *fromNative(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext = nullptr);
virtual EGLContext nativeContext() const = 0;
+ virtual EGLConfig config() const = 0;
+ virtual EGLDisplay display() const = 0;
+
+ virtual void invalidateContext() = 0;
};
#endif
-} // QPlatformInterface
+} // QNativeInterface
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qpaintdevicewindow.cpp b/src/gui/kernel/qpaintdevicewindow.cpp
index 4f45fc5fde..9e8c6ae5a8 100644
--- a/src/gui/kernel/qpaintdevicewindow.cpp
+++ b/src/gui/kernel/qpaintdevicewindow.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qpaintdevicewindow_p.h"
@@ -44,6 +8,12 @@
QT_BEGIN_NAMESPACE
+QPaintDeviceWindowPrivate::QPaintDeviceWindowPrivate()
+ = default;
+
+QPaintDeviceWindowPrivate::~QPaintDeviceWindowPrivate()
+ = default;
+
/*!
\class QPaintDeviceWindow
\inmodule QtGui
@@ -178,16 +148,7 @@ int QPaintDeviceWindow::metric(PaintDeviceMetric metric) const
*/
void QPaintDeviceWindow::exposeEvent(QExposeEvent *exposeEvent)
{
- Q_UNUSED(exposeEvent);
- Q_D(QPaintDeviceWindow);
- if (isExposed()) {
- d->markWindowAsDirty();
- // Do not rely on exposeEvent->region() as it has some issues for the
- // time being, namely that it is sometimes in local coordinates,
- // sometimes relative to the parent, depending on the platform plugin.
- // We require local coords here.
- d->doFlush(QRect(QPoint(0, 0), size()));
- }
+ QWindow::exposeEvent(exposeEvent);
}
/*!
@@ -201,6 +162,17 @@ bool QPaintDeviceWindow::event(QEvent *event)
if (handle()) // platform window may be gone when the window is closed during app exit
d->handleUpdateEvent();
return true;
+ } else if (event->type() == QEvent::Paint) {
+ d->markWindowAsDirty();
+ // Do not rely on exposeEvent->region() as it has some issues for the
+ // time being, namely that it is sometimes in local coordinates,
+ // sometimes relative to the parent, depending on the platform plugin.
+ // We require local coords here.
+ auto region = QRect(QPoint(0, 0), size());
+ d->doFlush(region); // Will end up calling paintEvent
+ return true;
+ } else if (event->type() == QEvent::Resize) {
+ d->handleResizeEvent();
}
return QWindow::event(event);
@@ -223,3 +195,5 @@ QPaintEngine *QPaintDeviceWindow::paintEngine() const
}
QT_END_NAMESPACE
+
+#include "moc_qpaintdevicewindow.cpp"
diff --git a/src/gui/kernel/qpaintdevicewindow.h b/src/gui/kernel/qpaintdevicewindow.h
index 3be078132f..d6b70298a6 100644
--- a/src/gui/kernel/qpaintdevicewindow.h
+++ b/src/gui/kernel/qpaintdevicewindow.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPAINTDEVICEWINDOW_H
#define QPAINTDEVICEWINDOW_H
@@ -66,10 +30,10 @@ public Q_SLOTS:
void update();
protected:
- virtual void paintEvent(QPaintEvent *event);
+ void exposeEvent(QExposeEvent *) override;
+ void paintEvent(QPaintEvent *event) override;
int metric(PaintDeviceMetric metric) const override;
- void exposeEvent(QExposeEvent *) override;
bool event(QEvent *event) override;
QPaintDeviceWindow(QPaintDeviceWindowPrivate &dd, QWindow *parent);
diff --git a/src/gui/kernel/qpaintdevicewindow_p.h b/src/gui/kernel/qpaintdevicewindow_p.h
index a16b83689e..85c11cbf91 100644
--- a/src/gui/kernel/qpaintdevicewindow_p.h
+++ b/src/gui/kernel/qpaintdevicewindow_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPAINTDEVICEWINDOW_P_H
#define QPAINTDEVICEWINDOW_P_H
@@ -64,6 +28,11 @@ class Q_GUI_EXPORT QPaintDeviceWindowPrivate : public QWindowPrivate
Q_DECLARE_PUBLIC(QPaintDeviceWindow)
public:
+ QPaintDeviceWindowPrivate();
+ ~QPaintDeviceWindowPrivate() override;
+
+ virtual void handleResizeEvent() {}
+
virtual void beginPaint(const QRegion &region)
{
Q_UNUSED(region);
@@ -115,7 +84,7 @@ public:
void markWindowAsDirty()
{
Q_Q(QPaintDeviceWindow);
- dirtyRegion += QRect(QPoint(0, 0), q->size());
+ dirtyRegion = QRect(QPoint(0, 0), q->size());
}
private:
diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp
index 2c636dc553..256ea52f01 100644
--- a/src/gui/kernel/qpalette.cpp
+++ b/src/gui/kernel/qpalette.cpp
@@ -1,44 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qpalette.h"
-#include "qguiapplication.h"
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qpalette_p.h"
#include "qguiapplication_p.h"
#include "qdatastream.h"
#include "qvariant.h"
@@ -48,37 +11,61 @@
QT_BEGIN_NAMESPACE
-static int qt_palette_count = 1;
+static_assert(QPalettePrivate::bitPosition(QPalette::ColorGroup(QPalette::NColorGroups - 1),
+ QPalette::ColorRole(QPalette::NColorRoles - 1))
+ < sizeof(QPalette::ResolveMask) * CHAR_BIT,
+ "The resolve mask type is not wide enough to fit the entire bit mask.");
-static constexpr QPalette::ResolveMask colorRoleOffset(QPalette::ColorGroup colorGroup)
+static QColor qt_mix_colors(QColor a, QColor b)
{
- return QPalette::NColorRoles * colorGroup;
+ return QColor((a.red() + b.red()) / 2, (a.green() + b.green()) / 2,
+ (a.blue() + b.blue()) / 2, (a.alpha() + b.alpha()) / 2);
}
-static constexpr QPalette::ResolveMask bitPosition(QPalette::ColorGroup colorGroup,
- QPalette::ColorRole colorRole)
+/*!
+ \internal
+
+ Derive undefined \l PlaceholderText colors from \l Text colors.
+ Unless already set, PlaceholderText colors will be derived from their Text pendents.
+ Colors of existing PlaceHolderText brushes will not be replaced.
+
+ \a alpha represents the dim factor as a percentage. By default, a PlaceHolderText color
+ becomes a 50% more transparent version of the corresponding Text color.
+*/
+static void qt_placeholder_from_text(QPalette &pal, int alpha = 50)
{
- return colorRole + colorRoleOffset(colorGroup);
-}
+ if (alpha < 0 or alpha > 100)
+ return;
-static_assert(bitPosition(QPalette::ColorGroup(QPalette::NColorGroups - 1),
- QPalette::ColorRole(QPalette::NColorRoles - 1))
- < sizeof(QPalette::ResolveMask) * CHAR_BIT,
- "The resolve mask type is not wide enough to fit the entire bit mask.");
+ for (int cg = 0; cg < int(QPalette::NColorGroups); ++cg) {
+ const QPalette::ColorGroup group = QPalette::ColorGroup(cg);
-class QPalettePrivate {
-public:
- QPalettePrivate() : ref(1), ser_no(qt_palette_count++), detach_no(0) { }
- QAtomicInt ref;
- QBrush br[QPalette::NColorGroups][QPalette::NColorRoles];
- int ser_no;
- int detach_no;
-};
+ // skip if the brush has been set already
+ if (!pal.isBrushSet(group, QPalette::PlaceholderText)) {
+ QColor c = pal.color(group, QPalette::Text);
+ const int a = (c.alpha() * alpha) / 100;
+ c.setAlpha(a);
+ pal.setColor(group, QPalette::PlaceholderText, c);
+ }
+ }
+}
-static QColor qt_mix_colors(QColor a, QColor b)
+static void qt_ensure_default_accent_color(QPalette &pal)
{
- return QColor((a.red() + b.red()) / 2, (a.green() + b.green()) / 2,
- (a.blue() + b.blue()) / 2, (a.alpha() + b.alpha()) / 2);
+ // have a lighter/darker factor handy, depending on dark/light heuristics
+ const int lighter = pal.base().color().lightness() > pal.text().color().lightness() ? 130 : 70;
+
+ // Act only for color groups where no accent color is set
+ for (int i = 0; i < QPalette::NColorGroups; ++i) {
+ const QPalette::ColorGroup group = static_cast<QPalette::ColorGroup>(i);
+ if (!pal.isBrushSet(group, QPalette::Accent)) {
+ // Default to highlight if available, otherwise use a shade of base
+ const QBrush accentBrush = pal.isBrushSet(group, QPalette::Highlight)
+ ? pal.brush(group, QPalette::Highlight)
+ : pal.brush(group, QPalette::Base).color().lighter(lighter);
+ pal.setBrush(group, QPalette::Accent, accentBrush);
+ }
+ }
}
static void qt_palette_from_color(QPalette &pal, const QColor &button)
@@ -103,6 +90,9 @@ static void qt_palette_from_color(QPalette &pal, const QColor &button)
pal.setColorGroup(QPalette::Disabled, buttonBrushDark, buttonBrush, buttonBrushLight150,
buttonBrushDark, buttonBrushDark150, buttonBrushDark,
whiteBrush, buttonBrush, buttonBrush);
+
+ qt_placeholder_from_text(pal);
+ qt_ensure_default_accent_color(pal);
}
/*!
@@ -156,13 +146,6 @@ static void qt_palette_from_color(QPalette &pal, const QColor &button)
*/
/*!
- \fn const QBrush & QPalette::foreground() const
- \obsolete
-
- Use windowText() instead.
-*/
-
-/*!
\fn const QBrush & QPalette::windowText() const
Returns the window text (general foreground) brush of the
@@ -278,13 +261,6 @@ static void qt_palette_from_color(QPalette &pal, const QColor &button)
*/
/*!
- \fn const QBrush & QPalette::background() const
- \obsolete
-
- Use window() instead.
-*/
-
-/*!
\fn const QBrush & QPalette::window() const
Returns the window (general background) brush of the current
@@ -318,6 +294,15 @@ static void qt_palette_from_color(QPalette &pal, const QColor &button)
*/
/*!
+ \fn const QBrush & QPalette::accent() const
+ \since 6.6
+
+ Returns the accent brush of the current color group.
+
+ \sa ColorRole, brush()
+*/
+
+/*!
\fn const QBrush & QPalette::link() const
Returns the unvisited link text brush of the current color group.
@@ -449,12 +434,8 @@ static void qt_palette_from_color(QPalette &pal, const QColor &button)
\value Window A general background color.
- \value Background This value is obsolete. Use Window instead.
-
\value WindowText A general foreground color.
- \value Foreground This value is obsolete. Use WindowText instead.
-
\value Base Used mostly as the background color for text entry widgets,
but can also be used for other painting - such as the
background of combobox drop down lists and toolbar handles.
@@ -521,6 +502,13 @@ static void qt_palette_from_color(QPalette &pal, const QColor &button)
item. By default, the highlight color is
Qt::darkBlue.
+ \value [since 6.6] Accent
+ A color that typically contrasts or complements
+ Base, Window and Button colors. It usually represents
+ the users' choice of desktop personalisation.
+ Styling of interactive components is a typical use case.
+ Unless explicitly set, it defaults to Highlight.
+
\value HighlightedText A text color that contrasts with \c Highlight.
By default, the highlighted text color is Qt::white.
@@ -546,7 +534,10 @@ static void qt_palette_from_color(QPalette &pal, const QColor &button)
*/
/*!
- Constructs a palette object that uses the application's default palette.
+ Constructs an empty palette object with no color roles set.
+
+ When used as the palette of a QWidget the colors are resolved
+ as described by QWidget::setPalette().
\sa QApplication::setPalette(), QApplication::palette()
*/
@@ -559,10 +550,11 @@ QPalette::QPalette()
if (QGuiApplicationPrivate::app_pal) {
d = QGuiApplicationPrivate::app_pal->d;
d->ref.ref();
+ setResolveMask(0);
} else {
init();
qt_palette_from_color(*this, Qt::black);
- data.resolveMask = 0;
+ d->resolveMask = 0;
}
}
@@ -604,10 +596,14 @@ QPalette::QPalette(const QBrush &windowText, const QBrush &button,
init();
setColorGroup(All, windowText, button, light, dark, mid, text, bright_text,
base, window);
+
+ qt_placeholder_from_text(*this);
+ qt_ensure_default_accent_color(*this);
}
-/*!\obsolete
+/*!
+ \deprecated
Constructs a palette with the specified \a windowText, \a
window, \a light, \a dark, \a mid, \a text, and \a base colors.
@@ -658,6 +654,9 @@ QPalette::QPalette(const QColor &button, const QColor &window)
setColorGroup(Disabled, disabledForeground, buttonBrush, buttonBrushLight150,
buttonBrushDark, buttonBrushDark150, disabledForeground,
whiteBrush, baseBrush, windowBrush);
+
+ qt_placeholder_from_text(*this);
+ qt_ensure_default_accent_color(*this);
}
/*!
@@ -666,7 +665,7 @@ QPalette::QPalette(const QColor &button, const QColor &window)
This constructor is fast thanks to \l{implicit sharing}.
*/
QPalette::QPalette(const QPalette &p)
- : d(p.d), data(p.data)
+ : d(p.d), currentGroup(p.currentGroup)
{
d->ref.ref();
}
@@ -692,7 +691,8 @@ QPalette::~QPalette()
}
/*!\internal*/
-void QPalette::init() {
+void QPalette::init()
+{
d = new QPalettePrivate;
}
@@ -705,7 +705,7 @@ void QPalette::init() {
QPalette &QPalette::operator=(const QPalette &p)
{
p.d->ref.ref();
- data = p.data;
+ currentGroup = p.currentGroup;
if (d && !d->ref.deref())
delete d;
d = p.d;
@@ -725,7 +725,7 @@ QPalette &QPalette::operator=(const QPalette &p)
*/
QPalette::operator QVariant() const
{
- return QVariant(QMetaType::QPalette, this);
+ return QVariant::fromValue(*this);
}
/*!
@@ -748,15 +748,15 @@ QPalette::operator QVariant() const
const QBrush &QPalette::brush(ColorGroup gr, ColorRole cr) const
{
Q_ASSERT(cr < NColorRoles);
- if(gr >= (int)NColorGroups) {
- if(gr == Current) {
- gr = data.currentGroup;
+ if (gr >= (int)NColorGroups) {
+ if (gr == Current) {
+ gr = currentGroup;
} else {
qWarning("QPalette::brush: Unknown ColorGroup: %d", (int)gr);
gr = Active;
}
}
- return d->br[gr][cr];
+ return d->data->br[gr][cr];
}
/*!
@@ -788,18 +788,24 @@ void QPalette::setBrush(ColorGroup cg, ColorRole cr, const QBrush &b)
}
if (cg == Current) {
- cg = data.currentGroup;
+ cg = currentGroup;
} else if (cg >= NColorGroups) {
qWarning("QPalette::setBrush: Unknown ColorGroup: %d", cg);
cg = Active;
}
- if (d->br[cg][cr] != b) {
+ const auto newResolveMask = d->resolveMask | ResolveMask(1) << QPalettePrivate::bitPosition(cg, cr);
+ const auto valueChanged = d->data->br[cg][cr] != b;
+
+ if (valueChanged) {
+ detach();
+ d->data.detach();
+ d->data->br[cg][cr] = b;
+ } else if (d->resolveMask != newResolveMask) {
detach();
- d->br[cg][cr] = b;
}
- data.resolveMask |= ResolveMask(1) << bitPosition(cg, cr);
+ d->resolveMask = newResolveMask;
}
/*!
@@ -818,8 +824,12 @@ void QPalette::setBrush(ColorGroup cg, ColorRole cr, const QBrush &b)
*/
bool QPalette::isBrushSet(ColorGroup cg, ColorRole cr) const
{
+ // NoRole has no resolve mask and should never be set anyway
+ if (cr == NoRole)
+ return false;
+
if (cg == Current)
- cg = data.currentGroup;
+ cg = currentGroup;
if (cg >= NColorGroups) {
qWarning() << "Wrong color group:" << cg;
@@ -831,7 +841,7 @@ bool QPalette::isBrushSet(ColorGroup cg, ColorRole cr) const
return false;
}
- return data.resolveMask & (ResolveMask(1) << bitPosition(cg, cr));
+ return d->resolveMask & (ResolveMask(1) << QPalettePrivate::bitPosition(cg, cr));
}
/*!
@@ -840,16 +850,14 @@ bool QPalette::isBrushSet(ColorGroup cg, ColorRole cr) const
void QPalette::detach()
{
if (d->ref.loadRelaxed() != 1) {
- QPalettePrivate *x = new QPalettePrivate;
- for(int grp = 0; grp < (int)NColorGroups; grp++) {
- for(int role = 0; role < (int)NColorRoles; role++)
- x->br[grp][role] = d->br[grp][role];
- }
- if(!d->ref.deref())
+ QPalettePrivate *x = new QPalettePrivate(d->data);
+ x->resolveMask = d->resolveMask;
+ if (!d->ref.deref())
delete d;
d = x;
+ } else {
+ d->detach_no = ++QPalettePrivate::qt_palette_private_count;
}
- ++d->detach_no;
}
/*!
@@ -868,18 +876,24 @@ void QPalette::detach()
Returns \c true (usually quickly) if this palette is equal to \a p;
otherwise returns \c false (slowly).
- \note The current ColorGroup is not taken into account when
- comparing palettes
+ \note The following is not taken into account when comparing palettes:
+ \list
+ \li the \c current ColorGroup
+ \li ColorRole NoRole \since 6.6
+ \endlist
\sa operator!=()
*/
bool QPalette::operator==(const QPalette &p) const
{
- if (isCopyOf(p))
+ if (isCopyOf(p) || d->data == p.d->data)
return true;
for(int grp = 0; grp < (int)NColorGroups; grp++) {
for(int role = 0; role < (int)NColorRoles; role++) {
- if(d->br[grp][role] != p.d->br[grp][role])
+ // Dont't verify NoRole, because it has no resolve bit
+ if (role == NoRole)
+ continue;
+ if (d->data->br[grp][role] != p.d->data->br[grp][role])
return false;
}
}
@@ -894,26 +908,26 @@ bool QPalette::operator==(const QPalette &p) const
*/
bool QPalette::isEqual(QPalette::ColorGroup group1, QPalette::ColorGroup group2) const
{
- if(group1 >= (int)NColorGroups) {
- if(group1 == Current) {
- group1 = data.currentGroup;
+ if (group1 >= (int)NColorGroups) {
+ if (group1 == Current) {
+ group1 = currentGroup;
} else {
qWarning("QPalette::brush: Unknown ColorGroup(1): %d", (int)group1);
group1 = Active;
}
}
- if(group2 >= (int)NColorGroups) {
- if(group2 == Current) {
- group2 = data.currentGroup;
+ if (group2 >= (int)NColorGroups) {
+ if (group2 == Current) {
+ group2 = currentGroup;
} else {
qWarning("QPalette::brush: Unknown ColorGroup(2): %d", (int)group2);
group2 = Active;
}
}
- if(group1 == group2)
+ if (group1 == group2)
return true;
for(int role = 0; role < (int)NColorRoles; role++) {
- if(d->br[group1][role] != d->br[group2][role])
+ if (d->data->br[group1][role] != d->data->br[group2][role])
return false;
}
return true;
@@ -928,7 +942,18 @@ bool QPalette::isEqual(QPalette::ColorGroup group1, QPalette::ColorGroup group2)
*/
qint64 QPalette::cacheKey() const
{
- return (((qint64) d->ser_no) << 32) | ((qint64) (d->detach_no));
+ return (((qint64) d->data->ser_no) << 32) | ((qint64) (d->detach_no));
+}
+
+static constexpr QPalette::ResolveMask allResolveMask()
+{
+ QPalette::ResolveMask mask = {0};
+ for (int role = 0; role < int(QPalette::NColorRoles); ++role) {
+ for (int grp = 0; grp < int(QPalette::NColorGroups); ++grp) {
+ mask |= (QPalette::ResolveMask(1) << QPalettePrivate::bitPosition(QPalette::ColorGroup(grp), QPalette::ColorRole(role)));
+ }
+ }
+ return mask;
}
/*!
@@ -937,44 +962,64 @@ qint64 QPalette::cacheKey() const
*/
QPalette QPalette::resolve(const QPalette &other) const
{
- if ((*this == other && data.resolveMask == other.data.resolveMask)
- || data.resolveMask == 0) {
+ if ((*this == other && d->resolveMask == other.d->resolveMask)
+ || d->resolveMask == 0) {
QPalette o = other;
- o.data.resolveMask = data.resolveMask;
+ o.setResolveMask(d->resolveMask);
return o;
}
+ if (d->resolveMask == allResolveMask())
+ return *this;
+
QPalette palette(*this);
palette.detach();
for (int role = 0; role < int(NColorRoles); ++role) {
+ // Don't resolve NoRole, its bits are needed for Accent (see bitPosition)
+ if (role == NoRole)
+ continue;
+
for (int grp = 0; grp < int(NColorGroups); ++grp) {
- if (!(data.resolveMask & (ResolveMask(1) << bitPosition(ColorGroup(grp), ColorRole(role))))) {
- palette.d->br[grp][role] = other.d->br[grp][role];
+ if (!(d->resolveMask & (ResolveMask(1) << QPalettePrivate::bitPosition(ColorGroup(grp), ColorRole(role))))) {
+ palette.d->data.detach();
+ palette.d->data->br[grp][role] = other.d->data->br[grp][role];
}
}
}
- palette.data.resolveMask |= other.data.resolveMask;
+ palette.d->resolveMask |= other.d->resolveMask;
return palette;
}
/*!
- \fn uint QPalette::resolve() const
\internal
*/
+QPalette::ResolveMask QPalette::resolveMask() const
+{
+ return d->resolveMask;
+}
/*!
- \typedef ResolveMaskType
\internal
- */
+*/
+void QPalette::setResolveMask(QPalette::ResolveMask mask)
+{
+ if (mask == d->resolveMask)
+ return;
+
+ detach();
+ d->resolveMask = mask;
+}
/*!
- \fn void QPalette::resolve(ResolveMaskType mask)
+ \typedef ResolveMask
\internal
-*/
+ A bit mask that stores which colors the palette instance explicitly defines,
+ and which ones are inherited from a parent.
+*/
/*****************************************************************************
QPalette stream functions
@@ -1001,7 +1046,7 @@ QDataStream &operator<<(QDataStream &s, const QPalette &p)
if (s.version() == 1) {
// Qt 1.x
for (int i = 0; i < NumOldRoles; ++i)
- s << p.d->br[grp][oldRoles[i]].color();
+ s << p.d->data->br[grp][oldRoles[i]].color();
} else {
int max = (int)QPalette::NColorRoles;
if (s.version() <= QDataStream::Qt_2_1)
@@ -1010,8 +1055,11 @@ QDataStream &operator<<(QDataStream &s, const QPalette &p)
max = QPalette::AlternateBase + 1;
else if (s.version() <= QDataStream::Qt_5_11)
max = QPalette::ToolTipText + 1;
+ else if (s.version() <= QDataStream::Qt_6_5)
+ max = QPalette::PlaceholderText + 1;
+
for (int r = 0; r < max; r++)
- s << p.d->br[grp][r];
+ s << p.d->data->br[grp][r];
}
}
return s;
@@ -1037,7 +1085,7 @@ static void readV1ColorGroup(QDataStream &s, QPalette &pal, QPalette::ColorGroup
QDataStream &operator>>(QDataStream &s, QPalette &p)
{
- if(s.version() == 1) {
+ if (s.version() == 1) {
p = QPalette();
readV1ColorGroup(s, p, QPalette::Active);
readV1ColorGroup(s, p, QPalette::Disabled);
@@ -1053,15 +1101,25 @@ QDataStream &operator>>(QDataStream &s, QPalette &p)
} else if (s.version() <= QDataStream::Qt_5_11) {
p = QPalette();
max = QPalette::ToolTipText + 1;
+ } else if (s.version() <= QDataStream::Qt_6_5) {
+ p = QPalette();
+ max = QPalette::PlaceholderText + 1;
}
+
QBrush tmp;
for(int grp = 0; grp < (int)QPalette::NColorGroups; ++grp) {
+ const QPalette::ColorGroup group = static_cast<QPalette::ColorGroup>(grp);
for(int role = 0; role < max; ++role) {
s >> tmp;
- p.setBrush((QPalette::ColorGroup)grp, (QPalette::ColorRole)role, tmp);
+ p.setBrush(group, (QPalette::ColorRole)role, tmp);
}
+
+ // Accent defaults to Highlight for stream versions that don't have it.
+ if (s.version() < QDataStream::Qt_6_6)
+ p.setBrush(group, QPalette::Accent, p.brush(group, QPalette::Highlight));
}
+
}
return s;
}
@@ -1108,10 +1166,10 @@ void QPalette::setColorGroup(ColorGroup cg, const QBrush &windowText, const QBru
for (int cr = Highlight; cr <= LinkVisited; ++cr) {
if (cg == All) {
for (int group = Active; group < NColorGroups; ++group) {
- data.resolveMask &= ~(ResolveMask(1) << bitPosition(ColorGroup(group), ColorRole(cr)));
+ d->resolveMask &= ~(ResolveMask(1) << QPalettePrivate::bitPosition(ColorGroup(group), ColorRole(cr)));
}
} else {
- data.resolveMask &= ~(ResolveMask(1) << bitPosition(ColorGroup(cg), ColorRole(cr)));
+ d->resolveMask &= ~(ResolveMask(1) << QPalettePrivate::bitPosition(ColorGroup(cg), ColorRole(cr)));
}
}
}
@@ -1166,47 +1224,6 @@ void QPalette::setColorGroup(ColorGroup cg, const QBrush &foreground, const QBru
setBrush(cg, ToolTipText, toolTipText);
}
-Q_GUI_EXPORT QPalette qt_fusionPalette()
-{
- QColor backGround(239, 239, 239);
- QColor light = backGround.lighter(150);
- QColor mid(backGround.darker(130));
- QColor midLight = mid.lighter(110);
- QColor base = Qt::white;
- QColor disabledBase(backGround);
- QColor dark = backGround.darker(150);
- QColor darkDisabled = QColor(209, 209, 209).darker(110);
- QColor text = Qt::black;
- QColor hightlightedText = Qt::white;
- QColor disabledText = QColor(190, 190, 190);
- QColor button = backGround;
- QColor shadow = dark.darker(135);
- QColor disabledShadow = shadow.lighter(150);
- QColor placeholder = text;
- placeholder.setAlpha(128);
-
- QPalette fusionPalette(Qt::black,backGround,light,dark,mid,text,base);
- fusionPalette.setBrush(QPalette::Midlight, midLight);
- fusionPalette.setBrush(QPalette::Button, button);
- fusionPalette.setBrush(QPalette::Shadow, shadow);
- fusionPalette.setBrush(QPalette::HighlightedText, hightlightedText);
-
- fusionPalette.setBrush(QPalette::Disabled, QPalette::Text, disabledText);
- fusionPalette.setBrush(QPalette::Disabled, QPalette::WindowText, disabledText);
- fusionPalette.setBrush(QPalette::Disabled, QPalette::ButtonText, disabledText);
- fusionPalette.setBrush(QPalette::Disabled, QPalette::Base, disabledBase);
- fusionPalette.setBrush(QPalette::Disabled, QPalette::Dark, darkDisabled);
- fusionPalette.setBrush(QPalette::Disabled, QPalette::Shadow, disabledShadow);
-
- fusionPalette.setBrush(QPalette::Active, QPalette::Highlight, QColor(48, 140, 198));
- fusionPalette.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(48, 140, 198));
- fusionPalette.setBrush(QPalette::Disabled, QPalette::Highlight, QColor(145, 145, 145));
-
- fusionPalette.setBrush(QPalette::PlaceholderText, placeholder);
-
- return fusionPalette;
-}
-
#ifndef QT_NO_DEBUG_STREAM
static QString groupsToString(const QPalette &p, QPalette::ColorRole cr)
{
@@ -1218,8 +1235,8 @@ static QString groupsToString(const QPalette &p, QPalette::ColorRole cr)
if (p.isBrushSet(cg, cr)) {
const auto &color = p.color(cg, cr);
- groupString += QString::fromUtf8(groupEnum.valueToKey(cg)) + QLatin1Char(':') +
- color.name(QColor::HexArgb) + QLatin1Char(',');
+ groupString += QString::fromUtf8(groupEnum.valueToKey(cg)) + u':' +
+ color.name(QColor::HexArgb) + u',';
}
}
groupString.chop(1);
@@ -1250,7 +1267,7 @@ QDebug operator<<(QDebug dbg, const QPalette &p)
QDebugStateSaver saver(dbg);
dbg.nospace();
- dbg << "QPalette(resolve=" << Qt::hex << Qt::showbase << p.resolve();
+ dbg << "QPalette(resolve=" << Qt::hex << Qt::showbase << p.resolveMask();
auto roleString = rolesToString(p);
if (!roleString.isEmpty())
@@ -1263,3 +1280,5 @@ QDebug operator<<(QDebug dbg, const QPalette &p)
#endif
QT_END_NAMESPACE
+
+#include "moc_qpalette.cpp"
diff --git a/src/gui/kernel/qpalette.h b/src/gui/kernel/qpalette.h
index 1f0f6725d8..a6162e1090 100644
--- a/src/gui/kernel/qpalette.h
+++ b/src/gui/kernel/qpalette.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPALETTE_H
#define QPALETTE_H
@@ -68,22 +32,20 @@ public:
~QPalette();
QPalette &operator=(const QPalette &palette);
QPalette(QPalette &&other) noexcept
- : d(other.d), data(other.data)
- { other.d = nullptr; }
- inline QPalette &operator=(QPalette &&other) noexcept
- {
- swap(other); return *this;
- }
+ : d(std::exchange(other.d, nullptr)), currentGroup(other.currentGroup)
+ {}
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPalette)
void swap(QPalette &other) noexcept
{
- qSwap(data, other.data);
- qSwap(d, other.d);
+ std::swap(currentGroup, other.currentGroup);
+ qt_ptr_swap(d, other.d);
}
operator QVariant() const;
// Do not change the order, the serialization format depends on it
+ // Ensure these values are kept in sync with QQuickColorGroup's properties.
enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = Active };
Q_ENUM(ColorGroup)
enum ColorRole { WindowText, Button, Light, Midlight, Dark, Mid,
@@ -94,16 +56,13 @@ public:
NoRole,
ToolTipBase, ToolTipText,
PlaceholderText,
- NColorRoles = PlaceholderText + 1,
-#if QT_DEPRECATED_SINCE(5, 13)
- Foreground Q_DECL_ENUMERATOR_DEPRECATED_X("Use QPalette::WindowText instead") = WindowText,
- Background Q_DECL_ENUMERATOR_DEPRECATED_X("Use QPalette::Window instead") = Window
-#endif
+ Accent,
+ NColorRoles = Accent + 1,
};
Q_ENUM(ColorRole)
- inline ColorGroup currentColorGroup() const { return data.currentGroup; }
- inline void setCurrentColorGroup(ColorGroup cg) { data.currentGroup = cg; }
+ inline ColorGroup currentColorGroup() const { return currentGroup; }
+ inline void setCurrentColorGroup(ColorGroup cg) { currentGroup = cg; }
inline const QColor &color(ColorGroup cg, ColorRole cr) const
{ return brush(cg, cr).color(); }
@@ -141,12 +100,7 @@ public:
inline const QBrush &link() const { return brush(Link); }
inline const QBrush &linkVisited() const { return brush(LinkVisited); }
inline const QBrush &placeholderText() const { return brush(PlaceholderText); }
-#if QT_DEPRECATED_SINCE(5, 13)
- QT_DEPRECATED_X("Use QPalette::windowText() instead")
- inline const QBrush &foreground() const { return windowText(); }
- QT_DEPRECATED_X("Use QPalette::window() instead")
- inline const QBrush &background() const { return window(); }
-#endif
+ inline const QBrush &accent() const { return brush(Accent); }
bool operator==(const QPalette &p) const;
inline bool operator!=(const QPalette &p) const { return !(operator==(p)); }
@@ -157,8 +111,8 @@ public:
QPalette resolve(const QPalette &other) const;
using ResolveMask = quint64;
- inline ResolveMask resolve() const { return data.resolveMask; }
- inline void resolve(ResolveMask mask) { data.resolveMask = mask; }
+ ResolveMask resolveMask() const;
+ void setResolveMask(ResolveMask mask);
private:
void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
@@ -182,11 +136,7 @@ private:
void detach();
QPalettePrivate *d;
- struct Data {
- ResolveMask resolveMask{0};
- ColorGroup currentGroup{Active};
- };
- Data data;
+ ColorGroup currentGroup{Active};
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p);
};
diff --git a/src/gui/kernel/qpalette_p.h b/src/gui/kernel/qpalette_p.h
new file mode 100644
index 0000000000..ce7c30d66d
--- /dev/null
+++ b/src/gui/kernel/qpalette_p.h
@@ -0,0 +1,77 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPALETTE_P_H
+#define QPALETTE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qpalette.h"
+
+QT_BEGIN_NAMESPACE
+
+class Q_GUI_EXPORT QPalettePrivate
+{
+public:
+ class Data : public QSharedData {
+ public:
+ // Every instance of Data has to have a unique serial number, even
+ // if it gets created by copying another - we wouldn't create a copy
+ // in the first place if the serial number should be the same!
+ Data(const Data &other)
+ : QSharedData(other)
+ {
+ for (int grp = 0; grp < int(QPalette::NColorGroups); grp++) {
+ for (int role = 0; role < int(QPalette::NColorRoles); role++)
+ br[grp][role] = other.br[grp][role];
+ }
+ }
+ Data() = default;
+
+ QBrush br[QPalette::NColorGroups][QPalette::NColorRoles];
+ const int ser_no = qt_palette_count++;
+ };
+
+ QPalettePrivate(const QExplicitlySharedDataPointer<Data> &data)
+ : ref(1), data(data)
+ { }
+ QPalettePrivate()
+ : QPalettePrivate(QExplicitlySharedDataPointer<Data>(new Data))
+ { }
+
+ static constexpr QPalette::ResolveMask colorRoleOffset(QPalette::ColorGroup colorGroup)
+ {
+ // Exclude NoRole; that bit is used for Accent
+ return (qToUnderlying(QPalette::NColorRoles) - 1) * qToUnderlying(colorGroup);
+ }
+
+ static constexpr QPalette::ResolveMask bitPosition(QPalette::ColorGroup colorGroup,
+ QPalette::ColorRole colorRole)
+ {
+ // Map Accent into NoRole for resolving purposes
+ if (colorRole == QPalette::Accent)
+ colorRole = QPalette::NoRole;
+
+ return colorRole + colorRoleOffset(colorGroup);
+ }
+
+ QAtomicInt ref;
+ QPalette::ResolveMask resolveMask = {0};
+ static inline int qt_palette_count = 0;
+ static inline int qt_palette_private_count = 0;
+ int detach_no = ++qt_palette_private_count;
+ QExplicitlySharedDataPointer<Data> data;
+};
+
+QT_END_NAMESPACE
+
+#endif // QPALETTE_P_H
diff --git a/src/gui/kernel/qpixelformat.cpp b/src/gui/kernel/qpixelformat.cpp
index 7a47dd472c..e05192f0b2 100644
--- a/src/gui/kernel/qpixelformat.cpp
+++ b/src/gui/kernel/qpixelformat.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qpixelformat.h"
@@ -186,7 +150,7 @@ QT_BEGIN_NAMESPACE
\enum QPixelFormat::YUVLayout
YUV is not represented by describing the size of the color channels. This is
- because YUV often use macro pixels, making the concept of sperate color channels
+ because YUV often use macro pixels, making the concept of separate color channels
invalid. Instead the different YUV layouts are described with this enum.
\value YUV444
diff --git a/src/gui/kernel/qpixelformat.h b/src/gui/kernel/qpixelformat.h
index a0bb300c12..4954a6cd94 100644
--- a/src/gui/kernel/qpixelformat.h
+++ b/src/gui/kernel/qpixelformat.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPIXELFORMAT_H
#define QPIXELFORMAT_H
@@ -76,28 +40,28 @@ class QPixelFormat
// work around bug in old clang versions: when building webkit
// with XCode 4.6 and older this fails compilation, thus cast to int
FirstField = ModelField + int(ModelFieldWidth),
- SecondField = FirstField + FirstFieldWidth,
- ThirdField = SecondField + SecondFieldWidth,
- FourthField = ThirdField + ThirdFieldWidth,
- FifthField = FourthField + FourthFieldWidth,
- AlphaField = FifthField + FifthFieldWidth,
- AlphaUsageField = AlphaField + AlphaFieldWidth,
- AlphaPositionField = AlphaUsageField + AlphaUsageFieldWidth,
- PremulField = AlphaPositionField + AlphaPositionFieldWidth,
- TypeInterpretationField = PremulField + PremulFieldWidth,
- ByteOrderField = TypeInterpretationField + TypeInterpretationFieldWidth,
- SubEnumField = ByteOrderField + ByteOrderFieldWidth,
- UnusedField = SubEnumField + SubEnumFieldWidth,
-
- TotalFieldWidthByOffsets = UnusedField + UnusedFieldWidth
+ SecondField = FirstField + int(FirstFieldWidth),
+ ThirdField = SecondField + int(SecondFieldWidth),
+ FourthField = ThirdField + int(ThirdFieldWidth),
+ FifthField = FourthField + int(FourthFieldWidth),
+ AlphaField = FifthField + int(FifthFieldWidth),
+ AlphaUsageField = AlphaField + int(AlphaFieldWidth),
+ AlphaPositionField = AlphaUsageField + int(AlphaUsageFieldWidth),
+ PremulField = AlphaPositionField + int(AlphaPositionFieldWidth),
+ TypeInterpretationField = PremulField + int(PremulFieldWidth),
+ ByteOrderField = TypeInterpretationField + int(TypeInterpretationFieldWidth),
+ SubEnumField = ByteOrderField + int(ByteOrderFieldWidth),
+ UnusedField = SubEnumField + int(SubEnumFieldWidth),
+
+ TotalFieldWidthByOffsets = UnusedField + int(UnusedFieldWidth)
};
static_assert(uint(TotalFieldWidthByWidths) == uint(TotalFieldWidthByOffsets));
static_assert(uint(TotalFieldWidthByWidths) == 8 * sizeof(quint64));
- Q_DECL_CONSTEXPR inline uchar get(Field offset, FieldWidth width) const noexcept
+ constexpr inline uchar get(Field offset, FieldWidth width) const noexcept
{ return uchar((data >> uint(offset)) & ((Q_UINT64_C(1) << uint(width)) - Q_UINT64_C(1))); }
- Q_DECL_CONSTEXPR static inline quint64 set(Field offset, FieldWidth width, uchar value)
+ constexpr static inline quint64 set(Field offset, FieldWidth width, uchar value)
{ return (quint64(value) & ((Q_UINT64_C(1) << uint(width)) - Q_UINT64_C(1))) << uint(offset); }
public:
@@ -160,8 +124,8 @@ public:
CurrentSystemEndian
};
- Q_DECL_CONSTEXPR inline QPixelFormat() noexcept : data(0) {}
- Q_DECL_CONSTEXPR inline QPixelFormat(ColorModel colorModel,
+ constexpr inline QPixelFormat() noexcept : data(0) {}
+ constexpr inline QPixelFormat(ColorModel colorModel,
uchar firstSize,
uchar secondSize,
uchar thirdSize,
@@ -175,57 +139,57 @@ public:
ByteOrder byteOrder = CurrentSystemEndian,
uchar subEnum = 0) noexcept;
- Q_DECL_CONSTEXPR inline ColorModel colorModel() const noexcept { return ColorModel(get(ModelField, ModelFieldWidth)); }
- Q_DECL_CONSTEXPR inline uchar channelCount() const noexcept { return (get(FirstField, FirstFieldWidth) > 0) +
+ constexpr inline ColorModel colorModel() const noexcept { return ColorModel(get(ModelField, ModelFieldWidth)); }
+ constexpr inline uchar channelCount() const noexcept { return (get(FirstField, FirstFieldWidth) > 0) +
(get(SecondField, SecondFieldWidth) > 0) +
(get(ThirdField, ThirdFieldWidth) > 0) +
(get(FourthField, FourthFieldWidth) > 0) +
(get(FifthField, FifthFieldWidth) > 0) +
(get(AlphaField, AlphaFieldWidth) > 0); }
- Q_DECL_CONSTEXPR inline uchar redSize() const noexcept { return get(FirstField, FirstFieldWidth); }
- Q_DECL_CONSTEXPR inline uchar greenSize() const noexcept { return get(SecondField, SecondFieldWidth); }
- Q_DECL_CONSTEXPR inline uchar blueSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
+ constexpr inline uchar redSize() const noexcept { return get(FirstField, FirstFieldWidth); }
+ constexpr inline uchar greenSize() const noexcept { return get(SecondField, SecondFieldWidth); }
+ constexpr inline uchar blueSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
- Q_DECL_CONSTEXPR inline uchar cyanSize() const noexcept { return get(FirstField, FirstFieldWidth); }
- Q_DECL_CONSTEXPR inline uchar magentaSize() const noexcept { return get(SecondField, SecondFieldWidth); }
- Q_DECL_CONSTEXPR inline uchar yellowSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
- Q_DECL_CONSTEXPR inline uchar blackSize() const noexcept { return get(FourthField, FourthFieldWidth); }
+ constexpr inline uchar cyanSize() const noexcept { return get(FirstField, FirstFieldWidth); }
+ constexpr inline uchar magentaSize() const noexcept { return get(SecondField, SecondFieldWidth); }
+ constexpr inline uchar yellowSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
+ constexpr inline uchar blackSize() const noexcept { return get(FourthField, FourthFieldWidth); }
- Q_DECL_CONSTEXPR inline uchar hueSize() const noexcept { return get(FirstField, FirstFieldWidth); }
- Q_DECL_CONSTEXPR inline uchar saturationSize() const noexcept { return get(SecondField, SecondFieldWidth); }
- Q_DECL_CONSTEXPR inline uchar lightnessSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
- Q_DECL_CONSTEXPR inline uchar brightnessSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
+ constexpr inline uchar hueSize() const noexcept { return get(FirstField, FirstFieldWidth); }
+ constexpr inline uchar saturationSize() const noexcept { return get(SecondField, SecondFieldWidth); }
+ constexpr inline uchar lightnessSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
+ constexpr inline uchar brightnessSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
- Q_DECL_CONSTEXPR inline uchar alphaSize() const noexcept { return get(AlphaField, AlphaFieldWidth); }
+ constexpr inline uchar alphaSize() const noexcept { return get(AlphaField, AlphaFieldWidth); }
- Q_DECL_CONSTEXPR inline uchar bitsPerPixel() const noexcept { return get(FirstField, FirstFieldWidth) +
+ constexpr inline uchar bitsPerPixel() const noexcept { return get(FirstField, FirstFieldWidth) +
get(SecondField, SecondFieldWidth) +
get(ThirdField, ThirdFieldWidth) +
get(FourthField, FourthFieldWidth) +
get(FifthField, FifthFieldWidth) +
get(AlphaField, AlphaFieldWidth); }
- Q_DECL_CONSTEXPR inline AlphaUsage alphaUsage() const noexcept { return AlphaUsage(get(AlphaUsageField, AlphaUsageFieldWidth)); }
- Q_DECL_CONSTEXPR inline AlphaPosition alphaPosition() const noexcept { return AlphaPosition(get(AlphaPositionField, AlphaPositionFieldWidth)); }
- Q_DECL_CONSTEXPR inline AlphaPremultiplied premultiplied() const noexcept { return AlphaPremultiplied(get(PremulField, PremulFieldWidth)); }
- Q_DECL_CONSTEXPR inline TypeInterpretation typeInterpretation() const noexcept { return TypeInterpretation(get(TypeInterpretationField, TypeInterpretationFieldWidth)); }
- Q_DECL_CONSTEXPR inline ByteOrder byteOrder() const noexcept { return ByteOrder(get(ByteOrderField, ByteOrderFieldWidth)); }
+ constexpr inline AlphaUsage alphaUsage() const noexcept { return AlphaUsage(get(AlphaUsageField, AlphaUsageFieldWidth)); }
+ constexpr inline AlphaPosition alphaPosition() const noexcept { return AlphaPosition(get(AlphaPositionField, AlphaPositionFieldWidth)); }
+ constexpr inline AlphaPremultiplied premultiplied() const noexcept { return AlphaPremultiplied(get(PremulField, PremulFieldWidth)); }
+ constexpr inline TypeInterpretation typeInterpretation() const noexcept { return TypeInterpretation(get(TypeInterpretationField, TypeInterpretationFieldWidth)); }
+ constexpr inline ByteOrder byteOrder() const noexcept { return ByteOrder(get(ByteOrderField, ByteOrderFieldWidth)); }
- Q_DECL_CONSTEXPR inline YUVLayout yuvLayout() const noexcept { return YUVLayout(get(SubEnumField, SubEnumFieldWidth)); }
- Q_DECL_CONSTEXPR inline uchar subEnum() const noexcept { return get(SubEnumField, SubEnumFieldWidth); }
+ constexpr inline YUVLayout yuvLayout() const noexcept { return YUVLayout(get(SubEnumField, SubEnumFieldWidth)); }
+ constexpr inline uchar subEnum() const noexcept { return get(SubEnumField, SubEnumFieldWidth); }
private:
- Q_DECL_CONSTEXPR static inline ByteOrder resolveByteOrder(ByteOrder bo)
+ constexpr static inline ByteOrder resolveByteOrder(ByteOrder bo)
{ return bo == CurrentSystemEndian ? Q_BYTE_ORDER == Q_LITTLE_ENDIAN ? LittleEndian : BigEndian : bo ; }
private:
quint64 data;
- friend Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline bool operator==(QPixelFormat fmt1, QPixelFormat fmt2)
+ friend Q_DECL_CONST_FUNCTION constexpr inline bool operator==(QPixelFormat fmt1, QPixelFormat fmt2)
{ return fmt1.data == fmt2.data; }
- friend Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline bool operator!=(QPixelFormat fmt1, QPixelFormat fmt2)
+ friend Q_DECL_CONST_FUNCTION constexpr inline bool operator!=(QPixelFormat fmt1, QPixelFormat fmt2)
{ return !(fmt1 == fmt2); }
};
static_assert(sizeof(QPixelFormat) == sizeof(quint64));
@@ -242,20 +206,19 @@ namespace QtPrivate {
QPixelFormat::ByteOrder byteOrder);
}
-Q_DECL_CONSTEXPR
-QPixelFormat::QPixelFormat(ColorModel mdl,
- uchar firstSize,
- uchar secondSize,
- uchar thirdSize,
- uchar fourthSize,
- uchar fifthSize,
- uchar alfa,
- AlphaUsage usage,
- AlphaPosition position,
- AlphaPremultiplied premult,
- TypeInterpretation typeInterp,
- ByteOrder b_order,
- uchar s_enum) noexcept
+constexpr QPixelFormat::QPixelFormat(ColorModel mdl,
+ uchar firstSize,
+ uchar secondSize,
+ uchar thirdSize,
+ uchar fourthSize,
+ uchar fifthSize,
+ uchar alfa,
+ AlphaUsage usage,
+ AlphaPosition position,
+ AlphaPremultiplied premult,
+ TypeInterpretation typeInterp,
+ ByteOrder b_order,
+ uchar s_enum) noexcept
: data(set(ModelField, ModelFieldWidth, uchar(mdl)) |
set(FirstField, FirstFieldWidth, firstSize) |
set(SecondField, SecondFieldWidth, secondSize) |
@@ -273,14 +236,14 @@ QPixelFormat::QPixelFormat(ColorModel mdl,
{
}
-Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatRgba(uchar red,
- uchar green,
- uchar blue,
- uchar alfa,
- QPixelFormat::AlphaUsage usage,
- QPixelFormat::AlphaPosition position,
- QPixelFormat::AlphaPremultiplied pmul=QPixelFormat::NotPremultiplied,
- QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
+constexpr inline QPixelFormat qPixelFormatRgba(uchar red,
+ uchar green,
+ uchar blue,
+ uchar alfa,
+ QPixelFormat::AlphaUsage usage,
+ QPixelFormat::AlphaPosition position,
+ QPixelFormat::AlphaPremultiplied pmul=QPixelFormat::NotPremultiplied,
+ QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
{
return QPixelFormat(QPixelFormat::RGB,
red,
@@ -295,8 +258,8 @@ Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatRgba(uchar red,
typeInt);
}
-Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatGrayscale(uchar channelSize,
- QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
+constexpr inline QPixelFormat qPixelFormatGrayscale(uchar channelSize,
+ QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
{
return QPixelFormat(QPixelFormat::Grayscale,
channelSize,
@@ -311,8 +274,8 @@ Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatGrayscale(uchar channelSize,
typeInt);
}
-Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatAlpha(uchar channelSize,
- QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
+constexpr inline QPixelFormat qPixelFormatAlpha(uchar channelSize,
+ QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
{
return QPixelFormat(QPixelFormat::Alpha,
0,
@@ -327,11 +290,11 @@ Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatAlpha(uchar channelSize,
typeInt);
}
-Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatCmyk(uchar channelSize,
- uchar alfa=0,
- QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha,
- QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning,
- QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
+constexpr inline QPixelFormat qPixelFormatCmyk(uchar channelSize,
+ uchar alfa=0,
+ QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha,
+ QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning,
+ QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
{
return QPixelFormat(QPixelFormat::CMYK,
channelSize,
@@ -346,11 +309,11 @@ Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatCmyk(uchar channelSize,
typeInt);
}
-Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatHsl(uchar channelSize,
- uchar alfa=0,
- QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha,
- QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning,
- QPixelFormat::TypeInterpretation typeInt=QPixelFormat::FloatingPoint) noexcept
+constexpr inline QPixelFormat qPixelFormatHsl(uchar channelSize,
+ uchar alfa=0,
+ QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha,
+ QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning,
+ QPixelFormat::TypeInterpretation typeInt=QPixelFormat::FloatingPoint) noexcept
{
return QPixelFormat(QPixelFormat::HSL,
channelSize,
@@ -365,11 +328,11 @@ Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatHsl(uchar channelSize,
typeInt);
}
-Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatHsv(uchar channelSize,
- uchar alfa=0,
- QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha,
- QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning,
- QPixelFormat::TypeInterpretation typeInt=QPixelFormat::FloatingPoint) noexcept
+constexpr inline QPixelFormat qPixelFormatHsv(uchar channelSize,
+ uchar alfa=0,
+ QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha,
+ QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning,
+ QPixelFormat::TypeInterpretation typeInt=QPixelFormat::FloatingPoint) noexcept
{
return QPixelFormat(QPixelFormat::HSV,
channelSize,
diff --git a/src/gui/kernel/qplatformclipboard.cpp b/src/gui/kernel/qplatformclipboard.cpp
index 34c94dca3b..7321b5065d 100644
--- a/src/gui/kernel/qplatformclipboard.cpp
+++ b/src/gui/kernel/qplatformclipboard.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformclipboard.h"
#ifndef QT_NO_CLIPBOARD
diff --git a/src/gui/kernel/qplatformclipboard.h b/src/gui/kernel/qplatformclipboard.h
index 3220201720..51b7c51abd 100644
--- a/src/gui/kernel/qplatformclipboard.h
+++ b/src/gui/kernel/qplatformclipboard.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMCLIPBOARD_H
#define QPLATFORMCLIPBOARD_H
diff --git a/src/gui/kernel/qplatformcursor.cpp b/src/gui/kernel/qplatformcursor.cpp
index 1330b5bf31..0e2fb9eba1 100644
--- a/src/gui/kernel/qplatformcursor.cpp
+++ b/src/gui/kernel/qplatformcursor.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformcursor.h"
#include <QPainter>
@@ -619,7 +583,7 @@ void QPlatformCursorImage::set(const uchar *data, const uchar *mask,
int p = 0;
int d, m;
- int x = -1, w = 0;
+ int x = -1;
uchar *cursor_data = cursorImage.bits();
qsizetype bpl = cursorImage.bytesPerLine();
@@ -641,15 +605,11 @@ void QPlatformCursorImage::set(const uchar *data, const uchar *mask,
x = j*8+b;
else if (x >= 0 && !m) {
x = -1;
- w = 0;
}
- if (m)
- w++;
}
}
if (x >= 0) {
x = -1;
- w = 0;
}
cursor_data += bpl;
}
diff --git a/src/gui/kernel/qplatformcursor.h b/src/gui/kernel/qplatformcursor.h
index f3871d8780..56216d475b 100644
--- a/src/gui/kernel/qplatformcursor.h
+++ b/src/gui/kernel/qplatformcursor.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMCURSOR_H
#define QPLATFORMCURSOR_H
diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp
index 443f5d2552..93de7933d4 100644
--- a/src/gui/kernel/qplatformdialoghelper.cpp
+++ b/src/gui/kernel/qplatformdialoghelper.cpp
@@ -1,61 +1,33 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformdialoghelper.h"
#include <QtCore/QCoreApplication>
-#include <QtCore/QVariant>
+#include <QtCore/QList>
#if QT_CONFIG(regularexpression)
#include <QtCore/QRegularExpression>
#endif
-#include <QtCore/QSharedData>
#if QT_CONFIG(settings)
#include <QtCore/QSettings>
#endif
+#include <QtCore/QSharedData>
#include <QtCore/QUrl>
-#include <QtCore/QVector>
+#include <QtCore/QVariant>
#include <QtGui/QColor>
+#include <QtGui/QPixmap>
#include <algorithm>
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
+QT_IMPL_METATYPE_EXTERN_TAGGED(QPlatformDialogHelper::StandardButton,
+ QPlatformDialogHelper__StandardButton)
+QT_IMPL_METATYPE_EXTERN_TAGGED(QPlatformDialogHelper::ButtonRole,
+ QPlatformDialogHelper__ButtonRole)
+
/*!
\class QPlatformDialogHelper
\since 5.0
@@ -107,11 +79,6 @@ static const int buttonRoleLayouts[2][6][14] =
QPlatformDialogHelper::AcceptRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::NoRole | QPlatformDialogHelper::Reverse,
QPlatformDialogHelper::YesRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::EOL },
- // MacModelessLayout
- { QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::Stretch,
- QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL,
- QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL },
-
// AndroidLayout (neutral, stretch, dismissive, affirmative)
// https://material.io/guidelines/components/dialogs.html#dialogs-specs
{ QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ActionRole,
@@ -143,11 +110,6 @@ static const int buttonRoleLayouts[2][6][14] =
QPlatformDialogHelper::AlternateRole, QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::Stretch,
QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL },
- // MacModelessLayout
- { QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::Stretch,
- QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL,
- QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL },
-
// AndroidLayout
// (affirmative
// dismissive
@@ -304,7 +266,7 @@ void QColorDialogStaticData::readSettings()
#if QT_CONFIG(settings)
const QSettings settings(QSettings::UserScope, QStringLiteral("QtProject"));
for (int i = 0; i < int(CustomColorCount); ++i) {
- const QVariant v = settings.value(QLatin1String("Qt/customColors/") + QString::number(i));
+ const QVariant v = settings.value("Qt/customColors/"_L1 + QString::number(i));
if (v.isValid())
customRgb[i] = v.toUInt();
}
@@ -318,7 +280,7 @@ void QColorDialogStaticData::writeSettings() const
const_cast<QColorDialogStaticData*>(this)->customSet = false;
QSettings settings(QSettings::UserScope, QStringLiteral("QtProject"));
for (int i = 0; i < int(CustomColorCount); ++i)
- settings.setValue(QLatin1String("Qt/customColors/") + QString::number(i), customRgb[i]);
+ settings.setValue("Qt/customColors/"_L1 + QString::number(i), customRgb[i]);
}
#endif
}
@@ -653,7 +615,7 @@ QStringList QFileDialogOptions::mimeTypeFilters() const
void QFileDialogOptions::setDefaultSuffix(const QString &suffix)
{
d->defaultSuffix = suffix;
- if (d->defaultSuffix.size() > 1 && d->defaultSuffix.startsWith(QLatin1Char('.')))
+ if (d->defaultSuffix.size() > 1 && d->defaultSuffix.startsWith(u'.'))
d->defaultSuffix.remove(0, 1); // Silently change ".txt" -> "txt".
}
@@ -741,7 +703,7 @@ QStringList QFileDialogOptions::supportedSchemes() const
void QPlatformFileDialogHelper::selectMimeTypeFilter(const QString &filter)
{
- Q_UNUSED(filter)
+ Q_UNUSED(filter);
}
QString QPlatformFileDialogHelper::selectedMimeTypeFilter() const
@@ -781,16 +743,15 @@ const char QPlatformFileDialogHelper::filterRegExp[] =
QStringList QPlatformFileDialogHelper::cleanFilterList(const QString &filter)
{
#if QT_CONFIG(regularexpression)
- QRegularExpression regexp(QString::fromLatin1(filterRegExp));
+ static const QRegularExpression regexp(QString::fromLatin1(filterRegExp));
Q_ASSERT(regexp.isValid());
QString f = filter;
- QRegularExpressionMatch match;
- filter.indexOf(regexp, 0, &match);
+ QRegularExpressionMatch match = regexp.match(filter);
if (match.hasMatch())
f = match.captured(2);
- return f.split(QLatin1Char(' '), Qt::SkipEmptyParts);
+ return f.split(u' ', Qt::SkipEmptyParts);
#else
- Q_UNUSED(filter)
+ Q_UNUSED(filter);
return QStringList();
#endif
}
@@ -807,13 +768,19 @@ public:
{}
QString windowTitle;
- QMessageDialogOptions::Icon icon;
+ QMessageDialogOptions::StandardIcon icon;
QString text;
QString informativeText;
QString detailedText;
QPlatformDialogHelper::StandardButtons buttons;
- QVector<QMessageDialogOptions::CustomButton> customButtons;
+ QList<QMessageDialogOptions::CustomButton> customButtons;
int nextCustomButtonId;
+ QPixmap iconPixmap;
+ QString checkBoxLabel;
+ Qt::CheckState checkBoxState = Qt::Unchecked;
+ int defaultButtonId = 0;
+ int escapeButtonId = 0;
+ QMessageDialogOptions::Options options;
};
QMessageDialogOptions::QMessageDialogOptions(QMessageDialogOptionsPrivate *dd)
@@ -855,16 +822,26 @@ void QMessageDialogOptions::setWindowTitle(const QString &title)
d->windowTitle = title;
}
-QMessageDialogOptions::Icon QMessageDialogOptions::icon() const
+QMessageDialogOptions::StandardIcon QMessageDialogOptions::standardIcon() const
{
return d->icon;
}
-void QMessageDialogOptions::setIcon(Icon icon)
+void QMessageDialogOptions::setStandardIcon(StandardIcon icon)
{
d->icon = icon;
}
+void QMessageDialogOptions::setIconPixmap(const QPixmap &pixmap)
+{
+ d->iconPixmap = pixmap;
+}
+
+QPixmap QMessageDialogOptions::iconPixmap() const
+{
+ return d->iconPixmap;
+}
+
QString QMessageDialogOptions::text() const
{
return d->text;
@@ -906,9 +883,9 @@ QPlatformDialogHelper::StandardButtons QMessageDialogOptions::standardButtons()
}
int QMessageDialogOptions::addButton(const QString &label, QPlatformDialogHelper::ButtonRole role,
- void *buttonImpl)
+ void *buttonImpl, int buttonId)
{
- const CustomButton b(d->nextCustomButtonId++, label, role, buttonImpl);
+ const CustomButton b(buttonId ? buttonId : d->nextCustomButtonId++, label, role, buttonImpl);
d->customButtons.append(b);
return b.id;
}
@@ -923,17 +900,81 @@ void QMessageDialogOptions::removeButton(int id)
d->customButtons.removeOne(CustomButton(id));
}
-const QVector<QMessageDialogOptions::CustomButton> &QMessageDialogOptions::customButtons()
+const QList<QMessageDialogOptions::CustomButton> &QMessageDialogOptions::customButtons()
{
return d->customButtons;
}
+void QMessageDialogOptions::clearCustomButtons()
+{
+ d->customButtons.clear();
+}
+
const QMessageDialogOptions::CustomButton *QMessageDialogOptions::customButton(int id)
{
- int i = d->customButtons.indexOf(CustomButton(id));
+ const int i = int(d->customButtons.indexOf(CustomButton(id)));
return (i < 0 ? nullptr : &d->customButtons.at(i));
}
+void QMessageDialogOptions::setCheckBox(const QString &label, Qt::CheckState state)
+{
+ d->checkBoxLabel = label;
+ d->checkBoxState = state;
+}
+
+QString QMessageDialogOptions::checkBoxLabel() const
+{
+ return d->checkBoxLabel;
+}
+
+Qt::CheckState QMessageDialogOptions::checkBoxState() const
+{
+ return d->checkBoxState;
+}
+
+void QMessageDialogOptions::setDefaultButton(int id)
+{
+ d->defaultButtonId = id;
+}
+
+int QMessageDialogOptions::defaultButton() const
+{
+ return d->defaultButtonId;
+}
+
+void QMessageDialogOptions::setEscapeButton(int id)
+{
+ d->escapeButtonId = id;
+}
+
+int QMessageDialogOptions::escapeButton() const
+{
+ return d->escapeButtonId;
+}
+
+void QMessageDialogOptions::setOption(QMessageDialogOptions::Option option, bool on)
+{
+ if (!(d->options & option) != !on)
+ setOptions(d->options ^ option);
+}
+
+bool QMessageDialogOptions::testOption(QMessageDialogOptions::Option option) const
+{
+ return d->options & option;
+}
+
+void QMessageDialogOptions::setOptions(QMessageDialogOptions::Options options)
+{
+ if (options != d->options)
+ d->options = options;
+}
+
+QMessageDialogOptions::Options QMessageDialogOptions::options() const
+{
+ return d->options;
+}
+
+
QPlatformDialogHelper::ButtonRole QPlatformDialogHelper::buttonRole(QPlatformDialogHelper::StandardButton button)
{
switch (button) {
@@ -1013,3 +1054,5 @@ void QPlatformMessageDialogHelper::setOptions(const QSharedPointer<QMessageDialo
}
QT_END_NAMESPACE
+
+#include "moc_qplatformdialoghelper.cpp"
diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h
index 59f01c9fc3..0569a7e2f9 100644
--- a/src/gui/kernel/qplatformdialoghelper.h
+++ b/src/gui/kernel/qplatformdialoghelper.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMDIALOGHELPER_H
#define QPLATFORMDIALOGHELPER_H
@@ -150,7 +114,6 @@ public:
MacLayout,
KdeLayout,
GnomeLayout,
- MacModelessLayout,
AndroidLayout
};
Q_ENUM(ButtonLayout)
@@ -177,8 +140,10 @@ Q_SIGNALS:
};
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QPlatformDialogHelper::StandardButton)
-Q_DECLARE_METATYPE(QPlatformDialogHelper::ButtonRole)
+QT_DECL_METATYPE_EXTERN_TAGGED(QPlatformDialogHelper::StandardButton,
+ QPlatformDialogHelper__StandardButton, Q_GUI_EXPORT)
+QT_DECL_METATYPE_EXTERN_TAGGED(QPlatformDialogHelper::ButtonRole,
+ QPlatformDialogHelper__ButtonRole, Q_GUI_EXPORT)
QT_BEGIN_NAMESPACE
class Q_GUI_EXPORT QColorDialogOptions
@@ -192,7 +157,8 @@ public:
enum ColorDialogOption {
ShowAlphaChannel = 0x00000001,
NoButtons = 0x00000002,
- DontUseNativeDialog = 0x00000004
+ DontUseNativeDialog = 0x00000004,
+ NoEyeDropperButton = 0x00000008
};
Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption)
@@ -315,18 +281,16 @@ public:
enum DialogLabel { LookIn, FileName, FileType, Accept, Reject, DialogLabelCount };
Q_ENUM(DialogLabel)
+ // keep this in sync with QFileDialog::Options
enum FileDialogOption
{
ShowDirsOnly = 0x00000001,
DontResolveSymlinks = 0x00000002,
DontConfirmOverwrite = 0x00000004,
-#if QT_DEPRECATED_SINCE(5, 14)
- DontUseSheet Q_DECL_ENUMERATOR_DEPRECATED = 0x00000008,
-#endif
- DontUseNativeDialog = 0x00000010,
- ReadOnly = 0x00000020,
- HideNameFilterDetails = 0x00000040,
- DontUseCustomDirectoryIcons = 0x00000080
+ DontUseNativeDialog = 0x00000008,
+ ReadOnly = 0x00000010,
+ HideNameFilterDetails = 0x00000020,
+ DontUseCustomDirectoryIcons = 0x00000040
};
Q_DECLARE_FLAGS(FileDialogOptions, FileDialogOption)
Q_FLAG(FileDialogOptions)
@@ -440,9 +404,16 @@ protected:
~QMessageDialogOptions();
public:
+ // Keep in sync with QMessageBox Option
+ enum class Option {
+ DontUseNativeDialog = 0x00000001,
+ };
+ Q_DECLARE_FLAGS(Options, Option);
+ Q_FLAG(Options);
+
// Keep in sync with QMessageBox::Icon
- enum Icon { NoIcon, Information, Warning, Critical, Question };
- Q_ENUM(Icon)
+ enum StandardIcon { NoIcon, Information, Warning, Critical, Question };
+ Q_ENUM(StandardIcon)
static QSharedPointer<QMessageDialogOptions> create();
QSharedPointer<QMessageDialogOptions> clone() const;
@@ -450,8 +421,11 @@ public:
QString windowTitle() const;
void setWindowTitle(const QString &);
- void setIcon(Icon icon);
- Icon icon() const;
+ void setStandardIcon(StandardIcon icon);
+ StandardIcon standardIcon() const;
+
+ void setIconPixmap(const QPixmap &pixmap);
+ QPixmap iconPixmap() const;
void setText(const QString &text);
QString text() const;
@@ -462,6 +436,11 @@ public:
void setDetailedText(const QString &text);
QString detailedText() const;
+ void setOption(Option option, bool on = true);
+ bool testOption(Option option) const;
+ void setOptions(Options options);
+ Options options() const;
+
void setStandardButtons(QPlatformDialogHelper::StandardButtons buttons);
QPlatformDialogHelper::StandardButtons standardButtons() const;
@@ -480,10 +459,21 @@ public:
};
int addButton(const QString &label, QPlatformDialogHelper::ButtonRole role,
- void *buttonImpl = nullptr);
+ void *buttonImpl = nullptr, int buttonId = 0);
void removeButton(int id);
const QList<CustomButton> &customButtons();
const CustomButton *customButton(int id);
+ void clearCustomButtons();
+
+ void setCheckBox(const QString &label, Qt::CheckState state);
+ QString checkBoxLabel() const;
+ Qt::CheckState checkBoxState() const;
+
+ void setEscapeButton(int id);
+ int escapeButton() const;
+
+ void setDefaultButton(int id);
+ int defaultButton() const;
private:
QMessageDialogOptionsPrivate *d;
@@ -498,6 +488,7 @@ public:
Q_SIGNALS:
void clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role);
+ void checkBoxStateChanged(Qt::CheckState state);
private:
QSharedPointer<QMessageDialogOptions> m_options;
diff --git a/src/gui/kernel/qplatformdrag.cpp b/src/gui/kernel/qplatformdrag.cpp
index b40ddcbfb8..cf50587996 100644
--- a/src/gui/kernel/qplatformdrag.cpp
+++ b/src/gui/kernel/qplatformdrag.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformdrag.h"
diff --git a/src/gui/kernel/qplatformdrag.h b/src/gui/kernel/qplatformdrag.h
index 0c99539357..d9e4a553b8 100644
--- a/src/gui/kernel/qplatformdrag.h
+++ b/src/gui/kernel/qplatformdrag.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMDRAG_H
#define QPLATFORMDRAG_H
diff --git a/src/gui/kernel/qplatformgraphicsbuffer.cpp b/src/gui/kernel/qplatformgraphicsbuffer.cpp
index 73ec033e19..52fc2770b4 100644
--- a/src/gui/kernel/qplatformgraphicsbuffer.cpp
+++ b/src/gui/kernel/qplatformgraphicsbuffer.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformgraphicsbuffer.h"
#include <QtGui/QOpenGLContext>
@@ -60,10 +24,6 @@ QT_BEGIN_NAMESPACE
There is no public constructor nor any public factory function.
- QPlatformGraphicsBuffer is intended to be created by using platform specific
- APIs available from QtPlatformHeaders, or there might be accessor functions
- similar to the accessor function that QPlatformBackingstore has.
-
\internal
*/
@@ -274,3 +234,5 @@ QPlatformGraphicsBuffer::Origin QPlatformGraphicsBuffer::origin() const
*/
QT_END_NAMESPACE
+
+#include "moc_qplatformgraphicsbuffer.cpp"
diff --git a/src/gui/kernel/qplatformgraphicsbuffer.h b/src/gui/kernel/qplatformgraphicsbuffer.h
index 9004116ea4..6723c63f0c 100644
--- a/src/gui/kernel/qplatformgraphicsbuffer.h
+++ b/src/gui/kernel/qplatformgraphicsbuffer.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMGRAPHICSBUFFER_H
#define QPLATFORMGRAPHICSBUFFER_H
diff --git a/src/gui/kernel/qplatformgraphicsbufferhelper.cpp b/src/gui/kernel/qplatformgraphicsbufferhelper.cpp
index ab9a92a383..0ec2308453 100644
--- a/src/gui/kernel/qplatformgraphicsbufferhelper.cpp
+++ b/src/gui/kernel/qplatformgraphicsbufferhelper.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QtGui/qpa/qplatformgraphicsbuffer.h>
@@ -215,14 +179,14 @@ bool QPlatformGraphicsBufferHelper::bindSWToTexture(const QPlatformGraphicsBuffe
QRect rect = subRect;
if (rect.isNull() || rect == QRect(QPoint(0,0),size)) {
if (needsRowLength)
- funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, image.bytesPerLine() / 4);
+ funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, GLint(image.bytesPerLine() / 4));
funcs->glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, size.width(), size.height(), 0, GL_RGBA, pixelType, image.constBits());
if (needsRowLength)
funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
} else {
if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) {
// OpenGL 2.1+ or OpenGL ES/3+
- funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, image.bytesPerLine() / 4);
+ funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, GLint(image.bytesPerLine() / 4));
funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, pixelType,
image.constScanLine(rect.y()) + rect.x() * 4);
funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
@@ -255,10 +219,10 @@ bool QPlatformGraphicsBufferHelper::bindSWToTexture(const QPlatformGraphicsBuffe
return true;
#else
- Q_UNUSED(graphicsBuffer)
- Q_UNUSED(swizzleRandB)
- Q_UNUSED(premultipliedB)
- Q_UNUSED(subRect)
+ Q_UNUSED(graphicsBuffer);
+ Q_UNUSED(swizzleRandB);
+ Q_UNUSED(premultipliedB);
+ Q_UNUSED(subRect);
return false;
#endif // QT_NO_OPENGL
}
diff --git a/src/gui/kernel/qplatformgraphicsbufferhelper.h b/src/gui/kernel/qplatformgraphicsbufferhelper.h
index 36afd4877b..e408e4a674 100644
--- a/src/gui/kernel/qplatformgraphicsbufferhelper.h
+++ b/src/gui/kernel/qplatformgraphicsbufferhelper.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMGRAPHICSBUFFERHELPER_H
#define QPLATFORMGRAPHICSBUFFERHELPER_H
diff --git a/src/gui/kernel/qplatforminputcontext.cpp b/src/gui/kernel/qplatforminputcontext.cpp
index 9771e6ba11..9d3ee4acb6 100644
--- a/src/gui/kernel/qplatforminputcontext.cpp
+++ b/src/gui/kernel/qplatforminputcontext.cpp
@@ -1,46 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatforminputcontext.h"
#include <qguiapplication.h>
#include <QRect>
#include "private/qkeymapper_p.h"
+#include "private/qhighdpiscaling_p.h"
#include <qpa/qplatforminputcontext_p.h>
#include <QtGui/qtransform.h>
@@ -82,6 +47,11 @@ QT_BEGIN_NAMESPACE
QPlatformInputContext::QPlatformInputContext()
: QObject(*(new QPlatformInputContextPrivate))
{
+ // Delay initialization of cached input direction
+ // until super class has finished constructing.
+ QMetaObject::invokeMethod(this, [this]{
+ m_inputDirection = inputDirection();
+ }, Qt::QueuedConnection);
}
/*!
@@ -106,7 +76,7 @@ bool QPlatformInputContext::isValid() const
*/
bool QPlatformInputContext::hasCapability(Capability capability) const
{
- Q_UNUSED(capability)
+ Q_UNUSED(capability);
return true;
}
@@ -130,13 +100,13 @@ void QPlatformInputContext::update(Qt::InputMethodQueries)
}
/*!
- Called when when the word currently being composed in input item is tapped by
+ Called when the word currently being composed in the input item is tapped by
the user. Input methods often use this information to offer more word
suggestions to the user.
*/
void QPlatformInputContext::invokeAction(QInputMethod::Action action, int cursorPosition)
{
- Q_UNUSED(cursorPosition)
+ Q_UNUSED(cursorPosition);
// Default behavior for simple ephemeral input contexts. Some
// complex input contexts should not be reset here.
if (action == QInputMethod::Click)
@@ -151,7 +121,7 @@ void QPlatformInputContext::invokeAction(QInputMethod::Action action, int cursor
*/
bool QPlatformInputContext::filterEvent(const QEvent *event)
{
- Q_UNUSED(event)
+ Q_UNUSED(event);
return false;
}
@@ -227,22 +197,29 @@ void QPlatformInputContext::emitInputPanelVisibleChanged()
QLocale QPlatformInputContext::locale() const
{
- return qt_keymapper_private()->keyboardInputLocale;
+ return QLocale::system();
}
void QPlatformInputContext::emitLocaleChanged()
{
emit QGuiApplication::inputMethod()->localeChanged();
+
+ // Changing the locale might have updated the input direction
+ emitInputDirectionChanged(inputDirection());
}
Qt::LayoutDirection QPlatformInputContext::inputDirection() const
{
- return qt_keymapper_private()->keyboardInputDirection;
+ return locale().textDirection();
}
void QPlatformInputContext::emitInputDirectionChanged(Qt::LayoutDirection newDirection)
{
+ if (newDirection == m_inputDirection)
+ return;
+
emit QGuiApplication::inputMethod()->inputDirectionChanged(newDirection);
+ m_inputDirection = newDirection;
}
/*!
@@ -251,7 +228,7 @@ void QPlatformInputContext::emitInputDirectionChanged(Qt::LayoutDirection newDir
*/
void QPlatformInputContext::setFocusObject(QObject *object)
{
- Q_UNUSED(object)
+ Q_UNUSED(object);
}
/*!
@@ -270,16 +247,20 @@ void QPlatformInputContextPrivate::setInputMethodAccepted(bool accepted)
}
/*!
- * \brief QPlatformInputContext::setSelectionOnFocusObject
- * \param anchorPos Beginning of selection in currently active window coordinates
- * \param cursorPos End of selection in currently active window coordinates
- */
-void QPlatformInputContext::setSelectionOnFocusObject(const QPointF &anchorPos, const QPointF &cursorPos)
+ \brief QPlatformInputContext::setSelectionOnFocusObject
+ \param anchorPos Beginning of selection in currently active window native coordinates
+ \param cursorPos End of selection in currently active window native coordinates
+*/
+void QPlatformInputContext::setSelectionOnFocusObject(const QPointF &nativeAnchorPos, const QPointF &nativeCursorPos)
{
QObject *focus = qApp->focusObject();
if (!focus)
return;
+ QWindow *window = qApp->focusWindow();
+ const QPointF &anchorPos = QHighDpi::fromNativePixels(nativeAnchorPos, window);
+ const QPointF &cursorPos = QHighDpi::fromNativePixels(nativeCursorPos, window);
+
QInputMethod *im = QGuiApplication::inputMethod();
const QTransform mapToLocal = im->inputItemTransform().inverted();
bool success;
@@ -297,4 +278,80 @@ void QPlatformInputContext::setSelectionOnFocusObject(const QPointF &anchorPos,
}
}
+/*!
+ \brief QPlatformInputContext::queryFocusObject
+
+ Queries the current foucus object with a window position in native pixels.
+*/
+QVariant QPlatformInputContext::queryFocusObject(Qt::InputMethodQuery query, QPointF nativePosition)
+{
+ const QPointF position = QHighDpi::fromNativePixels(nativePosition, QGuiApplication::focusWindow());
+ const QInputMethod *im = QGuiApplication::inputMethod();
+ const QTransform mapToLocal = im->inputItemTransform().inverted();
+ return im->queryFocusObject(query, mapToLocal.map(position));
+}
+
+/*!
+ \brief QPlatformInputContext::inputItemRectangle
+
+ Returns the input item rectangle for the currently active window
+ and input methiod in native window coordinates.
+*/
+QRectF QPlatformInputContext::inputItemRectangle()
+{
+ QInputMethod *im = QGuiApplication::inputMethod();
+ const QRectF deviceIndependentRectangle = im->inputItemTransform().mapRect(im->inputItemRectangle());
+ return QHighDpi::toNativePixels(deviceIndependentRectangle, QGuiApplication::focusWindow());
+}
+
+/*!
+ \brief QPlatformInputContext::inputItemClipRectangle
+
+ Returns the input item clip rectangle for the currently active window
+ and input methiod in native window coordinates.
+*/
+QRectF QPlatformInputContext::inputItemClipRectangle()
+{
+ return QHighDpi::toNativePixels(
+ QGuiApplication::inputMethod()->inputItemClipRectangle(), QGuiApplication::focusWindow());
+}
+
+/*!
+ \brief QPlatformInputContext::cursorRectangle
+
+ Returns the cursor rectangle for the currently active window
+ and input methiod in native window coordinates.
+*/
+QRectF QPlatformInputContext::cursorRectangle()
+{
+ return QHighDpi::toNativePixels(
+ QGuiApplication::inputMethod()->cursorRectangle(), QGuiApplication::focusWindow());
+}
+
+/*!
+ \brief QPlatformInputContext::anchorRectangle
+
+ Returns the anchor rectangle for the currently active window
+ and input methiod in native window coordinates.
+*/
+QRectF QPlatformInputContext::anchorRectangle()
+{
+ return QHighDpi::toNativePixels(
+ QGuiApplication::inputMethod()->anchorRectangle(), QGuiApplication::focusWindow());
+}
+
+/*!
+ \brief QPlatformInputContext::keyboardRectangle
+
+ Returns the keyboard rectangle for the currently active window
+ and input methiod in native window coordinates.
+*/
+QRectF QPlatformInputContext::keyboardRectangle()
+{
+ return QHighDpi::toNativePixels(
+ QGuiApplication::inputMethod()->keyboardRectangle(), QGuiApplication::focusWindow());
+}
+
QT_END_NAMESPACE
+
+#include "moc_qplatforminputcontext.cpp"
diff --git a/src/gui/kernel/qplatforminputcontext.h b/src/gui/kernel/qplatforminputcontext.h
index ad0e5bcf35..481f97a065 100644
--- a/src/gui/kernel/qplatforminputcontext.h
+++ b/src/gui/kernel/qplatforminputcontext.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMINPUTCONTEXT_H
#define QPLATFORMINPUTCONTEXT_H
@@ -97,11 +61,19 @@ public:
bool inputMethodAccepted() const;
static void setSelectionOnFocusObject(const QPointF &anchorPos, const QPointF &cursorPos);
+ static QVariant queryFocusObject(Qt::InputMethodQuery query, QPointF position);
+ static QRectF inputItemRectangle();
+ static QRectF inputItemClipRectangle();
+ static QRectF cursorRectangle();
+ static QRectF anchorRectangle();
+ static QRectF keyboardRectangle();
private:
friend class QGuiApplication;
friend class QGuiApplicationPrivate;
friend class QInputMethod;
+
+ Qt::LayoutDirection m_inputDirection;
};
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatforminputcontext_p.h b/src/gui/kernel/qplatforminputcontext_p.h
index c4f4b97d03..d26bfe70af 100644
--- a/src/gui/kernel/qplatforminputcontext_p.h
+++ b/src/gui/kernel/qplatforminputcontext_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMINPUTCONTEXT_P_H
#define QPLATFORMINPUTCONTEXT_P_H
diff --git a/src/gui/kernel/qplatforminputcontextfactory.cpp b/src/gui/kernel/qplatforminputcontextfactory.cpp
index 749abaf27a..933d990f7c 100644
--- a/src/gui/kernel/qplatforminputcontextfactory.cpp
+++ b/src/gui/kernel/qplatforminputcontextfactory.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qpa/qplatforminputcontextfactory_p.h>
#include <qpa/qplatforminputcontextplugin_p.h>
@@ -48,35 +12,60 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
#if QT_CONFIG(settings)
-Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
- (QPlatformInputContextFactoryInterface_iid, QLatin1String("/platforminputcontexts"), Qt::CaseInsensitive))
+Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, icLoader,
+ (QPlatformInputContextFactoryInterface_iid, "/platforminputcontexts"_L1, Qt::CaseInsensitive))
#endif
QStringList QPlatformInputContextFactory::keys()
{
#if QT_CONFIG(settings)
- return loader()->keyMap().values();
+ return icLoader()->keyMap().values();
#else
return QStringList();
#endif
}
-QString QPlatformInputContextFactory::requested()
+QStringList QPlatformInputContextFactory::requested()
{
- QByteArray env = qgetenv("QT_IM_MODULE");
- return env.isNull() ? QString() : QString::fromLocal8Bit(env);
+ QStringList imList;
+ QByteArray env = qgetenv("QT_IM_MODULES");
+
+ if (!env.isEmpty())
+ imList = QString::fromLocal8Bit(env).split(QChar::fromLatin1(';'), Qt::SkipEmptyParts);
+
+ if (!imList.isEmpty())
+ return imList;
+
+ env = qgetenv("QT_IM_MODULE");
+ if (!env.isEmpty())
+ imList = {QString::fromLocal8Bit(env)};
+
+ return imList;
+}
+
+QPlatformInputContext *QPlatformInputContextFactory::create(const QStringList& keys)
+{
+ for (const QString &key : keys) {
+ auto plugin = create(key);
+ if (plugin)
+ return plugin;
+ }
+
+ return nullptr;
}
QPlatformInputContext *QPlatformInputContextFactory::create(const QString& key)
{
#if QT_CONFIG(settings)
if (!key.isEmpty()) {
- QStringList paramList = key.split(QLatin1Char(':'));
+ QStringList paramList = key.split(u':');
const QString platform = paramList.takeFirst().toLower();
QPlatformInputContext *ic = qLoadPlugin<QPlatformInputContext, QPlatformInputContextPlugin>
- (loader(), platform, paramList);
+ (icLoader(), platform, paramList);
if (ic && ic->isValid())
return ic;
diff --git a/src/gui/kernel/qplatforminputcontextfactory_p.h b/src/gui/kernel/qplatforminputcontextfactory_p.h
index 881421ce49..5f5881c508 100644
--- a/src/gui/kernel/qplatforminputcontextfactory_p.h
+++ b/src/gui/kernel/qplatforminputcontextfactory_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMINPUTCONTEXTFACTORY_H
#define QPLATFORMINPUTCONTEXTFACTORY_H
@@ -63,7 +27,8 @@ class Q_GUI_EXPORT QPlatformInputContextFactory
{
public:
static QStringList keys();
- static QString requested();
+ static QStringList requested();
+ static QPlatformInputContext *create(const QStringList &keys);
static QPlatformInputContext *create(const QString &key);
static QPlatformInputContext *create();
};
diff --git a/src/gui/kernel/qplatforminputcontextplugin.cpp b/src/gui/kernel/qplatforminputcontextplugin.cpp
index 53d56dbb48..fdfc8483b5 100644
--- a/src/gui/kernel/qplatforminputcontextplugin.cpp
+++ b/src/gui/kernel/qplatforminputcontextplugin.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatforminputcontextplugin_p.h"
@@ -51,3 +15,5 @@ QPlatformInputContextPlugin::~QPlatformInputContextPlugin()
}
QT_END_NAMESPACE
+
+#include "moc_qplatforminputcontextplugin_p.cpp"
diff --git a/src/gui/kernel/qplatforminputcontextplugin_p.h b/src/gui/kernel/qplatforminputcontextplugin_p.h
index 2228d5c8d6..819955bef4 100644
--- a/src/gui/kernel/qplatforminputcontextplugin_p.h
+++ b/src/gui/kernel/qplatforminputcontextplugin_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMINPUTCONTEXTPLUGIN_H
#define QPLATFORMINPUTCONTEXTPLUGIN_H
diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp
index 63f66e6bf7..130b479c64 100644
--- a/src/gui/kernel/qplatformintegration.cpp
+++ b/src/gui/kernel/qplatformintegration.cpp
@@ -1,47 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformintegration.h"
#include <qpa/qplatformfontdatabase.h>
#include <qpa/qplatformclipboard.h>
#include <qpa/qplatformaccessibility.h>
+#include <qpa/qplatformkeymapper.h>
#include <qpa/qplatformtheme.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/private/qpixmap_raster_p.h>
@@ -187,7 +152,7 @@ QPlatformServices *QPlatformIntegration::services() const
/*!
\enum QPlatformIntegration::Capability
- Capabilities are used to determing specific features of a platform integration
+ Capabilities are used to determine specific features of a platform integration
\value ThreadedPixmaps The platform uses a pixmap implementation that is reentrant
and can be used from multiple threads, like the raster paint engine and QImage based
@@ -199,8 +164,8 @@ QPlatformServices *QPlatformIntegration::services() const
\value SharedGraphicsCache The platform supports a shared graphics cache
- \value BufferQueueingOpenGL The OpenGL implementation on the platform will queue
- up buffers when swapBuffers() is called and block only when its buffer pipeline
+ \value BufferQueueingOpenGL Deprecated. The OpenGL implementation on the platform will
+ queue up buffers when swapBuffers() is called and block only when its buffer pipeline
is full, rather than block immediately.
\value MultipleWindows The platform supports multiple QWindows, i.e. does some kind
@@ -247,6 +212,28 @@ QPlatformServices *QPlatformIntegration::services() const
\value OpenGLOnRasterSurface The platform supports making a QOpenGLContext current
in combination with a QWindow of type RasterSurface.
+
+ \value PaintEvents The platform sends paint events instead of expose events when
+ the window needs repainting. Expose events are only sent when a window is toggled
+ from a non-exposed to exposed state or back.
+
+ \value RhiBasedRendering The platform supports one or more of the 3D rendering APIs
+ that Qt Quick and other components can use via the Qt Rendering Hardware Interface. On
+ platforms where it is clear upfront that the platform cannot, or does not want to,
+ support rendering via 3D graphics APIs such as OpenGL, Vulkan, Direct 3D, or Metal,
+ this capability can be reported as \c false. That in effect means that in modules
+ where there is an alternative, such as Qt Quick with its \c software backend, an
+ automatic fallback to that alternative may occur, if applicable. The default
+ implementation of hasCapability() returns \c true.
+
+ \value ScreenWindowGrabbing The platform supports grabbing window on screen.
+ On Wayland, this capability can be reported as \c false. The default implementation
+ of hasCapability() returns \c true.
+
+ \value BackingStoreStaticContents The platform backingstore supports static contents.
+ On resize of the backingstore the static contents region is provided, and the backing
+ store is expected to propagate the static content to the resized backing store, without
+ clients needing to repaint the static content region.
*/
/*!
@@ -271,7 +258,8 @@ QPlatformServices *QPlatformIntegration::services() const
bool QPlatformIntegration::hasCapability(Capability cap) const
{
return cap == NonFullScreenWindows || cap == NativeWidgets || cap == WindowManagement
- || cap == TopStackedNativeChildWindows || cap == WindowActivation;
+ || cap == TopStackedNativeChildWindows || cap == WindowActivation
+ || cap == RhiBasedRendering || cap == ScreenWindowGrabbing;
}
QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
@@ -324,7 +312,7 @@ QPlatformSharedGraphicsCache *QPlatformIntegration::createPlatformSharedGraphics
*/
QPaintEngine *QPlatformIntegration::createImagePaintEngine(QPaintDevice *paintDevice) const
{
- Q_UNUSED(paintDevice)
+ Q_UNUSED(paintDevice);
return nullptr;
}
@@ -360,7 +348,22 @@ QPlatformInputContext *QPlatformIntegration::inputContext() const
return nullptr;
}
-#ifndef QT_NO_ACCESSIBILITY
+/*!
+ Accessor for the platform integration's key mapper.
+
+ Default implementation returns a default QPlatformKeyMapper.
+
+ \sa QPlatformKeyMapper
+*/
+QPlatformKeyMapper *QPlatformIntegration::keyMapper() const
+{
+ static QPlatformKeyMapper *keyMapper = nullptr;
+ if (!keyMapper)
+ keyMapper = new QPlatformKeyMapper;
+ return keyMapper;
+}
+
+#if QT_CONFIG(accessibility)
/*!
Returns the platforms accessibility.
@@ -411,7 +414,7 @@ QVariant QPlatformIntegration::styleHint(StyleHint hint) const
case UseRtlExtensions:
return QVariant(false);
case SetFocusOnTouchRelease:
- return QVariant(false);
+ return QPlatformTheme::defaultThemeHint(QPlatformTheme::SetFocusOnTouchRelease);
case MousePressAndHoldInterval:
return QPlatformTheme::defaultThemeHint(QPlatformTheme::MousePressAndHoldInterval);
case TabFocusBehavior:
@@ -426,6 +429,16 @@ QVariant QPlatformIntegration::styleHint(StyleHint hint) const
return QPlatformTheme::defaultThemeHint(QPlatformTheme::WheelScrollLines);
case MouseQuickSelectionThreshold:
return QPlatformTheme::defaultThemeHint(QPlatformTheme::MouseQuickSelectionThreshold);
+ case MouseDoubleClickDistance:
+ return QPlatformTheme::defaultThemeHint(QPlatformTheme::MouseDoubleClickDistance);
+ case FlickStartDistance:
+ return QPlatformTheme::defaultThemeHint(QPlatformTheme::FlickStartDistance);
+ case FlickMaximumVelocity:
+ return QPlatformTheme::defaultThemeHint(QPlatformTheme::FlickMaximumVelocity);
+ case FlickDeceleration:
+ return QPlatformTheme::defaultThemeHint(QPlatformTheme::FlickDeceleration);
+ case UnderlineShortcut:
+ return true;
}
return 0;
@@ -437,6 +450,9 @@ Qt::WindowState QPlatformIntegration::defaultWindowState(Qt::WindowFlags flags)
if (flags & Qt::Popup & ~Qt::Window)
return Qt::WindowNoState;
+ if (flags & Qt::SubWindow)
+ return Qt::WindowNoState;
+
if (styleHint(QPlatformIntegration::ShowIsFullScreen).toBool())
return Qt::WindowFullScreen;
else if (styleHint(QPlatformIntegration::ShowIsMaximized).toBool())
@@ -472,7 +488,7 @@ QStringList QPlatformIntegration::themeNames() const
class QPlatformTheme *QPlatformIntegration::createPlatformTheme(const QString &name) const
{
- Q_UNUSED(name)
+ Q_UNUSED(name);
return new QPlatformTheme;
}
@@ -483,7 +499,7 @@ class QPlatformTheme *QPlatformIntegration::createPlatformTheme(const QString &n
*/
QPlatformOffscreenSurface *QPlatformIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
{
- Q_UNUSED(surface)
+ Q_UNUSED(surface);
return nullptr;
}
@@ -525,6 +541,20 @@ void QPlatformIntegration::beep() const
{
}
+/*!
+ \since 6.0
+
+ Asks the platform to terminate the application.
+
+ Overrides should ensure there's a callback into the QWSI
+ function handleApplicationTermination so that the quit can
+ be propagated to QtGui and the application.
+*/
+void QPlatformIntegration::quit() const
+{
+ QWindowSystemInterface::handleApplicationTermination<QWindowSystemInterface::SynchronousDelivery>();
+}
+
#ifndef QT_NO_OPENGL
/*!
Platform integration function for querying the OpenGL implementation type.
@@ -562,7 +592,21 @@ void QPlatformIntegration::setApplicationIcon(const QIcon &icon) const
Q_UNUSED(icon);
}
-#if QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC)
+/*!
+ \since 6.5
+
+ Should set the application's badge to \a number.
+
+ If the number is 0 the badge should be cleared.
+
+ \sa QGuiApplication::setBadge()
+*/
+void QPlatformIntegration::setApplicationBadge(qint64 number)
+{
+ Q_UNUSED(number);
+}
+
+#if QT_CONFIG(vulkan) || defined(Q_QDOC)
/*!
Factory function for QPlatformVulkanInstance. The \a instance parameter is a
diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h
index 23e868180f..a18ae821c7 100644
--- a/src/gui/kernel/qplatformintegration.h
+++ b/src/gui/kernel/qplatformintegration.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMINTEGRATION_H
#define QPLATFORMINTEGRATION_H
@@ -69,6 +33,7 @@ class QPlatformOpenGLContext;
class QGuiGLFormat;
class QAbstractEventDispatcher;
class QPlatformInputContext;
+class QPlatformKeyMapper;
class QPlatformAccessibility;
class QPlatformTheme;
class QPlatformDialogHelper;
@@ -81,7 +46,7 @@ class QOffscreenSurface;
class QPlatformVulkanInstance;
class QVulkanInstance;
-namespace QPlatformInterface::Private {
+namespace QNativeInterface::Private {
template <typename R, typename I, auto func, typename... Args>
struct QInterfaceProxyImp
@@ -103,7 +68,7 @@ struct QInterfaceProxy<func> : public QInterfaceProxyImp<R, I, func, Args...> {}
template <typename R, typename I, typename... Args, R(I::*func)(Args...) const>
struct QInterfaceProxy<func> : public QInterfaceProxyImp<R, I, func, Args...> {};
-} // QPlatformInterface::Private
+} // QNativeInterface::Private
class Q_GUI_EXPORT QPlatformIntegration
{
@@ -131,7 +96,11 @@ public:
SwitchableWidgetComposition,
TopStackedNativeChildWindows,
OpenGLOnRasterSurface,
- MaximizeUsingFullscreenGeometry
+ MaximizeUsingFullscreenGeometry,
+ PaintEvents,
+ RhiBasedRendering,
+ ScreenWindowGrabbing, // whether QScreen::grabWindow() is supported
+ BackingStoreStaticContents
};
virtual ~QPlatformIntegration() { }
@@ -162,7 +131,7 @@ public:
virtual QPlatformDrag *drag() const;
#endif
virtual QPlatformInputContext *inputContext() const;
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
virtual QPlatformAccessibility *accessibility() const;
#endif
@@ -193,14 +162,23 @@ public:
UiEffects,
WheelScrollLines,
ShowShortcutsInContextMenus,
- MouseQuickSelectionThreshold
+ MouseQuickSelectionThreshold,
+ MouseDoubleClickDistance,
+ FlickStartDistance,
+ FlickMaximumVelocity,
+ FlickDeceleration,
+ UnderlineShortcut,
};
virtual QVariant styleHint(StyleHint hint) const;
virtual Qt::WindowState defaultWindowState(Qt::WindowFlags) const;
+protected:
virtual Qt::KeyboardModifiers queryKeyboardModifiers() const;
virtual QList<int> possibleKeys(const QKeyEvent *) const;
+ friend class QPlatformKeyMapper;
+public:
+ virtual QPlatformKeyMapper *keyMapper() const;
virtual QStringList themeNames() const;
virtual QPlatformTheme *createPlatformTheme(const QString &name) const;
@@ -217,17 +195,19 @@ public:
virtual QOpenGLContext::OpenGLModuleType openGLModuleType();
#endif
virtual void setApplicationIcon(const QIcon &icon) const;
+ virtual void setApplicationBadge(qint64 number);
virtual void beep() const;
+ virtual void quit() const;
-#if QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC)
+#if QT_CONFIG(vulkan) || defined(Q_QDOC)
virtual QPlatformVulkanInstance *createPlatformVulkanInstance(QVulkanInstance *instance) const;
#endif
template <auto func, typename... Args>
auto call(Args... args)
{
- using namespace QPlatformInterface::Private;
+ using namespace QNativeInterface::Private;
return QInterfaceProxy<func>::apply(this, args...);
}
diff --git a/src/gui/kernel/qplatformintegrationfactory.cpp b/src/gui/kernel/qplatformintegrationfactory.cpp
index 3fcf9014a7..d0a5e8871f 100644
--- a/src/gui/kernel/qplatformintegrationfactory.cpp
+++ b/src/gui/kernel/qplatformintegrationfactory.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qpa/qplatformintegrationfactory_p.h>
#include <qpa/qplatformintegrationplugin.h>
@@ -48,27 +12,15 @@
QT_BEGIN_NAMESPACE
-Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
- (QPlatformIntegrationFactoryInterface_iid, QLatin1String("/platforms"), Qt::CaseInsensitive))
+using namespace Qt::StringLiterals;
-#if QT_CONFIG(library)
-Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, directLoader,
- (QPlatformIntegrationFactoryInterface_iid, QLatin1String(""), Qt::CaseInsensitive))
-#endif // QT_CONFIG(library)
+Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, piLoader,
+ (QPlatformIntegrationFactoryInterface_iid, "/platforms"_L1, Qt::CaseInsensitive))
QPlatformIntegration *QPlatformIntegrationFactory::create(const QString &platform, const QStringList &paramList, int &argc, char **argv, const QString &platformPluginPath)
{
-#if QT_CONFIG(library)
- // Try loading the plugin from platformPluginPath first:
- if (!platformPluginPath.isEmpty()) {
- QCoreApplication::addLibraryPath(platformPluginPath);
- if (QPlatformIntegration *ret = qLoadPlugin<QPlatformIntegration, QPlatformIntegrationPlugin>(directLoader(), platform, paramList, argc, argv))
- return ret;
- }
-#else
- Q_UNUSED(platformPluginPath);
-#endif
- return qLoadPlugin<QPlatformIntegration, QPlatformIntegrationPlugin>(loader(), platform, paramList, argc, argv);
+ piLoader->setExtraSearchPath(platformPluginPath);
+ return qLoadPlugin<QPlatformIntegration, QPlatformIntegrationPlugin>(piLoader(), platform, paramList, argc, argv);
}
/*!
@@ -80,25 +32,8 @@ QPlatformIntegration *QPlatformIntegrationFactory::create(const QString &platfor
QStringList QPlatformIntegrationFactory::keys(const QString &platformPluginPath)
{
- QStringList list;
-#if QT_CONFIG(library)
- if (!platformPluginPath.isEmpty()) {
- QCoreApplication::addLibraryPath(platformPluginPath);
- list = directLoader()->keyMap().values();
- if (!list.isEmpty()) {
- const QString postFix = QLatin1String(" (from ")
- + QDir::toNativeSeparators(platformPluginPath)
- + QLatin1Char(')');
- const QStringList::iterator end = list.end();
- for (QStringList::iterator it = list.begin(); it != end; ++it)
- (*it).append(postFix);
- }
- }
-#else
- Q_UNUSED(platformPluginPath);
-#endif
- list.append(loader()->keyMap().values());
- return list;
+ piLoader->setExtraSearchPath(platformPluginPath);
+ return piLoader->keyMap().values();
}
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformintegrationfactory_p.h b/src/gui/kernel/qplatformintegrationfactory_p.h
index 22c77ce8bd..0010815956 100644
--- a/src/gui/kernel/qplatformintegrationfactory_p.h
+++ b/src/gui/kernel/qplatformintegrationfactory_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMINTEGRATIONFACTORY_H
#define QPLATFORMINTEGRATIONFACTORY_H
diff --git a/src/gui/kernel/qplatformintegrationplugin.cpp b/src/gui/kernel/qplatformintegrationplugin.cpp
index b100eacbb5..faf32887c7 100644
--- a/src/gui/kernel/qplatformintegrationplugin.cpp
+++ b/src/gui/kernel/qplatformintegrationplugin.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformintegrationplugin.h"
@@ -52,16 +16,18 @@ QPlatformIntegrationPlugin::~QPlatformIntegrationPlugin()
QPlatformIntegration *QPlatformIntegrationPlugin::create(const QString &key, const QStringList &paramList)
{
- Q_UNUSED(key)
+ Q_UNUSED(key);
Q_UNUSED(paramList);
return nullptr;
}
QPlatformIntegration *QPlatformIntegrationPlugin::create(const QString &key, const QStringList &paramList, int &argc, char **argv)
{
- Q_UNUSED(argc)
- Q_UNUSED(argv)
+ Q_UNUSED(argc);
+ Q_UNUSED(argv);
return create(key, paramList); // Fallback for platform plugins that do not implement the argc/argv version.
}
QT_END_NAMESPACE
+
+#include "moc_qplatformintegrationplugin.cpp"
diff --git a/src/gui/kernel/qplatformintegrationplugin.h b/src/gui/kernel/qplatformintegrationplugin.h
index 6a0b9dc9a7..cf4915ad83 100644
--- a/src/gui/kernel/qplatformintegrationplugin.h
+++ b/src/gui/kernel/qplatformintegrationplugin.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMINTEGRATIONPLUGIN_H
#define QPLATFORMINTEGRATIONPLUGIN_H
diff --git a/src/gui/kernel/qplatformkeymapper.cpp b/src/gui/kernel/qplatformkeymapper.cpp
new file mode 100644
index 0000000000..f54e4ff379
--- /dev/null
+++ b/src/gui/kernel/qplatformkeymapper.cpp
@@ -0,0 +1,38 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qplatformkeymapper.h"
+
+#include <private/qguiapplication_p.h>
+#include <qpa/qplatformintegration.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(lcQpaKeyMapper, "qt.qpa.keymapper")
+
+QPlatformKeyMapper::~QPlatformKeyMapper()
+{
+}
+
+/*
+ Should return a list of possible key combinations for the given key event.
+
+ For example, given a US English keyboard layout, the key event Shift+5
+ can represent both a "Shift+5" key combination, as well as just "%".
+*/
+QList<QKeyCombination> QPlatformKeyMapper::possibleKeyCombinations(const QKeyEvent *event) const
+{
+ auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
+ QList<int> possibleKeys = platformIntegration->possibleKeys(event);
+ QList<QKeyCombination> combinations;
+ for (int key : possibleKeys)
+ combinations << QKeyCombination::fromCombined(key);
+ return combinations;
+}
+
+Qt::KeyboardModifiers QPlatformKeyMapper::queryKeyboardModifiers() const
+{
+ return QGuiApplicationPrivate::platformIntegration()->queryKeyboardModifiers();
+}
+
+QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformkeymapper.h b/src/gui/kernel/qplatformkeymapper.h
new file mode 100644
index 0000000000..fb5b0cdb8b
--- /dev/null
+++ b/src/gui/kernel/qplatformkeymapper.h
@@ -0,0 +1,36 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPLATFORMKEYMAPPER_P
+#define QPLATFORMKEYMAPPER_P
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is part of the QPA API and is not meant to be used
+// in applications. Usage of this API may make your code
+// source and binary incompatible with future versions of Qt.
+//
+
+#include <QtGui/qtguiglobal.h>
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_EXPORTED_LOGGING_CATEGORY(lcQpaKeyMapper, Q_GUI_EXPORT)
+
+class QKeyEvent;
+
+class Q_GUI_EXPORT QPlatformKeyMapper
+{
+public:
+ virtual ~QPlatformKeyMapper();
+
+ virtual QList<QKeyCombination> possibleKeyCombinations(const QKeyEvent *event) const;
+ virtual Qt::KeyboardModifiers queryKeyboardModifiers() const;
+};
+
+QT_END_NAMESPACE
+
+#endif // QPLATFORMKEYMAPPER_P
diff --git a/src/gui/kernel/qplatformmenu.cpp b/src/gui/kernel/qplatformmenu.cpp
index 0d76f2039d..d629c8b02d 100644
--- a/src/gui/kernel/qplatformmenu.cpp
+++ b/src/gui/kernel/qplatformmenu.cpp
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2014 Martin Graesslin <mgraesslin@kde.org>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2014 Martin Graesslin <mgraesslin@kde.org>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformmenu.h"
@@ -92,3 +56,5 @@ QPlatformMenu *QPlatformMenuBar::createMenu() const
}
QT_END_NAMESPACE
+
+#include "moc_qplatformmenu.cpp"
diff --git a/src/gui/kernel/qplatformmenu.h b/src/gui/kernel/qplatformmenu.h
index 8e470aefd3..fbb54f2af1 100644
--- a/src/gui/kernel/qplatformmenu.h
+++ b/src/gui/kernel/qplatformmenu.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author James Turner <james.turner@kdab.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author James Turner <james.turner@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMMENU_H
#define QPLATFORMMENU_H
@@ -49,13 +13,14 @@
// source and binary incompatible with future versions of Qt.
//
+#include <QtCore/qobject.h>
#include <QtGui/qtguiglobal.h>
#include <QtCore/qpointer.h>
-#include <QtGui/QFont>
+#include <QtGui/qfont.h>
#if QT_CONFIG(shortcut)
-# include <QtGui/QKeySequence>
+# include <QtGui/qkeysequence.h>
#endif
-#include <QtGui/QIcon>
+#include <QtGui/qicon.h>
QT_BEGIN_NAMESPACE
diff --git a/src/gui/kernel/qplatformmenu_p.h b/src/gui/kernel/qplatformmenu_p.h
new file mode 100644
index 0000000000..00e3fa56da
--- /dev/null
+++ b/src/gui/kernel/qplatformmenu_p.h
@@ -0,0 +1,55 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QPLATFORMMENU_P_H
+#define QPLATFORMMENU_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/private/qtguiglobal_p.h>
+
+#include <QtCore/qnativeinterface.h>
+
+QT_BEGIN_NAMESPACE
+
+// ----------------- QNativeInterface -----------------
+
+#if !defined(Q_OS_MACOS) && defined(Q_QDOC)
+typedef void NSMenu;
+#else
+QT_END_NAMESPACE
+Q_FORWARD_DECLARE_OBJC_CLASS(NSMenu);
+QT_BEGIN_NAMESPACE
+#endif
+
+namespace QNativeInterface::Private {
+
+#if defined(Q_OS_MACOS) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QCocoaMenu
+{
+ QT_DECLARE_NATIVE_INTERFACE(QCocoaMenu)
+ virtual NSMenu *nsMenu() const = 0;
+ virtual void setAsDockMenu() const = 0;
+};
+
+struct Q_GUI_EXPORT QCocoaMenuBar
+{
+ QT_DECLARE_NATIVE_INTERFACE(QCocoaMenuBar)
+ virtual NSMenu *nsMenu() const = 0;
+};
+#endif
+
+} // QNativeInterface::Private
+
+QT_END_NAMESPACE
+
+#endif // QPLATFORMMENU_P_H
diff --git a/src/gui/kernel/qplatformnativeinterface.cpp b/src/gui/kernel/qplatformnativeinterface.cpp
index 8c9e73fbc2..d010f0b7c6 100644
--- a/src/gui/kernel/qplatformnativeinterface.cpp
+++ b/src/gui/kernel/qplatformnativeinterface.cpp
@@ -1,43 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformnativeinterface.h"
+#include <QtCore/qvariant.h>
+#include <QtCore/qmap.h>
#include <QtGui/qcursor.h>
QT_BEGIN_NAMESPACE
@@ -137,7 +103,7 @@ QFunctionPointer QPlatformNativeInterface::platformFunction(const QByteArray &fu
*/
QVariantMap QPlatformNativeInterface::windowProperties(QPlatformWindow *window) const
{
- Q_UNUSED(window)
+ Q_UNUSED(window);
return QVariantMap();
}
@@ -175,3 +141,5 @@ void QPlatformNativeInterface::setWindowProperty(QPlatformWindow *window, const
}
QT_END_NAMESPACE
+
+#include "moc_qplatformnativeinterface.cpp"
diff --git a/src/gui/kernel/qplatformnativeinterface.h b/src/gui/kernel/qplatformnativeinterface.h
index 58c8f6b414..6e721ec71c 100644
--- a/src/gui/kernel/qplatformnativeinterface.h
+++ b/src/gui/kernel/qplatformnativeinterface.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMNATIVEINTERFACE_H
#define QPLATFORMNATIVEINTERFACE_H
diff --git a/src/gui/kernel/qplatformoffscreensurface.cpp b/src/gui/kernel/qplatformoffscreensurface.cpp
index c2952e166c..653b0c762a 100644
--- a/src/gui/kernel/qplatformoffscreensurface.cpp
+++ b/src/gui/kernel/qplatformoffscreensurface.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformoffscreensurface.h"
diff --git a/src/gui/kernel/qplatformoffscreensurface.h b/src/gui/kernel/qplatformoffscreensurface.h
index cef0fab7e1..227c04794a 100644
--- a/src/gui/kernel/qplatformoffscreensurface.h
+++ b/src/gui/kernel/qplatformoffscreensurface.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMOFFSCREENSURFACE_H
#define QPLATFORMOFFSCREENSURFACE_H
@@ -49,10 +13,13 @@
// source and binary incompatible with future versions of Qt.
//
-#include <QtGui/qtguiglobal.h>
#include "qplatformsurface.h"
+
+#include <QtGui/qoffscreensurface.h>
#include <QtCore/qscopedpointer.h>
+#include <QtCore/qnativeinterface.h>
+
QT_BEGIN_NAMESPACE
class QOffscreenSurface;
@@ -75,10 +42,24 @@ public:
protected:
QScopedPointer<QPlatformOffscreenSurfacePrivate> d_ptr;
+ friend class QOffscreenSurfacePrivate;
private:
Q_DISABLE_COPY(QPlatformOffscreenSurface)
};
+namespace QNativeInterface::Private {
+
+#if defined(Q_OS_ANDROID)
+struct Q_GUI_EXPORT QAndroidOffScreenIntegration
+{
+ QT_DECLARE_NATIVE_INTERFACE(QAndroidOffScreenIntegration)
+ virtual QOffscreenSurface *createOffscreenSurface(ANativeWindow *nativeSurface) const = 0;
+};
+#endif
+
+} // QNativeInterface::Private
+
+
QT_END_NAMESPACE
#endif // QPLATFORMOFFSCREENSURFACE_H
diff --git a/src/gui/kernel/qplatformopenglcontext.cpp b/src/gui/kernel/qplatformopenglcontext.cpp
index 839ec008aa..8391425caf 100644
--- a/src/gui/kernel/qplatformopenglcontext.cpp
+++ b/src/gui/kernel/qplatformopenglcontext.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformopenglcontext.h"
@@ -165,4 +129,20 @@ bool QPlatformOpenGLContext::parseOpenGLVersion(const QByteArray &versionString,
return (majorOk && minorOk);
}
+/*!
+ Called when the RHI begins rendering a new frame in the context. Will always be paired with a
+ call to \l endFrame().
+*/
+void QPlatformOpenGLContext::beginFrame()
+{
+}
+
+/*!
+ Called when the RHI ends rendering a in the context. Is always preceded by a call to
+ \l beginFrame().
+*/
+void QPlatformOpenGLContext::endFrame()
+{
+}
+
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformopenglcontext.h b/src/gui/kernel/qplatformopenglcontext.h
index 8c38d88b56..ac13c42655 100644
--- a/src/gui/kernel/qplatformopenglcontext.h
+++ b/src/gui/kernel/qplatformopenglcontext.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMOPENGLCONTEXT_H
#define QPLATFORMOPENGLCONTEXT_H
@@ -59,6 +23,8 @@
#include <QtGui/qopengl.h>
#include <QtGui/qopenglcontext.h>
+#include <QtCore/qnativeinterface.h>
+
QT_BEGIN_NAMESPACE
@@ -82,6 +48,9 @@ public:
virtual bool makeCurrent(QPlatformSurface *surface) = 0;
virtual void doneCurrent() = 0;
+ virtual void beginFrame();
+ virtual void endFrame();
+
virtual bool isSharing() const { return false; }
virtual bool isValid() const { return true; }
@@ -102,18 +71,12 @@ private:
Q_DISABLE_COPY(QPlatformOpenGLContext)
};
-template <typename T>
-T *QOpenGLContext::platformInterface() const
-{
- return dynamic_cast<T*>(handle());
-}
-
-namespace QPlatformInterface::Private {
+namespace QNativeInterface::Private {
#if defined(Q_OS_MACOS)
struct Q_GUI_EXPORT QCocoaGLIntegration
{
- QT_DECLARE_PLATFORM_INTERFACE(QCocoaGLIntegration)
+ QT_DECLARE_NATIVE_INTERFACE(QCocoaGLIntegration)
virtual QOpenGLContext *createOpenGLContext(NSOpenGLContext *, QOpenGLContext *shareContext) const = 0;
};
#endif
@@ -121,16 +84,16 @@ struct Q_GUI_EXPORT QCocoaGLIntegration
#if defined(Q_OS_WIN)
struct Q_GUI_EXPORT QWindowsGLIntegration
{
- QT_DECLARE_PLATFORM_INTERFACE(QWindowsGLIntegration)
+ QT_DECLARE_NATIVE_INTERFACE(QWindowsGLIntegration)
virtual HMODULE openGLModuleHandle() const = 0;
virtual QOpenGLContext *createOpenGLContext(HGLRC context, HWND window, QOpenGLContext *shareContext) const = 0;
};
#endif
-#if defined(Q_OS_LINUX)
+#if QT_CONFIG(xcb_glx_plugin)
struct Q_GUI_EXPORT QGLXIntegration
{
- QT_DECLARE_PLATFORM_INTERFACE(QGLXIntegration)
+ QT_DECLARE_NATIVE_INTERFACE(QGLXIntegration)
virtual QOpenGLContext *createOpenGLContext(GLXContext context, void *visualInfo, QOpenGLContext *shareContext) const = 0;
};
#endif
@@ -138,12 +101,12 @@ struct Q_GUI_EXPORT QGLXIntegration
#if QT_CONFIG(egl)
struct Q_GUI_EXPORT QEGLIntegration
{
- QT_DECLARE_PLATFORM_INTERFACE(QEGLIntegration)
+ QT_DECLARE_NATIVE_INTERFACE(QEGLIntegration)
virtual QOpenGLContext *createOpenGLContext(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext) const = 0;
};
#endif
-} // QPlatformInterface::Private
+} // QNativeInterface::Private
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp
index e2890eda1e..0369a0b12a 100644
--- a/src/gui/kernel/qplatformscreen.cpp
+++ b/src/gui/kernel/qplatformscreen.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformscreen.h"
#include <QtCore/qdebug.h>
@@ -47,6 +11,7 @@
#include <QtGui/qscreen.h>
#include <QtGui/qwindow.h>
#include <private/qhighdpiscaling_p.h>
+#include <private/qwindow_p.h>
QT_BEGIN_NAMESPACE
@@ -60,15 +25,11 @@ QPlatformScreen::QPlatformScreen()
QPlatformScreen::~QPlatformScreen()
{
Q_D(QPlatformScreen);
- if (d->screen) {
- qWarning("Manually deleting a QPlatformScreen. Call QWindowSystemInterface::handleScreenRemoved instead.");
- delete d->screen;
- }
+ Q_ASSERT_X(!d->screen, "QPlatformScreen",
+ "QPlatformScreens should be removed via QWindowSystemInterface::handleScreenRemoved()");
}
/*!
- \fn QPixmap QPlatformScreen::grabWindow(WId window, int x, int y, int width, int height) const
-
This function is called when Qt needs to be able to grab the content of a window.
Returns the content of the window specified with the WId handle within the boundaries of
@@ -93,8 +54,9 @@ QPixmap QPlatformScreen::grabWindow(WId window, int x, int y, int width, int hei
QWindow *QPlatformScreen::topLevelAt(const QPoint & pos) const
{
const QWindowList list = QGuiApplication::topLevelWindows();
- for (int i = list.size()-1; i >= 0; --i) {
- QWindow *w = list[i];
+ const auto crend = list.crend();
+ for (auto it = list.crbegin(); it != crend; ++it) {
+ QWindow *w = *it;
if (w->isVisible() && QHighDpi::toNativePixels(w->geometry(), w).contains(pos))
return w;
}
@@ -176,21 +138,16 @@ QSizeF QPlatformScreen::physicalSize() const
Reimplement this function in subclass to return the logical horizontal
and vertical dots per inch metrics of the screen.
- The logical dots per inch metrics are used by QFont to convert point sizes
- to pixel sizes.
+ The logical dots per inch metrics are used by Qt to scale the user interface.
- The default implementation uses the screen pixel size and physical size to
- compute the metrics.
+ The default implementation returns logicalBaseDpi(), which results in a
+ UI scale factor of 1.0.
\sa physicalSize
*/
QDpi QPlatformScreen::logicalDpi() const
{
- QSizeF ps = physicalSize();
- QSize s = geometry().size();
-
- return QDpi(25.4 * s.width() / ps.width(),
- 25.4 * s.height() / ps.height());
+ return logicalBaseDpi();
}
// Helper function for accessing the platform screen logical dpi
@@ -207,7 +164,7 @@ QPair<qreal, qreal> QPlatformScreen::overrideDpi(const QPair<qreal, qreal> &in)
default implementation returns 96.
QtGui will use this value (together with logicalDpi) to compute
- the scale factor when high-DPI scaling is enabled:
+ the scale factor when high-DPI scaling is enabled, as follows:
factor = logicalDPI / baseDPI
*/
QDpi QPlatformScreen::logicalBaseDpi() const
@@ -222,7 +179,6 @@ QDpi QPlatformScreen::logicalBaseDpi() const
implementation returns 1.0.
\sa QPlatformWindow::devicePixelRatio()
- \sa QPlatformScreen::pixelDensity()
*/
qreal QPlatformScreen::devicePixelRatio() const
{
@@ -230,24 +186,6 @@ qreal QPlatformScreen::devicePixelRatio() const
}
/*!
- Reimplement this function in subclass to return the pixel density of the
- screen. This is the scale factor needed to make a low-dpi application
- usable on this screen. The default implementation returns 1.0.
-
- Returning something else than 1.0 from this function causes Qt to
- apply the scale factor to the application's coordinate system.
- This is different from devicePixelRatio, which reports a scale
- factor already applied by the windowing system. A platform plugin
- typically implements one (or none) of these two functions.
-
- \sa QPlatformWindow::devicePixelRatio()
-*/
-qreal QPlatformScreen::pixelDensity() const
-{
- return 1.0;
-}
-
-/*!
Reimplement this function in subclass to return the vertical refresh rate
of the screen, in Hz.
@@ -379,11 +317,12 @@ QPlatformCursor *QPlatformScreen::cursor() const
*/
void QPlatformScreen::resizeMaximizedWindows()
{
- // 'screen()' still has the old geometry info while 'this' has the new geometry info
+ // 'screen()' still has the old geometry (in device independent pixels),
+ // while 'this' has the new geometry (in native pixels)
const QRect oldGeometry = screen()->geometry();
const QRect oldAvailableGeometry = screen()->availableGeometry();
- const QRect newGeometry = deviceIndependentGeometry();
- const QRect newAvailableGeometry = QHighDpi::fromNative(availableGeometry(), QHighDpiScaling::factor(this), newGeometry.topLeft());
+ const QRect newNativeGeometry = this->geometry();
+ const QRect newNativeAvailableGeometry = this->availableGeometry();
const bool supportsMaximizeUsingFullscreen = QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::MaximizeUsingFullscreenGeometry);
@@ -392,14 +331,19 @@ void QPlatformScreen::resizeMaximizedWindows()
if (!w->handle())
continue;
+ // Set QPlatformWindow size in native pixels, and let the platform's geometry
+ // change signals update the QWindow geomeyry. This way we make sure that the
+ // platform window geometry covers the entire (available) platform screen geometry,
+ // also when fractional DPRs introduce rounding errors in the device independent
+ // QWindow and QScreen sizes.
if (supportsMaximizeUsingFullscreen
&& w->windowState() & Qt::WindowMaximized
&& w->flags() & Qt::MaximizeUsingFullscreenGeometryHint) {
- w->setGeometry(newGeometry);
+ w->handle()->setGeometry(newNativeGeometry);
} else if (w->windowState() & Qt::WindowMaximized || w->geometry() == oldAvailableGeometry) {
- w->setGeometry(newAvailableGeometry);
+ w->handle()->setGeometry(newNativeAvailableGeometry);
} else if (w->windowState() & Qt::WindowFullScreen || w->geometry() == oldGeometry) {
- w->setGeometry(newGeometry);
+ w->handle()->setGeometry(newNativeGeometry);
}
}
}
@@ -490,13 +434,6 @@ QRect QPlatformScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation
return rect;
}
-QRect QPlatformScreen::deviceIndependentGeometry() const
-{
- qreal scaleFactor = QHighDpiScaling::factor(this);
- QRect nativeGeometry = geometry();
- return QRect(nativeGeometry.topLeft(), QHighDpi::fromNative(nativeGeometry.size(), scaleFactor));
-}
-
/*!
Returns a hint about this screen's subpixel layout structure.
@@ -554,9 +491,9 @@ void QPlatformScreen::setPowerState(PowerState state)
\since 5.9
*/
-QVector<QPlatformScreen::Mode> QPlatformScreen::modes() const
+QList<QPlatformScreen::Mode> QPlatformScreen::modes() const
{
- QVector<QPlatformScreen::Mode> list;
+ QList<QPlatformScreen::Mode> list;
list.append({geometry().size(), refreshRate()});
return list;
}
diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h
index 32ad047147..a547a635e9 100644
--- a/src/gui/kernel/qplatformscreen.h
+++ b/src/gui/kernel/qplatformscreen.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMSCREEN_H
#define QPLATFORMSCREEN_H
@@ -57,6 +21,7 @@
#include <QtCore/qrect.h>
#include <QtCore/qobject.h>
+#include <QtGui/qcolorspace.h>
#include <QtGui/qcursor.h>
#include <QtGui/qimage.h>
#include <QtGui/qwindowdefs.h>
@@ -77,6 +42,7 @@ typedef QPair<qreal, qreal> QDpi;
class Q_GUI_EXPORT QPlatformScreen
{
+ Q_GADGET
Q_DECLARE_PRIVATE(QPlatformScreen)
public:
@@ -114,12 +80,12 @@ public:
virtual int depth() const = 0;
virtual QImage::Format format() const = 0;
+ virtual QColorSpace colorSpace() const { return QColorSpace::SRgb; }
virtual QSizeF physicalSize() const;
virtual QDpi logicalDpi() const;
virtual QDpi logicalBaseDpi() const;
virtual qreal devicePixelRatio() const;
- virtual qreal pixelDensity() const;
virtual qreal refreshRate() const;
@@ -159,9 +125,6 @@ public:
static QTransform transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target);
static QRect mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect);
- // The platform screen's geometry in device independent coordinates
- QRect deviceIndependentGeometry() const;
-
static QDpi overrideDpi(const QDpi &in);
protected:
@@ -170,7 +133,7 @@ protected:
QScopedPointer<QPlatformScreenPrivate> d_ptr;
private:
- friend class QScreenPrivate;
+ friend class QScreen;
};
// Qt doesn't currently support running with no platform screen
diff --git a/src/gui/kernel/qplatformscreen_p.h b/src/gui/kernel/qplatformscreen_p.h
index d5dc7b471a..345a90845c 100644
--- a/src/gui/kernel/qplatformscreen_p.h
+++ b/src/gui/kernel/qplatformscreen_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMSCREEN_P_H
#define QPLATFORMSCREEN_P_H
@@ -53,6 +17,9 @@
#include <QtGui/private/qtguiglobal_p.h>
+#include <QtCore/qpointer.h>
+#include <QtCore/qnativeinterface.h>
+
QT_BEGIN_NAMESPACE
class QScreen;
@@ -63,6 +30,45 @@ public:
QPointer<QScreen> screen;
};
+// ----------------- QNativeInterface -----------------
+
+namespace QNativeInterface::Private {
+
+#if QT_CONFIG(xcb) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QXcbScreen
+{
+ QT_DECLARE_NATIVE_INTERFACE(QXcbScreen, 1, QScreen)
+ virtual int virtualDesktopNumber() const = 0;
+};
+#endif
+
+#if QT_CONFIG(vsp2) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QVsp2Screen
+{
+ QT_DECLARE_NATIVE_INTERFACE(QVsp2Screen, 1, QScreen)
+ virtual int addLayer(int dmabufFd, const QSize &size, const QPoint &position, uint drmPixelFormat, uint bytesPerLine) = 0;
+ virtual void setLayerBuffer(int id, int dmabufFd) = 0;
+ virtual void setLayerPosition(int id, const QPoint &position) = 0;
+ virtual void setLayerAlpha(int id, qreal alpha) = 0;
+ virtual bool removeLayer(int id) = 0;
+ virtual void addBlendListener(void (*callback)()) = 0;
+};
+#endif
+
+#if defined(Q_OS_WEBOS) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QWebOSScreen
+{
+ QT_DECLARE_NATIVE_INTERFACE(QWebOSScreen, 1, QScreen)
+ virtual int addLayer(void *gbm_bo, const QRectF &geometry) = 0;
+ virtual void setLayerBuffer(int id, void *gbm_bo) = 0;
+ virtual void setLayerGeometry(int id, const QRectF &geometry) = 0;
+ virtual void setLayerAlpha(int id, qreal alpha) = 0;
+ virtual bool removeLayer(int id) = 0;
+ virtual void addFlipListener(void (*callback)()) = 0;
+};
+#endif
+} // QNativeInterface::Private
+
QT_END_NAMESPACE
#endif // QPLATFORMSCREEN_P_H
diff --git a/src/gui/kernel/qplatformservices.cpp b/src/gui/kernel/qplatformservices.cpp
index fdc6a6c4aa..7ff2a6c2f8 100644
--- a/src/gui/kernel/qplatformservices.cpp
+++ b/src/gui/kernel/qplatformservices.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformservices.h"
@@ -55,6 +19,19 @@ QT_BEGIN_NAMESPACE
\brief The QPlatformServices provides the backend for desktop-related functionality.
*/
+/*!
+ \enum QPlatformServices::Capability
+
+ Capabilities are used to determine a specific platform service's availability.
+
+ \value ColorPickingFromScreen The platform natively supports color picking from screen.
+ This capability indicates that the platform supports "opaque" color picking, where the
+ platform implements a complete user experience for color picking and outputs a color.
+ This is in contrast to the application implementing the color picking user experience
+ (taking care of showing a cross hair, instructing the platform integration to obtain
+ the color at a given pixel, etc.). The related service function is pickColor().
+ */
+
QPlatformServices::QPlatformServices()
{ }
@@ -85,5 +62,18 @@ QByteArray QPlatformServices::desktopEnvironment() const
return QByteArray("UNKNOWN");
}
+QPlatformServiceColorPicker *QPlatformServices::colorPicker(QWindow *parent)
+{
+ Q_UNUSED(parent);
+ return nullptr;
+}
+
+bool QPlatformServices::hasCapability(Capability capability) const
+{
+ Q_UNUSED(capability)
+ return false;
+}
QT_END_NAMESPACE
+
+#include "moc_qplatformservices.cpp"
diff --git a/src/gui/kernel/qplatformservices.h b/src/gui/kernel/qplatformservices.h
index 5de96cfa7d..063247af08 100644
--- a/src/gui/kernel/qplatformservices.h
+++ b/src/gui/kernel/qplatformservices.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMSERVICES_H
#define QPLATFORMSERVICES_H
@@ -50,16 +14,32 @@
//
#include <QtGui/qtguiglobal.h>
+#include <QtCore/qobject.h>
QT_BEGIN_NAMESPACE
class QUrl;
+class QWindow;
+
+class Q_GUI_EXPORT QPlatformServiceColorPicker : public QObject
+{
+ Q_OBJECT
+public:
+ using QObject::QObject;
+ virtual void pickColor() = 0;
+Q_SIGNALS:
+ void colorPicked(const QColor &color);
+};
class Q_GUI_EXPORT QPlatformServices
{
public:
Q_DISABLE_COPY_MOVE(QPlatformServices)
+ enum Capability {
+ ColorPicking,
+ };
+
QPlatformServices();
virtual ~QPlatformServices() { }
@@ -67,6 +47,10 @@ public:
virtual bool openDocument(const QUrl &url);
virtual QByteArray desktopEnvironment() const;
+
+ virtual bool hasCapability(Capability capability) const;
+
+ virtual QPlatformServiceColorPicker *colorPicker(QWindow *parent = nullptr);
};
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformsessionmanager.cpp b/src/gui/kernel/qplatformsessionmanager.cpp
index a66fc6d016..2a8e621294 100644
--- a/src/gui/kernel/qplatformsessionmanager.cpp
+++ b/src/gui/kernel/qplatformsessionmanager.cpp
@@ -1,43 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Samuel Gaist <samuel.gaist@edeltech.ch>
-** Copyright (C) 2013 Teo Mrnjavac <teo@kde.org>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2013 Samuel Gaist <samuel.gaist@edeltech.ch>
+// Copyright (C) 2013 Teo Mrnjavac <teo@kde.org>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformsessionmanager.h"
@@ -118,14 +82,14 @@ QStringList QPlatformSessionManager::discardCommand() const
void QPlatformSessionManager::setManagerProperty(const QString &name, const QString &value)
{
- Q_UNUSED(name)
- Q_UNUSED(value)
+ Q_UNUSED(name);
+ Q_UNUSED(value);
}
void QPlatformSessionManager::setManagerProperty(const QString &name, const QStringList &value)
{
- Q_UNUSED(name)
- Q_UNUSED(value)
+ Q_UNUSED(name);
+ Q_UNUSED(value);
}
bool QPlatformSessionManager::isPhase2() const
diff --git a/src/gui/kernel/qplatformsessionmanager.h b/src/gui/kernel/qplatformsessionmanager.h
index c6c3984816..213d8dc07e 100644
--- a/src/gui/kernel/qplatformsessionmanager.h
+++ b/src/gui/kernel/qplatformsessionmanager.h
@@ -1,43 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Samuel Gaist <samuel.gaist@edeltech.ch>
-** Copyright (C) 2013 Teo Mrnjavac <teo@kde.org>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2013 Samuel Gaist <samuel.gaist@edeltech.ch>
+// Copyright (C) 2013 Teo Mrnjavac <teo@kde.org>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMSESSIONMANAGER_H
#define QPLATFORMSESSIONMANAGER_H
diff --git a/src/gui/kernel/qplatformsharedgraphicscache.cpp b/src/gui/kernel/qplatformsharedgraphicscache.cpp
index f6c4e3309e..c482a94426 100644
--- a/src/gui/kernel/qplatformsharedgraphicscache.cpp
+++ b/src/gui/kernel/qplatformsharedgraphicscache.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformsharedgraphicscache.h"
@@ -100,7 +64,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QPlatformSharedGraphicsCache::requestItems(const QByteArray &cacheId, const QVector<quint32> &itemIds)
+ \fn void QPlatformSharedGraphicsCache::requestItems(const QByteArray &cacheId, const QList<quint32> &itemIds)
Requests all the items in \a itemIds from the cache with the name \a cacheId.
@@ -116,7 +80,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QPlatformSharedGraphicsCache::insertItems(const QByteArray &cacheId, const QVector<quint32> &itemIds, const QVector<QImage> &items)
+ \fn void QPlatformSharedGraphicsCache::insertItems(const QByteArray &cacheId, const QList<quint32> &itemIds, const QList<QImage> &items)
Inserts the items in \a itemIds into the cache named \a cacheId. The appearance of
each item is stored in \a items. The format of the QImage objects is expected to match the
@@ -132,7 +96,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QPlatformSharedGraphicsCache::releaseItems(const QByteArray &cacheId, const QVector<quint32> &itemIds)
+ \fn void QPlatformSharedGraphicsCache::releaseItems(const QByteArray &cacheId, const QList<quint32> &itemIds)
Releases the reference to the items in \a itemIds from the cache named \a cacheId. This should
only be called when all references to the items have been released by the user, and they are no
@@ -140,20 +104,20 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QPlatformSharedGraphicsCache::itemsMissing(const QByteArray &cacheId, const QVector<quint32> &itemIds)
+ \fn void QPlatformSharedGraphicsCache::itemsMissing(const QByteArray &cacheId, const QList<quint32> &itemIds)
This signal is emitted when requestItems() has been called for one or more items in the
cache named \a cacheId which are not yet available in the cache. The user is then expected to
call insertItems() to update the cache with the respective items, at which point they will
become available to all clients of the shared cache.
- The vector \a itemIds contains the IDs of the items that need to be inserted into the cache.
+ The \a itemIds list contains the IDs of the items that need to be inserted into the cache.
\sa itemsAvailable(), insertItems(), requestItems()
*/
/*!
- \fn void QPlatformSharedGraphicsCache::itemsAvailable(const QByteArray &cacheId, void *bufferId, const QVector<quint32> &itemIds, const QVector<QPoint> &positionsInBuffer)
+ \fn void QPlatformSharedGraphicsCache::itemsAvailable(const QByteArray &cacheId, void *bufferId, const QList<quint32> &itemIds, const QList<QPoint> &positionsInBuffer)
This signal can be emitted at any time when either requestItems() or insertItems() has been
called by the application for one or more items in the cache named \a cacheId, as long as
@@ -167,8 +131,8 @@ QT_BEGIN_NAMESPACE
initialization. If it is a OpenGLTexture, its texture ID can be requested using the
textureIdForBuffer() function. The dimensions of the buffer are given by \a bufferSize.
- The items provided by the cache are identified in the \a itemIds vector. The
- \a positionsInBuffer vector contains the locations inside the buffer of each item. Each entry in
+ The items provided by the cache are identified in the \a itemIds list. The
+ \a positionsInBuffer list contains the locations inside the buffer of each item. Each entry in
\a positionsInBuffer corresponds to an item in \a itemIds.
The buffer and the items' locations within the buffer can be considered valid until an
@@ -179,7 +143,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QPlatformSharedGraphicsCache::itemsUpdated(const QByteArray &cacheId, void *bufferId, const QVector<quint32> &itemIds, const QVector<QPoint> &positionsInBuffer)
+ \fn void QPlatformSharedGraphicsCache::itemsUpdated(const QByteArray &cacheId, void *bufferId, const QList<quint32> &itemIds, const QList<QPoint> &positionsInBuffer)
This signal is similar in usage to the itemsAvailable() signal, but will be emitted when
the location of a previously requested or inserted item has been updated. The application
@@ -194,7 +158,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QPlatformSharedGraphicsCache::itemsInvalidated(const QByteArray &cacheId, const QVector<quint32> &itemIds)
+ \fn void QPlatformSharedGraphicsCache::itemsInvalidated(const QByteArray &cacheId, const QList<quint32> &itemIds)
This signal is emitted when the items given by \a itemIds in the cache named \a cacheId have
been removed from the cache and the previously reported information about them is considered
@@ -292,3 +256,5 @@ QT_BEGIN_NAMESPACE
*/
QT_END_NAMESPACE
+
+#include "moc_qplatformsharedgraphicscache.cpp"
diff --git a/src/gui/kernel/qplatformsharedgraphicscache.h b/src/gui/kernel/qplatformsharedgraphicscache.h
index 56e51188cc..4935a52bd6 100644
--- a/src/gui/kernel/qplatformsharedgraphicscache.h
+++ b/src/gui/kernel/qplatformsharedgraphicscache.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMSHAREDGRAPHICSCACHE_H
#define QPLATFORMSHAREDGRAPHICSCACHE_H
diff --git a/src/gui/kernel/qplatformsurface.cpp b/src/gui/kernel/qplatformsurface.cpp
index fdb2cf567d..39a1869de6 100644
--- a/src/gui/kernel/qplatformsurface.cpp
+++ b/src/gui/kernel/qplatformsurface.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformsurface.h"
#ifndef QT_NO_DEBUG_STREAM
@@ -68,6 +32,17 @@ QPlatformSurface::QPlatformSurface(QSurface *surface) : m_surface(surface)
{
}
+bool QPlatformSurface::isRasterSurface(QSurface *surface)
+{
+ switch (surface->surfaceType()) {
+ case QSurface::RasterSurface:
+ case QSurface::RasterGLSurface:
+ return true;
+ default:
+ return false;
+ };
+}
+
#ifndef QT_NO_DEBUG_STREAM
Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QPlatformSurface *surface)
{
diff --git a/src/gui/kernel/qplatformsurface.h b/src/gui/kernel/qplatformsurface.h
index 475f3ef330..f867d3df1b 100644
--- a/src/gui/kernel/qplatformsurface.h
+++ b/src/gui/kernel/qplatformsurface.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMSURFACE_H
#define QPLATFORMSURFACE_H
@@ -73,6 +37,8 @@ public:
QSurface *surface() const;
virtual QPlatformScreen *screen() const = 0;
+ static bool isRasterSurface(QSurface *surface);
+
private:
explicit QPlatformSurface(QSurface *surface);
diff --git a/src/gui/kernel/qplatformsystemtrayicon.cpp b/src/gui/kernel/qplatformsystemtrayicon.cpp
index 296beda0f9..0b21fe39f7 100644
--- a/src/gui/kernel/qplatformsystemtrayicon.cpp
+++ b/src/gui/kernel/qplatformsystemtrayicon.cpp
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2012 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Christoph Schleifenbaum <christoph.schleifenbaum@kdab.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2012 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Christoph Schleifenbaum <christoph.schleifenbaum@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformsystemtrayicon.h"
diff --git a/src/gui/kernel/qplatformsystemtrayicon.h b/src/gui/kernel/qplatformsystemtrayicon.h
index bd74a2cc0a..76a7ef03d9 100644
--- a/src/gui/kernel/qplatformsystemtrayicon.h
+++ b/src/gui/kernel/qplatformsystemtrayicon.h
@@ -1,47 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2012 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Christoph Schleifenbaum <christoph.schleifenbaum@kdab.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2012 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Christoph Schleifenbaum <christoph.schleifenbaum@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMSYSTEMTRAYICON_H
#define QPLATFORMSYSTEMTRAYICON_H
#include <QtGui/qtguiglobal.h>
+#include <qpa/qplatformscreen.h>
#include "QtCore/qobject.h"
#ifndef QT_NO_SYSTEMTRAYICON
@@ -49,7 +14,6 @@
QT_BEGIN_NAMESPACE
class QPlatformMenu;
-class QPlatformScreen;
class QIcon;
class QString;
class QRect;
@@ -57,7 +21,6 @@ class QRect;
class Q_GUI_EXPORT QPlatformSystemTrayIcon : public QObject
{
Q_OBJECT
- Q_MOC_INCLUDE(<qpa/qplatformscreen.h>)
public:
enum ActivationReason {
Unknown,
diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp
index 6d0c49c327..48978b849a 100644
--- a/src/gui/kernel/qplatformtheme.cpp
+++ b/src/gui/kernel/qplatformtheme.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformtheme.h"
@@ -64,6 +28,8 @@ QT_BEGIN_NAMESPACE
\ingroup qpa
\brief The QPlatformTheme class allows customizing the UI based on themes.
+ See the init_platform function in qguiapplication.cpp for the complete
+ platform initialization process.
*/
/*!
@@ -163,6 +129,30 @@ QT_BEGIN_NAMESPACE
\value ShowShortcutsInContextMenus (bool) Whether to display shortcut key sequences in context menus.
+ \value InteractiveResizeAcrossScreens (bool) Whether using the whole virtual geometry of all the screens
+ as basis for the resize.
+ This enum value has been added in Qt 6.2.
+
+ \value ShowDirectoriesFirst (bool) Whether directories should be shown
+ first (before files) in file dialogs.
+ This enum value was added in Qt 6.3.
+
+ \value PreselectFirstFileInDirectory (bool) Whether the first file in a directory
+ should be automatically selected when a file dialog opens.
+ This enum value was added in Qt 6.3.
+
+ \value ButtonPressKeys (QList<Qt::Key>) A list of keys that can be used to press buttons via keyboard input.
+
+ \value SetFocusOnTouchRelease (bool) Whether focus objects (line edits etc) should receive
+ input focus after a touch/mouse release.
+ This enum value has been added in Qt 6.5.
+
+ \value MouseCursorTheme (QString) Name of the mouse cursor theme.
+ This enum value has been added in Qt 6.5.
+
+ \value MouseCursorSize (QSize) Size of the mouse cursor.
+ This enum value has been added in Qt 6.5.
+
\sa themeHint(), QStyle::pixelMetric()
*/
@@ -335,7 +325,7 @@ const QKeyBinding QPlatformThemePrivate::keyBindings[] = {
{QKeySequence::InsertLineSeparator, 0, Qt::SHIFT | Qt::Key_Enter, KB_All},
{QKeySequence::InsertLineSeparator, 0, Qt::SHIFT | Qt::Key_Return, KB_All},
{QKeySequence::InsertLineSeparator, 0, Qt::META | Qt::Key_O, KB_Mac},
- {QKeySequence::SaveAs, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_S, KB_Gnome | KB_Mac},
+ {QKeySequence::SaveAs, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_S, KB_All},
{QKeySequence::Preferences, 0, Qt::CTRL | Qt::Key_Comma, KB_Mac},
{QKeySequence::Quit, 0, Qt::CTRL | Qt::Key_Q, KB_X11 | KB_Gnome | KB_KDE | KB_Mac},
{QKeySequence::FullScreen, 1, Qt::META | Qt::CTRL | Qt::Key_F, KB_Mac},
@@ -345,6 +335,7 @@ const QKeyBinding QPlatformThemePrivate::keyBindings[] = {
{QKeySequence::FullScreen, 1, Qt::Key_F11, KB_Win | KB_KDE},
{QKeySequence::Deselect, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_A, KB_X11},
{QKeySequence::DeleteCompleteLine, 0, Qt::CTRL | Qt::Key_U, KB_X11},
+ {QKeySequence::Backspace, 1, Qt::Key_Backspace, KB_Mac},
{QKeySequence::Backspace, 0, Qt::META | Qt::Key_H, KB_Mac},
{QKeySequence::Cancel, 0, Qt::Key_Escape, KB_All},
{QKeySequence::Cancel, 0, Qt::CTRL | Qt::Key_Period, KB_Mac}
@@ -362,7 +353,61 @@ QPlatformThemePrivate::~QPlatformThemePrivate()
delete systemPalette;
}
-Q_GUI_EXPORT QPalette qt_fusionPalette();
+Q_GUI_EXPORT QPalette qt_fusionPalette()
+{
+ auto theme = QGuiApplicationPrivate::platformTheme();
+ const bool darkAppearance = theme
+ ? theme->colorScheme() == Qt::ColorScheme::Dark
+ : false;
+ const QColor windowText = darkAppearance ? QColor(240, 240, 240) : Qt::black;
+ const QColor backGround = darkAppearance ? QColor(50, 50, 50) : QColor(239, 239, 239);
+ const QColor light = backGround.lighter(150);
+ const QColor mid = (backGround.darker(130));
+ const QColor midLight = mid.lighter(110);
+ const QColor base = darkAppearance ? backGround.darker(140) : Qt::white;
+ const QColor disabledBase(backGround);
+ const QColor dark = backGround.darker(150);
+ const QColor darkDisabled = QColor(209, 209, 209).darker(110);
+ const QColor text = darkAppearance ? windowText : Qt::black;
+ const QColor highlight = QColor(48, 140, 198);
+ const QColor hightlightedText = darkAppearance ? windowText : Qt::white;
+ const QColor disabledText = darkAppearance ? QColor(130, 130, 130) : QColor(190, 190, 190);
+ const QColor button = backGround;
+ const QColor shadow = dark.darker(135);
+ const QColor disabledShadow = shadow.lighter(150);
+ const QColor disabledHighlight(145, 145, 145);
+ QColor placeholder = text;
+ placeholder.setAlpha(128);
+
+ QPalette fusionPalette(windowText, backGround, light, dark, mid, text, base);
+ fusionPalette.setBrush(QPalette::Midlight, midLight);
+ fusionPalette.setBrush(QPalette::Button, button);
+ fusionPalette.setBrush(QPalette::Shadow, shadow);
+ fusionPalette.setBrush(QPalette::HighlightedText, hightlightedText);
+
+ fusionPalette.setBrush(QPalette::Disabled, QPalette::Text, disabledText);
+ fusionPalette.setBrush(QPalette::Disabled, QPalette::WindowText, disabledText);
+ fusionPalette.setBrush(QPalette::Disabled, QPalette::ButtonText, disabledText);
+ fusionPalette.setBrush(QPalette::Disabled, QPalette::Base, disabledBase);
+ fusionPalette.setBrush(QPalette::Disabled, QPalette::Dark, darkDisabled);
+ fusionPalette.setBrush(QPalette::Disabled, QPalette::Shadow, disabledShadow);
+
+ fusionPalette.setBrush(QPalette::Active, QPalette::Highlight, highlight);
+ fusionPalette.setBrush(QPalette::Inactive, QPalette::Highlight, highlight);
+ fusionPalette.setBrush(QPalette::Disabled, QPalette::Highlight, disabledHighlight);
+
+ fusionPalette.setBrush(QPalette::Active, QPalette::Accent, highlight);
+ fusionPalette.setBrush(QPalette::Inactive, QPalette::Accent, highlight);
+ fusionPalette.setBrush(QPalette::Disabled, QPalette::Accent, disabledHighlight);
+
+ fusionPalette.setBrush(QPalette::PlaceholderText, placeholder);
+
+ // Use a more legible light blue on dark backgrounds than the default Qt::blue.
+ if (darkAppearance)
+ fusionPalette.setBrush(QPalette::Link, highlight);
+
+ return fusionPalette;
+}
void QPlatformThemePrivate::initializeSystemPalette()
{
@@ -397,6 +442,11 @@ QPlatformDialogHelper *QPlatformTheme::createPlatformDialogHelper(DialogType typ
return nullptr;
}
+Qt::ColorScheme QPlatformTheme::colorScheme() const
+{
+ return Qt::ColorScheme::Unknown;
+}
+
const QPalette *QPlatformTheme::palette(Palette type) const
{
Q_D(const QPlatformTheme);
@@ -410,7 +460,7 @@ const QPalette *QPlatformTheme::palette(Palette type) const
const QFont *QPlatformTheme::font(Font type) const
{
- Q_UNUSED(type)
+ Q_UNUSED(type);
return nullptr;
}
@@ -473,6 +523,16 @@ QVariant QPlatformTheme::themeHint(ThemeHint hint) const
return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::UiEffects);
case QPlatformTheme::ShowShortcutsInContextMenus:
return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ShowShortcutsInContextMenus);
+ case QPlatformTheme::SetFocusOnTouchRelease:
+ return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::SetFocusOnTouchRelease);
+ case QPlatformTheme::FlickStartDistance:
+ return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::FlickStartDistance);
+ case QPlatformTheme::FlickMaximumVelocity:
+ return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::FlickMaximumVelocity);
+ case QPlatformTheme::FlickDeceleration:
+ return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::FlickDeceleration);
+ case QPlatformTheme::UnderlineShortcut:
+ return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::UnderlineShortcut);
default:
return QPlatformTheme::defaultThemeHint(hint);
}
@@ -563,7 +623,32 @@ QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint)
}
case MouseQuickSelectionThreshold:
return QVariant(10);
+ case InteractiveResizeAcrossScreens:
+ return true;
+ case ShowDirectoriesFirst:
+ return true;
+ case PreselectFirstFileInDirectory:
+ return false;
+ case ButtonPressKeys:
+ return QVariant::fromValue(QList<Qt::Key>({ Qt::Key_Space, Qt::Key_Select }));
+ case SetFocusOnTouchRelease:
+ return false;
+ case FlickStartDistance:
+ return QVariant(15);
+ case FlickMaximumVelocity:
+ return QVariant(2500);
+ case FlickDeceleration:
+ return QVariant(1500);
+ case MenuBarFocusOnAltPressRelease:
+ return false;
+ case MouseCursorTheme:
+ return QVariant(QString());
+ case MouseCursorSize:
+ return QVariant(QSize(16, 16));
+ case UnderlineShortcut:
+ return true;
}
+
return QVariant();
}
@@ -608,21 +693,6 @@ QIconEngine *QPlatformTheme::createIconEngine(const QString &iconName) const
return new QIconLoaderEngine(iconName);
}
-#if defined(Q_OS_MACX)
-static inline int maybeSwapShortcut(int shortcut)
-{
- if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
- uint oldshortcut = shortcut;
- shortcut &= ~(Qt::CTRL | Qt::META);
- if (oldshortcut & Qt::CTRL)
- shortcut |= Qt::META;
- if (oldshortcut & Qt::META)
- shortcut |= Qt::CTRL;
- }
- return shortcut;
-}
-#endif
-
#if QT_CONFIG(shortcut)
// mixed-mode predicate: all of these overloads are actually needed (but not all for every compiler)
struct ByStandardKey {
@@ -660,12 +730,8 @@ QList<QKeySequence> QPlatformTheme::keyBindings(QKeySequence::StandardKey key) c
if (!(it->platform & platform))
continue;
- uint shortcut =
-#if defined(Q_OS_MACX)
- maybeSwapShortcut(it->shortcut);
-#else
- it->shortcut;
-#endif
+ uint shortcut = it->shortcut.toCombined();
+
if (it->priority > 0)
list.prepend(QKeySequence(shortcut));
else
@@ -698,7 +764,7 @@ QString QPlatformTheme::standardButtonText(int button) const
QKeySequence QPlatformTheme::standardButtonShortcut(int button) const
{
- Q_UNUSED(button)
+ Q_UNUSED(button);
return QKeySequence();
}
#endif // QT_CONFIG(shortcut)
@@ -750,33 +816,38 @@ QString QPlatformTheme::defaultStandardButtonText(int button)
QString QPlatformTheme::removeMnemonics(const QString &original)
{
+ const auto mnemonicInParentheses = [](QStringView text) {
+ /* Format of mnemonics to remove is /\(&[^&]\)/ but accept full-width
+ forms of ( and ) as equivalent, for cross-platform compatibility with
+ MS (and consequent behavior of translators, see QTBUG-110829).
+ */
+ Q_ASSERT(text.size() == 4); // Caller's responsibility.
+ constexpr QChar wideOpen = u'\uff08', wideClose = u'\uff09';
+ if (!text.startsWith(u'(') && !text.startsWith(wideOpen))
+ return false;
+ if (text[1] != u'&' || text[2] == u'&')
+ return false;
+ return text.endsWith(u')') || text.endsWith(wideClose);
+ };
QString returnText(original.size(), u'\0');
int finalDest = 0;
- int currPos = 0;
- int l = original.length();
- while (l) {
- if (original.at(currPos) == QLatin1Char('&')) {
- ++currPos;
- --l;
- if (l == 0)
+ QStringView text(original);
+ while (!text.isEmpty()) {
+ if (text.startsWith(u'&')) {
+ text = text.sliced(1);
+ if (text.isEmpty())
break;
- } else if (original.at(currPos) == QLatin1Char('(') && l >= 4 &&
- original.at(currPos + 1) == QLatin1Char('&') &&
- original.at(currPos + 2) != QLatin1Char('&') &&
- original.at(currPos + 3) == QLatin1Char(')')) {
- /* remove mnemonics its format is "\s*(&X)" */
- int n = 0;
- while (finalDest > n && returnText.at(finalDest - n - 1).isSpace())
- ++n;
- finalDest -= n;
- currPos += 4;
- l -= 4;
+ } else if (text.size() >= 4 && mnemonicInParentheses(text.first(4))) {
+ // Advance over the matched mnemonic:
+ text = text.sliced(4);
+ // Also strip any leading space before it:
+ while (finalDest > 0 && returnText.at(finalDest - 1).isSpace())
+ --finalDest;
continue;
}
- returnText[finalDest] = original.at(currPos);
- ++currPos;
+ returnText[finalDest] = text.front();
+ text = text.sliced(1);
++finalDest;
- --l;
}
returnText.truncate(finalDest);
return returnText;
@@ -795,4 +866,11 @@ unsigned QPlatformThemePrivate::currentKeyPlatforms()
return result;
}
+QString QPlatformTheme::name() const
+{
+ return d_func()->name;
+}
+
QT_END_NAMESPACE
+
+#include "moc_qplatformtheme.cpp"
diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h
index 6ed612b785..c0193947b9 100644
--- a/src/gui/kernel/qplatformtheme.h
+++ b/src/gui/kernel/qplatformtheme.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMTHEME_H
#define QPLATFORMTHEME_H
@@ -50,6 +14,7 @@
//
#include <QtGui/qtguiglobal.h>
+#include <QtCore/QObject>
#include <QtCore/QScopedPointer>
#if QT_CONFIG(shortcut)
# include <QtGui/QKeySequence>
@@ -76,7 +41,9 @@ class QFileInfo;
class Q_GUI_EXPORT QPlatformTheme
{
+ Q_GADGET
Q_DECLARE_PRIVATE(QPlatformTheme)
+
public:
Q_DISABLE_COPY_MOVE(QPlatformTheme)
@@ -106,12 +73,7 @@ public:
KeyboardScheme,
UiEffects,
SpellCheckUnderlineStyle,
-#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
TabFocusBehavior,
-#else
- TabAllWidgets,
- TabFocusBehavior = TabAllWidgets,
-#endif
IconPixmapSizes,
PasswordMaskCharacter,
DialogSnapToDefaultButton,
@@ -122,8 +84,21 @@ public:
TouchDoubleTapDistance,
ShowShortcutsInContextMenus,
IconFallbackSearchPaths,
- MouseQuickSelectionThreshold
+ MouseQuickSelectionThreshold,
+ InteractiveResizeAcrossScreens,
+ ShowDirectoriesFirst,
+ PreselectFirstFileInDirectory,
+ ButtonPressKeys,
+ SetFocusOnTouchRelease,
+ FlickStartDistance,
+ FlickMaximumVelocity,
+ FlickDeceleration,
+ MenuBarFocusOnAltPressRelease,
+ MouseCursorTheme,
+ MouseCursorSize,
+ UnderlineShortcut,
};
+ Q_ENUM(ThemeHint)
enum DialogType {
FileDialog,
@@ -131,6 +106,7 @@ public:
FontDialog,
MessageDialog
};
+ Q_ENUM(DialogType);
enum Palette {
SystemPalette,
@@ -153,6 +129,7 @@ public:
TextLineEditPalette,
NPalettes
};
+ Q_ENUM(Palette)
enum Font {
SystemFont,
@@ -184,6 +161,7 @@ public:
EditorFont,
NFonts
};
+ Q_ENUM(Font)
enum StandardPixmap { // Keep in sync with QStyle::StandardPixmap
TitleBarMenuButton,
@@ -257,9 +235,20 @@ public:
MediaVolume,
MediaVolumeMuted,
LineEditClearButton,
+ DialogYesToAllButton,
+ DialogNoToAllButton,
+ DialogSaveAllButton,
+ DialogAbortButton,
+ DialogRetryButton,
+ DialogIgnoreButton,
+ RestoreDefaultsButton,
+ TabCloseButton,
+ NStandardPixmap, // assertion value for sync with QStyle::StandardPixmap
+
// do not add any values below/greater than this
CustomBase = 0xf0000000
};
+ Q_ENUM(StandardPixmap)
enum KeyboardSchemes
{
@@ -270,6 +259,7 @@ public:
GnomeKeyboardScheme,
CdeKeyboardScheme
};
+ Q_ENUM(KeyboardSchemes)
enum UiEffect
{
@@ -282,6 +272,7 @@ public:
AnimateToolBoxUiEffect = 0x40,
HoverEffect = 0x80
};
+ Q_ENUM(UiEffect)
enum IconOption {
DontUseCustomDirectoryIcons = 0x01
@@ -303,6 +294,8 @@ public:
virtual QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const;
#endif
+ virtual Qt::ColorScheme colorScheme() const;
+
virtual const QPalette *palette(Palette type = SystemPalette) const;
virtual const QFont *font(Font type = SystemFont) const;
@@ -326,10 +319,14 @@ public:
static QVariant defaultThemeHint(ThemeHint hint);
static QString defaultStandardButtonText(int button);
static QString removeMnemonics(const QString &original);
+ QString name() const;
protected:
explicit QPlatformTheme(QPlatformThemePrivate *priv);
QScopedPointer<QPlatformThemePrivate> d_ptr;
+
+private:
+ friend class QPlatformThemeFactory;
};
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformtheme_p.h b/src/gui/kernel/qplatformtheme_p.h
index 2c16fec141..e847ead3be 100644
--- a/src/gui/kernel/qplatformtheme_p.h
+++ b/src/gui/kernel/qplatformtheme_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMTHEME_P_H
#define QPLATFORMTHEME_P_H
@@ -77,6 +41,8 @@ public:
static unsigned currentKeyPlatforms();
QPalette *systemPalette;
+
+ QString name;
};
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformthemefactory.cpp b/src/gui/kernel/qplatformthemefactory.cpp
index 447d385abe..beefa1c294 100644
--- a/src/gui/kernel/qplatformthemefactory.cpp
+++ b/src/gui/kernel/qplatformthemefactory.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qpa/qplatformthemefactory_p.h>
#include <qpa/qplatformthemeplugin.h>
@@ -44,33 +8,26 @@
#include "qmutex.h"
#include "qguiapplication.h"
+#include "qplatformtheme.h"
+#include "qplatformtheme_p.h"
#include "qdebug.h"
QT_BEGIN_NAMESPACE
-Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
- (QPlatformThemeFactoryInterface_iid, QLatin1String("/platformthemes"), Qt::CaseInsensitive))
+using namespace Qt::StringLiterals;
-#if QT_CONFIG(library)
-Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, directLoader,
- (QPlatformThemeFactoryInterface_iid, QLatin1String(""), Qt::CaseInsensitive))
-#endif
+Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, ptLoader,
+ (QPlatformThemeFactoryInterface_iid, "/platformthemes"_L1, Qt::CaseInsensitive))
QPlatformTheme *QPlatformThemeFactory::create(const QString& key, const QString &platformPluginPath)
{
- QStringList paramList = key.split(QLatin1Char(':'));
+ QStringList paramList = key.split(u':');
const QString platform = paramList.takeFirst().toLower();
-#if QT_CONFIG(library)
- // Try loading the plugin from platformPluginPath first:
- if (!platformPluginPath.isEmpty()) {
- QCoreApplication::addLibraryPath(platformPluginPath);
- if (QPlatformTheme *ret = qLoadPlugin<QPlatformTheme, QPlatformThemePlugin>(directLoader(), platform, paramList))
- return ret;
- }
-#else
- Q_UNUSED(platformPluginPath);
-#endif
- return qLoadPlugin<QPlatformTheme, QPlatformThemePlugin>(loader(), platform, paramList);
+ ptLoader->setExtraSearchPath(platformPluginPath);
+ QPlatformTheme *theme = qLoadPlugin<QPlatformTheme, QPlatformThemePlugin>(ptLoader(), platform, paramList);
+ if (theme)
+ theme->d_func()->name = key;
+ return theme;
}
/*!
@@ -81,26 +38,8 @@ QPlatformTheme *QPlatformThemeFactory::create(const QString& key, const QString
*/
QStringList QPlatformThemeFactory::keys(const QString &platformPluginPath)
{
- QStringList list;
-
-#if QT_CONFIG(library)
- if (!platformPluginPath.isEmpty()) {
- QCoreApplication::addLibraryPath(platformPluginPath);
- list += directLoader()->keyMap().values();
- if (!list.isEmpty()) {
- const QString postFix = QLatin1String(" (from ")
- + QDir::toNativeSeparators(platformPluginPath)
- + QLatin1Char(')');
- const QStringList::iterator end = list.end();
- for (QStringList::iterator it = list.begin(); it != end; ++it)
- (*it).append(postFix);
- }
- }
-#else
- Q_UNUSED(platformPluginPath);
-#endif
- list += loader()->keyMap().values();
- return list;
+ ptLoader->setExtraSearchPath(platformPluginPath);
+ return ptLoader->keyMap().values();
}
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformthemefactory_p.h b/src/gui/kernel/qplatformthemefactory_p.h
index c312eadf27..c466dcd461 100644
--- a/src/gui/kernel/qplatformthemefactory_p.h
+++ b/src/gui/kernel/qplatformthemefactory_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMTHEMEFACTORY_H
#define QPLATFORMTHEMEFACTORY_H
diff --git a/src/gui/kernel/qplatformthemeplugin.cpp b/src/gui/kernel/qplatformthemeplugin.cpp
index c09476bee5..8b22680c05 100644
--- a/src/gui/kernel/qplatformthemeplugin.cpp
+++ b/src/gui/kernel/qplatformthemeplugin.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformthemeplugin.h"
@@ -60,3 +24,5 @@ QPlatformThemePlugin::~QPlatformThemePlugin()
}
QT_END_NAMESPACE
+
+#include "moc_qplatformthemeplugin.cpp"
diff --git a/src/gui/kernel/qplatformthemeplugin.h b/src/gui/kernel/qplatformthemeplugin.h
index 0f88806b0b..a983f4c5b7 100644
--- a/src/gui/kernel/qplatformthemeplugin.h
+++ b/src/gui/kernel/qplatformthemeplugin.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMTHEMEPLUGIN_H
#define QPLATFORMTHEMEPLUGIN_H
diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp
index fc736033c2..3baa48247b 100644
--- a/src/gui/kernel/qplatformwindow.cpp
+++ b/src/gui/kernel/qplatformwindow.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformwindow.h"
#include "qplatformwindow_p.h"
@@ -229,7 +193,7 @@ bool QPlatformWindow::isActive() const
*/
bool QPlatformWindow::isAncestorOf(const QPlatformWindow *child) const
{
- for (const QPlatformWindow *parent = child->parent(); parent; parent = child->parent()) {
+ for (const QPlatformWindow *parent = child->parent(); parent; parent = parent->parent()) {
if (parent == this)
return true;
}
@@ -266,6 +230,20 @@ QPoint QPlatformWindow::mapToGlobal(const QPoint &pos) const
return result;
}
+QPointF QPlatformWindow::mapToGlobalF(const QPointF &pos) const
+{
+ const QPoint posPt = pos.toPoint();
+ const QPointF delta = pos - posPt;
+ return mapToGlobal(posPt) + delta;
+}
+
+QPointF QPlatformWindow::mapFromGlobalF(const QPointF &pos) const
+{
+ const QPoint posPt = pos.toPoint();
+ const QPointF delta = pos - posPt;
+ return mapFromGlobal(posPt) + delta;
+}
+
/*!
Translates the global screen coordinate \a pos to window
coordinates using native methods. This is required for embedded windows,
@@ -392,18 +370,18 @@ void QPlatformWindow::setMask(const QRegion &region)
Reimplement to let Qt be able to request activation/focus for a window
Some window systems will probably not have callbacks for this functionality,
- and then calling QWindowSystemInterface::handleWindowActivated(QWindow *w)
+ and then calling QWindowSystemInterface::handleFocusWindowChanged(QWindow *w)
would be sufficient.
If the window system has some event handling/callbacks then call
- QWindowSystemInterface::handleWindowActivated(QWindow *w) when the window system
+ QWindowSystemInterface::handleFocusWindowChanged(QWindow *w) when the window system
gives the notification.
- Default implementation calls QWindowSystem::handleWindowActivated(QWindow *w)
+ Default implementation calls QWindowSystem::handleFocusWindowChanged(QWindow *w)
*/
void QPlatformWindow::requestActivateWindow()
{
- QWindowSystemInterface::handleWindowActivated(window());
+ QWindowSystemInterface::handleFocusWindowChanged(window());
}
/*!
@@ -492,7 +470,7 @@ bool QPlatformWindow::windowEvent(QEvent *event)
bool QPlatformWindow::startSystemResize(Qt::Edges edges)
{
- Q_UNUSED(edges)
+ Q_UNUSED(edges);
return false;
}
@@ -519,7 +497,7 @@ bool QPlatformWindow::startSystemMove()
void QPlatformWindow::setFrameStrutEventsEnabled(bool enabled)
{
- Q_UNUSED(enabled) // Do not warn as widgets enable it by default causing warnings with XCB.
+ Q_UNUSED(enabled); // Do not warn as widgets enable it by default causing warnings with XCB.
}
/*!
@@ -607,7 +585,7 @@ QSize QPlatformWindow::constrainWindowSize(const QSize &size)
void QPlatformWindow::setAlertState(bool enable)
{
- Q_UNUSED(enable)
+ Q_UNUSED(enable);
}
/*!
@@ -664,16 +642,16 @@ void QPlatformWindow::invalidateSurface()
{
}
-static QSize fixInitialSize(QSize size, const QWindow *w,
- int defaultWidth, int defaultHeight)
+static QSize fixInitialSize(QSize size, const QWindow *w, int deviceIndependentDefaultWidth,
+ int deviceIndependentDefaultHeight)
{
if (size.width() == 0) {
const int minWidth = w->minimumWidth();
- size.setWidth(minWidth > 0 ? minWidth : defaultWidth);
+ size.setWidth(minWidth > 0 ? minWidth : deviceIndependentDefaultWidth);
}
if (size.height() == 0) {
const int minHeight = w->minimumHeight();
- size.setHeight(minHeight > 0 ? minHeight : defaultHeight);
+ size.setHeight(minHeight > 0 ? minHeight : deviceIndependentDefaultHeight);
}
return size;
}
@@ -686,6 +664,10 @@ static QSize fixInitialSize(QSize size, const QWindow *w,
layout new windows to optimize usage of the available desktop space.
However if the given window already has geometry which the application has
initialized, it takes priority.
+
+ \a initialGeometry has to be provided in native pixels.
+ \a defaultWidth has to be provided in device independent pixels
+ \a defaultHeight has to be provided in device independent pixels
*/
QRect QPlatformWindow::initialGeometry(const QWindow *w, const QRect &initialGeometry,
int defaultWidth, int defaultHeight,
@@ -695,9 +677,10 @@ QRect QPlatformWindow::initialGeometry(const QWindow *w, const QRect &initialGeo
*resultingScreenReturn = w->screen();
if (!w->isTopLevel()) {
const qreal factor = QHighDpiScaling::factor(w);
- const QSize size = fixInitialSize(QHighDpi::fromNative(initialGeometry.size(), factor),
- w, defaultWidth, defaultHeight);
- return QRect(initialGeometry.topLeft(), QHighDpi::toNative(size, factor));
+ const QSize deviceIndependentSize =
+ fixInitialSize(QHighDpi::fromNative(initialGeometry.size(), factor), w,
+ defaultWidth, defaultHeight);
+ return QRect(initialGeometry.topLeft(), QHighDpi::toNative(deviceIndependentSize, factor));
}
const auto *wp = qt_window_private(const_cast<QWindow*>(w));
const bool position = wp->positionAutomatic && w->type() != Qt::Popup;
@@ -711,26 +694,28 @@ QRect QPlatformWindow::initialGeometry(const QWindow *w, const QRect &initialGeo
if (resultingScreenReturn)
*resultingScreenReturn = screen;
// initialGeometry refers to window's screen
- QRect rect(QHighDpi::fromNativePixels(initialGeometry, w));
+ QRect deviceIndependentRect(QHighDpi::fromNativePixels(initialGeometry, w));
if (wp->resizeAutomatic)
- rect.setSize(fixInitialSize(rect.size(), w, defaultWidth, defaultHeight));
+ deviceIndependentRect.setSize(
+ fixInitialSize(deviceIndependentRect.size(), w, defaultWidth, defaultHeight));
if (position) {
- const QRect availableGeometry = screen->availableGeometry();
+ const QRect availableDeviceIndependentGeometry = screen->availableGeometry();
// Center unless the geometry ( + unknown window frame) is too large for the screen).
- if (rect.height() < (availableGeometry.height() * 8) / 9
- && rect.width() < (availableGeometry.width() * 8) / 9) {
+ if (deviceIndependentRect.height() < (availableDeviceIndependentGeometry.height() * 8) / 9
+ && deviceIndependentRect.width()
+ < (availableDeviceIndependentGeometry.width() * 8) / 9) {
const QWindow *tp = w->transientParent();
if (tp) {
// A transient window should be centered w.r.t. its transient parent.
- rect.moveCenter(tp->geometry().center());
+ deviceIndependentRect.moveCenter(tp->geometry().center());
} else {
// Center the window on the screen. (Only applicable on platforms
// which do not provide a better way.)
- rect.moveCenter(availableGeometry.center());
+ deviceIndependentRect.moveCenter(availableDeviceIndependentGeometry.center());
}
}
}
- return QHighDpi::toNativePixels(rect, screen);
+ return QHighDpi::toNativePixels(deviceIndependentRect, screen);
}
/*!
@@ -742,20 +727,29 @@ QRect QPlatformWindow::initialGeometry(const QWindow *w, const QRect &initialGeo
should be delivered using QPlatformWindow::deliverUpdateRequest()
to not get out of sync with the internal state of QWindow.
- The default implementation posts an UpdateRequest event to the
- window after 5 ms. The additional time is there to give the event
- loop a bit of idle time to gather system events.
+ The default implementation posts an UpdateRequest event to the window after
+ an interval that is at most 5 ms. If the window's associated screen reports
+ a \l{QPlatformScreen::refreshRate()}{refresh rate} higher than 60 Hz, the
+ interval is scaled down to a valid smaller than 5. The additional time is
+ there to give the event loop a bit of idle time to gather system events.
*/
void QPlatformWindow::requestUpdate()
{
Q_D(QPlatformWindow);
- static int updateInterval = []() {
- bool ok = false;
- int customUpdateInterval = qEnvironmentVariableIntValue("QT_QPA_UPDATE_IDLE_TIME", &ok);
- return ok ? customUpdateInterval : 5;
- }();
+ static bool customUpdateIntervalValid = false;
+ static int customUpdateInterval = qEnvironmentVariableIntValue("QT_QPA_UPDATE_IDLE_TIME",
+ &customUpdateIntervalValid);
+ int updateInterval = customUpdateInterval;
+ if (!customUpdateIntervalValid) {
+ updateInterval = 5;
+ if (QPlatformScreen *currentScreen = screen()) {
+ const qreal refreshRate = currentScreen->refreshRate();
+ if (refreshRate > 60.0)
+ updateInterval /= refreshRate / 60.0;
+ }
+ }
Q_ASSERT(!d->updateTimer.isActive());
d->updateTimer.start(updateInterval, Qt::PreciseTimer, window());
@@ -835,7 +829,7 @@ QSize QPlatformWindow::windowSizeIncrement() const
*/
QRect QPlatformWindow::windowGeometry() const
{
- return QHighDpi::toNativePixels(window()->geometry(), window());
+ return QHighDpi::toNativeWindowGeometry(window()->geometry(), window());
}
/*!
@@ -843,7 +837,7 @@ QRect QPlatformWindow::windowGeometry() const
*/
QRect QPlatformWindow::windowFrameGeometry() const
{
- return QHighDpi::toNativePixels(window()->frameGeometry(), window());
+ return QHighDpi::toNativeWindowGeometry(window()->frameGeometry(), window());
}
/*!
@@ -854,10 +848,10 @@ QRect QPlatformWindow::windowFrameGeometry() const
QRectF QPlatformWindow::closestAcceptableGeometry(const QWindow *qWindow, const QRectF &nativeRect)
{
- const QRectF rectF = QHighDpi::fromNativePixels(nativeRect, qWindow);
+ const QRectF rectF = QHighDpi::fromNativeWindowGeometry(nativeRect, qWindow);
const QRectF correctedGeometryF = qt_window_private(const_cast<QWindow *>(qWindow))->closestAcceptableGeometry(rectF);
return !correctedGeometryF.isEmpty() && rectF != correctedGeometryF
- ? QHighDpi::toNativePixels(correctedGeometryF, qWindow) : nativeRect;
+ ? QHighDpi::toNativeWindowGeometry(correctedGeometryF, qWindow) : nativeRect;
}
QRectF QPlatformWindow::windowClosestAcceptableGeometry(const QRectF &nativeRect) const
diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h
index 7b85090cc0..b6e96a457e 100644
--- a/src/gui/kernel/qplatformwindow.h
+++ b/src/gui/kernel/qplatformwindow.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMWINDOW_H
#define QPLATFORMWINDOW_H
@@ -60,6 +24,7 @@
QT_BEGIN_NAMESPACE
+#define QWINDOWSIZE_MAX ((1<<24)-1)
class QPlatformScreen;
class QPlatformWindowPrivate;
@@ -111,9 +76,11 @@ public:
virtual bool isActive() const;
virtual bool isAncestorOf(const QPlatformWindow *child) const;
virtual bool isEmbedded() const;
- virtual bool isForeignWindow() const { return false; };
+ virtual bool isForeignWindow() const { return false; }
virtual QPoint mapToGlobal(const QPoint &pos) const;
+ QPointF mapToGlobalF(const QPointF &pos) const;
virtual QPoint mapFromGlobal(const QPoint &pos) const;
+ QPointF mapFromGlobalF(const QPointF &pos) const;
virtual void propagateSizeHints();
diff --git a/src/gui/kernel/qplatformwindow_p.h b/src/gui/kernel/qplatformwindow_p.h
index 00dae9334c..2bbdfd5bf9 100644
--- a/src/gui/kernel/qplatformwindow_p.h
+++ b/src/gui/kernel/qplatformwindow_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPLATFORMWINDOW_P_H
#define QPLATFORMWINDOW_P_H
@@ -54,9 +18,20 @@
#include <QtGui/private/qtguiglobal_p.h>
#include <QtCore/qbasictimer.h>
#include <QtCore/qrect.h>
+#include <QtCore/qnativeinterface.h>
+#include <QtGui/qwindow.h>
+
+#if QT_CONFIG(wayland)
+#include <any>
+#include <QtCore/qobject.h>
+
+struct wl_surface;
+#endif
QT_BEGIN_NAMESPACE
+class QMargins;
+
class QPlatformWindowPrivate
{
public:
@@ -64,6 +39,104 @@ public:
QBasicTimer updateTimer;
};
+// ----------------- QNativeInterface -----------------
+
+namespace QNativeInterface::Private {
+
+#if defined(Q_OS_WASM) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QWasmWindow
+{
+ QT_DECLARE_NATIVE_INTERFACE(QWasmWindow, 1, QWindow)
+ virtual emscripten::val document() const = 0;
+ virtual emscripten::val clientArea() const = 0;
+};
+#endif
+
+#if defined(Q_OS_MACOS) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QCocoaWindow
+{
+ QT_DECLARE_NATIVE_INTERFACE(QCocoaWindow, 1, QWindow)
+ virtual void setContentBorderEnabled(bool enable) = 0;
+ virtual QPoint bottomLeftClippedByNSWindowOffset() const = 0;
+};
+#endif
+
+#if QT_CONFIG(xcb) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QXcbWindow
+{
+ QT_DECLARE_NATIVE_INTERFACE(QXcbWindow, 1, QWindow)
+
+ enum WindowType {
+ None = 0x000000,
+ Normal = 0x000001,
+ Desktop = 0x000002,
+ Dock = 0x000004,
+ Toolbar = 0x000008,
+ Menu = 0x000010,
+ Utility = 0x000020,
+ Splash = 0x000040,
+ Dialog = 0x000080,
+ DropDownMenu = 0x000100,
+ PopupMenu = 0x000200,
+ Tooltip = 0x000400,
+ Notification = 0x000800,
+ Combo = 0x001000,
+ Dnd = 0x002000,
+ KdeOverride = 0x004000
+ };
+ Q_DECLARE_FLAGS(WindowTypes, WindowType)
+
+ virtual void setWindowType(WindowTypes type) = 0;
+ virtual void setWindowRole(const QString &role) = 0;
+ virtual void setWindowIconText(const QString &text) = 0;
+ virtual uint visualId() const = 0;
+};
+#endif // xcb
+
+#if defined(Q_OS_WIN) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QWindowsWindow
+{
+ QT_DECLARE_NATIVE_INTERFACE(QWindowsWindow, 1, QWindow)
+
+ virtual void setHasBorderInFullScreen(bool border) = 0;
+ virtual bool hasBorderInFullScreen() const = 0;
+
+ virtual QMargins customMargins() const = 0;
+ virtual void setCustomMargins(const QMargins &margins) = 0;
+};
+#endif // Q_OS_WIN
+
+#if QT_CONFIG(wayland)
+struct Q_GUI_EXPORT QWaylandWindow : public QObject
+{
+ Q_OBJECT
+public:
+ QT_DECLARE_NATIVE_INTERFACE(QWaylandWindow, 1, QWindow)
+
+ virtual wl_surface *surface() const = 0;
+ virtual void setCustomMargins(const QMargins &margins) = 0;
+ virtual void requestXdgActivationToken(uint serial) = 0;
+ template<typename T>
+ T *surfaceRole() const
+ {
+ std::any anyRole = _surfaceRole();
+ auto role = std::any_cast<T *>(&anyRole);
+ return role ? *role : nullptr;
+ }
+Q_SIGNALS:
+ void surfaceCreated();
+ void surfaceDestroyed();
+ void surfaceRoleCreated();
+ void surfaceRoleDestroyed();
+ void xdgActivationTokenCreated(const QString &token);
+
+protected:
+ virtual std::any _surfaceRole() const = 0;
+};
+#endif
+
+} // QNativeInterface::Private
+
QT_END_NAMESPACE
#endif // QPLATFORMWINDOW_P_H
diff --git a/src/gui/kernel/qpointingdevice.cpp b/src/gui/kernel/qpointingdevice.cpp
index 97bc8f5554..c4c1e5fd5c 100644
--- a/src/gui/kernel/qpointingdevice.cpp
+++ b/src/gui/kernel/qpointingdevice.cpp
@@ -1,44 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qpointingdevice.h"
#include "qpointingdevice_p.h"
+#include "qwindowsysteminterface_p.h"
+#include "qeventpoint_p.h"
+
#include <QList>
#include <QLoggingCategory>
#include <QMutex>
@@ -48,7 +15,9 @@
QT_BEGIN_NAMESPACE
-Q_DECLARE_LOGGING_CATEGORY(lcQpaInputDevices)
+using namespace Qt::StringLiterals;
+
+Q_LOGGING_CATEGORY(lcPointerGrab, "qt.pointer.grab");
/*!
\class QPointingDevice
@@ -79,7 +48,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcQpaInputDevices)
In this type of device, the touch surface and display are integrated.
This means the surface and display typically have the same size, such
that there is a direct relationship between the touch points' physical
- positions and the coordinate reported by QTouchEvent::TouchPoint. As a
+ positions and the coordinate reported by QEventPoint. As a
result, Qt allows the user to interact directly with multiple QWidgets,
QGraphicsItems, or Qt Quick Items at the same time.
@@ -103,6 +72,9 @@ Q_DECLARE_LOGGING_CATEGORY(lcQpaInputDevices)
A device that is similar to a flat mouse with a transparent circle with
cross-hairs.
+ \value Keyboard
+ A keyboard.
+
\value AllDevices
Any of the above (used as a default filter value).
*/
@@ -133,53 +105,61 @@ Q_DECLARE_LOGGING_CATEGORY(lcQpaInputDevices)
\value Eraser
The other end of the stylus (if it has a virtual eraser on the other end).
\value Cursor
- A transparent circle with cross-hairs as found on a \l {DeviceType.Puck}{Puck} device.
+ A transparent circle with cross-hairs as found on a
+ \l {QInputDevice::DeviceType}{Puck} device.
\value AllPointerTypes
Any of the above (used as a default filter value).
*/
-/*! \enum QPointingDevice::Capability
+/*! \enum QPointingDevice::GrabTransition
- This enum is used with QPointingDevice::capabilities() to indicate what kind of information the
- touch device or its driver can provide.
+ This enum represents a transition of exclusive or passive grab
+ from one object (possibly \c nullptr) to another (possibly \c nullptr).
+ It is emitted as an argument of the QPointingDevice::grabChanged() signal.
- \value Position
- Indicates that position information is available, meaning that the
- pos() family of functions in the touch points return valid points.
-
- \value Area
- Indicates that touch area information is available, meaning that the
- rect() family of functions in the touch points return valid rectangles.
+ Valid values are:
- \value Pressure
- Indicates that pressure information is available, meaning that
- QPointerEvent::EventPoint::pressure() returns a valid value.
+ \value GrabExclusive
+ Emitted after QPointerEvent::setExclusiveGrabber().
+ \value UngrabExclusive
+ Emitted after QPointerEvent::setExclusiveGrabber() when the grabber is
+ set to \c nullptr, to notify that the grab has terminated normally.
+ \value CancelGrabExclusive
+ Emitted after QPointerEvent::setExclusiveGrabber() when the grabber is set
+ to a different object, to notify that the old grabber's grab is "stolen".
+ \value GrabPassive
+ Emitted after QPointerEvent::addPassiveGrabber().
+ \value UngrabPassive
+ Emitted when a passive grab is terminated normally,
+ for example after QPointerEvent::removePassiveGrabber().
+ \value CancelGrabPassive
+ Emitted when a passive grab is terminated abnormally (a gesture is canceled).
+ \value OverrideGrabPassive
+ This value is not currently used.
+*/
- \value Velocity
- Indicates that velocity information is available, meaning that
- QPointerEvent::EventPoint::velocity() returns a valid vector.
+/*! \fn void QPointingDevice::grabChanged(QObject *grabber, QPointingDevice::GrabTransition transition, const QPointerEvent *event, const QEventPoint &point) const
- \value RawPositions
- Indicates that the list returned by
- QPointerEvent::EventPoint::rawScreenPositions() may contain one or more
- positions for each touch point. This is relevant when the touch input
- gets filtered or corrected on the driver level.
+ This signal is emitted when the \a grabber object gains or loses an
+ exclusive or passive grab of \a point during delivery of \a event.
+ The \a transition tells what happened, from the perspective of the
+ \c grabber object.
- \value NormalizedPosition
- Indicates that the normalized position is available, meaning that
- QPointerEvent::EventPoint::normalizedPos() returns a valid value.
+ \note A grab transition from one object to another results in two signals,
+ to notify that one object has lost its grab, and to notify that there is
+ another grabber. In other cases, when transitioning to or from a non-grabbing
+ state, only one signal is emitted: the \a grabber argument is never \c nullptr.
- \value MouseEmulation
- Indicates that the device synthesizes mouse events.
+ \sa QPointerEvent::setExclusiveGrabber(), QPointerEvent::addPassiveGrabber(), QPointerEvent::removePassiveGrabber()
*/
/*!
- Creates a new invalid pointing device instance.
+ Creates a new invalid pointing device instance as a child of \a parent.
*/
-QPointingDevice::QPointingDevice()
- : QInputDevice(*(new QPointingDevicePrivate(QLatin1String("unknown"), -1,
+QPointingDevice::QPointingDevice(QObject *parent)
+ : QInputDevice(*(new QPointingDevicePrivate("unknown"_L1, -1,
DeviceType::Unknown, PointerType::Unknown,
- Capability::None, 0, 0)))
+ Capability::None, 0, 0)), parent)
{
}
@@ -189,8 +169,8 @@ QPointingDevice::~QPointingDevice()
/*!
Creates a new pointing device instance with the given
- \a deviceType, \a pointerType, \a capabilities, \a maxPoints,
- \a buttonCount, \a name, \a id and \a seatId.
+ \a name, \a deviceType, \a pointerType, \a capabilities, \a maxPoints,
+ \a buttonCount, \a seatName, \a uniqueId and \a parent.
*/
QPointingDevice::QPointingDevice(const QString &name, qint64 id, QInputDevice::DeviceType deviceType,
QPointingDevice::PointerType pointerType, Capabilities capabilities, int maxPoints, int buttonCount,
@@ -207,9 +187,10 @@ QPointingDevice::QPointingDevice(QPointingDevicePrivate &d, QObject *parent)
{
}
+#if QT_DEPRECATED_SINCE(6, 0)
/*!
\internal
- \deprecated Please use the constructor rather than setters.
+ \deprecated [6.0] Please use the constructor rather than setters.
Sets the device type \a devType and infers the pointer type.
*/
@@ -240,7 +221,7 @@ void QPointingDevice::setType(DeviceType devType)
/*!
\internal
- \deprecated Please use the constructor rather than setters.
+ \deprecated [6.0] Please use the constructor rather than setters.
*/
void QPointingDevice::setCapabilities(QInputDevice::Capabilities caps)
{
@@ -250,13 +231,14 @@ void QPointingDevice::setCapabilities(QInputDevice::Capabilities caps)
/*!
\internal
- \deprecated Please use the constructor rather than setters.
+ \deprecated [6.0] Please use the constructor rather than setters.
*/
void QPointingDevice::setMaximumTouchPoints(int c)
{
Q_D(QPointingDevice);
d->maximumTouchPoints = c;
}
+#endif // QT_DEPRECATED_SINCE(6, 0)
/*!
Returns the pointer type.
@@ -314,7 +296,7 @@ const QPointingDevice *QPointingDevice::primaryPointingDevice(const QString& sea
const QPointingDevice *mouse = nullptr;
const QPointingDevice *touchpad = nullptr;
for (const QInputDevice *dev : v) {
- if (dev->seatName() != seatName)
+ if (!seatName.isNull() && dev->seatName() != seatName)
continue;
if (dev->type() == QInputDevice::DeviceType::Mouse) {
if (!mouse)
@@ -331,55 +313,378 @@ const QPointingDevice *QPointingDevice::primaryPointingDevice(const QString& sea
qCDebug(lcQpaInputDevices) << "no mouse-like devices registered for seat" << seatName
<< "The platform plugin should have provided one via "
"QWindowSystemInterface::registerInputDevice(). Creating a default mouse for now.";
- mouse = new QPointingDevice(QLatin1String("core pointer"), 1, DeviceType::Mouse,
+ mouse = new QPointingDevice("core pointer"_L1, 1, DeviceType::Mouse,
PointerType::Generic, Capability::Position, 1, 3, seatName,
QPointingDeviceUniqueId(), QCoreApplication::instance());
QInputDevicePrivate::registerDevice(mouse);
return mouse;
}
- if (v.length() > 1)
+ if (v.size() > 1)
qCDebug(lcQpaInputDevices) << "core pointer ambiguous for seat" << seatName;
if (mouse)
return mouse;
return touchpad;
}
+QPointingDevicePrivate::~QPointingDevicePrivate()
+ = default;
+
/*!
+ \internal
Finds the device instance belonging to the drawing or eraser end of a particular stylus,
- identified by its \a deviceType, \a pointerType and \a uniqueId. The given \a busId
- may be used to update the stored USB ID, if it was not known before.
+ identified by its \a deviceType, \a pointerType, \a uniqueId and \a systemId.
+ Returns the device found, or \c nullptr if none was found.
+
+ If \a systemId is \c 0, it's not significant for the search.
+
+ If an instance matching the given \a deviceType and \a pointerType but with
+ only a default-constructed \c uniqueId is found, it will be assumed to be
+ the one we're looking for, its \c uniqueId will be updated to match the
+ given \a uniqueId, and its \c capabilities will be updated to match the
+ given \a capabilities. This is for the benefit of any platform plugin that can
+ discover the tablet itself at startup, along with the supported stylus types,
+ but then discovers specific styli later on as they come into proximity.
*/
-const QPointingDevice *QPointingDevice::tabletDevice(QInputDevice::DeviceType deviceType,
- QPointingDevice::PointerType pointerType,
- QPointingDeviceUniqueId uniqueId, quint32 busId)
+const QPointingDevice *QPointingDevicePrivate::queryTabletDevice(QInputDevice::DeviceType deviceType,
+ QPointingDevice::PointerType pointerType,
+ QPointingDeviceUniqueId uniqueId,
+ QPointingDevice::Capabilities capabilities,
+ qint64 systemId)
{
const auto &devices = QInputDevice::devices();
for (const QInputDevice *dev : devices) {
- if (dev->type() < DeviceType::Puck || dev->type() > DeviceType::Airbrush)
+ if (dev->type() < QPointingDevice::DeviceType::Puck || dev->type() > QPointingDevice::DeviceType::Airbrush)
continue;
const QPointingDevice *pdev = static_cast<const QPointingDevice *>(dev);
const auto devPriv = QPointingDevicePrivate::get(pdev);
bool uniqueIdDiscovered = (devPriv->uniqueId.numericId() == 0 && uniqueId.numericId() != 0);
if (devPriv->deviceType == deviceType && devPriv->pointerType == pointerType &&
+ (!systemId || devPriv->systemId == systemId) &&
(devPriv->uniqueId == uniqueId || uniqueIdDiscovered)) {
if (uniqueIdDiscovered) {
const_cast<QPointingDevicePrivate *>(devPriv)->uniqueId = uniqueId;
- qCDebug(lcQpaInputDevices) << "discovered unique ID of tablet tool" << pdev;
- }
- if (devPriv->busId.isEmpty() && busId) {
- const_cast<QPointingDevicePrivate *>(devPriv)->busId = QString::number(busId, 16);
- qCDebug(lcQpaInputDevices) << "discovered USB ID" << devPriv->busId << "of" << pdev;
+ if (capabilities)
+ const_cast<QPointingDevicePrivate *>(devPriv)->capabilities = capabilities;
+ qCDebug(lcQpaInputDevices) << "discovered unique ID and capabilities of tablet tool" << pdev;
}
return pdev;
}
}
- qCDebug(lcQpaInputDevices) << "failed to find registered tablet device" << deviceType << pointerType << Qt::hex << uniqueId.numericId()
- << "The platform plugin should have provided one via "
- "QWindowSystemInterface::registerInputDevice(). Creating a default one for now.";
- QPointingDevice *dev = new QPointingDevice(QLatin1String("fake tablet"), 2, deviceType, pointerType,
- QInputDevice::Capability::Position | QInputDevice::Capability::Pressure,
- 1, 1, QString(), uniqueId);
- QInputDevicePrivate::registerDevice(dev);
+ return nullptr;
+}
+
+/*!
+ \internal
+ Finds the device instance identified by its \a systemId.
+ Returns the device found, or \c nullptr if none was found.
+*/
+const QPointingDevice *QPointingDevicePrivate::pointingDeviceById(qint64 systemId)
+{
+ const auto &devices = QInputDevice::devices();
+ for (const QInputDevice *dev : devices) {
+ if (dev->type() >= QPointingDevice::DeviceType::Keyboard)
+ continue;
+ const QPointingDevice *pdev = static_cast<const QPointingDevice *>(dev);
+ const auto devPriv = QPointingDevicePrivate::get(pdev);
+ if (devPriv->systemId == systemId)
+ return pdev;
+ }
+ return nullptr;
+}
+
+/*!
+ \internal
+ First, ensure that the \a cancelEvent's QTouchEvent::points() list contains
+ all points that have exclusive grabs. Then send the event to each object
+ that has an exclusive grab of any of the points.
+*/
+void QPointingDevicePrivate::sendTouchCancelEvent(QTouchEvent *cancelEvent)
+{
+ // An incoming TouchCancel event will typically not contain any points, but
+ // QQuickPointerHandler::onGrabChanged needs to be called for each point
+ // that has an exclusive grabber. Adding those points to the event makes it
+ // an easy iteration there.
+ if (cancelEvent->points().isEmpty()) {
+ for (auto &epd : activePoints.values()) {
+ if (epd.exclusiveGrabber)
+ QMutableTouchEvent::from(cancelEvent)->addPoint(epd.eventPoint);
+ }
+ }
+ for (auto &epd : activePoints.values()) {
+ if (epd.exclusiveGrabber)
+ QCoreApplication::sendEvent(epd.exclusiveGrabber, cancelEvent);
+ // The next touch event can only be a TouchBegin, so clean up.
+ cancelEvent->setExclusiveGrabber(epd.eventPoint, nullptr);
+ cancelEvent->clearPassiveGrabbers(epd.eventPoint);
+ }
+}
+
+/*! \internal
+ Returns the active EventPointData instance with the given \a id, if available,
+ or \c nullptr if not.
+*/
+QPointingDevicePrivate::EventPointData *QPointingDevicePrivate::queryPointById(int id) const
+{
+ auto it = activePoints.find(id);
+ if (it == activePoints.end())
+ return nullptr;
+ return &it.value();
+}
+
+/*! \internal
+ Returns the active EventPointData instance with the given \a id, if available;
+ if not, appends a new instance and returns it.
+*/
+QPointingDevicePrivate::EventPointData *QPointingDevicePrivate::pointById(int id) const
+{
+ const auto [it, inserted] = activePoints.try_emplace(id);
+ if (inserted) {
+ Q_Q(const QPointingDevice);
+ auto &epd = it.value();
+ QMutableEventPoint::setId(epd.eventPoint, id);
+ QMutableEventPoint::setDevice(epd.eventPoint, q);
+ }
+ return &it.value();
+}
+
+/*! \internal
+ Remove the active EventPointData instance with the given \a id.
+*/
+void QPointingDevicePrivate::removePointById(int id)
+{
+ activePoints.remove(id);
+}
+
+/*!
+ \internal
+ Find the first non-null target (widget) via QMutableEventPoint::target()
+ in the active points. This is the widget that will receive any event that
+ comes from a touchpad, even if some of the touchpoints fall spatially on
+ other windows.
+*/
+QObject *QPointingDevicePrivate::firstActiveTarget() const
+{
+ for (auto &pt : activePoints.values()) {
+ if (auto target = QMutableEventPoint::target(pt.eventPoint))
+ return target;
+ }
+ return nullptr;
+}
+
+/*! \internal
+ Find the first non-null QWindow instance via QMutableEventPoint::window()
+ in the active points. This is the window that will receive any event that
+ comes from a touchpad, even if some of the touchpoints fall spatially on
+ other windows.
+*/
+QWindow *QPointingDevicePrivate::firstActiveWindow() const
+{
+ for (auto &pt : activePoints.values()) {
+ if (auto window = QMutableEventPoint::window(pt.eventPoint))
+ return window;
+ }
+ return nullptr;
+}
+
+/*! \internal
+ Return the exclusive grabber of the first point in activePoints.
+ This is mainly for autotests that try to verify the "current" grabber
+ outside the context of event delivery, which is something that the rest
+ of the codebase should not be doing.
+*/
+QObject *QPointingDevicePrivate::firstPointExclusiveGrabber() const
+{
+ if (activePoints.isEmpty())
+ return nullptr;
+ return activePoints.values().first().exclusiveGrabber;
+}
+
+void QPointingDevicePrivate::setExclusiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *exclusiveGrabber)
+{
+ Q_Q(QPointingDevice);
+ auto persistentPoint = queryPointById(point.id());
+ if (!persistentPoint) {
+ qWarning() << "point is not in activePoints" << point;
+ return;
+ }
+ Q_ASSERT(persistentPoint->eventPoint.id() == point.id());
+ if (persistentPoint->exclusiveGrabber == exclusiveGrabber)
+ return;
+ auto oldGrabber = persistentPoint->exclusiveGrabber;
+ persistentPoint->exclusiveGrabber = exclusiveGrabber;
+ if (oldGrabber)
+ emit q->grabChanged(oldGrabber, exclusiveGrabber ? QPointingDevice::CancelGrabExclusive : QPointingDevice::UngrabExclusive,
+ event, persistentPoint->eventPoint);
+ if (Q_UNLIKELY(lcPointerGrab().isDebugEnabled())) {
+ qCDebug(lcPointerGrab) << name << "point" << point.id() << point.state()
+ << "@" << point.scenePosition()
+ << ": grab" << oldGrabber << "->" << exclusiveGrabber;
+ }
+ QMutableEventPoint::setGlobalGrabPosition(persistentPoint->eventPoint, point.globalPosition());
+ if (exclusiveGrabber)
+ emit q->grabChanged(exclusiveGrabber, QPointingDevice::GrabExclusive, event, point);
+ else
+ persistentPoint->exclusiveGrabberContext.clear();
+}
+
+/*!
+ \internal
+ Call QEventPoint::setExclusiveGrabber(nullptr) on each active point that has a grabber.
+*/
+bool QPointingDevicePrivate::removeExclusiveGrabber(const QPointerEvent *event, const QObject *grabber)
+{
+ bool ret = false;
+ for (auto &pt : activePoints.values()) {
+ if (pt.exclusiveGrabber == grabber) {
+ setExclusiveGrabber(event, pt.eventPoint, nullptr);
+ ret = true;
+ }
+ }
+ return ret;
+}
+
+bool QPointingDevicePrivate::addPassiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *grabber)
+{
+ Q_Q(QPointingDevice);
+ auto persistentPoint = queryPointById(point.id());
+ if (!persistentPoint) {
+ qWarning() << "point is not in activePoints" << point;
+ return false;
+ }
+ if (persistentPoint->passiveGrabbers.contains(grabber))
+ return false;
+ if (Q_UNLIKELY(lcPointerGrab().isDebugEnabled())) {
+ qCDebug(lcPointerGrab) << name << "point" << point.id() << point.state()
+ << ": grab (passive)" << grabber;
+ }
+ persistentPoint->passiveGrabbers << grabber;
+ emit q->grabChanged(grabber, QPointingDevice::GrabPassive, event, point);
+ return true;
+}
+
+bool QPointingDevicePrivate::setPassiveGrabberContext(QPointingDevicePrivate::EventPointData *epd, QObject *grabber, QObject *context)
+{
+ qsizetype i = epd->passiveGrabbers.indexOf(grabber);
+ if (i < 0)
+ return false;
+ if (epd->passiveGrabbersContext.size() <= i)
+ epd->passiveGrabbersContext.resize(i + 1);
+ epd->passiveGrabbersContext[i] = context;
+ return true;
+}
+
+bool QPointingDevicePrivate::removePassiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *grabber)
+{
+ Q_Q(QPointingDevice);
+ auto persistentPoint = queryPointById(point.id());
+ if (!persistentPoint) {
+ qWarning() << "point is not in activePoints" << point;
+ return false;
+ }
+ qsizetype i = persistentPoint->passiveGrabbers.indexOf(grabber);
+ if (i >= 0) {
+ if (Q_UNLIKELY(lcPointerGrab().isDebugEnabled())) {
+ qCDebug(lcPointerGrab) << name << "point" << point.id() << point.state()
+ << ": removing passive grabber" << grabber;
+ }
+ emit q->grabChanged(grabber, QPointingDevice::UngrabPassive, event, point);
+ persistentPoint->passiveGrabbers.removeAt(i);
+ if (persistentPoint->passiveGrabbersContext.size()) {
+ Q_ASSERT(persistentPoint->passiveGrabbersContext.size() > i);
+ persistentPoint->passiveGrabbersContext.removeAt(i);
+ }
+ return true;
+ }
+ return false;
+}
+
+void QPointingDevicePrivate::clearPassiveGrabbers(const QPointerEvent *event, const QEventPoint &point)
+{
+ Q_Q(QPointingDevice);
+ auto persistentPoint = queryPointById(point.id());
+ if (!persistentPoint) {
+ qWarning() << "point is not in activePoints" << point;
+ return;
+ }
+ if (persistentPoint->passiveGrabbers.isEmpty())
+ return;
+ if (Q_UNLIKELY(lcPointerGrab().isDebugEnabled())) {
+ qCDebug(lcPointerGrab) << name << "point" << point.id() << point.state()
+ << ": clearing" << persistentPoint->passiveGrabbers;
+ }
+ for (auto g : persistentPoint->passiveGrabbers)
+ emit q->grabChanged(g, QPointingDevice::UngrabPassive, event, point);
+ persistentPoint->passiveGrabbers.clear();
+ persistentPoint->passiveGrabbersContext.clear();
+}
+
+/*!
+ \internal
+ Removes the given \a grabber as both passive and exclusive grabber from all
+ points in activePoints where it's currently found. If \a cancel is \c true,
+ the transition emitted from the grabChanged() signal will be
+ \c CancelGrabExclusive or \c CancelGrabPassive. Otherwise it will be
+ \c UngrabExclusive or \c UngrabPassive.
+
+ \note This function provides a way to work around the limitation that we
+ normally change grabbers only during event delivery; but it's also more expensive.
+*/
+void QPointingDevicePrivate::removeGrabber(QObject *grabber, bool cancel)
+{
+ Q_Q(QPointingDevice);
+ for (auto ap : activePoints) {
+ auto &epd = ap.second;
+ if (epd.exclusiveGrabber.data() == grabber) {
+ qCDebug(lcPointerGrab) << name << "point" << epd.eventPoint.id() << epd.eventPoint.state()
+ << "@" << epd.eventPoint.scenePosition()
+ << ": grab" << grabber << "-> nullptr";
+ epd.exclusiveGrabber.clear();
+ epd.exclusiveGrabberContext.clear();
+ emit q->grabChanged(grabber,
+ cancel ? QPointingDevice::CancelGrabExclusive : QPointingDevice::UngrabExclusive,
+ nullptr, epd.eventPoint);
+ }
+ qsizetype pi = epd.passiveGrabbers.indexOf(grabber);
+ if (pi >= 0) {
+ qCDebug(lcPointerGrab) << name << "point" << epd.eventPoint.id() << epd.eventPoint.state()
+ << ": removing passive grabber" << grabber;
+ epd.passiveGrabbers.removeAt(pi);
+ if (epd.passiveGrabbersContext.size()) {
+ Q_ASSERT(epd.passiveGrabbersContext.size() > pi);
+ epd.passiveGrabbersContext.removeAt(pi);
+ }
+ emit q->grabChanged(grabber,
+ cancel ? QPointingDevice::CancelGrabPassive : QPointingDevice::UngrabPassive,
+ nullptr, epd.eventPoint);
+ }
+ }
+}
+
+/*!
+ \internal
+ Finds the device instance belonging to the drawing or eraser end of a particular stylus,
+ identified by its \a deviceType, \a pointerType and \a uniqueId. If an existing device
+ is not found, a new one is created and registered, with a warning.
+
+ This function is called from QWindowSystemInterface. Platform plugins should use
+ \l queryTabletDeviceInstance() to check whether a tablet stylus coming into proximity
+ is previously known; if not known, the plugin should create and register the stylus.
+*/
+const QPointingDevice *QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType deviceType,
+ QPointingDevice::PointerType pointerType,
+ QPointingDeviceUniqueId uniqueId)
+{
+ const QPointingDevice *dev = queryTabletDevice(deviceType, pointerType, uniqueId);
+ if (!dev) {
+ qCDebug(lcQpaInputDevices) << "failed to find registered tablet device"
+ << deviceType << pointerType << Qt::hex << uniqueId.numericId()
+ << "The platform plugin should have provided one via "
+ "QWindowSystemInterface::registerInputDevice(). Creating a default one for now.";
+ dev = new QPointingDevice("fake tablet"_L1, 2, deviceType, pointerType,
+ QInputDevice::Capability::Position | QInputDevice::Capability::Pressure,
+ 1, 1, QString(), uniqueId, QCoreApplication::instance());
+ QInputDevicePrivate::registerDevice(dev);
+ }
return dev;
}
@@ -401,16 +706,23 @@ QDebug operator<<(QDebug debug, const QPointingDevice *device)
debug.noquote();
debug << "QPointingDevice(";
if (device) {
- debug << '"' << device->name() << "\", type=";
+ debug << '"' << device->name() << "\" ";
QtDebugUtils::formatQEnum(debug, device->type());
- debug << ", id=" << Qt::hex << device->id() << Qt::dec << ", seat=" << device->seatName();
- debug << ", pointerType=";
- QtDebugUtils::formatQEnum(debug, device->pointerType());
- debug << ", capabilities=";
- QtDebugUtils::formatQFlags(debug, device->capabilities());
- debug << ", maximumTouchPoints=" << device->maximumPoints();
- if (device->uniqueId().numericId())
- debug << ", uniqueId=" << Qt::hex << device->uniqueId().numericId() << Qt::dec;
+ debug << " id=" << device->systemId();
+ if (!device->seatName().isEmpty())
+ debug << " seat=" << device->seatName();
+ if (device->pointerType() != QPointingDevice::PointerType::Generic) {
+ debug << " ptrType=";
+ QtDebugUtils::formatQEnum(debug, device->pointerType());
+ }
+ if (int(device->capabilities()) != int(QInputDevice::Capability::Position)) {
+ debug << " caps=";
+ QtDebugUtils::formatQFlags(debug, device->capabilities());
+ }
+ if (device->maximumPoints() > 1)
+ debug << " maxPts=" << device->maximumPoints();
+ if (device->uniqueId().isValid())
+ debug << " uniqueId=" << Qt::hex << device->uniqueId().numericId() << Qt::dec;
} else {
debug << '0';
}
@@ -419,4 +731,93 @@ QDebug operator<<(QDebug debug, const QPointingDevice *device)
}
#endif // !QT_NO_DEBUG_STREAM
+/*!
+ \class QPointingDeviceUniqueId
+ \since 5.8
+ \ingroup events
+ \inmodule QtGui
+
+ \brief QPointingDeviceUniqueId identifies a unique object, such as a tagged token
+ or stylus, which is used with a pointing device.
+
+ QPointingDeviceUniqueIds can be compared for equality, and can be used as keys in a QHash.
+ You get access to the numerical ID via numericId(), if the device supports such IDs.
+ For future extensions, though, you should not use that function, but compare objects
+ of this type using the equality operator.
+
+ This class is a thin wrapper around an integer ID. You pass it into and out of
+ functions by value.
+
+ \sa QEventPoint
+*/
+
+/*!
+ \fn QPointingDeviceUniqueId::QPointingDeviceUniqueId()
+ Constructs an invalid unique pointer ID.
+*/
+
+/*!
+ Constructs a unique pointer ID from numeric ID \a id.
+*/
+QPointingDeviceUniqueId QPointingDeviceUniqueId::fromNumericId(qint64 id)
+{
+ QPointingDeviceUniqueId result;
+ result.m_numericId = id;
+ return result;
+}
+
+/*!
+ \fn bool QPointingDeviceUniqueId::isValid() const
+
+ Returns whether this unique pointer ID is valid, that is, it represents an actual
+ pointer.
+*/
+
+/*!
+ \property QPointingDeviceUniqueId::numericId
+ \brief the numeric unique ID of the token represented by a touchpoint
+
+ If the device provides a numeric ID, isValid() returns true, and this
+ property provides the numeric ID;
+ otherwise it is -1.
+
+ You should not use the value of this property in portable code, but
+ instead rely on equality to identify pointers.
+
+ \sa isValid()
+*/
+qint64 QPointingDeviceUniqueId::numericId() const noexcept
+{
+ return m_numericId;
+}
+
+/*!
+ \fn bool QPointingDeviceUniqueId::operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs)
+ \since 5.8
+
+ Returns whether the two unique pointer IDs \a lhs and \a rhs identify the same pointer
+ (\c true) or not (\c false).
+*/
+
+/*!
+ \fn bool QPointingDeviceUniqueId::operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs)
+ \since 5.8
+
+ Returns whether the two unique pointer IDs \a lhs and \a rhs identify different pointers
+ (\c true) or not (\c false).
+*/
+
+/*!
+ \relates QPointingDeviceUniqueId
+ \since 5.8
+
+ Returns the hash value for \a key, using \a seed to seed the calculation.
+*/
+size_t qHash(QPointingDeviceUniqueId key, size_t seed) noexcept
+{
+ return qHash(key.numericId(), seed);
+}
+
QT_END_NAMESPACE
+
+#include "moc_qpointingdevice.cpp"
diff --git a/src/gui/kernel/qpointingdevice.h b/src/gui/kernel/qpointingdevice.h
index a823af4ec9..b8e6460af7 100644
--- a/src/gui/kernel/qpointingdevice.h
+++ b/src/gui/kernel/qpointingdevice.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPOINTINGDEVICE_H
#define QPOINTINGDEVICE_H
@@ -47,7 +11,10 @@
QT_BEGIN_NAMESPACE
class QDebug;
+class QEventPoint;
+class QPointerEvent;
class QPointingDevicePrivate;
+class QPointerEvent;
class QScreen;
class Q_GUI_EXPORT QPointingDeviceUniqueId
@@ -56,39 +23,41 @@ class Q_GUI_EXPORT QPointingDeviceUniqueId
Q_PROPERTY(qint64 numericId READ numericId CONSTANT)
public:
Q_ALWAYS_INLINE
- Q_DECL_CONSTEXPR QPointingDeviceUniqueId() noexcept : m_numericId(-1) {}
+ constexpr QPointingDeviceUniqueId() noexcept : m_numericId(-1) {}
// compiler-generated copy/move ctor/assignment operators are ok!
// compiler-generated dtor is ok!
static QPointingDeviceUniqueId fromNumericId(qint64 id);
- Q_ALWAYS_INLINE Q_DECL_CONSTEXPR bool isValid() const noexcept { return m_numericId != -1; }
+ Q_ALWAYS_INLINE constexpr bool isValid() const noexcept { return m_numericId != -1; }
qint64 numericId() const noexcept;
private:
+ friend bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept
+ { return lhs.numericId() == rhs.numericId(); }
+ friend bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept
+ { return lhs.numericId() != rhs.numericId(); }
+
// TODO: for TUIO 2, or any other type of complex token ID, an internal
// array (or hash) can be added to hold additional properties.
// In this case, m_numericId will then turn into an index into that array (or hash).
qint64 m_numericId;
};
-Q_DECLARE_TYPEINFO(QPointingDeviceUniqueId, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QPointingDeviceUniqueId, Q_RELOCATABLE_TYPE);
-Q_GUI_EXPORT bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept;
-inline bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept
-{ return !operator==(lhs, rhs); }
Q_GUI_EXPORT size_t qHash(QPointingDeviceUniqueId key, size_t seed = 0) noexcept;
class Q_GUI_EXPORT QPointingDevice : public QInputDevice
{
Q_OBJECT
Q_DECLARE_PRIVATE(QPointingDevice)
- Q_PROPERTY(PointerType pointerType READ pointerType)
- Q_PROPERTY(int maximumPoints READ maximumPoints)
- Q_PROPERTY(int buttonCount READ buttonCount)
- Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId)
+ Q_PROPERTY(PointerType pointerType READ pointerType CONSTANT)
+ Q_PROPERTY(int maximumPoints READ maximumPoints CONSTANT)
+ Q_PROPERTY(int buttonCount READ buttonCount CONSTANT)
+ Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId CONSTANT)
public:
- enum class PointerType : qint16 {
+ enum class PointerType {
Unknown = 0,
Generic = 0x0001, // mouse or similar
Finger = 0x0002, // touchscreen or pad
@@ -100,9 +69,20 @@ public:
Q_DECLARE_FLAGS(PointerTypes, PointerType)
Q_FLAG(PointerTypes)
- QPointingDevice();
+ enum GrabTransition {
+ GrabPassive = 0x01,
+ UngrabPassive = 0x02,
+ CancelGrabPassive = 0x03,
+ OverrideGrabPassive = 0x04,
+ GrabExclusive = 0x10,
+ UngrabExclusive = 0x20,
+ CancelGrabExclusive = 0x30,
+ };
+ Q_ENUM(GrabTransition)
+
+ QPointingDevice(QObject *parent = nullptr);
~QPointingDevice();
- QPointingDevice(const QString &name, qint64 id, QInputDevice::DeviceType devType,
+ QPointingDevice(const QString &name, qint64 systemId, QInputDevice::DeviceType devType,
PointerType pType, Capabilities caps, int maxPoints, int buttonCount,
const QString &seatName = QString(),
QPointingDeviceUniqueId uniqueId = QPointingDeviceUniqueId(),
@@ -124,14 +104,19 @@ public:
static const QPointingDevice *primaryPointingDevice(const QString& seatName = QString());
- static const QPointingDevice *tabletDevice(QInputDevice::DeviceType deviceType,
- QPointingDevice::PointerType pointerType,
- QPointingDeviceUniqueId uniqueId, quint32 usbId = 0);
-
bool operator==(const QPointingDevice &other) const;
+Q_SIGNALS:
+#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
+ void grabChanged(QObject *grabber, GrabTransition transition,
+ const QPointerEvent *event, const QEventPoint &point) const;
+#else
+ void grabChanged(QObject *grabber, QPointingDevice::GrabTransition transition,
+ const QPointerEvent *event, const QEventPoint &point);
+#endif
+
protected:
- QPointingDevice(QPointingDevicePrivate &d, QObject *parent = nullptr);
+ QPointingDevice(QPointingDevicePrivate &d, QObject *parent);
Q_DISABLE_COPY_MOVE(QPointingDevice)
};
diff --git a/src/gui/kernel/qpointingdevice_p.h b/src/gui/kernel/qpointingdevice_p.h
index 91ba0137e0..b2f0574e9b 100644
--- a/src/gui/kernel/qpointingdevice_p.h
+++ b/src/gui/kernel/qpointingdevice_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPOINTINGDEVICE_P_H
#define QPOINTINGDEVICE_P_H
@@ -51,14 +15,22 @@
// We mean it.
//
+#include <QtCore/qloggingcategory.h>
+#include <QtGui/private/qevent_p.h>
+#include <QtGui/qpointingdevice.h>
#include <QtGui/private/qtguiglobal_p.h>
#include <QtGui/private/qinputdevice_p.h>
-#include <QtGui/qpointingdevice.h>
+
+#include <QtCore/qpointer.h>
+#include <QtCore/private/qflatmap_p.h>
QT_BEGIN_NAMESPACE
+Q_DECLARE_LOGGING_CATEGORY(lcPointerGrab);
+
class Q_GUI_EXPORT QPointingDevicePrivate : public QInputDevicePrivate
{
+ Q_DECLARE_PUBLIC(QPointingDevice)
public:
QPointingDevicePrivate(const QString &name, qint64 id, QInputDevice::DeviceType type,
QPointingDevice::PointerType pType, QPointingDevice::Capabilities caps,
@@ -71,9 +43,40 @@ public:
pointerType(pType)
{
pointingDeviceType = true;
+ activePoints.reserve(maxPoints);
}
+ ~QPointingDevicePrivate() override;
+
+ void sendTouchCancelEvent(QTouchEvent *cancelEvent);
+
+ /*! \internal
+ This struct (stored in activePoints) holds persistent state between event deliveries.
+ */
+ struct EventPointData {
+ QEventPoint eventPoint;
+ QPointer<QObject> exclusiveGrabber;
+ QPointer<QObject> exclusiveGrabberContext; // extra info about where the grab happened
+ QList<QPointer <QObject> > passiveGrabbers;
+ QList<QPointer <QObject> > passiveGrabbersContext; // parallel list: extra info about where the grabs happened
+ };
+ EventPointData *queryPointById(int id) const;
+ EventPointData *pointById(int id) const;
+ void removePointById(int id);
+ QObject *firstActiveTarget() const;
+ QWindow *firstActiveWindow() const;
+
+ QObject *firstPointExclusiveGrabber() const;
+ void setExclusiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *exclusiveGrabber);
+ bool removeExclusiveGrabber(const QPointerEvent *event, const QObject *grabber);
+ bool addPassiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *grabber);
+ static bool setPassiveGrabberContext(EventPointData *epd, QObject *grabber, QObject *context);
+ bool removePassiveGrabber(const QPointerEvent *event, const QEventPoint &point, QObject *grabber);
+ void clearPassiveGrabbers(const QPointerEvent *event, const QEventPoint &point);
+ void removeGrabber(QObject *grabber, bool cancel = false);
+
+ using EventPointMap = QVarLengthFlatMap<int, EventPointData, 20>;
+ mutable EventPointMap activePoints;
- void * extra = nullptr; // QPA plugins can store platform-specific stuff here
QPointingDeviceUniqueId uniqueId;
quint32 toolId = 0; // only for Wacom tablets
qint8 maximumTouchPoints = 0;
@@ -90,6 +93,18 @@ public:
{
return static_cast<const QPointingDevicePrivate *>(QObjectPrivate::get(q));
}
+
+ static const QPointingDevice *tabletDevice(QInputDevice::DeviceType deviceType,
+ QPointingDevice::PointerType pointerType,
+ QPointingDeviceUniqueId uniqueId);
+
+ static const QPointingDevice *queryTabletDevice(QInputDevice::DeviceType deviceType,
+ QPointingDevice::PointerType pointerType,
+ QPointingDeviceUniqueId uniqueId,
+ QInputDevice::Capabilities capabilities = QInputDevice::Capability::None,
+ qint64 systemId = 0);
+
+ static const QPointingDevice *pointingDeviceById(qint64 systemId);
};
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qrasterwindow.cpp b/src/gui/kernel/qrasterwindow.cpp
index 70d87347c3..f292344ca1 100644
--- a/src/gui/kernel/qrasterwindow.cpp
+++ b/src/gui/kernel/qrasterwindow.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qrasterwindow.h"
@@ -70,14 +34,20 @@ class QRasterWindowPrivate : public QPaintDeviceWindowPrivate
{
Q_DECLARE_PUBLIC(QRasterWindow)
public:
+ void handleResizeEvent() override
+ {
+ Q_Q(QRasterWindow);
+ if (backingstore->size() != q->size())
+ markWindowAsDirty();
+ }
+
void beginPaint(const QRegion &region) override
{
Q_Q(QRasterWindow);
const QSize size = q->size();
- if (backingstore->size() != size) {
+ if (backingstore->size() != size)
backingstore->resize(size);
- markWindowAsDirty();
- }
+
backingstore->beginPaint(region);
}
@@ -138,4 +108,10 @@ QPaintDevice *QRasterWindow::redirected(QPoint *) const
return d->backingstore->paintDevice();
}
+void QRasterWindow::resizeEvent(QResizeEvent *)
+{
+}
+
QT_END_NAMESPACE
+
+#include "moc_qrasterwindow.cpp"
diff --git a/src/gui/kernel/qrasterwindow.h b/src/gui/kernel/qrasterwindow.h
index 9fe01c076b..986bf6b511 100644
--- a/src/gui/kernel/qrasterwindow.h
+++ b/src/gui/kernel/qrasterwindow.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QRASTERWINDOW_H
#define QRASTERWINDOW_H
@@ -59,6 +23,7 @@ public:
protected:
int metric(PaintDeviceMetric metric) const override;
QPaintDevice *redirected(QPoint *) const override;
+ void resizeEvent(QResizeEvent *event) override;
private:
Q_DISABLE_COPY(QRasterWindow)
diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp
index 1d11358b3d..83641e7676 100644
--- a/src/gui/kernel/qscreen.cpp
+++ b/src/gui/kernel/qscreen.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qscreen.h"
#include "qscreen_p.h"
@@ -67,97 +31,48 @@ QT_BEGIN_NAMESPACE
desktop environment's settings panel, to let the user globally control UI
and font sizes in different applications.
+ \note Both physical and logical DPI are expressed in device-independent dots.
+ Multiply by QScreen::devicePixelRatio() to get device-dependent density.
+
\inmodule QtGui
*/
-QScreen::QScreen(QPlatformScreen *screen)
+QScreen::QScreen(QPlatformScreen *platformScreen)
: QObject(*new QScreenPrivate(), nullptr)
{
Q_D(QScreen);
- d->setPlatformScreen(screen);
-}
-void QScreenPrivate::updateGeometriesWithSignals()
-{
- const QRect oldGeometry = geometry;
- const QRect oldAvailableGeometry = availableGeometry;
- updateHighDpi();
- emitGeometryChangeSignals(oldGeometry != geometry, oldAvailableGeometry != availableGeometry);
-}
+ d->platformScreen = platformScreen;
+ platformScreen->d_func()->screen = this;
-void QScreenPrivate::emitGeometryChangeSignals(bool geometryChanged, bool availableGeometryChanged)
-{
- Q_Q(QScreen);
- if (availableGeometryChanged)
- emit q->availableGeometryChanged(availableGeometry);
+ d->orientation = platformScreen->orientation();
+ d->logicalDpi = QPlatformScreen::overrideDpi(platformScreen->logicalDpi());
+ d->refreshRate = platformScreen->refreshRate();
+ // safeguard ourselves against buggy platform behavior...
+ if (d->refreshRate < 1.0)
+ d->refreshRate = 60.0;
- if (geometryChanged || availableGeometryChanged) {
- const auto siblings = q->virtualSiblings();
- for (QScreen* sibling : siblings)
- emit sibling->virtualGeometryChanged(sibling->virtualGeometry());
- }
+ d->updateGeometry();
+ d->updatePrimaryOrientation(); // derived from the geometry
}
-void QScreenPrivate::setPlatformScreen(QPlatformScreen *screen)
+void QScreenPrivate::updateGeometry()
{
- Q_Q(QScreen);
- platformScreen = screen;
- platformScreen->d_func()->screen = q;
- orientation = platformScreen->orientation();
-
- logicalDpi = QPlatformScreen::overrideDpi(platformScreen->logicalDpi());
-
- refreshRate = platformScreen->refreshRate();
- // safeguard ourselves against buggy platform behavior...
- if (refreshRate < 1.0)
- refreshRate = 60.0;
-
- updatePrimaryOrientation();
- updateHighDpi();
+ qreal scaleFactor = QHighDpiScaling::factor(platformScreen);
+ QRect nativeGeometry = platformScreen->geometry();
+ geometry = QRect(nativeGeometry.topLeft(), QHighDpi::fromNative(nativeGeometry.size(), scaleFactor));
+ availableGeometry = QHighDpi::fromNative(platformScreen->availableGeometry(), scaleFactor, geometry.topLeft());
}
-
/*!
Destroys the screen.
+
+ \internal
*/
QScreen::~QScreen()
{
- // Remove screen
- const bool wasPrimary = QGuiApplication::primaryScreen() == this;
- QGuiApplicationPrivate::screen_list.removeOne(this);
- QGuiApplicationPrivate::resetCachedDevicePixelRatio();
-
- if (!qGuiApp)
- return;
-
- QScreen *newPrimaryScreen = QGuiApplication::primaryScreen();
- if (wasPrimary && newPrimaryScreen)
- emit qGuiApp->primaryScreenChanged(newPrimaryScreen);
-
- // Allow clients to manage windows that are affected by the screen going
- // away, before we fall back to moving them to the primary screen.
- emit qApp->screenRemoved(this);
-
- if (QGuiApplication::closingDown())
- return;
-
- bool movingFromVirtualSibling = newPrimaryScreen
- && newPrimaryScreen->handle()->virtualSiblings().contains(handle());
-
- // Move any leftover windows to the primary screen
- const auto allWindows = QGuiApplication::allWindows();
- for (QWindow *window : allWindows) {
- if (!window->isTopLevel() || window->screen() != this)
- continue;
-
- const bool wasVisible = window->isVisible();
- window->setScreen(newPrimaryScreen);
-
- // Re-show window if moved from a virtual sibling screen. Otherwise
- // leave it up to the application developer to show the window.
- if (movingFromVirtualSibling)
- window->setVisible(wasVisible);
- }
+ Q_ASSERT_X(!QGuiApplicationPrivate::screen_list.contains(this), "QScreen",
+ "QScreens should be removed via QWindowSystemInterface::handleScreenRemoved()");
}
/*!
@@ -177,6 +92,10 @@ QPlatformScreen *QScreen::handle() const
For example, on X11 these correspond to the XRandr screen names,
typically "VGA1", "HDMI1", etc.
+
+ \note The user presentable string is not guaranteed to match the
+ result of any native APIs, and should not be used to uniquely identify
+ a screen.
*/
QString QScreen::name() const
{
@@ -248,6 +167,9 @@ QSize QScreen::size() const
Depending on what information the underlying system provides the value might not be
entirely accurate.
+ \note Physical DPI is expressed in device-independent dots. Multiply by QScreen::devicePixelRatio()
+ to get device-dependent density.
+
\sa physicalDotsPerInchY()
*/
qreal QScreen::physicalDotsPerInchX() const
@@ -263,6 +185,9 @@ qreal QScreen::physicalDotsPerInchX() const
Depending on what information the underlying system provides the value might not be
entirely accurate.
+ \note Physical DPI is expressed in device-independent dots. Multiply by QScreen::devicePixelRatio()
+ to get device-dependent density.
+
\sa physicalDotsPerInchX()
*/
qreal QScreen::physicalDotsPerInchY() const
@@ -281,6 +206,9 @@ qreal QScreen::physicalDotsPerInchY() const
This is a convenience property that's simply the average of the physicalDotsPerInchX
and physicalDotsPerInchY properties.
+ \note Physical DPI is expressed in device-independent dots. Multiply by QScreen::devicePixelRatio()
+ to get device-dependent density.
+
\sa physicalDotsPerInchX()
\sa physicalDotsPerInchY()
*/
@@ -431,9 +359,12 @@ QList<QScreen *> QScreen::virtualSiblings() const
Q_D(const QScreen);
const QList<QPlatformScreen *> platformScreens = d->platformScreen->virtualSiblings();
QList<QScreen *> screens;
- screens.reserve(platformScreens.count());
- for (QPlatformScreen *platformScreen : platformScreens)
- screens << platformScreen->screen();
+ screens.reserve(platformScreens.size());
+ for (QPlatformScreen *platformScreen : platformScreens) {
+ // Only consider platform screens that have been added
+ if (auto *knownScreen = platformScreen->screen())
+ screens << knownScreen;
+ }
return screens;
}
@@ -518,7 +449,7 @@ QRect QScreen::availableVirtualGeometry() const
based on how it is being held; in that case, this \c orientation property
will change.
- \sa primaryOrientation(), QWindow::contentOrientation(), QOrientationSensor
+ \sa primaryOrientation(), QWindow::contentOrientation()
*/
Qt::ScreenOrientation QScreen::orientation() const
{
@@ -529,6 +460,11 @@ Qt::ScreenOrientation QScreen::orientation() const
/*!
\property QScreen::refreshRate
\brief the approximate vertical refresh rate of the screen in Hz
+
+ \warning Avoid using the screen's refresh rate to drive animations via a
+ timer such as QChronoTimer. Instead use QWindow::requestUpdate().
+
+ \sa QWindow::requestUpdate()
*/
qreal QScreen::refreshRate() const
{
@@ -768,14 +704,57 @@ QPixmap QScreen::grabWindow(WId window, int x, int y, int width, int height)
return result;
}
-#ifndef QT_NO_DEBUG_STREAM
+/*!
+ \fn template <typename QNativeInterface> QNativeInterface *QScreen::nativeInterface() const
+
+ Returns a native interface of the given type for the screen.
-static inline void formatRect(QDebug &debug, const QRect r)
+ This function provides access to platform specific functionality
+ of QScreen, as defined in the QNativeInterface namespace:
+
+ \annotatedlist native-interfaces-qscreen
+
+ If the requested interface is not available a \nullptr is returned.
+ */
+
+void *QScreen::resolveInterface(const char *name, int revision) const
{
- debug << r.width() << 'x' << r.height()
- << Qt::forcesign << r.x() << r.y() << Qt::noforcesign;
+ using namespace QNativeInterface;
+ using namespace QNativeInterface::Private;
+
+ auto *platformScreen = handle();
+ Q_UNUSED(platformScreen);
+ Q_UNUSED(name);
+ Q_UNUSED(revision);
+
+#if QT_CONFIG(xcb)
+ QT_NATIVE_INTERFACE_RETURN_IF(QXcbScreen, platformScreen);
+#endif
+
+#if QT_CONFIG(vsp2)
+ QT_NATIVE_INTERFACE_RETURN_IF(QVsp2Screen, platformScreen);
+#endif
+
+#if defined(Q_OS_WEBOS)
+ QT_NATIVE_INTERFACE_RETURN_IF(QWebOSScreen, platformScreen);
+#endif
+
+#if defined(Q_OS_WIN32)
+ QT_NATIVE_INTERFACE_RETURN_IF(QWindowsScreen, platformScreen);
+#endif
+
+#if defined(Q_OS_ANDROID)
+ QT_NATIVE_INTERFACE_RETURN_IF(QAndroidScreen, platformScreen);
+#endif
+
+#if QT_CONFIG(wayland)
+ QT_NATIVE_INTERFACE_RETURN_IF(QWaylandScreen, platformScreen);
+#endif
+
+ return nullptr;
}
+#ifndef QT_NO_DEBUG_STREAM
Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QScreen *screen)
{
const QDebugStateSaver saver(debug);
@@ -786,10 +765,8 @@ Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QScreen *screen)
if (debug.verbosity() > 2) {
if (screen == QGuiApplication::primaryScreen())
debug << ", primary";
- debug << ", geometry=";
- formatRect(debug, screen->geometry());
- debug << ", available=";
- formatRect(debug, screen->availableGeometry());
+ debug << ", geometry=" << screen->geometry();
+ debug << ", available=" << screen->availableGeometry();
debug << ", logical DPI=" << screen->logicalDotsPerInchX()
<< ',' << screen->logicalDotsPerInchY()
<< ", physical DPI=" << screen->physicalDotsPerInchX()
@@ -805,4 +782,60 @@ Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QScreen *screen)
}
#endif // !QT_NO_DEBUG_STREAM
+QScreenPrivate::UpdateEmitter::UpdateEmitter(QScreen *screen)
+{
+ initialState.platformScreen = screen->handle();
+
+ // Use public APIs to read out current state, rather
+ // than accessing the QScreenPrivate members, so that
+ // we detect any changes to the high-DPI scale factors
+ // that may be applied in the getters.
+
+ initialState.logicalDpi = QDpi{
+ screen->logicalDotsPerInchX(),
+ screen->logicalDotsPerInchY()
+ };
+ initialState.geometry = screen->geometry();
+ initialState.availableGeometry = screen->availableGeometry();
+ initialState.primaryOrientation = screen->primaryOrientation();
+}
+
+QScreenPrivate::UpdateEmitter::~UpdateEmitter()
+{
+ QScreen *screen = initialState.platformScreen->screen();
+
+ const auto logicalDotsPerInch = QDpi{
+ screen->logicalDotsPerInchX(),
+ screen->logicalDotsPerInchY()
+ };
+ if (logicalDotsPerInch != initialState.logicalDpi)
+ emit screen->logicalDotsPerInchChanged(screen->logicalDotsPerInch());
+
+ const auto geometry = screen->geometry();
+ const auto geometryChanged = geometry != initialState.geometry;
+ if (geometryChanged)
+ emit screen->geometryChanged(geometry);
+
+ const auto availableGeometry = screen->availableGeometry();
+ const auto availableGeometryChanged = availableGeometry != initialState.availableGeometry;
+ if (availableGeometryChanged)
+ emit screen->availableGeometryChanged(availableGeometry);
+
+ if (geometryChanged || availableGeometryChanged) {
+ const auto siblings = screen->virtualSiblings();
+ for (QScreen* sibling : siblings)
+ emit sibling->virtualGeometryChanged(sibling->virtualGeometry());
+ }
+
+ if (geometryChanged) {
+ emit screen->physicalDotsPerInchChanged(screen->physicalDotsPerInch());
+
+ const auto primaryOrientation = screen->primaryOrientation();
+ if (primaryOrientation != initialState.primaryOrientation)
+ emit screen->primaryOrientationChanged(primaryOrientation);
+ }
+}
+
QT_END_NAMESPACE
+
+#include "moc_qscreen.cpp"
diff --git a/src/gui/kernel/qscreen.h b/src/gui/kernel/qscreen.h
index 1bff3f4ec1..9442e7525b 100644
--- a/src/gui/kernel/qscreen.h
+++ b/src/gui/kernel/qscreen.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSCREEN_H
#define QSCREEN_H
@@ -50,6 +14,7 @@
#include <QtGui/QTransform>
#include <QtCore/qnamespace.h>
+#include <QtCore/qnativeinterface.h>
QT_BEGIN_NAMESPACE
@@ -80,16 +45,20 @@ class Q_GUI_EXPORT QScreen : public QObject
Q_PROPERTY(QRect geometry READ geometry NOTIFY geometryChanged)
Q_PROPERTY(QRect availableGeometry READ availableGeometry NOTIFY availableGeometryChanged)
Q_PROPERTY(QRect virtualGeometry READ virtualGeometry NOTIFY virtualGeometryChanged)
- Q_PROPERTY(QRect availableVirtualGeometry READ availableVirtualGeometry NOTIFY virtualGeometryChanged)
+ Q_PROPERTY(QRect availableVirtualGeometry READ availableVirtualGeometry
+ NOTIFY virtualGeometryChanged)
Q_PROPERTY(QSizeF physicalSize READ physicalSize NOTIFY physicalSizeChanged)
- Q_PROPERTY(qreal physicalDotsPerInchX READ physicalDotsPerInchX NOTIFY physicalDotsPerInchChanged)
- Q_PROPERTY(qreal physicalDotsPerInchY READ physicalDotsPerInchY NOTIFY physicalDotsPerInchChanged)
+ Q_PROPERTY(qreal physicalDotsPerInchX READ physicalDotsPerInchX
+ NOTIFY physicalDotsPerInchChanged)
+ Q_PROPERTY(qreal physicalDotsPerInchY READ physicalDotsPerInchY
+ NOTIFY physicalDotsPerInchChanged)
Q_PROPERTY(qreal physicalDotsPerInch READ physicalDotsPerInch NOTIFY physicalDotsPerInchChanged)
Q_PROPERTY(qreal logicalDotsPerInchX READ logicalDotsPerInchX NOTIFY logicalDotsPerInchChanged)
Q_PROPERTY(qreal logicalDotsPerInchY READ logicalDotsPerInchY NOTIFY logicalDotsPerInchChanged)
Q_PROPERTY(qreal logicalDotsPerInch READ logicalDotsPerInch NOTIFY logicalDotsPerInchChanged)
Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY physicalDotsPerInchChanged)
- Q_PROPERTY(Qt::ScreenOrientation primaryOrientation READ primaryOrientation NOTIFY primaryOrientationChanged)
+ Q_PROPERTY(Qt::ScreenOrientation primaryOrientation READ primaryOrientation
+ NOTIFY primaryOrientationChanged)
Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation NOTIFY orientationChanged)
Q_PROPERTY(Qt::ScreenOrientation nativeOrientation READ nativeOrientation)
Q_PROPERTY(qreal refreshRate READ refreshRate NOTIFY refreshRateChanged)
@@ -148,6 +117,8 @@ public:
qreal refreshRate() const;
+ QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QScreen)
+
Q_SIGNALS:
void geometryChanged(const QRect &geometry);
void availableGeometryChanged(const QRect &geometry);
@@ -176,5 +147,7 @@ Q_GUI_EXPORT QDebug operator<<(QDebug, const QScreen *);
QT_END_NAMESPACE
+#include <QtGui/qscreen_platform.h>
+
#endif // QSCREEN_H
diff --git a/src/gui/kernel/qscreen_p.h b/src/gui/kernel/qscreen_p.h
index 7543202c2f..964bc1cc58 100644
--- a/src/gui/kernel/qscreen_p.h
+++ b/src/gui/kernel/qscreen_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSCREEN_P_H
#define QSCREEN_P_H
@@ -60,21 +24,8 @@
QT_BEGIN_NAMESPACE
-class QScreenPrivate : public QObjectPrivate
+struct QScreenData
{
- Q_DECLARE_PUBLIC(QScreen)
-public:
- void setPlatformScreen(QPlatformScreen *screen);
- void updateHighDpi()
- {
- geometry = platformScreen->deviceIndependentGeometry();
- availableGeometry = QHighDpi::fromNative(platformScreen->availableGeometry(), QHighDpiScaling::factor(platformScreen), geometry.topLeft());
- }
-
- void updatePrimaryOrientation();
- void updateGeometriesWithSignals();
- void emitGeometryChangeSignals(bool geometryChanged, bool availableGeometryChanged);
-
QPlatformScreen *platformScreen = nullptr;
Qt::ScreenOrientation orientation = Qt::PrimaryOrientation;
@@ -85,6 +36,25 @@ public:
qreal refreshRate = 60;
};
+class QScreenPrivate : public QObjectPrivate, public QScreenData
+{
+ Q_DECLARE_PUBLIC(QScreen)
+public:
+ void updateGeometry();
+ void updatePrimaryOrientation();
+
+ class UpdateEmitter
+ {
+ public:
+ explicit UpdateEmitter(QScreen *screen);
+ ~UpdateEmitter();
+ UpdateEmitter(UpdateEmitter&&) noexcept = default;
+ private:
+ Q_DISABLE_COPY(UpdateEmitter)
+ QScreenData initialState;
+ };
+};
+
QT_END_NAMESPACE
#endif // QSCREEN_P_H
diff --git a/src/gui/kernel/qscreen_platform.h b/src/gui/kernel/qscreen_platform.h
new file mode 100644
index 0000000000..6f40e9273f
--- /dev/null
+++ b/src/gui/kernel/qscreen_platform.h
@@ -0,0 +1,61 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QSCREEN_PLATFORM_H
+#define QSCREEN_PLATFORM_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is part of the native interface APIs. Usage of
+// this API may make your code source and binary incompatible
+// with future versions of Qt.
+//
+
+#include <QtGui/qtguiglobal.h>
+
+#include <QtCore/qnativeinterface.h>
+#include <QtGui/qguiapplication.h>
+
+#if defined(Q_OS_WIN32)
+#include <QtGui/qwindowdefs_win.h>
+#endif
+
+#if QT_CONFIG(wayland)
+struct wl_output;
+#endif
+
+QT_BEGIN_NAMESPACE
+
+namespace QNativeInterface {
+
+#if defined(Q_OS_WIN32) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QWindowsScreen
+{
+ QT_DECLARE_NATIVE_INTERFACE(QWindowsScreen, 1, QScreen)
+ virtual HMONITOR handle() const = 0;
+};
+#endif
+
+#if QT_CONFIG(wayland) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QWaylandScreen
+{
+ QT_DECLARE_NATIVE_INTERFACE(QWaylandScreen, 1, QScreen)
+ virtual wl_output *output() const = 0;
+};
+#endif
+
+#if defined(Q_OS_ANDROID) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QAndroidScreen
+{
+ QT_DECLARE_NATIVE_INTERFACE(QAndroidScreen, 1, QScreen)
+ virtual int displayId() const = 0;
+};
+#endif
+
+} // namespace QNativeInterface
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/gui/kernel/qsessionmanager.cpp b/src/gui/kernel/qsessionmanager.cpp
index 8747e02719..0a1ff95656 100644
--- a/src/gui/kernel/qsessionmanager.cpp
+++ b/src/gui/kernel/qsessionmanager.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qsessionmanager.h>
#include <qguiapplication.h>
@@ -76,9 +40,6 @@ QT_BEGIN_NAMESPACE
QSessionManager object as argument. The session manager can only be
accessed in slots invoked by these signals.
- \warning If you use QSessionManager, you should disable fallback session
- management: QGuiApplication::setFallbackSessionManagementEnabled().
-
No user interaction is possible \e unless the application gets explicit
permission from the session manager. You ask for permission by calling
allowsInteraction() or, if it is really urgent, allowsErrorInteraction().
@@ -320,10 +281,6 @@ void QSessionManager::setRestartCommand(const QStringList &command)
/*!
Returns the currently set restart command.
- To iterate over the list, you can use the \l foreach pseudo-keyword:
-
- \snippet code/src_gui_kernel_qguiapplication.cpp 3
-
\sa setRestartCommand(), restartHint()
*/
QStringList QSessionManager::restartCommand() const
@@ -346,10 +303,6 @@ void QSessionManager::setDiscardCommand(const QStringList &command)
/*!
Returns the currently set discard command.
- To iterate over the list, you can use the \l foreach pseudo-keyword:
-
- \snippet code/src_gui_kernel_qguiapplication.cpp 4
-
\sa setDiscardCommand(), restartCommand(), setRestartCommand()
*/
QStringList QSessionManager::discardCommand() const
@@ -423,4 +376,6 @@ void QSessionManager::requestPhase2()
QT_END_NAMESPACE
+#include "moc_qsessionmanager.cpp"
+
#endif // QT_NO_SESSIONMANAGER
diff --git a/src/gui/kernel/qsessionmanager.h b/src/gui/kernel/qsessionmanager.h
index 21100b25d9..6015a0b378 100644
--- a/src/gui/kernel/qsessionmanager.h
+++ b/src/gui/kernel/qsessionmanager.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSESSIONMANAGER_H
#define QSESSIONMANAGER_H
diff --git a/src/gui/kernel/qsessionmanager_p.h b/src/gui/kernel/qsessionmanager_p.h
index d07d9b5eb8..c98f7a5a1d 100644
--- a/src/gui/kernel/qsessionmanager_p.h
+++ b/src/gui/kernel/qsessionmanager_p.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Samuel Gaist <samuel.gaist@edeltech.ch>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2013 Samuel Gaist <samuel.gaist@edeltech.ch>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSESSIONMANAGER_P_H
#define QSESSIONMANAGER_P_H
@@ -63,7 +27,7 @@ QT_BEGIN_NAMESPACE
class QPlatformSessionManager;
-class QSessionManagerPrivate : public QObjectPrivate
+class Q_GUI_EXPORT QSessionManagerPrivate : public QObjectPrivate
{
public:
QSessionManagerPrivate(const QString &id,
diff --git a/src/gui/kernel/qshapedpixmapdndwindow.cpp b/src/gui/kernel/qshapedpixmapdndwindow.cpp
index 1a85a5e853..546a1a4937 100644
--- a/src/gui/kernel/qshapedpixmapdndwindow.cpp
+++ b/src/gui/kernel/qshapedpixmapdndwindow.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qshapedpixmapdndwindow_p.h"
@@ -56,7 +20,7 @@ QShapedPixmapWindow::QShapedPixmapWindow(QScreen *screen)
QSurfaceFormat format;
format.setAlphaBufferSize(8);
setFormat(format);
- setFlags(Qt::ToolTip | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint
+ setFlags(Qt::FramelessWindowHint | Qt::BypassWindowManagerHint
| Qt::WindowTransparentForInput | Qt::WindowDoesNotAcceptFocus);
}
@@ -76,7 +40,7 @@ void QShapedPixmapWindow::setPixmap(const QPixmap &pixmap)
const auto pixmapDpr = m_pixmap.devicePixelRatio();
const auto winDpr = devicePixelRatio();
const auto maskSize = (QSizeF(m_pixmap.size()) * winDpr / pixmapDpr).toSize();
- platformWindow->setMask(QBitmap(mask.scaled(maskSize)));
+ platformWindow->setMask(QBitmap::fromPixmap(mask.scaled(maskSize)));
}
}
}
@@ -104,11 +68,11 @@ void QShapedPixmapWindow::updateGeometry(const QPoint &pos)
{
QSize size(1, 1);
if (!m_pixmap.isNull()) {
- size = qFuzzyCompare(m_pixmap.devicePixelRatio(), qreal(1.0))
- ? m_pixmap.size()
- : (QSizeF(m_pixmap.size()) / m_pixmap.devicePixelRatio()).toSize();
+ size = m_pixmap.deviceIndependentSize().toSize();
}
setGeometry(QRect(pos - m_hotSpot, size));
}
QT_END_NAMESPACE
+
+#include "moc_qshapedpixmapdndwindow_p.cpp"
diff --git a/src/gui/kernel/qshapedpixmapdndwindow_p.h b/src/gui/kernel/qshapedpixmapdndwindow_p.h
index 5089be7284..a2ce26a60e 100644
--- a/src/gui/kernel/qshapedpixmapdndwindow_p.h
+++ b/src/gui/kernel/qshapedpixmapdndwindow_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSHAPEDPIXMAPDNDWINDOW_H
#define QSHAPEDPIXMAPDNDWINDOW_H
diff --git a/src/gui/kernel/qshortcut.cpp b/src/gui/kernel/qshortcut.cpp
index c4305d5a7f..3f6822cb03 100644
--- a/src/gui/kernel/qshortcut.cpp
+++ b/src/gui/kernel/qshortcut.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qshortcut.h"
#include "qshortcut_p.h"
@@ -132,7 +96,7 @@ QT_BEGIN_NAMESPACE
\sa activated()
*/
-static bool simpleContextMatcher(QObject *object, Qt::ShortcutContext context)
+bool QShortcutPrivate::simpleContextMatcher(QObject *object, Qt::ShortcutContext context)
{
auto guiShortcut = qobject_cast<QShortcut *>(object);
if (QGuiApplication::applicationState() != Qt::ApplicationActive || guiShortcut == nullptr)
@@ -163,15 +127,23 @@ void QShortcutPrivate::redoGrab(QShortcutMap &map)
return;
}
- if (sc_id)
- map.removeShortcut(sc_id, q);
- if (sc_sequence.isEmpty())
+ for (int id : std::as_const(sc_ids))
+ map.removeShortcut(id, q);
+
+ sc_ids.clear();
+ if (sc_sequences.isEmpty())
return;
- sc_id = map.addShortcut(q, sc_sequence, sc_context, contextMatcher());
- if (!sc_enabled)
- map.setShortcutEnabled(false, sc_id, q);
- if (!sc_autorepeat)
- map.setShortcutAutoRepeat(false, sc_id, q);
+ sc_ids.reserve(sc_sequences.size());
+ for (const auto &keySequence : std::as_const(sc_sequences)) {
+ if (keySequence.isEmpty())
+ continue;
+ int id = map.addShortcut(q, keySequence, sc_context, contextMatcher());
+ sc_ids.append(id);
+ if (!sc_enabled)
+ map.setShortcutEnabled(false, id, q);
+ if (!sc_autorepeat)
+ map.setShortcutAutoRepeat(false, id, q);
+ }
}
QShortcutPrivate *QGuiApplicationPrivate::createShortcutPrivate() const
@@ -210,7 +182,34 @@ QShortcut::QShortcut(const QKeySequence &key, QObject *parent,
{
Q_D(QShortcut);
d->sc_context = context;
- d->sc_sequence = key;
+ if (!key.isEmpty()) {
+ d->sc_sequences = { key };
+ d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap);
+ }
+ if (member)
+ connect(this, SIGNAL(activated()), parent, member);
+ if (ambiguousMember)
+ connect(this, SIGNAL(activatedAmbiguously()), parent, ambiguousMember);
+}
+
+/*!
+ \since 6.0
+ Constructs a QShortcut object for the \a parent, which should be a
+ QWindow or a QWidget.
+
+ The shortcut operates on its parent, listening for \l{QShortcutEvent}s that
+ match the \a standardKey. Depending on the ambiguity of the event, the
+ shortcut will call the \a member function, or the \a ambiguousMember function,
+ if the key press was in the shortcut's \a context.
+*/
+QShortcut::QShortcut(QKeySequence::StandardKey standardKey, QObject *parent,
+ const char *member, const char *ambiguousMember,
+ Qt::ShortcutContext context)
+ : QShortcut(parent)
+{
+ Q_D(QShortcut);
+ d->sc_context = context;
+ d->sc_sequences = QKeySequence::keyBindings(standardKey);
d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap);
if (member)
connect(this, SIGNAL(activated()), parent, member);
@@ -220,10 +219,7 @@ QShortcut::QShortcut(const QKeySequence &key, QObject *parent,
/*!
- \fn template<typename Functor>
- QShortcut(const QKeySequence &key, QObject *parent,
- Functor functor,
- Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
+ \fn template<typename Functor> QShortcut::QShortcut(const QKeySequence &key, QObject *parent, Functor functor, Qt::ShortcutContext shortcutContext = Qt::WindowShortcut)
\since 5.15
\overload
@@ -231,10 +227,7 @@ QShortcut::QShortcut(const QKeySequence &key, QObject *parent,
\l{QShortcut::activated()}{activated()} signal to the \a functor.
*/
/*!
- \fn template<typename Functor>
- QShortcut(const QKeySequence &key, QObject *parent,
- const QObject *context, Functor functor,
- Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
+ \fn template<typename Functor> QShortcut::QShortcut(const QKeySequence &key, QObject *parent, const QObject *context, Functor functor, Qt::ShortcutContext shortcutContext = Qt::WindowShortcut)
\since 5.15
\overload
@@ -246,46 +239,94 @@ QShortcut::QShortcut(const QKeySequence &key, QObject *parent,
If the \a context object is destroyed, the \a functor will not be called.
*/
/*!
- \fn template<typename Functor, typename FunctorAmbiguous>
- QShortcut(const QKeySequence &key, QObject *parent,
- const QObject *context1, Functor functor,
- FunctorAmbiguous functorAmbiguous,
- Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
+ \fn template<typename Functor, typename FunctorAmbiguous> QShortcut::QShortcut(const QKeySequence &key, QObject *parent, const QObject *context, Functor functor, FunctorAmbiguous functorAmbiguous, Qt::ShortcutContext shortcutContext = Qt::WindowShortcut)
\since 5.15
\overload
This is a QShortcut convenience constructor which connects the shortcut's
\l{QShortcut::activated()}{activated()} signal to the \a functor and
\l{QShortcut::activatedAmbiguously()}{activatedAmbiguously()}
- signal to the \a FunctorAmbiguous.
+ signal to the \a functorAmbiguous.
- The \a functor and \a FunctorAmbiguous can be a pointer to a member
+ The \a functor and \a functorAmbiguous can be a pointer to a member
function of the \a context object.
If the \a context object is destroyed, the \a functor and
- \a FunctorAmbiguous will not be called.
+ \a functorAmbiguous will not be called.
*/
/*!
- \fn template<typename Functor, typename FunctorAmbiguous>
- QShortcut(const QKeySequence &key, QObject *parent,
- const QObject *context1, Functor functor,
- const QObject *context2, FunctorAmbiguous functorAmbiguous,
- Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
+ \fn template<typename Functor, typename FunctorAmbiguous> QShortcut::QShortcut(const QKeySequence &key, QObject *parent, const QObject *context1, Functor functor, const QObject *context2, FunctorAmbiguous functorAmbiguous, Qt::ShortcutContext shortcutContext = Qt::WindowShortcut)
\since 5.15
\overload
This is a QShortcut convenience constructor which connects the shortcut's
\l{QShortcut::activated()}{activated()} signal to the \a functor and
\l{QShortcut::activatedAmbiguously()}{activatedAmbiguously()}
- signal to the \a FunctorAmbiguous.
+ signal to the \a functorAmbiguous.
+
+ The \a functor can be a pointer to a member function of the
+ \a context1 object.
+ The \a functorAmbiguous can be a pointer to a member function of the
+ \a context2 object.
+
+ If the \a context1 object is destroyed, the \a functor will not be called.
+ If the \a context2 object is destroyed, the \a functorAmbiguous
+ will not be called.
+*/
+
+/*!
+ \fn template<typename Functor> QShortcut::QShortcut(QKeySequence::StandardKey key, QObject *parent, Functor functor, Qt::ShortcutContext shortcutContext = Qt::WindowShortcut)
+ \since 6.0
+ \overload
+
+ This is a QShortcut convenience constructor which connects the shortcut's
+ \l{QShortcut::activated()}{activated()} signal to the \a functor.
+*/
+/*!
+ \fn template<typename Functor> QShortcut::QShortcut(QKeySequence::StandardKey key, QObject *parent, const QObject *context, Functor functor, Qt::ShortcutContext shortcutContext = Qt::WindowShortcut)
+ \since 6.0
+ \overload
+
+ This is a QShortcut convenience constructor which connects the shortcut's
+ \l{QShortcut::activated()}{activated()} signal to the \a functor.
+
+ The \a functor can be a pointer to a member function of the \a context object.
+
+ If the \a context object is destroyed, the \a functor will not be called.
+*/
+/*!
+ \fn template<typename Functor, typename FunctorAmbiguous> QShortcut::QShortcut(QKeySequence::StandardKey key, QObject *parent, const QObject *context, Functor functor, FunctorAmbiguous functorAmbiguous, Qt::ShortcutContext shortcutContext = Qt::WindowShortcut)
+ \since 6.0
+ \overload
+
+ This is a QShortcut convenience constructor which connects the shortcut's
+ \l{QShortcut::activated()}{activated()} signal to the \a functor and
+ \l{QShortcut::activatedAmbiguously()}{activatedAmbiguously()}
+ signal to the \a functorAmbiguous.
+
+ The \a functor and \a functorAmbiguous can be a pointer to a member
+ function of the \a context object.
+
+ If the \a context object is destroyed, the \a functor and
+ \a functorAmbiguous will not be called.
+*/
+/*!
+ \fn template<typename Functor, typename FunctorAmbiguous> QShortcut::QShortcut(QKeySequence::StandardKey key, QObject *parent, const QObject *context1, Functor functor, const QObject *context2, FunctorAmbiguous functorAmbiguous, Qt::ShortcutContext shortcutContext = Qt::WindowShortcut)
+ \since 6.0
+ \overload
+
+ This is a QShortcut convenience constructor which connects the shortcut's
+ \l{QShortcut::activated()}{activated()} signal to the \a functor and
+ \l{QShortcut::activatedAmbiguously()}{activatedAmbiguously()}
+ signal to the \a functorAmbiguous.
The \a functor can be a pointer to a member function of the
\a context1 object.
- The \a FunctorAmbiguous can be a pointer to a member function of the
+ The \a functorAmbiguous can be a pointer to a member function of the
\a context2 object.
If the \a context1 object is destroyed, the \a functor will not be called.
- If the \a context2 object is destroyed, the \a FunctorAmbiguous
+ If the \a context2 object is destroyed, the \a functorAmbiguous
will not be called.
*/
@@ -295,13 +336,15 @@ QShortcut::QShortcut(const QKeySequence &key, QObject *parent,
QShortcut::~QShortcut()
{
Q_D(QShortcut);
- if (qApp)
- QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(d->sc_id, this);
+ if (qApp) {
+ for (int id : std::as_const(d->sc_ids))
+ QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(id, this);
+ }
}
/*!
\property QShortcut::key
- \brief the shortcut's key sequence
+ \brief the shortcut's primary key sequence
This is a key sequence with an optional combination of Shift, Ctrl,
and Alt. The key sequence may be supplied in a number of ways:
@@ -312,18 +355,61 @@ QShortcut::~QShortcut()
*/
void QShortcut::setKey(const QKeySequence &key)
{
+ if (key.isEmpty())
+ setKeys({});
+ else
+ setKeys({ key });
+}
+
+QKeySequence QShortcut::key() const
+{
+ Q_D(const QShortcut);
+ if (d->sc_sequences.isEmpty())
+ return QKeySequence();
+ return d->sc_sequences.first();
+}
+
+/*!
+ Sets \a keys as the list of key sequences that trigger the
+ shortcut.
+
+ \since 6.0
+
+ \sa key, keys()
+*/
+void QShortcut::setKeys(const QList<QKeySequence> &keys)
+{
Q_D(QShortcut);
- if (d->sc_sequence == key)
+ if (d->sc_sequences == keys)
return;
- QAPP_CHECK("setKey");
- d->sc_sequence = key;
+ QAPP_CHECK("setKeys");
+ d->sc_sequences = keys;
d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap);
}
-QKeySequence QShortcut::key() const
+/*!
+ Sets the triggers to those matching the standard key \a key.
+
+ \since 6.0
+
+ \sa key, keys()
+*/
+void QShortcut::setKeys(QKeySequence::StandardKey key)
+{
+ setKeys(QKeySequence::keyBindings(key));
+}
+
+/*!
+ Returns the list of key sequences which trigger this
+ shortcut.
+
+ \since 6.0
+ \sa key, setKeys()
+*/
+QList<QKeySequence> QShortcut::keys() const
{
Q_D(const QShortcut);
- return d->sc_sequence;
+ return d->sc_sequences;
}
/*!
@@ -348,7 +434,8 @@ void QShortcut::setEnabled(bool enable)
return;
QAPP_CHECK("setEnabled");
d->sc_enabled = enable;
- QGuiApplicationPrivate::instance()->shortcutMap.setShortcutEnabled(enable, d->sc_id, this);
+ for (int id : d->sc_ids)
+ QGuiApplicationPrivate::instance()->shortcutMap.setShortcutEnabled(enable, id, this);
}
bool QShortcut::isEnabled() const
@@ -401,7 +488,8 @@ void QShortcut::setAutoRepeat(bool on)
return;
QAPP_CHECK("setAutoRepeat");
d->sc_autorepeat = on;
- QGuiApplicationPrivate::instance()->shortcutMap.setShortcutAutoRepeat(on, d->sc_id, this);
+ for (int id : d->sc_ids)
+ QGuiApplicationPrivate::instance()->shortcutMap.setShortcutAutoRepeat(on, id, this);
}
bool QShortcut::autoRepeat() const
@@ -412,8 +500,7 @@ bool QShortcut::autoRepeat() const
/*!
- \property QShortcut::whatsThis
- \brief the shortcut's "What's This?" help text
+ Sets the shortcut's "What's This?" help \a text.
The text will be shown when a widget application is in "What's
This?" mode and the user types the shortcut key() sequence.
@@ -421,9 +508,9 @@ bool QShortcut::autoRepeat() const
To set "What's This?" help on a menu item (with or without a
shortcut key), set the help on the item's action.
- By default, this property contains an empty string.
+ By default, the help text is an empty string.
- This property has no effect in applications that don't use
+ This function has no effect in applications that don't use
widgets.
\sa QWhatsThis::inWhatsThisMode(), QAction::setWhatsThis()
@@ -434,23 +521,33 @@ void QShortcut::setWhatsThis(const QString &text)
d->sc_whatsthis = text;
}
+/*!
+ Returns the shortcut's "What's This?" help text.
+
+ \sa setWhatsThis()
+*/
QString QShortcut::whatsThis() const
{
Q_D(const QShortcut);
return d->sc_whatsthis;
}
-
+#if QT_DEPRECATED_SINCE(6,0)
/*!
- Returns the shortcut's ID.
+ Returns the primary key binding's ID.
+
+ \deprecated
\sa QShortcutEvent::shortcutId()
*/
int QShortcut::id() const
{
Q_D(const QShortcut);
- return d->sc_id;
+ if (d->sc_ids.isEmpty())
+ return 0;
+ return d->sc_ids.first();
}
+#endif
/*!
\fn QWidget *QShortcut::parentWidget() const
@@ -466,8 +563,8 @@ bool QShortcut::event(QEvent *e)
Q_D(QShortcut);
if (d->sc_enabled && e->type() == QEvent::Shortcut) {
auto se = static_cast<QShortcutEvent *>(e);
- if (se->shortcutId() == d->sc_id && se->key() == d->sc_sequence
- && !d->handleWhatsThis()) {
+ if (!d->handleWhatsThis()) {
+ Q_ASSERT_X(d->sc_ids.contains(se->shortcutId()), "QShortcut::event", "Received shortcut event from wrong shortcut");
if (se->isAmbiguous())
emit activatedAmbiguously();
else
diff --git a/src/gui/kernel/qshortcut.h b/src/gui/kernel/qshortcut.h
index 1b90a21925..00b9168bea 100644
--- a/src/gui/kernel/qshortcut.h
+++ b/src/gui/kernel/qshortcut.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSHORTCUT_H
#define QSHORTCUT_H
@@ -64,8 +28,11 @@ public:
explicit QShortcut(const QKeySequence& key, QObject *parent,
const char *member = nullptr, const char *ambiguousMember = nullptr,
Qt::ShortcutContext context = Qt::WindowShortcut);
+ explicit QShortcut(QKeySequence::StandardKey key, QObject *parent,
+ const char *member = nullptr, const char *ambiguousMember = nullptr,
+ Qt::ShortcutContext context = Qt::WindowShortcut);
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template<typename Functor>
QShortcut(const QKeySequence &key, QObject *parent,
Functor functor,
@@ -84,6 +51,25 @@ public:
const QObject *context1, Functor functor,
const QObject *context2, FunctorAmbiguous functorAmbiguous,
Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
+
+ template<typename Functor>
+ QShortcut(QKeySequence::StandardKey key, QObject *parent,
+ Functor functor,
+ Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
+ template<typename Functor>
+ QShortcut(QKeySequence::StandardKey key, QObject *parent,
+ const QObject *context, Functor functor,
+ Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
+ template<typename Functor, typename FunctorAmbiguous>
+ QShortcut(QKeySequence::StandardKey key, QObject *parent,
+ const QObject *context1, Functor functor,
+ FunctorAmbiguous functorAmbiguous,
+ Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
+ template<typename Functor, typename FunctorAmbiguous>
+ QShortcut(QKeySequence::StandardKey key, QObject *parent,
+ const QObject *context1, Functor functor,
+ const QObject *context2, FunctorAmbiguous functorAmbiguous,
+ Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
#else
template<typename Func1>
QShortcut(const QKeySequence &key, QObject *parent,
@@ -124,12 +110,55 @@ public:
connect(this, &QShortcut::activated, object1, std::move(slot1));
connect(this, &QShortcut::activatedAmbiguously, object2, std::move(slot2));
}
+
+ template<typename Func1>
+ QShortcut(QKeySequence::StandardKey key, QObject *parent,
+ Func1 slot1,
+ Qt::ShortcutContext context = Qt::WindowShortcut)
+ : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
+ {
+ connect(this, &QShortcut::activated, std::move(slot1));
+ }
+ template<class Obj1, typename Func1>
+ QShortcut(QKeySequence::StandardKey key, QObject *parent,
+ const Obj1 *object1, Func1 slot1,
+ Qt::ShortcutContext context = Qt::WindowShortcut,
+ typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj1*>::Value>::type* = 0)
+ : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
+ {
+ connect(this, &QShortcut::activated, object1, std::move(slot1));
+ }
+ template<class Obj1, typename Func1, typename Func2>
+ QShortcut(QKeySequence::StandardKey key, QObject *parent,
+ const Obj1 *object1, Func1 slot1, Func2 slot2,
+ Qt::ShortcutContext context = Qt::WindowShortcut,
+ typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj1*>::Value>::type* = 0)
+ : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
+ {
+ connect(this, &QShortcut::activated, object1, std::move(slot1));
+ connect(this, &QShortcut::activatedAmbiguously, object1, std::move(slot2));
+ }
+ template<class Obj1, typename Func1, class Obj2, typename Func2>
+ QShortcut(QKeySequence::StandardKey key, QObject *parent,
+ const Obj1 *object1, Func1 slot1,
+ const Obj2 *object2, Func2 slot2,
+ Qt::ShortcutContext context = Qt::WindowShortcut,
+ typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj1*>::Value>::type* = 0,
+ typename std::enable_if<QtPrivate::IsPointerToTypeDerivedFromQObject<Obj2*>::Value>::type* = 0)
+ : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
+ {
+ connect(this, &QShortcut::activated, object1, std::move(slot1));
+ connect(this, &QShortcut::activatedAmbiguously, object2, std::move(slot2));
+ }
#endif
~QShortcut();
void setKey(const QKeySequence& key);
QKeySequence key() const;
+ void setKeys(QKeySequence::StandardKey key);
+ void setKeys(const QList<QKeySequence> &keys);
+ QList<QKeySequence> keys() const;
void setEnabled(bool enable);
bool isEnabled() const;
@@ -140,16 +169,19 @@ public:
void setAutoRepeat(bool on);
bool autoRepeat() const;
- int id() const;
+#if QT_DEPRECATED_SINCE(6,0)
+ QT_DEPRECATED_VERSION_6_0 int id() const;
+#endif
void setWhatsThis(const QString &text);
QString whatsThis() const;
#if QT_DEPRECATED_SINCE(6,0)
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
QWidget *parentWidget() const;
#else
template<typename T = QWidget*>
+ QT_DEPRECATED_VERSION_X_6_0("Use parent() and qobject_cast instead")
inline T parentWidget() const
{ return static_cast<T>(QObject::parent()); }
#endif
diff --git a/src/gui/kernel/qshortcut_p.h b/src/gui/kernel/qshortcut_p.h
index 254745960f..8ff833d477 100644
--- a/src/gui/kernel/qshortcut_p.h
+++ b/src/gui/kernel/qshortcut_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSHORTCUT_P_H
#define QSHORTCUT_P_H
@@ -55,13 +19,13 @@
#include "qshortcut.h"
#include <QtGui/qkeysequence.h>
+#include <QtCore/qlist.h>
#include <QtCore/qstring.h>
#include <QtCore/private/qobject_p.h>
#include <private/qshortcutmap_p.h>
-
QT_BEGIN_NAMESPACE
class QShortcutMap;
@@ -79,12 +43,14 @@ public:
virtual QShortcutMap::ContextMatcher contextMatcher() const;
virtual bool handleWhatsThis() { return false; }
- QKeySequence sc_sequence;
+ static bool simpleContextMatcher(QObject *object, Qt::ShortcutContext context);
+
+ QList<QKeySequence> sc_sequences;
QString sc_whatsthis;
Qt::ShortcutContext sc_context = Qt::WindowShortcut;
bool sc_enabled = true;
bool sc_autorepeat = true;
- int sc_id = 0;
+ QList<int> sc_ids;
void redoGrab(QShortcutMap &map);
};
diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp
index 2152418641..800e703ac2 100644
--- a/src/gui/kernel/qshortcutmap.cpp
+++ b/src/gui/kernel/qshortcutmap.cpp
@@ -1,51 +1,17 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qshortcutmap_p.h"
#include "private/qobject_p.h"
#include "qkeysequence.h"
#include "qdebug.h"
#include "qevent.h"
-#include "qvector.h"
-#include "qcoreapplication.h"
+#include "qlist.h"
+#include "qguiapplication.h"
+#include "qwindow.h"
#include <private/qkeymapper_p.h>
#include <QtCore/qloggingcategory.h>
+#include <QtCore/qscopeguard.h>
#include <algorithm>
@@ -63,23 +29,23 @@ Q_LOGGING_CATEGORY(lcShortcutMap, "qt.gui.shortcutmap")
struct QShortcutEntry
{
QShortcutEntry()
- : keyseq(0), context(Qt::WindowShortcut), enabled(false), autorepeat(1), id(0), owner(nullptr), contextMatcher(nullptr)
+ : keySequence(0), context(Qt::WindowShortcut), enabled(false), autorepeat(1), id(0), owner(nullptr), contextMatcher(nullptr)
{}
QShortcutEntry(const QKeySequence &k)
- : keyseq(k), context(Qt::WindowShortcut), enabled(false), autorepeat(1), id(0), owner(nullptr), contextMatcher(nullptr)
+ : keySequence(k), context(Qt::WindowShortcut), enabled(false), autorepeat(1), id(0), owner(nullptr), contextMatcher(nullptr)
{}
QShortcutEntry(QObject *o, const QKeySequence &k, Qt::ShortcutContext c, int i, bool a, QShortcutMap::ContextMatcher m)
- : keyseq(k), context(c), enabled(true), autorepeat(a), id(i), owner(o), contextMatcher(m)
+ : keySequence(k), context(c), enabled(true), autorepeat(a), id(i), owner(o), contextMatcher(m)
{}
bool correctContext() const { return contextMatcher(owner, context); }
bool operator<(const QShortcutEntry &f) const
- { return keyseq < f.keyseq; }
+ { return keySequence < f.keySequence; }
- QKeySequence keyseq;
+ QKeySequence keySequence;
Qt::ShortcutContext context;
bool enabled : 1;
bool autorepeat : 1;
@@ -87,7 +53,7 @@ struct QShortcutEntry
QObject *owner;
QShortcutMap::ContextMatcher contextMatcher;
};
-Q_DECLARE_TYPEINFO(QShortcutEntry, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QShortcutEntry, Q_RELOCATABLE_TYPE);
#ifdef Dump_QShortcutMap
/*! \internal
@@ -122,15 +88,15 @@ public:
}
QShortcutMap *q_ptr; // Private's parent
- QVector<QShortcutEntry> sequences; // All sequences!
+ QList<QShortcutEntry> shortcuts; // All shortcuts!
int currentId; // Global shortcut ID number
int ambigCount; // Index of last enabled ambiguous dispatch
QKeySequence::SequenceMatch currentState;
- QVector<QKeySequence> currentSequences; // Sequence for the current state
- QVector<QKeySequence> newEntries;
+ QList<QKeySequence> currentSequences; // Sequence for the current state
+ QList<QKeySequence> newEntries;
QKeySequence prevSequence; // Sequence for the previous identical match
- QVector<const QShortcutEntry*> identicals; // Last identical matches
+ QList<const QShortcutEntry*> identicals; // Last identical matches
};
@@ -154,18 +120,18 @@ QShortcutMap::~QShortcutMap()
Adds a shortcut to the global map.
Returns the id of the newly added shortcut.
*/
-int QShortcutMap::addShortcut(QObject *owner, const QKeySequence &key, Qt::ShortcutContext context, ContextMatcher matcher)
+int QShortcutMap::addShortcut(QObject *owner, const QKeySequence &keySequence, Qt::ShortcutContext context, ContextMatcher matcher)
{
Q_ASSERT_X(owner, "QShortcutMap::addShortcut", "All shortcuts need an owner");
- Q_ASSERT_X(!key.isEmpty(), "QShortcutMap::addShortcut", "Cannot add keyless shortcuts to map");
+ Q_ASSERT_X(!keySequence.isEmpty(), "QShortcutMap::addShortcut", "Cannot add keyless shortcuts to map");
Q_D(QShortcutMap);
- QShortcutEntry newEntry(owner, key, context, --(d->currentId), true, matcher);
- const auto it = std::upper_bound(d->sequences.begin(), d->sequences.end(), newEntry);
- d->sequences.insert(it, newEntry); // Insert sorted
+ QShortcutEntry newEntry(owner, keySequence, context, --(d->currentId), true, matcher);
+ const auto it = std::upper_bound(d->shortcuts.begin(), d->shortcuts.end(), newEntry);
+ d->shortcuts.insert(it, newEntry); // Insert sorted
qCDebug(lcShortcutMap).nospace()
<< "QShortcutMap::addShortcut(" << owner << ", "
- << key << ", " << context << ") = " << d->currentId;
+ << keySequence << ", " << context << ") added shortcut with ID " << d->currentId;
return d->currentId;
}
@@ -178,39 +144,42 @@ int QShortcutMap::addShortcut(QObject *owner, const QKeySequence &key, Qt::Short
Returns the number of sequences removed from the map.
*/
-int QShortcutMap::removeShortcut(int id, QObject *owner, const QKeySequence &key)
+int QShortcutMap::removeShortcut(int id, QObject *owner, const QKeySequence &keySequence)
{
Q_D(QShortcutMap);
int itemsRemoved = 0;
bool allOwners = (owner == nullptr);
- bool allKeys = key.isEmpty();
+ bool allKeys = keySequence.isEmpty();
bool allIds = id == 0;
+ auto debug = qScopeGuard([&](){
+ qCDebug(lcShortcutMap).nospace()
+ << "QShortcutMap::removeShortcut(" << id << ", " << owner << ", "
+ << keySequence << ") removed " << itemsRemoved << " shortcuts(s)";
+ });
+
// Special case, remove everything
if (allOwners && allKeys && allIds) {
- itemsRemoved = d->sequences.size();
- d->sequences.clear();
+ itemsRemoved = d->shortcuts.size();
+ d->shortcuts.clear();
return itemsRemoved;
}
- int i = d->sequences.size()-1;
+ int i = d->shortcuts.size()-1;
while (i>=0)
{
- const QShortcutEntry &entry = d->sequences.at(i);
+ const QShortcutEntry &entry = d->shortcuts.at(i);
int entryId = entry.id;
if ((allOwners || entry.owner == owner)
&& (allIds || entry.id == id)
- && (allKeys || entry.keyseq == key)) {
- d->sequences.removeAt(i);
+ && (allKeys || entry.keySequence == keySequence)) {
+ d->shortcuts.removeAt(i);
++itemsRemoved;
}
if (id == entryId)
return itemsRemoved;
--i;
}
- qCDebug(lcShortcutMap).nospace()
- << "QShortcutMap::removeShortcut(" << id << ", " << owner << ", "
- << key << ") = " << itemsRemoved;
return itemsRemoved;
}
@@ -222,22 +191,22 @@ int QShortcutMap::removeShortcut(int id, QObject *owner, const QKeySequence &key
are changed.
Returns the number of sequences which are matched in the map.
*/
-int QShortcutMap::setShortcutEnabled(bool enable, int id, QObject *owner, const QKeySequence &key)
+int QShortcutMap::setShortcutEnabled(bool enable, int id, QObject *owner, const QKeySequence &keySequence)
{
Q_D(QShortcutMap);
int itemsChanged = 0;
bool allOwners = (owner == nullptr);
- bool allKeys = key.isEmpty();
+ bool allKeys = keySequence.isEmpty();
bool allIds = id == 0;
- int i = d->sequences.size()-1;
+ int i = d->shortcuts.size()-1;
while (i>=0)
{
- QShortcutEntry entry = d->sequences.at(i);
+ QShortcutEntry entry = d->shortcuts.at(i);
if ((allOwners || entry.owner == owner)
&& (allIds || entry.id == id)
- && (allKeys || entry.keyseq == key)) {
- d->sequences[i].enabled = enable;
+ && (allKeys || entry.keySequence == keySequence)) {
+ d->shortcuts[i].enabled = enable;
++itemsChanged;
}
if (id == entry.id)
@@ -246,7 +215,7 @@ int QShortcutMap::setShortcutEnabled(bool enable, int id, QObject *owner, const
}
qCDebug(lcShortcutMap).nospace()
<< "QShortcutMap::setShortcutEnabled(" << enable << ", " << id << ", "
- << owner << ", " << key << ") = " << itemsChanged;
+ << owner << ", " << keySequence << ") = " << itemsChanged;
return itemsChanged;
}
@@ -258,22 +227,22 @@ int QShortcutMap::setShortcutEnabled(bool enable, int id, QObject *owner, const
are changed.
Returns the number of sequences which are matched in the map.
*/
-int QShortcutMap::setShortcutAutoRepeat(bool on, int id, QObject *owner, const QKeySequence &key)
+int QShortcutMap::setShortcutAutoRepeat(bool on, int id, QObject *owner, const QKeySequence &keySequence)
{
Q_D(QShortcutMap);
int itemsChanged = 0;
bool allOwners = (owner == nullptr);
- bool allKeys = key.isEmpty();
+ bool allKeys = keySequence.isEmpty();
bool allIds = id == 0;
- int i = d->sequences.size()-1;
+ int i = d->shortcuts.size()-1;
while (i>=0)
{
- QShortcutEntry entry = d->sequences.at(i);
+ QShortcutEntry entry = d->shortcuts.at(i);
if ((allOwners || entry.owner == owner)
&& (allIds || entry.id == id)
- && (allKeys || entry.keyseq == key)) {
- d->sequences[i].autorepeat = on;
+ && (allKeys || entry.keySequence == keySequence)) {
+ d->shortcuts[i].autorepeat = on;
++itemsChanged;
}
if (id == entry.id)
@@ -282,7 +251,7 @@ int QShortcutMap::setShortcutAutoRepeat(bool on, int id, QObject *owner, const Q
}
qCDebug(lcShortcutMap).nospace()
<< "QShortcutMap::setShortcutAutoRepeat(" << on << ", " << id << ", "
- << owner << ", " << key << ") = " << itemsChanged;
+ << owner << ", " << keySequence << ") = " << itemsChanged;
return itemsChanged;
}
@@ -336,7 +305,7 @@ bool QShortcutMap::tryShortcut(QKeyEvent *e)
case QKeySequence::ExactMatch: {
// Save number of identical matches before dispatching
// to keep QShortcutMap and tryShortcut reentrant.
- const int identicalMatches = d->identicals.count();
+ const int identicalMatches = d->identicals.size();
resetState();
dispatchEvent(e);
// If there are no identicals we've only found disabled shortcuts, and
@@ -344,8 +313,7 @@ bool QShortcutMap::tryShortcut(QKeyEvent *e)
return identicalMatches > 0;
}
}
- Q_UNREACHABLE();
- return false;
+ Q_UNREACHABLE_RETURN(false);
}
/*! \internal
@@ -359,7 +327,7 @@ QKeySequence::SequenceMatch QShortcutMap::nextState(QKeyEvent *e)
Q_D(QShortcutMap);
// Modifiers can NOT be shortcuts...
if (e->key() >= Qt::Key_Shift &&
- e->key() <= Qt::Key_Alt)
+ e->key() <= Qt::Key_ScrollLock)
return d->currentState;
QKeySequence::SequenceMatch result = QKeySequence::NoMatch;
@@ -391,17 +359,18 @@ QKeySequence::SequenceMatch QShortcutMap::nextState(QKeyEvent *e)
/*! \internal
- Determines if an enabled shortcut has a matcing key sequence.
+ Determines if an enabled shortcut has a matching key sequence.
*/
bool QShortcutMap::hasShortcutForKeySequence(const QKeySequence &seq) const
{
Q_D(const QShortcutMap);
QShortcutEntry entry(seq); // needed for searching
- const auto itEnd = d->sequences.cend();
- auto it = std::lower_bound(d->sequences.cbegin(), itEnd, entry);
+ const auto itEnd = d->shortcuts.cend();
+ auto it = std::lower_bound(d->shortcuts.cbegin(), itEnd, entry);
for (;it != itEnd; ++it) {
- if (matches(entry.keyseq, (*it).keyseq) == QKeySequence::ExactMatch && (*it).correctContext() && (*it).enabled) {
+ if (entry.keySequence.matches(it->keySequence) == QKeySequence::ExactMatch
+ && (*it).correctContext() && (*it).enabled) {
return true;
}
}
@@ -413,22 +382,22 @@ bool QShortcutMap::hasShortcutForKeySequence(const QKeySequence &seq) const
/*! \internal
Returns the next state of the statemachine, based
on the new key event \a e.
- Matches are appended to the vector of identicals,
+ Matches are appended to the list of identicals,
which can be access through matches().
\sa matches
*/
QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e, int ignoredModifiers)
{
Q_D(QShortcutMap);
- if (!d->sequences.count())
+ if (!d->shortcuts.size())
return QKeySequence::NoMatch;
createNewSequences(e, d->newEntries, ignoredModifiers);
- qCDebug(lcShortcutMap) << "Possible shortcut key sequences:" << d->newEntries;
+ qCDebug(lcShortcutMap) << "Possible input sequences:" << d->newEntries;
// Should never happen
if (d->newEntries == d->currentSequences) {
- Q_ASSERT_X(e->key() != Qt::Key_unknown || e->text().length(),
+ Q_ASSERT_X(e->key() != Qt::Key_unknown || e->text().size(),
"QShortcutMap::find", "New sequence to find identical to previous");
return QKeySequence::NoMatch;
}
@@ -438,27 +407,34 @@ QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e, int ignoredModifier
bool partialFound = false;
bool identicalDisabledFound = false;
- QVector<QKeySequence> okEntries;
- int result = QKeySequence::NoMatch;
- for (int i = d->newEntries.count()-1; i >= 0 ; --i) {
+ QList<QKeySequence> okEntries;
+ QKeySequence::SequenceMatch result = QKeySequence::NoMatch;
+ for (int i = d->newEntries.size()-1; i >= 0 ; --i) {
QShortcutEntry entry(d->newEntries.at(i)); // needed for searching
- const auto itEnd = d->sequences.constEnd();
- auto it = std::lower_bound(d->sequences.constBegin(), itEnd, entry);
+ qCDebug(lcShortcutMap) << "Looking for shortcuts matching" << entry.keySequence;
- int oneKSResult = QKeySequence::NoMatch;
- int tempRes = QKeySequence::NoMatch;
- do {
- if (it == itEnd)
+ QKeySequence::SequenceMatch bestMatchForEntry = QKeySequence::NoMatch;
+
+ const auto itEnd = d->shortcuts.constEnd();
+ auto it = std::lower_bound(d->shortcuts.constBegin(), itEnd, entry);
+ for (; it != itEnd; ++it) {
+ QKeySequence::SequenceMatch match = entry.keySequence.matches(it->keySequence);
+ qCDebug(lcShortcutMap) << " -" << match << "for shortcut" << it->keySequence;
+
+ // If we got a valid match, there might still be more keys to check against,
+ // but if we get no match, we know that there are no more possible matches.
+ if (match == QKeySequence::NoMatch)
break;
- tempRes = matches(entry.keyseq, (*it).keyseq);
- oneKSResult = qMax(oneKSResult, tempRes);
- if (tempRes != QKeySequence::NoMatch && (*it).correctContext()) {
- if (tempRes == QKeySequence::ExactMatch) {
+
+ bestMatchForEntry = qMax(bestMatchForEntry, match);
+
+ if ((*it).correctContext()) {
+ if (match == QKeySequence::ExactMatch) {
if ((*it).enabled)
d->identicals.append(&*it);
else
identicalDisabledFound = true;
- } else if (tempRes == QKeySequence::PartialMatch) {
+ } else if (match == QKeySequence::PartialMatch) {
// We don't need partials, if we have identicals
if (d->identicals.size())
break;
@@ -466,20 +442,18 @@ QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e, int ignoredModifier
// key events when all partials are disabled!
partialFound |= (*it).enabled;
}
+ } else {
+ qCDebug(lcShortcutMap) << " - But context was not correct";
}
- ++it;
- // If we got a valid match on this run, there might still be more keys to check against,
- // so we'll loop once more. If we get NoMatch, there's guaranteed no more possible
- // matches in the shortcutmap.
- } while (tempRes != QKeySequence::NoMatch);
+ }
// If the type of match improves (ergo, NoMatch->Partial, or Partial->Exact), clear the
// previous list. If this match is equal or better than the last match, append to the list
- if (oneKSResult > result) {
+ if (bestMatchForEntry > result) {
okEntries.clear();
qCDebug(lcShortcutMap) << "Found better match (" << d->newEntries << "), clearing key sequence list";
}
- if (oneKSResult && oneKSResult >= result) {
+ if (bestMatchForEntry && bestMatchForEntry >= result) {
okEntries << d->newEntries.at(i);
qCDebug(lcShortcutMap) << "Added ok key sequence" << d->newEntries;
}
@@ -498,7 +472,7 @@ QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e, int ignoredModifier
if (result != QKeySequence::NoMatch)
d->currentSequences = okEntries;
qCDebug(lcShortcutMap) << "Returning shortcut match == " << result;
- return QKeySequence::SequenceMatch(result);
+ return result;
}
/*! \internal
@@ -506,7 +480,7 @@ QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e, int ignoredModifier
Same as doing (the slower)
\snippet code/src_gui_kernel_qshortcutmap.cpp 0
*/
-void QShortcutMap::clearSequence(QVector<QKeySequence> &ksl)
+void QShortcutMap::clearSequence(QList<QKeySequence> &ksl)
{
ksl.clear();
d_func()->newEntries.clear();
@@ -516,17 +490,17 @@ void QShortcutMap::clearSequence(QVector<QKeySequence> &ksl)
Alters \a seq to the new sequence state, based on the
current sequence state, and the new key event \a e.
*/
-void QShortcutMap::createNewSequences(QKeyEvent *e, QVector<QKeySequence> &ksl, int ignoredModifiers)
+void QShortcutMap::createNewSequences(QKeyEvent *e, QList<QKeySequence> &ksl, int ignoredModifiers)
{
Q_D(QShortcutMap);
- QList<int> possibleKeys = QKeyMapper::possibleKeys(e);
+ QList<QKeyCombination> possibleKeys = QKeyMapper::possibleKeys(e);
qCDebug(lcShortcutMap) << "Creating new sequences for" << e
<< "with ignoredModifiers=" << Qt::KeyboardModifiers(ignoredModifiers);
- int pkTotal = possibleKeys.count();
+ int pkTotal = possibleKeys.size();
if (!pkTotal)
return;
- int ssActual = d->currentSequences.count();
+ int ssActual = d->currentSequences.size();
int ssTotal = qMax(1, ssActual);
// Resize to possible permutations of the current sequence(s).
ksl.resize(pkTotal * ssTotal);
@@ -543,51 +517,18 @@ void QShortcutMap::createNewSequences(QKeyEvent *e, QVector<QKeySequence> &ksl,
curKsl.setKey(curSeq[2], 2);
curKsl.setKey(curSeq[3], 3);
} else {
- curKsl.setKey(0, 0);
- curKsl.setKey(0, 1);
- curKsl.setKey(0, 2);
- curKsl.setKey(0, 3);
+ curKsl.setKey(QKeyCombination::fromCombined(0), 0);
+ curKsl.setKey(QKeyCombination::fromCombined(0), 1);
+ curKsl.setKey(QKeyCombination::fromCombined(0), 2);
+ curKsl.setKey(QKeyCombination::fromCombined(0), 3);
}
- curKsl.setKey(possibleKeys.at(pkNum) & ~ignoredModifiers, index);
+ const int key = possibleKeys.at(pkNum).toCombined();
+ curKsl.setKey(QKeyCombination::fromCombined(key & ~ignoredModifiers), index);
}
}
}
/*! \internal
- Basically the same function as QKeySequence::matches(const QKeySequence &seq) const
- only that is specially handles Key_hyphen as Key_Minus, as people mix these up all the time and
- they conceptually the same.
-*/
-QKeySequence::SequenceMatch QShortcutMap::matches(const QKeySequence &seq1,
- const QKeySequence &seq2) const
-{
- uint userN = seq1.count(),
- seqN = seq2.count();
-
- if (userN > seqN)
- return QKeySequence::NoMatch;
-
- // If equal in length, we have a potential ExactMatch sequence,
- // else we already know it can only be partial.
- QKeySequence::SequenceMatch match = (userN == seqN
- ? QKeySequence::ExactMatch
- : QKeySequence::PartialMatch);
-
- for (uint i = 0; i < userN; ++i) {
- int userKey = seq1[i],
- sequenceKey = seq2[i];
- if ((userKey & Qt::Key_unknown) == Qt::Key_hyphen)
- userKey = (userKey & Qt::KeyboardModifierMask) | Qt::Key_Minus;
- if ((sequenceKey & Qt::Key_unknown) == Qt::Key_hyphen)
- sequenceKey = (sequenceKey & Qt::KeyboardModifierMask) | Qt::Key_Minus;
- if (userKey != sequenceKey)
- return QKeySequence::NoMatch;
- }
- return match;
-}
-
-
-/*! \internal
Converts keyboard button states into modifier states
*/
int QShortcutMap::translateModifiers(Qt::KeyboardModifiers modifiers)
@@ -605,9 +546,9 @@ int QShortcutMap::translateModifiers(Qt::KeyboardModifiers modifiers)
}
/*! \internal
- Returns the vector of QShortcutEntry's matching the last Identical state.
+ Returns the list of QShortcutEntry's matching the last Identical state.
*/
-QVector<const QShortcutEntry*> QShortcutMap::matches() const
+QList<const QShortcutEntry*> QShortcutMap::matches() const
{
Q_D(const QShortcutMap);
return d->identicals;
@@ -622,7 +563,7 @@ void QShortcutMap::dispatchEvent(QKeyEvent *e)
if (!d->identicals.size())
return;
- const QKeySequence &curKey = d->identicals.at(0)->keyseq;
+ const QKeySequence &curKey = d->identicals.at(0)->keySequence;
if (d->prevSequence != curKey) {
d->ambigCount = 0;
d->prevSequence = curKey;
@@ -630,7 +571,7 @@ void QShortcutMap::dispatchEvent(QKeyEvent *e)
// Find next
const QShortcutEntry *current = nullptr, *next = nullptr;
int i = 0, enabledShortcuts = 0;
- QVector<const QShortcutEntry*> ambiguousShortcuts;
+ QList<const QShortcutEntry*> ambiguousShortcuts;
while(i < d->identicals.size()) {
current = d->identicals.at(i);
if (current->enabled || !next){
@@ -652,19 +593,59 @@ void QShortcutMap::dispatchEvent(QKeyEvent *e)
if (lcShortcutMap().isDebugEnabled()) {
if (ambiguousShortcuts.size() > 1) {
qCDebug(lcShortcutMap) << "The following shortcuts are about to be activated ambiguously:";
- for (const QShortcutEntry *entry : qAsConst(ambiguousShortcuts))
- qCDebug(lcShortcutMap).nospace() << "- " << entry->keyseq << " (belonging to " << entry->owner << ")";
+ for (const QShortcutEntry *entry : std::as_const(ambiguousShortcuts))
+ qCDebug(lcShortcutMap).nospace() << "- " << entry->keySequence << " (belonging to " << entry->owner << ")";
}
qCDebug(lcShortcutMap).nospace()
<< "QShortcutMap::dispatchEvent(): Sending QShortcutEvent(\""
- << next->keyseq.toString() << "\", " << next->id << ", "
+ << next->keySequence.toString() << "\", " << next->id << ", "
<< static_cast<bool>(enabledShortcuts>1) << ") to object(" << next->owner << ')';
}
- QShortcutEvent se(next->keyseq, next->id, enabledShortcuts>1);
+ QShortcutEvent se(next->keySequence, next->id, enabledShortcuts > 1);
QCoreApplication::sendEvent(const_cast<QObject *>(next->owner), &se);
}
+QList<QKeySequence> QShortcutMap::keySequences(bool getAll) const
+{
+ Q_D(const QShortcutMap);
+ QList<QKeySequence> keys;
+ for (auto sequence : d->shortcuts) {
+ bool addSequence = false;
+ if (sequence.enabled) {
+ if (getAll || sequence.context == Qt::ApplicationShortcut ||
+ sequence.owner == QGuiApplication::focusObject()) {
+ addSequence = true;
+ } else {
+ QObject *possibleWindow = sequence.owner;
+ while (possibleWindow) {
+ if (qobject_cast<QWindow *>(possibleWindow))
+ break;
+ possibleWindow = possibleWindow->parent();
+ }
+ if (possibleWindow == QGuiApplication::focusWindow()) {
+ if (sequence.context == Qt::WindowShortcut) {
+ addSequence = true;
+ } else if (sequence.context == Qt::WidgetWithChildrenShortcut) {
+ QObject *possibleWidget = QGuiApplication::focusObject();
+ while (possibleWidget->parent()) {
+ possibleWidget = possibleWidget->parent();
+ if (possibleWidget == sequence.owner) {
+ addSequence = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+ if (addSequence)
+ keys << sequence.keySequence;
+ }
+ }
+ return keys;
+
+}
+
/* \internal
QShortcutMap dump function, only available when DEBUG_QSHORTCUTMAP is
defined.
@@ -673,8 +654,8 @@ void QShortcutMap::dispatchEvent(QKeyEvent *e)
void QShortcutMap::dumpMap() const
{
Q_D(const QShortcutMap);
- for (int i = 0; i < d->sequences.size(); ++i)
- qDebug().nospace() << &(d->sequences.at(i));
+ for (int i = 0; i < d->shortcuts.size(); ++i)
+ qDebug().nospace() << &(d->shortcuts.at(i));
}
#endif
diff --git a/src/gui/kernel/qshortcutmap_p.h b/src/gui/kernel/qshortcutmap_p.h
index ff92a38e56..26d2b5301c 100644
--- a/src/gui/kernel/qshortcutmap_p.h
+++ b/src/gui/kernel/qshortcutmap_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSHORTCUTMAP_P_H
#define QSHORTCUTMAP_P_H
@@ -86,6 +50,7 @@ public:
bool tryShortcut(QKeyEvent *e);
bool hasShortcutForKeySequence(const QKeySequence &seq) const;
+ QList<QKeySequence> keySequences(bool getAll = false) const;
#ifdef Dump_QShortcutMap
void dumpMap() const;
@@ -97,7 +62,6 @@ private:
void dispatchEvent(QKeyEvent *e);
QKeySequence::SequenceMatch find(QKeyEvent *e, int ignoredModifiers = 0);
- QKeySequence::SequenceMatch matches(const QKeySequence &seq1, const QKeySequence &seq2) const;
QList<const QShortcutEntry *> matches() const;
void createNewSequences(QKeyEvent *e, QList<QKeySequence> &ksl, int ignoredModifiers);
void clearSequence(QList<QKeySequence> &ksl);
diff --git a/src/gui/kernel/qsimpledrag.cpp b/src/gui/kernel/qsimpledrag.cpp
index 58fdf7a2c3..a90e8dd33c 100644
--- a/src/gui/kernel/qsimpledrag.cpp
+++ b/src/gui/kernel/qsimpledrag.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsimpledrag_p.h"
@@ -70,9 +34,10 @@ Q_LOGGING_CATEGORY(lcDnd, "qt.gui.dnd")
static QWindow* topLevelAt(const QPoint &pos)
{
- QWindowList list = QGuiApplication::topLevelWindows();
- for (int i = list.count()-1; i >= 0; --i) {
- QWindow *w = list.at(i);
+ const QWindowList list = QGuiApplication::topLevelWindows();
+ const auto crend = list.crend();
+ for (auto it = list.crbegin(); it != crend; ++it) {
+ QWindow *w = *it;
if (w->isVisible() && w->handle() && w->geometry().contains(pos) && !qobject_cast<QShapedPixmapWindow*>(w))
return w;
}
@@ -160,6 +125,7 @@ bool QBasicDrag::eventFilter(QObject *o, QEvent *e)
}
case QEvent::MouseButtonRelease:
{
+ QPointer<QObject> objGuard(o);
disableEventFilter();
if (canDrop()) {
QPoint nativePosition = getNativeMousePos(e, m_drag_icon_window);
@@ -169,6 +135,8 @@ bool QBasicDrag::eventFilter(QObject *o, QEvent *e)
cancel();
}
exitDndEventLoop();
+ if (!objGuard)
+ return true;
// If a QShapedPixmapWindow (drag feedback) is being dragged along, the
// mouse event's localPos() will be relative to that, which is useless.
@@ -180,11 +148,11 @@ bool QBasicDrag::eventFilter(QObject *o, QEvent *e)
qCDebug(lcDnd) << "mouse released over" << releaseWindow << "after drag from" << m_sourceWindow << "globalPos" << release->globalPosition().toPoint();
if (!releaseWindow)
releaseWindow = m_sourceWindow;
- QPoint releaseWindowPos = (releaseWindow ? releaseWindow->mapFromGlobal(release->globalPosition().toPoint()) : release->globalPosition().toPoint());
+ QPointF releaseWindowPos = (releaseWindow ? releaseWindow->mapFromGlobal(release->globalPosition()) : release->globalPosition());
QMouseEvent *newRelease = new QMouseEvent(release->type(),
releaseWindowPos, releaseWindowPos, release->globalPosition(),
release->button(), release->buttons(),
- release->modifiers(), release->source());
+ release->modifiers(), release->source(), release->pointingDevice());
QCoreApplication::postEvent(o, newRelease);
return true; // defer mouse release events until drag event loop has returned
}
@@ -342,7 +310,7 @@ static inline QPoint fromNativeGlobalPixels(const QPoint &point)
#ifndef QT_NO_HIGHDPISCALING
QPoint res = point;
if (QHighDpiScaling::isActive()) {
- for (const QScreen *s : qAsConst(QGuiApplicationPrivate::screen_list)) {
+ for (const QScreen *s : std::as_const(QGuiApplicationPrivate::screen_list)) {
if (s->handle()->geometry().contains(point)) {
res = QHighDpi::fromNativePixels(point, s);
break;
diff --git a/src/gui/kernel/qsimpledrag_p.h b/src/gui/kernel/qsimpledrag_p.h
index 4409deb1da..32ba1cef6f 100644
--- a/src/gui/kernel/qsimpledrag_p.h
+++ b/src/gui/kernel/qsimpledrag_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSIMPLEDRAG_P_H
#define QSIMPLEDRAG_P_H
diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp
index 7b3c70c51b..5becae76c6 100644
--- a/src/gui/kernel/qstylehints.cpp
+++ b/src/gui/kernel/qstylehints.cpp
@@ -1,43 +1,8 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <qstylehints.h>
+#include "qstylehints_p.h"
#include <qpa/qplatformintegration.h>
#include <qpa/qplatformtheme.h>
#include <private/qguiapplication_p.h>
@@ -79,25 +44,6 @@ static inline QVariant themeableHint(QPlatformTheme::ThemeHint th)
return QPlatformTheme::defaultThemeHint(th);
}
-class QStyleHintsPrivate : public QObjectPrivate
-{
- Q_DECLARE_PUBLIC(QStyleHints)
-public:
- int m_mouseDoubleClickInterval = -1;
- int m_mousePressAndHoldInterval = -1;
- int m_startDragDistance = -1;
- int m_startDragTime = -1;
- int m_keyboardInputInterval = -1;
- int m_cursorFlashTime = -1;
- int m_tabFocusBehavior = -1;
- int m_uiEffects = -1;
- int m_showShortcutsInContextMenus = -1;
- int m_wheelScrollLines = -1;
- int m_mouseQuickSelectionThreshold = -1;
- int m_mouseDoubleClickDistance = -1;
- int m_touchDoubleTapDistance = -1;
-};
-
/*!
\class QStyleHints
\since 5.0
@@ -107,11 +53,10 @@ public:
An object of this class, obtained from QGuiApplication, provides access to certain global
user interface parameters of the current platform.
- Access is read only; typically the platform itself provides the user a way to tune these
- parameters.
-
- Access to these parameters are useful when implementing custom user interface components, in that
- they allow the components to exhibit the same behaviour and feel as other components.
+ Access to most settings is read only. The platform itself usually provides the user with
+ ways to tune these parameters. Authors of custom user interface components should read
+ relevant settings to allow the components to exhibit the same behavior and feel as other
+ components.
\sa QGuiApplication::styleHints()
*/
@@ -159,7 +104,7 @@ int QStyleHints::mouseDoubleClickDistance() const
Q_D(const QStyleHints);
return d->m_mouseDoubleClickDistance >= 0 ?
d->m_mouseDoubleClickDistance :
- themeableHint(QPlatformTheme::MouseDoubleClickDistance).toInt();
+ themeableHint(QPlatformTheme::MouseDoubleClickDistance, QPlatformIntegration::MouseDoubleClickDistance).toInt();
}
/*!
@@ -177,6 +122,18 @@ int QStyleHints::touchDoubleTapDistance() const
}
/*!
+ \property QStyleHints::colorScheme
+ \brief the color scheme of the platform theme.
+ \sa Qt::ColorScheme
+ \since 6.5
+*/
+Qt::ColorScheme QStyleHints::colorScheme() const
+{
+ Q_D(const QStyleHints);
+ return d->colorScheme();
+}
+
+/*!
Sets the \a mousePressAndHoldInterval.
\internal
\sa mousePressAndHoldInterval()
@@ -322,15 +279,29 @@ int QStyleHints::keyboardInputInterval() const
themeableHint(QPlatformTheme::KeyboardInputInterval, QPlatformIntegration::KeyboardInputInterval).toInt();
}
+#if QT_DEPRECATED_SINCE(6, 5)
/*!
\property QStyleHints::keyboardAutoRepeatRate
\brief the rate, in events per second, in which additional repeated key
presses will automatically be generated if a key is being held down.
+ \deprecated [6.5] Use keyboardAutoRepeatRateF() instead
*/
int QStyleHints::keyboardAutoRepeatRate() const
{
return themeableHint(QPlatformTheme::KeyboardAutoRepeatRate, QPlatformIntegration::KeyboardAutoRepeatRate).toInt();
}
+#endif
+
+/*!
+ \property QStyleHints::keyboardAutoRepeatRateF
+ \since 6.5
+ \brief the rate, in events per second, in which additional repeated key
+ presses will automatically be generated if a key is being held down.
+*/
+qreal QStyleHints::keyboardAutoRepeatRateF() const
+{
+ return themeableHint(QPlatformTheme::KeyboardAutoRepeatRate, QPlatformIntegration::KeyboardAutoRepeatRate).toReal();
+}
/*!
Sets the \a cursorFlashTime.
@@ -406,6 +377,8 @@ bool QStyleHints::showIsMaximized() const
Since Qt 5.13, the setShowShortcutsInContextMenus() function can be used to
override the platform default.
+
+ \sa Qt::AA_DontShowShortcutsInContextMenus
*/
bool QStyleHints::showShortcutsInContextMenus() const
{
@@ -476,7 +449,7 @@ bool QStyleHints::useRtlExtensions() const
*/
bool QStyleHints::setFocusOnTouchRelease() const
{
- return hint(QPlatformIntegration::SetFocusOnTouchRelease).toBool();
+ return themeableHint(QPlatformTheme::SetFocusOnTouchRelease, QPlatformIntegration::SetFocusOnTouchRelease).toBool();
}
/*!
@@ -620,4 +593,27 @@ int QStyleHints::mouseQuickSelectionThreshold() const
return themeableHint(QPlatformTheme::MouseQuickSelectionThreshold, QPlatformIntegration::MouseQuickSelectionThreshold).toInt();
}
+/*!
+ \internal
+ QStyleHintsPrivate::setColorScheme - set a new color scheme.
+ Set \a colorScheme as the new color scheme of the QStyleHints.
+ The colorSchemeChanged signal will be emitted if present and new color scheme differ.
+ */
+void QStyleHintsPrivate::setColorScheme(Qt::ColorScheme colorScheme)
+{
+ if (m_colorScheme == colorScheme)
+ return;
+ m_colorScheme = colorScheme;
+ Q_Q(QStyleHints);
+ emit q->colorSchemeChanged(colorScheme);
+}
+
+QStyleHintsPrivate *QStyleHintsPrivate::get(QStyleHints *q)
+{
+ Q_ASSERT(q);
+ return q->d_func();
+}
+
QT_END_NAMESPACE
+
+#include "moc_qstylehints.cpp"
diff --git a/src/gui/kernel/qstylehints.h b/src/gui/kernel/qstylehints.h
index 30d8fdc64d..969bec4b35 100644
--- a/src/gui/kernel/qstylehints.h
+++ b/src/gui/kernel/qstylehints.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSTYLEHINTS_H
#define QSTYLEHINTS_H
@@ -55,27 +19,40 @@ class Q_GUI_EXPORT QStyleHints : public QObject
Q_DECLARE_PRIVATE(QStyleHints)
Q_PROPERTY(int cursorFlashTime READ cursorFlashTime NOTIFY cursorFlashTimeChanged FINAL)
Q_PROPERTY(qreal fontSmoothingGamma READ fontSmoothingGamma STORED false CONSTANT FINAL)
+#if QT_DEPRECATED_SINCE(6, 5)
Q_PROPERTY(int keyboardAutoRepeatRate READ keyboardAutoRepeatRate STORED false CONSTANT FINAL)
- Q_PROPERTY(int keyboardInputInterval READ keyboardInputInterval NOTIFY keyboardInputIntervalChanged FINAL)
- Q_PROPERTY(int mouseDoubleClickInterval READ mouseDoubleClickInterval NOTIFY mouseDoubleClickIntervalChanged FINAL)
- Q_PROPERTY(int mousePressAndHoldInterval READ mousePressAndHoldInterval NOTIFY mousePressAndHoldIntervalChanged FINAL)
+#endif
+ Q_PROPERTY(qreal keyboardAutoRepeatRateF READ keyboardAutoRepeatRateF STORED false CONSTANT FINAL)
+ Q_PROPERTY(int keyboardInputInterval READ keyboardInputInterval
+ NOTIFY keyboardInputIntervalChanged FINAL)
+ Q_PROPERTY(int mouseDoubleClickInterval READ mouseDoubleClickInterval
+ NOTIFY mouseDoubleClickIntervalChanged FINAL)
+ Q_PROPERTY(int mousePressAndHoldInterval READ mousePressAndHoldInterval
+ NOTIFY mousePressAndHoldIntervalChanged FINAL)
Q_PROPERTY(QChar passwordMaskCharacter READ passwordMaskCharacter STORED false CONSTANT FINAL)
Q_PROPERTY(int passwordMaskDelay READ passwordMaskDelay STORED false CONSTANT FINAL)
Q_PROPERTY(bool setFocusOnTouchRelease READ setFocusOnTouchRelease STORED false CONSTANT FINAL)
Q_PROPERTY(bool showIsFullScreen READ showIsFullScreen STORED false CONSTANT FINAL)
Q_PROPERTY(bool showIsMaximized READ showIsMaximized STORED false CONSTANT FINAL)
- Q_PROPERTY(bool showShortcutsInContextMenus READ showShortcutsInContextMenus WRITE setShowShortcutsInContextMenus NOTIFY showShortcutsInContextMenusChanged FINAL)
+ Q_PROPERTY(bool showShortcutsInContextMenus READ showShortcutsInContextMenus
+ WRITE setShowShortcutsInContextMenus NOTIFY showShortcutsInContextMenusChanged FINAL)
Q_PROPERTY(int startDragDistance READ startDragDistance NOTIFY startDragDistanceChanged FINAL)
Q_PROPERTY(int startDragTime READ startDragTime NOTIFY startDragTimeChanged FINAL)
Q_PROPERTY(int startDragVelocity READ startDragVelocity STORED false CONSTANT FINAL)
Q_PROPERTY(bool useRtlExtensions READ useRtlExtensions STORED false CONSTANT FINAL)
- Q_PROPERTY(Qt::TabFocusBehavior tabFocusBehavior READ tabFocusBehavior NOTIFY tabFocusBehaviorChanged FINAL)
+ Q_PROPERTY(Qt::TabFocusBehavior tabFocusBehavior READ tabFocusBehavior
+ NOTIFY tabFocusBehaviorChanged FINAL)
Q_PROPERTY(bool singleClickActivation READ singleClickActivation STORED false CONSTANT FINAL)
- Q_PROPERTY(bool useHoverEffects READ useHoverEffects WRITE setUseHoverEffects NOTIFY useHoverEffectsChanged FINAL)
+ Q_PROPERTY(bool useHoverEffects READ useHoverEffects WRITE setUseHoverEffects
+ NOTIFY useHoverEffectsChanged FINAL)
Q_PROPERTY(int wheelScrollLines READ wheelScrollLines NOTIFY wheelScrollLinesChanged FINAL)
- Q_PROPERTY(int mouseQuickSelectionThreshold READ mouseQuickSelectionThreshold WRITE setMouseQuickSelectionThreshold NOTIFY mouseQuickSelectionThresholdChanged FINAL)
- Q_PROPERTY(int mouseDoubleClickDistance READ mouseDoubleClickDistance STORED false CONSTANT FINAL)
+ Q_PROPERTY(int mouseQuickSelectionThreshold READ mouseQuickSelectionThreshold
+ WRITE setMouseQuickSelectionThreshold NOTIFY mouseQuickSelectionThresholdChanged
+ FINAL)
+ Q_PROPERTY(int mouseDoubleClickDistance READ mouseDoubleClickDistance STORED false CONSTANT
+ FINAL)
Q_PROPERTY(int touchDoubleTapDistance READ touchDoubleTapDistance STORED false CONSTANT FINAL)
+ Q_PROPERTY(Qt::ColorScheme colorScheme READ colorScheme NOTIFY colorSchemeChanged FINAL)
public:
void setMouseDoubleClickInterval(int mouseDoubleClickInterval);
@@ -91,7 +68,11 @@ public:
int startDragVelocity() const;
void setKeyboardInputInterval(int keyboardInputInterval);
int keyboardInputInterval() const;
+#if QT_DEPRECATED_SINCE(6, 5)
+ QT_DEPRECATED_VERSION_X_6_5("Use keyboardAutoRepeatRateF() instead")
int keyboardAutoRepeatRate() const;
+#endif
+ qreal keyboardAutoRepeatRateF() const;
void setCursorFlashTime(int cursorFlashTime);
int cursorFlashTime() const;
bool showIsFullScreen() const;
@@ -112,6 +93,7 @@ public:
void setWheelScrollLines(int scrollLines);
void setMouseQuickSelectionThreshold(int threshold);
int mouseQuickSelectionThreshold() const;
+ Qt::ColorScheme colorScheme() const;
Q_SIGNALS:
void cursorFlashTimeChanged(int cursorFlashTime);
@@ -125,6 +107,7 @@ Q_SIGNALS:
void showShortcutsInContextMenusChanged(bool);
void wheelScrollLinesChanged(int scrollLines);
void mouseQuickSelectionThresholdChanged(int threshold);
+ void colorSchemeChanged(Qt::ColorScheme colorScheme);
private:
friend class QGuiApplication;
diff --git a/src/gui/kernel/qstylehints_p.h b/src/gui/kernel/qstylehints_p.h
new file mode 100644
index 0000000000..c58386d7a3
--- /dev/null
+++ b/src/gui/kernel/qstylehints_p.h
@@ -0,0 +1,54 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QSTYLEHINTS_P_H
+#define QSTYLEHINTS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qpa/qplatformintegration.h>
+#include <QPalette>
+#include <private/qguiapplication_p.h>
+#include "qstylehints.h"
+
+QT_BEGIN_NAMESPACE
+
+class QStyleHintsPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QStyleHints)
+public:
+ int m_mouseDoubleClickInterval = -1;
+ int m_mousePressAndHoldInterval = -1;
+ int m_startDragDistance = -1;
+ int m_startDragTime = -1;
+ int m_keyboardInputInterval = -1;
+ int m_cursorFlashTime = -1;
+ int m_tabFocusBehavior = -1;
+ int m_uiEffects = -1;
+ int m_showShortcutsInContextMenus = -1;
+ int m_wheelScrollLines = -1;
+ int m_mouseQuickSelectionThreshold = -1;
+ int m_mouseDoubleClickDistance = -1;
+ int m_touchDoubleTapDistance = -1;
+
+ Qt::ColorScheme colorScheme() const { return m_colorScheme; }
+ void setColorScheme(Qt::ColorScheme colorScheme);
+
+ static QStyleHintsPrivate *get(QStyleHints *q);
+
+private:
+ Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/gui/kernel/qsurface.cpp b/src/gui/kernel/qsurface.cpp
index 85c576b21c..c00cf55a09 100644
--- a/src/gui/kernel/qsurface.cpp
+++ b/src/gui/kernel/qsurface.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsurface.h"
#include "qopenglcontext.h"
@@ -44,6 +8,7 @@
QT_BEGIN_NAMESPACE
+QT_IMPL_METATYPE_EXTERN_TAGGED(QSurface*, QSurface_ptr)
/*!
\class QSurface
@@ -65,13 +30,12 @@ QT_BEGIN_NAMESPACE
\value Offscreen The surface is an instance of QOffscreenSurface.
*/
-
/*!
\enum QSurface::SurfaceType
The SurfaceType enum describes what type of surface this is.
- \value RasterSurface The surface is is composed of pixels and can be rendered to using
+ \value RasterSurface The surface is composed of pixels and can be rendered to using
a software rasterizer like Qt's raster paint engine.
\value OpenGLSurface The surface is an OpenGL compatible surface and can be used
in conjunction with QOpenGLContext.
@@ -83,12 +47,13 @@ QT_BEGIN_NAMESPACE
\value VulkanSurface The surface is a Vulkan compatible surface and can be used
in conjunction with the Vulkan graphics API.
\value MetalSurface The surface is a Metal compatible surface and can be used
- in conjunction with Apple's Metal graphics API. This surface type is supported
- on macOS only.
-
+ in conjunction with Apple's Metal graphics API. This surface type is only supported
+ on \macos and iOS.
+ \value Direct3DSurface The surface is a Direct 3D 11 and 12 compatible
+ surface and can be used in conjunction with the DXGI and Direct3D APIs. This
+ surface type is only supported on Windows.
*/
-
/*!
\fn QSurfaceFormat QSurface::format() const
@@ -160,3 +125,5 @@ QSurface::SurfaceClass QSurface::surfaceClass() const
QT_END_NAMESPACE
+#include "moc_qsurface.cpp"
+
diff --git a/src/gui/kernel/qsurface.h b/src/gui/kernel/qsurface.h
index 521593ea5c..ef70beab21 100644
--- a/src/gui/kernel/qsurface.h
+++ b/src/gui/kernel/qsurface.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSURFACE_H
#define QSURFACE_H
@@ -69,7 +33,8 @@ public:
RasterGLSurface,
OpenVGSurface,
VulkanSurface,
- MetalSurface
+ MetalSurface,
+ Direct3DSurface
};
Q_ENUM(SurfaceType)
@@ -95,6 +60,6 @@ protected:
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QSurface*)
+QT_DECL_METATYPE_EXTERN_TAGGED(QSurface*, QSurface_ptr, Q_GUI_EXPORT)
#endif //QSURFACE_H
diff --git a/src/gui/kernel/qsurfaceformat.cpp b/src/gui/kernel/qsurfaceformat.cpp
index 6c04abc293..74add6e973 100644
--- a/src/gui/kernel/qsurfaceformat.cpp
+++ b/src/gui/kernel/qsurfaceformat.cpp
@@ -1,47 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsurfaceformat.h"
#include <QtCore/qatomic.h>
#include <QtCore/QDebug>
#include <QOpenGLContext>
+#include <QtGui/qcolorspace.h>
#include <QtGui/qguiapplication.h>
#ifdef major
@@ -73,7 +38,6 @@ public:
, major(2)
, minor(0)
, swapInterval(1) // default to vsync
- , colorSpace(QSurfaceFormat::DefaultColorSpace)
{
}
@@ -112,7 +76,7 @@ public:
int major;
int minor;
int swapInterval;
- QSurfaceFormat::ColorSpace colorSpace;
+ QColorSpace colorSpace;
};
/*!
@@ -152,6 +116,9 @@ public:
the monitoring of the loss of context, such as, Windows with WGL, or Linux/X11 (xcb) with GLX, will
monitor the status in every call to \l{QOpenGLContext::makeCurrent()}{makeCurrent()}. See
\l{QOpenGLContext::isValid()}{isValid()} for more information on this.
+ \value ProtectedContent Enables access to protected content. This allows the GPU to operate on protected
+ resources (surfaces, buffers, textures), for example DRM-protected video content.
+ Currently only implemented for EGL.
*/
/*!
@@ -346,49 +313,14 @@ void QSurfaceFormat::setSamples(int numSamples)
}
}
-#if QT_DEPRECATED_SINCE(5, 2)
-/*!
- \obsolete
- \overload
-
- Use setOption(QSurfaceFormat::FormatOption, bool) or setOptions() instead.
-
- Sets the format options to the OR combination of \a opt and the
- current format options.
-
- \sa options(), testOption()
-*/
-void QSurfaceFormat::setOption(QSurfaceFormat::FormatOptions opt)
-{
- const QSurfaceFormat::FormatOptions newOptions = d->opts | opt;
- if (int(newOptions) != int(d->opts)) {
- detach();
- d->opts = newOptions;
- }
-}
-
-/*!
- \obsolete
- \overload
-
- Use testOption(QSurfaceFormat::FormatOption) instead.
-
- Returns \c true if any of the options in \a opt is currently set
- on this object; otherwise returns false.
-
- \sa setOption()
-*/
-bool QSurfaceFormat::testOption(QSurfaceFormat::FormatOptions opt) const
-{
- return d->opts & opt;
-}
-#endif // QT_DEPRECATED_SINCE(5, 2)
-
/*!
\since 5.3
Sets the format options to \a options.
+ To verify that an option was respected, compare the actual format to the
+ requested format after surface/context creation.
+
\sa options(), testOption()
*/
void QSurfaceFormat::setOptions(QSurfaceFormat::FormatOptions options)
@@ -404,6 +336,9 @@ void QSurfaceFormat::setOptions(QSurfaceFormat::FormatOptions options)
Sets the format option \a option if \a on is true; otherwise, clears the option.
+ To verify that an option was respected, compare the actual format to the
+ requested format after surface/context creation.
+
\sa setOptions(), options(), testOption()
*/
void QSurfaceFormat::setOption(QSurfaceFormat::FormatOption option, bool on)
@@ -770,11 +705,11 @@ int QSurfaceFormat::swapInterval() const
blending to be performed in the given color space instead of using the
standard linear operations.
- \since 5.10
+ \since 6.0
\sa colorSpace()
*/
-void QSurfaceFormat::setColorSpace(ColorSpace colorSpace)
+void QSurfaceFormat::setColorSpace(const QColorSpace &colorSpace)
{
if (d->colorSpace != colorSpace) {
detach();
@@ -782,6 +717,30 @@ void QSurfaceFormat::setColorSpace(ColorSpace colorSpace)
}
}
+#if QT_DEPRECATED_SINCE(6, 0)
+/*!
+ \overload
+ \deprecated [6.0] Use setColorSpace(QColorSpace) instead.
+
+ Sets the colorspace to one of the predefined values.
+
+ \since 5.10
+
+ \sa colorSpace()
+ */
+void QSurfaceFormat::setColorSpace(ColorSpace colorSpace)
+{
+ switch (colorSpace) {
+ case DefaultColorSpace:
+ setColorSpace(QColorSpace());
+ break;
+ case sRGBColorSpace:
+ setColorSpace(QColorSpace::SRgb);
+ break;
+ }
+}
+#endif // QT_DEPRECATED_SINCE(6, 0)
+
/*!
\return the color space.
@@ -789,7 +748,7 @@ void QSurfaceFormat::setColorSpace(ColorSpace colorSpace)
\sa setColorSpace()
*/
-QSurfaceFormat::ColorSpace QSurfaceFormat::colorSpace() const
+const QColorSpace &QSurfaceFormat::colorSpace() const
{
return d->colorSpace;
}
@@ -806,7 +765,7 @@ Q_GLOBAL_STATIC(QSurfaceFormat, qt_default_surface_format)
question's own setFormat() function. However, it is often more convenient to
set the format for all windows once at the start of the application. It also
guarantees proper behavior in cases where shared contexts are required,
- because settings the format via this function guarantees that all contexts
+ because setting the format via this function guarantees that all contexts
and surfaces, even the ones created internally by Qt, will use the same
format.
@@ -848,37 +807,37 @@ QSurfaceFormat QSurfaceFormat::defaultFormat()
}
/*!
- Returns \c true if all the options of the two QSurfaceFormat objects
- \a a and \a b are equal.
+ \fn bool QSurfaceFormat::operator==(const QSurfaceFormat& lhs, const QSurfaceFormat& rhs)
- \relates QSurfaceFormat
+ Returns \c true if all the options of the two QSurfaceFormat objects
+ \a lhs and \a rhs are equal.
*/
-bool operator==(const QSurfaceFormat& a, const QSurfaceFormat& b)
-{
- return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts
- && a.d->stencilSize == b.d->stencilSize
- && a.d->redBufferSize == b.d->redBufferSize
- && a.d->greenBufferSize == b.d->greenBufferSize
- && a.d->blueBufferSize == b.d->blueBufferSize
- && a.d->alphaBufferSize == b.d->alphaBufferSize
- && a.d->depthSize == b.d->depthSize
- && a.d->numSamples == b.d->numSamples
- && a.d->swapBehavior == b.d->swapBehavior
- && a.d->profile == b.d->profile
- && a.d->major == b.d->major
- && a.d->minor == b.d->minor
- && a.d->swapInterval == b.d->swapInterval);
-}
/*!
+ \fn bool QSurfaceFormat::operator!=(const QSurfaceFormat& lhs, const QSurfaceFormat& rhs)
+
Returns \c false if all the options of the two QSurfaceFormat objects
- \a a and \a b are equal; otherwise returns \c true.
+ \a lhs and \a rhs are equal; otherwise returns \c true.
+*/
- \relates QSurfaceFormat
+/*!
+ \internal
*/
-bool operator!=(const QSurfaceFormat& a, const QSurfaceFormat& b)
+bool QSurfaceFormat::equals(const QSurfaceFormat& other) const noexcept
{
- return !(a == b);
+ return (d == other.d) || ((int) d->opts == (int) other.d->opts
+ && d->stencilSize == other.d->stencilSize
+ && d->redBufferSize == other.d->redBufferSize
+ && d->greenBufferSize == other.d->greenBufferSize
+ && d->blueBufferSize == other.d->blueBufferSize
+ && d->alphaBufferSize == other.d->alphaBufferSize
+ && d->depthSize == other.d->depthSize
+ && d->numSamples == other.d->numSamples
+ && d->swapBehavior == other.d->swapBehavior
+ && d->profile == other.d->profile
+ && d->major == other.d->major
+ && d->minor == other.d->minor
+ && d->swapInterval == other.d->swapInterval);
}
#ifndef QT_NO_DEBUG_STREAM
@@ -908,3 +867,5 @@ QDebug operator<<(QDebug dbg, const QSurfaceFormat &f)
#endif
QT_END_NAMESPACE
+
+#include "moc_qsurfaceformat.cpp"
diff --git a/src/gui/kernel/qsurfaceformat.h b/src/gui/kernel/qsurfaceformat.h
index ed63eb8bbf..07ee1cc07d 100644
--- a/src/gui/kernel/qsurfaceformat.h
+++ b/src/gui/kernel/qsurfaceformat.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSURFACEFORMAT_H
#define QSURFACEFORMAT_H
@@ -45,7 +9,7 @@
QT_BEGIN_NAMESPACE
-
+class QColorSpace;
class QOpenGLContext;
class QSurfaceFormatPrivate;
@@ -57,7 +21,8 @@ public:
StereoBuffers = 0x0001,
DebugContext = 0x0002,
DeprecatedFunctions = 0x0004,
- ResetNotification = 0x0008
+ ResetNotification = 0x0008,
+ ProtectedContent = 0x0010
};
Q_ENUM(FormatOption)
Q_DECLARE_FLAGS(FormatOptions, FormatOption)
@@ -85,14 +50,16 @@ public:
};
Q_ENUM(OpenGLContextProfile)
+#if QT_DEPRECATED_SINCE(6,0)
enum ColorSpace {
DefaultColorSpace,
sRGBColorSpace
};
Q_ENUM(ColorSpace)
+#endif
QSurfaceFormat();
- /*implicit*/ QSurfaceFormat(FormatOptions options);
+ Q_IMPLICIT QSurfaceFormat(FormatOptions options);
QSurfaceFormat(const QSurfaceFormat &other);
QSurfaceFormat &operator=(const QSurfaceFormat &other);
~QSurfaceFormat();
@@ -138,11 +105,6 @@ public:
bool stereo() const;
void setStereo(bool enable);
-#if QT_DEPRECATED_SINCE(5, 2)
- QT_DEPRECATED void setOption(QSurfaceFormat::FormatOptions opt);
- QT_DEPRECATED bool testOption(QSurfaceFormat::FormatOptions opt) const;
-#endif
-
void setOptions(QSurfaceFormat::FormatOptions options);
void setOption(FormatOption option, bool on = true);
bool testOption(FormatOption option) const;
@@ -151,8 +113,12 @@ public:
int swapInterval() const;
void setSwapInterval(int interval);
- ColorSpace colorSpace() const;
+ const QColorSpace &colorSpace() const;
+ void setColorSpace(const QColorSpace &colorSpace);
+#if QT_DEPRECATED_SINCE(6,0)
+ Q_DECL_DEPRECATED_X("Use setColorSpace(QColorSpace) instead.")
void setColorSpace(ColorSpace colorSpace);
+#endif
static void setDefaultFormat(const QSurfaceFormat &format);
static QSurfaceFormat defaultFormat();
@@ -161,17 +127,17 @@ private:
QSurfaceFormatPrivate *d;
void detach();
+ bool equals(const QSurfaceFormat &other) const noexcept;
- friend Q_GUI_EXPORT bool operator==(const QSurfaceFormat&, const QSurfaceFormat&);
- friend Q_GUI_EXPORT bool operator!=(const QSurfaceFormat&, const QSurfaceFormat&);
+ friend inline bool operator==(const QSurfaceFormat &lhs, const QSurfaceFormat &rhs) noexcept
+ { return lhs.equals(rhs); }
+ friend inline bool operator!=(const QSurfaceFormat &lhs, const QSurfaceFormat &rhs) noexcept
+ { return !lhs.equals(rhs); }
#ifndef QT_NO_DEBUG_STREAM
friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QSurfaceFormat &);
#endif
};
-Q_GUI_EXPORT bool operator==(const QSurfaceFormat&, const QSurfaceFormat&);
-Q_GUI_EXPORT bool operator!=(const QSurfaceFormat&, const QSurfaceFormat&);
-
#ifndef QT_NO_DEBUG_STREAM
Q_GUI_EXPORT QDebug operator<<(QDebug, const QSurfaceFormat &);
#endif
diff --git a/src/gui/kernel/qt_gui_pch.h b/src/gui/kernel/qt_gui_pch.h
index 5e07fa45e7..fbde1cf9a2 100644
--- a/src/gui/kernel/qt_gui_pch.h
+++ b/src/gui/kernel/qt_gui_pch.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
/*
* This is a precompiled header file for use in Xcode / Mac GCC /
@@ -48,6 +12,7 @@
#include "../../corelib/global/qt_pch.h"
#if defined __cplusplus
+#include <qtguiexports.h>
#include <qtguiglobal.h>
#include <qguiapplication.h>
#include <qbitmap.h>
diff --git a/src/gui/kernel/qtestsupport_gui.cpp b/src/gui/kernel/qtestsupport_gui.cpp
index 79da26f2ca..869eddce49 100644
--- a/src/gui/kernel/qtestsupport_gui.cpp
+++ b/src/gui/kernel/qtestsupport_gui.cpp
@@ -1,43 +1,8 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <private/qguiapplication_p.h>
+#include <private/qeventpoint_p.h>
#include <qpa/qplatformintegration.h>
@@ -45,6 +10,7 @@
#include "qwindow.h"
#include <QtCore/qtestsupport_core.h>
+#include <QtCore/qthread.h>
#include <QtCore/QDebug>
QT_BEGIN_NAMESPACE
@@ -52,11 +18,18 @@ QT_BEGIN_NAMESPACE
/*!
\since 5.0
- Waits for \a timeout milliseconds or until the \a window is active.
+ Returns \c true, if \a window is active within \a timeout milliseconds. Otherwise returns \c false.
- Returns \c true if \c window is active within \a timeout milliseconds, otherwise returns \c false.
+ The method is useful in tests that call QWindow::show() and rely on the window actually being
+ active (i.e. being visible and having focus) before proceeding.
- \sa qWaitForWindowExposed(), QWindow::isActive()
+ \note The method will time out and return \c false if another window prevents \a window from
+ becoming active.
+
+ \note Since focus is an exclusive property, \a window may loose its focus to another window at
+ any time - even after the method has returned \c true.
+
+ \sa qWaitForWindowExposed(), qWaitForWindowFocused(), QWindow::isActive()
*/
Q_GUI_EXPORT bool QTest::qWaitForWindowActive(QWindow *window, int timeout)
{
@@ -72,17 +45,37 @@ Q_GUI_EXPORT bool QTest::qWaitForWindowActive(QWindow *window, int timeout)
}
/*!
+ \since 6.7
+
+ Returns \c true, if \a window is the focus window within \a timeout. Otherwise returns \c false.
+
+ The method is useful in tests that call QWindow::show() and rely on the window
+ having focus (for receiving keyboard events e.g.) before proceeding.
+
+ \note The method will time out and return \c false if another window prevents \a window from
+ becoming focused.
+
+ \note Since focus is an exclusive property, \a window may loose its focus to another window at
+ any time - even after the method has returned \c true.
+
+ \sa qWaitForWindowExposed(), qWaitForWindowActive(), QGuiApplication::focusWindow()
+*/
+Q_GUI_EXPORT bool QTest::qWaitForWindowFocused(QWindow *window, QDeadlineTimer timeout)
+{
+ return QTest::qWaitFor([&]() { return qGuiApp->focusWindow() == window; }, timeout);
+}
+
+/*!
\since 5.0
- Waits for \a timeout milliseconds or until the \a window is exposed.
- Returns \c true if \c window is exposed within \a timeout milliseconds, otherwise returns \c false.
+ Returns \c true, if \a window is exposed within \a timeout milliseconds. Otherwise returns \c false.
- This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some
- time after being asked to show itself on the screen.
+ The method is useful in tests that call QWindow::show() and rely on the window actually being
+ being visible before proceeding.
- Note that a window that is mapped to screen may still not be considered exposed if the window client
- area is completely covered by other windows, or if the window is otherwise not visible. This function
- will then time out when waiting for such a window.
+ \note A window mapped to screen may still not be considered exposed, if the window client area is
+ not visible, e.g. because it is completely covered by other windows.
+ In such cases, the method will time out and return \c false.
\sa qWaitForWindowActive(), QWindow::isExposed()
*/
@@ -91,4 +84,86 @@ Q_GUI_EXPORT bool QTest::qWaitForWindowExposed(QWindow *window, int timeout)
return QTest::qWaitFor([&]() { return window->isExposed(); }, timeout);
}
+namespace QTest {
+
+QTouchEventSequence::~QTouchEventSequence()
+{
+ if (commitWhenDestroyed)
+ QTouchEventSequence::commit();
+}
+QTouchEventSequence& QTouchEventSequence::press(int touchId, const QPoint &pt, QWindow *window)
+{
+ auto &p = point(touchId);
+ QMutableEventPoint::setGlobalPosition(p, mapToScreen(window, pt));
+ QMutableEventPoint::setState(p, QEventPoint::State::Pressed);
+ return *this;
+}
+QTouchEventSequence& QTouchEventSequence::move(int touchId, const QPoint &pt, QWindow *window)
+{
+ auto &p = point(touchId);
+ QMutableEventPoint::setGlobalPosition(p, mapToScreen(window, pt));
+ QMutableEventPoint::setState(p, QEventPoint::State::Updated);
+ return *this;
+}
+QTouchEventSequence& QTouchEventSequence::release(int touchId, const QPoint &pt, QWindow *window)
+{
+ auto &p = point(touchId);
+ QMutableEventPoint::setGlobalPosition(p, mapToScreen(window, pt));
+ QMutableEventPoint::setState(p, QEventPoint::State::Released);
+ return *this;
+}
+QTouchEventSequence& QTouchEventSequence::stationary(int touchId)
+{
+ auto &p = pointOrPreviousPoint(touchId);
+ QMutableEventPoint::setState(p, QEventPoint::State::Stationary);
+ return *this;
+}
+
+bool QTouchEventSequence::commit(bool processEvents)
+{
+ if (points.isEmpty())
+ return false;
+ QThread::sleep(std::chrono::milliseconds{1});
+ bool ret = false;
+ if (targetWindow)
+ ret = qt_handleTouchEventv2(targetWindow, device, points.values());
+ if (processEvents)
+ QCoreApplication::processEvents();
+ previousPoints = points;
+ points.clear();
+ return ret;
+}
+
+QTouchEventSequence::QTouchEventSequence(QWindow *window, QPointingDevice *aDevice, bool autoCommit)
+ : targetWindow(window), device(aDevice), commitWhenDestroyed(autoCommit)
+{
+}
+
+QPoint QTouchEventSequence::mapToScreen(QWindow *window, const QPoint &pt)
+{
+ if (window)
+ return window->mapToGlobal(pt);
+ return targetWindow ? targetWindow->mapToGlobal(pt) : pt;
+}
+
+QEventPoint &QTouchEventSequence::point(int touchId)
+{
+ if (!points.contains(touchId))
+ points[touchId] = QEventPoint(touchId);
+ return points[touchId];
+}
+
+QEventPoint &QTouchEventSequence::pointOrPreviousPoint(int touchId)
+{
+ if (!points.contains(touchId)) {
+ if (previousPoints.contains(touchId))
+ points[touchId] = previousPoints.value(touchId);
+ else
+ points[touchId] = QEventPoint(touchId);
+ }
+ return points[touchId];
+}
+
+} // namespace QTest
+
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qtestsupport_gui.h b/src/gui/kernel/qtestsupport_gui.h
index 1f0c4f0960..e5b2a88455 100644
--- a/src/gui/kernel/qtestsupport_gui.h
+++ b/src/gui/kernel/qtestsupport_gui.h
@@ -1,55 +1,63 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTESTSUPPORT_GUI_H
#define QTESTSUPPORT_GUI_H
#include <QtGui/qtguiglobal.h>
+#include <QtGui/qevent.h>
+#include <QtCore/qmap.h>
QT_BEGIN_NAMESPACE
class QWindow;
+Q_GUI_EXPORT void qt_handleTouchEvent(QWindow *w, const QPointingDevice *device,
+ const QList<QEventPoint> &points,
+ Qt::KeyboardModifiers mods = Qt::NoModifier);
+
+Q_GUI_EXPORT bool qt_handleTouchEventv2(QWindow *w, const QPointingDevice *device,
+ const QList<QEventPoint> &points,
+ Qt::KeyboardModifiers mods = Qt::NoModifier);
+
namespace QTest {
-Q_GUI_EXPORT Q_REQUIRED_RESULT bool qWaitForWindowActive(QWindow *window, int timeout = 5000);
-Q_GUI_EXPORT Q_REQUIRED_RESULT bool qWaitForWindowExposed(QWindow *window, int timeout = 5000);
-}
+
+[[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowActive(QWindow *window, int timeout = 5000);
+[[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowFocused(QWindow *widget, QDeadlineTimer timeout = std::chrono::seconds{5});
+[[nodiscard]] Q_GUI_EXPORT bool qWaitForWindowExposed(QWindow *window, int timeout = 5000);
+
+Q_GUI_EXPORT QPointingDevice * createTouchDevice(QInputDevice::DeviceType devType = QInputDevice::DeviceType::TouchScreen,
+ QInputDevice::Capabilities caps = QInputDevice::Capability::Position);
+
+class Q_GUI_EXPORT QTouchEventSequence
+{
+public:
+ virtual ~QTouchEventSequence();
+ QTouchEventSequence& press(int touchId, const QPoint &pt, QWindow *window = nullptr);
+ QTouchEventSequence& move(int touchId, const QPoint &pt, QWindow *window = nullptr);
+ QTouchEventSequence& release(int touchId, const QPoint &pt, QWindow *window = nullptr);
+ virtual QTouchEventSequence& stationary(int touchId);
+
+ virtual bool commit(bool processEvents = true);
+
+protected:
+ QTouchEventSequence(QWindow *window, QPointingDevice *aDevice, bool autoCommit);
+
+ QPoint mapToScreen(QWindow *window, const QPoint &pt);
+
+ QEventPoint &point(int touchId);
+
+ QEventPoint &pointOrPreviousPoint(int touchId);
+
+ QMap<int, QEventPoint> previousPoints;
+ QMap<int, QEventPoint> points;
+ QWindow *targetWindow;
+ QPointingDevice *device;
+ bool commitWhenDestroyed;
+ friend QTouchEventSequence touchEvent(QWindow *window, QPointingDevice *device, bool autoCommit);
+};
+
+} // namespace QTest
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qtguiglobal.h b/src/gui/kernel/qtguiglobal.h
index 8a7409e3d9..cea6448755 100644
--- a/src/gui/kernel/qtguiglobal.h
+++ b/src/gui/kernel/qtguiglobal.h
@@ -1,60 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTGUIGLOBAL_H
#define QTGUIGLOBAL_H
#include <QtCore/qglobal.h>
#include <QtGui/qtgui-config.h>
-
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_STATIC
-# if defined(QT_BUILD_GUI_LIB)
-# define Q_GUI_EXPORT Q_DECL_EXPORT
-# else
-# define Q_GUI_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define Q_GUI_EXPORT
-#endif
-
-QT_END_NAMESPACE
+#include <QtGui/qtguiexports.h>
#endif // QTGUIGLOBAL_H
diff --git a/src/gui/kernel/qtguiglobal_p.h b/src/gui/kernel/qtguiglobal_p.h
index d2c0b3c5d1..c9f341c172 100644
--- a/src/gui/kernel/qtguiglobal_p.h
+++ b/src/gui/kernel/qtguiglobal_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTGUIGLOBAL_P_H
#define QTGUIGLOBAL_P_H
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index c06f03f4e7..46a787e706 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -1,46 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qwindow.h"
#include <qpa/qplatformwindow.h>
#include <qpa/qplatformintegration.h>
+#ifndef QT_NO_CONTEXTMENU
+#include <qpa/qplatformtheme.h>
+#endif
#include "qsurfaceformat.h"
#ifndef QT_NO_OPENGL
#include <qpa/qplatformopenglcontext.h>
@@ -51,7 +18,7 @@
#include "qwindow_p.h"
#include "qguiapplication_p.h"
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
# include "qaccessible.h"
#endif
#include "qhighdpiscaling_p.h"
@@ -66,6 +33,7 @@
#include <QStyleHints>
#include <qpa/qplatformcursor.h>
+#include <qpa/qplatformwindow_p.h>
QT_BEGIN_NAMESPACE
@@ -160,7 +128,7 @@ QWindow::QWindow(QScreen *targetScreen)
, QSurface(QSurface::Window)
{
Q_D(QWindow);
- d->init(targetScreen);
+ d->init(nullptr, targetScreen);
}
static QWindow *nonDesktopParent(QWindow *parent)
@@ -201,11 +169,11 @@ QWindow::QWindow(QWindow *parent)
\sa setParent()
*/
QWindow::QWindow(QWindowPrivate &dd, QWindow *parent)
- : QObject(dd, nonDesktopParent(parent))
+ : QObject(dd, nullptr)
, QSurface(QSurface::Window)
{
Q_D(QWindow);
- d->init();
+ d->init(nonDesktopParent(parent));
}
/*!
@@ -215,35 +183,74 @@ QWindow::~QWindow()
{
Q_D(QWindow);
d->destroy();
+ // Decouple from parent before window goes under
+ setParent(nullptr);
QGuiApplicationPrivate::window_list.removeAll(this);
if (!QGuiApplicationPrivate::is_app_closing)
QGuiApplicationPrivate::instance()->modalWindowList.removeOne(this);
- // focus_window is normally cleared in destroy(), but the window may in
- // some cases end up becoming the focus window again. Clear it again
- // here as a workaround. See QTBUG-75326.
+ // thse are normally cleared in destroy(), but the window may in
+ // some cases end up becoming the focus window again, or receive an enter
+ // event. Clear it again here as a workaround. See QTBUG-75326.
if (QGuiApplicationPrivate::focus_window == this)
QGuiApplicationPrivate::focus_window = nullptr;
+ if (QGuiApplicationPrivate::currentMouseWindow == this)
+ QGuiApplicationPrivate::currentMouseWindow = nullptr;
+ if (QGuiApplicationPrivate::currentMousePressWindow == this)
+ QGuiApplicationPrivate::currentMousePressWindow = nullptr;
+
+ d->isWindow = false;
}
-void QWindowPrivate::init(QScreen *targetScreen)
+QWindowPrivate::QWindowPrivate()
+ = default;
+
+QWindowPrivate::~QWindowPrivate()
+ = default;
+
+void QWindowPrivate::init(QWindow *parent, QScreen *targetScreen)
{
Q_Q(QWindow);
+ q->QObject::setParent(parent);
+
+ isWindow = true;
parentWindow = static_cast<QWindow *>(q->QObject::parent());
+ QScreen *connectScreen = targetScreen ? targetScreen : QGuiApplication::primaryScreen();
+
if (!parentWindow)
- connectToScreen(targetScreen ? targetScreen : QGuiApplication::primaryScreen());
+ connectToScreen(connectScreen);
// If your application aborts here, you are probably creating a QWindow
// before the screen list is populated.
if (Q_UNLIKELY(!parentWindow && !topLevelScreen)) {
qFatal("Cannot create window: no screens available");
- exit(1);
}
QGuiApplicationPrivate::window_list.prepend(q);
requestedFormat = QSurfaceFormat::defaultFormat();
+ devicePixelRatio = connectScreen->devicePixelRatio();
+
+ QObject::connect(q, &QWindow::screenChanged, q, [q, this](QScreen *){
+ // We may have changed scaling; trigger resize event if needed,
+ // except on Windows, where we send resize events during WM_DPICHANGED
+ // event handling. FIXME: unify DPI change handling across all platforms.
+#ifndef Q_OS_WIN
+ if (q->handle()) {
+ QWindowSystemInterfacePrivate::GeometryChangeEvent gce(q, QHighDpi::fromNativePixels(q->handle()->geometry(), q));
+ QGuiApplicationPrivate::processGeometryChangeEvent(&gce);
+ }
+#else
+ Q_UNUSED(q);
+#endif
+ updateDevicePixelRatio();
+ });
+
+ if (parentWindow) {
+ QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded, q);
+ QCoreApplication::sendEvent(parentWindow, &childAddedEvent);
+ }
}
/*!
@@ -324,7 +331,6 @@ void QWindow::setVisibility(Visibility v)
break;
default:
Q_ASSERT(false);
- break;
}
}
@@ -354,8 +360,14 @@ void QWindowPrivate::setVisible(bool visible)
return;
// We only need to create the window if it's being shown
- if (visible)
+ if (visible) {
+ // FIXME: At this point we've already updated the visible state of
+ // the QWindow, so if the platform layer reads the window state during
+ // creation, and reflects that in the native window, it will end up
+ // with a visible window. This may in turn result in resize or expose
+ // events from the platform before we have sent the show event below.
q->create();
+ }
}
if (visible) {
@@ -443,14 +455,14 @@ void QWindowPrivate::updateSiblingPosition(SiblingPosition position)
QObjectList &siblings = q->parent()->d_ptr->children;
- const int siblingCount = siblings.size() - 1;
+ const qsizetype siblingCount = siblings.size() - 1;
if (siblingCount == 0)
return;
- const int currentPosition = siblings.indexOf(q);
+ const qsizetype currentPosition = siblings.indexOf(q);
Q_ASSERT(currentPosition >= 0);
- const int targetPosition = position == PositionTop ? siblingCount : 0;
+ const qsizetype targetPosition = position == PositionTop ? siblingCount : 0;
if (currentPosition == targetPosition)
return;
@@ -458,7 +470,7 @@ void QWindowPrivate::updateSiblingPosition(SiblingPosition position)
siblings.move(currentPosition, targetPosition);
}
-inline bool QWindowPrivate::windowRecreationRequired(QScreen *newScreen) const
+bool QWindowPrivate::windowRecreationRequired(QScreen *newScreen) const
{
Q_Q(const QWindow);
const QScreen *oldScreen = q->screen();
@@ -466,7 +478,7 @@ inline bool QWindowPrivate::windowRecreationRequired(QScreen *newScreen) const
&& !(oldScreen && oldScreen->virtualSiblings().contains(newScreen));
}
-inline void QWindowPrivate::disconnectFromScreen()
+void QWindowPrivate::disconnectFromScreen()
{
if (topLevelScreen)
topLevelScreen = nullptr;
@@ -523,6 +535,20 @@ void QWindowPrivate::create(bool recursive, WId nativeHandle)
if (q->parent())
q->parent()->create();
+ if (platformWindow) {
+ // Creating the parent window will end up creating any child window
+ // that was already visible, via setVisible. If this applies to us,
+ // we will already have a platform window at this point.
+ return;
+ }
+
+ // QPlatformWindow will poll geometry() during construction below. Set the
+ // screen here so that high-dpi scaling will use the correct scale factor.
+ if (q->isTopLevel()) {
+ if (QScreen *screen = screenForGeometry(geometry))
+ setTopLevelScreen(screen, false);
+ }
+
QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
platformWindow = nativeHandle ? platformIntegration->createForeignWindow(q, nativeHandle)
: platformIntegration->createPlatformWindow(q);
@@ -558,6 +584,8 @@ void QWindowPrivate::create(bool recursive, WId nativeHandle)
QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
QGuiApplication::sendEvent(q, &e);
+ updateDevicePixelRatio();
+
if (needsUpdate)
q->requestUpdate();
}
@@ -571,10 +599,41 @@ void QWindowPrivate::clearFocusObject()
// implement heightForWidth().
QRectF QWindowPrivate::closestAcceptableGeometry(const QRectF &rect) const
{
- Q_UNUSED(rect)
+ Q_UNUSED(rect);
return QRectF();
}
+void QWindowPrivate::setMinOrMaxSize(QSize *oldSizeMember, const QSize &size,
+ qxp::function_ref<void()> funcWidthChanged,
+ qxp::function_ref<void()> funcHeightChanged)
+{
+ Q_Q(QWindow);
+ Q_ASSERT(oldSizeMember);
+ const QSize adjustedSize =
+ size.expandedTo(QSize(0, 0)).boundedTo(QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX));
+ if (*oldSizeMember == adjustedSize)
+ return;
+ const bool widthChanged = adjustedSize.width() != oldSizeMember->width();
+ const bool heightChanged = adjustedSize.height() != oldSizeMember->height();
+ *oldSizeMember = adjustedSize;
+
+ if (platformWindow && q->isTopLevel())
+ platformWindow->propagateSizeHints();
+
+ if (widthChanged)
+ funcWidthChanged();
+ if (heightChanged)
+ funcHeightChanged();
+
+ // resize window if current size is outside of min and max limits
+ if (minimumSize.width() <= maximumSize.width()
+ || minimumSize.height() <= maximumSize.height()) {
+ const QSize currentSize = q->size();
+ const QSize boundedSize = currentSize.expandedTo(minimumSize).boundedTo(maximumSize);
+ q->resize(boundedSize);
+ }
+}
+
/*!
Sets the \a surfaceType of the window.
@@ -614,6 +673,13 @@ QWindow::SurfaceType QWindow::surfaceType() const
By default, the window is not visible, you must call setVisible(true), or
show() or similar to make it visible.
+ \note Hiding a window does not remove the window from the windowing system,
+ it only hides it. On windowing systems that give full screen applications a
+ dedicated desktop (such as macOS), hiding a full screen window will not remove
+ that desktop, but leave it blank. Another window from the same application
+ might be shown full screen, and will fill that desktop. Use QWindow::close to
+ completely remove a window from the windowing system.
+
\sa show()
*/
void QWindow::setVisible(bool visible)
@@ -637,7 +703,7 @@ bool QWindow::isVisible() const
into an actual native surface. However, the window remains hidden until setVisible() is called.
Note that it is not usually necessary to call this function directly, as it will be implicitly
- called by show(), setVisible(), and other functions that require access to the platform
+ called by show(), setVisible(), winId(), and other functions that require access to the platform
resources.
Call destroy() to free the platform resources if necessary.
@@ -653,6 +719,9 @@ void QWindow::create()
/*!
Returns the window's platform id.
+ \note This function will cause the platform window to be created if it is not already.
+ Returns 0, if the platform window creation failed.
+
For platforms where this id might be useful, the value returned
will uniquely represent the window inside the corresponding screen.
@@ -662,9 +731,12 @@ WId QWindow::winId() const
{
Q_D(const QWindow);
- if(!d->platformWindow)
+ if (!d->platformWindow)
const_cast<QWindow *>(this)->create();
+ if (!d->platformWindow)
+ return 0;
+
return d->platformWindow->winId();
}
@@ -708,6 +780,10 @@ void QWindow::setParent(QWindow *parent)
return;
}
+ QEvent parentAboutToChangeEvent(QEvent::ParentWindowAboutToChange);
+ QCoreApplication::sendEvent(this, &parentAboutToChangeEvent);
+
+ const auto previousParent = d->parentWindow;
QObject::setParent(parent);
d->parentWindow = parent;
@@ -730,6 +806,19 @@ void QWindow::setParent(QWindow *parent)
}
QGuiApplicationPrivate::updateBlockedStatus(this);
+
+ if (previousParent) {
+ QChildWindowEvent childRemovedEvent(QEvent::ChildWindowRemoved, this);
+ QCoreApplication::sendEvent(previousParent, &childRemovedEvent);
+ }
+
+ if (parent) {
+ QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded, this);
+ QCoreApplication::sendEvent(parent, &childAddedEvent);
+ }
+
+ QEvent parentChangedEvent(QEvent::ParentWindowChange);
+ QCoreApplication::sendEvent(this, &parentChangedEvent);
}
/*!
@@ -1053,7 +1142,7 @@ void QWindow::lower()
it will make the window resize so that its edge follows the mouse cursor.
On platforms that support it, this method of resizing windows is preferred over
- \c setGeometry, because it allows a more native look-and-feel of resizing windows, e.g.
+ \c setGeometry, because it allows a more native look and feel of resizing windows, e.g.
letting the window manager snap this window against other windows, or special resizing
behavior with animations when dragged to the edge of the screen.
@@ -1174,7 +1263,7 @@ QRegion QWindow::mask() const
/*!
Requests the window to be activated, i.e. receive keyboard focus.
- \sa isActive(), QGuiApplication::focusWindow(), QWindowsWindowFunctions::setWindowActivationBehavior()
+ \sa isActive(), QGuiApplication::focusWindow()
*/
void QWindow::requestActivate()
{
@@ -1192,7 +1281,7 @@ void QWindow::requestActivate()
When the window is not exposed, it is shown by the application
but it is still not showing in the windowing system, so the application
- should minimize rendering and other graphical activities.
+ should minimize animations and other graphical activities.
An exposeEvent() is sent every time this value changes.
@@ -1213,12 +1302,16 @@ bool QWindow::isExposed() const
*/
/*!
- Returns \c true if the window should appear active from a style perspective.
+ Returns \c true if the window is active.
This is the case for the window that has input focus as well as windows
that are in the same parent / transient parent chain as the focus window.
+ Typically active windows should appear active from a style perspective.
+
To get the window that currently has focus, use QGuiApplication::focusWindow().
+
+ \sa requestActivate()
*/
bool QWindow::isActive() const
{
@@ -1292,14 +1385,31 @@ Qt::ScreenOrientation QWindow::contentOrientation() const
qreal QWindow::devicePixelRatio() const
{
Q_D(const QWindow);
+ return d->devicePixelRatio;
+}
+
+/*
+ Updates the cached devicePixelRatio value by polling for a new value.
+ Sends QEvent::DevicePixelRatioChange to the window if the DPR has changed.
+ Returns true if the DPR was changed.
+*/
+bool QWindowPrivate::updateDevicePixelRatio()
+{
+ Q_Q(QWindow);
// If there is no platform window use the associated screen's devicePixelRatio,
// which typically is the primary screen and will be correct for single-display
// systems (a very common case).
- if (!d->platformWindow)
- return screen()->devicePixelRatio();
+ const qreal newDevicePixelRatio = platformWindow ?
+ platformWindow->devicePixelRatio() * QHighDpiScaling::factor(q) : q->screen()->devicePixelRatio();
+
+ if (newDevicePixelRatio == devicePixelRatio)
+ return false;
- return d->platformWindow->devicePixelRatio() * QHighDpiScaling::factor(this);
+ devicePixelRatio = newDevicePixelRatio;
+ QEvent dprChangeEvent(QEvent::DevicePixelRatioChange);
+ QGuiApplication::sendEvent(q, &dprChangeEvent);
+ return true;
}
Qt::WindowState QWindowPrivate::effectiveState(Qt::WindowStates state)
@@ -1354,8 +1464,13 @@ void QWindow::setWindowStates(Qt::WindowStates state)
if (d->platformWindow)
d->platformWindow->setWindowState(state);
+
+ auto originalEffectiveState = QWindowPrivate::effectiveState(d->windowState);
d->windowState = state;
- emit windowStateChanged(QWindowPrivate::effectiveState(d->windowState));
+ auto newEffectiveState = QWindowPrivate::effectiveState(d->windowState);
+ if (newEffectiveState != originalEffectiveState)
+ emit windowStateChanged(newEffectiveState);
+
d->updateVisibility();
}
@@ -1530,17 +1645,9 @@ QSize QWindow::sizeIncrement() const
void QWindow::setMinimumSize(const QSize &size)
{
Q_D(QWindow);
- QSize adjustedSize = QSize(qBound(0, size.width(), QWINDOWSIZE_MAX), qBound(0, size.height(), QWINDOWSIZE_MAX));
- if (d->minimumSize == adjustedSize)
- return;
- QSize oldSize = d->minimumSize;
- d->minimumSize = adjustedSize;
- if (d->platformWindow && isTopLevel())
- d->platformWindow->propagateSizeHints();
- if (d->minimumSize.width() != oldSize.width())
- emit minimumWidthChanged(d->minimumSize.width());
- if (d->minimumSize.height() != oldSize.height())
- emit minimumHeightChanged(d->minimumSize.height());
+ d->setMinOrMaxSize(
+ &d->minimumSize, size, [this, d]() { emit minimumWidthChanged(d->minimumSize.width()); },
+ [this, d]() { emit minimumHeightChanged(d->minimumSize.height()); });
}
/*!
@@ -1573,20 +1680,18 @@ void QWindow::setY(int arg)
\property QWindow::width
\brief the width of the window's geometry
*/
-void QWindow::setWidth(int arg)
+void QWindow::setWidth(int w)
{
- if (width() != arg)
- resize(arg, height());
+ resize(w, height());
}
/*!
\property QWindow::height
\brief the height of the window's geometry
*/
-void QWindow::setHeight(int arg)
+void QWindow::setHeight(int h)
{
- if (height() != arg)
- resize(width(), arg);
+ resize(width(), h);
}
/*!
@@ -1617,17 +1722,9 @@ void QWindow::setMinimumHeight(int h)
void QWindow::setMaximumSize(const QSize &size)
{
Q_D(QWindow);
- QSize adjustedSize = QSize(qBound(0, size.width(), QWINDOWSIZE_MAX), qBound(0, size.height(), QWINDOWSIZE_MAX));
- if (d->maximumSize == adjustedSize)
- return;
- QSize oldSize = d->maximumSize;
- d->maximumSize = adjustedSize;
- if (d->platformWindow && isTopLevel())
- d->platformWindow->propagateSizeHints();
- if (d->maximumSize.width() != oldSize.width())
- emit maximumWidthChanged(d->maximumSize.width());
- if (d->maximumSize.height() != oldSize.height())
- emit maximumHeightChanged(d->maximumSize.height());
+ d->setMinOrMaxSize(
+ &d->maximumSize, size, [this, d]() { emit maximumWidthChanged(d->maximumSize.width()); },
+ [this, d]() { emit maximumHeightChanged(d->maximumSize.height()); });
}
/*!
@@ -1720,13 +1817,10 @@ void QWindow::setGeometry(const QRect &rect)
d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
if (d->platformWindow) {
- QRect nativeRect;
QScreen *newScreen = d->screenForGeometry(rect);
if (newScreen && isTopLevel())
- nativeRect = QHighDpi::toNativePixels(rect, newScreen);
- else
- nativeRect = QHighDpi::toNativeLocalPosition(rect, newScreen);
- d->platformWindow->setGeometry(nativeRect);
+ d->setTopLevelScreen(newScreen, true);
+ d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(rect, this));
} else {
d->geometry = rect;
@@ -1778,9 +1872,7 @@ QRect QWindow::geometry() const
Q_D(const QWindow);
if (d->platformWindow) {
const auto nativeGeometry = d->platformWindow->geometry();
- return isTopLevel()
- ? QHighDpi::fromNativePixels(nativeGeometry, this)
- : QHighDpi::fromNativeLocalPosition(nativeGeometry, this);
+ return QHighDpi::fromNativeWindowGeometry(nativeGeometry, this);
}
return d->geometry;
}
@@ -1810,7 +1902,7 @@ QRect QWindow::frameGeometry() const
Q_D(const QWindow);
if (d->platformWindow) {
QMargins m = frameMargins();
- return QHighDpi::fromNativePixels(d->platformWindow->geometry(), this).adjusted(-m.left(), -m.top(), m.right(), m.bottom());
+ return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry(), this).adjusted(-m.left(), -m.top(), m.right(), m.bottom());
}
return d->geometry;
}
@@ -1827,7 +1919,7 @@ QPoint QWindow::framePosition() const
Q_D(const QWindow);
if (d->platformWindow) {
QMargins margins = frameMargins();
- return QHighDpi::fromNativePixels(d->platformWindow->geometry().topLeft(), this) - QPoint(margins.left(), margins.top());
+ return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry().topLeft(), this) - QPoint(margins.left(), margins.top());
}
return d->geometry.topLeft();
}
@@ -1845,7 +1937,7 @@ void QWindow::setFramePosition(const QPoint &point)
d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
d->positionAutomatic = false;
if (d->platformWindow) {
- d->platformWindow->setGeometry(QHighDpi::toNativePixels(QRect(point, size()), this));
+ d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(QRect(point, size()), this));
} else {
d->geometry.moveTopLeft(point);
}
@@ -1859,6 +1951,10 @@ void QWindow::setFramePosition(const QPoint &point)
For interactively moving windows, see startSystemMove(). For interactively
resizing windows, see startSystemResize().
+ \note Not all windowing systems support setting or querying top level window positions.
+ On such a system, programmatically moving windows may not have any effect, and artificial
+ values may be returned for the current positions, such as \c QPoint(0, 0).
+
\sa position(), startSystemMove()
*/
void QWindow::setPosition(const QPoint &pt)
@@ -1882,6 +1978,10 @@ void QWindow::setPosition(int posx, int posy)
\fn QPoint QWindow::position() const
\brief Returns the position of the window on the desktop excluding any window frame
+ \note Not all windowing systems support setting or querying top level window positions.
+ On such a system, programmatically moving windows may not have any effect, and artificial
+ values may be returned for the current positions, such as \c QPoint(0, 0).
+
\sa setPosition()
*/
@@ -1913,11 +2013,16 @@ void QWindow::resize(int w, int h)
void QWindow::resize(const QSize &newSize)
{
Q_D(QWindow);
+
+ const QSize oldSize = size();
+ if (newSize == oldSize)
+ return;
+
d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
if (d->platformWindow) {
- d->platformWindow->setGeometry(QHighDpi::toNativePixels(QRect(position(), newSize), this));
+ d->platformWindow->setGeometry(
+ QHighDpi::toNativeWindowGeometry(QRect(position(), newSize), this));
} else {
- const QSize oldSize = d->geometry.size();
d->geometry.setSize(newSize);
if (newSize.width() != oldSize.width())
emit widthChanged(newSize.width());
@@ -1958,17 +2063,6 @@ void QWindowPrivate::destroy()
}
}
- if (QGuiApplicationPrivate::focus_window == q)
- QGuiApplicationPrivate::focus_window = q->parent();
- if (QGuiApplicationPrivate::currentMouseWindow == q)
- QGuiApplicationPrivate::currentMouseWindow = q->parent();
- if (QGuiApplicationPrivate::currentMousePressWindow == q)
- QGuiApplicationPrivate::currentMousePressWindow = q->parent();
-
- for (int i = 0; i < QGuiApplicationPrivate::tabletDevicePoints.size(); ++i)
- if (QGuiApplicationPrivate::tabletDevicePoints.at(i).target == q)
- QGuiApplicationPrivate::tabletDevicePoints[i].target = q->parent();
-
bool wasVisible = q->isVisible();
visibilityOnDestroy = wasVisible && platformWindow;
@@ -1977,7 +2071,7 @@ void QWindowPrivate::destroy()
// Let subclasses act, typically by doing graphics resource cleaup, when
// the window, to which graphics resource may be tied, is going away.
//
- // NB! This is disfunctional when destroy() is invoked from the dtor since
+ // NB! This is dysfunctional when destroy() is invoked from the dtor since
// a reimplemented event() will not get called in the subclasses at that
// stage. However, the typical QWindow cleanup involves either close() or
// going through QWindowContainer, both of which will do an explicit, early
@@ -1989,9 +2083,18 @@ void QWindowPrivate::destroy()
// Unset platformWindow before deleting, so that the destructor of the
// platform window does not recurse back into the platform window via
// this window during destruction (e.g. as a result of platform events).
- QPlatformWindow *pw = platformWindow;
- platformWindow = nullptr;
- delete pw;
+ delete std::exchange(platformWindow, nullptr);
+
+ if (QGuiApplicationPrivate::focus_window == q)
+ QGuiApplicationPrivate::focus_window = q->parent();
+ if (QGuiApplicationPrivate::currentMouseWindow == q)
+ QGuiApplicationPrivate::currentMouseWindow = q->parent();
+ if (QGuiApplicationPrivate::currentMousePressWindow == q)
+ QGuiApplicationPrivate::currentMousePressWindow = q->parent();
+
+ for (int i = 0; i < QGuiApplicationPrivate::tabletDevicePoints.size(); ++i)
+ if (QGuiApplicationPrivate::tabletDevicePoints.at(i).target == q)
+ QGuiApplicationPrivate::tabletDevicePoints[i].target = q->parent();
resizeEventPending = true;
receivedExpose = false;
@@ -2128,20 +2231,26 @@ QObject *QWindow::focusObject() const
/*!
Shows the window.
- This is equivalent to calling showFullScreen(), showMaximized(), or showNormal(),
+ For child windows, this is equivalent to calling showNormal().
+ Otherwise, it is equivalent to calling showFullScreen(), showMaximized(), or showNormal(),
depending on the platform's default behavior for the window type and flags.
\sa showFullScreen(), showMaximized(), showNormal(), hide(), QStyleHints::showIsFullScreen(), flags()
*/
void QWindow::show()
{
- Qt::WindowState defaultState = QGuiApplicationPrivate::platformIntegration()->defaultWindowState(d_func()->windowFlags);
- if (defaultState == Qt::WindowFullScreen)
- showFullScreen();
- else if (defaultState == Qt::WindowMaximized)
- showMaximized();
- else
+ if (parent()) {
showNormal();
+ } else {
+ const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
+ Qt::WindowState defaultState = platformIntegration->defaultWindowState(d_func()->windowFlags);
+ if (defaultState == Qt::WindowFullScreen)
+ showFullScreen();
+ else if (defaultState == Qt::WindowMaximized)
+ showMaximized();
+ else
+ showNormal();
+ }
}
/*!
@@ -2190,6 +2299,9 @@ void QWindow::showMaximized()
Equivalent to calling setWindowStates(Qt::WindowFullScreen) and then
setVisible(true).
+ See the \l{QWidget::showFullScreen()} documentation for platform-specific
+ considerations and limitations.
+
\sa setWindowStates(), setVisible()
*/
void QWindow::showFullScreen()
@@ -2228,36 +2340,71 @@ void QWindow::showNormal()
bool QWindow::close()
{
Q_D(QWindow);
+ if (d->inClose)
+ return true;
// Do not close non top level windows
- if (parent())
+ if (!isTopLevel())
return false;
if (!d->platformWindow)
return true;
- return d->platformWindow->close();
+ // The window might be deleted during close,
+ // as a result of delivering the close event.
+ QPointer guard(this);
+ d->inClose = true;
+ bool success = d->platformWindow->close();
+ if (guard)
+ d->inClose = false;
+
+ return success;
+}
+
+bool QWindowPrivate::participatesInLastWindowClosed() const
+{
+ Q_Q(const QWindow);
+
+ if (!q->isTopLevel())
+ return false;
+
+ // Tool-tip widgets do not normally have Qt::WA_QuitOnClose,
+ // but since we do not have a similar flag for non-widget
+ // windows we need an explicit exclusion here as well.
+ if (q->type() == Qt::ToolTip)
+ return false;
+
+ // A window with a transient parent is not a primary window,
+ // it's a secondary window.
+ if (q->transientParent())
+ return false;
+
+ return true;
+}
+
+bool QWindowPrivate::treatAsVisible() const
+{
+ Q_Q(const QWindow);
+ return q->isVisible();
}
/*!
- The expose event (\a ev) is sent by the window system whenever an area of
- the window is invalidated, for example due to the exposure in the windowing
- system changing.
+ The expose event (\a ev) is sent by the window system when a window moves
+ between the un-exposed and exposed states.
- The application can start rendering into the window with QBackingStore
- and QOpenGLContext as soon as it gets an exposeEvent() such that
- isExposed() is true.
+ An exposed window is potentially visible to the user. If the window is moved
+ off screen, is made totally obscured by another window, is minimized, or
+ similar, this function might be called and the value of isExposed() might
+ change to false. You may use this event to limit expensive operations such
+ as animations to only run when the window is exposed.
- If the window is moved off screen, is made totally obscured by another
- window, iconified or similar, this function might be called and the
- value of isExposed() might change to false. When this happens,
- an application should stop its rendering as it is no longer visible
- to the user.
+ This event should not be used to paint. To handle painting implement
+ paintEvent() instead.
A resize event will always be sent before the expose event the first time
a window is shown.
- \sa isExposed()
+ \sa paintEvent(), isExposed()
*/
void QWindow::exposeEvent(QExposeEvent *ev)
{
@@ -2265,6 +2412,25 @@ void QWindow::exposeEvent(QExposeEvent *ev)
}
/*!
+ The paint event (\a ev) is sent by the window system whenever an area of
+ the window needs a repaint, for example when initially showing the window,
+ or due to parts of the window being uncovered by moving another window.
+
+ The application is expected to render into the window in response to the
+ paint event, regardless of the exposed state of the window. For example,
+ a paint event may be sent before the window is exposed, to prepare it for
+ showing to the user.
+
+ \since 6.0
+
+ \sa exposeEvent()
+*/
+void QWindow::paintEvent(QPaintEvent *ev)
+{
+ ev->ignore();
+}
+
+/*!
Override this to handle window move events (\a ev).
*/
void QWindow::moveEvent(QMoveEvent *ev)
@@ -2372,7 +2538,7 @@ bool QWindow::event(QEvent *ev)
case QEvent::FocusIn: {
focusInEvent(static_cast<QFocusEvent *>(ev));
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessible::State state;
state.active = true;
QAccessibleStateChangeEvent event(this, state);
@@ -2382,7 +2548,7 @@ bool QWindow::event(QEvent *ev)
case QEvent::FocusOut: {
focusOutEvent(static_cast<QFocusEvent *>(ev));
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessible::State state;
state.active = true;
QAccessibleStateChangeEvent event(this, state);
@@ -2396,25 +2562,34 @@ bool QWindow::event(QEvent *ev)
break;
#endif
- case QEvent::Close:
+ case QEvent::Close: {
+
+ Q_D(QWindow);
+ const bool wasVisible = d->treatAsVisible();
+ const bool participatesInLastWindowClosed = d->participatesInLastWindowClosed();
+
+ // The window might be deleted in the close event handler
+ QPointer<QWindow> deletionGuard(this);
closeEvent(static_cast<QCloseEvent*>(ev));
+
if (ev->isAccepted()) {
- Q_D(QWindow);
- bool wasVisible = isVisible();
- destroy();
- if (wasVisible) {
- // FIXME: This check for visibility is a workaround for both QWidgetWindow
- // and QWindow having logic to emit lastWindowClosed, and possibly quit the
- // application. We should find a better way to handle this.
- d->maybeQuitOnLastWindowClosed();
- }
+ if (deletionGuard)
+ destroy();
+ if (wasVisible && participatesInLastWindowClosed)
+ QGuiApplicationPrivate::instance()->maybeLastWindowClosed();
}
+
break;
+ }
case QEvent::Expose:
exposeEvent(static_cast<QExposeEvent *>(ev));
break;
+ case QEvent::Paint:
+ paintEvent(static_cast<QPaintEvent *>(ev));
+ break;
+
case QEvent::Show:
showEvent(static_cast<QShowEvent *>(ev));
break;
@@ -2427,13 +2602,6 @@ bool QWindow::event(QEvent *ev)
setIcon(icon());
break;
- case QEvent::WindowStateChange: {
- Q_D(QWindow);
- emit windowStateChanged(QWindowPrivate::effectiveState(d->windowState));
- d->updateVisibility();
- break;
- }
-
#if QT_CONFIG(tabletevent)
case QEvent::TabletPress:
case QEvent::TabletMove:
@@ -2456,17 +2624,50 @@ bool QWindow::event(QEvent *ev)
default:
return QObject::event(ev);
}
+
+#ifndef QT_NO_CONTEXTMENU
+ /*
+ QGuiApplicationPrivate::processContextMenuEvent blocks mouse-triggered
+ context menu events that the QPA plugin might generate. In practice that
+ never happens, as even on Windows WM_CONTEXTMENU is never generated by
+ the OS (we never call the default window procedure that would do that in
+ response to unhandled WM_RBUTTONUP).
+
+ So, we always have to syntheize QContextMenuEvent for mouse events anyway.
+ QWidgetWindow synthesizes QContextMenuEvent similar to this code, and
+ never calls QWindow::event, so we have to do it here as well.
+
+ This logic could be simplified by always synthesizing events in
+ QGuiApplicationPrivate, or perhaps even in each QPA plugin. See QTBUG-93486.
+ */
+ static const QEvent::Type contextMenuTrigger =
+ QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ?
+ QEvent::MouseButtonRelease : QEvent::MouseButtonPress;
+ auto asMouseEvent = [](QEvent *ev) {
+ const auto t = ev->type();
+ return t == QEvent::MouseButtonPress || t == QEvent::MouseButtonRelease
+ ? static_cast<QMouseEvent *>(ev) : nullptr ;
+ };
+ if (QMouseEvent *me = asMouseEvent(ev); me &&
+ ev->type() == contextMenuTrigger && me->button() == Qt::RightButton) {
+ QContextMenuEvent e(QContextMenuEvent::Mouse, me->position().toPoint(),
+ me->globalPosition().toPoint(), me->modifiers());
+ QGuiApplication::sendEvent(this, &e);
+ }
+#endif
return true;
}
/*!
Schedules a QEvent::UpdateRequest event to be delivered to this window.
- The event is delivered in sync with the display vsync on platforms
- where this is possible. Otherwise, the event is delivered after a
- delay of 5 ms. The additional time is there to give the event loop
- a bit of idle time to gather system events, and can be overridden
- using the QT_QPA_UPDATE_IDLE_TIME environment variable.
+ The event is delivered in sync with the display vsync on platforms where
+ this is possible. Otherwise, the event is delivered after a delay of at
+ most 5 ms. If the window's associated screen reports a
+ \l{QScreen::refreshRate()}{refresh rate} higher than 60 Hz, the interval is
+ scaled down to a value smaller than 5. The additional time is there to give
+ the event loop a bit of idle time to gather system events, and can be
+ overridden using the QT_QPA_UPDATE_IDLE_TIME environment variable.
When driving animations, this function should be called once after drawing
has completed. Calling this function multiple times will result in a single
@@ -2618,11 +2819,7 @@ void QWindow::tabletEvent(QTabletEvent *ev)
Should return true only if the event was handled.
*/
-#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool QWindow::nativeEvent(const QByteArray &eventType, void *message, qintptr *result)
-#else
-bool QWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
-#endif
{
Q_UNUSED(eventType);
Q_UNUSED(message);
@@ -2631,51 +2828,94 @@ bool QWindow::nativeEvent(const QByteArray &eventType, void *message, long *resu
}
/*!
- \fn QPoint QWindow::mapToGlobal(const QPoint &pos) const
+ \fn QPointF QWindow::mapToGlobal(const QPointF &pos) const
Translates the window coordinate \a pos to global screen
- coordinates. For example, \c{mapToGlobal(QPoint(0,0))} would give
+ coordinates. For example, \c{mapToGlobal(QPointF(0,0))} would give
the global coordinates of the top-left pixel of the window.
\sa mapFromGlobal()
+ \since 6.0
*/
-QPoint QWindow::mapToGlobal(const QPoint &pos) const
+QPointF QWindow::mapToGlobal(const QPointF &pos) const
{
Q_D(const QWindow);
// QTBUG-43252, prefer platform implementation for foreign windows.
if (d->platformWindow
&& (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
- return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapToGlobal(QHighDpi::toNativeLocalPosition(pos, this)), this);
+ return QHighDpi::fromNativeGlobalPosition(d->platformWindow->mapToGlobalF(QHighDpi::toNativeLocalPosition(pos, this)), this);
}
- if (QHighDpiScaling::isActive())
- return QHighDpiScaling::mapPositionToGlobal(pos, d->globalPosition(), this);
+ if (!QHighDpiScaling::isActive())
+ return pos + d->globalPosition();
- return pos + d->globalPosition();
+ // The normal pos + windowGlobalPos calculation may give a point which is outside
+ // screen geometry for windows which span multiple screens, due to the way QHighDpiScaling
+ // creates gaps between screens in the the device indendent cooordinate system.
+ //
+ // Map the position (and the window's global position) to native coordinates, perform
+ // the addition, and then map back to device independent coordinates.
+ QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos, this);
+ // Get the native window position directly from the platform window
+ // if available (it can be null if the window hasn't been shown yet),
+ // or fall back to scaling the QWindow position.
+ QPointF nativeWindowGlobalPos = d->platformWindow
+ ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
+ : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()), this);
+ QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos;
+ QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos, this);
+ return deviceIndependentGlobalPos;
}
+/*!
+ \overload
+*/
+QPoint QWindow::mapToGlobal(const QPoint &pos) const
+{
+ return mapToGlobal(QPointF(pos)).toPoint();
+}
/*!
- \fn QPoint QWindow::mapFromGlobal(const QPoint &pos) const
+ \fn QPointF QWindow::mapFromGlobal(const QPointF &pos) const
Translates the global screen coordinate \a pos to window
coordinates.
\sa mapToGlobal()
+ \since 6.0
*/
-QPoint QWindow::mapFromGlobal(const QPoint &pos) const
+QPointF QWindow::mapFromGlobal(const QPointF &pos) const
{
Q_D(const QWindow);
// QTBUG-43252, prefer platform implementation for foreign windows.
if (d->platformWindow
&& (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
- return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobal(QHighDpi::toNativeLocalPosition(pos, this)), this);
+ return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobalF(QHighDpi::toNativeGlobalPosition(pos, this)), this);
}
- if (QHighDpiScaling::isActive())
- return QHighDpiScaling::mapPositionFromGlobal(pos, d->globalPosition(), this);
+ if (!QHighDpiScaling::isActive())
+ return pos - d->globalPosition();
- return pos - d->globalPosition();
+ // Calculate local position in the native coordinate system. (See comment for the
+ // corresponding mapToGlobal() code above).
+ QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(pos, this);
+ // Get the native window position directly from the platform window
+ // if available (it can be null if the window hasn't been shown yet),
+ // or fall back to scaling the QWindow position.
+ QPointF nativeWindowGlobalPos = d->platformWindow
+ ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
+ : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()), this);
+ QPointF nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos;
+ QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos, this);
+ return deviceIndependentLocalPos;
+}
+
+/*!
+ \overload
+*/
+QPoint QWindow::mapFromGlobal(const QPoint &pos) const
+{
+ return QWindow::mapFromGlobal(QPointF(pos)).toPoint();
}
QPoint QWindowPrivate::globalPosition() const
@@ -2700,34 +2940,6 @@ Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window)
return window->d_func();
}
-void QWindowPrivate::maybeQuitOnLastWindowClosed()
-{
- if (!QCoreApplication::instance())
- return;
-
- Q_Q(QWindow);
- if (!q->isTopLevel())
- return;
- // Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent
- bool quitOnClose = QGuiApplication::quitOnLastWindowClosed() && !q->parent();
- QWindowList list = QGuiApplication::topLevelWindows();
- bool lastWindowClosed = true;
- for (int i = 0; i < list.size(); ++i) {
- QWindow *w = list.at(i);
- if (!w->isVisible() || w->transientParent() || w->type() == Qt::ToolTip)
- continue;
- lastWindowClosed = false;
- break;
- }
- if (lastWindowClosed) {
- QGuiApplicationPrivate::emitLastWindowClosed();
- if (quitOnClose) {
- QCoreApplicationPrivate *applicationPrivate = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(QCoreApplication::instance()));
- applicationPrivate->maybeQuit();
- }
- }
-}
-
QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode) const
{
Q_Q(const QWindow);
@@ -2745,13 +2957,6 @@ QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode) const
return window;
}
-#if QT_CONFIG(opengl)
-QOpenGLContext *QWindowPrivate::shareContext() const
-{
- return qt_gl_global_share_context();
-};
-#endif
-
/*!
Creates a local representation of a window created by another process or by
using native libraries below Qt.
@@ -2792,7 +2997,7 @@ QWindow *QWindow::fromWinId(WId id)
}
/*!
- Causes an alert to be shown for \a msec miliseconds. If \a msec is \c 0 (the
+ Causes an alert to be shown for \a msec milliseconds. If \a msec is \c 0 (the
default), then the alert is shown indefinitely until the window becomes
active again. This function has no effect on an active window.
@@ -2909,6 +3114,38 @@ bool QWindowPrivate::applyCursor()
}
#endif // QT_NO_CURSOR
+void *QWindow::resolveInterface(const char *name, int revision) const
+{
+ using namespace QNativeInterface::Private;
+
+ auto *platformWindow = handle();
+ Q_UNUSED(platformWindow);
+ Q_UNUSED(name);
+ Q_UNUSED(revision);
+
+#if defined(Q_OS_WIN)
+ QT_NATIVE_INTERFACE_RETURN_IF(QWindowsWindow, platformWindow);
+#endif
+
+#if QT_CONFIG(xcb)
+ QT_NATIVE_INTERFACE_RETURN_IF(QXcbWindow, platformWindow);
+#endif
+
+#if defined(Q_OS_MACOS)
+ QT_NATIVE_INTERFACE_RETURN_IF(QCocoaWindow, platformWindow);
+#endif
+
+#if QT_CONFIG(wayland)
+ QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow);
+#endif
+
+#if defined(Q_OS_WASM)
+ QT_NATIVE_INTERFACE_RETURN_IF(QWasmWindow, platformWindow);
+#endif
+
+ return nullptr;
+}
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, const QWindow *window)
{
@@ -2948,7 +3185,7 @@ QDebug operator<<(QDebug debug, const QWindow *window)
}
#endif // !QT_NO_DEBUG_STREAM
-#if QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC)
+#if QT_CONFIG(vulkan) || defined(Q_QDOC)
/*!
Associates this window with the specified Vulkan \a instance.
diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h
index 2cca039883..a5ec47708a 100644
--- a/src/gui/kernel/qwindow.h
+++ b/src/gui/kernel/qwindow.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWINDOW_H
#define QWINDOW_H
@@ -47,6 +11,7 @@
#include <QtCore/QRect>
#include <QtCore/qnamespace.h>
+#include <QtCore/qnativeinterface.h>
#include <QtGui/qsurface.h>
#include <QtGui/qsurfaceformat.h>
@@ -64,6 +29,7 @@ QT_BEGIN_NAMESPACE
class QWindowPrivate;
class QExposeEvent;
+class QPaintEvent;
class QFocusEvent;
class QMoveEvent;
class QResizeEvent;
@@ -89,7 +55,7 @@ class QWindowContainer;
#ifndef QT_NO_DEBUG_STREAM
class QDebug;
#endif
-#if QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC)
+#if QT_CONFIG(vulkan) || defined(Q_QDOC)
class QVulkanInstance;
#endif
@@ -106,7 +72,7 @@ class Q_GUI_EXPORT QWindow : public QObject, public QSurface
// Any new properties which you add here MUST be versioned and MUST be documented both as
// C++ properties in qwindow.cpp AND as QML properties in qquickwindow.cpp.
- // http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-definetypes.html#type-revisions-and-versions
+ // https://doc.qt.io/qt/qtqml-cppintegration-definetypes.html#type-revisions-and-versions
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY windowTitleChanged)
Q_PROPERTY(Qt::WindowModality modality READ modality WRITE setModality NOTIFY modalityChanged)
@@ -116,15 +82,24 @@ class Q_GUI_EXPORT QWindow : public QObject, public QSurface
Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged)
- Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight NOTIFY minimumHeightChanged)
+ Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight
+ NOTIFY minimumHeightChanged)
Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth NOTIFY maximumWidthChanged)
- Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight NOTIFY maximumHeightChanged)
+ Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight
+ NOTIFY maximumHeightChanged)
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
Q_PROPERTY(bool active READ isActive NOTIFY activeChanged REVISION(2, 1))
- Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged REVISION(2, 1))
- Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation WRITE reportContentOrientationChange NOTIFY contentOrientationChanged)
+ Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged
+ REVISION(2, 1))
+ Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation
+ WRITE reportContentOrientationChange NOTIFY contentOrientationChanged)
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged REVISION(2, 1))
- Q_PRIVATE_PROPERTY(QWindow::d_func(), QWindow* transientParent MEMBER transientParent WRITE setTransientParent NOTIFY transientParentChanged REVISION(2, 13))
+#ifdef Q_QDOC
+ Q_PROPERTY(QWindow* transientParent READ transientParent WRITE setTransientParent NOTIFY transientParentChanged)
+#else
+ Q_PRIVATE_PROPERTY(QWindow::d_func(), QWindow* transientParent MEMBER transientParent
+ WRITE setTransientParent NOTIFY transientParentChanged REVISION(2, 13))
+#endif
public:
enum Visibility {
@@ -260,6 +235,8 @@ public:
virtual QAccessibleInterface *accessibleRoot() const;
virtual QObject *focusObject() const;
+ QPointF mapToGlobal(const QPointF &pos) const;
+ QPointF mapFromGlobal(const QPointF &pos) const;
QPoint mapToGlobal(const QPoint &pos) const;
QPoint mapFromGlobal(const QPoint &pos) const;
@@ -271,11 +248,13 @@ public:
static QWindow *fromWinId(WId id);
-#if QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC)
+#if QT_CONFIG(vulkan) || defined(Q_QDOC)
void setVulkanInstance(QVulkanInstance *instance);
QVulkanInstance *vulkanInstance() const;
#endif
+ QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QWindow)
+
public Q_SLOTS:
Q_REVISION(2, 1) void requestActivate();
@@ -311,7 +290,7 @@ public Q_SLOTS:
Q_REVISION(2, 1) void alert(int msec);
- Q_REVISION(2 ,3) void requestUpdate();
+ Q_REVISION(2, 3) void requestUpdate();
Q_SIGNALS:
void screenChanged(QScreen *screen);
@@ -344,6 +323,7 @@ Q_SIGNALS:
protected:
virtual void exposeEvent(QExposeEvent *);
virtual void resizeEvent(QResizeEvent *);
+ virtual void paintEvent(QPaintEvent *);
virtual void moveEvent(QMoveEvent *);
virtual void focusInEvent(QFocusEvent *);
virtual void focusOutEvent(QFocusEvent *);
@@ -366,11 +346,7 @@ protected:
#if QT_CONFIG(tabletevent)
virtual void tabletEvent(QTabletEvent *);
#endif
-#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result);
-#else
- virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result);
-#endif
QWindow(QWindowPrivate &dd, QWindow *parent);
diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h
index 5a7ec518fd..1bcbda6b8f 100644
--- a/src/gui/kernel/qwindow_p.h
+++ b/src/gui/kernel/qwindow_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWINDOW_P_H
#define QWINDOW_P_H
@@ -58,11 +22,13 @@
#include <QtCore/private/qobject_p.h>
#include <QtCore/qelapsedtimer.h>
-#include <QtGui/QIcon>
+#include <QtCore/qxpfunctional.h>
+#include <QtGui/qicon.h>
+#include <QtGui/qpalette.h>
-QT_BEGIN_NAMESPACE
+#include <QtCore/qpointer.h>
-#define QWINDOWSIZE_MAX ((1<<24)-1)
+QT_BEGIN_NAMESPACE
class Q_GUI_EXPORT QWindowPrivate : public QObjectPrivate
{
@@ -75,15 +41,11 @@ public:
WindowFrameExclusive
};
- QWindowPrivate()
- : QObjectPrivate()
- {
- isWindow = true;
- }
+ QWindowPrivate();
+ ~QWindowPrivate() override;
- void init(QScreen *targetScreen = nullptr);
+ void init(QWindow *parent, QScreen *targetScreen = nullptr);
- void maybeQuitOnLastWindowClosed();
#ifndef QT_NO_CURSOR
void setCursor(const QCursor *c = nullptr);
bool applyCursor();
@@ -93,11 +55,8 @@ public:
QWindow *topLevelWindow(QWindow::AncestorMode mode = QWindow::IncludeTransients) const;
-#if QT_CONFIG(opengl)
- virtual QOpenGLContext *shareContext() const;
-#endif
-
virtual QWindow *eventReceiver() { Q_Q(QWindow); return q; }
+ virtual QPalette windowPalette() const { return QPalette(); }
virtual void setVisible(bool visible);
void updateVisibility();
@@ -119,19 +78,25 @@ public:
virtual void clearFocusObject();
virtual QRectF closestAcceptableGeometry(const QRectF &rect) const;
- virtual void processSafeAreaMarginsChanged() {};
+ void setMinOrMaxSize(QSize *oldSizeMember, const QSize &size,
+ qxp::function_ref<void()> funcWidthChanged,
+ qxp::function_ref<void()> funcHeightChanged);
+
+ virtual void processSafeAreaMarginsChanged() {}
+
+ virtual bool participatesInLastWindowClosed() const;
+ virtual bool treatAsVisible() const;
bool isPopup() const { return (windowFlags & Qt::WindowType_Mask) == Qt::Popup; }
void setAutomaticPositionAndResizeEnabled(bool a)
{ positionAutomatic = resizeAutomatic = a; }
+ bool updateDevicePixelRatio();
+
static QWindowPrivate *get(QWindow *window) { return window->d_func(); }
static Qt::WindowState effectiveState(Qt::WindowStates);
- // ### Qt6: unused
- virtual bool allowClickThrough(const QPoint &) const { return true; }
-
QWindow::SurfaceType surfaceType = QWindow::RasterSurface;
Qt::WindowFlags windowFlags = Qt::Window;
QWindow *parentWindow = nullptr;
@@ -139,11 +104,13 @@ public:
bool visible= false;
bool visibilityOnDestroy = false;
bool exposed = false;
+ bool inClose = false;
QSurfaceFormat requestedFormat;
QString windowTitle;
QString windowFilePath;
QIcon windowIcon;
QRect geometry;
+ qreal devicePixelRatio = 1.0;
Qt::WindowStates windowState = Qt::WindowNoState;
QWindow::Visibility visibility = QWindow::Hidden;
bool resizeEventPending = true;
@@ -178,7 +145,6 @@ public:
bool hasCursor = false;
#endif
- bool compositing = false;
QElapsedTimer lastComposeTime;
#if QT_CONFIG(vulkan)
diff --git a/src/gui/kernel/qwindowdefs.h b/src/gui/kernel/qwindowdefs.h
index 5d4955c436..27d02d4d58 100644
--- a/src/gui/kernel/qwindowdefs.h
+++ b/src/gui/kernel/qwindowdefs.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWINDOWDEFS_H
#define QWINDOWDEFS_H
@@ -88,7 +52,7 @@ QT_END_NAMESPACE
// Window system dependent definitions
-#if defined(Q_OS_WIN)
+#if defined(Q_OS_WIN) || defined(Q_QDOC)
# include <QtGui/qwindowdefs_win.h>
#endif // Q_OS_WIN
@@ -101,10 +65,7 @@ typedef QT_PREPEND_NAMESPACE(quintptr) WId;
QT_BEGIN_NAMESPACE
-template<class K, class V> class QHash;
typedef QHash<WId, QWidget *> QWidgetMapper;
-
-template<class V> class QSet;
typedef QSet<QWidget *> QWidgetSet;
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qwindowdefs_win.h b/src/gui/kernel/qwindowdefs_win.h
index 40074d6cce..c2b968fe1f 100644
--- a/src/gui/kernel/qwindowdefs_win.h
+++ b/src/gui/kernel/qwindowdefs_win.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWINDOWDEFS_WIN_H
#define QWINDOWDEFS_WIN_H
diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp
index fb9f4cafe0..1875594300 100644
--- a/src/gui/kernel/qwindowsysteminterface.cpp
+++ b/src/gui/kernel/qwindowsysteminterface.cpp
@@ -1,47 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qwindowsysteminterface.h"
#include <qpa/qplatformwindow.h>
#include "qwindowsysteminterface_p.h"
#include "private/qguiapplication_p.h"
#include "private/qevent_p.h"
+#include "private/qeventpoint_p.h"
#include "private/qpointingdevice_p.h"
+#include "private/qscreen_p.h"
#include <QAbstractEventDispatcher>
#include <qpa/qplatformintegration.h>
#include <qdebug.h>
@@ -56,15 +22,16 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
Q_LOGGING_CATEGORY(lcQpaInputDevices, "qt.qpa.input.devices")
-QElapsedTimer QWindowSystemInterfacePrivate::eventTime;
+Q_CONSTINIT QElapsedTimer QWindowSystemInterfacePrivate::eventTime;
bool QWindowSystemInterfacePrivate::synchronousWindowSystemEvents = false;
-bool QWindowSystemInterfacePrivate::platformFiltersEvents = false;
bool QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse = true;
QWaitCondition QWindowSystemInterfacePrivate::eventsFlushed;
-QMutex QWindowSystemInterfacePrivate::flushEventMutex;
-QAtomicInt QWindowSystemInterfacePrivate::eventAccepted;
+Q_CONSTINIT QMutex QWindowSystemInterfacePrivate::flushEventMutex;
+Q_CONSTINIT QAtomicInt QWindowSystemInterfacePrivate::eventAccepted;
QWindowSystemEventHandler *QWindowSystemInterfacePrivate::eventHandler;
QWindowSystemInterfacePrivate::WindowSystemEventList QWindowSystemInterfacePrivate::windowSystemEventQueue;
@@ -73,20 +40,45 @@ extern QPointer<QWindow> qt_last_mouse_receiver;
// ------------------- QWindowSystemInterfacePrivate -------------------
+/*!
+ \internal
+
+ The QWindowSystemHelper creates synchronously delivered events on the stack, unless
+ the calling thread is not the Gui thread.
+
+ Asynchronously delivered events, and events created outside the Gui thread are
+ allocated on the heap.
+*/
+
+template<typename Delivery>
+struct QWindowSystemHelper
+{
+ template<typename EventType, typename ...Args>
+ static bool handleEvent(Args ...);
+};
+
/*
- Handles a window system event asynchronously by posting the event to Qt Gui.
+ Handles a window system event.
- This function posts the event on the window system event queue and wakes the
- Gui event dispatcher. Qt Gui will then handle the event asynchonously at a
- later point.
+ By default this function posts the event on the window system event queue and
+ wakes the Gui event dispatcher. Qt Gui will then handle the event asynchronously
+ at a later point. The return value is not used in asynchronous mode and will
+ always be true.
+
+ In synchronous mode Qt Gui will process the event immediately. The return value
+ indicates if Qt accepted the event. If the event is delivered from another thread
+ than the Qt main thread the window system event queue is flushed, which may deliver
+ other events as well.
+
+ \sa flushWindowSystemEvents(), setSynchronousWindowSystemEvents()
*/
template<>
-bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterface::AsynchronousDelivery>(WindowSystemEvent *ev)
+template<typename EventType, typename ...Args>
+bool QWindowSystemHelper<QWindowSystemInterface::DefaultDelivery>::handleEvent(Args ...args)
{
- windowSystemEventQueue.append(ev);
- if (QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::qt_qpa_core_dispatcher())
- dispatcher->wakeUp();
- return true;
+ return QWindowSystemInterfacePrivate::synchronousWindowSystemEvents
+ ? QWindowSystemHelper<QWindowSystemInterface::SynchronousDelivery>::handleEvent<EventType>(args...)
+ : QWindowSystemHelper<QWindowSystemInterface::AsynchronousDelivery>::handleEvent<EventType>(args...);
}
/*
@@ -100,50 +92,53 @@ bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterfa
well.
*/
template<>
-bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterface::SynchronousDelivery>(WindowSystemEvent *ev)
+template<typename EventType, typename ...Args>
+bool QWindowSystemHelper<QWindowSystemInterface::SynchronousDelivery>::handleEvent(Args ...args)
{
- bool accepted = true;
if (QThread::currentThread() == QGuiApplication::instance()->thread()) {
- // Process the event immediately on the current thread and return the accepted state.
- QGuiApplicationPrivate::processWindowSystemEvent(ev);
- accepted = ev->eventAccepted;
- delete ev;
+ EventType event(args...);
+ // Process the event immediately on the Gui thread and return the accepted state
+ if (QWindowSystemInterfacePrivate::eventHandler) {
+ if (!QWindowSystemInterfacePrivate::eventHandler->sendEvent(&event))
+ return false;
+ } else {
+ QGuiApplicationPrivate::processWindowSystemEvent(&event);
+ }
+ return event.eventAccepted;
} else {
// Post the event on the Qt main thread queue and flush the queue.
// This will wake up the Gui thread which will process the event.
// Return the accepted state for the last event on the queue,
// which is the event posted by this function.
- handleWindowSystemEvent<QWindowSystemInterface::AsynchronousDelivery>(ev);
- accepted = QWindowSystemInterface::flushWindowSystemEvents();
+ QWindowSystemHelper<QWindowSystemInterface::AsynchronousDelivery>::handleEvent<EventType>(args...);
+ return QWindowSystemInterface::flushWindowSystemEvents();
}
- return accepted;
}
/*
- Handles a window system event.
-
- By default this function posts the event on the window system event queue and
- wakes the Gui event dispatcher. Qt Gui will then handle the event asynchonously
- at a later point. The return value is not used in asynchronous mode and will
- always be true.
-
- In synchronous mode Qt Gui will process the event immediately. The return value
- indicates if Qt accepted the event. If the event is delivered from another thread
- than the Qt main thread the window system event queue is flushed, which may deliver
- other events as well.
+ Handles a window system event asynchronously by posting the event to Qt Gui.
- \sa flushWindowSystemEvents(), setSynchronousWindowSystemEvents()
+ This function posts the event on the window system event queue and wakes the
+ Gui event dispatcher. Qt Gui will then handle the event asynchronously at a
+ later point.
*/
template<>
-bool QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterface::DefaultDelivery>(QWindowSystemInterfacePrivate::WindowSystemEvent *ev)
+template<typename EventType, typename ...Args>
+bool QWindowSystemHelper<QWindowSystemInterface::AsynchronousDelivery>::handleEvent(Args ...args)
{
- if (synchronousWindowSystemEvents)
- return handleWindowSystemEvent<QWindowSystemInterface::SynchronousDelivery>(ev);
- else
- return handleWindowSystemEvent<QWindowSystemInterface::AsynchronousDelivery>(ev);
+ QWindowSystemInterfacePrivate::windowSystemEventQueue.append(new EventType(args...));
+ if (QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::qt_qpa_core_dispatcher())
+ dispatcher->wakeUp();
+ return true;
}
-int QWindowSystemInterfacePrivate::windowSystemEventsQueued()
+template <typename EventType, typename Delivery = QWindowSystemInterface::DefaultDelivery, typename ...Args>
+static bool handleWindowSystemEvent(Args ...args)
+{
+ return QWindowSystemHelper<Delivery>::template handleEvent<EventType>(args...);
+}
+
+qsizetype QWindowSystemInterfacePrivate::windowSystemEventsQueued()
{
return windowSystemEventQueue.count();
}
@@ -222,16 +217,14 @@ bool QWindowSystemEventHandler::sendEvent(QWindowSystemInterfacePrivate::WindowS
QT_DEFINE_QPA_EVENT_HANDLER(void, handleEnterEvent, QWindow *window, const QPointF &local, const QPointF &global)
{
if (window) {
- QWindowSystemInterfacePrivate::EnterEvent *e
- = new QWindowSystemInterfacePrivate::EnterEvent(window, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window));
- QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::EnterEvent, Delivery>(window,
+ QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window));
}
}
QT_DEFINE_QPA_EVENT_HANDLER(void, handleLeaveEvent, QWindow *window)
{
- QWindowSystemInterfacePrivate::LeaveEvent *e = new QWindowSystemInterfacePrivate::LeaveEvent(window);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::LeaveEvent, Delivery>(window);
}
/*!
@@ -247,11 +240,9 @@ void QWindowSystemInterface::handleEnterLeaveEvent(QWindow *enter, QWindow *leav
handleEnterEvent(enter, local, global);
}
-QT_DEFINE_QPA_EVENT_HANDLER(void, handleWindowActivated, QWindow *window, Qt::FocusReason r)
+QT_DEFINE_QPA_EVENT_HANDLER(void, handleFocusWindowChanged, QWindow *window, Qt::FocusReason r)
{
- QWindowSystemInterfacePrivate::ActivatedWindowEvent *e =
- new QWindowSystemInterfacePrivate::ActivatedWindowEvent(window, r);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::FocusWindowEvent, Delivery>(window, r);
}
QT_DEFINE_QPA_EVENT_HANDLER(void, handleWindowStateChanged, QWindow *window, Qt::WindowStates newState, int oldState)
@@ -260,38 +251,35 @@ QT_DEFINE_QPA_EVENT_HANDLER(void, handleWindowStateChanged, QWindow *window, Qt:
if (oldState < Qt::WindowNoState)
oldState = window->windowStates();
- QWindowSystemInterfacePrivate::WindowStateChangedEvent *e =
- new QWindowSystemInterfacePrivate::WindowStateChangedEvent(window, newState, Qt::WindowStates(oldState));
- QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowStateChangedEvent, Delivery>(window, newState, Qt::WindowStates(oldState));
}
QT_DEFINE_QPA_EVENT_HANDLER(void, handleWindowScreenChanged, QWindow *window, QScreen *screen)
{
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowScreenChangedEvent, Delivery>(window, screen);
+}
- QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e =
- new QWindowSystemInterfacePrivate::WindowScreenChangedEvent(window, screen);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
+QT_DEFINE_QPA_EVENT_HANDLER(void, handleWindowDevicePixelRatioChanged, QWindow *window)
+{
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent, Delivery>(window);
}
+
QT_DEFINE_QPA_EVENT_HANDLER(void, handleSafeAreaMarginsChanged, QWindow *window)
{
- QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *e =
- new QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent(window);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent, Delivery>(window);
}
QT_DEFINE_QPA_EVENT_HANDLER(void, handleApplicationStateChanged, Qt::ApplicationState newState, bool forcePropagate)
{
Q_ASSERT(QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState));
- QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *e =
- new QWindowSystemInterfacePrivate::ApplicationStateChangedEvent(newState, forcePropagate);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent, Delivery>(newState, forcePropagate);
}
QT_DEFINE_QPA_EVENT_HANDLER(bool, handleApplicationTermination)
{
- auto *e = new QWindowSystemInterfacePrivate::WindowSystemEvent(QWindowSystemInterfacePrivate::ApplicationTermination);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowSystemEvent, Delivery>(
+ QWindowSystemInterfacePrivate::ApplicationTermination);
}
QWindowSystemInterfacePrivate::GeometryChangeEvent::GeometryChangeEvent(QWindow *window, const QRect &newGeometry)
@@ -301,19 +289,14 @@ QWindowSystemInterfacePrivate::GeometryChangeEvent::GeometryChangeEvent(QWindow
{
if (const QPlatformWindow *pw = window->handle()) {
const auto nativeGeometry = pw->QPlatformWindow::geometry();
- requestedGeometry = window->isTopLevel()
- ? QHighDpi::fromNativePixels(nativeGeometry, window)
- : QHighDpi::fromNativeLocalPosition(nativeGeometry, window);
+ requestedGeometry = QHighDpi::fromNativeWindowGeometry(nativeGeometry, window);
}
}
QT_DEFINE_QPA_EVENT_HANDLER(void, handleGeometryChange, QWindow *window, const QRect &newRect)
{
Q_ASSERT(window);
- const auto newRectDi = window->isTopLevel()
- ? QHighDpi::fromNativePixels(newRect, window)
- : QHighDpi::fromNativeLocalPosition(newRect, window);
- auto e = new QWindowSystemInterfacePrivate::GeometryChangeEvent(window, newRectDi);
+ const auto newRectDi = QHighDpi::fromNativeWindowGeometry(newRect, window);
if (window->handle()) {
// Persist the new geometry so that QWindow::geometry() can be queried in the resize event
window->handle()->QPlatformWindow::setGeometry(newRect);
@@ -321,7 +304,7 @@ QT_DEFINE_QPA_EVENT_HANDLER(void, handleGeometryChange, QWindow *window, const Q
// have its handle set up yet. Platforms that deliver events during window creation need
// to handle the persistence manually, e.g. by overriding geometry().
}
- QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::GeometryChangeEvent, Delivery>(window, newRectDi);
}
QWindowSystemInterfacePrivate::ExposeEvent::ExposeEvent(QWindow *window, const QRegion &region)
@@ -349,18 +332,23 @@ QWindowSystemInterfacePrivate::ExposeEvent::ExposeEvent(QWindow *window, const Q
This is required behavior on platforms where OpenGL swapbuffers stops
blocking for obscured windows (like macOS).
*/
-QT_DEFINE_QPA_EVENT_HANDLER(void, handleExposeEvent, QWindow *window, const QRegion &region)
+QT_DEFINE_QPA_EVENT_HANDLER(bool, handleExposeEvent, QWindow *window, const QRegion &region)
+{
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::ExposeEvent, Delivery>(window,
+ QHighDpi::fromNativeLocalExposedRegion(region, window));
+}
+
+QT_DEFINE_QPA_EVENT_HANDLER(bool, handlePaintEvent, QWindow *window, const QRegion &region)
{
- QWindowSystemInterfacePrivate::ExposeEvent *e =
- new QWindowSystemInterfacePrivate::ExposeEvent(window, QHighDpi::fromNativeLocalExposedRegion(region, window));
- QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::PaintEvent, Delivery>(window,
+ QHighDpi::fromNativeLocalExposedRegion(region, window));
}
+
QT_DEFINE_QPA_EVENT_HANDLER(bool, handleCloseEvent, QWindow *window)
{
Q_ASSERT(window);
- auto *event = new QWindowSystemInterfacePrivate::CloseEvent(window);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(event);
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::CloseEvent, Delivery>(window);
}
/*!
@@ -378,6 +366,15 @@ QT_DEFINE_QPA_EVENT_HANDLER(bool, handleMouseEvent, QWindow *window,
return handleMouseEvent<Delivery>(window, time, local, global, state, button, type, mods, source);
}
+QT_DEFINE_QPA_EVENT_HANDLER(bool, handleMouseEvent, QWindow *window, const QPointingDevice *device,
+ const QPointF &local, const QPointF &global, Qt::MouseButtons state,
+ Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
+ Qt::MouseEventSource source)
+{
+ unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
+ return handleMouseEvent<Delivery>(window, time, device, local, global, state, button, type, mods, source);
+}
+
QT_DEFINE_QPA_EVENT_HANDLER(bool, handleMouseEvent, QWindow *window, ulong timestamp,
const QPointF &local, const QPointF &global, Qt::MouseButtons state,
Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
@@ -392,54 +389,34 @@ QT_DEFINE_QPA_EVENT_HANDLER(bool, handleMouseEvent, QWindow *window, ulong times
Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
Qt::MouseEventSource source)
{
- Q_ASSERT_X(type != QEvent::MouseButtonDblClick && type != QEvent::NonClientAreaMouseButtonDblClick,
- "QWindowSystemInterface::handleMouseEvent",
- "QTBUG-71263: Native double clicks are not implemented.");
- auto localPos = QHighDpi::fromNativeLocalPosition(local, window);
- auto globalPos = QHighDpi::fromNativePixels(global, window);
- QWindowSystemInterfacePrivate::MouseEvent *e =
- new QWindowSystemInterfacePrivate::MouseEvent(window, timestamp, localPos, globalPos,
- state, mods, button, type, source, false, device);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
-}
+ bool isNonClientArea = {};
-bool QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *window,
- const QPointF &local, const QPointF &global,
- Qt::MouseButtons state,
- Qt::MouseButton button, QEvent::Type type,
- Qt::KeyboardModifiers mods,
- Qt::MouseEventSource source)
-{
- const unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
- return handleFrameStrutMouseEvent(window, time, local, global, state, button, type, mods, source);
-}
-
-bool QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *window, ulong timestamp,
- const QPointF &local, const QPointF &global,
- Qt::MouseButtons state,
- Qt::MouseButton button, QEvent::Type type,
- Qt::KeyboardModifiers mods,
- Qt::MouseEventSource source)
-{
- return handleFrameStrutMouseEvent(window, timestamp, QPointingDevice::primaryPointingDevice(),
- local, global, state, button, type, mods, source);
-}
+ switch (type) {
+ case QEvent::MouseButtonDblClick:
+ case QEvent::NonClientAreaMouseButtonDblClick:
+ Q_ASSERT_X(false, "QWindowSystemInterface::handleMouseEvent",
+ "QTBUG-71263: Native double clicks are not implemented.");
+ return false;
+ case QEvent::MouseMove:
+ case QEvent::MouseButtonPress:
+ case QEvent::MouseButtonRelease:
+ isNonClientArea = false;
+ break;
+ case QEvent::NonClientAreaMouseMove:
+ case QEvent::NonClientAreaMouseButtonPress:
+ case QEvent::NonClientAreaMouseButtonRelease:
+ isNonClientArea = true;
+ break;
+ default:
+ Q_UNREACHABLE();
+ }
-bool QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *window, ulong timestamp, const QPointingDevice *device,
- const QPointF &local, const QPointF &global,
- Qt::MouseButtons state,
- Qt::MouseButton button, QEvent::Type type,
- Qt::KeyboardModifiers mods,
- Qt::MouseEventSource source)
-{
auto localPos = QHighDpi::fromNativeLocalPosition(local, window);
- auto globalPos = QHighDpi::fromNativePixels(global, window);
+ auto globalPos = QHighDpi::fromNativeGlobalPosition(global, window);
- QWindowSystemInterfacePrivate::MouseEvent *e =
- new QWindowSystemInterfacePrivate::MouseEvent(window, timestamp, localPos, globalPos,
- state, mods, button, type, source, true, device);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::MouseEvent, Delivery>(window,
+ timestamp, localPos, globalPos, state, mods, button, type, source, isNonClientArea, device);
}
bool QWindowSystemInterface::handleShortcutEvent(QWindow *window, ulong timestamp, int keyCode, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode,
@@ -456,13 +433,11 @@ bool QWindowSystemInterface::handleShortcutEvent(QWindow *window, ulong timestam
// key event, so that the target that accepted the shortcut override event can handle it. Note that we only
// do this if the shortcut map hasn't found a partial shortcut match yet. If it has, the shortcut can not be
// overridden.
- QWindowSystemInterfacePrivate::KeyEvent *shortcutOverrideEvent = new QWindowSystemInterfacePrivate::KeyEvent(window, timestamp,
- QEvent::ShortcutOverride, keyCode, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorepeat, count);
-
- {
- if (QWindowSystemInterfacePrivate::handleWindowSystemEvent<SynchronousDelivery>(shortcutOverrideEvent))
- return false;
- }
+ bool overridden = handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent, SynchronousDelivery>
+ (window,timestamp, QEvent::ShortcutOverride, keyCode, modifiers, nativeScanCode,
+ nativeVirtualKey, nativeModifiers, text, autorepeat, count);
+ if (overridden)
+ return false;
}
// The shortcut event is dispatched as a QShortcutEvent, not a QKeyEvent, but we use
@@ -473,16 +448,16 @@ bool QWindowSystemInterface::handleShortcutEvent(QWindow *window, ulong timestam
return shortcutMap.tryShortcut(&keyEvent);
#else
- Q_UNUSED(window)
- Q_UNUSED(timestamp)
- Q_UNUSED(keyCode)
- Q_UNUSED(modifiers)
- Q_UNUSED(nativeScanCode)
- Q_UNUSED(nativeVirtualKey)
- Q_UNUSED(nativeModifiers)
- Q_UNUSED(text)
- Q_UNUSED(autorepeat)
- Q_UNUSED(count)
+ Q_UNUSED(window);
+ Q_UNUSED(timestamp);
+ Q_UNUSED(keyCode);
+ Q_UNUSED(modifiers);
+ Q_UNUSED(nativeScanCode);
+ Q_UNUSED(nativeVirtualKey);
+ Q_UNUSED(nativeModifiers);
+ Q_UNUSED(text);
+ Q_UNUSED(autorepeat);
+ Q_UNUSED(count);
return false;
#endif
}
@@ -494,25 +469,19 @@ QT_DEFINE_QPA_EVENT_HANDLER(bool, handleKeyEvent, QWindow *window, QEvent::Type
QT_DEFINE_QPA_EVENT_HANDLER(bool, handleKeyEvent, QWindow *window, ulong timestamp, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text, bool autorep, ushort count)
{
-#if defined(Q_OS_MACOS)
- if (t == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(window, timestamp, k, mods, 0, 0, 0, text, autorep, count))
- return true;
-#endif
-
- QWindowSystemInterfacePrivate::KeyEvent * e =
- new QWindowSystemInterfacePrivate::KeyEvent(window, timestamp, t, k, mods, text, autorep, count);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent, Delivery>(window,
+ timestamp, t, k, mods, text, autorep, count);
}
bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
quint32 nativeScanCode, quint32 nativeVirtualKey,
quint32 nativeModifiers,
const QString& text, bool autorep,
- ushort count, bool tryShortcutOverride)
+ ushort count)
{
unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
return handleExtendedKeyEvent(window, time, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers,
- text, autorep, count, tryShortcutOverride);
+ text, autorep, count);
}
bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, ulong timestamp, QEvent::Type type, int key,
@@ -520,21 +489,10 @@ bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, ulong times
quint32 nativeScanCode, quint32 nativeVirtualKey,
quint32 nativeModifiers,
const QString& text, bool autorep,
- ushort count, bool tryShortcutOverride)
+ ushort count)
{
-#if defined(Q_OS_MACOS)
- if (tryShortcutOverride && type == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(window,
- timestamp, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count)) {
- return true;
- }
-#else
- Q_UNUSED(tryShortcutOverride)
-#endif
-
- QWindowSystemInterfacePrivate::KeyEvent * e =
- new QWindowSystemInterfacePrivate::KeyEvent(window, timestamp, type, key, modifiers,
- nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent>(window,
+ timestamp, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
}
bool QWindowSystemInterface::handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource source)
@@ -562,7 +520,6 @@ bool QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp,
// In addition high-resolution pixel-based deltas are also supported.
// Platforms that does not support these may pass a null point here.
// Angle deltas must always be sent in addition to pixel deltas.
- QWindowSystemInterfacePrivate::WheelEvent *e;
// Pass Qt::ScrollBegin and Qt::ScrollEnd through
// even if the wheel delta is null.
@@ -571,17 +528,16 @@ bool QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp,
// Simple case: vertical deltas only:
if (angleDelta.y() != 0 && angleDelta.x() == 0) {
- e = new QWindowSystemInterfacePrivate::WheelEvent(window, timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical,
- mods, phase, source, invertedScrolling, device);
-
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
+ timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
+ pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling, device);
}
// Simple case: horizontal deltas only:
if (angleDelta.y() == 0 && angleDelta.x() != 0) {
- e = new QWindowSystemInterfacePrivate::WheelEvent(window, timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal,
- mods, phase, source, invertedScrolling, device);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
+ timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
+ pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling, device);
}
bool acceptVert;
@@ -589,15 +545,16 @@ bool QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp,
// Both horizontal and vertical deltas: Send two wheel events.
// The first event contains the Qt 5 pixel and angle delta as points,
// and in addition the Qt 4 compatibility vertical angle delta.
- e = new QWindowSystemInterfacePrivate::WheelEvent(window, timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical,
- mods, phase, source, invertedScrolling, device);
- acceptVert = QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ acceptVert = handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
+ timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
+ pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling, device);
// The second event contains null pixel and angle points and the
// Qt 4 compatibility horizontal angle delta.
- e = new QWindowSystemInterfacePrivate::WheelEvent(window, timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativePixels(global, window), QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal,
- mods, phase, source, invertedScrolling, device);
- acceptHorz = QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ acceptHorz = handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
+ timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
+ QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling, device);
+
return acceptVert || acceptHorz;
}
@@ -623,37 +580,57 @@ void QWindowSystemInterface::registerInputDevice(const QInputDevice *device)
QInputDevicePrivate::registerDevice(device);
}
-QList<QTouchEvent::TouchPoint>
+/*!
+ \internal
+ Convert a list of \l QWindowSystemInterface::TouchPoint \a points to a list
+ of \e temporary QEventPoint instances, scaled (but not localized)
+ for delivery to the given \a window.
+
+ This is called from QWindowSystemInterface::handleTouchEvent():
+ that is too early to update the QEventPoint instances in QPointingDevice,
+ because we want those to hold "current" state from the applcation's
+ point of view. The QWindowSystemInterfacePrivate::TouchEvent, to which
+ the returned touchpoints will "belong", might go through the queue before
+ being processed; the application doesn't see the equivalent QTouchEvent
+ until later on. Therefore the responsibility to update the QEventPoint
+ instances in QPointingDevice is in QGuiApplication, not here.
+
+ QGuiApplicationPrivate::processMouseEvent() also calls this function
+ when it synthesizes a touch event from a mouse event. But that's outside
+ the normal use case.
+
+ It might be better if we change all the platform plugins to create
+ temporary instances of QEventPoint directly, and remove
+ QWindowSystemInterface::TouchPoint completely. Then we will no longer need
+ this function either. But that's only possible as long as QEventPoint
+ remains a Q_GADGET, not a QObject, so that it continues to be small and
+ suitable for temporary stack allocation. QEventPoint is a little bigger
+ than QWindowSystemInterface::TouchPoint, though.
+*/
+QList<QEventPoint>
QWindowSystemInterfacePrivate::fromNativeTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points,
const QWindow *window, QEvent::Type *type)
{
- QList<QTouchEvent::TouchPoint> touchPoints;
- Qt::TouchPointStates states;
- QTouchEvent::TouchPoint p;
+ QList<QEventPoint> touchPoints;
+ QEventPoint::States states;
- touchPoints.reserve(points.count());
+ touchPoints.reserve(points.size());
QList<QWindowSystemInterface::TouchPoint>::const_iterator point = points.constBegin();
QList<QWindowSystemInterface::TouchPoint>::const_iterator end = points.constEnd();
while (point != end) {
- p.setId(point->id);
- if (point->uniqueId >= 0)
- p.setUniqueId(point->uniqueId);
- p.setPressure(point->pressure);
- p.setRotation(point->rotation);
+ QPointF globalPos = QHighDpi::fromNativePixels(point->area.center(), window);
+ QEventPoint p(point->id, point->state, globalPos, globalPos);
states |= point->state;
- p.setState(point->state);
-
- p.setScreenPos(QHighDpi::fromNativePixels(point->area.center(), window));
- p.setEllipseDiameters(QHighDpi::fromNativePixels(point->area.size(), window));
+ if (point->uniqueId >= 0)
+ QMutableEventPoint::setUniqueId(p, QPointingDeviceUniqueId::fromNumericId(point->uniqueId));
+ QMutableEventPoint::setPressure(p, point->pressure);
+ QMutableEventPoint::setRotation(p, point->rotation);
+ QMutableEventPoint::setEllipseDiameters(p, QHighDpi::fromNativePixels(point->area.size(), window));
+ QMutableEventPoint::setVelocity(p, QHighDpi::fromNativePixels(point->velocity, window));
// The local pos is not set: it will be calculated
// when the event gets processed by QGuiApplication.
- p.setNormalizedPos(QHighDpi::fromNativePixels(point->normalPosition, window));
- p.setVelocity(QHighDpi::fromNativePixels(point->velocity, window));
- p.setFlags(point->flags);
- p.setRawScreenPositions(QHighDpi::fromNativePixels(point->rawPositions, window));
-
touchPoints.append(p);
++point;
}
@@ -661,37 +638,28 @@ QList<QTouchEvent::TouchPoint>
// Determine the event type based on the combined point states.
if (type) {
*type = QEvent::TouchUpdate;
- if (states == Qt::TouchPointPressed)
+ if (states == QEventPoint::State::Pressed)
*type = QEvent::TouchBegin;
- else if (states == Qt::TouchPointReleased)
+ else if (states == QEventPoint::State::Released)
*type = QEvent::TouchEnd;
}
return touchPoints;
}
-QList<QWindowSystemInterface::TouchPoint>
- QWindowSystemInterfacePrivate::toNativeTouchPoints(const QList<QTouchEvent::TouchPoint>& pointList,
- const QWindow *window)
-{
- QList<QWindowSystemInterface::TouchPoint> newList;
- newList.reserve(pointList.size());
- for (const QTouchEvent::TouchPoint &pt : pointList) {
- QWindowSystemInterface::TouchPoint p;
- p.id = pt.id();
- p.flags = pt.flags();
- p.normalPosition = QHighDpi::toNativeLocalPosition(pt.normalizedPos(), window);
- QRectF area(QPointF(), pt.ellipseDiameters());
- area.moveCenter(pt.globalPosition());
- // TODO store ellipseDiameters in QWindowSystemInterface::TouchPoint or just use QTouchEvent::TouchPoint
- p.area = QHighDpi::toNativePixels(area, window);
- p.pressure = pt.pressure();
- p.state = pt.state();
- p.velocity = QHighDpi::toNativePixels(pt.velocity(), window);
- p.rawPositions = QHighDpi::toNativePixels(pt.rawScreenPositions(), window);
- newList.append(p);
- }
- return newList;
+QWindowSystemInterface::TouchPoint
+QWindowSystemInterfacePrivate::toNativeTouchPoint(const QEventPoint &pt, const QWindow *window)
+{
+ QWindowSystemInterface::TouchPoint p;
+ p.id = pt.id();
+ QRectF area(QPointF(), pt.ellipseDiameters());
+ area.moveCenter(pt.globalPosition());
+ // TODO store ellipseDiameters in QWindowSystemInterface::TouchPoint or just use QEventPoint
+ p.area = QHighDpi::toNativePixels(area, window);
+ p.pressure = pt.pressure();
+ p.state = pt.state();
+ p.velocity = QHighDpi::toNativePixels(pt.velocity(), window);
+ return p;
}
QT_DEFINE_QPA_EVENT_HANDLER(bool, handleTouchEvent, QWindow *window, const QPointingDevice *device,
@@ -711,11 +679,11 @@ QT_DEFINE_QPA_EVENT_HANDLER(bool, handleTouchEvent, QWindow *window, ulong times
return false;
QEvent::Type type;
- QList<QTouchEvent::TouchPoint> touchPoints =
+ QList<QEventPoint> touchPoints =
QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
- QWindowSystemInterfacePrivate::TouchEvent *e =
- new QWindowSystemInterfacePrivate::TouchEvent(window, timestamp, type, device, touchPoints, mods);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
+
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TouchEvent, Delivery>(window,
+ timestamp, type, device, touchPoints, mods);
}
QT_DEFINE_QPA_EVENT_HANDLER(bool, handleTouchCancelEvent, QWindow *window, const QPointingDevice *device,
@@ -728,10 +696,8 @@ QT_DEFINE_QPA_EVENT_HANDLER(bool, handleTouchCancelEvent, QWindow *window, const
QT_DEFINE_QPA_EVENT_HANDLER(bool, handleTouchCancelEvent, QWindow *window, ulong timestamp, const QPointingDevice *device,
Qt::KeyboardModifiers mods)
{
- QWindowSystemInterfacePrivate::TouchEvent *e =
- new QWindowSystemInterfacePrivate::TouchEvent(window, timestamp, QEvent::TouchCancel, device,
- QList<QTouchEvent::TouchPoint>(), mods);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TouchEvent, Delivery>(window,
+ timestamp, QEvent::TouchCancel, device, QList<QEventPoint>(), mods);
}
/*!
@@ -745,9 +711,9 @@ QT_DEFINE_QPA_EVENT_HANDLER(bool, handleTouchCancelEvent, QWindow *window, ulong
The screen should be deleted by calling QWindowSystemInterface::handleScreenRemoved().
*/
-void QWindowSystemInterface::handleScreenAdded(QPlatformScreen *ps, bool isPrimary)
+void QWindowSystemInterface::handleScreenAdded(QPlatformScreen *platformScreen, bool isPrimary)
{
- QScreen *screen = new QScreen(ps);
+ QScreen *screen = new QScreen(platformScreen);
if (isPrimary)
QGuiApplicationPrivate::screen_list.prepend(screen);
@@ -755,6 +721,8 @@ void QWindowSystemInterface::handleScreenAdded(QPlatformScreen *ps, bool isPrima
QGuiApplicationPrivate::screen_list.append(screen);
QGuiApplicationPrivate::resetCachedDevicePixelRatio();
+ QHighDpiScaling::updateHighDpiScaling();
+ screen->d_func()->updateGeometry();
emit qGuiApp->screenAdded(screen);
@@ -772,9 +740,45 @@ void QWindowSystemInterface::handleScreenAdded(QPlatformScreen *ps, bool isPrima
*/
void QWindowSystemInterface::handleScreenRemoved(QPlatformScreen *platformScreen)
{
- // Important to keep this order since the QSceen doesn't own the platform screen.
- // The QScreen destructor will take care changing the primary screen, so no need here.
- delete platformScreen->screen();
+ QScreen *screen = platformScreen->screen();
+
+ // Remove screen
+ const bool wasPrimary = QGuiApplication::primaryScreen() == screen;
+ QGuiApplicationPrivate::screen_list.removeOne(screen);
+ QGuiApplicationPrivate::resetCachedDevicePixelRatio();
+
+ if (qGuiApp) {
+ QScreen *newPrimaryScreen = QGuiApplication::primaryScreen();
+ if (wasPrimary && newPrimaryScreen)
+ emit qGuiApp->primaryScreenChanged(newPrimaryScreen);
+
+ // Allow clients to manage windows that are affected by the screen going
+ // away, before we fall back to moving them to the primary screen.
+ emit qApp->screenRemoved(screen);
+
+ if (!QGuiApplication::closingDown()) {
+ bool movingFromVirtualSibling = newPrimaryScreen
+ && newPrimaryScreen->handle()->virtualSiblings().contains(platformScreen);
+
+ // Move any leftover windows to the primary screen
+ const auto allWindows = QGuiApplication::allWindows();
+ for (QWindow *window : allWindows) {
+ if (!window->isTopLevel() || window->screen() != screen)
+ continue;
+
+ const bool wasVisible = window->isVisible();
+ window->setScreen(newPrimaryScreen);
+
+ // Re-show window if moved from a virtual sibling screen. Otherwise
+ // leave it up to the application developer to show the window.
+ if (movingFromVirtualSibling)
+ window->setVisible(wasVisible);
+ }
+ }
+ }
+
+ // Important to keep this order since the QSceen doesn't own the platform screen
+ delete screen;
delete platformScreen;
}
@@ -787,7 +791,7 @@ void QWindowSystemInterface::handleScreenRemoved(QPlatformScreen *platformScreen
void QWindowSystemInterface::handlePrimaryScreenChanged(QPlatformScreen *newPrimary)
{
QScreen *newPrimaryScreen = newPrimary->screen();
- int indexOfScreen = QGuiApplicationPrivate::screen_list.indexOf(newPrimaryScreen);
+ qsizetype indexOfScreen = QGuiApplicationPrivate::screen_list.indexOf(newPrimaryScreen);
Q_ASSERT(indexOfScreen >= 0);
if (indexOfScreen == 0)
return;
@@ -798,36 +802,36 @@ void QWindowSystemInterface::handlePrimaryScreenChanged(QPlatformScreen *newPrim
void QWindowSystemInterface::handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation orientation)
{
- QWindowSystemInterfacePrivate::ScreenOrientationEvent *e =
- new QWindowSystemInterfacePrivate::ScreenOrientationEvent(screen, orientation);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenOrientationEvent>(screen, orientation);
}
void QWindowSystemInterface::handleScreenGeometryChange(QScreen *screen, const QRect &geometry, const QRect &availableGeometry)
{
- QWindowSystemInterfacePrivate::ScreenGeometryEvent *e =
- new QWindowSystemInterfacePrivate::ScreenGeometryEvent(screen, QHighDpi::fromNativeScreenGeometry(geometry, screen), QHighDpi::fromNative(availableGeometry, screen, geometry.topLeft()));
- QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenGeometryEvent>(screen,
+ QHighDpi::fromNativeScreenGeometry(geometry, screen), QHighDpi::fromNative(availableGeometry,
+ screen, geometry.topLeft()));
}
void QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal dpiX, qreal dpiY)
{
+ // Keep QHighDpiScaling::m_active in sync with platform screen state, in
+ // order to make scaling calls made during DPI change use the new state.
+ // FIXME: Remove when QHighDpiScaling::m_active has been removed.
+ QHighDpiScaling::updateHighDpiScaling();
+
const QDpi effectiveDpi = QPlatformScreen::overrideDpi(QDpi{dpiX, dpiY});
- auto e = new QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent(screen, effectiveDpi.first, effectiveDpi.second);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent>(screen,
+ effectiveDpi.first, effectiveDpi.second);
}
void QWindowSystemInterface::handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate)
{
- QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e =
- new QWindowSystemInterfacePrivate::ScreenRefreshRateEvent(screen, newRefreshRate);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent>(screen, newRefreshRate);
}
QT_DEFINE_QPA_EVENT_HANDLER(void, handleThemeChange, QWindow *window)
{
- QWindowSystemInterfacePrivate::ThemeChangeEvent *e = new QWindowSystemInterfacePrivate::ThemeChangeEvent(window);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::ThemeChangeEvent, Delivery>(window);
}
#if QT_CONFIG(draganddrop)
@@ -862,11 +866,7 @@ QPlatformDropQtResponse QWindowSystemInterface::handleDrop(QWindow *window, cons
\note This function can only be called from the GUI thread.
*/
-#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool QWindowSystemInterface::handleNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result)
-#else
-bool QWindowSystemInterface::handleNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result)
-#endif
{
return QGuiApplicationPrivate::processNativeEvent(window, eventType, message, result);
}
@@ -894,13 +894,24 @@ bool QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp,
qreal tangentialPressure, qreal rotation, int z,
Qt::KeyboardModifiers modifiers)
{
- QWindowSystemInterfacePrivate::TabletEvent *e =
- new QWindowSystemInterfacePrivate::TabletEvent(window, timestamp,
- QHighDpi::fromNativeLocalPosition(local, window),
- QHighDpi::fromNativePixels(global, window),
- device, buttons, pressure,
- xTilt, yTilt, tangentialPressure, rotation, z, modifiers);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletEvent>(window,
+ timestamp,
+ QHighDpi::fromNativeLocalPosition(local, window),
+ QHighDpi::fromNativeGlobalPosition(global, window),
+ device, buttons, pressure,
+ xTilt, yTilt, tangentialPressure, rotation, z, modifiers);
+}
+
+bool QWindowSystemInterface::handleTabletEvent(QWindow *window, const QPointingDevice *device,
+ const QPointF &local, const QPointF &global,
+ Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
+ qreal tangentialPressure, qreal rotation, int z,
+ Qt::KeyboardModifiers modifiers)
+{
+ const ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
+ return handleTabletEvent(window, time, device, local, global,
+ buttons, pressure, xTilt, yTilt, tangentialPressure,
+ rotation, z, modifiers);
}
bool QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global,
@@ -908,8 +919,8 @@ bool QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp,
qreal tangentialPressure, qreal rotation, int z, qint64 uid,
Qt::KeyboardModifiers modifiers)
{
- const QPointingDevice *dev = QPointingDevice::tabletDevice(QInputDevice::DeviceType(device),QPointingDevice::PointerType(pointerType),
- QPointingDeviceUniqueId::fromNumericId(uid));
+ const QPointingDevice *dev = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(device),QPointingDevice::PointerType(pointerType),
+ QPointingDeviceUniqueId::fromNumericId(uid));
return handleTabletEvent(window, timestamp, dev, local, global, buttons, pressure,
xTilt, yTilt, tangentialPressure, rotation, z, modifiers);
}
@@ -940,25 +951,30 @@ bool QWindowSystemInterface::handleTabletEnterLeaveProximityEvent(QWindow *windo
Q_UNUSED(rotation);
Q_UNUSED(z);
Q_UNUSED(modifiers);
- if (inProximity) {
- QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e =
- new QWindowSystemInterfacePrivate::TabletEnterProximityEvent(timestamp, device);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
- } else {
- QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e =
- new QWindowSystemInterfacePrivate::TabletLeaveProximityEvent(timestamp, device);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
- }
+ return inProximity
+ ? handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletEnterProximityEvent>(timestamp, device)
+ : handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent>(timestamp, device);
}
+bool QWindowSystemInterface::handleTabletEnterLeaveProximityEvent(QWindow *window, const QPointingDevice *device,
+ bool inProximity, const QPointF &local, const QPointF &global,
+ Qt::MouseButtons buttons, int xTilt, int yTilt,
+ qreal tangentialPressure, qreal rotation, int z,
+ Qt::KeyboardModifiers modifiers)
+{
+ const ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
+ return handleTabletEnterLeaveProximityEvent(window, time, device, inProximity,
+ local, global, buttons, xTilt, yTilt,
+ tangentialPressure, rotation, z, modifiers);
+}
+
+
bool QWindowSystemInterface::handleTabletEnterProximityEvent(ulong timestamp, int deviceType, int pointerType, qint64 uid)
{
- const QPointingDevice *device = QPointingDevice::tabletDevice(QInputDevice::DeviceType(deviceType),
- QPointingDevice::PointerType(pointerType),
- QPointingDeviceUniqueId::fromNumericId(uid));
- QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e =
- new QWindowSystemInterfacePrivate::TabletEnterProximityEvent(timestamp, device);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ const QPointingDevice *device = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(deviceType),
+ QPointingDevice::PointerType(pointerType),
+ QPointingDeviceUniqueId::fromNumericId(uid));
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletEnterProximityEvent>(timestamp, device);
}
void QWindowSystemInterface::handleTabletEnterProximityEvent(int deviceType, int pointerType, qint64 uid)
@@ -969,12 +985,10 @@ void QWindowSystemInterface::handleTabletEnterProximityEvent(int deviceType, int
bool QWindowSystemInterface::handleTabletLeaveProximityEvent(ulong timestamp, int deviceType, int pointerType, qint64 uid)
{
- const QPointingDevice *device = QPointingDevice::tabletDevice(QInputDevice::DeviceType(deviceType),
- QPointingDevice::PointerType(pointerType),
- QPointingDeviceUniqueId::fromNumericId(uid));
- QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e =
- new QWindowSystemInterfacePrivate::TabletLeaveProximityEvent(timestamp, device);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ const QPointingDevice *device = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(deviceType),
+ QPointingDevice::PointerType(pointerType),
+ QPointingDeviceUniqueId::fromNumericId(uid));
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent>(timestamp, device);
}
void QWindowSystemInterface::handleTabletLeaveProximityEvent(int deviceType, int pointerType, qint64 uid)
@@ -985,39 +999,32 @@ void QWindowSystemInterface::handleTabletLeaveProximityEvent(int deviceType, int
#ifndef QT_NO_GESTURES
bool QWindowSystemInterface::handleGestureEvent(QWindow *window, ulong timestamp, const QPointingDevice *device,
- Qt::NativeGestureType type, const QPointF &local, const QPointF &global)
+ Qt::NativeGestureType type, const QPointF &local, const QPointF &global, int fingerCount)
{
- QWindowSystemInterfacePrivate::GestureEvent *e =
- new QWindowSystemInterfacePrivate::GestureEvent(window, timestamp, type, device, local, global);
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ return handleGestureEventWithValueAndDelta(window, timestamp, device, type, {}, {}, local, global, fingerCount);
}
bool QWindowSystemInterface::handleGestureEventWithRealValue(QWindow *window, ulong timestamp, const QPointingDevice *device,
- Qt::NativeGestureType type, qreal value, const QPointF &local, const QPointF &global)
+ Qt::NativeGestureType type, qreal value, const QPointF &local, const QPointF &global, int fingerCount)
{
- QWindowSystemInterfacePrivate::GestureEvent *e =
- new QWindowSystemInterfacePrivate::GestureEvent(window, timestamp, type, device, local, global);
- e->realValue = value;
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ return handleGestureEventWithValueAndDelta(window, timestamp, device, type, value, {}, local, global, fingerCount);
}
-bool QWindowSystemInterface::handleGestureEventWithSequenceIdAndValue(QWindow *window, ulong timestamp, const QPointingDevice *device,
- Qt::NativeGestureType type, ulong sequenceId, quint64 value,
- const QPointF &local, const QPointF &global)
+bool QWindowSystemInterface::handleGestureEventWithValueAndDelta(QWindow *window, ulong timestamp, const QPointingDevice *device,
+ Qt::NativeGestureType type, qreal value, const QPointF &delta,
+ const QPointF &local, const QPointF &global, int fingerCount)
{
- QWindowSystemInterfacePrivate::GestureEvent *e =
- new QWindowSystemInterfacePrivate::GestureEvent(window, timestamp, type, device, local, global);
- e->sequenceId = sequenceId;
- e->intValue = value;
- return QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ auto localPos = QHighDpi::fromNativeLocalPosition(local, window);
+ auto globalPos = QHighDpi::fromNativeGlobalPosition(global, window);
+
+ return handleWindowSystemEvent<QWindowSystemInterfacePrivate::GestureEvent>(window,
+ timestamp, type, device, fingerCount, localPos, globalPos, value, delta);
}
#endif // QT_NO_GESTURES
void QWindowSystemInterface::handlePlatformPanelEvent(QWindow *w)
{
- QWindowSystemInterfacePrivate::PlatformPanelEvent *e =
- new QWindowSystemInterfacePrivate::PlatformPanelEvent(w);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::PlatformPanelEvent>(w);
}
#ifndef QT_NO_CONTEXTMENU
@@ -1025,19 +1032,16 @@ void QWindowSystemInterface::handleContextMenuEvent(QWindow *window, bool mouseT
const QPoint &pos, const QPoint &globalPos,
Qt::KeyboardModifiers modifiers)
{
- QWindowSystemInterfacePrivate::ContextMenuEvent *e =
- new QWindowSystemInterfacePrivate::ContextMenuEvent(window, mouseTriggered, pos,
- globalPos, modifiers);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::ContextMenuEvent>(window,
+ mouseTriggered, pos, globalPos, modifiers);
}
#endif
#if QT_CONFIG(whatsthis)
void QWindowSystemInterface::handleEnterWhatsThisEvent()
{
- QWindowSystemInterfacePrivate::WindowSystemEvent *e =
- new QWindowSystemInterfacePrivate::WindowSystemEvent(QWindowSystemInterfacePrivate::EnterWhatsThisMode);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowSystemEvent>(
+ QWindowSystemInterfacePrivate::EnterWhatsThisMode);
}
#endif
@@ -1059,7 +1063,7 @@ Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QWindowSystemInterface::TouchPo
*/
bool QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
{
- const int count = QWindowSystemInterfacePrivate::windowSystemEventQueue.count();
+ const qsizetype count = QWindowSystemInterfacePrivate::windowSystemEventQueue.count();
if (!count)
return false;
if (!QGuiApplication::instance()) {
@@ -1073,8 +1077,7 @@ bool QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ProcessEventsFl
// Post a FlushEvents event which will trigger a call back to
// deferredFlushWindowSystemEvents from the Gui thread.
QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex);
- QWindowSystemInterfacePrivate::FlushEventsEvent *e = new QWindowSystemInterfacePrivate::FlushEventsEvent(flags);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent<AsynchronousDelivery>(e);
+ handleWindowSystemEvent<QWindowSystemInterfacePrivate::FlushEventsEvent, AsynchronousDelivery>(flags);
QWindowSystemInterfacePrivate::eventsFlushed.wait(&QWindowSystemInterfacePrivate::flushEventMutex);
} else {
sendWindowSystemEvents(flags);
@@ -1096,15 +1099,10 @@ bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFla
int nevents = 0;
while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) {
- QWindowSystemInterfacePrivate::WindowSystemEvent *event = nullptr;
-
- if (QWindowSystemInterfacePrivate::platformFiltersEvents) {
- event = QWindowSystemInterfacePrivate::getWindowSystemEvent();
- } else {
- event = flags & QEventLoop::ExcludeUserInputEvents ?
+ QWindowSystemInterfacePrivate::WindowSystemEvent *event =
+ flags & QEventLoop::ExcludeUserInputEvents ?
QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() :
QWindowSystemInterfacePrivate::getWindowSystemEvent();
- }
if (!event)
break;
@@ -1143,21 +1141,6 @@ bool QWindowSystemInterface::nonUserInputEventsQueued()
return QWindowSystemInterfacePrivate::nonUserInputEventsQueued();
}
-/*!
- Platforms that implement UserInputEvent filtering at native event level must
- set this property to \c true. The default is \c false, which means that event
- filtering logic is handled by QWindowSystemInterface. Doing the filtering in
- platform plugins is necessary when supporting AbstractEventDispatcher::filterNativeEvent(),
- which should respect flags that were passed to event dispatcher's processEvents()
- call.
-
- \since 5.12
-*/
-void QWindowSystemInterface::setPlatformFiltersEvents(bool enable)
-{
- QWindowSystemInterfacePrivate::platformFiltersEvents = enable;
-}
-
// --------------------- QtTestLib support ---------------------
// The following functions are used by testlib, and need to be synchronous to avoid
@@ -1169,30 +1152,24 @@ Q_GUI_EXPORT void qt_handleMouseEvent(QWindow *window, const QPointF &local, con
Qt::MouseButtons state, Qt::MouseButton button,
QEvent::Type type, Qt::KeyboardModifiers mods, int timestamp)
{
- const qreal factor = QHighDpiScaling::factor(window);
- QWindowSystemInterface::handleMouseEvent<QWindowSystemInterface::SynchronousDelivery>(window,
- timestamp, local * factor, global * factor, state, button, type, mods);
-}
-
-// Wrapper for compatibility with Qt < 5.11
-// ### Qt6: Remove
-Q_GUI_EXPORT void qt_handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global,
- Qt::MouseButtons b, Qt::KeyboardModifiers mods, int timestamp)
-{
- const qreal factor = QHighDpiScaling::factor(window);
+ QPointF nativeLocal = QHighDpi::toNativeLocalPosition(local, window);
+ QPointF nativeGlobal = QHighDpi::toNativeGlobalPosition(global, window);
QWindowSystemInterface::handleMouseEvent<QWindowSystemInterface::SynchronousDelivery>(window,
- timestamp, local * factor, global * factor, b, Qt::NoButton, QEvent::None, mods);
-}
-
-// Wrapper for compatibility with Qt < 5.6
-// ### Qt6: Remove
-Q_GUI_EXPORT void qt_handleMouseEvent(QWindow *w, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods = Qt::NoModifier)
-{
- qt_handleMouseEvent(w, local, global, b, mods, QWindowSystemInterfacePrivate::eventTime.elapsed());
+ timestamp, nativeLocal, nativeGlobal, state, button, type, mods);
}
+/*
+ Used by QTest::simulateEvent() to synthesize key events during testing
+*/
Q_GUI_EXPORT void qt_handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(), bool autorep = false, ushort count = 1)
{
+#if defined(Q_OS_MACOS)
+ // FIXME: Move into QTest::simulateEvent() and align with QGuiApplicationPrivate::processKeyEvent()
+ auto timestamp = QWindowSystemInterfacePrivate::eventTime.elapsed();
+ if (t == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(window, timestamp, k, mods, 0, 0, 0, text, autorep, count))
+ return;
+#endif
+
QWindowSystemInterface::handleKeyEvent<QWindowSystemInterface::SynchronousDelivery>(window, t, k, mods, text, autorep, count);
}
@@ -1222,24 +1199,31 @@ Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int
// Then as QShortcutEvent
return shortcutMap.tryShortcut(&qevent);
#else
- Q_UNUSED(o)
- Q_UNUSED(timestamp)
- Q_UNUSED(k)
- Q_UNUSED(mods)
- Q_UNUSED(text)
- Q_UNUSED(autorep)
- Q_UNUSED(count)
+ Q_UNUSED(o);
+ Q_UNUSED(timestamp);
+ Q_UNUSED(k);
+ Q_UNUSED(mods);
+ Q_UNUSED(text);
+ Q_UNUSED(autorep);
+ Q_UNUSED(count);
return false;
#endif
}
+Q_GUI_EXPORT void qt_handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global,
+ QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods,
+ Qt::ScrollPhase phase)
+{
+ QWindowSystemInterface::handleWheelEvent(window, local, global, pixelDelta, angleDelta, mods, phase);
+}
+
namespace QTest
{
- Q_GUI_EXPORT QPointingDevice * createTouchDevice(QInputDevice::DeviceType devType = QInputDevice::DeviceType::TouchScreen,
- QInputDevice::Capabilities caps = QInputDevice::Capability::Position)
+ Q_GUI_EXPORT QPointingDevice * createTouchDevice(QInputDevice::DeviceType devType,
+ QInputDevice::Capabilities caps)
{
static qint64 nextId = 0x100000000;
- QPointingDevice *ret = new QPointingDevice(QLatin1String("test touch device"), nextId++,
+ QPointingDevice *ret = new QPointingDevice("test touch device"_L1, nextId++,
devType, QPointingDevice::PointerType::Finger,
caps, 8, 0);
QWindowSystemInterface::registerInputDevice(ret);
@@ -1247,13 +1231,19 @@ namespace QTest
}
}
-Q_GUI_EXPORT void qt_handleTouchEvent(QWindow *window, const QPointingDevice *device,
- const QList<QTouchEvent::TouchPoint> &points,
- Qt::KeyboardModifiers mods = Qt::NoModifier)
+Q_GUI_EXPORT bool qt_handleTouchEventv2(QWindow *window, const QPointingDevice *device,
+ const QList<QEventPoint> &points,
+ Qt::KeyboardModifiers mods)
{
- QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(window, device,
+ return QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(window, device,
QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window), mods);
}
+Q_GUI_EXPORT void qt_handleTouchEvent(QWindow *window, const QPointingDevice *device,
+ const QList<QEventPoint> &points,
+ Qt::KeyboardModifiers mods)
+{
+ qt_handleTouchEventv2(window, device, points, mods);
+}
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h
index 5116c72120..4fc61a475d 100644
--- a/src/gui/kernel/qwindowsysteminterface.h
+++ b/src/gui/kernel/qwindowsysteminterface.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWINDOWSYSTEMINTERFACE_H
#define QWINDOWSYSTEMINTERFACE_H
@@ -82,6 +46,12 @@ public:
Qt::KeyboardModifiers mods = Qt::NoModifier,
Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
+ static bool handleMouseEvent(QWindow *window, const QPointingDevice *device,
+ const QPointF &local, const QPointF &global,
+ Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type,
+ Qt::KeyboardModifiers mods = Qt::NoModifier,
+ Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
+ template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
static bool handleMouseEvent(QWindow *window, ulong timestamp, const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
Qt::MouseButton button, QEvent::Type type,
@@ -94,24 +64,6 @@ public:
Qt::KeyboardModifiers mods = Qt::NoModifier,
Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
- static bool handleFrameStrutMouseEvent(QWindow *window, const QPointF &local,
- const QPointF &global, Qt::MouseButtons state,
- Qt::MouseButton button, QEvent::Type type,
- Qt::KeyboardModifiers mods = Qt::NoModifier,
- Qt::MouseEventSource source =
- Qt::MouseEventNotSynthesized);
- static bool handleFrameStrutMouseEvent(QWindow *window, ulong timestamp, const QPointF &local,
- const QPointF &global, Qt::MouseButtons state,
- Qt::MouseButton button, QEvent::Type type,
- Qt::KeyboardModifiers mods = Qt::NoModifier,
- Qt::MouseEventSource source =
- Qt::MouseEventNotSynthesized);
- static bool handleFrameStrutMouseEvent(QWindow *window, ulong timestamp, const QPointingDevice *device,
- const QPointF &local, const QPointF &global, Qt::MouseButtons state,
- Qt::MouseButton button, QEvent::Type type,
- Qt::KeyboardModifiers mods = Qt::NoModifier,
- Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
-
static bool handleShortcutEvent(QWindow *window, ulong timestamp, int k, Qt::KeyboardModifiers mods, quint32 nativeScanCode,
quint32 nativeVirtualKey, quint32 nativeModifiers, const QString & text = QString(), bool autorep = false, ushort count = 1);
@@ -124,18 +76,18 @@ public:
quint32 nativeScanCode, quint32 nativeVirtualKey,
quint32 nativeModifiers,
const QString& text = QString(), bool autorep = false,
- ushort count = 1, bool tryShortcutOverride = true);
+ ushort count = 1);
static bool handleExtendedKeyEvent(QWindow *window, ulong timestamp, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
quint32 nativeScanCode, quint32 nativeVirtualKey,
quint32 nativeModifiers,
const QString& text = QString(), bool autorep = false,
- ushort count = 1, bool tryShortcutOverride = true);
+ ushort count = 1);
static bool handleExtendedKeyEvent(QWindow *window, ulong timestamp, const QInputDevice *device,
QEvent::Type type, int key, Qt::KeyboardModifiers modifiers,
quint32 nativeScanCode, quint32 nativeVirtualKey,
quint32 nativeModifiers,
const QString& text = QString(), bool autorep = false,
- ushort count = 1, bool tryShortcutOverride = true);
+ ushort count = 1);
static bool handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global,
QPoint pixelDelta, QPoint angleDelta,
Qt::KeyboardModifiers mods = Qt::NoModifier,
@@ -155,8 +107,10 @@ public:
Qt::MouseEventSource source = Qt::MouseEventNotSynthesized,
bool inverted = false);
+ // A very-temporary QPA touchpoint which gets converted to a QEventPoint as early as possible
+ // in QWindowSystemInterfacePrivate::fromNativeTouchPoints()
struct TouchPoint {
- TouchPoint() : id(0), uniqueId(-1), pressure(0), rotation(0), state(Qt::TouchPointStationary) { }
+ TouchPoint() : id(0), uniqueId(-1), pressure(0), rotation(0), state(QEventPoint::State::Stationary) { }
int id; // for application use
qint64 uniqueId; // for TUIO: object/token ID; otherwise empty
// TODO for TUIO 2.0: add registerPointerUniqueID(QPointingDeviceUniqueId)
@@ -166,9 +120,8 @@ public:
qreal pressure; // 0 to 1
qreal rotation; // rotation applied to the elliptical contact patch
// 0 means pointing straight up; 0 if unknown (like QTabletEvent::rotation)
- Qt::TouchPointState state; //Qt::TouchPoint{Pressed|Moved|Stationary|Released}
+ QEventPoint::State state; // Pressed|Updated|Stationary|Released
QVector2D velocity; // in screen coordinate system, pixels / seconds
- QTouchEvent::TouchPoint::InfoFlags flags;
QList<QPointF> rawPositions; // in screen coordinates
};
@@ -191,7 +144,10 @@ public:
// region is in local coordinates, do not confuse with geometry which is parent-relative
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static void handleExposeEvent(QWindow *window, const QRegion &region);
+ static bool handleExposeEvent(QWindow *window, const QRegion &region);
+
+ template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
+ static bool handlePaintEvent(QWindow *window, const QRegion &region);
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
static bool handleCloseEvent(QWindow *window);
@@ -201,8 +157,9 @@ public:
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
static void handleLeaveEvent(QWindow *window);
static void handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local = QPointF(), const QPointF& global = QPointF());
+
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static void handleWindowActivated(QWindow *window, Qt::FocusReason r = Qt::OtherFocusReason);
+ static void handleFocusWindowChanged(QWindow *window, Qt::FocusReason r = Qt::OtherFocusReason);
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
static void handleWindowStateChanged(QWindow *window, Qt::WindowStates newState, int oldState = -1);
@@ -210,6 +167,9 @@ public:
static void handleWindowScreenChanged(QWindow *window, QScreen *newScreen);
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
+ static void handleWindowDevicePixelRatioChanged(QWindow *window);
+
+ template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
static void handleSafeAreaMarginsChanged(QWindow *window);
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
@@ -227,11 +187,7 @@ public:
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
#endif // QT_CONFIG(draganddrop)
-#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
static bool handleNativeEvent(QWindow *window, const QByteArray &eventType, void *message, qintptr *result);
-#else
- static bool handleNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result);
-#endif
// Changes to the screen
static void handleScreenAdded(QPlatformScreen *screen, bool isPrimary = false);
@@ -244,7 +200,7 @@ public:
static void handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate);
template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static void handleThemeChange(QWindow *window);
+ static void handleThemeChange(QWindow *window = nullptr);
static void handleFileOpenEvent(const QString& fileName);
static void handleFileOpenEvent(const QUrl &url);
@@ -253,6 +209,10 @@ public:
const QPointF &local, const QPointF &global,
Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ static bool handleTabletEvent(QWindow *window, const QPointingDevice *device,
+ const QPointF &local, const QPointF &global,
+ Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
+ qreal tangentialPressure, qreal rotation, int z, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
static bool handleTabletEvent(QWindow *window, ulong timestamp, const QPointF &local, const QPointF &global,
int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z, qint64 uid,
@@ -266,6 +226,13 @@ public:
Qt::MouseButtons buttons = {}, int xTilt = 0, int yTilt = 0,
qreal tangentialPressure = 0, qreal rotation = 0, int z = 0,
Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ static bool handleTabletEnterLeaveProximityEvent(QWindow *window, const QPointingDevice *device,
+ bool inProximity, const QPointF &local = QPointF(), const QPointF &global = QPointF(),
+ Qt::MouseButtons buttons = {}, int xTilt = 0, int yTilt = 0,
+ qreal tangentialPressure = 0, qreal rotation = 0, int z = 0,
+ Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+
+ // The following 4 functions are deprecated (QTBUG-114560)
static bool handleTabletEnterProximityEvent(ulong timestamp, int deviceType, int pointerType, qint64 uid);
static void handleTabletEnterProximityEvent(int deviceType, int pointerType, qint64 uid);
static bool handleTabletLeaveProximityEvent(ulong timestamp, int deviceType, int pointerType, qint64 uid);
@@ -273,11 +240,11 @@ public:
#ifndef QT_NO_GESTURES
static bool handleGestureEvent(QWindow *window, ulong timestamp, const QPointingDevice *device, Qt::NativeGestureType type,
- const QPointF &local, const QPointF &global);
+ const QPointF &local, const QPointF &global, int fingerCount = 0);
static bool handleGestureEventWithRealValue(QWindow *window, ulong timestamp, const QPointingDevice *device, Qt::NativeGestureType type,
- qreal value, const QPointF &local, const QPointF &global);
- static bool handleGestureEventWithSequenceIdAndValue(QWindow *window, ulong timestamp, const QPointingDevice *device, Qt::NativeGestureType type,
- ulong sequenceId, quint64 value, const QPointF &local, const QPointF &global);
+ qreal value, const QPointF &local, const QPointF &global, int fingerCount = 2);
+ static bool handleGestureEventWithValueAndDelta(QWindow *window, ulong timestamp, const QPointingDevice *device, Qt::NativeGestureType type, qreal value,
+ const QPointF &delta, const QPointF &local, const QPointF &global, int fingerCount = 2);
#endif // QT_NO_GESTURES
static void handlePlatformPanelEvent(QWindow *window);
@@ -297,7 +264,6 @@ public:
static void deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags);
static int windowSystemEventsQueued();
static bool nonUserInputEventsQueued();
- static void setPlatformFiltersEvents(bool enable);
};
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h
index 6db1fc2499..51ab58fc99 100644
--- a/src/gui/kernel/qwindowsysteminterface_p.h
+++ b/src/gui/kernel/qwindowsysteminterface_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** 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-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QWINDOWSYSTEMINTERFACE_P_H
#define QWINDOWSYSTEMINTERFACE_P_H
@@ -50,6 +14,7 @@
// We mean it.
//
+#include <QtGui/private/qevent_p.h>
#include <QtGui/private/qtguiglobal_p.h>
#include "qwindowsysteminterface.h"
@@ -59,9 +24,12 @@
#include <QList>
#include <QWaitCondition>
#include <QAtomicInt>
+#include <QLoggingCategory>
QT_BEGIN_NAMESPACE
+Q_DECLARE_LOGGING_CATEGORY(lcQpaInputDevices);
+
class QWindowSystemEventHandler;
class Q_GUI_EXPORT QWindowSystemInterfacePrivate {
@@ -72,10 +40,9 @@ public:
GeometryChange = 0x02,
Enter = UserInputEvent | 0x03,
Leave = UserInputEvent | 0x04,
- ActivatedWindow = 0x05,
+ FocusWindow = 0x05,
WindowStateChanged = 0x06,
Mouse = UserInputEvent | 0x07,
- FrameStrutMouse = UserInputEvent | 0x08, // ### Qt6 remove
Wheel = UserInputEvent | 0x09,
Key = UserInputEvent | 0x0a,
Touch = UserInputEvent | 0x0b,
@@ -100,7 +67,9 @@ public:
FlushEvents = 0x20,
WindowScreenChanged = 0x21,
SafeAreaMarginsChanged = 0x22,
- ApplicationTermination = 0x23
+ ApplicationTermination = 0x23,
+ Paint = 0x24,
+ WindowDevicePixelRatioChanged = 0x25,
};
class WindowSystemEvent {
@@ -156,12 +125,12 @@ public:
QPointer<QWindow> leave;
};
- class ActivatedWindowEvent : public WindowSystemEvent {
+ class FocusWindowEvent : public WindowSystemEvent {
public:
- explicit ActivatedWindowEvent(QWindow *activatedWindow, Qt::FocusReason r)
- : WindowSystemEvent(ActivatedWindow), activated(activatedWindow), reason(r)
+ explicit FocusWindowEvent(QWindow *focusedWindow, Qt::FocusReason r)
+ : WindowSystemEvent(FocusWindow), focused(focusedWindow), reason(r)
{ }
- QPointer<QWindow> activated;
+ QPointer<QWindow> focused;
Qt::FocusReason reason;
};
@@ -186,6 +155,15 @@ public:
QPointer<QScreen> screen;
};
+ class WindowDevicePixelRatioChangedEvent : public WindowSystemEvent {
+ public:
+ WindowDevicePixelRatioChangedEvent(QWindow *w)
+ : WindowSystemEvent(WindowDevicePixelRatioChanged), window(w)
+ { }
+
+ QPointer<QWindow> window;
+ };
+
class SafeAreaMarginsChangedEvent : public WindowSystemEvent {
public:
SafeAreaMarginsChangedEvent(QWindow *w)
@@ -234,23 +212,22 @@ public:
const QInputDevice *device;
};
- class MouseEvent : public InputEvent {
+ class PointerEvent : public InputEvent {
+ public:
+ PointerEvent(QWindow * w, ulong time, EventType t, Qt::KeyboardModifiers mods, const QPointingDevice *device)
+ : InputEvent(w, time, t, mods, device) {}
+ };
+
+ class MouseEvent : public PointerEvent {
public:
MouseEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global,
Qt::MouseButtons state, Qt::KeyboardModifiers mods,
Qt::MouseButton b, QEvent::Type type,
Qt::MouseEventSource src = Qt::MouseEventNotSynthesized, bool frame = false,
const QPointingDevice *device = QPointingDevice::primaryPointingDevice())
- : InputEvent(w, time, Mouse, mods, device), localPos(local), globalPos(global),
+ : PointerEvent(w, time, Mouse, mods, device), localPos(local), globalPos(global),
buttons(state), source(src), nonClientArea(frame), button(b), buttonType(type) { }
- // ### In Qt6 this method can be removed as there won't be need for compatibility code path
- bool enhancedMouseEvent() const
- {
- static const bool disableEnhanced = qEnvironmentVariableIsSet("QT_QPA_DISABLE_ENHANCED_MOUSE");
- return !disableEnhanced && buttonType != QEvent::None;
- }
-
QPointF localPos;
QPointF globalPos;
Qt::MouseButtons buttons;
@@ -260,12 +237,12 @@ public:
QEvent::Type buttonType;
};
- class WheelEvent : public InputEvent {
+ class WheelEvent : public PointerEvent {
public:
WheelEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O,
Qt::KeyboardModifiers mods, Qt::ScrollPhase phase = Qt::NoScrollPhase, Qt::MouseEventSource src = Qt::MouseEventNotSynthesized,
bool inverted = false, const QPointingDevice *device = QPointingDevice::primaryPointingDevice())
- : InputEvent(w, time, Wheel, mods, device), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D),
+ : PointerEvent(w, time, Wheel, mods, device), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D),
qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src), inverted(inverted) { }
QPoint pixelDelta;
QPoint angleDelta;
@@ -280,17 +257,20 @@ public:
class KeyEvent : public InputEvent {
public:
- KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString & text = QString(),
- bool autorep = false, ushort count = 1, const QInputDevice *device = QInputDevice::primaryKeyboard())
- : InputEvent(w, time, Key, mods, device), key(k), unicode(text), repeat(autorep),
- repeatCount(count), keyType(t),
+ KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods,
+ const QString & text = QString(), bool autorep = false, ushort count = 1,
+ const QInputDevice *device = QInputDevice::primaryKeyboard())
+ : InputEvent(w, time, Key, mods, device), source(nullptr), key(k), unicode(text),
+ repeat(autorep), repeatCount(count), keyType(t),
nativeScanCode(0), nativeVirtualKey(0), nativeModifiers(0) { }
KeyEvent(QWindow *w, ulong time, QEvent::Type t, int k, Qt::KeyboardModifiers mods,
quint32 nativeSC, quint32 nativeVK, quint32 nativeMods,
- const QString & text = QString(), bool autorep = false, ushort count = 1, const QInputDevice *device = QInputDevice::primaryKeyboard())
- : InputEvent(w, time, Key, mods, device), key(k), unicode(text), repeat(autorep),
- repeatCount(count), keyType(t),
+ const QString & text = QString(), bool autorep = false, ushort count = 1,
+ const QInputDevice *device = QInputDevice::primaryKeyboard())
+ : InputEvent(w, time, Key, mods, device), source(nullptr), key(k), unicode(text),
+ repeat(autorep), repeatCount(count), keyType(t),
nativeScanCode(nativeSC), nativeVirtualKey(nativeVK), nativeModifiers(nativeMods) { }
+ const QInputDevice *source;
int key;
QString unicode;
bool repeat;
@@ -301,13 +281,12 @@ public:
quint32 nativeModifiers;
};
- class TouchEvent : public InputEvent {
+ class TouchEvent : public PointerEvent {
public:
TouchEvent(QWindow *w, ulong time, QEvent::Type t, const QPointingDevice *device,
- const QList<QTouchEvent::TouchPoint> &p, Qt::KeyboardModifiers mods)
- : InputEvent(w, time, Touch, mods, device), points(p), touchType(t) {
- }
- QList<QTouchEvent::TouchPoint> points;
+ const QList<QEventPoint> &p, Qt::KeyboardModifiers mods)
+ : PointerEvent(w, time, Touch, mods, device), points(p), touchType(t) { }
+ QList<QEventPoint> points;
QEvent::Type touchType;
};
@@ -360,6 +339,14 @@ public:
QRegion region;
};
+ class PaintEvent : public WindowSystemEvent {
+ public:
+ PaintEvent(QWindow *window, const QRegion &region)
+ : WindowSystemEvent(Paint), window(window), region(region) {}
+ QPointer<QWindow> window;
+ QRegion region;
+ };
+
class FileOpenEvent : public WindowSystemEvent {
public:
FileOpenEvent(const QString& fileName)
@@ -371,8 +358,9 @@ public:
QUrl url;
};
- class Q_GUI_EXPORT TabletEvent : public InputEvent {
+ class Q_GUI_EXPORT TabletEvent : public PointerEvent {
public:
+ // TODO take QPointingDevice* instead of types and IDs
static void handleTabletEvent(QWindow *w, const QPointF &local, const QPointF &global,
int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z, qint64 uid,
@@ -382,7 +370,7 @@ public:
TabletEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global,
const QPointingDevice *device, Qt::MouseButtons b, qreal pressure, int xTilt, int yTilt, qreal tpressure,
qreal rotation, int z, Qt::KeyboardModifiers mods)
- : InputEvent(w, time, Tablet, mods, device),
+ : PointerEvent(w, time, Tablet, mods, device),
buttons(b), local(local), global(global),
pressure(pressure), xTilt(xTilt), yTilt(yTilt), tangentialPressure(tpressure),
rotation(rotation), z(z) { }
@@ -398,16 +386,18 @@ public:
static bool platformSynthesizesMouse;
};
- class TabletEnterProximityEvent : public InputEvent {
+ class TabletEnterProximityEvent : public PointerEvent {
public:
+ // TODO store more info: position and whatever else we can get on most platforms
TabletEnterProximityEvent(ulong time, const QPointingDevice *device)
- : InputEvent(nullptr, time, TabletEnterProximity, Qt::NoModifier, device) { }
+ : PointerEvent(nullptr, time, TabletEnterProximity, Qt::NoModifier, device) { }
};
- class TabletLeaveProximityEvent : public InputEvent {
+ class TabletLeaveProximityEvent : public PointerEvent {
public:
+ // TODO store more info: position and whatever else we can get on most platforms
TabletLeaveProximityEvent(ulong time, const QPointingDevice *device)
- : InputEvent(nullptr, time, TabletLeaveProximity, Qt::NoModifier, device) { }
+ : PointerEvent(nullptr, time, TabletLeaveProximity, Qt::NoModifier, device) { }
};
class PlatformPanelEvent : public WindowSystemEvent {
@@ -433,20 +423,22 @@ public:
#endif
#ifndef QT_NO_GESTURES
- class GestureEvent : public InputEvent {
+ class GestureEvent : public PointerEvent {
public:
- GestureEvent(QWindow *window, ulong time, Qt::NativeGestureType type, const QPointingDevice *dev, QPointF pos, QPointF globalPos)
- : InputEvent(window, time, Gesture, Qt::NoModifier, dev), type(type), pos(pos), globalPos(globalPos),
- realValue(0), sequenceId(0), intValue(0), device(dev) { }
+ GestureEvent(QWindow *window, ulong time, Qt::NativeGestureType type, const QPointingDevice *dev,
+ int fingerCount, QPointF pos, QPointF globalPos, qreal realValue, QPointF delta)
+ : PointerEvent(window, time, Gesture, Qt::NoModifier, dev), type(type), pos(pos), globalPos(globalPos),
+ delta(delta), fingerCount(fingerCount), realValue(realValue), sequenceId(0), intValue(0) { }
Qt::NativeGestureType type;
QPointF pos;
QPointF globalPos;
+ QPointF delta;
+ int fingerCount;
// Mac
qreal realValue;
// Windows
ulong sequenceId;
quint64 intValue;
- const QPointingDevice *device;
};
#endif
@@ -462,7 +454,7 @@ public:
void prepend(WindowSystemEvent *e)
{ const QMutexLocker locker(&mutex); impl.prepend(e); }
WindowSystemEvent *takeFirstOrReturnNull()
- { const QMutexLocker locker(&mutex); return impl.empty() ? 0 : impl.takeFirst(); }
+ { const QMutexLocker locker(&mutex); return impl.empty() ? nullptr : impl.takeFirst(); }
WindowSystemEvent *takeFirstNonUserInputOrReturnNull()
{
const QMutexLocker locker(&mutex);
@@ -481,8 +473,8 @@ public:
}
void append(WindowSystemEvent *e)
{ const QMutexLocker locker(&mutex); impl.append(e); }
- int count() const
- { const QMutexLocker locker(&mutex); return impl.count(); }
+ qsizetype count() const
+ { const QMutexLocker locker(&mutex); return impl.size(); }
WindowSystemEvent *peekAtFirstOfType(EventType t) const
{
const QMutexLocker locker(&mutex);
@@ -508,14 +500,12 @@ public:
static WindowSystemEventList windowSystemEventQueue;
- static int windowSystemEventsQueued();
+ static qsizetype windowSystemEventsQueued();
static bool nonUserInputEventsQueued();
static WindowSystemEvent *getWindowSystemEvent();
static WindowSystemEvent *getNonUserInputWindowSystemEvent();
static WindowSystemEvent *peekWindowSystemEvent(EventType t);
static void removeWindowSystemEvent(WindowSystemEvent *event);
- template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
- static bool handleWindowSystemEvent(WindowSystemEvent *ev);
public:
static QElapsedTimer eventTime;
@@ -526,12 +516,22 @@ public:
static QMutex flushEventMutex;
static QAtomicInt eventAccepted;
- static QList<QTouchEvent::TouchPoint>
+ static QList<QEventPoint>
fromNativeTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points,
const QWindow *window, QEvent::Type *type = nullptr);
+ template<class EventPointList>
static QList<QWindowSystemInterface::TouchPoint>
- toNativeTouchPoints(const QList<QTouchEvent::TouchPoint>& pointList,
- const QWindow *window);
+ toNativeTouchPoints(const EventPointList &pointList, const QWindow *window)
+ {
+ QList<QWindowSystemInterface::TouchPoint> newList;
+ newList.reserve(pointList.size());
+ for (const auto &point : pointList) {
+ newList.append(toNativeTouchPoint(point, window));
+ }
+ return newList;
+ }
+ static QWindowSystemInterface::TouchPoint
+ toNativeTouchPoint(const QEventPoint &point, const QWindow *window);
static void installWindowSystemEventHandler(QWindowSystemEventHandler *handler);
static void removeWindowSystemEventhandler(QWindowSystemEventHandler *handler);