bool EditPointTool::keyRelease(QKeyEvent* event) { if (text_editor) return text_editor->keyReleaseEvent(event); if (event->key() == Qt::Key_Control) { angle_helper->setActive(false); if (editingInProgress()) { reapplyConstraintHelpers(); } } else if (event->key() == Qt::Key_Shift) { snap_helper->setFilter(SnappingToolHelper::NoSnapping); if (editingInProgress()) { reapplyConstraintHelpers(); } } else if (event->key() == Qt::Key_Space) { space_pressed = false; } else { return false; } updateStatusText(); return true; }
bool DrawFreehandTool::mouseMoveEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget) { Q_UNUSED(widget); bool mouse_down = containsDrawingButtons(event->buttons()); if (!mouse_down) { if (!editingInProgress()) { setPreviewPointsPosition(map_coord); setDirtyRect(); } } else { if (!editingInProgress()) return false; dragging = true; cur_pos = event->pos(); cur_pos_map = map_coord; updatePath(); } return true; }
void DrawPathTool::updateDrawHover() { if (!shift_pressed) angle_helper->getConstrainedCursorPosMap(cur_pos_map, constrained_pos_map); if (!previous_point_is_curve_point && !left_mouse_down && editingInProgress()) { // Show a line to the cursor position as preview hidePreviewPoints(); if (!path_has_preview_point) { preview_path->addCoordinate(MapCoord(constrained_pos_map)); path_has_preview_point = true; } preview_path->setCoordinate(preview_path->getCoordinateCount() - 1, MapCoord(constrained_pos_map)); updatePreviewPath(); updateDirtyRect(); // TODO: Possible optimization: mark only the last segment as dirty } else if (previous_point_is_curve_point && !left_mouse_down && editingInProgress()) { setPreviewPointsPosition(constrained_pos_map, 1); updateDirtyRect(); } }
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; }
void DrawPathTool::updateDirtyRect() { QRectF rect; if (dragging) { rectIncludeSafe(rect, click_pos_map); rectInclude(rect, cur_pos_map); } if (editingInProgress() && previous_point_is_curve_point) { rectIncludeSafe(rect, previous_pos_map); rectInclude(rect, previous_drag_map); } if ((editingInProgress() && !dragging) || (!editingInProgress() && !shift_pressed && ctrl_pressed) || (!editingInProgress() && (picking_angle || picked_angle))) { angle_helper->includeDirtyRect(rect); } if (shift_pressed || (!editingInProgress() && ctrl_pressed)) snap_helper->includeDirtyRect(rect); includePreviewRects(rect); if (is_helper_tool) emit(dirtyRectChanged(rect)); else { if (rect.isValid()) map()->setDrawingBoundingBox(rect, qMax(qMax(dragging ? 1 : 0, angle_helper->getDisplayRadius()), snap_helper->getDisplayRadius()), true); else map()->clearDrawingBoundingBox(); } }
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 EditPointTool::keyPress(QKeyEvent* event) { if (text_editor) { if (event->key() == Qt::Key_Escape) { finishEditing(); return true; } return text_editor->keyPressEvent(event); } int num_selected_objects = map()->getNumSelectedObjects(); if (num_selected_objects > 0 && event->key() == delete_object_key) { deleteSelectedObjects(); } else if (num_selected_objects > 0 && event->key() == Qt::Key_Escape) { map()->clearObjectSelection(true); } else if (event->key() == Qt::Key_Control) { if (editingInProgress()) activateAngleHelperWhileEditing(); } else if (event->key() == Qt::Key_Shift && editingInProgress()) { if (hover_state == OverObjectNode && hover_object->getType() == Object::Path && hover_object->asPath()->isCurveHandle(hover_point)) { // In this case, Shift just activates deactivates // the opposite curve handle constraints return true; } activateSnapHelperWhileEditing(); } else if (event->key() == Qt::Key_Space) { space_pressed = true; } else { return false; } updateStatusText(); return true; }
void DrawRectangleTool::updateHover(bool mouse_down) { if (shift_pressed) constrained_pos_map = MapCoordF(snap_helper->snapToObject(cur_pos_map, cur_map_widget)); else constrained_pos_map = cur_pos_map; if (!editingInProgress()) { setPreviewPointsPosition(constrained_pos_map); updateDirtyRect(); if (mouse_down && ctrl_pressed) pickDirection(constrained_pos_map, cur_map_widget); else if (!mouse_down) angle_helper->setCenter(constrained_pos_map); } else { hidePreviewPoints(); if (mouse_down && !dragging && (cur_pos - click_pos).manhattanLength() >= Settings::getInstance().getStartDragDistancePx()) { // Start dragging dragging = true; } if (!mouse_down || dragging) updateRectangle(); } }
void DrawLineAndAreaTool::setDrawingSymbol(const Symbol* symbol) { // Avoid using deleted symbol if (map()->findSymbolIndex(drawing_symbol) == -1) symbol = NULL; // End current editing if (editingInProgress()) { if (symbol) finishDrawing(); else abortDrawing(); } // Handle new symbol if (!is_helper_tool) drawing_symbol = symbol; if (!symbol) deactivate(); else if (symbol->isHidden()) deactivate(); else if ((symbol->getType() & (Symbol::Line | Symbol::Area | Symbol::Combined)) == 0) switchToDefaultDrawTool(symbol); else createPreviewPoints(); }
void DrawLineAndAreaTool::leaveEvent(QEvent* event) { Q_UNUSED(event); if (!editingInProgress()) map()->clearDrawingBoundingBox(); }
bool MapEditorToolBase::mousePressEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget) { active_modifiers = Qt::KeyboardModifiers(event->modifiers() | (key_button_bar ? key_button_bar->activeModifiers() : 0)); if (event->button() == Qt::LeftButton) { cur_map_widget = widget; click_pos = event->pos(); click_pos_map = map_coord; cur_pos = click_pos; cur_pos_map = click_pos_map; calcConstrainedPositions(widget); clickPress(); return true; } else if (event->button() == Qt::RightButton) { // Do not show the ring menu when editing return editingInProgress(); } else { return false; } }
void MapEditorToolBase::startEditing() { Q_ASSERT(!editingInProgress()); setEditingInProgress(true); startEditingSelection(*old_renderables); }
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 MapEditorTool::containsDrawingButtons(Qt::MouseButtons buttons) const { if (buttons.testFlag(Qt::LeftButton)) return true; return (draw_on_right_click && buttons.testFlag(Qt::RightButton) && editingInProgress()); }
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 MapEditorTool::isDrawingButton(Qt::MouseButton button) const { if (button == Qt::LeftButton) return true; return (draw_on_right_click && button == Qt::RightButton && editingInProgress()); }
void DrawPathTool::finishDrawing() { Q_ASSERT(editingInProgress()); // Does the symbols contain only areas? If so, auto-close the path if not done yet bool contains_only_areas = !is_helper_tool && (drawing_symbol->getContainedTypes() & ~(Symbol::Area | Symbol::Combined)) == 0 && (drawing_symbol->getContainedTypes() & Symbol::Area); if (contains_only_areas && !preview_path->parts().empty()) preview_path->parts().front().setClosed(true, true); // Remove last point if closed and first and last points are equal, or if the last point was just a preview if (path_has_preview_point && !dragging) preview_path->deleteCoordinate(preview_path->getCoordinateCount() - (preview_path->parts().front().isClosed() ? 2 : 1), false); if (preview_path->getCoordinateCount() < (contains_only_areas ? 3 : 2)) { renderables->removeRenderablesOfObject(preview_path, false); delete preview_path; preview_path = NULL; } dragging = false; following = false; setEditingInProgress(false); if (!ctrl_pressed) angle_helper->setActive(false); updateSnapHelper(); updateStatusText(); hidePreviewPoints(); DrawLineAndAreaTool::finishDrawing(appending ? append_to_object : NULL); finished_path_is_selected = true; }
void DrawRectangleTool::updateDirtyRect() { QRectF rect; includePreviewRects(rect); if (shift_pressed) snap_helper->includeDirtyRect(rect); if (is_helper_tool) emit(dirtyRectChanged(rect)); else { if (angle_helper->isActive()) angle_helper->includeDirtyRect(rect); if (rect.isValid()) { float helper_cross_radius = Settings::getInstance().getRectangleToolHelperCrossRadiusPx(); int pixel_border = 0; if (editingInProgress()) pixel_border = helper_cross_radius; // helper_cross_radius as border is less than ideal but the only way to always ensure visibility of the helper cross at the moment if (angle_helper->isActive()) pixel_border = qMax(pixel_border, angle_helper->getDisplayRadius()); map()->setDrawingBoundingBox(rect, pixel_border, true); } else map()->clearDrawingBoundingBox(); } }
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; }
bool DrawCircleTool::mouseMoveEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget) { Q_UNUSED(widget); bool mouse_down = containsDrawingButtons(event->buttons()); if (!mouse_down) { if (!editingInProgress()) { setPreviewPointsPosition(map_coord); setDirtyRect(); } else { cur_pos = event->pos(); cur_pos_map = map_coord; if (!second_point_set) opposite_pos_map = map_coord; updateCircle(); } } else { if (!editingInProgress()) return false; if ((event->pos() - click_pos).manhattanLength() >= Settings::getInstance().getStartDragDistancePx()) { if (!dragging) { dragging = true; updateStatusText(); } } if (dragging) { cur_pos = event->pos(); cur_pos_map = map_coord; if (!second_point_set) opposite_pos_map = cur_pos_map; updateCircle(); } } return true; }
void DrawRectangleTool::updateStatusText() { QString text; static const QString text_more_shift_control_space(MapEditorTool::tr("More: %1, %2, %3").arg(ModifierKey::shift(), ModifierKey::control(), ModifierKey::space())); static const QString text_more_shift_space(MapEditorTool::tr("More: %1, %2").arg(ModifierKey::shift(), ModifierKey::space())); static const QString text_more_control_space(MapEditorTool::tr("More: %1, %2").arg(ModifierKey::control(), ModifierKey::space())); QString text_more(text_more_shift_control_space); if (draw_dash_points) text += DrawLineAndAreaTool::tr("<b>Dash points on.</b> ") + "| "; if (!editingInProgress()) { if (ctrl_pressed) { text += DrawLineAndAreaTool::tr("<b>%1+Click</b>: Pick direction from existing objects. ").arg(ModifierKey::control()); text_more = text_more_shift_space; } else if (shift_pressed) { text += DrawLineAndAreaTool::tr("<b>%1+Click</b>: Snap to existing objects. ").arg(ModifierKey::shift()); text_more = text_more_control_space; } else { text += tr("<b>Click or Drag</b>: Start drawing a rectangle. "); } } else { if (ctrl_pressed) { if (angles.size() == 1) { text += DrawLineAndAreaTool::tr("<b>%1</b>: Fixed angles. ").arg(ModifierKey::control()); } else { text += tr("<b>%1</b>: Snap to previous lines. ").arg(ModifierKey::control()); } text_more = text_more_shift_space; } else if (shift_pressed) { text += DrawLineAndAreaTool::tr("<b>%1+Click</b>: Snap to existing objects. ").arg(ModifierKey::shift()); text_more = text_more_control_space; } else { text += tr("<b>Click</b>: Set a corner point. <b>Right or double click</b>: Finish the rectangle. "); text += DrawLineAndAreaTool::tr("<b>%1</b>: Undo last point. ").arg(ModifierKey::backspace()); text += MapEditorTool::tr("<b>%1</b>: Abort. ").arg(ModifierKey::escape()); } } text += "| " + text_more; setStatusBarText(text); }
void MapEditorToolBase::abortEditing() { Q_ASSERT(editingInProgress()); resetEditedObjects(); finishEditingSelection(*renderables, *old_renderables, false); setEditingInProgress(false); }
bool DrawPathTool::mouseDoubleClickEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget) { Q_UNUSED(map_coord); Q_UNUSED(widget); if (event->button() != Qt::LeftButton) return false; if (editingInProgress()) { if (created_point_at_last_mouse_press) undoLastPoint(); if (editingInProgress()) finishDrawing(); } return true; }
void MapEditorToolBase::finishEditing(bool delete_objects, bool create_undo_step) { Q_ASSERT(editingInProgress()); finishEditingSelection(*renderables, *old_renderables, create_undo_step, delete_objects); map()->setObjectsDirty(); map()->emitSelectionEdited(); MapEditorTool::finishEditing(); }
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; }
void DrawPathTool::updateSnapHelper() { if (editingInProgress()) snap_helper->setFilter(SnappingToolHelper::AllTypes); else { //snap_helper.setFilter((SnappingToolHelper::SnapObjects)(SnappingToolHelper::GridCorners | SnappingToolHelper::ObjectCorners)); snap_helper->setFilter(SnappingToolHelper::AllTypes); } }
void MapEditorToolBase::updatePreviewObjects() { if (!editingInProgress()) { qWarning("MapEditorToolBase::updatePreviewObjects() called but editing == false"); return; } updateSelectionEditPreview(*renderables); updateDirtyRect(); }
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; }
void DrawPathTool::draw(QPainter* painter, MapWidget* widget) { drawPreviewObjects(painter, widget); if (editingInProgress()) { painter->setRenderHint(QPainter::Antialiasing); if (dragging && (cur_pos - click_pos).manhattanLength() >= Settings::getInstance().getStartDragDistancePx()) { QPen pen(qRgb(255, 255, 255)); pen.setWidth(3); painter->setPen(pen); painter->drawLine(widget->mapToViewport(click_pos_map), widget->mapToViewport(constrained_pos_map)); painter->setPen(active_color); painter->drawLine(widget->mapToViewport(click_pos_map), widget->mapToViewport(constrained_pos_map)); } if (previous_point_is_curve_point) { QPen pen(qRgb(255, 255, 255)); pen.setWidth(3); painter->setPen(pen); painter->drawLine(widget->mapToViewport(previous_pos_map), widget->mapToViewport(previous_drag_map)); painter->setPen(active_color); painter->drawLine(widget->mapToViewport(previous_pos_map), widget->mapToViewport(previous_drag_map)); } if (!shift_pressed) angle_helper->draw(painter, widget); } if (shift_pressed && !dragging) { snap_helper->draw(painter, widget); } else if (!editingInProgress() && (picking_angle || picked_angle)) { if (picking_angle) snap_helper->draw(painter, widget); angle_helper->draw(painter, widget); } }
void CutoutTool::finishEditing() { if (editingInProgress()) { if (cutout_object_index >= 0) map()->getCurrentPart()->addObject(cutout_object, cutout_object_index); map()->clearObjectSelection(false); map()->addObjectToSelection(cutout_object, true); abortEditing(); } }