]> git.sesse.net Git - kdenlive/blob - src/beziercurve/cubicbezierspline.h
Bezier Spline: Allow to link the handles of a point. They will then always remain...
[kdenlive] / src / beziercurve / cubicbezierspline.h
1 /***************************************************************************
2  *   Copyright (C) 2010 by Till Theato (root@ttill.de)                     *
3  *   This file is part of Kdenlive (www.kdenlive.org).                     *
4  *                                                                         *
5  *   Kdenlive 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  *   Kdenlive 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 Kdenlive.  If not, see <http://www.gnu.org/licenses/>.     *
17  ***************************************************************************/
18
19 #ifndef CUBICBEZIERSPLINE_H
20 #define CUBICBEZIERSPLINE_H
21
22 #include "bpoint.h"
23
24 #include <QtCore>
25
26
27 class CubicBezierSpline : public QObject
28 {
29     Q_OBJECT
30
31 public:
32     CubicBezierSpline(QObject* parent = 0);
33     CubicBezierSpline(const CubicBezierSpline &spline, QObject* parent = 0);
34     CubicBezierSpline& operator=(const CubicBezierSpline &spline);
35
36     void fromString(const QString &spline);
37     QString toString() const;
38
39     QList <BPoint> points();
40     qreal value(qreal x, bool cont = false);
41
42     int setPoint(int ix, const BPoint &point);
43     int addPoint(const BPoint &point);
44     void removePoint(int ix);
45     void setPrecision(int pre);
46     int getPrecision();
47
48 private:
49     QPointF point(double t, const QList<QPointF> &points);
50     void validatePoints();
51     void keepSorted();
52     void update();
53     int indexOf(const BPoint &p);
54
55     QList <BPoint> m_points;
56     QMap <double, double> m_spline;
57     QMap <double, double>::const_iterator m_i;
58     bool m_validSpline;
59     int m_precision;
60     
61 };
62
63 #endif