diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-06-23 02:33:32 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-06-26 23:03:32 +0200 |
commit | d37ce65ef1c224317b26664e0211aa2f82c18099 (patch) | |
tree | 9ffa0908915befd2707625ef55e8216d1f607914 /spline/spline-widget.cpp | |
parent | c26eeb45c905d985aba199e631651e69fcc10083 (diff) |
spline/widget: fix drag-too-close handling
Dragging toward adjacent point makes sure it's as close
as allowed.
Work against any remaining cases where points "merged".
Diffstat (limited to 'spline/spline-widget.cpp')
-rw-r--r-- | spline/spline-widget.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/spline/spline-widget.cpp b/spline/spline-widget.cpp index b0300b1a..de8a6fd3 100644 --- a/spline/spline-widget.cpp +++ b/spline/spline-widget.cpp @@ -184,7 +184,7 @@ void spline_widget::drawFunction() //#define DEBUG_SPLINE #ifndef DEBUG_SPLINE - constexpr double step_ = 5; + constexpr double step_ = 3; const double maxx = _config->max_input(); const double step = std::fmax(1e-4, step_ / c.x()); @@ -415,36 +415,36 @@ void spline_widget::mouseMoveEvent(QMouseEvent *e) const double point_closeness_limit = get_closeness_limit(); QPointF new_pt = pixel_to_point(e->localPos()); const QPointF pix = point_to_pixel(new_pt); - //bool overlap = false; + const bool has_prev = i > 0, has_next = i + 1 < points.size(); auto check_next = [&] { - return !has_next || points[i+1].x() - new_pt.x() < point_closeness_limit; + return points[i+1].x() - new_pt.x() >= point_closeness_limit; }; auto check_prev = [&] { - return !has_prev || new_pt.x() - points[i-1].x() < point_closeness_limit; + return new_pt.x() - points[i-1].x() >= point_closeness_limit; }; - const bool status_next = !has_next || !check_next(); - const bool status_prev = !has_prev || !check_prev(); - - if (!status_prev) - new_pt = { points[i-1].x() + point_closeness_limit, new_pt.y() }; - - if (!status_next) - new_pt = { points[i+1].x() - point_closeness_limit, new_pt.y() }; - - if (check_prev() && check_next()) - new_pt = { points[i].x(), new_pt.y() }; - - _config->move_point(i, new_pt); + if (has_prev && !check_prev()) + { + new_pt.rx() = points[i-1].x() + point_closeness_limit + 1e-4; + } - _draw_function = true; - repaint(); + if (has_next && !check_next()) + { + new_pt.rx() = points[i+1].x() - point_closeness_limit - 1e-4; + } setCursor(Qt::ClosedHandCursor); show_tooltip(pix.toPoint(), new_pt); + + if ((!has_prev || check_prev()) && (!has_next || check_next())) + { + _config->move_point(i, new_pt); + _draw_function = true; + repaint(); + } } else if (sz) { |