From 982b3b20c9c354964309e339659e4418636b4147 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 5 Feb 2020 14:12:09 +0530 Subject: [PATCH] Ensure headless QPA plugin uses fusion style --- src/calibre/headless/headless_integration.cpp | 32 +++++++++++++++++++ src/calibre/headless/headless_integration.h | 5 +-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/calibre/headless/headless_integration.cpp b/src/calibre/headless/headless_integration.cpp index ce5f07226c..5e8345ab20 100644 --- a/src/calibre/headless/headless_integration.cpp +++ b/src/calibre/headless/headless_integration.cpp @@ -20,6 +20,7 @@ class QCoreTextFontEngine; #include #include #include +#include QT_BEGIN_NAMESPACE @@ -128,4 +129,35 @@ HeadlessIntegration *HeadlessIntegration::instance() return static_cast(QGuiApplicationPrivate::platformIntegration()); } +static QString themeName() { return QStringLiteral("headless"); } + +QStringList HeadlessIntegration::themeNames() const +{ + return QStringList(themeName()); +} + +// Restrict the styles to "fusion" to prevent native styles requiring native +// window handles (eg Windows Vista style) from being used. +class HeadlessTheme : public QPlatformTheme +{ +public: + HeadlessTheme() {} + + QVariant themeHint(ThemeHint h) const override + { + switch (h) { + case StyleNames: + return QVariant(QStringList(QStringLiteral("fusion"))); + default: + break; + } + return QPlatformTheme::themeHint(h); + } +}; + +QPlatformTheme *HeadlessIntegration::createPlatformTheme(const QString &name) const +{ + return name == themeName() ? new HeadlessTheme() : nullptr; +} + QT_END_NAMESPACE diff --git a/src/calibre/headless/headless_integration.h b/src/calibre/headless/headless_integration.h index dc37a021c6..5d32f363a9 100644 --- a/src/calibre/headless/headless_integration.h +++ b/src/calibre/headless/headless_integration.h @@ -42,7 +42,9 @@ public: QPlatformWindow *createPlatformWindow(QWindow *window) const; QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; QAbstractEventDispatcher *createEventDispatcher() const; - QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const; + QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const; + QStringList themeNames() const override; + QPlatformTheme *createPlatformTheme(const QString &name) const override; unsigned options() const { return 0; } @@ -56,4 +58,3 @@ private: }; QT_END_NAMESPACE -