]> git.sesse.net Git - kdenlive/blobdiff - src/keyframeedit.cpp
Allow to select between timecode (hh:mm:ss:ff) and frame count overlay when rendering
[kdenlive] / src / keyframeedit.cpp
index 5354a2429febbe6e5abf30637a30f5a6d165be15..f502b69c07d873e10ea204b75f45a0ef2a0373af 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
-                          geomeytrval.cpp  -  description
+                          keyframedit.cpp  -  description
                              -------------------
     begin                : 03 Aug 2008
     copyright            : (C) 2008 by Marco Gittler
@@ -17,6 +17,7 @@
 
 #include "keyframeedit.h"
 #include "doubleparameterwidget.h"
+#include "positionedit.h"
 #include "kdenlivesettings.h"
 
 #include <KDebug>
@@ -39,7 +40,7 @@ KeyframeEdit::KeyframeEdit(QDomElement e, int minFrame, int maxFrame, Timecode t
     buttonSeek->setChecked(KdenliveSettings::keyframeseek());
     connect(buttonSeek, SIGNAL(toggled(bool)), this, SLOT(slotSetSeeking(bool)));
 
-    buttonKeyframes->setIcon(KIcon("list-add"));
+    buttonKeyframes->setIcon(KIcon("chronometer"));
     button_add->setIcon(KIcon("list-add"));
     button_add->setToolTip(i18n("Add keyframe"));
     button_delete->setIcon(KIcon("list-remove"));
@@ -49,7 +50,14 @@ KeyframeEdit::KeyframeEdit(QDomElement e, int minFrame, int maxFrame, Timecode t
     connect(keyframe_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotAdjustKeyframeInfo()));
     connect(keyframe_list, SIGNAL(cellChanged(int, int)), this, SLOT(slotGenerateParams(int, int)));
 
+    m_position = new PositionEdit(i18n("Position"), 0, 0, 1, tc, widgetTable);
+    ((QGridLayout*)widgetTable->layout())->addWidget(m_position, 3, 0, 1, -1);
+
     m_slidersLayout = new QGridLayout(param_sliders);
+    //m_slidersLayout->setSpacing(0);
+    
+    m_slidersLayout->setContentsMargins(0, 0, 0, 0);
+    m_slidersLayout->setVerticalSpacing(2);
     keyframe_list->setSelectionBehavior(QAbstractItemView::SelectRows);
     keyframe_list->setSelectionMode(QAbstractItemView::SingleSelection);
     addParameter(e, activeKeyframe);
@@ -60,11 +68,10 @@ KeyframeEdit::KeyframeEdit(QDomElement e, int minFrame, int maxFrame, Timecode t
     connect(button_add, SIGNAL(clicked()), this, SLOT(slotAddKeyframe()));
     connect(buttonKeyframes, SIGNAL(clicked()), this, SLOT(slotKeyframeMode()));
     connect(buttonResetKeyframe, SIGNAL(clicked()), this, SLOT(slotResetKeyframe()));
-    connect(keyframe_pos, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustKeyframePos(int)));
+    connect(m_position, SIGNAL(parameterChanged(int)), this, SLOT(slotAdjustKeyframePos(int)));
 
     //connect(keyframe_list, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotSaveCurrentParam(QTreeWidgetItem *, int)));
 
-    keyframe_pos->setPageStep(1);
     if (!keyframe_list->currentItem()) {
         keyframe_list->setCurrentCell(0, 0);
         keyframe_list->selectRow(0);
@@ -96,17 +103,28 @@ void KeyframeEdit::addParameter(QDomElement e, int activeKeyframe)
 {
     keyframe_list->blockSignals(true);
     m_params.append(e.cloneNode().toElement());
-    QDomNode na = e.firstChildElement("name");
-    QString paramName = i18n(na.toElement().text().toUtf8().data());
+
+    QDomElement na = e.firstChildElement("name");
+    QString paramName = i18n(na.text().toUtf8().data());
+    QDomElement commentElem = e.firstChildElement("comment");
+    QString comment;
+    if (!commentElem.isNull())
+        comment = i18n(commentElem.text().toUtf8().data());
+    
     int columnId = keyframe_list->columnCount();
     keyframe_list->insertColumn(columnId);
     keyframe_list->setHorizontalHeaderItem(columnId, new QTableWidgetItem(paramName));
 
     DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, 0,
             m_params.at(columnId).attribute("min").toInt(), m_params.at(columnId).attribute("max").toInt(),
-            m_params.at(columnId).attribute("default").toInt(), m_params.at(columnId).attribute("suffix"), this);
+            m_params.at(columnId).attribute("default").toInt(), comment, columnId, m_params.at(columnId).attribute("suffix"), this);
     connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustKeyframeValue(int)));
+    connect(this, SIGNAL(showComments(bool)), doubleparam, SLOT(slotShowComment(bool)));
+    connect(doubleparam, SIGNAL(setInTimeline(int)), this, SLOT(slotUpdateVisibleParameter(int)));
     m_slidersLayout->addWidget(doubleparam, columnId, 0);
+    if (e.attribute("intimeline") == "1") {
+        doubleparam->setInTimelineProperty(true);
+    }
 
     QStringList frames = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
     for (int i = 0; i < frames.count(); i++) {
@@ -151,7 +169,12 @@ void KeyframeEdit::slotDeleteKeyframe()
     keyframe_list->setCurrentCell(row, col);
     keyframe_list->selectRow(row);
     generateAllParams();
-    button_delete->setEnabled(keyframe_list->rowCount() > 1);
+
+    bool disable = keyframe_list->rowCount() < 2;
+    button_delete->setEnabled(!disable);
+    disable &= getPos(0) == m_min;
+    widgetTable->setHidden(disable);
+    buttonKeyframes->setHidden(!disable);
 }
 
 void KeyframeEdit::slotAddKeyframe()
@@ -175,8 +198,14 @@ void KeyframeEdit::slotAddKeyframe()
             result = m_min;
         }
     } else {
-        int pos2 = getPos(row - 1);
-        result = pos2 + (pos1 - pos2) / 2;
+        if (pos1 < m_max - 1) {
+            // last keyframe selected and it is not at end of clip -> add keyframe at the end
+            result = m_max - 1;
+            newrow++;
+        } else {
+            int pos2 = getPos(row - 1);
+            result = pos2 + (pos1 - pos2) / 2;
+        }
     }
 
     keyframe_list->insertRow(newrow);
@@ -303,10 +332,11 @@ void KeyframeEdit::slotAdjustKeyframeInfo(bool seek)
     if (below)
         max = getPos(below->row()) - 1;
 
-    keyframe_pos->blockSignals(true);
-    keyframe_pos->setRange(min, max);
-    keyframe_pos->setValue(getPos(item->row()));
-    keyframe_pos->blockSignals(false);
+    m_position->blockSignals(true);
+    m_position->setRange(min, max);
+    m_position->setPosition(getPos(item->row()));
+    m_position->blockSignals(false);
+
     for (int col = 0; col < keyframe_list->columnCount(); col++) {
         DoubleParameterWidget *doubleparam = static_cast <DoubleParameterWidget*>(m_slidersLayout->itemAtPosition(col, 0)->widget());
         if (!doubleparam)
@@ -320,7 +350,7 @@ void KeyframeEdit::slotAdjustKeyframeInfo(bool seek)
         doubleparam->blockSignals(false);
     }
     if (KdenliveSettings::keyframeseek() && seek)
-        emit seekToPos(keyframe_pos->value() - m_min);
+        emit seekToPos(m_position->getPosition() - m_min);
 }
 
 void KeyframeEdit::slotAdjustKeyframePos(int value)
@@ -343,7 +373,7 @@ void KeyframeEdit::slotAdjustKeyframeValue(int value)
             continue;
         int val = doubleparam->getValue();
         QTableWidgetItem *nitem = keyframe_list->item(item->row(), col);
-        if (nitem->text().toInt() != val)
+        if (nitem && nitem->text().toInt() != val)
             nitem->setText(QString::number(val));
     }
     //keyframe_list->item(item->row() - 1, item->column());
@@ -380,6 +410,8 @@ void KeyframeEdit::updateTimecodeFormat()
         else
             keyframe_list->verticalHeaderItem(row)->setText(m_timecode.getTimecodeFromFrames(pos.toInt()));
     }
+
+    m_position->updateTimecodeFormat();
 }
 
 void KeyframeEdit::slotKeyframeMode()
@@ -398,4 +430,44 @@ void KeyframeEdit::slotResetKeyframe()
     }
 }
 
+void KeyframeEdit::slotUpdateVisibleParameter(int id, bool update)
+{
+    for (int i = 0; i < m_params.count(); ++i) {
+        m_params[i].setAttribute("intimeline", (i == id ? "1" : "0"));        
+    }
+    for (int col = 0; col < keyframe_list->columnCount(); col++) {
+        DoubleParameterWidget *doubleparam = static_cast <DoubleParameterWidget*>(m_slidersLayout->itemAtPosition(col, 0)->widget());
+        if (!doubleparam)
+            continue;
+        doubleparam->setInTimelineProperty(col == id);
+        //kDebug()<<"// PARAM: "<<col<<" Set TO: "<<(bool) (col == id);
+        
+    }
+    if (update) emit parameterChanged();
+}
+
+bool KeyframeEdit::isVisibleParam(const QString& name)
+{
+    for (int col = 0; col < keyframe_list->columnCount(); ++col) {
+        QDomNode na = m_params.at(col).firstChildElement("name");
+        QString paramName = i18n(na.toElement().text().toUtf8().data());
+        if (paramName == name)
+            return m_params.at(col).attribute("intimeline") == "1";
+    }
+    return false;
+}
+
+void KeyframeEdit::checkVisibleParam()
+{
+    if (m_params.count() == 0)
+        return;
+    
+    foreach(QDomElement elem, m_params) {
+        if (elem.attribute("intimeline") == "1")
+            return;
+    }
+
+    slotUpdateVisibleParameter(0);
+}
+
 #include "keyframeedit.moc"