void CutTool::updateDragging(MapCoordF cursor_pos_map, MapWidget* widget) { Q_UNUSED(widget); if (dragging_on_line) { PathCoord path_coord; if (hover_state != EditTool::OverObjectNode) { float distance_sq; edit_object->calcClosestPointOnPath(cursor_pos_map, distance_sq, path_coord); } else { path_coord = edit_object->findPathCoordForIndex(hover_point); } if (edit_object->findPartIndexForIndex(path_coord.index) != drag_part_index) return; // dragging on a different part //float click_tolerance_map = 0.001 * widget->getMapView()->pixelToLength(click_tolerance); //if (distance_sq <= click_tolerance_map*click_tolerance_map) { auto new_drag_end_len = path_coord.clen; const PathPart& drag_part = edit_object->parts()[drag_part_index]; auto path_length = drag_part.path_coords.back().clen; bool delta_forward; if (drag_part.isClosed()) { auto value = fmod(new_drag_end_len - drag_end_len + path_length, path_length); delta_forward = value >= 0 && value < 0.5 * path_length; } else { delta_forward = new_drag_end_len >= drag_end_len; } if (delta_forward && !drag_forward && fmod(drag_end_len - drag_start_len + path_length, path_length) > 0.5f * path_length && fmod(new_drag_end_len - drag_start_len + path_length, path_length) <= 0.5f * path_length) { drag_forward = true; } else if (!delta_forward && drag_forward && fmod(drag_end_len - drag_start_len + path_length, path_length) <= 0.5f * path_length && fmod(new_drag_end_len - drag_start_len + path_length, path_length) > 0.5f * path_length) { drag_forward = false; } drag_end_len = new_drag_end_len; if (drag_end_len != drag_start_len) updatePreviewObjects(); } } }
void CutoutTool::initImpl() { // Take cutout shape object out of the map Q_ASSERT(map()->getNumSelectedObjects() == 1); cutout_object = (*(map()->selectedObjectsBegin()))->asPath(); startEditing(); cutout_object->setSymbol(Map::getCoveringCombinedLine(), true); updatePreviewObjects(); cutout_object_index = map()->getCurrentPart()->findObjectIndex(cutout_object); map()->removeObjectFromSelection(cutout_object, true); map()->deleteObject(cutout_object, true); }
void ScaleTool::updateDragging(const MapCoordF cursor_pos_map) { if (scaling) { double scaling = (cursor_pos_map - scaling_center).length(); scaling_factor = scaling / qMax(1e-7, original_scale); resetEditedObjects(); Map::ObjectSelection::const_iterator it_end = map()->selectedObjectsEnd(); for (Map::ObjectSelection::const_iterator it = map()->selectedObjectsBegin(); it != it_end; ++it) (*it)->scale(scaling_center, scaling_factor); updatePreviewObjects(); updateStatusText(); } }
void RotateTool::dragMove() { if (rotating) { angle_helper->getConstrainedCursorPositions(cur_pos_map, constrained_pos_map, constrained_pos, cur_map_widget); double rotation = (constrained_pos_map - rotation_center).angle(); double delta_rotation = rotation - old_rotation; Map::ObjectSelection::const_iterator it_end = map()->selectedObjectsEnd(); for (Map::ObjectSelection::const_iterator it = map()->selectedObjectsBegin(); it != it_end; ++it) (*it)->rotateAround(rotation_center, -1.0 * delta_rotation); updatePreviewObjects(); old_rotation = rotation; updateStatusText(); } }
void RotatePatternTool::dragMove() { const auto rotation = -M_PI / 2 - (constrained_pos_map - click_pos_map).angle(); for (auto object : editedObjects()) { /// \todo Refactor, provide a unified interface for rotation in Object if (object->getType() == Object::Point) { if (object->getSymbol()->asPoint()->isRotatable()) object->asPoint()->setRotation(rotation); } else if (object->getType() == Object::Path) { object->asPath()->setPatternOrigin(MapCoord(click_pos_map)); object->asPath()->setPatternRotation(rotation); } } updatePreviewObjects(); updateStatusText(); }
void EditPointTool::textSelectionChanged(bool text_change) { Q_UNUSED(text_change); updatePreviewObjects(); }
void EditPointTool::clickPress() { Q_ASSERT(!hover_state.testFlag(OverObjectNode) || !hover_state.testFlag(OverPathEdge) || hover_object); if (hover_state.testFlag(OverPathEdge) && active_modifiers & Qt::ControlModifier) { // Add new point to path PathObject* path = hover_object->asPath(); float distance_sq; PathCoord path_coord; path->calcClosestPointOnPath(cur_pos_map, distance_sq, path_coord); float click_tolerance_map_sq = cur_map_widget->getMapView()->pixelToLength(clickTolerance()); click_tolerance_map_sq = click_tolerance_map_sq * click_tolerance_map_sq; if (distance_sq <= click_tolerance_map_sq) { startEditing(); QScopedValueRollback<bool> no_effect_rollback(no_more_effect_on_click); no_more_effect_on_click = true; startDragging(); hover_state = OverObjectNode; hover_point = path->subdivide(path_coord); if (addDashPointDefault() ^ space_pressed) { MapCoord point = path->getCoordinate(hover_point); point.setDashPoint(true); path->setCoordinate(hover_point, point); map()->emitSelectionEdited(); } startEditingSetup(); updatePreviewObjects(); } } else if (hover_state.testFlag(OverObjectNode) && hover_object->getType() == Object::Path) { PathObject* hover_object = this->hover_object->asPath(); Q_ASSERT(hover_point < hover_object->getCoordinateCount()); if (space_pressed && !hover_object->isCurveHandle(hover_point)) { // Switch point between dash / normal point createReplaceUndoStep(hover_object); MapCoord& hover_coord = hover_object->getCoordinate(hover_point); hover_coord.setDashPoint(!hover_coord.isDashPoint()); hover_object->update(); updateDirtyRect(); no_more_effect_on_click = true; } else if (active_modifiers & Qt::ControlModifier) { auto hover_point_part_index = hover_object->findPartIndexForIndex(hover_point); PathPart& hover_point_part = hover_object->parts()[hover_point_part_index]; if (hover_object->isCurveHandle(hover_point)) { // Convert the curve into a straight line createReplaceUndoStep(hover_object); hover_object->deleteCoordinate(hover_point, false); hover_object->update(); map()->emitSelectionEdited(); updateHoverState(cur_pos_map); updateDirtyRect(); no_more_effect_on_click = true; } else { // Delete the point if (hover_point_part.countRegularNodes() <= 2 || ( !(hover_object->getSymbol()->getContainedTypes() & Symbol::Line) && hover_point_part.size() <= 3 ) ) { // Not enough remaining points -> delete the part and maybe object if (hover_object->parts().size() == 1) { map()->removeObjectFromSelection(hover_object, false); auto undo_step = new AddObjectsUndoStep(map()); auto part = map()->getCurrentPart(); int index = part->findObjectIndex(hover_object); Q_ASSERT(index >= 0); undo_step->addObject(index, hover_object); map()->deleteObject(hover_object, true); map()->push(undo_step); map()->setObjectsDirty(); map()->emitSelectionEdited(); updateHoverState(cur_pos_map); } else { createReplaceUndoStep(hover_object); hover_object->deletePart(hover_point_part_index); hover_object->update(); map()->emitSelectionEdited(); updateHoverState(cur_pos_map); updateDirtyRect(); } no_more_effect_on_click = true; } else { // Delete the point only createReplaceUndoStep(hover_object); int delete_bezier_spline_point_setting; if (active_modifiers & Qt::ShiftModifier) delete_bezier_spline_point_setting = Settings::EditTool_DeleteBezierPointActionAlternative; else delete_bezier_spline_point_setting = Settings::EditTool_DeleteBezierPointAction; hover_object->deleteCoordinate(hover_point, true, Settings::getInstance().getSettingCached((Settings::SettingsEnum)delete_bezier_spline_point_setting).toInt()); hover_object->update(); map()->emitSelectionEdited(); updateHoverState(cur_pos_map); updateDirtyRect(); no_more_effect_on_click = true; } } } } else if (hoveringOverSingleText()) { TextObject* hover_object = map()->getFirstSelectedObject()->asText(); startEditing(); // Don't show the original text while editing map()->removeRenderablesOfObject(hover_object, true); // Make sure that the TextObjectEditorHelper remembers the correct standard cursor cur_map_widget->setCursor(getCursor()); old_text = hover_object->getText(); old_horz_alignment = (int)hover_object->getHorizontalAlignment(); old_vert_alignment = (int)hover_object->getVerticalAlignment(); text_editor = new TextObjectEditorHelper(hover_object, editor); connect(text_editor, SIGNAL(selectionChanged(bool)), this, SLOT(textSelectionChanged(bool))); // Select clicked position int pos = hover_object->calcTextPositionAt(cur_pos_map, false); text_editor->setSelection(pos, pos); updatePreviewObjects(); } click_timer.restart(); }
void MapEditorToolBase::updatePreviewObjectsSlot() { preview_update_triggered = false; if (editingInProgress()) updatePreviewObjects(); }