]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Show the track type in add track dialog through icons in the track list
[kdenlive] / src / customtrackview.cpp
index 555a7da63cc82b2937ff741868c6b4c679f01c8d..7ac1542f1621a2b71c87604f45b955372786e7aa 100644 (file)
@@ -572,8 +572,16 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
             setCursor(KCursor("left_side", Qt::SizeHorCursor));
         else if (opMode == RESIZEEND)
             setCursor(KCursor("right_side", Qt::SizeHorCursor));
-        else if (opMode == FADEIN || opMode == FADEOUT || opMode == TRANSITIONSTART || opMode == TRANSITIONEND || opMode == KEYFRAME)
+        else if (opMode == FADEIN || opMode == FADEOUT) {
             setCursor(Qt::PointingHandCursor);
+            emit displayMessage(i18n("Drag to add or resize a fade effect."), InformationMessage);
+        } else if (opMode == TRANSITIONSTART || opMode == TRANSITIONEND) {
+            setCursor(Qt::PointingHandCursor);
+            emit displayMessage(i18n("Click to add a transition."), InformationMessage);
+        } else if (opMode == KEYFRAME) {
+            setCursor(Qt::PointingHandCursor);
+            emit displayMessage(i18n("Move keyframe above or below clip to remove it, double click to add a new one."), InformationMessage);
+        }
     } // no clip under mouse
     else if (m_tool == RAZORTOOL) {
         event->accept();
@@ -1176,11 +1184,10 @@ void CustomTrackView::editItemDuration()
         if (m_scene->selectedItems().count() == 1) {
             item = static_cast <AbstractClipItem *>(m_scene->selectedItems().at(0));
         } else {
-            if (m_scene->selectedItems().empty()) {
+            if (m_scene->selectedItems().empty())
                 emit displayMessage(i18n("Cannot find clip to edit"), ErrorMessage);
-            } else {
+            else
                 emit displayMessage(i18n("Cannot edit the duration of multiple items"), ErrorMessage);
-            }
             return;
         }
     }
@@ -1205,39 +1212,34 @@ void CustomTrackView::editItemDuration()
         //kDebug()<<"// GOT MOVE POS: "<<minimum.frames(25)<<" - "<<maximum.frames(25);
         ClipDurationDialog d(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
-                ItemInfo startInfo;
-                startInfo.startPos = item->startPos();
-                startInfo.endPos = item->endPos();
-                startInfo.track = item->track();
-                ItemInfo endInfo;
-                endInfo.startPos = d.startPos();
-                endInfo.endPos = endInfo.startPos + d.duration();
-                endInfo.track = item->track();
-                MoveTransitionCommand *command = new MoveTransitionCommand(this, startInfo, endInfo, true);
+                clipInfo.startPos = d.startPos();
+                clipInfo.endPos = clipInfo.startPos + d.duration();
+                clipInfo.track = item->track();
+                MoveTransitionCommand *command = new MoveTransitionCommand(this, startInfo, clipInfo, true);
                 m_commandStack->push(command);
             } else {
                 // move and resize clip
                 QUndoCommand *moveCommand = new QUndoCommand();
                 moveCommand->setText(i18n("Edit clip"));
-                ItemInfo clipInfo = item->info();
                 if (d.duration() < item->cropDuration() || d.cropStart() != clipInfo.cropStart) {
                     // duration was reduced, so process it first
-                    ItemInfo startInfo = clipInfo;
                     clipInfo.endPos = clipInfo.startPos + d.duration();
                     clipInfo.cropStart = d.cropStart();
                     new ResizeClipCommand(this, startInfo, clipInfo, true, false, moveCommand);
                 }
                 if (d.startPos() != clipInfo.startPos) {
-                    ItemInfo startInfo = clipInfo;
+                    startInfo = clipInfo;
                     clipInfo.startPos = d.startPos();
                     clipInfo.endPos = item->endPos() + (clipInfo.startPos - startInfo.startPos);
                     new MoveClipCommand(this, startInfo, clipInfo, true, moveCommand);
                 }
                 if (d.duration() > item->cropDuration()) {
                     // duration was increased, so process it after move
-                    ItemInfo startInfo = clipInfo;
+                    startInfo = clipInfo;
                     clipInfo.endPos = clipInfo.startPos + d.duration();
                     clipInfo.cropStart = d.cropStart();
                     new ResizeClipCommand(this, startInfo, clipInfo, true, false, moveCommand);
@@ -2790,7 +2792,6 @@ void CustomTrackView::deleteClip(const QString &clipId)
 
 void CustomTrackView::setCursorPos(int pos, bool seek)
 {
-    kDebug() << "SEEk TO: " << pos << ", SEEK: " << seek;
     if (pos == m_cursorPos) return;
     emit cursorMoved((int)(m_cursorPos), (int)(pos));
     m_cursorPos = pos;
@@ -3277,11 +3278,12 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         val = (br.bottom() - val) * maxh;
         int start = item->cropStart().frames(m_document->fps());
         int end = (item->cropStart() + item->cropDuration()).frames(m_document->fps()) - 1;
+
         if ((val < -50 || val > 150) && item->editedKeyFramePos() != start && item->editedKeyFramePos() != end) {
             //delete keyframe
-            kDebug() << "// DELETE KFR: " << item->editedKeyFramePos();
             item->movedKeyframe(item->getEffectAt(item->selectedEffectIndex()), item->selectedKeyFramePos(), -1, 0);
         } else item->movedKeyframe(item->getEffectAt(item->selectedEffectIndex()), item->selectedKeyFramePos(), item->editedKeyFramePos(), item->editedKeyFrameValue());
+
         QDomElement newEffect = item->selectedEffect().cloneNode().toElement();
         //item->updateKeyframeEffect();
         //QString next = item->keyframes(item->selectedEffectIndex());
@@ -4007,7 +4009,7 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol
         if (success) {
             QUndoCommand *resizeCommand = new QUndoCommand();
             resizeCommand->setText(i18n("Resize clip"));
-            
+
             // Check if there is an automatic transition on that clip (lower track)
             Transition *transition = getTransitionItemAtStart(oldInfo.startPos, oldInfo.track);
             if (transition && transition->isAutomatic()) {
@@ -4027,10 +4029,10 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol
                 if ((!upperClip || !upperClip->baseClip()->isTransparent()) && newTrInfo.startPos < newTrInfo.endPos)
                     new MoveTransitionCommand(this, trInfo, newTrInfo, true, resizeCommand);
             }
-            
+
             ClipItem *clip = static_cast < ClipItem * >(item);
             updatePositionEffects(clip, oldInfo);
-            
+
             // check keyframes
             QDomDocument doc;
             QDomElement root = doc.createElement("list");
@@ -4043,7 +4045,7 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol
                     indexes.append(i);
                 }
             }
-            
+
             if (clip->checkEffectsKeyframesPos(oldInfo.cropStart.frames(m_document->fps()), clip->cropStart().frames(m_document->fps()), true)) {
                 // Keyframes were modified, updateClip
                 QDomNodeList effs = doc.elementsByTagName("effect");
@@ -4051,7 +4053,7 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol
                 // Since we must always resize clip before updating the keyframes, we
                 // put a resize command before & after checking keyframes so that
                 // we are sure the resize is performed before whenever we do or undo the action
-                
+
                 new ResizeClipCommand(this, oldInfo, info, false, true, resizeCommand);
                 for (int i = 0; i < indexes.count(); i++) {
                     new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effs.at(i).cloneNode().toElement(), clip->effectAt(indexes.at(i)), indexes.at(i), false, resizeCommand);
@@ -4062,7 +4064,7 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol
             } else {
                 new ResizeClipCommand(this, oldInfo, info, false, false, resizeCommand);
             }
-            
+
             m_commandStack->push(resizeCommand);
         } else {
             KdenliveSettings::setSnaptopoints(false);
@@ -4082,7 +4084,7 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol
             MoveTransitionCommand *command = new MoveTransitionCommand(this, oldInfo, info, false);
             m_commandStack->push(command);
         }
-        
+
     }
     if (item->parentItem() && item->parentItem() != m_selectionGroup)
         rebuildGroup(static_cast <AbstractGroupItem *>(item->parentItem()));
@@ -4112,7 +4114,7 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
         if (success) {
             QUndoCommand *resizeCommand = new QUndoCommand();
             resizeCommand->setText(i18n("Resize clip"));
-            
+
             // Check if there is an automatic transition on that clip (lower track)
             Transition *tr = getTransitionItemAtEnd(oldInfo.endPos, oldInfo.track);
             if (tr && tr->isAutomatic()) {
@@ -4122,7 +4124,7 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
                 if (newTrInfo.endPos > newTrInfo.startPos)
                     new MoveTransitionCommand(this, trInfo, newTrInfo, true, resizeCommand);
             }
-            
+
             // Check if there is an automatic transition on that clip (upper track)
             tr = getTransitionItemAtEnd(oldInfo.endPos, oldInfo.track - 1);
             if (tr && tr->isAutomatic() && (m_document->tracksCount() - tr->transitionEndTrack()) == oldInfo.track) {
@@ -4134,7 +4136,7 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
                     new MoveTransitionCommand(this, trInfo, newTrInfo, true, resizeCommand);
 
             }
-            
+
             // check keyframes
             ClipItem *clip = static_cast < ClipItem * >(item);
             QDomDocument doc;
@@ -4148,7 +4150,7 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
                     indexes.append(i);
                 }
             }
-            
+
             if (clip->checkEffectsKeyframesPos((oldInfo.cropStart + oldInfo.endPos - oldInfo.startPos).frames(m_document->fps()) - 1, (clip->cropStart() + clip->cropDuration()).frames(m_document->fps()) - 1, false)) {
                 // Keyframes were modified, updateClip
                 QDomNodeList effs = doc.elementsByTagName("effect");
@@ -4156,7 +4158,7 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
                 // Since we must always resize clip before updating the keyframes, we
                 // put a resize command before & after checking keyframes so that
                 // we are sure the resize is performed before whenever we do or undo the action
-                
+
                 new ResizeClipCommand(this, oldInfo, info, false, true, resizeCommand);
                 for (int i = 0; i < indexes.count(); i++) {
                     new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effs.at(i).cloneNode().toElement(), clip->effectAt(indexes.at(i)), indexes.at(i), false, resizeCommand);
@@ -4167,7 +4169,7 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
             } else {
                 new ResizeClipCommand(this, oldInfo, info, false, false, resizeCommand);
             }
-            
+
             m_commandStack->push(resizeCommand);
             updatePositionEffects(clip, oldInfo);
         } else {
@@ -4295,6 +4297,10 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
         QDomElement oldeffect = item->effectAt(effectPos);
         int start = item->cropStart().frames(m_document->fps());
         int max = start + item->cropDuration().frames(m_document->fps());
+        if (start < 0) {
+            max -= start;
+            start = 0;
+        }
         oldeffect.setAttribute("in", start);
         oldeffect.setAttribute("out", max);
         if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), item->getEffectArgs(oldeffect)))
@@ -4667,8 +4673,10 @@ void CustomTrackView::drawBackground(QPainter * painter, const QRectF &rect)
         TrackInfo info = m_document->trackInfoAt(maxTrack - i - 1);
         if (info.isLocked || info.type == AUDIOTRACK || i == m_selectedTrack) {
             const QRectF track(min, m_tracksHeight * i + 1, max - min, m_tracksHeight - 1);
-            if (i == m_selectedTrack) painter->fillRect(track, scheme.background(KColorScheme::ActiveBackground).color());
-            else painter->fillRect(track, info.isLocked ? lockedColor : audioColor);
+            if (i == m_selectedTrack)
+                painter->fillRect(track, scheme.background(KColorScheme::ActiveBackground).color());
+            else
+                painter->fillRect(track, info.isLocked ? lockedColor : audioColor);
         }
         painter->drawLine(QPointF(min, m_tracksHeight *(i + 1)), QPointF(max, m_tracksHeight *(i + 1)));
     }
@@ -5171,28 +5179,23 @@ void CustomTrackView::saveThumbnails()
 void CustomTrackView::slotInsertTrack(int ix)
 {
     TrackDialog d(m_document, parentWidget());
+    d.comboTracks->setCurrentIndex(ix);
     d.label->setText(i18n("Insert track"));
-    d.track_nb->setMaximum(m_document->tracksCount() - 1);
-    d.track_nb->setValue(ix);
     d.setWindowTitle(i18n("Insert New Track"));
-    d.slotUpdateName(ix);
 
     if (d.exec() == QDialog::Accepted) {
-        ix = d.track_nb->value();
-        if (d.before_select->currentIndex() == 1) {
+        ix = d.comboTracks->currentIndex();
+        if (d.before_select->currentIndex() == 1)
             ix++;
-        }
         TrackInfo info;
+        info.isMute = false;
+        info.isLocked = false;
         if (d.video_track->isChecked()) {
             info.type = VIDEOTRACK;
-            info.isMute = false;
             info.isBlind = false;
-            info.isLocked = false;
         } else {
             info.type = AUDIOTRACK;
-            info.isMute = false;
             info.isBlind = true;
-            info.isLocked = false;
         }
         AddTrackCommand *addTrack = new AddTrackCommand(this, ix, info, true);
         m_commandStack->push(addTrack);
@@ -5204,16 +5207,14 @@ 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.track_nb->setMaximum(m_document->tracksCount() - 1);
-    d.track_nb->setValue(ix);
-    d.slotUpdateName(ix);
     d.setWindowTitle(i18n("Delete Track"));
     d.video_track->setHidden(true);
     d.audio_track->setHidden(true);
     if (d.exec() == QDialog::Accepted) {
-        ix = d.track_nb->value();
+        ix = d.comboTracks->currentIndex();
         TrackInfo info = m_document->trackInfoAt(m_document->tracksCount() - ix - 1);
         deleteTimelineTrack(ix, info);
         setDocumentModified();