Plasma-framework

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
98 QQuickItem *compactRepresentationItem();
99 QQuickItem *fullRepresentationItem();
100
101 ////PROPERTY ACCESSORS
102 int switchWidth() const;
103 void setSwitchWidth(int width);
104
105 int switchHeight() const;
106 void setSwitchHeight(int width);
107
108 QQmlComponent *compactRepresentation();
109 void setCompactRepresentation(QQmlComponent *component);
110
111 QQmlComponent *fullRepresentation();
112 void setFullRepresentation(QQmlComponent *component);
113
114 QQmlComponent *preferredRepresentation();
115 void setPreferredRepresentation(QQmlComponent *component);
116
117 bool isExpanded() const;
118 void setExpanded(bool expanded);
119
120 bool isActivationTogglesExpanded() const;
121 void setActivationTogglesExpanded(bool activationTogglesExpanded);
122
123 bool hideOnWindowDeactivate() const;
124 void setHideOnWindowDeactivate(bool hide);
125
126 bool preloadFullRepresentation() const;
127 void setPreloadFullRepresentation(bool preload);
128
129 static bool hasItemForApplet(Plasma::Applet *applet);
130 static AppletQuickItem *itemForApplet(Plasma::Applet *applet);
131
132Q_SIGNALS:
133 // Property signals
134 void switchWidthChanged(int width);
135 void switchHeightChanged(int height);
136
137 void expandedChanged(bool expanded);
138
139 void activationTogglesExpandedChanged(bool activationTogglesExpanded);
140 void hideOnWindowDeactivateChanged(bool hide);
141
142 void compactRepresentationChanged(QQmlComponent *compactRepresentation);
143 void fullRepresentationChanged(QQmlComponent *fullRepresentation);
144 void preferredRepresentationChanged(QQmlComponent *preferredRepresentation);
145
146 void compactRepresentationItemChanged(QObject *compactRepresentationItem);
147 void fullRepresentationItemChanged(QObject *fullRepresentationItem);
148
149 void preloadFullRepresentationChanged(bool preload);
150
151protected:
152 // Initializations that need to be executed after classBegin()
153 virtual void init();
154 PlasmaQuick::SharedQmlEngine *qmlObject();
155
156 // Reimplementation
157 void childEvent(QChildEvent *event) override;
158 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
159 void itemChange(ItemChange change, const ItemChangeData &value) 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
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 Fri May 17 2024 11:54:11 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.