bool DrawCircleTool::mouseReleaseEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget) { Q_UNUSED(widget); if (!isDrawingButton(event->button())) { if (event->button() == Qt::RightButton) abortDrawing(); return false; } if (!editingInProgress()) return false; updateStatusText(); if (dragging || second_point_set) { cur_pos = event->pos(); cur_pos_map = map_coord; if (dragging && !second_point_set) opposite_pos_map = map_coord; updateCircle(); finishDrawing(); return true; } return false; }
bool DrawRectangleTool::mouseReleaseEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget) { cur_pos = event->pos(); cur_pos_map = map_coord; if (shift_pressed) cur_pos_map = MapCoordF(snap_helper->snapToObject(cur_pos_map, widget)); constrained_pos_map = cur_pos_map; if (no_more_effect_on_click) { no_more_effect_on_click = false; return true; } if (ctrl_pressed && event->button() == Qt::LeftButton && !editingInProgress()) { pickDirection(cur_pos_map, widget); return true; } bool result = false; if (editingInProgress()) { if (isDrawingButton(event->button()) && dragging) { dragging = false; result = mousePressEvent(event, cur_pos_map, widget); } if (event->button() == Qt::RightButton && drawOnRightClickEnabled()) { if (!dragging) { constrained_pos_map = MapCoordF(preview_path->getCoordinate(angles.size() - 1)); undoLastPoint(); } if (editingInProgress()) // despite undoLastPoint() finishDrawing(); return true; } } return result; }
bool DrawCircleTool::mousePressEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget) { Q_UNUSED(widget); if (isDrawingButton(event->button())) { cur_pos = event->pos(); cur_pos_map = map_coord; if (!first_point_set && event->buttons() & Qt::LeftButton) { click_pos = event->pos(); circle_start_pos_map = map_coord; opposite_pos_map = map_coord; dragging = false; first_point_set = true; start_from_center = (event->modifiers() | (key_button_bar ? key_button_bar->activeModifiers() : 0)) & Qt::ControlModifier; if (!editingInProgress()) startDrawing(); } else if (first_point_set && !second_point_set) { click_pos = event->pos(); opposite_pos_map = map_coord; dragging = false; second_point_set = true; } else return false; hidePreviewPoints(); return true; } else if (event->button() == Qt::RightButton && editingInProgress()) { abortDrawing(); return true; } return false; }
bool DrawPathTool::mouseReleaseEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget) { if (!isDrawingButton(event->button())) return false; left_mouse_down = false; if (picking_angle) { picking_angle = false; picked_angle = pickAngle(map_coord, widget); return true; } else if (!editingInProgress()) { return false; } if (following) { finishFollowing(); if ((event->button() == Qt::RightButton) && drawOnRightClickEnabled()) finishDrawing(); return true; } if (!create_segment) return true; if (previous_point_is_curve_point && !dragging && !create_spline_corner) { // The new point has not been added yet MapCoord coord; if (shift_pressed) { coord = snap_helper->snapToObject(map_coord, widget); } else if (angle_helper->isActive()) { QPointF constrained_pos; angle_helper->getConstrainedCursorPositions(map_coord, constrained_pos_map, constrained_pos, widget); coord = MapCoord(constrained_pos_map); } else { coord = MapCoord(map_coord); } if (draw_dash_points) coord.setDashPoint(true); preview_path->addCoordinate(coord); updatePreviewPath(); updateDirtyRect(); } previous_point_is_curve_point = dragging; if (previous_point_is_curve_point) { QPointF constrained_pos; angle_helper->getConstrainedCursorPositions(map_coord, constrained_pos_map, constrained_pos, widget); previous_pos_map = click_pos_map; previous_drag_map = constrained_pos_map; previous_point_direction = calculateRotation(constrained_pos.toPoint(), constrained_pos_map); } updateAngleHelper(); create_spline_corner = false; path_has_preview_point = false; dragging = false; if ((event->button() == Qt::RightButton) && drawOnRightClickEnabled()) finishDrawing(); return true; }
bool DrawPathTool::mousePressEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget) { cur_map_widget = widget; created_point_at_last_mouse_press = false; if (editingInProgress() && ((event->button() == Qt::RightButton) && !drawOnRightClickEnabled())) { finishDrawing(); return true; } else if (editingInProgress() && ((event->button() == Qt::RightButton && event->buttons() & Qt::LeftButton) || (event->button() == Qt::LeftButton && event->buttons() & Qt::RightButton))) { if (!previous_point_is_curve_point) undoLastPoint(); if (editingInProgress()) finishDrawing(); return true; } else if (isDrawingButton(event->button())) { dragging = false; bool start_appending = false; if (shift_pressed) { SnappingToolHelperSnapInfo snap_info; MapCoord snap_coord = snap_helper->snapToObject(map_coord, widget, &snap_info); click_pos_map = MapCoordF(snap_coord); cur_pos_map = click_pos_map; click_pos = widget->mapToViewport(click_pos_map).toPoint(); // Check for following and appending if (!is_helper_tool) { if (!editingInProgress()) { if (snap_info.type == SnappingToolHelper::ObjectCorners && (snap_info.coord_index == 0 || snap_info.coord_index == snap_info.object->asPath()->getCoordinateCount() - 1) && snap_info.object->getSymbol() == editor->activeSymbol()) { // Appending to another path start_appending = true; startAppending(snap_info); } // Setup angle helper if (snap_helper->snapToDirection(map_coord, widget, angle_helper.data())) picked_angle = true; } else if (editingInProgress() && (snap_info.type == SnappingToolHelper::ObjectCorners || snap_info.type == SnappingToolHelper::ObjectPaths) && snap_info.object->getType() == Object::Path) { // Start following another path startFollowing(snap_info, snap_coord); return true; } } } else if (!editingInProgress() && ctrl_pressed) { // Start picking direction of an existing object picking_angle = true; pickAngle(map_coord, widget); return true; } else { click_pos = event->pos(); click_pos_map = map_coord; cur_pos_map = map_coord; } if (!editingInProgress()) { // Start a new path startDrawing(); angle_helper->setCenter(click_pos_map); updateSnapHelper(); path_has_preview_point = false; previous_point_is_curve_point = false; appending = start_appending; } else { if (!shift_pressed) angle_helper->getConstrainedCursorPosMap(click_pos_map, click_pos_map); cur_pos_map = click_pos_map; } // Set path point auto coord = MapCoord { click_pos_map }; if (draw_dash_points) coord.setDashPoint(true); if (preview_path->getCoordinateCount() > 0 && picked_angle) picked_angle = false; if (previous_point_is_curve_point) { // Do nothing yet, wait until the user drags or releases the mouse button } else if (path_has_preview_point) { preview_path->setCoordinate(preview_path->getCoordinateCount() - 1, coord); updateAngleHelper(); created_point_at_last_mouse_press = true; } else { if (preview_path->getCoordinateCount() == 0 || !preview_path->getCoordinate(preview_path->getCoordinateCount() - 1).isPositionEqualTo(coord)) { preview_path->addCoordinate(coord); updatePreviewPath(); if (!start_appending) updateAngleHelper(); created_point_at_last_mouse_press = true; } } path_has_preview_point = false; create_segment = true; updateDirtyRect(); updateStatusText(); return true; } return false; }
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; }