Coverage Report

Created: 2026-06-30 07:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/gui/kernel/qplatformdrag.cpp
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
#include "qplatformdrag.h"
6
7
#include <QtGui/private/qdnd_p.h>
8
#include <QtGui/QKeyEvent>
9
#include <QtGui/QGuiApplication>
10
#include <QtCore/QEventLoop>
11
12
QT_BEGIN_NAMESPACE
13
14
#ifdef QDND_DEBUG
15
#  include <QtCore/QDebug>
16
#endif
17
18
QPlatformDropQtResponse::QPlatformDropQtResponse(bool accepted, Qt::DropAction acceptedAction)
19
0
    : m_accepted(accepted)
20
0
    , m_accepted_action(acceptedAction)
21
0
{
22
0
}
23
24
bool QPlatformDropQtResponse::isAccepted() const
25
0
{
26
0
    return m_accepted;
27
0
}
28
29
Qt::DropAction QPlatformDropQtResponse::acceptedAction() const
30
0
{
31
0
    return m_accepted_action;
32
0
}
33
34
QPlatformDragQtResponse::QPlatformDragQtResponse(bool accepted, Qt::DropAction acceptedAction, QRect answerRect)
35
0
    : QPlatformDropQtResponse(accepted,acceptedAction)
36
0
    , m_answer_rect(answerRect)
37
0
{
38
0
}
39
40
QRect QPlatformDragQtResponse::answerRect() const
41
0
{
42
0
    return m_answer_rect;
43
0
}
44
45
class QPlatformDragPrivate {
46
public:
47
0
    QPlatformDragPrivate() : cursor_drop_action(Qt::IgnoreAction) {}
48
49
    Qt::DropAction cursor_drop_action;
50
};
51
52
/*!
53
    \class QPlatformDrag
54
    \since 5.0
55
    \internal
56
    \preliminary
57
    \ingroup qpa
58
59
    \brief The QPlatformDrag class provides an abstraction for drag.
60
 */
61
0
QPlatformDrag::QPlatformDrag() : d_ptr(new QPlatformDragPrivate)
62
0
{
63
0
}
64
65
QPlatformDrag::~QPlatformDrag()
66
0
{
67
0
    delete d_ptr;
68
0
}
69
70
QDrag *QPlatformDrag::currentDrag() const
71
0
{
72
0
    return QDragManager::self()->object();
73
0
}
74
75
Qt::DropAction QPlatformDrag::defaultAction(Qt::DropActions possibleActions,
76
                                           Qt::KeyboardModifiers modifiers) const
77
0
{
78
#ifdef QDND_DEBUG
79
    qDebug() << "QDragManager::defaultAction(Qt::DropActions possibleActions)\nkeyboard modifiers : " << modifiers;
80
#endif
81
82
0
    Qt::DropAction default_action = Qt::IgnoreAction;
83
84
0
    if (currentDrag()) {
85
0
        default_action = currentDrag()->defaultAction();
86
0
    }
87
88
89
0
    if (default_action == Qt::IgnoreAction) {
90
        //This means that the drag was initiated by QDrag::start and we need to
91
        //preserve the old behavior
92
0
        default_action = Qt::CopyAction;
93
0
    }
94
95
0
    if (modifiers & Qt::ControlModifier && modifiers & Qt::ShiftModifier)
96
0
        default_action = Qt::LinkAction;
97
0
    else if (modifiers & Qt::ControlModifier)
98
0
        default_action = Qt::CopyAction;
99
0
    else if (modifiers & Qt::ShiftModifier)
100
0
        default_action = Qt::MoveAction;
101
0
    else if (modifiers & Qt::AltModifier)
102
0
        default_action = Qt::LinkAction;
103
104
#ifdef QDND_DEBUG
105
    qDebug() << "possible actions : " << possibleActions;
106
#endif
107
108
    // Check if the action determined is allowed
109
0
    if (!(possibleActions & default_action)) {
110
0
        if (possibleActions & Qt::CopyAction)
111
0
            default_action = Qt::CopyAction;
112
0
        else if (possibleActions & Qt::MoveAction)
113
0
            default_action = Qt::MoveAction;
114
0
        else if (possibleActions & Qt::LinkAction)
115
0
            default_action = Qt::LinkAction;
116
0
        else
117
0
            default_action = Qt::IgnoreAction;
118
0
    }
119
120
#ifdef QDND_DEBUG
121
    qDebug() << "default action : " << default_action;
122
#endif
123
124
0
    return default_action;
125
0
}
126
127
/*!
128
    \brief Cancels the currently active drag (only for drags of
129
    the current application initiated by QPlatformDrag::drag()).
130
131
    The default implementation does nothing.
132
133
    \since 5.7
134
 */
135
136
void QPlatformDrag::cancelDrag()
137
0
{
138
0
    Q_UNIMPLEMENTED();
139
0
}
140
141
/*!
142
    \brief Called to notify QDrag about changes of the current action.
143
 */
144
145
void QPlatformDrag::updateAction(Qt::DropAction action)
146
0
{
147
0
    Q_D(QPlatformDrag);
148
0
    if (d->cursor_drop_action != action) {
149
0
        d->cursor_drop_action = action;
150
0
        emit currentDrag()->actionChanged(action);
151
0
    }
152
0
}
153
154
static const char *const default_pm[] = {
155
"13 9 3 1",
156
".      c None",
157
"       c #000000",
158
"X      c #FFFFFF",
159
"X X X X X X X",
160
" X X X X X X ",
161
"X ......... X",
162
" X.........X ",
163
"X ......... X",
164
" X.........X ",
165
"X ......... X",
166
" X X X X X X ",
167
"X X X X X X X",
168
};
169
170
Q_GLOBAL_STATIC_WITH_ARGS(QPixmap,qt_drag_default_pixmap,(default_pm))
171
172
QPixmap QPlatformDrag::defaultPixmap()
173
0
{
174
0
    return *qt_drag_default_pixmap();
175
0
}
176
177
/*!
178
    \since 5.4
179
    \brief Returns bool indicating whether QPlatformDrag takes ownership
180
    and therefore responsibility of deleting the QDrag object passed in
181
    from QPlatformDrag::drag. This can be useful on platforms where QDrag
182
    object has to be kept around.
183
 */
184
bool QPlatformDrag::ownsDragObject() const
185
0
{
186
0
    return false;
187
0
}
188
189
QT_END_NAMESPACE