]> git.sesse.net Git - kdenlive/blobdiff - src/geometryval.cpp
[PATCH by Ray Lehtiniemi] Do not return references to temporaries.
[kdenlive] / src / geometryval.cpp
index 65ddfe564a51179d5fdf607c21f1671821dc125e..a42d96d1d4a317d143948cd23b72adc1e3d4d4fe 100644 (file)
  *                                                                         *
  ***************************************************************************/
 
+#include "geometryval.h"
+#include "graphicsscenerectmove.h"
+#include "kdenlivesettings.h"
 
+#include <KDebug>
 
 #include <QGraphicsView>
 #include <QVBoxLayout>
-#include <QGraphicsScene>
 #include <QGraphicsRectItem>
-#include <QMouseEvent>
 #include <QMenu>
 
-#include <KDebug>
 
-#include "graphicsscenerectmove.h"
-#include "geometryval.h"
-#include "kdenlivesettings.h"
-
-Geometryval::Geometryval(const MltVideoProfile profile, QWidget* parent): QWidget(parent), m_profile(profile), m_geom(NULL), m_path(NULL), paramRect(NULL) {
+Geometryval::Geometryval(const MltVideoProfile profile, QWidget* parent): QWidget(parent), m_profile(profile), m_geom(NULL), m_path(NULL), paramRect(NULL), m_fixedMode(false) {
     ui.setupUi(this);
     QVBoxLayout* vbox = new QVBoxLayout(ui.widget);
     QGraphicsView *view = new QGraphicsView(this);
@@ -96,7 +93,7 @@ Geometryval::Geometryval(const MltVideoProfile profile, QWidget* parent): QWidge
     //view->fitInView(m_frameBorder, Qt::KeepAspectRatio);
     const double sc = 100.0 / profile.height * 0.8;
     QRectF srect = view->sceneRect();
-    view->setSceneRect(srect.x(), -srect.height() / 3, srect.width(), srect.height() + srect.height() / 3 * 2);
+    view->setSceneRect(srect.x(), -srect.height() / 3 + 10, srect.width(), srect.height() + srect.height() / 3 * 2 - 10);
     scene->setZoom(sc);
     view->centerOn(m_frameBorder);
     connect(ui.buttonNext , SIGNAL(clicked()) , this , SLOT(slotNextFrame()));
@@ -273,6 +270,15 @@ void Geometryval::slotPositionChanged(int pos, bool seek) {
 }
 
 void Geometryval::slotDeleteFrame() {
+    // check there is more than one keyframe
+    Mlt::GeometryItem item;
+    const int pos = ui.spinPos->value();
+    int error = m_geom->next_key(&item, pos + 1);
+    if (error) {
+        error = m_geom->prev_key(&item, pos - 1);
+        if (error || item.frame() == pos) return;
+    }
+
     m_geom->remove(ui.spinPos->value());
     ui.buttonAdd->setEnabled(true);
     ui.buttonDelete->setEnabled(false);
@@ -281,6 +287,9 @@ void Geometryval::slotDeleteFrame() {
     m_scaleMenu->setEnabled(false);
     m_alignMenu->setEnabled(false);
     m_helper->update();
+    slotPositionChanged(pos, false);
+    updateTransitionPath();
+    emit parameterChanged();
 }
 
 void Geometryval::slotAddFrame() {
@@ -300,13 +309,18 @@ void Geometryval::slotAddFrame() {
     m_scaleMenu->setEnabled(true);
     m_alignMenu->setEnabled(true);
     m_helper->update();
+    emit parameterChanged();
 }
 
 void Geometryval::slotNextFrame() {
     Mlt::GeometryItem item;
     int error = m_geom->next_key(&item, m_helper->value() + 1);
     kDebug() << "// SEEK TO NEXT KFR: " << error;
-    if (error) return;
+    if (error) {
+        // Go to end
+        ui.spinPos->setValue(ui.spinPos->maximum());
+        return;
+    }
     int pos = item.frame();
     ui.spinPos->setValue(pos);
 }
@@ -330,25 +344,39 @@ QDomElement Geometryval::getParamDesc() {
 void Geometryval::setupParam(const QDomElement& par, int minFrame, int maxFrame) {
     param = par;
     QString val = par.attribute("value");
+    if (par.attribute("fixed") == "1") {
+        m_fixedMode = true;
+        ui.buttonPrevious->setHidden(true);
+        ui.buttonNext->setHidden(true);
+        ui.buttonDelete->setHidden(true);
+        ui.buttonAdd->setHidden(true);
+        ui.spinTransp->setMaximum(500);
+        ui.label_pos->setHidden(true);
+        m_helper->setHidden(true);
+        ui.spinPos->setHidden(true);
+    }
     char *tmp = (char *) qstrdup(val.toUtf8().data());
     if (m_geom) m_geom->parse(tmp, maxFrame - minFrame, m_profile.width, m_profile.height);
     else m_geom = new Mlt::Geometry(tmp, maxFrame - minFrame, m_profile.width, m_profile.height);
     delete[] tmp;
+
     //kDebug() << " / / UPDATING TRANSITION VALUE: " << m_geom->serialise();
     //read param her and set rect
-    m_helper->setKeyGeometry(m_geom, maxFrame - minFrame - 1);
-    m_helper->update();
-    /*QDomDocument doc;
-    doc.appendChild(doc.importNode(par, true));
-    kDebug() << "IMPORTED TRANS: " << doc.toString();*/
-    ui.spinPos->setMaximum(maxFrame - minFrame - 1);
-    Mlt::GeometryItem item;
-    if (m_path == NULL) {
-        m_path = new QGraphicsPathItem();
-        m_path->setPen(QPen(Qt::red));
-        scene->addItem(m_path);
+    if (!m_fixedMode) {
+        m_helper->setKeyGeometry(m_geom, maxFrame - minFrame - 1);
+        m_helper->update();
+        /*QDomDocument doc;
+        doc.appendChild(doc.importNode(par, true));
+        kDebug() << "IMPORTED TRANS: " << doc.toString();*/
+        ui.spinPos->setMaximum(maxFrame - minFrame - 1);
+        if (m_path == NULL) {
+            m_path = new QGraphicsPathItem();
+            m_path->setPen(QPen(Qt::red));
+            scene->addItem(m_path);
+        }
+        updateTransitionPath();
     }
-    updateTransitionPath();
+    Mlt::GeometryItem item;
 
     m_geom->fetch(&item, 0);
     if (paramRect) delete paramRect;
@@ -359,11 +387,14 @@ void Geometryval::setupParam(const QDomElement& par, int minFrame, int maxFrame)
     paramRect->setPen(QPen(QBrush(QColor(255, 0, 0, 255)), 1.0));
     scene->addItem(paramRect);
     slotPositionChanged(0, false);
-    connect(ui.spinPos, SIGNAL(valueChanged(int)), this , SLOT(slotPositionChanged(int)));
+    if (!m_fixedMode) {
+        connect(ui.spinPos, SIGNAL(valueChanged(int)), this , SLOT(slotPositionChanged(int)));
+    }
     connect(ui.spinTransp, SIGNAL(valueChanged(int)), this , SLOT(slotTransparencyChanged(int)));
 }
 
 void Geometryval::updateTransitionPath() {
+    if (m_fixedMode) return;
     Mlt::GeometryItem item;
     int pos = 0;
     int counter = 0;