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
4#ifndef QWASMTHEME_H
5#define QWASMTHEME_H
6
7#include <qpa/qplatformtheme.h>
8#include <QtGui/QFont>
9
10#include <memory>
11
12#include <private/qstdweb_p.h>
13
15
16class QWasmEventTranslator;
17class QWasmFontDatabase;
18class QWasmWindow;
20class QWasmScreen;
21class QWasmCompositor;
23
24// this reflects @media/prefers-contrast
25constexpr auto colorSchemePreferenceDark = "(prefers-color-scheme: dark)";
26constexpr auto contrastPreferenceNoPreference = "(prefers-contrast: no-preference)";
27constexpr auto contrastPreferenceMore = "(prefers-contrast: more)";
28constexpr auto contrastPreferenceLess = "(prefers-contrast: less)";
29constexpr auto contrastPreferenceCustom = "(prefers-contrast: custom)";
30
31template <typename MediaName, typename CallbackFn, typename Container>
32void registerCallbacks(std::initializer_list<MediaName> mediaNames, CallbackFn callback, Container &callbacksContainer)
33{
34 emscripten::val window = emscripten::val::global("window");
35 if (!window.isUndefined()) {
36 for (auto &&mediaName : mediaNames) {
37 auto media = window.call<emscripten::val>("matchMedia", emscripten::val(mediaName));
38 if constexpr (std::is_same_v<Container, std::vector<QWasmEventHandler>>) {
39 callbacksContainer.emplace_back(media, "change", callback);
40 } else {
41 Q_ASSERT(mediaNames.size() == 1);
42 callbacksContainer = QWasmEventHandler(media, "change", callback);
43 }
44 }
45 }
46}
47
49{
50public:
51 QWasmTheme();
52 ~QWasmTheme();
53
54 const QPalette *palette(Palette type = SystemPalette) const override;
55 Qt::ColorScheme colorScheme() const override;
56 void requestColorScheme(Qt::ColorScheme scheme) override;
58 QVariant themeHint(ThemeHint hint) const override;
59 const QFont *font(Font type) const override;
60 QFont *fixedFont = nullptr;
61
64
65private:
66 Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown;
67 QWasmEventHandler m_colorSchemeChangeCallback;
68 std::unique_ptr<QPalette> m_palette;
69 mutable bool m_paletteIsDirty = false;
70 Qt::ContrastPreference m_contrastPreference;
71 std::vector<QWasmEventHandler> m_contrastPreferenceChangeCallbacks;
72};
73
74QT_END_NAMESPACE
75
76#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:60
void onContrastPreferenceChange()
Qt::ContrastPreference contrastPreference() 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
const QFont * font(Font type) const override
friend class QWasmCompositor
QJSValue function
Definition qjsengine.cpp:9
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:26
void registerCallbacks(std::initializer_list< MediaName > mediaNames, CallbackFn callback, Container &callbacksContainer)
Definition qwasmtheme.h:32
constexpr auto contrastPreferenceMore
Definition qwasmtheme.h:27
constexpr auto colorSchemePreferenceDark
Definition qwasmtheme.h:25
constexpr auto contrastPreferenceCustom
Definition qwasmtheme.h:29
constexpr auto contrastPreferenceLess
Definition qwasmtheme.h:28