]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Small fix to transition change
[kdenlive] / src / customtrackview.cpp
index 04eaba36cafbe9ce9e1d706b60f7305dfdb2b424..8610843be801041f45b7776c097c0db5a5a218db 100644 (file)
@@ -91,6 +91,8 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene
 
     KIcon razorIcon("edit-cut");
     m_razorCursor = QCursor(razorIcon.pixmap(22, 22));
+    verticalScrollBar()->setTracking(true);
+    connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slotRefreshGuides()));
 }
 
 CustomTrackView::~CustomTrackView() {
@@ -590,7 +592,7 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) {
             m_commandStack->push(command);
             updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
         }
-    } else {
+    } else if (m_dragItem) {
         ClipDurationDialog d(m_dragItem, m_document->timecode(), this);
         if (d.exec() == QDialog::Accepted) {
             if (d.startPos() != m_dragItem->startPos()) {
@@ -626,6 +628,12 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) {
                 }
             }
         }
+    } else {
+        QList<QGraphicsItem *> collisionList = items(event->pos());
+        if (collisionList.count() == 1 && collisionList.at(0)->type() == GUIDEITEM) {
+            Guide *editGuide = (Guide *) collisionList.at(0);
+            if (editGuide) slotEditGuide(editGuide->info());
+        }
     }
 }
 
@@ -860,6 +868,7 @@ void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTr
         return;
     }
     m_document->renderer()->mltUpdateTransition(oldTransition.attribute("tag"), transition.attribute("tag"), transition.attribute("transition_btrack").toInt(), m_tracksList.count() - transition.attribute("transition_atrack").toInt(), item->startPos(), item->endPos(), transition);
+    item->setTransitionParameters(transition);
     m_document->setModified(true);
 }
 
@@ -999,6 +1008,7 @@ int CustomTrackView::cursorPos() {
 }
 
 void CustomTrackView::moveCursorPos(int delta) {
+    if (m_cursorPos + delta < 0) delta = 0 - m_cursorPos;
     emit cursorMoved((int)(m_cursorPos * m_scale), (int)((m_cursorPos + delta) * m_scale));
     m_cursorPos += delta;
     m_cursorLine->setPos(m_cursorPos * m_scale, 0);
@@ -1030,7 +1040,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
         m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, false);
         EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), GenTime(m_dragGuide->pos().x() / m_scale, m_document->fps()), m_dragGuide->label(), false);
         m_commandStack->push(command);
-        m_dragGuide->update(GenTime(m_dragGuide->pos().x() / m_scale, m_document->fps()));
+        m_dragGuide->updateGuide(GenTime(m_dragGuide->pos().x() / m_scale, m_document->fps()));
         m_dragGuide = NULL;
         m_dragItem = NULL;
         return;
@@ -1451,6 +1461,7 @@ void CustomTrackView::slotSeekToPreviousSnap() {
         }
     }
     setCursorPos((int) res.frames(m_document->fps()));
+    checkScrolling();
 }
 
 void CustomTrackView::slotSeekToNextSnap() {
@@ -1464,6 +1475,31 @@ void CustomTrackView::slotSeekToNextSnap() {
         }
     }
     setCursorPos((int) res.frames(m_document->fps()));
+    checkScrolling();
+}
+
+void CustomTrackView::clipStart() {
+    QList<QGraphicsItem *> itemList = scene()->selectedItems();
+    for (int i = 0; i < itemList.count(); i++) {
+        if (itemList.at(i)->type() == AVWIDGET) {
+            ClipItem *item = (ClipItem *) itemList.at(i);
+            setCursorPos((int) item->startPos().frames(m_document->fps()));
+            checkScrolling();
+            break;
+        }
+    }
+}
+
+void CustomTrackView::clipEnd() {
+    QList<QGraphicsItem *> itemList = scene()->selectedItems();
+    for (int i = 0; i < itemList.count(); i++) {
+        if (itemList.at(i)->type() == AVWIDGET) {
+            ClipItem *item = (ClipItem *) itemList.at(i);
+            setCursorPos((int) item->endPos().frames(m_document->fps()));
+            checkScrolling();
+            break;
+        }
+    }
 }
 
 void CustomTrackView::slotAddClipMarker() {
@@ -1579,11 +1615,9 @@ void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const Q
     if (oldPos > GenTime() && pos > GenTime()) {
         // move guide
         for (int i = 0; i < m_guides.count(); i++) {
-            kDebug() << "// LOOKING FOR GUIDE (" << i << "): " << m_guides.at(i)->position().frames(25) << ", LOOK: " << oldPos.frames(25) << "x" << pos.frames(25);
             if (m_guides.at(i)->position() == oldPos) {
                 Guide *item = m_guides.at(i);
-                item->update(pos, comment);
-                item->updatePosition(m_scale);
+                item->updateGuide(pos, comment);
                 break;
             }
         }
@@ -1617,12 +1651,37 @@ bool CustomTrackView::addGuide(const GenTime pos, const QString &comment) {
 }
 
 void CustomTrackView::slotAddGuide() {
-    if (addGuide(GenTime(m_cursorPos, m_document->fps()), i18n("guide"))) {
-        EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), GenTime(m_cursorPos, m_document->fps()), i18n("guide"), false);
+    CommentedTime marker(GenTime(m_cursorPos, m_document->fps()), i18n("Guide"));
+    MarkerDialog d(NULL, marker, m_document->timecode(), this);
+    if (d.exec() != QDialog::Accepted) return;
+    if (addGuide(d.newMarker().time(), d.newMarker().comment())) {
+        EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), d.newMarker().time(), d.newMarker().comment(), false);
+        m_commandStack->push(command);
+    }
+}
+
+void CustomTrackView::slotEditGuide() {
+    GenTime pos = GenTime(m_cursorPos, m_document->fps());
+    bool found = false;
+    for (int i = 0; i < m_guides.count(); i++) {
+        if (m_guides.at(i)->position() == pos) {
+            slotEditGuide(m_guides.at(i)->info());
+            found = true;
+            break;
+        }
+    }
+    if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
+}
+
+void CustomTrackView::slotEditGuide(CommentedTime guide) {
+    MarkerDialog d(NULL, guide, m_document->timecode(), 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() {
     GenTime pos = GenTime(m_cursorPos, m_document->fps());
     bool found = false;
@@ -1674,6 +1733,15 @@ void CustomTrackView::setScale(double scaleFactor) {
     verticalScrollBar()->setValue(vert);
 }
 
+void CustomTrackView::slotRefreshGuides() {
+    if (KdenliveSettings::showmarkers()) {
+        kDebug() << "// refresh GUIDES";
+        for (int i = 0; i < m_guides.count(); i++) {
+            m_guides.at(i)->update();
+        }
+    }
+}
+
 void CustomTrackView::drawBackground(QPainter * painter, const QRectF & rect) {
     QRect rectInView = viewport()->rect();
     rectInView.moveTo(horizontalScrollBar()->value(), verticalScrollBar()->value());
@@ -1740,19 +1808,26 @@ bool CustomTrackView::findNextString(const QString &text) {
 
 void CustomTrackView::initSearchStrings() {
     m_searchPoints.clear();
-
     QList<QGraphicsItem *> itemList = items();
     for (int i = 0; i < itemList.count(); i++) {
+        // parse all clip names
         if (itemList.at(i)->type() == AVWIDGET) {
             ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
             GenTime start = item->startPos();
             CommentedTime t(start, item->clipName());
             m_searchPoints.append(t);
-
+            // add all clip markers
             QList < CommentedTime > markers = item->commentedSnapMarkers();
             m_searchPoints += markers;
         }
     }
+
+    // add guides
+    for (int i = 0; i < m_guides.count(); i++) {
+        m_searchPoints.append(m_guides.at(i)->info());
+    }
+
+    qSort(m_searchPoints);
 }
 
 void CustomTrackView::clearSearchStrings() {