Coverage Report

Created: 2026-03-12 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/gui/kernel/qsimpledrag_p.h
Line
Count
Source
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
// Qt-Security score:significant reason:default
4
5
#ifndef QSIMPLEDRAG_P_H
6
#define QSIMPLEDRAG_P_H
7
8
//
9
//  W A R N I N G
10
//  -------------
11
//
12
// This file is not part of the Qt API.  It exists purely as an
13
// implementation detail.  This header file may change from version to
14
// version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#include <QtGui/private/qtguiglobal_p.h>
20
#include <qpa/qplatformdrag.h>
21
22
#include <QtCore/QObject>
23
#include <QtCore/QPointer>
24
#include <QtGui/QWindow>
25
26
QT_REQUIRE_CONFIG(draganddrop);
27
28
QT_BEGIN_NAMESPACE
29
30
class QMouseEvent;
31
class QEventLoop;
32
class QDropData;
33
class QShapedPixmapWindow;
34
class QScreen;
35
36
class Q_GUI_EXPORT QBasicDrag : public QPlatformDrag, public QObject
37
{
38
public:
39
    ~QBasicDrag();
40
41
    virtual Qt::DropAction drag(QDrag *drag) override;
42
    void cancelDrag() override;
43
44
    virtual bool eventFilter(QObject *o, QEvent *e) override;
45
46
protected:
47
    QBasicDrag();
48
49
    virtual void startDrag();
50
    virtual void cancel();
51
    virtual void move(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) = 0;
52
    virtual void drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) = 0;
53
    virtual void endDrag();
54
55
56
    void moveShapedPixmapWindow(const QPoint &deviceIndependentPosition);
57
0
    QShapedPixmapWindow *shapedPixmapWindow() const { return m_drag_icon_window; }
58
    void recreateShapedPixmapWindow(QScreen *screen, const QPoint &pos);
59
    void updateCursor(Qt::DropAction action);
60
61
0
    bool canDrop() const { return m_can_drop; }
62
0
    void setCanDrop(bool c) { m_can_drop = c; }
63
64
0
    bool useCompositing() const { return m_useCompositing; }
65
0
    void setUseCompositing(bool on) { m_useCompositing = on; }
66
67
0
    void setScreen(QScreen *screen) { m_screen = screen; }
68
69
0
    Qt::DropAction executedDropAction() const { return m_executed_drop_action; }
70
0
    void  setExecutedDropAction(Qt::DropAction da) { m_executed_drop_action = da; }
71
72
0
    QDrag *drag() const { return m_drag; }
73
74
protected:
75
    QWindow *m_sourceWindow = nullptr;
76
    QPointer<QWindow> m_windowUnderCursor = nullptr;
77
78
private:
79
    void enableEventFilter();
80
    void disableEventFilter();
81
    void restoreCursor();
82
    void exitDndEventLoop();
83
84
#ifndef QT_NO_CURSOR
85
    bool m_dndHasSetOverrideCursor = false;
86
#endif
87
    QEventLoop *m_eventLoop = nullptr;
88
    Qt::DropAction m_executed_drop_action = Qt::IgnoreAction;
89
    bool m_can_drop = false;
90
    QDrag *m_drag = nullptr;
91
    QShapedPixmapWindow *m_drag_icon_window = nullptr;
92
    bool m_useCompositing = true;
93
    QScreen *m_screen = nullptr;
94
    QPoint m_lastPos;
95
};
96
97
class Q_GUI_EXPORT QSimpleDrag : public QBasicDrag
98
{
99
public:
100
    QSimpleDrag();
101
102
protected:
103
    virtual void startDrag() override;
104
    virtual void cancel() override;
105
    virtual void move(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) override;
106
    virtual void drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) override;
107
};
108
109
QT_END_NAMESPACE
110
111
#endif