]> git.sesse.net Git - kdenlive/blobdiff - src/geometrywidget.cpp
Allow to loop selected timeline item
[kdenlive] / src / geometrywidget.cpp
index 787a4562e0588eb026ef781f321bec6f9b66dcb6..41159724830bcae050682102f6b210145b23e923 100644 (file)
@@ -32,7 +32,9 @@
 #include <QVBoxLayout>
 #include <QGridLayout>
 
-GeometryWidget::GeometryWidget(Monitor* monitor, Timecode timecode, int clipPos, bool isEffect, QWidget* parent ):
+
+
+GeometryWidget::GeometryWidget(Monitor* monitor, Timecode timecode, int clipPos, bool isEffect, QWidget* parent):
         QWidget(parent),
         m_monitor(monitor),
         m_timePos(new TimecodeDisplay(timecode)),
@@ -154,6 +156,7 @@ GeometryWidget::GeometryWidget(Monitor* monitor, Timecode timecode, int clipPos,
 
 
     connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateGeometry()));
+    connect(m_scene, SIGNAL(addKeyframe()),    this, SLOT(slotAddKeyframe()));
     connect(m_monitor, SIGNAL(renderPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
     connect(this, SIGNAL(parameterChanged()), this, SLOT(slotUpdateProperties()));
 }
@@ -183,14 +186,12 @@ void GeometryWidget::setupParam(const QDomElement elem, int minframe, int maxfra
     m_inPoint = minframe;
     m_outPoint = maxframe;
 
-    char *tmp = (char *) qstrdup(elem.attribute("value").toUtf8().data());
     if (m_geometry)
-        m_geometry->parse(tmp, maxframe - minframe, m_monitor->render->renderWidth(), m_monitor->render->renderHeight());
+        m_geometry->parse(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
     else
-        m_geometry = new Mlt::Geometry(tmp, maxframe - minframe, m_monitor->render->renderWidth(), m_monitor->render->renderHeight());
-    delete[] tmp;
+        m_geometry = new Mlt::Geometry(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
 
-    if (elem.attribute("fixed") == "1") {
+    if (elem.attribute("fixed") == "1" || maxframe < minframe) {
         // Keyframes are disabled
         m_ui.widgetTimeWrapper->setHidden(true);
     } else {
@@ -208,7 +209,7 @@ void GeometryWidget::setupParam(const QDomElement elem, int minframe, int maxfra
 
     m_geometry->fetch(&item, 0);
     delete m_rect;
-    m_rect = new QGraphicsRectItem(QRectF(0, 0, item.w(), item.h()));
+    m_rect = new QGraphicsRectHandleItem(QRectF(0, 0, item.w(), item.h()));
     m_rect->setPos(item.x(), item.y());
     m_rect->setZValue(0);
     m_rect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
@@ -249,12 +250,14 @@ void GeometryWidget::slotPositionChanged(int pos, bool seek)
     Mlt::GeometryItem item;
     if (m_geometry->fetch(&item, pos) || item.key() == false) {
         // no keyframe
+        m_rect->drawHandles = false;
         m_scene->setEnabled(false);
         m_ui.widgetGeometry->setEnabled(false);
         m_ui.buttonAddDelete->setIcon(KIcon("document-new"));
         m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
     } else {
         // keyframe
+        m_rect->drawHandles = true;
         m_scene->setEnabled(true);
         m_ui.widgetGeometry->setEnabled(true);
         m_ui.buttonAddDelete->setIcon(KIcon("edit-delete"));
@@ -281,6 +284,7 @@ void GeometryWidget::slotKeyframeMoved(int pos)
 {
     slotPositionChanged(pos);
     slotUpdateGeometry();
+    QTimer::singleShot(100, this, SIGNAL(parameterChanged()));
 }
 
 void GeometryWidget::slotAddKeyframe(int pos)
@@ -326,7 +330,7 @@ void GeometryWidget::slotPreviousKeyframe()
     // Go to start if no keyframe is found
     int currentPos = m_timePos->getValue();
     int pos = 0;
-    if(!m_geometry->prev_key(&item, currentPos - 1) && item.frame() < currentPos)
+    if (!m_geometry->prev_key(&item, currentPos - 1) && item.frame() < currentPos)
         pos = item.frame();
 
     slotPositionChanged(pos);
@@ -358,7 +362,7 @@ void GeometryWidget::slotCheckMonitorPosition(int renderPos)
     if (m_showScene) {
         /*
             We do only get the position in timeline if this geometry belongs to a transition,
-            therefore we need to ways here.
+            therefore we need two ways here.
         */
         if (m_isEffect) {
             emit checkMonitorPosition(renderPos);
@@ -378,6 +382,7 @@ void GeometryWidget::slotUpdateGeometry()
 {
     Mlt::GeometryItem item;
     int pos = m_timePos->getValue();
+
     // get keyframe and make sure it is the correct one
     if (m_geometry->next_key(&item, pos) || item.frame() != pos)
         return;
@@ -398,7 +403,7 @@ void GeometryWidget::slotUpdateProperties()
     QPointF rectPos = m_rect->pos();
     int size;
     if (rectSize.width() / m_monitor->render->dar() < rectSize.height())
-        size = (int)((rectSize.width() * 100.0 / m_monitor->render->renderWidth()) + 0.5);
+        size = (int)((rectSize.width() * 100.0 / m_monitor->render->frameRenderWidth()) + 0.5);
     else
         size = (int)((rectSize.height() * 100.0 / m_monitor->render->renderHeight()) + 0.5);
 
@@ -450,7 +455,7 @@ void GeometryWidget::slotSetHeight(int value)
 void GeometryWidget::slotResize(int value)
 {
     m_rect->setRect(0, 0,
-                    (int)((m_monitor->render->renderWidth() * value / 100.0) + 0.5),
+                    (int)((m_monitor->render->frameRenderWidth() * value / 100.0) + 0.5),
                     (int)((m_monitor->render->renderHeight() * value / 100.0) + 0.5));
     slotUpdateGeometry();
 }
@@ -481,13 +486,13 @@ void GeometryWidget::slotMoveLeft()
 
 void GeometryWidget::slotCenterH()
 {
-    m_rect->setPos((m_monitor->render->renderWidth() - m_rect->rect().width()) / 2, m_rect->pos().y());
+    m_rect->setPos((m_monitor->render->frameRenderWidth() - m_rect->rect().width()) / 2, m_rect->pos().y());
     slotUpdateGeometry();
 }
 
 void GeometryWidget::slotMoveRight()
 {
-    m_rect->setPos(m_monitor->render->renderWidth() - m_rect->rect().width(), m_rect->pos().y());
+    m_rect->setPos(m_monitor->render->frameRenderWidth() - m_rect->rect().width(), m_rect->pos().y());
     slotUpdateGeometry();
 }
 
@@ -513,6 +518,8 @@ void GeometryWidget::slotMoveBottom()
 void GeometryWidget::slotSetSynchronize(bool sync)
 {
     KdenliveSettings::setTransitionfollowcursor(sync);
+    if (sync)
+        emit seekToPos(m_clipPos + m_timePos->getValue());
 }
 
 void GeometryWidget::slotShowScene(bool show)