Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickdrag_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QQUICKDRAG_P_H
6#define QQUICKDRAG_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQuick/qquickitem.h>
20
21#include <private/qintrusivelist_p.h>
22#include <private/qqmlguard_p.h>
23#include <private/qtquickglobal_p.h>
24
25#include <QtCore/qmimedata.h>
26#include <QtCore/qstringlist.h>
27#include <QtCore/qurl.h>
28#include <QtGui/qevent.h>
29
31
32QT_BEGIN_NAMESPACE
33
34class QQuickItem;
35class QQuickDrag;
36
38{
39 class Item : public QQmlGuard<QQuickItem>
40 {
41 public:
42 Item(QQuickItem *item) : QQmlGuard<QQuickItem>(Item::objectDestroyedImpl, item) {}
43
44 QIntrusiveListNode node;
45 private:
46 static void objectDestroyedImpl(QQmlGuardImpl *guard) { delete static_cast<Item *>(guard); }
47 };
48
49 typedef QIntrusiveList<Item, &Item::node> ItemList;
50
51public:
53 ~QQuickDragGrabber() { while (!m_items.isEmpty()) delete m_items.first(); }
54
55
56 QObject *target() const
57 {
58 if (m_target)
59 return m_target;
60 else if (!m_items.isEmpty())
61 return *m_items.first();
62 else
63 return nullptr;
64 }
65 void setTarget(QObject *target) { m_target = target; }
66 void resetTarget() { m_target = nullptr; }
67
68 bool isEmpty() const { return m_items.isEmpty(); }
69
71 iterator begin() { return m_items.begin(); }
72 iterator end() { return m_items.end(); }
73
74 void grab(QQuickItem *item) { m_items.insert(new Item(item)); }
75 iterator release(iterator at) { Item *item = *at; at = at.erase(); delete item; return at; }
76
77 auto& ignoreList() { return m_ignoreDragItems; }
78
79private:
80
81 ItemList m_items;
82 QVarLengthArray<QQuickItem *, 4> m_ignoreDragItems;
83 QObject *m_target;
84};
85
87{
88public:
89 void setProposedAction(Qt::DropAction action) { m_defaultAction = action; m_dropAction = action; }
90
91 static void setProposedAction(QDropEvent *event, Qt::DropAction action) {
92 static_cast<QQuickDropEventEx *>(event)->setProposedAction(action);
93 }
94
95 void copyActions(const QDropEvent &from) {
96 m_defaultAction = from.proposedAction(); m_dropAction = from.dropAction(); }
97
98 static void copyActions(QDropEvent *to, const QDropEvent &from) {
99 static_cast<QQuickDropEventEx *>(to)->copyActions(from);
100 }
101};
102
104{
106public:
108 : m_source(nullptr)
109 {
110 }
111
112 QStringList keys() const { return m_keys; }
113 QObject *source() const { return m_source; }
114
115private:
117 Qt::DropActions m_supportedActions;
118 QStringList m_keys;
119
120 friend class QQuickDragAttached;
121 friend class QQuickDragAttachedPrivate;
122};
123
124class QQuickDragAttached;
125class Q_QUICK_EXPORT QQuickDrag : public QObject
126{
127 Q_OBJECT
128
129 Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged RESET resetTarget FINAL)
130 Q_PROPERTY(Axis axis READ axis WRITE setAxis NOTIFY axisChanged FINAL FINAL)
131 Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged FINAL)
132 Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged FINAL)
133 Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged FINAL)
134 Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged FINAL)
135 Q_PROPERTY(bool active READ active NOTIFY activeChanged FINAL)
136 Q_PROPERTY(bool filterChildren READ filterChildren WRITE setFilterChildren NOTIFY filterChildrenChanged FINAL)
137 Q_PROPERTY(bool smoothed READ smoothed WRITE setSmoothed NOTIFY smoothedChanged FINAL)
138 // Note, threshold was added in QtQuick 2.2 but REVISION is not supported (or needed) for grouped
139 // properties See QTBUG-33179
140 Q_PROPERTY(qreal threshold READ threshold WRITE setThreshold NOTIFY thresholdChanged RESET resetThreshold FINAL)
141 //### consider drag and drop
142
143 QML_NAMED_ELEMENT(Drag)
144 QML_ADDED_IN_VERSION(2, 0)
145 QML_UNCREATABLE("Drag is only available via attached properties.")
146 QML_ATTACHED(QQuickDragAttached)
147
148public:
149 QQuickDrag(QObject *parent=nullptr);
150 ~QQuickDrag();
151
152 enum DragType { None, Automatic, Internal };
153 Q_ENUM(DragType)
154
155 QQuickItem *target() const;
156 void setTarget(QQuickItem *target);
157 void resetTarget();
158
159 enum Axis { XAxis=0x01, YAxis=0x02, XAndYAxis=0x03, XandYAxis=XAndYAxis };
160 Q_ENUM(Axis)
161 Axis axis() const;
162 void setAxis(Axis);
163
164 qreal xmin() const;
165 void setXmin(qreal);
166 qreal xmax() const;
167 void setXmax(qreal);
168 qreal ymin() const;
169 void setYmin(qreal);
170 qreal ymax() const;
171 void setYmax(qreal);
172
173 bool smoothed() const;
174 void setSmoothed(bool smooth);
175
176 qreal threshold() const;
177 void setThreshold(qreal);
178 void resetThreshold();
179
180 bool active() const;
181 void setActive(bool);
182
183 bool filterChildren() const;
184 void setFilterChildren(bool);
185
186 static QQuickDragAttached *qmlAttachedProperties(QObject *obj);
187
188Q_SIGNALS:
189 void targetChanged();
190 void axisChanged();
191 void minimumXChanged();
192 void maximumXChanged();
193 void minimumYChanged();
194 void maximumYChanged();
195 void activeChanged();
196 void filterChildrenChanged();
197 void smoothedChanged();
198 void thresholdChanged();
199
200private:
201 QQuickItem *_target;
202 Axis _axis;
203 qreal _xmin;
204 qreal _xmax;
205 qreal _ymin;
206 qreal _ymax;
207 bool _active : 1;
208 bool _filterChildren: 1;
209 bool _smoothed : 1;
210 qreal _threshold;
211 Q_DISABLE_COPY(QQuickDrag)
212};
213
214class QQuickDragAttachedPrivate;
215class Q_QUICK_EXPORT QQuickDragAttached : public QObject
216{
217 Q_OBJECT
218 Q_DECLARE_PRIVATE(QQuickDragAttached)
219
220 Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged FINAL)
221 Q_PROPERTY(QObject *source READ source WRITE setSource NOTIFY sourceChanged RESET resetSource FINAL)
222 Q_PROPERTY(QObject *target READ target NOTIFY targetChanged FINAL)
223 Q_PROPERTY(QPointF hotSpot READ hotSpot WRITE setHotSpot NOTIFY hotSpotChanged FINAL)
224 Q_PROPERTY(QUrl imageSource READ imageSource WRITE setImageSource NOTIFY imageSourceChanged FINAL)
225 // imageSourceSize is new in Qt 6.8; revision omitted because of QTBUG-33179
226 Q_PROPERTY(QSize imageSourceSize READ imageSourceSize WRITE setImageSourceSize NOTIFY imageSourceSizeChanged FINAL)
227 Q_PROPERTY(QStringList keys READ keys WRITE setKeys NOTIFY keysChanged FINAL)
228 Q_PROPERTY(QVariantMap mimeData READ mimeData WRITE setMimeData NOTIFY mimeDataChanged FINAL)
229 Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions WRITE setSupportedActions NOTIFY supportedActionsChanged FINAL)
230 Q_PROPERTY(Qt::DropAction proposedAction READ proposedAction WRITE setProposedAction NOTIFY proposedActionChanged FINAL)
231 Q_PROPERTY(QQuickDrag::DragType dragType READ dragType WRITE setDragType NOTIFY dragTypeChanged FINAL)
232
233 QML_ANONYMOUS
234 QML_ADDED_IN_VERSION(2, 0)
235
236public:
237 QQuickDragAttached(QObject *parent);
238 ~QQuickDragAttached();
239
240 bool isActive() const;
241 void setActive(bool active);
242
243 QObject *source() const;
244 void setSource(QObject *item);
245 void resetSource();
246
247 QObject *target() const;
248
249 QPointF hotSpot() const;
250 void setHotSpot(const QPointF &hotSpot);
251
252 QUrl imageSource() const;
253 void setImageSource(const QUrl &url);
254
255 QSize imageSourceSize() const;
256 void setImageSourceSize(const QSize &size);
257
258 QStringList keys() const;
259 void setKeys(const QStringList &keys);
260
261 QVariantMap mimeData() const;
262 void setMimeData(const QVariantMap &mimeData);
263
264 Qt::DropActions supportedActions() const;
265 void setSupportedActions(Qt::DropActions actions);
266
267 Qt::DropAction proposedAction() const;
268 void setProposedAction(Qt::DropAction action);
269
270 QQuickDrag::DragType dragType() const;
271 void setDragType(QQuickDrag::DragType dragType);
272
273 Q_INVOKABLE int drop();
274
275 bool event(QEvent *event) override;
276
277public Q_SLOTS:
278 void start(QQmlV4FunctionPtr);
279 void startDrag(QQmlV4FunctionPtr);
280 void cancel();
281
282Q_SIGNALS:
283 void dragStarted();
284 void dragFinished(Qt::DropAction dropAction);
285
286 void activeChanged();
287 void sourceChanged();
288 void targetChanged();
289 void hotSpotChanged();
290 void imageSourceChanged();
291 void imageSourceSizeChanged(); // new in Qt 6.8
292 void keysChanged();
293 void mimeDataChanged();
294 void supportedActionsChanged();
295 void proposedActionChanged();
296 void dragTypeChanged();
297};
298
299QT_END_NAMESPACE
300
301#endif
iterator release(iterator at)
ItemList::iterator iterator
void grab(QQuickItem *item)
bool isEmpty() const
QObject * target() const
void setTarget(QObject *target)
void setProposedAction(Qt::DropAction action)
static void setProposedAction(QDropEvent *event, Qt::DropAction action)
static void copyActions(QDropEvent *to, const QDropEvent &from)
void copyActions(const QDropEvent &from)
QT_REQUIRE_CONFIG(quick_draganddrop)