Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qplatformdrag.cpp
Go to the documentation of this file.
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
: m_accepted(accepted)
20
, m_accepted_action(acceptedAction)
21
{
22
}
23
24
bool
QPlatformDropQtResponse::isAccepted()
const
25
{
26
return
m_accepted;
27
}
28
29
Qt::DropAction QPlatformDropQtResponse::acceptedAction()
const
30
{
31
return
m_accepted_action;
32
}
33
34
QPlatformDragQtResponse::QPlatformDragQtResponse(
bool
accepted, Qt::DropAction acceptedAction, QRect answerRect)
35
: QPlatformDropQtResponse(accepted,acceptedAction)
36
, m_answer_rect(answerRect)
37
{
38
}
39
40
QRect QPlatformDragQtResponse::answerRect()
const
41
{
42
return
m_answer_rect;
43
}
44
45
class
QPlatformDragPrivate
{
46
public
:
47
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
QPlatformDrag::QPlatformDrag() : d_ptr(
new
QPlatformDragPrivate)
62
{
63
}
64
65
QPlatformDrag::~QPlatformDrag()
66
{
67
delete
d_ptr;
68
}
69
70
QDrag *QPlatformDrag::currentDrag()
const
71
{
72
return
QDragManager::self()->object();
73
}
74
75
Qt::DropAction QPlatformDrag::defaultAction(Qt::DropActions possibleActions,
76
Qt::KeyboardModifiers modifiers)
const
77
{
78
#
ifdef
QDND_DEBUG
79
qDebug() <<
"QDragManager::defaultAction(Qt::DropActions possibleActions)\nkeyboard modifiers : "
<< modifiers;
80
#
endif
81
82
Qt::DropAction default_action = Qt::IgnoreAction;
83
84
if
(currentDrag()) {
85
default_action = currentDrag()->defaultAction();
86
}
87
88
89
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
default_action = Qt::CopyAction;
93
}
94
95
if
(modifiers & Qt::ControlModifier && modifiers & Qt::ShiftModifier)
96
default_action = Qt::LinkAction;
97
else
if
(modifiers & Qt::ControlModifier)
98
default_action = Qt::CopyAction;
99
else
if
(modifiers & Qt::ShiftModifier)
100
default_action = Qt::MoveAction;
101
else
if
(modifiers & Qt::AltModifier)
102
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
if
(!(possibleActions & default_action)) {
110
if
(possibleActions & Qt::CopyAction)
111
default_action = Qt::CopyAction;
112
else
if
(possibleActions & Qt::MoveAction)
113
default_action = Qt::MoveAction;
114
else
if
(possibleActions & Qt::LinkAction)
115
default_action = Qt::LinkAction;
116
else
117
default_action = Qt::IgnoreAction;
118
}
119
120
#
ifdef
QDND_DEBUG
121
qDebug() <<
"default action : "
<< default_action;
122
#
endif
123
124
return
default_action;
125
}
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
{
138
Q_UNIMPLEMENTED();
139
}
140
141
/*!
142
\brief Called to notify QDrag about changes of the current action.
143
*/
144
145
void
QPlatformDrag::updateAction(Qt::DropAction action)
146
{
147
Q_D(QPlatformDrag);
148
if
(d->cursor_drop_action != action) {
149
d->cursor_drop_action = action;
150
emit currentDrag()->actionChanged(action);
151
}
152
}
153
154
#
if
QT_CONFIG
(
imageformat_xpm
)
155
static
const
char
*
const
default_pm[] = {
156
"13 9 3 1"
,
157
". c None"
,
158
" c #000000"
,
159
"X c #FFFFFF"
,
160
"X X X X X X X"
,
161
" X X X X X X "
,
162
"X ......... X"
,
163
" X.........X "
,
164
"X ......... X"
,
165
" X.........X "
,
166
"X ......... X"
,
167
" X X X X X X "
,
168
"X X X X X X X"
,
169
};
170
171
Q_GLOBAL_STATIC_WITH_ARGS(QPixmap,qt_drag_default_pixmap,(default_pm))
172
#
endif
173
174
QPixmap QPlatformDrag::defaultPixmap()
175
{
176
#
if
QT_CONFIG
(
imageformat_xpm
)
177
return
*qt_drag_default_pixmap();
178
#
else
179
QPixmap pm(13, 9);
180
pm.fill(QColor(128, 128, 128, 128));
181
return
pm;
182
#
endif
183
}
184
185
/*!
186
\since 5.4
187
\brief Returns bool indicating whether QPlatformDrag takes ownership
188
and therefore responsibility of deleting the QDrag object passed in
189
from QPlatformDrag::drag. This can be useful on platforms where QDrag
190
object has to be kept around.
191
*/
192
bool
QPlatformDrag::ownsDragObject()
const
193
{
194
return
false
;
195
}
196
197
QT_END_NAMESPACE
QPlatformDragPrivate
Definition
qplatformdrag.cpp:45
QPlatformDragPrivate::cursor_drop_action
Qt::DropAction cursor_drop_action
Definition
qplatformdrag.cpp:49
QPlatformDragPrivate::QPlatformDragPrivate
QPlatformDragPrivate()
Definition
qplatformdrag.cpp:47
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtbase
src
gui
kernel
qplatformdrag.cpp
Generated on
for Qt by
1.18.0