Propagate appearance property from QPlatformTheme to QStyleHints
Implement appearance property, getter and notifier in QStyleHints. Update appearance property in QStyleHints when handling theme change in QGuiApplicationPrivate. Task-number: QTBUG-106381 Change-Id: Idd67ca9df248ec9d9e67c0d48121e8eead11a9e2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
ac2154c7e9
commit
d35feca20c
@ -132,7 +132,7 @@ qt_internal_add_module(Gui
|
||||
kernel/qrasterwindow.cpp kernel/qrasterwindow.h
|
||||
kernel/qscreen.cpp kernel/qscreen.h kernel/qscreen_p.h
|
||||
kernel/qsessionmanager.cpp kernel/qsessionmanager.h kernel/qsessionmanager_p.h
|
||||
kernel/qstylehints.cpp kernel/qstylehints.h
|
||||
kernel/qstylehints.cpp kernel/qstylehints.h kernel/qstylehints_p.h
|
||||
kernel/qsurface.cpp kernel/qsurface.h
|
||||
kernel/qsurfaceformat.cpp kernel/qsurfaceformat.h
|
||||
kernel/qtestsupport_gui.cpp kernel/qtestsupport_gui.h
|
||||
|
@ -41,6 +41,7 @@
|
||||
|
||||
#include <QtGui/qgenericpluginfactory.h>
|
||||
#include <QtGui/qstylehints.h>
|
||||
#include <QtGui/private/qstylehints_p.h>
|
||||
#include <QtGui/qinputmethod.h>
|
||||
#include <QtGui/qpixmapcache.h>
|
||||
#include <qpa/qplatforminputcontext.h>
|
||||
@ -2553,6 +2554,21 @@ void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::
|
||||
const QWindowList windows = tce->window ? QWindowList{tce->window} : window_list;
|
||||
for (auto *window : windows)
|
||||
QGuiApplication::sendSpontaneousEvent(window, &themeChangeEvent);
|
||||
|
||||
QStyleHintsPrivate::get(QGuiApplication::styleHints())->setAppearance(appearance());
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
\brief QGuiApplicationPrivate::appearance
|
||||
\return the platform theme's appearance
|
||||
or Qt::Appearance::Unknown if a platform theme cannot be established
|
||||
Qt::Appearance.
|
||||
*/
|
||||
Qt::Appearance QGuiApplicationPrivate::appearance()
|
||||
{
|
||||
return platformTheme() ? platformTheme()->appearance()
|
||||
: Qt::Appearance::Unknown;
|
||||
}
|
||||
|
||||
void QGuiApplicationPrivate::handleThemeChanged()
|
||||
|
@ -313,6 +313,8 @@ private:
|
||||
|
||||
friend class QDragManager;
|
||||
|
||||
static Qt::Appearance appearance();
|
||||
|
||||
static QGuiApplicationPrivate *self;
|
||||
static int m_fakeMouseSourcePointId;
|
||||
#ifdef Q_OS_WIN
|
||||
|
@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#include <qstylehints.h>
|
||||
#include "qstylehints_p.h"
|
||||
#include <qpa/qplatformintegration.h>
|
||||
#include <qpa/qplatformtheme.h>
|
||||
#include <private/qguiapplication_p.h>
|
||||
@ -43,25 +44,6 @@ static inline QVariant themeableHint(QPlatformTheme::ThemeHint th)
|
||||
return QPlatformTheme::defaultThemeHint(th);
|
||||
}
|
||||
|
||||
class QStyleHintsPrivate : public QObjectPrivate
|
||||
{
|
||||
Q_DECLARE_PUBLIC(QStyleHints)
|
||||
public:
|
||||
int m_mouseDoubleClickInterval = -1;
|
||||
int m_mousePressAndHoldInterval = -1;
|
||||
int m_startDragDistance = -1;
|
||||
int m_startDragTime = -1;
|
||||
int m_keyboardInputInterval = -1;
|
||||
int m_cursorFlashTime = -1;
|
||||
int m_tabFocusBehavior = -1;
|
||||
int m_uiEffects = -1;
|
||||
int m_showShortcutsInContextMenus = -1;
|
||||
int m_wheelScrollLines = -1;
|
||||
int m_mouseQuickSelectionThreshold = -1;
|
||||
int m_mouseDoubleClickDistance = -1;
|
||||
int m_touchDoubleTapDistance = -1;
|
||||
};
|
||||
|
||||
/*!
|
||||
\class QStyleHints
|
||||
\since 5.0
|
||||
@ -139,6 +121,17 @@ int QStyleHints::touchDoubleTapDistance() const
|
||||
themeableHint(QPlatformTheme::TouchDoubleTapDistance).toInt();
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QStyleHints::appearance
|
||||
\brief the appearance of the platform theme
|
||||
\sa Qt::Appearance
|
||||
\since 6.5
|
||||
*/
|
||||
Qt::Appearance QStyleHints::appearance() const
|
||||
{
|
||||
return d_func()->appearance();
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the \a mousePressAndHoldInterval.
|
||||
\internal
|
||||
@ -583,6 +576,26 @@ int QStyleHints::mouseQuickSelectionThreshold() const
|
||||
return themeableHint(QPlatformTheme::MouseQuickSelectionThreshold, QPlatformIntegration::MouseQuickSelectionThreshold).toInt();
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
QStyleHintsPrivate::setAppearance - set a new appearance.
|
||||
Set \a appearance as the new appearance of the QStyleHints.
|
||||
The appearanceChanged signal will be emitted if present and new appearance differ.
|
||||
*/
|
||||
void QStyleHintsPrivate::setAppearance(Qt::Appearance appearance)
|
||||
{
|
||||
if (m_appearance != appearance) {
|
||||
m_appearance = appearance;
|
||||
emit q_func()->appearanceChanged(appearance);
|
||||
}
|
||||
}
|
||||
|
||||
QStyleHintsPrivate *QStyleHintsPrivate::get(QStyleHints *q)
|
||||
{
|
||||
Q_ASSERT(q);
|
||||
return q->d_func();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "moc_qstylehints.cpp"
|
||||
|
@ -49,6 +49,7 @@ 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::Appearance appearance READ appearance NOTIFY appearanceChanged FINAL)
|
||||
|
||||
public:
|
||||
void setMouseDoubleClickInterval(int mouseDoubleClickInterval);
|
||||
@ -85,6 +86,7 @@ public:
|
||||
void setWheelScrollLines(int scrollLines);
|
||||
void setMouseQuickSelectionThreshold(int threshold);
|
||||
int mouseQuickSelectionThreshold() const;
|
||||
Qt::Appearance appearance() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void cursorFlashTimeChanged(int cursorFlashTime);
|
||||
@ -98,6 +100,7 @@ Q_SIGNALS:
|
||||
void showShortcutsInContextMenusChanged(bool);
|
||||
void wheelScrollLinesChanged(int scrollLines);
|
||||
void mouseQuickSelectionThresholdChanged(int threshold);
|
||||
void appearanceChanged(Qt::Appearance appearance);
|
||||
|
||||
private:
|
||||
friend class QGuiApplication;
|
||||
|
53
src/gui/kernel/qstylehints_p.h
Normal file
53
src/gui/kernel/qstylehints_p.h
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright (C) 2022 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#ifndef QSTYLEHINTS_P_H
|
||||
#define QSTYLEHINTS_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <qpa/qplatformintegration.h>
|
||||
#include <QPalette>
|
||||
#include <private/qguiapplication_p.h>
|
||||
#include "qstylehints.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QStyleHintsPrivate : public QObjectPrivate
|
||||
{
|
||||
Q_DECLARE_PUBLIC(QStyleHints)
|
||||
public:
|
||||
int m_mouseDoubleClickInterval = -1;
|
||||
int m_mousePressAndHoldInterval = -1;
|
||||
int m_startDragDistance = -1;
|
||||
int m_startDragTime = -1;
|
||||
int m_keyboardInputInterval = -1;
|
||||
int m_cursorFlashTime = -1;
|
||||
int m_tabFocusBehavior = -1;
|
||||
int m_uiEffects = -1;
|
||||
int m_showShortcutsInContextMenus = -1;
|
||||
int m_wheelScrollLines = -1;
|
||||
int m_mouseQuickSelectionThreshold = -1;
|
||||
int m_mouseDoubleClickDistance = -1;
|
||||
int m_touchDoubleTapDistance = -1;
|
||||
|
||||
Qt::Appearance appearance() const { return m_appearance; };
|
||||
void setAppearance(Qt::Appearance appearance);
|
||||
static QStyleHintsPrivate *get(QStyleHints *q);
|
||||
|
||||
private:
|
||||
Qt::Appearance m_appearance = Qt::Appearance::Unknown;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user