Libplasma

containmentitem.h
1/*
2 SPDX-FileCopyrightText: 2008-2013 Aaron Seigo <aseigo@kde.org>
3 SPDX-FileCopyrightText: 2010-2013 Marco Martin <mart@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef CONTAINMENTITEM_H
9#define CONTAINMENTITEM_H
10
11#include <QMenu>
12
13#include <Plasma/Containment>
14
15#include "plasmoiditem.h"
16
17class AppletQuickItem;
18class WallpaperItem;
19class DropMenu;
20class KJob;
21
22namespace KIO
23{
24class Job;
25class DropJob;
26}
27
28/**
29 * @brief This class is exposed to containments QML as the attached property Plasmoid
30 *
31 * <b>Import Statement</b>
32 * @code import org.kde.plasma.plasmoid @endcode
33 * @version 2.0
34 */
36{
38
39 Q_PROPERTY(WallpaperItem *wallpaper READ wallpaperItem NOTIFY wallpaperItemChanged)
40
41 /**
42 * True if the UI is still loading, for instance a desktop which doesn't have its wallpaper yet
43 */
44 Q_PROPERTY(bool loading READ isLoading NOTIFY isLoadingChanged)
45
46public:
48
49 void classBegin() override;
50
51 // Not for QML
52 Plasma::Containment *containment() const
53 {
54 return m_containment.data();
55 }
56
57 inline WallpaperItem *wallpaperItem() const
58 {
59 return m_wallpaperItem;
60 }
61
62 // For QML use
63 /**
64 * Returns the corresponding PlasmoidItem of one of its applets
65 */
66 Q_INVOKABLE AppletQuickItem *itemFor(Plasma::Applet *applet) const;
67
68 /**
69 * Process the mime data arrived to a particular coordinate, either with a drag and drop or paste with middle mouse button
70 */
71 Q_INVOKABLE void processMimeData(QMimeData *data, int x, int y, KIO::DropJob *dropJob = nullptr);
72
73 /**
74 * Process the mime data arrived to a particular coordinate, either with a drag and drop or paste with middle mouse button
75 */
76 Q_INVOKABLE void processMimeData(QObject *data, int x, int y, KIO::DropJob *dropJob = nullptr);
77
78 /**
79 * Search for a containment at those coordinates.
80 * the coordinates are passed as local coordinates of *this* containment
81 */
83
84 /**
85 * Map coordinates from relative to the given applet to relative to this containment
86 */
88
89 /**
90 *Map coordinates from relative to this containment to relative to the given applet
91 */
93
94 /**
95 * Given a geometry, it adjusts it moving it completely inside of the boundaries
96 * of availableScreenRegion
97 * @return the toLeft point of the rectangle
98 */
99 Q_INVOKABLE QPointF adjustToAvailableScreenRegion(int x, int y, int w, int h) const;
100
101 /**
102 * Opens the context menu of the Corona
103 *
104 * @param globalPos menu position in the global coordinate system
105 * @since 5.102
106 */
107 Q_INVOKABLE void openContextMenu(const QPointF &globalPos);
108
109protected:
110 void init() override;
111 void loadWallpaper();
112 void mousePressEvent(QMouseEvent *event) override;
113 void mouseReleaseEvent(QMouseEvent *event) override;
114 void wheelEvent(QWheelEvent *event) override;
115 void keyPressEvent(QKeyEvent *event) override;
116
117 void addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEvent *event);
118 void addContainmentActions(QMenu *desktopMenu, QEvent *event);
119
120 bool isLoading() const;
121 void itemChange(ItemChange change, const ItemChangeData &value) override;
122
124 // Property notifiers
125 void appletsChanged();
126 void drawWallpaperChanged();
127 void actionsChanged();
128 void editModeChanged();
129 void wallpaperItemChanged();
130 void isLoadingChanged();
131
132private Q_SLOTS:
133 // Used only internally by a metaObject()->invokeMethod
134 Plasma::Applet *createApplet(const QString &plugin, const QVariantList &args, const QRectF &geom);
135
136private:
137 void dropJobResult(KJob *job);
138 void mimeTypeRetrieved(KIO::Job *job, const QString &mimetype);
139 void appletAddedForward(Plasma::Applet *applet, const QRectF &geometryHint);
140 void appletRemovedForward(Plasma::Applet *applet);
141 void clearDataForMimeJob(KIO::Job *job);
142 void setAppletArgs(Plasma::Applet *applet, const QString &mimetype, const QVariant &data);
143 void deleteWallpaperItem();
144
145 WallpaperItem *m_wallpaperItem = nullptr;
146 QList<QObject *> m_plasmoidItems;
147 QPointer<Plasma::Containment> m_containment;
148 std::unique_ptr<QMenu> m_contextMenu; // QTBUG-122409: Keep the context menu so menu actions will keep their accessible interfaces valid
149 QPointer<DropMenu> m_dropMenu;
150 int m_wheelDelta;
151 friend class PlasmoidItem;
152};
153
154#endif
This class is exposed to containments QML as the attached property Plasmoid.
Q_INVOKABLE QObject * containmentItemAt(int x, int y)
Search for a containment at those coordinates.
bool loading
True if the UI is still loading, for instance a desktop which doesn't have its wallpaper yet.
Q_INVOKABLE QPointF adjustToAvailableScreenRegion(int x, int y, int w, int h) const
Given a geometry, it adjusts it moving it completely inside of the boundaries of availableScreenRegio...
Q_INVOKABLE AppletQuickItem * itemFor(Plasma::Applet *applet) const
Returns the corresponding PlasmoidItem of one of its applets.
Q_INVOKABLE QPointF mapToApplet(Plasma::Applet *applet, int x, int y)
Map coordinates from relative to this containment to relative to the given applet.
Q_INVOKABLE void processMimeData(QMimeData *data, int x, int y, KIO::DropJob *dropJob=nullptr)
Process the mime data arrived to a particular coordinate, either with a drag and drop or paste with m...
Q_INVOKABLE void openContextMenu(const QPointF &globalPos)
Opens the context menu of the Corona.
Q_INVOKABLE QPointF mapFromApplet(Plasma::Applet *applet, int x, int y)
Map coordinates from relative to the given applet to relative to this containment.
The base Applet class.
Definition applet.h:64
Import Statement
This class is exposed to wallpapers as the WallpaperItem root qml item.
Namespace for everything in libplasma.
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
T * data() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:34:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.