qsimpledrag.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9