Commit 867b0561 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Refactoring: continue moving tool functions out of customtrackview

parent 5b7908a7
......@@ -54,6 +54,8 @@ enum OperationType {
ResizeEnd,
RollingStart,
RollingEnd,
RippleStart,
RippleEnd,
FadeIn,
FadeOut,
TransitionStart,
......
......@@ -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) {
......
......@@ -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:
......
This diff is collapsed.
......@@ -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();
......
......@@ -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()
{
}
......@@ -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;
};
......
......@@ -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);
......
......@@ -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
......
......@@ -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();
}
......@@ -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
......
......@@ -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())));
}
}
......@@ -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:
**/