Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwasmtheme.h
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QWASMTHEME_H
6#define QWASMTHEME_H
7
8#include <qpa/qplatformtheme.h>
9#include <QtGui/QFont>
10
11#include <memory>
12
13#include <private/qstdweb_p.h>
14
16
17class QWasmEventTranslator;
18class QWasmFontDatabase;
19class QWasmWindow;
21class QWasmScreen;
22class QWasmCompositor;
24
25// this reflects @media/prefers-contrast
26constexpr auto colorSchemePreferenceDark = "(prefers-color-scheme: dark)";
27constexpr auto contrastPreferenceNoPreference = "(prefers-contrast: no-preference)";
28constexpr auto contrastPreferenceMore = "(prefers-contrast: more)";
29constexpr auto contrastPreferenceLess = "(prefers-contrast: less)";
30constexpr auto contrastPreferenceCustom = "(prefers-contrast: custom)";
31
32// this reflects @media/prefers-reduced-motion
33constexpr auto reducedMotionPreferenceReduce = "(prefers-reduced-motion: reduce)";
34
35template <typename MediaName, typename CallbackFn, typename Container>
36void registerCallbacks(std::initializer_list<MediaName> mediaNames, CallbackFn callback, Container &callbacksContainer)
37{
38 emscripten::val window = emscripten::val::global("window");
39 if (!window.isUndefined()) {
40 for (auto &&mediaName : mediaNames) {
41 auto media = window.call<emscripten::val>("matchMedia", emscripten::val(mediaName));
42 if constexpr (std::is_same_v<Container, std::vector<QWasmEventHandler>>) {
43 callbacksContainer.emplace_back(media, "change", callback);
44 } else {
45 Q_ASSERT(mediaNames.size() == 1);
46 callbacksContainer = QWasmEventHandler(media, "change", callback);
47 }
48 }
49 }
50}
51
53{
54public:
55 QWasmTheme();
56 ~QWasmTheme();
57
58 const QPalette *palette(Palette type = SystemPalette) const override;
59 Qt::ColorScheme colorScheme() const override;
60 void requestColorScheme(Qt::ColorScheme scheme) override;
62 Qt::MotionPreference motionPreference() const override;
63 QVariant themeHint(ThemeHint hint) const override;
64 const QFont *font(Font type) const override;
65 bool usePlatformNativeDialog(DialogType type) const override;
66 QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const override;
67
68 QFont *fixedFont = nullptr;
69
73
74private:
75 Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown;
76 QWasmEventHandler m_colorSchemeChangeCallback;
77 std::unique_ptr<QPalette> m_palette;
78 mutable bool m_paletteIsDirty = false;
79 Qt::ContrastPreference m_contrastPreference;
80 std::vector<QWasmEventHandler> m_contrastPreferenceChangeCallbacks;
81 Qt::MotionPreference m_motionPreference;
82 QWasmEventHandler m_motionPreferenceChangeCallback;
83};
84
85QT_END_NAMESPACE
86
87#endif // QWASMTHEME_H
static bool releaseRequestUpdateHold()
QWasmCompositor(QWasmScreen *screen)
QPlatformInputContext * inputContext() const override
Returns the platforms input context.
void setContainerElements(emscripten::val elementArray)
static QWasmIntegration * get()
Qt::WindowState defaultWindowState(Qt::WindowFlags flags) const override
QPlatformFontDatabase * fontDatabase() const override
Accessor for the platform integration's fontdatabase.
void addContainerElement(emscripten::val elementArray)
void initialize() override
Performs initialization steps that depend on having an event dispatcher available.
void removeContainerElement(emscripten::val elementArray)
QAbstractEventDispatcher * createEventDispatcher() const override
Factory function for the GUI event dispatcher.
QStringList themeNames() const override
void loadLocalFontFamilies(emscripten::val families)
QPlatformOpenGLContext * createPlatformOpenGLContext(QOpenGLContext *context) const override
Factory function for QPlatformOpenGLContext.
void removeBackingStore(QWindow *window)
QPlatformBackingStore * createPlatformBackingStore(QWindow *window) const override
Factory function for QPlatformBackingStore.
QPlatformServices * services() const override
QPlatformWindow * createForeignWindow(QWindow *window, WId nativeHandle) const override
QPlatformTheme * createPlatformTheme(const QString &name) const override
void resizeScreen(const emscripten::val &canvas)
QVariant styleHint(QPlatformIntegration::StyleHint hint) const override
bool hasCapability(QPlatformIntegration::Capability cap) const override
QPlatformWindow * createPlatformWindow(QWindow *window) const override
Factory function for QPlatformWindow.
QPlatformAccessibility * accessibility() const override
QWasmOffscreenSurface(QOffscreenSurface *offscreenSurface)
static void destroyWebGLContext(QPlatformSurface *surface)
bool isSharing() const override
bool isValid() const override
void doneCurrent() override
QWasmOpenGLContext(QOpenGLContext *context)
void swapBuffers(QPlatformSurface *surface) override
Reimplement in subclass to native swap buffers calls.
bool makeCurrent(QPlatformSurface *surface) override
QSurfaceFormat format() const override
QFunctionPointer getProcAddress(const char *procName) override
Reimplement in subclass to allow dynamic querying of OpenGL symbols.
GLuint defaultFramebufferObject(QPlatformSurface *surface) const override
Reimplement in subclass if your platform uses framebuffer objects for surfaces.
void deleteScreen()
QFont * fixedFont
Definition qwasmtheme.h:68
void onContrastPreferenceChange()
QPlatformDialogHelper * createPlatformDialogHelper(DialogType type) const override
Qt::ContrastPreference contrastPreference() const override
void onMotionPreferenceChange()
bool usePlatformNativeDialog(DialogType type) const override
const QPalette * palette(Palette type=SystemPalette) const override
Return a color palette for type type.
Qt::ColorScheme colorScheme() const override
void requestColorScheme(Qt::ColorScheme scheme) override
void onColorSchemeChange()
QVariant themeHint(ThemeHint hint) const override
Qt::MotionPreference motionPreference() const override
const QFont * font(Font type) const override
friend class QWasmCompositor
QJSValue function
Definition qjsengine.cpp:9
Combined button and popup list for selecting options.
EMSCRIPTEN_BINDINGS(qtQWasmIntegraton)
static void addContainerElement(emscripten::val element)
static void removeContainerElement(emscripten::val element)
QT_BEGIN_NAMESPACE void qt_set_sequence_auto_mnemonic(bool)
static void loadLocalFontFamilies(emscripten::val event)
static void resizeAllScreens(emscripten::val event)
static void resizeContainerElement(emscripten::val element)
static void setContainerElements(emscripten::val elementArray)
static void qtUpdateDpi()
QT_BEGIN_NAMESPACE Platform platform()
constexpr auto contrastPreferenceNoPreference
Definition qwasmtheme.h:27
void registerCallbacks(std::initializer_list< MediaName > mediaNames, CallbackFn callback, Container &callbacksContainer)
Definition qwasmtheme.h:36
constexpr auto contrastPreferenceMore
Definition qwasmtheme.h:28
constexpr auto colorSchemePreferenceDark
Definition qwasmtheme.h:26
constexpr auto contrastPreferenceCustom
Definition qwasmtheme.h:30
constexpr auto reducedMotionPreferenceReduce
Definition qwasmtheme.h:33
constexpr auto contrastPreferenceLess
Definition qwasmtheme.h:29