summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Baptiste Mardelle <jb@kdenlive.org>2016-10-07 13:37:52 (GMT)
committerJean-Baptiste Mardelle <jb@kdenlive.org>2016-10-07 13:37:52 (GMT)
commit867b056161b2da707b6899734cb8c18360eb3d74 (patch)
treee0e8588db8b0abd0895e3e674bf06d8a7cf54f6c
parent5b7908a70b2fe1981aba1c11f093c592795e4297 (diff)
Refactoring: continue moving tool functions out of customtrackview
-rw-r--r--src/definitions.h2
-rw-r--r--src/renderer.cpp5
-rw-r--r--src/renderer.h5
-rw-r--r--src/timeline/customtrackview.cpp478
-rw-r--r--src/timeline/customtrackview.h33
-rw-r--r--src/timeline/managers/abstracttoolmanager.cpp87
-rw-r--r--src/timeline/managers/abstracttoolmanager.h30
-rw-r--r--src/timeline/managers/guidemanager.cpp11
-rw-r--r--src/timeline/managers/guidemanager.h6
-rw-r--r--src/timeline/managers/movemanager.cpp54
-rw-r--r--src/timeline/managers/movemanager.h17
-rw-r--r--src/timeline/managers/razormanager.cpp76
-rw-r--r--src/timeline/managers/razormanager.h20
-rw-r--r--src/timeline/managers/resizemanager.cpp48
-rw-r--r--src/timeline/managers/resizemanager.h6
-rw-r--r--src/timeline/managers/selectmanager.cpp248
-rw-r--r--src/timeline/managers/selectmanager.h9
-rw-r--r--src/timeline/managers/spacermanager.cpp55
-rw-r--r--src/timeline/managers/spacermanager.h9
-rw-r--r--src/timeline/managers/trimmanager.cpp138
-rw-r--r--src/timeline/managers/trimmanager.h22
-rw-r--r--src/timeline/timeline.cpp29
-rw-r--r--src/timeline/timeline.h2
-rw-r--r--src/timeline/track.cpp7
-rw-r--r--src/timeline/track.h1
25 files changed, 897 insertions, 501 deletions
diff --git a/src/definitions.h b/src/definitions.h
index 50ba186..a724373 100644
--- a/src/definitions.h
+++ b/src/definitions.h
@@ -54,6 +54,8 @@ enum OperationType {
ResizeEnd,
RollingStart,
RollingEnd,
+ RippleStart,
+ RippleEnd,
FadeIn,
FadeOut,
TransitionStart,
diff --git a/src/renderer.cpp b/src/renderer.cpp
index 2ef987e..87d7451 100644
--- a/src/renderer.cpp
+++ b/src/renderer.cpp
@@ -59,6 +59,7 @@
Render::Render(Kdenlive::MonitorId rendererName, BinController *binController, GLWidget *qmlView, QWidget *parent) :
AbstractRender(rendererName, parent),
+ byPassSeek(false),
requestedSeekPosition(SEEK_INACTIVE),
showFrameSemaphore(1),
externalConsumer(false),
@@ -834,6 +835,10 @@ void Render::seekToFrame(int pos)
void Render::seekToFrameDiff(int diff)
{
+ if (byPassSeek) {
+ emit renderSeek(diff);
+ return;
+ }
if (!m_mltProducer || !m_isActive)
return;
if (requestedSeekPosition == SEEK_INACTIVE) {
diff --git a/src/renderer.h b/src/renderer.h
index a381a6e..f634a11 100644
--- a/src/renderer.h
+++ b/src/renderer.h
@@ -108,6 +108,9 @@ class Render: public AbstractRender
/** @brief Destroy the MLT Renderer. */
virtual ~Render();
+ /** @brief In some trim modes, arrow keys move the trim pos but not timeline cursor.
+ * if byPassSeek is true, we don't seek renderer but emit a signal for timeline. */
+ bool byPassSeek;
/** @brief Seeks the renderer clip to the given time. */
void seek(const GenTime &time);
@@ -345,6 +348,8 @@ signals:
void mltFrameReceived(Mlt::Frame *);
/** @brief We want to replace a clip with another, but before we need to change clip producer id so that there is no interference*/
void prepareTimelineReplacement(const QString &);
+ /** @brief When in bypass seek mode, we don't seek but pass over the position diff. */
+ void renderSeek(int);
public slots:
diff --git a/src/timeline/customtrackview.cpp b/src/timeline/customtrackview.cpp
index bf221e4..bdf2fee 100644
--- a/src/timeline/customtrackview.cpp
+++ b/src/timeline/customtrackview.cpp
@@ -89,13 +89,13 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, Timeline *timeline, CustomTra
, m_timeline(timeline)
, m_scene(projectscene)
, m_cursorLine(NULL)
- , m_cutLine(NULL)
, m_operationMode(None)
, m_moveOpMode(None)
, m_dragItem(NULL)
, m_dragGuide(NULL)
, m_visualTip(NULL)
, m_keyProperties(NULL)
+ , m_currentToolManager(NULL)
, m_autoScroll(KdenliveSettings::autoscroll())
, m_timelineContextMenu(NULL)
, m_timelineContextClipMenu(NULL)
@@ -109,7 +109,6 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, Timeline *timeline, CustomTra
, m_editGuide(NULL)
, m_deleteGuide(NULL)
, m_clipTypeGroup(NULL)
- , m_scrollOffset(0)
, m_clipDrag(false)
, m_findIndex(0)
, m_tool(SelectTool)
@@ -155,7 +154,6 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, Timeline *timeline, CustomTra
verticalScrollBar()->setTracking(true);
// repaint guides when using vertical scroll
connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slotRefreshGuides()));
- connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slotRefreshCutLine()));
m_cursorLine = projectscene->addLine(0, 0, 0, m_tracksHeight);
m_cursorLine->setZValue(1000);
@@ -166,12 +164,6 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, Timeline *timeline, CustomTra
pen1.setColor(line);
m_cursorLine->setPen(pen1);
- connect(&m_scrollTimer, SIGNAL(timeout()), this, SLOT(slotCheckMouseScrolling()));
- m_scrollTimer.setInterval(100);
- m_scrollTimer.setSingleShot(true);
-
- QIcon razorIcon = KoIconUtils::themedIcon(QStringLiteral("edit-cut"));
- m_razorCursor = QCursor(razorIcon.pixmap(32, 32));
connect(m_document->renderer(), SIGNAL(prepareTimelineReplacement(QString)), this, SLOT(slotPrepareTimelineReplacement(QString)), Qt::DirectConnection);
connect(m_document->renderer(), SIGNAL(replaceTimelineProducer(QString)), this, SLOT(slotReplaceTimelineProducer(QString)), Qt::DirectConnection);
connect(m_document->renderer(), SIGNAL(updateTimelineProducer(QString)), this, SLOT(slotUpdateTimelineProducer(QString)));
@@ -199,13 +191,17 @@ void CustomTrackView::initTools()
{
TrimManager *trim = new TrimManager(this, m_commandStack);
connect(trim, &TrimManager::updateTrimMode, this, &CustomTrackView::updateTrimMode);
- m_toolManagers.insert(TrimType, trim);
- m_toolManagers.insert(SpacerType, new SpacerManager(this, m_commandStack));
- m_toolManagers.insert(ResizeType, new ResizeManager(this, m_commandStack));
- m_toolManagers.insert(RazorType, new RazorManager(this, m_commandStack));
- m_toolManagers.insert(MoveType, new MoveManager(m_timeline->transitionHandler, this, m_commandStack));
- m_toolManagers.insert(SelectType, new SelectManager(this, m_commandStack));
- m_toolManagers.insert(GuideType, new GuideManager(this, m_commandStack));
+ m_currentToolManager = new SelectManager(this, m_commandStack);
+ m_toolManagers.insert(AbstractToolManager::TrimType, trim);
+ m_toolManagers.insert(AbstractToolManager::SpacerType, new SpacerManager(this, m_commandStack));
+ m_toolManagers.insert(AbstractToolManager::ResizeType, new ResizeManager(this, m_commandStack));
+
+ AbstractToolManager *razorManager = new RazorManager(this, m_commandStack);
+ m_toolManagers.insert(AbstractToolManager::RazorType, razorManager);
+ connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), razorManager, SLOT(updateTimelineItems()));
+ m_toolManagers.insert(AbstractToolManager::MoveType, new MoveManager(m_timeline->transitionHandler, this, m_commandStack));
+ m_toolManagers.insert(AbstractToolManager::SelectType, m_currentToolManager);
+ m_toolManagers.insert(AbstractToolManager::GuideType, new GuideManager(this, m_commandStack));
emit updateTrimMode();
}
@@ -230,7 +226,7 @@ void CustomTrackView::keyPressEvent(QKeyEvent * event)
bool CustomTrackView::event( QEvent * e )
{
if (e->type() == QEvent::ShortcutOverride) {
- TrimManager *mgr = qobject_cast<TrimManager *>(m_toolManagers.value(TrimType));
+ TrimManager *mgr = qobject_cast<TrimManager *>(m_toolManagers.value(AbstractToolManager::TrimType));
if (mgr && mgr->trimMode() != NormalTrim) {
if (((QKeyEvent*)e)->key() == Qt::Key_Escape) {
mgr->setTrimMode(NormalTrim);
@@ -394,9 +390,7 @@ bool CustomTrackView::checkTrackHeight(bool force)
} else {
m_cursorLine->setLine(0, 0, 0, m_tracksHeight * m_timeline->visibleTracksCount() - 1);
}
- if (m_cutLine) {
- m_cutLine->setLine(0, 0, 0, m_tracksHeight * m_scene->scale().y());
- }
+ m_currentToolManager->updateTimelineItems();
for (int i = 0; i < m_guides.count(); ++i) {
m_guides.at(i)->setLine(0, 0, 0, newHeight - 1);
}
@@ -458,16 +452,6 @@ int CustomTrackView::getNextVideoTrack(int track)
return track;
}
-void CustomTrackView::slotCheckMouseScrolling()
-{
- if (m_scrollOffset == 0) {
- m_scrollTimer.stop();
- return;
- }
- horizontalScrollBar()->setValue(horizontalScrollBar()->value() + m_scrollOffset);
- m_scrollTimer.start();
-}
-
void CustomTrackView::slotCheckPositionScrolling()
{
// If mouse is at a border of the view, scroll
@@ -604,14 +588,9 @@ void CustomTrackView::spaceToolMoveToSnapPos(double snappedPos)
// virtual
void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
{
- int pos = event->x();
int mappedXPos = qMax((int)(mapToScene(event->pos()).x()), 0);
- double snappedPos = getSnapPointForPos(mappedXPos);
emit mousePosition(mappedXPos);
- if (m_cutLine) {
- m_cutLine->setPos(mappedXPos, getPositionFromTrack(getTrackFromPos(mapToScene(event->pos()).y())));
- }
if (m_moveOpMode == Seek && event->buttons() != Qt::NoButton) {
QGraphicsView::mouseMoveEvent(event);
if (mappedXPos != m_document->renderer()->getCurrentSeekPosition() && mappedXPos != cursorPos()) {
@@ -637,52 +616,6 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
m_moveOpMode = m_operationMode;
}
}
- if (m_moveOpMode == Spacer) {
- // spacer tool
- m_toolManagers.value(SpacerType)->mouseMove(mappedXPos);
- event->accept();
- return;
- }
- if (m_moveOpMode != None && m_moveOpMode != WaitingForConfirm && event->buttons() != Qt::NoButton) {
- if (m_dragItem && m_operationMode != ZoomTimeline) m_clipDrag = true;
- if (m_dragItem && m_tool == SelectTool) {
- if (m_moveOpMode == MoveOperation && m_clipDrag) {
- QGraphicsView::mouseMoveEvent(event);
- // If mouse is at a border of the view, scroll
- if (pos < 5) {
- m_scrollOffset = -30;
- m_scrollTimer.start();
- } else if (viewport()->width() - pos < 10) {
- m_scrollOffset = 30;
- m_scrollTimer.start();
- } else if (m_scrollTimer.isActive()) {
- m_scrollTimer.stop();
- }
- } else if (m_moveOpMode == RollingStart || m_moveOpMode == RollingEnd) {
- m_toolManagers.value(TrimType)->mouseMove(snappedPos);
- } else if (m_moveOpMode == ResizeStart || m_moveOpMode == ResizeEnd) {
- emit pauseMonitor();
- m_toolManagers.value(ResizeType)->mouseMove(snappedPos);
- } else if (m_moveOpMode == FadeIn) {
- static_cast<ClipItem*>(m_dragItem)->setFadeIn(static_cast<int>(mappedXPos - m_dragItem->startPos().frames(m_document->fps())));
- } else if (m_moveOpMode == FadeOut) {
- static_cast<ClipItem*>(m_dragItem)->setFadeOut(static_cast<int>(m_dragItem->endPos().frames(m_document->fps()) - mappedXPos));
- } else if (m_moveOpMode == KeyFrame) {
- GenTime keyFramePos = GenTime(mappedXPos, m_document->fps()) - m_dragItem->startPos();
- double value = m_dragItem->mapFromScene(mapToScene(event->pos()).toPoint()).y();
- m_dragItem->updateKeyFramePos(keyFramePos.frames(fps()), value);
- QString position = m_document->timecode().getDisplayTimecodeFromFrames(m_dragItem->selectedKeyFramePos(), KdenliveSettings::frametimecode());
- emit displayMessage(position + " : " + QString::number(m_dragItem->editedKeyFrameValue()), InformationMessage);
- }
- removeTipAnimation();
- event->accept();
- return;
- } else if (m_moveOpMode == MoveGuide) {
- removeTipAnimation();
- QGraphicsView::mouseMoveEvent(event);
- return;
- }
- }
QList<QGraphicsItem *> itemList = items(event->pos());
QGraphicsRectItem *item = NULL;
@@ -703,14 +636,19 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
}
switch (m_tool) {
case RazorTool:
- setCursor(m_razorCursor);
RazorManager::checkOperation(item, this, event, mappedXPos, m_operationMode, abort);
break;
+ case SpacerTool:
+ break;
case SelectTool:
default:
SelectManager::checkOperation(item, this, event, m_selectionGroup, m_operationMode, m_moveOpMode);
break;
}
+
+ if (!m_currentToolManager->mouseMove(event, mappedXPos, getPositionFromTrack(getTrackFromPos(mapToScene(event->pos()).y())))) {
+ QGraphicsView::mouseMoveEvent(event);
+ }
}
QString CustomTrackView::getDisplayTimecode(const GenTime &time) const
@@ -887,12 +825,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
}
return;
}
- if (m_tool == SelectTool && event->button() == Qt::LeftButton) {
- if (m_toolManagers.value(SelectType)->mousePress(ItemInfo(), event->modifiers())) {
- QGraphicsView::mousePressEvent(event);
- return;
- }
- }
+
m_dragGuide = NULL;
m_clickEvent = event->pos();
@@ -906,8 +839,12 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
return;
}
- if (event->button() == Qt::LeftButton && m_toolManagers.value(GuideType)->mousePress(ItemInfo(), event->modifiers(), collisionList)) {
+ if (event->button() == Qt::LeftButton && m_toolManagers.value(AbstractToolManager::GuideType)->mousePress(event, ItemInfo(), collisionList)) {
QGraphicsView::mousePressEvent(event);
+ if (m_currentToolManager->type() != AbstractToolManager::GuideType) {
+ m_currentToolManager->closeTool();
+ m_currentToolManager = m_toolManagers.value(AbstractToolManager::GuideType);
+ }
return;
}
@@ -979,22 +916,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
m_dragItem = NULL;
}
- // No item under click
- if (m_dragItem == NULL && m_tool != SpacerTool) {
- resetSelectionGroup(false);
- m_scene->clearSelection();
- updateClipTypeActions(NULL);
- updateTimelineSelection();
- if (event->button() == Qt::LeftButton) {
- m_moveOpMode = Seek;
- setCursor(Qt::ArrowCursor);
- seekCursorPos((int)(mapToScene(event->x(), 0).x()));
- event->setAccepted(true);
- QGraphicsView::mousePressEvent(event);
- return;
- }
- }
-
// context menu requested
if (event->button() == Qt::RightButton) {
// Check if we want keyframes context menu
@@ -1038,20 +959,24 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
ItemInfo clickInfo;
clickInfo.startPos = GenTime(clickPoint.x(), m_document->fps());
clickInfo.track = getTrackFromPos(clickPoint.y());
- if (event->button() == Qt::LeftButton) {
+ if (m_currentToolManager->type() == AbstractToolManager::SpacerType || m_currentToolManager->type() == AbstractToolManager::RazorType) {
+ m_currentToolManager->mousePress(event, clickInfo);
+ return;
+ }
+ /*if (event->button() == Qt::LeftButton) {
if (m_tool == SpacerTool) {
- m_toolManagers.value(SpacerType)->mousePress(clickInfo, event->modifiers());
+ m_toolManagers.value(AbstractToolManager::SpacerType)->mousePress(clickInfo, event->modifiers());
QGraphicsView::mousePressEvent(event);
return;
}
// Razor tool
if (m_tool == RazorTool) {
m_document->renderer()->switchPlay(false);
- m_toolManagers.value(RazorType)->mousePress(clickInfo);
+ m_toolManagers.value(AbstractToolManager::RazorType)->mousePress(clickInfo);
event->accept();
return;
}
- }
+ }*/
if (m_dragItem) {
bool itemSelected = false;
bool selected = true;
@@ -1083,25 +1008,8 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
}
updateTimelineSelection();
return;
-
- resetSelectionGroup();
- m_dragItem->setSelected(selected);
- groupSelectedItems(QList <QGraphicsItem*>(), false, true);
- if (selected) {
- m_selectionMutex.lock();
- if (m_selectionGroup) {
- m_selectionGroup->setProperty("y_absolute", yOffset);
- m_selectionGroup->setProperty("locked_tracks", QVariant::fromValue(lockedTracks));
- }
- m_selectionMutex.unlock();
- }
- else {
- m_dragItem->setMainSelectedClip(false);
- m_dragItem = NULL;
- }
- updateTimelineSelection();
- return;
}
+
if (itemSelected == false) {
// User clicked a non selected item, select it
resetSelectionGroup(false);
@@ -1162,6 +1070,13 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
}
else m_operationMode = None;
}
+ // Switch to correct tool
+ if (!m_currentToolManager->isCurrent(m_operationMode)) {
+ m_currentToolManager->closeTool();
+ m_currentToolManager = m_toolManagers.value(m_currentToolManager->getTool(m_operationMode));
+ m_currentToolManager->initTool(mapToScene(event->pos()).x());
+ }
+
// Update snap points
if (m_selectionGroup == NULL) {
if (m_operationMode == ResizeEnd || m_operationMode == ResizeStart) {
@@ -1194,27 +1109,12 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
}
m_selectionMutex.unlock();
}
-
- if (m_operationMode == ResizeEnd || m_operationMode == ResizeStart) {
- // Start Ripple edit
- if (event->modifiers() & Qt::ControlModifier && event->modifiers() & Qt::AltModifier) {
- // Rolling edit
- if (!m_toolManagers.value(TrimType)->mousePress(m_dragItemInfo)) {
- event->ignore();
- return;
- }
- } else {
- // Resize
- m_toolManagers.value(ResizeType)->mousePress(m_dragItemInfo, event->modifiers());
- }
- }
+ m_currentToolManager->mousePress(event, m_dragItemInfo);
QGraphicsView::mousePressEvent(event);
if (m_operationMode == KeyFrame) {
m_dragItem->prepareKeyframeMove();
return;
- } else if (m_operationMode == MoveOperation) {
- m_toolManagers.value(MoveType)->mousePress(m_dragItem->info());
} else if (m_operationMode == TransitionStart && event->modifiers() != Qt::ControlModifier) {
ItemInfo info;
info.startPos = m_dragItem->startPos();
@@ -2217,7 +2117,7 @@ bool CustomTrackView::createSplitOverlay(Mlt::Filter *filter)
return m_timeline->createOverlay(filter, m_dragItem->track(), m_dragItem->startPos().frames(m_document->fps()));
}
-void CustomTrackView::trimMode(bool enable)
+void CustomTrackView::trimMode(bool enable, int ripplePos)
{
if (!enable) {
m_timeline->removeSplitOverlay();
@@ -2235,13 +2135,17 @@ void CustomTrackView::trimMode(bool enable)
} else if (m_operationMode == ResizeStart) {
m_moveOpMode = RollingStart;
}
- int ripplePos = m_moveOpMode == RollingStart ? m_dragItem->startPos().frames(m_document->fps()) : m_dragItem->endPos().frames(m_document->fps());
- qDebug()<<" * **STARTING RIPPLE MODE: "<<ripplePos;
- if (m_timeline->createRippleWindow(m_dragItem->track(), ripplePos)) {
+
+ if (m_timeline->createRippleWindow(m_dragItem->track(), ripplePos, m_moveOpMode)) {
monitorRefresh();
}
}
+AbstractToolManager *CustomTrackView::toolManager(AbstractToolManager::ToolManagerType trimType)
+{
+ return m_toolManagers.value(trimType);
+}
+
void CustomTrackView::slotAddEffectToCurrentItem(QDomElement effect)
{
slotAddEffect(effect, GenTime(), -1);
@@ -3098,26 +3002,14 @@ void CustomTrackView::dragLeaveEvent(QDragLeaveEvent * event)
void CustomTrackView::enterEvent(QEvent * event)
{
- if (m_tool == RazorTool && !m_cutLine) {
- m_cutLine = m_scene->addLine(0, 0, 0, m_tracksHeight * m_scene->scale().y());
- m_cutLine->setZValue(1000);
- QPen pen1 = QPen();
- pen1.setWidth(1);
- QColor line(Qt::red);
- pen1.setColor(line);
- m_cutLine->setPen(pen1);
- m_cutLine->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
- }
+ m_currentToolManager->enterEvent(0, m_tracksHeight * m_scene->scale().y());
QGraphicsView::enterEvent(event);
}
void CustomTrackView::leaveEvent(QEvent * event)
{
removeTipAnimation();
- if (m_cutLine) {
- delete m_cutLine;
- m_cutLine = NULL;
- }
+ m_currentToolManager->leaveEvent();
QGraphicsView::leaveEvent(event);
}
@@ -4107,7 +3999,7 @@ void CustomTrackView::setCursorPos(int pos)
if (pos != m_cursorPos) {
emit cursorMoved(m_cursorPos, pos);
if (m_moveOpMode == RollingStart || m_moveOpMode == RollingEnd) {
- TrimManager *mgr = qobject_cast<TrimManager *>(m_toolManagers.value(TrimType));
+ TrimManager *mgr = qobject_cast<TrimManager *>(m_toolManagers.value(AbstractToolManager::TrimType));
mgr->moveRoll(pos > m_cursorPos, pos);
}
m_cursorPos = pos;
@@ -4253,7 +4145,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
return;
}
m_clipDrag = false;
- if (m_scrollTimer.isActive()) m_scrollTimer.stop();
+
/*if (m_dragItem == NULL && m_selectionGroup == NULL) {
emit transitionItemSelected(NULL);
@@ -4262,152 +4154,12 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
}*/
QPointF clickPoint = mapToScene(event->pos());
GenTime clickFrame(clickPoint.x(), m_document->fps());
-
- switch ((int) (m_moveOpMode == WaitingForConfirm ? m_operationMode : m_moveOpMode)) {
- case MoveGuide:
- m_toolManagers.value(GuideType)->mouseRelease();
- break;
- case Spacer:
- m_toolManagers.value(SpacerType)->mouseRelease(GenTime(m_selectionGroup->sceneBoundingRect().left(), m_document->fps()));
- break;
- case RubberSelection:
- m_toolManagers.value(SelectType)->mouseRelease();
- break;
- case MoveOperation:
- m_toolManagers.value(MoveType)->mouseRelease();
- break;
- case RollingStart:
- case RollingEnd:
- m_toolManagers.value(TrimType)->mouseRelease(m_selectionGroup ? m_selectionGroup->startPos() : GenTime());
- break;
- case ResizeStart:
- case ResizeEnd:
- m_toolManagers.value(ResizeType)->mouseRelease();
- break;
- }
-
-
- if (m_moveOpMode == FadeIn && m_dragItem) {
- ClipItem * item = static_cast <ClipItem *>(m_dragItem);
- // find existing video fade, if none then audio fade
-
- int fadeIndex = item->hasEffect(QLatin1String(""), QStringLiteral("fade_from_black"));
- int fadeIndex2 = item->hasEffect(QStringLiteral("volume"), QStringLiteral("fadein"));
- if (fadeIndex >= 0 && fadeIndex2 >= 0) {
- // We have 2 fadin effects, use currently selected or first one
- int current = item->selectedEffectIndex();
- if (fadeIndex != current) {
- if (fadeIndex2 == current) {
- fadeIndex = current;
- }
- else fadeIndex = qMin(fadeIndex, fadeIndex2);
- }
- }
- else fadeIndex = qMax(fadeIndex, fadeIndex2);
- // resize fade in effect
- if (fadeIndex >= 0) {
- QDomElement oldeffect = item->effectAtIndex(fadeIndex);
- int end = item->fadeIn();
- if (end == 0) {
- slotDeleteEffect(item, -1, oldeffect, false);
- } else {
- int start = item->cropStart().frames(m_document->fps());
- end += start;
- QDomElement effect = oldeffect.cloneNode().toElement();
- EffectsList::setParameter(oldeffect, QStringLiteral("in"), QString::number(start));
- EffectsList::setParameter(oldeffect, QStringLiteral("out"), QString::number(end));
- slotUpdateClipEffect(item, -1, effect, oldeffect, fadeIndex);
- emit clipItemSelected(item);
- }
- // new fade in
- } else if (item->fadeIn() != 0) {
- QDomElement effect;
- if (item->clipState() == PlaylistState::VideoOnly || (item->clipType() != Audio && item->clipState() != PlaylistState::AudioOnly && item->clipType() != Playlist)) {
- effect = MainWindow::videoEffects.getEffectByTag(QLatin1String(""), QStringLiteral("fade_from_black")).cloneNode().toElement();
- } else {
- effect = MainWindow::audioEffects.getEffectByTag(QStringLiteral("volume"), QStringLiteral("fadein")).cloneNode().toElement();
- }
- EffectsList::setParameter(effect, QStringLiteral("out"), QString::number(item->fadeIn()));
- slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
- }
-
- } else if (m_moveOpMode == FadeOut && m_dragItem) {
- ClipItem * item = static_cast <ClipItem *>(m_dragItem);
- // find existing video fade, if none then audio fade
-
- int fadeIndex = item->hasEffect(QLatin1String(""), QStringLiteral("fade_to_black"));
- int fadeIndex2 = item->hasEffect(QStringLiteral("volume"), QStringLiteral("fadeout"));
- if (fadeIndex >= 0 && fadeIndex2 >= 0) {
- // We have 2 fadin effects, use currently selected or first one
- int current = item->selectedEffectIndex();
- if (fadeIndex != current) {
- if (fadeIndex2 == current) {
- fadeIndex = current;
- }
- else fadeIndex = qMin(fadeIndex, fadeIndex2);
- }
- }
- else fadeIndex = qMax(fadeIndex, fadeIndex2);
- // resize fade out effect
- if (fadeIndex >= 0) {
- QDomElement oldeffect = item->effectAtIndex(fadeIndex);
- int start = item->fadeOut();
- if (start == 0) {
- slotDeleteEffect(item, -1, oldeffect, false);
- } else {
- int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
- start = end - start;
- QDomElement effect = oldeffect.cloneNode().toElement();
- EffectsList::setParameter(oldeffect, QStringLiteral("in"), QString::number(start));
- EffectsList::setParameter(oldeffect, QStringLiteral("out"), QString::number(end));
- slotUpdateClipEffect(item, -1, effect, oldeffect, fadeIndex);
- emit clipItemSelected(item);
- }
- // new fade out
- } else if (item->fadeOut() != 0) {
- QDomElement effect;
- if (item->clipState() == PlaylistState::VideoOnly || (item->clipType() != Audio && item->clipState() != PlaylistState::AudioOnly && item->clipType() != Playlist)) {
- effect = MainWindow::videoEffects.getEffectByTag(QLatin1String(""), QStringLiteral("fade_to_black")).cloneNode().toElement();
- } else {
- effect = MainWindow::audioEffects.getEffectByTag(QStringLiteral("volume"), QStringLiteral("fadeout")).cloneNode().toElement();
- }
- int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
- int start = end-item->fadeOut();
- EffectsList::setParameter(effect, QStringLiteral("in"), QString::number(start));
- EffectsList::setParameter(effect, QStringLiteral("out"), QString::number(end));
- slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
- }
-
- } else if (m_moveOpMode == KeyFrame && m_dragItem) {
- // update the MLT effect
- ClipItem * item = static_cast <ClipItem *>(m_dragItem);
- QDomElement oldEffect = item->selectedEffect().cloneNode().toElement();
-
- // check if we want to remove keyframe
- double val = mapToScene(event->pos()).toPoint().y();
- QRectF br = item->sceneBoundingRect();
- double maxh = 100.0 / br.height();
- 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->selectedKeyFramePos() != start && item->selectedKeyFramePos() != end && item->keyframesCount() > 1) {
- //delete keyframe
- item->removeKeyframe(item->getEffectAtIndex(item->selectedEffectIndex()), item->selectedKeyFramePos());
- } else {
- item->movedKeyframe(item->getEffectAtIndex(item->selectedEffectIndex()), item->selectedKeyFramePos(), item->originalKeyFramePos());
- }
-
- QDomElement newEffect = item->selectedEffect().cloneNode().toElement();
-
- EditEffectCommand *command = new EditEffectCommand(this, item->track(), item->startPos(), oldEffect, newEffect, item->selectedEffectIndex(), false, false, true);
- m_commandStack->push(command);
- updateEffect(item->track(), item->startPos(), item->selectedEffect());
- emit clipItemSelected(item);
- } else if (m_moveOpMode == WaitingForConfirm && m_operationMode == KeyFrame && m_dragItem) {
- emit setActiveKeyframe(m_dragItem->selectedKeyFramePos());
+ m_currentToolManager->mouseRelease(event, m_selectionGroup ? m_selectionGroup->startPos() : GenTime());
+ if (m_tool == SelectTool && m_currentToolManager->type() != AbstractToolManager::SelectType) {
+ m_currentToolManager->closeTool();
+ m_currentToolManager = m_toolManagers.value(AbstractToolManager::SelectType);
+ m_currentToolManager->initTool(m_tracksHeight * m_scene->scale().y());
}
-
m_moveOpMode = None;
}
@@ -6070,32 +5822,21 @@ void CustomTrackView::slotDeleteAllGuides()
void CustomTrackView::setTool(ProjectTool tool)
{
+ if (m_tool == tool)
+ return;
m_tool = tool;
- if (m_cutLine && tool != RazorTool) {
- delete m_cutLine;
- m_cutLine = NULL;
- }
+ m_currentToolManager->closeTool();
switch (m_tool) {
case RazorTool:
- if (!m_cutLine) {
- m_cutLine = m_scene->addLine(0, 0, 0, m_tracksHeight * m_scene->scale().y());
- m_cutLine->setZValue(1000);
- QPen pen1 = QPen();
- pen1.setWidth(1);
- QColor line(Qt::red);
- pen1.setColor(line);
- m_cutLine->setPen(pen1);
- m_cutLine->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
- slotRefreshCutLine();
- }
- setCursor(m_razorCursor);
+ m_currentToolManager = m_toolManagers.value(AbstractToolManager::RazorType);
break;
case SpacerTool:
- setCursor(Qt::SplitHCursor);
+ m_currentToolManager = m_toolManagers.value(AbstractToolManager::SpacerType);
break;
default:
- unsetCursor();
+ m_currentToolManager = m_toolManagers.value(AbstractToolManager::SelectType);
}
+ m_currentToolManager->initTool(m_tracksHeight * m_scene->scale().y());
}
void CustomTrackView::setScale(double scaleFactor, double verticalScale)
@@ -6145,7 +5886,7 @@ void CustomTrackView::setScale(double scaleFactor, double verticalScale)
}
double verticalPos = mapToScene(QPoint(0, viewport()->height() / 2)).y();
centerOn(QPointF(cursorPos(), verticalPos));
- slotRefreshCutLine();
+ m_currentToolManager->updateTimelineItems();
m_scene->isZooming = false;
}
@@ -6343,14 +6084,15 @@ bool CustomTrackView::canBePastedTo(QList <ItemInfo> infoList, int type) const
return true;
}
-bool CustomTrackView::canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const
+bool CustomTrackView::canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset, QList <AbstractClipItem *>excluded) const
{
+ excluded << items;
for (int i = 0; i < items.count(); ++i) {
ItemInfo info = items.at(i)->info();
info.startPos += offset;
info.endPos += offset;
info.track += trackOffset;
- if (!canBePastedTo(info, items.at(i)->type(), items)) return false;
+ if (!canBePastedTo(info, items.at(i)->type(), excluded)) return false;
}
return true;
}
@@ -8443,15 +8185,6 @@ void CustomTrackView::importPlaylist(ItemInfo info, QMap <QString, QString> idMa
else delete command;
}
-void CustomTrackView::slotRefreshCutLine()
-{
- if (m_cutLine) {
- QPointF pos = mapToScene(mapFromGlobal(QCursor::pos()));
- int mappedXPos = qMax((int)(pos.x()), 0);
- m_cutLine->setPos(mappedXPos, getPositionFromTrack(getTrackFromPos(pos.y())));
- }
-}
-
void CustomTrackView::updateTransitionWidget(Transition *tr, ItemInfo info)
{
QPoint p;
@@ -8548,13 +8281,13 @@ void CustomTrackView::switchAllTrackLock()
slotSwitchTrackLock(m_selectedTrack, !m_timeline->getTrackInfo(2).isLocked, true);
}
-void CustomTrackView::slotAcceptRipple(bool accept)
+void CustomTrackView::slotAcceptRipple(bool)
{
- if (m_moveOpMode == RollingEnd || m_moveOpMode == RollingStart) {
- TrimManager *mgr = qobject_cast<TrimManager *>(m_toolManagers.value(TrimType));
- if (mgr)
- QMetaObject::invokeMethod(mgr, "endRoll", Qt::QueuedConnection);
- }
+ QMetaObject::invokeMethod(this, "switchTrimMode", Qt::QueuedConnection);
+ /*TrimManager *mgr = qobject_cast<TrimManager *>(m_toolManagers.value(TrimType));
+ if (mgr)
+
+ }*/
}
void CustomTrackView::doRipple(bool accept)
@@ -8658,7 +8391,7 @@ void CustomTrackView::switchTrimMode(int mode)
void CustomTrackView::switchTrimMode(TrimMode mode)
{
- TrimManager *mgr = qobject_cast<TrimManager *>(m_toolManagers.value(TrimType));
+ TrimManager *mgr = qobject_cast<TrimManager *>(m_toolManagers.value(AbstractToolManager::TrimType));
if (mode == NormalTrim) {
mode = (TrimMode) (qMax(((int) mgr->trimMode() + 1) %5, 1));
}
@@ -8691,3 +8424,58 @@ void CustomTrackView::switchTrimMode(TrimMode mode)
}
}
}
+
+bool CustomTrackView::rippleClip(ClipItem *clip, int diff)
+{
+ GenTime timeOffset(diff, m_document->fps());
+ if (clip->cropDuration() + timeOffset > clip->maxDuration()) {
+ emit displayMessage(i18n("Maximum length reached"), InformationMessage);
+ return false;
+ }
+ QList<QGraphicsItem *> selection;
+ spaceToolSelectTrackOnly(clip->track(), selection, clip->endPos());
+ createGroupForSelectedItems(selection);
+ QList <AbstractClipItem *> items;
+ foreach(QGraphicsItem *item, selection) {
+ if (item->type() == AVWidget || item->type() == TransitionWidget)
+ items << (AbstractClipItem *) item;
+ }
+ bool snap = KdenliveSettings::snaptopoints();
+ KdenliveSettings::setSnaptopoints(false);
+ QList <AbstractClipItem*> excluded;
+ excluded << clip;
+ if (canBePasted(items, timeOffset, 0, excluded)) {
+ m_selectionGroup->setTransform(QTransform::fromTranslate(diff, 0), true);
+ clip->setCropStart(clip->cropStart() - GenTime(diff, m_document->fps()));
+ clip->resizeEnd(clip->endPos().frames(m_document->fps()) + diff, false);
+ qDebug()<<"* * *RESIZING END: "<<clip->endPos().frames(m_document->fps()) + diff;
+ } else {
+ //TODO: corruption, cannot move
+ }
+ /*if (diff > 0) {
+ for (int i = 0; i < list
+ m_view->
+ m_secondClip->resizeStart(pos, true, false);
+ m_firstClip->resizeEnd(pos, false);
+ } else {
+ m_secondClip->resizeStart(pos, true, false);
+ }*/
+ KdenliveSettings::setSnaptopoints(snap);
+ return true;
+}
+
+void CustomTrackView::finishRipple(ClipItem *clip, ItemInfo startInfo, int diff, bool fromStart)
+{
+ QUndoCommand *moveCommand = new QUndoCommand();
+ moveCommand->setText(i18n("Ripple clip"));
+ ItemInfo newInfo = clip->info();
+ if (fromStart) {
+ //newInfo.cropStart += GenTime(diff, m_document->fps());
+ }
+ qDebug()<<"CROPSATRT: "<<startInfo.cropStart.frames(25)<<" / "<<newInfo.cropStart.frames(25);
+ new ResizeClipCommand(this, startInfo, newInfo, false, false, moveCommand);
+ m_commandStack->push(moveCommand);
+ if (m_timeline->track(startInfo.track)->resize_in_out(startInfo.startPos.frames(m_document->fps()), clip->cropStart().frames(m_document->fps()), clip->cropStart().frames(m_document->fps()) + clip->cropDuration().frames(m_document->fps())))
+ //resizeClip(startInfo, clip->info(), true);
+ qDebug()<<"* * *RESIZING CLIP: "<<diff<<", FROM START: "<<fromStart;
+}
diff --git a/src/timeline/customtrackview.h b/src/timeline/customtrackview.h
index 528c03c..fbd3461 100644
--- a/src/timeline/customtrackview.h
+++ b/src/timeline/customtrackview.h
@@ -35,6 +35,7 @@
#include "timeline/guide.h"
#include "effectslist/effectslist.h"
#include "timeline/customtrackscene.h"
+#include "timeline/managers/abstracttoolmanager.h"
class Timeline;
class ClipController;
@@ -44,7 +45,6 @@ class AbstractGroupItem;
class Transition;
class AudioCorrelation;
class KSelectAction;
-class AbstractToolManager;
class CustomTrackView : public QGraphicsView
{
@@ -53,6 +53,7 @@ class CustomTrackView : public QGraphicsView
public:
CustomTrackView(KdenliveDoc *doc, Timeline* timeline, CustomTrackScene* projectscene, QWidget *parent = 0);
virtual ~ CustomTrackView();
+
virtual void mousePressEvent(QMouseEvent * event);
virtual void mouseReleaseEvent(QMouseEvent * event);
virtual void mouseMoveEvent(QMouseEvent * event);
@@ -267,7 +268,7 @@ public:
void switchAllTrackLock();
/** @brief Insert space in timeline. track = -1 means all tracks */
void insertTimelineSpace(GenTime startPos, GenTime duration, int track = -1, QList <ItemInfo> excludeList = QList <ItemInfo>());
- void trimMode(bool enable);
+ void trimMode(bool enable, int ripplePos = -1);
/** @brief Returns a clip from timeline
* @param pos the end time position
* @param track the track where the clip is in MLT coordinates */
@@ -325,8 +326,10 @@ public:
GenTime groupSelectedItems(QList <QGraphicsItem *> selection = QList <QGraphicsItem *>(), bool createNewGroup = false, bool selectNewGroup = false);
void sortGuides();
void initTools();
- /** @brief Cycle through timeline trim modes, returns label text for trim mode */
- void switchTrimMode(TrimMode mode = NormalTrim);
+ AbstractToolManager *toolManager(AbstractToolManager::ToolManagerType trimType);
+ /** @brief Perform a ripple move on timeline clips */
+ bool rippleClip(ClipItem *clip, int diff);
+ void finishRipple(ClipItem *clip, ItemInfo startInfo, int diff, bool fromStart);
public slots:
/** @brief Send seek request to MLT. */
@@ -411,6 +414,8 @@ public slots:
void extractZone(QPoint z, bool closeGap, QList <ItemInfo> excludedClips = QList <ItemInfo>(), QUndoCommand *masterCommand = NULL, int track = -1);
/** @brief Select an item in timeline. */
void slotSelectItem(AbstractClipItem *item);
+ /** @brief Cycle through timeline trim modes */
+ void switchTrimMode(TrimMode mode = NormalTrim);
void switchTrimMode(int mode);
protected:
@@ -431,15 +436,6 @@ protected:
virtual void contextMenuEvent(QContextMenuEvent * event);
private:
- enum ToolManagerType {
- TrimType = 0,
- SpacerType,
- MoveType,
- ResizeType,
- RazorType,
- SelectType,
- GuideType
- };
int m_ct;
int m_tracksHeight;
int m_projectDuration;
@@ -449,7 +445,6 @@ private:
Timeline *m_timeline;
CustomTrackScene *m_scene;
QGraphicsLineItem *m_cursorLine;
- QGraphicsLineItem *m_cutLine;
ItemInfo m_dragItemInfo;
ItemInfo m_selectionGroupInfo;
/** @brief Possible timeline action */
@@ -469,7 +464,8 @@ private:
QList <Guide *> m_guides;
QColor m_selectedTrackColor;
QColor m_lockedTrackColor;
- QMap <ToolManagerType, AbstractToolManager*> m_toolManagers;
+ QMap <AbstractToolManager::ToolManagerType, AbstractToolManager*> m_toolManagers;
+ AbstractToolManager *m_currentToolManager;
/** @brief Returns a clip from timeline
* @param pos a time value that is inside the clip
@@ -507,8 +503,6 @@ private:
QList <QAction*> m_audioActions;
QList <QAction*> m_avActions;
QActionGroup *m_clipTypeGroup;
- QTimer m_scrollTimer;
- int m_scrollOffset;
bool m_clipDrag;
int m_findIndex;
@@ -531,7 +525,7 @@ private:
void updatePositionEffects(ClipItem * item, const ItemInfo &info, bool standalone = true);
bool insertDropClips(const QMimeData *data, const QPoint &pos);
bool canBePastedTo(QList <ItemInfo> infoList, int type) const;
- bool canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const;
+ bool canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset, QList <AbstractClipItem *>excluded = QList <AbstractClipItem *>()) const;
ClipItem *getClipUnderCursor() const;
AbstractClipItem *getMainActiveClip() const;
/** Get available space for clip move (min and max free positions) */
@@ -568,7 +562,6 @@ private:
private slots:
void slotRefreshGuides();
- void slotCheckMouseScrolling();
void slotEditTimeLineGuide();
void slotDeleteTimeLineGuide();
void checkTrackSequence(int track);
@@ -585,8 +578,6 @@ private slots:
void slotPrepareTimelineReplacement(const QString &id);
/** @brief Update a producer in all tracks (for example when an effect changed). */
void slotUpdateTimelineProducer(const QString &id);
- /** @brief Refresh razor marker. */
- void slotRefreshCutLine();
void slotEditKeyframeType(QAction *action);
void slotAttachKeyframeToEnd(bool attach);
void disableClip();
diff --git a/src/timeline/managers/abstracttoolmanager.cpp b/src/timeline/managers/abstracttoolmanager.cpp
index 90d16c3..f800e52 100644
--- a/src/timeline/managers/abstracttoolmanager.cpp
+++ b/src/timeline/managers/abstracttoolmanager.cpp
@@ -20,10 +20,95 @@
#include "abstracttoolmanager.h"
#include "timeline/customtrackview.h"
-AbstractToolManager::AbstractToolManager(CustomTrackView *view, DocUndoStack *commandStack) : QObject()
+AbstractToolManager::AbstractToolManager(ToolManagerType type, CustomTrackView *view, DocUndoStack *commandStack) : QObject()
+ , m_managerType(type)
, m_view(view)
, m_commandStack(commandStack)
{
}
+AbstractToolManager::ToolManagerType AbstractToolManager::type() const
+{
+ return m_managerType;
+}
+bool AbstractToolManager::mouseMove(QMouseEvent *, int, int)
+{
+ return true;
+}
+
+bool AbstractToolManager::isCurrent(OperationType type) const
+{
+ switch (type) {
+ case MoveOperation:
+ return m_managerType == MoveType;
+ break;
+ case ResizeStart:
+ case ResizeEnd:
+ return m_managerType == ResizeType;
+ break;
+ case RollingStart:
+ case RollingEnd:
+ case RippleStart:
+ case RippleEnd:
+ return m_managerType == TrimType;
+ break;
+ case MoveGuide:
+ return m_managerType == GuideType;
+ break;
+ case Spacer:
+ return m_managerType == SpacerType;
+ break;
+ default:
+ return m_managerType == SelectType;
+ break;
+ }
+}
+
+AbstractToolManager::ToolManagerType AbstractToolManager::getTool(OperationType type) const
+{
+ switch (type) {
+ case MoveOperation:
+ return MoveType;
+ break;
+ case ResizeStart:
+ case ResizeEnd:
+ return ResizeType;
+ break;
+ case RollingStart:
+ case RollingEnd:
+ case RippleStart:
+ case RippleEnd:
+ return TrimType;
+ break;
+ case MoveGuide:
+ return GuideType;
+ break;
+ case Spacer:
+ return SpacerType;
+ break;
+ default:
+ return SelectType;
+ break;
+ }
+}
+
+void AbstractToolManager::updateTimelineItems()
+{
+}
+
+void AbstractToolManager::initTool(double)
+{
+}
+
+void AbstractToolManager::enterEvent(int , double)
+{
+}
+
+void AbstractToolManager::leaveEvent()
+{
+}
+
+void AbstractToolManager::closeTool()
+{
+}
diff --git a/src/timeline/managers/abstracttoolmanager.h b/src/timeline/managers/abstracttoolmanager.h
index a839017..57183dc 100644
--- a/src/timeline/managers/abstracttoolmanager.h
+++ b/src/timeline/managers/abstracttoolmanager.h
@@ -37,12 +37,34 @@ class AbstractToolManager : public QObject
Q_OBJECT
public:
- explicit AbstractToolManager(CustomTrackView *view, DocUndoStack *commandStack = NULL);
- virtual bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier, QList<QGraphicsItem *> list = QList<QGraphicsItem *>()) = 0;
- virtual void mouseMove(int pos = 0) = 0;
- virtual void mouseRelease(GenTime pos = GenTime()) = 0;
+ enum ToolManagerType {
+ TrimType = 0,
+ SpacerType,
+ MoveType,
+ ResizeType,
+ RazorType,
+ SelectType,
+ GuideType
+ };
+ explicit AbstractToolManager(ToolManagerType type, CustomTrackView *view, DocUndoStack *commandStack = NULL);
+ virtual bool mousePress(QMouseEvent *event, ItemInfo info = ItemInfo(), QList<QGraphicsItem *> list = QList<QGraphicsItem *>()) = 0;
+ virtual bool mouseMove(QMouseEvent *event, int pos = 0, int track = -1);
+ virtual void mouseRelease(QMouseEvent *event, GenTime pos = GenTime()) = 0;
+ virtual void enterEvent(int pos, double trackHeight);
+ virtual void leaveEvent();
+ virtual void initTool(double trackHeight);
+ virtual void closeTool();
+ /** @brief returns true if the current tool is adapted to the operation mode */
+ bool isCurrent(OperationType type) const;
+ /** @brief returns the tool adapted to the operation mode */
+ AbstractToolManager::ToolManagerType getTool(OperationType type) const;
+ AbstractToolManager::ToolManagerType type() const;
+
+public slots:
+ virtual void updateTimelineItems();
protected:
+ ToolManagerType m_managerType;
CustomTrackView *m_view;
DocUndoStack *m_commandStack;
};
diff --git a/src/timeline/managers/guidemanager.cpp b/src/timeline/managers/guidemanager.cpp
index 136a8cb..b144808 100644
--- a/src/timeline/managers/guidemanager.cpp
+++ b/src/timeline/managers/guidemanager.cpp
@@ -25,11 +25,11 @@
#include <QMouseEvent>
#include <QGraphicsItem>
-GuideManager::GuideManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(view, commandStack)
+GuideManager::GuideManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(GuideType, view, commandStack)
{
}
-bool GuideManager::mousePress(ItemInfo info, Qt::KeyboardModifiers, QList<QGraphicsItem *> list)
+bool GuideManager::mousePress(QMouseEvent *, ItemInfo info, QList<QGraphicsItem *> list)
{
Q_UNUSED(info);
m_collisionList = list;
@@ -49,12 +49,13 @@ bool GuideManager::mousePress(ItemInfo info, Qt::KeyboardModifiers, QList<QGraph
return false;
}
-void GuideManager::mouseMove(int pos)
+bool GuideManager::mouseMove(QMouseEvent *event, int pos, int)
{
- Q_UNUSED(pos);
+ event->accept();
+ return false;
}
-void GuideManager::mouseRelease(GenTime pos)
+void GuideManager::mouseRelease(QMouseEvent *, GenTime pos)
{
m_view->setCursor(Qt::ArrowCursor);
m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, false);
diff --git a/src/timeline/managers/guidemanager.h b/src/timeline/managers/guidemanager.h
index db68ba2..9c002e0 100644
--- a/src/timeline/managers/guidemanager.h
+++ b/src/timeline/managers/guidemanager.h
@@ -38,9 +38,9 @@ class GuideManager : public AbstractToolManager
public:
explicit GuideManager(CustomTrackView *view, DocUndoStack *commandStack = NULL);
- bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier, QList<QGraphicsItem *> list = QList<QGraphicsItem *>());
- void mouseMove(int pos = 0);
- void mouseRelease(GenTime pos = GenTime());
+ bool mousePress(QMouseEvent *event, ItemInfo info = ItemInfo(), QList<QGraphicsItem *> list = QList<QGraphicsItem *>());
+ void mouseRelease(QMouseEvent *event, GenTime pos = GenTime());
+ bool mouseMove(QMouseEvent *event, int pos, int);
/** @brief Check if a guide operation is applicable on items under mouse.
* @param items The list of items under mouse
* @param operationMode Will be set to MoveGuide if applicable
diff --git a/src/timeline/managers/movemanager.cpp b/src/timeline/managers/movemanager.cpp
index 1c59f2f..3772437 100644
--- a/src/timeline/managers/movemanager.cpp
+++ b/src/timeline/managers/movemanager.cpp
@@ -27,28 +27,63 @@
#include "timeline/transitionhandler.h"
#include <KLocalizedString>
+#include <QScrollBar>
+#include <QFontMetrics>
+#include <QApplication>
-MoveManager::MoveManager(TransitionHandler *handler, CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(view, commandStack)
+MoveManager::MoveManager(TransitionHandler *handler, CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(MoveType, view, commandStack)
, m_transitionHandler(handler)
+ , m_scrollOffset(0)
+ , m_scrollTrigger(QFontMetrics(view->font()).averageCharWidth() * 3)
+ , m_dragMoved(false)
{
+ connect(&m_scrollTimer, SIGNAL(timeout()), this, SLOT(slotCheckMouseScrolling()));
+ m_scrollTimer.setInterval(100);
+ m_scrollTimer.setSingleShot(true);
}
-bool MoveManager::mousePress(ItemInfo info, Qt::KeyboardModifiers , QList<QGraphicsItem *>)
+bool MoveManager::mousePress(QMouseEvent *event, ItemInfo info, QList<QGraphicsItem *>)
{
m_view->setCursor(Qt::ClosedHandCursor);
+ m_dragMoved = false;
+ m_clickPoint = event->pos();
m_dragItemInfo = info;
+ m_view->setOperationMode(MoveOperation);
return true;
}
-void MoveManager::mouseMove(int pos)
+bool MoveManager::mouseMove(QMouseEvent *event, int , int)
{
- Q_UNUSED(pos);
+ if (!m_dragMoved && event->buttons() & Qt::LeftButton) {
+ if ((m_clickPoint - event->pos()).manhattanLength() < QApplication::startDragDistance()) {
+ event->ignore();
+ return false;
+ }
+ m_dragMoved = true;
+ }
+ if (m_dragItemInfo.isValid()) {
+ if (event->pos().x() < m_scrollTrigger) {
+ m_scrollOffset = -30;
+ m_scrollTimer.start();
+ } else if (m_view->viewport()->width() - event->pos().x() < m_scrollTrigger) {
+ m_scrollOffset = 30;
+ m_scrollTimer.start();
+ } else if (m_scrollTimer.isActive()) {
+ m_scrollTimer.stop();
+ }
+ event->accept();
+ return false;
+ }
+ return true;
}
-void MoveManager::mouseRelease(GenTime pos)
+void MoveManager::mouseRelease(QMouseEvent *, GenTime pos)
{
Q_UNUSED(pos);
+ if (m_scrollTimer.isActive()) m_scrollTimer.stop();
m_view->setCursor(Qt::OpenHandCursor);
+ if (!m_dragMoved)
+ return;
AbstractClipItem *dragItem = m_view->dragItem();
if (!dragItem || !m_dragItemInfo.isValid() || m_view->operationMode() == WaitingForConfirm) {
// No move performed
@@ -321,3 +356,12 @@ void MoveManager::mouseRelease(GenTime pos)
}
+void MoveManager::slotCheckMouseScrolling()
+{
+ if (m_scrollOffset == 0) {
+ m_scrollTimer.stop();
+ return;
+ }
+ m_view->horizontalScrollBar()->setValue(m_view->horizontalScrollBar()->value() + m_scrollOffset);
+ m_scrollTimer.start();
+}
diff --git a/src/timeline/managers/movemanager.h b/src/timeline/managers/movemanager.h
index 60d0d19..cceb5c2 100644
--- a/src/timeline/managers/movemanager.h
+++ b/src/timeline/managers/movemanager.h
@@ -22,6 +22,9 @@
#include "abstracttoolmanager.h"
+#include <QTimer>
+#include <QPoint>
+
class TransitionHandler;
/**
@@ -35,13 +38,21 @@ class MoveManager : public AbstractToolManager
public:
explicit MoveManager(TransitionHandler *handler, CustomTrackView *view, DocUndoStack *commandStack = NULL);
- bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier, QList<QGraphicsItem *> list = QList<QGraphicsItem *>());
- void mouseMove(int pos = 0);
- void mouseRelease(GenTime pos = GenTime());
+ bool mousePress(QMouseEvent *event, ItemInfo info = ItemInfo(), QList<QGraphicsItem *> list = QList<QGraphicsItem *>());
+ void mouseRelease(QMouseEvent *event, GenTime pos = GenTime());
+ bool mouseMove(QMouseEvent *event, int pos, int);
private:
ItemInfo m_dragItemInfo;
TransitionHandler *m_transitionHandler;
+ int m_scrollOffset;
+ int m_scrollTrigger;
+ QTimer m_scrollTimer;
+ bool m_dragMoved;
+ QPoint m_clickPoint;
+
+private slots:
+ void slotCheckMouseScrolling();
};
#endif
diff --git a/src/timeline/managers/razormanager.cpp b/src/timeline/managers/razormanager.cpp
index 35e3328..20f9e11 100644
--- a/src/timeline/managers/razormanager.cpp
+++ b/src/timeline/managers/razormanager.cpp
@@ -23,16 +23,23 @@
#include "timeline/clipitem.h"
#include "timeline/abstractgroupitem.h"
#include "timeline/timelinecommands.h"
+#include "utils/KoIconUtils.h"
#include <QMouseEvent>
+#include <QIcon>
#include <QGraphicsItem>
+#include <QGraphicsLineItem>
#include <klocalizedstring.h>
-RazorManager::RazorManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(view, commandStack)
+
+RazorManager::RazorManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(RazorType, view, commandStack)
+ , m_cutLine(NULL)
{
+ QIcon razorIcon = KoIconUtils::themedIcon(QStringLiteral("edit-cut"));
+ m_cursor = QCursor(razorIcon.pixmap(32, 32));
}
-bool RazorManager::mousePress(ItemInfo info, Qt::KeyboardModifiers, QList<QGraphicsItem *>)
+bool RazorManager::mousePress(QMouseEvent *, ItemInfo info, QList<QGraphicsItem *>)
{
QList<QGraphicsItem *> items;
AbstractClipItem *dragItem = m_view->dragItem();
@@ -47,12 +54,63 @@ bool RazorManager::mousePress(ItemInfo info, Qt::KeyboardModifiers, QList<QGraph
return true;
}
-void RazorManager::mouseMove(int pos)
+void RazorManager::enterEvent(int, double trackHeight)
{
- Q_UNUSED(pos);
+ buildCutLine(trackHeight);
+}
+
+void RazorManager::initTool(double trackHeight)
+{
+ buildCutLine(trackHeight);
+ m_view->setCursor(m_cursor);
+}
+
+void RazorManager::buildCutLine(double trackHeight)
+{
+ if (!m_cutLine) {
+ m_cutLine = m_view->scene()->addLine(0, 0, 0, trackHeight);
+ m_cutLine->setZValue(1000);
+ QPen pen1 = QPen();
+ pen1.setWidth(1);
+ QColor line(Qt::red);
+ pen1.setColor(line);
+ m_cutLine->setPen(pen1);
+ m_cutLine->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
+ slotRefreshCutLine();
+ }
+}
+
+void RazorManager::leaveEvent()
+{
+ if (m_cutLine) {
+ delete m_cutLine;
+ m_cutLine = NULL;
+ }
+}
+
+void RazorManager::closeTool()
+{
+ if (m_cutLine) {
+ delete m_cutLine;
+ m_cutLine = NULL;
+ }
+}
+
+bool RazorManager::mouseMove(QMouseEvent *, int pos, int track)
+{
+ if (m_cutLine) {
+ m_cutLine->setPos(pos, track);
+ }
+ return true;
+}
+
+void RazorManager::updateTimelineItems()
+{
+ if (m_cutLine)
+ slotRefreshCutLine();
}
-void RazorManager::mouseRelease(GenTime pos)
+void RazorManager::mouseRelease(QMouseEvent *, GenTime pos)
{
Q_UNUSED(pos);
m_view->setCursor(Qt::OpenHandCursor);
@@ -77,3 +135,11 @@ void RazorManager::checkOperation(QGraphicsItem *item, CustomTrackView *view, QM
}
}
+void RazorManager::slotRefreshCutLine()
+{
+ if (m_cutLine) {
+ QPointF pos = m_view->mapToScene(m_view->mapFromGlobal(QCursor::pos()));
+ int mappedXPos = qMax((int)(pos.x()), 0);
+ m_cutLine->setPos(mappedXPos, m_view->getPositionFromTrack(m_view->getTrackFromPos(pos.y())));
+ }
+}
diff --git a/src/timeline/managers/razormanager.h b/src/timeline/managers/razormanager.h
index 84d79f5..dc4aa0f 100644
--- a/src/timeline/managers/razormanager.h
+++ b/src/timeline/managers/razormanager.h
@@ -25,7 +25,7 @@
class QGraphicsItem;
class QMouseEvent;
class CustomTrackView;
-
+class QGraphicsLineItem;
#include "abstracttoolmanager.h"
@@ -41,9 +41,13 @@ class RazorManager : public AbstractToolManager
public:
explicit RazorManager(CustomTrackView *view, DocUndoStack *commandStack = NULL);
- bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier, QList<QGraphicsItem *> list = QList<QGraphicsItem *>());
- void mouseMove(int pos = 0);
- void mouseRelease(GenTime pos = GenTime());
+ bool mousePress(QMouseEvent *event, ItemInfo info = ItemInfo(), QList<QGraphicsItem *> list = QList<QGraphicsItem *>());
+ bool mouseMove(QMouseEvent *event, int pos = 0, int track = -1);
+ void mouseRelease(QMouseEvent *event, GenTime pos = GenTime());
+ void enterEvent(int pos, double trackHeight);
+ void leaveEvent();
+ void initTool(double trackHeight);
+ void closeTool();
/** @brief Check if a guide operation is applicable on items under mouse.
* @param items The list of items under mouse
* @param operationMode Will be set to MoveGuide if applicable
@@ -51,6 +55,14 @@ public:
**/
static void checkOperation(QGraphicsItem *item, CustomTrackView *view, QMouseEvent *event, int eventPos, OperationType &operationMode, bool &abort);
+public slots:
+ void slotRefreshCutLine();
+ void updateTimelineItems();
+
+private:
+ QGraphicsLineItem *m_cutLine;
+ QCursor m_cursor;
+ void buildCutLine( double trackHeight);
};
#endif
diff --git a/src/timeline/managers/resizemanager.cpp b/src/timeline/managers/resizemanager.cpp
index fb01218..f45b987 100644
--- a/src/timeline/managers/resizemanager.cpp
+++ b/src/timeline/managers/resizemanager.cpp
@@ -28,20 +28,21 @@
#include <KLocalizedString>
-ResizeManager::ResizeManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(view, commandStack)
+ResizeManager::ResizeManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(ResizeType, view, commandStack)
{
}
-bool ResizeManager::mousePress(ItemInfo info, Qt::KeyboardModifiers modifiers, QList<QGraphicsItem *>)
+bool ResizeManager::mousePress(QMouseEvent *event, ItemInfo info, QList<QGraphicsItem *>)
{
m_dragItemInfo = info;
- m_controlModifier = modifiers;
+ m_controlModifier = event->modifiers();
AbstractClipItem *dragItem = m_view->dragItem();
AbstractGroupItem *selectionGroup = m_view->selectionGroup();
if (selectionGroup) {
m_view->resetSelectionGroup(false);
dragItem->setSelected(true);
}
+ m_view->setOperationMode(m_view->prepareMode());
m_startInfos.clear();
if (dragItem->type() == AVWidget && dragItem->parentItem()) {
// Store start infos
@@ -59,30 +60,35 @@ bool ResizeManager::mousePress(ItemInfo info, Qt::KeyboardModifiers modifiers, Q
return true;
}
-void ResizeManager::mouseMove(int pos)
+bool ResizeManager::mouseMove(QMouseEvent *event, int pos, int)
{
- AbstractClipItem *dragItem = m_view->dragItem();
- if (!(m_controlModifier & Qt::ControlModifier) && dragItem->type() == AVWidget && dragItem->parentItem()) {
- AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(dragItem->parentItem());
- if (parent) {
+ double snappedPos = m_view->getSnapPointForPos(pos);
+ if (event->buttons() & Qt::LeftButton) {
+ AbstractClipItem *dragItem = m_view->dragItem();
+ if (!(m_controlModifier & Qt::ControlModifier) && dragItem->type() == AVWidget && dragItem->parentItem()) {
+ AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(dragItem->parentItem());
+ if (parent) {
+ if (m_view->operationMode() == ResizeStart)
+ parent->resizeStart(snappedPos);
+ else
+ parent->resizeEnd(snappedPos);
+ }
+ } else {
if (m_view->operationMode() == ResizeStart)
- parent->resizeStart(pos);
- else
- parent->resizeEnd(pos);
+ dragItem->resizeStart(snappedPos, true, false);
+ else
+ dragItem->resizeEnd(snappedPos,false);
}
- } else {
- if (m_view->operationMode() == ResizeStart)
- dragItem->resizeStart(pos, true, false);
- else
- dragItem->resizeEnd(pos,false);
+ QString crop = m_view->timecode().getDisplayTimecode(dragItem->cropStart(), KdenliveSettings::frametimecode());
+ QString duration = m_view->timecode().getDisplayTimecode(dragItem->cropDuration(), KdenliveSettings::frametimecode());
+ QString offset = m_view->timecode().getDisplayTimecode(dragItem->cropStart() - m_dragItemInfo.cropStart, KdenliveSettings::frametimecode());
+ m_view->displayMessage(i18n("Crop from start: %1 Duration: %2 Offset: %3", crop, duration, offset), InformationMessage);
+ event->accept();
}
- QString crop = m_view->timecode().getDisplayTimecode(dragItem->cropStart(), KdenliveSettings::frametimecode());
- QString duration = m_view->timecode().getDisplayTimecode(dragItem->cropDuration(), KdenliveSettings::frametimecode());
- QString offset = m_view->timecode().getDisplayTimecode(dragItem->cropStart() - m_dragItemInfo.cropStart, KdenliveSettings::frametimecode());
- m_view->displayMessage(i18n("Crop from start: %1 Duration: %2 Offset: %3", crop, duration, offset), InformationMessage);
+ return true;
}
-void ResizeManager::mouseRelease(GenTime pos)
+void ResizeManager::mouseRelease(QMouseEvent *, GenTime pos)
{
Q_UNUSED(pos);
AbstractClipItem *dragItem = m_view->dragItem();
diff --git a/src/timeline/managers/resizemanager.h b/src/timeline/managers/resizemanager.h
index 0714f64..c5da3f1 100644
--- a/src/timeline/managers/resizemanager.h
+++ b/src/timeline/managers/resizemanager.h
@@ -34,9 +34,9 @@ class ResizeManager : public AbstractToolManager
public:
explicit ResizeManager(CustomTrackView *view, DocUndoStack *commandStack = NULL);
- bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier, QList<QGraphicsItem *> list = QList<QGraphicsItem *>());
- void mouseMove(int pos = 0);
- void mouseRelease(GenTime pos = GenTime());
+ bool mousePress(QMouseEvent *event, ItemInfo info = ItemInfo(), QList<QGraphicsItem *> list = QList<QGraphicsItem *>());
+ bool mouseMove(QMouseEvent *event, int pos = 0, int track = -1);
+ void mouseRelease(QMouseEvent *event, GenTime pos = GenTime());
private:
ItemInfo m_dragItemInfo;
diff --git a/src/timeline/managers/selectmanager.cpp b/src/timeline/managers/selectmanager.cpp
index 2d90900..b85e7c0 100644
--- a/src/timeline/managers/selectmanager.cpp
+++ b/src/timeline/managers/selectmanager.cpp
@@ -21,6 +21,9 @@
#include "timeline/customtrackview.h"
#include "timeline/clipitem.h"
#include "timeline/abstractgroupitem.h"
+#include "kdenlivesettings.h"
+#include "mainwindow.h"
+#include "timeline/timelinecommands.h"
#include <KLocalizedString>
#include <QProcess>
@@ -31,45 +34,254 @@
#include "klocalizedstring.h"
-SelectManager::SelectManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(view, commandStack)
+SelectManager::SelectManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(SelectType, view, commandStack)
+ , m_dragMoved(false)
{
}
-bool SelectManager::mousePress(ItemInfo info, Qt::KeyboardModifiers modifiers, QList<QGraphicsItem *>)
+bool SelectManager::mousePress(QMouseEvent *event, ItemInfo info, QList<QGraphicsItem *>)
{
Q_UNUSED(info);
- m_modifiers = modifiers;
+ m_view->activateMonitor();
+ m_modifiers = event->modifiers();
+ m_dragMoved = false;
+ m_clickPoint = event->pos();
if (m_modifiers & Qt::ShiftModifier) {
- m_view->createRectangleSelection(modifiers);
+ m_view->createRectangleSelection(event->modifiers());
return true;
}
- m_view->activateMonitor();
+ // No item under click
+ AbstractClipItem *dragItem = m_view->dragItem();
+ if (dragItem == NULL) {
+ m_view->clearSelection(true);
+ if (event->button() == Qt::LeftButton) {
+ m_view->setOperationMode(Seek);
+ m_view->seekCursorPos((int) m_view->mapToScene(event->pos()).x());
+ event->setAccepted(true);
+ return true;
+ }
+ } else m_view->setOperationMode(m_view->prepareMode());
+ switch(m_view->operationMode()) {
+ case FadeIn:
+ case FadeOut:
+ //m_view->setCursor(Qt::PointingHandCursor);
+ break;
+ case KeyFrame:
+ //m_view->setCursor(Qt::PointingHandCursor);
+ dragItem->prepareKeyframeMove();
+ break;
+ default:
+ //m_view->setCursor(Qt::ArrowCursor);
+ break;
+ }
return false;
}
-void SelectManager::mouseMove(int pos)
+bool SelectManager::mouseMove(QMouseEvent *event, int pos, int)
{
- Q_UNUSED(pos);
+ OperationType mode = m_view->operationMode();
+ if (mode == Seek) {
+ return false;
+ }
+ if (!m_dragMoved && event->buttons() & Qt::LeftButton) {
+ if ((m_clickPoint - event->pos()).manhattanLength() < QApplication::startDragDistance()) {
+ event->ignore();
+ return false;
+ }
+ m_dragMoved = true;
+ }
+ if (mode == FadeIn) {
+ AbstractClipItem *dragItem = m_view->dragItem();
+ double mappedXPos = m_view->mapToScene(event->pos()).x();
+ static_cast<ClipItem*>(dragItem)->setFadeIn(static_cast<int>(mappedXPos - dragItem->startPos().frames(m_view->fps())));
+ event->accept();
+ return true;
+ } else if (mode == FadeOut) {
+ AbstractClipItem *dragItem = m_view->dragItem();
+ double mappedXPos = m_view->mapToScene(event->pos()).x();
+ static_cast<ClipItem*>(dragItem)->setFadeOut(static_cast<int>(dragItem->endPos().frames(m_view->fps()) - mappedXPos));
+ event->accept();
+ return true;
+ } else if (mode == KeyFrame) {
+ AbstractClipItem *dragItem = m_view->dragItem();
+ double mappedXPos = m_view->mapToScene(event->pos()).x();
+ GenTime keyFramePos = GenTime(mappedXPos, m_view->fps()) - dragItem->startPos();
+ double value = dragItem->mapFromScene(m_view->mapToScene(event->pos()).toPoint()).y();
+ dragItem->updateKeyFramePos(keyFramePos.frames(m_view->fps()), value);
+ QString position = m_view->timecode().getDisplayTimecodeFromFrames(dragItem->selectedKeyFramePos(), KdenliveSettings::frametimecode());
+ m_view->displayMessage(position + " : " + QString::number(dragItem->editedKeyFrameValue()), InformationMessage);
+ event->accept();
+ return true;
+ }
+ return false;
}
-void SelectManager::mouseRelease(GenTime pos)
+void SelectManager::mouseRelease(QMouseEvent *event, GenTime pos)
{
Q_UNUSED(pos);
+ if (!m_dragMoved)
+ return;
AbstractClipItem *dragItem = m_view->dragItem();
- if (!(m_modifiers & Qt::ControlModifier)) {
- if (dragItem) dragItem->setMainSelectedClip(false);
+ OperationType moveType = m_view->operationMode();
+ if (moveType == RubberSelection) {
+ //setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
+ if (event->modifiers() != Qt::ControlModifier) {
+ if (dragItem) dragItem->setMainSelectedClip(false);
dragItem = NULL;
+ }
+ //event->accept();
+ m_view->resetSelectionGroup();
+ m_view->groupSelectedItems();
+ if (m_view->selectionGroup() == NULL && dragItem) {
+ // Only 1 item selected
+ if (dragItem->type() == AVWidget) {
+ dragItem->setMainSelectedClip(true);
+ m_view->clipItemSelected(static_cast<ClipItem *>(dragItem), false);
+ }
+ }
+ return;
}
- m_view->resetSelectionGroup();
- m_view->groupSelectedItems();
- AbstractGroupItem *selectionGroup = m_view->selectionGroup();
- if (selectionGroup == NULL && dragItem) {
- // Only 1 item selected
- if (dragItem->type() == AVWidget) {
- dragItem->setMainSelectedClip(true);
- m_view->clipItemSelected(static_cast<ClipItem *>(dragItem), false);
+ if (moveType == Seek || moveType == WaitingForConfirm || moveType == None || (!m_dragMoved && moveType == MoveOperation)) {
+ if (!(m_modifiers & Qt::ControlModifier)) {
+ if (dragItem) dragItem->setMainSelectedClip(false);
+ dragItem = NULL;
+ }
+ m_view->resetSelectionGroup();
+ m_view->groupSelectedItems();
+ AbstractGroupItem *selectionGroup = m_view->selectionGroup();
+ if (selectionGroup == NULL && dragItem) {
+ // Only 1 item selected
+ if (dragItem->type() == AVWidget) {
+ dragItem->setMainSelectedClip(true);
+ m_view->clipItemSelected(static_cast<ClipItem *>(dragItem), false);
+ }
}
}
+ if (moveType == FadeIn && dragItem) {
+ ClipItem * item = static_cast <ClipItem *>(dragItem);
+ // find existing video fade, if none then audio fade
+
+ int fadeIndex = item->hasEffect(QLatin1String(""), QStringLiteral("fade_from_black"));
+ int fadeIndex2 = item->hasEffect(QStringLiteral("volume"), QStringLiteral("fadein"));
+ if (fadeIndex >= 0 && fadeIndex2 >= 0) {
+ // We have 2 fadin effects, use currently selected or first one
+ int current = item->selectedEffectIndex();
+ if (fadeIndex != current) {
+ if (fadeIndex2 == current) {
+ fadeIndex = current;
+ }
+ else fadeIndex = qMin(fadeIndex, fadeIndex2);
+ }
+ }
+ else fadeIndex = qMax(fadeIndex, fadeIndex2);
+ // resize fade in effect
+ if (fadeIndex >= 0) {
+ QDomElement oldeffect = item->effectAtIndex(fadeIndex);
+ int end = item->fadeIn();
+ if (end == 0) {
+ m_view->slotDeleteEffect(item, -1, oldeffect, false);
+ } else {
+ int start = item->cropStart().frames(m_view->fps());
+ end += start;
+ QDomElement effect = oldeffect.cloneNode().toElement();
+ EffectsList::setParameter(oldeffect, QStringLiteral("in"), QString::number(start));
+ EffectsList::setParameter(oldeffect, QStringLiteral("out"), QString::number(end));
+ m_view->slotUpdateClipEffect(item, -1, effect, oldeffect, fadeIndex);
+ m_view->clipItemSelected(item);
+ }
+ // new fade in
+ } else if (item->fadeIn() != 0) {
+ QDomElement effect;
+ if (item->clipState() == PlaylistState::VideoOnly || (item->clipType() != Audio && item->clipState() != PlaylistState::AudioOnly && item->clipType() != Playlist)) {
+ effect = MainWindow::videoEffects.getEffectByTag(QLatin1String(""), QStringLiteral("fade_from_black")).cloneNode().toElement();
+ } else {
+ effect = MainWindow::audioEffects.getEffectByTag(QStringLiteral("volume"), QStringLiteral("fadein")).cloneNode().toElement();
+ }
+ EffectsList::setParameter(effect, QStringLiteral("out"), QString::number(item->fadeIn()));
+ m_view->slotAddEffect(effect, dragItem->startPos(), dragItem->track());
+ }
+
+ } else if (moveType == FadeOut && dragItem) {
+ ClipItem * item = static_cast <ClipItem *>(dragItem);
+ // find existing video fade, if none then audio fade
+
+ int fadeIndex = item->hasEffect(QLatin1String(""), QStringLiteral("fade_to_black"));
+ int fadeIndex2 = item->hasEffect(QStringLiteral("volume"), QStringLiteral("fadeout"));
+ if (fadeIndex >= 0 && fadeIndex2 >= 0) {
+ // We have 2 fadin effects, use currently selected or first one
+ int current = item->selectedEffectIndex();
+ if (fadeIndex != current) {
+ if (fadeIndex2 == current) {
+ fadeIndex = current;
+ }
+ else fadeIndex = qMin(fadeIndex, fadeIndex2);
+ }
+ }
+ else fadeIndex = qMax(fadeIndex, fadeIndex2);
+ // resize fade out effect
+ if (fadeIndex >= 0) {
+ QDomElement oldeffect = item->effectAtIndex(fadeIndex);
+ int start = item->fadeOut();
+ if (start == 0) {
+ m_view->slotDeleteEffect(item, -1, oldeffect, false);
+ } else {
+ int end = (item->cropDuration() + item->cropStart()).frames(m_view->fps());
+ start = end - start;
+ QDomElement effect = oldeffect.cloneNode().toElement();
+ EffectsList::setParameter(oldeffect, QStringLiteral("in"), QString::number(start));
+ EffectsList::setParameter(oldeffect, QStringLiteral("out"), QString::number(end));
+ m_view->slotUpdateClipEffect(item, -1, effect, oldeffect, fadeIndex);
+ m_view->clipItemSelected(item);
+ }
+ // new fade out
+ } else if (item->fadeOut() != 0) {
+ QDomElement effect;
+ if (item->clipState() == PlaylistState::VideoOnly || (item->clipType() != Audio && item->clipState() != PlaylistState::AudioOnly && item->clipType() != Playlist)) {
+ effect = MainWindow::videoEffects.getEffectByTag(QLatin1String(""), QStringLiteral("fade_to_black")).cloneNode().toElement();
+ } else {
+ effect = MainWindow::audioEffects.getEffectByTag(QStringLiteral("volume"), QStringLiteral("fadeout")).cloneNode().toElement();
+ }
+ int end = (item->cropDuration() + item->cropStart()).frames(m_view->fps());
+ int start = end-item->fadeOut();
+ EffectsList::setParameter(effect, QStringLiteral("in"), QString::number(start));
+ EffectsList::setParameter(effect, QStringLiteral("out"), QString::number(end));
+ m_view->slotAddEffect(effect, dragItem->startPos(), dragItem->track());
+ }
+
+ } else if (moveType == KeyFrame && dragItem && m_dragMoved) {
+ // update the MLT effect
+ ClipItem * item = static_cast <ClipItem *>(dragItem);
+ QDomElement oldEffect = item->selectedEffect().cloneNode().toElement();
+
+ // check if we want to remove keyframe
+ double val = m_view->mapToScene(event->pos()).toPoint().y();
+ QRectF br = item->sceneBoundingRect();
+ double maxh = 100.0 / br.height();
+ val = (br.bottom() - val) * maxh;
+ int start = item->cropStart().frames(m_view->fps());
+ int end = (item->cropStart() + item->cropDuration()).frames(m_view->fps()) - 1;
+
+ if ((val < -50 || val > 150) && item->selectedKeyFramePos() != start && item->selectedKeyFramePos() != end && item->keyframesCount() > 1) {
+ //delete keyframe
+ item->removeKeyframe(item->getEffectAtIndex(item->selectedEffectIndex()), item->selectedKeyFramePos());
+ } else {
+ item->movedKeyframe(item->getEffectAtIndex(item->selectedEffectIndex()), item->selectedKeyFramePos(), item->originalKeyFramePos());
+ }
+
+ QDomElement newEffect = item->selectedEffect().cloneNode().toElement();
+
+ EditEffectCommand *command = new EditEffectCommand(m_view, item->track(), item->startPos(), oldEffect, newEffect, item->selectedEffectIndex(), false, false, true);
+ m_commandStack->push(command);
+ m_view->updateEffect(item->track(), item->startPos(), item->selectedEffect());
+ m_view->clipItemSelected(item);
+ } else if (moveType == KeyFrame && dragItem) {
+ m_view->setActiveKeyframe(dragItem->selectedKeyFramePos());
+ }
+}
+
+void SelectManager::initTool(double)
+{
+ m_view->unsetCursor();
}
void SelectManager::checkOperation(QGraphicsItem *item, CustomTrackView *view, QMouseEvent *event, AbstractGroupItem *group, OperationType &operationMode, OperationType moveOperation)
diff --git a/src/timeline/managers/selectmanager.h b/src/timeline/managers/selectmanager.h
index bc15696..2a4f17d 100644
--- a/src/timeline/managers/selectmanager.h
+++ b/src/timeline/managers/selectmanager.h
@@ -38,17 +38,20 @@ class SelectManager : public AbstractToolManager
public:
explicit SelectManager(CustomTrackView *view, DocUndoStack *commandStack = NULL);
- bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier, QList<QGraphicsItem *> list = QList<QGraphicsItem *>());
- void mouseMove(int pos);
- void mouseRelease(GenTime pos = GenTime());
+ bool mousePress(QMouseEvent *event, ItemInfo info = ItemInfo(), QList<QGraphicsItem *> list = QList<QGraphicsItem *>());
+ void mouseRelease(QMouseEvent *event, GenTime pos = GenTime());
+ bool mouseMove(QMouseEvent *event, int pos, int);
/** @brief Check if a guide operation is applicable on items under mouse.
* @param item The item under mouse
* @param operationMode Will be set to under mouse operation if applicable
* @param abort Will be set to true if an operation matched and the items list should not be tested for further operation modes
**/
static void checkOperation(QGraphicsItem *item, CustomTrackView *view, QMouseEvent *event, AbstractGroupItem *group, OperationType &operationMode, OperationType moveOperation);
+ void initTool(double trackHeight);
private:
Qt::KeyboardModifiers m_modifiers;
+ bool m_dragMoved;
+ QPoint m_clickPoint;
};
#endif
diff --git a/src/timeline/managers/spacermanager.cpp b/src/timeline/managers/spacermanager.cpp
index 0fa3fd4..7eafa30 100644
--- a/src/timeline/managers/spacermanager.cpp
+++ b/src/timeline/managers/spacermanager.cpp
@@ -20,28 +20,34 @@
#include "spacermanager.h"
#include "timeline/customtrackview.h"
#include "timeline/clipitem.h"
+#include "timeline/abstractgroupitem.h"
#include <KLocalizedString>
#include <QProcess>
#include <QGraphicsItem>
+#include <QApplication>
-
-SpacerManager::SpacerManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(view, commandStack)
+SpacerManager::SpacerManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(SpacerType, view, commandStack)
+ , m_dragMoved(false)
{
}
-bool SpacerManager::mousePress(ItemInfo info, Qt::KeyboardModifiers modifiers, QList<QGraphicsItem *>)
+bool SpacerManager::mousePress(QMouseEvent *event, ItemInfo info, QList<QGraphicsItem *>)
{
m_view->clearSelection();
m_view->updateClipTypeActions(NULL);
m_view->setOperationMode(Spacer);
+ m_dragMoved = false;
+ m_clickPoint = event->pos();
QList<QGraphicsItem *> selection;
- if (modifiers & Qt::ControlModifier) {
+ if (event->modifiers() & Qt::ControlModifier) {
// Ctrl + click, select all items on track after click position
m_track = info.track;
- if (m_view->spaceToolSelectTrackOnly(info.track, selection))
- return true;
+ if (m_view->spaceToolSelectTrackOnly(info.track, selection)) {
+ event->accept();
+ return false;
+ }
} else {
m_track = -1;
// Select all items on all tracks after click position
@@ -49,20 +55,43 @@ bool SpacerManager::mousePress(ItemInfo info, Qt::KeyboardModifiers modifiers, Q
}
m_startPos = m_view->createGroupForSelectedItems(selection);
m_spacerOffset = m_startPos - info.startPos;
- return true;
+ event->accept();
+ return false;
}
-void SpacerManager::mouseMove(int pos)
+void SpacerManager::initTool(double )
{
+ qDebug()<<"* ** INIT SPACER";
m_view->setCursor(Qt::SplitHCursor);
- int snappedPos = m_view->getSnapPointForPos(pos + m_spacerOffset.frames(m_view->fps()));
- if (snappedPos < 0) snappedPos = 0;
- m_view->spaceToolMoveToSnapPos(snappedPos);
}
-void SpacerManager::mouseRelease(GenTime pos)
+bool SpacerManager::mouseMove(QMouseEvent *event, int pos, int )
+{
+ if (event->buttons() & Qt::LeftButton) {
+ if (!m_dragMoved) {
+ if ((m_clickPoint - event->pos()).manhattanLength() < QApplication::startDragDistance()) {
+ event->ignore();
+ return false;
+ }
+ m_dragMoved = true;
+ }
+ int snappedPos = m_view->getSnapPointForPos(pos + m_spacerOffset.frames(m_view->fps()));
+ if (snappedPos < 0) snappedPos = 0;
+ m_view->spaceToolMoveToSnapPos(snappedPos);
+ event->accept();
+ return true;
+ }
+ return false;
+}
+
+void SpacerManager::mouseRelease(QMouseEvent *, GenTime pos)
{
- GenTime timeOffset = pos - m_startPos;
+ //GenTime timeOffset = pos - m_startPos;
+ if (!m_dragMoved || !m_view->selectionGroup()) {
+ m_view->clearSelection();
+ return;
+ }
+ GenTime timeOffset = GenTime(m_view->selectionGroup()->sceneBoundingRect().left(), m_view->fps()) - m_startPos;
m_view->completeSpaceOperation(m_track, timeOffset);
}
diff --git a/src/timeline/managers/spacermanager.h b/src/timeline/managers/spacermanager.h
index 9678b4b..4aa0346 100644
--- a/src/timeline/managers/spacermanager.h
+++ b/src/timeline/managers/spacermanager.h
@@ -35,14 +35,17 @@ class SpacerManager : public AbstractToolManager
public:
explicit SpacerManager(CustomTrackView *view, DocUndoStack *commandStack = NULL);
- bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier, QList<QGraphicsItem *> list = QList<QGraphicsItem *>());
- void mouseMove(int pos = 0);
- void mouseRelease(GenTime pos = GenTime());
+ bool mousePress(QMouseEvent *event, ItemInfo info = ItemInfo(), QList<QGraphicsItem *> list = QList<QGraphicsItem *>());
+ bool mouseMove(QMouseEvent *event, int pos = 0, int track = -1);
+ void mouseRelease(QMouseEvent *event, GenTime pos = GenTime());
+ void initTool(double trackHeight);
private:
int m_track;
GenTime m_startPos;
GenTime m_spacerOffset;
+ bool m_dragMoved;
+ QPoint m_clickPoint;
};
#endif
diff --git a/src/timeline/managers/trimmanager.cpp b/src/timeline/managers/trimmanager.cpp
index b747f25..d518de5 100644
--- a/src/timeline/managers/trimmanager.cpp
+++ b/src/timeline/managers/trimmanager.cpp
@@ -21,50 +21,59 @@
#include "kdenlivesettings.h"
#include "timeline/customtrackview.h"
#include "timeline/clipitem.h"
+#include "renderer.h"
#include <KLocalizedString>
#include <QtConcurrent>
#include <QStandardPaths>
#include <QProcess>
+#include <mlt++/MltPlaylist.h>
-
-TrimManager::TrimManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(view, commandStack)
+TrimManager::TrimManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(TrimType, view, commandStack)
, m_firstClip(NULL)
, m_secondClip(NULL)
, m_trimMode(NormalTrim)
+ , m_rippleIndex(0)
+ , m_trimPlaylist(NULL)
+ , trimChanged(false)
{
}
-bool TrimManager::mousePress(ItemInfo info, Qt::KeyboardModifiers, QList<QGraphicsItem *>)
+bool TrimManager::mousePress(QMouseEvent *, ItemInfo info, QList<QGraphicsItem *>)
{
return enterTrimMode(info, m_view->prepareMode() == ResizeStart);
}
-void TrimManager::mouseMove(int pos)
+bool TrimManager::mouseMove(QMouseEvent *event, int pos, int)
{
- if (!m_firstInfo.isValid() || !m_secondInfo.isValid())
- return;
- if (pos < m_firstClip->endPos().frames(m_view->fps())) {
- m_firstClip->resizeEnd(pos, false);
- m_secondClip->resizeStart(pos, true, false);
- } else {
- m_secondClip->resizeStart(pos, true, false);
- m_firstClip->resizeEnd(pos, false);
+ if (event->buttons() & Qt::LeftButton) {
+ if (!m_firstInfo.isValid() || !m_secondInfo.isValid())
+ return false;
+ double snappedPos = m_view->getSnapPointForPos(pos);
+ if (snappedPos < m_firstClip->endPos().frames(m_view->fps())) {
+ m_firstClip->resizeEnd(snappedPos, false);
+ m_secondClip->resizeStart(snappedPos, true, false);
+ } else {
+ m_secondClip->resizeStart(snappedPos, true, false);
+ m_firstClip->resizeEnd(snappedPos, false);
+ }
+ m_view->seekCursorPos(snappedPos);
+ return true;
}
- m_view->seekCursorPos(pos);
+ return false;
}
-void TrimManager::mouseRelease(GenTime)
+void TrimManager::mouseRelease(QMouseEvent *, GenTime)
{
- endRoll();
+ endTrim();
}
bool TrimManager::enterTrimMode(ItemInfo info, bool trimStart)
{
m_view->loadMonitorScene(MonitorSceneRipple, true);
m_view->setQmlProperty(QStringLiteral("trimmode"), (int) m_trimMode);
- if (m_trimMode == RollingTrim) {
+ if (m_trimMode == RollingTrim || m_trimMode == RippleTrim) {
if (trimStart) {
m_firstClip = m_view->getClipItemAtEnd(info.startPos, info.track);
m_secondClip = m_view->getClipItemAtStart(info.startPos, info.track);
@@ -85,16 +94,58 @@ bool TrimManager::enterTrimMode(ItemInfo info, bool trimStart)
m_view->resetSelectionGroup(false);
dragItem->setSelected(true);
}
- m_view->setOperationMode(trimStart ? RollingStart : RollingEnd);
m_firstInfo = m_firstClip->info();
m_secondInfo = m_secondClip->info();
- m_view->trimMode(true);
+ if (m_trimMode == RollingTrim) {
+ m_view->setOperationMode(trimStart ? RollingStart : RollingEnd);
+ } else if (m_trimMode == RippleTrim) {
+ m_view->setOperationMode(trimStart ? RippleStart : RippleEnd);
+ }
+ m_view->trimMode(true, m_secondInfo.startPos.frames(m_view->fps()));
m_view->seekCursorPos(trimStart ? info.startPos.frames(m_view->fps()) : info.endPos.frames(m_view->fps()));
- return true;
+ }
+ if (m_trimMode == RippleTrim) {
+ m_render->byPassSeek = true;
+ connect(m_render, SIGNAL(renderSeek(int)), this, SLOT(renderSeekRequest(int)), Qt::UniqueConnection);
+ } else if (m_render->byPassSeek) {
+ m_render->byPassSeek = false;
+ disconnect(m_render, SIGNAL(renderSeek(int)), this, SLOT(renderSeekRequest(int)));
}
return true;
}
+void TrimManager::initRipple(Mlt::Playlist *playlist, int pos, Render *renderer)
+{
+ m_render = renderer;
+ connect(renderer, SIGNAL(renderSeek(int)), this, SLOT(renderSeekRequest(int)));
+ m_trimPlaylist = playlist;
+ m_rippleIndex = playlist->get_clip_index_at(pos);
+}
+
+void TrimManager::renderSeekRequest(int diff)
+{
+ qDebug()<<" + + +RIPPLE DIFF: "<<diff;
+ Mlt::ClipInfo *cInfo = m_trimPlaylist->clip_info(m_rippleIndex);
+ int in = cInfo->frame_in;
+ int out = cInfo->frame_out;
+ qDebug()<<"* * *RESITE CLIP FIRST IN: "<<in<<"-"<<out<<", "<<cInfo->start<<", "<<cInfo->length;
+ delete cInfo;
+ ClipItem *clipToRipple = NULL;
+ if (m_view->operationMode() == RippleStart) {
+ in -= diff;
+ clipToRipple = m_secondClip;
+ } else {
+ out += diff;
+ clipToRipple = m_firstClip;
+ m_render->seekToFrame(m_firstClip->endPos().frames(m_view->fps()) + diff);
+ }
+ qDebug()<<"* * *RESITE CLIP IN: "<<in;
+ m_trimPlaylist->resize_clip(m_rippleIndex, in, out);
+ m_render->doRefresh();
+ m_view->rippleClip(clipToRipple, diff);
+ trimChanged = true;
+}
+
void TrimManager::moveRoll(bool forward, int pos)
{
if (!m_firstInfo.isValid() || !m_secondInfo.isValid())
@@ -117,25 +168,43 @@ void TrimManager::moveRoll(bool forward, int pos)
}
//m_view->seekCursorPos(pos);
KdenliveSettings::setSnaptopoints(snap);
+ trimChanged = true;
}
-void TrimManager::endRoll()
+void TrimManager::endTrim()
{
+ m_view->trimMode(false);
if (!m_firstInfo.isValid() || !m_secondInfo.isValid())
+ return;
+ if (m_render->byPassSeek) {
+ m_render->byPassSeek = false;
+ disconnect(m_render, SIGNAL(renderSeek(int)), this, SLOT(renderSeekRequest(int)));
+ }
+ if (m_view->operationMode() == RippleStart || m_view->operationMode() == RippleEnd) {
+ delete m_trimPlaylist;
+ m_trimPlaylist = NULL;
+ if (m_view->operationMode() == RippleStart) {
+ m_view->finishRipple(m_secondClip, m_secondInfo, (m_secondInfo.endPos - m_secondClip->endPos()).frames(m_view->fps()), true);
+ } else {
+ m_view->finishRipple(m_firstClip, m_firstInfo, (m_firstClip->endPos() - m_firstInfo.endPos).frames(m_view->fps()), false);
+ }
+ //TODO: integrate in undo/redo framework
return;
- m_view->trimMode(false);
- QUndoCommand *command = new QUndoCommand;
- command->setText(i18n("Rolling Edit"));
- if (m_firstClip->endPos() < m_firstInfo.endPos) {
- m_view->prepareResizeClipEnd(m_firstClip, m_firstInfo, m_firstClip->startPos().frames(m_view->fps()), false, command);
- m_view->prepareResizeClipStart(m_secondClip, m_secondInfo, m_secondClip->startPos().frames(m_view->fps()), false, command);
- } else {
- m_view->prepareResizeClipStart(m_secondClip, m_secondInfo, m_secondClip->startPos().frames(m_view->fps()), false, command);
- m_view->prepareResizeClipEnd(m_firstClip, m_firstInfo, m_firstClip->startPos().frames(m_view->fps()), false, command);
}
- m_commandStack->push(command);
- m_firstInfo = ItemInfo();
- m_secondInfo = ItemInfo();
+ if (m_view->operationMode() == RollingStart || m_view->operationMode() == RollingEnd) {
+ QUndoCommand *command = new QUndoCommand;
+ command->setText(i18n("Rolling Edit"));
+ if (m_firstClip->endPos() < m_firstInfo.endPos) {
+ m_view->prepareResizeClipEnd(m_firstClip, m_firstInfo, m_firstClip->startPos().frames(m_view->fps()), false, command);
+ m_view->prepareResizeClipStart(m_secondClip, m_secondInfo, m_secondClip->startPos().frames(m_view->fps()), false, command);
+ } else {
+ m_view->prepareResizeClipStart(m_secondClip, m_secondInfo, m_secondClip->startPos().frames(m_view->fps()), false, command);
+ m_view->prepareResizeClipEnd(m_firstClip, m_firstInfo, m_firstClip->startPos().frames(m_view->fps()), false, command);
+ }
+ m_commandStack->push(command);
+ m_firstInfo = ItemInfo();
+ m_secondInfo = ItemInfo();
+ }
}
TrimMode TrimManager::trimMode() const
@@ -146,6 +215,9 @@ TrimMode TrimManager::trimMode() const
void TrimManager::setTrimMode(TrimMode mode, ItemInfo info, bool fromStart)
{
m_trimMode = mode;
+ if (trimChanged && mode != NormalTrim) {
+ endTrim();
+ }
QString modeLabel;
switch (m_trimMode) {
case RippleTrim:
@@ -162,7 +234,7 @@ void TrimManager::setTrimMode(TrimMode mode, ItemInfo info, bool fromStart)
break;
default:
emit updateTrimMode(modeLabel);
- endRoll();
+ endTrim();
return;
break;
}
diff --git a/src/timeline/managers/trimmanager.h b/src/timeline/managers/trimmanager.h
index 219215a..8241557 100644
--- a/src/timeline/managers/trimmanager.h
+++ b/src/timeline/managers/trimmanager.h
@@ -22,7 +22,12 @@
#include "abstracttoolmanager.h"
+
class ClipItem;
+class Render;
+namespace Mlt {
+ class Playlist;
+};
/**
* @namespace TrimManager
@@ -35,16 +40,20 @@ class TrimManager : public AbstractToolManager
public:
explicit TrimManager(CustomTrackView *view, DocUndoStack *commandStack = NULL);
- bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier, QList<QGraphicsItem *> list = QList<QGraphicsItem *>());
- void mouseMove(int pos);
- void mouseRelease(GenTime pos = GenTime());
+ bool mousePress(QMouseEvent *event, ItemInfo info = ItemInfo(), QList<QGraphicsItem *> list = QList<QGraphicsItem *>());
+ bool mouseMove(QMouseEvent *event, int pos, int track = -1);
+ void mouseRelease(QMouseEvent *event, GenTime pos = GenTime());
bool enterTrimMode(ItemInfo info, bool trimStart);
void moveRoll(bool forward, int pos = -1);
void setTrimMode(TrimMode mode, ItemInfo info = ItemInfo(), bool fromStart = true);
TrimMode trimMode() const;
+ void initRipple(Mlt::Playlist *playlist, int pos, Render *renderer);
public slots:
- void endRoll();
+ void endTrim();
+
+private slots:
+ void renderSeekRequest(int diff);
private:
ClipItem *m_firstClip;
@@ -52,6 +61,11 @@ private:
ItemInfo m_firstInfo;
ItemInfo m_secondInfo;
TrimMode m_trimMode;
+ int m_rippleIndex;
+ Mlt::Playlist *m_trimPlaylist;
+ bool trimChanged;
+ Render *m_render;
+ void closeRipple();
signals:
void updateTrimMode(const QString);
diff --git a/src/timeline/timeline.cpp b/src/timeline/timeline.cpp
index 94af764..402ea67 100644
--- a/src/timeline/timeline.cpp
+++ b/src/timeline/timeline.cpp
@@ -41,6 +41,7 @@
#include "effectslist/initeffects.h"
#include "mltcontroller/effectscontroller.h"
#include "managers/previewmanager.h"
+#include "managers/trimmanager.h"
#include <QScrollBar>
#include <QLocale>
@@ -1710,8 +1711,11 @@ bool Timeline::createOverlay(Mlt::Filter *filter, int tk, int startPos)
return true;
}
-bool Timeline::createRippleWindow(int tk, int startPos)
+bool Timeline::createRippleWindow(int tk, int startPos, OperationType mode)
{
+ if (m_hasOverlayTrack) {
+ return true;
+ }
Track *sourceTrack = track(tk);
if (!sourceTrack) return false;
m_tractor->lock();
@@ -1742,7 +1746,14 @@ bool Timeline::createRippleWindow(int tk, int startPos)
Mlt::Producer *cln = new Mlt::Producer(firstClip->parent());
cln->set_in_and_out(firstClip->get_in(), -1);
Clip(*cln).addEffects(*firstClip);
- int secondStart = playlist.clip_start(clipIndex) - secondClip->get_in();
+ int secondStart = playlist.clip_start(clipIndex);
+ bool rolling = m_trackview->operationMode() == RollingStart || m_trackview->operationMode() == RollingEnd;
+ if (rolling) {
+ secondStart -= secondClip->get_in();
+ } else {
+ //cln2->set_in_and_out(secondClip->get_in(), secondClip->get_out());
+ qDebug()<<"* * *INIT RIPPLE; CLP START: "<<secondClip->get_in();
+ }
int rippleStart = playlist.clip_start(clipIndex - 1);
Mlt::Filter f1(*m_tractor->profile(), "affine");
@@ -1750,14 +1761,17 @@ bool Timeline::createRippleWindow(int tk, int startPos)
f1.set("transition.always_active", 1);
cln2->attach(f1);
- Mlt::Playlist ripple1(*m_tractor->profile());
+ Mlt::Playlist *ripple1 = new Mlt::Playlist(*m_tractor->profile());
if (secondStart < 0) {
cln2->set_in_and_out(-secondStart, -1);
secondStart = 0;
}
if (secondStart > 0)
- ripple1.insert_blank(0, secondStart);
- ripple1.insert_at(secondStart, cln2, 1);
+ ripple1->insert_blank(0, secondStart);
+ ripple1->insert_at(secondStart, cln2, 1);
+ int ix = ripple1->get_clip_index_at(secondStart);
+ ripple1->resize_clip(ix, secondClip->get_in(), secondClip->get_out());
+ qDebug()<<"* * *INIT RIPPLE; REAL START: "<<cln2->get_in()<<" / "<<secondStart;
Mlt::Playlist ripple2(*m_tractor->profile());
ripple2.insert_blank(0, rippleStart);
ripple2.insert_at(rippleStart, cln, 1);
@@ -1769,7 +1783,7 @@ bool Timeline::createRippleWindow(int tk, int startPos)
t.set("geometry", "0% 0 50% 50%");
t.set("always_active", 1);
- trac.set_track(ripple1, 0);
+ trac.set_track(*ripple1, 0);
trac.set_track(ripple2, 1);
trac.plant_transition(t, 0, 1);
delete cln;
@@ -1786,6 +1800,9 @@ bool Timeline::createRippleWindow(int tk, int startPos)
delete overlayTrack;
m_hasOverlayTrack = true;
m_tractor->unlock();
+ AbstractToolManager *mgr = m_trackview->toolManager(AbstractToolManager::TrimType);
+ TrimManager *trimmer = qobject_cast<TrimManager *>(mgr);
+ trimmer->initRipple(ripple1, secondStart, m_doc->renderer());
return true;
}
diff --git a/src/timeline/timeline.h b/src/timeline/timeline.h
index f7343eb..5e317a6 100644
--- a/src/timeline/timeline.h
+++ b/src/timeline/timeline.h
@@ -158,7 +158,7 @@ public:
/** @brief Creates an overlay track with a filtered clip */
bool createOverlay(Mlt::Filter *filter, int tk, int startPos);
/** @brief Creates an overlay track with a ripple transition*/
- bool createRippleWindow(int tk, int startPos);
+ bool createRippleWindow(int tk, int startPos, OperationType mode);
void removeSplitOverlay();
/** @brief Temporarily add/remove track before saving */
void connectOverlayTrack(bool enable);
diff --git a/src/timeline/track.cpp b/src/timeline/track.cpp
index fb40416..2f78b43 100644
--- a/src/timeline/track.cpp
+++ b/src/timeline/track.cpp
@@ -1017,3 +1017,10 @@ QList <QPoint> Track::visibleClips()
delete info;
return clips;
}
+
+bool Track::resize_in_out(int pos, int in, int out)
+{
+ int ix = m_playlist.get_clip_index_at(pos);
+ m_playlist.resize_clip(ix, in, out);
+ return true;
+}
diff --git a/src/timeline/track.h b/src/timeline/track.h
index b4135d7..1b0599b 100644
--- a/src/timeline/track.h
+++ b/src/timeline/track.h
@@ -206,6 +206,7 @@ public:
bool moveEffect(double start, int oldPos, int newPos);
bool moveTrackEffect(int oldPos, int newPos);
QList <QPoint> visibleClips();
+ bool resize_in_out(int pos, int in, int out);
signals:
/** @brief notify track length change to update background