1 /***************************************************************************
2 * Copyright (C) 2011 by Till Theato (root@ttill.de) *
3 * This file is part of Kdenlive (www.kdenlive.org). *
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. *
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. *
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 ***************************************************************************/
19 #include "rotowidget.h"
22 #include "monitorscene.h"
23 #include "monitoreditwidget.h"
24 #include "onmonitoritems/rotoscoping/bpointitem.h"
25 #include "onmonitoritems/rotoscoping/splineitem.h"
27 #include <qjson/parser.h>
28 #include <qjson/serializer.h>
31 RotoWidget::RotoWidget(QString data, Monitor *monitor, int in, int out, QWidget* parent) :
39 MonitorEditWidget *edit = monitor->getEffectEdit();
40 edit->showVisibilityButton(true);
41 m_scene = edit->getScene();
45 m_data = parser.parse(data.toUtf8(), &ok);
50 int width = m_monitor->render->frameRenderWidth();
51 int height = m_monitor->render->renderHeight();
52 QList <BPoint> points;
53 foreach (const QVariant &bpoint, m_data.toList()) {
54 QList <QVariant> l = bpoint.toList();
56 p.h1 = QPointF(l.at(0).toList().at(0).toDouble() * width, l.at(0).toList().at(1).toDouble() * height);
57 p.p = QPointF(l.at(1).toList().at(0).toDouble() * width, l.at(1).toList().at(1).toDouble() * height);
58 p.h2 = QPointF(l.at(2).toList().at(0).toDouble() * width, l.at(2).toList().at(1).toDouble() * height);
62 m_item = new SplineItem(points, NULL, m_scene);
64 connect(m_item, SIGNAL(changed()), this, SLOT(slotUpdateData()));
65 connect(edit, SIGNAL(showEdit(bool)), this, SLOT(slotShowScene(bool)));
66 connect(m_monitor, SIGNAL(renderPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
69 RotoWidget::~RotoWidget()
71 m_scene->removeItem(m_item);
75 MonitorEditWidget *edit = m_monitor->getEffectEdit();
76 edit->showVisibilityButton(false);
77 edit->removeCustomControls();
78 m_monitor->slotEffectScene(false);
82 void RotoWidget::slotCheckMonitorPosition(int renderPos)
85 emit checkMonitorPosition(renderPos);
88 void RotoWidget::slotSyncPosition(int relTimelinePos)
90 Q_UNUSED(relTimelinePos);
93 void RotoWidget::slotShowScene(bool show)
97 m_monitor->slotEffectScene(false);
99 slotCheckMonitorPosition(m_monitor->render->seekFramePosition());
102 void RotoWidget::slotUpdateData()
104 int width = m_monitor->render->frameRenderWidth();
105 int height = m_monitor->render->renderHeight();
107 QList <BPoint> spline = m_item->getPoints();
108 QList <QVariant> vlist;
109 foreach (const BPoint &point, spline) {
111 for (int i = 0; i < 3; ++i)
112 pl << QVariant(QList <QVariant>() << QVariant(point[i].x() / width) << QVariant(point[i].y() / height));
113 vlist << QVariant(pl);
115 m_data = QVariant(vlist);
120 QString RotoWidget::getSpline()
122 QJson::Serializer serializer;
123 return QString(serializer.serialize(m_data));
126 #include "rotowidget.moc"