]> git.sesse.net Git - kdenlive/commitdiff
Automatically update numbers in track names when adding/deleting a track. If a track...
authorTill Theato <root@ttill.de>
Thu, 23 Sep 2010 16:13:08 +0000 (16:13 +0000)
committerTill Theato <root@ttill.de>
Thu, 23 Sep 2010 16:13:08 +0000 (16:13 +0000)
svn path=/trunk/kdenlive/; revision=4926

src/customtrackview.cpp
src/customtrackview.h

index 974cb86bd28fdb306e46aaae62134564e7a73396..1701e96eb8caa7682390995f1096e2f0e14a836d 100644 (file)
@@ -2572,9 +2572,10 @@ void CustomTrackView::addTrack(TrackInfo type, int ix)
     m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight - 1);
     setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
     viewport()->update();
-    emit tracksChanged();
     //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged()));
     //setFixedHeight(50 * m_tracksCount);
+
+    updateTrackNames(ix, true);
 }
 
 void CustomTrackView::removeTrack(int ix)
@@ -2644,7 +2645,8 @@ void CustomTrackView::removeTrack(int ix)
 
     m_selectedTrack = qMin(m_selectedTrack, m_document->tracksCount() - 1);
     viewport()->update();
-    emit tracksChanged();
+
+    updateTrackNames(ix, false);
     //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged()));
 }
 
@@ -6468,3 +6470,41 @@ void CustomTrackView::updatePanZoom(ClipItem* item, GenTime cutPos)
     if (effects.count() > 0)
         emit clipItemSelected(item, item->selectedEffectIndex());
 }
+
+void CustomTrackView::updateTrackNames(int track, bool added)
+{
+    QList <TrackInfo> tracks = m_document->tracksList();
+    int max = tracks.count();
+    int docTrack = max - track - 1;
+
+    // count number of tracks of each type
+    int videoTracks = 0;
+    int audioTracks = 0;
+    for (int i = max - 1; i >= 0; --i) {
+        TrackInfo info = tracks.at(i);
+        if (info.type == VIDEOTRACK)
+            videoTracks++;
+        else
+            audioTracks++;
+
+        if (i <= docTrack) {
+            QString type = (info.type == VIDEOTRACK ? "Video " : "Audio ");
+            int typeNumber = (info.type == VIDEOTRACK ? videoTracks : audioTracks);
+
+            if (added) {
+                if (i == docTrack || info.trackName == type + QString::number(typeNumber - 1)) {
+                    info.trackName = type + QString::number(typeNumber);
+                    m_document->setTrackType(i, info);
+                }
+            } else {
+                if (info.trackName == type + QString::number(typeNumber + 1)) {
+                    info.trackName = type + QString::number(typeNumber);
+                    m_document->setTrackType(i, info);
+                }
+            }
+        }
+    }
+
+    emit tracksChanged();
+}
+
index cead1468a4cc72ccb849e6b39d461e4199cfc81f..2287ea739533ffcfb64f08f55a6fd6c5a4f6b485 100644 (file)
@@ -410,6 +410,14 @@ private:
      * @param cutPos (optional) if clip was cut, cut position relative to the original's clip position */
     void updatePanZoom(ClipItem *item, GenTime cutPos = GenTime());
 
+    /** @brief Update Tracknames to fit again after track was added/deleted.
+     * @param track Number of track which was added/deleted
+     * @param added true = track added, false = track deleted
+     * 
+     * The default track name consists of type + number. If we add/delete a track the number has to be adjusted
+     * if the name is still the default one. */
+    void updateTrackNames(int track, bool added);
+
 private slots:
     void slotRefreshGuides();
     void slotEnableRefresh();