bool QBasicDrag::eventFilter(QObject *o, QEvent *e) { Q_UNUSED(o); if (!m_drag) { if (e->type() == QEvent::KeyRelease && static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) { disableEventFilter(); exitDndEventLoop(); return true; // block the key release } return false; } switch (e->type()) { case QEvent::ShortcutOverride: // prevent accelerators from firing while dragging e->accept(); return true; case QEvent::KeyPress: case QEvent::KeyRelease: { QKeyEvent *ke = static_cast<QKeyEvent *>(e); if (ke->key() == Qt::Key_Escape && e->type() == QEvent::KeyPress) { cancel(); disableEventFilter(); exitDndEventLoop(); } return true; // Eat all key events } case QEvent::MouseMove: { QPoint nativePosition = getNativeMousePos(e, o); move(nativePosition); return true; // Eat all mouse move events } case QEvent::MouseButtonRelease: disableEventFilter(); if (canDrop()) { QPoint nativePosition = getNativeMousePos(e, o); drop(nativePosition); } else { cancel(); } exitDndEventLoop(); QCoreApplication::postEvent(o, new QMouseEvent(*static_cast<QMouseEvent *>(e))); return true; // defer mouse release events until drag event loop has returned case QEvent::MouseButtonDblClick: case QEvent::Wheel: return true; default: break; } return false; }
bool QBasicDrag::eventFilter(QObject *o, QEvent *e) { Q_UNUSED(o); if (!m_drag) { if (e->type() == QEvent::KeyRelease && static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) { disableEventFilter(); exitDndEventLoop(); return true; // block the key release } return false; } switch (e->type()) { case QEvent::ShortcutOverride: // prevent accelerators from firing while dragging e->accept(); return true; case QEvent::KeyPress: case QEvent::KeyRelease: { QKeyEvent *ke = static_cast<QKeyEvent *>(e); if (ke->key() == Qt::Key_Escape && e->type() == QEvent::KeyPress) { cancel(); disableEventFilter(); exitDndEventLoop(); } return true; // Eat all key events } case QEvent::MouseMove: move(static_cast<QMouseEvent *>(e)); return true; // Eat all mouse events case QEvent::MouseButtonRelease: disableEventFilter(); if (canDrop()) { drop(static_cast<QMouseEvent *>(e)); } else { cancel(); } exitDndEventLoop(); return true; // Eat all mouse events case QEvent::MouseButtonPress: case QEvent::MouseButtonDblClick: case QEvent::Wheel: return true; default: break; } return false; }