Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
16 | ** | - |
17 | ** GNU Lesser General Public License Usage | - |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
19 | ** General Public License version 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qplatformdrag.h" | - |
43 | | - |
44 | #include <QtGui/private/qdnd_p.h> | - |
45 | #include <QtGui/QKeyEvent> | - |
46 | #include <QtGui/QGuiApplication> | - |
47 | #include <QtCore/QEventLoop> | - |
48 | | - |
49 | QT_BEGIN_NAMESPACE | - |
50 | | - |
51 | #ifndef QT_NO_DRAGANDDROP | - |
52 | #ifdef QDND_DEBUG | - |
53 | QString dragActionsToString(Qt::DropActions actions) | - |
54 | { | - |
55 | QString str; | - |
56 | if (actions == Qt::IgnoreAction) { | - |
57 | if (!str.isEmpty()) | - |
58 | str += QLatin1String(" | "); | - |
59 | str += QLatin1String("IgnoreAction"); | - |
60 | } | - |
61 | if (actions & Qt::LinkAction) { | - |
62 | if (!str.isEmpty()) | - |
63 | str += QLatin1String(" | "); | - |
64 | str += QLatin1String("LinkAction"); | - |
65 | } | - |
66 | if (actions & Qt::CopyAction) { | - |
67 | if (!str.isEmpty()) | - |
68 | str += QLatin1String(" | "); | - |
69 | str += QLatin1String("CopyAction"); | - |
70 | } | - |
71 | if (actions & Qt::MoveAction) { | - |
72 | if (!str.isEmpty()) | - |
73 | str += QLatin1String(" | "); | - |
74 | str += QLatin1String("MoveAction"); | - |
75 | } | - |
76 | if ((actions & Qt::TargetMoveAction) == Qt::TargetMoveAction ) { | - |
77 | if (!str.isEmpty()) | - |
78 | str += QLatin1String(" | "); | - |
79 | str += QLatin1String("TargetMoveAction"); | - |
80 | } | - |
81 | return str; | - |
82 | } | - |
83 | | - |
84 | QString KeyboardModifiersToString(Qt::KeyboardModifiers modifiers) | - |
85 | { | - |
86 | QString str; | - |
87 | if (modifiers & Qt::ControlModifier) { | - |
88 | if (!str.isEmpty()) | - |
89 | str += QLatin1String(" | "); | - |
90 | str += QLatin1String("ControlModifier"); | - |
91 | } | - |
92 | if (modifiers & Qt::AltModifier) { | - |
93 | if (!str.isEmpty()) | - |
94 | str += QLatin1String(" | "); | - |
95 | str += QLatin1String("AltModifier"); | - |
96 | } | - |
97 | if (modifiers & Qt::ShiftModifier) { | - |
98 | if (!str.isEmpty()) | - |
99 | str += QLatin1String(" | "); | - |
100 | str += QLatin1String("ShiftModifier"); | - |
101 | } | - |
102 | return str; | - |
103 | } | - |
104 | #endif | - |
105 | | - |
106 | QPlatformDropQtResponse::QPlatformDropQtResponse(bool accepted, Qt::DropAction acceptedAction) | - |
107 | : m_accepted(accepted) | - |
108 | , m_accepted_action(acceptedAction) | - |
109 | { | - |
110 | } | 0 |
111 | | - |
112 | bool QPlatformDropQtResponse::isAccepted() const | - |
113 | { | - |
114 | return m_accepted; never executed: return m_accepted; | 0 |
115 | } | - |
116 | | - |
117 | Qt::DropAction QPlatformDropQtResponse::acceptedAction() const | - |
118 | { | - |
119 | return m_accepted_action; never executed: return m_accepted_action; | 0 |
120 | } | - |
121 | | - |
122 | QPlatformDragQtResponse::QPlatformDragQtResponse(bool accepted, Qt::DropAction acceptedAction, QRect answerRect) | - |
123 | : QPlatformDropQtResponse(accepted,acceptedAction) | - |
124 | , m_answer_rect(answerRect) | - |
125 | { | - |
126 | } | 0 |
127 | | - |
128 | QRect QPlatformDragQtResponse::answerRect() const | - |
129 | { | - |
130 | return m_answer_rect; never executed: return m_answer_rect; | 0 |
131 | } | - |
132 | | - |
133 | class QPlatformDragPrivate { | - |
134 | public: | - |
135 | QPlatformDragPrivate() : cursor_drop_action(Qt::IgnoreAction) {} executed: } Execution Count:289 | 289 |
136 | | - |
137 | Qt::DropAction cursor_drop_action; | - |
138 | }; | - |
139 | | - |
140 | /*! | - |
141 | \class QPlatformDrag | - |
142 | \since 5.0 | - |
143 | \internal | - |
144 | \preliminary | - |
145 | \ingroup qpa | - |
146 | | - |
147 | \brief The QPlatformDrag class provides an abstraction for drag. | - |
148 | */ | - |
149 | QPlatformDrag::QPlatformDrag() : d_ptr(new QPlatformDragPrivate) | - |
150 | { | - |
151 | } executed: } Execution Count:289 | 289 |
152 | | - |
153 | QPlatformDrag::~QPlatformDrag() | - |
154 | { | - |
155 | delete d_ptr; executed (the execution status of this line is deduced): delete d_ptr; | - |
156 | } executed: } Execution Count:287 | 287 |
157 | | - |
158 | QDrag *QPlatformDrag::currentDrag() const | - |
159 | { | - |
160 | return QDragManager::self()->object(); executed: return QDragManager::self()->object(); Execution Count:64 | 64 |
161 | } | - |
162 | | - |
163 | Qt::DropAction QPlatformDrag::defaultAction(Qt::DropActions possibleActions, | - |
164 | Qt::KeyboardModifiers modifiers) const | - |
165 | { | - |
166 | #ifdef QDND_DEBUG | - |
167 | qDebug("QDragManager::defaultAction(Qt::DropActions possibleActions)"); | - |
168 | qDebug("keyboard modifiers : %s", qPrintable(KeyboardModifiersToString(modifiers))); | - |
169 | #endif | - |
170 | | - |
171 | Qt::DropAction default_action = Qt::IgnoreAction; executed (the execution status of this line is deduced): Qt::DropAction default_action = Qt::IgnoreAction; | - |
172 | | - |
173 | if (currentDrag()) { partially evaluated: currentDrag() no Evaluation Count:0 | yes Evaluation Count:27 |
| 0-27 |
174 | default_action = currentDrag()->defaultAction(); never executed (the execution status of this line is deduced): default_action = currentDrag()->defaultAction(); | - |
175 | } | 0 |
176 | | - |
177 | | - |
178 | if (default_action == Qt::IgnoreAction) { partially evaluated: default_action == Qt::IgnoreAction yes Evaluation Count:27 | no Evaluation Count:0 |
| 0-27 |
179 | //This means that the drag was initiated by QDrag::start and we need to | - |
180 | //preserve the old behavior | - |
181 | default_action = Qt::CopyAction; executed (the execution status of this line is deduced): default_action = Qt::CopyAction; | - |
182 | } executed: } Execution Count:27 | 27 |
183 | | - |
184 | if (modifiers & Qt::ControlModifier && modifiers & Qt::ShiftModifier) partially evaluated: modifiers & Qt::ControlModifier no Evaluation Count:0 | yes Evaluation Count:27 |
never evaluated: modifiers & Qt::ShiftModifier | 0-27 |
185 | default_action = Qt::LinkAction; never executed: default_action = Qt::LinkAction; | 0 |
186 | else if (modifiers & Qt::ControlModifier) partially evaluated: modifiers & Qt::ControlModifier no Evaluation Count:0 | yes Evaluation Count:27 |
| 0-27 |
187 | default_action = Qt::CopyAction; never executed: default_action = Qt::CopyAction; | 0 |
188 | else if (modifiers & Qt::ShiftModifier) partially evaluated: modifiers & Qt::ShiftModifier no Evaluation Count:0 | yes Evaluation Count:27 |
| 0-27 |
189 | default_action = Qt::MoveAction; never executed: default_action = Qt::MoveAction; | 0 |
190 | else if (modifiers & Qt::AltModifier) partially evaluated: modifiers & Qt::AltModifier no Evaluation Count:0 | yes Evaluation Count:27 |
| 0-27 |
191 | default_action = Qt::LinkAction; never executed: default_action = Qt::LinkAction; | 0 |
192 | | - |
193 | #ifdef QDND_DEBUG | - |
194 | qDebug("possible actions : %s", qPrintable(dragActionsToString(possibleActions))); | - |
195 | #endif | - |
196 | | - |
197 | // Check if the action determined is allowed | - |
198 | if (!(possibleActions & default_action)) { partially evaluated: !(possibleActions & default_action) no Evaluation Count:0 | yes Evaluation Count:27 |
| 0-27 |
199 | if (possibleActions & Qt::CopyAction) never evaluated: possibleActions & Qt::CopyAction | 0 |
200 | default_action = Qt::CopyAction; never executed: default_action = Qt::CopyAction; | 0 |
201 | else if (possibleActions & Qt::MoveAction) never evaluated: possibleActions & Qt::MoveAction | 0 |
202 | default_action = Qt::MoveAction; never executed: default_action = Qt::MoveAction; | 0 |
203 | else if (possibleActions & Qt::LinkAction) never evaluated: possibleActions & Qt::LinkAction | 0 |
204 | default_action = Qt::LinkAction; never executed: default_action = Qt::LinkAction; | 0 |
205 | else | - |
206 | default_action = Qt::IgnoreAction; never executed: default_action = Qt::IgnoreAction; | 0 |
207 | } | - |
208 | | - |
209 | #ifdef QDND_DEBUG | - |
210 | qDebug("default action : %s", qPrintable(dragActionsToString(default_action))); | - |
211 | #endif | - |
212 | | - |
213 | return default_action; executed: return default_action; Execution Count:27 | 27 |
214 | } | - |
215 | | - |
216 | /*! | - |
217 | \brief Called to notify QDrag about changes of the current action. | - |
218 | */ | - |
219 | | - |
220 | void QPlatformDrag::updateAction(Qt::DropAction action) | - |
221 | { | - |
222 | Q_D(QPlatformDrag); never executed (the execution status of this line is deduced): QPlatformDragPrivate * const d = d_func(); | - |
223 | if (d->cursor_drop_action != action) { never evaluated: d->cursor_drop_action != action | 0 |
224 | d->cursor_drop_action = action; never executed (the execution status of this line is deduced): d->cursor_drop_action = action; | - |
225 | emit currentDrag()->actionChanged(action); never executed (the execution status of this line is deduced): currentDrag()->actionChanged(action); | - |
226 | } | 0 |
227 | } | 0 |
228 | | - |
229 | static const char *const default_pm[] = { | - |
230 | "13 9 3 1", | - |
231 | ". c None", | - |
232 | " c #000000", | - |
233 | "X c #FFFFFF", | - |
234 | "X X X X X X X", | - |
235 | " X X X X X X ", | - |
236 | "X ......... X", | - |
237 | " X.........X ", | - |
238 | "X ......... X", | - |
239 | " X.........X ", | - |
240 | "X ......... X", | - |
241 | " X X X X X X ", | - |
242 | "X X X X X X X", | - |
243 | }; | - |
244 | | - |
245 | Q_GLOBAL_STATIC_WITH_ARGS(QPixmap,qt_drag_default_pixmap,(default_pm)) never executed: delete x; never executed: return thisGlobalStatic.pointer.load(); never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) never evaluated: !thisGlobalStatic.pointer.load() never evaluated: !thisGlobalStatic.destroyed | 0 |
246 | | - |
247 | QPixmap QPlatformDrag::defaultPixmap() | - |
248 | { | - |
249 | return *qt_drag_default_pixmap(); never executed: return *qt_drag_default_pixmap(); | 0 |
250 | } | - |
251 | | - |
252 | #endif // QT_NO_DRAGANDDROP | - |
253 | | - |
254 | QT_END_NAMESPACE | - |
255 | | - |
| | |