File indexing completed on 2024-11-10 04:56:47
0001 /* 0002 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 #pragma once 0007 0008 #include <KDecoration2/DecorationButton> 0009 #include <KDecoration2/Private/DecorationBridge> 0010 0011 #include <QList> 0012 #include <QPointer> 0013 0014 class QQuickItem; 0015 0016 class KPluginFactory; 0017 0018 namespace KDecoration2 0019 { 0020 namespace Preview 0021 { 0022 0023 class PreviewClient; 0024 class PreviewItem; 0025 class PreviewSettings; 0026 0027 class PreviewBridge : public DecorationBridge 0028 { 0029 Q_OBJECT 0030 Q_PROPERTY(QString plugin READ plugin WRITE setPlugin NOTIFY pluginChanged) 0031 Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged) 0032 Q_PROPERTY(QString kcmoduleName READ kcmoduleName WRITE setKcmoduleName NOTIFY kcmoduleNameChanged) 0033 Q_PROPERTY(bool valid READ isValid NOTIFY validChanged) 0034 public: 0035 explicit PreviewBridge(QObject *parent = nullptr); 0036 ~PreviewBridge() override; 0037 std::unique_ptr<DecoratedClientPrivate> createClient(DecoratedClient *client, Decoration *decoration) override; 0038 std::unique_ptr<DecorationSettingsPrivate> settings(DecorationSettings *parent) override; 0039 0040 PreviewClient *lastCreatedClient() 0041 { 0042 return m_lastCreatedClient; 0043 } 0044 PreviewSettings *lastCreatedSettings() 0045 { 0046 return m_lastCreatedSettings; 0047 } 0048 0049 void registerPreviewItem(PreviewItem *item); 0050 void unregisterPreviewItem(PreviewItem *item); 0051 0052 void setPlugin(const QString &plugin); 0053 QString plugin() const; 0054 void setKcmoduleName(const QString &name); 0055 QString kcmoduleName() const; 0056 void setTheme(const QString &theme); 0057 QString theme() const; 0058 bool isValid() const; 0059 0060 KDecoration2::Decoration *createDecoration(QObject *parent = nullptr); 0061 KDecoration2::DecorationButton *createButton(KDecoration2::Decoration *decoration, KDecoration2::DecorationButtonType type, QObject *parent = nullptr); 0062 0063 public Q_SLOTS: 0064 void configure(QQuickItem *ctx); 0065 0066 Q_SIGNALS: 0067 void pluginChanged(); 0068 void themeChanged(); 0069 void validChanged(); 0070 void kcmoduleNameChanged(); 0071 0072 private: 0073 void createFactory(); 0074 void setValid(bool valid); 0075 PreviewClient *m_lastCreatedClient; 0076 PreviewSettings *m_lastCreatedSettings; 0077 QList<PreviewItem *> m_previewItems; 0078 QString m_plugin; 0079 QString m_theme; 0080 QString m_kcmoduleName; 0081 QPointer<KPluginFactory> m_factory; 0082 bool m_valid; 0083 }; 0084 0085 class BridgeItem : public QObject 0086 { 0087 Q_OBJECT 0088 Q_PROPERTY(QString plugin READ plugin WRITE setPlugin NOTIFY pluginChanged) 0089 Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged) 0090 Q_PROPERTY(QString kcmoduleName READ kcmoduleName WRITE setKcmoduleName NOTIFY kcmoduleNameChanged) 0091 Q_PROPERTY(bool valid READ isValid NOTIFY validChanged) 0092 Q_PROPERTY(KDecoration2::Preview::PreviewBridge *bridge READ bridge CONSTANT) 0093 0094 public: 0095 explicit BridgeItem(QObject *parent = nullptr); 0096 ~BridgeItem() override; 0097 0098 void setPlugin(const QString &plugin) 0099 { 0100 m_bridge->setPlugin(plugin); 0101 } 0102 QString plugin() const 0103 { 0104 return m_bridge->plugin(); 0105 } 0106 void setTheme(const QString &theme) 0107 { 0108 m_bridge->setTheme(theme); 0109 } 0110 QString kcmoduleName() const 0111 { 0112 return m_bridge->kcmoduleName(); 0113 } 0114 void setKcmoduleName(const QString &name) 0115 { 0116 m_bridge->setKcmoduleName(name); 0117 } 0118 QString theme() const 0119 { 0120 return m_bridge->theme(); 0121 } 0122 bool isValid() const 0123 { 0124 return m_bridge->isValid(); 0125 } 0126 0127 PreviewBridge *bridge() const 0128 { 0129 return m_bridge; 0130 } 0131 0132 Q_SIGNALS: 0133 void pluginChanged(); 0134 void themeChanged(); 0135 void kcmoduleNameChanged(); 0136 void validChanged(); 0137 0138 private: 0139 PreviewBridge *m_bridge; 0140 }; 0141 0142 } 0143 } 0144 0145 Q_DECLARE_METATYPE(KDecoration2::Preview::PreviewBridge *)