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 * True if this applet will open its FullRepresentation when something is
86 * dragged over its CompactRepresentation (only has any effect when using
87 * the default CompactRepresentation).
88 */
89 Q_PROPERTY(bool expandedOnDragHover READ expandedOnDragHover WRITE setExpandedOnDragHover NOTIFY expandedOnDragHoverChanged)
90
91 /**
92 * Gives compatibility to the old plasmoid.* api
93 */
94 Q_PROPERTY(QObject *plasmoid READ applet CONSTANT)
95
96 /**
97 * Text to display in a badge overlay on top of the applet's icon. If empty,
98 * no badge will be displayed.
99 *
100 * The default value is an empty string.
101 *
102 * @since 6.4
103 */
104 Q_PROPERTY(QString badgeText READ badgeText WRITE setBadgeText NOTIFY badgeTextChanged)
105
106public:
107 AppletQuickItem(QQuickItem *parent = nullptr);
108 ~AppletQuickItem() override;
109
110 ////API NOT SUPPOSED TO BE USED BY QML
111 Plasma::Applet *applet() const;
112
113 void classBegin() override;
114 void componentComplete() override;
115
116 QQuickItem *compactRepresentationItem();
117 QQuickItem *fullRepresentationItem();
118
119 ////PROPERTY ACCESSORS
120 int switchWidth() const;
121 void setSwitchWidth(int width);
122
123 int switchHeight() const;
124 void setSwitchHeight(int width);
125
126 QQmlComponent *compactRepresentation();
127 void setCompactRepresentation(QQmlComponent *component);
128
129 QQmlComponent *fullRepresentation();
130 void setFullRepresentation(QQmlComponent *component);
131
132 QQmlComponent *preferredRepresentation();
133 void setPreferredRepresentation(QQmlComponent *component);
134
135 bool isExpanded() const;
136 void setExpanded(bool expanded);
137
138 bool isActivationTogglesExpanded() const;
139 void setActivationTogglesExpanded(bool activationTogglesExpanded);
140
141 bool hideOnWindowDeactivate() const;
142 void setHideOnWindowDeactivate(bool hide);
143
144 bool preloadFullRepresentation() const;
145 void setPreloadFullRepresentation(bool preload);
146
147 bool expandedOnDragHover() const;
148 void setExpandedOnDragHover(bool expandedOnDragHover);
149
150 QString badgeText() const;
151 void setBadgeText(const QString &text);
152
153 static bool hasItemForApplet(Plasma::Applet *applet);
154 static AppletQuickItem *itemForApplet(Plasma::Applet *applet);
155
156Q_SIGNALS:
157 // Property signals
158 void switchWidthChanged(int width);
159 void switchHeightChanged(int height);
160
161 void expandedChanged(bool expanded);
162
163 void activationTogglesExpandedChanged(bool activationTogglesExpanded);
164 void hideOnWindowDeactivateChanged(bool hide);
165
166 void compactRepresentationChanged(QQmlComponent *compactRepresentation);
167 void fullRepresentationChanged(QQmlComponent *fullRepresentation);
168 void preferredRepresentationChanged(QQmlComponent *preferredRepresentation);
169
170 void compactRepresentationItemChanged(QObject *compactRepresentationItem);
171 void fullRepresentationItemChanged(QObject *fullRepresentationItem);
172
173 void preloadFullRepresentationChanged(bool preload);
174
175 void expandedOnDragHoverChanged(bool expandedOnDragHover);
176
177 void badgeTextChanged(QString text);
178
179protected:
180 // Initializations that need to be executed after classBegin()
181 virtual void init();
182 PlasmaQuick::SharedQmlEngine *qmlObject();
183
184 // Reimplementation
185 void childEvent(QChildEvent *event) override;
186 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
187
188private:
189 AppletQuickItemPrivate *const d;
190
191 Q_PRIVATE_SLOT(d, void minimumWidthChanged())
192 Q_PRIVATE_SLOT(d, void minimumHeightChanged())
193 Q_PRIVATE_SLOT(d, void preferredWidthChanged())
194 Q_PRIVATE_SLOT(d, void preferredHeightChanged())
195 Q_PRIVATE_SLOT(d, void maximumWidthChanged())
196 Q_PRIVATE_SLOT(d, void maximumHeightChanged())
197 Q_PRIVATE_SLOT(d, void fillWidthChanged())
198 Q_PRIVATE_SLOT(d, void fillHeightChanged())
199};
200
201}
202
203#endif
An object that instantiates an entire QML context, with its own declarative engine.
The base Applet class.
Definition applet.h:64
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.
QCA_EXPORT void init()
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 18 2025 12:12:56 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.