#include "moveclipcommand.h"
#include "movetransitioncommand.h"
#include "resizeclipcommand.h"
+#include "editguidecommand.h"
#include "addtimelineclipcommand.h"
#include "addeffectcommand.h"
#include "editeffectcommand.h"
// const int duration = animate ? 1500 : 1;
CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent)
- : QGraphicsView(projectscene, parent), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(QPoint()), m_document(doc), m_autoScroll(KdenliveSettings::autoscroll()), m_tracksHeight(KdenliveSettings::trackheight()), m_tool(SELECTTOOL) {
+ : QGraphicsView(projectscene, parent), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(QPoint()), m_document(doc), m_autoScroll(KdenliveSettings::autoscroll()), m_tracksHeight(KdenliveSettings::trackheight()), m_tool(SELECTTOOL), m_dragGuide(NULL) {
if (doc) m_commandStack = doc->commandStack();
else m_commandStack == NULL;
setMouseTracking(true);
m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_tracksList.count());
for (int i = 0; i < m_guides.count(); i++) {
- m_guides.at(i)->updatePosition(m_scale, m_tracksHeight * m_tracksList.count());
+ QLineF l = m_guides.at(i)->line();
+ l.setP2(QPointF(l.x2(), m_tracksHeight * m_tracksList.count()));
+ m_guides.at(i)->setLine(l);
}
setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_tracksList.count());
((ClipItem*) m_dragItem)->setFadeOut((int)(m_dragItem->endPos().frames(m_document->fps()) - pos), m_scale);
}
+ if (m_animation) delete m_animation;
+ m_animation = NULL;
+ if (m_visualTip) delete m_visualTip;
+ m_visualTip = NULL;
+ QGraphicsView::mouseMoveEvent(event);
+ return;
+ } else if (m_operationMode == MOVEGUIDE) {
if (m_animation) delete m_animation;
m_animation = NULL;
if (m_visualTip) delete m_visualTip;
return;
}
- QList<QGraphicsItem *> itemList = items(event->pos());
- QGraphicsRectItem *item = NULL;
- for (int i = 0; i < itemList.count(); i++) {
- if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
- item = (QGraphicsRectItem*) itemList.at(i);
- break;
- }
- }
if (m_tool == RAZORTOOL) {
setCursor(m_razorCursor);
QGraphicsView::mouseMoveEvent(event);
return;
}
+ QList<QGraphicsItem *> itemList = items(event->pos());
+ QGraphicsRectItem *item = NULL;
+ OPERATIONTYPE opMode = NONE;
+
+ if (itemList.count() == 1 && itemList.at(0)->type() == GUIDEITEM) {
+ opMode = MOVEGUIDE;
+ } else for (int i = 0; i < itemList.count(); i++) {
+ if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
+ item = (QGraphicsRectItem*) itemList.at(i);
+ break;
+ }
+ }
+
if (item && event->buttons() == Qt::NoButton) {
AbstractClipItem *clip = (AbstractClipItem*) item;
- OPERATIONTYPE opMode = opMode = clip->operationMode(mapToScene(event->pos()), m_scale);
+ opMode = clip->operationMode(mapToScene(event->pos()), m_scale);
double size = 8;
if (opMode == m_moveOpMode) {
}
}
m_moveOpMode = opMode;
+
if (opMode == MOVE) {
setCursor(Qt::OpenHandCursor);
} else if (opMode == RESIZESTART) {
}
setCursor(Qt::PointingHandCursor);
}
+ } else if (opMode == MOVEGUIDE) {
+ m_moveOpMode = opMode;
+ setCursor(Qt::SplitHCursor);
} else {
m_moveOpMode = NONE;
if (event->buttons() != Qt::NoButton && event->modifiers() == Qt::NoModifier) {
bool collision = false;
m_dragItem = NULL;
QList<QGraphicsItem *> collisionList = items(event->pos());
- for (int i = 0; i < collisionList.size(); ++i) {
- QGraphicsItem *item = collisionList.at(i);
- if (item->type() == AVWIDGET || item->type() == TRANSITIONWIDGET) {
- if (m_tool == RAZORTOOL) {
- if (item->type() == TRANSITIONWIDGET) return;
- AbstractClipItem *clip = (AbstractClipItem *) item;
- ItemInfo info;
- info.startPos = clip->startPos();
- info.endPos = clip->endPos();
- info.track = clip->track();
- RazorClipCommand* command = new RazorClipCommand(this, info, GenTime((int)(mapToScene(event->pos()).x() / m_scale), m_document->fps()), true);
- m_commandStack->push(command);
- m_document->setModified(true);
- return;
- }
- // select item
- if (!item->isSelected()) {
- QList<QGraphicsItem *> itemList = items();
- for (int i = 0; i < itemList.count(); i++) {
- itemList.at(i)->setSelected(false);
- itemList.at(i)->update();
+ if (collisionList.count() == 1 && collisionList.at(0)->type() == GUIDEITEM) {
+ // a guide item was pressed
+ collisionList.at(0)->setFlag(QGraphicsItem::ItemIsMovable, true);
+ m_dragItem = NULL;
+ m_dragGuide = (Guide *) collisionList.at(0);
+ collision = true;
+ m_operationMode = MOVEGUIDE;
+ // deselect all clips so that only the guide will move
+ QList<QGraphicsItem *> clips = scene()->selectedItems();
+ for (int i = 0; i < clips.count(); ++i)
+ clips.at(i)->setSelected(false);
+ updateSnapPoints(NULL);
+ QGraphicsView::mousePressEvent(event);
+ } else for (int i = 0; i < collisionList.count(); ++i) {
+ QGraphicsItem *item = collisionList.at(i);
+ if (item->type() == AVWIDGET || item->type() == TRANSITIONWIDGET) {
+ if (m_tool == RAZORTOOL) {
+ if (item->type() == TRANSITIONWIDGET) return;
+ AbstractClipItem *clip = (AbstractClipItem *) item;
+ ItemInfo info;
+ info.startPos = clip->startPos();
+ info.endPos = clip->endPos();
+ info.track = clip->track();
+ RazorClipCommand* command = new RazorClipCommand(this, info, GenTime((int)(mapToScene(event->pos()).x() / m_scale), m_document->fps()), true);
+ m_commandStack->push(command);
+ m_document->setModified(true);
+ return;
+ }
+ // select item
+ if (!item->isSelected()) {
+ QList<QGraphicsItem *> itemList = items();
+ for (int i = 0; i < itemList.count(); i++) {
+ itemList.at(i)->setSelected(false);
+ itemList.at(i)->update();
+ }
+ item->setSelected(true);
+ item->update();
}
- item->setSelected(true);
- item->update();
- }
- m_dragItem = (AbstractClipItem *) item;
-
- m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps()) * m_scale), (int)(event->pos().y() - m_dragItem->rect().top()));
- m_dragItemInfo.startPos = m_dragItem->startPos();
- m_dragItemInfo.endPos = m_dragItem->endPos();
- m_dragItemInfo.track = m_dragItem->track();
-
- m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale);
- if (m_operationMode == MOVE) setCursor(Qt::ClosedHandCursor);
- if (m_operationMode == TRANSITIONSTART) {
- ItemInfo info;
- info.startPos = m_dragItem->startPos();
- info.track = m_dragItem->track();
- int transitiontrack = getPreviousVideoTrack(info.track);
- ClipItem *transitionClip = NULL;
- if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.startPos.frames(m_document->fps()), m_tracksList.count() - transitiontrack);
- if (transitionClip && transitionClip->endPos() < m_dragItem->endPos()) {
- info.endPos = transitionClip->endPos();
- } else info.endPos = info.startPos + GenTime(2.5);
-
- slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
- }
- if (m_operationMode == TRANSITIONEND) {
- ItemInfo info;
- info.endPos = m_dragItem->endPos();
- info.track = m_dragItem->track();
- int transitiontrack = getPreviousVideoTrack(info.track);
- ClipItem *transitionClip = NULL;
- if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.endPos.frames(m_document->fps()), m_tracksList.count() - transitiontrack);
- if (transitionClip && transitionClip->startPos() > m_dragItem->startPos()) {
- info.startPos = transitionClip->startPos();
- } else info.startPos = info.endPos - GenTime(2.5);
- slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
+ m_dragItem = (AbstractClipItem *) item;
+
+ m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps()) * m_scale), (int)(event->pos().y() - m_dragItem->rect().top()));
+ m_dragItemInfo.startPos = m_dragItem->startPos();
+ m_dragItemInfo.endPos = m_dragItem->endPos();
+ m_dragItemInfo.track = m_dragItem->track();
+
+ m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale);
+ if (m_operationMode == MOVE) setCursor(Qt::ClosedHandCursor);
+ else if (m_operationMode == TRANSITIONSTART) {
+ ItemInfo info;
+ info.startPos = m_dragItem->startPos();
+ info.track = m_dragItem->track();
+ int transitiontrack = getPreviousVideoTrack(info.track);
+ ClipItem *transitionClip = NULL;
+ if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.startPos.frames(m_document->fps()), m_tracksList.count() - transitiontrack);
+ if (transitionClip && transitionClip->endPos() < m_dragItem->endPos()) {
+ info.endPos = transitionClip->endPos();
+ } else info.endPos = info.startPos + GenTime(2.5);
+
+ slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
+ } else if (m_operationMode == TRANSITIONEND) {
+ ItemInfo info;
+ info.endPos = m_dragItem->endPos();
+ info.track = m_dragItem->track();
+ int transitiontrack = getPreviousVideoTrack(info.track);
+ ClipItem *transitionClip = NULL;
+ if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.endPos.frames(m_document->fps()), m_tracksList.count() - transitiontrack);
+ if (transitionClip && transitionClip->startPos() > m_dragItem->startPos()) {
+ info.startPos = transitionClip->startPos();
+ } else info.startPos = info.endPos - GenTime(2.5);
+ slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
+ }
+ updateSnapPoints(m_dragItem);
+ collision = true;
+ break;
}
- updateSnapPoints(m_dragItem);
- collision = true;
- break;
}
- }
emit clipItemSelected((m_dragItem && m_dragItem->type() == AVWIDGET) ? (ClipItem*) m_dragItem : NULL);
if (!collision) {
}
QGraphicsView::mouseReleaseEvent(event);
setDragMode(QGraphicsView::NoDrag);
+ if (m_operationMode == MOVEGUIDE) {
+ setCursor(Qt::ArrowCursor);
+ m_operationMode = NONE;
+ m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, false);
+ EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), GenTime(m_dragGuide->pos().x() / m_scale, m_document->fps()), m_dragGuide->label(), false);
+ m_commandStack->push(command);
+ m_dragGuide->update(GenTime(m_dragGuide->pos().x() / m_scale, m_document->fps()));
+ m_dragGuide = NULL;
+ m_dragItem = NULL;
+ return;
+ }
if (m_dragItem == NULL) {
emit transitionItemSelected(NULL);
return;
}
}
+
emit transitionItemSelected((m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) ? (Transition*) m_dragItem : NULL);
m_document->setModified(true);
m_operationMode = NONE;
}
}
- // add cursor position
+ // add cursor position
GenTime pos = GenTime(m_cursorPos, m_document->fps());
m_snapPoints.append(pos);
if (offset != GenTime()) m_snapPoints.append(pos - offset);
- // add guides
+ // add guides
for (int i = 0; i < m_guides.count(); i++) {
- m_snapPoints.append(m_guides.at(i)->position());
- if (offset != GenTime()) m_snapPoints.append(m_guides.at(i)->position() - offset);
+ m_snapPoints.append(m_guides.at(i)->position());
+ if (offset != GenTime()) m_snapPoints.append(m_guides.at(i)->position() - offset);
}
qSort(m_snapPoints);
viewport()->update();
}
-void CustomTrackView::slotAddGuide() {
- Guide *g = new Guide(GenTime(m_cursorPos, m_document->fps()), i18n("guide"), m_scale, m_document->fps(), m_tracksHeight * m_tracksList.count());
+
+
+void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const QString &comment) {
+ if (oldPos != GenTime() && pos != GenTime()) {
+ // move guide
+ for (int i = 0; i < m_guides.count(); i++) {
+ kDebug() << "// LOOKING FOR GUIDE (" << i << "): " << m_guides.at(i)->position().frames(25) << ", LOOK: " << oldPos.frames(25) << "x" << pos.frames(25);
+ if (m_guides.at(i)->position() == oldPos) {
+ Guide *item = m_guides.at(i);
+ item->update(pos, comment);
+ item->updatePosition(m_scale);
+ break;
+ }
+ }
+ } else if (pos != GenTime()) addGuide(pos, comment);
+ else {
+ // remove guide
+ for (int i = 0; i < m_guides.count(); i++) {
+ if (m_guides.at(i)->position() == oldPos) {
+ Guide *item = m_guides.takeAt(i);
+ delete item;
+ break;
+ }
+ }
+
+ }
+}
+
+void CustomTrackView::addGuide(const GenTime pos, const QString &comment) {
+ Guide *g = new Guide(this, pos, comment, m_scale, m_document->fps(), m_tracksHeight * m_tracksList.count());
scene()->addItem(g);
m_guides.append(g);
}
+void CustomTrackView::slotAddGuide() {
+ addGuide(GenTime(m_cursorPos, m_document->fps()), i18n("guide"));
+ EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), GenTime(m_cursorPos, m_document->fps()), i18n("guide"), false);
+ m_commandStack->push(command);
+
+}
+
+void CustomTrackView::slotDeleteGuide() {
+ GenTime pos = GenTime(m_cursorPos, m_document->fps());
+ for (int i = 0; i < m_guides.count(); i++) {
+ if (m_guides.at(i)->position() == pos) {
+ EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true);
+ m_commandStack->push(command);
+ break;
+ }
+ }
+}
+
void CustomTrackView::setTool(PROJECTTOOL tool) {
m_tool = tool;
}
}
for (int i = 0; i < m_guides.count(); i++) {
- m_guides.at(i)->updatePosition(m_scale, m_tracksHeight * m_tracksList.count());
+ m_guides.at(i)->updatePosition(m_scale);
}
updateCursorPos();
#include <QPen>
+#include <QBrush>
#include <KDebug>
#include "guide.h"
+#include "customtrackview.h"
-Guide::Guide(GenTime pos, QString label, double scale, double fps, double height)
- : QGraphicsLineItem(), m_position(pos), m_label(label), m_fps(fps) {
-
- setLine(m_position.frames(m_fps) * scale, 0, m_position.frames(m_fps) * scale, height);
- setPen(QPen(QColor(0, 0, 200, 180)));
+Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double scale, double fps, double height)
+ : QGraphicsLineItem(), m_view(view), m_position(pos), m_label(label), m_scale(scale), m_fps(fps) {
+ setFlags(QGraphicsItem::ItemIsMovable);
+ setToolTip(label);
+ setLine(0, 0, 0, height);
+ setPos(m_position.frames(m_fps) * scale, 0);
+ setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 2));
setZValue(999);
+ setAcceptsHoverEvents(true);
+}
+
+
+void Guide::updatePosition(double scale) {
+ setPos(m_position.frames(m_fps) * scale, 0);
+ m_scale = scale;
}
+QString Guide::label() const {
+ return m_label;
+}
-void Guide::updatePosition(double scale, double height) {
- setLine(m_position.frames(m_fps) * scale, 0, m_position.frames(m_fps) * scale, height);
+GenTime Guide::position() const {
+ return m_position;
}
-GenTime Guide::position() {
- return m_position;
+void Guide::update(const GenTime newPos, const QString &comment) {
+ m_position = newPos;
+ if (comment != QString()) {
+ m_label = comment;
+ setToolTip(m_label);
+ }
}
+//virtual
+int Guide::type() const {
+ return GUIDEITEM;
+}
+//virtual
+void Guide::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
+ setPen(QPen(QBrush(QColor(200, 0, 0, 180)), 2));
+}
+
+//virtual
+void Guide::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
+ setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 2));
+}
+
+//virtual
+QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value) {
+ if (change == ItemPositionChange && scene()) {
+ // value is the new position.
+ QPointF newPos = value.toPointF();
+ newPos.setY(0);
+ const double offset = m_position.frames(m_fps) * m_scale;
+ newPos.setX(m_view->getSnapPointForPos(offset + newPos.x()) - offset);
+ return newPos;
+ }
+ return QGraphicsItem::itemChange(change, value);
+}