| 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::cancelDrag() | - | ||||||||||||||||||
| 128 | { | - | ||||||||||||||||||
| 129 | if (m_eventLoop
| 0 | ||||||||||||||||||
| 130 | cancel(); | - | ||||||||||||||||||
| 131 | m_eventLoop->quit(); | - | ||||||||||||||||||
| 132 | } never executed: end of block | 0 | ||||||||||||||||||
| 133 | } never executed: end of block | 0 | ||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | void QBasicDrag::restoreCursor() | - | ||||||||||||||||||
| 136 | { | - | ||||||||||||||||||
| 137 | if (m_restoreCursor
| 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 | - | |||||||||||||||||||
| 145 | void QBasicDrag::startDrag() | - | ||||||||||||||||||
| 146 | { | - | ||||||||||||||||||
| 147 | QPoint pos; | - | ||||||||||||||||||
| 148 | - | |||||||||||||||||||
| 149 | pos = QCursor::pos(); | - | ||||||||||||||||||
| 150 | if (pos.x() == int(qInf())
| 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 | - | |||||||||||||||||||
| 159 | void QBasicDrag::endDrag() | - | ||||||||||||||||||
| 160 | { | - | ||||||||||||||||||
| 161 | } | - | ||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | void 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 | - | |||||||||||||||||||
| 177 | void 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 | - | |||||||||||||||||||
| 189 | void QBasicDrag::moveShapedPixmapWindow(const QPoint &globalPos) | - | ||||||||||||||||||
| 190 | { | - | ||||||||||||||||||
| 191 | if (m_drag
| 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 | - | |||||||||||||||||||
| 195 | void QBasicDrag::drop(const QPoint &) | - | ||||||||||||||||||
| 196 | { | - | ||||||||||||||||||
| 197 | disableEventFilter(); | - | ||||||||||||||||||
| 198 | restoreCursor(); | - | ||||||||||||||||||
| 199 | m_drag_icon_window->setVisible(false); | - | ||||||||||||||||||
| 200 | } never executed: end of block | 0 | ||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | void QBasicDrag::exitDndEventLoop() | - | ||||||||||||||||||
| 203 | { | - | ||||||||||||||||||
| 204 | if (m_eventLoop
| 0 | ||||||||||||||||||
| 205 | m_eventLoop->exit(); never executed: m_eventLoop->exit(); | 0 | ||||||||||||||||||
| 206 | } never executed: end of block | 0 | ||||||||||||||||||
| 207 | - | |||||||||||||||||||
| 208 | void QBasicDrag::updateCursor(Qt::DropAction action) | - | ||||||||||||||||||
| 209 | { | - | ||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | Qt::CursorShape cursorShape = Qt::ForbiddenCursor; | - | ||||||||||||||||||
| 212 | if (canDrop()
| 0 | ||||||||||||||||||
| 213 | switch (action) { | - | ||||||||||||||||||
| 214 | case never executed: Qt::CopyAction:case Qt::CopyAction:never executed: case Qt::CopyAction: | 0 | ||||||||||||||||||
| 215 | cursorShape = Qt::DragCopyCursor; | - | ||||||||||||||||||
| 216 | break; never executed: break; | 0 | ||||||||||||||||||
| 217 | case never executed: Qt::LinkAction:case 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
| 0 | ||||||||||||||||||
| 229 | QGuiApplication::changeOverrideCursor((pixmap.isNull()) ? QCursor(cursorShape) : QCursor(pixmap)); | - | ||||||||||||||||||
| 230 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 231 | if (!pixmap.isNull()
| 0 | ||||||||||||||||||
| 232 | if ((
| 0 | ||||||||||||||||||
| 233 | QGuiApplication::changeOverrideCursor(QCursor(pixmap)); | - | ||||||||||||||||||
| 234 | } never executed: end of block | 0 | ||||||||||||||||||
| 235 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 236 | if (cursorShape != cursor->shape()
| 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 | ||||||||||||||||||
| 244 | QSimpleDrag::QSimpleDrag() : m_current_window(0) | - | ||||||||||||||||||
| 245 | { | - | ||||||||||||||||||
| 246 | } never executed: end of block | 0 | ||||||||||||||||||
| 247 | - | |||||||||||||||||||
| 248 | QMimeData *QSimpleDrag::platformDropData() | - | ||||||||||||||||||
| 249 | { | - | ||||||||||||||||||
| 250 | if (drag()
| 0 | ||||||||||||||||||
| 251 | return never executed: drag()->mimeData();return drag()->mimeData();never executed: return drag()->mimeData(); | 0 | ||||||||||||||||||
| 252 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 253 | } | - | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | void QSimpleDrag::startDrag() | - | ||||||||||||||||||
| 256 | { | - | ||||||||||||||||||
| 257 | QBasicDrag::startDrag(); | - | ||||||||||||||||||
| 258 | m_current_window = topLevelAt(QCursor::pos()); | - | ||||||||||||||||||
| 259 | if (m_current_window
| 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: else {end of block | 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 | - | |||||||||||||||||||
| 270 | void QSimpleDrag::cancel() | - | ||||||||||||||||||
| 271 | { | - | ||||||||||||||||||
| 272 | QBasicDrag::cancel(); | - | ||||||||||||||||||
| 273 | if (drag()
| 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 | - | |||||||||||||||||||
| 279 | void QSimpleDrag::move(const QPoint &globalPos) | - | ||||||||||||||||||
| 280 | { | - | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | moveShapedPixmapWindow(globalPos); | - | ||||||||||||||||||
| 283 | QWindow *window = topLevelAt(globalPos); | - | ||||||||||||||||||
| 284 | if (!window
| 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 | - | |||||||||||||||||||
| 295 | void QSimpleDrag::drop(const QPoint &globalPos) | - | ||||||||||||||||||
| 296 | { | - | ||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | - | |||||||||||||||||||
| 299 | QBasicDrag::drop(globalPos); | - | ||||||||||||||||||
| 300 | QWindow *window = topLevelAt(globalPos); | - | ||||||||||||||||||
| 301 | if (!window
| 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()
| 0 | ||||||||||||||||||
| 308 | setExecutedDropAction(response.acceptedAction()); | - | ||||||||||||||||||
| 309 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 310 | setExecutedDropAction(Qt::IgnoreAction); | - | ||||||||||||||||||
| 311 | } never executed: end of block | 0 | ||||||||||||||||||
| 312 | } | - | ||||||||||||||||||
| 313 | - | |||||||||||||||||||
| 314 | - | |||||||||||||||||||
| 315 | - | |||||||||||||||||||
| 316 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |