]> git.sesse.net Git - kdenlive/blobdiff - src/keyframeedit.cpp
Captured files should go to project folder if wanted:
[kdenlive] / src / keyframeedit.cpp
index 71f9dde1409f5a343923a12f8f054ddaa0e2a8cf..69d93776c5b8cfa785fd7a9c844f9954dc6385cf 100644 (file)
@@ -16,6 +16,7 @@
  ***************************************************************************/
 
 #include "keyframeedit.h"
+#include "doubleparameterwidget.h"
 #include "kdenlivesettings.h"
 
 #include <KDebug>
@@ -23,7 +24,6 @@
 
 #include <QHeaderView>
 
-
 KeyframeEdit::KeyframeEdit(QDomElement e, int minFrame, int maxFrame, int minVal, int maxVal, Timecode tc, int active_keyframe, QWidget* parent) :
         QWidget(parent),
         m_min(minFrame),
@@ -36,6 +36,14 @@ KeyframeEdit::KeyframeEdit(QDomElement e, int minFrame, int maxFrame, int minVal
 {
     kDebug() << " / / / /MODIFIED KFR: " << m_active_keyframe;
     setupUi(this);
+    if (m_max == -1) {
+        // special case: keyframe for tracks, do not allow keyframes
+        button_add->setEnabled(false);
+        button_delete->setEnabled(false);
+        keyframe_seek->setEnabled(false);
+        label->setHidden(true);
+        keyframe_pos->setHidden(true);
+    }
     m_params.append(e.cloneNode().toElement());
     keyframe_list->setFont(KGlobalSettings::generalFont());
     keyframe_seek->setChecked(KdenliveSettings::keyframeseek());
@@ -62,6 +70,8 @@ KeyframeEdit::KeyframeEdit(QDomElement e, int minFrame, int maxFrame, int minVal
         keyframe_list->setCurrentCell(0, 0);
         keyframe_list->selectRow(0);
     }
+    // ensure the keyframe list shows at least 3 lines
+    keyframe_list->setMinimumHeight(QFontInfo(keyframe_list->font()).pixelSize() * 9);
     /*m_delegate = new KeyItemDelegate(minVal, maxVal);
     keyframe_list->setItemDelegate(m_delegate);*/
 }
@@ -89,11 +99,12 @@ void KeyframeEdit::addParameter(QDomElement e)
     int columnId = keyframe_list->columnCount();
     keyframe_list->insertColumn(columnId);
     keyframe_list->setHorizontalHeaderItem(columnId, new QTableWidgetItem(paramName));
-    m_slidersLayout->addWidget(new QLabel(paramName), columnId, 0);
-    QSlider *sl = new QSlider(Qt::Horizontal, this);
-    sl->setRange(m_params.at(columnId).attribute("min").toInt(), m_params.at(columnId).attribute("max").toInt());
-    connect(sl, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustKeyframeValue(int)));
-    m_slidersLayout->addWidget(sl, columnId, 1);
+
+    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);
+    connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustKeyframeValue(int)));
+    m_slidersLayout->addWidget(doubleparam, columnId, 0);
 
     QStringList frames = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
     for (int i = 0; i < frames.count(); i++) {
@@ -132,17 +143,19 @@ void KeyframeEdit::setupParam()
     kDebug() << " INSERT COL: " << col << ", " << paramName;
     keyframe_list->insertColumn(col);
     keyframe_list->setHorizontalHeaderItem(col, new QTableWidgetItem(paramName));
-    m_slidersLayout = new QGridLayout;
-    m_slidersLayout->addWidget(new QLabel(paramName), 0, 0);
-    QSlider *sl = new QSlider(Qt::Horizontal, this);
-    sl->setRange(m_params.at(0).attribute("min").toInt(), m_params.at(0).attribute("max").toInt());
-    connect(sl, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustKeyframeValue(int)));
-    m_slidersLayout->addWidget(sl, 0, 1);
-    param_sliders->setLayout(m_slidersLayout);
+    m_slidersLayout = new QGridLayout(param_sliders);
+
+    DoubleParameterWidget *doubleparam = new DoubleParameterWidget(paramName, 0,
+            m_params.at(0).attribute("min").toInt(), m_params.at(0).attribute("max").toInt(),
+            m_params.at(0).attribute("default").toInt(), m_params.at(0).attribute("suffix"), this);
+    connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustKeyframeValue(int)));
+    m_slidersLayout->addWidget(doubleparam, 0, 0);
+
     keyframe_list->setSelectionBehavior(QAbstractItemView::SelectRows);
     keyframe_list->setSelectionMode(QAbstractItemView::SingleSelection);
 
     QStringList frames = m_params.at(0).attribute("keyframes").split(";", QString::SkipEmptyParts);
+    setEnabled(frames.count() > 0);
     for (int i = 0; i < frames.count(); i++) {
         keyframe_list->insertRow(i);
         int currentpos = frames.at(i).section(':', 0, 0).toInt();
@@ -229,7 +242,7 @@ void KeyframeEdit::slotGenerateParams(int row, int column)
         int pos = getPos(row);
         if (pos <= m_min)
             pos = m_min;
-        if (pos > m_max)
+        if (m_max != -1 && pos > m_max)
             pos = m_max;
         QString val = getPosString(pos);
         if (val != keyframe_list->verticalHeaderItem(row)->text())
@@ -261,7 +274,7 @@ void KeyframeEdit::slotGenerateParams(int row, int column)
     int pos = getPos(row);
     if (pos <= m_min)
         pos = m_min;
-    if (pos > m_max)
+    if (m_max != -1 && pos > m_max)
         pos = m_max;
     /*QList<QTreeWidgetItem *> duplicates = keyframe_list->findItems(val, Qt::MatchExactly, 0);
     duplicates.removeAll(item);
@@ -307,7 +320,7 @@ const QString KeyframeEdit::getValue(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());
-        kDebug() << paramName << " == " << name;
+        //kDebug() << paramName << " == " << name;
         if (paramName == name)
             return m_params.at(col).attribute("keyframes");
     }
@@ -333,12 +346,16 @@ void KeyframeEdit::slotAdjustKeyframeInfo(bool seek)
     keyframe_pos->setValue(getPos(item->row()));
     keyframe_pos->blockSignals(false);
     for (int col = 0; col < keyframe_list->columnCount(); col++) {
-        QSlider *sl = static_cast <QSlider*>(m_slidersLayout->itemAtPosition(col, 1)->widget());
-        if (!sl)
+        DoubleParameterWidget *doubleparam = static_cast <DoubleParameterWidget*>(m_slidersLayout->itemAtPosition(col, 0)->widget());
+        if (!doubleparam)
             continue;
-        sl->blockSignals(true);
-        sl->setValue(keyframe_list->item(item->row(), col)->text().toInt());
-        sl->blockSignals(false);
+        doubleparam->blockSignals(true);
+        if (keyframe_list->item(item->row(), col)) {
+            doubleparam->setValue(keyframe_list->item(item->row(), col)->text().toInt());
+        } else {
+            kDebug() << "Null pointer exception caught: http://www.kdenlive.org/mantis/view.php?id=1771";
+        }
+        doubleparam->blockSignals(false);
     }
     if (KdenliveSettings::keyframeseek() && seek)
         emit seekToPos(keyframe_pos->value() - m_min);
@@ -357,10 +374,10 @@ void KeyframeEdit::slotAdjustKeyframeValue(int /*value*/)
 {
     QTableWidgetItem *item = keyframe_list->currentItem();
     for (int col = 0; col < keyframe_list->columnCount(); col++) {
-        QSlider *sl = static_cast <QSlider*>(m_slidersLayout->itemAtPosition(col, 1)->widget());
-        if (!sl)
+        DoubleParameterWidget *doubleparam = static_cast <DoubleParameterWidget*>(m_slidersLayout->itemAtPosition(col, 0)->widget());
+        if (!doubleparam)
             continue;
-        int val = sl->value();
+        int val = doubleparam->getValue();
         QTableWidgetItem *nitem = keyframe_list->item(item->row(), col);
         if (nitem->text().toInt() != val)
             nitem->setText(QString::number(val));