File indexing completed on 2025-03-09 04:05:57
0001 /* 0002 SPDX-FileCopyrightText: 2010 BetterInbox <contact@betterinbox.com> 0003 Original author: Gregory Schlomoff <greg@betterinbox.com> 0004 0005 SPDX-License-Identifier: MIT 0006 */ 0007 0008 #ifndef DECLARATIVEDRAGAREA_H 0009 #define DECLARATIVEDRAGAREA_H 0010 0011 #include <QQuickItem> 0012 #include <QImage> 0013 0014 class DeclarativeMimeData; 0015 0016 class DeclarativeDragArea : public QQuickItem 0017 { 0018 Q_OBJECT 0019 0020 /** 0021 * The delegate is the item that will be displayed next to the mouse cursor during the drag and drop operation. 0022 * It usually consists of a large, semi-transparent icon representing the data being dragged. 0023 */ 0024 Q_PROPERTY(QQuickItem* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged RESET resetDelegate) 0025 0026 /** 0027 * The QML element that is the source of the resulting drag and drop operation. This can be defined to any item, and will 0028 * be available to the DropArea as event.data.source 0029 */ 0030 Q_PROPERTY(QQuickItem* source READ source WRITE setSource NOTIFY sourceChanged RESET resetSource) 0031 0032 //TODO: to be implemented 0033 Q_PROPERTY(QQuickItem* target READ source NOTIFY targetChanged) 0034 0035 /** 0036 * the mime data of the drag operation 0037 * @see DeclarativeMimeData 0038 */ 0039 Q_PROPERTY(DeclarativeMimeData* mimeData READ mimeData CONSTANT) 0040 0041 /** 0042 * If false no drag operation will be generate 0043 */ 0044 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) //TODO: Should call setAcceptDrops() 0045 0046 /** 0047 * Supported operations, a combination of 0048 * Qt.CopyAction 0049 * Qt.MoveAction 0050 * Qt.LinkAction 0051 * Qt.ActionMask 0052 * Qt.IgnoreAction 0053 * Qt.TargetMoveAction 0054 */ 0055 Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions WRITE setSupportedActions NOTIFY supportedActionsChanged) 0056 0057 /** 0058 * The default action will be performed during a drag when no modifiers are pressed. 0059 */ 0060 Q_PROPERTY(Qt::DropAction defaultAction READ defaultAction WRITE setDefaultAction NOTIFY defaultActionChanged) 0061 0062 /** 0063 * distance in pixel after which a drag event will get started 0064 */ 0065 Q_PROPERTY(int startDragDistance READ startDragDistance WRITE setStartDragDistance NOTIFY startDragDistanceChanged) 0066 0067 /** 0068 * an image to be used as delegate. if present overrides the delegate property. in can be either a QImage or a QIcon 0069 */ 0070 Q_PROPERTY(QVariant delegateImage READ delegateImage WRITE setDelegateImage NOTIFY delegateImageChanged) 0071 0072 public: 0073 DeclarativeDragArea(QQuickItem *parent=0); 0074 ~DeclarativeDragArea(); 0075 0076 QQuickItem *delegate() const; 0077 void setDelegate(QQuickItem* delegate); 0078 void resetDelegate(); 0079 0080 QVariant delegateImage() const; 0081 void setDelegateImage(const QVariant &image); 0082 QQuickItem* target() const; 0083 QQuickItem* source() const; 0084 void setSource(QQuickItem* source); 0085 void resetSource(); 0086 0087 bool isEnabled() const; 0088 void setEnabled(bool enabled); 0089 0090 int startDragDistance() const; 0091 void setStartDragDistance(int distance); 0092 0093 //supported actions 0094 Qt::DropActions supportedActions() const; 0095 void setSupportedActions(Qt::DropActions actions); 0096 0097 //default action 0098 Qt::DropAction defaultAction() const; 0099 void setDefaultAction(Qt::DropAction action); 0100 0101 DeclarativeMimeData* mimeData() const; 0102 0103 Q_SIGNALS: 0104 void dragStarted(); 0105 void delegateChanged(); 0106 void sourceChanged(); 0107 void targetChanged(); 0108 void dataChanged(); 0109 void enabledChanged(); 0110 void drop(int action); 0111 void supportedActionsChanged(); 0112 void defaultActionChanged(); 0113 void startDragDistanceChanged(); 0114 void delegateImageChanged(); 0115 0116 protected: 0117 void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; 0118 void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; 0119 void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE; 0120 bool childMouseEventFilter(QQuickItem *item, QEvent *event) Q_DECL_OVERRIDE; 0121 0122 private: 0123 QQuickItem* m_delegate; 0124 QQuickItem* m_source; 0125 QQuickItem* m_target; 0126 bool m_enabled; 0127 bool m_draggingJustStarted; 0128 Qt::DropActions m_supportedActions; 0129 Qt::DropAction m_defaultAction; 0130 DeclarativeMimeData* const m_data; 0131 QImage m_delegateImage; 0132 int m_startDragDistance; 0133 QPointF m_buttonDownPos; 0134 }; 0135 0136 #endif // DECLARATIVEDRAGAREA_H 0137