summaryrefslogtreecommitdiffhomepage
path: root/spline-widget
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-01-29 03:09:09 +0100
committerStanislaw Halik <sthalik@misaki.pl>2017-01-29 03:09:09 +0100
commitff0d3aefe8d14796f636b890595f12b5b08d6d2f (patch)
treef9b2483b5926c6e7627f49aaf4121463b20a31b1 /spline-widget
parentcb5873922f4528b80d40e13b05bd7590421d79ee (diff)
spline-widget: remove camel case
My eyes bleed a bit less
Diffstat (limited to 'spline-widget')
-rw-r--r--spline-widget/spline-widget.cpp32
-rw-r--r--spline-widget/spline.cpp60
-rw-r--r--spline-widget/spline.hpp32
3 files changed, 71 insertions, 53 deletions
diff --git a/spline-widget/spline-widget.cpp b/spline-widget/spline-widget.cpp
index 826673e9..c8356fb4 100644
--- a/spline-widget/spline-widget.cpp
+++ b/spline-widget/spline-widget.cpp
@@ -122,8 +122,8 @@ void spline_widget::drawBackground()
const QPen pen(color__, 1, Qt::SolidLine, Qt::FlatCap);
const int xstep = 10, ystep = 10;
- const qreal maxx = _config->maxInput();
- const qreal maxy = _config->maxOutput();
+ const qreal maxx = _config->max_input();
+ const qreal maxy = _config->max_output();
// horizontal grid
for (int i = 0; i <= maxy; i += xstep)
@@ -163,7 +163,7 @@ void spline_widget::drawFunction()
QPainter painter(&_function);
painter.setRenderHint(QPainter::Antialiasing, true);
- const points_t points = _config->getPoints();
+ const points_t points = _config->get_points();
if (moving_control_point_idx >= 0 &&
moving_control_point_idx < points.size())
@@ -205,7 +205,7 @@ void spline_widget::drawFunction()
#ifndef DEBUG_SPLINE
static constexpr double step_ = 3./3;
- const double maxx = _config->maxInput();
+ const double maxx = _config->max_input();
const double step = step_ / c.x();
QPainterPath path;
@@ -283,7 +283,7 @@ void spline_widget::paintEvent(QPaintEvent *e)
// Show that point on the graph, with some lines to assist.
// This new feature is very handy for tweaking the curves!
QPointF last;
- if (_config->getLastPoint(last) && isEnabled())
+ if (_config->get_last_value(last) && isEnabled())
drawPoint(p, point_to_pixel(last), QColor(255, 0, 0, 120));
}
@@ -317,7 +317,7 @@ void spline_widget::mousePressEvent(QMouseEvent *e)
const int point_pixel_closeness_limit = get_closeness_limit();
- points_t points = _config->getPoints();
+ points_t points = _config->get_points();
if (e->button() == Qt::LeftButton)
{
bool bTouchingPoint = false;
@@ -351,7 +351,7 @@ void spline_widget::mousePressEvent(QMouseEvent *e)
if (!too_close)
{
- _config->addPoint(pixel_coord_to_point(e->pos()));
+ _config->add_point(pixel_coord_to_point(e->pos()));
show_tooltip(e->pos());
}
}
@@ -374,7 +374,7 @@ void spline_widget::mousePressEvent(QMouseEvent *e)
if (found_pt != -1)
{
- _config->removePoint(found_pt);
+ _config->remove_point(found_pt);
}
moving_control_point_idx = -1;
}
@@ -399,7 +399,7 @@ void spline_widget::mouseMoveEvent(QMouseEvent *e)
}
const int i = moving_control_point_idx;
- const points_t points = _config->getPoints();
+ const points_t points = _config->get_points();
const int sz = points.size();
if (i >= 0 && i < sz)
@@ -429,7 +429,7 @@ void spline_widget::mouseMoveEvent(QMouseEvent *e)
if (overlap)
new_pt.setX(points[i].x());
- _config->movePoint(i, new_pt);
+ _config->move_point(i, new_pt);
_draw_function = true;
setCursor(Qt::ClosedHandCursor);
@@ -546,7 +546,7 @@ void spline_widget::update_range()
const int mwr = 15, mhr = 35;
pixel_bounds = QRect(mwl, mhl, (w - mwl - mwr), (h - mhl - mhr));
- c = QPointF(pixel_bounds.width() / _config->maxInput(), pixel_bounds.height() / _config->maxOutput());
+ c = QPointF(pixel_bounds.width() / _config->max_input(), pixel_bounds.height() / _config->max_output());
_draw_function = true;
_background = QPixmap();
@@ -597,13 +597,13 @@ QPointF spline_widget::pixel_coord_to_point(const QPoint& point)
if (x < 0)
x = 0;
- if (x > _config->maxInput())
- x = _config->maxInput();
+ if (x > _config->max_input())
+ x = _config->max_input();
if (y < 0)
y = 0;
- if (y > _config->maxOutput())
- y = _config->maxOutput();
+ if (y > _config->max_output())
+ y = _config->max_output();
return QPointF(x, y);
}
@@ -635,7 +635,7 @@ bool spline_widget::is_on_pt(const QPoint& pos, int* pt)
return false;
}
- const points_t points = _config->getPoints();
+ const points_t points = _config->get_points();
for (int i = 0; i < points.size(); i++)
{
diff --git a/spline-widget/spline.cpp b/spline-widget/spline.cpp
index 57817d40..59ed9939 100644
--- a/spline-widget/spline.cpp
+++ b/spline-widget/spline.cpp
@@ -42,16 +42,15 @@ spline::~spline()
if (connection)
{
QObject::disconnect(connection);
+ connection = QMetaObject::Connection();
}
}
-spline::spline() : spline(0, 0, "")
-{
-}
+spline::spline() : spline(0, 0, "") {}
-void spline::setTrackingActive(bool blnActive)
+void spline::set_tracking_active(bool value)
{
- activep = blnActive;
+ activep = value;
}
bundle spline::get_bundle()
@@ -59,40 +58,40 @@ bundle spline::get_bundle()
return s->b;
}
-void spline::removeAllPoints()
+void spline::clear()
{
QMutexLocker l(&_mutex);
s->points = points_t();
validp = false;
}
-void spline::setMaxInput(qreal max_input)
+void spline::set_max_input(qreal max_input)
{
QMutexLocker l(&_mutex);
max_x = max_input;
recompute();
}
-void spline::setMaxOutput(qreal max_output)
+void spline::set_max_output(qreal max_output)
{
QMutexLocker l(&_mutex);
max_y = max_output;
recompute();
}
-qreal spline::maxInput() const
+qreal spline::max_input() const
{
QMutexLocker l(&_mutex);
return max_x;
}
-qreal spline::maxOutput() const
+qreal spline::max_output() const
{
QMutexLocker l(&_mutex);
return max_y;
}
-float spline::getValue(double x)
+float spline::get_value(double x)
{
QMutexLocker foo(&_mutex);
@@ -106,23 +105,26 @@ float spline::get_value_no_save(double x)
{
QMutexLocker foo(&_mutex);
+ if (max_x > 0)
+ x = std::min(max_x, x);
+
float q = float(x * precision(s->points));
int xi = (int)q;
- float yi = getValueInternal(xi);
- float yiplus1 = getValueInternal(xi+1);
+ float yi = get_value_internal(xi);
+ float yiplus1 = get_value_internal(xi+1);
float f = (q-xi);
float ret = yiplus1 * f + yi * (1.0f - f); // at least do a linear interpolation.
return ret;
}
-bool spline::getLastPoint(QPointF& point)
+DEFUN_WARN_UNUSED bool spline::get_last_value(QPointF& point)
{
QMutexLocker foo(&_mutex);
point = last_input_value;
return activep;
}
-float spline::getValueInternal(int x)
+float spline::get_value_internal(int x)
{
if (!validp)
{
@@ -148,11 +150,27 @@ void spline::add_lone_point()
QPointF spline::ensure_in_bounds(const QList<QPointF>& points, int i)
{
const int sz = points.size();
+start:
if (i < 0 || sz == 0)
return QPointF(0, 0);
+
if (i < sz)
+ {
+ if (max_x > 0 && max_x < points[i])
+ {
+ i--;
+ goto start;
+ }
return points[i];
+ }
+
+ if (max_x > 0 && max_x < points[sz - 1])
+ {
+ i = sz - 2;
+ goto start;
+ }
+
return points[sz - 1];
}
@@ -244,7 +262,7 @@ void spline::update_interp_data()
}
}
-void spline::removePoint(int i)
+void spline::remove_point(int i)
{
QMutexLocker foo(&_mutex);
@@ -258,7 +276,7 @@ void spline::removePoint(int i)
}
}
-void spline::addPoint(QPointF pt)
+void spline::add_point(QPointF pt)
{
QMutexLocker foo(&_mutex);
@@ -269,12 +287,12 @@ void spline::addPoint(QPointF pt)
validp = false;
}
-void spline::addPoint(double x, double y)
+void spline::add_point(double x, double y)
{
- addPoint(QPointF(x, y));
+ add_point(QPointF(x, y));
}
-void spline::movePoint(int idx, QPointF pt)
+void spline::move_point(int idx, QPointF pt)
{
QMutexLocker foo(&_mutex);
@@ -290,7 +308,7 @@ void spline::movePoint(int idx, QPointF pt)
}
}
-QList<QPointF> spline::getPoints() const
+QList<QPointF> spline::get_points() const
{
QMutexLocker foo(&_mutex);
return s->points;
diff --git a/spline-widget/spline.hpp b/spline-widget/spline.hpp
index adabd33c..660757f2 100644
--- a/spline-widget/spline.hpp
+++ b/spline-widget/spline.hpp
@@ -44,7 +44,7 @@ class OPENTRACK_SPLINE_EXPORT spline final
{
double precision(const QList<QPointF>& points) const;
void update_interp_data();
- float getValueInternal(int x);
+ float get_value_internal(int x);
void add_lone_point();
static bool sort_fn(const QPointF& one, const QPointF& two);
@@ -72,8 +72,8 @@ public:
void save();
void set_bundle(bundle b);
- qreal maxInput() const;
- qreal maxOutput() const;
+ qreal max_input() const;
+ qreal max_output() const;
spline();
spline(qreal maxx, qreal maxy, const QString& name);
~spline();
@@ -81,20 +81,20 @@ public:
spline& operator=(const spline&) = default;
spline(const spline&) = default;
- float getValue(double x);
+ float get_value(double x);
float get_value_no_save(double x);
- bool getLastPoint(QPointF& point);
- void removePoint(int i);
- void removeAllPoints();
-
- void addPoint(QPointF pt);
- void addPoint(double x, double y);
- void movePoint(int idx, QPointF pt);
- QList<QPointF> getPoints() const;
- void setMaxInput(qreal MaxInput);
- void setMaxOutput(qreal MaxOutput);
-
- void setTrackingActive(bool blnActive);
+ DEFUN_WARN_UNUSED bool get_last_value(QPointF& point);
+ void remove_point(int i);
+ void clear();
+
+ void add_point(QPointF pt);
+ void add_point(double x, double y);
+ void move_point(int idx, QPointF pt);
+ QList<QPointF> get_points() const;
+ void set_max_input(qreal MaxInput);
+ void set_max_output(qreal MaxOutput);
+
+ void set_tracking_active(bool value);
bundle get_bundle();
void recompute();