]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Fix right click in timeline: http://kdenlive.org/mantis/view.php?id=2829
[kdenlive] / src / customtrackview.cpp
index 2c211f1c9d2abbe3d6996405348c820ebdcc480e..b1b0bb63f3896d1289c195a1f275a35e375e5346 100644 (file)
@@ -405,6 +405,15 @@ void CustomTrackView::slotCheckPositionScrolling()
     }
 }
 
+void CustomTrackView::slotAlignPlayheadToMousePos()
+{
+       /* get curser point ref in screen coord */
+       QPoint ps = QCursor::pos();
+       /* get xPos in scene coord */
+       int mappedXPos = qMax((int)(mapToScene(mapFromGlobal(ps)).x() + 0.5), 0);
+       /* move playhead to new xPos*/
+       seekCursorPos(mappedXPos);
+}
 
 // virtual
 void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
@@ -850,14 +859,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
 
     // context menu requested
     if (event->button() == Qt::RightButton) {
-        if (m_dragItem) {
-            if (dragGroup) dragGroup->setSelected(true);
-            else if (!m_dragItem->isSelected()) {
-                resetSelectionGroup(false);
-                m_scene->clearSelection();
-                m_dragItem->setSelected(true);
-            }
-        } else if (!m_dragGuide) {
+        if (!m_dragItem && !m_dragGuide) {
             // check if there is a guide close to mouse click
             QList<QGraphicsItem *> guidesCollisionList = items(event->pos().x() - 5, event->pos().y(), 10, 2); // a rect of height < 2 does not always collide with the guide
             for (int i = 0; i < guidesCollisionList.count(); i++) {
@@ -877,9 +879,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         m_operationMode = NONE;
         displayContextMenu(event->globalPos(), m_dragItem, dragGroup);
         m_menuPosition = m_clickEvent;
-        m_dragItem = NULL;
-        event->accept();
-        return;
     }
 
     // No item under click
@@ -956,7 +955,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
                 updateSnapPoints(NULL, cleandOffsetList, true);
             }
             m_operationMode = SPACER;
-        } else {
+        } else if (event->button() != Qt::RightButton) {
            setCursor(Qt::ArrowCursor);
             seekCursorPos((int)(mapToScene(event->x(), 0).x()));
         }
@@ -1265,6 +1264,13 @@ void CustomTrackView::groupSelectedItems(QList <QGraphicsItem *> selection, bool
        }
     }
     if (itemsList.isEmpty() && groupsList.isEmpty()) return;
+    if (itemsList.count() == 1) {
+       // only one item selected:
+       QSetIterator<QGraphicsItem *> it(itemsList);
+       m_dragItem = static_cast<AbstractClipItem *>(it.next());
+       m_dragItem->setSelected(true);
+       emit clipItemSelected(static_cast<ClipItem *>(m_dragItem));
+    }
     
     QRectF rectUnion;
     // Find top left position of selection
@@ -3936,6 +3942,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             }
         } else {
             prepareResizeClipStart(m_dragItem, m_dragItemInfo, m_dragItem->startPos().frames(m_document->fps()));
+           if (m_dragItem->type() == AVWIDGET) static_cast <ClipItem*>(m_dragItem)->slotUpdateRange();
         }
     } else if (m_operationMode == RESIZEEND && m_dragItem->endPos() != m_dragItemInfo.endPos) {
         // resize end
@@ -3961,6 +3968,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             }
         } else {
             prepareResizeClipEnd(m_dragItem, m_dragItemInfo, m_dragItem->endPos().frames(m_document->fps()));
+           if (m_dragItem->type() == AVWIDGET) static_cast <ClipItem*>(m_dragItem)->slotUpdateRange();
         }
     } else if (m_operationMode == FADEIN) {
         // resize fade in effect
@@ -7589,19 +7597,27 @@ void CustomTrackView::slotGotFilterJobResults(const QString &/*id*/, int startPo
 
 void CustomTrackView::slotImportClipKeyframes(GRAPHICSRECTITEM type)
 {
-    if (!m_selectionGroup) {
-       emit displayMessage(i18n("You need to select one clip and one transition"), ErrorMessage);
-       return;
-    }
-    // Make sure there is no collision
-    QList<QGraphicsItem *> children = m_selectionGroup->childItems();
     ClipItem *item = NULL;
-    for (int i = 0; i < children.count(); i++) {
-       if (children.at(i)->type() == AVWIDGET) {
-            item = (ClipItem*) children.at(i);
-            break;
-        }
+    if (type == TRANSITIONWIDGET) {
+       // We want to import keyframes to a transition
+       if (!m_selectionGroup) {
+           emit displayMessage(i18n("You need to select one clip and one transition"), ErrorMessage);
+           return;
+       }
+       // Make sure there is no collision
+       QList<QGraphicsItem *> children = m_selectionGroup->childItems();
+       for (int i = 0; i < children.count(); i++) {
+           if (children.at(i)->type() == AVWIDGET) {
+               item = (ClipItem*) children.at(i);
+               break;
+           }
+       }
+    }
+    else {
+       // Import keyframes from current clip to its effect
+       if (m_dragItem) item = static_cast<ClipItem*> (m_dragItem);
     }
+    
     if (!item) {
        emit displayMessage(i18n("No clip found"), ErrorMessage);
        return;
@@ -7630,7 +7646,23 @@ void CustomTrackView::slotImportClipKeyframes(GRAPHICSRECTITEM type)
        return;
     }
     QString keyframeData = ui.data_list->itemData(ui.data_list->currentIndex()).toString();
-    QStringList keyframeList = keyframeData.split(';', QString::SkipEmptyParts);
+    
+    int offset = item->cropStart().frames(m_document->fps());
+    Mlt::Geometry geometry(keyframeData.toUtf8().data(), item->baseClip()->maxDuration().frames(m_document->fps()), m_document->mltProfile().width, m_document->mltProfile().height);
+    Mlt::Geometry newGeometry(QString().toUtf8().data(), item->baseClip()->maxDuration().frames(m_document->fps()), m_document->mltProfile().width, m_document->mltProfile().height);
+    Mlt::GeometryItem gitem;
+    geometry.fetch(&gitem, offset);
+    gitem.frame(0);
+    newGeometry.insert(gitem);
+    int pos = offset + 1;
+    while (!geometry.next_key(&gitem, pos)) {
+       pos = gitem.frame();
+       gitem.frame(pos - offset);
+       pos++;
+       newGeometry.insert(gitem);
+    }
+    QStringList keyframeList = QString(newGeometry.serialise()).split(';', QString::SkipEmptyParts);
+    
     QString result;
     if (ui.import_position->isChecked()) {
        if (ui.import_size->isChecked()) {