static gboolean btnReleaseHook(GSignalInvocationHint*, unsigned, const GValue*, void*) { if (dragWidget) dragEnd(); return true; }
void CQDrag:: mouseMoveEvent(QMouseEvent *event) { // set press point (if not already set) if (! pressed_) { pressPos_ = event->pos(); pressed_ = true; } // Ignore if left button isn't pressed if (! (event->buttons() & Qt::LeftButton)) return; // If the distance is too small then return if ((event->pos() - pressPos_).manhattanLength() < QApplication::startDragDistance()) return; emit dragStart(); // initiate drag QDrag *drag = new QDrag(this); drag->setPixmap(QPixmap(drag_data)); QMimeData *mimeData = new QMimeData; mimeData->setData("action", "CQDrag"); drag->setMimeData(mimeData); drag->exec(); emit dragEnd(); }
static void trigger(GtkWidget *w, int x, int y) { GtkWindow *topLevel = GTK_WINDOW(gtk_widget_get_toplevel(w)); xcb_window_t wid = GDK_WINDOW_XID(gtk_widget_get_window(GTK_WIDGET(topLevel))); qtcX11MoveTrigger(wid, x, y); dragEnd(); }
void CInputHandler::processMessage(CMessage *msg) { const CMouseMsg *mouseMsg = dynamic_cast<const CMouseMsg *>(msg); _singleton = false; dispatchMessage(msg); if (_singleton) { _singleton = false; } else if (mouseMsg) { // Keep the game state mouse position up to date if (_mousePos != mouseMsg->_mousePos) { _mousePos = mouseMsg->_mousePos; _gameManager->_gameState.setMousePos(mouseMsg->_mousePos); } // Set flag for whether a mouse button is currently being pressed if (mouseMsg->isButtonDownMsg()) _buttonDown = true; else if (mouseMsg->isButtonUpMsg()) _buttonDown = false; // Drag events generation if (_dragging) { if (mouseMsg->isMouseMoveMsg()) { if (_dragItem) { CMouseDragMoveMsg moveMsg(_mousePos); moveMsg.execute(_dragItem); } } else { if (mouseMsg->isButtonUpMsg() && _dragItem) { // Mouse drag ended CGameObject *target = dragEnd(_mousePos, _dragItem); CMouseDragEndMsg endMsg(_mousePos, target); endMsg.execute(_dragItem); } _dragging = false; _dragItem = nullptr; } } else if (_buttonDown) { if (!mouseMsg->isMouseMoveMsg()) { // Save where the drag movement started from _dragStartPos = _mousePos; } else { Point delta = mouseMsg->_mousePos - _dragStartPos; int distance = (int)sqrt(double(delta.x * delta.x + delta.y * delta.y)); if (distance > 4) { // We've moved far enough with the mouse button held down // to trigger an official dragging operation CMouseDragStartMsg startMsg(_dragStartPos); dispatchMessage(&startMsg); // Set the drag item, if any, that a handler will have set on the message _dragItem = startMsg._dragItem; _gameManager->_dragItem = startMsg._dragItem; if (_dragItem) { CMouseDragMoveMsg moveMsg(_dragStartPos); dispatchMessage(&moveMsg); } _dragging = true; } } } } }
static gboolean leave(GtkWidget*, GdkEventMotion*, void*) { return dragEnd(); }