summaryrefslogtreecommitdiffhomepage
path: root/qfunctionconfigurator/qfunctionconfigurator.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-07-07 11:50:24 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-07-07 12:38:18 +0200
commit80bac8b7583f1757d17bbc2ead69261b8b6347b5 (patch)
tree50cdb182cd124a544d4f435b2fe9c43b9d11fd2d /qfunctionconfigurator/qfunctionconfigurator.cpp
parentcdbe9e8ea3283dde4667098e8b35f09b94cbcfc4 (diff)
qfc: don't cancel moving if points come too close
Instead, block moving but allow the user to move the other way.
Diffstat (limited to 'qfunctionconfigurator/qfunctionconfigurator.cpp')
-rw-r--r--qfunctionconfigurator/qfunctionconfigurator.cpp59
1 files changed, 39 insertions, 20 deletions
diff --git a/qfunctionconfigurator/qfunctionconfigurator.cpp b/qfunctionconfigurator/qfunctionconfigurator.cpp
index 11eb8a71..a59b0f00 100644
--- a/qfunctionconfigurator/qfunctionconfigurator.cpp
+++ b/qfunctionconfigurator/qfunctionconfigurator.cpp
@@ -132,7 +132,7 @@ void QFunctionConfigurator::drawFunction()
QPen pen(spline_color, 1.2, Qt::SolidLine);
const double max = _config->maxInput();
- const double step = std::max(.1, max / 300.);
+ const double step = std::max(1e-2, max / 500.);
QPointF prev = point_to_pixel(QPointF(0, 0));
for (double i = 0; i < max; i += step) {
@@ -141,11 +141,6 @@ void QFunctionConfigurator::drawFunction()
drawLine(&painter, prev, cur, pen);
prev = cur;
}
- if (points.size())
- {
- auto last = point_to_pixel(points[points.size()-1]);
- drawLine(&painter, prev, last, pen);
- }
}
void QFunctionConfigurator::paintEvent(QPaintEvent *e)
@@ -259,16 +254,45 @@ void QFunctionConfigurator::mouseMoveEvent(QMouseEvent *e)
bool overlap = false;
- QPointF new_pt = pixel_coord_to_point(e->pos());
+ QPoint pix = e->pos();
+ QPointF new_pt = pixel_coord_to_point(pix);
- if (moving_control_point_idx + 1 < points.size())
- overlap |= new_pt.x() > points[moving_control_point_idx+1].x();
- if (moving_control_point_idx != 0)
- overlap |= new_pt.x() < points[moving_control_point_idx-1].x();
+ static constexpr int limit = 8;
- if (overlap)
- moving_control_point_idx = -1;
- else
+ for (int i = 0; i < 2; i++)
+ {
+ bool bad = false;
+ if (moving_control_point_idx + 1 < points.size())
+ {
+ auto other = points[moving_control_point_idx+1];
+ auto other_pix = point_to_pixel(other);
+ bad = pix.x() + limit > other_pix.x();
+ if (i == 0 && bad)
+ {
+ pix.setX(other_pix.x() - limit - 1);
+ new_pt = pixel_coord_to_point(pix);
+ }
+ else
+ overlap |= bad;
+ }
+ if (moving_control_point_idx != 0)
+ {
+ auto other = points[moving_control_point_idx-1];
+ auto other_pix = point_to_pixel(other);
+ bad = pix.x() - limit < other_pix.x();
+ if (i == 0 && bad)
+ {
+ pix.setX(other_pix.x() + limit + 1);
+ new_pt = pixel_coord_to_point(pix);
+ }
+ else
+ overlap |= bad;
+ }
+ if (!bad)
+ break;
+ }
+
+ if (!overlap)
{
points[moving_control_point_idx] = new_pt;
_config->movePoint(moving_control_point_idx, new_pt);
@@ -299,12 +323,7 @@ void QFunctionConfigurator::mouseReleaseEvent(QMouseEvent *e)
return;
if (e->button() == Qt::LeftButton) {
- QList<QPointF> points = _config->getPoints();
- if (moving_control_point_idx >= 0 && moving_control_point_idx < points.size()) {
- if (_config) {
- _config->movePoint(moving_control_point_idx, pixel_coord_to_point(e->pos()));
- }
- }
+ mouseMoveEvent(e);
setCursor(Qt::ArrowCursor);
moving_control_point_idx = -1;