void AbstractScopeWidget::mouseMoveEvent(QMouseEvent *event) { m_mousePos = event->pos(); m_mouseWithinWidget = true; emit signalMousePositionChanged(); QPoint movement = event->pos()-m_rescaleStartPoint; if (m_rescaleActive) { if (m_rescalePropertiesLocked) { // Direction is known, now adjust parameters // Reset the starting point to make the next moveEvent relative to the current one m_rescaleStartPoint = event->pos(); if (!m_rescaleFirstRescaleDone) { // We have just learned the desired direction; Normalize the movement to one pixel // to avoid a jump by m_rescaleMinDist if (movement.x() != 0) { movement.setX(movement.x() / abs(movement.x())); } if (movement.y() != 0) { movement.setY(movement.y() / abs(movement.y())); } m_rescaleFirstRescaleDone = true; } handleMouseDrag(movement, m_rescaleDirection, m_rescaleModifiers); } else { // Detect the movement direction here. // This algorithm relies on the aspect ratio of dy/dx (size and signum). if (movement.manhattanLength() > m_rescaleMinDist) { float diff = ((float) movement.y())/movement.x(); if (fabs(diff) > m_rescaleVerticalThreshold || movement.x() == 0) { m_rescaleDirection = North; } else if (fabs(diff) < 1/m_rescaleVerticalThreshold) { m_rescaleDirection = East; } else if (diff < 0) { m_rescaleDirection = Northeast; } else { m_rescaleDirection = Southeast; } #ifdef DEBUG_ASW qDebug() << "Diff is " << diff << "; chose " << directions[m_rescaleDirection] << " as direction"; #endif m_rescalePropertiesLocked = true; } } } }
void updateMouseEvent(uint tick, int x, int y) { event = 0; if (left_down) { down_pos_x = x; down_pos_y = y; if (!left_btn_down) { left_btn_down = 1; } else { event = MOUSE_DRAGGING; } } else { if (left_btn_down) { left_btn_down = 0; down_pos_x = 0; down_pos_y = 0; if (tick - last_tick <= 30) event = LEFT_DOUBLE_CLICK; else { if (mouse_info.event == MOUSE_DRAGGING) event = 0; else event = LEFT_CLICK; } if (event == LEFT_DOUBLE_CLICK) last_tick = -30; else last_tick = tick; } } if (right_down) { if (!right_btn_down) right_btn_down = 1; } else { if (right_btn_down) { right_btn_down = 0; event = RIGHT_CLICK; } } mouse_info.event = event; if (event == LEFT_CLICK) { handleLeftClick(); } if (event == LEFT_DOUBLE_CLICK) { handleLeftDoubleClick(); } if (event == MOUSE_DRAGGING) { handleMouseDrag(); } if (event == RIGHT_CLICK) { handleRightClick(); } if (event == 0) { if (drag_state == 1) updateLastWindow(); drag_state = 0; } }
/** Handles events. Returns true if handled, false otherwise.*/ bool OrbitCameraManipulator::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) { switch( ea.getEventType() ) { case osgGA::GUIEventAdapter::FRAME: return handleFrame( ea, aa ); case osgGA::GUIEventAdapter::RESIZE: return handleResize( ea, aa ); default: break; } if( ea.getHandled() ) { return false; } computeRayPointer( ea, aa ); bool handled = false; switch( ea.getEventType() ) { case osgGA::GUIEventAdapter::MOVE: handled = handleMouseMove( ea, aa ); break; case osgGA::GUIEventAdapter::DRAG: handled = handleMouseDrag( ea, aa ); break; case osgGA::GUIEventAdapter::PUSH: handled = handleMousePush( ea, aa ); break; case osgGA::GUIEventAdapter::RELEASE: handled = handleMouseRelease( ea, aa ); break; case osgGA::GUIEventAdapter::KEYDOWN: handled = handleKeyDown( ea, aa ); break; case osgGA::GUIEventAdapter::KEYUP: m_control_key_down = false; handled = handleKeyUp( ea, aa ); break; case osgGA::GUIEventAdapter::SCROLL: if( _flags & PROCESS_MOUSE_WHEEL ) handled = handleMouseWheel( ea, aa ); else handled = false; break; default: handled = false; } return handled; }