Libplasma

plasmoiditem.h
1/*
2 SPDX-FileCopyrightText: 2008 Chani Armitage <chani@kde.org>
3 SPDX-FileCopyrightText: 2008, 2009 Aaron Seigo <aseigo@kde.org>
4 SPDX-FileCopyrightText: 2010 Marco Martin <mart@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef PLASMOIDITEM_H
10#define PLASMOIDITEM_H
11
12#include <QAction>
13#include <QQuickItem>
14#include <QQuickView>
15
16#include <KPluginMetaData>
17
18#include <Plasma/Applet>
19#include <Plasma/Containment>
20#include <Plasma/Theme>
21
22#include <appletquickitem.h>
23
24class QActionGroup;
25class QSizeF;
27
28namespace Plasma
29{
30class ConfigLoader;
31} // namespace Plasma
32
33/**
34 * @class PlasmoidItem
35 *
36 * <b>Import Statement</b>
37 * @code import org.kde.plasma.plasmoid @endcode
38 * @version 2.0
39 */
40class PlasmoidItem : public PlasmaQuick::AppletQuickItem
41{
43
44 /**
45 * The QML root object defined in the applet main.qml will be direct child of an PlasmoidItem instance
46 */
47
48 /**
49 * Main title for the plasmoid tooltip or other means of quick information:
50 * it's the same as the title property by default, but it can be personalized
51 */
52 Q_PROPERTY(QString toolTipMainText READ toolTipMainText WRITE setToolTipMainText NOTIFY toolTipMainTextChanged)
53
54 /**
55 * Description for the plasmoid tooltip or other means of quick information:
56 * it comes from the pluginifo comment by default, but it can be personalized
57 */
58 Q_PROPERTY(QString toolTipSubText READ toolTipSubText WRITE setToolTipSubText NOTIFY toolTipSubTextChanged)
59
60 /**
61 * how to handle the text format of the tooltip subtext:
62 * * Text.AutoText (default)
63 * * Text.PlainText
64 * * Text.StyledText
65 * * Text.RichText
66 * Note: in the default implementation the main text is always plain text
67 */
68 Q_PROPERTY(int toolTipTextFormat READ toolTipTextFormat WRITE setToolTipTextFormat NOTIFY toolTipTextFormatChanged)
69
70 /**
71 * This allows to set fully custom QML item as the tooltip.
72 * It will ignore all texts set by setToolTipMainText or setToolTipSubText
73 *
74 * @since 5.19
75 */
76 Q_PROPERTY(QQuickItem *toolTipItem READ toolTipItem WRITE setToolTipItem NOTIFY toolTipItemChanged)
77
78 // TODO: This was moved up from ContainmentItem because it is required by the
79 // Task Manager applet (for "Show only tasks from this screen") and no Qt API exposes
80 // screen numbering. An alternate solution that doesn't extend the applet interface
81 // would be preferable if found.
82 Q_PROPERTY(int screen READ screen NOTIFY screenChanged)
83
84 /**
85 * Provides access to the geometry of the applet is in.
86 * Can be useful to figure out what's the absolute position of the applet.
87 * TODO: move in containment
88 */
89 Q_PROPERTY(QRect screenGeometry READ screenGeometry NOTIFY screenGeometryChanged)
90
91 /**
92 * Whether the dialog should be hidden when the dialog loses focus.
93 *
94 * The default value is @c false.
95 * TODO KF6: move to Applet? probably not
96 **/
97 Q_PROPERTY(bool hideOnWindowDeactivate READ hideOnWindowDeactivate WRITE setHideOnWindowDeactivate NOTIFY hideOnWindowDeactivateChanged)
98
99 /**
100 * screen area free of panels: the coordinates are relative to the containment,
101 * it's independent from the screen position
102 * For more precise available geometry use availableScreenRegion()
103 */
104 Q_PROPERTY(QRect availableScreenRect READ availableScreenRect NOTIFY availableScreenRectChanged)
105
106 /**
107 * The available region of this screen, panels excluded. It's a list of rectanglesO: from containment
108 */
109 Q_PROPERTY(QVariantList availableScreenRegion READ availableScreenRegion NOTIFY availableScreenRegionChanged)
110
111public:
112 PlasmoidItem(QQuickItem *parent = nullptr);
113 ~PlasmoidItem() override;
114
115 // QML API-------------------------------------------------------------------
116
117 /**
118 * Should be called before retrieving any action
119 * to ensure contents are up to date
120 * @see contextualActionsAboutToShow
121 * @since 5.58
122 */
124
125 QVariantList availableScreenRegion() const;
126
128
129 // PROPERTY ACCESSORS-------------------------------------------------------------------
130 QString pluginName() const;
131
132 QString toolTipMainText() const;
133 void setToolTipMainText(const QString &text);
134
135 QString toolTipSubText() const;
136 void setToolTipSubText(const QString &text);
137
138 int toolTipTextFormat() const;
139 void setToolTipTextFormat(int format);
140
141 QQuickItem *toolTipItem() const;
142 void setToolTipItem(QQuickItem *toolTipItem);
143
144 int screen() const;
145 QRect screenGeometry() const;
146
147 bool hideOnWindowDeactivate() const;
148 void setHideOnWindowDeactivate(bool hide);
149
151 /**
152 * somebody else, usually the containment sent some data to the applet
153 * @param mimetype the mime type of the data such as text/plain
154 * @param data either the actual data or an URL representing it
155 */
156 void externalData(const QString &mimetype, const QVariant &data);
157
158 /**
159 * Emitted just before the contextual actions are about to show
160 * For instance just before the context menu containing the actions
161 * added with setAction() is shown
162 */
164
165 // PROPERTY change notifiers--------------
166 void toolTipMainTextChanged();
167 void toolTipSubTextChanged();
168 void toolTipTextFormatChanged();
169 void toolTipItemChanged();
170 void screenChanged();
171 void screenGeometryChanged();
172 void hideOnWindowDeactivateChanged();
173 void availableScreenRegionChanged();
174 void availableScreenRectChanged();
175 void contextualActionsChanged();
176
177protected:
178 void init() override;
179 bool event(QEvent *event) override;
180 bool eventFilter(QObject *watched, QEvent *event) override;
181
182private:
183 void destroyedChanged(bool destroyed);
184
185 // UI-specific members ------------------
186
187 QString m_toolTipMainText;
188 QString m_toolTipSubText;
189 int m_toolTipTextFormat;
190 QPointer<QQuickItem> m_toolTipItem;
191 bool m_hideOnDeactivate : 1;
192 int m_oldKeyboardShortcut;
193
194 friend class ContainmentItem;
195 // This is used by ContainmentItem
196 QPointF m_positionBeforeRemoval;
197};
198
199#endif
This class is exposed to containments QML as the attached property Plasmoid.
Import Statement
void contextualActionsAboutToShow()
Emitted just before the contextual actions are about to show For instance just before the context men...
Q_INVOKABLE void prepareContextualActions()
Should be called before retrieving any action to ensure contents are up to date.
void externalData(const QString &mimetype, const QVariant &data)
somebody else, usually the containment sent some data to the applet
QRect screenGeometry
Provides access to the geometry of the applet is in.
QQuickItem * toolTipItem
This allows to set fully custom QML item as the tooltip.
QVariantList availableScreenRegion
The available region of this screen, panels excluded.
QString toolTipMainText
The QML root object defined in the applet main.qml will be direct child of an PlasmoidItem instance.
bool hideOnWindowDeactivate
Whether the dialog should be hidden when the dialog loses focus.
QRect availableScreenRect
screen area free of panels: the coordinates are relative to the containment, it's independent from th...
QString toolTipSubText
Description for the plasmoid tooltip or other means of quick information: it comes from the pluginifo...
int toolTipTextFormat
how to handle the text format of the tooltip subtext:
Namespace for everything in libplasma.
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
void destroyed(QObject *obj)
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.