| 547 | } |
| 548 | |
| 549 | void EditLineTool::updateHoverState(const MapCoordF& cursor_pos) |
| 550 | { |
| 551 | HoverState new_hover_state = OverNothing; |
| 552 | const PathObject* new_hover_object = nullptr; |
| 553 | MapCoordVector::size_type new_hover_line = 0; |
| 554 | |
| 555 | if (!map()->selectedObjects().empty()) |
| 556 | { |
| 557 | // Check selected objects |
| 558 | if (map()->selectedObjects().size() <= max_objects_for_handle_display) |
| 559 | { |
| 560 | auto click_tolerance_sq = qPow(0.001 * cur_map_widget->getMapView()->pixelToLength(clickTolerance()), 2); |
| 561 | auto best_distance_sq = std::numeric_limits<double>::max(); |
| 562 | |
| 563 | for (auto object : map()->selectedObjects()) |
| 564 | { |
| 565 | if (object->getType() == Object::Path) |
| 566 | { |
| 567 | PathObject* path = object->asPath(); |
| 568 | auto closest = path->findClosestPointTo(cursor_pos); |
| 569 | |
| 570 | if (closest.distance_squared >= +0.0 && |
| 571 | closest.distance_squared < best_distance_sq && |
| 572 | closest.distance_squared < qMax(click_tolerance_sq, qPow(path->getSymbol()->calculateLargestLineExtent(), 2))) |
| 573 | { |
| 574 | new_hover_state = OverPathEdge; |
| 575 | new_hover_object = path; |
| 576 | new_hover_line = closest.path_coord.index; |
| 577 | best_distance_sq = closest.distance_squared; |
| 578 | handle_offset = closest.path_coord.pos - cursor_pos; |
| 579 | |
| 580 | const auto part = path->findPartForIndex(new_hover_line); |
| 581 | if (new_hover_line == part->last_index) |
| 582 | { |
| 583 | new_hover_line = part->prevCoordIndex(new_hover_line); |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | // Check bounding box |
| 591 | if (new_hover_state != OverPathEdge && selection_extent.isValid()) |
| 592 | { |
| 593 | QRectF selection_extent_viewport = cur_map_widget->mapToViewport(selection_extent); |
| 594 | if (pointOverRectangle(cur_map_widget->mapToViewport(cursor_pos), selection_extent_viewport)) |
| 595 | { |
| 596 | new_hover_state = OverFrame; |
| 597 | new_hover_object = nullptr; |
| 598 | handle_offset = closestPointOnRect(cursor_pos, selection_extent) - cursor_pos; |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | // Apply possible changes |
| 604 | if (new_hover_state != hover_state || |
| 605 | new_hover_line != hover_line || |
| 606 | new_hover_object != hover_object) |
nothing calls this directly
no test coverage detected