From 4f7bafa0124c3baa7b8da18806f50e6ff84fcf98 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 5 Sep 2016 17:20:35 +0200 Subject: spline-widget: add tooltips, refactor Tooltip shows current cursor/point position. Factor out common functions. Use QPoint/QPointF appropriately. Remove rounding that led to snapping to integral values. Allow for non-integral snapping amounts. Issue: #436 --- spline-widget/spline-widget.hpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'spline-widget/spline-widget.hpp') diff --git a/spline-widget/spline-widget.hpp b/spline-widget/spline-widget.hpp index 94e6b32c..53560d6a 100644 --- a/spline-widget/spline-widget.hpp +++ b/spline-widget/spline-widget.hpp @@ -17,9 +17,13 @@ using namespace options; #include "export.hpp" #include -#include -#include +#include +#include #include +#include +#include +#include + #include class OPENTRACK_SPLINE_EXPORT spline_widget final : public QWidget @@ -62,30 +66,31 @@ protected slots: void mouseReleaseEvent(QMouseEvent *e) override; void reload_spline(); private: + void show_tooltip(const QPoint& pos, const QPointF& value = QPointF(0, 0), const QString& prefix = QStringLiteral("")); + bool is_in_bounds(const QPoint& pos) const; + void drawBackground(); void drawFunction(); - void drawPoint(QPainter *painter, const QPointF &pt, QColor colBG, QColor border = QColor(50, 100, 120, 200)); - void drawLine(QPainter *painter, const QPointF &start, const QPointF &end, QPen& pen); - bool point_within_pixel(const QPointF& pt, const QPointF& pixel); + 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); protected: void resizeEvent(QResizeEvent *) override; private: + bool is_on_pt(const QPoint& pos, int* pt = nullptr); void update_range(); - - QPointF pixel_coord_to_point (const QPointF& point); + QPointF pixel_coord_to_point(const QPoint& point); QPointF point_to_pixel(const QPointF& point); - spline* _config; - - // bounds of the rectangle user can interact with - QRectF pixel_bounds; - QPointF c; - - QColor spline_color; + spline* _config; QPixmap _background; QPixmap _function; + QColor spline_color; + + // bounds of the rectangle user can interact with + QRect pixel_bounds; QMetaObject::Connection connection; @@ -95,5 +100,5 @@ private: static constexpr int line_length_pixels = 3; static constexpr int point_size = 4; - static constexpr int point_closeness_limit = 5; + static constexpr int point_closeness_limit = 7; }; -- cgit v1.2.3