]> git.sesse.net Git - kdenlive/blob - src/onmonitoritems/rotoscoping/splineitem.cpp
9260d4fc026c3a986d0bee945da05246bdb18fde
[kdenlive] / src / onmonitoritems / rotoscoping / splineitem.cpp
1 /***************************************************************************
2  *   Copyright (C) 2011 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 #include "splineitem.h"
20 #include "bpointitem.h"
21
22 #include <QGraphicsScene>
23
24 SplineItem::SplineItem(const QList< BPoint >& points, QGraphicsItem* parent, QGraphicsScene *scene) :
25     QGraphicsPathItem(parent, scene)
26 {
27     QPen framepen(Qt::SolidLine);
28     framepen.setColor(Qt::yellow);
29     setPen(framepen);
30     setBrush(Qt::NoBrush);
31
32     if (points.isEmpty())
33         return;
34
35     QPainterPath path(points.at(0).p);
36     int j;
37     for (int i = 0; i < points.count(); ++i) {
38         new BPointItem(points.at(i), this);
39         j = (i + 1) % points.count();
40         path.cubicTo(points.at(i).h2, points.at(j).h1, points.at(j).p);
41     }
42     setPath(path);
43 }
44
45 int SplineItem::type() const
46 {
47     return Type;
48 }
49
50 void SplineItem::updateSpline()
51 {
52     QPainterPath path(qgraphicsitem_cast<BPointItem *>(childItems().at(0))->getPoint().p);
53
54     BPoint p1, p2;
55     int j;
56     for (int i = 0; i < childItems().count(); ++i) {
57         j = (i + 1) % childItems().count();
58         p1 = qgraphicsitem_cast<BPointItem *>(childItems().at(i))->getPoint();
59         p2 = qgraphicsitem_cast<BPointItem *>(childItems().at(j))->getPoint();
60         path.cubicTo(p1.h2, p2.h1, p2.p);
61     }
62     setPath(path);
63
64     emit changed();
65 }
66
67 QList <BPoint> SplineItem::getPoints()
68 {
69     QList <BPoint> points;
70     foreach (QGraphicsItem *child, childItems())
71         points << qgraphicsitem_cast<BPointItem *>(child)->getPoint();
72     return points;
73 }
74
75 #include "splineitem.moc"