File indexing completed on 2024-05-19 15:09:22

0001 /*
0002     SPDX-FileCopyrightText: 2010 BetterInbox <contact@betterinbox.com>
0003     SPDX-FileContributor: Gregory Schlomoff <greg@betterinbox.com>
0004 
0005     SPDX-License-Identifier: MIT
0006 */
0007 
0008 #ifndef DECLARATIVEDROPAREA_H
0009 #define DECLARATIVEDROPAREA_H
0010 
0011 #include <QQuickItem>
0012 
0013 class DeclarativeDragDropEvent;
0014 
0015 class DeclarativeDropArea : public QQuickItem
0016 {
0017     Q_OBJECT
0018 
0019     /**
0020      * If false the area will receive no drop events
0021      */
0022     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
0023 
0024     /**
0025      *
0026      */
0027     Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged)
0028 
0029     Q_PROPERTY(bool containsDrag READ containsDrag NOTIFY containsDragChanged)
0030 
0031 public:
0032     DeclarativeDropArea(QQuickItem *parent = nullptr);
0033     bool isEnabled() const;
0034     void setEnabled(bool enabled);
0035 
0036     bool preventStealing() const;
0037     void setPreventStealing(bool prevent);
0038     bool containsDrag() const;
0039 
0040 Q_SIGNALS:
0041     /**
0042      * Emitted when the mouse cursor dragging something enters in the drag area
0043      * @param event description of the dragged content
0044      * @see DeclarativeDragDropEvent
0045      */
0046     void dragEnter(DeclarativeDragDropEvent *event);
0047 
0048     /**
0049      * Emitted when the mouse cursor dragging something leaves the drag area
0050      * @param event description of the dragged content
0051      * @see DeclarativeDragDropEvent
0052      */
0053     void dragLeave(DeclarativeDragDropEvent *event);
0054 
0055     /**
0056      * Emitted when the mouse cursor dragging something moves over the drag area
0057      * @param event description of the dragged content
0058      * @see DeclarativeDragDropEvent
0059      */
0060     void dragMove(DeclarativeDragDropEvent *event);
0061 
0062     /**
0063      * Emitted when the user drops something in the area
0064      * @param event description of the dragged content
0065      * @see DeclarativeDragDropEvent
0066      */
0067     void drop(DeclarativeDragDropEvent *event);
0068 
0069     // Notifiers
0070     void enabledChanged();
0071 
0072     void preventStealingChanged();
0073 
0074     void containsDragChanged(bool contained);
0075 
0076 protected:
0077     void dragEnterEvent(QDragEnterEvent *event) override;
0078     void dragLeaveEvent(QDragLeaveEvent *event) override;
0079     void dragMoveEvent(QDragMoveEvent *event) override;
0080     void dropEvent(QDropEvent *event) override;
0081 
0082 private Q_SLOTS:
0083     void temporaryInhibitParent(bool inhibit);
0084 
0085 private:
0086     void setContainsDrag(bool dragging);
0087 
0088     bool m_enabled : 1;
0089     bool m_preventStealing : 1;
0090     bool m_temporaryInhibition : 1;
0091     bool m_containsDrag : 1;
0092     QPoint m_oldDragMovePos;
0093 };
0094 
0095 #endif