From: Till Theato Date: Sun, 23 Jan 2011 12:03:19 +0000 (+0000) Subject: corners: Add keyframe by double-clicking on the monitor X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=f0b79f72db2da2ae5e042bc10b201ef155e7a425;p=kdenlive corners: Add keyframe by double-clicking on the monitor svn path=/trunk/kdenlive/; revision=5345 --- diff --git a/src/cornerswidget.cpp b/src/cornerswidget.cpp index 86a2dd20..8eb1e07c 100644 --- a/src/cornerswidget.cpp +++ b/src/cornerswidget.cpp @@ -30,6 +30,11 @@ #include +inline int lerp( const int a, const int b, double t ) +{ + return a + (b - a) * t; +} + CornersWidget::CornersWidget(Monitor *monitor, QDomElement e, int minFrame, int maxFrame, Timecode tc, int activeKeyframe, QWidget* parent) : KeyframeEdit(e, minFrame, maxFrame, tc, activeKeyframe, parent), m_monitor(monitor), @@ -65,6 +70,7 @@ CornersWidget::CornersWidget(Monitor *monitor, QDomElement e, int minFrame, int connect(m_config, SIGNAL(showScene(bool)), this, SLOT(slotShowScene(bool))); connect(m_monitor, SIGNAL(renderPosition(int)), this, SLOT(slotCheckMonitorPosition(int))); connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateProperties())); + connect(m_scene, SIGNAL(addKeyframe()), this, SLOT(slotInsertKeyframe())); connect(keyframe_list, SIGNAL(cellChanged(int, int)), this, SLOT(slotUpdateItem())); } @@ -119,7 +125,9 @@ void CornersWidget::slotUpdateItem() m_item->setPolygon(QPolygonF() << points.at(0) << points.at(1) << points.at(2) << points.at(3)); m_scene->blockSignals(false); - m_item->setEnabled(getPos(keyframe->row()) == m_pos || keyframe_list->rowCount() == 1); + bool enable = getPos(keyframe->row()) == m_pos || keyframe_list->rowCount() == 1; + m_item->setEnabled(enable); + m_scene->setEnabled(enable); } void CornersWidget::slotUpdateProperties() @@ -204,4 +212,57 @@ void CornersWidget::slotSyncPosition(int relTimelinePos) } } +void CornersWidget::slotInsertKeyframe() +{ + keyframe_list->blockSignals(true); + + int row; + QTableWidgetItem *keyframe, *keyframeOld; + keyframe = keyframe_list->item(0, 0); + for (row = 0; row < keyframe_list->rowCount(); ++row) { + keyframeOld = keyframe; + keyframe = keyframe_list->item(row, 0); + if (getPos(row) >= m_pos) + break; + } + + int pos2 = getPos(row); + if (pos2 == m_pos) + return; + + int pos1 = 0; + if (row > 0) + pos1 = getPos(row - 1); + + int col = keyframe_list->currentColumn(); + double pos = (m_pos - pos1) / (double)(pos2 - pos1 + 1); + + keyframe_list->insertRow(row); + keyframe_list->setVerticalHeaderItem(row, new QTableWidgetItem(getPosString(m_pos))); + + QPolygonF pol = m_item->polygon(); + double val; + for (int i = 0; i < keyframe_list->columnCount(); i++) { + if (i < 8) { + if (i % 2 == 0) + val = pol.at(i / 2).x() / (double)m_monitor->render->frameRenderWidth(); + else + val = pol.at(i / 2).y() / (double)m_monitor->render->renderHeight(); + val *= 2000; + val += 2000; + keyframe_list->setItem(row, i, new QTableWidgetItem(QString::number((int)val))); + } else { + keyframe_list->setItem(row, i, new QTableWidgetItem(QString::number(lerp(keyframe_list->item(keyframeOld->row(), i)->text().toInt(), keyframe_list->item(keyframe->row(), i)->text().toInt(), pos)))); + } + } + + keyframe_list->resizeRowsToContents(); + slotAdjustKeyframeInfo(); + keyframe_list->blockSignals(false); + generateAllParams(); + button_delete->setEnabled(true); + keyframe_list->setCurrentCell(row, col); + keyframe_list->selectRow(row); +} + #include "cornerswidget.moc" diff --git a/src/cornerswidget.h b/src/cornerswidget.h index 35f8638f..6f13846c 100644 --- a/src/cornerswidget.h +++ b/src/cornerswidget.h @@ -73,6 +73,9 @@ private slots: /** @brief Updates the keyframe editor according to the on-monitor item. */ void slotUpdateProperties(); + /** @brief Inserts a keyframe at the current (playback) position (m_pos). */ + void slotInsertKeyframe(); + /** @brief Shows/Hides the lines connecting the corners in the on-monitor item according to @param show. */ void slotShowLines(bool show = true); diff --git a/src/keyframeedit.h b/src/keyframeedit.h index c415c0d7..1d323b9d 100644 --- a/src/keyframeedit.h +++ b/src/keyframeedit.h @@ -98,6 +98,11 @@ protected: /** @brief Gets the position of a keyframe from the table. * @param row Row of the keyframe in the table */ int getPos(int row); + /** @brief Converts a frame value to timecode considering the frames vs. HH:MM:SS:FF setting. + * @return timecode */ + QString getPosString(int pos); + + void generateAllParams(); int m_min; int m_max; @@ -112,11 +117,6 @@ private: QButtonGroup *m_showButtons; PositionEdit *m_position; - void generateAllParams(); - /** @brief Converts a frame value to timecode considering the frames vs. HH:MM:SS:FF setting. - * @return timecode */ - QString getPosString(int pos); - private slots: void slotDeleteKeyframe(); void slotAddKeyframe();