]> git.sesse.net Git - kdenlive/commitdiff
c0rners on-monitor editing: align handles position with timeline position
authorTill Theato <root@ttill.de>
Sat, 22 Jan 2011 22:52:54 +0000 (22:52 +0000)
committerTill Theato <root@ttill.de>
Sat, 22 Jan 2011 22:52:54 +0000 (22:52 +0000)
svn path=/trunk/kdenlive/; revision=5342

src/cornerswidget.cpp
src/cornerswidget.h
src/effectstackedit.cpp
src/keyframeedit.h

index 3368f0be828461b31f1d5cd120e475687b1dc740..a560f030b9911ed99dc286989c43f6525e79f813 100644 (file)
@@ -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<QPointF> points, pointsPrev, pointsNext;
+    pointsPrev = getPoints(keyframeOld);
+    pointsNext = getPoints(keyframe);
+    if (pointsPrev.count() != 4 || pointsNext.count() != 4)
         return;
 
-    QList<QPointF> 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<QPointF> CornersWidget::getPoints(QTableWidgetItem* keyframe)
+{
+    QList<QPointF> points;
+
+    if (!keyframe)
+        return points;
+
+    double val;
+    for (int col = 0; col < 8; col++) {
+        if (!keyframe_list->item(keyframe->row(), col))
+            return QList<QPointF>();
+        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"
index 709d361f98bf93401ca6d39899660091ec4d9145..35f8638f8b3938793402043de43bf4aa0e6f1aa1 100644 (file)
@@ -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 <QPointF> 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();
index 929db2346aebab0d59fbd5baed6277c04e25f772..1cb9d1d24df264e8e4e114965b31d8c2f4776d04 100644 (file)
@@ -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<KeyframeEdit *>(corners);
                 } else {
                     geo = new KeyframeEdit(pa, m_in, m_in + m_out, m_timecode, e.attribute("active_keyframe", "-1").toInt());
index 4d1f1f5f2d67b9ff1a36ba05666a9270fdb11cd9..c415c0d7a9a15089f36b07e2181fbbb17e9fc2b9 100644 (file)
@@ -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 <QDomElement> m_params;
-    int m_min;
-    int m_max;
     Timecode m_timecode;
     QGridLayout *m_slidersLayout;
     QButtonGroup *m_showButtons;