bool QVistaHelper::eventFilter(QObject *obj, QEvent *event) { if (obj != wizard) return QObject::eventFilter(obj, event); if (event->type() == QEvent::MouseMove) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); long result; MSG msg; msg.message = WM_NCHITTEST; msg.wParam = 0; msg.lParam = MAKELPARAM(mouseEvent->globalX(), mouseEvent->globalY()); msg.hwnd = wizardHWND(); winEvent(&msg, &result); msg.wParam = result; msg.message = WM_NCMOUSEMOVE; winEvent(&msg, &result); } else if (event->type() == QEvent::MouseButtonPress) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); if (mouseEvent->button() == Qt::LeftButton) { long result; MSG msg; msg.message = WM_NCHITTEST; msg.wParam = 0; msg.lParam = MAKELPARAM(mouseEvent->globalX(), mouseEvent->globalY()); msg.hwnd = wizardHWND(); winEvent(&msg, &result); msg.wParam = result; msg.message = WM_NCLBUTTONDOWN; winEvent(&msg, &result); } } else if (event->type() == QEvent::MouseButtonRelease) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); if (mouseEvent->button() == Qt::LeftButton) { long result; MSG msg; msg.message = WM_NCHITTEST; msg.wParam = 0; msg.lParam = MAKELPARAM(mouseEvent->globalX(), mouseEvent->globalY()); msg.hwnd = wizardHWND(); winEvent(&msg, &result); msg.wParam = result; msg.message = WM_NCLBUTTONUP; winEvent(&msg, &result); } } return false; }
bool TopBar::eventFilter(QObject *object, QEvent *event) { if(object == ui->buttonIcon) { if(event->type() == QEvent::MouseButtonPress) { canMoveTopbar = true; QMouseEvent *e = (QMouseEvent *)event; pressedMouseX = e->x(); pressedMouseY = e->y(); event->accept(); } else if (event->type() == QEvent::MouseMove) { if(canMoveTopbar) { QMouseEvent *e = (QMouseEvent *)event; ui->buttonIcon->setCursor(Qt::ClosedHandCursor); move(e->globalX() - pressedMouseX, e->globalY() - pressedMouseY); } } else if(event->type() == QEvent::MouseButtonRelease) { canMoveTopbar = false; ui->buttonIcon->setCursor(Qt::OpenHandCursor); event->accept(); } else if(event->type() == QEvent::Enter) { ui->buttonIcon->setCursor(Qt::OpenHandCursor); } } return QObject::eventFilter(object, event); }
void GAllEvents::storeMouseState(QEvent *event) { QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); this->nX = mouseEvent->x(); this->nY = mouseEvent->y(); this->nGlobalX = mouseEvent->globalX(); this->nGlobalY = mouseEvent->globalY(); this->nButton = mouseEvent->button(); this->nButtons = mouseEvent->buttons(); }
void CPrivateInfo::mouseMoveEvent(QMouseEvent *ev) { QMouseEvent *mv = (QMouseEvent*) ev; QRect labelrect = QRect(ui->lb_top->pos() + this->pos(), ui->lb_top->size()); if(labelrect.contains(mv->globalPos())) { this->move(mv->globalX() - m_Ptcur.rx(), mv->globalY() - m_Ptcur.ry()); m_Ptbefore = mv->globalPos(); sleep(0.1); } }
void QKmsCursor::pointerEvent(const QMouseEvent &event) { m_moved = true; int status = drmModeMoveCursor(m_screen->device()->fd(), m_screen->crtcId(), event.globalX(), event.globalY()); if (status) { qWarning("failed to move cursor: %d", status); } }
dmz::V8Value dmz::JsModuleUiV8QtBasic::_mouse_event_global_y (const v8::Arguments &Args) { v8::HandleScope scope; V8Value result = v8::Undefined (); JsModuleUiV8QtBasic *self = _to_self (Args); if (self) { QMouseEvent *event = (QMouseEvent *)self->_to_qevent (Args.This ()); if (event) { result = v8::Number::New (event->globalY ()); } } return scope.Close (result); }
bool UIDnDMimeData::eventFilter(QObject *pObject, QEvent *pEvent) { if (pEvent) { switch (pEvent->type()) { #ifdef DEBUG_andy case QEvent::MouseMove: { QMouseEvent *pMouseEvent = (QMouseEvent*)(pEvent); AssertPtr(pMouseEvent); LogFlowFunc(("MouseMove: x=%d, y=%d\n", pMouseEvent->globalX(), pMouseEvent->globalY())); return true; /* Never reached. */ } #endif case QEvent::MouseButtonRelease: { LogFlowFunc(("MouseButtonRelease\n")); m_enmState = Dropped; return true; /* Never reached. */ } case QEvent::KeyPress: { /* ESC pressed? */ if (static_cast<QKeyEvent*>(pEvent)->key() == Qt::Key_Escape) { LogFlowFunc(("ESC pressed, cancelling drag and drop operation\n")); m_enmState = Canceled; } return true; /* Never reached. */ } default: break; } } return QObject::eventFilter(pObject, pEvent); }
bool XCA_application::eventFilter(QObject *watched, QEvent *ev) { static int mctr; QMouseEvent *me; QStringList l; XcaTreeView *treeview; int key; switch (ev->type()) { case QEvent::FileOpen: l << static_cast<QFileOpenEvent *>(ev)->file(); mainw->openURLs(l); return true; case QEvent::MouseMove: case QEvent::NonClientAreaMouseMove: if (mctr++ > 8) { me = static_cast<QMouseEvent *>(ev); entropy.add(me->globalX()); entropy.add(me->globalY()); mctr = 0; } break; case QEvent::KeyPress: key = static_cast<QKeyEvent *>(ev)->key(); if (key < 0x100) { entropy.add(key); } break; case QEvent::MouseButtonPress: me = static_cast<QMouseEvent *>(ev); treeview = watched ? dynamic_cast<XcaTreeView*>(watched->parent()) : NULL; if ((watched == mainw || treeview) && me->button() == Qt::MidButton && QApplication::clipboard()->supportsSelection()) { mainw->pastePem(); return true; } break; default: break; } return false; }
bool CameraWidget::eventFilter(QObject *target, QEvent *event) { if (target == _POIsImageWidget && event->type() == QEvent::MouseButtonPress) { QMouseEvent *mouseEvent = static_cast<QMouseEvent *> (event); //--- Pauses Video Capture _videoController->stopVideoCapture(); POI selectedPOI = _POIsImageWidget->getPOIAtPosition(mouseEvent->x(), mouseEvent->y()); //--- Valid POI must have coordinates > 0 if (selectedPOI.getCoordinates2d().x > 0) { //--- Removes old POI if it already has semantic if (selectedPOI.isInitialized()) { _videoController->getCamera()->removePOI(selectedPOI.getSemantic().toStdString()); } QPoint dialogPosition(mouseEvent->globalX(), mouseEvent->globalY()); POISemanticSelectionDialog POISemanticDialog(this, &selectedPOI, dialogPosition, _POISemanticTypesRef); //--- POI semantic selection POISemanticDialog.exec(); //--- Predicted position now should be the observed position selectedPOI.setPredictedPosition(selectedPOI.getCoordinates2d()); //--- Inserts POI with updated semantic _videoController->getCamera()->insertPOI(selectedPOI); } _videoController->startVideoCapture(); } return QWidget::eventFilter(target, event); }
bool Application:: notify(QObject * receiver, QEvent * e) { bool v = false; string err; try { if (e) { QEvent::Type t = e->type(); switch (t) { case QEvent::MouseButtonPress: { QMouseEvent* m = static_cast<QMouseEvent*>(e); TaskInfo("QEvent::MouseButtonPress button=%d at %d, %d (%d, %d) on %s %s %p", m->button(), m->x(), m->y(), m->globalX(), m->globalY(), vartype(*receiver).c_str(), receiver->objectName().toStdString().c_str(), receiver); break; } case QEvent::MouseButtonRelease: { QMouseEvent* m = static_cast<QMouseEvent*>(e); TaskInfo("QEvent::MouseButtonRelease button=%d at %d, %d (%d, %d) from %s %s %p", m->button(), m->pos().x(), m->pos().y(), m->globalX(), m->globalY(), vartype(*receiver).c_str(), receiver->objectName().toStdString().c_str(), receiver); break; } case QEvent::KeyPress: { QKeyEvent* m = static_cast<QKeyEvent*>(e); TaskInfo(boost::format("QEvent::KeyPress key=0x%x on %s [%s %p]") % m->key() % vartype(*receiver) % receiver->objectName().toStdString() % receiver); break; } default: break; } switch (t) { case QEvent::MouseButtonPress: case QEvent::KeyPress: case QEvent::Show: case QEvent::Enter: foreach (pProject p, _projects) { if (receiver == p->mainWindow()) p->tools().render_view()->redraw(); } break; default: break; } } v = QApplication::notify(receiver,e); } catch (...) { Tools::ApplicationErrorLogController::registerException (boost::current_exception ()); } return v; }
bool MainWindow::eventFilter(QObject *obj, QEvent *event) { QKeyEvent *kevent; QMouseEvent *mevent; QString position; static bool interior = false; UNUSED_PARAMETER(obj); switch (event->type()) { case QEvent::MouseMove: mevent = static_cast<QMouseEvent *>(event); interior = frameGeometry().contains(mevent->globalPos()); if (m_mouseAcquired) { position = QString::number(mevent->globalX()) + "," + QString::number(mevent->globalY()); ui->statusBar->showMessage("Mouse move " + position); writeDatagram(DFBINPUT_MOUSE_MOTION, 0, mevent->globalX(), mevent->globalY()); } break; case QEvent::KeyPress: kevent = static_cast<QKeyEvent *>(event); if (m_mouseAcquired) { // Forward the event to the MainWindow if (kevent->modifiers() & Qt::ControlModifier) return false; ui->statusBar->showMessage("Key press " + kevent->text()); if (kevent->text().length() > 0) writeDatagram(DFBINPUT_KEYPRESS, kevent->text().at(0).toAscii(), 0, 0); } break; case QEvent::MouseButtonPress: if (m_mouseAcquired) { mevent = static_cast<QMouseEvent *>(event); position = QString::number(mevent->globalX()) + "," + QString::number(mevent->globalY()); ui->statusBar->showMessage("Mouse click at " + position); writeDatagram(DFBINPUT_MOUSE_CLICK, mevent->button() == Qt::LeftButton ? 1 : (mevent->button() == Qt::RightButton ? 2 : 0), mevent->globalX(), mevent->globalY()); } break; case QEvent::MouseButtonDblClick: if (m_mouseAcquired) { mevent = static_cast<QMouseEvent *>(event); position = QString::number(mevent->globalX()) + "," + QString::number(mevent->globalY()); ui->statusBar->showMessage("Mouse double-click at " + position); writeDatagram(DFBINPUT_MOUSE_DBLCLICK, mevent->button() == Qt::LeftButton ? 1 : (mevent->button() == Qt::RightButton ? 2 : 0), mevent->globalX(), mevent->globalY()); } break; case QEvent::Leave: if (m_mouseAcquired && interior) grabMouse(); break; default: return false; } return true; }
bool QtInputService::eventFilter(QObject *obj, QEvent *event) { switch(event->type()) { case QEvent::KeyPress: { QKeyEvent *e = static_cast<QKeyEvent*>(event); KeyEvent keyEvent; keyEvent.keyCode = StripModifiersFromKey(e->key()); keyEvent.keyPressCount = 1; keyEvent.modifiers = e->modifiers(); keyEvent.text = e->text(); keyEvent.sequence = QKeySequence(e->key() | e->modifiers()); ///\todo Track multi-key sequences. keyEvent.eventType = KeyEvent::KeyPressed; // keyEvent.otherHeldKeys = heldKeys; ///\todo keyEvent.handled = false; current_modifiers_ = e->modifiers(); // local tracking for mouse events // We only take key events from the main QGraphicsView. if (obj != qobject_cast<QObject*>(mainView)) return false; std::map<Qt::Key, KeyPressInformation>::iterator keyRecord = heldKeys.find(keyEvent.keyCode); if (keyRecord != heldKeys.end()) { if (e->isAutoRepeat()) // If this is a repeat, track the proper keyPressCount. { keyEvent.keyPressCount = ++keyRecord->second.keyPressCount; keyEvent.sequence = QKeySequence(); // Repeated keys do not trigger keysequences. } } else { KeyPressInformation info; info.keyPressCount = 1; info.keyState = KeyEvent::KeyPressed; // info.firstPressTime = now; ///\todo heldKeys[keyEvent.keyCode] = info; } // Queue up the press event for the polling API, independent of whether any Qt widget has keyboard focus. if (keyEvent.keyPressCount == 1) /// \todo The polling API does not get key repeats at all. Should it? newKeysPressedQueue.push_back(StripModifiersFromKey(e->key())); TriggerKeyEvent(keyEvent); return keyEvent.handled; // If we got true here, need to suppress this event from going to Qt. } case QEvent::KeyRelease: { // We only take key events from the main window. if (obj != qobject_cast<QObject*>(mainWindow)) return false; QKeyEvent *e = static_cast<QKeyEvent *>(event); // Our input system policy: Key releases on repeated keys are not transmitted. This means // that the client gets always a sequences like "press (first), press(1st repeat), press(2nd repeat), release", // instead of "press(first), release, press(1st repeat), release, press(2nd repeat), release". if (e->isAutoRepeat()) return false; HeldKeysMap::iterator existingKey = heldKeys.find(StripModifiersFromKey(e->key())); // If we received a release on an unknown key we haven't received a press for, don't pass it to the scene, // since we didn't pass the press to the scene either (or we've already passed the release before, so don't // pass duplicate releases). if (existingKey == heldKeys.end()) return false; KeyEvent keyEvent; keyEvent.keyCode = StripModifiersFromKey(e->key()); keyEvent.keyPressCount = existingKey->second.keyPressCount; keyEvent.modifiers = e->modifiers(); keyEvent.text = e->text(); keyEvent.eventType = KeyEvent::KeyReleased; // keyEvent.otherHeldKeys = heldKeys; ///\todo keyEvent.handled = false; heldKeys.erase(existingKey); current_modifiers_ = e->modifiers(); // local tracking for mouse events // Queue up the release event for the polling API, independent of whether any Qt widget has keyboard focus. if (keyEvent.keyPressCount == 1) /// \todo The polling API does not get key repeats at all. Should it? newKeysReleasedQueue.push_back(StripModifiersFromKey(e->key())); TriggerKeyEvent(keyEvent); return keyEvent.handled; // Suppress this event from going forward. } case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: { // We only take mouse button press and release events from the main QGraphicsView viewport. if (obj != qobject_cast<QObject*>(mainView->viewport())) return false; QMouseEvent *e = static_cast<QMouseEvent *>(event); // QGraphicsItem *itemUnderMouse = GetVisibleItemAtCoords(e->x(), e->y()); /* // Update the flag that tracks whether the inworld scene or QGraphicsScene is grabbing mouse movement. if (event->type() == QEvent::MouseButtonPress) sceneMouseCapture = (itemUnderMouse ? QtMouseCapture : SceneMouseCapture); else // event type == MouseButtonRelease sceneMouseCapture = NoMouseCapture; */ // We always update the global polled input states, independent of whether any the mouse cursor is // on top of any Qt widget. if (event->type() == QEvent::MouseButtonPress) { heldMouseButtons |= (MouseEvent::MouseButton)e->button(); newMouseButtonsPressedQueue |= (MouseEvent::MouseButton)e->button(); } else { if (lastMouseButtonReleaseTime.msecsTo(QTime::currentTime()) < 300) { doubleClickDetected = true; } heldMouseButtons &= ~(MouseEvent::MouseButton)e->button(); newMouseButtonsReleasedQueue |= (MouseEvent::MouseButton)e->button(); lastMouseButtonReleaseTime = QTime::currentTime(); } // If there's a visible QGraphicsItem under the mouse and mouse is not in FPS mode, // the click's supposed to go there - don't send it at all to inworld scene. // if (itemUnderMouse && mouseCursorVisible) // return false; // The mouse coordinates we receive can come from different widgets, and we are interested only in the coordinates // in the QGraphicsView client area, so we need to remap them. QPoint mousePos = MapPointToMainGraphicsView(obj, e->pos()); MouseEvent mouseEvent; mouseEvent.itemUnderMouse = GetVisibleItemAtCoords(e->x(), e->y()); mouseEvent.origin = mouseEvent.itemUnderMouse ? MouseEvent::PressOriginQtWidget : MouseEvent::PressOriginScene; if ( !doubleClickDetected) { mouseEvent.eventType = (event->type() == QEvent::MouseButtonPress) ? MouseEvent::MousePressed : MouseEvent::MouseReleased; } else { mouseEvent.eventType = MouseEvent::MouseDoubleClicked; } mouseEvent.button = (MouseEvent::MouseButton)e->button(); mouseEvent.x = mousePos.x(); mouseEvent.y = mousePos.y(); mouseEvent.z = 0; mouseEvent.relativeX = mouseEvent.x - lastMouseX; mouseEvent.relativeY = mouseEvent.y - lastMouseY; mouseEvent.modifiers = current_modifiers_; lastMouseX = mouseEvent.x; lastMouseY = mouseEvent.y; mouseEvent.globalX = e->globalX(); mouseEvent.globalY = e->globalY(); mouseEvent.otherButtons = e->buttons(); // mouseEvent.heldKeys = heldKeys; ///\todo mouseEvent.handled = false; // The mouse press is going to the inworld scene - clear keyboard focus from the QGraphicsScene widget, if any had it so key events also go to inworld scene. if (event->type() == QEvent::MouseButtonPress && !mouseEvent.itemUnderMouse && mouseCursorVisible) mainView->scene()->clearFocus(); TriggerMouseEvent(mouseEvent); return mouseEvent.handled; } case QEvent::MouseMove: { // If a mouse button is held down, we get the mouse drag events from the viewport widget. // If a mouse button is not held down, the application main window will get the events. // Duplicate events are not received, so no need to worry about filtering them here. QMouseEvent *e = static_cast<QMouseEvent *>(event); //QGraphicsItem *itemUnderMouse = GetVisibleItemAtCoords(e->x(), e->y()); // If there is a graphicsItem under the mouse, don't pass the move message to the inworld scene, unless the inworld scene has captured it. // if (mouseCursorVisible) // if ((itemUnderMouse && sceneMouseCapture != SceneMouseCapture) || sceneMouseCapture == QtMouseCapture) // return false; // if (mouseCursorVisible && itemUnderMouse) // return false; MouseEvent mouseEvent; mouseEvent.eventType = MouseEvent::MouseMove; mouseEvent.button = (MouseEvent::MouseButton)e->button(); mouseEvent.itemUnderMouse = GetVisibleItemAtCoords(e->x(), e->y()); ///\todo Set whether the previous press originated over a Qt widget or scene. mouseEvent.origin = mouseEvent.itemUnderMouse ? MouseEvent::PressOriginQtWidget : MouseEvent::PressOriginScene; QWidget *sender = qobject_cast<QWidget*>(obj); assert(sender); // The mouse coordinates we receive can come from different widgets, and we are interested only in the coordinates // in the QGraphicsView client area, so we need to remap them. QPoint mousePos = MapPointToMainGraphicsView(obj, e->pos()); if (mouseCursorVisible) { mouseEvent.x = mousePos.x(); mouseEvent.y = mousePos.y(); } else { // If mouse cursor is hidden, we're in relative "crosshair" mode. In this mode, // the mouse absolute coordinates are restricted to stay in the center of the screen. mouseEvent.x = mainView->size().width()/2; mouseEvent.y = mainView->size().height()/2; } mouseEvent.z = 0; mouseEvent.relativeX = mousePos.x() - lastMouseX; mouseEvent.relativeY = mousePos.y() - lastMouseY; // If there wasn't any change to the mouse relative coords in FPS mode, ignore this event. if (!mouseCursorVisible && mouseEvent.relativeX == 0 && mouseEvent.relativeY == 0) return true; mouseEvent.globalX = e->globalX(); // Note that these may "jitter" when mouse is in relative movement mode. mouseEvent.globalY = e->globalY(); mouseEvent.otherButtons = e->buttons(); // mouseEvent.heldKeys = heldKeys; ///\todo mouseEvent.handled = false; // Save the absolute coordinates to be able to compute the proper relative movement values in the next // mouse event. lastMouseX = mouseEvent.x; lastMouseY = mouseEvent.y; TriggerMouseEvent(mouseEvent); // In relative mouse movement mode, keep the mouse cursor hidden at screen center at all times. if (!mouseCursorVisible) { RecenterMouse(); return true; // In relative mouse movement mode, the QGraphicsScene does not receive mouse movement at all. } return mouseEvent.handled; } case QEvent::Wheel: { // If this event did not originate from the application main window, we are not interested in it. if (obj != qobject_cast<QObject*>(mainWindow)) return false; QObject *mv = qobject_cast<QObject*>(mainView); QObject *mw = qobject_cast<QObject*>(mainWindow); QWheelEvent *e = static_cast<QWheelEvent *>(event); // QGraphicsItem *itemUnderMouse = GetVisibleItemAtCoords(e->x(), e->y()); // if (itemUnderMouse) // return false; MouseEvent mouseEvent; mouseEvent.eventType = MouseEvent::MouseScroll; mouseEvent.itemUnderMouse = GetVisibleItemAtCoords(e->x(), e->y()); mouseEvent.origin = mouseEvent.itemUnderMouse ? MouseEvent::PressOriginQtWidget : MouseEvent::PressOriginScene; mouseEvent.button = MouseEvent::NoButton; mouseEvent.otherButtons = e->buttons(); mouseEvent.x = e->x(); mouseEvent.y = e->y(); mouseEvent.z = 0; // Mouse wheel does not have an absolute z position, only relative. mouseEvent.relativeX = 0; mouseEvent.relativeY = 0; mouseEvent.relativeZ = e->delta(); mouseEvent.globalX = e->globalX(); mouseEvent.globalY = e->globalY(); mouseEvent.otherButtons = e->buttons(); ///\todo Can this be trusted? // mouseEvent.heldKeys = heldKeys; ///\todo mouseEvent.handled = false; TriggerMouseEvent(mouseEvent); return mouseEvent.handled; } } // ~switch return QObject::eventFilter(obj, event); }