summaryrefslogtreecommitdiffhomepage
path: root/spline/spline-widget.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'spline/spline-widget.hpp')
-rw-r--r--spline/spline-widget.hpp76
1 files changed, 43 insertions, 33 deletions
diff --git a/spline/spline-widget.hpp b/spline/spline-widget.hpp
index 12d21970..610baf43 100644
--- a/spline/spline-widget.hpp
+++ b/spline/spline-widget.hpp
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2016 Stanislaw Halik <sthalik@misaki.pl>
+/* Copyright (c) 2012-2019 Stanislaw Halik <sthalik@misaki.pl>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -11,23 +11,23 @@
#include "spline.hpp"
#include "api/plugin-api.hpp"
+#include "compat/qt-dpi.hpp"
#include "options/options.hpp"
-using namespace options;
#include "export.hpp"
+#include <cmath>
+
#include <QWidget>
-#include <QRect>
-#include <QPoint>
-#include <QPointF>
-#include <QToolTip>
-#include <QShowEvent>
-#include <QFocusEvent>
#include <QMetaObject>
#include <QDebug>
-class OTR_SPLINE_EXPORT spline_widget final : public QWidget
+namespace spline_detail {
+
+using namespace options;
+
+class OTR_SPLINE_EXPORT spline_widget final : public QWidget, public screen_dpi_mixin<spline_widget>
{
Q_OBJECT
Q_PROPERTY(QColor colorBezier READ colorBezier WRITE setColorBezier)
@@ -35,27 +35,28 @@ class OTR_SPLINE_EXPORT spline_widget final : public QWidget
Q_PROPERTY(int x_step READ x_step WRITE set_x_step)
Q_PROPERTY(int y_step READ y_step WRITE set_y_step)
- using points_t = spline::points_t;
public:
- spline_widget(QWidget *parent = 0);
- ~spline_widget();
+ explicit spline_widget(QWidget *parent = nullptr);
+ ~spline_widget() override;
- void setConfig(base_spline* spl);
+ void set_config(base_spline* spl);
QColor colorBezier() const;
- void setColorBezier(QColor color);
+ void setColorBezier(QColor const& color);
void force_redraw();
void set_preview_only(bool val);
bool is_preview_only() const;
- double x_step() const { return _x_step; }
- double y_step() const { return _y_step; }
- void set_x_step(double val) { _x_step = std::fmax(1., val); }
- void set_y_step(double val) { _y_step = std::fmax(1., val); }
+ double x_step() const { return x_step_; }
+ double y_step() const { return y_step_; }
+ void set_x_step(double val) { x_step_ = std::fmax(1., val); }
+ void set_y_step(double val) { y_step_ = std::fmax(1., val); }
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; }
+
+ QSize minimumSizeHint() const override;
public slots:
void reload_spline();
protected slots:
@@ -64,33 +65,35 @@ protected slots:
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
private:
- int get_closeness_limit();
+ double min_pt_distance() const;
void show_tooltip(const QPoint& pos, const QPointF& value = QPointF(0, 0));
- bool is_in_bounds(const QPoint& pos) const;
+ bool is_in_bounds(const QPointF& pos) const;
void drawBackground();
void drawFunction();
void drawPoint(QPainter& painter, const QPointF& pt, const QColor& colBG, const QColor& border = QColor(50, 100, 120, 200));
- void drawLine(QPainter& painter, const QPoint& start, const QPoint& end, const QPen& pen);
- bool point_within_pixel(const QPointF& pt, const QPoint& pixel);
+ void drawLine(QPainter& painter, const QPointF& start, const QPointF& end, const QPen& pen);
+ bool point_within_pixel(const QPointF& pt, const QPointF& pixel);
void focusOutEvent(QFocusEvent*e) override;
void resizeEvent(QResizeEvent *) override;
- bool is_on_pt(const QPoint& pos, int* pt = nullptr);
+ bool is_on_pt(const QPointF& pos, int* pt = nullptr);
void update_range();
- QPointF pixel_coord_to_point(const QPoint& point);
+ void changeEvent(QEvent* e) override;
+
+ QPointF pixel_to_point(const QPointF& point);
+ QPointF point_to_pixel(const QPointF& point);
- QPointF point_to_pixel_(const QPointF& point);
- QPoint point_to_pixel(const QPointF& point);
+ static double snap(double x, double snap_value);
QPointF c;
- base_spline* _config = nullptr;
+ base_spline* config = nullptr;
- QPixmap _background;
- QPixmap _function;
+ QPixmap background_img;
+ QPixmap spline_img;
QColor spline_color;
- QColor widget_bg_color = palette().background().color();
+ QColor widget_bg_color = palette().window().color();
// bounds of the rectangle user can interact with
QRect pixel_bounds;
@@ -98,9 +101,16 @@ private:
QMetaObject::Connection connection;
double snap_x = 0, snap_y = 0;
- double _x_step = 10, _y_step = 10;
+ double x_step_ = 10, y_step_ = 10;
int moving_control_point_idx = -1;
- bool _draw_function = true, _preview_only = false;
+ bool draw_function = true, preview_only = false;
+
+ // point's circle radius on the widget
+ static constexpr int point_size_in_pixels_ = 5;
- static constexpr inline int point_size = 4;
+ const double point_size_in_pixels = point_size_in_pixels_ * screen_dpi();
};
+
+} // ns spline_detail
+
+using spline_widget = spline_detail::spline_widget;