diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-09-05 12:40:31 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-09-05 12:40:31 +0200 |
commit | c587590ddb8a4f76a134018155588e2470992600 (patch) | |
tree | fdbe0749ca06707a931da9d264fe58ae3c53d448 /spline-widget | |
parent | 063acd81a4006ac0d26da07f2f72657d76ae4153 (diff) |
spline-widget: allow for non-integral snap values
Diffstat (limited to 'spline-widget')
-rw-r--r-- | spline-widget/spline-widget.cpp | 8 | ||||
-rw-r--r-- | spline-widget/spline-widget.hpp | 7 |
2 files changed, 8 insertions, 7 deletions
diff --git a/spline-widget/spline-widget.cpp b/spline-widget/spline-widget.cpp index 6e3a95b3..ff18a2f9 100644 --- a/spline-widget/spline-widget.cpp +++ b/spline-widget/spline-widget.cpp @@ -19,9 +19,9 @@ spline_widget::spline_widget(QWidget *parent) : QWidget(parent), _config(nullptr), - moving_control_point_idx(-1), snap_x(0), snap_y(0), + moving_control_point_idx(-1), _draw_function(true), _preview_only(false) { @@ -472,10 +472,12 @@ QPointF spline_widget::pixel_coord_to_point(const QPointF& point) qreal x = round((point.x() - pixel_bounds.x()) / c.x()); qreal y = round((pixel_bounds.height() - point.y() + pixel_bounds.y()) / c.y()); + const volatile int c = 8192; + if (snap_x > 0) - x -= int(x) % snap_x; + x = std::nearbyint(x * c - (int(x * c) % int(snap_x * c))) / double(c); if (snap_y > 0) - y -= int(y) % snap_y; + y = std::nearbyint(y * c - (int(y * c) % int(snap_y * c))) / double(c); if (x < 0) x = 0; diff --git a/spline-widget/spline-widget.hpp b/spline-widget/spline-widget.hpp index 80397ac7..94e6b32c 100644 --- a/spline-widget/spline-widget.hpp +++ b/spline-widget/spline-widget.hpp @@ -53,8 +53,8 @@ public: } void set_preview_only(bool val); bool is_preview_only() const; - void set_snap(int x, int y) { snap_x = x; snap_y = y; } - void get_snap(int& x, int& y) const { x = snap_x; y = snap_y; } + void set_snap(double x, double y) { snap_x = x; snap_y = y; } + void get_snap(double& x, double& y) const { x = snap_x; y = snap_y; } protected slots: void paintEvent(QPaintEvent *e) override; void mousePressEvent(QMouseEvent *e) override; @@ -89,9 +89,8 @@ private: QMetaObject::Connection connection; + double snap_x, snap_y; int moving_control_point_idx; - - int snap_x, snap_y; bool _draw_function, _preview_only; static constexpr int line_length_pixels = 3; |