From: Jean-Baptiste Mardelle Date: Mon, 23 Feb 2009 22:24:25 +0000 (+0000) Subject: Allow to change clip speed only for video clips (not supported for color, image,... X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=778b74eb30f064927a892849df639de50a63e5ba;p=kdenlive Allow to change clip speed only for video clips (not supported for color, image, ...) svn path=/branches/KDE4/; revision=3073 --- diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 19193cf9..5893b7d3 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -79,7 +79,7 @@ // const int duration = animate ? 1500 : 1; CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscene, QWidget *parent) - : QGraphicsView(projectscene, parent), m_scene(projectscene), m_cursorPos(0), m_cursorLine(NULL), m_operationMode(NONE), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_clickPoint(QPoint()), m_document(doc), m_autoScroll(KdenliveSettings::autoscroll()), m_tracksHeight(KdenliveSettings::trackheight()), m_tool(SELECTTOOL), m_dragGuide(NULL), m_findIndex(0), m_menuPosition(QPoint()), m_blockRefresh(false), m_selectionGroup(NULL), m_selectedTrack(0), m_copiedItems(QList ()), m_scrollOffset(0) { + : QGraphicsView(projectscene, parent), m_scene(projectscene), m_cursorPos(0), m_cursorLine(NULL), m_operationMode(NONE), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_clickPoint(QPoint()), m_document(doc), m_autoScroll(KdenliveSettings::autoscroll()), m_tracksHeight(KdenliveSettings::trackheight()), m_tool(SELECTTOOL), m_dragGuide(NULL), m_findIndex(0), m_menuPosition(QPoint()), m_blockRefresh(false), m_selectionGroup(NULL), m_selectedTrack(0), m_copiedItems(QList ()), m_scrollOffset(0), m_changeSpeedAction(NULL), m_pasteEffectsAction(NULL) { if (doc) m_commandStack = doc->commandStack(); else m_commandStack == NULL; setMouseTracking(true); @@ -122,10 +122,20 @@ void CustomTrackView::setDocumentModified() { void CustomTrackView::setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition) { m_timelineContextMenu = timeline; m_timelineContextClipMenu = clip; + QList list = m_timelineContextClipMenu->actions(); + for (int i = 0; i < list.count(); i++) { + if (list.at(i)->data().toString() == "change_speed") m_changeSpeedAction = list.at(i); + else if (list.at(i)->data().toString() == "paste_effects") m_pasteEffectsAction = list.at(i); + } + m_timelineContextTransitionMenu = transition; - QList list = m_timelineContextTransitionMenu->actions(); - for (int i = 0; i < list.count(); i++) - if (list.at(i)->data().toString() == "auto") m_autoTransition = list.at(i); + list = m_timelineContextTransitionMenu->actions(); + for (int i = 0; i < list.count(); i++) { + if (list.at(i)->data().toString() == "auto") { + m_autoTransition = list.at(i); + break; + } + } } void CustomTrackView::checkAutoScroll() { @@ -667,6 +677,9 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) { if (event->modifiers() != Qt::ControlModifier) m_scene->clearSelection(); m_dragItem->setSelected(!m_dragItem->isSelected()); groupSelectedItems(); + ClipItem *clip = static_cast (m_dragItem); + m_changeSpeedAction->setEnabled(clip->clipType() == AV || clip->clipType() == VIDEO); + m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1); } if (m_selectionGroup == NULL) updateSnapPoints(m_dragItem); @@ -925,8 +938,12 @@ void CustomTrackView::editKeyFrame(const GenTime pos, const int track, const int void CustomTrackView::displayContextMenu(QPoint pos, AbstractClipItem *clip) { if (clip == NULL) m_timelineContextMenu->popup(pos); - else if (clip->type() == AVWIDGET) m_timelineContextClipMenu->popup(pos); - else if (clip->type() == TRANSITIONWIDGET) m_timelineContextTransitionMenu->popup(pos); + else if (clip->type() == AVWIDGET) { + ClipItem *item = static_cast (clip); + m_changeSpeedAction->setEnabled(item->clipType() == AV || item->clipType() == VIDEO); + m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1); + m_timelineContextClipMenu->popup(pos); + } else if (clip->type() == TRANSITIONWIDGET) m_timelineContextTransitionMenu->popup(pos); } void CustomTrackView::activateMonitor() { @@ -1412,8 +1429,10 @@ void CustomTrackView::dropEvent(QDropEvent * event) { QList items = m_selectionGroup->childItems(); resetSelectionGroup(); m_scene->clearSelection(); + bool hasVideoClip = false; for (int i = 0; i < items.count(); i++) { ClipItem *item = static_cast (items.at(i)); + if (!hasVideoClip && (item->clipType() == AV || item->clipType() == VIDEO)) hasVideoClip = true; AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false); m_commandStack->push(command); item->baseClip()->addReference(); @@ -1439,6 +1458,8 @@ void CustomTrackView::dropEvent(QDropEvent * event) { m_document->renderer()->mltInsertClip(info, item->xml(), item->baseClip()->producer(item->track())); item->setSelected(true); } + m_changeSpeedAction->setEnabled(hasVideoClip); + m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1); groupSelectedItems(true); m_document->setModified(true); } else QGraphicsView::dropEvent(event); @@ -2339,14 +2360,16 @@ void CustomTrackView::changeClipSpeed() { QUndoCommand *changeSelected = new QUndoCommand(); changeSelected->setText("Edit clip speed"); int count = 0; + int percent = -1; + bool ok; for (int i = 0; i < itemList.count(); i++) { if (itemList.at(i)->type() == AVWIDGET) { ClipItem *item = static_cast (itemList.at(i)); ItemInfo info = item->info(); - bool ok; - int percent = QInputDialog::getInteger(this, i18n("Edit Clip Speed"), i18n("New speed (percents)"), item->speed() * 100, 1, 300, 1, &ok); + if (percent == -1) percent = QInputDialog::getInteger(this, i18n("Edit Clip Speed"), i18n("New speed (percents)"), item->speed() * 100, 1, 300, 1, &ok); + if (!ok) break; double speed = (double) percent / 100.0; - if (ok && item->speed() != speed) { + if (item->speed() != speed && (item->clipType() == VIDEO || item->clipType() == AV)) { count++; new ChangeSpeedCommand(this, info, item->speed(), speed, item->clipProducer(), true, changeSelected); } diff --git a/src/customtrackview.h b/src/customtrackview.h index 3b25d901..f7088671 100644 --- a/src/customtrackview.h +++ b/src/customtrackview.h @@ -197,6 +197,8 @@ private: QMenu *m_timelineContextClipMenu; QMenu *m_timelineContextTransitionMenu; QAction *m_autoTransition; + QAction *m_changeSpeedAction; + QAction *m_pasteEffectsAction; QTimer m_scrollTimer; int m_scrollOffset; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f0191d85..f2804eab 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -892,6 +892,7 @@ void MainWindow::setupActions() { KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this); collection->addAction("change_clip_speed", editTimelineClipSpeed); + editTimelineClipSpeed->setData("change_speed"); connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed())); KAction *stickTransition = collection->addAction("auto_transition"); @@ -960,6 +961,7 @@ void MainWindow::setupActions() { QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this); collection->addAction("paste_effects", pasteEffects); + pasteEffects->setData("paste_effects"); connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects())); m_closeAction = KStandardAction::close(this, SLOT(closeCurrentDocument()), collection);