| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include <qpa/qplatformthemefactory_p.h> |
| 5 | #include <qpa/qplatformthemeplugin.h> |
| 6 | #include <QDir> |
| 7 | #include "private/qfactoryloader_p.h" |
| 8 | #include "qmutex.h" |
| 9 | |
| 10 | #include "qguiapplication.h" |
| 11 | #include "qplatformtheme.h" |
| 12 | #include "qplatformtheme_p.h" |
| 13 | #include "qdebug.h" |
| 14 | |
| 15 | QT_BEGIN_NAMESPACE |
| 16 | |
| 17 | using namespace Qt::StringLiterals; |
| 18 | |
| 19 | Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, ptLoader, |
| 20 | (QPlatformThemeFactoryInterface_iid, "/platformthemes"_L1, Qt::CaseInsensitive)) |
| 21 | |
| 22 | QPlatformTheme *QPlatformThemeFactory::create(const QString& key, const QString &platformPluginPath) |
| 23 | { |
| 24 | QStringList paramList = key.split(sep: u':'); |
| 25 | const QString platform = paramList.takeFirst().toLower(); |
| 26 | ptLoader->setExtraSearchPath(platformPluginPath); |
| 27 | QPlatformTheme *theme = qLoadPlugin<QPlatformTheme, QPlatformThemePlugin>(loader: ptLoader(), key: platform, args&: paramList); |
| 28 | if (theme) |
| 29 | theme->d_func()->name = key; |
| 30 | return theme; |
| 31 | } |
| 32 | |
| 33 | /*! |
| 34 | Returns the list of valid keys, i.e. the keys this factory can |
| 35 | create styles for. |
| 36 | |
| 37 | \sa create() |
| 38 | */ |
| 39 | QStringList QPlatformThemeFactory::keys(const QString &platformPluginPath) |
| 40 | { |
| 41 | ptLoader->setExtraSearchPath(platformPluginPath); |
| 42 | return ptLoader->keyMap().values(); |
| 43 | } |
| 44 | |
| 45 | QT_END_NAMESPACE |
| 46 |
