KDeclarative

DeclarativeDragArea.h
1 /*
2  SPDX-FileCopyrightText: 2010 BetterInbox <[email protected]>
3  SPDX-FileContributor: Gregory Schlomoff <[email protected]>
4 
5  SPDX-License-Identifier: MIT
6 */
7 
8 #ifndef DECLARATIVEDRAGAREA_H
9 #define DECLARATIVEDRAGAREA_H
10 
11 #include <QQuickItem>
12 #include <QImage>
13 #include <QSharedPointer>
14 
15 class QQmlComponent;
18 
19 class DeclarativeDragArea : public QQuickItem
20 {
21  Q_OBJECT
22 
27  Q_PROPERTY(QQuickItem* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged RESET resetDelegate)
28 
29 
33  Q_PROPERTY(QQuickItem* source READ source WRITE setSource NOTIFY sourceChanged RESET resetSource)
34 
35  //TODO: to be implemented
36  Q_PROPERTY(QQuickItem* target READ source NOTIFY targetChanged)
37 
38 
42  Q_PROPERTY(DeclarativeMimeData* mimeData READ mimeData CONSTANT)
43 
44 
47  Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) //TODO: Should call setAcceptDrops()
48 
49 
58  Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions WRITE setSupportedActions NOTIFY supportedActionsChanged)
59 
60 
63  Q_PROPERTY(Qt::DropAction defaultAction READ defaultAction WRITE setDefaultAction NOTIFY defaultActionChanged)
64 
65 
68  Q_PROPERTY(int startDragDistance READ startDragDistance WRITE setStartDragDistance NOTIFY startDragDistanceChanged)
69 
70 
73  Q_PROPERTY(QVariant delegateImage READ delegateImage WRITE setDelegateImage NOTIFY delegateImageChanged)
74 
75 
80  Q_PROPERTY(bool dragActive READ dragActive NOTIFY dragActiveChanged)
81 
82 public:
83  DeclarativeDragArea(QQuickItem *parent=nullptr);
84  ~DeclarativeDragArea() override;
85 
86  QQuickItem *delegate() const;
87  void setDelegate(QQuickItem* delegate);
88  void resetDelegate();
89 
90  QVariant delegateImage() const;
91  void setDelegateImage(const QVariant &image);
92  QQuickItem* target() const;
93  QQuickItem* source() const;
94  void setSource(QQuickItem* source);
95  void resetSource();
96 
97  bool dragActive() const;
98 
99  bool isEnabled() const;
100  void setEnabled(bool enabled);
101 
102  int startDragDistance() const;
103  void setStartDragDistance(int distance);
104 
105  //supported actions
106  Qt::DropActions supportedActions() const;
107  void setSupportedActions(Qt::DropActions actions);
108 
109  //default action
110  Qt::DropAction defaultAction() const;
111  void setDefaultAction(Qt::DropAction action);
112 
113  DeclarativeMimeData* mimeData() const;
114 
115 Q_SIGNALS:
116  void dragStarted();
117  void delegateChanged();
118  void dragActiveChanged();
119  void sourceChanged();
120  void targetChanged();
121  void dataChanged();
122  void enabledChanged();
123  void drop(int action);
124  void supportedActionsChanged();
125  void defaultActionChanged();
126  void startDragDistanceChanged();
127  void delegateImageChanged();
128 
129 protected:
130  void mouseMoveEvent(QMouseEvent *event) override;
131  void mousePressEvent(QMouseEvent *event) override;
132  void mouseReleaseEvent(QMouseEvent *) override;
133  void timerEvent(QTimerEvent *event) override;
134  bool childMouseEventFilter(QQuickItem *item, QEvent *event) override;
135 
136 private:
137  void startDrag(const QImage &image);
138 
139  QQuickItem* m_delegate;
140  QQuickItem* m_source;
141  QQuickItem* m_target;
143  bool m_enabled;
144  bool m_draggingJustStarted;
145  bool m_dragActive;
146  Qt::DropActions m_supportedActions;
147  Qt::DropAction m_defaultAction;
148  DeclarativeMimeData* const m_data;
149  QImage m_delegateImage;
150  int m_startDragDistance;
151  QPointF m_buttonDownPos;
152  int m_pressAndHoldTimerId;
153 };
154 
155 #endif // DECLARATIVEDRAGAREA_H
virtual void mousePressEvent(QMouseEvent *event)
Q_SIGNALSQ_SIGNALS
virtual void timerEvent(QTimerEvent *event)
virtual void mouseMoveEvent(QMouseEvent *event)
Q_OBJECTQ_OBJECT
virtual bool childMouseEventFilter(QQuickItem *item, QEvent *event)
Q_PROPERTY(...)
virtual void mouseReleaseEvent(QMouseEvent *event)
KIOWIDGETS_EXPORT DropJob * drop(const QDropEvent *dropEvent, const QUrl &destUrl, JobFlags flags=DefaultFlags)
bool isEnabled() const const
typedef DropActions
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 25 2021 22:44:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.