summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/kernel.pri6
-rw-r--r--src/gui/kernel/qclipboard.cpp6
-rw-r--r--src/gui/kernel/qcursor.cpp16
-rw-r--r--src/gui/kernel/qdnd.cpp12
-rw-r--r--src/gui/kernel/qdrag.cpp6
-rw-r--r--src/gui/kernel/qevent.cpp37
-rw-r--r--src/gui/kernel/qguiaction.h2
-rw-r--r--src/gui/kernel/qguiactiongroup.cpp5
-rw-r--r--src/gui/kernel/qguiapplication.cpp272
-rw-r--r--src/gui/kernel/qguiapplication_p.h11
-rw-r--r--src/gui/kernel/qguivariant.cpp16
-rw-r--r--src/gui/kernel/qhighdpiscaling.cpp29
-rw-r--r--src/gui/kernel/qinputdevicemanager_p_p.h2
-rw-r--r--src/gui/kernel/qkeymapper.cpp2
-rw-r--r--src/gui/kernel/qoffscreensurface.cpp14
-rw-r--r--src/gui/kernel/qopenglcontext.cpp66
-rw-r--r--src/gui/kernel/qopenglcontext.h2
-rw-r--r--src/gui/kernel/qopenglcontext_p.h1
-rw-r--r--src/gui/kernel/qopenglwindow.cpp698
-rw-r--r--src/gui/kernel/qopenglwindow.h107
-rw-r--r--src/gui/kernel/qpaintdevicewindow.cpp2
-rw-r--r--src/gui/kernel/qpalette.cpp206
-rw-r--r--src/gui/kernel/qpalette.h27
-rw-r--r--src/gui/kernel/qplatformclipboard.cpp2
-rw-r--r--src/gui/kernel/qplatformcursor.cpp20
-rw-r--r--src/gui/kernel/qplatformcursor.h1
-rw-r--r--src/gui/kernel/qplatformdialoghelper.cpp22
-rw-r--r--src/gui/kernel/qplatforminputcontextfactory.cpp2
-rw-r--r--src/gui/kernel/qplatformintegration.cpp22
-rw-r--r--src/gui/kernel/qplatformintegration.h3
-rw-r--r--src/gui/kernel/qplatformintegrationplugin.cpp2
-rw-r--r--src/gui/kernel/qplatformnativeinterface.cpp20
-rw-r--r--src/gui/kernel/qplatformopenglcontext.cpp2
-rw-r--r--src/gui/kernel/qplatformscreen.cpp33
-rw-r--r--src/gui/kernel/qplatformscreen.h23
-rw-r--r--src/gui/kernel/qplatformtheme.cpp16
-rw-r--r--src/gui/kernel/qplatformtheme.h2
-rw-r--r--src/gui/kernel/qplatformwindow.cpp9
-rw-r--r--src/gui/kernel/qplatformwindow.h6
-rw-r--r--src/gui/kernel/qscreen.cpp2
-rw-r--r--src/gui/kernel/qsessionmanager.cpp2
-rw-r--r--src/gui/kernel/qshortcutmap.cpp93
-rw-r--r--src/gui/kernel/qsimpledrag.cpp4
-rw-r--r--src/gui/kernel/qstylehints.cpp2
-rw-r--r--src/gui/kernel/qsurface.cpp2
-rw-r--r--src/gui/kernel/qsurfaceformat.cpp2
-rw-r--r--src/gui/kernel/qwindow.cpp21
-rw-r--r--src/gui/kernel/qwindowsysteminterface.cpp16
-rw-r--r--src/gui/kernel/qwindowsysteminterface.h1
-rw-r--r--src/gui/kernel/qwindowsysteminterface_p.h1
50 files changed, 608 insertions, 1268 deletions
diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri
index 3784abdacc..d47fd6e4e4 100644
--- a/src/gui/kernel/kernel.pri
+++ b/src/gui/kernel/kernel.pri
@@ -158,13 +158,11 @@ qtConfig(opengl) {
HEADERS += \
kernel/qplatformopenglcontext.h \
kernel/qopenglcontext.h \
- kernel/qopenglcontext_p.h \
- kernel/qopenglwindow.h
+ kernel/qopenglcontext_p.h
SOURCES += \
kernel/qplatformopenglcontext.cpp \
- kernel/qopenglcontext.cpp \
- kernel/qopenglwindow.cpp
+ kernel/qopenglcontext.cpp
}
qtConfig(shortcut) {
diff --git a/src/gui/kernel/qclipboard.cpp b/src/gui/kernel/qclipboard.cpp
index 267c079ad9..db22ef2486 100644
--- a/src/gui/kernel/qclipboard.cpp
+++ b/src/gui/kernel/qclipboard.cpp
@@ -461,7 +461,7 @@ void QClipboard::setPixmap(const QPixmap &pixmap, Mode mode)
const QMimeData* QClipboard::mimeData(Mode mode) const
{
QPlatformClipboard *clipboard = QGuiApplicationPrivate::platformIntegration()->clipboard();
- if (!clipboard->supportsMode(mode)) return 0;
+ if (!clipboard->supportsMode(mode)) return nullptr;
return clipboard->mimeData(mode);
}
@@ -488,7 +488,7 @@ void QClipboard::setMimeData(QMimeData* src, Mode mode)
{
QPlatformClipboard *clipboard = QGuiApplicationPrivate::platformIntegration()->clipboard();
if (!clipboard->supportsMode(mode)) {
- if (src != 0) {
+ if (src != nullptr) {
qDebug("Data set on unsupported clipboard mode. QMimeData object will be deleted.");
src->deleteLater();
}
@@ -512,7 +512,7 @@ void QClipboard::setMimeData(QMimeData* src, Mode mode)
*/
void QClipboard::clear(Mode mode)
{
- setMimeData(0, mode);
+ setMimeData(nullptr, mode);
}
/*!
diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp
index 1ba8760a9d..f5a794b642 100644
--- a/src/gui/kernel/qcursor.cpp
+++ b/src/gui/kernel/qcursor.cpp
@@ -175,6 +175,8 @@ QT_BEGIN_NAMESPACE
\fn void QCursor::swap(QCursor &other)
Swaps this cursor with the \a other cursor.
+
+ \since 5.7
*/
/*!
@@ -384,7 +386,7 @@ QDataStream &operator>>(QDataStream &s, QCursor &c)
*/
QCursor::QCursor(const QPixmap &pixmap, int hotX, int hotY)
- : d(0)
+ : d(nullptr)
{
QImage img = pixmap.toImage().convertToFormat(QImage::Format_Indexed8, Qt::ThresholdDither|Qt::AvoidDither);
QBitmap bm = QBitmap::fromImage(img, Qt::ThresholdDither|Qt::AvoidDither);
@@ -440,7 +442,7 @@ QCursor::QCursor(const QPixmap &pixmap, int hotX, int hotY)
*/
QCursor::QCursor(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
- : d(0)
+ : d(nullptr)
{
d = QCursorData::setBitmap(bitmap, mask, hotX, hotY, 1.0);
}
@@ -452,7 +454,7 @@ QCursor::QCursor()
{
if (!QCursorData::initialized) {
if (QCoreApplication::startingUp()) {
- d = 0;
+ d = nullptr;
return;
}
QCursorData::initialize();
@@ -470,7 +472,7 @@ QCursor::QCursor()
\sa setShape()
*/
QCursor::QCursor(Qt::CursorShape shape)
- : d(0)
+ : d(nullptr)
{
if (!QCursorData::initialized)
QCursorData::initialize();
@@ -550,7 +552,7 @@ void QCursor::setShape(Qt::CursorShape shape)
{
if (!QCursorData::initialized)
QCursorData::initialize();
- QCursorData *c = uint(shape) <= Qt::LastCursor ? qt_cursorTable[shape] : 0;
+ QCursorData *c = uint(shape) <= Qt::LastCursor ? qt_cursorTable[shape] : nullptr;
if (!c)
c = qt_cursorTable[0];
c->ref.ref();
@@ -675,7 +677,7 @@ QCursorData *qt_cursorTable[Qt::LastCursor + 1];
bool QCursorData::initialized = false;
QCursorData::QCursorData(Qt::CursorShape s)
- : ref(1), cshape(s), bm(0), bmm(0), hx(0), hy(0)
+ : ref(1), cshape(s), bm(nullptr), bmm(nullptr), hx(0), hy(0)
{
}
@@ -695,7 +697,7 @@ void QCursorData::cleanup()
// In case someone has a static QCursor defined with this shape
if (!qt_cursorTable[shape]->ref.deref())
delete qt_cursorTable[shape];
- qt_cursorTable[shape] = 0;
+ qt_cursorTable[shape] = nullptr;
}
QCursorData::initialized = false;
}
diff --git a/src/gui/kernel/qdnd.cpp b/src/gui/kernel/qdnd.cpp
index dd541af3b8..fe766c900e 100644
--- a/src/gui/kernel/qdnd.cpp
+++ b/src/gui/kernel/qdnd.cpp
@@ -48,19 +48,19 @@
QT_BEGIN_NAMESPACE
// the universe's only drag manager
-QDragManager *QDragManager::m_instance = 0;
+QDragManager *QDragManager::m_instance = nullptr;
QDragManager::QDragManager()
- : QObject(qApp), m_currentDropTarget(0),
+ : QObject(qApp), m_currentDropTarget(nullptr),
m_platformDrag(QGuiApplicationPrivate::platformIntegration()->drag()),
- m_object(0)
+ m_object(nullptr)
{
Q_ASSERT(!m_instance);
}
QDragManager::~QDragManager()
{
- m_instance = 0;
+ m_instance = nullptr;
}
QDragManager *QDragManager::self()
@@ -74,7 +74,7 @@ QObject *QDragManager::source() const
{
if (m_object)
return m_object->source();
- return 0;
+ return nullptr;
}
void QDragManager::setCurrentTarget(QObject *target, bool dropped)
@@ -111,7 +111,7 @@ Qt::DropAction QDragManager::drag(QDrag *o)
m_object = o;
- m_object->d_func()->target = 0;
+ m_object->d_func()->target = nullptr;
QGuiApplicationPrivate::instance()->notifyDragStarted(m_object.data());
const Qt::DropAction result = m_platformDrag->drag(m_object);
diff --git a/src/gui/kernel/qdrag.cpp b/src/gui/kernel/qdrag.cpp
index 8e2f7be23e..3712eace15 100644
--- a/src/gui/kernel/qdrag.cpp
+++ b/src/gui/kernel/qdrag.cpp
@@ -112,8 +112,8 @@ QDrag::QDrag(QObject *dragSource)
{
Q_D(QDrag);
d->source = dragSource;
- d->target = 0;
- d->data = 0;
+ d->target = nullptr;
+ d->data = nullptr;
d->hotspot = QPoint(-10, -10);
d->executed_action = Qt::IgnoreAction;
d->supported_actions = Qt::IgnoreAction;
@@ -138,7 +138,7 @@ void QDrag::setMimeData(QMimeData *data)
Q_D(QDrag);
if (d->data == data)
return;
- if (d->data != 0)
+ if (d->data != nullptr)
delete d->data;
d->data = data;
}
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 23defef50c..e36080eee2 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -667,9 +667,9 @@ QHoverEvent::~QHoverEvent()
if that widget does not handle the event they are sent to the
focus widget. Wheel events are generated for both mouse wheels
and trackpad scroll gestures. There are two ways to read the
- wheel event delta: angleDelta() returns the delta in wheel
- degrees. This value is always provided. pixelDelta() returns
- the delta in screen pixels and is available on platforms that
+ wheel event delta: angleDelta() returns the deltas in wheel
+ 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.
@@ -846,12 +846,13 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
/*!
Constructs a wheel event object.
+ \since 5.12
The \a pos provides the location of the mouse cursor
within the window. The position in global coordinates is specified
by \a globalPos.
\a pixelDelta contains the scrolling distance in pixels on screen, while
- \a angleDelta contains the wheel rotation distance. \a pixelDelta is
+ \a angleDelta contains the wheel rotation angle. \a pixelDelta is
optional and can be null.
The mouse and keyboard states at the time of the event are specified by
@@ -913,10 +914,16 @@ QWheelEvent::~QWheelEvent()
/*!
\fn QPoint QWheelEvent::angleDelta() const
- Returns the distance that the wheel is rotated, in eighths of a
- degree. A positive value indicates that the wheel was rotated
- forwards away from the user; a negative value indicates that the
- wheel was rotated backwards toward the user.
+ Returns the relative amount that the wheel was rotated, in eighths of a
+ degree. A positive value indicates that the wheel was rotated forwards away
+ from the user; a negative value indicates that the wheel was rotated
+ backwards toward the user. \c angleDelta().y() provides the angle through
+ which the common vertical mouse wheel was rotated since the previous event.
+ \c angleDelta().x() provides the angle through which the horizontal mouse
+ wheel was rotated, if the mouse has a horizontal wheel; otherwise it stays
+ at zero. Some mice allow the user to tilt the wheel to perform horizontal
+ scrolling, and some touchpads support a horizontal scrolling gesture; that
+ will also appear in \c angleDelta().x().
Most mouse types work in steps of 15 degrees, in which case the
delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.
@@ -925,7 +932,9 @@ QWheelEvent::~QWheelEvent()
that are less than 120 units (less than 15 degrees). To support this
possibility, you can either cumulatively add the delta values from events
until the value of 120 is reached, then scroll the widget, or you can
- partially scroll the widget in response to each wheel event.
+ partially scroll the widget in response to each wheel event. But to
+ provide a more native feel, you should prefer \l pixelDelta() on platforms
+ where it's available.
Example:
@@ -936,6 +945,8 @@ 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
+
+ \see pixelDelta()
*/
/*!
@@ -2938,7 +2949,7 @@ QObject* QDropEvent::source() const
{
if (const QDragManager *manager = QDragManager::self())
return manager->source();
- return 0;
+ return nullptr;
}
@@ -4303,8 +4314,8 @@ QTouchEvent::QTouchEvent(QEvent::Type eventType,
Qt::TouchPointStates touchPointStates,
const QList<QTouchEvent::TouchPoint> &touchPoints)
: QInputEvent(eventType, modifiers),
- _window(0),
- _target(0),
+ _window(nullptr),
+ _target(nullptr),
_device(device),
_touchPointStates(touchPointStates),
_touchPoints(touchPoints)
@@ -4996,7 +5007,7 @@ void QTouchEvent::TouchPoint::setFlags(InfoFlags flags)
The \a startPos is the position of a touch or mouse event that started the scrolling.
*/
QScrollPrepareEvent::QScrollPrepareEvent(const QPointF &startPos)
- : QEvent(QEvent::ScrollPrepare), m_target(0), m_startPos(startPos)
+ : QEvent(QEvent::ScrollPrepare), m_target(nullptr), m_startPos(startPos)
{
Q_UNUSED(m_target);
}
diff --git a/src/gui/kernel/qguiaction.h b/src/gui/kernel/qguiaction.h
index bd7d13e156..454f66893f 100644
--- a/src/gui/kernel/qguiaction.h
+++ b/src/gui/kernel/qguiaction.h
@@ -62,7 +62,7 @@ class Q_GUI_EXPORT QGuiAction : public QObject
Q_DECLARE_PRIVATE(QGuiAction)
Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY changed)
- Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled)
+ Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY changed)
Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY changed)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY changed)
diff --git a/src/gui/kernel/qguiactiongroup.cpp b/src/gui/kernel/qguiactiongroup.cpp
index 82f5e0a0af..7360214aad 100644
--- a/src/gui/kernel/qguiactiongroup.cpp
+++ b/src/gui/kernel/qguiactiongroup.cpp
@@ -222,7 +222,8 @@ QList<QGuiAction*> QGuiActionGroup::guiActions() const
\brief Enable or disable the group exclusion checking
This is a convenience method that calls
- setExclusionPolicy(ExclusionPolicy::Exclusive).
+ setExclusionPolicy(ExclusionPolicy::Exclusive) when \a b is true,
+ else setExclusionPolicy(QActionGroup::ExclusionPolicy::None).
\sa QGuiActionGroup::exclusionPolicy
*/
@@ -233,7 +234,7 @@ void QGuiActionGroup::setExclusive(bool b)
}
/*!
- \brief Returs true if the group is exclusive
+ \brief Returns true if the group is exclusive
The group is exclusive if the ExclusionPolicy is either Exclusive
or ExclusionOptional.
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index f4a5c0e104..d72cc2df79 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -141,22 +141,28 @@ Qt::KeyboardModifiers QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
QPointF QGuiApplicationPrivate::lastCursorPosition(qInf(), qInf());
-QWindow *QGuiApplicationPrivate::currentMouseWindow = 0;
+QWindow *QGuiApplicationPrivate::currentMouseWindow = nullptr;
QString QGuiApplicationPrivate::styleOverride;
Qt::ApplicationState QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
Qt::HighDpiScaleFactorRoundingPolicy QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy =
- Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor;
+#ifdef Q_OS_ANDROID
+ // On Android, Qt has newer rounded the scale factor. Preserve
+ // that behavior by disabling rounding by default.
+ Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
+#else
+ Qt::HighDpiScaleFactorRoundingPolicy::Round;
+#endif
bool QGuiApplicationPrivate::highDpiScalingUpdated = false;
QPointer<QWindow> QGuiApplicationPrivate::currentDragWindow;
QVector<QGuiApplicationPrivate::TabletPointData> QGuiApplicationPrivate::tabletDevicePoints;
-QPlatformIntegration *QGuiApplicationPrivate::platform_integration = 0;
-QPlatformTheme *QGuiApplicationPrivate::platform_theme = 0;
+QPlatformIntegration *QGuiApplicationPrivate::platform_integration = nullptr;
+QPlatformTheme *QGuiApplicationPrivate::platform_theme = nullptr;
QList<QObject *> QGuiApplicationPrivate::generic_plugin_list;
@@ -166,19 +172,18 @@ bool QGuiApplicationPrivate::is_fallback_session_management_enabled = true;
enum ApplicationResourceFlags
{
- ApplicationPaletteExplicitlySet = 0x1,
ApplicationFontExplicitlySet = 0x2
};
static unsigned applicationResourceFlags = 0;
-QIcon *QGuiApplicationPrivate::app_icon = 0;
+QIcon *QGuiApplicationPrivate::app_icon = nullptr;
-QString *QGuiApplicationPrivate::platform_name = 0;
-QString *QGuiApplicationPrivate::displayName = 0;
-QString *QGuiApplicationPrivate::desktopFileName = 0;
+QString *QGuiApplicationPrivate::platform_name = nullptr;
+QString *QGuiApplicationPrivate::displayName = nullptr;
+QString *QGuiApplicationPrivate::desktopFileName = nullptr;
-QPalette *QGuiApplicationPrivate::app_pal = 0; // default application palette
+QPalette *QGuiApplicationPrivate::app_pal = nullptr; // default application palette
ulong QGuiApplicationPrivate::mousePressTime = 0;
Qt::MouseButton QGuiApplicationPrivate::mousePressButton = Qt::NoButton;
@@ -188,30 +193,30 @@ int QGuiApplicationPrivate::mousePressY = 0;
static int mouseDoubleClickDistance = -1;
static int touchDoubleTapDistance = -1;
-QWindow *QGuiApplicationPrivate::currentMousePressWindow = 0;
+QWindow *QGuiApplicationPrivate::currentMousePressWindow = nullptr;
static Qt::LayoutDirection layout_direction = Qt::LayoutDirectionAuto;
static bool force_reverse = false;
-QGuiApplicationPrivate *QGuiApplicationPrivate::self = 0;
-QTouchDevice *QGuiApplicationPrivate::m_fakeTouchDevice = 0;
+QGuiApplicationPrivate *QGuiApplicationPrivate::self = nullptr;
+QTouchDevice *QGuiApplicationPrivate::m_fakeTouchDevice = nullptr;
int QGuiApplicationPrivate::m_fakeMouseSourcePointId = 0;
#ifndef QT_NO_CLIPBOARD
-QClipboard *QGuiApplicationPrivate::qt_clipboard = 0;
+QClipboard *QGuiApplicationPrivate::qt_clipboard = nullptr;
#endif
QList<QScreen *> QGuiApplicationPrivate::screen_list;
QWindowList QGuiApplicationPrivate::window_list;
-QWindow *QGuiApplicationPrivate::focus_window = 0;
+QWindow *QGuiApplicationPrivate::focus_window = nullptr;
static QBasicMutex applicationFontMutex;
-QFont *QGuiApplicationPrivate::app_font = 0;
+QFont *QGuiApplicationPrivate::app_font = nullptr;
QStyleHints *QGuiApplicationPrivate::styleHints = nullptr;
bool QGuiApplicationPrivate::obey_desktop_settings = true;
-QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = 0;
+QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = nullptr;
qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0;
@@ -231,21 +236,6 @@ static bool qt_detectRTLLanguage()
" and Arabic) to get proper widget layout.") == QLatin1String("RTL"));
}
-static void initPalette()
-{
- if (!QGuiApplicationPrivate::app_pal)
- if (const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette())
- QGuiApplicationPrivate::app_pal = new QPalette(*themePalette);
- if (!QGuiApplicationPrivate::app_pal)
- QGuiApplicationPrivate::app_pal = new QPalette(Qt::gray);
-}
-
-static inline void clearPalette()
-{
- delete QGuiApplicationPrivate::app_pal;
- QGuiApplicationPrivate::app_pal = 0;
-}
-
static void initFontUnlocked()
{
if (!QGuiApplicationPrivate::app_font) {
@@ -261,7 +251,7 @@ static void initFontUnlocked()
static inline void clearFontUnlocked()
{
delete QGuiApplicationPrivate::app_font;
- QGuiApplicationPrivate::app_font = 0;
+ QGuiApplicationPrivate::app_font = nullptr;
}
static void initThemeHints()
@@ -600,8 +590,13 @@ static QWindowGeometrySpecification windowGeometrySpecification = Q_WINDOW_GEOME
The following parameters are available for \c {-platform windows}:
\list
+ \li \c {altgr}, detect the key \c {AltGr} found on some keyboards as
+ Qt::GroupSwitchModifier (since Qt 5.12).
\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 {menus=[native|none]}, controls the use of native menus.
@@ -611,10 +606,23 @@ static QWindowGeometrySpecification windowGeometrySpecification = Q_WINDOW_GEOME
provide hover signals. They are mainly intended for Qt Quick.
By default, they will be used if the application is not an
instance of QApplication or for Qt Quick Controls 2
- applications.
+ applications (since Qt 5.10).
- \li \c {altgr}, detect the key \c {AltGr} found on some keyboards as
- Qt::GroupSwitchModifier.
+ \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 {nomousefromtouch} Ignores mouse events synthesized
+ from touch events by the operating system.
+
+ \li \c {nowmpointer} Switches from Pointer Input Messages handling
+ to legacy mouse handling (since Qt 5.12).
+ \li \c {reverse} Activates Right-to-left mode (experimental).
+ Windows title bars will be shown accordingly in Right-to-left locales
+ (since Qt 5.13).
+ \li \c {tabletabsoluterange=<value>} Sets a value for mouse mode detection
+ of WinTab tablets (Legacy, since Qt 5.3).
\endlist
The following parameter is available for \c {-platform cocoa} (on macOS):
@@ -656,19 +664,19 @@ QGuiApplication::~QGuiApplication()
Q_D(QGuiApplication);
d->eventDispatcher->closingDown();
- d->eventDispatcher = 0;
+ d->eventDispatcher = nullptr;
#ifndef QT_NO_CLIPBOARD
delete QGuiApplicationPrivate::qt_clipboard;
- QGuiApplicationPrivate::qt_clipboard = 0;
+ QGuiApplicationPrivate::qt_clipboard = nullptr;
#endif
#ifndef QT_NO_SESSIONMANAGER
delete d->session_manager;
- d->session_manager = 0;
+ d->session_manager = nullptr;
#endif //QT_NO_SESSIONMANAGER
- clearPalette();
+ QGuiApplicationPrivate::clearPalette();
QFontDatabase::removeAllApplicationFonts();
#ifndef QT_NO_CURSOR
@@ -676,22 +684,20 @@ QGuiApplication::~QGuiApplication()
#endif
delete QGuiApplicationPrivate::app_icon;
- QGuiApplicationPrivate::app_icon = 0;
+ QGuiApplicationPrivate::app_icon = nullptr;
delete QGuiApplicationPrivate::platform_name;
- QGuiApplicationPrivate::platform_name = 0;
+ QGuiApplicationPrivate::platform_name = nullptr;
delete QGuiApplicationPrivate::displayName;
- QGuiApplicationPrivate::displayName = 0;
+ QGuiApplicationPrivate::displayName = nullptr;
delete QGuiApplicationPrivate::m_inputDeviceManager;
- QGuiApplicationPrivate::m_inputDeviceManager = 0;
+ QGuiApplicationPrivate::m_inputDeviceManager = nullptr;
delete QGuiApplicationPrivate::desktopFileName;
- QGuiApplicationPrivate::desktopFileName = 0;
+ QGuiApplicationPrivate::desktopFileName = nullptr;
QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
QGuiApplicationPrivate::lastCursorPosition = {qInf(), qInf()};
QGuiApplicationPrivate::currentMousePressWindow = QGuiApplicationPrivate::currentMouseWindow = nullptr;
QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
- QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy =
- Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor;
QGuiApplicationPrivate::highDpiScalingUpdated = false;
QGuiApplicationPrivate::currentDragWindow = nullptr;
QGuiApplicationPrivate::tabletDevicePoints.clear();
@@ -704,7 +710,7 @@ QGuiApplication::~QGuiApplication()
QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags)
: QCoreApplicationPrivate(argc, argv, flags),
- inputMethod(0),
+ inputMethod(nullptr),
lastTouchType(QEvent::TouchEnd),
ownGlobalShareContext(false)
{
@@ -797,7 +803,7 @@ QWindow *QGuiApplication::modalWindow()
{
CHECK_QAPP_INSTANCE(nullptr)
if (QGuiApplicationPrivate::self->modalWindowList.isEmpty())
- return 0;
+ return nullptr;
return QGuiApplicationPrivate::self->modalWindowList.first();
}
@@ -844,7 +850,7 @@ void QGuiApplicationPrivate::showModalWindow(QWindow *modal)
self->modalWindowList.removeFirst();
QEvent e(QEvent::Leave);
QGuiApplication::sendEvent(currentMouseWindow, &e);
- currentMouseWindow = 0;
+ currentMouseWindow = nullptr;
self->modalWindowList.prepend(modal);
}
}
@@ -874,12 +880,12 @@ void QGuiApplicationPrivate::hideModalWindow(QWindow *window)
*/
bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow) const
{
- QWindow *unused = 0;
+ QWindow *unused = nullptr;
if (!blockingWindow)
blockingWindow = &unused;
if (modalWindowList.isEmpty()) {
- *blockingWindow = 0;
+ *blockingWindow = nullptr;
return false;
}
@@ -889,7 +895,7 @@ bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blocking
// 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 = 0;
+ *blockingWindow = nullptr;
return false;
}
@@ -930,7 +936,7 @@ bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blocking
break;
}
}
- *blockingWindow = 0;
+ *blockingWindow = nullptr;
return false;
}
@@ -969,7 +975,7 @@ QObject *QGuiApplication::focusObject()
{
if (focusWindow())
return focusWindow()->focusObject();
- return 0;
+ return nullptr;
}
/*!
@@ -1022,7 +1028,7 @@ QWindowList QGuiApplication::topLevelWindows()
QScreen *QGuiApplication::primaryScreen()
{
if (QGuiApplicationPrivate::screen_list.isEmpty())
- return 0;
+ return nullptr;
return QGuiApplicationPrivate::screen_list.at(0);
}
@@ -1454,7 +1460,7 @@ void QGuiApplicationPrivate::createPlatformIntegration()
}
if (j < argc) {
- argv[j] = 0;
+ argv[j] = nullptr;
argc = j;
}
@@ -1474,7 +1480,7 @@ void QGuiApplicationPrivate::createEventDispatcher()
{
Q_ASSERT(!eventDispatcher);
- if (platform_integration == 0)
+ if (platform_integration == nullptr)
createPlatformIntegration();
// The platform integration should not mess with the event dispatcher
@@ -1485,7 +1491,7 @@ void QGuiApplicationPrivate::createEventDispatcher()
void QGuiApplicationPrivate::eventDispatcherReady()
{
- if (platform_integration == 0)
+ if (platform_integration == nullptr)
createPlatformIntegration();
platform_integration->initialize();
@@ -1582,7 +1588,7 @@ void QGuiApplicationPrivate::init()
}
if (j < argc) {
- argv[j] = 0;
+ argv[j] = nullptr;
argc = j;
}
@@ -1591,10 +1597,10 @@ void QGuiApplicationPrivate::init()
if (!envPlugins.isEmpty())
pluginList += envPlugins.split(',');
- if (platform_integration == 0)
+ if (platform_integration == nullptr)
createPlatformIntegration();
- initPalette();
+ updatePalette();
QFont::initialize();
initThemeHints();
@@ -1697,22 +1703,16 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate()
#ifndef QT_NO_OPENGL
if (ownGlobalShareContext) {
delete qt_gl_global_share_context();
- qt_gl_set_global_share_context(0);
+ qt_gl_set_global_share_context(nullptr);
}
#endif
-#ifdef Q_OS_WASM
- EM_ASM(
- // unmount persistent directory as IDBFS
- // see QTBUG-70002
- FS.unmount('/home/web_user');
- );
-#endif
+
platform_integration->destroy();
delete platform_theme;
- platform_theme = 0;
+ platform_theme = nullptr;
delete platform_integration;
- platform_integration = 0;
+ platform_integration = nullptr;
window_list.clear();
screen_list.clear();
@@ -1773,7 +1773,7 @@ Qt::KeyboardModifiers QGuiApplication::keyboardModifiers()
*/
Qt::KeyboardModifiers QGuiApplication::queryKeyboardModifiers()
{
- CHECK_QAPP_INSTANCE(Qt::KeyboardModifiers(0))
+ CHECK_QAPP_INSTANCE(Qt::KeyboardModifiers{})
QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
return pi->queryKeyboardModifiers();
}
@@ -1803,7 +1803,7 @@ Qt::MouseButtons QGuiApplication::mouseButtons()
QPlatformNativeInterface *QGuiApplication::platformNativeInterface()
{
QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
- return pi ? pi->nativeInterface() : 0;
+ return pi ? pi->nativeInterface() : nullptr;
}
/*!
@@ -2154,7 +2154,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
window = currentMousePressWindow;
} else if (currentMousePressWindow) {
window = currentMousePressWindow;
- currentMousePressWindow = 0;
+ currentMousePressWindow = nullptr;
}
QPointF delta = globalPoint - globalPoint.toPoint();
localPoint = window->mapFromGlobal(globalPoint.toPoint()) + delta;
@@ -2367,7 +2367,7 @@ void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::Le
return;
}
- currentMouseWindow = 0;
+ currentMouseWindow = nullptr;
QEvent event(QEvent::Leave);
QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
@@ -2386,7 +2386,7 @@ void QGuiApplicationPrivate::processActivatedEvent(QWindowSystemInterfacePrivate
if (platformWindow->isAlertState())
platformWindow->setAlertState(false);
- QObject *previousFocusObject = previous ? previous->focusObject() : 0;
+ QObject *previousFocusObject = previous ? previous->focusObject() : nullptr;
if (previous) {
QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
@@ -2455,7 +2455,7 @@ void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterf
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(0);
+ topLevelWindow->setScreen(nullptr);
}
// we may have changed scaling, so trigger resize event if needed
if (window->handle()) {
@@ -2881,7 +2881,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
break;
}
- Q_ASSERT(w.data() != 0);
+ 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,
@@ -3257,12 +3257,12 @@ QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w, const QM
*/
QClipboard * QGuiApplication::clipboard()
{
- if (QGuiApplicationPrivate::qt_clipboard == 0) {
+ if (QGuiApplicationPrivate::qt_clipboard == nullptr) {
if (!qApp) {
qWarning("QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
- return 0;
+ return nullptr;
}
- QGuiApplicationPrivate::qt_clipboard = new QClipboard(0);
+ QGuiApplicationPrivate::qt_clipboard = new QClipboard(nullptr);
}
return QGuiApplicationPrivate::qt_clipboard;
}
@@ -3278,36 +3278,95 @@ QClipboard * QGuiApplication::clipboard()
*/
/*!
- Returns the default application palette.
+ Returns the current application palette.
+
+ Roles that have not been explicitly set will reflect the system's platform theme.
\sa setPalette()
*/
QPalette QGuiApplication::palette()
{
- initPalette();
+ if (!QGuiApplicationPrivate::app_pal)
+ QGuiApplicationPrivate::updatePalette();
+
return *QGuiApplicationPrivate::app_pal;
}
+void QGuiApplicationPrivate::updatePalette()
+{
+ if (app_pal) {
+ if (setPalette(*app_pal) && qGuiApp)
+ qGuiApp->d_func()->handlePaletteChanged();
+ } else {
+ setPalette(QPalette());
+ }
+}
+
+void QGuiApplicationPrivate::clearPalette()
+{
+ delete app_pal;
+ app_pal = nullptr;
+}
+
/*!
- Changes the default application palette to \a pal.
+ Changes the application palette to \a pal.
+
+ The color roles from this palette are combined with the system's platform
+ theme to form the application's final palette.
\sa palette()
*/
void QGuiApplication::setPalette(const QPalette &pal)
{
- if (QGuiApplicationPrivate::app_pal && pal.isCopyOf(*QGuiApplicationPrivate::app_pal))
- return;
- if (!QGuiApplicationPrivate::app_pal)
- QGuiApplicationPrivate::app_pal = new QPalette(pal);
+ if (QGuiApplicationPrivate::setPalette(pal) && qGuiApp)
+ qGuiApp->d_func()->handlePaletteChanged();
+}
+
+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
+ QPalette resolvedPalette = palette.resolve(basePalette);
+
+ if (app_pal && resolvedPalette == *app_pal && resolvedPalette.resolve() == app_pal->resolve())
+ return false;
+
+ if (!app_pal)
+ app_pal = new QPalette(resolvedPalette);
else
- *QGuiApplicationPrivate::app_pal = pal;
+ *app_pal = resolvedPalette;
+
+ QCoreApplication::setAttribute(Qt::AA_SetPalette, app_pal->resolve() != 0);
+
+ return true;
+}
- applicationResourceFlags |= ApplicationPaletteExplicitlySet;
- QCoreApplication::setAttribute(Qt::AA_SetPalette);
+/*
+ Returns the base palette used to fill in missing roles in
+ the current application palette.
+
+ Normally this is the theme palette, but QApplication
+ overrides this for compatibility reasons.
+*/
+QPalette QGuiApplicationPrivate::basePalette() const
+{
+ return platformTheme() ? *platformTheme()->palette() : Qt::gray;
+}
- if (qGuiApp)
+void QGuiApplicationPrivate::handlePaletteChanged(const char *className)
+{
+ if (!className) {
+ Q_ASSERT(app_pal);
emit qGuiApp->paletteChanged(*QGuiApplicationPrivate::app_pal);
+ }
+
+ if (is_app_running && !is_app_closing) {
+ QEvent event(QEvent::ApplicationPaletteChange);
+ QGuiApplication::sendEvent(qGuiApp, &event);
+ }
}
void QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(QWindow *window)
@@ -3558,7 +3617,9 @@ Qt::ApplicationState QGuiApplication::applicationState()
environment variable. The QGuiApplication::highDpiScaleFactorRoundingPolicy()
accessor will reflect the environment, if set.
- The default value is Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor.
+ 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.
*/
void QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy policy)
{
@@ -3883,7 +3944,7 @@ Qt::LayoutDirection QGuiApplication::layoutDirection()
QCursor *QGuiApplication::overrideCursor()
{
CHECK_QAPP_INSTANCE(nullptr)
- return qGuiApp->d_func()->cursor_list.isEmpty() ? 0 : &qGuiApp->d_func()->cursor_list.first();
+ return qGuiApp->d_func()->cursor_list.isEmpty() ? nullptr : &qGuiApp->d_func()->cursor_list.first();
}
/*!
@@ -3917,7 +3978,7 @@ static inline void unsetCursor(QWindow *w)
{
if (const QScreen *screen = w->screen())
if (QPlatformCursor *cursor = screen->handle()->cursor())
- cursor->changeCursor(0, w);
+ cursor->changeCursor(nullptr, w);
}
static inline void applyCursor(const QList<QWindow *> &l, const QCursor &c)
@@ -4106,14 +4167,8 @@ QPixmap QGuiApplicationPrivate::getPixmapCursor(Qt::CursorShape cshape)
void QGuiApplicationPrivate::notifyThemeChanged()
{
- if (!(applicationResourceFlags & ApplicationPaletteExplicitlySet) &&
- !QCoreApplication::testAttribute(Qt::AA_SetPalette)) {
- clearPalette();
- initPalette();
- emit qGuiApp->paletteChanged(*app_pal);
- if (is_app_running && !is_app_closing)
- sendApplicationPaletteChange();
- }
+ updatePalette();
+
if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
const auto locker = qt_scoped_lock(applicationFontMutex);
clearFontUnlocked();
@@ -4122,15 +4177,6 @@ void QGuiApplicationPrivate::notifyThemeChanged()
initThemeHints();
}
-void QGuiApplicationPrivate::sendApplicationPaletteChange(bool toAllWidgets, const char *className)
-{
- Q_UNUSED(toAllWidgets)
- Q_UNUSED(className)
-
- QEvent event(QEvent::ApplicationPaletteChange);
- QGuiApplication::sendEvent(QGuiApplication::instance(), &event);
-}
-
#if QT_CONFIG(draganddrop)
void QGuiApplicationPrivate::notifyDragStarted(const QDrag *drag)
{
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index 56a3be1122..dc2963aee7 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -119,7 +119,7 @@ public:
static QAbstractEventDispatcher *qt_qpa_core_dispatcher()
{
if (QCoreApplication::instance())
- return QCoreApplication::instance()->d_func()->threadData->eventDispatcher.loadRelaxed();
+ return QCoreApplication::instance()->d_func()->threadData.loadRelaxed()->eventDispatcher.loadRelaxed();
else
return nullptr;
}
@@ -328,13 +328,20 @@ public:
protected:
virtual void notifyThemeChanged();
- virtual void sendApplicationPaletteChange(bool toAllWidgets = false, const char *className = nullptr);
+
+ 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;
diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp
index 2d6d12cc21..0f29633222 100644
--- a/src/gui/kernel/qguivariant.cpp
+++ b/src/gui/kernel/qguivariant.cpp
@@ -105,13 +105,13 @@ static void construct(QVariant::Private *x, const void *copy)
{
const int type = x->type;
QVariantConstructor<GuiTypesFilter> constructor(x, copy);
- QMetaTypeSwitcher::switcher<void>(constructor, type, 0);
+ QMetaTypeSwitcher::switcher<void>(constructor, type, nullptr);
}
static void clear(QVariant::Private *d)
{
QVariantDestructor<GuiTypesFilter> destructor(d);
- QMetaTypeSwitcher::switcher<void>(destructor, d->type, 0);
+ QMetaTypeSwitcher::switcher<void>(destructor, d->type, nullptr);
}
// This class is a hack that customizes access to QPolygon and QPolygonF
@@ -131,7 +131,7 @@ public:
static bool isNull(const QVariant::Private *d)
{
QGuiVariantIsNull<GuiTypesFilter> isNull(d);
- return QMetaTypeSwitcher::switcher<bool>(isNull, d->type, 0);
+ return QMetaTypeSwitcher::switcher<bool>(isNull, d->type, nullptr);
}
// This class is a hack that customizes access to QPixmap, QBitmap, QCursor and QIcon
@@ -173,7 +173,7 @@ public:
static bool compare(const QVariant::Private *a, const QVariant::Private *b)
{
QGuiVariantComparator<GuiTypesFilter> comparator(a, b);
- return QMetaTypeSwitcher::switcher<bool>(comparator, a->type, 0);
+ return QMetaTypeSwitcher::switcher<bool>(comparator, a->type, nullptr);
}
static bool convert(const QVariant::Private *d, int t,
@@ -313,7 +313,7 @@ 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, 0);
+ QMetaTypeSwitcher::switcher<void>(stream, d->type, nullptr);
}
#endif
@@ -322,12 +322,12 @@ const QVariant::Handler qt_gui_variant_handler = {
clear,
isNull,
#ifndef QT_NO_DATASTREAM
- 0,
- 0,
+ nullptr,
+ nullptr,
#endif
compare,
convert,
- 0,
+ nullptr,
#if !defined(QT_NO_DEBUG_STREAM)
streamDebug
#else
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp
index 76548d5d86..fde6bb0180 100644
--- a/src/gui/kernel/qhighdpiscaling.cpp
+++ b/src/gui/kernel/qhighdpiscaling.cpp
@@ -56,6 +56,9 @@ Q_LOGGING_CATEGORY(lcScaling, "qt.scaling");
#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";
@@ -104,12 +107,6 @@ static inline qreal initialGlobalScaleFactor()
if (dpr > 0)
result = dpr;
}
-
- if (qEnvironmentVariableIsSet(legacyAutoScreenEnvVar)) {
- qWarning("Warning: %s is deprecated. Instead use:\n"
- " %s to enable platform plugin controlled per-screen factors.",
- legacyAutoScreenEnvVar, enableHighDpiScalingEnvVar);
- }
}
return result;
}
@@ -644,7 +641,7 @@ QPoint QHighDpiScaling::mapPositionFromGlobal(const QPoint &pos, const QPoint &w
qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen)
{
- qreal factor = qreal(1.0);
+ auto factor = qreal(1.0);
if (!screen)
return factor;
@@ -657,14 +654,16 @@ qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen)
// Check if there is a factor set on the screen object or associated
// with the screen name. These are mutually exclusive, so checking
// order is not significant.
- QVariant byIndex = screen->screen()->property(scaleFactorProperty);
- auto byNameIt = qNamedScreenScaleFactors()->constFind(screen->name());
- if (byIndex.isValid()) {
- screenPropertyUsed = true;
- factor = byIndex.toReal();
- } else if (byNameIt != qNamedScreenScaleFactors()->cend()) {
- screenPropertyUsed = true;
- factor = *byNameIt;
+ if (auto qScreen = screen->screen()) {
+ auto screenFactor = qScreen->property(scaleFactorProperty).toReal(&screenPropertyUsed);
+ if (screenPropertyUsed)
+ factor = screenFactor;
+ }
+
+ if (!screenPropertyUsed) {
+ auto byNameIt = qNamedScreenScaleFactors()->constFind(screen->name());
+ if ((screenPropertyUsed = byNameIt != qNamedScreenScaleFactors()->cend()))
+ factor = *byNameIt;
}
}
diff --git a/src/gui/kernel/qinputdevicemanager_p_p.h b/src/gui/kernel/qinputdevicemanager_p_p.h
index 871f9315c3..82a86446a0 100644
--- a/src/gui/kernel/qinputdevicemanager_p_p.h
+++ b/src/gui/kernel/qinputdevicemanager_p_p.h
@@ -69,7 +69,7 @@ public:
int deviceCount(QInputDeviceManager::DeviceType type) const;
void setDeviceCount(QInputDeviceManager::DeviceType type, int count);
- std::array<int, QInputDeviceManager::NumDeviceTypes> m_deviceCount;
+ std::array<int, QInputDeviceManager::NumDeviceTypes> m_deviceCount = {};
Qt::KeyboardModifiers keyboardModifiers;
};
diff --git a/src/gui/kernel/qkeymapper.cpp b/src/gui/kernel/qkeymapper.cpp
index 4893b1d57b..274574f561 100644
--- a/src/gui/kernel/qkeymapper.cpp
+++ b/src/gui/kernel/qkeymapper.cpp
@@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE
Constructs a new key mapper.
*/
QKeyMapper::QKeyMapper()
- : QObject(*new QKeyMapperPrivate, 0)
+ : QObject(*new QKeyMapperPrivate, nullptr)
{
}
diff --git a/src/gui/kernel/qoffscreensurface.cpp b/src/gui/kernel/qoffscreensurface.cpp
index 0cc11ca3bb..c74fe0b3a1 100644
--- a/src/gui/kernel/qoffscreensurface.cpp
+++ b/src/gui/kernel/qoffscreensurface.cpp
@@ -99,10 +99,10 @@ public:
QOffscreenSurfacePrivate()
: QObjectPrivate()
, surfaceType(QSurface::OpenGLSurface)
- , platformOffscreenSurface(0)
- , offscreenWindow(0)
+ , platformOffscreenSurface(nullptr)
+ , offscreenWindow(nullptr)
, requestedFormat(QSurfaceFormat::defaultFormat())
- , screen(0)
+ , screen(nullptr)
, size(1, 1)
, nativeHandle(nullptr)
{
@@ -235,11 +235,11 @@ void QOffscreenSurface::destroy()
QGuiApplication::sendEvent(this, &e);
delete d->platformOffscreenSurface;
- d->platformOffscreenSurface = 0;
+ d->platformOffscreenSurface = nullptr;
if (d->offscreenWindow) {
d->offscreenWindow->destroy();
delete d->offscreenWindow;
- d->offscreenWindow = 0;
+ d->offscreenWindow = nullptr;
}
d->nativeHandle = nullptr;
@@ -341,7 +341,7 @@ void QOffscreenSurface::setScreen(QScreen *newScreen)
if (!newScreen)
newScreen = QCoreApplication::instance() ? QGuiApplication::primaryScreen() : nullptr;
if (newScreen != d->screen) {
- const bool wasCreated = d->platformOffscreenSurface != 0 || d->offscreenWindow != 0;
+ const bool wasCreated = d->platformOffscreenSurface != nullptr || d->offscreenWindow != nullptr;
if (wasCreated)
destroy();
if (d->screen)
@@ -385,7 +385,7 @@ void QOffscreenSurface::screenDestroyed(QObject *object)
{
Q_D(QOffscreenSurface);
if (object == static_cast<QObject *>(d->screen))
- setScreen(0);
+ setScreen(nullptr);
}
/*!
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp
index 638eb1d12f..ab71434c13 100644
--- a/src/gui/kernel/qopenglcontext.cpp
+++ b/src/gui/kernel/qopenglcontext.cpp
@@ -56,8 +56,6 @@
#include <private/qopenglextensions_p.h>
#include <private/qopenglversionfunctionsfactory_p.h>
-#include <private/qopengltexturehelper_p.h>
-
#include <QDebug>
#ifndef QT_OPENGL_ES_2
@@ -223,7 +221,7 @@ class QGuiGLThreadContext
{
public:
QGuiGLThreadContext()
- : context(0)
+ : context(nullptr)
{
}
~QGuiGLThreadContext() {
@@ -234,7 +232,7 @@ public:
};
Q_GLOBAL_STATIC(QThreadStorage<QGuiGLThreadContext *>, qwindow_context_storage);
-static QOpenGLContext *global_share_context = 0;
+static QOpenGLContext *global_share_context = nullptr;
#ifndef QT_NO_DEBUG
QHash<QOpenGLContext *, bool> QOpenGLContextPrivate::makeCurrentTracker;
@@ -347,7 +345,7 @@ QOpenGLContext *QOpenGLContextPrivate::setCurrentContext(QOpenGLContext *context
if (!threadContext) {
if (!QThread::currentThread()) {
qWarning("No QTLS available. currentContext won't work");
- return 0;
+ return nullptr;
}
threadContext = new QGuiGLThreadContext;
qwindow_context_storage()->setLocalData(threadContext);
@@ -372,10 +370,10 @@ int QOpenGLContextPrivate::maxTextureSize()
GLint size;
GLint next = 64;
- funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+ funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
- QOpenGLFunctions_1_0 *gl1funcs = 0;
- QOpenGLFunctions_3_2_Core *gl3funcs = 0;
+ QOpenGLFunctions_1_0 *gl1funcs = nullptr;
+ QOpenGLFunctions_3_2_Core *gl3funcs = nullptr;
if (q->format().profile() == QSurfaceFormat::CoreProfile)
gl3funcs = q->versionFunctions<QOpenGLFunctions_3_2_Core>();
@@ -398,7 +396,7 @@ int QOpenGLContextPrivate::maxTextureSize()
if (next > max_texture_size)
break;
- funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+ funcs->glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
if (gl1funcs)
gl1funcs->glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &next);
else
@@ -455,7 +453,7 @@ QPlatformOpenGLContext *QOpenGLContext::shareHandle() const
Q_D(const QOpenGLContext);
if (d->shareContext)
return d->shareContext->handle();
- return 0;
+ return nullptr;
}
/*!
@@ -517,8 +515,8 @@ void QOpenGLContextPrivate::_q_screenDestroyed(QObject *object)
{
Q_Q(QOpenGLContext);
if (object == static_cast<QObject *>(screen)) {
- screen = 0;
- q->setScreen(0);
+ screen = nullptr;
+ q->setScreen(nullptr);
}
}
@@ -615,7 +613,7 @@ bool QOpenGLContext::create()
d->platformGLContext->setContext(this);
d->platformGLContext->initialize();
if (!d->platformGLContext->isSharing())
- d->shareContext = 0;
+ d->shareContext = nullptr;
d->shareGroup = d->shareContext ? d->shareContext->shareGroup() : new QOpenGLContextGroup;
d->shareGroup->d_func()->addContext(this);
return isValid();
@@ -649,23 +647,26 @@ void QOpenGLContext::destroy()
doneCurrent();
if (d->shareGroup)
d->shareGroup->d_func()->removeContext(this);
- d->shareGroup = 0;
+ d->shareGroup = nullptr;
delete d->platformGLContext;
- d->platformGLContext = 0;
+ d->platformGLContext = nullptr;
delete d->functions;
- d->functions = 0;
+ d->functions = nullptr;
for (QAbstractOpenGLFunctions *func : qAsConst(d->externalVersionFunctions)) {
QAbstractOpenGLFunctionsPrivate *func_d = QAbstractOpenGLFunctionsPrivate::get(func);
- func_d->owningContext = 0;
+ func_d->owningContext = nullptr;
func_d->initialized = false;
}
d->externalVersionFunctions.clear();
qDeleteAll(d->versionFunctions);
d->versionFunctions.clear();
- delete d->textureFunctions;
- d->textureFunctions = 0;
+ if (d->textureFunctionsDestroyCallback) {
+ d->textureFunctionsDestroyCallback();
+ d->textureFunctionsDestroyCallback = nullptr;
+ }
+ d->textureFunctions = nullptr;
d->nativeHandle = QVariant();
}
@@ -823,7 +824,7 @@ QAbstractOpenGLFunctions *QOpenGLContext::versionFunctions(const QOpenGLVersionP
#ifndef QT_OPENGL_ES_2
if (isOpenGLES()) {
qWarning("versionFunctions: Not supported on OpenGL ES");
- return 0;
+ return nullptr;
}
#endif // QT_OPENGL_ES_2
@@ -838,16 +839,16 @@ QAbstractOpenGLFunctions *QOpenGLContext::versionFunctions(const QOpenGLVersionP
// Check that context is compatible with requested version
const QPair<int, int> v = qMakePair(f.majorVersion(), f.minorVersion());
if (v < vp.version())
- return 0;
+ return nullptr;
// If this context only offers core profile functions then we can't create
// function objects for legacy or compatibility profile requests
if (((vp.hasProfiles() && vp.profile() != QSurfaceFormat::CoreProfile) || vp.isLegacyVersion())
&& f.profile() == QSurfaceFormat::CoreProfile)
- return 0;
+ return nullptr;
// Create object if suitable one not cached
- QAbstractOpenGLFunctions* funcs = 0;
+ QAbstractOpenGLFunctions* funcs = nullptr;
auto it = d->versionFunctions.constFind(vp);
if (it == d->versionFunctions.constEnd()) {
funcs = QOpenGLVersionFunctionsFactory::create(vp);
@@ -1022,7 +1023,7 @@ bool QOpenGLContext::makeCurrent(QSurface *surface)
|| qstrncmp(rendererString, "Adreno 6xx", 8) == 0 // Same as above but without the '(TM)'
|| qstrcmp(rendererString, "GC800 core") == 0
|| qstrcmp(rendererString, "GC1000 core") == 0
- || strstr(rendererString, "GC2000") != 0
+ || strstr(rendererString, "GC2000") != nullptr
|| qstrcmp(rendererString, "Immersion.16") == 0;
}
needsWorkaroundSet = true;
@@ -1053,9 +1054,9 @@ void QOpenGLContext::doneCurrent()
d->shareGroup->d_func()->deletePendingResources(this);
d->platformGLContext->doneCurrent();
- QOpenGLContextPrivate::setCurrentContext(0);
+ QOpenGLContextPrivate::setCurrentContext(nullptr);
- d->surface = 0;
+ d->surface = nullptr;
}
/*!
@@ -1224,8 +1225,8 @@ void QOpenGLContext::deleteQGLContext()
Q_D(QOpenGLContext);
if (d->qGLContextDeleteFunction && d->qGLContextHandle) {
d->qGLContextDeleteFunction(d->qGLContextHandle);
- d->qGLContextDeleteFunction = 0;
- d->qGLContextHandle = 0;
+ d->qGLContextDeleteFunction = nullptr;
+ d->qGLContextHandle = nullptr;
}
}
@@ -1252,7 +1253,7 @@ void *QOpenGLContext::openGLModuleHandle()
Q_ASSERT(ni);
return ni->nativeResourceForIntegration(QByteArrayLiteral("glhandle"));
#else
- return 0;
+ return nullptr;
#endif
}
@@ -1388,10 +1389,11 @@ QOpenGLTextureHelper* QOpenGLContext::textureFunctions() const
/*!
\internal
*/
-void QOpenGLContext::setTextureFunctions(QOpenGLTextureHelper* textureFuncs)
+void QOpenGLContext::setTextureFunctions(QOpenGLTextureHelper* textureFuncs, std::function<void()> destroyCallback)
{
Q_D(QOpenGLContext);
d->textureFunctions = textureFuncs;
+ d->textureFunctionsDestroyCallback = destroyCallback;
}
/*!
@@ -1438,7 +1440,7 @@ QList<QOpenGLContext *> QOpenGLContextGroup::shares() const
QOpenGLContextGroup *QOpenGLContextGroup::currentContextGroup()
{
QOpenGLContext *current = QOpenGLContext::currentContext();
- return current ? current->shareGroup() : 0;
+ return current ? current->shareGroup() : nullptr;
}
void QOpenGLContextGroupPrivate::addContext(QOpenGLContext *ctx)
@@ -1491,7 +1493,7 @@ void QOpenGLContextGroupPrivate::cleanup()
while (it != end) {
(*it)->invalidateResource();
- (*it)->m_group = 0;
+ (*it)->m_group = nullptr;
++it;
}
diff --git a/src/gui/kernel/qopenglcontext.h b/src/gui/kernel/qopenglcontext.h
index 9cfaa52f17..f19dde465a 100644
--- a/src/gui/kernel/qopenglcontext.h
+++ b/src/gui/kernel/qopenglcontext.h
@@ -243,7 +243,7 @@ private:
void removeExternalFunctions(QAbstractOpenGLFunctions *f);
QOpenGLTextureHelper* textureFunctions() const;
- void setTextureFunctions(QOpenGLTextureHelper* textureFuncs);
+ void setTextureFunctions(QOpenGLTextureHelper* textureFuncs, std::function<void()> destroyCallback);
void destroy();
diff --git a/src/gui/kernel/qopenglcontext_p.h b/src/gui/kernel/qopenglcontext_p.h
index 833cfb20c3..7770b1ce02 100644
--- a/src/gui/kernel/qopenglcontext_p.h
+++ b/src/gui/kernel/qopenglcontext_p.h
@@ -240,6 +240,7 @@ public:
QOpenGLFunctions *functions;
mutable QSet<QByteArray> extensionNames;
QOpenGLTextureHelper* textureFunctions;
+ std::function<void()> textureFunctionsDestroyCallback;
GLint max_texture_size;
diff --git a/src/gui/kernel/qopenglwindow.cpp b/src/gui/kernel/qopenglwindow.cpp
deleted file mode 100644
index 022a47c919..0000000000
--- a/src/gui/kernel/qopenglwindow.cpp
+++ /dev/null
@@ -1,698 +0,0 @@
-/****************************************************************************
-**
-** 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 "qopenglwindow.h"
-#include "qpaintdevicewindow_p.h"
-#include <QtGui/QOpenGLFramebufferObject>
-#include <QtGui/QOpenGLPaintDevice>
-#include <QtGui/QOpenGLFunctions>
-#include <QtGui/QOpenGLTextureBlitter>
-#include <QtGui/private/qopenglextensions_p.h>
-#include <QtGui/private/qopenglcontext_p.h>
-#include <QtGui/QMatrix4x4>
-#include <QtGui/QOffscreenSurface>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QOpenGLWindow
- \inmodule QtGui
- \since 5.4
- \brief The QOpenGLWindow class is a convenience subclass of QWindow to perform OpenGL painting.
-
- QOpenGLWindow is an enhanced QWindow that allows easily creating windows that
- perform OpenGL rendering using an API that is compatible with QOpenGLWidget
- and is similar to the legacy QGLWidget. Unlike QOpenGLWidget, QOpenGLWindow
- has no dependency on the widgets module and offers better performance.
-
- A typical application will subclass QOpenGLWindow and reimplement the following
- virtual functions:
-
- \list
-
- \li initializeGL() to perform OpenGL resource initialization
-
- \li resizeGL() to set up the transformation matrices and other window size dependent resources
-
- \li paintGL() to issue OpenGL commands or draw using QPainter
-
- \endlist
-
- To schedule a repaint, call the update() function. Note that this will not
- immediately result in a call to paintGL(). Calling update() multiple times in
- a row will not change the behavior in any way.
-
- This is a slot so it can be connected to a \l QTimer::timeout() signal to
- perform animation. Note however that in the modern OpenGL world it is a much
- better choice to rely on synchronization to the vertical refresh rate of the
- display. See \l{QSurfaceFormat::setSwapInterval()}{setSwapInterval()} on a
- description of the swap interval. With a swap interval of \c 1, which is the
- case on most systems by default, the
- \l{QOpenGLContext::swapBuffers()}{swapBuffers()} call, that is executed
- internally by QOpenGLWindow after each repaint, will block and wait for
- vsync. This means that whenever the swap is done, an update can be scheduled
- again by calling update(), without relying on timers.
-
- To request a specific configuration for the context, use setFormat()
- like for any other QWindow. This allows, among others, requesting a
- given OpenGL version and profile, or enabling depth and stencil
- buffers.
-
- Unlike QWindow, QOpenGLWindow allows opening a painter on itself and perform
- QPainter-based drawing.
-
- QOpenGLWindow supports multiple update behaviors. The default,
- \c NoPartialUpdate is equivalent to a regular, OpenGL-based QWindow or the
- legacy QGLWidget. In contrast, \c PartialUpdateBlit and \c PartialUpdateBlend are
- more in line with QOpenGLWidget's way of working, where there is always an
- extra, dedicated framebuffer object present. These modes allow, by
- sacrificing some performance, redrawing only a smaller area on each paint and
- having the rest of the content preserved from of the previous frame. This is
- useful for applications than render incrementally using QPainter, because
- this way they do not have to redraw the entire window content on each
- paintGL() call.
-
- Similarly to QOpenGLWidget, QOpenGLWindow supports the Qt::AA_ShareOpenGLContexts
- attribute. When enabled, the OpenGL contexts of all QOpenGLWindow instances will share
- with each other. This allows accessing each other's shareable OpenGL resources.
-
- For more information on graphics in Qt, see \l {Graphics}.
- */
-
-/*!
- \enum QOpenGLWindow::UpdateBehavior
-
- This enum describes the update strategy of the QOpenGLWindow.
-
- \value NoPartialUpdate Indicates that the entire window surface will
- redrawn on each update and so no additional framebuffers are needed.
- This is the setting used in most cases and is equivalent to how drawing
- directly via QWindow would function.
-
- \value PartialUpdateBlit Indicates that the drawing performed in paintGL()
- does not cover the entire window. In this case an extra framebuffer object
- is created under the hood, and rendering performed in paintGL() will target
- this framebuffer. This framebuffer is then blitted onto the window surface's
- default framebuffer after each paint. This allows having QPainter-based drawing
- code in paintGL() which only repaints a smaller area at a time, because, unlike
- NoPartialUpdate, the previous content is preserved.
-
- \value PartialUpdateBlend Similar to PartialUpdateBlit, but instead of using
- framebuffer blits, the contents of the extra framebuffer is rendered by
- drawing a textured quad with blending enabled. This, unlike PartialUpdateBlit,
- allows alpha blended content and works even when the glBlitFramebuffer is
- not available. Performance-wise this setting is likely to be somewhat slower
- than PartialUpdateBlit.
- */
-
-/*!
- \fn void QOpenGLWindow::frameSwapped()
-
- This signal is emitted after the potentially blocking
- \l{QOpenGLContext::swapBuffers()}{buffer swap} has been done. Applications
- that wish to continuously repaint synchronized to the vertical refresh,
- should issue an update() upon this signal. This allows for a much smoother
- experience compared to the traditional usage of timers.
-*/
-
-// GLES2 builds won't have these constants with the suffixless names
-#ifndef GL_READ_FRAMEBUFFER
-#define GL_READ_FRAMEBUFFER 0x8CA8
-#endif
-#ifndef GL_DRAW_FRAMEBUFFER
-#define GL_DRAW_FRAMEBUFFER 0x8CA9
-#endif
-
-class QOpenGLWindowPaintDevice : public QOpenGLPaintDevice
-{
-public:
- QOpenGLWindowPaintDevice(QOpenGLWindow *window) : m_window(window) { }
- void ensureActiveTarget() override;
-
- QOpenGLWindow *m_window;
-};
-
-class QOpenGLWindowPrivate : public QPaintDeviceWindowPrivate
-{
- Q_DECLARE_PUBLIC(QOpenGLWindow)
-public:
- QOpenGLWindowPrivate(QOpenGLContext *shareContext, QOpenGLWindow::UpdateBehavior updateBehavior)
- : updateBehavior(updateBehavior)
- , hasFboBlit(false)
- , shareContext(shareContext)
- {
- if (!shareContext)
- this->shareContext = qt_gl_global_share_context();
- }
-
- ~QOpenGLWindowPrivate();
-
- static QOpenGLWindowPrivate *get(QOpenGLWindow *w) { return w->d_func(); }
-
- void bindFBO();
- void initialize();
-
- void beginPaint(const QRegion &region) override;
- void endPaint() override;
- void flush(const QRegion &region) override;
-
- QOpenGLWindow::UpdateBehavior updateBehavior;
- bool hasFboBlit;
- QScopedPointer<QOpenGLContext> context;
- QOpenGLContext *shareContext;
- QScopedPointer<QOpenGLFramebufferObject> fbo;
- QScopedPointer<QOpenGLWindowPaintDevice> paintDevice;
- QOpenGLTextureBlitter blitter;
- QColor backgroundColor;
- QScopedPointer<QOffscreenSurface> offscreenSurface;
-};
-
-QOpenGLWindowPrivate::~QOpenGLWindowPrivate()
-{
- Q_Q(QOpenGLWindow);
- if (q->isValid()) {
- q->makeCurrent(); // this works even when the platformwindow is destroyed
- paintDevice.reset(0);
- fbo.reset(0);
- blitter.destroy();
- q->doneCurrent();
- }
-}
-
-void QOpenGLWindowPrivate::initialize()
-{
- Q_Q(QOpenGLWindow);
-
- if (context)
- return;
-
- if (!q->handle())
- qWarning("Attempted to initialize QOpenGLWindow without a platform window");
-
- context.reset(new QOpenGLContext);
- context->setShareContext(shareContext);
- context->setFormat(q->requestedFormat());
- if (!context->create())
- qWarning("QOpenGLWindow::beginPaint: Failed to create context");
- if (!context->makeCurrent(q))
- qWarning("QOpenGLWindow::beginPaint: Failed to make context current");
-
- paintDevice.reset(new QOpenGLWindowPaintDevice(q));
- if (updateBehavior == QOpenGLWindow::PartialUpdateBlit)
- hasFboBlit = QOpenGLFramebufferObject::hasOpenGLFramebufferBlit();
-
- q->initializeGL();
-}
-
-void QOpenGLWindowPrivate::beginPaint(const QRegion &region)
-{
- Q_UNUSED(region);
- Q_Q(QOpenGLWindow);
-
- initialize();
- context->makeCurrent(q);
-
- const int deviceWidth = q->width() * q->devicePixelRatio();
- const int deviceHeight = q->height() * q->devicePixelRatio();
- const QSize deviceSize(deviceWidth, deviceHeight);
- if (updateBehavior > QOpenGLWindow::NoPartialUpdate) {
- if (!fbo || fbo->size() != deviceSize) {
- QOpenGLFramebufferObjectFormat fboFormat;
- fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
- const int samples = q->requestedFormat().samples();
- if (samples > 0) {
- if (updateBehavior != QOpenGLWindow::PartialUpdateBlend)
- fboFormat.setSamples(samples);
- else
- qWarning("QOpenGLWindow: PartialUpdateBlend does not support multisampling");
- }
- fbo.reset(new QOpenGLFramebufferObject(deviceSize, fboFormat));
- markWindowAsDirty();
- }
- } else {
- markWindowAsDirty();
- }
-
- paintDevice->setSize(QSize(deviceWidth, deviceHeight));
- paintDevice->setDevicePixelRatio(q->devicePixelRatio());
- context->functions()->glViewport(0, 0, deviceWidth, deviceHeight);
-
- context->functions()->glBindFramebuffer(GL_FRAMEBUFFER, context->defaultFramebufferObject());
-
- q->paintUnderGL();
-
- if (updateBehavior > QOpenGLWindow::NoPartialUpdate)
- fbo->bind();
-}
-
-void QOpenGLWindowPrivate::endPaint()
-{
- Q_Q(QOpenGLWindow);
-
- if (updateBehavior > QOpenGLWindow::NoPartialUpdate)
- fbo->release();
-
- context->functions()->glBindFramebuffer(GL_FRAMEBUFFER, context->defaultFramebufferObject());
-
- if (updateBehavior == QOpenGLWindow::PartialUpdateBlit && hasFboBlit) {
- const int deviceWidth = q->width() * q->devicePixelRatio();
- const int deviceHeight = q->height() * q->devicePixelRatio();
- QOpenGLExtensions extensions(context.data());
- extensions.glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo->handle());
- extensions.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, context->defaultFramebufferObject());
- extensions.glBlitFramebuffer(0, 0, deviceWidth, deviceHeight,
- 0, 0, deviceWidth, deviceHeight,
- GL_COLOR_BUFFER_BIT, GL_NEAREST);
- } else if (updateBehavior > QOpenGLWindow::NoPartialUpdate) {
- if (updateBehavior == QOpenGLWindow::PartialUpdateBlend) {
- context->functions()->glEnable(GL_BLEND);
- context->functions()->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
- if (!blitter.isCreated())
- blitter.create();
-
- QRect windowRect(QPoint(0, 0), fbo->size());
- QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(windowRect, windowRect);
- blitter.bind();
- blitter.blit(fbo->texture(), target, QOpenGLTextureBlitter::OriginBottomLeft);
- blitter.release();
-
- if (updateBehavior == QOpenGLWindow::PartialUpdateBlend)
- context->functions()->glDisable(GL_BLEND);
- }
-
- q->paintOverGL();
-}
-
-void QOpenGLWindowPrivate::bindFBO()
-{
- if (updateBehavior > QOpenGLWindow::NoPartialUpdate)
- fbo->bind();
- else
- QOpenGLFramebufferObject::bindDefault();
-}
-
-void QOpenGLWindowPrivate::flush(const QRegion &region)
-{
- Q_UNUSED(region);
- Q_Q(QOpenGLWindow);
- context->swapBuffers(q);
- emit q->frameSwapped();
-}
-
-void QOpenGLWindowPaintDevice::ensureActiveTarget()
-{
- QOpenGLWindowPrivate::get(m_window)->bindFBO();
-}
-
-/*!
- Constructs a new QOpenGLWindow with the given \a parent and \a updateBehavior.
-
- \sa QOpenGLWindow::UpdateBehavior
- */
-QOpenGLWindow::QOpenGLWindow(QOpenGLWindow::UpdateBehavior updateBehavior, QWindow *parent)
- : QPaintDeviceWindow(*(new QOpenGLWindowPrivate(nullptr, updateBehavior)), parent)
-{
- setSurfaceType(QSurface::OpenGLSurface);
-}
-
-/*!
- Constructs a new QOpenGLWindow with the given \a parent and \a updateBehavior. The QOpenGLWindow's context will share with \a shareContext.
-
- \sa QOpenGLWindow::UpdateBehavior shareContext
-*/
-QOpenGLWindow::QOpenGLWindow(QOpenGLContext *shareContext, UpdateBehavior updateBehavior, QWindow *parent)
- : QPaintDeviceWindow(*(new QOpenGLWindowPrivate(shareContext, updateBehavior)), parent)
-{
- setSurfaceType(QSurface::OpenGLSurface);
-}
-
-/*!
- Destroys the QOpenGLWindow instance, freeing its resources.
-
- The OpenGLWindow's context is made current in the destructor, allowing for
- safe destruction of any child object that may need to release OpenGL
- resources belonging to the context provided by this window.
-
- \warning if you have objects wrapping OpenGL resources (such as
- QOpenGLBuffer, QOpenGLShaderProgram, etc.) as members of a QOpenGLWindow
- subclass, you may need to add a call to makeCurrent() in that subclass'
- destructor as well. Due to the rules of C++ object destruction, those objects
- will be destroyed \e{before} calling this function (but after that the
- destructor of the subclass has run), therefore making the OpenGL context
- current in this function happens too late for their safe disposal.
-
- \sa makeCurrent
-
- \since 5.5
-*/
-QOpenGLWindow::~QOpenGLWindow()
-{
- makeCurrent();
-}
-
-/*!
- \return the update behavior for this QOpenGLWindow.
-*/
-QOpenGLWindow::UpdateBehavior QOpenGLWindow::updateBehavior() const
-{
- Q_D(const QOpenGLWindow);
- return d->updateBehavior;
-}
-
-/*!
- \return \c true if the window's OpenGL resources, like the context, have
- been successfully initialized. Note that the return value is always \c false
- until the window becomes exposed (shown).
-*/
-bool QOpenGLWindow::isValid() const
-{
- Q_D(const QOpenGLWindow);
- return d->context && d->context->isValid();
-}
-
-/*!
- Prepares for rendering OpenGL content for this window by making the
- corresponding context current and binding the framebuffer object, if there is
- one, in that context context.
-
- It is not necessary to call this function in most cases, because it is called
- automatically before invoking paintGL(). It is provided nonetheless to support
- advanced, multi-threaded scenarios where a thread different than the GUI or main
- thread may want to update the surface or framebuffer contents. See QOpenGLContext
- for more information on threading related issues.
-
- This function is suitable for calling also when the underlying platform window
- is already destroyed. This means that it is safe to call this function from
- a QOpenGLWindow subclass' destructor. If there is no native window anymore,
- an offscreen surface is used instead. This ensures that OpenGL resource
- cleanup operations in the destructor will always work, as long as
- this function is called first.
-
- \sa QOpenGLContext, context(), paintGL(), doneCurrent()
- */
-void QOpenGLWindow::makeCurrent()
-{
- Q_D(QOpenGLWindow);
-
- if (!isValid())
- return;
-
- // The platform window may be destroyed at this stage and therefore
- // makeCurrent() may not safely be called with 'this'.
- if (handle()) {
- d->context->makeCurrent(this);
- } else {
- if (!d->offscreenSurface) {
- d->offscreenSurface.reset(new QOffscreenSurface(screen()));
- d->offscreenSurface->setFormat(d->context->format());
- d->offscreenSurface->create();
- }
- d->context->makeCurrent(d->offscreenSurface.data());
- }
-
- d->bindFBO();
-}
-
-/*!
- Releases the context.
-
- It is not necessary to call this function in most cases, since the widget
- will make sure the context is bound and released properly when invoking
- paintGL().
-
- \sa makeCurrent()
- */
-void QOpenGLWindow::doneCurrent()
-{
- Q_D(QOpenGLWindow);
-
- if (!isValid())
- return;
-
- d->context->doneCurrent();
-}
-
-/*!
- \return The QOpenGLContext used by this window or \c 0 if not yet initialized.
- */
-QOpenGLContext *QOpenGLWindow::context() const
-{
- Q_D(const QOpenGLWindow);
- return d->context.data();
-}
-
-/*!
- \return The QOpenGLContext requested to be shared with this window's QOpenGLContext.
-*/
-QOpenGLContext *QOpenGLWindow::shareContext() const
-{
- Q_D(const QOpenGLWindow);
- return d->shareContext;
-}
-
-/*!
- The framebuffer object handle used by this window.
-
- When the update behavior is set to \c NoPartialUpdate, there is no separate
- framebuffer object. In this case the returned value is the ID of the
- default framebuffer.
-
- Otherwise the value of the ID of the framebuffer object or \c 0 if not
- yet initialized.
- */
-GLuint QOpenGLWindow::defaultFramebufferObject() const
-{
- Q_D(const QOpenGLWindow);
- if (d->updateBehavior > NoPartialUpdate && d->fbo)
- return d->fbo->handle();
- else if (QOpenGLContext *ctx = QOpenGLContext::currentContext())
- return ctx->defaultFramebufferObject();
- else
- return 0;
-}
-
-extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha);
-
-/*!
- Returns a copy of the framebuffer.
-
- \note This is a potentially expensive operation because it relies on
- glReadPixels() to read back the pixels. This may be slow and can stall the
- GPU pipeline.
-
- \note When used together with update behavior \c NoPartialUpdate, the returned
- image may not contain the desired content when called after the front and back
- buffers have been swapped (unless preserved swap is enabled in the underlying
- windowing system interface). In this mode the function reads from the back
- buffer and the contents of that may not match the content on the screen (the
- front buffer). In this case the only place where this function can safely be
- used is paintGL() or paintOverGL().
- */
-QImage QOpenGLWindow::grabFramebuffer()
-{
- if (!isValid())
- return QImage();
-
- makeCurrent();
-
- const bool hasAlpha = format().hasAlpha();
- QImage img = qt_gl_read_framebuffer(size() * devicePixelRatio(), hasAlpha, hasAlpha);
- img.setDevicePixelRatio(devicePixelRatio());
- return img;
-}
-
-/*!
- This virtual function is called once before the first call to paintGL() or
- resizeGL(). Reimplement it in a subclass.
-
- This function should set up any required OpenGL resources and state.
-
- There is no need to call makeCurrent() because this has already been done
- when this function is called. Note however that the framebuffer, in case
- partial update mode is used, is not yet available at this stage, so avoid
- issuing draw calls from here. Defer such calls to paintGL() instead.
-
- \sa paintGL(), resizeGL()
- */
-void QOpenGLWindow::initializeGL()
-{
-}
-
-/*!
- This virtual function is called whenever the widget has been resized.
- Reimplement it in a subclass. The new size is passed in \a w and \a h.
-
- \note This is merely a convenience function in order to provide an API that is
- compatible with QOpenGLWidget. Unlike with QOpenGLWidget, derived classes are
- free to choose to override resizeEvent() instead of this function.
-
- \note Avoid issuing OpenGL commands from this function as there may not be a
- context current when it is invoked. If it cannot be avoided, call makeCurrent().
-
- \note Scheduling updates from here is not necessary. The windowing systems
- will send expose events that trigger an update automatically.
-
- \sa initializeGL(), paintGL()
- */
-void QOpenGLWindow::resizeGL(int w, int h)
-{
- Q_UNUSED(w);
- Q_UNUSED(h);
-}
-
-/*!
- This virtual function is called whenever the window contents needs to be
- painted. Reimplement it in a subclass.
-
- There is no need to call makeCurrent() because this has already
- been done when this function is called.
-
- Before invoking this function, the context and the framebuffer, if there is
- one, are bound, and the viewport is set up by a call to glViewport(). No
- other state is set and no clearing or drawing is performed by the framework.
-
- \note When using a partial update behavior, like \c PartialUpdateBlend, the
- output of the previous paintGL() call is preserved and, after the additional
- drawing perfomed in the current invocation of the function, the content is
- blitted or blended over the content drawn directly to the window in
- paintUnderGL().
-
- \sa initializeGL(), resizeGL(), paintUnderGL(), paintOverGL(), UpdateBehavior
- */
-void QOpenGLWindow::paintGL()
-{
-}
-
-/*!
- The virtual function is called before each invocation of paintGL().
-
- When the update mode is set to \c NoPartialUpdate, there is no difference
- between this function and paintGL(), performing rendering in either of them
- leads to the same result.
-
- The difference becomes significant when using \c PartialUpdateBlend, where an
- extra framebuffer object is used. There, paintGL() targets this additional
- framebuffer object, which preserves its contents, while paintUnderGL() and
- paintOverGL() target the default framebuffer, i.e. directly the window
- surface, the contents of which is lost after each displayed frame.
-
- \note Avoid relying on this function when the update behavior is
- \c PartialUpdateBlit. This mode involves blitting the extra framebuffer used by
- paintGL() onto the default framebuffer after each invocation of paintGL(),
- thus overwriting all drawing generated in this function.
-
- \sa paintGL(), paintOverGL(), UpdateBehavior
- */
-void QOpenGLWindow::paintUnderGL()
-{
-}
-
-/*!
- This virtual function is called after each invocation of paintGL().
-
- When the update mode is set to NoPartialUpdate, there is no difference
- between this function and paintGL(), performing rendering in either of them
- leads to the same result.
-
- Like paintUnderGL(), rendering in this function targets the default
- framebuffer of the window, regardless of the update behavior. It gets called
- after paintGL() has returned and the blit (PartialUpdateBlit) or quad drawing
- (PartialUpdateBlend) has been done.
-
- \sa paintGL(), paintUnderGL(), UpdateBehavior
- */
-void QOpenGLWindow::paintOverGL()
-{
-}
-
-/*!
- Paint \a event handler. Calls paintGL().
-
- \sa paintGL()
- */
-void QOpenGLWindow::paintEvent(QPaintEvent *event)
-{
- Q_UNUSED(event);
- paintGL();
-}
-
-/*!
- Resize \a event handler. Calls resizeGL().
-
- \sa resizeGL()
- */
-void QOpenGLWindow::resizeEvent(QResizeEvent *event)
-{
- Q_UNUSED(event);
- Q_D(QOpenGLWindow);
- d->initialize();
- resizeGL(width(), height());
-}
-
-/*!
- \internal
- */
-int QOpenGLWindow::metric(PaintDeviceMetric metric) const
-{
- Q_D(const QOpenGLWindow);
-
- switch (metric) {
- case PdmDepth:
- if (d->paintDevice)
- return d->paintDevice->depth();
- break;
- default:
- break;
- }
- return QPaintDeviceWindow::metric(metric);
-}
-
-/*!
- \internal
- */
-QPaintDevice *QOpenGLWindow::redirected(QPoint *) const
-{
- Q_D(const QOpenGLWindow);
- if (QOpenGLContext::currentContext() == d->context.data())
- return d->paintDevice.data();
- return 0;
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qopenglwindow.h b/src/gui/kernel/qopenglwindow.h
deleted file mode 100644
index 7b3bf004a3..0000000000
--- a/src/gui/kernel/qopenglwindow.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#ifndef QOPENGLWINDOW_H
-#define QOPENGLWINDOW_H
-
-#include <QtGui/qtguiglobal.h>
-
-#ifndef QT_NO_OPENGL
-
-#include <QtGui/QPaintDeviceWindow>
-#include <QtGui/QOpenGLContext>
-#include <QtGui/QImage>
-
-QT_BEGIN_NAMESPACE
-
-class QOpenGLWindowPrivate;
-
-class Q_GUI_EXPORT QOpenGLWindow : public QPaintDeviceWindow
-{
- Q_OBJECT
- Q_DECLARE_PRIVATE(QOpenGLWindow)
-
-public:
- enum UpdateBehavior {
- NoPartialUpdate,
- PartialUpdateBlit,
- PartialUpdateBlend
- };
-
- explicit QOpenGLWindow(UpdateBehavior updateBehavior = NoPartialUpdate, QWindow *parent = nullptr);
- explicit QOpenGLWindow(QOpenGLContext *shareContext, UpdateBehavior updateBehavior = NoPartialUpdate, QWindow *parent = nullptr);
- ~QOpenGLWindow();
-
- UpdateBehavior updateBehavior() const;
- bool isValid() const;
-
- void makeCurrent();
- void doneCurrent();
-
- QOpenGLContext *context() const;
- QOpenGLContext *shareContext() const;
-
- GLuint defaultFramebufferObject() const;
-
- QImage grabFramebuffer();
-
-Q_SIGNALS:
- void frameSwapped();
-
-protected:
- virtual void initializeGL();
- virtual void resizeGL(int w, int h);
- virtual void paintGL();
- virtual void paintUnderGL();
- virtual void paintOverGL();
-
- void paintEvent(QPaintEvent *event) override;
- void resizeEvent(QResizeEvent *event) override;
- int metric(PaintDeviceMetric metric) const override;
- QPaintDevice *redirected(QPoint *) const override;
-
-private:
- Q_DISABLE_COPY(QOpenGLWindow)
-};
-
-QT_END_NAMESPACE
-
-#endif // QT_NO_OPENGL
-
-#endif
diff --git a/src/gui/kernel/qpaintdevicewindow.cpp b/src/gui/kernel/qpaintdevicewindow.cpp
index 4521c2f62c..4f45fc5fde 100644
--- a/src/gui/kernel/qpaintdevicewindow.cpp
+++ b/src/gui/kernel/qpaintdevicewindow.cpp
@@ -219,7 +219,7 @@ QPaintDeviceWindow::QPaintDeviceWindow(QPaintDeviceWindowPrivate &dd, QWindow *p
*/
QPaintEngine *QPaintDeviceWindow::paintEngine() const
{
- return 0;
+ return nullptr;
}
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp
index 61dccd77ac..e31ce00e14 100644
--- a/src/gui/kernel/qpalette.cpp
+++ b/src/gui/kernel/qpalette.cpp
@@ -44,10 +44,28 @@
#include "qvariant.h"
#include "qdebug.h"
+#include <QtCore/qmetaobject.h>
+
QT_BEGIN_NAMESPACE
static int qt_palette_count = 1;
+static constexpr QPalette::ResolveMask colorRoleOffset(QPalette::ColorGroup colorGroup)
+{
+ return QPalette::NColorRoles * colorGroup;
+}
+
+static constexpr QPalette::ResolveMask bitPosition(QPalette::ColorGroup colorGroup,
+ QPalette::ColorRole colorRole)
+{
+ return colorRole + colorRoleOffset(colorGroup);
+}
+
+Q_STATIC_ASSERT_X(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.");
+
class QPalettePrivate {
public:
QPalettePrivate() : ref(1), ser_no(qt_palette_count++), detach_no(0) { }
@@ -321,11 +339,8 @@ static void qt_palette_from_color(QPalette &pal, const QColor &button)
Returns the placeholder text brush of the current color group.
- \note Before Qt 5.12, the placeholder text color was hard-coded in the code as
- QPalette::text().color() where an alpha of 128 was applied.
- We continue to support this behavior by default, unless you set your own brush.
- One can get back the original placeholder color setting the special QBrush default
- constructor as placeholder brush.
+ \note Before Qt 5.12, the placeholder text color was hard-coded as QPalette::text().color()
+ with an alpha of 128 applied. In Qt 6, it is an independent color.
\sa ColorRole, brush()
*/
@@ -536,10 +551,8 @@ static void qt_palette_from_color(QPalette &pal, const QColor &button)
\sa QApplication::setPalette(), QApplication::palette()
*/
QPalette::QPalette()
- : d(0)
+ : d(nullptr)
{
- data.current_group = Active;
- data.resolve_mask = 0;
// Initialize to application palette if present, else default to black.
// This makes it possible to instantiate QPalette outside QGuiApplication,
// for example in the platform plugins.
@@ -549,7 +562,7 @@ QPalette::QPalette()
} else {
init();
qt_palette_from_color(*this, Qt::black);
- data.resolve_mask = 0;
+ data.resolveMask = 0;
}
}
@@ -681,8 +694,6 @@ QPalette::~QPalette()
/*!\internal*/
void QPalette::init() {
d = new QPalettePrivate;
- data.resolve_mask = 0;
- data.current_group = Active; //as a default..
}
/*!
@@ -739,7 +750,7 @@ const QBrush &QPalette::brush(ColorGroup gr, ColorRole cr) const
Q_ASSERT(cr < NColorRoles);
if(gr >= (int)NColorGroups) {
if(gr == Current) {
- gr = (ColorGroup)data.current_group;
+ gr = data.currentGroup;
} else {
qWarning("QPalette::brush: Unknown ColorGroup: %d", (int)gr);
gr = Active;
@@ -777,38 +788,18 @@ void QPalette::setBrush(ColorGroup cg, ColorRole cr, const QBrush &b)
}
if (cg == Current) {
- cg = ColorGroup(data.current_group);
+ cg = data.currentGroup;
} else if (cg >= NColorGroups) {
qWarning("QPalette::setBrush: Unknown ColorGroup: %d", cg);
cg = Active;
}
- // For placeholder we want to continue to respect the original behavior, which is
- // derivating the text color, but only if user has not yet set his own brush.
- // We then use Qt::NoBrush as an inernal way to know if the brush is customized or not.
-
- // ### Qt 6 - remove this special case
- // Part 1 - Restore initial color to the given color group
- if (cr == PlaceholderText && b == QBrush()) {
- QColor col = brush(Text).color();
- col.setAlpha(128);
- setBrush(cg, PlaceholderText, QBrush(col, Qt::NoBrush));
- return;
- }
-
if (d->br[cg][cr] != b) {
detach();
d->br[cg][cr] = b;
}
- data.resolve_mask |= (1<<cr);
-
- // ### Qt 6 - remove this special case
- // Part 2 - Update initial color to the given color group
- if (cr == Text && d->br[cg][PlaceholderText].style() == Qt::NoBrush) {
- QColor col = brush(Text).color();
- col.setAlpha(128);
- setBrush(cg, PlaceholderText, QBrush(col, Qt::NoBrush));
- }
+
+ data.resolveMask |= ResolveMask(1) << bitPosition(cg, cr);
}
/*!
@@ -817,12 +808,30 @@ void QPalette::setBrush(ColorGroup cg, ColorRole cr, const QBrush &b)
Returns \c true if the ColorGroup \a cg and ColorRole \a cr has been
set previously on this palette; otherwise returns \c false.
- \sa setBrush()
+ The ColorGroup \a cg should be less than QPalette::NColorGroups,
+ but you can use QPalette::Current. In this case, the previously
+ set current color group will be used.
+
+ The ColorRole \a cr should be less than QPalette::NColorRoles.
+
+ \sa setBrush(), currentColorGroup()
*/
bool QPalette::isBrushSet(ColorGroup cg, ColorRole cr) const
{
- Q_UNUSED(cg);
- return (data.resolve_mask & (1<<cr));
+ if (cg == Current)
+ cg = data.currentGroup;
+
+ if (cg >= NColorGroups) {
+ qWarning() << "Wrong color group:" << cg;
+ return false;
+ }
+
+ if (cr >= NColorRoles) {
+ qWarning() << "Wrong color role:" << cr;
+ return false;
+ }
+
+ return data.resolveMask & (ResolveMask(1) << bitPosition(cg, cr));
}
/*!
@@ -887,7 +896,7 @@ bool QPalette::isEqual(QPalette::ColorGroup group1, QPalette::ColorGroup group2)
{
if(group1 >= (int)NColorGroups) {
if(group1 == Current) {
- group1 = (ColorGroup)data.current_group;
+ group1 = data.currentGroup;
} else {
qWarning("QPalette::brush: Unknown ColorGroup(1): %d", (int)group1);
group1 = Active;
@@ -895,7 +904,7 @@ bool QPalette::isEqual(QPalette::ColorGroup group1, QPalette::ColorGroup group2)
}
if(group2 >= (int)NColorGroups) {
if(group2 == Current) {
- group2 = (ColorGroup)data.current_group;
+ group2 = data.currentGroup;
} else {
qWarning("QPalette::brush: Unknown ColorGroup(2): %d", (int)group2);
group2 = Active;
@@ -946,21 +955,25 @@ qint64 QPalette::cacheKey() const
*/
QPalette QPalette::resolve(const QPalette &other) const
{
- if ((*this == other && data.resolve_mask == other.data.resolve_mask)
- || data.resolve_mask == 0) {
+ if ((*this == other && data.resolveMask == other.data.resolveMask)
+ || data.resolveMask == 0) {
QPalette o = other;
- o.data.resolve_mask = data.resolve_mask;
+ o.data.resolveMask = data.resolveMask;
return o;
}
QPalette palette(*this);
palette.detach();
- for(int role = 0; role < (int)NColorRoles; role++)
- if (!(data.resolve_mask & (1<<role)))
- for(int grp = 0; grp < (int)NColorGroups; grp++)
+ for (int role = 0; role < int(NColorRoles); ++role) {
+ 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];
- palette.data.resolve_mask |= other.data.resolve_mask;
+ }
+ }
+ }
+
+ palette.data.resolveMask |= other.data.resolveMask;
return palette;
}
@@ -971,7 +984,12 @@ QPalette QPalette::resolve(const QPalette &other) const
*/
/*!
- \fn void QPalette::resolve(uint mask)
+ \typedef ResolveMaskType
+ \internal
+ */
+
+/*!
+ \fn void QPalette::resolve(ResolveMaskType mask)
\internal
*/
@@ -1105,10 +1123,15 @@ void QPalette::setColorGroup(ColorGroup cg, const QBrush &windowText, const QBru
QBrush(Qt::blue), QBrush(Qt::magenta), QBrush(toolTipBase),
QBrush(toolTipText));
- data.resolve_mask &= ~(1 << Highlight);
- data.resolve_mask &= ~(1 << HighlightedText);
- data.resolve_mask &= ~(1 << LinkVisited);
- data.resolve_mask &= ~(1 << Link);
+ 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)));
+ }
+ } else {
+ data.resolveMask &= ~(ResolveMask(1) << bitPosition(ColorGroup(cg), ColorRole(cr)));
+ }
+ }
}
@@ -1177,6 +1200,8 @@ Q_GUI_EXPORT QPalette qt_fusionPalette()
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);
@@ -1194,40 +1219,65 @@ Q_GUI_EXPORT QPalette qt_fusionPalette()
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
-QDebug operator<<(QDebug dbg, const QPalette &p)
+static QString groupsToString(const QPalette &p, QPalette::ColorRole cr)
{
- const char *colorGroupNames[] = {"Active", "Disabled", "Inactive"};
- const char *colorRoleNames[] =
- {"WindowText", "Button", "Light", "Midlight", "Dark", "Mid", "Text",
- "BrightText", "ButtonText", "Base", "Window", "Shadow", "Highlight",
- "HighlightedText", "Link", "LinkVisited", "AlternateBase", "NoRole",
- "ToolTipBase","ToolTipText", "PlaceholderText" };
- QDebugStateSaver saver(dbg);
- QDebug nospace = dbg.nospace();
- const uint mask = p.resolve();
- nospace << "QPalette(resolve=" << Qt::hex << Qt::showbase << mask << ',';
- for (int role = 0; role < (int)QPalette::NColorRoles; ++role) {
- if (mask & (1<<role)) {
- if (role)
- nospace << ',';
- nospace << colorRoleNames[role] << ":[";
- for (int group = 0; group < (int)QPalette::NColorGroups; ++group) {
- if (group)
- nospace << ',';
- const QRgb color = p.color(static_cast<QPalette::ColorGroup>(group),
- static_cast<QPalette::ColorRole>(role)).rgba();
- nospace << colorGroupNames[group] << ':' << color;
- }
- nospace << ']';
+ const auto groupEnum = QMetaEnum::fromType<QPalette::ColorGroup>();
+
+ QString groupString;
+ for (int group = 0; group < QPalette::NColorGroups; ++group) {
+ const auto cg = QPalette::ColorGroup(group);
+
+ if (p.isBrushSet(cg, cr)) {
+ const auto &color = p.color(cg, cr);
+ groupString += QString::fromUtf8(groupEnum.valueToKey(cg)) + QLatin1Char(':') +
+ color.name(QColor::HexArgb) + QLatin1Char(',');
}
}
- nospace << ')' << Qt::noshowbase << Qt::dec;
- return dbg;
+ groupString.chop(1);
+
+ return groupString;
}
+
+static QString rolesToString(const QPalette &p)
+{
+ const auto roleEnum = QMetaEnum::fromType<QPalette::ColorRole>();
+
+ QString roleString;
+ for (int role = 0; role < QPalette::NColorRoles; ++role) {
+ const auto cr = QPalette::ColorRole(role);
+
+ auto groupString = groupsToString(p, cr);
+ if (!groupString.isEmpty())
+ roleString += QString::fromUtf8(roleEnum.valueToKey(cr)) + QStringLiteral(":[") +
+ groupString + QStringLiteral("],");
+ }
+ roleString.chop(1);
+
+ return roleString;
+}
+
+QDebug operator<<(QDebug dbg, const QPalette &p)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace();
+
+ dbg << "QPalette(resolve=" << Qt::hex << Qt::showbase << p.resolve();
+
+ auto roleString = rolesToString(p);
+ if (!roleString.isEmpty())
+ dbg << ',' << roleString;
+
+ dbg << ')';
+
+ return dbg;
+ }
#endif
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qpalette.h b/src/gui/kernel/qpalette.h
index d3a840d9ad..fd0ef2e2d9 100644
--- a/src/gui/kernel/qpalette.h
+++ b/src/gui/kernel/qpalette.h
@@ -72,14 +72,13 @@ public:
{ other.d = nullptr; }
inline QPalette &operator=(QPalette &&other) noexcept
{
- for_faster_swapping_dont_use = other.for_faster_swapping_dont_use;
- qSwap(d, other.d); return *this;
+ swap(other); return *this;
}
void swap(QPalette &other) noexcept
{
+ qSwap(data, other.data);
qSwap(d, other.d);
- qSwap(for_faster_swapping_dont_use, other.for_faster_swapping_dont_use);
}
operator QVariant() const;
@@ -103,8 +102,8 @@ public:
};
Q_ENUM(ColorRole)
- inline ColorGroup currentColorGroup() const { return static_cast<ColorGroup>(data.current_group); }
- inline void setCurrentColorGroup(ColorGroup cg) { data.current_group = cg; }
+ inline ColorGroup currentColorGroup() const { return data.currentGroup; }
+ inline void setCurrentColorGroup(ColorGroup cg) { data.currentGroup = cg; }
inline const QColor &color(ColorGroup cg, ColorRole cr) const
{ return brush(cg, cr).color(); }
@@ -158,9 +157,11 @@ public:
#endif
qint64 cacheKey() const;
- QPalette resolve(const QPalette &) const;
- inline uint resolve() const { return data.resolve_mask; }
- inline void resolve(uint mask) { data.resolve_mask = mask; }
+ QPalette resolve(const QPalette &other) const;
+
+ using ResolveMask = quint64;
+ inline ResolveMask resolve() const { return data.resolveMask; }
+ inline void resolve(ResolveMask mask) { data.resolveMask = mask; }
private:
void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
@@ -185,13 +186,11 @@ private:
QPalettePrivate *d;
struct Data {
- uint current_group : 4;
- uint resolve_mask : 28;
- };
- union {
- Data data;
- quint32 for_faster_swapping_dont_use;
+ ResolveMask resolveMask{0};
+ ColorGroup currentGroup{Active};
};
+ Data data;
+
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p);
};
diff --git a/src/gui/kernel/qplatformclipboard.cpp b/src/gui/kernel/qplatformclipboard.cpp
index ab2998b901..34c94dca3b 100644
--- a/src/gui/kernel/qplatformclipboard.cpp
+++ b/src/gui/kernel/qplatformclipboard.cpp
@@ -67,7 +67,7 @@ private:
QClipboardData::QClipboardData()
{
- src = 0;
+ src = nullptr;
}
QClipboardData::~QClipboardData()
diff --git a/src/gui/kernel/qplatformcursor.cpp b/src/gui/kernel/qplatformcursor.cpp
index 49eff2ad23..5a438a54a2 100644
--- a/src/gui/kernel/qplatformcursor.cpp
+++ b/src/gui/kernel/qplatformcursor.cpp
@@ -103,7 +103,7 @@ QT_BEGIN_NAMESPACE
QPlatformCursor::clearOverrideCursor().
*/
-QPlatformCursor::Capabilities QPlatformCursor::m_capabilities = 0;
+QPlatformCursor::Capabilities QPlatformCursor::m_capabilities = { };
/*!
\fn QPlatformCursor::QPlatformCursor()
@@ -128,7 +128,15 @@ void QPlatformCursor::setPos(const QPoint &pos)
qWarning("This plugin does not support QCursor::setPos()"
"; emulating movement within the application.");
}
- QWindowSystemInterface::handleMouseEvent(0, pos, pos, Qt::NoButton, Qt::NoButton, QEvent::MouseMove);
+ QWindowSystemInterface::handleMouseEvent(nullptr, pos, pos, Qt::NoButton, Qt::NoButton, QEvent::MouseMove);
+}
+
+/*!
+ Returns the size of the cursor, in native pixels.
+*/
+QSize QPlatformCursor::size() const
+{
+ return QSize(16, 16);
}
// End of display and pointer event handling code
@@ -431,7 +439,7 @@ void QPlatformCursorImage::createSystemCursor(int id)
{
if (!systemCursorTableInit) {
for (int i = 0; i <= Qt::LastCursor; i++)
- systemCursorTable[i] = 0;
+ systemCursorTable[i] = nullptr;
systemCursorTableInit = true;
}
switch (id) {
@@ -478,7 +486,7 @@ void QPlatformCursorImage::createSystemCursor(int id)
case Qt::BlankCursor:
systemCursorTable[Qt::BlankCursor] =
- new QPlatformCursorImage(0, 0, 0, 0, 0, 0);
+ new QPlatformCursorImage(nullptr, nullptr, 0, 0, 0, 0);
break;
// 20x20 cursors
@@ -548,14 +556,14 @@ void QPlatformCursorImage::createSystemCursor(int id)
void QPlatformCursorImage::set(Qt::CursorShape id)
{
- QPlatformCursorImage *cursor = 0;
+ QPlatformCursorImage *cursor = nullptr;
if (unsigned(id) <= unsigned(Qt::LastCursor)) {
if (!systemCursorTable[id])
createSystemCursor(id);
cursor = systemCursorTable[id];
}
- if (cursor == 0) {
+ if (cursor == nullptr) {
if (!systemCursorTable[Qt::ArrowCursor])
createSystemCursor(Qt::ArrowCursor);
cursor = systemCursorTable[Qt::ArrowCursor];
diff --git a/src/gui/kernel/qplatformcursor.h b/src/gui/kernel/qplatformcursor.h
index f36a73c861..f3871d8780 100644
--- a/src/gui/kernel/qplatformcursor.h
+++ b/src/gui/kernel/qplatformcursor.h
@@ -96,6 +96,7 @@ public:
#endif // QT_NO_CURSOR
virtual QPoint pos() const;
virtual void setPos(const QPoint &pos);
+ virtual QSize size() const;
static Capabilities capabilities() { return m_capabilities; }
static void setCapabilities(Capabilities c) { m_capabilities = c; }
diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp
index 4bee153489..15ac4acf91 100644
--- a/src/gui/kernel/qplatformdialoghelper.cpp
+++ b/src/gui/kernel/qplatformdialoghelper.cpp
@@ -186,7 +186,7 @@ QVariant QPlatformDialogHelper::defaultStyleHint(QPlatformDialogHelper::StyleHi
class QFontDialogOptionsPrivate : public QSharedData
{
public:
- QFontDialogOptionsPrivate() : options(0) {}
+ QFontDialogOptionsPrivate() = default;
QFontDialogOptions::FontDialogOptions options;
QString windowTitle;
@@ -328,7 +328,7 @@ Q_GLOBAL_STATIC(QColorDialogStaticData, qColorDialogStaticData)
class QColorDialogOptionsPrivate : public QSharedData
{
public:
- QColorDialogOptionsPrivate() : options(0) {}
+ QColorDialogOptionsPrivate() = default;
// Write out settings around destruction of dialogs
~QColorDialogOptionsPrivate() { qColorDialogStaticData()->writeSettings(); }
@@ -465,24 +465,16 @@ void QPlatformColorDialogHelper::setOptions(const QSharedPointer<QColorDialogOpt
class QFileDialogOptionsPrivate : public QSharedData
{
public:
- QFileDialogOptionsPrivate() : options(0),
- viewMode(QFileDialogOptions::Detail),
- fileMode(QFileDialogOptions::AnyFile),
- acceptMode(QFileDialogOptions::AcceptOpen),
- filters(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs),
- useDefaultNameFilters(true)
- {}
-
QFileDialogOptions::FileDialogOptions options;
QString windowTitle;
- QFileDialogOptions::ViewMode viewMode;
- QFileDialogOptions::FileMode fileMode;
- QFileDialogOptions::AcceptMode acceptMode;
+ QFileDialogOptions::ViewMode viewMode = QFileDialogOptions::Detail;
+ QFileDialogOptions::FileMode fileMode = QFileDialogOptions::AnyFile;
+ QFileDialogOptions::AcceptMode acceptMode = QFileDialogOptions::AcceptOpen;
QString labels[QFileDialogOptions::DialogLabelCount];
- QDir::Filters filters;
+ QDir::Filters filters = QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs;
QList<QUrl> sidebarUrls;
- bool useDefaultNameFilters;
+ bool useDefaultNameFilters = true;
QStringList nameFilters;
QStringList mimeTypeFilters;
QString defaultSuffix;
diff --git a/src/gui/kernel/qplatforminputcontextfactory.cpp b/src/gui/kernel/qplatforminputcontextfactory.cpp
index df7b95d8df..749abaf27a 100644
--- a/src/gui/kernel/qplatforminputcontextfactory.cpp
+++ b/src/gui/kernel/qplatforminputcontextfactory.cpp
@@ -85,7 +85,7 @@ QPlatformInputContext *QPlatformInputContextFactory::create(const QString& key)
#else
Q_UNUSED(key);
#endif
- return 0;
+ return nullptr;
}
QPlatformInputContext *QPlatformInputContextFactory::create()
diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp
index b3d3db0751..63f66e6bf7 100644
--- a/src/gui/kernel/qplatformintegration.cpp
+++ b/src/gui/kernel/qplatformintegration.cpp
@@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE
*/
QPlatformFontDatabase *QPlatformIntegration::fontDatabase() const
{
- static QPlatformFontDatabase *db = 0;
+ static QPlatformFontDatabase *db = nullptr;
if (!db) {
db = new QPlatformFontDatabase;
}
@@ -86,7 +86,7 @@ QPlatformFontDatabase *QPlatformIntegration::fontDatabase() const
QPlatformClipboard *QPlatformIntegration::clipboard() const
{
- static QPlatformClipboard *clipboard = 0;
+ static QPlatformClipboard *clipboard = nullptr;
if (!clipboard) {
clipboard = new QPlatformClipboard;
}
@@ -104,7 +104,7 @@ QPlatformClipboard *QPlatformIntegration::clipboard() const
*/
QPlatformDrag *QPlatformIntegration::drag() const
{
- static QSimpleDrag *drag = 0;
+ static QSimpleDrag *drag = nullptr;
if (!drag) {
drag = new QSimpleDrag;
}
@@ -114,12 +114,12 @@ QPlatformDrag *QPlatformIntegration::drag() const
QPlatformNativeInterface * QPlatformIntegration::nativeInterface() const
{
- return 0;
+ return nullptr;
}
QPlatformServices *QPlatformIntegration::services() const
{
- return 0;
+ return nullptr;
}
/*!
@@ -303,7 +303,7 @@ QPlatformOpenGLContext *QPlatformIntegration::createPlatformOpenGLContext(QOpenG
{
Q_UNUSED(context);
qWarning("This plugin does not support createPlatformOpenGLContext!");
- return 0;
+ return nullptr;
}
#endif // QT_NO_OPENGL
@@ -315,7 +315,7 @@ QPlatformSharedGraphicsCache *QPlatformIntegration::createPlatformSharedGraphics
{
qWarning("This plugin does not support createPlatformSharedGraphicsBuffer for cacheId: %s!",
cacheId);
- return 0;
+ return nullptr;
}
/*!
@@ -325,7 +325,7 @@ QPlatformSharedGraphicsCache *QPlatformIntegration::createPlatformSharedGraphics
QPaintEngine *QPlatformIntegration::createImagePaintEngine(QPaintDevice *paintDevice) const
{
Q_UNUSED(paintDevice)
- return 0;
+ return nullptr;
}
/*!
@@ -357,7 +357,7 @@ void QPlatformIntegration::destroy()
*/
QPlatformInputContext *QPlatformIntegration::inputContext() const
{
- return 0;
+ return nullptr;
}
#ifndef QT_NO_ACCESSIBILITY
@@ -370,7 +370,7 @@ QPlatformInputContext *QPlatformIntegration::inputContext() const
*/
QPlatformAccessibility *QPlatformIntegration::accessibility() const
{
- static QPlatformAccessibility *accessibility = 0;
+ static QPlatformAccessibility *accessibility = nullptr;
if (Q_UNLIKELY(!accessibility)) {
accessibility = new QPlatformAccessibility;
}
@@ -484,7 +484,7 @@ class QPlatformTheme *QPlatformIntegration::createPlatformTheme(const QString &n
QPlatformOffscreenSurface *QPlatformIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
{
Q_UNUSED(surface)
- return 0;
+ return nullptr;
}
#ifndef QT_NO_SESSIONMANAGER
diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h
index d9f349555a..01406958e2 100644
--- a/src/gui/kernel/qplatformintegration.h
+++ b/src/gui/kernel/qplatformintegration.h
@@ -106,7 +106,8 @@ public:
ApplicationIcon,
SwitchableWidgetComposition,
TopStackedNativeChildWindows,
- OpenGLOnRasterSurface
+ OpenGLOnRasterSurface,
+ MaximizeUsingFullscreenGeometry
};
virtual ~QPlatformIntegration() { }
diff --git a/src/gui/kernel/qplatformintegrationplugin.cpp b/src/gui/kernel/qplatformintegrationplugin.cpp
index 35e4d2797b..b100eacbb5 100644
--- a/src/gui/kernel/qplatformintegrationplugin.cpp
+++ b/src/gui/kernel/qplatformintegrationplugin.cpp
@@ -54,7 +54,7 @@ QPlatformIntegration *QPlatformIntegrationPlugin::create(const QString &key, con
{
Q_UNUSED(key)
Q_UNUSED(paramList);
- return 0;
+ return nullptr;
}
QPlatformIntegration *QPlatformIntegrationPlugin::create(const QString &key, const QStringList &paramList, int &argc, char **argv)
diff --git a/src/gui/kernel/qplatformnativeinterface.cpp b/src/gui/kernel/qplatformnativeinterface.cpp
index b24541d3ec..8c9e73fbc2 100644
--- a/src/gui/kernel/qplatformnativeinterface.cpp
+++ b/src/gui/kernel/qplatformnativeinterface.cpp
@@ -56,35 +56,35 @@ QT_BEGIN_NAMESPACE
void *QPlatformNativeInterface::nativeResourceForIntegration(const QByteArray &resource)
{
Q_UNUSED(resource);
- return 0;
+ return nullptr;
}
void *QPlatformNativeInterface::nativeResourceForScreen(const QByteArray &resource, QScreen *screen)
{
Q_UNUSED(resource);
Q_UNUSED(screen);
- return 0;
+ return nullptr;
}
void *QPlatformNativeInterface::nativeResourceForWindow(const QByteArray &resource, QWindow *window)
{
Q_UNUSED(resource);
Q_UNUSED(window);
- return 0;
+ return nullptr;
}
void *QPlatformNativeInterface::nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context)
{
Q_UNUSED(resource);
Q_UNUSED(context);
- return 0;
+ return nullptr;
}
void * QPlatformNativeInterface::nativeResourceForBackingStore(const QByteArray &resource, QBackingStore *backingStore)
{
Q_UNUSED(resource);
Q_UNUSED(backingStore);
- return 0;
+ return nullptr;
}
#ifndef QT_NO_CURSOR
@@ -99,31 +99,31 @@ void *QPlatformNativeInterface::nativeResourceForCursor(const QByteArray &resour
QPlatformNativeInterface::NativeResourceForIntegrationFunction QPlatformNativeInterface::nativeResourceFunctionForIntegration(const QByteArray &resource)
{
Q_UNUSED(resource);
- return 0;
+ return nullptr;
}
QPlatformNativeInterface::NativeResourceForContextFunction QPlatformNativeInterface::nativeResourceFunctionForContext(const QByteArray &resource)
{
Q_UNUSED(resource);
- return 0;
+ return nullptr;
}
QPlatformNativeInterface::NativeResourceForScreenFunction QPlatformNativeInterface::nativeResourceFunctionForScreen(const QByteArray &resource)
{
Q_UNUSED(resource);
- return 0;
+ return nullptr;
}
QPlatformNativeInterface::NativeResourceForWindowFunction QPlatformNativeInterface::nativeResourceFunctionForWindow(const QByteArray &resource)
{
Q_UNUSED(resource);
- return 0;
+ return nullptr;
}
QPlatformNativeInterface::NativeResourceForBackingStoreFunction QPlatformNativeInterface::nativeResourceFunctionForBackingStore(const QByteArray &resource)
{
Q_UNUSED(resource);
- return 0;
+ return nullptr;
}
QFunctionPointer QPlatformNativeInterface::platformFunction(const QByteArray &function) const
diff --git a/src/gui/kernel/qplatformopenglcontext.cpp b/src/gui/kernel/qplatformopenglcontext.cpp
index 07b5a0dda6..839ec008aa 100644
--- a/src/gui/kernel/qplatformopenglcontext.cpp
+++ b/src/gui/kernel/qplatformopenglcontext.cpp
@@ -81,7 +81,7 @@ QT_BEGIN_NAMESPACE
class QPlatformOpenGLContextPrivate
{
public:
- QPlatformOpenGLContextPrivate() : context(0) {}
+ QPlatformOpenGLContextPrivate() : context(nullptr) {}
QOpenGLContext *context;
};
diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp
index f3213bf5ea..7c1e2158b1 100644
--- a/src/gui/kernel/qplatformscreen.cpp
+++ b/src/gui/kernel/qplatformscreen.cpp
@@ -54,7 +54,7 @@ QPlatformScreen::QPlatformScreen()
: d_ptr(new QPlatformScreenPrivate)
{
Q_D(QPlatformScreen);
- d->screen = 0;
+ d->screen = nullptr;
}
QPlatformScreen::~QPlatformScreen()
@@ -99,7 +99,7 @@ QWindow *QPlatformScreen::topLevelAt(const QPoint & pos) const
return w;
}
- return 0;
+ return nullptr;
}
/*!
@@ -310,7 +310,7 @@ QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *window
// QTBUG 32681: It can happen during the transition between screens
// when one screen is disconnected that the window doesn't have a screen.
if (!window->screen())
- return 0;
+ return nullptr;
return window->screen()->handle();
}
@@ -395,7 +395,7 @@ QString QPlatformScreen::serialNumber() const
*/
QPlatformCursor *QPlatformScreen::cursor() const
{
- return 0;
+ return nullptr;
}
/*!
@@ -410,15 +410,22 @@ void QPlatformScreen::resizeMaximizedWindows()
const QRect newGeometry = deviceIndependentGeometry();
const QRect newAvailableGeometry = QHighDpi::fromNative(availableGeometry(), QHighDpiScaling::factor(this), newGeometry.topLeft());
+ const bool supportsMaximizeUsingFullscreen = QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::MaximizeUsingFullscreenGeometry);
+
for (QWindow *w : windows()) {
// Skip non-platform windows, e.g., offscreen windows.
if (!w->handle())
continue;
- if (w->windowState() & Qt::WindowMaximized || w->geometry() == oldAvailableGeometry)
+ if (supportsMaximizeUsingFullscreen
+ && w->windowState() & Qt::WindowMaximized
+ && w->flags() & Qt::MaximizeUsingFullscreenGeometryHint) {
+ w->setGeometry(newGeometry);
+ } else if (w->windowState() & Qt::WindowMaximized || w->geometry() == oldAvailableGeometry) {
w->setGeometry(newAvailableGeometry);
- else if (w->windowState() & Qt::WindowFullScreen || w->geometry() == oldGeometry)
+ } else if (w->windowState() & Qt::WindowFullScreen || w->geometry() == oldGeometry) {
w->setGeometry(newGeometry);
+ }
}
}
@@ -609,4 +616,18 @@ int QPlatformScreen::preferredMode() const
return 0;
}
+QList<QPlatformScreen *> QPlatformPlaceholderScreen::virtualSiblings() const
+{
+ QList<QPlatformScreen *> siblings;
+
+ if (!m_virtualSibling)
+ return siblings;
+
+ for (QScreen *screen : QGuiApplication::screens()) {
+ if (screen->handle() && screen->handle() != this)
+ siblings << screen->handle();
+ }
+ return siblings;
+}
+
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h
index d7378aed51..0be7646032 100644
--- a/src/gui/kernel/qplatformscreen.h
+++ b/src/gui/kernel/qplatformscreen.h
@@ -105,6 +105,8 @@ public:
QPlatformScreen();
virtual ~QPlatformScreen();
+ virtual bool isPlaceholder() const { return false; }
+
virtual QPixmap grabWindow(WId window, int x, int y, int width, int height) const;
virtual QRect geometry() const = 0;
@@ -172,6 +174,27 @@ private:
friend class QScreenPrivate;
};
+// Qt doesn't currently support running with no platform screen
+// QPA plugins can use this class to create a fake screen
+class Q_GUI_EXPORT QPlatformPlaceholderScreen : public QPlatformScreen {
+public:
+ // virtualSibling can be passed in to make the placeholder a sibling with other screens during
+ // the transitioning phase when the real screen is about to be removed, or the first real screen
+ // is about to be added. This is useful because Qt will currently recreate (but now show!)
+ // windows when they are moved from one virtual desktop to another, so if the last monitor is
+ // unplugged, then plugged in again, windows will be hidden unless the placeholder belongs to
+ // the same virtual desktop as the other screens.
+ QPlatformPlaceholderScreen(bool virtualSibling = true) : m_virtualSibling(virtualSibling) {}
+ bool isPlaceholder() const override { return true; }
+ QRect geometry() const override { return QRect(); }
+ QRect availableGeometry() const override { return QRect(); }
+ int depth() const override { return 32; }
+ QImage::Format format() const override { return QImage::Format::Format_RGB32; }
+ QList<QPlatformScreen *> virtualSiblings() const override;
+private:
+ bool m_virtualSibling = true;
+};
+
QT_END_NAMESPACE
#endif // QPLATFORMSCREEN_H
diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp
index ff6f32de10..93fd59e53f 100644
--- a/src/gui/kernel/qplatformtheme.cpp
+++ b/src/gui/kernel/qplatformtheme.cpp
@@ -354,7 +354,7 @@ const uint QPlatformThemePrivate::numberOfKeyBindings = sizeof(QPlatformThemePri
#endif
QPlatformThemePrivate::QPlatformThemePrivate()
- : systemPalette(0)
+ : systemPalette(nullptr)
{ }
QPlatformThemePrivate::~QPlatformThemePrivate()
@@ -394,7 +394,7 @@ bool QPlatformTheme::usePlatformNativeDialog(DialogType type) const
QPlatformDialogHelper *QPlatformTheme::createPlatformDialogHelper(DialogType type) const
{
Q_UNUSED(type);
- return 0;
+ return nullptr;
}
const QPalette *QPlatformTheme::palette(Palette type) const
@@ -405,13 +405,13 @@ const QPalette *QPlatformTheme::palette(Palette type) const
const_cast<QPlatformTheme *>(this)->d_ptr->initializeSystemPalette();
return d->systemPalette;
}
- return 0;
+ return nullptr;
}
const QFont *QPlatformTheme::font(Font type) const
{
Q_UNUSED(type)
- return 0;
+ return nullptr;
}
QPixmap QPlatformTheme::standardPixmap(StandardPixmap sp, const QSizeF &size) const
@@ -569,17 +569,17 @@ QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint)
QPlatformMenuItem *QPlatformTheme::createPlatformMenuItem() const
{
- return 0;
+ return nullptr;
}
QPlatformMenu *QPlatformTheme::createPlatformMenu() const
{
- return 0;
+ return nullptr;
}
QPlatformMenuBar *QPlatformTheme::createPlatformMenuBar() const
{
- return 0;
+ return nullptr;
}
#ifndef QT_NO_SYSTEMTRAYICON
@@ -589,7 +589,7 @@ QPlatformMenuBar *QPlatformTheme::createPlatformMenuBar() const
*/
QPlatformSystemTrayIcon *QPlatformTheme::createPlatformSystemTrayIcon() const
{
- return 0;
+ return nullptr;
}
#endif
diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h
index 7b88af954c..6ed612b785 100644
--- a/src/gui/kernel/qplatformtheme.h
+++ b/src/gui/kernel/qplatformtheme.h
@@ -311,7 +311,7 @@ public:
virtual QPixmap standardPixmap(StandardPixmap sp, const QSizeF &size) const;
virtual QIcon fileIcon(const QFileInfo &fileInfo,
- QPlatformTheme::IconOptions iconOptions = nullptr) const;
+ QPlatformTheme::IconOptions iconOptions = { }) const;
virtual QIconEngine *createIconEngine(const QString &iconName) const;
#if QT_CONFIG(shortcut)
diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp
index 2a0cb1094c..65accc9f68 100644
--- a/src/gui/kernel/qplatformwindow.cpp
+++ b/src/gui/kernel/qplatformwindow.cpp
@@ -694,9 +694,12 @@ static QSize fixInitialSize(QSize size, const QWindow *w,
However if the given window already has geometry which the application has
initialized, it takes priority.
*/
-QRect QPlatformWindow::initialGeometry(const QWindow *w,
- const QRect &initialGeometry, int defaultWidth, int defaultHeight)
+QRect QPlatformWindow::initialGeometry(const QWindow *w, const QRect &initialGeometry,
+ int defaultWidth, int defaultHeight,
+ const QScreen **resultingScreenReturn)
{
+ if (resultingScreenReturn)
+ *resultingScreenReturn = w->screen();
if (!w->isTopLevel()) {
const qreal factor = QHighDpiScaling::factor(w);
const QSize size = fixInitialSize(QHighDpi::fromNative(initialGeometry.size(), factor),
@@ -712,6 +715,8 @@ QRect QPlatformWindow::initialGeometry(const QWindow *w,
: QGuiApplication::screenAt(initialGeometry.center());
if (!screen)
return initialGeometry;
+ if (resultingScreenReturn)
+ *resultingScreenReturn = screen;
// initialGeometry refers to window's screen
QRect rect(QHighDpi::fromNativePixels(initialGeometry, w));
if (wp->resizeAutomatic)
diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h
index 4d48cc2f13..b6aeb3a86a 100644
--- a/src/gui/kernel/qplatformwindow.h
+++ b/src/gui/kernel/qplatformwindow.h
@@ -63,6 +63,7 @@ QT_BEGIN_NAMESPACE
class QPlatformScreen;
class QPlatformWindowPrivate;
+class QScreen;
class QWindow;
class QIcon;
class QRegion;
@@ -142,8 +143,9 @@ public:
virtual void invalidateSurface();
- static QRect initialGeometry(const QWindow *w,
- const QRect &initialGeometry, int defaultWidth, int defaultHeight);
+ static QRect initialGeometry(const QWindow *w, const QRect &initialGeometry,
+ int defaultWidth, int defaultHeight,
+ const QScreen **resultingScreenReturn = nullptr);
virtual void requestUpdate();
bool hasPendingUpdateRequest() const;
diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp
index 80de561297..9de59f8c7e 100644
--- a/src/gui/kernel/qscreen.cpp
+++ b/src/gui/kernel/qscreen.cpp
@@ -71,7 +71,7 @@ QT_BEGIN_NAMESPACE
*/
QScreen::QScreen(QPlatformScreen *screen)
- : QObject(*new QScreenPrivate(), 0)
+ : QObject(*new QScreenPrivate(), nullptr)
{
Q_D(QScreen);
d->setPlatformScreen(screen);
diff --git a/src/gui/kernel/qsessionmanager.cpp b/src/gui/kernel/qsessionmanager.cpp
index e5e9c624b2..8747e02719 100644
--- a/src/gui/kernel/qsessionmanager.cpp
+++ b/src/gui/kernel/qsessionmanager.cpp
@@ -135,7 +135,7 @@ QSessionManagerPrivate::QSessionManagerPrivate(const QString &id,
QSessionManagerPrivate::~QSessionManagerPrivate()
{
delete platformSessionManager;
- platformSessionManager = 0;
+ platformSessionManager = nullptr;
}
QSessionManager::QSessionManager(QGuiApplication *app, QString &id, QString &key)
diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp
index b5cd342138..6039101cf4 100644
--- a/src/gui/kernel/qshortcutmap.cpp
+++ b/src/gui/kernel/qshortcutmap.cpp
@@ -45,13 +45,13 @@
#include "qvector.h"
#include "qcoreapplication.h"
#include <private/qkeymapper_p.h>
+#include <QtCore/qloggingcategory.h>
#include <algorithm>
QT_BEGIN_NAMESPACE
-// To enable verbose output uncomment below
-//#define DEBUG_QSHORTCUTMAP
+Q_LOGGING_CATEGORY(lcShortcutMap, "qt.gui.shortcutmap")
/* \internal
Entry data for QShortcutMap
@@ -63,11 +63,11 @@ QT_BEGIN_NAMESPACE
struct QShortcutEntry
{
QShortcutEntry()
- : keyseq(0), context(Qt::WindowShortcut), enabled(false), autorepeat(1), id(0), owner(0), contextMatcher(0)
+ : keyseq(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(0), contextMatcher(0)
+ : keyseq(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)
@@ -163,11 +163,9 @@ int QShortcutMap::addShortcut(QObject *owner, const QKeySequence &key, Qt::Short
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
-#if defined(DEBUG_QSHORTCUTMAP)
- qDebug().nospace()
+ qCDebug(lcShortcutMap).nospace()
<< "QShortcutMap::addShortcut(" << owner << ", "
<< key << ", " << context << ") = " << d->currentId;
-#endif
return d->currentId;
}
@@ -184,7 +182,7 @@ int QShortcutMap::removeShortcut(int id, QObject *owner, const QKeySequence &key
{
Q_D(QShortcutMap);
int itemsRemoved = 0;
- bool allOwners = (owner == 0);
+ bool allOwners = (owner == nullptr);
bool allKeys = key.isEmpty();
bool allIds = id == 0;
@@ -210,11 +208,9 @@ int QShortcutMap::removeShortcut(int id, QObject *owner, const QKeySequence &key
return itemsRemoved;
--i;
}
-#if defined(DEBUG_QSHORTCUTMAP)
- qDebug().nospace()
+ qCDebug(lcShortcutMap).nospace()
<< "QShortcutMap::removeShortcut(" << id << ", " << owner << ", "
<< key << ") = " << itemsRemoved;
-#endif
return itemsRemoved;
}
@@ -230,7 +226,7 @@ int QShortcutMap::setShortcutEnabled(bool enable, int id, QObject *owner, const
{
Q_D(QShortcutMap);
int itemsChanged = 0;
- bool allOwners = (owner == 0);
+ bool allOwners = (owner == nullptr);
bool allKeys = key.isEmpty();
bool allIds = id == 0;
@@ -248,11 +244,9 @@ int QShortcutMap::setShortcutEnabled(bool enable, int id, QObject *owner, const
return itemsChanged;
--i;
}
-#if defined(DEBUG_QSHORTCUTMAP)
- qDebug().nospace()
+ qCDebug(lcShortcutMap).nospace()
<< "QShortcutMap::setShortcutEnabled(" << enable << ", " << id << ", "
<< owner << ", " << key << ") = " << itemsChanged;
-#endif
return itemsChanged;
}
@@ -268,7 +262,7 @@ int QShortcutMap::setShortcutAutoRepeat(bool on, int id, QObject *owner, const Q
{
Q_D(QShortcutMap);
int itemsChanged = 0;
- bool allOwners = (owner == 0);
+ bool allOwners = (owner == nullptr);
bool allKeys = key.isEmpty();
bool allIds = id == 0;
@@ -286,11 +280,9 @@ int QShortcutMap::setShortcutAutoRepeat(bool on, int id, QObject *owner, const Q
return itemsChanged;
--i;
}
-#if defined(DEBUG_QSHORTCUTMAP)
- qDebug().nospace()
+ qCDebug(lcShortcutMap).nospace()
<< "QShortcutMap::setShortcutAutoRepeat(" << on << ", " << id << ", "
<< owner << ", " << key << ") = " << itemsChanged;
-#endif
return itemsChanged;
}
@@ -393,9 +385,7 @@ QKeySequence::SequenceMatch QShortcutMap::nextState(QKeyEvent *e)
clearSequence(d->currentSequences);
d->currentState = result;
-#if defined(DEBUG_QSHORTCUTMAP)
- qDebug().nospace() << "QShortcutMap::nextState(" << e << ") = " << result;
-#endif
+ qCDebug(lcShortcutMap).nospace() << "QShortcutMap::nextState(" << e << ") = " << result;
return result;
}
@@ -434,9 +424,7 @@ QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e, int ignoredModifier
return QKeySequence::NoMatch;
createNewSequences(e, d->newEntries, ignoredModifiers);
-#if defined(DEBUG_QSHORTCUTMAP)
- qDebug() << "Possible shortcut key sequences:" << d->newEntries;
-#endif
+ qCDebug(lcShortcutMap) << "Possible shortcut key sequences:" << d->newEntries;
// Should never happen
if (d->newEntries == d->currentSequences) {
@@ -489,15 +477,11 @@ QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e, int ignoredModifier
// previous list. If this match is equal or better than the last match, append to the list
if (oneKSResult > result) {
okEntries.clear();
-#if defined(DEBUG_QSHORTCUTMAP)
- qDebug() << "Found better match (" << d->newEntries << "), clearing key sequence list";
-#endif
+ qCDebug(lcShortcutMap) << "Found better match (" << d->newEntries << "), clearing key sequence list";
}
if (oneKSResult && oneKSResult >= result) {
okEntries << d->newEntries.at(i);
-#if defined(DEBUG_QSHORTCUTMAP)
- qDebug() << "Added ok key sequence" << d->newEntries;
-#endif
+ qCDebug(lcShortcutMap) << "Added ok key sequence" << d->newEntries;
}
}
@@ -513,9 +497,7 @@ QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e, int ignoredModifier
}
if (result != QKeySequence::NoMatch)
d->currentSequences = okEntries;
-#if defined(DEBUG_QSHORTCUTMAP)
- qDebug() << "Returning shortcut match == " << result;
-#endif
+ qCDebug(lcShortcutMap) << "Returning shortcut match == " << result;
return QKeySequence::SequenceMatch(result);
}
@@ -538,19 +520,16 @@ void QShortcutMap::createNewSequences(QKeyEvent *e, QVector<QKeySequence> &ksl,
{
Q_D(QShortcutMap);
QList<int> possibleKeys = QKeyMapper::possibleKeys(e);
-#if defined(DEBUG_QSHORTCUTMAP)
- {
- QDebug debug = qDebug().nospace();
- debug << __FUNCTION__ << '(' << e << ", ignoredModifiers="
+ if (lcShortcutMap().isDebugEnabled()) {
+ qCDebug(lcShortcutMap).nospace() << __FUNCTION__ << '(' << e << ", ignoredModifiers="
<< Qt::KeyboardModifiers(ignoredModifiers) << "), possibleKeys=(";
for (int i = 0, size = possibleKeys.size(); i < size; ++i) {
if (i)
- debug << ", ";
- debug << QKeySequence(possibleKeys.at(i));
+ qCDebug(lcShortcutMap).nospace() << ", ";
+ qCDebug(lcShortcutMap).nospace() << QKeySequence(possibleKeys.at(i));
}
- debug << ')';
+ qCDebug(lcShortcutMap).nospace() << ')';
}
-#endif // DEBUG_QSHORTCUTMAP
int pkTotal = possibleKeys.count();
if (!pkTotal)
return;
@@ -657,18 +636,15 @@ void QShortcutMap::dispatchEvent(QKeyEvent *e)
d->prevSequence = curKey;
}
// Find next
- const QShortcutEntry *current = 0, *next = 0;
+ const QShortcutEntry *current = nullptr, *next = nullptr;
int i = 0, enabledShortcuts = 0;
-#if defined(DEBUG_QSHORTCUTMAP)
QVector<const QShortcutEntry*> ambiguousShortcuts;
-#endif
while(i < d->identicals.size()) {
current = d->identicals.at(i);
if (current->enabled || !next){
++enabledShortcuts;
-#if defined(DEBUG_QSHORTCUTMAP)
- ambiguousShortcuts.append(current);
-#endif
+ if (lcShortcutMap().isDebugEnabled())
+ ambiguousShortcuts.append(current);
if (enabledShortcuts > d->ambigCount + 1)
break;
next = current;
@@ -681,19 +657,18 @@ void QShortcutMap::dispatchEvent(QKeyEvent *e)
if (!next || (e->isAutoRepeat() && !next->autorepeat))
return;
// Dispatch next enabled
-#if defined(DEBUG_QSHORTCUTMAP)
- if (ambiguousShortcuts.size() > 1) {
- qDebug() << "The following shortcuts are about to be activated ambiguously:";
- for (const QShortcutEntry *entry : qAsConst(ambiguousShortcuts)) {
- qDebug().nospace() << "- " << entry->keyseq << " (belonging to " << entry->owner << ")";
+ 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 << ")";
}
- }
- qDebug().nospace()
- << "QShortcutMap::dispatchEvent(): Sending QShortcutEvent(\""
- << next->keyseq.toString() << "\", " << next->id << ", "
- << (bool)(enabledShortcuts>1) << ") to object(" << next->owner << ')';
-#endif
+ qCDebug(lcShortcutMap).nospace()
+ << "QShortcutMap::dispatchEvent(): Sending QShortcutEvent(\""
+ << next->keyseq.toString() << "\", " << next->id << ", "
+ << static_cast<bool>(enabledShortcuts>1) << ") to object(" << next->owner << ')';
+ }
QShortcutEvent se(next->keyseq, next->id, enabledShortcuts>1);
QCoreApplication::sendEvent(const_cast<QObject *>(next->owner), &se);
}
diff --git a/src/gui/kernel/qsimpledrag.cpp b/src/gui/kernel/qsimpledrag.cpp
index d3070a3d1a..dec3cc399d 100644
--- a/src/gui/kernel/qsimpledrag.cpp
+++ b/src/gui/kernel/qsimpledrag.cpp
@@ -76,7 +76,7 @@ static QWindow* topLevelAt(const QPoint &pos)
if (w->isVisible() && w->handle() && w->geometry().contains(pos) && !qobject_cast<QShapedPixmapWindow*>(w))
return w;
}
- return 0;
+ return nullptr;
}
/*!
@@ -393,7 +393,7 @@ void QSimpleDrag::startDrag()
static void sendDragLeave(QWindow *window)
{
- QWindowSystemInterface::handleDrag(window, nullptr, QPoint(), Qt::IgnoreAction, 0, 0);
+ QWindowSystemInterface::handleDrag(window, nullptr, QPoint(), Qt::IgnoreAction, { }, { });
}
void QSimpleDrag::cancel()
diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp
index 732ede90d0..7b3c70c51b 100644
--- a/src/gui/kernel/qstylehints.cpp
+++ b/src/gui/kernel/qstylehints.cpp
@@ -116,7 +116,7 @@ public:
\sa QGuiApplication::styleHints()
*/
QStyleHints::QStyleHints()
- : QObject(*new QStyleHintsPrivate(), 0)
+ : QObject(*new QStyleHintsPrivate(), nullptr)
{
}
diff --git a/src/gui/kernel/qsurface.cpp b/src/gui/kernel/qsurface.cpp
index 709f28d431..85c576b21c 100644
--- a/src/gui/kernel/qsurface.cpp
+++ b/src/gui/kernel/qsurface.cpp
@@ -134,7 +134,7 @@ bool QSurface::supportsOpenGL() const
Creates a surface with the given \a type.
*/
QSurface::QSurface(SurfaceClass type)
- : m_type(type), m_reserved(0)
+ : m_type(type), m_reserved(nullptr)
{
}
diff --git a/src/gui/kernel/qsurfaceformat.cpp b/src/gui/kernel/qsurfaceformat.cpp
index 238886220b..571b820409 100644
--- a/src/gui/kernel/qsurfaceformat.cpp
+++ b/src/gui/kernel/qsurfaceformat.cpp
@@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE
class QSurfaceFormatPrivate
{
public:
- explicit QSurfaceFormatPrivate(QSurfaceFormat::FormatOptions _opts = 0)
+ explicit QSurfaceFormatPrivate(QSurfaceFormat::FormatOptions _opts = { })
: ref(1)
, opts(_opts)
, redBufferSize(-1)
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index b71a0c54aa..dad1b6ba2d 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -156,7 +156,7 @@ QT_BEGIN_NAMESPACE
\sa setScreen()
*/
QWindow::QWindow(QScreen *targetScreen)
- : QObject(*new QWindowPrivate(), 0)
+ : QObject(*new QWindowPrivate(), nullptr)
, QSurface(QSurface::Window)
{
Q_D(QWindow);
@@ -223,7 +223,7 @@ QWindow::~QWindow()
// some cases end up becoming the focus window again. Clear it again
// here as a workaround. See QTBUG-75326.
if (QGuiApplicationPrivate::focus_window == this)
- QGuiApplicationPrivate::focus_window = 0;
+ QGuiApplicationPrivate::focus_window = nullptr;
}
void QWindowPrivate::init(QScreen *targetScreen)
@@ -469,7 +469,7 @@ inline bool QWindowPrivate::windowRecreationRequired(QScreen *newScreen) const
inline void QWindowPrivate::disconnectFromScreen()
{
if (topLevelScreen)
- topLevelScreen = 0;
+ topLevelScreen = nullptr;
}
void QWindowPrivate::connectToScreen(QScreen *screen)
@@ -732,7 +732,7 @@ void QWindow::setParent(QWindow *parent)
if (parent)
parent->create();
- d->platformWindow->setParent(parent ? parent->d_func()->platformWindow : 0);
+ d->platformWindow->setParent(parent ? parent->d_func()->platformWindow : nullptr);
}
QGuiApplicationPrivate::updateBlockedStatus(this);
@@ -744,7 +744,7 @@ void QWindow::setParent(QWindow *parent)
bool QWindow::isTopLevel() const
{
Q_D(const QWindow);
- return d->parentWindow == 0;
+ return d->parentWindow == nullptr;
}
/*!
@@ -1344,7 +1344,7 @@ Qt::WindowStates QWindow::windowStates() const
This is a hint to the window manager that this window is a dialog or pop-up
on behalf of the transient parent.
- In order to cause the window to be centered above its transient parent by
+ In order to cause the window to be centered above its transient \a parent by
default, depending on the window manager, it may also be necessary to call
setFlags() with a suitable \l Qt::WindowType (such as \c Qt::Dialog).
@@ -2018,7 +2018,7 @@ void QWindow::setScreen(QScreen *newScreen)
Q_D(QWindow);
if (!newScreen)
newScreen = QGuiApplication::primaryScreen();
- d->setTopLevelScreen(newScreen, newScreen != 0);
+ d->setTopLevelScreen(newScreen, newScreen != nullptr);
}
/*!
@@ -2036,7 +2036,7 @@ void QWindow::setScreen(QScreen *newScreen)
*/
QAccessibleInterface *QWindow::accessibleRoot() const
{
- return 0;
+ return nullptr;
}
/*!
@@ -2690,13 +2690,12 @@ QOpenGLContext *QWindowPrivate::shareContext() const
platform dependent and untested.
\sa setParent()
- \sa setTransientParent()
*/
QWindow *QWindow::fromWinId(WId id)
{
if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) {
qWarning("QWindow::fromWinId(): platform plugin does not support foreign windows.");
- return 0;
+ return nullptr;
}
QWindow *window = new QWindow;
@@ -2770,7 +2769,7 @@ void QWindow::setCursor(const QCursor &cursor)
void QWindow::unsetCursor()
{
Q_D(QWindow);
- d->setCursor(0);
+ d->setCursor(nullptr);
}
/*!
diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp
index 286dfaa8cc..2de0131640 100644
--- a/src/gui/kernel/qwindowsysteminterface.cpp
+++ b/src/gui/kernel/qwindowsysteminterface.cpp
@@ -46,7 +46,9 @@
#include <qpa/qplatformintegration.h>
#include <qdebug.h>
#include "qhighdpiscaling_p.h"
+
#include <QtCore/qscopedvaluerollback.h>
+#include <QtCore/private/qlocking_p.h>
#if QT_CONFIG(draganddrop)
#include <qpa/qplatformdrag.h>
@@ -179,7 +181,7 @@ void QWindowSystemInterfacePrivate::installWindowSystemEventHandler(QWindowSyste
void QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(QWindowSystemEventHandler *handler)
{
if (eventHandler == handler)
- eventHandler = 0;
+ eventHandler = nullptr;
}
QWindowSystemEventHandler::~QWindowSystemEventHandler()
@@ -623,7 +625,7 @@ bool QWindowSystemInterface::isTouchDeviceRegistered(const QTouchDevice *device)
static int g_nextPointId = 1;
// map from device-independent point id (arbitrary) to "Qt point" ids
-QMutex QWindowSystemInterfacePrivate::pointIdMapMutex;
+static QBasicMutex pointIdMapMutex;
typedef QMap<quint64, int> PointIdMap;
Q_GLOBAL_STATIC(PointIdMap, g_pointIdMap)
@@ -641,7 +643,7 @@ Q_GLOBAL_STATIC(PointIdMap, g_pointIdMap)
*/
static int acquireCombinedPointId(quint8 deviceId, int pointId)
{
- QMutexLocker locker(&QWindowSystemInterfacePrivate::pointIdMapMutex);
+ const auto locker = qt_scoped_lock(pointIdMapMutex);
quint64 combinedId64 = (quint64(deviceId) << 32) + pointId;
auto it = g_pointIdMap->constFind(combinedId64);
@@ -702,7 +704,7 @@ QList<QTouchEvent::TouchPoint>
}
if (states == Qt::TouchPointReleased) {
- QMutexLocker locker(&QWindowSystemInterfacePrivate::pointIdMapMutex);
+ const auto locker = qt_scoped_lock(pointIdMapMutex);
// All points on deviceId have been released.
// Remove all points associated with that device from g_pointIdMap.
@@ -723,7 +725,7 @@ QList<QTouchEvent::TouchPoint>
void QWindowSystemInterfacePrivate::clearPointIdMap()
{
- QMutexLocker locker(&QWindowSystemInterfacePrivate::pointIdMapMutex);
+ const auto locker = qt_scoped_lock(pointIdMapMutex);
g_pointIdMap->clear();
g_nextPointId = 1;
}
@@ -880,10 +882,10 @@ void QWindowSystemInterface::handleScreenRefreshRateChange(QScreen *screen, qrea
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
-void QWindowSystemInterface::handleThemeChange(QWindow *window)
+QT_DEFINE_QPA_EVENT_HANDLER(void, handleThemeChange, QWindow *window)
{
QWindowSystemInterfacePrivate::ThemeChangeEvent *e = new QWindowSystemInterfacePrivate::ThemeChangeEvent(window);
- QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+ QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
}
#if QT_CONFIG(draganddrop)
diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h
index d5a4ad30d8..95e20f0f8b 100644
--- a/src/gui/kernel/qwindowsysteminterface.h
+++ b/src/gui/kernel/qwindowsysteminterface.h
@@ -249,6 +249,7 @@ public:
static void handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal newDpiX, qreal newDpiY);
static void handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate);
+ template<typename Delivery = QWindowSystemInterface::DefaultDelivery>
static void handleThemeChange(QWindow *window);
static void handleFileOpenEvent(const QString& fileName);
diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h
index 6e4bce607e..dd6f29b41f 100644
--- a/src/gui/kernel/qwindowsysteminterface_p.h
+++ b/src/gui/kernel/qwindowsysteminterface_p.h
@@ -529,7 +529,6 @@ public:
static QWaitCondition eventsFlushed;
static QMutex flushEventMutex;
- static QMutex pointIdMapMutex;
static QAtomicInt eventAccepted;
static QList<QTouchEvent::TouchPoint>