1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include <QMouseEvent>
21 #include <QStylePainter>
22 #include <QGraphicsItem>
23 #include <QDomDocument>
25 #include <QApplication>
26 #include <QInputDialog>
34 #include "customtrackview.h"
35 #include "customtrackscene.h"
36 #include "docclipbase.h"
38 #include "definitions.h"
39 #include "moveclipcommand.h"
40 #include "movetransitioncommand.h"
41 #include "resizeclipcommand.h"
42 #include "editguidecommand.h"
43 #include "addtimelineclipcommand.h"
44 #include "addeffectcommand.h"
45 #include "editeffectcommand.h"
46 #include "moveeffectcommand.h"
47 #include "addtransitioncommand.h"
48 #include "edittransitioncommand.h"
49 #include "editkeyframecommand.h"
50 #include "changespeedcommand.h"
51 #include "addmarkercommand.h"
52 #include "razorclipcommand.h"
53 #include "kdenlivesettings.h"
54 #include "transition.h"
56 #include "customtrackview.h"
57 #include "clipmanager.h"
59 #include "markerdialog.h"
60 #include "mainwindow.h"
61 #include "ui_keyframedialog_ui.h"
62 #include "clipdurationdialog.h"
63 #include "abstractgroupitem.h"
67 // disable animation if user asked it in KDE's global settings
68 // http://lists.kde.org/?l=kde-commits&m=120398724717624&w=2
69 // needs something like below (taken from dolphin)
70 // #include <kglobalsettings.h>
71 // const bool animate = KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects;
72 // const int duration = animate ? 1500 : 1;
74 CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscene, QWidget *parent)
75 : QGraphicsView(projectscene, parent), m_scene(projectscene), 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_clickPoint(QPoint()), m_document(doc), m_autoScroll(KdenliveSettings::autoscroll()), m_tracksHeight(KdenliveSettings::trackheight()), m_tool(SELECTTOOL), m_dragGuide(NULL), m_findIndex(0), m_menuPosition(QPoint()), m_blockRefresh(false), m_selectionGroup(NULL), m_selectedTrack(0), m_copiedItems(QList<AbstractClipItem *> ()), m_selectedClipList(QList<AbstractClipItem *> ()) {
76 if (doc) m_commandStack = doc->commandStack();
77 else m_commandStack == NULL;
78 setMouseTracking(true);
80 m_animationTimer = new QTimeLine(800);
81 m_animationTimer->setFrameRange(0, 5);
82 m_animationTimer->setUpdateInterval(100);
83 m_animationTimer->setLoopCount(0);
84 m_tipColor = QColor(0, 192, 0, 200);
85 QColor border = QColor(255, 255, 255, 100);
86 m_tipPen.setColor(border);
88 setContentsMargins(0, 0, 0, 0);
90 m_cursorLine = projectscene->addLine(0, 0, 0, m_tracksHeight);
91 m_cursorLine->setZValue(1000);
94 KIcon razorIcon("edit-cut");
95 m_razorCursor = QCursor(razorIcon.pixmap(22, 22));
96 verticalScrollBar()->setTracking(true);
97 connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slotRefreshGuides()));
100 CustomTrackView::~CustomTrackView() {
101 qDeleteAll(m_guides);
104 void CustomTrackView::setDocumentModified() {
105 m_document->setModified(true);
108 void CustomTrackView::setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition) {
109 m_timelineContextMenu = timeline;
110 m_timelineContextClipMenu = clip;
111 m_timelineContextTransitionMenu = transition;
114 void CustomTrackView::checkAutoScroll() {
115 m_autoScroll = KdenliveSettings::autoscroll();
118 QList <TrackInfo> CustomTrackView::tracksList() const {
119 return m_scene->m_tracksList;
122 void CustomTrackView::checkTrackHeight() {
123 if (m_tracksHeight == KdenliveSettings::trackheight()) return;
124 m_tracksHeight = KdenliveSettings::trackheight();
125 emit trackHeightChanged();
126 QList<QGraphicsItem *> itemList = items();
128 Transition *transitionitem;
129 for (int i = 0; i < itemList.count(); i++) {
130 if (itemList.at(i)->type() == AVWIDGET) {
131 item = (ClipItem*) itemList.at(i);
132 item->setRect(0, 0, item->rect().width() - 0.02, m_tracksHeight - 1);
133 item->setPos((qreal) item->startPos().frames(m_document->fps()), (qreal) item->track() * m_tracksHeight + 1);
135 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
136 transitionitem = (Transition*) itemList.at(i);
137 transitionitem->setRect(0, 0, transitionitem->rect().width() - 0.02, m_tracksHeight / 3 * 2 - 1);
138 transitionitem->setPos((qreal) transitionitem->startPos().frames(m_document->fps()), (qreal) transitionitem->track() * m_tracksHeight + m_tracksHeight / 3 * 2);
141 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_scene->m_tracksList.count());
143 for (int i = 0; i < m_guides.count(); i++) {
144 QLineF l = m_guides.at(i)->line();
145 l.setP2(QPointF(l.x2(), m_tracksHeight * m_scene->m_tracksList.count()));
146 m_guides.at(i)->setLine(l);
149 setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_scene->m_tracksList.count());
150 verticalScrollBar()->setMaximum(m_tracksHeight * m_scene->m_tracksList.count());
155 void CustomTrackView::resizeEvent(QResizeEvent * event) {
156 QGraphicsView::resizeEvent(event);
160 void CustomTrackView::wheelEvent(QWheelEvent * e) {
161 if (e->modifiers() == Qt::ControlModifier) {
162 if (e->delta() > 0) emit zoomIn();
165 if (e->delta() > 0) horizontalScrollBar()->setValue(horizontalScrollBar()->value() + horizontalScrollBar()->singleStep());
166 else horizontalScrollBar()->setValue(horizontalScrollBar()->value() - horizontalScrollBar()->singleStep());
170 int CustomTrackView::getPreviousVideoTrack(int track) {
171 track = m_scene->m_tracksList.count() - track - 1;
173 for (int i = track; i > -1; i--) {
174 if (m_scene->m_tracksList.at(i).type == VIDEOTRACK) return i + 1;
181 void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
182 int pos = event->x();
183 emit mousePosition((int)(mapToScene(event->pos()).x()));
184 if (event->buttons() & Qt::MidButton) return;
185 if (event->buttons() != Qt::NoButton) {
186 if (m_dragItem && m_tool == SELECTTOOL) {
187 if (m_operationMode == MOVE) {
188 if ((event->pos() - m_clickEvent).manhattanLength() >= QApplication::startDragDistance()) QGraphicsView::mouseMoveEvent(event);
190 /*&& (event->pos() - m_clickEvent).manhattanLength() >= QApplication::startDragDistance()) {
191 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint.x());
192 //kDebug() << "/////// MOVE CLIP, EVENTĀ Y: "<<m_clickPoint.y();//<<event->scenePos().y()<<", SCENE HEIGHT: "<<scene()->sceneRect().height();
193 int moveTrack = (int) mapToScene(event->pos() - QPoint(0, (m_dragItem->type() == TRANSITIONWIDGET ? m_dragItem->boundingRect().height() / 2 : 0))).y() / m_tracksHeight;
194 int currentTrack = m_dragItem->track();
196 if (moveTrack > 1000) moveTrack = 0;
197 else if (moveTrack > m_scene->m_tracksList.count() - 1) moveTrack = m_scene->m_tracksList.count() - 1;
198 else if (moveTrack < 0) moveTrack = 0;
200 int offset = moveTrack - currentTrack;
201 if (m_selectedClipList.count() == 1) m_dragItem->moveTo((int)(snappedPos / m_scale), m_scale, offset * m_tracksHeight, moveTrack);
203 int moveOffset = (int)(snappedPos / m_scale) - m_dragItem->startPos().frames(m_document->fps());
204 if (canBeMoved(m_selectedClipList, GenTime(moveOffset, m_document->fps()), offset)) {
205 for (int i = 0; i < m_selectedClipList.count(); i++) {
206 AbstractClipItem *item = m_selectedClipList.at(i);
207 item->moveTo(item->startPos().frames(m_document->fps()) + moveOffset, m_scale, offset * m_tracksHeight, item->track() + offset, false);
212 } else if (m_operationMode == RESIZESTART) {
213 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x());
214 m_dragItem->resizeStart((int)(snappedPos));
215 } else if (m_operationMode == RESIZEEND) {
216 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x());
217 m_dragItem->resizeEnd((int)(snappedPos));
218 } else if (m_operationMode == FADEIN) {
219 int pos = (int)(mapToScene(event->pos()).x());
220 ((ClipItem*) m_dragItem)->setFadeIn((int)(pos - m_dragItem->startPos().frames(m_document->fps())));
221 } else if (m_operationMode == FADEOUT) {
222 int pos = (int)(mapToScene(event->pos()).x());
223 ((ClipItem*) m_dragItem)->setFadeOut((int)(m_dragItem->endPos().frames(m_document->fps()) - pos));
224 } else if (m_operationMode == KEYFRAME) {
225 GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart();
226 double pos = mapToScene(event->pos()).toPoint().y();
227 QRectF br = m_dragItem->sceneBoundingRect();
228 double maxh = 100.0 / br.height();
229 pos = (br.bottom() - pos) * maxh;
230 m_dragItem->updateKeyFramePos(keyFramePos, pos);
233 if (m_animation) delete m_animation;
235 if (m_visualTip) delete m_visualTip;
238 } else if (m_operationMode == MOVEGUIDE) {
239 if (m_animation) delete m_animation;
241 if (m_visualTip) delete m_visualTip;
243 QGraphicsView::mouseMoveEvent(event);
248 if (m_tool == RAZORTOOL) {
249 setCursor(m_razorCursor);
250 //QGraphicsView::mouseMoveEvent(event);
254 QList<QGraphicsItem *> itemList = items(event->pos());
255 QGraphicsRectItem *item = NULL;
256 OPERATIONTYPE opMode = NONE;
258 if (itemList.count() == 1 && itemList.at(0)->type() == GUIDEITEM) {
260 } else for (int i = 0; i < itemList.count(); i++) {
261 if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
262 item = (QGraphicsRectItem*) itemList.at(i);
267 if (item && event->buttons() == Qt::NoButton) {
268 AbstractClipItem *clip = static_cast <AbstractClipItem*>(item);
269 if (m_tool == RAZORTOOL) {
270 // razor tool over a clip, display current frame in monitor
271 if (!m_blockRefresh && item->type() == AVWIDGET) {
272 //TODO: solve crash when showing frame when moving razor over clip
273 //emit showClipFrame(((ClipItem *) item)->baseClip(), mapToScene(event->pos()).x() / m_scale - (clip->startPos() - clip->cropStart()).frames(m_document->fps()));
278 opMode = clip->operationMode(mapToScene(event->pos()));
280 if (opMode == m_moveOpMode) {
281 QGraphicsView::mouseMoveEvent(event);
285 if (m_animation) delete m_animation;
287 m_animationTimer->stop();
292 m_moveOpMode = opMode;
293 if (opMode == MOVE) {
294 setCursor(Qt::OpenHandCursor);
295 } else if (opMode == RESIZESTART) {
296 setCursor(KCursor("left_side", Qt::SizeHorCursor));
297 if (m_visualTip == NULL) {
298 QRectF rect = clip->sceneBoundingRect();
300 polygon << QPoint(0, rect.height() / 2 - size * 2);
301 polygon << QPoint(size * 2, (int)(rect.height() / 2));
302 polygon << QPoint(0, (int)(rect.height() / 2 + size * 2));
303 polygon << QPoint(0, (int)(rect.height() / 2 - size * 2));
305 m_visualTip = new QGraphicsPolygonItem(polygon);
306 ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
307 ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen);
308 m_visualTip->setPos(rect.x(), rect.y());
309 m_visualTip->setFlags(QGraphicsItem::ItemIgnoresTransformations);
310 m_visualTip->setZValue(100);
311 m_animation = new QGraphicsItemAnimation;
312 m_animation->setItem(m_visualTip);
313 m_animation->setTimeLine(m_animationTimer);
315 m_animation->setScaleAt(.5, scale, 1);
316 //m_animation->setPosAt(.5, QPointF(rect.x() - rect.x() * scale, 0));
318 m_animation->setScaleAt(1, scale, 1);
319 //m_animation->setPosAt(1, QPointF(rect.x() - rect.x() * scale, 0));
320 scene()->addItem(m_visualTip);
321 m_animationTimer->start();
323 } else if (opMode == RESIZEEND) {
324 setCursor(KCursor("right_side", Qt::SizeHorCursor));
325 if (m_visualTip == NULL) {
326 QRectF rect = clip->sceneBoundingRect();
328 polygon << QPoint(0, (int)(rect.height() / 2 - size * 2));
329 polygon << QPoint(- size * 2, (int)(rect.height() / 2));
330 polygon << QPoint(0, (int)(rect.height() / 2 + size * 2));
331 polygon << QPoint(0, (int)(rect.height() / 2 - size * 2));
333 m_visualTip = new QGraphicsPolygonItem(polygon);
334 ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
335 ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen);
336 m_visualTip->setFlags(QGraphicsItem::ItemIgnoresTransformations);
337 m_visualTip->setPos(rect.right(), rect.y());
338 m_visualTip->setZValue(100);
339 m_animation = new QGraphicsItemAnimation;
340 m_animation->setItem(m_visualTip);
341 m_animation->setTimeLine(m_animationTimer);
343 m_animation->setScaleAt(.5, scale, 1);
345 m_animation->setScaleAt(1, scale, 1);
346 scene()->addItem(m_visualTip);
347 m_animationTimer->start();
349 } else if (opMode == FADEIN) {
350 if (m_visualTip == NULL) {
351 ClipItem *item = (ClipItem *) clip;
352 QRectF rect = clip->sceneBoundingRect();
353 m_visualTip = new QGraphicsEllipseItem(-size, -size, size * 2, size * 2);
354 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
355 ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen);
356 m_visualTip->setPos(rect.x() + item->fadeIn(), rect.y());
357 m_visualTip->setFlags(QGraphicsItem::ItemIgnoresTransformations);
358 m_visualTip->setZValue(100);
359 m_animation = new QGraphicsItemAnimation;
360 m_animation->setItem(m_visualTip);
361 m_animation->setTimeLine(m_animationTimer);
363 m_animation->setScaleAt(.5, scale, scale);
365 m_animation->setScaleAt(1, scale, scale);
366 scene()->addItem(m_visualTip);
367 m_animationTimer->start();
369 setCursor(Qt::PointingHandCursor);
370 } else if (opMode == FADEOUT) {
371 if (m_visualTip == NULL) {
372 ClipItem *item = (ClipItem *) clip;
373 QRectF rect = clip->sceneBoundingRect();
374 m_visualTip = new QGraphicsEllipseItem(-size, -size, size * 2, size * 2);
375 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
376 ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen);
377 m_visualTip->setPos(rect.right() - item->fadeOut(), rect.y());
378 m_visualTip->setFlags(QGraphicsItem::ItemIgnoresTransformations);
379 m_visualTip->setZValue(100);
380 m_animation = new QGraphicsItemAnimation;
381 m_animation->setItem(m_visualTip);
382 m_animation->setTimeLine(m_animationTimer);
384 m_animation->setScaleAt(.5, scale, scale);
386 m_animation->setScaleAt(1, scale, scale);
387 scene()->addItem(m_visualTip);
388 m_animationTimer->start();
390 setCursor(Qt::PointingHandCursor);
391 } else if (opMode == TRANSITIONSTART) {
392 /*if (m_visualTip == NULL) {
393 QRectF rect = clip->sceneBoundingRect();
394 m_visualTip = new QGraphicsEllipseItem(-5, -5 , 10, 10);
395 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
396 ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen);
397 m_visualTip->setZValue(100);
398 m_animation = new QGraphicsItemAnimation;
399 m_animation->setItem(m_visualTip);
400 m_animation->setTimeLine(m_animationTimer);
401 m_visualTip->setPos(rect.x() + 10, rect.y() + rect.height() / 2 + 12);
403 m_animation->setScaleAt(.5, scale, scale);
405 m_animation->setScaleAt(1, scale, scale);
406 scene()->addItem(m_visualTip);
407 m_animationTimer->start();
409 setCursor(Qt::PointingHandCursor);
410 } else if (opMode == TRANSITIONEND) {
411 /*if (m_visualTip == NULL) {
412 QRectF rect = clip->sceneBoundingRect();
413 m_visualTip = new QGraphicsEllipseItem(-5, -5 , 10, 10);
414 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
415 ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen);
416 m_visualTip->setZValue(100);
417 m_animation = new QGraphicsItemAnimation;
418 m_animation->setItem(m_visualTip);
419 m_animation->setTimeLine(m_animationTimer);
420 m_visualTip->setPos(rect.x() + rect.width() - 10 , rect.y() + rect.height() / 2 + 12);
422 m_animation->setScaleAt(.5, scale, scale);
424 m_animation->setScaleAt(1, scale, scale);
425 scene()->addItem(m_visualTip);
426 m_animationTimer->start();
428 setCursor(Qt::PointingHandCursor);
429 } else if (opMode == KEYFRAME) {
430 setCursor(Qt::PointingHandCursor);
432 } // no clip under mouse
433 else if (m_tool == RAZORTOOL) {
436 } else if (opMode == MOVEGUIDE) {
437 m_moveOpMode = opMode;
438 setCursor(Qt::SplitHCursor);
441 if (event->buttons() != Qt::NoButton && event->modifiers() == Qt::NoModifier) {
442 setCursorPos((int)(mapToScene(event->pos().x(), 0).x()));
445 if (m_animation) delete m_animation;
446 m_animationTimer->stop();
452 setCursor(Qt::ArrowCursor);
454 QGraphicsView::mouseMoveEvent(event);
458 void CustomTrackView::mousePressEvent(QMouseEvent * event) {
459 m_menuPosition = QPoint();
460 m_blockRefresh = true;
461 bool collision = false;
463 if (m_tool != RAZORTOOL) activateMonitor();
464 m_clickEvent = event->pos();
466 // special cases (middle click button or ctrl / shift click
467 if (event->button() == Qt::MidButton) {
468 m_document->renderer()->switchPlay();
469 m_blockRefresh = false;
473 // check item under mouse
474 QList<QGraphicsItem *> collisionList = items(event->pos());
476 if (event->modifiers() == Qt::ControlModifier && collisionList.count() == 0) {
477 setDragMode(QGraphicsView::ScrollHandDrag);
478 QGraphicsView::mousePressEvent(event);
479 m_blockRefresh = false;
483 if (event->modifiers() == Qt::ShiftModifier && collisionList.count() == 0) {
484 setDragMode(QGraphicsView::RubberBandDrag);
485 QGraphicsView::mousePressEvent(event);
486 m_blockRefresh = false;
490 if (collisionList.count() == 1 && collisionList.at(0)->type() == GUIDEITEM) {
491 // a guide item was pressed
492 collisionList.at(0)->setFlag(QGraphicsItem::ItemIsMovable, true);
494 m_dragGuide = (Guide *) collisionList.at(0);
496 m_operationMode = MOVEGUIDE;
497 // deselect all clips so that only the guide will move
498 m_scene->clearSelection();
499 if (m_selectionGroup) {
500 scene()->destroyItemGroup(m_selectionGroup);
501 m_selectionGroup = NULL;
503 updateSnapPoints(NULL);
504 QGraphicsView::mousePressEvent(event);
508 // Find first clip or transition under mouse
511 while (i < collisionList.count()) {
512 if (collisionList.at(i)->type() == AVWIDGET || collisionList.at(i)->type() == TRANSITIONWIDGET) {
513 m_dragItem = static_cast <AbstractClipItem *>(collisionList.at(i));
514 m_dragItemInfo = m_dragItem->info();
520 // context menu requested
521 if (event->button() == Qt::RightButton) {
523 if (!m_dragItem->isSelected()) {
524 m_scene->clearSelection();
525 if (m_selectionGroup) {
526 scene()->destroyItemGroup(m_selectionGroup);
527 m_selectionGroup = NULL;
529 m_dragItem->setSelected(true);
532 m_operationMode = NONE;
533 displayContextMenu(event->globalPos(), m_dragItem);
534 m_menuPosition = event->pos();
540 // No item under click
541 if (m_dragItem == NULL) {
542 if (m_selectionGroup) {
543 scene()->destroyItemGroup(m_selectionGroup);
544 m_selectionGroup = NULL;
546 setCursor(Qt::ArrowCursor);
547 m_scene->clearSelection();
548 setCursorPos((int)(mapToScene(event->x(), 0).x()));
554 if (m_tool == RAZORTOOL) {
555 if (m_dragItem->type() == TRANSITIONWIDGET) {
556 emit displayMessage(i18n("Cannot cut a transition"), ErrorMessage);
561 AbstractClipItem *clip = static_cast <AbstractClipItem *>(m_dragItem);
562 RazorClipCommand* command = new RazorClipCommand(this, clip->info(), GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()), true);
563 m_commandStack->push(command);
564 m_document->setModified(true);
569 updateSnapPoints(m_dragItem);
570 if (m_dragItem && m_dragItem->type() == AVWIDGET) emit clipItemSelected((ClipItem*) m_dragItem);
571 else emit clipItemSelected(NULL);
573 if (m_selectionGroup) {
574 // delete selection group
575 scene()->destroyItemGroup(m_selectionGroup);
576 m_selectionGroup = NULL;
579 if (m_dragItem && m_operationMode == NONE) QGraphicsView::mousePressEvent(event);
581 QList<QGraphicsItem *> selection = m_scene->selectedItems();
582 if (selection.count() > 1) {
583 m_selectionGroup = new AbstractGroupItem(m_document->fps());
584 scene()->addItem(m_selectionGroup);
585 for (int i = 0; i < selection.count(); i++) {
586 if (selection.at(i)->type() == AVWIDGET)
587 m_selectionGroup->addItem(selection.at(i));
591 m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y()));
593 if (!item->isSelected()) {
595 if (event->modifiers() != Qt::ControlModifier) {
596 QList<QGraphicsItem *> itemList = items();
597 for (int i = 0; i < itemList.count(); i++) {
598 itemList.at(i)->setSelected(false);
599 itemList.at(i)->update();
602 item->setSelected(true);
608 m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps()) * m_scale), (int)(event->pos().y() - m_dragItem->pos().y()));
609 m_dragItemInfo.startPos = m_dragItem->startPos();
610 m_dragItemInfo.endPos = m_dragItem->endPos();
611 m_dragItemInfo.track = m_dragItem->track();
613 m_selectedClipList.clear();
614 QList<QGraphicsItem *> selected = scene()->selectedItems();
615 for (int i = 0; i < selected.count(); i++) {
616 if (selected.at(i)->type() == AVWIDGET || selected.at(i)->type() == TRANSITIONWIDGET)
617 m_selectedClipList.append(static_cast <AbstractClipItem *>(selected.at(i)));
620 m_operationMode = m_dragItem->operationMode(mapToScene(event->pos()));
622 if (m_operationMode == KEYFRAME) {
623 m_dragItem->updateSelectedKeyFrame();
624 m_blockRefresh = false;
626 } else if (m_operationMode == MOVE) {
627 setCursor(Qt::ClosedHandCursor);
628 } else if (m_operationMode == TRANSITIONSTART) {
630 info.startPos = m_dragItem->startPos();
631 info.track = m_dragItem->track();
632 int transitiontrack = getPreviousVideoTrack(info.track);
633 ClipItem *transitionClip = NULL;
634 if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.startPos.frames(m_document->fps()), m_scene->m_tracksList.count() - transitiontrack);
635 if (transitionClip && transitionClip->endPos() < m_dragItem->endPos()) {
636 info.endPos = transitionClip->endPos();
637 } else info.endPos = info.startPos + GenTime(2.5);
639 slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
640 } else if (m_operationMode == TRANSITIONEND) {
642 info.endPos = m_dragItem->endPos();
643 info.track = m_dragItem->track();
644 int transitiontrack = getPreviousVideoTrack(info.track);
645 ClipItem *transitionClip = NULL;
646 if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.endPos.frames(m_document->fps()), m_scene->m_tracksList.count() - transitiontrack);
647 if (transitionClip && transitionClip->startPos() > m_dragItem->startPos()) {
648 info.startPos = transitionClip->startPos();
649 } else info.startPos = info.endPos - GenTime(2.5);
650 slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
653 m_blockRefresh = false;
655 //QGraphicsView::mousePressEvent(event);
658 void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) {
659 if (m_dragItem && m_dragItem->hasKeyFrames()) {
660 if (m_moveOpMode == KEYFRAME) {
661 // user double clicked on a keyframe, open edit dialog
662 QDialog d(parentWidget());
663 Ui::KeyFrameDialog_UI view;
665 view.kfr_position->setText(m_document->timecode().getTimecode(GenTime(m_dragItem->selectedKeyFramePos(), m_document->fps()) - m_dragItem->cropStart(), m_document->fps()));
666 view.kfr_value->setValue(m_dragItem->selectedKeyFrameValue());
667 view.kfr_value->setFocus();
668 if (d.exec() == QDialog::Accepted) {
669 int pos = m_document->timecode().getFrameCount(view.kfr_position->text(), m_document->fps());
670 m_dragItem->updateKeyFramePos(GenTime(pos, m_document->fps()) + m_dragItem->cropStart(), (double) view.kfr_value->value() * m_dragItem->keyFrameFactor());
671 ClipItem *item = (ClipItem *)m_dragItem;
672 QString previous = item->keyframes(item->selectedEffectIndex());
673 item->updateKeyframeEffect();
674 QString next = item->keyframes(item->selectedEffectIndex());
675 EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
676 m_commandStack->push(command);
677 updateEffect(m_scene->m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
682 GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart();
683 m_dragItem->addKeyFrame(keyFramePos, mapToScene(event->pos()).toPoint().y());
684 ClipItem * item = (ClipItem *) m_dragItem;
685 QString previous = item->keyframes(item->selectedEffectIndex());
686 item->updateKeyframeEffect();
687 QString next = item->keyframes(item->selectedEffectIndex());
688 EditKeyFrameCommand *command = new EditKeyFrameCommand(this, m_dragItem->track(), m_dragItem->startPos(), item->selectedEffectIndex(), previous, next, false);
689 m_commandStack->push(command);
690 updateEffect(m_scene->m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
692 } else if (m_dragItem) {
693 ClipDurationDialog d(m_dragItem, m_document->timecode(), this);
694 if (d.exec() == QDialog::Accepted) {
695 if (d.startPos() != m_dragItem->startPos()) {
696 if (m_dragItem->type() == AVWIDGET) {
698 startInfo.startPos = m_dragItem->startPos();
699 startInfo.endPos = m_dragItem->endPos();
700 startInfo.track = m_dragItem->track();
702 endInfo.startPos = d.startPos();
703 endInfo.endPos = m_dragItem->endPos() + (endInfo.startPos - startInfo.startPos);
704 endInfo.track = m_dragItem->track();
705 MoveClipCommand *command = new MoveClipCommand(this, startInfo, endInfo, true);
706 m_commandStack->push(command);
708 //TODO: move transition
711 if (d.duration() != m_dragItem->duration()) {
712 if (m_dragItem->type() == AVWIDGET) {
714 startInfo.startPos = m_dragItem->startPos();
715 startInfo.endPos = m_dragItem->endPos();
716 startInfo.track = m_dragItem->track();
718 endInfo.startPos = startInfo.startPos;
719 endInfo.endPos = endInfo.startPos + d.duration();
720 endInfo.track = m_dragItem->track();
721 ResizeClipCommand *command = new ResizeClipCommand(this, startInfo, endInfo, true);
722 m_commandStack->push(command);
724 //TODO: resize transition
729 QList<QGraphicsItem *> collisionList = items(event->pos());
730 if (collisionList.count() == 1 && collisionList.at(0)->type() == GUIDEITEM) {
731 Guide *editGuide = (Guide *) collisionList.at(0);
732 if (editGuide) slotEditGuide(editGuide->info());
738 void CustomTrackView::editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes) {
739 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), track);
741 clip->setKeyframes(index, keyframes);
742 updateEffect(m_scene->m_tracksList.count() - clip->track(), clip->startPos(), clip->effectAt(index), index);
743 } else emit displayMessage(i18n("Cannot find clip with keyframe"), ErrorMessage);
747 void CustomTrackView::displayContextMenu(QPoint pos, AbstractClipItem *clip) {
748 if (clip == NULL) m_timelineContextMenu->popup(pos);
749 else if (clip->type() == AVWIDGET) m_timelineContextClipMenu->popup(pos);
750 else if (clip->type() == TRANSITIONWIDGET) m_timelineContextTransitionMenu->popup(pos);
753 void CustomTrackView::activateMonitor() {
754 emit activateDocumentMonitor();
757 void CustomTrackView::dragEnterEvent(QDragEnterEvent * event) {
758 if (event->mimeData()->hasFormat("kdenlive/clip")) {
759 QStringList list = QString(event->mimeData()->data("kdenlive/clip")).split(";");
760 kDebug() << "DRAG ENTER EVENT, DATA: " << list;
761 DocClipBase *clip = m_document->getBaseClip(list.at(0));
762 if (clip == NULL) kDebug() << "Ā WARNING))))))))) CLIP NOT FOUND : " << list.at(0);
763 addItem(clip, event->pos(), QPoint(list.at(1).toInt(), list.at(2).toInt()));
764 event->acceptProposedAction();
765 } else if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
766 kDebug() << "/////////////// DRAG ENTERED, TEXT: " << event->mimeData()->data("kdenlive/producerslist");
767 QStringList ids = QString(event->mimeData()->data("kdenlive/producerslist")).split(";");
768 //TODO: drop of several clips
769 for (int i = 0; i < ids.size(); ++i) {
771 DocClipBase *clip = m_document->getBaseClip(ids.at(0));
772 if (clip == NULL) kDebug() << "Ā WARNING))))))))) CLIP NOT FOUND : " << ids.at(0);
773 addItem(clip, event->pos());
774 event->acceptProposedAction();
775 } else QGraphicsView::dragEnterEvent(event);
778 void CustomTrackView::slotRefreshEffects(ClipItem *clip) {
779 int track = m_scene->m_tracksList.count() - clip->track();
780 GenTime pos = clip->startPos();
781 if (!m_document->renderer()->mltRemoveEffect(track, pos, "-1", false)) {
782 emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
786 for (int i = 0; i < clip->effectsCount(); i++) {
787 if (!m_document->renderer()->mltAddEffect(track, pos, clip->getEffectArgs(clip->effectAt(i)), false)) success = false;
789 if (!success) emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
790 m_document->renderer()->doRefresh();
793 void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) {
794 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_scene->m_tracksList.count() - track);
796 QHash <QString, QString> effectParams = clip->addEffect(effect);
797 if (!m_document->renderer()->mltAddEffect(track, pos, effectParams))
798 emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
799 emit clipItemSelected(clip);
800 } else emit displayMessage(i18n("Cannot find clip to add effect"), ErrorMessage);
803 void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) {
804 QString index = effect.attribute("kdenlive_ix");
805 if (effect.attribute("disabled") != "1" && !m_document->renderer()->mltRemoveEffect(track, pos, index)) {
806 emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
809 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_scene->m_tracksList.count() - track);
811 clip->deleteEffect(index);
812 emit clipItemSelected(clip);
816 void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) {
817 QList<QGraphicsItem *> itemList;
818 if (track == -1) itemList = scene()->selectedItems();
819 if (itemList.isEmpty()) {
820 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, track);
821 if (clip) itemList.append(clip);
822 else emit displayMessage(i18n("Select a clip if you want to apply an effect"), ErrorMessage);
824 kDebug() << "// REQUESTING EFFECT ONĀ CLIP: " << pos.frames(25) << ", TRK: " << track << "SELECTED ITEMS: " << itemList.count();
825 for (int i = 0; i < itemList.count(); i++) {
826 if (itemList.at(i)->type() == AVWIDGET) {
827 ClipItem *item = (ClipItem *)itemList.at(i);
828 item->initEffect(effect);
829 AddEffectCommand *command = new AddEffectCommand(this, m_scene->m_tracksList.count() - item->track(), item->startPos(), effect, true);
830 m_commandStack->push(command);
833 m_document->setModified(true);
836 void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect) {
837 AddEffectCommand *command = new AddEffectCommand(this, m_scene->m_tracksList.count() - clip->track(), clip->startPos(), effect, false);
838 m_commandStack->push(command);
839 m_document->setModified(true);
842 void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect, int ix) {
843 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_scene->m_tracksList.count() - track);
845 QHash <QString, QString> effectParams = clip->getEffectArgs(effect);
846 if (effectParams.value("disabled") == "1") {
847 if (m_document->renderer()->mltRemoveEffect(track, pos, effectParams.value("kdenlive_ix"))) {
848 kDebug() << "////// DISABLING EFFECT: " << index << ", CURRENTLA: " << clip->selectedEffectIndex();
849 } else emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
850 } else if (!m_document->renderer()->mltEditEffect(m_scene->m_tracksList.count() - clip->track(), clip->startPos(), effectParams))
851 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
852 if (ix == clip->selectedEffectIndex()) {
853 clip->setSelectedEffect(clip->selectedEffectIndex());
856 m_document->setModified(true);
859 void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos) {
860 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_scene->m_tracksList.count() - track);
862 m_document->renderer()->mltMoveEffect(track, pos, oldPos, newPos);
864 m_document->setModified(true);
867 void CustomTrackView::slotChangeEffectState(ClipItem *clip, int effectPos, bool disable) {
868 QDomElement effect = clip->effectAt(effectPos);
869 QDomElement oldEffect = effect.cloneNode().toElement();
870 effect.setAttribute("disabled", disable);
871 EditEffectCommand *command = new EditEffectCommand(this, m_scene->m_tracksList.count() - clip->track(), clip->startPos(), oldEffect, effect, effectPos, true);
872 m_commandStack->push(command);
873 m_document->setModified(true);
876 void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos) {
877 MoveEffectCommand *command = new MoveEffectCommand(this, m_scene->m_tracksList.count() - clip->track(), clip->startPos(), currentPos, newPos, true);
878 m_commandStack->push(command);
879 m_document->setModified(true);
882 void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect, int ix) {
883 EditEffectCommand *command = new EditEffectCommand(this, m_scene->m_tracksList.count() - clip->track(), clip->startPos(), oldeffect, effect, ix, true);
884 m_commandStack->push(command);
887 void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) {
890 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()) + 1, info.track);
891 if (!item || cutTime >= item->endPos() || cutTime <= item->startPos()) {
892 emit displayMessage(i18n("Cannot find clip to cut"), ErrorMessage);
893 kDebug() << "///////// ERROR CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25);
894 m_blockRefresh = false;
897 kDebug() << "///////// CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25);
899 m_document->renderer()->mltCutClip(m_scene->m_tracksList.count() - info.track, cutTime);
900 int cutPos = (int) cutTime.frames(m_document->fps());
902 newPos.startPos = cutTime;
903 newPos.endPos = info.endPos;
904 newPos.cropStart = item->cropStart() + (cutTime - info.startPos);
905 newPos.track = info.track;
906 ClipItem *dup = item->clone(newPos);
907 kDebug() << "// REsizing item to: " << cutPos;
908 item->resizeEnd(cutPos);
909 scene()->addItem(dup);
910 item->baseClip()->addReference();
911 m_document->updateClip(item->baseClip()->getId());
912 kDebug() << "///////// CUTTING CLIP RESULT: (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), DUP: (" << dup->startPos().frames(25) << "-" << dup->endPos().frames(25) << ")" << ", CUT: " << cutTime.frames(25);
913 kDebug() << "// CUTTING CLIP dONE";
917 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
918 ClipItem *dup = getClipItemAt((int) cutTime.frames(m_document->fps()) + 1, info.track);
919 if (!item || !dup || item == dup) {
920 emit displayMessage(i18n("Cannot find clip to uncut"), ErrorMessage);
921 m_blockRefresh = false;
925 kDebug() << "// UNCUTTING CLIPS: ITEM 1 (" << item->startPos().frames(25) << "x" << item->endPos().frames(25) << ")";
926 kDebug() << "// UNCUTTING CLIPS: ITEM 2 (" << dup->startPos().frames(25) << "x" << dup->endPos().frames(25) << ")";
927 kDebug() << "// UNCUTTING CLIPS, INFO (" << info.startPos.frames(25) << "x" << info.endPos.frames(25) << ") , CUT: " << cutTime.frames(25);;
928 //deleteClip(dup->info());
931 if (dup->isSelected()) emit clipItemSelected(NULL);
932 dup->baseClip()->removeReference();
933 m_document->updateClip(dup->baseClip()->getId());
934 scene()->removeItem(dup);
936 m_document->renderer()->mltRemoveClip(m_scene->m_tracksList.count() - info.track, cutTime);
938 ItemInfo clipinfo = item->info();
939 clipinfo.track = m_scene->m_tracksList.count() - clipinfo.track;
940 bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, info.endPos - info.startPos);
942 item->resizeEnd((int) info.endPos.frames(m_document->fps()));
944 emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
947 QTimer::singleShot(3000, this, SLOT(slotEnableRefresh()));
950 void CustomTrackView::slotEnableRefresh() {
951 m_blockRefresh = false;
954 void CustomTrackView::slotAddTransitionToSelectedClips(QDomElement transition) {
955 QList<QGraphicsItem *> itemList = scene()->selectedItems();
956 for (int i = 0; i < itemList.count(); i++) {
957 if (itemList.at(i)->type() == AVWIDGET) {
958 ClipItem *item = (ClipItem *) itemList.at(i);
960 info.startPos = item->startPos();
961 info.endPos = info.startPos + GenTime(2.5);
962 info.track = item->track();
963 int transitiontrack = getPreviousVideoTrack(info.track);
964 slotAddTransition(item, info, transitiontrack, transition);
969 void CustomTrackView::slotAddTransition(ClipItem* clip, ItemInfo transitionInfo, int endTrack, QDomElement transition) {
970 AddTransitionCommand* command = new AddTransitionCommand(this, transitionInfo, endTrack, transition, false, true);
971 m_commandStack->push(command);
972 m_document->setModified(true);
975 void CustomTrackView::addTransition(ItemInfo transitionInfo, int endTrack, QDomElement params) {
976 Transition *tr = new Transition(transitionInfo, endTrack, m_document->fps(), params);
977 scene()->addItem(tr);
979 //kDebug() << "---- ADDING transition " << e.attribute("tag") << ", on tracks " << m_scene->m_tracksList.count() - e.attribute("transition_track").toInt() << " / " << getPreviousVideoTrack(e.attribute("transition_track").toInt());
980 m_document->renderer()->mltAddTransition(tr->transitionTag(), endTrack, m_scene->m_tracksList.count() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, tr->toXML());
981 m_document->setModified(true);
984 void CustomTrackView::deleteTransition(ItemInfo transitionInfo, int endTrack, QDomElement params) {
985 Transition *item = getTransitionItemAt((int)transitionInfo.startPos.frames(m_document->fps()) + 1, transitionInfo.track);
986 m_document->renderer()->mltDeleteTransition(item->transitionTag(), endTrack, m_scene->m_tracksList.count() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, item->toXML());
988 emit transitionItemSelected(NULL);
989 m_document->setModified(true);
992 void CustomTrackView::slotTransitionUpdated(Transition *tr, QDomElement old) {
993 EditTransitionCommand *command = new EditTransitionCommand(this, tr->track(), tr->startPos(), old, tr->toXML() , true);
994 m_commandStack->push(command);
995 m_document->setModified(true);
998 void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTransition, QDomElement transition) {
999 Transition *item = getTransitionItemAt((int)pos.frames(m_document->fps()) + 1, track);
1001 kWarning() << "Unable to find transition at pos :" << pos.frames(m_document->fps()) << ", ON track: " << track;
1004 m_document->renderer()->mltUpdateTransition(oldTransition.attribute("tag"), transition.attribute("tag"), transition.attribute("transition_btrack").toInt(), m_scene->m_tracksList.count() - transition.attribute("transition_atrack").toInt(), item->startPos(), item->endPos(), transition);
1005 item->setTransitionParameters(transition);
1006 m_document->setModified(true);
1009 void CustomTrackView::addItem(DocClipBase *clip, QPoint pos) {
1011 info.startPos = GenTime((int)(mapToScene(pos).x()), m_document->fps());
1012 info.endPos = info.startPos + clip->duration();
1013 info.track = (int)(pos.y() / m_tracksHeight);
1014 kDebug() << "------------ ADDING CLIP ITEM----: " << info.startPos.frames(25) << ", " << info.endPos.frames(25) << ", " << info.track;
1015 m_dropItem = new ClipItem(clip, info, m_document->fps());
1016 scene()->addItem(m_dropItem);
1019 void CustomTrackView::addItem(DocClipBase *clip, QPoint pos, QPoint zone) {
1021 info.startPos = GenTime((int)(mapToScene(pos).x()), m_document->fps());
1022 info.cropStart = GenTime(zone.x(), m_document->fps());
1023 info.endPos = info.startPos + GenTime(zone.y() - zone.x(), m_document->fps());
1024 info.track = (int)(pos.y() / m_tracksHeight);
1025 kDebug() << "------------ ADDING CLIP ZONE ITEM----: " << zone;
1026 m_dropItem = new ClipItem(clip, info, m_document->fps());
1027 scene()->addItem(m_dropItem);
1031 void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) {
1032 event->setDropAction(Qt::IgnoreAction);
1034 int track = (int)(mapToScene(event->pos()).y() / m_tracksHeight);
1035 int pos = mapToScene(event->pos()).x();
1036 m_dropItem->setPos(pos, track * m_tracksHeight + 1);
1037 event->setDropAction(Qt::MoveAction);
1038 if (event->mimeData()->hasFormat("kdenlive/producerslist") || event->mimeData()->hasFormat("kdenlive/clip")) {
1039 event->acceptProposedAction();
1042 QGraphicsView::dragMoveEvent(event);
1046 void CustomTrackView::dragLeaveEvent(QDragLeaveEvent * event) {
1050 } else QGraphicsView::dragLeaveEvent(event);
1053 void CustomTrackView::dropEvent(QDropEvent * event) {
1055 AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->clipProducer(), m_dropItem->info(), m_dropItem->effectList(), false, false);
1056 m_commandStack->push(command);
1057 //((ClipItem *) m_dropItem)->refreshClip();
1058 m_dropItem->baseClip()->addReference();
1059 m_document->updateClip(m_dropItem->baseClip()->getId());
1061 info = m_dropItem->info();
1062 info.track = m_scene->m_tracksList.count() - m_dropItem->track();
1063 //kDebug()<<"IIIIIIIIIIIIIIIIIIIIIIII TRAX CNT: "<<m_scene->m_tracksList.count()<<", DROP: "<<m_dropItem->track();
1064 m_document->renderer()->mltInsertClip(info, m_dropItem->xml(), m_dropItem->baseClip()->producer());
1065 //if (m_dropItem->baseClip()->isTransparent()) m_document->renderer()->mltAddClipTransparency(info, getPreviousVideoTrack(m_dropItem->track()), m_dropItem->baseClip()->getId());
1067 m_document->setModified(true);
1068 } else QGraphicsView::dropEvent(event);
1073 QStringList CustomTrackView::mimeTypes() const {
1074 QStringList qstrList;
1075 // list of accepted mime types for drop
1076 qstrList.append("text/plain");
1077 qstrList.append("kdenlive/producerslist");
1078 qstrList.append("kdenlive/clip");
1082 Qt::DropActions CustomTrackView::supportedDropActions() const {
1083 // returns what actions are supported when dropping
1084 return Qt::MoveAction;
1087 void CustomTrackView::setDuration(int duration) {
1088 if (duration > sceneRect().width())
1089 setSceneRect(0, 0, (duration + 100), sceneRect().height());
1090 m_projectDuration = duration;
1093 int CustomTrackView::duration() const {
1094 return m_projectDuration;
1097 void CustomTrackView::addTrack(TrackInfo type) {
1098 m_scene->m_tracksList << type;
1099 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_scene->m_tracksList.count());
1100 setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_scene->m_tracksList.count());
1101 verticalScrollBar()->setMaximum(m_tracksHeight * m_scene->m_tracksList.count());
1102 //setFixedHeight(50 * m_tracksCount);
1105 void CustomTrackView::removeTrack() {
1106 // TODO: implement track deletion
1108 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_scene->m_tracksList.count());
1112 void CustomTrackView::slotSwitchTrackAudio(int ix) {
1113 int tracknumber = m_scene->m_tracksList.count() - ix;
1114 kDebug() << "///// MUTING TRK: " << ix << ";Ā PL NUM: " << tracknumber;
1115 m_scene->m_tracksList[tracknumber - 1].isMute = !m_scene->m_tracksList.at(tracknumber - 1).isMute;
1116 m_document->renderer()->mltChangeTrackState(tracknumber, m_scene->m_tracksList.at(tracknumber - 1).isMute, m_scene->m_tracksList.at(tracknumber - 1).isBlind);
1119 void CustomTrackView::slotSwitchTrackVideo(int ix) {
1120 int tracknumber = m_scene->m_tracksList.count() - ix;
1121 m_scene->m_tracksList[tracknumber - 1].isBlind = !m_scene->m_tracksList.at(tracknumber - 1).isBlind;
1122 m_document->renderer()->mltChangeTrackState(tracknumber, m_scene->m_tracksList.at(tracknumber - 1).isMute, m_scene->m_tracksList.at(tracknumber - 1).isBlind);
1125 void CustomTrackView::deleteClip(const QString &clipId) {
1126 QList<QGraphicsItem *> itemList = items();
1127 for (int i = 0; i < itemList.count(); i++) {
1128 if (itemList.at(i)->type() == AVWIDGET) {
1129 ClipItem *item = (ClipItem *)itemList.at(i);
1130 if (item->clipProducer() == clipId) {
1131 AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), true, true);
1132 m_commandStack->push(command);
1139 void CustomTrackView::setCursorPos(int pos, bool seek) {
1140 emit cursorMoved((int)(m_cursorPos), (int)(pos));
1142 m_cursorLine->setPos(pos, 0);
1143 if (seek) m_document->renderer()->seek(GenTime(pos, m_document->fps()));
1144 else if (m_autoScroll) checkScrolling();
1147 void CustomTrackView::updateCursorPos() {
1148 m_cursorLine->setPos(m_cursorPos, 0);
1151 int CustomTrackView::cursorPos() {
1152 return (int)(m_cursorPos);
1155 void CustomTrackView::moveCursorPos(int delta) {
1156 if (m_cursorPos + delta < 0) delta = 0 - m_cursorPos;
1157 emit cursorMoved((int)(m_cursorPos), (int)((m_cursorPos + delta)));
1158 m_cursorPos += delta;
1159 m_cursorLine->setPos(m_cursorPos, 0);
1160 m_document->renderer()->seek(GenTime(m_cursorPos, m_document->fps()));
1161 //if (m_autoScroll && m_scale < 50) checkScrolling();
1164 void CustomTrackView::checkScrolling() {
1165 int vert = verticalScrollBar()->value();
1166 int hor = cursorPos();
1167 ensureVisible(hor, vert + 10, 2, 2, 50, 0);
1168 //centerOn(QPointF(cursorPos(), m_tracksHeight));
1169 /*QRect rectInView = viewport()->rect();
1170 int delta = rectInView.width() / 3;
1171 int max = rectInView.right() + horizontalScrollBar()->value() - delta;
1172 //kDebug() << "CURSOR POS: "<<m_cursorPos<< "Scale: "<<m_scale;
1173 if (m_cursorPos * m_scale >= max) horizontalScrollBar()->setValue((int)(horizontalScrollBar()->value() + 1 + m_scale));*/
1176 void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
1177 QGraphicsView::mouseReleaseEvent(event);
1178 if (event->button() == Qt::MidButton) {
1181 setDragMode(QGraphicsView::NoDrag);
1182 if (m_operationMode == MOVEGUIDE) {
1183 setCursor(Qt::ArrowCursor);
1184 m_operationMode = NONE;
1185 m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, false);
1186 EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), GenTime(m_dragGuide->pos().x(), m_document->fps()), m_dragGuide->label(), false);
1187 m_commandStack->push(command);
1188 m_dragGuide->updateGuide(GenTime(m_dragGuide->pos().x(), m_document->fps()));
1193 if (m_dragItem == NULL) {
1194 emit transitionItemSelected(NULL);
1197 ItemInfo info = m_dragItem->info();
1199 if (m_operationMode == MOVE) {
1200 setCursor(Qt::OpenHandCursor);
1202 if (m_selectionGroup == NULL) {
1203 // we are moving one clip, easy
1204 if (m_dragItem->type() == AVWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
1205 bool success = m_document->renderer()->mltMoveClip((int)(m_scene->m_tracksList.count() - m_dragItemInfo.track), (int)(m_scene->m_tracksList.count() - m_dragItem->track()), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(m_dragItem->startPos().frames(m_document->fps())));
1207 MoveClipCommand *command = new MoveClipCommand(this, m_dragItemInfo, info, false);
1208 m_commandStack->push(command);
1210 // undo last move and emit error message
1211 MoveClipCommand *command = new MoveClipCommand(this, info, m_dragItemInfo, true);
1212 m_commandStack->push(command);
1213 emit displayMessage(i18n("Cannot move clip to position %1seconds", QString::number(m_dragItemInfo.startPos.seconds(), 'g', 2)), ErrorMessage);
1216 if (m_dragItem->type() == TRANSITIONWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
1217 MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false);
1218 m_commandStack->push(command);
1219 Transition *transition = (Transition *) m_dragItem;
1220 transition->updateTransitionEndTrack(getPreviousVideoTrack(m_dragItem->track()));
1221 m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_scene->m_tracksList.count() - m_dragItemInfo.track), (int)(m_scene->m_tracksList.count() - m_dragItem->track()), transition->transitionEndTrack(), m_dragItemInfo.startPos, m_dragItemInfo.endPos, info.startPos, info.endPos);
1224 // Moving several clips. We need to delete them and readd them to new position,
1225 // or they might overlap each other during the move
1227 GenTime timeOffset = info.startPos - m_dragItemInfo.startPos;
1228 int trackOffset = info.track - m_dragItemInfo.track;
1229 if (timeOffset != GenTime() || trackOffset != 0) {
1230 QUndoCommand *moveClips = new QUndoCommand();
1231 moveClips->setText("Move clips");
1232 // remove items in MLT playlist
1233 for (int i = 0; i < m_selectedClipList.count(); i++) {
1234 AbstractClipItem *item = m_selectedClipList.at(i);
1235 ItemInfo info = item->info();
1236 info.startPos = info.startPos - timeOffset;
1237 info.endPos = info.endPos - timeOffset;
1238 info.track = info.track - trackOffset;
1239 if (item->type() == AVWIDGET) {
1240 ClipItem *clip = static_cast <ClipItem*>(item);
1241 new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), info, clip->effectList(), false, true, moveClips);
1242 m_document->renderer()->mltRemoveClip(m_scene->m_tracksList.count() - info.track, info.startPos);
1244 Transition *tr = static_cast <Transition*>(item);
1245 new AddTransitionCommand(this, info, tr->transitionEndTrack(), tr->toXML(), false, true, moveClips);
1246 m_document->renderer()->mltDeleteTransition(tr->transitionTag(), tr->transitionEndTrack(), m_scene->m_tracksList.count() - info.track, info.startPos, info.endPos, tr->toXML());
1250 for (int i = 0; i < m_selectedClipList.count(); i++) {
1251 // re-add items in correct place
1252 AbstractClipItem *item = m_selectedClipList.at(i);
1253 if (item->type() == AVWIDGET) {
1254 ClipItem *clip = static_cast <ClipItem*>(item);
1255 new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), item->info(), clip->effectList(), false, false, moveClips);
1256 ItemInfo info = item->info();
1257 info.track = m_scene->m_tracksList.count() - item->track();
1258 m_document->renderer()->mltInsertClip(info, clip->xml(), clip->baseClip()->producer());
1260 Transition *tr = static_cast <Transition*>(item);
1261 ItemInfo transitionInfo = tr->info();
1262 new AddTransitionCommand(this, info, tr->transitionEndTrack(), tr->toXML(), false, false, moveClips);
1263 m_document->renderer()->mltAddTransition(tr->transitionTag(), tr->transitionEndTrack() + trackOffset, m_scene->m_tracksList.count() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, tr->toXML());
1266 m_commandStack->push(moveClips);
1270 } else if (m_operationMode == RESIZESTART && m_dragItem->startPos() != m_dragItemInfo.startPos) {
1272 if (m_dragItem->type() == AVWIDGET) {
1273 ItemInfo resizeinfo = m_dragItemInfo;
1274 resizeinfo.track = m_scene->m_tracksList.count() - resizeinfo.track;
1275 bool success = m_document->renderer()->mltResizeClipStart(resizeinfo, m_dragItem->startPos() - m_dragItemInfo.startPos);
1277 updateClipFade((ClipItem *) m_dragItem);
1278 ResizeClipCommand *command = new ResizeClipCommand(this, m_dragItemInfo, info, false);
1279 m_commandStack->push(command);
1281 m_dragItem->resizeStart((int) m_dragItemInfo.startPos.frames(m_document->fps()));
1282 emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
1284 } else if (m_dragItem->type() == TRANSITIONWIDGET) {
1285 MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false);
1286 m_commandStack->push(command);
1287 Transition *transition = static_cast <Transition *>(m_dragItem);
1288 m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_scene->m_tracksList.count() - m_dragItemInfo.track), (int)(m_scene->m_tracksList.count() - m_dragItemInfo.track), 0, m_dragItemInfo.startPos, m_dragItemInfo.endPos, info.startPos, info.endPos);
1291 //m_document->renderer()->doRefresh();
1292 } else if (m_operationMode == RESIZEEND && m_dragItem->endPos() != m_dragItemInfo.endPos) {
1294 if (m_dragItem->type() == AVWIDGET) {
1295 ItemInfo resizeinfo = info;
1296 resizeinfo.track = m_scene->m_tracksList.count() - resizeinfo.track;
1297 bool success = m_document->renderer()->mltResizeClipEnd(resizeinfo, resizeinfo.endPos - resizeinfo.startPos);
1299 ResizeClipCommand *command = new ResizeClipCommand(this, m_dragItemInfo, info, false);
1300 m_commandStack->push(command);
1302 m_dragItem->resizeEnd((int) m_dragItemInfo.endPos.frames(m_document->fps()));
1303 emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
1305 } else if (m_dragItem->type() == TRANSITIONWIDGET) {
1306 MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false);
1307 m_commandStack->push(command);
1308 Transition *transition = static_cast <Transition *>(m_dragItem);
1309 m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_scene->m_tracksList.count() - m_dragItemInfo.track), (int)(m_scene->m_tracksList.count() - m_dragItemInfo.track), 0, m_dragItemInfo.startPos, m_dragItemInfo.endPos, info.startPos, info.endPos);
1311 //m_document->renderer()->doRefresh();
1312 } else if (m_operationMode == FADEIN) {
1313 //Ā resize fade in effect
1314 ClipItem * item = (ClipItem *) m_dragItem;
1315 QStringList clipeffects = item->effectNames();
1316 if (clipeffects.contains(i18n("Fade in"))) {
1317 int ix = clipeffects.indexOf(i18n("Fade in"));
1318 QDomElement oldeffect = item->effectAt(ix);
1319 int start = item->cropStart().frames(m_document->fps());
1320 int end = item->fadeIn();
1322 slotDeleteEffect(item, oldeffect);
1325 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade in");
1326 EffectsList::setParameter(effect, "in", QString::number(start));
1327 EffectsList::setParameter(effect, "out", QString::number(end));
1328 slotUpdateClipEffect(item, oldeffect, effect, ix);
1330 } else if (item->fadeIn() != 0) {
1331 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade in");
1332 int start = item->cropStart().frames(m_document->fps());
1333 int end = item->fadeIn() + start;
1334 EffectsList::setParameter(effect, "in", QString::number(start));
1335 EffectsList::setParameter(effect, "out", QString::number(end));
1336 slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
1338 } else if (m_operationMode == FADEOUT) {
1339 //Ā resize fade in effect
1340 ClipItem * item = (ClipItem *) m_dragItem;
1341 QStringList clipeffects = item->effectNames();
1342 if (clipeffects.contains(i18n("Fade out"))) {
1343 int ix = clipeffects.indexOf(i18n("Fade out"));
1344 QDomElement oldeffect = item->effectAt(ix);
1345 int end = (item->duration() + item->cropStart()).frames(m_document->fps());
1346 int start = item->fadeOut();
1348 slotDeleteEffect(item, oldeffect);
1350 start = end - start;
1351 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade out");
1352 EffectsList::setParameter(effect, "in", QString::number(start));
1353 EffectsList::setParameter(effect, "out", QString::number(end));
1354 slotUpdateClipEffect(item, oldeffect, effect, ix);
1356 } else if (item->fadeOut() != 0) {
1357 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade out");
1358 int end = (item->duration() + item->cropStart()).frames(m_document->fps());
1359 int start = end - item->fadeOut();
1360 EffectsList::setParameter(effect, "in", QString::number(start));
1361 EffectsList::setParameter(effect, "out", QString::number(end));
1362 slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
1364 } else if (m_operationMode == KEYFRAME) {
1365 // update the MLT effect
1366 ClipItem * item = (ClipItem *) m_dragItem;
1367 QString previous = item->keyframes(item->selectedEffectIndex());
1368 item->updateKeyframeEffect();
1369 QString next = item->keyframes(item->selectedEffectIndex());
1370 EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
1371 m_commandStack->push(command);
1372 updateEffect(m_scene->m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
1375 emit transitionItemSelected((m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) ? static_cast <Transition *>(m_dragItem) : NULL);
1376 m_document->setModified(true);
1377 m_operationMode = NONE;
1380 void CustomTrackView::deleteClip(ItemInfo info) {
1381 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()) + 1, info.track);
1383 kDebug() << "----------------Ā ERROR, CANNOT find clip to delete at...";// << rect.x();
1386 if (item->isSelected()) emit clipItemSelected(NULL);
1387 item->baseClip()->removeReference();
1388 m_document->updateClip(item->baseClip()->getId());
1389 scene()->removeItem(item);
1391 m_document->renderer()->mltRemoveClip(m_scene->m_tracksList.count() - info.track, info.startPos);
1392 m_document->renderer()->doRefresh();
1395 void CustomTrackView::deleteSelectedClips() {
1396 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1397 if (itemList.count() == 0) {
1398 emit displayMessage(i18n("Select clip to delete"), ErrorMessage);
1401 QUndoCommand *deleteSelected = new QUndoCommand();
1402 deleteSelected->setText(i18n("Delete selected items"));
1403 for (int i = 0; i < itemList.count(); i++) {
1404 if (itemList.at(i)->type() == AVWIDGET) {
1405 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1406 new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), true, true, deleteSelected);
1407 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
1408 Transition *item = static_cast <Transition *>(itemList.at(i));
1410 info.startPos = item->startPos();
1411 info.endPos = item->endPos();
1412 info.track = item->track();
1413 new AddTransitionCommand(this, info, item->transitionEndTrack(), item->toXML(), true, true, deleteSelected);
1416 m_commandStack->push(deleteSelected);
1419 void CustomTrackView::changeClipSpeed() {
1420 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1421 if (itemList.count() == 0) {
1422 emit displayMessage(i18n("Select clip to change speed"), ErrorMessage);
1425 QUndoCommand *changeSelected = new QUndoCommand();
1426 changeSelected->setText("Edit clip speed");
1427 for (int i = 0; i < itemList.count(); i++) {
1428 if (itemList.at(i)->type() == AVWIDGET) {
1429 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1430 ItemInfo info = item->info();
1431 int percent = QInputDialog::getInteger(this, i18n("Edit Clip Speed"), i18n("New speed (percents)"), 100, 1, 300);
1432 double speed = (double) percent / 100.0;
1433 if (item->speed() != speed)
1434 new ChangeSpeedCommand(this, info, item->speed(), speed, item->clipProducer(), true, changeSelected);
1437 m_commandStack->push(changeSelected);
1440 void CustomTrackView::doChangeClipSpeed(ItemInfo info, double speed, const QString &id) {
1441 DocClipBase *baseclip = m_document->clipManager()->getClipById(id);
1442 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()) + 1, info.track);
1443 info.track = m_scene->m_tracksList.count() - item->track();
1444 m_document->renderer()->mltChangeClipSpeed(info, speed, baseclip->producer());
1445 item->setSpeed(speed);
1446 GenTime maxDuration = item->maxDuration();
1447 if (maxDuration < item->duration()) {
1448 info = item->info();
1449 ItemInfo endInfo = info;
1450 endInfo.endPos = info.startPos + maxDuration;
1451 ResizeClipCommand *command = new ResizeClipCommand(this, info, endInfo, true);
1452 m_commandStack->push(command);
1456 void CustomTrackView::cutSelectedClips() {
1457 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1458 GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
1459 for (int i = 0; i < itemList.count(); i++) {
1460 if (itemList.at(i)->type() == AVWIDGET) {
1461 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1462 if (currentPos > item->startPos() && currentPos < item->endPos()) {
1463 RazorClipCommand *command = new RazorClipCommand(this, item->info(), currentPos, true);
1464 m_commandStack->push(command);
1470 void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo info, EffectsList effects) {
1471 DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId);
1472 if (baseclip == NULL) {
1473 emit displayMessage(i18n("No clip copied"), ErrorMessage);
1476 ClipItem *item = new ClipItem(baseclip, info, m_document->fps());
1477 item->setEffectList(effects);
1478 scene()->addItem(item);
1479 baseclip->addReference();
1480 m_document->updateClip(baseclip->getId());
1481 info.track = m_scene->m_tracksList.count() - info.track;
1482 m_document->renderer()->mltInsertClip(info, xml, baseclip->producer());
1483 for (int i = 0; i < item->effectsCount(); i++) {
1484 m_document->renderer()->mltAddEffect(info.track, info.startPos, item->getEffectArgs(item->effectAt(i)), false);
1486 m_document->renderer()->doRefresh();
1489 void CustomTrackView::slotUpdateClip(const QString &clipId) {
1490 QList<QGraphicsItem *> list = scene()->items();
1491 ClipItem *clip = NULL;
1492 for (int i = 0; i < list.size(); ++i) {
1493 if (list.at(i)->type() == AVWIDGET) {
1494 clip = static_cast <ClipItem *>(list.at(i));
1495 if (clip->clipProducer() == clipId) {
1496 clip->refreshClip();
1497 ItemInfo info = clip->info();
1498 info.track = m_scene->m_tracksList.count() - clip->track();
1499 m_document->renderer()->mltUpdateClip(info, clip->xml(), clip->baseClip()->producer());
1505 ClipItem *CustomTrackView::getClipItemAt(int pos, int track) {
1506 QList<QGraphicsItem *> list = scene()->items(QPointF(pos , track * m_tracksHeight + m_tracksHeight / 2));
1507 ClipItem *clip = NULL;
1508 for (int i = 0; i < list.size(); ++i) {
1509 if (list.at(i)->type() == AVWIDGET) {
1510 clip = static_cast <ClipItem *>(list.at(i));
1517 ClipItem *CustomTrackView::getClipItemAt(GenTime pos, int track) {
1518 int framepos = (int)(pos.frames(m_document->fps()));
1519 return getClipItemAt(framepos, track);
1522 Transition *CustomTrackView::getTransitionItemAt(int pos, int track) {
1523 QList<QGraphicsItem *> list = scene()->items(QPointF(pos, (track + 1) * m_tracksHeight));
1524 Transition *clip = NULL;
1525 for (int i = 0; i < list.size(); ++i) {
1526 if (list.at(i)->type() == TRANSITIONWIDGET) {
1527 clip = static_cast <Transition *>(list.at(i));
1534 Transition *CustomTrackView::getTransitionItemAt(GenTime pos, int track) {
1535 int framepos = (int)(pos.frames(m_document->fps()));
1536 return getTransitionItemAt(framepos, track);
1539 void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end) {
1540 ClipItem *item = getClipItemAt((int) start.startPos.frames(m_document->fps()) + 1, start.track);
1542 emit displayMessage(i18n("Cannot move clip at time: %1s on track %2", QString::number(start.startPos.seconds(), 'g', 2), start.track), ErrorMessage);
1543 kDebug() << "----------------Ā ERROR, CANNOT find clip to move at.. ";// << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2;
1546 //kDebug() << "----------------Ā Move CLIP FROM: " << startPos.x() << ", END:" << endPos.x() << ",TRACKS: " << startPos.y() << " TO " << endPos.y();
1548 bool success = m_document->renderer()->mltMoveClip((int)(m_scene->m_tracksList.count() - start.track), (int)(m_scene->m_tracksList.count() - end.track), (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()));
1550 item->setPos((int) end.startPos.frames(m_document->fps()), (int)(end.track * m_tracksHeight + 1));
1552 // undo last move and emit error message
1553 emit displayMessage(i18n("Cannot move clip to position %1seconds", QString::number(end.startPos.seconds(), 'g', 2)), ErrorMessage);
1557 void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end) {
1558 Transition *item = getTransitionItemAt((int)start.startPos.frames(m_document->fps()) + 1, start.track);
1560 emit displayMessage(i18n("Cannot move transition at time: %1s on track %2", start.startPos.seconds(), start.track), ErrorMessage);
1561 kDebug() << "----------------Ā ERROR, CANNOT find transition to move... ";// << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2;
1564 //kDebug() << "----------------Ā Move TRANSITION FROM: " << startPos.x() << ", END:" << endPos.x() << ",TRACKS: " << oldtrack << " TO " << newtrack;
1566 //kDebug()<<"/// RESIZEĀ TRANS START: ("<< startPos.x()<<"x"<< startPos.y()<<") / ("<<endPos.x()<<"x"<< endPos.y()<<")";
1567 if (end.endPos - end.startPos == start.endPos - start.startPos) {
1568 // Transition was moved
1569 item->setPos((int) end.startPos.frames(m_document->fps()), (end.track) * m_tracksHeight + 1);
1570 } else if (end.endPos == start.endPos) {
1571 // Transition start resize
1572 item->resizeStart((int) end.startPos.frames(m_document->fps()));
1574 // Transition end resize;
1575 item->resizeEnd((int) end.endPos.frames(m_document->fps()));
1577 //item->moveTransition(GenTime((int) (endPos.x() - startPos.x()), m_document->fps()));
1578 item->updateTransitionEndTrack(getPreviousVideoTrack(end.track));
1579 m_document->renderer()->mltMoveTransition(item->transitionTag(), m_scene->m_tracksList.count() - start.track, m_scene->m_tracksList.count() - end.track, item->transitionEndTrack(), start.startPos, start.endPos, end.startPos, end.endPos);
1582 void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end) {
1584 bool resizeClipStart = true;
1585 if (start.startPos == end.startPos) resizeClipStart = false;
1586 /*if (resizeClipStart) offset = 1;
1588 ClipItem *item = getClipItemAt((int)(start.startPos.frames(m_document->fps()) + offset), start.track);
1590 emit displayMessage(i18n("Cannot move clip at time: %1s on track %2", start.startPos.seconds(), start.track), ErrorMessage);
1591 kDebug() << "----------------Ā ERROR, CANNOT find clip to resize at... "; // << startPos;
1594 if (resizeClipStart) {
1595 ItemInfo clipinfo = item->info();
1596 clipinfo.track = m_scene->m_tracksList.count() - clipinfo.track;
1597 bool success = m_document->renderer()->mltResizeClipStart(clipinfo, end.startPos - item->startPos());
1599 item->resizeStart((int) end.startPos.frames(m_document->fps()));
1600 updateClipFade(item);
1601 } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
1603 ItemInfo clipinfo = item->info();
1604 clipinfo.track = m_scene->m_tracksList.count() - clipinfo.track;
1605 bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, end.endPos - clipinfo.startPos);
1607 item->resizeEnd((int) end.endPos.frames(m_document->fps()));
1608 updateClipFade(item, true);
1609 } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
1611 m_document->renderer()->doRefresh();
1614 void CustomTrackView::updateClipFade(ClipItem * item, bool updateFadeOut) {
1615 if (!updateFadeOut) {
1616 int end = item->fadeIn();
1618 // there is a fade in effect
1619 QStringList clipeffects = item->effectNames();
1620 QDomElement oldeffect = item->effectAt(clipeffects.indexOf("Fade in"));
1621 int start = item->cropStart().frames(m_document->fps());
1623 EffectsList::setParameter(oldeffect, "in", QString::number(start));
1624 EffectsList::setParameter(oldeffect, "out", QString::number(end));
1625 QHash <QString, QString> effectParams = item->getEffectArgs(oldeffect);
1626 if (!m_document->renderer()->mltEditEffect(m_scene->m_tracksList.count() - item->track(), item->startPos(), effectParams))
1627 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
1630 int start = item->fadeOut();
1632 // there is a fade in effect
1633 QStringList clipeffects = item->effectNames();
1634 QDomElement oldeffect = item->effectAt(clipeffects.indexOf("Fade out"));
1635 int end = (item->duration() - item->cropStart()).frames(m_document->fps());
1636 start = end - start;
1637 EffectsList::setParameter(oldeffect, "in", QString::number(start));
1638 EffectsList::setParameter(oldeffect, "out", QString::number(end));
1639 QHash <QString, QString> effectParams = item->getEffectArgs(oldeffect);
1640 if (m_document->renderer()->mltEditEffect(m_scene->m_tracksList.count() - item->track(), item->startPos(), effectParams))
1641 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
1646 double CustomTrackView::getSnapPointForPos(double pos) {
1647 return m_scene->getSnapPointForPos(pos);
1650 void CustomTrackView::updateSnapPoints(AbstractClipItem *selected) {
1651 QList <GenTime> snaps;
1653 if (selected) offset = selected->duration();
1654 QList<QGraphicsItem *> itemList = items();
1655 for (int i = 0; i < itemList.count(); i++) {
1656 if (itemList.at(i)->type() == AVWIDGET && itemList.at(i) != selected) {
1657 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1658 GenTime start = item->startPos();
1659 GenTime end = item->endPos();
1660 snaps.append(start);
1662 QList < GenTime > markers = item->snapMarkers();
1663 for (int i = 0; i < markers.size(); ++i) {
1664 GenTime t = markers.at(i);
1666 if (t > offset) snaps.append(t - offset);
1668 if (offset != GenTime()) {
1669 if (start > offset) snaps.append(start - offset);
1670 if (end > offset) snaps.append(end - offset);
1672 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
1673 Transition *transition = static_cast <Transition*>(itemList.at(i));
1674 GenTime start = transition->startPos();
1675 GenTime end = transition->endPos();
1676 snaps.append(start);
1678 if (offset != GenTime()) {
1679 if (start > offset) snaps.append(start - offset);
1680 if (end > offset) snaps.append(end - offset);
1685 // add cursor position
1686 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1688 if (offset != GenTime()) snaps.append(pos - offset);
1691 for (int i = 0; i < m_guides.count(); i++) {
1692 snaps.append(m_guides.at(i)->position());
1693 if (offset != GenTime()) snaps.append(m_guides.at(i)->position() - offset);
1697 m_scene->setSnapList(snaps);
1698 //for (int i = 0; i < m_snapPoints.size(); ++i)
1699 // kDebug() << "SNAP POINT: " << m_snapPoints.at(i).frames(25);
1702 void CustomTrackView::slotSeekToPreviousSnap() {
1703 updateSnapPoints(NULL);
1704 GenTime res = m_scene->previousSnapPoint(GenTime(m_cursorPos, m_document->fps()));
1705 setCursorPos((int) res.frames(m_document->fps()));
1709 void CustomTrackView::slotSeekToNextSnap() {
1710 updateSnapPoints(NULL);
1711 GenTime res = m_scene->nextSnapPoint(GenTime(m_cursorPos, m_document->fps()));
1712 setCursorPos((int) res.frames(m_document->fps()));
1716 void CustomTrackView::clipStart() {
1717 ClipItem *item = getMainActiveClip();
1719 setCursorPos((int) item->startPos().frames(m_document->fps()));
1724 void CustomTrackView::clipEnd() {
1725 ClipItem *item = getMainActiveClip();
1727 setCursorPos((int) item->endPos().frames(m_document->fps()));
1732 void CustomTrackView::slotAddClipMarker() {
1733 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1734 if (itemList.count() != 1) {
1735 emit displayMessage(i18n("Cannot add marker if more than one clip is selected"), ErrorMessage);
1736 kDebug() << "// CANNOT ADD MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1739 AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1740 if (item->type() != AVWIDGET) return;
1741 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1742 if (item->startPos() > pos || item->endPos() < pos) return;
1743 ClipItem *clip = (ClipItem *) item;
1744 QString id = clip->baseClip()->getId();
1745 GenTime position = pos - item->startPos() + item->cropStart();
1746 CommentedTime marker(position, i18n("Marker"));
1747 MarkerDialog d(clip->baseClip(), marker, m_document->timecode(), this);
1748 if (d.exec() == QDialog::Accepted) {
1749 slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1753 void CustomTrackView::slotAddClipMarker(const QString &id, GenTime t, QString c) {
1754 QString oldcomment = m_document->clipManager()->getClipById(id)->markerComment(t);
1755 AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, c, id, t, true);
1756 m_commandStack->push(command);
1759 void CustomTrackView::slotDeleteClipMarker() {
1760 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1761 if (itemList.count() != 1) {
1762 emit displayMessage(i18n("Cannot delete marker if more than one clip is selected"), ErrorMessage);
1763 kDebug() << "// CANNOT DELETE MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1766 AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1767 if (item->type() != AVWIDGET) {
1768 emit displayMessage(i18n("No clip selected"), ErrorMessage);
1771 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1772 if (item->startPos() > pos || item->endPos() < pos) {
1773 emit displayMessage(i18n("No selected clip at cursor time"), ErrorMessage);
1776 ClipItem *clip = (ClipItem *) item;
1777 QString id = clip->baseClip()->getId();
1778 GenTime position = pos - item->startPos() + item->cropStart();
1779 QString comment = clip->baseClip()->markerComment(position);
1780 if (comment.isEmpty()) {
1781 emit displayMessage(i18n("No marker found at cursor time"), ErrorMessage);
1784 AddMarkerCommand *command = new AddMarkerCommand(this, comment, QString(), id, position, true);
1785 m_commandStack->push(command);
1788 void CustomTrackView::slotDeleteAllClipMarkers() {
1789 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1790 if (itemList.count() != 1) {
1791 emit displayMessage(i18n("Cannot delete marker if more than one clip is selected"), ErrorMessage);
1792 kDebug() << "// CANNOT DELETE MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1795 AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1796 if (item->type() != AVWIDGET) {
1797 emit displayMessage(i18n("No clip selected"), ErrorMessage);
1801 ClipItem *clip = static_cast <ClipItem *>(item);
1802 QList <CommentedTime> markers = clip->baseClip()->commentedSnapMarkers();
1804 if (markers.isEmpty()) {
1805 emit displayMessage(i18n("Clip has no markers"), ErrorMessage);
1808 QString id = clip->baseClip()->getId();
1809 QUndoCommand *deleteMarkers = new QUndoCommand();
1810 deleteMarkers->setText("Delete clip markers");
1812 for (int i = 0; i < markers.size(); i++) {
1813 new AddMarkerCommand(this, markers.at(i).comment(), QString(), id, markers.at(i).time(), true, deleteMarkers);
1815 m_commandStack->push(deleteMarkers);
1818 void CustomTrackView::slotEditClipMarker() {
1819 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1820 if (itemList.count() != 1) {
1821 emit displayMessage(i18n("Cannot edit marker if more than one clip is selected"), ErrorMessage);
1822 kDebug() << "// CANNOT DELETE MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1825 AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1826 if (item->type() != AVWIDGET) {
1827 emit displayMessage(i18n("No clip at cursor time"), ErrorMessage);
1830 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1831 if (item->startPos() > pos || item->endPos() < pos) {
1832 emit displayMessage(i18n("No selected clip at cursor time"), ErrorMessage);
1835 ClipItem *clip = (ClipItem *) item;
1836 QString id = clip->baseClip()->getId();
1837 GenTime position = pos - item->startPos() + item->cropStart();
1838 QString oldcomment = clip->baseClip()->markerComment(position);
1839 if (oldcomment.isEmpty()) {
1840 emit displayMessage(i18n("No marker found at cursor time"), ErrorMessage);
1844 CommentedTime marker(position, oldcomment);
1845 MarkerDialog d(clip->baseClip(), marker, m_document->timecode(), this);
1846 if (d.exec() == QDialog::Accepted) {
1847 if (d.newMarker().time() == position) {
1848 // marker position was not changed, only text
1849 AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, d.newMarker().comment(), id, position, true);
1850 m_commandStack->push(command);
1852 // marker text and position were changed, remove previous marker and add new one
1853 AddMarkerCommand *command1 = new AddMarkerCommand(this, oldcomment, QString(), id, position, true);
1854 AddMarkerCommand *command2 = new AddMarkerCommand(this, QString(), d.newMarker().comment(), id, d.newMarker().time(), true);
1855 m_commandStack->push(command1);
1856 m_commandStack->push(command2);
1861 void CustomTrackView::addMarker(const QString &id, const GenTime &pos, const QString comment) {
1862 DocClipBase *base = m_document->clipManager()->getClipById(id);
1863 if (!comment.isEmpty()) base->addSnapMarker(pos, comment);
1864 else base->deleteSnapMarker(pos);
1865 m_document->setModified(true);
1866 viewport()->update();
1869 bool sortGuidesList(const Guide *g1 , const Guide *g2) {
1870 return (*g1).position() < (*g2).position();
1873 void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const QString &comment) {
1874 if (oldPos > GenTime() && pos > GenTime()) {
1876 for (int i = 0; i < m_guides.count(); i++) {
1877 if (m_guides.at(i)->position() == oldPos) {
1878 Guide *item = m_guides.at(i);
1879 item->updateGuide(pos, comment);
1883 } else if (pos > GenTime()) addGuide(pos, comment);
1887 for (int i = 0; i < m_guides.count(); i++) {
1888 if (m_guides.at(i)->position() == oldPos) {
1889 Guide *item = m_guides.takeAt(i);
1895 if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
1897 qSort(m_guides.begin(), m_guides.end(), sortGuidesList);
1898 m_document->syncGuides(m_guides);
1901 bool CustomTrackView::addGuide(const GenTime pos, const QString &comment) {
1902 for (int i = 0; i < m_guides.count(); i++) {
1903 if (m_guides.at(i)->position() == pos) {
1904 emit displayMessage(i18n("A guide already exists at that position"), ErrorMessage);
1908 Guide *g = new Guide(this, pos, comment, m_document->fps(), m_tracksHeight * m_scene->m_tracksList.count());
1909 scene()->addItem(g);
1911 qSort(m_guides.begin(), m_guides.end(), sortGuidesList);
1912 m_document->syncGuides(m_guides);
1916 void CustomTrackView::slotAddGuide() {
1917 CommentedTime marker(GenTime(m_cursorPos, m_document->fps()), i18n("Guide"));
1918 MarkerDialog d(NULL, marker, m_document->timecode(), this);
1919 if (d.exec() != QDialog::Accepted) return;
1920 if (addGuide(d.newMarker().time(), d.newMarker().comment())) {
1921 EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), d.newMarker().time(), d.newMarker().comment(), false);
1922 m_commandStack->push(command);
1926 void CustomTrackView::slotEditGuide() {
1927 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1929 for (int i = 0; i < m_guides.count(); i++) {
1930 if (m_guides.at(i)->position() == pos) {
1931 slotEditGuide(m_guides.at(i)->info());
1936 if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
1939 void CustomTrackView::slotEditGuide(CommentedTime guide) {
1940 MarkerDialog d(NULL, guide, m_document->timecode(), this);
1941 if (d.exec() == QDialog::Accepted) {
1942 EditGuideCommand *command = new EditGuideCommand(this, guide.time(), guide.comment(), d.newMarker().time(), d.newMarker().comment(), true);
1943 m_commandStack->push(command);
1948 void CustomTrackView::slotDeleteGuide() {
1949 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1951 for (int i = 0; i < m_guides.count(); i++) {
1952 if (m_guides.at(i)->position() == pos) {
1953 EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true);
1954 m_commandStack->push(command);
1959 if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
1962 void CustomTrackView::slotDeleteAllGuides() {
1963 QUndoCommand *deleteAll = new QUndoCommand();
1964 deleteAll->setText("Delete all guides");
1965 for (int i = 0; i < m_guides.count(); i++) {
1966 EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true, deleteAll);
1968 m_commandStack->push(deleteAll);
1971 void CustomTrackView::setTool(PROJECTTOOL tool) {
1975 void CustomTrackView::setScale(double scaleFactor) {
1977 matrix = matrix.scale(scaleFactor, 1);
1978 m_scene->setScale(scaleFactor);
1979 //scale(scaleFactor, 1);
1980 m_animationTimer->stop();
1989 /*double pos = cursorPos() / m_scale;
1990 m_scale = scaleFactor;
1991 m_scene->setScale(m_scale);
1992 int vert = verticalScrollBar()->value();
1993 kDebug() << " HHHHHHHH SCALING: " << m_scale;
1994 QList<QGraphicsItem *> itemList = items();
1995 for (int i = 0; i < itemList.count(); i++) {
1996 if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
1997 AbstractClipItem *clip = (AbstractClipItem *)itemList.at(i);
1998 clip->setRect(0, 0, (qreal) clip->duration().frames(m_document->fps()) * m_scale - .5, clip->rect().height());
1999 clip->setPos((qreal) clip->startPos().frames(m_document->fps()) * m_scale, clip->pos().y());
2003 for (int i = 0; i < m_guides.count(); i++) {
2004 m_guides.at(i)->updatePosition(m_scale);
2007 setSceneRect(0, 0, (m_projectDuration + 100) * m_scale, sceneRect().height());
2008 updateCursorPos();*/
2010 centerOn(QPointF(cursorPos(), m_tracksHeight));
2011 //verticalScrollBar()->setValue(vert);*/
2014 void CustomTrackView::slotRefreshGuides() {
2015 if (KdenliveSettings::showmarkers()) {
2016 kDebug() << "// refresh GUIDES";
2017 for (int i = 0; i < m_guides.count(); i++) {
2018 m_guides.at(i)->update();
2023 void CustomTrackView::drawBackground(QPainter * painter, const QRectF & rect) {
2024 QColor base = palette().button().color();
2026 r.setWidth(r.width() + 1);
2027 painter->setClipRect(r);
2028 painter->drawLine(r.left(), 0, r.right(), 0);
2029 uint max = m_scene->m_tracksList.count();
2030 for (uint i = 0; i < max;i++) {
2031 /*if (max - i - 1 == m_selectedTrack) painter->fillRect(r.left(), m_tracksHeight * i + 1, r.right() - r.left() + 1, m_tracksHeight - 1, QBrush(QColor(211, 205, 147)));
2033 if (m_scene->m_tracksList.at(max - i - 1).type == AUDIOTRACK) painter->fillRect(r.left(), m_tracksHeight * i + 1, r.right() - r.left() + 1, m_tracksHeight - 1, QBrush(QColor(240, 240, 255)));
2034 painter->drawLine(r.left(), m_tracksHeight * (i + 1), r.right(), m_tracksHeight * (i + 1));
2036 int lowerLimit = m_tracksHeight * m_scene->m_tracksList.count() + 1;
2037 if (height() > lowerLimit)
2038 painter->fillRect(QRectF(r.left(), lowerLimit, r.width(), height() - lowerLimit), QBrush(base));
2041 bool CustomTrackView::findString(const QString &text) {
2043 for (int i = 0; i < m_searchPoints.size(); ++i) {
2044 marker = m_searchPoints.at(i).comment();
2045 if (marker.contains(text, Qt::CaseInsensitive)) {
2046 setCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()), true);
2047 int vert = verticalScrollBar()->value();
2048 int hor = cursorPos();
2049 ensureVisible(hor, vert + 10, 2, 2, 50, 0);
2057 bool CustomTrackView::findNextString(const QString &text) {
2059 for (int i = m_findIndex + 1; i < m_searchPoints.size(); ++i) {
2060 marker = m_searchPoints.at(i).comment();
2061 if (marker.contains(text, Qt::CaseInsensitive)) {
2062 setCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()), true);
2063 int vert = verticalScrollBar()->value();
2064 int hor = cursorPos();
2065 ensureVisible(hor, vert + 10, 2, 2, 50, 0);
2074 void CustomTrackView::initSearchStrings() {
2075 m_searchPoints.clear();
2076 QList<QGraphicsItem *> itemList = items();
2077 for (int i = 0; i < itemList.count(); i++) {
2078 // parse all clip names
2079 if (itemList.at(i)->type() == AVWIDGET) {
2080 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
2081 GenTime start = item->startPos();
2082 CommentedTime t(start, item->clipName());
2083 m_searchPoints.append(t);
2084 // add all clip markers
2085 QList < CommentedTime > markers = item->commentedSnapMarkers();
2086 m_searchPoints += markers;
2091 for (int i = 0; i < m_guides.count(); i++) {
2092 m_searchPoints.append(m_guides.at(i)->info());
2095 qSort(m_searchPoints);
2098 void CustomTrackView::clearSearchStrings() {
2099 m_searchPoints.clear();
2103 void CustomTrackView::copyClip() {
2104 while (m_copiedItems.count() > 0) {
2105 delete m_copiedItems.takeFirst();
2107 QList<QGraphicsItem *> itemList = scene()->selectedItems();
2108 if (itemList.count() == 0) {
2109 emit displayMessage(i18n("Select a clip before copying"), ErrorMessage);
2112 for (int i = 0; i < itemList.count(); i++) {
2113 if (itemList.at(i)->type() == AVWIDGET) {
2114 ClipItem *dup = static_cast <ClipItem *>(itemList.at(i));
2115 m_copiedItems.append(dup->clone(dup->info()));
2116 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
2117 Transition *dup = static_cast <Transition *>(itemList.at(i));
2118 m_copiedItems.append(dup->clone());
2123 bool CustomTrackView::canBePastedTo(ItemInfo info, int type) const {
2124 QRectF rect((double) info.startPos.frames(m_document->fps()), (double)(info.track * m_tracksHeight + 1), (double)(info.endPos - info.startPos).frames(m_document->fps()), (double)(m_tracksHeight - 1));
2125 QList<QGraphicsItem *> collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect);
2126 for (int i = 0; i < collisions.count(); i++) {
2127 if (collisions.at(i)->type() == type) return false;
2132 bool CustomTrackView::canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const {
2133 for (int i = 0; i < items.count(); i++) {
2134 ItemInfo info = items.at(i)->info();
2135 info.startPos += offset;
2136 info.endPos += offset;
2137 info.track += trackOffset;
2138 if (!canBePastedTo(info, items.at(i)->type())) return false;
2143 bool CustomTrackView::canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const {
2144 QPainterPath movePath;
2145 movePath.moveTo(0, 0);
2147 for (int i = 0; i < items.count(); i++) {
2148 ItemInfo info = items.at(i)->info();
2149 info.startPos = info.startPos + offset;
2150 info.endPos = info.endPos + offset;
2151 info.track = info.track + trackOffset;
2152 if (info.startPos < GenTime()) {
2153 // No clip should go below 0
2156 QRectF rect((double) info.startPos.frames(m_document->fps()), (double)(info.track * m_tracksHeight + 1), (double)(info.endPos - info.startPos).frames(m_document->fps()), (double)(m_tracksHeight - 1));
2157 movePath.addRect(rect);
2159 QList<QGraphicsItem *> collisions = scene()->items(movePath, Qt::IntersectsItemBoundingRect);
2160 for (int i = 0; i < collisions.count(); i++) {
2161 if ((collisions.at(i)->type() == AVWIDGET || collisions.at(i)->type() == TRANSITIONWIDGET) && !items.contains(static_cast <AbstractClipItem *>(collisions.at(i)))) {
2162 kDebug() << " //////////// CLIP COLLISION, MOVE NOT ALLOWED";
2169 void CustomTrackView::pasteClip() {
2170 if (m_copiedItems.count() == 0) {
2171 emit displayMessage(i18n("No clip copied"), ErrorMessage);
2175 if (m_menuPosition.isNull()) position = mapFromGlobal(QCursor::pos());
2176 else position = m_menuPosition;
2177 GenTime pos = GenTime((int)(mapToScene(position).x()), m_document->fps());
2178 int track = (int)(position.y() / m_tracksHeight);
2179 ItemInfo first = m_copiedItems.at(0)->info();
2181 GenTime offset = pos - first.startPos;
2182 int trackOffset = track - first.track;
2184 if (!canBePasted(m_copiedItems, offset, trackOffset)) {
2185 emit displayMessage(i18n("Cannot paste selected clips"), ErrorMessage);
2188 QUndoCommand *pasteClips = new QUndoCommand();
2189 pasteClips->setText("Paste clips");
2191 for (int i = 0; i < m_copiedItems.count(); i++) {
2192 // parse all clip names
2193 if (m_copiedItems.at(i) && m_copiedItems.at(i)->type() == AVWIDGET) {
2194 ClipItem *clip = static_cast <ClipItem *>(m_copiedItems.at(i));
2196 info.startPos = clip->startPos() + offset;
2197 info.endPos = clip->endPos() + offset;
2198 info.cropStart = clip->cropStart();
2199 info.track = clip->track() + trackOffset;
2200 if (canBePastedTo(info, AVWIDGET)) {
2201 new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), info, clip->effectList(), true, false, pasteClips);
2202 } else emit displayMessage(i18n("Cannot paste clip to selected place"), ErrorMessage);
2203 } else if (m_copiedItems.at(i) && m_copiedItems.at(i)->type() == TRANSITIONWIDGET) {
2204 Transition *tr = static_cast <Transition *>(m_copiedItems.at(i));
2206 info.startPos = tr->startPos() + offset;
2207 info.endPos = tr->endPos() + offset;
2208 info.track = tr->track() + trackOffset;
2209 if (canBePastedTo(info, TRANSITIONWIDGET)) {
2210 new AddTransitionCommand(this, info, tr->transitionEndTrack() + trackOffset, tr->toXML(), false, true, pasteClips);
2211 } else emit displayMessage(i18n("Cannot paste transition to selected place"), ErrorMessage);
2214 m_commandStack->push(pasteClips);
2217 void CustomTrackView::pasteClipEffects() {
2218 if (m_copiedItems.count() != 1 || m_copiedItems.at(0)->type() != AVWIDGET) {
2219 emit displayMessage(i18n("You must copy exactly one clip before pasting effects"), ErrorMessage);
2222 ClipItem *clip = static_cast < ClipItem *>(m_copiedItems.at(0));
2223 EffectsList effects = clip->effectList();
2225 QUndoCommand *paste = new QUndoCommand();
2226 paste->setText("Paste effects");
2228 QList<QGraphicsItem *> clips = scene()->selectedItems();
2229 for (int i = 0; i < clips.count(); ++i) {
2230 if (clips.at(i)->type() == AVWIDGET) {
2231 ClipItem *item = static_cast < ClipItem *>(clips.at(i));
2232 for (int i = 0; i < clip->effectsCount(); i++) {
2233 new AddEffectCommand(this, m_scene->m_tracksList.count() - item->track(), item->startPos(), clip->effectAt(i), true, paste);
2237 m_commandStack->push(paste);
2241 ClipItem *CustomTrackView::getClipUnderCursor() const {
2242 QRectF rect((double) m_cursorPos, 0.0, 1.0, (double)(m_tracksHeight * m_scene->m_tracksList.count()));
2243 QList<QGraphicsItem *> collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect);
2244 for (int i = 0; i < collisions.count(); i++) {
2245 if (collisions.at(i)->type() == AVWIDGET) {
2246 return static_cast < ClipItem *>(collisions.at(i));
2252 ClipItem *CustomTrackView::getMainActiveClip() const {
2253 QList<QGraphicsItem *> clips = scene()->selectedItems();
2254 if (clips.isEmpty()) {
2255 return getClipUnderCursor();
2257 ClipItem *item = NULL;
2258 for (int i = 0; i < clips.count(); ++i) {
2259 if (clips.at(i)->type() == AVWIDGET)
2260 item = static_cast < ClipItem *>(clips.at(i));
2261 if (item->startPos().frames(m_document->fps()) <= m_cursorPos && item->endPos().frames(m_document->fps()) >= m_cursorPos) break;
2263 if (item) return item;
2268 ClipItem *CustomTrackView::getActiveClipUnderCursor() const {
2269 QList<QGraphicsItem *> clips = scene()->selectedItems();
2270 if (clips.isEmpty()) {
2271 return getClipUnderCursor();
2274 for (int i = 0; i < clips.count(); ++i) {
2275 if (clips.at(i)->type() == AVWIDGET)
2276 item = static_cast < ClipItem *>(clips.at(i));
2277 if (item->startPos().frames(m_document->fps()) <= m_cursorPos && item->endPos().frames(m_document->fps()) >= m_cursorPos) return item;
2283 void CustomTrackView::setInPoint() {
2284 ClipItem *clip = getActiveClipUnderCursor();
2286 emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
2289 ItemInfo startInfo = clip->info();
2290 ItemInfo endInfo = clip->info();
2291 endInfo.startPos = GenTime(m_cursorPos, m_document->fps());
2292 ResizeClipCommand *command = new ResizeClipCommand(this, startInfo, endInfo, true);
2293 m_commandStack->push(command);
2296 void CustomTrackView::setOutPoint() {
2297 ClipItem *clip = getActiveClipUnderCursor();
2299 emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
2302 ItemInfo startInfo = clip->info();
2303 ItemInfo endInfo = clip->info();
2304 endInfo.endPos = GenTime(m_cursorPos, m_document->fps());
2305 ResizeClipCommand *command = new ResizeClipCommand(this, startInfo, endInfo, true);
2306 m_commandStack->push(command);
2309 void CustomTrackView::updateAllThumbs() {
2310 QList<QGraphicsItem *> itemList = items();
2312 Transition *transitionitem;
2313 for (int i = 0; i < itemList.count(); i++) {
2314 if (itemList.at(i)->type() == AVWIDGET) {
2315 item = static_cast <ClipItem *>(itemList.at(i));
2316 item->refreshClip();
2317 qApp->processEvents();
2322 #include "customtrackview.moc"