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) {
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) scene()->destroyItemGroup(m_selectionGroup);
526 m_dragItem->setSelected(true);
529 m_operationMode = NONE;
530 displayContextMenu(event->globalPos(), m_dragItem);
531 m_menuPosition = event->pos();
537 // No item under click
538 if (m_dragItem == NULL) {
539 if (m_selectionGroup) scene()->destroyItemGroup(m_selectionGroup);
540 setCursor(Qt::ArrowCursor);
541 m_scene->clearSelection();
542 setCursorPos((int)(mapToScene(event->x(), 0).x()));
548 if (m_tool == RAZORTOOL) {
549 if (m_dragItem->type() == TRANSITIONWIDGET) {
550 emit displayMessage(i18n("Cannot cut a transition"), ErrorMessage);
555 AbstractClipItem *clip = static_cast <AbstractClipItem *>(m_dragItem);
556 RazorClipCommand* command = new RazorClipCommand(this, clip->info(), GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()), true);
557 m_commandStack->push(command);
558 m_document->setModified(true);
563 updateSnapPoints(m_dragItem);
564 if (m_dragItem && m_dragItem->type() == AVWIDGET) emit clipItemSelected((ClipItem*) m_dragItem);
565 else emit clipItemSelected(NULL);
567 if (m_dragItem && m_operationMode == NONE) QGraphicsView::mousePressEvent(event);
569 if (m_selectionGroup) {
570 // delete selection group
571 scene()->destroyItemGroup(m_selectionGroup);
572 m_selectionGroup = NULL;
575 QList<QGraphicsItem *> selection = m_scene->selectedItems();
576 if (selection.count() > 1) {
577 m_selectionGroup = new AbstractGroupItem(m_document->fps());
578 scene()->addItem(m_selectionGroup);
579 for (int i = 0; i < selection.count(); i++) {
580 if (selection.at(i)->type() == AVWIDGET)
581 m_selectionGroup->addItem(selection.at(i));
585 m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y()));
587 if (!item->isSelected()) {
589 if (event->modifiers() != Qt::ControlModifier) {
590 QList<QGraphicsItem *> itemList = items();
591 for (int i = 0; i < itemList.count(); i++) {
592 itemList.at(i)->setSelected(false);
593 itemList.at(i)->update();
596 item->setSelected(true);
602 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()));
603 m_dragItemInfo.startPos = m_dragItem->startPos();
604 m_dragItemInfo.endPos = m_dragItem->endPos();
605 m_dragItemInfo.track = m_dragItem->track();
607 m_selectedClipList.clear();
608 QList<QGraphicsItem *> selected = scene()->selectedItems();
609 for (int i = 0; i < selected.count(); i++) {
610 if (selected.at(i)->type() == AVWIDGET || selected.at(i)->type() == TRANSITIONWIDGET)
611 m_selectedClipList.append(static_cast <AbstractClipItem *>(selected.at(i)));
614 m_operationMode = m_dragItem->operationMode(mapToScene(event->pos()));
616 if (m_operationMode == KEYFRAME) {
617 m_dragItem->updateSelectedKeyFrame();
618 m_blockRefresh = false;
620 } else if (m_operationMode == MOVE) {
621 setCursor(Qt::ClosedHandCursor);
622 } else if (m_operationMode == TRANSITIONSTART) {
624 info.startPos = m_dragItem->startPos();
625 info.track = m_dragItem->track();
626 int transitiontrack = getPreviousVideoTrack(info.track);
627 ClipItem *transitionClip = NULL;
628 if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.startPos.frames(m_document->fps()), m_scene->m_tracksList.count() - transitiontrack);
629 if (transitionClip && transitionClip->endPos() < m_dragItem->endPos()) {
630 info.endPos = transitionClip->endPos();
631 } else info.endPos = info.startPos + GenTime(2.5);
633 slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
634 } else if (m_operationMode == TRANSITIONEND) {
636 info.endPos = m_dragItem->endPos();
637 info.track = m_dragItem->track();
638 int transitiontrack = getPreviousVideoTrack(info.track);
639 ClipItem *transitionClip = NULL;
640 if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.endPos.frames(m_document->fps()), m_scene->m_tracksList.count() - transitiontrack);
641 if (transitionClip && transitionClip->startPos() > m_dragItem->startPos()) {
642 info.startPos = transitionClip->startPos();
643 } else info.startPos = info.endPos - GenTime(2.5);
644 slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
647 m_blockRefresh = false;
649 //QGraphicsView::mousePressEvent(event);
652 void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) {
653 if (m_dragItem && m_dragItem->hasKeyFrames()) {
654 if (m_moveOpMode == KEYFRAME) {
655 // user double clicked on a keyframe, open edit dialog
656 QDialog d(parentWidget());
657 Ui::KeyFrameDialog_UI view;
659 view.kfr_position->setText(m_document->timecode().getTimecode(GenTime(m_dragItem->selectedKeyFramePos(), m_document->fps()) - m_dragItem->cropStart(), m_document->fps()));
660 view.kfr_value->setValue(m_dragItem->selectedKeyFrameValue());
661 view.kfr_value->setFocus();
662 if (d.exec() == QDialog::Accepted) {
663 int pos = m_document->timecode().getFrameCount(view.kfr_position->text(), m_document->fps());
664 m_dragItem->updateKeyFramePos(GenTime(pos, m_document->fps()) + m_dragItem->cropStart(), (double) view.kfr_value->value() * m_dragItem->keyFrameFactor());
665 ClipItem *item = (ClipItem *)m_dragItem;
666 QString previous = item->keyframes(item->selectedEffectIndex());
667 item->updateKeyframeEffect();
668 QString next = item->keyframes(item->selectedEffectIndex());
669 EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
670 m_commandStack->push(command);
671 updateEffect(m_scene->m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
676 GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart();
677 m_dragItem->addKeyFrame(keyFramePos, mapToScene(event->pos()).toPoint().y());
678 ClipItem * item = (ClipItem *) m_dragItem;
679 QString previous = item->keyframes(item->selectedEffectIndex());
680 item->updateKeyframeEffect();
681 QString next = item->keyframes(item->selectedEffectIndex());
682 EditKeyFrameCommand *command = new EditKeyFrameCommand(this, m_dragItem->track(), m_dragItem->startPos(), item->selectedEffectIndex(), previous, next, false);
683 m_commandStack->push(command);
684 updateEffect(m_scene->m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
686 } else if (m_dragItem) {
687 ClipDurationDialog d(m_dragItem, m_document->timecode(), this);
688 if (d.exec() == QDialog::Accepted) {
689 if (d.startPos() != m_dragItem->startPos()) {
690 if (m_dragItem->type() == AVWIDGET) {
692 startInfo.startPos = m_dragItem->startPos();
693 startInfo.endPos = m_dragItem->endPos();
694 startInfo.track = m_dragItem->track();
696 endInfo.startPos = d.startPos();
697 endInfo.endPos = m_dragItem->endPos() + (endInfo.startPos - startInfo.startPos);
698 endInfo.track = m_dragItem->track();
699 MoveClipCommand *command = new MoveClipCommand(this, startInfo, endInfo, true);
700 m_commandStack->push(command);
702 //TODO: move transition
705 if (d.duration() != m_dragItem->duration()) {
706 if (m_dragItem->type() == AVWIDGET) {
708 startInfo.startPos = m_dragItem->startPos();
709 startInfo.endPos = m_dragItem->endPos();
710 startInfo.track = m_dragItem->track();
712 endInfo.startPos = startInfo.startPos;
713 endInfo.endPos = endInfo.startPos + d.duration();
714 endInfo.track = m_dragItem->track();
715 ResizeClipCommand *command = new ResizeClipCommand(this, startInfo, endInfo, true);
716 m_commandStack->push(command);
718 //TODO: resize transition
723 QList<QGraphicsItem *> collisionList = items(event->pos());
724 if (collisionList.count() == 1 && collisionList.at(0)->type() == GUIDEITEM) {
725 Guide *editGuide = (Guide *) collisionList.at(0);
726 if (editGuide) slotEditGuide(editGuide->info());
732 void CustomTrackView::editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes) {
733 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), track);
735 clip->setKeyframes(index, keyframes);
736 updateEffect(m_scene->m_tracksList.count() - clip->track(), clip->startPos(), clip->effectAt(index), index);
737 } else emit displayMessage(i18n("Cannot find clip with keyframe"), ErrorMessage);
741 void CustomTrackView::displayContextMenu(QPoint pos, AbstractClipItem *clip) {
742 if (clip == NULL) m_timelineContextMenu->popup(pos);
743 else if (clip->type() == AVWIDGET) m_timelineContextClipMenu->popup(pos);
744 else if (clip->type() == TRANSITIONWIDGET) m_timelineContextTransitionMenu->popup(pos);
747 void CustomTrackView::activateMonitor() {
748 emit activateDocumentMonitor();
751 void CustomTrackView::dragEnterEvent(QDragEnterEvent * event) {
752 if (event->mimeData()->hasFormat("kdenlive/clip")) {
753 QStringList list = QString(event->mimeData()->data("kdenlive/clip")).split(";");
754 kDebug() << "DRAG ENTER EVENT, DATA: " << list;
755 DocClipBase *clip = m_document->getBaseClip(list.at(0));
756 if (clip == NULL) kDebug() << "Ā WARNING))))))))) CLIP NOT FOUND : " << list.at(0);
757 addItem(clip, event->pos(), QPoint(list.at(1).toInt(), list.at(2).toInt()));
758 event->acceptProposedAction();
759 } else if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
760 kDebug() << "/////////////// DRAG ENTERED, TEXT: " << event->mimeData()->data("kdenlive/producerslist");
761 QStringList ids = QString(event->mimeData()->data("kdenlive/producerslist")).split(";");
762 //TODO: drop of several clips
763 for (int i = 0; i < ids.size(); ++i) {
765 DocClipBase *clip = m_document->getBaseClip(ids.at(0));
766 if (clip == NULL) kDebug() << "Ā WARNING))))))))) CLIP NOT FOUND : " << ids.at(0);
767 addItem(clip, event->pos());
768 event->acceptProposedAction();
769 } else QGraphicsView::dragEnterEvent(event);
772 void CustomTrackView::slotRefreshEffects(ClipItem *clip) {
773 int track = m_scene->m_tracksList.count() - clip->track();
774 GenTime pos = clip->startPos();
775 if (!m_document->renderer()->mltRemoveEffect(track, pos, "-1", false)) {
776 emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
780 for (int i = 0; i < clip->effectsCount(); i++) {
781 if (!m_document->renderer()->mltAddEffect(track, pos, clip->getEffectArgs(clip->effectAt(i)), false)) success = false;
783 if (!success) emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
784 m_document->renderer()->doRefresh();
787 void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) {
788 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_scene->m_tracksList.count() - track);
790 QHash <QString, QString> effectParams = clip->addEffect(effect);
791 if (!m_document->renderer()->mltAddEffect(track, pos, effectParams))
792 emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
793 emit clipItemSelected(clip);
794 } else emit displayMessage(i18n("Cannot find clip to add effect"), ErrorMessage);
797 void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) {
798 QString index = effect.attribute("kdenlive_ix");
799 if (effect.attribute("disabled") != "1" && !m_document->renderer()->mltRemoveEffect(track, pos, index)) {
800 emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
803 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_scene->m_tracksList.count() - track);
805 clip->deleteEffect(index);
806 emit clipItemSelected(clip);
810 void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) {
811 QList<QGraphicsItem *> itemList;
812 if (track == -1) itemList = scene()->selectedItems();
813 if (itemList.isEmpty()) {
814 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, track);
815 if (clip) itemList.append(clip);
816 else emit displayMessage(i18n("Select a clip if you want to apply an effect"), ErrorMessage);
818 kDebug() << "// REQUESTING EFFECT ONĀ CLIP: " << pos.frames(25) << ", TRK: " << track << "SELECTED ITEMS: " << itemList.count();
819 for (int i = 0; i < itemList.count(); i++) {
820 if (itemList.at(i)->type() == AVWIDGET) {
821 ClipItem *item = (ClipItem *)itemList.at(i);
822 item->initEffect(effect);
823 AddEffectCommand *command = new AddEffectCommand(this, m_scene->m_tracksList.count() - item->track(), item->startPos(), effect, true);
824 m_commandStack->push(command);
827 m_document->setModified(true);
830 void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect) {
831 AddEffectCommand *command = new AddEffectCommand(this, m_scene->m_tracksList.count() - clip->track(), clip->startPos(), effect, false);
832 m_commandStack->push(command);
833 m_document->setModified(true);
836 void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect, int ix) {
837 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_scene->m_tracksList.count() - track);
839 QHash <QString, QString> effectParams = clip->getEffectArgs(effect);
840 if (effectParams.value("disabled") == "1") {
841 if (m_document->renderer()->mltRemoveEffect(track, pos, effectParams.value("kdenlive_ix"))) {
842 kDebug() << "////// DISABLING EFFECT: " << index << ", CURRENTLA: " << clip->selectedEffectIndex();
843 } else emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
844 } else if (!m_document->renderer()->mltEditEffect(m_scene->m_tracksList.count() - clip->track(), clip->startPos(), effectParams))
845 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
846 if (ix == clip->selectedEffectIndex()) {
847 clip->setSelectedEffect(clip->selectedEffectIndex());
850 m_document->setModified(true);
853 void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos) {
854 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_scene->m_tracksList.count() - track);
856 m_document->renderer()->mltMoveEffect(track, pos, oldPos, newPos);
858 m_document->setModified(true);
861 void CustomTrackView::slotChangeEffectState(ClipItem *clip, int effectPos, bool disable) {
862 QDomElement effect = clip->effectAt(effectPos);
863 QDomElement oldEffect = effect.cloneNode().toElement();
864 effect.setAttribute("disabled", disable);
865 EditEffectCommand *command = new EditEffectCommand(this, m_scene->m_tracksList.count() - clip->track(), clip->startPos(), oldEffect, effect, effectPos, true);
866 m_commandStack->push(command);
867 m_document->setModified(true);
870 void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos) {
871 MoveEffectCommand *command = new MoveEffectCommand(this, m_scene->m_tracksList.count() - clip->track(), clip->startPos(), currentPos, newPos, true);
872 m_commandStack->push(command);
873 m_document->setModified(true);
876 void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect, int ix) {
877 EditEffectCommand *command = new EditEffectCommand(this, m_scene->m_tracksList.count() - clip->track(), clip->startPos(), oldeffect, effect, ix, true);
878 m_commandStack->push(command);
881 void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) {
884 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()) + 1, info.track);
885 if (!item || cutTime >= item->endPos() || cutTime <= item->startPos()) {
886 emit displayMessage(i18n("Cannot find clip to cut"), ErrorMessage);
887 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);
888 m_blockRefresh = false;
891 kDebug() << "///////// CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25);
893 m_document->renderer()->mltCutClip(m_scene->m_tracksList.count() - info.track, cutTime);
894 int cutPos = (int) cutTime.frames(m_document->fps());
896 newPos.startPos = cutTime;
897 newPos.endPos = info.endPos;
898 newPos.cropStart = item->cropStart() + (cutTime - info.startPos);
899 newPos.track = info.track;
900 ClipItem *dup = item->clone(newPos);
901 kDebug() << "// REsizing item to: " << cutPos;
902 item->resizeEnd(cutPos);
903 scene()->addItem(dup);
904 item->baseClip()->addReference();
905 m_document->updateClip(item->baseClip()->getId());
906 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);
907 kDebug() << "// CUTTING CLIP dONE";
911 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
912 ClipItem *dup = getClipItemAt((int) cutTime.frames(m_document->fps()) + 1, info.track);
913 if (!item || !dup || item == dup) {
914 emit displayMessage(i18n("Cannot find clip to uncut"), ErrorMessage);
915 m_blockRefresh = false;
919 kDebug() << "// UNCUTTING CLIPS: ITEM 1 (" << item->startPos().frames(25) << "x" << item->endPos().frames(25) << ")";
920 kDebug() << "// UNCUTTING CLIPS: ITEM 2 (" << dup->startPos().frames(25) << "x" << dup->endPos().frames(25) << ")";
921 kDebug() << "// UNCUTTING CLIPS, INFO (" << info.startPos.frames(25) << "x" << info.endPos.frames(25) << ") , CUT: " << cutTime.frames(25);;
922 //deleteClip(dup->info());
925 if (dup->isSelected()) emit clipItemSelected(NULL);
926 dup->baseClip()->removeReference();
927 m_document->updateClip(dup->baseClip()->getId());
928 scene()->removeItem(dup);
930 m_document->renderer()->mltRemoveClip(m_scene->m_tracksList.count() - info.track, cutTime);
932 ItemInfo clipinfo = item->info();
933 clipinfo.track = m_scene->m_tracksList.count() - clipinfo.track;
934 bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, info.endPos - info.startPos);
936 item->resizeEnd((int) info.endPos.frames(m_document->fps()));
938 emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
941 QTimer::singleShot(3000, this, SLOT(slotEnableRefresh()));
944 void CustomTrackView::slotEnableRefresh() {
945 m_blockRefresh = false;
948 void CustomTrackView::slotAddTransitionToSelectedClips(QDomElement transition) {
949 QList<QGraphicsItem *> itemList = scene()->selectedItems();
950 for (int i = 0; i < itemList.count(); i++) {
951 if (itemList.at(i)->type() == AVWIDGET) {
952 ClipItem *item = (ClipItem *) itemList.at(i);
954 info.startPos = item->startPos();
955 info.endPos = info.startPos + GenTime(2.5);
956 info.track = item->track();
957 int transitiontrack = getPreviousVideoTrack(info.track);
958 slotAddTransition(item, info, transitiontrack, transition);
963 void CustomTrackView::slotAddTransition(ClipItem* clip, ItemInfo transitionInfo, int endTrack, QDomElement transition) {
964 AddTransitionCommand* command = new AddTransitionCommand(this, transitionInfo, endTrack, transition, false, true);
965 m_commandStack->push(command);
966 m_document->setModified(true);
969 void CustomTrackView::addTransition(ItemInfo transitionInfo, int endTrack, QDomElement params) {
970 Transition *tr = new Transition(transitionInfo, endTrack, m_document->fps(), params);
971 scene()->addItem(tr);
973 //kDebug() << "---- ADDING transition " << e.attribute("tag") << ", on tracks " << m_scene->m_tracksList.count() - e.attribute("transition_track").toInt() << " / " << getPreviousVideoTrack(e.attribute("transition_track").toInt());
974 m_document->renderer()->mltAddTransition(tr->transitionTag(), endTrack, m_scene->m_tracksList.count() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, tr->toXML());
975 m_document->setModified(true);
978 void CustomTrackView::deleteTransition(ItemInfo transitionInfo, int endTrack, QDomElement params) {
979 Transition *item = getTransitionItemAt((int)transitionInfo.startPos.frames(m_document->fps()) + 1, transitionInfo.track);
980 m_document->renderer()->mltDeleteTransition(item->transitionTag(), endTrack, m_scene->m_tracksList.count() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, item->toXML());
982 emit transitionItemSelected(NULL);
983 m_document->setModified(true);
986 void CustomTrackView::slotTransitionUpdated(Transition *tr, QDomElement old) {
987 EditTransitionCommand *command = new EditTransitionCommand(this, tr->track(), tr->startPos(), old, tr->toXML() , true);
988 m_commandStack->push(command);
989 m_document->setModified(true);
992 void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTransition, QDomElement transition) {
993 Transition *item = getTransitionItemAt((int)pos.frames(m_document->fps()) + 1, track);
995 kWarning() << "Unable to find transition at pos :" << pos.frames(m_document->fps()) << ", ON track: " << track;
998 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);
999 item->setTransitionParameters(transition);
1000 m_document->setModified(true);
1003 void CustomTrackView::addItem(DocClipBase *clip, QPoint pos) {
1005 info.startPos = GenTime((int)(mapToScene(pos).x()), m_document->fps());
1006 info.endPos = info.startPos + clip->duration();
1007 info.track = (int)(pos.y() / m_tracksHeight);
1008 kDebug() << "------------ ADDING CLIP ITEM----: " << info.startPos.frames(25) << ", " << info.endPos.frames(25) << ", " << info.track;
1009 m_dropItem = new ClipItem(clip, info, m_document->fps());
1010 scene()->addItem(m_dropItem);
1013 void CustomTrackView::addItem(DocClipBase *clip, QPoint pos, QPoint zone) {
1015 info.startPos = GenTime((int)(mapToScene(pos).x()), m_document->fps());
1016 info.cropStart = GenTime(zone.x(), m_document->fps());
1017 info.endPos = info.startPos + GenTime(zone.y() - zone.x(), m_document->fps());
1018 info.track = (int)(pos.y() / m_tracksHeight);
1019 kDebug() << "------------ ADDING CLIP ZONE ITEM----: " << zone;
1020 m_dropItem = new ClipItem(clip, info, m_document->fps());
1021 scene()->addItem(m_dropItem);
1025 void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) {
1026 event->setDropAction(Qt::IgnoreAction);
1028 int track = (int)(mapToScene(event->pos()).y() / m_tracksHeight);
1029 int pos = mapToScene(event->pos()).x();
1030 m_dropItem->setPos(pos, track * m_tracksHeight + 1);
1031 event->setDropAction(Qt::MoveAction);
1032 if (event->mimeData()->hasFormat("kdenlive/producerslist") || event->mimeData()->hasFormat("kdenlive/clip")) {
1033 event->acceptProposedAction();
1036 QGraphicsView::dragMoveEvent(event);
1040 void CustomTrackView::dragLeaveEvent(QDragLeaveEvent * event) {
1044 } else QGraphicsView::dragLeaveEvent(event);
1047 void CustomTrackView::dropEvent(QDropEvent * event) {
1049 AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->clipProducer(), m_dropItem->info(), m_dropItem->effectList(), false, false);
1050 m_commandStack->push(command);
1051 //((ClipItem *) m_dropItem)->refreshClip();
1052 m_dropItem->baseClip()->addReference();
1053 m_document->updateClip(m_dropItem->baseClip()->getId());
1055 info = m_dropItem->info();
1056 info.track = m_scene->m_tracksList.count() - m_dropItem->track();
1057 //kDebug()<<"IIIIIIIIIIIIIIIIIIIIIIII TRAX CNT: "<<m_scene->m_tracksList.count()<<", DROP: "<<m_dropItem->track();
1058 m_document->renderer()->mltInsertClip(info, m_dropItem->xml(), m_dropItem->baseClip()->producer());
1059 //if (m_dropItem->baseClip()->isTransparent()) m_document->renderer()->mltAddClipTransparency(info, getPreviousVideoTrack(m_dropItem->track()), m_dropItem->baseClip()->getId());
1061 m_document->setModified(true);
1062 } else QGraphicsView::dropEvent(event);
1067 QStringList CustomTrackView::mimeTypes() const {
1068 QStringList qstrList;
1069 // list of accepted mime types for drop
1070 qstrList.append("text/plain");
1071 qstrList.append("kdenlive/producerslist");
1072 qstrList.append("kdenlive/clip");
1076 Qt::DropActions CustomTrackView::supportedDropActions() const {
1077 // returns what actions are supported when dropping
1078 return Qt::MoveAction;
1081 void CustomTrackView::setDuration(int duration) {
1082 if (duration > sceneRect().width())
1083 setSceneRect(0, 0, (duration + 100), sceneRect().height());
1084 m_projectDuration = duration;
1087 int CustomTrackView::duration() const {
1088 return m_projectDuration;
1091 void CustomTrackView::addTrack(TrackInfo type) {
1092 m_scene->m_tracksList << type;
1093 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_scene->m_tracksList.count());
1094 setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_scene->m_tracksList.count());
1095 verticalScrollBar()->setMaximum(m_tracksHeight * m_scene->m_tracksList.count());
1096 //setFixedHeight(50 * m_tracksCount);
1099 void CustomTrackView::removeTrack() {
1100 // TODO: implement track deletion
1102 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_scene->m_tracksList.count());
1106 void CustomTrackView::slotSwitchTrackAudio(int ix) {
1107 int tracknumber = m_scene->m_tracksList.count() - ix;
1108 kDebug() << "///// MUTING TRK: " << ix << ";Ā PL NUM: " << tracknumber;
1109 m_scene->m_tracksList[tracknumber - 1].isMute = !m_scene->m_tracksList.at(tracknumber - 1).isMute;
1110 m_document->renderer()->mltChangeTrackState(tracknumber, m_scene->m_tracksList.at(tracknumber - 1).isMute, m_scene->m_tracksList.at(tracknumber - 1).isBlind);
1113 void CustomTrackView::slotSwitchTrackVideo(int ix) {
1114 int tracknumber = m_scene->m_tracksList.count() - ix;
1115 m_scene->m_tracksList[tracknumber - 1].isBlind = !m_scene->m_tracksList.at(tracknumber - 1).isBlind;
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::deleteClip(const QString &clipId) {
1120 QList<QGraphicsItem *> itemList = items();
1121 for (int i = 0; i < itemList.count(); i++) {
1122 if (itemList.at(i)->type() == AVWIDGET) {
1123 ClipItem *item = (ClipItem *)itemList.at(i);
1124 if (item->clipProducer() == clipId) {
1125 AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), true, true);
1126 m_commandStack->push(command);
1133 void CustomTrackView::setCursorPos(int pos, bool seek) {
1134 emit cursorMoved((int)(m_cursorPos), (int)(pos));
1136 m_cursorLine->setPos(pos, 0);
1137 if (seek) m_document->renderer()->seek(GenTime(pos, m_document->fps()));
1138 else if (m_autoScroll) checkScrolling();
1141 void CustomTrackView::updateCursorPos() {
1142 m_cursorLine->setPos(m_cursorPos, 0);
1145 int CustomTrackView::cursorPos() {
1146 return (int)(m_cursorPos);
1149 void CustomTrackView::moveCursorPos(int delta) {
1150 if (m_cursorPos + delta < 0) delta = 0 - m_cursorPos;
1151 emit cursorMoved((int)(m_cursorPos), (int)((m_cursorPos + delta)));
1152 m_cursorPos += delta;
1153 m_cursorLine->setPos(m_cursorPos, 0);
1154 m_document->renderer()->seek(GenTime(m_cursorPos, m_document->fps()));
1155 //if (m_autoScroll && m_scale < 50) checkScrolling();
1158 void CustomTrackView::checkScrolling() {
1159 int vert = verticalScrollBar()->value();
1160 int hor = cursorPos();
1161 ensureVisible(hor, vert + 10, 2, 2, 50, 0);
1162 //centerOn(QPointF(cursorPos(), m_tracksHeight));
1163 /*QRect rectInView = viewport()->rect();
1164 int delta = rectInView.width() / 3;
1165 int max = rectInView.right() + horizontalScrollBar()->value() - delta;
1166 //kDebug() << "CURSOR POS: "<<m_cursorPos<< "Scale: "<<m_scale;
1167 if (m_cursorPos * m_scale >= max) horizontalScrollBar()->setValue((int)(horizontalScrollBar()->value() + 1 + m_scale));*/
1170 void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
1171 QGraphicsView::mouseReleaseEvent(event);
1172 if (event->button() == Qt::MidButton) {
1175 setDragMode(QGraphicsView::NoDrag);
1176 if (m_operationMode == MOVEGUIDE) {
1177 setCursor(Qt::ArrowCursor);
1178 m_operationMode = NONE;
1179 m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, false);
1180 EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), GenTime(m_dragGuide->pos().x(), m_document->fps()), m_dragGuide->label(), false);
1181 m_commandStack->push(command);
1182 m_dragGuide->updateGuide(GenTime(m_dragGuide->pos().x(), m_document->fps()));
1187 if (m_dragItem == NULL) {
1188 emit transitionItemSelected(NULL);
1191 ItemInfo info = m_dragItem->info();
1193 if (m_operationMode == MOVE) {
1194 setCursor(Qt::OpenHandCursor);
1196 if (m_selectionGroup == NULL) {
1197 // we are moving one clip, easy
1198 if (m_dragItem->type() == AVWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
1199 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())));
1201 MoveClipCommand *command = new MoveClipCommand(this, m_dragItemInfo, info, false);
1202 m_commandStack->push(command);
1204 // undo last move and emit error message
1205 MoveClipCommand *command = new MoveClipCommand(this, info, m_dragItemInfo, true);
1206 m_commandStack->push(command);
1207 emit displayMessage(i18n("Cannot move clip to position %1seconds", QString::number(m_dragItemInfo.startPos.seconds(), 'g', 2)), ErrorMessage);
1210 if (m_dragItem->type() == TRANSITIONWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
1211 MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false);
1212 m_commandStack->push(command);
1213 Transition *transition = (Transition *) m_dragItem;
1214 transition->updateTransitionEndTrack(getPreviousVideoTrack(m_dragItem->track()));
1215 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);
1218 // Moving several clips. We need to delete them and readd them to new position,
1219 // or they might overlap each other during the move
1221 GenTime timeOffset = info.startPos - m_dragItemInfo.startPos;
1222 int trackOffset = info.track - m_dragItemInfo.track;
1223 if (timeOffset != GenTime() || trackOffset != 0) {
1224 QUndoCommand *moveClips = new QUndoCommand();
1225 moveClips->setText("Move clips");
1226 // remove items in MLT playlist
1227 for (int i = 0; i < m_selectedClipList.count(); i++) {
1228 AbstractClipItem *item = m_selectedClipList.at(i);
1229 ItemInfo info = item->info();
1230 info.startPos = info.startPos - timeOffset;
1231 info.endPos = info.endPos - timeOffset;
1232 info.track = info.track - trackOffset;
1233 if (item->type() == AVWIDGET) {
1234 ClipItem *clip = static_cast <ClipItem*>(item);
1235 new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), info, clip->effectList(), false, true, moveClips);
1236 m_document->renderer()->mltRemoveClip(m_scene->m_tracksList.count() - info.track, info.startPos);
1238 Transition *tr = static_cast <Transition*>(item);
1239 new AddTransitionCommand(this, info, tr->transitionEndTrack(), tr->toXML(), false, true, moveClips);
1240 m_document->renderer()->mltDeleteTransition(tr->transitionTag(), tr->transitionEndTrack(), m_scene->m_tracksList.count() - info.track, info.startPos, info.endPos, tr->toXML());
1244 for (int i = 0; i < m_selectedClipList.count(); i++) {
1245 // re-add items in correct place
1246 AbstractClipItem *item = m_selectedClipList.at(i);
1247 if (item->type() == AVWIDGET) {
1248 ClipItem *clip = static_cast <ClipItem*>(item);
1249 new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), item->info(), clip->effectList(), false, false, moveClips);
1250 ItemInfo info = item->info();
1251 info.track = m_scene->m_tracksList.count() - item->track();
1252 m_document->renderer()->mltInsertClip(info, clip->xml(), clip->baseClip()->producer());
1254 Transition *tr = static_cast <Transition*>(item);
1255 ItemInfo transitionInfo = tr->info();
1256 new AddTransitionCommand(this, info, tr->transitionEndTrack(), tr->toXML(), false, false, moveClips);
1257 m_document->renderer()->mltAddTransition(tr->transitionTag(), tr->transitionEndTrack() + trackOffset, m_scene->m_tracksList.count() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, tr->toXML());
1260 m_commandStack->push(moveClips);
1264 } else if (m_operationMode == RESIZESTART && m_dragItem->startPos() != m_dragItemInfo.startPos) {
1266 if (m_dragItem->type() == AVWIDGET) {
1267 ItemInfo resizeinfo = m_dragItemInfo;
1268 resizeinfo.track = m_scene->m_tracksList.count() - resizeinfo.track;
1269 bool success = m_document->renderer()->mltResizeClipStart(resizeinfo, m_dragItem->startPos() - m_dragItemInfo.startPos);
1271 updateClipFade((ClipItem *) m_dragItem);
1272 ResizeClipCommand *command = new ResizeClipCommand(this, m_dragItemInfo, info, false);
1273 m_commandStack->push(command);
1275 m_dragItem->resizeStart((int) m_dragItemInfo.startPos.frames(m_document->fps()));
1276 emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
1278 } else if (m_dragItem->type() == TRANSITIONWIDGET) {
1279 MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false);
1280 m_commandStack->push(command);
1281 Transition *transition = static_cast <Transition *>(m_dragItem);
1282 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);
1285 //m_document->renderer()->doRefresh();
1286 } else if (m_operationMode == RESIZEEND && m_dragItem->endPos() != m_dragItemInfo.endPos) {
1288 if (m_dragItem->type() == AVWIDGET) {
1289 ItemInfo resizeinfo = info;
1290 resizeinfo.track = m_scene->m_tracksList.count() - resizeinfo.track;
1291 bool success = m_document->renderer()->mltResizeClipEnd(resizeinfo, resizeinfo.endPos - resizeinfo.startPos);
1293 ResizeClipCommand *command = new ResizeClipCommand(this, m_dragItemInfo, info, false);
1294 m_commandStack->push(command);
1296 m_dragItem->resizeEnd((int) m_dragItemInfo.endPos.frames(m_document->fps()));
1297 emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
1299 } else if (m_dragItem->type() == TRANSITIONWIDGET) {
1300 MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false);
1301 m_commandStack->push(command);
1302 Transition *transition = static_cast <Transition *>(m_dragItem);
1303 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);
1305 //m_document->renderer()->doRefresh();
1306 } else if (m_operationMode == FADEIN) {
1307 //Ā resize fade in effect
1308 ClipItem * item = (ClipItem *) m_dragItem;
1309 QStringList clipeffects = item->effectNames();
1310 if (clipeffects.contains(i18n("Fade in"))) {
1311 int ix = clipeffects.indexOf(i18n("Fade in"));
1312 QDomElement oldeffect = item->effectAt(ix);
1313 int start = item->cropStart().frames(m_document->fps());
1314 int end = item->fadeIn();
1316 slotDeleteEffect(item, oldeffect);
1319 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade in");
1320 EffectsList::setParameter(effect, "in", QString::number(start));
1321 EffectsList::setParameter(effect, "out", QString::number(end));
1322 slotUpdateClipEffect(item, oldeffect, effect, ix);
1324 } else if (item->fadeIn() != 0) {
1325 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade in");
1326 int start = item->cropStart().frames(m_document->fps());
1327 int end = item->fadeIn() + start;
1328 EffectsList::setParameter(effect, "in", QString::number(start));
1329 EffectsList::setParameter(effect, "out", QString::number(end));
1330 slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
1332 } else if (m_operationMode == FADEOUT) {
1333 //Ā resize fade in effect
1334 ClipItem * item = (ClipItem *) m_dragItem;
1335 QStringList clipeffects = item->effectNames();
1336 if (clipeffects.contains(i18n("Fade out"))) {
1337 int ix = clipeffects.indexOf(i18n("Fade out"));
1338 QDomElement oldeffect = item->effectAt(ix);
1339 int end = (item->duration() + item->cropStart()).frames(m_document->fps());
1340 int start = item->fadeOut();
1342 slotDeleteEffect(item, oldeffect);
1344 start = end - start;
1345 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade out");
1346 EffectsList::setParameter(effect, "in", QString::number(start));
1347 EffectsList::setParameter(effect, "out", QString::number(end));
1348 slotUpdateClipEffect(item, oldeffect, effect, ix);
1350 } else if (item->fadeOut() != 0) {
1351 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade out");
1352 int end = (item->duration() + item->cropStart()).frames(m_document->fps());
1353 int start = end - item->fadeOut();
1354 EffectsList::setParameter(effect, "in", QString::number(start));
1355 EffectsList::setParameter(effect, "out", QString::number(end));
1356 slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
1358 } else if (m_operationMode == KEYFRAME) {
1359 // update the MLT effect
1360 ClipItem * item = (ClipItem *) m_dragItem;
1361 QString previous = item->keyframes(item->selectedEffectIndex());
1362 item->updateKeyframeEffect();
1363 QString next = item->keyframes(item->selectedEffectIndex());
1364 EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
1365 m_commandStack->push(command);
1366 updateEffect(m_scene->m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
1369 emit transitionItemSelected((m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) ? static_cast <Transition *>(m_dragItem) : NULL);
1370 m_document->setModified(true);
1371 m_operationMode = NONE;
1374 void CustomTrackView::deleteClip(ItemInfo info) {
1375 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()) + 1, info.track);
1377 kDebug() << "----------------Ā ERROR, CANNOT find clip to delete at...";// << rect.x();
1380 if (item->isSelected()) emit clipItemSelected(NULL);
1381 item->baseClip()->removeReference();
1382 m_document->updateClip(item->baseClip()->getId());
1383 scene()->removeItem(item);
1385 m_document->renderer()->mltRemoveClip(m_scene->m_tracksList.count() - info.track, info.startPos);
1386 m_document->renderer()->doRefresh();
1389 void CustomTrackView::deleteSelectedClips() {
1390 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1391 if (itemList.count() == 0) {
1392 emit displayMessage(i18n("Select clip to delete"), ErrorMessage);
1395 QUndoCommand *deleteSelected = new QUndoCommand();
1396 deleteSelected->setText("Delete selected items");
1397 for (int i = 0; i < itemList.count(); i++) {
1398 if (itemList.at(i)->type() == AVWIDGET) {
1399 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1400 new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), true, true, deleteSelected);
1401 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
1402 Transition *item = static_cast <Transition *>(itemList.at(i));
1404 info.startPos = item->startPos();
1405 info.endPos = item->endPos();
1406 info.track = item->track();
1407 new AddTransitionCommand(this, info, item->transitionEndTrack(), item->toXML(), true, true, deleteSelected);
1410 m_commandStack->push(deleteSelected);
1413 void CustomTrackView::changeClipSpeed() {
1414 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1415 if (itemList.count() == 0) {
1416 emit displayMessage(i18n("Select clip to change speed"), ErrorMessage);
1419 QUndoCommand *changeSelected = new QUndoCommand();
1420 changeSelected->setText("Edit clip speed");
1421 for (int i = 0; i < itemList.count(); i++) {
1422 if (itemList.at(i)->type() == AVWIDGET) {
1423 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1424 ItemInfo info = item->info();
1425 int percent = QInputDialog::getInteger(this, i18n("Edit Clip Speed"), i18n("New speed (percents)"), 100, 1, 300);
1426 double speed = (double) percent / 100.0;
1427 if (item->speed() != speed)
1428 new ChangeSpeedCommand(this, info, item->speed(), speed, item->clipProducer(), true, changeSelected);
1431 m_commandStack->push(changeSelected);
1434 void CustomTrackView::doChangeClipSpeed(ItemInfo info, double speed, const QString &id) {
1435 DocClipBase *baseclip = m_document->clipManager()->getClipById(id);
1436 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()) + 1, info.track);
1437 info.track = m_scene->m_tracksList.count() - item->track();
1438 m_document->renderer()->mltChangeClipSpeed(info, speed, baseclip->producer());
1439 item->setSpeed(speed);
1440 GenTime maxDuration = item->maxDuration();
1441 if (maxDuration < item->duration()) {
1442 info = item->info();
1443 ItemInfo endInfo = info;
1444 endInfo.endPos = info.startPos + maxDuration;
1445 ResizeClipCommand *command = new ResizeClipCommand(this, info, endInfo, true);
1446 m_commandStack->push(command);
1450 void CustomTrackView::cutSelectedClips() {
1451 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1452 GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
1453 for (int i = 0; i < itemList.count(); i++) {
1454 if (itemList.at(i)->type() == AVWIDGET) {
1455 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1456 if (currentPos > item->startPos() && currentPos < item->endPos()) {
1457 RazorClipCommand *command = new RazorClipCommand(this, item->info(), currentPos, true);
1458 m_commandStack->push(command);
1464 void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo info, EffectsList effects) {
1465 DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId);
1466 ClipItem *item = new ClipItem(baseclip, info, m_document->fps());
1467 item->setEffectList(effects);
1468 scene()->addItem(item);
1469 baseclip->addReference();
1470 m_document->updateClip(baseclip->getId());
1471 info.track = m_scene->m_tracksList.count() - info.track;
1472 m_document->renderer()->mltInsertClip(info, xml, baseclip->producer());
1473 for (int i = 0; i < item->effectsCount(); i++) {
1474 m_document->renderer()->mltAddEffect(info.track, info.startPos, item->getEffectArgs(item->effectAt(i)), false);
1476 m_document->renderer()->doRefresh();
1479 void CustomTrackView::slotUpdateClip(const QString &clipId) {
1480 QList<QGraphicsItem *> list = scene()->items();
1481 ClipItem *clip = NULL;
1482 for (int i = 0; i < list.size(); ++i) {
1483 if (list.at(i)->type() == AVWIDGET) {
1484 clip = static_cast <ClipItem *>(list.at(i));
1485 if (clip->clipProducer() == clipId) {
1486 clip->refreshClip();
1487 ItemInfo info = clip->info();
1488 info.track = m_scene->m_tracksList.count() - clip->track();
1489 m_document->renderer()->mltUpdateClip(info, clip->xml(), clip->baseClip()->producer());
1495 ClipItem *CustomTrackView::getClipItemAt(int pos, int track) {
1496 QList<QGraphicsItem *> list = scene()->items(QPointF(pos , track * m_tracksHeight + m_tracksHeight / 2));
1497 ClipItem *clip = NULL;
1498 for (int i = 0; i < list.size(); ++i) {
1499 if (list.at(i)->type() == AVWIDGET) {
1500 clip = static_cast <ClipItem *>(list.at(i));
1507 ClipItem *CustomTrackView::getClipItemAt(GenTime pos, int track) {
1508 int framepos = (int)(pos.frames(m_document->fps()));
1509 return getClipItemAt(framepos, track);
1512 Transition *CustomTrackView::getTransitionItemAt(int pos, int track) {
1513 QList<QGraphicsItem *> list = scene()->items(QPointF(pos, (track + 1) * m_tracksHeight));
1514 Transition *clip = NULL;
1515 for (int i = 0; i < list.size(); ++i) {
1516 if (list.at(i)->type() == TRANSITIONWIDGET) {
1517 clip = static_cast <Transition *>(list.at(i));
1524 Transition *CustomTrackView::getTransitionItemAt(GenTime pos, int track) {
1525 int framepos = (int)(pos.frames(m_document->fps()));
1526 return getTransitionItemAt(framepos, track);
1529 void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end) {
1530 ClipItem *item = getClipItemAt((int) start.startPos.frames(m_document->fps()) + 1, start.track);
1532 emit displayMessage(i18n("Cannot move clip at time: %1s on track %2", QString::number(start.startPos.seconds(), 'g', 2), start.track), ErrorMessage);
1533 kDebug() << "----------------Ā ERROR, CANNOT find clip to move at.. ";// << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2;
1536 //kDebug() << "----------------Ā Move CLIP FROM: " << startPos.x() << ", END:" << endPos.x() << ",TRACKS: " << startPos.y() << " TO " << endPos.y();
1538 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()));
1540 item->setPos((int) end.startPos.frames(m_document->fps()), (int)(end.track * m_tracksHeight + 1));
1542 // undo last move and emit error message
1543 emit displayMessage(i18n("Cannot move clip to position %1seconds", QString::number(end.startPos.seconds(), 'g', 2)), ErrorMessage);
1547 void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end) {
1548 Transition *item = getTransitionItemAt((int)start.startPos.frames(m_document->fps()) + 1, start.track);
1550 emit displayMessage(i18n("Cannot move transition at time: %1s on track %2", start.startPos.seconds(), start.track), ErrorMessage);
1551 kDebug() << "----------------Ā ERROR, CANNOT find transition to move... ";// << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2;
1554 //kDebug() << "----------------Ā Move TRANSITION FROM: " << startPos.x() << ", END:" << endPos.x() << ",TRACKS: " << oldtrack << " TO " << newtrack;
1556 //kDebug()<<"/// RESIZEĀ TRANS START: ("<< startPos.x()<<"x"<< startPos.y()<<") / ("<<endPos.x()<<"x"<< endPos.y()<<")";
1557 if (end.endPos - end.startPos == start.endPos - start.startPos) {
1558 // Transition was moved
1559 item->setPos((int) end.startPos.frames(m_document->fps()), (end.track) * m_tracksHeight + 1);
1560 } else if (end.endPos == start.endPos) {
1561 // Transition start resize
1562 item->resizeStart((int) end.startPos.frames(m_document->fps()));
1564 // Transition end resize;
1565 item->resizeEnd((int) end.endPos.frames(m_document->fps()));
1567 //item->moveTransition(GenTime((int) (endPos.x() - startPos.x()), m_document->fps()));
1568 item->updateTransitionEndTrack(getPreviousVideoTrack(end.track));
1569 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);
1572 void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end) {
1574 bool resizeClipStart = true;
1575 if (start.startPos == end.startPos) resizeClipStart = false;
1576 /*if (resizeClipStart) offset = 1;
1578 ClipItem *item = getClipItemAt((int)(start.startPos.frames(m_document->fps()) + offset), start.track);
1580 emit displayMessage(i18n("Cannot move clip at time: %1s on track %2", start.startPos.seconds(), start.track), ErrorMessage);
1581 kDebug() << "----------------Ā ERROR, CANNOT find clip to resize at... "; // << startPos;
1584 if (resizeClipStart) {
1585 ItemInfo clipinfo = item->info();
1586 clipinfo.track = m_scene->m_tracksList.count() - clipinfo.track;
1587 bool success = m_document->renderer()->mltResizeClipStart(clipinfo, end.startPos - item->startPos());
1589 item->resizeStart((int) end.startPos.frames(m_document->fps()));
1590 updateClipFade(item);
1591 } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
1593 ItemInfo clipinfo = item->info();
1594 clipinfo.track = m_scene->m_tracksList.count() - clipinfo.track;
1595 bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, end.endPos - clipinfo.startPos);
1597 item->resizeEnd((int) end.endPos.frames(m_document->fps()));
1598 updateClipFade(item, true);
1599 } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
1601 m_document->renderer()->doRefresh();
1604 void CustomTrackView::updateClipFade(ClipItem * item, bool updateFadeOut) {
1605 if (!updateFadeOut) {
1606 int end = item->fadeIn();
1608 // there is a fade in effect
1609 QStringList clipeffects = item->effectNames();
1610 QDomElement oldeffect = item->effectAt(clipeffects.indexOf("Fade in"));
1611 int start = item->cropStart().frames(m_document->fps());
1613 EffectsList::setParameter(oldeffect, "in", QString::number(start));
1614 EffectsList::setParameter(oldeffect, "out", QString::number(end));
1615 QHash <QString, QString> effectParams = item->getEffectArgs(oldeffect);
1616 if (!m_document->renderer()->mltEditEffect(m_scene->m_tracksList.count() - item->track(), item->startPos(), effectParams))
1617 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
1620 int start = item->fadeOut();
1622 // there is a fade in effect
1623 QStringList clipeffects = item->effectNames();
1624 QDomElement oldeffect = item->effectAt(clipeffects.indexOf("Fade out"));
1625 int end = (item->duration() - item->cropStart()).frames(m_document->fps());
1626 start = end - start;
1627 EffectsList::setParameter(oldeffect, "in", QString::number(start));
1628 EffectsList::setParameter(oldeffect, "out", QString::number(end));
1629 QHash <QString, QString> effectParams = item->getEffectArgs(oldeffect);
1630 if (m_document->renderer()->mltEditEffect(m_scene->m_tracksList.count() - item->track(), item->startPos(), effectParams))
1631 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
1636 double CustomTrackView::getSnapPointForPos(double pos) {
1637 return m_scene->getSnapPointForPos(pos);
1640 void CustomTrackView::updateSnapPoints(AbstractClipItem *selected) {
1641 QList <GenTime> snaps;
1643 if (selected) offset = selected->duration();
1644 QList<QGraphicsItem *> itemList = items();
1645 for (int i = 0; i < itemList.count(); i++) {
1646 if (itemList.at(i)->type() == AVWIDGET && itemList.at(i) != selected) {
1647 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1648 GenTime start = item->startPos();
1649 GenTime end = item->endPos();
1650 snaps.append(start);
1652 QList < GenTime > markers = item->snapMarkers();
1653 for (int i = 0; i < markers.size(); ++i) {
1654 GenTime t = markers.at(i);
1656 if (t > offset) snaps.append(t - offset);
1658 if (offset != GenTime()) {
1659 if (start > offset) snaps.append(start - offset);
1660 if (end > offset) snaps.append(end - offset);
1662 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
1663 Transition *transition = static_cast <Transition*>(itemList.at(i));
1664 GenTime start = transition->startPos();
1665 GenTime end = transition->endPos();
1666 snaps.append(start);
1668 if (offset != GenTime()) {
1669 if (start > offset) snaps.append(start - offset);
1670 if (end > offset) snaps.append(end - offset);
1675 // add cursor position
1676 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1678 if (offset != GenTime()) snaps.append(pos - offset);
1681 for (int i = 0; i < m_guides.count(); i++) {
1682 snaps.append(m_guides.at(i)->position());
1683 if (offset != GenTime()) snaps.append(m_guides.at(i)->position() - offset);
1687 m_scene->setSnapList(snaps);
1688 //for (int i = 0; i < m_snapPoints.size(); ++i)
1689 // kDebug() << "SNAP POINT: " << m_snapPoints.at(i).frames(25);
1692 void CustomTrackView::slotSeekToPreviousSnap() {
1693 updateSnapPoints(NULL);
1694 GenTime res = m_scene->previousSnapPoint(GenTime(m_cursorPos, m_document->fps()));
1695 setCursorPos((int) res.frames(m_document->fps()));
1699 void CustomTrackView::slotSeekToNextSnap() {
1700 updateSnapPoints(NULL);
1701 GenTime res = m_scene->nextSnapPoint(GenTime(m_cursorPos, m_document->fps()));
1702 setCursorPos((int) res.frames(m_document->fps()));
1706 void CustomTrackView::clipStart() {
1707 ClipItem *item = getMainActiveClip();
1709 setCursorPos((int) item->startPos().frames(m_document->fps()));
1714 void CustomTrackView::clipEnd() {
1715 ClipItem *item = getMainActiveClip();
1717 setCursorPos((int) item->endPos().frames(m_document->fps()));
1722 void CustomTrackView::slotAddClipMarker() {
1723 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1724 if (itemList.count() != 1) {
1725 emit displayMessage(i18n("Cannot add marker if more than one clip is selected"), ErrorMessage);
1726 kDebug() << "// CANNOT ADD MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1729 AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1730 if (item->type() != AVWIDGET) return;
1731 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1732 if (item->startPos() > pos || item->endPos() < pos) return;
1733 ClipItem *clip = (ClipItem *) item;
1734 QString id = clip->baseClip()->getId();
1735 GenTime position = pos - item->startPos() + item->cropStart();
1736 CommentedTime marker(position, i18n("Marker"));
1737 MarkerDialog d(clip->baseClip(), marker, m_document->timecode(), this);
1738 if (d.exec() == QDialog::Accepted) {
1739 slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1743 void CustomTrackView::slotAddClipMarker(const QString &id, GenTime t, QString c) {
1744 QString oldcomment = m_document->clipManager()->getClipById(id)->markerComment(t);
1745 AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, c, id, t, true);
1746 m_commandStack->push(command);
1749 void CustomTrackView::slotDeleteClipMarker() {
1750 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1751 if (itemList.count() != 1) {
1752 emit displayMessage(i18n("Cannot delete marker if more than one clip is selected"), ErrorMessage);
1753 kDebug() << "// CANNOT DELETE MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1756 AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1757 if (item->type() != AVWIDGET) {
1758 emit displayMessage(i18n("No clip selected"), ErrorMessage);
1761 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1762 if (item->startPos() > pos || item->endPos() < pos) {
1763 emit displayMessage(i18n("No selected clip at cursor time"), ErrorMessage);
1766 ClipItem *clip = (ClipItem *) item;
1767 QString id = clip->baseClip()->getId();
1768 GenTime position = pos - item->startPos() + item->cropStart();
1769 QString comment = clip->baseClip()->markerComment(position);
1770 if (comment.isEmpty()) {
1771 emit displayMessage(i18n("No marker found at cursor time"), ErrorMessage);
1774 AddMarkerCommand *command = new AddMarkerCommand(this, comment, QString(), id, position, true);
1775 m_commandStack->push(command);
1778 void CustomTrackView::slotDeleteAllClipMarkers() {
1779 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1780 if (itemList.count() != 1) {
1781 emit displayMessage(i18n("Cannot delete marker if more than one clip is selected"), ErrorMessage);
1782 kDebug() << "// CANNOT DELETE MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1785 AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1786 if (item->type() != AVWIDGET) {
1787 emit displayMessage(i18n("No clip selected"), ErrorMessage);
1791 ClipItem *clip = static_cast <ClipItem *>(item);
1792 QList <CommentedTime> markers = clip->baseClip()->commentedSnapMarkers();
1794 if (markers.isEmpty()) {
1795 emit displayMessage(i18n("Clip has no markers"), ErrorMessage);
1798 QString id = clip->baseClip()->getId();
1799 QUndoCommand *deleteMarkers = new QUndoCommand();
1800 deleteMarkers->setText("Delete clip markers");
1802 for (int i = 0; i < markers.size(); i++) {
1803 new AddMarkerCommand(this, markers.at(i).comment(), QString(), id, markers.at(i).time(), true, deleteMarkers);
1805 m_commandStack->push(deleteMarkers);
1808 void CustomTrackView::slotEditClipMarker() {
1809 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1810 if (itemList.count() != 1) {
1811 emit displayMessage(i18n("Cannot edit marker if more than one clip is selected"), ErrorMessage);
1812 kDebug() << "// CANNOT DELETE MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1815 AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1816 if (item->type() != AVWIDGET) {
1817 emit displayMessage(i18n("No clip at cursor time"), ErrorMessage);
1820 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1821 if (item->startPos() > pos || item->endPos() < pos) {
1822 emit displayMessage(i18n("No selected clip at cursor time"), ErrorMessage);
1825 ClipItem *clip = (ClipItem *) item;
1826 QString id = clip->baseClip()->getId();
1827 GenTime position = pos - item->startPos() + item->cropStart();
1828 QString oldcomment = clip->baseClip()->markerComment(position);
1829 if (oldcomment.isEmpty()) {
1830 emit displayMessage(i18n("No marker found at cursor time"), ErrorMessage);
1834 CommentedTime marker(position, oldcomment);
1835 MarkerDialog d(clip->baseClip(), marker, m_document->timecode(), this);
1836 if (d.exec() == QDialog::Accepted) {
1837 if (d.newMarker().time() == position) {
1838 // marker position was not changed, only text
1839 AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, d.newMarker().comment(), id, position, true);
1840 m_commandStack->push(command);
1842 // marker text and position were changed, remove previous marker and add new one
1843 AddMarkerCommand *command1 = new AddMarkerCommand(this, oldcomment, QString(), id, position, true);
1844 AddMarkerCommand *command2 = new AddMarkerCommand(this, QString(), d.newMarker().comment(), id, d.newMarker().time(), true);
1845 m_commandStack->push(command1);
1846 m_commandStack->push(command2);
1851 void CustomTrackView::addMarker(const QString &id, const GenTime &pos, const QString comment) {
1852 DocClipBase *base = m_document->clipManager()->getClipById(id);
1853 if (!comment.isEmpty()) base->addSnapMarker(pos, comment);
1854 else base->deleteSnapMarker(pos);
1855 m_document->setModified(true);
1856 viewport()->update();
1859 bool sortGuidesList(const Guide *g1 , const Guide *g2) {
1860 return (*g1).position() < (*g2).position();
1863 void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const QString &comment) {
1864 if (oldPos > GenTime() && pos > GenTime()) {
1866 for (int i = 0; i < m_guides.count(); i++) {
1867 if (m_guides.at(i)->position() == oldPos) {
1868 Guide *item = m_guides.at(i);
1869 item->updateGuide(pos, comment);
1873 } else if (pos > GenTime()) addGuide(pos, comment);
1877 for (int i = 0; i < m_guides.count(); i++) {
1878 if (m_guides.at(i)->position() == oldPos) {
1879 Guide *item = m_guides.takeAt(i);
1885 if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
1887 qSort(m_guides.begin(), m_guides.end(), sortGuidesList);
1888 m_document->syncGuides(m_guides);
1891 bool CustomTrackView::addGuide(const GenTime pos, const QString &comment) {
1892 for (int i = 0; i < m_guides.count(); i++) {
1893 if (m_guides.at(i)->position() == pos) {
1894 emit displayMessage(i18n("A guide already exists at that position"), ErrorMessage);
1898 Guide *g = new Guide(this, pos, comment, m_document->fps(), m_tracksHeight * m_scene->m_tracksList.count());
1899 scene()->addItem(g);
1901 qSort(m_guides.begin(), m_guides.end(), sortGuidesList);
1902 m_document->syncGuides(m_guides);
1906 void CustomTrackView::slotAddGuide() {
1907 CommentedTime marker(GenTime(m_cursorPos, m_document->fps()), i18n("Guide"));
1908 MarkerDialog d(NULL, marker, m_document->timecode(), this);
1909 if (d.exec() != QDialog::Accepted) return;
1910 if (addGuide(d.newMarker().time(), d.newMarker().comment())) {
1911 EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), d.newMarker().time(), d.newMarker().comment(), false);
1912 m_commandStack->push(command);
1916 void CustomTrackView::slotEditGuide() {
1917 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1919 for (int i = 0; i < m_guides.count(); i++) {
1920 if (m_guides.at(i)->position() == pos) {
1921 slotEditGuide(m_guides.at(i)->info());
1926 if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
1929 void CustomTrackView::slotEditGuide(CommentedTime guide) {
1930 MarkerDialog d(NULL, guide, m_document->timecode(), this);
1931 if (d.exec() == QDialog::Accepted) {
1932 EditGuideCommand *command = new EditGuideCommand(this, guide.time(), guide.comment(), d.newMarker().time(), d.newMarker().comment(), true);
1933 m_commandStack->push(command);
1938 void CustomTrackView::slotDeleteGuide() {
1939 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1941 for (int i = 0; i < m_guides.count(); i++) {
1942 if (m_guides.at(i)->position() == pos) {
1943 EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true);
1944 m_commandStack->push(command);
1949 if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
1952 void CustomTrackView::slotDeleteAllGuides() {
1953 QUndoCommand *deleteAll = new QUndoCommand();
1954 deleteAll->setText("Delete all guides");
1955 for (int i = 0; i < m_guides.count(); i++) {
1956 EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true, deleteAll);
1958 m_commandStack->push(deleteAll);
1961 void CustomTrackView::setTool(PROJECTTOOL tool) {
1965 void CustomTrackView::setScale(double scaleFactor) {
1967 matrix = matrix.scale(scaleFactor, 1);
1968 m_scene->setScale(scaleFactor);
1969 //scale(scaleFactor, 1);
1970 m_animationTimer->stop();
1979 /*double pos = cursorPos() / m_scale;
1980 m_scale = scaleFactor;
1981 m_scene->setScale(m_scale);
1982 int vert = verticalScrollBar()->value();
1983 kDebug() << " HHHHHHHH SCALING: " << m_scale;
1984 QList<QGraphicsItem *> itemList = items();
1985 for (int i = 0; i < itemList.count(); i++) {
1986 if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
1987 AbstractClipItem *clip = (AbstractClipItem *)itemList.at(i);
1988 clip->setRect(0, 0, (qreal) clip->duration().frames(m_document->fps()) * m_scale - .5, clip->rect().height());
1989 clip->setPos((qreal) clip->startPos().frames(m_document->fps()) * m_scale, clip->pos().y());
1993 for (int i = 0; i < m_guides.count(); i++) {
1994 m_guides.at(i)->updatePosition(m_scale);
1997 setSceneRect(0, 0, (m_projectDuration + 100) * m_scale, sceneRect().height());
1998 updateCursorPos();*/
2000 centerOn(QPointF(cursorPos(), m_tracksHeight));
2001 //verticalScrollBar()->setValue(vert);*/
2004 void CustomTrackView::slotRefreshGuides() {
2005 if (KdenliveSettings::showmarkers()) {
2006 kDebug() << "// refresh GUIDES";
2007 for (int i = 0; i < m_guides.count(); i++) {
2008 m_guides.at(i)->update();
2013 void CustomTrackView::drawBackground(QPainter * painter, const QRectF & rect) {
2014 QColor base = palette().button().color();
2016 r.setWidth(r.width() + 1);
2017 painter->setClipRect(r);
2018 painter->drawLine(r.left(), 0, r.right(), 0);
2019 uint max = m_scene->m_tracksList.count();
2020 for (uint i = 0; i < max;i++) {
2021 /*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)));
2023 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)));
2024 painter->drawLine(r.left(), m_tracksHeight * (i + 1), r.right(), m_tracksHeight * (i + 1));
2026 int lowerLimit = m_tracksHeight * m_scene->m_tracksList.count() + 1;
2027 if (height() > lowerLimit)
2028 painter->fillRect(QRectF(r.left(), lowerLimit, r.width(), height() - lowerLimit), QBrush(base));
2031 bool CustomTrackView::findString(const QString &text) {
2033 for (int i = 0; i < m_searchPoints.size(); ++i) {
2034 marker = m_searchPoints.at(i).comment();
2035 if (marker.contains(text, Qt::CaseInsensitive)) {
2036 setCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()), true);
2037 int vert = verticalScrollBar()->value();
2038 int hor = cursorPos();
2039 ensureVisible(hor, vert + 10, 2, 2, 50, 0);
2047 bool CustomTrackView::findNextString(const QString &text) {
2049 for (int i = m_findIndex + 1; i < m_searchPoints.size(); ++i) {
2050 marker = m_searchPoints.at(i).comment();
2051 if (marker.contains(text, Qt::CaseInsensitive)) {
2052 setCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()), true);
2053 int vert = verticalScrollBar()->value();
2054 int hor = cursorPos();
2055 ensureVisible(hor, vert + 10, 2, 2, 50, 0);
2064 void CustomTrackView::initSearchStrings() {
2065 m_searchPoints.clear();
2066 QList<QGraphicsItem *> itemList = items();
2067 for (int i = 0; i < itemList.count(); i++) {
2068 // parse all clip names
2069 if (itemList.at(i)->type() == AVWIDGET) {
2070 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
2071 GenTime start = item->startPos();
2072 CommentedTime t(start, item->clipName());
2073 m_searchPoints.append(t);
2074 // add all clip markers
2075 QList < CommentedTime > markers = item->commentedSnapMarkers();
2076 m_searchPoints += markers;
2081 for (int i = 0; i < m_guides.count(); i++) {
2082 m_searchPoints.append(m_guides.at(i)->info());
2085 qSort(m_searchPoints);
2088 void CustomTrackView::clearSearchStrings() {
2089 m_searchPoints.clear();
2093 void CustomTrackView::copyClip() {
2094 while (m_copiedItems.count() > 0) {
2095 delete m_copiedItems.takeFirst();
2097 QList<QGraphicsItem *> itemList = scene()->selectedItems();
2098 if (itemList.count() == 0) {
2099 emit displayMessage(i18n("Select a clip before copying"), ErrorMessage);
2102 for (int i = 0; i < itemList.count(); i++) {
2103 if (itemList.at(i)->type() == AVWIDGET) {
2104 ClipItem *dup = static_cast <ClipItem *>(itemList.at(i));
2105 m_copiedItems.append(dup->clone(dup->info()));
2106 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
2107 Transition *dup = static_cast <Transition *>(itemList.at(i));
2108 m_copiedItems.append(dup->clone());
2113 bool CustomTrackView::canBePastedTo(ItemInfo info, int type) const {
2114 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));
2115 QList<QGraphicsItem *> collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect);
2116 for (int i = 0; i < collisions.count(); i++) {
2117 if (collisions.at(i)->type() == type) return false;
2122 bool CustomTrackView::canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const {
2123 for (int i = 0; i < items.count(); i++) {
2124 ItemInfo info = items.at(i)->info();
2125 info.startPos += offset;
2126 info.endPos += offset;
2127 info.track += trackOffset;
2128 if (!canBePastedTo(info, items.at(i)->type())) return false;
2133 bool CustomTrackView::canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const {
2134 QPainterPath movePath;
2135 movePath.moveTo(0, 0);
2137 for (int i = 0; i < items.count(); i++) {
2138 ItemInfo info = items.at(i)->info();
2139 info.startPos = info.startPos + offset;
2140 info.endPos = info.endPos + offset;
2141 info.track = info.track + trackOffset;
2142 if (info.startPos < GenTime()) {
2143 // No clip should go below 0
2146 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));
2147 movePath.addRect(rect);
2149 QList<QGraphicsItem *> collisions = scene()->items(movePath, Qt::IntersectsItemBoundingRect);
2150 for (int i = 0; i < collisions.count(); i++) {
2151 if ((collisions.at(i)->type() == AVWIDGET || collisions.at(i)->type() == TRANSITIONWIDGET) && !items.contains(static_cast <AbstractClipItem *>(collisions.at(i)))) {
2152 kDebug() << " //////////// CLIP COLLISION, MOVE NOT ALLOWED";
2159 void CustomTrackView::pasteClip() {
2160 if (m_copiedItems.count() == 0) {
2161 emit displayMessage(i18n("No clip copied"), ErrorMessage);
2165 if (m_menuPosition.isNull()) position = mapFromGlobal(QCursor::pos());
2166 else position = m_menuPosition;
2167 GenTime pos = GenTime((int)(mapToScene(position).x()), m_document->fps());
2168 int track = (int)(position.y() / m_tracksHeight);
2169 ItemInfo first = m_copiedItems.at(0)->info();
2171 GenTime offset = pos - first.startPos;
2172 int trackOffset = track - first.track;
2174 if (!canBePasted(m_copiedItems, offset, trackOffset)) {
2175 emit displayMessage(i18n("Cannot paste selected clips"), ErrorMessage);
2178 QUndoCommand *pasteClips = new QUndoCommand();
2179 pasteClips->setText("Paste clips");
2181 for (int i = 0; i < m_copiedItems.count(); i++) {
2182 // parse all clip names
2183 if (m_copiedItems.at(i) && m_copiedItems.at(i)->type() == AVWIDGET) {
2184 ClipItem *clip = static_cast <ClipItem *>(m_copiedItems.at(i));
2186 info.startPos = clip->startPos() + offset;
2187 info.endPos = clip->endPos() + offset;
2188 info.cropStart = clip->cropStart();
2189 info.track = clip->track() + trackOffset;
2190 if (canBePastedTo(info, AVWIDGET)) {
2191 new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), info, clip->effectList(), true, false, pasteClips);
2192 } else emit displayMessage(i18n("Cannot paste clip to selected place"), ErrorMessage);
2193 } else if (m_copiedItems.at(i) && m_copiedItems.at(i)->type() == TRANSITIONWIDGET) {
2194 Transition *tr = static_cast <Transition *>(m_copiedItems.at(i));
2196 info.startPos = tr->startPos() + offset;
2197 info.endPos = tr->endPos() + offset;
2198 info.track = tr->track() + trackOffset;
2199 if (canBePastedTo(info, TRANSITIONWIDGET)) {
2200 new AddTransitionCommand(this, info, tr->transitionEndTrack() + trackOffset, tr->toXML(), false, true, pasteClips);
2201 } else emit displayMessage(i18n("Cannot paste transition to selected place"), ErrorMessage);
2204 m_commandStack->push(pasteClips);
2207 void CustomTrackView::pasteClipEffects() {
2208 if (m_copiedItems.count() != 1 || m_copiedItems.at(0)->type() != AVWIDGET) {
2209 emit displayMessage(i18n("You must copy exactly one clip before pasting effects"), ErrorMessage);
2212 ClipItem *clip = static_cast < ClipItem *>(m_copiedItems.at(0));
2213 EffectsList effects = clip->effectList();
2215 QUndoCommand *paste = new QUndoCommand();
2216 paste->setText("Paste effects");
2218 QList<QGraphicsItem *> clips = scene()->selectedItems();
2219 for (int i = 0; i < clips.count(); ++i) {
2220 if (clips.at(i)->type() == AVWIDGET) {
2221 ClipItem *item = static_cast < ClipItem *>(clips.at(i));
2222 for (int i = 0; i < clip->effectsCount(); i++) {
2223 new AddEffectCommand(this, m_scene->m_tracksList.count() - item->track(), item->startPos(), clip->effectAt(i), true, paste);
2227 m_commandStack->push(paste);
2231 ClipItem *CustomTrackView::getClipUnderCursor() const {
2232 QRectF rect((double) m_cursorPos, 0.0, 1.0, (double)(m_tracksHeight * m_scene->m_tracksList.count()));
2233 QList<QGraphicsItem *> collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect);
2234 for (int i = 0; i < collisions.count(); i++) {
2235 if (collisions.at(i)->type() == AVWIDGET) {
2236 return static_cast < ClipItem *>(collisions.at(i));
2242 ClipItem *CustomTrackView::getMainActiveClip() const {
2243 QList<QGraphicsItem *> clips = scene()->selectedItems();
2244 if (clips.isEmpty()) {
2245 return getClipUnderCursor();
2247 ClipItem *item = NULL;
2248 for (int i = 0; i < clips.count(); ++i) {
2249 if (clips.at(i)->type() == AVWIDGET)
2250 item = static_cast < ClipItem *>(clips.at(i));
2251 if (item->startPos().frames(m_document->fps()) <= m_cursorPos && item->endPos().frames(m_document->fps()) >= m_cursorPos) break;
2253 if (item) return item;
2258 ClipItem *CustomTrackView::getActiveClipUnderCursor() const {
2259 QList<QGraphicsItem *> clips = scene()->selectedItems();
2260 if (clips.isEmpty()) {
2261 return getClipUnderCursor();
2264 for (int i = 0; i < clips.count(); ++i) {
2265 if (clips.at(i)->type() == AVWIDGET)
2266 item = static_cast < ClipItem *>(clips.at(i));
2267 if (item->startPos().frames(m_document->fps()) <= m_cursorPos && item->endPos().frames(m_document->fps()) >= m_cursorPos) return item;
2273 void CustomTrackView::setInPoint() {
2274 ClipItem *clip = getActiveClipUnderCursor();
2276 emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
2279 ItemInfo startInfo = clip->info();
2280 ItemInfo endInfo = clip->info();
2281 endInfo.startPos = GenTime(m_cursorPos, m_document->fps());
2282 ResizeClipCommand *command = new ResizeClipCommand(this, startInfo, endInfo, true);
2283 m_commandStack->push(command);
2286 void CustomTrackView::setOutPoint() {
2287 ClipItem *clip = getActiveClipUnderCursor();
2289 emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
2292 ItemInfo startInfo = clip->info();
2293 ItemInfo endInfo = clip->info();
2294 endInfo.endPos = GenTime(m_cursorPos, m_document->fps());
2295 ResizeClipCommand *command = new ResizeClipCommand(this, startInfo, endInfo, true);
2296 m_commandStack->push(command);
2299 void CustomTrackView::updateAllThumbs() {
2300 QList<QGraphicsItem *> itemList = items();
2302 Transition *transitionitem;
2303 for (int i = 0; i < itemList.count(); i++) {
2304 if (itemList.at(i)->type() == AVWIDGET) {
2305 item = static_cast <ClipItem *>(itemList.at(i));
2306 item->refreshClip();
2307 qApp->processEvents();
2312 #include "customtrackview.moc"