| 775 | } |
| 776 | |
| 777 | void EditPointTool::updateHoverState(const MapCoordF& cursor_pos) |
| 778 | { |
| 779 | HoverState new_hover_state = OverNothing; |
| 780 | const Object* new_hover_object = nullptr; |
| 781 | MapCoordVector::size_type new_hover_point = no_point; |
| 782 | |
| 783 | if (text_editor) |
| 784 | { |
| 785 | handle_offset = MapCoordF(0, 0); |
| 786 | } |
| 787 | else if (!map()->selectedObjects().empty()) |
| 788 | { |
| 789 | if (map()->selectedObjects().size() <= max_objects_for_handle_display) |
| 790 | { |
| 791 | // Try to find object node. |
| 792 | auto best_distance_sq = std::numeric_limits<double>::max(); |
| 793 | for (const auto* object : map()->selectedObjects()) |
| 794 | { |
| 795 | MapCoordF handle_pos; |
| 796 | auto hover_point = findHoverPoint(cur_map_widget->mapToViewport(cursor_pos), cur_map_widget, object, true, &handle_pos); |
| 797 | if (hover_point == no_point) |
| 798 | continue; |
| 799 | |
| 800 | auto distance_sq = cursor_pos.distanceSquaredTo(handle_pos); |
| 801 | if (distance_sq < best_distance_sq) |
| 802 | { |
| 803 | new_hover_state |= OverObjectNode; |
| 804 | new_hover_object = object; |
| 805 | new_hover_point = hover_point; |
| 806 | best_distance_sq = distance_sq; |
| 807 | handle_offset = handle_pos - cursor_pos; |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | if (!new_hover_state.testFlag(OverObjectNode)) |
| 812 | { |
| 813 | // No object node found. Try to find path object edge. |
| 814 | /// \todo De-duplicate: Copied from EditLineTool |
| 815 | auto click_tolerance_sq = qPow(0.001 * cur_map_widget->getMapView()->pixelToLength(clickTolerance()), 2); |
| 816 | |
| 817 | for (auto object : map()->selectedObjects()) |
| 818 | { |
| 819 | if (object->getType() == Object::Path) |
| 820 | { |
| 821 | PathObject* path = object->asPath(); |
| 822 | auto closest = path->findClosestPointTo(cursor_pos); |
| 823 | |
| 824 | if (closest.distance_squared >= +0.0 && |
| 825 | closest.distance_squared < best_distance_sq && |
| 826 | closest.distance_squared < qMax(click_tolerance_sq, qPow(path->getSymbol()->calculateLargestLineExtent(), 2))) |
| 827 | { |
| 828 | new_hover_state |= OverPathEdge; |
| 829 | new_hover_object = path; |
| 830 | new_hover_point = closest.path_coord.index; |
| 831 | best_distance_sq = closest.distance_squared; |
| 832 | handle_offset = closest.path_coord.pos - cursor_pos; |
| 833 | } |
| 834 | } |
nothing calls this directly
no test coverage detected