6#include <QtCore/qvariant.h>
7#include <QFontDatabase>
9#include <qloggingcategory.h>
10#include <qpa/qwindowsysteminterface.h>
13#include <emscripten.h>
14#include <emscripten/bind.h>
15#include <emscripten/val.h>
26 return emscripten::val::global(
"window")
27 .call<emscripten::val>(
"matchMedia", mediaQueryString)[
"matches"]
34 return Qt::ColorScheme::Dark;
36 return Qt::ColorScheme::Light;
43 return Qt::ContrastPreference::HighContrast;
45 return Qt::ContrastPreference::NoPreference;
50using namespace Qt::StringLiterals;
54 m_colorScheme = getColorSchemeFromMedia();
55 qCDebug(lcQpaThemeWasm) <<
"Initializing Wasm theme. Color scheme: " << m_colorScheme;
56 m_contrastPreference = getContrastPreferenceFromMedia();
57 qCDebug(lcQpaThemeWasm) <<
"Initializing Wasm theme. Contrast preference: " << m_contrastPreference;
59 for (
auto family : QFontDatabase::families())
60 if (QFontDatabase::isFixedPitch(family))
61 fixedFont =
new QFont(family);
63 m_palette = std::make_unique<QPalette>();
64 m_paletteIsDirty =
true;
67 { colorSchemePreferenceDark },
68 [
this](emscripten::val) { QWasmTheme::onColorSchemeChange(); },
69 m_colorSchemeChangeCallback);
71 { contrastPreferenceNoPreference, contrastPreferenceMore, contrastPreferenceLess,
72 contrastPreferenceCustom },
73 [
this](emscripten::val) { QWasmTheme::onContrastPreferenceChange(); },
74 m_contrastPreferenceChangeCallbacks);
85 if (type == SystemPalette) {
86 if (m_paletteIsDirty) {
87 m_paletteIsDirty =
false;
88 *m_palette = qt_fusionPalette();
90 return m_palette.get();
102 if (m_colorScheme != scheme) {
103 m_paletteIsDirty =
true;
104 m_colorScheme = scheme;
105 QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>();
111 return m_contrastPreference;
116 if (hint == QPlatformTheme::StyleNames)
117 return QVariant(QStringList() <<
"Fusion"_L1);
118 if (hint == QPlatformTheme::UiEffects)
119 return QVariant(
int(HoverEffect));
120 return QPlatformTheme::themeHint(hint);
125 if (type == QPlatformTheme::FixedFont) {
133 return (type == DialogType::FileDialog);
138 if (type == DialogType::FileDialog)
139 return new QWasmFileDialogHelper();
145 auto colorScheme = getColorSchemeFromMedia();
146 if (m_colorScheme != colorScheme) {
147 qCDebug(lcQpaThemeWasm) <<
"Color scheme changed to " << colorScheme;
148 m_colorScheme = colorScheme;
149 m_paletteIsDirty =
true;
150 QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>();
156 auto contrastPreference = getContrastPreferenceFromMedia();
157 if (m_contrastPreference != contrastPreference) {
158 qCDebug(lcQpaThemeWasm) <<
"Contrast preference changed to " << contrastPreference;
159 m_contrastPreference = contrastPreference;
160 m_paletteIsDirty =
true;
161 QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>();
void onContrastPreferenceChange()
QPlatformDialogHelper * createPlatformDialogHelper(DialogType type) const override
Qt::ContrastPreference contrastPreference() const override
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
const QFont * font(Font type) const override
Qt::ContrastPreference getContrastPreferenceFromMedia()
Qt::ColorScheme getColorSchemeFromMedia()
bool matchMedia(std::string mediaQueryString)
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)
QDebug Q_GUI_EXPORT & operator<<(QDebug &s, const QVectorPath &path)
constexpr auto contrastPreferenceMore
constexpr auto colorSchemePreferenceDark