]> git.sesse.net Git - kdenlive/commitdiff
Fix possible crash on clip deletion, fetch thumbs sequentially when adding several...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 17 Jun 2009 10:27:36 +0000 (10:27 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 17 Jun 2009 10:27:36 +0000 (10:27 +0000)
svn path=/trunk/kdenlive/; revision=3553

src/clipitem.cpp
src/clipitem.h
src/customtrackview.cpp
src/customtrackview.h

index 1159d3432298cfdb2909ec03be08a96030693adc..392feeb7a6c4fa4e635507f8ff69c699704c2329 100644 (file)
@@ -118,6 +118,11 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, b
 
 ClipItem::~ClipItem()
 {
+    blockSignals(true);
+    if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
+        disconnect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
+        disconnect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
+    }
     delete m_startThumbTimer;
     delete m_endThumbTimer;
     delete m_timeLine;
@@ -491,18 +496,16 @@ void ClipItem::slotSetEndThumb(QImage img)
 void ClipItem::slotThumbReady(int frame, QPixmap pix)
 {
     if (scene() == NULL) return;
-    QRectF r = sceneBoundingRect();
-    double width = m_startPix.width() / projectScene()->scale();
+    QRectF r = boundingRect();
+    double width = pix.width() / projectScene()->scale();
     if (m_startThumbRequested && frame == cropStart().frames(m_fps)) {
         m_startPix = pix;
         m_startThumbRequested = false;
-        double height = r.height();
-        update(r.x(), r.y(), width, height);
+        update(r.left(), r.top(), width, pix.height());
     } else if (m_endThumbRequested && frame == (cropStart() + cropDuration()).frames(m_fps) - 1) {
         m_endPix = pix;
         m_endThumbRequested = false;
-        double height = r.height();
-        update(r.right() - width, r.y(), width, height);
+        update(r.right() - width, r.y(), width, pix.height());
     }
 }
 
index 9436033d97d919ce33baf95144f0d5c6f3b5f57c..ba485b55ce68c28e9d9ffa80adc587be22df7029 100644 (file)
@@ -157,7 +157,6 @@ private:
     QPixmap m_audioPix;
 
 private slots:
-    void slotFetchThumbs();
     void slotGetStartThumb();
     void slotGetEndThumb();
     void slotGotAudioData();
@@ -168,6 +167,7 @@ private slots:
     void slotThumbReady(int frame, QPixmap pix);
 
 public slots:
+    void slotFetchThumbs();
     void slotSetStartThumb(const QPixmap pix);
     void slotSetEndThumb(const QPixmap pix);
 
index 97b14501b8b17d40c0160db5c67b15cea8e54911..c76b8a599ac9783ef9e809e75080970da269409f 100644 (file)
@@ -140,11 +140,16 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen
     connect(&m_scrollTimer, SIGNAL(timeout()), this, SLOT(slotCheckMouseScrolling()));
     m_scrollTimer.setInterval(100);
     m_scrollTimer.setSingleShot(true);
+
+    connect(&m_thumbsTimer, SIGNAL(timeout()), this, SLOT(slotFetchNextThumbs()));
+    m_thumbsTimer.setInterval(500);
+    m_thumbsTimer.setSingleShot(true);
 }
 
 CustomTrackView::~CustomTrackView()
 {
     qDeleteAll(m_guides);
+    m_waitingThumbs.clear();
 }
 
 void CustomTrackView::setDocumentModified()
@@ -258,6 +263,18 @@ int CustomTrackView::getPreviousVideoTrack(int track)
 }
 
 
+void CustomTrackView::slotFetchNextThumbs()
+{
+    if (!m_waitingThumbs.isEmpty()) {
+        ClipItem *item = m_waitingThumbs.takeFirst();
+        while ((item == NULL) && !m_waitingThumbs.isEmpty()) {
+            item = m_waitingThumbs.takeFirst();
+        }
+        if (item) item->slotFetchThumbs();
+        if (!m_waitingThumbs.isEmpty()) m_thumbsTimer.start();
+    }
+}
+
 void CustomTrackView::slotCheckMouseScrolling()
 {
     if (m_scrollOffset == 0) {
@@ -1158,17 +1175,20 @@ void CustomTrackView::dragEnterEvent(QDragEnterEvent * event)
             info.startPos = start;
             info.endPos = info.startPos + clip->duration();
             info.track = (int)(1 / m_tracksHeight);
-            ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0);
+            ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, false);
             start += clip->duration();
             offsetList.append(start);
             m_selectionGroup->addToGroup(item);
             item->setFlags(QGraphicsItem::ItemIsSelectable);
+            m_waitingThumbs.append(item);
         }
         //TODO: check if we do not overlap another clip when first dropping in timeline
         //if (insertPossible(m_selectionGroup, event->pos()))
         updateSnapPoints(NULL, offsetList);
         scene()->addItem(m_selectionGroup);
+        m_thumbsTimer.start();
         event->acceptProposedAction();
+
     } else {
         // the drag is not a clip (may be effect, ...)
         m_clipDrag = false;
@@ -1697,6 +1717,8 @@ void CustomTrackView::dragMoveEvent(QDragMoveEvent * event)
 void CustomTrackView::dragLeaveEvent(QDragLeaveEvent * event)
 {
     if (m_selectionGroup && m_clipDrag) {
+        m_thumbsTimer.stop();
+        m_waitingThumbs.clear();
         QList<QGraphicsItem *> items = m_selectionGroup->childItems();
         qDeleteAll(items);
         scene()->destroyItemGroup(m_selectionGroup);
@@ -2731,8 +2753,10 @@ void CustomTrackView::deleteClip(ItemInfo info)
         }
     }*/
     scene()->removeItem(item);
+    m_waitingThumbs.removeAll(item);
     if (m_dragItem == item) m_dragItem = NULL;
     delete item;
+    item = NULL;
     m_document->setModified(true);
     m_document->renderer()->doRefresh();
 }
index 6ece8977ed6d3a54ffef7d4e66f7582262440cd9..967ecbd581c3afc2bc799e5d8286f6e9b789b91f 100644 (file)
@@ -216,6 +216,7 @@ private:
     QAction *m_deleteGuide;
     QActionGroup *m_clipTypeGroup;
     QTimer m_scrollTimer;
+    QTimer m_thumbsTimer;
     int m_scrollOffset;
     bool m_clipDrag;
 
@@ -229,6 +230,7 @@ private:
     QPoint m_menuPosition;
     bool m_blockRefresh;
     AbstractGroupItem *m_selectionGroup;
+    QList <ClipItem *> m_waitingThumbs;
 
     /** Get the index of the video track that is just below current track */
     int getPreviousVideoTrack(int track);
@@ -253,6 +255,7 @@ private slots:
     void slotCheckMouseScrolling();
     void slotEditTimeLineGuide();
     void slotDeleteTimeLineGuide();
+    void slotFetchNextThumbs();
 
 signals:
     void cursorMoved(int, int);