summaryrefslogtreecommitdiffhomepage
path: root/qfunctionconfigurator/qfunctionconfigurator.h
blob: e4af0062f945703acd4a3cd61bed638845434f43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* Copyright (c) 2011-2012 Stanislaw Halik <sthalik@misaki.pl>
 *                         Adapted to FaceTrackNoIR by Wim Vriend.
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 */
#pragma once

#include <QWidget>
#include <QtGui>
#include <QPointF>
#include <QElapsedTimer>
#include "qfunctionconfigurator/functionconfig.h"
#include "ftnoir_tracker_base/ftnoir_tracker_base.h"

class FTNOIR_TRACKER_BASE_EXPORT QFunctionConfigurator : public QWidget
{
	Q_OBJECT
    Q_PROPERTY(QString Name READ get_name WRITE set_name)
    
    QColor colorBezier() const
    {
        return colBezier;
    }
    void setColorBezier(QColor color)
    {
        colBezier = color;
        update();
    }
    QString get_name() const {
        return name;
    }
    void set_name(QString name)
    {
        this->name = name;
    }
public:
	QFunctionConfigurator(QWidget *parent = 0);
	FunctionConfig* config();

    void setConfig(FunctionConfig* config);
    void saveSettings(QString settingsFile);
public slots:
protected slots:
	void paintEvent(QPaintEvent *e);
	void mousePressEvent(QMouseEvent *e);
	void mouseMoveEvent(QMouseEvent *e);
	void mouseReleaseEvent(QMouseEvent *e);
protected:
    void drawBackground();
	void drawFunction();
	void drawPoint(QPainter *painter, const QPointF &pt, QColor colBG );
	void drawLine(QPainter *painter, const QPointF &start, const QPointF &end, QPen pen);
    bool point_within_pixel(QPointF pt, QPointF pixel) const;
protected:
	virtual void resizeEvent(QResizeEvent *);

private:
    QString name;
    void update_range() {
        if (!_config)
            return;
        double w = width(), h = height();
        const double mwl = 40, mhl = 20;
        const double mwr = 15, mhr = 35;
        range = QRectF(mwl, mhl, (w - mwl - mwr), (h - mhl - mhr));
        c = QPointF(range.width() / _config->maxInput(), range.height() / _config->maxOutput());
        _draw_function = _draw_background = true;
    }

	QRectF  range;
	QPointF lastPoint;
    QPointF pixel_coord_to_point (QPointF point) const;
    QPointF point_to_pixel (QPointF point) const;

    int     movingPoint;
    QElapsedTimer timer;
    QPointF c;

	QColor colBezier;

	bool _draw_background;
	QPixmap _background;
	bool _draw_function;
	QPixmap _function;

	FunctionConfig* _config;
};