]> git.sesse.net Git - kdenlive/blob - src/widgets/kis_curve_widget.h
Moving choosecolorwidget and colorpickerwidget in the widget folder.
[kdenlive] / src / widgets / 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     explicit 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     virtual QSize sizeHint() const;
86
87 signals:
88
89     /**
90      * Emitted whenever a control point has changed position.
91      */
92     void modified(void);
93
94 protected slots:
95     void inOutChanged(int);
96
97
98 protected:
99
100     void keyPressEvent(QKeyEvent *);
101     void paintEvent(QPaintEvent *);
102     void mousePressEvent(QMouseEvent * e);
103     void mouseReleaseEvent(QMouseEvent * e);
104     void mouseMoveEvent(QMouseEvent * e);
105     void leaveEvent(QEvent *);
106     void resizeEvent(QResizeEvent *e);
107
108 public:
109
110     /**
111      * @return get a list with all defined points. If you want to know what the
112      * y value for a given x is on the curve defined by these points, use getCurveValue().
113      * @see getCurveValue
114      */
115     KisCubicCurve curve();
116
117     /**
118      * Replace the current curve with a curve specified by the curve defined by the control
119      * points in @param inlist.
120      */
121     void setCurve(KisCubicCurve inlist);
122
123     /**
124      * Connect/disconnect external spinboxes to the curve
125      * @min/@max - is the range for their values
126      */
127     void setupInOutControls(QSpinBox *in, QSpinBox *out, int min, int max);
128     void dropInOutControls();
129
130     /**
131      * Handy function that creates new point in the middle
132      * of the curve and sets focus on the m_intIn field,
133      * so the user can move this point anywhere in a moment
134      */
135     void addPointInTheMiddle();
136
137     void setMaxPoints(int max);
138
139 private:
140
141     class Private;
142     Private * const d;
143
144 };
145
146
147 #endif /* KIS_CURVE_WIDGET_H */