summaryrefslogtreecommitdiffhomepage
path: root/spline-widget
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-05-26 17:16:43 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-05-26 17:32:54 +0200
commit70c9aaa9c297d2b20b7d3b466ceaf5f1def36752 (patch)
tree4dba0df4a63404fd90f0bc8e8fc58de8eba0d057 /spline-widget
parent26de6a0ad9ed082e14de928ef03f4db379e9686f (diff)
spline-widget: allow using as preview when disabled
Diffstat (limited to 'spline-widget')
-rw-r--r--spline-widget/qfunctionconfigurator.cpp30
-rw-r--r--spline-widget/qfunctionconfigurator.h5
2 files changed, 26 insertions, 9 deletions
diff --git a/spline-widget/qfunctionconfigurator.cpp b/spline-widget/qfunctionconfigurator.cpp
index 18af8c46..538b5dc9 100644
--- a/spline-widget/qfunctionconfigurator.cpp
+++ b/spline-widget/qfunctionconfigurator.cpp
@@ -19,9 +19,10 @@ QFunctionConfigurator::QFunctionConfigurator(QWidget *parent) :
QWidget(parent),
_config(nullptr),
moving_control_point_idx(-1),
- _draw_function(true),
snap_x(0),
- snap_y(0)
+ snap_y(0),
+ _draw_function(true),
+ _preview_only(false)
{
update_range();
setMouseTracking(true);
@@ -37,6 +38,16 @@ void QFunctionConfigurator::setConfig(Map* config, const QString& name) {
update();
}
+void QFunctionConfigurator::set_preview_only(bool val)
+{
+ _preview_only = val;
+}
+
+bool QFunctionConfigurator::is_preview_only() const
+{
+ return _preview_only;
+}
+
void QFunctionConfigurator::drawBackground()
{
if (!_config)
@@ -47,7 +58,7 @@ void QFunctionConfigurator::drawBackground()
painter.fillRect(rect(), QColor::fromRgb(204, 204, 204));
QColor bg_color(112, 154, 209);
- if (!isEnabled())
+ if (!isEnabled() && !_preview_only)
bg_color = QColor(176,176,180);
painter.fillRect(pixel_bounds, bg_color);
@@ -120,13 +131,13 @@ void QFunctionConfigurator::drawFunction()
QColor color = spline_color;
- if (!isEnabled())
+ if (!isEnabled() && !_preview_only)
{
- const int avg = 176;
+ const float avg = (color.red() + color.green() + color.blue())/3.f;
auto color_ = color;
- color = QColor(color_.red() * .5 + avg * .5,
- color_.green() * .5 + avg * .5,
- color_.blue() * .5 + avg * .5,
+ color = QColor(int(color_.red() * .5 + avg * .5),
+ int(color_.green() * .5 + avg * .5),
+ int(color_.blue() * .5 + avg * .5),
96);
}
@@ -201,6 +212,9 @@ void QFunctionConfigurator::paintEvent(QPaintEvent *e)
void QFunctionConfigurator::drawPoint(QPainter *painter, const QPointF &pos, QColor colBG, QColor border)
{
+ if (_preview_only)
+ return;
+
painter->save();
painter->setPen(border);
painter->setBrush( colBG );
diff --git a/spline-widget/qfunctionconfigurator.h b/spline-widget/qfunctionconfigurator.h
index ffd1dd78..1700dfca 100644
--- a/spline-widget/qfunctionconfigurator.h
+++ b/spline-widget/qfunctionconfigurator.h
@@ -19,6 +19,7 @@ class SPLINE_WIDGET_EXPORT QFunctionConfigurator : 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)
public:
QFunctionConfigurator(QWidget *parent = 0);
@@ -39,6 +40,8 @@ public:
_background = QPixmap();
update();
}
+ void set_preview_only(bool val);
+ bool is_preview_only() const;
void set_snap(int x, int y) { snap_x = x; snap_y = y; }
void get_snap(int& x, int& y) const { x = snap_x; y = snap_y; }
protected slots:
@@ -72,8 +75,8 @@ private:
QPixmap _background;
QPixmap _function;
- bool _draw_function;
int snap_x, snap_y;
+ bool _draw_function, _preview_only;
static constexpr int line_length_pixels = 3;
static constexpr int point_size = 5;