Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
6
7#include <QtGui/private/qdnd_p.h>
8#include <QtGui/QKeyEvent>
9#include <QtGui/QGuiApplication>
10#include <QtCore/QEventLoop>
11
13
14#ifdef QDND_DEBUG
15# include <QtCore/QDebug>
16#endif
17
18QPlatformDropQtResponse::QPlatformDropQtResponse(bool accepted, Qt::DropAction acceptedAction)
19 : m_accepted(accepted)
20 , m_accepted_action(acceptedAction)
21{
22}
23
24bool QPlatformDropQtResponse::isAccepted() const
25{
26 return m_accepted;
27}
28
29Qt::DropAction QPlatformDropQtResponse::acceptedAction() const
30{
31 return m_accepted_action;
32}
33
34QPlatformDragQtResponse::QPlatformDragQtResponse(bool accepted, Qt::DropAction acceptedAction, QRect answerRect)
35 : QPlatformDropQtResponse(accepted,acceptedAction)
36 , m_answer_rect(answerRect)
37{
38}
39
40QRect QPlatformDragQtResponse::answerRect() const
41{
42 return m_answer_rect;
43}
44
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 */
61QPlatformDrag::QPlatformDrag() : d_ptr(new QPlatformDragPrivate)
62{
63}
64
65QPlatformDrag::~QPlatformDrag()
66{
67 delete d_ptr;
68}
69
70QDrag *QPlatformDrag::currentDrag() const
71{
72 return QDragManager::self()->object();
73}
74
75Qt::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
136void QPlatformDrag::cancelDrag()
137{
138 Q_UNIMPLEMENTED();
139}
140
141/*!
142 \brief Called to notify QDrag about changes of the current action.
143 */
144
145void 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
154static 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
170Q_GLOBAL_STATIC_WITH_ARGS(QPixmap,qt_drag_default_pixmap,(default_pm))
171
172QPixmap QPlatformDrag::defaultPixmap()
173{
174 return *qt_drag_default_pixmap();
175}
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 */
184bool QPlatformDrag::ownsDragObject() const
185{
186 return false;
187}
188
189QT_END_NAMESPACE
Qt::DropAction cursor_drop_action
Combined button and popup list for selecting options.
Q_GLOBAL_STATIC_WITH_ARGS(PermissionStatusHash, g_permissionStatusHash,({ { qMetaTypeId< QCameraPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QMicrophonePermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QBluetoothPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QContactsPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QCalendarPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QLocationPermission >(), Qt::PermissionStatus::Undetermined } }))
static const char *const default_pm[]