Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qsimpledrag.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | - | |||||||||||||||||||
10 | static QWindow* topLevelAt(const QPoint &pos) | - | ||||||||||||||||||
11 | { | - | ||||||||||||||||||
12 | QWindowList list = QGuiApplication::topLevelWindows(); | - | ||||||||||||||||||
13 | for (int i = list.count()-1; i >= 0
| 0 | ||||||||||||||||||
14 | QWindow *w = list.at(i); | - | ||||||||||||||||||
15 | if (w->isVisible()
| 0 | ||||||||||||||||||
16 | return never executed: w;return w; never executed: return w; | 0 | ||||||||||||||||||
17 | } never executed: end of block | 0 | ||||||||||||||||||
18 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
19 | } | - | ||||||||||||||||||
20 | QBasicDrag::QBasicDrag() : | - | ||||||||||||||||||
21 | m_restoreCursor(false), m_eventLoop(0), | - | ||||||||||||||||||
22 | m_executed_drop_action(Qt::IgnoreAction), m_can_drop(false), | - | ||||||||||||||||||
23 | m_drag(0), m_drag_icon_window(0), m_useCompositing(true), | - | ||||||||||||||||||
24 | m_screen(nullptr) | - | ||||||||||||||||||
25 | { | - | ||||||||||||||||||
26 | } never executed: end of block | 0 | ||||||||||||||||||
27 | - | |||||||||||||||||||
28 | QBasicDrag::~QBasicDrag() | - | ||||||||||||||||||
29 | { | - | ||||||||||||||||||
30 | delete m_drag_icon_window; | - | ||||||||||||||||||
31 | } never executed: end of block | 0 | ||||||||||||||||||
32 | - | |||||||||||||||||||
33 | void QBasicDrag::enableEventFilter() | - | ||||||||||||||||||
34 | { | - | ||||||||||||||||||
35 | (static_cast<QGuiApplication *>(QCoreApplication::instance()))->installEventFilter(this); | - | ||||||||||||||||||
36 | } never executed: end of block | 0 | ||||||||||||||||||
37 | - | |||||||||||||||||||
38 | void QBasicDrag::disableEventFilter() | - | ||||||||||||||||||
39 | { | - | ||||||||||||||||||
40 | (static_cast<QGuiApplication *>(QCoreApplication::instance()))->removeEventFilter(this); | - | ||||||||||||||||||
41 | } never executed: end of block | 0 | ||||||||||||||||||
42 | - | |||||||||||||||||||
43 | - | |||||||||||||||||||
44 | static inline QPoint getNativeMousePos(QEvent *e, QObject *o) | - | ||||||||||||||||||
45 | { | - | ||||||||||||||||||
46 | return never executed: QHighDpi::toNativePixels(static_cast<QMouseEvent *>(e)->globalPos(), qobject_cast<QWindow*>(o));return QHighDpi::toNativePixels(static_cast<QMouseEvent *>(e)->globalPos(), qobject_cast<QWindow*>(o)); never executed: return QHighDpi::toNativePixels(static_cast<QMouseEvent *>(e)->globalPos(), qobject_cast<QWindow*>(o)); | 0 | ||||||||||||||||||
47 | } | - | ||||||||||||||||||
48 | - | |||||||||||||||||||
49 | bool QBasicDrag::eventFilter(QObject *o, QEvent *e) | - | ||||||||||||||||||
50 | { | - | ||||||||||||||||||
51 | (void)o;; | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | if (!m_drag
| 0 | ||||||||||||||||||
54 | if (e->type() == QEvent::KeyRelease
| 0 | ||||||||||||||||||
55 | disableEventFilter(); | - | ||||||||||||||||||
56 | exitDndEventLoop(); | - | ||||||||||||||||||
57 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||
58 | } | - | ||||||||||||||||||
59 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||
60 | } | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | switch (e->type()) { | - | ||||||||||||||||||
63 | case never executed: QEvent::ShortcutOverride:case QEvent::ShortcutOverride: never executed: case QEvent::ShortcutOverride: | 0 | ||||||||||||||||||
64 | - | |||||||||||||||||||
65 | e->accept(); | - | ||||||||||||||||||
66 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | case never executed: QEvent::KeyPress:case QEvent::KeyPress: never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||
69 | case never executed: QEvent::KeyRelease:case QEvent::KeyRelease: never executed: case QEvent::KeyRelease: | 0 | ||||||||||||||||||
70 | { | - | ||||||||||||||||||
71 | QKeyEvent *ke = static_cast<QKeyEvent *>(e); | - | ||||||||||||||||||
72 | if (ke->key() == Qt::Key_Escape
| 0 | ||||||||||||||||||
73 | cancel(); | - | ||||||||||||||||||
74 | disableEventFilter(); | - | ||||||||||||||||||
75 | exitDndEventLoop(); | - | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | } never executed: end of block | 0 | ||||||||||||||||||
78 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||
79 | } | - | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | case never executed: QEvent::MouseMove:case QEvent::MouseMove: never executed: case QEvent::MouseMove: | 0 | ||||||||||||||||||
82 | { | - | ||||||||||||||||||
83 | QPoint nativePosition = getNativeMousePos(e, o); | - | ||||||||||||||||||
84 | move(nativePosition); | - | ||||||||||||||||||
85 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||
86 | } | - | ||||||||||||||||||
87 | case never executed: QEvent::MouseButtonRelease:case QEvent::MouseButtonRelease: never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||||||||
88 | disableEventFilter(); | - | ||||||||||||||||||
89 | if (canDrop()
| 0 | ||||||||||||||||||
90 | QPoint nativePosition = getNativeMousePos(e, o); | - | ||||||||||||||||||
91 | drop(nativePosition); | - | ||||||||||||||||||
92 | } never executed: else {end of block | 0 | ||||||||||||||||||
93 | cancel(); | - | ||||||||||||||||||
94 | } never executed: end of block | 0 | ||||||||||||||||||
95 | exitDndEventLoop(); | - | ||||||||||||||||||
96 | QCoreApplication::postEvent(o, new QMouseEvent(*static_cast<QMouseEvent *>(e))); | - | ||||||||||||||||||
97 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||
98 | case never executed: QEvent::MouseButtonDblClick:case QEvent::MouseButtonDblClick: never executed: case QEvent::MouseButtonDblClick: | 0 | ||||||||||||||||||
99 | case never executed: QEvent::Wheel:case QEvent::Wheel: never executed: case QEvent::Wheel: | 0 | ||||||||||||||||||
100 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||||||||
101 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
102 | break; never executed: break; | 0 | ||||||||||||||||||
103 | } | - | ||||||||||||||||||
104 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||
105 | } | - | ||||||||||||||||||
106 | - | |||||||||||||||||||
107 | Qt::DropAction QBasicDrag::drag(QDrag *o) | - | ||||||||||||||||||
108 | { | - | ||||||||||||||||||
109 | m_drag = o; | - | ||||||||||||||||||
110 | m_executed_drop_action = Qt::IgnoreAction; | - | ||||||||||||||||||
111 | m_can_drop = false; | - | ||||||||||||||||||
112 | m_restoreCursor = true; | - | ||||||||||||||||||
113 | - | |||||||||||||||||||
114 | (static_cast<QGuiApplication *>(QCoreApplication::instance()))->setOverrideCursor(Qt::DragCopyCursor); | - | ||||||||||||||||||
115 | updateCursor(m_executed_drop_action); | - | ||||||||||||||||||
116 | - | |||||||||||||||||||
117 | startDrag(); | - | ||||||||||||||||||
118 | m_eventLoop = new QEventLoop; | - | ||||||||||||||||||
119 | m_eventLoop->exec(); | - | ||||||||||||||||||
120 | delete m_eventLoop; | - | ||||||||||||||||||
121 | m_eventLoop = 0; | - | ||||||||||||||||||
122 | m_drag = 0; | - | ||||||||||||||||||
123 | endDrag(); | - | ||||||||||||||||||
124 | return never executed: m_executed_drop_action;return m_executed_drop_action; never executed: return m_executed_drop_action; | 0 | ||||||||||||||||||
125 | } | - | ||||||||||||||||||
126 | - | |||||||||||||||||||
127 | void QBasicDrag::restoreCursor() | - | ||||||||||||||||||
128 | { | - | ||||||||||||||||||
129 | if (m_restoreCursor
| 0 | ||||||||||||||||||
130 | - | |||||||||||||||||||
131 | QGuiApplication::restoreOverrideCursor(); | - | ||||||||||||||||||
132 | - | |||||||||||||||||||
133 | m_restoreCursor = false; | - | ||||||||||||||||||
134 | } never executed: end of block | 0 | ||||||||||||||||||
135 | } never executed: end of block | 0 | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | void QBasicDrag::startDrag() | - | ||||||||||||||||||
138 | { | - | ||||||||||||||||||
139 | QPoint pos; | - | ||||||||||||||||||
140 | - | |||||||||||||||||||
141 | pos = QCursor::pos(); | - | ||||||||||||||||||
142 | if (pos.x() == int(qInf())
| 0 | ||||||||||||||||||
143 | - | |||||||||||||||||||
144 | pos = QPoint(); | - | ||||||||||||||||||
145 | } never executed: end of block | 0 | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | recreateShapedPixmapWindow(m_screen, pos); | - | ||||||||||||||||||
148 | enableEventFilter(); | - | ||||||||||||||||||
149 | } never executed: end of block | 0 | ||||||||||||||||||
150 | - | |||||||||||||||||||
151 | void QBasicDrag::endDrag() | - | ||||||||||||||||||
152 | { | - | ||||||||||||||||||
153 | } | - | ||||||||||||||||||
154 | - | |||||||||||||||||||
155 | void QBasicDrag::recreateShapedPixmapWindow(QScreen *screen, const QPoint &pos) | - | ||||||||||||||||||
156 | { | - | ||||||||||||||||||
157 | delete m_drag_icon_window; | - | ||||||||||||||||||
158 | - | |||||||||||||||||||
159 | - | |||||||||||||||||||
160 | m_drag_icon_window = new QShapedPixmapWindow(screen); | - | ||||||||||||||||||
161 | - | |||||||||||||||||||
162 | m_drag_icon_window->setUseCompositing(m_useCompositing); | - | ||||||||||||||||||
163 | m_drag_icon_window->setPixmap(m_drag->pixmap()); | - | ||||||||||||||||||
164 | m_drag_icon_window->setHotspot(m_drag->hotSpot()); | - | ||||||||||||||||||
165 | m_drag_icon_window->updateGeometry(pos); | - | ||||||||||||||||||
166 | m_drag_icon_window->setVisible(true); | - | ||||||||||||||||||
167 | } never executed: end of block | 0 | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | void QBasicDrag::cancel() | - | ||||||||||||||||||
170 | { | - | ||||||||||||||||||
171 | disableEventFilter(); | - | ||||||||||||||||||
172 | restoreCursor(); | - | ||||||||||||||||||
173 | m_drag_icon_window->setVisible(false); | - | ||||||||||||||||||
174 | } never executed: end of block | 0 | ||||||||||||||||||
175 | - | |||||||||||||||||||
176 | - | |||||||||||||||||||
177 | - | |||||||||||||||||||
178 | - | |||||||||||||||||||
179 | - | |||||||||||||||||||
180 | - | |||||||||||||||||||
181 | void QBasicDrag::moveShapedPixmapWindow(const QPoint &globalPos) | - | ||||||||||||||||||
182 | { | - | ||||||||||||||||||
183 | if (m_drag
| 0 | ||||||||||||||||||
184 | m_drag_icon_window->updateGeometry(globalPos); never executed: m_drag_icon_window->updateGeometry(globalPos); | 0 | ||||||||||||||||||
185 | } never executed: end of block | 0 | ||||||||||||||||||
186 | - | |||||||||||||||||||
187 | void QBasicDrag::drop(const QPoint &) | - | ||||||||||||||||||
188 | { | - | ||||||||||||||||||
189 | disableEventFilter(); | - | ||||||||||||||||||
190 | restoreCursor(); | - | ||||||||||||||||||
191 | m_drag_icon_window->setVisible(false); | - | ||||||||||||||||||
192 | } never executed: end of block | 0 | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | void QBasicDrag::exitDndEventLoop() | - | ||||||||||||||||||
195 | { | - | ||||||||||||||||||
196 | if (m_eventLoop
| 0 | ||||||||||||||||||
197 | m_eventLoop->exit(); never executed: m_eventLoop->exit(); | 0 | ||||||||||||||||||
198 | } never executed: end of block | 0 | ||||||||||||||||||
199 | - | |||||||||||||||||||
200 | void QBasicDrag::updateCursor(Qt::DropAction action) | - | ||||||||||||||||||
201 | { | - | ||||||||||||||||||
202 | - | |||||||||||||||||||
203 | Qt::CursorShape cursorShape = Qt::ForbiddenCursor; | - | ||||||||||||||||||
204 | if (canDrop()
| 0 | ||||||||||||||||||
205 | switch (action) { | - | ||||||||||||||||||
206 | case never executed: Qt::CopyAction:case Qt::CopyAction: never executed: case Qt::CopyAction: | 0 | ||||||||||||||||||
207 | cursorShape = Qt::DragCopyCursor; | - | ||||||||||||||||||
208 | break; never executed: break; | 0 | ||||||||||||||||||
209 | case never executed: Qt::LinkAction:case Qt::LinkAction: never executed: case Qt::LinkAction: | 0 | ||||||||||||||||||
210 | cursorShape = Qt::DragLinkCursor; | - | ||||||||||||||||||
211 | break; never executed: break; | 0 | ||||||||||||||||||
212 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
213 | cursorShape = Qt::DragMoveCursor; | - | ||||||||||||||||||
214 | break; never executed: break; | 0 | ||||||||||||||||||
215 | } | - | ||||||||||||||||||
216 | } | - | ||||||||||||||||||
217 | - | |||||||||||||||||||
218 | QCursor *cursor = QGuiApplication::overrideCursor(); | - | ||||||||||||||||||
219 | QPixmap pixmap = m_drag->dragCursor(action); | - | ||||||||||||||||||
220 | if (!cursor
| 0 | ||||||||||||||||||
221 | QGuiApplication::changeOverrideCursor((pixmap.isNull()) ? QCursor(cursorShape) : QCursor(pixmap)); | - | ||||||||||||||||||
222 | } never executed: else {end of block | 0 | ||||||||||||||||||
223 | if (!pixmap.isNull()
| 0 | ||||||||||||||||||
224 | if ((
| 0 | ||||||||||||||||||
225 | QGuiApplication::changeOverrideCursor(QCursor(pixmap)); | - | ||||||||||||||||||
226 | } never executed: end of block | 0 | ||||||||||||||||||
227 | } never executed: else {end of block | 0 | ||||||||||||||||||
228 | if (cursorShape != cursor->shape()
| 0 | ||||||||||||||||||
229 | QGuiApplication::changeOverrideCursor(QCursor(cursorShape)); | - | ||||||||||||||||||
230 | } never executed: end of block | 0 | ||||||||||||||||||
231 | } never executed: end of block | 0 | ||||||||||||||||||
232 | } | - | ||||||||||||||||||
233 | - | |||||||||||||||||||
234 | updateAction(action); | - | ||||||||||||||||||
235 | } never executed: end of block | 0 | ||||||||||||||||||
236 | QSimpleDrag::QSimpleDrag() : m_current_window(0) | - | ||||||||||||||||||
237 | { | - | ||||||||||||||||||
238 | } never executed: end of block | 0 | ||||||||||||||||||
239 | - | |||||||||||||||||||
240 | QMimeData *QSimpleDrag::platformDropData() | - | ||||||||||||||||||
241 | { | - | ||||||||||||||||||
242 | if (drag()
| 0 | ||||||||||||||||||
243 | return never executed: drag()->mimeData();return drag()->mimeData(); never executed: return drag()->mimeData(); | 0 | ||||||||||||||||||
244 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
245 | } | - | ||||||||||||||||||
246 | - | |||||||||||||||||||
247 | void QSimpleDrag::startDrag() | - | ||||||||||||||||||
248 | { | - | ||||||||||||||||||
249 | QBasicDrag::startDrag(); | - | ||||||||||||||||||
250 | m_current_window = topLevelAt(QCursor::pos()); | - | ||||||||||||||||||
251 | if (m_current_window
| 0 | ||||||||||||||||||
252 | QPlatformDragQtResponse response = QWindowSystemInterface::handleDrag(m_current_window, drag()->mimeData(), QCursor::pos(), drag()->supportedActions()); | - | ||||||||||||||||||
253 | setCanDrop(response.isAccepted()); | - | ||||||||||||||||||
254 | updateCursor(response.acceptedAction()); | - | ||||||||||||||||||
255 | } never executed: else {end of block | 0 | ||||||||||||||||||
256 | setCanDrop(false); | - | ||||||||||||||||||
257 | updateCursor(Qt::IgnoreAction); | - | ||||||||||||||||||
258 | } never executed: end of block | 0 | ||||||||||||||||||
259 | setExecutedDropAction(Qt::IgnoreAction); | - | ||||||||||||||||||
260 | } never executed: end of block | 0 | ||||||||||||||||||
261 | - | |||||||||||||||||||
262 | void QSimpleDrag::cancel() | - | ||||||||||||||||||
263 | { | - | ||||||||||||||||||
264 | QBasicDrag::cancel(); | - | ||||||||||||||||||
265 | if (drag()
| 0 | ||||||||||||||||||
266 | QWindowSystemInterface::handleDrag(m_current_window, 0, QPoint(), Qt::IgnoreAction); | - | ||||||||||||||||||
267 | m_current_window = 0; | - | ||||||||||||||||||
268 | } never executed: end of block | 0 | ||||||||||||||||||
269 | } never executed: end of block | 0 | ||||||||||||||||||
270 | - | |||||||||||||||||||
271 | void QSimpleDrag::move(const QPoint &globalPos) | - | ||||||||||||||||||
272 | { | - | ||||||||||||||||||
273 | - | |||||||||||||||||||
274 | moveShapedPixmapWindow(globalPos); | - | ||||||||||||||||||
275 | QWindow *window = topLevelAt(globalPos); | - | ||||||||||||||||||
276 | if (!window
| 0 | ||||||||||||||||||
277 | return; never executed: return; | 0 | ||||||||||||||||||
278 | - | |||||||||||||||||||
279 | const QPoint pos = globalPos - window->geometry().topLeft(); | - | ||||||||||||||||||
280 | const QPlatformDragQtResponse qt_response = | - | ||||||||||||||||||
281 | QWindowSystemInterface::handleDrag(window, drag()->mimeData(), pos, drag()->supportedActions()); | - | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | updateCursor(qt_response.acceptedAction()); | - | ||||||||||||||||||
284 | setCanDrop(qt_response.isAccepted()); | - | ||||||||||||||||||
285 | } never executed: end of block | 0 | ||||||||||||||||||
286 | - | |||||||||||||||||||
287 | void QSimpleDrag::drop(const QPoint &globalPos) | - | ||||||||||||||||||
288 | { | - | ||||||||||||||||||
289 | - | |||||||||||||||||||
290 | - | |||||||||||||||||||
291 | QBasicDrag::drop(globalPos); | - | ||||||||||||||||||
292 | QWindow *window = topLevelAt(globalPos); | - | ||||||||||||||||||
293 | if (!window
| 0 | ||||||||||||||||||
294 | return; never executed: return; | 0 | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | const QPoint pos = globalPos - window->geometry().topLeft(); | - | ||||||||||||||||||
297 | const QPlatformDropQtResponse response = | - | ||||||||||||||||||
298 | QWindowSystemInterface::handleDrop(window, drag()->mimeData(),pos, drag()->supportedActions()); | - | ||||||||||||||||||
299 | if (response.isAccepted()
| 0 | ||||||||||||||||||
300 | setExecutedDropAction(response.acceptedAction()); | - | ||||||||||||||||||
301 | } never executed: else {end of block | 0 | ||||||||||||||||||
302 | setExecutedDropAction(Qt::IgnoreAction); | - | ||||||||||||||||||
303 | } never executed: end of block | 0 | ||||||||||||||||||
304 | } | - | ||||||||||||||||||
305 | - | |||||||||||||||||||
306 | - | |||||||||||||||||||
307 | - | |||||||||||||||||||
308 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |