1 /* 2 Copyright (C) 2010 by BetterInbox <contact@betterinbox.com> 3 Original author: Gregory Schlomoff <greg@betterinbox.com> 4 5 Permission is hereby granted, free of charge, to any person obtaining a copy 6 of this software and associated documentation files (the "Software"), to deal 7 in the Software without restriction, including without limitation the rights 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 copies of the Software, and to permit persons to whom the Software is 10 furnished to do so, subject to the following conditions: 11 12 The above copyright notice and this permission notice shall be included in 13 all copies or substantial portions of the Software. 14 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 THE SOFTWARE. 22 */ 23 24 #ifndef DECLARATIVEDROPAREA_H 25 #define DECLARATIVEDROPAREA_H 26 27 #include <QQuickItem> 28 29 class DeclarativeDragDropEvent; 30 31 class DeclarativeDropArea : public QQuickItem 32 { 33 Q_OBJECT 34 35 /** 36 * If false the area will receive no drop events 37 */ 38 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) 39 40 /** 41 * 42 */ 43 Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged) 44 45 Q_PROPERTY(bool containsDrag READ containsDrag NOTIFY containsDragChanged ) 46 47 public: 48 DeclarativeDropArea(QQuickItem *parent=0); 49 bool isEnabled() const; 50 void setEnabled(bool enabled); 51 52 bool preventStealing() const; 53 void setPreventStealing(bool prevent); 54 bool containsDrag() const; 55 56 Q_SIGNALS: 57 /** 58 * Emitted when the mouse cursor dragging something enters in the drag area 59 * @arg DeclarativeDragDropEvent description of the dragged content 60 * @see DeclarativeDragDropEvent 61 */ 62 void dragEnter(DeclarativeDragDropEvent* event); 63 64 /** 65 * Emitted when the mouse cursor dragging something leaves the drag area 66 * @arg DeclarativeDragDropEvent description of the dragged content 67 * @see DeclarativeDragDropEvent 68 */ 69 void dragLeave(DeclarativeDragDropEvent* event); 70 71 /** 72 * Emitted when the mouse cursor dragging something moves over the drag area 73 * @arg DeclarativeDragDropEvent description of the dragged content 74 * @see DeclarativeDragDropEvent 75 */ 76 void dragMove(DeclarativeDragDropEvent *event); 77 78 /** 79 * Emitted when the user drops something in the area 80 * @arg DeclarativeDragDropEvent description of the dragged content 81 * @see DeclarativeDragDropEvent 82 */ 83 void drop(DeclarativeDragDropEvent* event); 84 85 //Notifiers 86 void enabledChanged(); 87 88 void preventStealingChanged(); 89 90 void containsDragChanged(bool contained); 91 92 protected: 93 void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE; 94 void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE; 95 void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE; 96 void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; 97 98 private Q_SLOTS: 99 void temporaryInhibitParent(bool inhibit); 100 101 private: 102 void setContainsDrag(bool dragging); 103 104 bool m_enabled : 1; 105 bool m_preventStealing : 1; 106 bool m_temporaryInhibition : 1; 107 bool m_containsDrag : 1; 108 QPoint m_oldDragMovePos; 109 }; 110 111 #endif 112 113 114