bool DrawRectangleTool::mouseDoubleClickEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget) { Q_UNUSED(map_coord); Q_UNUSED(widget); if (event->button() != Qt::LeftButton) return false; if (editingInProgress()) { // Finish drawing by double click. // As the double click is also reported as two single clicks first // (in total: press - release - press - double - release), // need to undo two steps in general. if (angles.size() > 2 && !ctrl_pressed) { undoLastPoint(); updateHover(false); } if (angles.size() <= 1) { abortDrawing(); } else { constrained_pos_map = MapCoordF(preview_path->getCoordinate(angles.size() - 1)); undoLastPoint(); finishDrawing(); } no_more_effect_on_click = true; } return true; }
bool GameScene::event(QEvent *event) { if (event->type() == QEvent::GraphicsSceneMouseMove) updateHover(static_cast<QGraphicsSceneMouseEvent *>(event)->scenePos()); return QGraphicsScene::event(event); }
bool DrawRectangleTool::keyReleaseEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Control) { ctrl_pressed = false; if (!picked_direction && (!editingInProgress() || (editingInProgress() && angles.size() == 1))) { angle_helper->setActive(false); if (dragging && editingInProgress()) updateRectangle(); } else if (editingInProgress() && angles.size() > 2) { updateRectangle(); } if (picked_direction) picked_direction = false; updateStatusText(); } else if (event->key() == Qt::Key_Shift) { shift_pressed = false; updateHover(false); updateStatusText(); } else return false; return true; }
bool DrawPathTool::keyReleaseEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Control) { ctrl_pressed = false; if (!picked_angle) angle_helper->setActive(false); if (editingInProgress() && !dragging) updateDrawHover(); updateStatusText(); } else if (event->key() == Qt::Key_Shift) { shift_pressed = false; if (!dragging && !following) { updateHover(); updateDirtyRect(); } updateStatusText(); } else return false; return true; }
void ConfirmBox::mouseReleaseEvent(QMouseEvent *e) { _lastMousePos = e->globalPos(); updateHover(); if (ClickHandlerPtr activated = ClickHandler::unpressed()) { Ui::hideLayer(); App::activateClickHandler(activated, e->button()); } }
void ConfirmBox::mousePressEvent(QMouseEvent *e) { _lastMousePos = e->globalPos(); updateHover(); if (textlnkOver()) { textlnkDown(textlnkOver()); update(); } return LayeredWidget::mousePressEvent(e); }
void ConfirmBox::mouseReleaseEvent(QMouseEvent *e) { _lastMousePos = e->globalPos(); updateHover(); if (textlnkOver() && textlnkOver() == textlnkDown()) { App::wnd()->hideLayer(); textlnkOver()->onClick(e->button()); } textlnkDown(TextLinkPtr()); }
bool DrawRectangleTool::mouseMoveEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget) { Q_UNUSED(widget); cur_pos = event->pos(); cur_pos_map = map_coord; constrained_pos_map = cur_pos_map; updateHover(containsDrawingButtons(event->buttons())); return true; }
bool DrawPathTool::keyPressEvent(QKeyEvent* event) { bool key_handled = false; if (editingInProgress()) { key_handled = true; if (event->key() == Qt::Key_Escape) abortDrawing(); else if (event->key() == Qt::Key_Backspace) undoLastPoint(); else if (event->key() == Qt::Key_Return && allow_closing_paths) { if (! (event->modifiers() & Qt::ControlModifier)) closeDrawing(); finishDrawing(); } else key_handled = false; } else if (event->key() == Qt::Key_Backspace && finished_path_is_selected) { key_handled = removeLastPointFromSelectedPath(); } if (event->key() == Qt::Key_Tab) deactivate(); else if (event->key() == Qt::Key_Space) { draw_dash_points = !draw_dash_points; updateStatusText(); } else if (event->key() == Qt::Key_Control) { ctrl_pressed = true; angle_helper->setActive(true); if (editingInProgress() && !dragging) updateDrawHover(); picked_angle = false; updateStatusText(); } else if (event->key() == Qt::Key_Shift) { shift_pressed = true; if (!dragging) { updateHover(); updateDirtyRect(); } updateStatusText(); } else return key_handled; return true; }
bool UIPopupBox::eventFilter(QObject * /* pWatched */, QEvent *pEvent) { QEvent::Type type = pEvent->type(); if ( type == QEvent::MouseMove || type == QEvent::Wheel || type == QEvent::Resize || type == QEvent::Enter || type == QEvent::Leave) updateHover(); return false; }
Text::StateResult FlatLabel::dragActionUpdate() { auto m = mapFromGlobal(_lastMousePos); auto state = getTextState(m); updateHover(state); if (_dragAction == PrepareDrag && (m - _dragStartPosition).manhattanLength() >= QApplication::startDragDistance()) { _dragAction = Dragging; QTimer::singleShot(1, this, SLOT(onExecuteDrag())); } return state; }
bool UIPopupBox::eventFilter(QObject *pWatched, QEvent *pEvent) { /* Handle all mouse-event to update hover: */ QEvent::Type type = pEvent->type(); if (type == QEvent::Enter || type == QEvent::Leave || type == QEvent::MouseMove || type == QEvent::Wheel) updateHover(); /* Call to base-class: */ return QWidget::eventFilter(pWatched, pEvent); }
Text::StateResult FlatLabel::dragActionStart(const QPoint &p, Qt::MouseButton button) { _lastMousePos = p; auto state = dragActionUpdate(); if (button != Qt::LeftButton) return state; ClickHandler::pressed(); _dragAction = NoDrag; _dragWasInactive = App::wnd()->inactivePress(); if (_dragWasInactive) App::wnd()->inactivePress(false); if (ClickHandler::getPressed()) { _dragStartPosition = mapFromGlobal(_lastMousePos); _dragAction = PrepareDrag; } if (!_selectable || _dragAction != NoDrag) { return state; } if (_trippleClickTimer.isActive() && (_lastMousePos - _trippleClickPoint).manhattanLength() < QApplication::startDragDistance()) { if (state.uponSymbol) { _selection = { state.symbol, state.symbol }; _savedSelection = { 0, 0 }; _dragSymbol = state.symbol; _dragAction = Selecting; _selectionType = TextSelectType::Paragraphs; updateHover(state); _trippleClickTimer.start(QApplication::doubleClickInterval()); update(); } } if (_selectionType != TextSelectType::Paragraphs) { _dragSymbol = state.symbol; bool uponSelected = state.uponSymbol; if (uponSelected) { if (_dragSymbol < _selection.from || _dragSymbol >= _selection.to) { uponSelected = false; } } if (uponSelected) { _dragStartPosition = mapFromGlobal(_lastMousePos); _dragAction = PrepareDrag; // start text drag } else if (!_dragWasInactive) { if (state.afterSymbol) ++_dragSymbol; _selection = { _dragSymbol, _dragSymbol }; _savedSelection = { 0, 0 }; _dragAction = Selecting; update(); } } return state; }
void Player::update(Game& game, Level& level) { processQueuedActions(game); if (hasValidState() == false) { return; } if (useAI == true) { updateAI(level); } if (playerStatus != PlayerStatus::Dead && LifeNow() <= 0) { playerStatus = PlayerStatus::Dead; playSound(dieSound); } switch (playerStatus) { default: case PlayerStatus::Stand: updateAnimation(game); break; case PlayerStatus::Walk: updateWalk(game, level); break; case PlayerStatus::Attack: updateAttack(game, level); break; case PlayerStatus::Dead: updateDead(game, level); break; } updateHover(game, level); }
void ConfirmBox::mousePressEvent(QMouseEvent *e) { _lastMousePos = e->globalPos(); updateHover(); ClickHandler::pressed(); return LayerWidget::mousePressEvent(e); }
void ConfirmBox::updateLink() { _lastMousePos = QCursor::pos(); updateHover(); }
void ConfirmBox::mouseMoveEvent(QMouseEvent *e) { _lastMousePos = e->globalPos(); updateHover(); }
void DrawPathTool::undoLastPoint() { Q_ASSERT(editingInProgress()); if (preview_path->getCoordinateCount() <= (preview_path->parts().front().isClosed() ? 3 : (path_has_preview_point ? 2 : 1))) { abortDrawing(); return; } auto& part = preview_path->parts().back(); auto last_index = part.last_index; auto prev_coord_index = part.prevCoordIndex(part.last_index); auto prev_coord = preview_path->getCoordinate(prev_coord_index); // Pre-undo preparation if (path_has_preview_point) { if (prev_coord.isCurveStart()) { // Undo just the preview point path_has_preview_point = false; } else { // Remove the preview point from a straight edge, preparing for re-adding. Q_ASSERT(!previous_point_is_curve_point); preview_path->deleteCoordinate(last_index, false); last_index = prev_coord_index; prev_coord_index = part.prevCoordIndex(part.last_index); prev_coord = preview_path->getCoordinate(prev_coord_index); path_has_preview_point = !prev_coord.isCurveStart(); } } if (prev_coord.isCurveStart()) { // Removing last point of a curve, no re-adding of preview point. MapCoord prev_drag = preview_path->getCoordinate(prev_coord_index+1); previous_point_direction = -atan2(prev_drag.x() - prev_coord.x(), prev_coord.y() - prev_drag.y()); previous_pos_map = MapCoordF(prev_coord); previous_drag_map = MapCoordF((prev_coord.x() + prev_drag.x()) / 2, (prev_coord.y() + prev_drag.y()) / 2); previous_point_is_curve_point = true; path_has_preview_point = false; } else if (!path_has_preview_point) { // Removing last point from a straight edge, no re-adding of preview point. previous_point_is_curve_point = false; } // Actually delete the last point of the edge. preview_path->deleteCoordinate(last_index, false); if (preview_path->getRawCoordinateVector().empty()) { // Re-add first point. prev_coord.setCurveStart(false); preview_path->addCoordinate(prev_coord); } // Post-undo if (path_has_preview_point) { // Re-add preview point. preview_path->addCoordinate(MapCoord(cur_pos_map)); } else if (previous_point_is_curve_point && dragging) { cur_pos = click_pos; cur_pos_map = click_pos_map; } dragging = false; updateHover(); updatePreviewPath(); updateAngleHelper(); updateDirtyRect(); }
void UIPopupBox::mouseMoveEvent(QMouseEvent *pEvent) { updateHover(); QWidget::mouseMoveEvent(pEvent); }
void UIPopupBox::leaveEvent(QEvent *pEvent) { updateHover(); QWidget::leaveEvent(pEvent); }
void UIPopupBox::wheelEvent(QWheelEvent *pEvent) { updateHover(); QWidget::wheelEvent(pEvent); }
void GraphicalStepSequencer::mouseExit(const MouseEvent& e) { updateHover(-1); }
bool DrawRectangleTool::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Return) { if (editingInProgress()) { if (angles.size() <= 1) abortDrawing(); else { constrained_pos_map = MapCoordF(preview_path->getCoordinate(angles.size() - 1)); undoLastPoint(); finishDrawing(); } } } else if (event->key() == Qt::Key_Escape) { if (editingInProgress()) abortDrawing(); } else if (event->key() == Qt::Key_Backspace) { if (editingInProgress()) { undoLastPoint(); updateHover(false); } } else if (event->key() == Qt::Key_Tab) { deactivate(); } else if (event->key() == Qt::Key_Space) { draw_dash_points = !draw_dash_points; updateStatusText(); } else if (event->key() == Qt::Key_Control) { ctrl_pressed = true; if (editingInProgress() && angles.size() == 1) { angle_helper->clearAngles(); angle_helper->addDefaultAnglesDeg(0); angle_helper->setActive(true, MapCoordF(preview_path->getCoordinate(0))); if (dragging) updateRectangle(); } else if (editingInProgress() && angles.size() > 2) { // Try to snap to existing lines updateRectangle(); } updateStatusText(); } else if (event->key() == Qt::Key_Shift) { shift_pressed = true; updateHover(false); updateStatusText(); } else return false; return true; }
void UIPopupBox::setTitle(const QString& strTitle) { m_strTitle = strTitle; updateHover(true); recalc(); }
void UIPopupBox::setTitleIcon(const QIcon& icon) { m_icon = icon; updateHover(true); recalc(); }
void GraphicalStepSequencer::mouseMove(const MouseEvent& e) { updateHover(getHoveredStep(e.getPosition())); }
void UIPopupBox::resizeEvent(QResizeEvent *pEvent) { updateHover(); recalc(); QWidget::resizeEvent(pEvent); }
bool DrawRectangleTool::mousePressEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget) { // Adjust flags to have possibly more recent state int modifiers = (event->modifiers() | (key_button_bar ? key_button_bar->activeModifiers() : 0)); ctrl_pressed = modifiers & Qt::ControlModifier; shift_pressed = modifiers & Qt::ShiftModifier; cur_map_widget = widget; if (isDrawingButton(event->button())) { dragging = false; click_pos = event->pos(); click_pos_map = map_coord; cur_pos = event->pos(); cur_pos_map = click_pos_map; if (shift_pressed) cur_pos_map = MapCoordF(snap_helper->snapToObject(cur_pos_map, widget)); constrained_pos_map = cur_pos_map; if (!editingInProgress()) { if (ctrl_pressed) { // Pick direction pickDirection(cur_pos_map, widget); } else { // Start drawing if (angle_helper->isActive()) angle_helper->setCenter(click_pos_map); startDrawing(); MapCoord coord = MapCoord(cur_pos_map); coord.setDashPoint(draw_dash_points); preview_path->addCoordinate(coord); preview_path->addCoordinate(coord); angles.push_back(0); updateStatusText(); } } else { if (angles.size() >= 2 && drawingParallelTo(angles[angles.size() - 2])) { // Drawing parallel to last section, just move the last point undoLastPoint(); } // Add new point int cur_point_index = angles.size(); if (!preview_path->getCoordinate(cur_point_index).isPositionEqualTo(preview_path->getCoordinate(cur_point_index - 1))) { MapCoord coord = MapCoord(cur_pos_map); coord.setDashPoint(draw_dash_points); preview_path->addCoordinate(coord); if (angles.size() == 1) { // Bring to correct number of points: line becomes a rectangle preview_path->addCoordinate(coord); } angles.push_back(0); angle_helper->setActive(true, MapCoordF(preview_path->getCoordinate(cur_point_index))); angle_helper->clearAngles(); angle_helper->addAngles(angles[0], M_PI/4); if (event->button() != Qt::RightButton || !drawOnRightClickEnabled()) { updateHover(false); updateHover(false); // Call it again, really. } } } } else if (event->button() == Qt::RightButton && editingInProgress()) { constrained_pos_map = MapCoordF(preview_path->getCoordinate(angles.size() - 1)); undoLastPoint(); if (editingInProgress()) // despite undoLastPoint() finishDrawing(); no_more_effect_on_click = true; } else { return false; } return true; }
bool DrawPathTool::mouseMoveEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget) { cur_pos = event->pos(); cur_pos_map = map_coord; if (!containsDrawingButtons(event->buttons())) { updateHover(); } else if (!editingInProgress()) { left_mouse_down = true; if (picking_angle) pickAngle(map_coord, widget); else return false; } else if (following) { updateFollowing(); } else { bool drag_distance_reached = (event->pos() - click_pos).manhattanLength() >= Settings::getInstance().getStartDragDistancePx(); if (dragging && !drag_distance_reached) { if (create_spline_corner) { create_spline_corner = false; } else if (path_has_preview_point) { undoLastPoint(); } } else if (drag_distance_reached) { // Giving a direction by dragging dragging = true; create_spline_corner = false; create_segment = true; if (previous_point_is_curve_point) angle_helper->setCenter(click_pos_map); QPointF constrained_pos; angle_helper->getConstrainedCursorPositions(map_coord, constrained_pos_map, constrained_pos, widget); if (previous_point_is_curve_point) { hidePreviewPoints(); float drag_direction = calculateRotation(constrained_pos.toPoint(), constrained_pos_map); // Add a new node or convert the last node into a corner? if ((widget->mapToViewport(previous_pos_map) - click_pos).manhattanLength() >= Settings::getInstance().getStartDragDistancePx()) createPreviewCurve(MapCoord(click_pos_map), drag_direction); else { create_spline_corner = true; // This hides the old direction indicator previous_drag_map = previous_pos_map; } } updateDirtyRect(); } } return true; }
void GraphicalStepSequencer::mouseDrag(const MouseEvent& e) { updateHover(getHoveredStep(e.getPosition())); changeStep(e); last_edit_position_ = e.getPosition(); }