1// Copyright (C) 2016 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 QSIMPLEDRAG_P_H
5#define QSIMPLEDRAG_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 <QtGui/private/qtguiglobal_p.h>
19#include <qpa/qplatformdrag.h>
20
21#include <QtCore/QObject>
22#include <QtCore/QPointer>
23#include <QtGui/QWindow>
24
25QT_REQUIRE_CONFIG(draganddrop);
26
27QT_BEGIN_NAMESPACE
28
29class QMouseEvent;
30class QEventLoop;
31class QDropData;
32class QShapedPixmapWindow;
33class QScreen;
34
35class Q_GUI_EXPORT QBasicDrag : public QPlatformDrag, public QObject
36{
37public:
38 ~QBasicDrag();
39
40 virtual Qt::DropAction drag(QDrag *drag) override;
41 void cancelDrag() override;
42
43 virtual bool eventFilter(QObject *o, QEvent *e) override;
44
45protected:
46 QBasicDrag();
47
48 virtual void startDrag();
49 virtual void cancel();
50 virtual void move(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) = 0;
51 virtual void drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) = 0;
52 virtual void endDrag();
53
54
55 void moveShapedPixmapWindow(const QPoint &deviceIndependentPosition);
56 QShapedPixmapWindow *shapedPixmapWindow() const { return m_drag_icon_window; }
57 void recreateShapedPixmapWindow(QScreen *screen, const QPoint &pos);
58 void updateCursor(Qt::DropAction action);
59
60 bool canDrop() const { return m_can_drop; }
61 void setCanDrop(bool c) { m_can_drop = c; }
62
63 bool useCompositing() const { return m_useCompositing; }
64 void setUseCompositing(bool on) { m_useCompositing = on; }
65
66 void setScreen(QScreen *screen) { m_screen = screen; }
67
68 Qt::DropAction executedDropAction() const { return m_executed_drop_action; }
69 void setExecutedDropAction(Qt::DropAction da) { m_executed_drop_action = da; }
70
71 QDrag *drag() const { return m_drag; }
72
73protected:
74 QWindow *m_sourceWindow = nullptr;
75 QPointer<QWindow> m_windowUnderCursor = nullptr;
76
77private:
78 void enableEventFilter();
79 void disableEventFilter();
80 void restoreCursor();
81 void exitDndEventLoop();
82
83#ifndef QT_NO_CURSOR
84 bool m_dndHasSetOverrideCursor = false;
85#endif
86 QEventLoop *m_eventLoop = nullptr;
87 Qt::DropAction m_executed_drop_action = Qt::IgnoreAction;
88 bool m_can_drop = false;
89 QDrag *m_drag = nullptr;
90 QShapedPixmapWindow *m_drag_icon_window = nullptr;
91 bool m_useCompositing = true;
92 QScreen *m_screen = nullptr;
93 QPoint m_lastPos;
94};
95
96class Q_GUI_EXPORT QSimpleDrag : public QBasicDrag
97{
98public:
99 QSimpleDrag();
100
101protected:
102 virtual void startDrag() override;
103 virtual void cancel() override;
104 virtual void move(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) override;
105 virtual void drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) override;
106};
107
108QT_END_NAMESPACE
109
110#endif
111

source code of qtbase/src/gui/kernel/qsimpledrag_p.h