]> git.sesse.net Git - kdenlive/blob - src/kis_curve_widget.h
- Limit number of points in curve widget as they are limited in frei0r
[kdenlive] / src / kis_curve_widget.h
1 /*
2  *  Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
3  *  Copyright (c) 2009 Dmitry Kazakov <dimula73@gmail.com>
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 #ifndef KIS_CURVE_WIDGET_H
20 #define KIS_CURVE_WIDGET_H
21
22 // Qt includes.
23
24 #include <QWidget>
25 #include <QColor>
26 #include <QPointF>
27 #include <QPixmap>
28 #include <QMouseEvent>
29 #include <QKeyEvent>
30 #include <QEvent>
31 #include <QPaintEvent>
32 #include <QList>
33
34 class QSpinBox;
35 class KisCubicCurve;
36
37 /**
38  * KisCurveWidget is a widget that shows a single curve that can be edited
39  * by the user. The user can grab the curve and move it; this creates
40  * a new control point. Control points can be deleted by selecting a point
41  * and pressing the delete key.
42  *
43  * (From: http://techbase.kde.org/Projects/Widgets_and_Classes#KisCurveWidget)
44  * KisCurveWidget allows editing of spline based y=f(x) curves. Handy for cases
45  * where you want the user to control such things as tablet pressure
46  * response, color transformations, acceleration by time, aeroplane lift
47  *by angle of attack.
48  */
49 class KisCurveWidget : public QWidget
50 {
51     Q_OBJECT
52
53 public:
54
55     /**
56      * Create a new curve widget with a default curve, that is a straight
57      * line from bottom-left to top-right.
58      */
59     KisCurveWidget(QWidget *parent = 0, Qt::WFlags f = 0);
60
61     virtual ~KisCurveWidget();
62
63     /**
64      * Reset the curve to the default shape
65      */
66     void reset(void);
67
68     /**
69      * Enable the guide and set the guide color to the specified color.
70      *
71      * XXX: it seems that the guide feature isn't actually implemented yet?
72      */
73     void setCurveGuide(const QColor & color);
74
75
76     /**
77      * Set a background pixmap. The background pixmap will be drawn under
78      * the grid and the curve.
79      *
80      * XXX: or is the pixmap what is drawn to the  left and bottom of the curve
81      * itself?
82      */
83     void setPixmap(const QPixmap & pix);
84
85 signals:
86
87     /**
88      * Emitted whenever a control point has changed position.
89      */
90     void modified(void);
91
92 protected slots:
93     void inOutChanged(int);
94
95
96 protected:
97
98     void keyPressEvent(QKeyEvent *);
99     void paintEvent(QPaintEvent *);
100     void mousePressEvent(QMouseEvent * e);
101     void mouseReleaseEvent(QMouseEvent * e);
102     void mouseMoveEvent(QMouseEvent * e);
103     void leaveEvent(QEvent *);
104     void resizeEvent(QResizeEvent *e);
105
106 public:
107
108     /**
109      * @return get a list with all defined points. If you want to know what the
110      * y value for a given x is on the curve defined by these points, use getCurveValue().
111      * @see getCurveValue
112      */
113     KisCubicCurve curve();
114
115     /**
116      * Replace the current curve with a curve specified by the curve defined by the control
117      * points in @param inlist.
118      */
119     void setCurve(KisCubicCurve inlist);
120
121     /**
122      * Connect/disconnect external spinboxes to the curve
123      * @min/@max - is the range for their values
124      */
125     void setupInOutControls(QSpinBox *in, QSpinBox *out, int min, int max);
126     void dropInOutControls();
127
128     /**
129      * Handy function that creates new point in the middle
130      * of the curve and sets focus on the m_intIn field,
131      * so the user can move this point anywhere in a moment
132      */
133     void addPointInTheMiddle();
134     
135     void setMaxPoints(int max);
136
137 private:
138
139     class Private;
140     Private * const d;
141
142 };
143
144
145 #endif /* KIS_CURVE_WIDGET_H */