]> git.sesse.net Git - kdenlive/blob - src/geometryval.cpp
First steps to a working composite transition
[kdenlive] / src / geometryval.cpp
1 /***************************************************************************
2                           geomeytrval.cpp  -  description
3                              -------------------
4     begin                : 03 Aug 2008
5     copyright            : (C) 2008 by Marco Gittler
6     email                : g.marco@freenet.de
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18
19
20 #include <QGraphicsView>
21 #include <QVBoxLayout>
22 #include <QGraphicsScene>
23 #include "graphicsscenerectmove.h"
24 #include <QGraphicsRectItem>
25 #include <QMouseEvent>
26 #include <KDebug>
27
28 #include "geometryval.h"
29
30 Geometryval::Geometryval(const MltVideoProfile profile, QWidget* parent): QWidget(parent), m_profile(profile) {
31     ui.setupUi(this);
32     QVBoxLayout* vbox = new QVBoxLayout(ui.widget);
33     QGraphicsView *view = new QGraphicsView(this);
34     view->setBackgroundBrush(QBrush(Qt::black));
35     vbox->addWidget(view);
36     vbox->setContentsMargins(0, 0, 0, 0);
37
38     QVBoxLayout* vbox2 = new QVBoxLayout(ui.keyframeWidget);
39     m_helper = new KeyframeHelper(this);
40     vbox2->addWidget(m_helper);
41     vbox2->setContentsMargins(0, 0, 0, 0);
42
43     scene = new GraphicsSceneRectMove(this);
44     scene->setTool(TITLE_SELECT);
45     view->setScene(scene);
46     double aspect = (double) profile.sample_aspect_num / profile.sample_aspect_den * profile.width / profile.height;
47     QGraphicsRectItem *m_frameBorder = new QGraphicsRectItem(QRectF(0, 0, profile.width, profile.height));
48     m_frameBorder->setZValue(-1100);
49     m_frameBorder->setBrush(QColor(255, 255, 0, 30));
50     m_frameBorder->setPen(QPen(QBrush(QColor(255, 255, 255, 255)), 1.0, Qt::DashLine));
51     scene->addItem(m_frameBorder);
52
53     //scene->setSceneRect(-100.0*aspect, -100, 300.0*aspect, 300);
54     //view->fitInView(m_frameBorder, Qt::KeepAspectRatio);
55     const double sc = 100.0 / profile.height;
56     view->scale(sc, sc);
57     view->centerOn(m_frameBorder);
58     connect(scene , SIGNAL(itemMoved()) , this , SLOT(moveEvent()));
59     connect(ui.buttonNext , SIGNAL(clicked()) , this , SLOT(slotNextFrame()));
60     connect(ui.buttonPrevious , SIGNAL(clicked()) , this , SLOT(slotPreviousFrame()));
61 }
62
63 void Geometryval::slotNextFrame() {
64     Mlt::GeometryItem item;
65     m_geom->next_key(&item, ui.keyframeSlider->value() + 1);
66     int pos = item.frame();
67     ui.keyframeSlider->setValue(pos);
68 }
69
70 void Geometryval::slotPreviousFrame() {
71     Mlt::GeometryItem item;
72     m_geom->prev_key(&item, ui.keyframeSlider->value() - 1);
73     int pos = item.frame();
74     ui.keyframeSlider->setValue(pos);
75 }
76
77 void Geometryval::moveEvent() {
78     //if (event->button())
79
80     QDomNodeList namenode = param.elementsByTagName("parameter");
81     QDomNode pa = namenode.item(0);
82     QRectF rec = paramRect->rect().translated(paramRect->pos());
83     pa.attributes().namedItem("value").setNodeValue(
84         QString("%1;%2;%3;%4;%5").arg(
85             (int)rec.x()).arg(
86             (int)rec.y()).arg(
87             (int)(rec.x() + rec.width())).arg(
88             (int)(rec.y() + rec.height())).arg(
89             "100"
90         )
91     );
92     //pa.attributes().namedItem("start").setNodeValue("50");
93     QString dat;
94     QTextStream stre(&dat);
95     param.save(stre, 2);
96     kDebug() << dat;
97     emit parameterChanged();
98 }
99
100 QDomElement Geometryval::getParamDesc() {
101     return param;
102 }
103
104 void Geometryval::setupParam(const QDomElement& par, int minFrame, int maxFrame) {
105     param = par;
106     QString val = par.attribute("value");
107     char *tmp = (char *) qstrdup(val.toUtf8().data());
108     m_geom = new Mlt::Geometry(tmp, val.count(';') + 1, m_profile.width, m_profile.height);
109     delete[] tmp;
110     //read param her and set rect
111     ui.keyframeSlider->setRange(0, maxFrame - minFrame);
112     m_helper->setKeyGeometry(m_geom, maxFrame - minFrame);
113     QDomDocument doc;
114     doc.appendChild(doc.importNode(par, true));
115     kDebug() << "IMPORTED TRANS: " << doc.toString();
116
117     Mlt::GeometryItem item;
118     m_geom->fetch(&item, 0);
119     paramRect = new QGraphicsRectItem(QRectF(0, 0, item.w(), item.h()));
120     paramRect->setPos(item.x(), item.y());
121     paramRect->setZValue(0);
122
123     paramRect->setBrush(QColor(255, 0, 0, 40));
124     paramRect->setPen(QPen(QBrush(QColor(255, 0, 0, 255)), 1.0));
125     scene->addItem(paramRect);
126 }