Continuing timeline refactor

parent 0c4b6e16
......@@ -183,11 +183,12 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, Timeline *timeline, CustomTra
connect(m_disableClipAction, &QAction::triggered, this, &CustomTrackView::disableClip);
m_disableClipAction->setCheckable(true);
m_document->doAddAction(QStringLiteral("clip_disabled"), m_disableClipAction, QKeySequence());
m_toolManagers.insert(TrimType, new TrimManager(this));
m_toolManagers.insert(SpacerType, new SpacerManager(this));
m_toolManagers.insert(ResizeType, new ResizeManager(this));
m_toolManagers.insert(RazorType, new RazorManager(m_commandStack, this));
m_toolManagers.insert(MoveType, new MoveManager(m_timeline->transitionHandler, this));
m_toolManagers.insert(TrimType, new TrimManager(this, m_commandStack));
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));
}
CustomTrackView::~CustomTrackView()
......@@ -673,11 +674,11 @@ void CustomTrackView::graphicsViewMouseEvent(QMouseEvent * event)
QGraphicsView::mouseMoveEvent(event);
}
void CustomTrackView::createRectangleSelection(QMouseEvent * event)
void CustomTrackView::createRectangleSelection(Qt::KeyboardModifiers modifiers)
{
setDragMode(QGraphicsView::RubberBandDrag);
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
if (!(event->modifiers() & Qt::ControlModifier)) {
if (!(modifiers & Qt::ControlModifier)) {
resetSelectionGroup();
if (m_dragItem) {
emit clipItemSelected(NULL);
......@@ -687,7 +688,6 @@ void CustomTrackView::createRectangleSelection(QMouseEvent * event)
scene()->clearSelection();
}
m_moveOpMode = RubberSelection;
QGraphicsView::mousePressEvent(event);
}
QList<QGraphicsItem *> CustomTrackView::selectAllItemsToTheRight(int x)
......@@ -829,15 +829,13 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
return;
}
if (event->button() == Qt::LeftButton) {
if (event->modifiers() & Qt::ShiftModifier && m_tool == SelectTool) {
createRectangleSelection(event);
return;
}
if (m_tool != RazorTool) activateMonitor();
else if (m_document->renderer()->isPlaying()) {
m_document->renderer()->switchPlay(false);
return;
if (m_tool == SelectTool) {
if (event->button() == Qt::LeftButton) {
if (m_toolManagers.value(SelectType)->mousePress(ItemInfo(), event->modifiers())) {
QGraphicsView::mousePressEvent(event);
return;
}
QGraphicsView::mousePressEvent(event);
}
}
......@@ -4320,7 +4318,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
m_moveOpMode = None;
return;
} else if (m_moveOpMode == Spacer) {
m_toolManagers.value(SpacerType)->mouseRelease(NULL);
m_toolManagers.value(SpacerType)->mouseRelease();
} else if (m_moveOpMode == RubberSelection) {
//setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
if (event->modifiers() != Qt::ControlModifier) {
......@@ -4345,11 +4343,11 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
return;
}
if (m_moveOpMode == MoveOperation) {
m_toolManagers.value(MoveType)->mouseRelease(m_commandStack);
m_toolManagers.value(MoveType)->mouseRelease();
} else if (m_moveOpMode == RollingStart || m_moveOpMode == RollingEnd) {
m_toolManagers.value(TrimType)->mouseRelease(m_commandStack, m_selectionGroup ? m_selectionGroup->startPos() : GenTime());
m_toolManagers.value(TrimType)->mouseRelease(m_selectionGroup ? m_selectionGroup->startPos() : GenTime());
} else if (m_moveOpMode == ResizeStart || m_moveOpMode == ResizeEnd) {
m_toolManagers.value(ResizeType)->mouseRelease(m_commandStack);
m_toolManagers.value(ResizeType)->mouseRelease();
} else if (m_moveOpMode == FadeIn && m_dragItem) {
ClipItem * item = static_cast <ClipItem *>(m_dragItem);
// find existing video fade, if none then audio fade
......
......@@ -221,7 +221,7 @@ public:
void completeSpaceOperation(int track, GenTime &timeOffset);
void spaceToolMoveToSnapPos(double snappedPos);
void createRectangleSelection(QMouseEvent * event);
void createRectangleSelection(Qt::KeyboardModifiers modifiers);
int spaceToolSelectTrackOnly(int track, QList<QGraphicsItem *> &selection);
QList<QGraphicsItem *> selectAllItemsToTheRight(int x);
GenTime createGroupForSelectedItems(QList<QGraphicsItem *> &selection);
......@@ -422,7 +422,8 @@ private:
SpacerType,
MoveType,
ResizeType,
RazorType
RazorType,
SelectType
};
int m_ct;
int m_tracksHeight;
......
......@@ -20,8 +20,9 @@
#include "abstracttoolmanager.h"
#include "timeline/customtrackview.h"
AbstractToolManager::AbstractToolManager(CustomTrackView *view) : QObject()
AbstractToolManager::AbstractToolManager(CustomTrackView *view, DocUndoStack *commandStack) : QObject()
, m_view(view)
, m_commandStack(commandStack)
{
}
......
......@@ -36,13 +36,14 @@ class AbstractToolManager : public QObject
Q_OBJECT
public:
explicit AbstractToolManager(CustomTrackView *view);
explicit AbstractToolManager(CustomTrackView *view, DocUndoStack *commandStack = NULL);
virtual bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier) = 0;
virtual void mouseMove(int pos = 0) = 0;
virtual void mouseRelease(DocUndoStack *commandStack = NULL, GenTime pos = GenTime()) = 0;
virtual void mouseRelease(GenTime pos = GenTime()) = 0;
protected:
CustomTrackView *m_view;
DocUndoStack *m_commandStack;
};
#endif
......@@ -33,7 +33,7 @@
MoveManager::MoveManager(TransitionHandler *handler, CustomTrackView *view) : AbstractToolManager(view)
MoveManager::MoveManager(TransitionHandler *handler, CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(view, commandStack)
, m_transitionHandler(handler)
{
}
......@@ -50,7 +50,7 @@ void MoveManager::mouseMove(int pos)
Q_UNUSED(pos);
}
void MoveManager::mouseRelease(DocUndoStack *commandStack, GenTime pos)
void MoveManager::mouseRelease(GenTime pos)
{
Q_UNUSED(pos);
m_view->setCursor(Qt::OpenHandCursor);
......@@ -225,7 +225,7 @@ void MoveManager::mouseRelease(DocUndoStack *commandStack, GenTime pos)
bool refresh = item->hasVisibleVideo();
if (refresh)
new RefreshMonitorCommand(m_view, QList <ItemInfo>() << info << m_dragItemInfo, false, false, moveCommand);
commandStack->push(moveCommand);
m_commandStack->push(moveCommand);
if (refresh)
m_view->monitorRefresh(QList <ItemInfo>() << info << m_dragItemInfo, true);
item = m_view->getClipItemAtStart(info.startPos, info.track, info.endPos);
......@@ -255,7 +255,7 @@ void MoveManager::mouseRelease(DocUndoStack *commandStack, GenTime pos)
m_view->updateTrackDuration(info.track, moveCommand);
if (m_dragItemInfo.track != info.track)
m_view->updateTrackDuration(m_dragItemInfo.track, moveCommand);
commandStack->push(moveCommand);
m_commandStack->push(moveCommand);
m_view->monitorRefresh(QList <ItemInfo>() << info << m_dragItemInfo, true);
m_view->updateTransitionWidget(transition, info);
}
......@@ -313,7 +313,7 @@ void MoveManager::mouseRelease(DocUndoStack *commandStack, GenTime pos)
m_view->extractZone(QPoint(cutInfo.startPos.frames(m_view->fps()), cutInfo.endPos.frames(m_view->fps())), false, updatedClipsToMove, moveGroup, -1);
}
new MoveGroupCommand(m_view, clipsToMove, transitionsToMove, timeOffset, trackOffset, true, true, moveGroup);
commandStack->push(moveGroup);
m_commandStack->push(moveGroup);
}
m_view->setOperationMode(None);
}
......
......@@ -34,10 +34,10 @@ class MoveManager : public AbstractToolManager
Q_OBJECT
public:
explicit MoveManager(TransitionHandler *handler, CustomTrackView *view);
explicit MoveManager(TransitionHandler *handler, CustomTrackView *view, DocUndoStack *commandStack = NULL);
bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier);
void mouseMove(int pos = 0);
void mouseRelease(DocUndoStack *commandStack = NULL, GenTime pos = GenTime());
void mouseRelease(GenTime pos = GenTime());
private:
ItemInfo m_dragItemInfo;
......
......@@ -28,8 +28,7 @@
#include <QGraphicsItem>
#include <klocalizedstring.h>
RazorManager::RazorManager(DocUndoStack *commandStack, CustomTrackView *view) : AbstractToolManager(view)
, m_commandStack(commandStack)
RazorManager::RazorManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(view, commandStack)
{
}
......@@ -65,7 +64,7 @@ void RazorManager::mouseMove(int pos)
Q_UNUSED(pos);
}
void RazorManager::mouseRelease(DocUndoStack *commandStack, GenTime pos)
void RazorManager::mouseRelease(GenTime pos)
{
Q_UNUSED(pos);
m_view->setCursor(Qt::OpenHandCursor);
......
......@@ -40,10 +40,10 @@ class RazorManager : public AbstractToolManager
Q_OBJECT
public:
explicit RazorManager(DocUndoStack *commandStack, CustomTrackView *view);
explicit RazorManager(CustomTrackView *view, DocUndoStack *commandStack = NULL);
bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier);
void mouseMove(int pos = 0);
void mouseRelease(DocUndoStack *commandStack = NULL, GenTime pos = GenTime());
void mouseRelease(GenTime pos = GenTime());
/** @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,9 +51,6 @@ public:
**/
static void checkOperation(QGraphicsItem *item, CustomTrackView *view, QMouseEvent *event, int eventPos, OperationType &operationMode, bool &abort);
private:
DocUndoStack *m_commandStack;
};
#endif
......
......@@ -28,7 +28,7 @@
#include <KLocalizedString>
ResizeManager::ResizeManager(CustomTrackView *view) : AbstractToolManager(view)
ResizeManager::ResizeManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(view, commandStack)
{
}
......@@ -65,8 +65,9 @@ void ResizeManager::mouseMove(int pos)
m_view->displayMessage(i18n("Crop from start: %1 Duration: %2 Offset: %3", crop, duration, offset), InformationMessage);
}
void ResizeManager::mouseRelease(DocUndoStack *commandStack, GenTime pos)
void ResizeManager::mouseRelease(GenTime pos)
{
Q_UNUSED(pos);
AbstractClipItem *dragItem = m_view->dragItem();
AbstractGroupItem *selectionGroup = m_view->selectionGroup();
if (dragItem) {
......@@ -97,7 +98,7 @@ void ResizeManager::mouseRelease(DocUndoStack *commandStack, GenTime pos)
++itemcount;
}
}
commandStack->push(resizeCommand);
m_commandStack->push(resizeCommand);
if (min < max) {
ItemInfo nfo;
nfo.startPos = min;
......@@ -163,7 +164,7 @@ void ResizeManager::mouseRelease(DocUndoStack *commandStack, GenTime pos)
}
}
m_view->updateTrackDuration(-1, resizeCommand);
commandStack->push(resizeCommand);
m_commandStack->push(resizeCommand);
if (min < max) {
ItemInfo nfo;
nfo.startPos = min;
......
......@@ -33,10 +33,10 @@ class ResizeManager : public AbstractToolManager
Q_OBJECT
public:
explicit ResizeManager(CustomTrackView *view);
explicit ResizeManager(CustomTrackView *view, DocUndoStack *commandStack = NULL);
bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier);
void mouseMove(int pos = 0);
void mouseRelease(DocUndoStack *commandStack = NULL, GenTime pos = GenTime());
void mouseRelease(GenTime pos = GenTime());
private:
ItemInfo m_dragItemInfo;
......
......@@ -18,19 +18,44 @@
***************************************************************************/
#include "selectmanager.h"
#include "../customtrackview.h"
#include "../clipitem.h"
#include "../abstractclipitem.h"
#include "../abstractgroupitem.h"
#include "../gentime.h"
#include "bin/projectclip.h"
#include "mltcontroller/clipcontroller.h"
#include "timeline/customtrackview.h"
#include "timeline/clipitem.h"
#include "timeline/abstractgroupitem.h"
#include <KLocalizedString>
#include <QProcess>
#include <QGraphicsItem>
#include <QMouseEvent>
#include <QGraphicsItem>
#include "klocalizedstring.h"
SelectManager::SelectManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(view, commandStack)
{
}
bool SelectManager::mousePress(ItemInfo info, Qt::KeyboardModifiers modifiers)
{
Q_UNUSED(info);
if (modifiers & Qt::ShiftModifier) {
m_view->createRectangleSelection(modifiers);
return true;
}
m_view->activateMonitor();
return false;
}
void SelectManager::mouseMove(int pos)
{
Q_UNUSED(pos);
}
void SelectManager::mouseRelease(GenTime pos)
{
Q_UNUSED(pos);
}
void SelectManager::checkOperation(QGraphicsItem *item, CustomTrackView *view, QMouseEvent *event, AbstractGroupItem *group, OperationType &operationMode, OperationType moveOperation)
{
OperationType currentMode = operationMode;
......
......@@ -20,7 +20,7 @@
#ifndef SELECTMANAGER_H
#define SELECTMANAGER_H
#include "definitions.h"
#include "abstracttoolmanager.h"
class QGraphicsItem;
class QMouseEvent;
......@@ -32,14 +32,21 @@ class AbstractGroupItem;
* @brief Provides convenience methods to handle selection tool.
*/
namespace SelectManager
class SelectManager : public AbstractToolManager
{
Q_OBJECT
public:
explicit SelectManager(CustomTrackView *view, DocUndoStack *commandStack = NULL);
bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier);
void mouseMove(int pos);
void mouseRelease(GenTime pos = GenTime());
/** @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
**/
void checkOperation(QGraphicsItem *item, CustomTrackView *view, QMouseEvent *event, AbstractGroupItem *group, OperationType &operationMode, OperationType moveOperation);
static void checkOperation(QGraphicsItem *item, CustomTrackView *view, QMouseEvent *event, AbstractGroupItem *group, OperationType &operationMode, OperationType moveOperation);
};
#endif
......@@ -27,7 +27,7 @@
SpacerManager::SpacerManager(CustomTrackView *view) : AbstractToolManager(view)
SpacerManager::SpacerManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(view, commandStack)
{
}
......@@ -60,9 +60,8 @@ void SpacerManager::mouseMove(int pos)
m_view->spaceToolMoveToSnapPos(snappedPos);
}
void SpacerManager::mouseRelease(DocUndoStack *commandStack, GenTime pos)
void SpacerManager::mouseRelease(GenTime pos)
{
Q_UNUSED(commandStack);
GenTime timeOffset = pos - m_startPos;
m_view->completeSpaceOperation(m_track, timeOffset);
}
......
......@@ -34,10 +34,10 @@ class SpacerManager : public AbstractToolManager
Q_OBJECT
public:
explicit SpacerManager(CustomTrackView *view);
explicit SpacerManager(CustomTrackView *view, DocUndoStack *commandStack = NULL);
bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier);
void mouseMove(int pos = 0);
void mouseRelease(DocUndoStack *commandStack = NULL, GenTime pos = GenTime());
void mouseRelease(GenTime pos = GenTime());
private:
int m_track;
......
......@@ -29,7 +29,7 @@
TrimManager::TrimManager(CustomTrackView *view) : AbstractToolManager(view)
TrimManager::TrimManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(view, commandStack)
, m_firstClip(NULL)
, m_secondClip(NULL)
{
......@@ -61,7 +61,7 @@ void TrimManager::mouseMove(int pos)
m_view->seekCursorPos(pos);
}
void TrimManager::mouseRelease(DocUndoStack *commandStack, GenTime)
void TrimManager::mouseRelease(GenTime)
{
m_view->rippleMode(false);
QUndoCommand *command = new QUndoCommand;
......@@ -73,7 +73,7 @@ void TrimManager::mouseRelease(DocUndoStack *commandStack, GenTime)
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);
}
commandStack->push(command);
m_commandStack->push(command);
}
......@@ -34,10 +34,10 @@ class TrimManager : public AbstractToolManager
Q_OBJECT
public:
explicit TrimManager(CustomTrackView *view);
explicit TrimManager(CustomTrackView *view, DocUndoStack *commandStack = NULL);
bool mousePress(ItemInfo info = ItemInfo(), Qt::KeyboardModifiers modifiers = Qt::NoModifier);
void mouseMove(int pos);
void mouseRelease(DocUndoStack *commandStack, GenTime pos = GenTime());
void mouseRelease(GenTime pos = GenTime());
private:
ClipItem *m_firstClip;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment