summaryrefslogtreecommitdiffhomepage
path: root/bin/qbezierconfigurator.h
blob: 81ce013aac825103f856314b4a6c90c7b22267a5 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef QBEZIERCONFIGURATOR_H
#define QBEZIERCONFIGURATOR_H

#include <QtGui>
#include <QtDesigner/QDesignerExportWidget>
#include <QPointF>

class QDESIGNER_WIDGET_EXPORT QBezierConfigurator : public QWidget
{
	Q_OBJECT
    Q_PROPERTY(int maxInputEGU READ maxInputEGU WRITE setmaxInputEGU);
    Q_PROPERTY(int maxOutputEGU READ maxOutputEGU WRITE setmaxOutputEGU);
    Q_PROPERTY(int pixPerEGU READ pixPerEGU WRITE setpixPerEGU);

	Q_PROPERTY(QColor colorBezier READ colorBezier WRITE setColorBezier);
    Q_PROPERTY(QColor colorBackground READ colorBackground WRITE setColorBackground);
    Q_PROPERTY(QString stringInputEGU READ stringInputEGU WRITE setInputEGU);
    Q_PROPERTY(QString stringOutputEGU READ stringOutputEGU WRITE setOutputEGU);
    Q_PROPERTY(QString stringCaption READ stringCaption WRITE setCaption);

	// Return the current value to Designer
	int maxInputEGU() const
    {
        return MaxInput;
    }
	int maxOutputEGU() const
    {
        return MaxOutput;
    }
	int pixPerEGU() const
    {
        return pPerEGU;
    }

	// Return the current color to Designer
	QColor colorBezier() const
    {
        return colBezier;
    }
	// Return the current color to Designer
	QColor colorBackground() const
    {
        return colBackground;
    }
	// Return the current string to Designer
	QString stringInputEGU() const
    {
        return strInputEGU;
    }
	// Return the current string to Designer
	QString stringOutputEGU() const
    {
        return strOutputEGU;
    }
	// Return the current string to Designer
	QString stringCaption() const
    {
        return strCaption;
    }

public:
	QBezierConfigurator(QWidget *parent = 0);
	~QBezierConfigurator();

signals:
    void valueNeutralZoneChanged(int);
    void BezierCurveChanged(bool);

public slots:
    void setmaxInputEGU(int);
    void setmaxOutputEGU(int);
    void setpixPerEGU(int);

    QPointF getPointOne();
    QPointF getPointTwo();
    QPointF getPointThree();
    QPointF getPointFour();

	void setPointOne(QPointF);
    void setPointTwo(QPointF);
    void setPointThree(QPointF);
    void setPointFour(QPointF);

	void setNeutralZone(int zone);

    void setColorBezier(QColor);
    void setColorBackground(QColor);
    void setInputEGU(QString);
    void setOutputEGU(QString);
    void setCaption(QString);

protected slots:
	void paintEvent(QPaintEvent *e);
	void mousePressEvent(QMouseEvent *e);
	void mouseMoveEvent(QMouseEvent *e);
	void mouseReleaseEvent(QMouseEvent *e);
      
protected:
	void drawBackground(QPainter *painter, const QRectF &rect);
	void drawPoint(QPainter *painter, const QPointF &pt);
	void drawLine(QPainter *painter, const QPointF &start, const QPointF &end, QPen pen);
	bool markContains(const QPointF &pt, const QPointF &coord) const;
	bool withinRange( const QPointF &coord ) const;

protected:
	virtual void resizeEvent(QResizeEvent *);

private:
	QRectF  range;										// The actual rectangle for the Bezier-curve
	QPointF one, two, three, four;						// The four points, that define the curve
	QPointF normalizePoint (QPointF point) const;		// Convert the graphical Point to a real-life Point
	QPointF graphicalizePoint (QPointF point) const;	// Convert the Point to a graphical Point

	QPointF mouseStart;
	QPointF *moving;
	int     movingPoint;

	int MaxInput;					// Maximum input limit
	int MaxOutput;					// Maximum output limit
	int pPerEGU;					// Number of pixels, per EGU

	QColor colBezier;				// Color of Bezier curve
	QColor colBackground;			// Color of widget background
	QString strInputEGU;			// Engineering Units input (vertical axis)
	QString strOutputEGU;			// Engineering Units output (horizontal axis)
	QString strCaption;				// Caption of the graph

};

#endif // QBEZIERCONFIGURATOR_H