File indexing completed on 2024-05-19 05:32:23
0001 /* 0002 SPDX-FileCopyrightText: 2023 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "effect/quickeffect.h" 0010 0011 #include <KConfigPropertyMap> 0012 0013 #include <QTimer> 0014 0015 class KConfigLoader; 0016 class KConfigPropertyMap; 0017 0018 namespace KWin 0019 { 0020 0021 /** 0022 * The SceneEffect type provides a way to implement effects that replace the default scene with 0023 * a custom one. 0024 * 0025 * Example usage: 0026 * @code 0027 * SceneEffect { 0028 * id: root 0029 * 0030 * delegate: Rectangle { 0031 * color: "blue" 0032 * } 0033 * 0034 * ShortcutHandler { 0035 * name: "Toggle Effect" 0036 * text: i18n("Toggle Effect") 0037 * sequence: "Meta+E" 0038 * onActivated: root.visible = !root.visible; 0039 * } 0040 * } 0041 * @endcode 0042 */ 0043 class ScriptedQuickSceneEffect : public QuickSceneEffect 0044 { 0045 Q_OBJECT 0046 Q_PROPERTY(QQmlListProperty<QObject> data READ data) 0047 Q_CLASSINFO("DefaultProperty", "data") 0048 0049 /** 0050 * The key-value store with the effect settings. 0051 */ 0052 Q_PROPERTY(KConfigPropertyMap *configuration READ configuration NOTIFY configurationChanged) 0053 0054 /** 0055 * Whether the effect is shown. Setting this property to @c true activates the effect; setting 0056 * this property to @c false will deactivate the effect and the screen views will be unloaded at 0057 * the next available time. 0058 */ 0059 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) 0060 0061 public: 0062 explicit ScriptedQuickSceneEffect(); 0063 ~ScriptedQuickSceneEffect() override; 0064 0065 void setMetaData(const KPluginMetaData &metaData); 0066 0067 void reconfigure(ReconfigureFlags flags) override; 0068 int requestedEffectChainPosition() const override; 0069 0070 bool isVisible() const; 0071 void setVisible(bool visible); 0072 0073 QQmlListProperty<QObject> data(); 0074 KConfigPropertyMap *configuration() const; 0075 0076 static void data_append(QQmlListProperty<QObject> *objects, QObject *object); 0077 static qsizetype data_count(QQmlListProperty<QObject> *objects); 0078 static QObject *data_at(QQmlListProperty<QObject> *objects, qsizetype index); 0079 static void data_clear(QQmlListProperty<QObject> *objects); 0080 0081 Q_SIGNALS: 0082 void visibleChanged(); 0083 void configurationChanged(); 0084 0085 private: 0086 KConfigLoader *m_configLoader = nullptr; 0087 KConfigPropertyMap *m_configuration = nullptr; 0088 QObjectList m_children; 0089 QTimer m_visibleTimer; 0090 bool m_isVisible = false; 0091 int m_requestedEffectChainPosition = 0; 0092 }; 0093 0094 } // namespace KWin