File indexing completed on 2024-05-12 15:42:37

0001 /*
0002  *  SPDX-FileCopyrightText: 2017 by Marco Martin <mart@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef KIRIGAMI_KIRIGAMIPLUGINFACTORY_H
0008 #define KIRIGAMI_KIRIGAMIPLUGINFACTORY_H
0009 
0010 #include "platformtheme.h"
0011 #include <QObject>
0012 
0013 #ifndef KIRIGAMI_BUILD_TYPE_STATIC
0014 #include "kirigami2_export.h"
0015 #endif
0016 
0017 class QQmlEngine;
0018 
0019 namespace Kirigami {
0020 class Units;
0021 
0022 /**
0023  * @class KirigamiPluginFactory kirigamipluginfactory.h <Kirigami/KirigamiPluginFactory>
0024  *
0025  * This class is reimpleented by plugins to provide different implementations
0026  * of PlatformTheme
0027  */
0028 #ifdef KIRIGAMI_BUILD_TYPE_STATIC
0029 class KirigamiPluginFactory : public QObject
0030 #else
0031 class KIRIGAMI2_EXPORT KirigamiPluginFactory : public QObject
0032 #endif
0033 {
0034     Q_OBJECT
0035 
0036 public:
0037     explicit KirigamiPluginFactory(QObject *parent = nullptr);
0038     ~KirigamiPluginFactory() override;
0039 
0040     /**
0041      * Creates an instance of PlatformTheme which can come out from
0042      * an implementation provided by a plugin
0043      *
0044      * If this returns @c nullptr the PlatformTheme will use a fallback
0045      * implementation that loads a theme definition from a QML file.
0046      *
0047      * @param parent the parent object of the created PlatformTheme
0048      */
0049     virtual PlatformTheme *createPlatformTheme(QObject *parent) = 0;
0050 
0051     /**
0052      * finds the plugin providing units and platformtheme for the current style
0053      * The plugin pointer is cached, so only the first call is a potentially heavy operation
0054      * @return pointer to the KirigamiPluginFactory of the current style
0055      */
0056     static KirigamiPluginFactory *findPlugin();
0057 };
0058 
0059 // TODO KF6 unify KirigamiPluginFactory and KirigamiPluginFactoryV2 again
0060 /**
0061  * This class provides an extended version of KirigamiPluginFactory.
0062  * Plugins that support Units need to implement it instead of KirigamiPluginFactory.
0063  */
0064 #ifdef KIRIGAMI_BUILD_TYPE_STATIC
0065 class KirigamiPluginFactoryV2 : public KirigamiPluginFactory
0066 #else
0067 class KIRIGAMI2_EXPORT KirigamiPluginFactoryV2 : public KirigamiPluginFactory
0068 #endif
0069 {
0070     Q_OBJECT
0071 
0072 public:
0073     explicit KirigamiPluginFactoryV2(QObject *parent = nullptr);
0074     ~KirigamiPluginFactoryV2() override;
0075 
0076     /**
0077      * Creates an instance of Units which can come from an implementation
0078      * provided by a plugin
0079      * @param parent the parent of the units object
0080      */
0081     virtual Units *createUnits(QObject *parent) = 0;
0082 };
0083 }
0084 
0085 QT_BEGIN_NAMESPACE
0086 #define KirigamiPluginFactory_iid "org.kde.kirigami.KirigamiPluginFactory"
0087 Q_DECLARE_INTERFACE(Kirigami::KirigamiPluginFactory, KirigamiPluginFactory_iid)
0088 QT_END_NAMESPACE
0089 
0090 #endif // KIRIGAMIPLUGINFACTORY_H