| 1 | // Copyright (C) 2024 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 QQUICKFILEDIALOGDELEGATE_P_P_H |
| 5 | #define QQUICKFILEDIALOGDELEGATE_P_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 "qquickfiledialogimpl_p.h" |
| 19 | #include "qquickfiledialogimpl_p_p.h" |
| 20 | #include "qquickfolderdialogimpl_p.h" |
| 21 | #include "qquickfiledialogdelegate_p.h" |
| 22 | #include <QtQuick/private/qquicksinglepointhandler_p.h> |
| 23 | #include <QtQuick/private/qquicktaphandler_p.h> |
| 24 | #include <QtQuick/private/qquickdroparea_p.h> |
| 25 | #include <QtQuickTemplates2/private/qquickitemdelegate_p_p.h> |
| 26 | #include <QtGui/qdrag.h> |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | class QQuickFileDialogTapHandler : public QQuickTapHandler |
| 31 | { |
| 32 | Q_OBJECT |
| 33 | |
| 34 | public: |
| 35 | explicit QQuickFileDialogTapHandler(QQuickItem *parent); |
| 36 | |
| 37 | enum State { |
| 38 | Listening, // the pointer is not being pressed |
| 39 | Tracking, // the pointer is being pressed |
| 40 | DraggingStarted, // dragging started |
| 41 | Dragging, // a drag is ongoing |
| 42 | DraggingFinished // dragging finished |
| 43 | }; |
| 44 | |
| 45 | State state() { return m_state; } |
| 46 | |
| 47 | QQuickFileDialogImpl *getFileDialogImpl() const; |
| 48 | void grabFolder(); |
| 49 | QUrl getFolderUrlAtPress() const; |
| 50 | |
| 51 | void handleDrag(QQuickDragEvent *event); |
| 52 | void handleDrop(QQuickDragEvent *event); |
| 53 | void handleContainsDragChanged(); |
| 54 | |
| 55 | friend class QQuickFileDialogDelegatePrivate; |
| 56 | |
| 57 | protected: |
| 58 | void handleEventPoint(QPointerEvent *event, QEventPoint &point) override; |
| 59 | bool wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) override; |
| 60 | |
| 61 | private: |
| 62 | void resetDragData(); |
| 63 | |
| 64 | QPointer<QDrag> m_drag; |
| 65 | QPointer<QQuickDropArea> m_dropArea; |
| 66 | State m_state = Listening; |
| 67 | QUrl m_sourceUrl; |
| 68 | bool m_longPressed = false; |
| 69 | }; |
| 70 | |
| 71 | class QQuickFileDialogDelegatePrivate : public QQuickItemDelegatePrivate |
| 72 | { |
| 73 | public: |
| 74 | Q_DECLARE_PUBLIC(QQuickFileDialogDelegate) |
| 75 | |
| 76 | static QQuickFileDialogDelegatePrivate *get(QQuickFileDialogDelegate *delegate) |
| 77 | { |
| 78 | return delegate->d_func(); |
| 79 | } |
| 80 | |
| 81 | void highlightFile(); |
| 82 | void chooseFile(); |
| 83 | void initTapHandler(); |
| 84 | void destroyTapHandler(); |
| 85 | void handleLongPress(); |
| 86 | |
| 87 | bool acceptKeyClick(Qt::Key key) const override; |
| 88 | |
| 89 | QQuickDialog *dialog = nullptr; |
| 90 | QQuickFileDialogImpl *fileDialog = nullptr; |
| 91 | QQuickFolderDialogImpl *folderDialog = nullptr; |
| 92 | QQuickFileDialogTapHandler *tapHandler = nullptr; |
| 93 | QUrl file; |
| 94 | }; |
| 95 | |
| 96 | QT_END_NAMESPACE |
| 97 | |
| 98 | #endif // QQUICKFILEDIALOGDELEGATE_P_P_H |
| 99 |
