diff options
Diffstat (limited to 'src/gui/kernel')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 48 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication.h | 2 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication_p.h | 2 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication_platform.h | 30 | ||||
-rw-r--r-- | src/gui/kernel/qguivariant.cpp | 2 | ||||
-rw-r--r-- | src/gui/kernel/qhighdpiscaling_p.h | 4 | ||||
-rw-r--r-- | src/gui/kernel/qplatformtheme.cpp | 5 | ||||
-rw-r--r-- | src/gui/kernel/qplatformtheme.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qstylehints.cpp | 83 | ||||
-rw-r--r-- | src/gui/kernel/qstylehints.h | 10 | ||||
-rw-r--r-- | src/gui/kernel/qstylehints_p.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 8 | ||||
-rw-r--r-- | src/gui/kernel/qwindow_p.h | 10 |
13 files changed, 176 insertions, 30 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 444091afef..5228ac9477 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2643,28 +2643,18 @@ void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate:: QIconPrivate::clearIconCache(); - QStyleHintsPrivate::get(QGuiApplication::styleHints())->updateColorScheme(colorScheme()); - QEvent themeChangeEvent(QEvent::ThemeChange); const QWindowList windows = tce->window ? QWindowList{tce->window} : window_list; for (auto *window : windows) QGuiApplication::sendSpontaneousEvent(window, &themeChangeEvent); } -/*! - \internal - \brief QGuiApplicationPrivate::colorScheme - \return the platform theme's color scheme - or Qt::ColorScheme::Unknown if a platform theme cannot be established - */ -Qt::ColorScheme QGuiApplicationPrivate::colorScheme() -{ - return platformTheme() ? platformTheme()->colorScheme() - : Qt::ColorScheme::Unknown; -} - void QGuiApplicationPrivate::handleThemeChanged() { + const auto newColorScheme = platformTheme() ? platformTheme()->colorScheme() + : Qt::ColorScheme::Unknown; + QStyleHintsPrivate::get(QGuiApplication::styleHints())->updateColorScheme(newColorScheme); + updatePalette(); QIconLoader::instance()->updateSystemTheme(); @@ -3457,6 +3447,15 @@ void QGuiApplicationPrivate::updatePalette() } } +QEvent::Type QGuiApplicationPrivate::contextMenuEventType() +{ + switch (QGuiApplication::styleHints()->contextMenuTrigger()) { + case Qt::ContextMenuTrigger::Press: return QEvent::MouseButtonPress; + case Qt::ContextMenuTrigger::Release: return QEvent::MouseButtonRelease; + } + return QEvent::None; +} + void QGuiApplicationPrivate::clearPalette() { delete app_pal; @@ -3675,9 +3674,13 @@ void QGuiApplicationPrivate::notifyWindowIconChanged() The default is \c true. - If this property is \c true, the applications quits when the last visible - \l{Primary and Secondary Windows}{primary window} (i.e. top level window - with no transient parent) is closed. + If this property is \c true, the application will attempt to + quit when the last visible \l{Primary and Secondary Windows}{primary window} + (i.e. top level window with no transient parent) is closed. + + Note that attempting a quit may not necessarily result in the + application quitting, for example if there still are active + QEventLoopLocker instances, or the QEvent::Quit event is ignored. \sa quit(), QWindow::close() */ @@ -3733,7 +3736,13 @@ bool QGuiApplicationPrivate::lastWindowClosed() const bool QGuiApplicationPrivate::canQuitAutomatically() { - if (quitOnLastWindowClosed && !lastWindowClosed()) + // The automatic quit functionality is triggered by + // both QEventLoopLocker and maybeLastWindowClosed. + // Although the former is a QCoreApplication feature + // we don't want to quit the application when there + // are open windows, regardless of whether the app + // also quits automatically on maybeLastWindowClosed. + if (!lastWindowClosed()) return false; return QCoreApplicationPrivate::canQuitAutomatically(); @@ -4392,6 +4401,9 @@ void *QGuiApplication::resolveInterface(const char *name, int revision) const #if QT_CONFIG(wayland) QT_NATIVE_INTERFACE_RETURN_IF(QWaylandApplication, platformNativeInterface()); #endif +#if defined(Q_OS_VISIONOS) + QT_NATIVE_INTERFACE_RETURN_IF(QVisionOSApplication, platformIntegration); +#endif return QCoreApplication::resolveInterface(name, revision); } diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h index 14bce88c62..23d7fb3d65 100644 --- a/src/gui/kernel/qguiapplication.h +++ b/src/gui/kernel/qguiapplication.h @@ -42,7 +42,7 @@ class Q_GUI_EXPORT QGuiApplication : public QCoreApplication Q_PROPERTY(QString desktopFileName READ desktopFileName WRITE setDesktopFileName) Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged) - Q_PROPERTY(QString platformName READ platformName STORED false) + Q_PROPERTY(QString platformName READ platformName STORED false CONSTANT) Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed) Q_PROPERTY(QScreen *primaryScreen READ primaryScreen NOTIFY primaryScreenChanged STORED false) diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 2bfcd87f3f..39c490c581 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -323,7 +323,7 @@ public: static void updatePalette(); - static Qt::ColorScheme colorScheme(); + static QEvent::Type contextMenuEventType(); protected: virtual void handleThemeChanged(); diff --git a/src/gui/kernel/qguiapplication_platform.h b/src/gui/kernel/qguiapplication_platform.h index 545bf75c84..d9ff01bf14 100644 --- a/src/gui/kernel/qguiapplication_platform.h +++ b/src/gui/kernel/qguiapplication_platform.h @@ -32,6 +32,22 @@ struct wl_pointer; struct wl_touch; #endif +#if defined(Q_OS_VISIONOS) || defined(Q_QDOC) +# ifdef __OBJC__ +Q_FORWARD_DECLARE_OBJC_CLASS(CP_OBJECT_cp_layer_renderer_capabilities); +typedef CP_OBJECT_cp_layer_renderer_capabilities *cp_layer_renderer_capabilities_t; +Q_FORWARD_DECLARE_OBJC_CLASS(CP_OBJECT_cp_layer_renderer_configuration); +typedef CP_OBJECT_cp_layer_renderer_configuration *cp_layer_renderer_configuration_t; +Q_FORWARD_DECLARE_OBJC_CLASS(CP_OBJECT_cp_layer_renderer); +typedef CP_OBJECT_cp_layer_renderer *cp_layer_renderer_t; +# else +typedef struct cp_layer_renderer_capabilities_s *cp_layer_renderer_capabilities_t; +typedef struct cp_layer_renderer_configuration_s *cp_layer_renderer_configuration_t; +typedef struct cp_layer_renderer_s *cp_layer_renderer_t; +# endif +#endif + + QT_BEGIN_NAMESPACE namespace QNativeInterface @@ -61,6 +77,20 @@ struct Q_GUI_EXPORT QWaylandApplication }; #endif +#if defined(Q_OS_VISIONOS) || defined(Q_QDOC) +struct Q_GUI_EXPORT QVisionOSApplication +{ + QT_DECLARE_NATIVE_INTERFACE(QVisionOSApplication, 1, QGuiApplication) + struct ImmersiveSpaceCompositorLayer { + virtual void configure(cp_layer_renderer_capabilities_t, cp_layer_renderer_configuration_t) const {} + virtual void render(cp_layer_renderer_t) = 0; + }; + virtual void setImmersiveSpaceCompositorLayer(ImmersiveSpaceCompositorLayer *layer) = 0; + virtual void openImmersiveSpace() = 0; + virtual void dismissImmersiveSpace() = 0; +}; +#endif + } // QNativeInterface QT_END_NAMESPACE diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index fe72e7782f..78a1660355 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -78,7 +78,9 @@ static constexpr struct : QMetaTypeModuleHelper // either two nullptrs from canConvert, or two valid pointers Q_ASSERT(onlyCheck || (bool(from) && bool(to))); +#if QT_CONFIG(shortcut) using Int = int; +#endif switch (makePair(toTypeId, fromTypeId)) { QMETATYPE_CONVERTER(QByteArray, QColor, result = source.name(source.alpha() != 255 ? diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h index 189f31fd0a..d6deb8a72a 100644 --- a/src/gui/kernel/qhighdpiscaling_p.h +++ b/src/gui/kernel/qhighdpiscaling_p.h @@ -172,7 +172,7 @@ inline QMargins scale(const QMargins &margins, qreal scaleFactor, QPoint origin template<typename T> QList<T> scale(const QList<T> &list, qreal scaleFactor, QPoint origin = QPoint(0, 0)) { - if (!QHighDpiScaling::isActive()) + if (qFuzzyCompare(scaleFactor, qreal(1))) return list; QList<T> scaled; @@ -184,7 +184,7 @@ QList<T> scale(const QList<T> &list, qreal scaleFactor, QPoint origin = QPoint(0 inline QRegion scale(const QRegion ®ion, qreal scaleFactor, QPoint origin = QPoint(0, 0)) { - if (!QHighDpiScaling::isActive()) + if (qFuzzyCompare(scaleFactor, qreal(1))) return region; QRegion scaled = region.translated(-origin); diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 48978b849a..3d1319615e 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -447,6 +447,11 @@ Qt::ColorScheme QPlatformTheme::colorScheme() const return Qt::ColorScheme::Unknown; } +void QPlatformTheme::requestColorScheme(Qt::ColorScheme scheme) +{ + Q_UNUSED(scheme); +} + const QPalette *QPlatformTheme::palette(Palette type) const { Q_D(const QPlatformTheme); diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index c0193947b9..d007a19675 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -295,6 +295,7 @@ public: #endif virtual Qt::ColorScheme colorScheme() const; + virtual void requestColorScheme(Qt::ColorScheme scheme); virtual const QPalette *palette(Palette type = SystemPalette) const; diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp index 5029701f24..73c6199733 100644 --- a/src/gui/kernel/qstylehints.cpp +++ b/src/gui/kernel/qstylehints.cpp @@ -123,8 +123,29 @@ int QStyleHints::touchDoubleTapDistance() const /*! \property QStyleHints::colorScheme - \brief the color scheme of the platform theme. - \sa Qt::ColorScheme + \brief the color scheme used by the application. + + By default, this follows the system's default color scheme (also known as appearance), + and changes when the system color scheme changes (e.g. during dusk or dawn). + Setting the color scheme to an explicit value will override the system setting and + ignore any changes to the system's color scheme. However, doing so is a hint to the + system, and overriding the color scheme is not supported on all platforms. + + Resetting this property, or setting it to \l{Qt::ColorScheme::Unknown}, will remove + the override and make the application follow the system default again. The property + value will change to the color scheme the system currently has. + + When this property changes, Qt will read the system palette and update the default + palette, but won't overwrite palette entries that have been explicitly set by the + application. When the colorSchemeChange() signal gets emitted, the old palette is + still in effect. + + Application-specific colors should be selected to work well with the effective + palette, taking the current color scheme into account. To update application- + specific colors when the effective palette changes, handle + \l{QEvent::}{PaletteChange} or \l{QEvent::}{ApplicationPaletteChange} events. + + \sa Qt::ColorScheme, QGuiApplication::palette(), QEvent::PaletteChange \since 6.5 */ Qt::ColorScheme QStyleHints::colorScheme() const @@ -134,6 +155,30 @@ Qt::ColorScheme QStyleHints::colorScheme() const } /*! + \since 6.8 + + Sets the color scheme used by the application to an explicit \a scheme, or + revert to the system's current color scheme if \a scheme is Qt::ColorScheme::Unknown. +*/ +void QStyleHints::setColorScheme(Qt::ColorScheme scheme) +{ + if (!QCoreApplication::instance()) { + qWarning("Must construct a QGuiApplication before accessing a platform theme hint."); + return; + } + if (QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + theme->requestColorScheme(scheme); +} + +/*! + \fn void QStyleHints::unsetColorScheme() + \since 6.8 + + Restores the color scheme to the system's current color scheme. +*/ + + +/*! Sets the \a mousePressAndHoldInterval. \internal \sa mousePressAndHoldInterval() @@ -398,6 +443,40 @@ void QStyleHints::setShowShortcutsInContextMenus(bool s) } /*! + \property QStyleHints::contextMenuTrigger + \since 6.8 + \brief mouse event used to trigger a context menu event. + + The default on UNIX systems is to show context menu on mouse button press event, while on + Windows it is the mouse button release event. This property can be used to override the default + platform behavior. + + \note Developers must use this property with great care, as it changes the default interaction + mode that their users will expect on the platform that they are running on. + + \sa Qt::ContextMenuTrigger +*/ +Qt::ContextMenuTrigger QStyleHints::contextMenuTrigger() const +{ + Q_D(const QStyleHints); + if (d->m_contextMenuTrigger == -1) { + return themeableHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() + ? Qt::ContextMenuTrigger::Release + : Qt::ContextMenuTrigger::Press; + } + return Qt::ContextMenuTrigger(d->m_contextMenuTrigger); +} + +void QStyleHints::setContextMenuTrigger(Qt::ContextMenuTrigger contextMenuTrigger) +{ + Q_D(QStyleHints); + const Qt::ContextMenuTrigger currentTrigger = this->contextMenuTrigger(); + d->m_contextMenuTrigger = int(contextMenuTrigger); + if (currentTrigger != contextMenuTrigger) + emit contextMenuTriggerChanged(contextMenuTrigger); +} + +/*! \property QStyleHints::passwordMaskDelay \brief the time, in milliseconds, a typed letter is displayed unshrouded in a text input field in password mode. diff --git a/src/gui/kernel/qstylehints.h b/src/gui/kernel/qstylehints.h index 969bec4b35..97ef59f3cf 100644 --- a/src/gui/kernel/qstylehints.h +++ b/src/gui/kernel/qstylehints.h @@ -36,6 +36,8 @@ class Q_GUI_EXPORT QStyleHints : public QObject Q_PROPERTY(bool showIsMaximized READ showIsMaximized STORED false CONSTANT FINAL) Q_PROPERTY(bool showShortcutsInContextMenus READ showShortcutsInContextMenus WRITE setShowShortcutsInContextMenus NOTIFY showShortcutsInContextMenusChanged FINAL) + Q_PROPERTY(Qt::ContextMenuTrigger contextMenuTrigger READ contextMenuTrigger WRITE + setContextMenuTrigger NOTIFY contextMenuTriggerChanged FINAL) Q_PROPERTY(int startDragDistance READ startDragDistance NOTIFY startDragDistanceChanged FINAL) Q_PROPERTY(int startDragTime READ startDragTime NOTIFY startDragTimeChanged FINAL) Q_PROPERTY(int startDragVelocity READ startDragVelocity STORED false CONSTANT FINAL) @@ -52,7 +54,8 @@ class Q_GUI_EXPORT QStyleHints : public QObject Q_PROPERTY(int mouseDoubleClickDistance READ mouseDoubleClickDistance STORED false CONSTANT FINAL) Q_PROPERTY(int touchDoubleTapDistance READ touchDoubleTapDistance STORED false CONSTANT FINAL) - Q_PROPERTY(Qt::ColorScheme colorScheme READ colorScheme NOTIFY colorSchemeChanged FINAL) + Q_PROPERTY(Qt::ColorScheme colorScheme READ colorScheme WRITE setColorScheme + RESET unsetColorScheme NOTIFY colorSchemeChanged FINAL) public: void setMouseDoubleClickInterval(int mouseDoubleClickInterval); @@ -79,6 +82,8 @@ public: bool showIsMaximized() const; bool showShortcutsInContextMenus() const; void setShowShortcutsInContextMenus(bool showShortcutsInContextMenus); + Qt::ContextMenuTrigger contextMenuTrigger() const; + void setContextMenuTrigger(Qt::ContextMenuTrigger contextMenuTrigger); int passwordMaskDelay() const; QChar passwordMaskCharacter() const; qreal fontSmoothingGamma() const; @@ -94,6 +99,8 @@ public: void setMouseQuickSelectionThreshold(int threshold); int mouseQuickSelectionThreshold() const; Qt::ColorScheme colorScheme() const; + void setColorScheme(Qt::ColorScheme scheme); + void unsetColorScheme() { setColorScheme(Qt::ColorScheme::Unknown); } Q_SIGNALS: void cursorFlashTimeChanged(int cursorFlashTime); @@ -105,6 +112,7 @@ Q_SIGNALS: void tabFocusBehaviorChanged(Qt::TabFocusBehavior tabFocusBehavior); void useHoverEffectsChanged(bool useHoverEffects); void showShortcutsInContextMenusChanged(bool); + void contextMenuTriggerChanged(Qt::ContextMenuTrigger contextMenuTrigger); void wheelScrollLinesChanged(int scrollLines); void mouseQuickSelectionThresholdChanged(int threshold); void colorSchemeChanged(Qt::ColorScheme colorScheme); diff --git a/src/gui/kernel/qstylehints_p.h b/src/gui/kernel/qstylehints_p.h index 2b3979512a..497bf95cbf 100644 --- a/src/gui/kernel/qstylehints_p.h +++ b/src/gui/kernel/qstylehints_p.h @@ -35,6 +35,7 @@ public: int m_tabFocusBehavior = -1; int m_uiEffects = -1; int m_showShortcutsInContextMenus = -1; + int m_contextMenuTrigger = -1; int m_wheelScrollLines = -1; int m_mouseQuickSelectionThreshold = -1; int m_mouseDoubleClickDistance = -1; diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index b40fd7e8e8..7c885032c7 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -2654,16 +2654,14 @@ bool QWindow::event(QEvent *ev) This logic could be simplified by always synthesizing events in QGuiApplicationPrivate, or perhaps even in each QPA plugin. See QTBUG-93486. */ - static const QEvent::Type contextMenuTrigger = - QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ? - QEvent::MouseButtonRelease : QEvent::MouseButtonPress; auto asMouseEvent = [](QEvent *ev) { const auto t = ev->type(); return t == QEvent::MouseButtonPress || t == QEvent::MouseButtonRelease ? static_cast<QMouseEvent *>(ev) : nullptr ; }; - if (QMouseEvent *me = asMouseEvent(ev); me && - ev->type() == contextMenuTrigger && me->button() == Qt::RightButton) { + if (QMouseEvent *me = asMouseEvent(ev); + me && ev->type() == QGuiApplicationPrivate::contextMenuEventType() + && me->button() == Qt::RightButton) { QContextMenuEvent e(QContextMenuEvent::Mouse, me->position().toPoint(), me->globalPosition().toPoint(), me->modifiers()); QGuiApplication::sendEvent(this, &e); diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h index a9716847a1..40ab06af8b 100644 --- a/src/gui/kernel/qwindow_p.h +++ b/src/gui/kernel/qwindow_p.h @@ -76,6 +76,16 @@ public: void setTransientParent(QWindow *parent); virtual void clearFocusObject(); + + enum class FocusTarget { + First, + Last, + Current, + Next, + Prev + }; + virtual void setFocusToTarget(FocusTarget, Qt::FocusReason) {} + virtual QRectF closestAcceptableGeometry(const QRectF &rect) const; void setMinOrMaxSize(QSize *oldSizeMember, const QSize &size, |