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
96public:
97 AppletQuickItem(QQuickItem *parent = nullptr);
98 ~AppletQuickItem() override;
99
100 ////API NOT SUPPOSED TO BE USED BY QML
101 Plasma::Applet *applet() const;
102
103 void classBegin() override;
104 void componentComplete() override;
105
106 QQuickItem *compactRepresentationItem();
107 QQuickItem *fullRepresentationItem();
108
109 ////PROPERTY ACCESSORS
110 int switchWidth() const;
111 void setSwitchWidth(int width);
112
113 int switchHeight() const;
114 void setSwitchHeight(int width);
115
116 QQmlComponent *compactRepresentation();
117 void setCompactRepresentation(QQmlComponent *component);
118
119 QQmlComponent *fullRepresentation();
120 void setFullRepresentation(QQmlComponent *component);
121
122 QQmlComponent *preferredRepresentation();
123 void setPreferredRepresentation(QQmlComponent *component);
124
125 bool isExpanded() const;
126 void setExpanded(bool expanded);
127
128 bool isActivationTogglesExpanded() const;
129 void setActivationTogglesExpanded(bool activationTogglesExpanded);
130
131 bool hideOnWindowDeactivate() const;
132 void setHideOnWindowDeactivate(bool hide);
133
134 bool preloadFullRepresentation() const;
135 void setPreloadFullRepresentation(bool preload);
136
137 bool expandedOnDragHover() const;
138 void setExpandedOnDragHover(bool expandedOnDragHover);
139
140 static bool hasItemForApplet(Plasma::Applet *applet);
141 static AppletQuickItem *itemForApplet(Plasma::Applet *applet);
142
143Q_SIGNALS:
144 // Property signals
145 void switchWidthChanged(int width);
146 void switchHeightChanged(int height);
147
148 void expandedChanged(bool expanded);
149
150 void activationTogglesExpandedChanged(bool activationTogglesExpanded);
151 void hideOnWindowDeactivateChanged(bool hide);
152
153 void compactRepresentationChanged(QQmlComponent *compactRepresentation);
154 void fullRepresentationChanged(QQmlComponent *fullRepresentation);
155 void preferredRepresentationChanged(QQmlComponent *preferredRepresentation);
156
157 void compactRepresentationItemChanged(QObject *compactRepresentationItem);
158 void fullRepresentationItemChanged(QObject *fullRepresentationItem);
159
160 void preloadFullRepresentationChanged(bool preload);
161
162 void expandedOnDragHoverChanged(bool expandedOnDragHover);
163
164protected:
165 // Initializations that need to be executed after classBegin()
166 virtual void init();
167 PlasmaQuick::SharedQmlEngine *qmlObject();
168
169 // Reimplementation
170 void childEvent(QChildEvent *event) override;
171 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
172
173private:
174 AppletQuickItemPrivate *const d;
175
176 Q_PRIVATE_SLOT(d, void minimumWidthChanged())
177 Q_PRIVATE_SLOT(d, void minimumHeightChanged())
178 Q_PRIVATE_SLOT(d, void preferredWidthChanged())
179 Q_PRIVATE_SLOT(d, void preferredHeightChanged())
180 Q_PRIVATE_SLOT(d, void maximumWidthChanged())
181 Q_PRIVATE_SLOT(d, void maximumHeightChanged())
182 Q_PRIVATE_SLOT(d, void fillWidthChanged())
183 Q_PRIVATE_SLOT(d, void fillHeightChanged())
184};
185
186}
187
188#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-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.