diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-11-06 21:18:13 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-11-06 21:18:13 +0100 |
commit | 2521a7918783758928a58f6032ca6fad53a89c01 (patch) | |
tree | a34eda1e01b44133b7a1d6035f101662e7c292d2 /spline-widget/qfunctionconfigurator.cpp | |
parent | 0fb267c19925a949a8b1f8c62d9fbe52ba821d3d (diff) |
spline: snap x, y coordinates to grid
Diffstat (limited to 'spline-widget/qfunctionconfigurator.cpp')
-rw-r--r-- | spline-widget/qfunctionconfigurator.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/spline-widget/qfunctionconfigurator.cpp b/spline-widget/qfunctionconfigurator.cpp index 5d910826..112b5457 100644 --- a/spline-widget/qfunctionconfigurator.cpp +++ b/spline-widget/qfunctionconfigurator.cpp @@ -21,7 +21,9 @@ QFunctionConfigurator::QFunctionConfigurator(QWidget *parent) : QWidget(parent), _config(nullptr), moving_control_point_idx(-1), - _draw_function(true) + _draw_function(true), + snap_x(0), + snap_y(0) { update_range(); setMouseTracking(true); @@ -412,8 +414,13 @@ QPointF QFunctionConfigurator::pixel_coord_to_point(const QPointF& point) if (!_config) return QPointF(-1, -1); - double x = (point.x() - pixel_bounds.x()) / c.x(); - double y = (pixel_bounds.height() - point.y() + pixel_bounds.y()) / c.y(); + int x = (point.x() - pixel_bounds.x()) / c.x(); + int y = (pixel_bounds.height() - point.y() + pixel_bounds.y()) / c.y(); + + if (snap_x > 0) + x -= x % snap_x; + if (snap_y > 0) + y -= y % snap_y; if (x < 0) x = 0; |