Libplasma

appletquickitem.h
1/*
2 SPDX-FileCopyrightText: 2014 Marco Martin <mart@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef APPLETQUICKITEM_H
8#define APPLETQUICKITEM_H
9
10#include <QQmlComponent>
11#include <QQmlEngine>
12#include <QQmlParserStatus>
13#include <QQuickItem>
14#include <QTimer>
15
16#include <plasmaquick/plasmaquick_export.h>
17
18//
19// W A R N I N G
20// -------------
21//
22// This file is not part of the public Plasma API. It exists purely as an
23// implementation detail. This header file may change from version to
24// version without notice, or even be removed.
25//
26// We mean it.
27//
28
29namespace Plasma
30{
31class Applet;
32}
33
34namespace PlasmaQuick
35{
36class AppletQuickItemPrivate;
37class SharedQmlEngine;
38
39class PLASMAQUICK_EXPORT AppletQuickItem : public QQuickItem
40{
41 Q_OBJECT
42
43 Q_PROPERTY(int switchWidth READ switchWidth WRITE setSwitchWidth NOTIFY switchWidthChanged)
44 Q_PROPERTY(int switchHeight READ switchHeight WRITE setSwitchHeight NOTIFY switchHeightChanged)
45
46 Q_PROPERTY(QQmlComponent *compactRepresentation READ compactRepresentation WRITE setCompactRepresentation NOTIFY compactRepresentationChanged)
47 Q_PROPERTY(QQuickItem *compactRepresentationItem READ compactRepresentationItem NOTIFY compactRepresentationItemChanged)
48
49 Q_PROPERTY(QQmlComponent *fullRepresentation READ fullRepresentation WRITE setFullRepresentation NOTIFY fullRepresentationChanged)
50 Q_PROPERTY(QQuickItem *fullRepresentationItem READ fullRepresentationItem NOTIFY fullRepresentationItemChanged)
51
52 /**
53 * When true the full representation will be loaded immediately together with the main plasmoid.
54 * Note that this will have a negative impact on plasmoid loading times
55 * This is needed only when some important logic has to live inside the full representation and
56 * needs to be accessed from the outside. Use with care
57 * TODO: remove? we whould find a better way to fix folderview and Notes
58 */
59 Q_PROPERTY(bool preloadFullRepresentation READ preloadFullRepresentation WRITE setPreloadFullRepresentation NOTIFY preloadFullRepresentationChanged)
60
61 /**
62 * this is supposed to be either one between compactRepresentation or fullRepresentation
63 */
64 Q_PROPERTY(QQmlComponent *preferredRepresentation READ preferredRepresentation WRITE setPreferredRepresentation NOTIFY preferredRepresentationChanged)
65
66 /**
67 * Hint set to true if the applet should be displayed as expanded, such as the main popup open
68 */
69 Q_PROPERTY(bool expanded READ isExpanded WRITE setExpanded NOTIFY expandedChanged)
70
71 /**
72 * True when the applet wants the activation signal act in toggle mode, i.e. while being expanded
73 * the signal shrinks the applet to its not expanded state instead of reexpanding it.
74 */
75 Q_PROPERTY(bool activationTogglesExpanded WRITE setActivationTogglesExpanded READ isActivationTogglesExpanded NOTIFY activationTogglesExpandedChanged)
76
77 /**
78 * Whether the dialog should be hidden when the dialog loses focus.
79 *
80 * The default value is @c false.
81 **/
82 Q_PROPERTY(bool hideOnWindowDeactivate READ hideOnWindowDeactivate WRITE setHideOnWindowDeactivate NOTIFY hideOnWindowDeactivateChanged)
83
84 /**
85 * Gives compatibility to the old plasmoid.* api
86 */
87 Q_PROPERTY(QObject *plasmoid READ applet CONSTANT)
88
89public:
90 AppletQuickItem(QQuickItem *parent = nullptr);
91 ~AppletQuickItem() override;
92
93 ////API NOT SUPPOSED TO BE USED BY QML
94 Plasma::Applet *applet() const;
95
96 void classBegin() override;
97 void componentComplete() override;
98
99 QQuickItem *compactRepresentationItem();
100 QQuickItem *fullRepresentationItem();
101
102 ////PROPERTY ACCESSORS
103 int switchWidth() const;
104 void setSwitchWidth(int width);
105
106 int switchHeight() const;
107 void setSwitchHeight(int width);
108
109 QQmlComponent *compactRepresentation();
110 void setCompactRepresentation(QQmlComponent *component);
111
112 QQmlComponent *fullRepresentation();
113 void setFullRepresentation(QQmlComponent *component);
114
115 QQmlComponent *preferredRepresentation();
116 void setPreferredRepresentation(QQmlComponent *component);
117
118 bool isExpanded() const;
119 void setExpanded(bool expanded);
120
121 bool isActivationTogglesExpanded() const;
122 void setActivationTogglesExpanded(bool activationTogglesExpanded);
123
124 bool hideOnWindowDeactivate() const;
125 void setHideOnWindowDeactivate(bool hide);
126
127 bool preloadFullRepresentation() const;
128 void setPreloadFullRepresentation(bool preload);
129
130 static bool hasItemForApplet(Plasma::Applet *applet);
131 static AppletQuickItem *itemForApplet(Plasma::Applet *applet);
132
133Q_SIGNALS:
134 // Property signals
135 void switchWidthChanged(int width);
136 void switchHeightChanged(int height);
137
138 void expandedChanged(bool expanded);
139
140 void activationTogglesExpandedChanged(bool activationTogglesExpanded);
141 void hideOnWindowDeactivateChanged(bool hide);
142
143 void compactRepresentationChanged(QQmlComponent *compactRepresentation);
144 void fullRepresentationChanged(QQmlComponent *fullRepresentation);
145 void preferredRepresentationChanged(QQmlComponent *preferredRepresentation);
146
147 void compactRepresentationItemChanged(QObject *compactRepresentationItem);
148 void fullRepresentationItemChanged(QObject *fullRepresentationItem);
149
150 void preloadFullRepresentationChanged(bool preload);
151
152protected:
153 // Initializations that need to be executed after classBegin()
154 virtual void init();
155 PlasmaQuick::SharedQmlEngine *qmlObject();
156
157 // Reimplementation
158 void childEvent(QChildEvent *event) override;
159 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
160
161private:
162 AppletQuickItemPrivate *const d;
163
164 Q_PRIVATE_SLOT(d, void minimumWidthChanged())
165 Q_PRIVATE_SLOT(d, void minimumHeightChanged())
166 Q_PRIVATE_SLOT(d, void preferredWidthChanged())
167 Q_PRIVATE_SLOT(d, void preferredHeightChanged())
168 Q_PRIVATE_SLOT(d, void maximumWidthChanged())
169 Q_PRIVATE_SLOT(d, void maximumHeightChanged())
170 Q_PRIVATE_SLOT(d, void fillWidthChanged())
171 Q_PRIVATE_SLOT(d, void fillHeightChanged())
172};
173
174}
175
176#endif
An object that instantiates an entire QML context, with its own declarative engine.
The base Applet class.
Definition applet.h:64
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
The EdgeEventForwarder class This class forwards edge events to be replayed within the given margin T...
Definition action.h:20
Namespace for everything in libplasma.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:09:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.