X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fkeyframeedit.cpp;h=ac367215b7b24a7cbb69165db0642431fc45f708;hb=1404e8f1d631c81399e0e92ffce7dfac0195fabb;hp=cc050c181702343be318334f0081d7dc870beb14;hpb=551a8d38219bd1ccd96636b87df49264fa330c8c;p=kdenlive diff --git a/src/keyframeedit.cpp b/src/keyframeedit.cpp index cc050c18..ac367215 100644 --- a/src/keyframeedit.cpp +++ b/src/keyframeedit.cpp @@ -24,14 +24,12 @@ #include #include -#include -#include - -KeyframeEdit::KeyframeEdit(QDomElement e, int minFrame, int maxFrame, Timecode tc, int activeKeyframe, QWidget* parent) : - QWidget(parent), - m_min(minFrame), - m_max(maxFrame), - m_timecode(tc) + +KeyframeEdit::KeyframeEdit(const QDomElement &e, int minFrame, int maxFrame, const Timecode &tc, int activeKeyframe, QWidget* parent) : + QWidget(parent), + m_min(minFrame), + m_max(maxFrame), + m_timecode(tc) { setupUi(this); if (m_max == -1) { @@ -50,13 +48,16 @@ KeyframeEdit::KeyframeEdit(QDomElement e, int minFrame, int maxFrame, Timecode t buttonResetKeyframe->setIcon(KIcon("edit-undo")); buttonSeek->setIcon(KIcon("insert-link")); connect(keyframe_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotAdjustKeyframeInfo())); - connect(keyframe_list, SIGNAL(cellChanged(int, int)), this, SLOT(slotGenerateParams(int, int))); + 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_showButtons = new QButtonGroup(this); 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); @@ -68,9 +69,8 @@ KeyframeEdit::KeyframeEdit(QDomElement e, int minFrame, int maxFrame, Timecode t connect(buttonKeyframes, SIGNAL(clicked()), this, SLOT(slotKeyframeMode())); connect(buttonResetKeyframe, SIGNAL(clicked()), this, SLOT(slotResetKeyframe())); connect(m_position, SIGNAL(parameterChanged(int)), this, SLOT(slotAdjustKeyframePos(int))); - connect(m_showButtons, SIGNAL(buttonClicked(int)), this, SLOT(slotUpdateVisibleParameter(int))); - //connect(keyframe_list, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(slotSaveCurrentParam(QTreeWidgetItem *, int))); + //connect(keyframe_list, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(slotSaveCurrentParam(QTreeWidgetItem*,int))); if (!keyframe_list->currentItem()) { keyframe_list->setCurrentCell(0, 0); @@ -99,7 +99,7 @@ KeyframeEdit::~KeyframeEdit() } } -void KeyframeEdit::addParameter(QDomElement e, int activeKeyframe) +void KeyframeEdit::addParameter(const QDomElement &e, int activeKeyframe) { keyframe_list->blockSignals(true); m_params.append(e.cloneNode().toElement()); @@ -110,29 +110,24 @@ void KeyframeEdit::addParameter(QDomElement e, int activeKeyframe) 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(), comment, m_params.at(columnId).attribute("suffix"), this); - connect(doubleparam, SIGNAL(valueChanged(int)), this, SLOT(slotAdjustKeyframeValue(int))); - connect(this, SIGNAL(showComments()), doubleparam, SLOT(slotShowComment())); + m_params.at(columnId).attribute("min").toDouble(), m_params.at(columnId).attribute("max").toDouble(), + m_params.at(columnId).attribute("default").toDouble(), comment, columnId, m_params.at(columnId).attribute("suffix"), m_params.at(columnId).attribute("decimals").toInt(), this); + connect(doubleparam, SIGNAL(valueChanged(double)), this, SLOT(slotAdjustKeyframeValue(double))); + 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); + } - QRadioButton *radio = new QRadioButton(this); - m_showButtons->addButton(radio, columnId); - if (e.attribute("intimeline") == "1") - radio->setChecked(true); - - QVBoxLayout *radioLayout = new QVBoxLayout(this); - radioLayout->addWidget(radio, 0, Qt::AlignTop); - m_slidersLayout->addLayout(radioLayout, columnId, 1); - - QStringList frames = e.attribute("keyframes").split(";", QString::SkipEmptyParts); - for (int i = 0; i < frames.count(); i++) { + QStringList frames = e.attribute("keyframes").split(';', QString::SkipEmptyParts); + for (int i = 0; i < frames.count(); ++i) { int frame = frames.at(i).section(':', 0, 0).toInt(); bool found = false; int j; @@ -197,19 +192,25 @@ void KeyframeEdit::slotAddKeyframe() newrow++; } else if (row == 0) { if (pos1 == m_min) { - result = m_max - 1; + result = m_max; newrow++; } else { result = m_min; } } else { - int pos2 = getPos(row - 1); - result = pos2 + (pos1 - pos2) / 2; + if (pos1 < m_max) { + // last keyframe selected and it is not at end of clip -> add keyframe at the end + result = m_max; + newrow++; + } else { + int pos2 = getPos(row - 1); + result = pos2 + (pos1 - pos2) / 2; + } } keyframe_list->insertRow(newrow); keyframe_list->setVerticalHeaderItem(newrow, new QTableWidgetItem(getPosString(result))); - for (int i = 0; i < keyframe_list->columnCount(); i++) + for (int i = 0; i < keyframe_list->columnCount(); ++i) keyframe_list->setItem(newrow, i, new QTableWidgetItem(keyframe_list->item(item->row(), i)->text())); keyframe_list->resizeRowsToContents(); @@ -241,13 +242,14 @@ void KeyframeEdit::slotGenerateParams(int row, int column) for (int col = 0; col < keyframe_list->horizontalHeader()->count(); col++) { item = keyframe_list->item(row, col); + if (!item) continue; int v = item->text().toInt(); if (v >= m_params.at(col).attribute("max").toInt()) item->setText(m_params.at(col).attribute("max")); if (v <= m_params.at(col).attribute("min").toInt()) item->setText(m_params.at(col).attribute("min")); QString keyframes; - for (int i = 0; i < keyframe_list->rowCount(); i++) { + for (int i = 0; i < keyframe_list->rowCount(); ++i) { if (keyframe_list->item(i, col)) keyframes.append(QString::number(getPos(i)) + ':' + keyframe_list->item(i, col)->text() + ';'); } @@ -285,7 +287,7 @@ void KeyframeEdit::slotGenerateParams(int row, int column) slotAdjustKeyframeInfo(false); QString keyframes; - for (int i = 0; i < keyframe_list->rowCount(); i++) { + for (int i = 0; i < keyframe_list->rowCount(); ++i) { if (keyframe_list->item(i, column)) keyframes.append(QString::number(getPos(i)) + ':' + keyframe_list->item(i, column)->text() + ';'); } @@ -297,7 +299,7 @@ void KeyframeEdit::generateAllParams() { for (int col = 0; col < keyframe_list->columnCount(); col++) { QString keyframes; - for (int i = 0; i < keyframe_list->rowCount(); i++) { + for (int i = 0; i < keyframe_list->rowCount(); ++i) { if (keyframe_list->item(i, col)) keyframes.append(QString::number(getPos(i)) + ':' + keyframe_list->item(i, col)->text() + ';'); } @@ -332,7 +334,7 @@ void KeyframeEdit::slotAdjustKeyframeInfo(bool seek) max = getPos(below->row()) - 1; m_position->blockSignals(true); - m_position->setRange(min, max); + m_position->setRange(min, max, true); m_position->setPosition(getPos(item->row())); m_position->blockSignals(false); @@ -342,7 +344,7 @@ void KeyframeEdit::slotAdjustKeyframeInfo(bool seek) continue; doubleparam->blockSignals(true); if (keyframe_list->item(item->row(), col)) { - doubleparam->setValue(keyframe_list->item(item->row(), col)->text().toInt()); + doubleparam->setValue(keyframe_list->item(item->row(), col)->text().toDouble()); } else { kDebug() << "Null pointer exception caught: http://www.kdenlive.org/mantis/view.php?id=1771"; } @@ -361,18 +363,18 @@ void KeyframeEdit::slotAdjustKeyframePos(int value) emit seekToPos(value - m_min); } -void KeyframeEdit::slotAdjustKeyframeValue(int value) +void KeyframeEdit::slotAdjustKeyframeValue(double value) { - Q_UNUSED(value); + Q_UNUSED(value) QTableWidgetItem *item = keyframe_list->currentItem(); for (int col = 0; col < keyframe_list->columnCount(); col++) { DoubleParameterWidget *doubleparam = static_cast (m_slidersLayout->itemAtPosition(col, 0)->widget()); if (!doubleparam) continue; - int val = doubleparam->getValue(); + double val = doubleparam->getValue(); QTableWidgetItem *nitem = keyframe_list->item(item->row(), col); - if (nitem->text().toInt() != val) + if (nitem && nitem->text().toDouble() != val) nitem->setText(QString::number(val)); } //keyframe_list->item(item->row() - 1, item->column()); @@ -381,6 +383,8 @@ void KeyframeEdit::slotAdjustKeyframeValue(int value) int KeyframeEdit::getPos(int row) { + if (!keyframe_list->verticalHeaderItem(row)) + return 0; if (KdenliveSettings::frametimecode()) return keyframe_list->verticalHeaderItem(row)->text().toInt(); else @@ -431,8 +435,17 @@ void KeyframeEdit::slotResetKeyframe() void KeyframeEdit::slotUpdateVisibleParameter(int id, bool update) { - for (int i = 0; i < m_params.count(); ++i) + 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 (m_slidersLayout->itemAtPosition(col, 0)->widget()); + if (!doubleparam) + continue; + doubleparam->setInTimelineProperty(col == id); + //kDebug()<<"// PARAM: "<(m_slidersLayout->itemAtPosition(0, 1)->widget()); - if (radio) - radio->setChecked(true); + slotUpdateVisibleParameter(0); +} + +void KeyframeEdit::slotUpdateRange(int inPoint, int outPoint) +{ + m_min = inPoint; + m_max = outPoint; } #include "keyframeedit.moc"