7#include <QtGui/qguiapplication.h>
8#include <QtGui/qstylehints.h>
10#include <QtCore/qapplicationstatic.h>
11#include <QtCore/qloggingcategory.h>
12#include <QtCore/qthread.h>
14#if defined(Q_OS_MACOS)
15# include "qquickmacstyle_mac_p.h"
16#elif defined(Q_OS_WINDOWS)
17# include "qquickwindowsxpstyle_p.h"
46 QStyle *style() {
return m_style.get(); }
49 std::unique_ptr<QStyle> m_style;
52Q_APPLICATION_STATIC(StyleSingleton, styleSingleton);
54StyleSingleton::StyleSingleton()
56 qCDebug(lcNativeStylePlugin) <<
"Creating native style";
60 if (qEnvironmentVariable(
"QQC2_COMMONSTYLE") == u"true")
61 m_style = std::make_unique<QCommonStyle>();
62 else if (
const QString envStyle = qEnvironmentVariable(
"QQC2_STYLE"); !envStyle.isNull()) {
63 if (envStyle == u"common")
64 m_style = std::make_unique<QCommonStyle>();
65#if defined(Q_OS_MACOS)
66 else if (envStyle == u"mac")
67 m_style.reset(QMacStyle::create());
69#if defined(Q_OS_WINDOWS)
70 else if (envStyle == u"windows")
71 m_style = std::make_unique<QWindowsStyle>();
72 else if (envStyle == u"windowsxp")
73 m_style = std::make_unique<QWindowsXPStyle>();
78#if defined(Q_OS_MACOS)
79 m_style.reset(QMacStyle::create());
80#elif defined(Q_OS_WINDOWS)
81 m_style = std::make_unique<QWindowsXPStyle>();
82 if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark)
83 qobject_cast<QWindowsStyle *>(m_style.get())->refreshPalette();
88 m_style = std::make_unique<QCommonStyle>();
95 Q_ASSERT(m_style->thread()->isMainThread());
96 QObject::connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, m_style.get(),
98 m_style->handleThemeChange();
102StyleSingleton::~StyleSingleton()
104 qCDebug(lcNativeStylePlugin) <<
"Destroying native style";
113 return styleSingleton()->style();
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)