]> git.sesse.net Git - kdenlive/commitdiff
Spacer tool can now remove space too
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 25 Nov 2008 01:56:37 +0000 (01:56 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 25 Nov 2008 01:56:37 +0000 (01:56 +0000)
svn path=/branches/KDE4/; revision=2731

src/customtrackview.cpp
src/renderer.cpp
src/renderer.h

index 1b980671473c182c4dbe54f963d1a2538d9ec051..e946c89e822fd4c283c79ee785cb0e9b168f3c33 100644 (file)
@@ -273,8 +273,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
         } else if (m_operationMode == SPACER && move) {
             // spacer tool
             int mappedClick = (int)(mapToScene(m_clickEvent).x() + 0.5);
-            if (mappedXPos > mappedClick)
-                m_selectionGroup->setPos(mappedXPos + (m_spacerStart - mappedClick) , m_selectionGroup->pos().y());
+            m_selectionGroup->setPos(mappedXPos + (m_spacerStart - mappedClick) , m_selectionGroup->pos().y());
         }
     }
 
@@ -1349,7 +1348,7 @@ void CustomTrackView::insertSpace(const GenTime &pos, int track, const GenTime d
     if (!add) diff = -diff;
     QList<QGraphicsItem *> itemList;
     if (track == -1) itemList = items();
-    else itemList = scene()->items(pos.frames(m_document->fps()) , track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width() - pos.frames(m_document->fps()), m_tracksHeight / 4);
+    else itemList = scene()->items(pos.frames(m_document->fps()) , track * m_tracksHeight + 1, sceneRect().width() - pos.frames(m_document->fps()), m_tracksHeight - 2);
     if (m_selectionGroup) {
         scene()->destroyItemGroup(m_selectionGroup);
         m_selectionGroup = NULL;
@@ -1375,7 +1374,8 @@ void CustomTrackView::insertSpace(const GenTime &pos, int track, const GenTime d
         m_selectionGroup = NULL;
     }
     if (track != -1) track = m_scene->m_tracksList.count() - track;
-    m_document->renderer()->mltInsertSpace(pos, track, duration, add);
+    if (!add) m_document->renderer()->mltInsertSpace(pos, track, GenTime() - duration);
+    else m_document->renderer()->mltInsertSpace(pos, track, duration);
 }
 
 void CustomTrackView::deleteClip(const QString &clipId) {
@@ -1450,12 +1450,14 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
     } else if (m_operationMode == SPACER) {
         int endClick = (int)(mapToScene(event->pos()).x() + 0.5);
         int mappedClick = (int)(mapToScene(m_clickEvent).x() + 0.5);
-        int diff = endClick - mappedClick;
+        int diff = m_selectionGroup->pos().x() - m_spacerStart;//endClick - mappedClick;
+        kDebug() << "// MOVING SPACER DIFF:" << diff;
         int track = (int)(mapToScene(m_clickEvent).y() / m_tracksHeight);
+        if (diff < 0) mappedClick += diff;
         InsertSpaceCommand *command = new InsertSpaceCommand(this, GenTime(mappedClick, m_document->fps()), track, GenTime(diff, m_document->fps()), false);
         m_commandStack->push(command);
         track = m_scene->m_tracksList.count() - track;
-        m_document->renderer()->mltInsertSpace(GenTime(mappedClick, m_document->fps()), track, GenTime(diff, m_document->fps()), true);
+        m_document->renderer()->mltInsertSpace(GenTime(mappedClick, m_document->fps()), track, GenTime(diff, m_document->fps()));
         if (m_selectionGroup) {
             scene()->destroyItemGroup(m_selectionGroup);
             m_selectionGroup = NULL;
index 9c862aa905e5cc68aa5fd1555ec4e508011f4c01..5f4d2dabe99b4f1ca7996a8b2331f3c8e3dab571 100644 (file)
@@ -1445,7 +1445,7 @@ bool Render::mltRemoveClip(int track, GenTime position) {
     return true;
 }
 
-void Render::mltInsertSpace(const GenTime pos, int track, const GenTime duration, bool add) {
+void Render::mltInsertSpace(const GenTime pos, int track, const GenTime duration) {
     if (!m_mltProducer) {
         kDebug() << "PLAYLIST NOT INITIALISED //////";
         return;
@@ -1460,20 +1460,19 @@ void Render::mltInsertSpace(const GenTime pos, int track, const GenTime duration
     Mlt::Tractor tractor(service);
     mlt_service_lock(service.get_service());
     int insertPos = pos.frames(m_fps);
-    int diff = duration.frames(m_fps) - 1;
+    int diff = duration.frames(m_fps);
 
     if (track != -1) {
         // insert space in one track only
         Mlt::Producer trackProducer(tractor.track(track));
         Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
         int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
-        if (add) trackPlaylist.insert_blank(clipIndex,  duration.frames(m_fps) - 1);
+        if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
         else {
             int position = trackPlaylist.clip_start(clipIndex);
-            trackPlaylist.remove_region(position, diff);
+            trackPlaylist.remove_region(position, -diff - 1);
         }
         // now move transitions
-        if (!add) diff = -diff;
         mlt_service serv = m_mltProducer->parent().get_service();
         mlt_service nextservice = mlt_service_get_producer(serv);
         mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
@@ -1501,15 +1500,14 @@ void Render::mltInsertSpace(const GenTime pos, int track, const GenTime duration
             Mlt::Producer trackProducer(tractor.track(trackNb - 1));
             Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
             int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
-            if (add) trackPlaylist.insert_blank(clipIndex,  diff);
+            if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
             else {
                 int position = trackPlaylist.clip_start(clipIndex);
-                trackPlaylist.remove_region(position, diff);
+                trackPlaylist.remove_region(position, -diff - 1);
             }
             trackNb--;
         }
         // now move transitions
-        if (!add) diff = -diff;
         mlt_service serv = m_mltProducer->parent().get_service();
         mlt_service nextservice = mlt_service_get_producer(serv);
         mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
index d4b712af1358f068a806dd9e271cd10cf136b9db..b0f019da7fb3ef3259ef36dae7e857f7083c5c33 100644 (file)
@@ -150,7 +150,7 @@ Q_OBJECT public:
     void mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
     void mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
     void mltCutClip(int track, GenTime position);
-    void mltInsertSpace(const GenTime pos, int track, const GenTime duration, bool add);
+    void mltInsertSpace(const GenTime pos, int track, const GenTime duration);
     bool mltResizeClipEnd(ItemInfo info, GenTime clipDuration);
     bool mltResizeClipStart(ItemInfo info, GenTime diff);
     bool mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart, Mlt::Producer *prod);