From: Till Theato Date: Sat, 22 Jan 2011 22:52:54 +0000 (+0000) Subject: c0rners on-monitor editing: align handles position with timeline position X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=f313ace5a34c48ecda307ff37ffb9a5db50f1c06;p=kdenlive c0rners on-monitor editing: align handles position with timeline position svn path=/trunk/kdenlive/; revision=5342 --- diff --git a/src/cornerswidget.cpp b/src/cornerswidget.cpp index 3368f0be..a560f030 100644 --- a/src/cornerswidget.cpp +++ b/src/cornerswidget.cpp @@ -33,7 +33,8 @@ 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), - m_showScene(true) + m_showScene(true), + m_pos(0) { m_scene = monitor->getEffectScene(); @@ -64,9 +65,6 @@ 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(keyframe_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotUpdateItem())); - connect(keyframe_list, SIGNAL(cellChanged(int, int)), this, SLOT(slotUpdateItem())); } CornersWidget::~CornersWidget() @@ -91,20 +89,28 @@ void CornersWidget::slotUpdateItem() if (keyframe_list->columnCount() < 8) return; - QTableWidgetItem *item = keyframe_list->currentItem(); - if (!item) + QTableWidgetItem *keyframe, *keyframeOld; + keyframe = keyframe_list->item(0, 0); + for (int row = 0; row < keyframe_list->rowCount(); ++row) { + keyframeOld = keyframe; + keyframe = keyframe_list->item(row, 0); + if (getPos(row) >= m_pos) + break; + } + + QList points, pointsPrev, pointsNext; + pointsPrev = getPoints(keyframeOld); + pointsNext = getPoints(keyframe); + if (pointsPrev.count() != 4 || pointsNext.count() != 4) return; - QList points; - double val; - for (int col = 0; col < 8; col++) { - if (!keyframe_list->item(item->row(), col)) - return; - val = (keyframe_list->item(item->row(), col)->text().toInt() - 2000) / 2000.; - if (col % 2 == 0) - points << QPointF(val * m_monitor->render->frameRenderWidth(), 0); - else - points[col / 2].setY(val * m_monitor->render->renderHeight()); + qreal position = (m_pos - getPos(keyframeOld->row())) / (qreal)( getPos(keyframe->row()) - getPos(keyframeOld->row()) + 1 ); + + if (keyframeOld == keyframe) { + points = pointsNext; + } else { + for (int i = 0; i < 4; ++i) + points.append(QLineF(pointsPrev.at(i), pointsNext.at(i)).pointAt(position)); } m_scene->blockSignals(true); @@ -136,6 +142,26 @@ void CornersWidget::slotUpdateProperties() slotAdjustKeyframeInfo(false); } +QList CornersWidget::getPoints(QTableWidgetItem* keyframe) +{ + QList points; + + if (!keyframe) + return points; + + double val; + for (int col = 0; col < 8; col++) { + if (!keyframe_list->item(keyframe->row(), col)) + return QList(); + val = (keyframe_list->item(keyframe->row(), col)->text().toInt() - 2000) / 2000.; + if (col % 2 == 0) + points << QPointF(val * m_monitor->render->frameRenderWidth(), 0); + else + points[col / 2].setY(val * m_monitor->render->renderHeight()); + } + return points; +} + void CornersWidget::slotCheckMonitorPosition(int renderPos) { if (m_showScene) @@ -163,4 +189,15 @@ void CornersWidget::slotShowControls(bool show) m_item->update(); } +void CornersWidget::slotSyncPosition(int relTimelinePos) +{ + if (keyframe_list->rowCount()) { + relTimelinePos = qBound(0, relTimelinePos, m_max); + if (relTimelinePos != m_pos) { + m_pos = relTimelinePos; + slotUpdateItem(); + } + } +} + #include "cornerswidget.moc" diff --git a/src/cornerswidget.h b/src/cornerswidget.h index 709d361f..35f8638f 100644 --- a/src/cornerswidget.h +++ b/src/cornerswidget.h @@ -49,6 +49,8 @@ public: public slots: /** @brief Switches from normal monitor to monitor scene according to @param show. */ void slotShowScene(bool show = true); + /** @brief Updates the on-monitor item. */ + void slotSyncPosition(int relTimelinePos); private: Monitor *m_monitor; @@ -56,13 +58,17 @@ private: OnMonitorCornersItem *m_item; bool m_showScene; MonitorSceneControlWidget *m_config; + int m_pos; + + /** @brief Returns the corner positions set in the row of @param keyframe. */ + QList getPoints(QTableWidgetItem *keyframe); private slots: /** @brief Makes sure the monitor effect scene is only visible if the clip this geometry belongs to is visible. * @param renderPos Postion of the Monitor / Timeline cursor */ void slotCheckMonitorPosition(int renderPos); - /** @brief Updates the on-monitor item according current values in the keyframe editor. */ + /** @brief Updates the on-monitor item according to the current timeline position. */ void slotUpdateItem(); /** @brief Updates the keyframe editor according to the on-monitor item. */ void slotUpdateProperties(); diff --git a/src/effectstackedit.cpp b/src/effectstackedit.cpp index 929db234..1cb9d1d2 100644 --- a/src/effectstackedit.cpp +++ b/src/effectstackedit.cpp @@ -330,6 +330,7 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, int pos, int in, in corners->slotShowScene(!disable); connect(corners, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int))); connect(this, SIGNAL(effectStateChanged(bool)), corners, SLOT(slotShowScene(bool))); + connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int))); geo = static_cast(corners); } else { geo = new KeyframeEdit(pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt()); diff --git a/src/keyframeedit.h b/src/keyframeedit.h index 4d1f1f5f..c415c0d7 100644 --- a/src/keyframeedit.h +++ b/src/keyframeedit.h @@ -99,13 +99,14 @@ protected: * @param row Row of the keyframe in the table */ int getPos(int row); + int m_min; + int m_max; + protected slots: void slotAdjustKeyframeInfo(bool seek = true); private: QList m_params; - int m_min; - int m_max; Timecode m_timecode; QGridLayout *m_slidersLayout; QButtonGroup *m_showButtons;