]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
*Render dialog can now create xml files for dvd chapters based on guides (usable...
[kdenlive] / src / customtrackview.cpp
index 4476f4f5333aed372dcb6c8e129947fcd0d2cbe5..c42f5866566087a5954a104b45a37c2e430cd455 100644 (file)
@@ -172,6 +172,15 @@ void CustomTrackView::setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transi
             break;
         }
     }
+
+    m_timelineContextMenu->addSeparator();
+    m_deleteGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
+    connect(m_deleteGuide, SIGNAL(triggered()), this, SLOT(slotDeleteTimeLineGuide()));
+    m_timelineContextMenu->addAction(m_deleteGuide);
+
+    m_editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
+    connect(m_editGuide, SIGNAL(triggered()), this, SLOT(slotEditTimeLineGuide()));
+    m_timelineContextMenu->addAction(m_editGuide);
 }
 
 void CustomTrackView::checkAutoScroll()
@@ -565,6 +574,8 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     kDebug() << "mousePressEvent STARTED";
     m_menuPosition = QPoint();
     m_blockRefresh = true;
+    m_dragItem = NULL;
+    m_dragGuide = NULL;
     bool collision = false;
 
     if (m_tool != RAZORTOOL) activateMonitor();
@@ -583,7 +594,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     }
 
     // check item under mouse
-    QList<QGraphicsItem *> collisionList = items(event->pos());
+    QList<QGraphicsItem *> collisionList = items(m_clickEvent);
 
     if (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL && collisionList.count() == 0) {
         setDragMode(QGraphicsView::ScrollHandDrag);
@@ -605,26 +616,30 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         return;
     }
 
-    if (collisionList.count() == 1 && collisionList.at(0)->type() == GUIDEITEM) {
-        // a guide item was pressed
-        collisionList.at(0)->setFlag(QGraphicsItem::ItemIsMovable, true);
-        m_dragItem = NULL;
-        m_dragGuide = (Guide *) collisionList.at(0);
-        collision = true;
-        m_operationMode = MOVEGUIDE;
-        // deselect all clips so that only the guide will move
-        m_scene->clearSelection();
-        resetSelectionGroup();
-        updateSnapPoints(NULL);
-        QGraphicsView::mousePressEvent(event);
-        return;
+    // if a guide and a clip were pressed, just select the guide
+    for (int i = 0; i < collisionList.count(); ++i) {
+        if (collisionList.at(i)->type() == GUIDEITEM) {
+            // a guide item was pressed
+            m_dragGuide = (Guide *) collisionList.at(i);
+            if (event->button() == Qt::LeftButton) { // move it
+                m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, true);
+                collision = true;
+                m_operationMode = MOVEGUIDE;
+                // deselect all clips so that only the guide will move
+                m_scene->clearSelection();
+                resetSelectionGroup(false);
+                updateSnapPoints(NULL);
+                QGraphicsView::mousePressEvent(event);
+                return;
+            } else // show context menu
+                break;
+        }
     }
 
-    // Find first clip, transition or group under mouse
+    // Find first clip, transition or group under mouse (when no guides selected)
     int ct = 0;
-    m_dragItem = NULL;
     AbstractGroupItem *dragGroup = NULL;
-    while (ct < collisionList.count()) {
+    while (!m_dragGuide && ct < collisionList.count()) {
         if (collisionList.at(ct)->type() == AVWIDGET || collisionList.at(ct)->type() == TRANSITIONWIDGET) {
             m_dragItem = static_cast <AbstractClipItem *>(collisionList.at(ct));
             m_dragItemInfo = m_dragItem->info();
@@ -652,7 +667,23 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
                 m_scene->clearSelection();
                 m_dragItem->setSelected(true);
             }
+        } else if (!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++) {
+                if (guidesCollisionList.at(i)->type() == GUIDEITEM) {
+                    m_dragGuide = static_cast <Guide *>(guidesCollisionList.at(i));
+                    break;
+                }
+            }
+            // keep this to support multiple guides context menu in the future (?)
+            /*if (guidesCollisionList.at(0)->type() != GUIDEITEM)
+                guidesCollisionList.removeAt(0);
+            }
+            if (!guidesCollisionList.isEmpty())
+            m_dragGuide = static_cast <Guide *>(guidesCollisionList.at(0));*/
         }
+
         m_operationMode = NONE;
         displayContextMenu(event->globalPos(), m_dragItem, dragGroup);
         m_menuPosition = m_clickEvent;
@@ -749,12 +780,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     if (m_dragItem->type() == AVWIDGET && !m_dragItem->isItemLocked()) emit clipItemSelected((ClipItem*) m_dragItem);
     else emit clipItemSelected(NULL);
 
-    if (event->modifiers() != Qt::ControlModifier && (m_dragItem->isSelected() || (dragGroup && dragGroup->isSelected()))) {
-        // If clicked item is selected, allow move
-        if (dragGroup) dragGroup->setSelected(true);
-        //event->accept();
-        if (m_operationMode == NONE) QGraphicsView::mousePressEvent(event);
-    } else {
+    if (event->modifiers() == Qt::ControlModifier || !(m_dragItem->isSelected() || (dragGroup && dragGroup->isSelected()))) {
         resetSelectionGroup();
         if (event->modifiers() != Qt::ControlModifier) m_scene->clearSelection();
         dragGroup = NULL;
@@ -773,6 +799,10 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
     }
 
+    // If clicked item is selected, allow move
+    //event->accept();
+    if (event->modifiers() != Qt::ControlModifier && (m_dragItem->isSelected() || (dragGroup && dragGroup->isSelected())) && m_operationMode == NONE) QGraphicsView::mousePressEvent(event);
+
     m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y()));
     m_operationMode = m_dragItem->operationMode(mapToScene(event->pos()));
 
@@ -1046,6 +1076,8 @@ void CustomTrackView::editKeyFrame(const GenTime pos, const int track, const int
 
 void CustomTrackView::displayContextMenu(QPoint pos, AbstractClipItem *clip, AbstractGroupItem *group)
 {
+    m_deleteGuide->setEnabled(m_dragGuide != NULL);
+    m_editGuide->setEnabled(m_dragGuide != NULL);
     if (clip == NULL) m_timelineContextMenu->popup(pos);
     else if (group != NULL) {
         m_changeSpeedAction->setEnabled(false);
@@ -1326,7 +1358,6 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect, i
                 int pos = effectParams.paramValue("out").toInt() - effectParams.paramValue("in").toInt();
                 clip->setFadeOut(pos);
             }
-
         }
     }
     m_document->setModified(true);
@@ -1396,6 +1427,17 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut)
         else newPos.cropStart = item->info().cropStart + (cutTime - info.startPos) * speed;
         newPos.track = info.track;
         ClipItem *dup = item->clone(newPos);
+        // remove unwanted effects (fade in) from 2nd part of cutted clip
+        int ix = dup->hasEffect(QString(), "fadein");
+        if (ix != -1) {
+            QDomElement oldeffect = item->effectAt(ix);
+            dup->deleteEffect(oldeffect.attribute("kdenlive_ix"));
+        }
+        ix = dup->hasEffect(QString(), "fade_from_black");
+        if (ix != -1) {
+            QDomElement oldeffect = item->effectAt(ix);
+            dup->deleteEffect(oldeffect.attribute("kdenlive_ix"));
+        }
         item->resizeEnd(cutPos, false);
         scene()->addItem(dup);
         if (item->checkKeyFrames()) slotRefreshEffects(item);
@@ -1604,6 +1646,7 @@ void CustomTrackView::dragMoveEvent(QDragMoveEvent * event)
     const QPointF pos = mapToScene(event->pos());
     if (m_selectionGroup && m_clipDrag) {
         m_selectionGroup->setPos(pos.x(), pos.y());
+        emit mousePosition((int)(m_selectionGroup->scenePos().x() + 0.5));
         event->setDropAction(Qt::MoveAction);
         event->acceptProposedAction();
     } else {
@@ -1703,8 +1746,10 @@ int CustomTrackView::duration() const
 
 void CustomTrackView::addTrack(TrackInfo type, int ix)
 {
-    if (ix == -1) m_document->insertTrack(ix, type);
-    else {
+    if (ix == -1 || ix == m_document->tracksCount()) {
+        m_document->insertTrack(ix, type);
+        m_document->renderer()->mltInsertTrack(1, type.type == VIDEOTRACK);
+    } else {
         m_document->insertTrack(m_document->tracksCount() - ix, type);
         // insert track in MLT playlist
         m_document->renderer()->mltInsertTrack(m_document->tracksCount() - ix, type.type == VIDEOTRACK);
@@ -2120,9 +2165,12 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         setCursor(Qt::ArrowCursor);
         m_operationMode = NONE;
         m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, false);
-        EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), GenTime(m_dragGuide->pos().x(), m_document->fps()), m_dragGuide->label(), false);
-        m_commandStack->push(command);
-        m_dragGuide->updateGuide(GenTime(m_dragGuide->pos().x(), m_document->fps()));
+        GenTime newPos = GenTime(m_dragGuide->pos().x(), m_document->fps());
+        if (newPos != m_dragGuide->position()) {
+            EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), newPos, m_dragGuide->label(), false);
+            m_commandStack->push(command);
+            m_dragGuide->updateGuide(GenTime(m_dragGuide->pos().x(), m_document->fps()));
+        }
         m_dragGuide = NULL;
         m_dragItem = NULL;
         return;
@@ -3047,15 +3095,10 @@ void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end)
 void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> startTransition, const GenTime offset, const int trackOffset, bool reverseMove)
 {
     // Group Items
-    kDebug() << "//GRP MOVE, REVERS:" << reverseMove;
-    kDebug() << "// GROUP MOV; OFFSET: " << offset.frames(25) << ", TK OFF: " << trackOffset;
+    /*kDebug() << "//GRP MOVE, REVERS:" << reverseMove;
+    kDebug() << "// GROUP MOV; OFFSET: " << offset.frames(25) << ", TK OFF: " << trackOffset;*/
     resetSelectionGroup();
     m_scene->clearSelection();
-    QList<QGraphicsItem *> itemList = items();
-    for (int i = 0; i < itemList.count(); i++) {
-        if (itemList.at(i)->type() == AVWIDGET)
-            kDebug() << "ITEM " << i << ": " << static_cast <AbstractClipItem *>(itemList.at(i))->startPos().frames(25) << ",REEL: " << itemList.at(i)->scenePos();
-    }
 
     for (int i = 0; i < startClip.count(); i++) {
         if (reverseMove) {
@@ -3138,13 +3181,6 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
         }
         KdenliveSettings::setSnaptopoints(snap);
     } else kDebug() << "///////// WARNING; NO GROUP TO MOVE";
-
-    kDebug() << "///////// DONE+++++++++++++";
-    itemList = items();
-    for (int i = 0; i < itemList.count(); i++) {
-        if (itemList.at(i)->type() == AVWIDGET)
-            kDebug() << "ITEM " << i << ": " << static_cast <AbstractClipItem *>(itemList.at(i))->startPos().frames(25) << ",REEL: " << itemList.at(i)->scenePos();
-    }
 }
 
 void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end)
@@ -3469,6 +3505,16 @@ bool sortGuidesList(const Guide *g1 , const Guide *g2)
     return (*g1).position() < (*g2).position();
 }
 
+int CustomTrackView::hasGuide(int pos, int offset)
+{
+    for (int i = 0; i < m_guides.count(); i++) {
+        int guidePos = m_guides.at(i)->position().frames(m_document->fps());
+        if (qAbs(guidePos - pos) <= offset) return guidePos;
+        else if (guidePos > pos) return -1;
+    }
+    return -1;
+}
+
 void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const QString &comment)
 {
     if (oldPos > GenTime() && pos > GenTime()) {
@@ -3524,9 +3570,11 @@ void CustomTrackView::slotAddGuide()
     }
 }
 
-void CustomTrackView::slotEditGuide()
+void CustomTrackView::slotEditGuide(int guidePos)
 {
-    GenTime pos = GenTime(m_cursorPos, m_document->fps());
+    GenTime pos;
+    if (guidePos == -1) pos = GenTime(m_cursorPos, m_document->fps());
+    else pos = GenTime(guidePos, m_document->fps());
     bool found = false;
     for (int i = 0; i < m_guides.count(); i++) {
         if (m_guides.at(i)->position() == pos) {
@@ -3548,9 +3596,22 @@ void CustomTrackView::slotEditGuide(CommentedTime guide)
 }
 
 
-void CustomTrackView::slotDeleteGuide()
+void CustomTrackView::slotEditTimeLineGuide()
 {
-    GenTime pos = GenTime(m_cursorPos, m_document->fps());
+    if (m_dragGuide == NULL) return;
+    CommentedTime guide = m_dragGuide->info();
+    MarkerDialog d(NULL, guide, m_document->timecode(), i18n("Edit Guide"), this);
+    if (d.exec() == QDialog::Accepted) {
+        EditGuideCommand *command = new EditGuideCommand(this, guide.time(), guide.comment(), d.newMarker().time(), d.newMarker().comment(), true);
+        m_commandStack->push(command);
+    }
+}
+
+void CustomTrackView::slotDeleteGuide(int guidePos)
+{
+    GenTime pos;
+    if (guidePos == -1) pos = GenTime(m_cursorPos, m_document->fps());
+    else pos = GenTime(guidePos, m_document->fps());
     bool found = false;
     for (int i = 0; i < m_guides.count(); i++) {
         if (m_guides.at(i)->position() == pos) {
@@ -3563,6 +3624,15 @@ void CustomTrackView::slotDeleteGuide()
     if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
 }
 
+
+void CustomTrackView::slotDeleteTimeLineGuide()
+{
+    if (m_dragGuide == NULL) return;
+    EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), GenTime(), QString(), true);
+    m_commandStack->push(command);
+}
+
+
 void CustomTrackView::slotDeleteAllGuides()
 {
     QUndoCommand *deleteAll = new QUndoCommand();
@@ -4088,6 +4158,11 @@ void CustomTrackView::slotChangeTrack(int ix)
     view.track_nb->setValue(ix);
     d.setWindowTitle(i18n("Change Track Type"));
 
+    if (m_document->trackInfoAt(m_document->tracksCount() - ix - 1).type == VIDEOTRACK)
+        view.video_track->setChecked(true);
+    else
+        view.audio_track->setChecked(true);
+
     if (d.exec() == QDialog::Accepted) {
         TrackInfo info;
         info.isLocked = false;
@@ -4334,6 +4409,7 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split)
                 break;
             }
         }
+        clip->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
         m_document->clipManager()->removeGroup(grp);
         scene()->destroyItemGroup(grp);
     }