diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2016-12-08 05:38:00 +0100 | 
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-12-08 05:38:00 +0100 | 
| commit | b48a48c143d64caac7d456f9f2a7db180f845a9a (patch) | |
| tree | 1c44500607674f8b5234a97ee1341c582b14633d /spline-widget | |
| parent | ec4c9bb2b53d351dd20f3db342a79a9a75fbc5b9 (diff) | |
spline-widget: improve preview mode for tobii
Diffstat (limited to 'spline-widget')
| -rw-r--r-- | spline-widget/spline-widget.cpp | 26 | ||||
| -rw-r--r-- | spline-widget/spline-widget.hpp | 11 | 
2 files changed, 29 insertions, 8 deletions
diff --git a/spline-widget/spline-widget.cpp b/spline-widget/spline-widget.cpp index 45a90c6a..f10995d4 100644 --- a/spline-widget/spline-widget.cpp +++ b/spline-widget/spline-widget.cpp @@ -101,7 +101,8 @@ void spline_widget::drawBackground()      _background = QPixmap(width(), height());      QPainter painter(&_background); -    painter.fillRect(rect(), QColor::fromRgb(204, 204, 204)); + +    painter.fillRect(rect(), QWidget::palette().color(QWidget::backgroundRole()));      QColor bg_color(112, 154, 209);      if (!isEnabled() && !_preview_only) @@ -308,11 +309,11 @@ void spline_widget::drawLine(QPainter& painter, const QPoint& start, const QPoin  void spline_widget::mousePressEvent(QMouseEvent *e)  { -    if (!_config || !isEnabled()) -        return; - -    if (!is_in_bounds(e->pos())) +    if (!_config || !isEnabled() || !is_in_bounds(e->pos())) +    { +        clearFocus();          return; +    }      const int point_pixel_closeness_limit = get_closeness_limit(); @@ -384,6 +385,13 @@ void spline_widget::mousePressEvent(QMouseEvent *e)  void spline_widget::mouseMoveEvent(QMouseEvent *e)  { +    if (_preview_only && _config) +    { +        show_tooltip(e->pos()); +        clearFocus(); +        return; +    } +      if (!_config || !isEnabled() || !isActiveWindow() || (moving_control_point_idx != -1 && !hasFocus()))      {          clearFocus(); @@ -488,11 +496,15 @@ int spline_widget::get_closeness_limit()      return std::max(iround(snap_x * c.x()), 1);  } -void spline_widget::show_tooltip(const QPoint& pos, const QPointF& value_, const QString& prefix) +void spline_widget::show_tooltip(const QPoint& pos, const QPointF& value_)  {      const QPointF value = QPoint(0, 0) == value_ ? pixel_coord_to_point(pos) : value_;      double x = value.x(), y = value.y(); + +    if (_preview_only) +        y = _config->get_value_no_save(x); +      const int x_ = iround(x), y_ = iround(y);      using std::fabs; @@ -508,7 +520,7 @@ void spline_widget::show_tooltip(const QPoint& pos, const QPointF& value_, const      const QPoint pix(int(pos.x()) + add_x, int(pos.y()) + add_y);      QToolTip::showText(mapToGlobal(pix), -                       QStringLiteral("value: %1%2x%3").arg(prefix).arg(x).arg(y), +                       QStringLiteral("value: %1x%2").arg(x).arg(y),                         this,                         rect(),                         0); diff --git a/spline-widget/spline-widget.hpp b/spline-widget/spline-widget.hpp index d52e249c..921f44a2 100644 --- a/spline-widget/spline-widget.hpp +++ b/spline-widget/spline-widget.hpp @@ -32,6 +32,8 @@ class OPENTRACK_SPLINE_EXPORT spline_widget final : public QWidget      Q_OBJECT      Q_PROPERTY(QColor colorBezier READ colorBezier WRITE setColorBezier)      Q_PROPERTY(bool is_preview_only READ is_preview_only WRITE set_preview_only) +    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: @@ -47,6 +49,12 @@ public:      void force_redraw();      void set_preview_only(bool val);      bool is_preview_only() const; + +    double x_step() { return _x_step; } +    double y_step() { return _y_step; } +    void set_x_step(double val) { _x_step = val; } +    void set_y_step(double val) { _y_step = 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; }  protected slots: @@ -57,7 +65,7 @@ protected slots:      void reload_spline();  private:      int get_closeness_limit(); -    void show_tooltip(const QPoint& pos, const QPointF& value = QPointF(0, 0), const QString& prefix = QStringLiteral("")); +    void show_tooltip(const QPoint& pos, const QPointF& value = QPointF(0, 0));      bool is_in_bounds(const QPoint& pos) const;      void drawBackground(); @@ -89,6 +97,7 @@ private:      QMetaObject::Connection connection;      double snap_x, snap_y; +    double _x_step, _y_step;      int moving_control_point_idx;      bool _draw_function, _preview_only;  | 
