]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Fix crash on clip cut introduced in recent coverity fix:
[kdenlive] / src / customtrackview.cpp
index 991c964275bf0d49b2a62df856de0ad929f8f0fb..29bbc263f7e7047b724c5454c694abf4bcef0984 100644 (file)
@@ -87,6 +87,8 @@
 #include <QGraphicsDropShadowEffect>
 #endif
 
+#define SEEK_INACTIVE (-1)
+
 //#define DEBUG
 
 bool sortGuidesList(const Guide *g1 , const Guide *g2)
@@ -390,10 +392,10 @@ void CustomTrackView::slotCheckPositionScrolling()
     if (mapFromScene(m_cursorPos, 0).x() < 3) {
         horizontalScrollBar()->setValue(horizontalScrollBar()->value() - 2);
         QTimer::singleShot(200, this, SLOT(slotCheckPositionScrolling()));
-        setCursorPos(mapToScene(QPoint(-2, 0)).x());
+        seekCursorPos(mapToScene(QPoint(-2, 0)).x());
     } else if (viewport()->width() - 3 < mapFromScene(m_cursorPos + 1, 0).x()) {
         horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 2);
-        setCursorPos(mapToScene(QPoint(viewport()->width(), 0)).x() + 1);
+        seekCursorPos(mapToScene(QPoint(viewport()->width(), 0)).x() + 1);
         QTimer::singleShot(200, this, SLOT(slotCheckPositionScrolling()));
     }
 }
@@ -420,6 +422,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
         bool move = (event->pos() - m_clickEvent).manhattanLength() >= QApplication::startDragDistance();
         if (m_dragItem && m_tool == SELECTTOOL) {
             if (m_operationMode == MOVE && move) {
+               //m_dragItem->setProperty("y_absolute", event->pos().y());
                 QGraphicsView::mouseMoveEvent(event);
                 // If mouse is at a border of the view, scroll
                 if (pos < 5) {
@@ -706,7 +709,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
         if (event->buttons() != Qt::NoButton && event->modifiers() == Qt::NoModifier) {
             QGraphicsView::mouseMoveEvent(event);
             m_moveOpMode = SEEK;
-            setCursorPos(mappedXPos);
+            seekCursorPos(mappedXPos);
             slotCheckPositionScrolling();
             return;
         } else m_moveOpMode = NONE;
@@ -797,6 +800,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
             else
                 m_dragItem = collisionClip;
             found = true;
+           m_dragItem->setProperty("y_absolute", m_clickEvent.y() - m_dragItem->scenePos().y());
             m_dragItemInfo = m_dragItem->info();
             if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET && m_dragItem->parentItem() != m_selectionGroup) {
                 // kDebug()<<"// KLIK FOUND GRP: "<<m_dragItem->sceneBoundingRect();
@@ -938,7 +942,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
             }
             m_operationMode = SPACER;
         } else {
-            setCursorPos((int)(mapToScene(event->x(), 0).x()));
+            seekCursorPos((int)(mapToScene(event->x(), 0).x()));
         }
         //QGraphicsView::mousePressEvent(event);
         event->ignore();
@@ -1356,14 +1360,15 @@ void CustomTrackView::editItemDuration()
         else
             getClipAvailableSpace(item, minimum, maximum);
 
-        ClipDurationDialog d(item, m_document->timecode(), minimum, maximum, this);
-        if (d.exec() == QDialog::Accepted) {
+        QPointer<ClipDurationDialog> d = new ClipDurationDialog(item,
+                               m_document->timecode(), minimum, maximum, this);
+        if (d->exec() == QDialog::Accepted) {
             ItemInfo clipInfo = item->info();
             ItemInfo startInfo = clipInfo;
             if (item->type() == TRANSITIONWIDGET) {
                 // move & resize transition
-                clipInfo.startPos = d.startPos();
-                clipInfo.endPos = clipInfo.startPos + d.duration();
+                clipInfo.startPos = d->startPos();
+                clipInfo.endPos = clipInfo.startPos + d->duration();
                 clipInfo.track = item->track();
                 MoveTransitionCommand *command = new MoveTransitionCommand(this, startInfo, clipInfo, true);
                 updateTrackDuration(clipInfo.track, command);
@@ -1373,10 +1378,10 @@ void CustomTrackView::editItemDuration()
                 ClipItem *clip = static_cast<ClipItem *>(item);
                 QUndoCommand *moveCommand = new QUndoCommand();
                 moveCommand->setText(i18n("Edit clip"));
-                if (d.duration() < item->cropDuration() || d.cropStart() != clipInfo.cropStart) {
+                if (d->duration() < item->cropDuration() || d->cropStart() != clipInfo.cropStart) {
                     // duration was reduced, so process it first
-                    clipInfo.endPos = clipInfo.startPos + d.duration();
-                    clipInfo.cropStart = d.cropStart();
+                    clipInfo.endPos = clipInfo.startPos + d->duration();
+                    clipInfo.cropStart = d->cropStart();
 
                     resizeClip(startInfo, clipInfo);
                     new ResizeClipCommand(this, startInfo, clipInfo, false, true, moveCommand);
@@ -1384,18 +1389,18 @@ void CustomTrackView::editItemDuration()
                     new ResizeClipCommand(this, startInfo, clipInfo, false, true, moveCommand);
                 }
 
-                if (d.startPos() != clipInfo.startPos) {
+                if (d->startPos() != clipInfo.startPos) {
                     startInfo = clipInfo;
-                    clipInfo.startPos = d.startPos();
+                    clipInfo.startPos = d->startPos();
                     clipInfo.endPos = item->endPos() + (clipInfo.startPos - startInfo.startPos);
                     new MoveClipCommand(this, startInfo, clipInfo, true, moveCommand);
                 }
 
-                if (d.duration() > item->cropDuration()) {
+                if (d->duration() > item->cropDuration()) {
                     // duration was increased, so process it after move
                     startInfo = clipInfo;
-                    clipInfo.endPos = clipInfo.startPos + d.duration();
-                    clipInfo.cropStart = d.cropStart();
+                    clipInfo.endPos = clipInfo.startPos + d->duration();
+                    clipInfo.cropStart = d->cropStart();
 
                     resizeClip(startInfo, clipInfo);
                     new ResizeClipCommand(this, startInfo, clipInfo, false, true, moveCommand);
@@ -1406,6 +1411,7 @@ void CustomTrackView::editItemDuration()
                 m_commandStack->push(moveCommand);
             }
         }
+        delete d;
     } else {
         emit displayMessage(i18n("Item is locked"), ErrorMessage);
     }
@@ -2198,7 +2204,13 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
             return NULL;
         }
 
-        if (execute) m_document->renderer()->mltCutClip(m_document->tracksCount() - info.track, cutTime);
+        if (execute) {
+           if (!m_document->renderer()->mltCutClip(m_document->tracksCount() - info.track, cutTime)) {
+               // Error cuting clip in playlist
+               m_blockRefresh = false;
+               return NULL;
+           }
+       }
         int cutPos = (int) cutTime.frames(m_document->fps());
         ItemInfo newPos;
         newPos.startPos = cutTime;
@@ -3074,15 +3086,19 @@ void CustomTrackView::slotRemoveSpace()
     if (m_menuPosition.isNull()) {
         pos = GenTime(cursorPos(), m_document->fps());
 
-        TrackDialog d(m_document, parentWidget());
-        d.comboTracks->setCurrentIndex(m_selectedTrack);
-        d.label->setText(i18n("Track"));
-        d.before_select->setHidden(true);
-        d.setWindowTitle(i18n("Remove Space"));
-        d.video_track->setHidden(true);
-        d.audio_track->setHidden(true);
-        if (d.exec() != QDialog::Accepted) return;
-        track = d.comboTracks->currentIndex();
+        QPointer<TrackDialog> d = new TrackDialog(m_document, parentWidget());
+        d->comboTracks->setCurrentIndex(m_selectedTrack);
+        d->label->setText(i18n("Track"));
+        d->before_select->setHidden(true);
+        d->setWindowTitle(i18n("Remove Space"));
+        d->video_track->setHidden(true);
+        d->audio_track->setHidden(true);
+        if (d->exec() != QDialog::Accepted) {
+            delete d;
+            return;
+        }
+        track = d->comboTracks->currentIndex();
+        delete d;
     } else {
         pos = GenTime((int)(mapToScene(m_menuPosition).x()), m_document->fps());
         track = (int)(mapToScene(m_menuPosition).y() / m_tracksHeight);
@@ -3177,10 +3193,15 @@ void CustomTrackView::slotInsertSpace()
         pos = GenTime((int)(mapToScene(m_menuPosition).x()), m_document->fps());
         track = (int)(mapToScene(m_menuPosition).y() / m_tracksHeight) + 1;
     }
-    SpacerDialog d(GenTime(65, m_document->fps()), m_document->timecode(), track, m_document->tracksList(), this);
-    if (d.exec() != QDialog::Accepted) return;
-    GenTime spaceDuration = d.selectedDuration();
-    track = d.selectedTrack();
+    QPointer<SpacerDialog> d = new SpacerDialog(GenTime(65, m_document->fps()),
+                m_document->timecode(), track, m_document->tracksList(), this);
+    if (d->exec() != QDialog::Accepted) {
+        delete d;
+        return;
+    }
+    GenTime spaceDuration = d->selectedDuration();
+    track = d->selectedTrack();
+    delete d;
 
     QList<QGraphicsItem *> items;
     if (track >= 0) {
@@ -3325,14 +3346,26 @@ void CustomTrackView::deleteClip(const QString &clipId)
     }
 }
 
+void CustomTrackView::seekCursorPos(int pos)
+{
+    m_document->renderer()->seek(pos);
+    emit updateRuler();
+}
+
+int CustomTrackView::seekPosition() const
+{
+    return m_document->renderer()->requestedSeekPosition;
+}
+
+
 void CustomTrackView::setCursorPos(int pos, bool seek)
 {
-    if (pos == m_cursorPos) return;
-    emit cursorMoved((int)(m_cursorPos), (int)(pos));
-    m_cursorPos = pos;
-    if (seek) m_document->renderer()->seek(m_cursorPos);
+    if (pos != m_cursorPos) {
+       emit cursorMoved((int)(m_cursorPos), (int)(pos));
+       m_cursorPos = pos;
+       m_cursorLine->setPos(m_cursorPos, 0);
+    }
     else if (m_autoScroll) checkScrolling();
-    m_cursorLine->setPos(m_cursorPos, 0);
 }
 
 void CustomTrackView::updateCursorPos()
@@ -3347,11 +3380,12 @@ int CustomTrackView::cursorPos()
 
 void CustomTrackView::moveCursorPos(int delta)
 {
-    if (m_cursorPos + delta < 0) delta = 0 - m_cursorPos;
-    emit cursorMoved((int)(m_cursorPos), (int)((m_cursorPos + delta)));
-    m_cursorPos += delta;
-    m_cursorLine->setPos(m_cursorPos, 0);
-    m_document->renderer()->seek(m_cursorPos);
+    int currentPos = m_document->renderer()->requestedSeekPosition;
+    if (currentPos == SEEK_INACTIVE) currentPos = m_document->renderer()->seekFramePosition();
+    if (currentPos + delta < 0) delta = 0 - currentPos;
+    currentPos += delta;
+    m_document->renderer()->seek(currentPos);
+    emit updateRuler();
 }
 
 void CustomTrackView::initCursorPos(int pos)
@@ -5110,7 +5144,7 @@ void CustomTrackView::slotSeekToPreviousSnap()
 {
     updateSnapPoints(NULL);
     GenTime res = m_scene->previousSnapPoint(GenTime(m_cursorPos, m_document->fps()));
-    setCursorPos((int) res.frames(m_document->fps()));
+    seekCursorPos((int) res.frames(m_document->fps()));
     checkScrolling();
 }
 
@@ -5118,7 +5152,7 @@ void CustomTrackView::slotSeekToNextSnap()
 {
     updateSnapPoints(NULL);
     GenTime res = m_scene->nextSnapPoint(GenTime(m_cursorPos, m_document->fps()));
-    setCursorPos((int) res.frames(m_document->fps()));
+    seekCursorPos((int) res.frames(m_document->fps()));
     checkScrolling();
 }
 
@@ -5126,7 +5160,7 @@ void CustomTrackView::clipStart()
 {
     AbstractClipItem *item = getMainActiveClip();
     if (item != NULL) {
-        setCursorPos((int) item->startPos().frames(m_document->fps()));
+        seekCursorPos((int) item->startPos().frames(m_document->fps()));
         checkScrolling();
     }
 }
@@ -5135,7 +5169,7 @@ void CustomTrackView::clipEnd()
 {
     AbstractClipItem *item = getMainActiveClip();
     if (item != NULL) {
-        setCursorPos((int) item->endPos().frames(m_document->fps()) - 1);
+        seekCursorPos((int) item->endPos().frames(m_document->fps()) - 1);
         checkScrolling();
     }
 }
@@ -5197,7 +5231,7 @@ void CustomTrackView::buildGuidesMenu(QMenu *goMenu) const
     goMenu->clear();
     double fps = m_document->fps();
     for (int i = 0; i < m_guides.count(); i++) {
-        act = goMenu->addAction(m_guides.at(i)->label() + "/" + Timecode::getStringTimecode(m_guides.at(i)->position().frames(fps), fps));
+        act = goMenu->addAction(m_guides.at(i)->label() + '/' + Timecode::getStringTimecode(m_guides.at(i)->position().frames(fps), fps));
         act->setData(m_guides.at(i)->position().frames(m_document->fps()));
     }
     goMenu->setEnabled(!m_guides.isEmpty());
@@ -5251,10 +5285,14 @@ void CustomTrackView::slotAddGuide(bool dialog)
 {
     CommentedTime marker(GenTime(m_cursorPos, m_document->fps()), i18n("Guide"));
     if (dialog) {
-        MarkerDialog d(NULL, marker, m_document->timecode(), i18n("Add Guide"), this);
-        if (d.exec() != QDialog::Accepted) return;
-        marker = d.newMarker();
-        
+        QPointer<MarkerDialog> d = new MarkerDialog(NULL, marker,
+                             m_document->timecode(), i18n("Add Guide"), this);
+        if (d->exec() != QDialog::Accepted) {
+            delete d;
+            return;
+        }
+        marker = d->newMarker();
+        delete d;
     } else {
         marker.setComment(m_document->timecode().getDisplayTimecodeFromFrames(m_cursorPos, false));
     }
@@ -5282,11 +5320,12 @@ void CustomTrackView::slotEditGuide(int guidePos)
 
 void CustomTrackView::slotEditGuide(CommentedTime guide)
 {
-    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);
+    QPointer<MarkerDialog> d = new MarkerDialog(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);
     }
+    delete d;
 }
 
 
@@ -5294,11 +5333,13 @@ void CustomTrackView::slotEditTimeLineGuide()
 {
     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);
+    QPointer<MarkerDialog> d = new MarkerDialog(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);
     }
+    delete d;
 }
 
 void CustomTrackView::slotDeleteGuide(int guidePos)
@@ -5412,7 +5453,7 @@ bool CustomTrackView::findString(const QString &text)
     for (int i = 0; i < m_searchPoints.size(); ++i) {
         marker = m_searchPoints.at(i).comment();
         if (marker.contains(text, Qt::CaseInsensitive)) {
-            setCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()), true);
+            seekCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()));
             int vert = verticalScrollBar()->value();
             int hor = cursorPos();
             ensureVisible(hor, vert + 10, 2, 2, 50, 0);
@@ -5425,7 +5466,7 @@ bool CustomTrackView::findString(const QString &text)
 
 void CustomTrackView::selectFound(QString track, QString pos)
 {
-    setCursorPos(m_document->timecode().getFrameCount(pos), true);
+    seekCursorPos(m_document->timecode().getFrameCount(pos));
     slotSelectTrack(track.toInt());
     selectClip(true);
     int vert = verticalScrollBar()->value();
@@ -5439,7 +5480,7 @@ bool CustomTrackView::findNextString(const QString &text)
     for (int i = m_findIndex + 1; i < m_searchPoints.size(); ++i) {
         marker = m_searchPoints.at(i).comment();
         if (marker.contains(text, Qt::CaseInsensitive)) {
-            setCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()), true);
+            seekCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()));
             int vert = verticalScrollBar()->value();
             int hor = cursorPos();
             ensureVisible(hor, vert + 10, 2, 2, 50, 0);
@@ -5736,7 +5777,7 @@ void CustomTrackView::adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime
         if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
             QString def = e.attribute("default");
             // Effect has a keyframe type parameter, we need to adjust the values
-            QStringList keys = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
+            QStringList keys = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
             QStringList newKeyFrames;
             foreach(const QString &str, keys) {
                 int pos = str.section(':', 0, 0).toInt();
@@ -5915,21 +5956,21 @@ void CustomTrackView::saveThumbnails()
 
 void CustomTrackView::slotInsertTrack(int ix)
 {
-    TrackDialog d(m_document, parentWidget());
-    d.comboTracks->setCurrentIndex(ix);
-    d.label->setText(i18n("Insert track"));
-    d.setWindowTitle(i18n("Insert New Track"));
+    QPointer<TrackDialog> d = new TrackDialog(m_document, parentWidget());
+    d->comboTracks->setCurrentIndex(ix);
+    d->label->setText(i18n("Insert track"));
+    d->setWindowTitle(i18n("Insert New Track"));
 
-    if (d.exec() == QDialog::Accepted) {
-        ix = d.comboTracks->currentIndex();
-        if (d.before_select->currentIndex() == 1)
+    if (d->exec() == QDialog::Accepted) {
+        ix = d->comboTracks->currentIndex();
+        if (d->before_select->currentIndex() == 1)
             ix++;
         TrackInfo info;
         info.duration = 0;
         info.isMute = false;
         info.isLocked = false;
        info.effectsList = EffectsList(true);
-        if (d.video_track->isChecked()) {
+        if (d->video_track->isChecked()) {
             info.type = VIDEOTRACK;
             info.isBlind = false;
         } else {
@@ -5940,41 +5981,45 @@ void CustomTrackView::slotInsertTrack(int ix)
         m_commandStack->push(addTrack);
         setDocumentModified();
     }
+    delete d;
 }
 
 void CustomTrackView::slotDeleteTrack(int ix)
 {
     if (m_document->tracksCount() < 2) return;
-    TrackDialog d(m_document, parentWidget());
-    d.comboTracks->setCurrentIndex(ix);
-    d.label->setText(i18n("Delete track"));
-    d.before_select->setHidden(true);
-    d.setWindowTitle(i18n("Delete Track"));
-    d.video_track->setHidden(true);
-    d.audio_track->setHidden(true);
-    if (d.exec() == QDialog::Accepted) {
-        ix = d.comboTracks->currentIndex();
+    QPointer<TrackDialog> d = new TrackDialog(m_document, parentWidget());
+    d->comboTracks->setCurrentIndex(ix);
+    d->label->setText(i18n("Delete track"));
+    d->before_select->setHidden(true);
+    d->setWindowTitle(i18n("Delete Track"));
+    d->video_track->setHidden(true);
+    d->audio_track->setHidden(true);
+    if (d->exec() == QDialog::Accepted) {
+        ix = d->comboTracks->currentIndex();
         TrackInfo info = m_document->trackInfoAt(m_document->tracksCount() - ix - 1);
         deleteTimelineTrack(ix, info);
         setDocumentModified();
         /*AddTrackCommand* command = new AddTrackCommand(this, ix, info, false);
         m_commandStack->push(command);*/
     }
+    delete d;
 }
 
 void CustomTrackView::slotConfigTracks(int ix)
 {
-    TracksConfigDialog d(m_document, ix, parentWidget());
-    if (d.exec() == QDialog::Accepted) {
-        ConfigTracksCommand *configTracks = new ConfigTracksCommand(this, m_document->tracksList(), d.tracksList());
+    QPointer<TracksConfigDialog> d = new TracksConfigDialog(m_document,
+                                                        ix, parentWidget());
+    if (d->exec() == QDialog::Accepted) {
+        ConfigTracksCommand *configTracks = new ConfigTracksCommand(this, m_document->tracksList(), d->tracksList());
         m_commandStack->push(configTracks);
-        QList <int> toDelete = d.deletedTracks();
+        QList <int> toDelete = d->deletedTracks();
         for (int i = 0; i < toDelete.count(); ++i) {
             TrackInfo info = m_document->trackInfoAt(m_document->tracksCount() - toDelete.at(i) + i - 1);
             deleteTimelineTrack(toDelete.at(i) - i, info);
         }
         setDocumentModified();
     }
+    delete d;
 }
 
 void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo)
@@ -6504,7 +6549,7 @@ void CustomTrackView::updateClipTypeActions(ClipItem *clip)
 void CustomTrackView::slotGoToMarker(QAction *action)
 {
     int pos = action->data().toInt();
-    setCursorPos(pos, true);
+    seekCursorPos(pos);
 }
 
 void CustomTrackView::reloadTransitionLumas()
@@ -7004,13 +7049,13 @@ void CustomTrackView::adjustEffectParameters(EffectsParameterList &parameters, Q
             parameters.addParam("_sync_in_out", "1");
         }
         if (e.attribute("type") == "simplekeyframe") {
-            QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
+            QStringList values = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
             double factor = e.attribute("factor", "1").toDouble();
             double offset = e.attribute("offset", "0").toDouble();
             for (int j = 0; j < values.count(); j++) {
                 QString pos = values.at(j).section(':', 0, 0);
                 double val = (values.at(j).section(':', 1, 1).toDouble() - offset) / factor;
-                values[j] = pos + "=" + locale.toString(val);
+                values[j] = pos + '=' + locale.toString(val);
             }
             // kDebug() << "/ / / /SENDING KEYFR:" << values;
             parameters.addParam(paramname, values.join(";"));