Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#ifndef QQUICKDRAG_P_H
5#define QQUICKDRAG_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick/qquickitem.h>
19
20#include <private/qintrusivelist_p.h>
21#include <private/qqmlguard_p.h>
22#include <private/qtquickglobal_p.h>
23
24#include <QtCore/qmimedata.h>
25#include <QtCore/qstringlist.h>
26#include <QtCore/qurl.h>
27
28QT_REQUIRE_CONFIG(quick_draganddrop);
29
31
32class QQuickItem;
33class QQuickDrag;
34
36{
37 class Item : public QQmlGuard<QQuickItem>
38 {
39 public:
40 Item(QQuickItem *item) : QQmlGuard<QQuickItem>(Item::objectDestroyedImpl, item) {}
41
43 private:
44 static void objectDestroyedImpl(QQmlGuardImpl *guard) { delete static_cast<Item *>(guard); }
45 };
46
47 typedef QIntrusiveList<Item, &Item::node> ItemList;
48
49public:
50 QQuickDragGrabber() : m_target(nullptr) {}
51 ~QQuickDragGrabber() { while (!m_items.isEmpty()) delete m_items.first(); }
52
53
54 QObject *target() const
55 {
56 if (m_target)
57 return m_target;
58 else if (!m_items.isEmpty())
59 return *m_items.first();
60 else
61 return nullptr;
62 }
63 void setTarget(QObject *target) { m_target = target; }
64 void resetTarget() { m_target = nullptr; }
65
66 bool isEmpty() const { return m_items.isEmpty(); }
67
68 typedef ItemList::iterator iterator;
69 iterator begin() { return m_items.begin(); }
70 iterator end() { return m_items.end(); }
71
72 void grab(QQuickItem *item) { m_items.insert(new Item(item)); }
73 iterator release(iterator at) { Item *item = *at; at = at.erase(); delete item; return at; }
74
75 auto& ignoreList() { return m_ignoreDragItems; }
76
77private:
78
79 ItemList m_items;
80 QVarLengthArray<QQuickItem *, 4> m_ignoreDragItems;
81 QObject *m_target;
82};
83
84class QQuickDropEventEx : public QDropEvent
85{
86public:
87 void setProposedAction(Qt::DropAction action) { m_defaultAction = action; m_dropAction = action; }
88
89 static void setProposedAction(QDropEvent *event, Qt::DropAction action) {
90 static_cast<QQuickDropEventEx *>(event)->setProposedAction(action);
91 }
92
93 void copyActions(const QDropEvent &from) {
94 m_defaultAction = from.proposedAction(); m_dropAction = from.dropAction(); }
95
96 static void copyActions(QDropEvent *to, const QDropEvent &from) {
97 static_cast<QQuickDropEventEx *>(to)->copyActions(from);
98 }
99};
100
102{
104public:
106 : m_source(nullptr)
107 {
108 }
109
110 QStringList keys() const { return m_keys; }
111 QObject *source() const { return m_source; }
112
113private:
114 QObject *m_source;
115 Qt::DropActions m_supportedActions;
116 QStringList m_keys;
117
118 friend class QQuickDragAttached;
120};
121
123class Q_QUICK_EXPORT QQuickDrag : public QObject
124{
126
127 Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged RESET resetTarget FINAL)
128 Q_PROPERTY(Axis axis READ axis WRITE setAxis NOTIFY axisChanged FINAL FINAL)
129 Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged FINAL)
130 Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged FINAL)
131 Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged FINAL)
132 Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged FINAL)
133 Q_PROPERTY(bool active READ active NOTIFY activeChanged FINAL)
134 Q_PROPERTY(bool filterChildren READ filterChildren WRITE setFilterChildren NOTIFY filterChildrenChanged FINAL)
135 Q_PROPERTY(bool smoothed READ smoothed WRITE setSmoothed NOTIFY smoothedChanged FINAL)
136 // Note, threshold was added in QtQuick 2.2 but REVISION is not supported (or needed) for grouped
137 // properties See QTBUG-33179
138 Q_PROPERTY(qreal threshold READ threshold WRITE setThreshold NOTIFY thresholdChanged RESET resetThreshold FINAL)
139 //### consider drag and drop
140
143 QML_UNCREATABLE("Drag is only available via attached properties.")
145
146public:
147 QQuickDrag(QObject *parent=nullptr);
148 ~QQuickDrag();
149
150 enum DragType { None, Automatic, Internal };
151 Q_ENUM(DragType)
152
153 QQuickItem *target() const;
154 void setTarget(QQuickItem *target);
155 void resetTarget();
156
157 enum Axis { XAxis=0x01, YAxis=0x02, XAndYAxis=0x03, XandYAxis=XAndYAxis };
158 Q_ENUM(Axis)
159 Axis axis() const;
160 void setAxis(Axis);
161
162 qreal xmin() const;
163 void setXmin(qreal);
164 qreal xmax() const;
165 void setXmax(qreal);
166 qreal ymin() const;
167 void setYmin(qreal);
168 qreal ymax() const;
169 void setYmax(qreal);
170
171 bool smoothed() const;
172 void setSmoothed(bool smooth);
173
174 qreal threshold() const;
175 void setThreshold(qreal);
176 void resetThreshold();
177
178 bool active() const;
179 void setActive(bool);
180
181 bool filterChildren() const;
182 void setFilterChildren(bool);
183
184 static QQuickDragAttached *qmlAttachedProperties(QObject *obj);
185
197
198private:
199 QQuickItem *_target;
200 Axis _axis;
201 qreal _xmin;
202 qreal _xmax;
203 qreal _ymin;
204 qreal _ymax;
205 bool _active : 1;
206 bool _filterChildren: 1;
207 bool _smoothed : 1;
208 qreal _threshold;
209 Q_DISABLE_COPY(QQuickDrag)
210};
211
213class Q_QUICK_EXPORT QQuickDragAttached : public QObject
214{
216 Q_DECLARE_PRIVATE(QQuickDragAttached)
217
218 Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged FINAL)
219 Q_PROPERTY(QObject *source READ source WRITE setSource NOTIFY sourceChanged RESET resetSource FINAL)
220 Q_PROPERTY(QObject *target READ target NOTIFY targetChanged FINAL)
221 Q_PROPERTY(QPointF hotSpot READ hotSpot WRITE setHotSpot NOTIFY hotSpotChanged FINAL)
222 Q_PROPERTY(QUrl imageSource READ imageSource WRITE setImageSource NOTIFY imageSourceChanged FINAL)
223 // imageSourceSize is new in Qt 6.8; revision omitted because of QTBUG-33179
224 Q_PROPERTY(QSize imageSourceSize READ imageSourceSize WRITE setImageSourceSize NOTIFY imageSourceSizeChanged FINAL)
225 Q_PROPERTY(QStringList keys READ keys WRITE setKeys NOTIFY keysChanged FINAL)
226 Q_PROPERTY(QVariantMap mimeData READ mimeData WRITE setMimeData NOTIFY mimeDataChanged FINAL)
227 Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions WRITE setSupportedActions NOTIFY supportedActionsChanged FINAL)
228 Q_PROPERTY(Qt::DropAction proposedAction READ proposedAction WRITE setProposedAction NOTIFY proposedActionChanged FINAL)
229 Q_PROPERTY(QQuickDrag::DragType dragType READ dragType WRITE setDragType NOTIFY dragTypeChanged FINAL)
230
233
234public:
237
238 bool isActive() const;
239 void setActive(bool active);
240
241 QObject *source() const;
242 void setSource(QObject *item);
243 void resetSource();
244
245 QObject *target() const;
246
247 QPointF hotSpot() const;
248 void setHotSpot(const QPointF &hotSpot);
249
250 QUrl imageSource() const;
251 void setImageSource(const QUrl &url);
252
253 QSize imageSourceSize() const;
254 void setImageSourceSize(const QSize &size);
255
256 QStringList keys() const;
257 void setKeys(const QStringList &keys);
258
259 QVariantMap mimeData() const;
260 void setMimeData(const QVariantMap &mimeData);
261
262 Qt::DropActions supportedActions() const;
263 void setSupportedActions(Qt::DropActions actions);
264
265 Qt::DropAction proposedAction() const;
266 void setProposedAction(Qt::DropAction action);
267
268 QQuickDrag::DragType dragType() const;
269 void setDragType(QQuickDrag::DragType dragType);
270
271 Q_INVOKABLE int drop();
272
273 bool event(QEvent *event) override;
274
275public Q_SLOTS:
277 void startDrag(QQmlV4FunctionPtr);
278 void cancel();
279
281 void dragStarted();
282 void dragFinished(Qt::DropAction dropAction);
283
284 void activeChanged();
285 void sourceChanged();
286 void targetChanged();
287 void hotSpotChanged();
288 void imageSourceChanged();
289 void imageSourceSizeChanged(); // new in Qt 6.8
290 void keysChanged();
291 void mimeDataChanged();
292 void supportedActionsChanged();
293 void proposedActionChanged();
294 void dragTypeChanged();
295};
296
298
299#endif
bool isActive
\inmodule QtCore
Definition qcoreevent.h:45
bool isEmpty() const
void insert(N *n)
Insert object into the list.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list.
const N * first() const
Returns the first entry in this list, or null if the list is empty.
iterator begin()
Returns an STL-style interator pointing to the first item in the list.
\inmodule QtCore
Definition qmimedata.h:16
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore\reentrant
Definition qpoint.h:217
iterator release(iterator at)
ItemList::iterator iterator
void grab(QQuickItem *item)
bool isEmpty() const
QObject * target() const
void setTarget(QObject *target)
QObject * source() const
QStringList keys() const
void activeChanged()
void maximumXChanged()
void minimumXChanged()
void targetChanged()
void thresholdChanged()
void smoothedChanged()
void minimumYChanged()
void axisChanged()
void filterChildrenChanged()
void maximumYChanged()
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)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
\inmodule QtCore
Definition qurl.h:94
std::list< Item > ItemList
Definition lalr.h:33
Combined button and popup list for selecting options.
Definition qcompare.h:63
DropAction
static const QCssKnownValue properties[NumProperties - 1]
@ None
Definition qhash.cpp:531
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum target
GLuint start
GLsizei GLsizei GLchar * source
struct _cl_event * event
GLhandleARB obj
[2]
#define QML_UNCREATABLE(REASON)
#define QML_ANONYMOUS
#define QML_NAMED_ELEMENT(NAME)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
#define QML_ATTACHED(ATTACHED_TYPE)
#define QT_REQUIRE_CONFIG(feature)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_INVOKABLE
#define Q_SLOTS
#define Q_SIGNALS
double qreal
Definition qtypes.h:187
future cancel()
QStringList keys
QUrl url("example.com")
[constructor-url-reference]
QMimeData * mimeData
QObject::connect nullptr
QGraphicsItem * item
QAction * at