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 ***************************************************************************/
21 #include "customtrackview.h"
22 #include "docclipbase.h"
24 #include "definitions.h"
25 #include "moveclipcommand.h"
26 #include "movetransitioncommand.h"
27 #include "resizeclipcommand.h"
28 #include "editguidecommand.h"
29 #include "addtimelineclipcommand.h"
30 #include "addeffectcommand.h"
31 #include "editeffectcommand.h"
32 #include "moveeffectcommand.h"
33 #include "addtransitioncommand.h"
34 #include "edittransitioncommand.h"
35 #include "editkeyframecommand.h"
36 #include "changespeedcommand.h"
37 #include "addmarkercommand.h"
38 #include "razorclipcommand.h"
39 #include "kdenlivesettings.h"
40 #include "transition.h"
41 #include "clipmanager.h"
43 #include "markerdialog.h"
44 #include "mainwindow.h"
45 #include "ui_keyframedialog_ui.h"
46 #include "clipdurationdialog.h"
47 #include "abstractgroupitem.h"
48 #include "insertspacecommand.h"
49 #include "spacerdialog.h"
50 #include "addtrackcommand.h"
51 #include "movegroupcommand.h"
52 #include "ui_addtrack_ui.h"
53 #include "initeffects.h"
54 #include "locktrackcommand.h"
55 #include "groupclipscommand.h"
56 #include "splitaudiocommand.h"
57 #include "changecliptypecommand.h"
58 #include "trackdialog.h"
59 #include "tracksconfigdialog.h"
60 #include "configtrackscommand.h"
67 #include <KColorScheme>
68 #include <KMessageBox>
69 #include <KIO/NetAccess>
71 #include <QMouseEvent>
72 #include <QStylePainter>
73 #include <QGraphicsItem>
74 #include <QDomDocument>
76 #include <QApplication>
77 #include <QInputDialog>
80 #if QT_VERSION >= 0x040600
81 #include <QGraphicsDropShadowEffect>
84 bool sortGuidesList(const Guide *g1 , const Guide *g2)
86 return (*g1).position() < (*g2).position();
91 // disable animation if user asked it in KDE's global settings
92 // http://lists.kde.org/?l=kde-commits&m=120398724717624&w=2
93 // needs something like below (taken from dolphin)
94 // #include <kglobalsettings.h>
95 // const bool animate = KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects;
96 // const int duration = animate ? 1500 : 1;
98 CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscene, QWidget *parent) :
99 QGraphicsView(projectscene, parent),
100 m_tracksHeight(KdenliveSettings::trackheight()),
101 m_projectDuration(0),
104 m_scene(projectscene),
106 m_operationMode(NONE),
113 m_autoScroll(KdenliveSettings::autoscroll()),
114 m_pasteEffectsAction(NULL),
115 m_ungroupAction(NULL),
122 m_blockRefresh(false),
123 m_selectionGroup(NULL),
126 if (doc) m_commandStack = doc->commandStack();
127 else m_commandStack = NULL;
128 setMouseTracking(true);
129 setAcceptDrops(true);
130 setFrameShape(QFrame::NoFrame);
132 //setCacheMode(QGraphicsView::CacheBackground);
133 //setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
134 setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
136 pixmapCache = new KPixmapCache("kdenlive-thumbs");
137 KdenliveSettings::setTrackheight(m_tracksHeight);
138 m_animationTimer = new QTimeLine(800);
139 m_animationTimer->setFrameRange(0, 5);
140 m_animationTimer->setUpdateInterval(100);
141 m_animationTimer->setLoopCount(0);
142 m_tipColor = QColor(0, 192, 0, 200);
143 QColor border = QColor(255, 255, 255, 100);
144 m_tipPen.setColor(border);
145 m_tipPen.setWidth(3);
146 setContentsMargins(0, 0, 0, 0);
147 const int maxHeight = m_tracksHeight * m_document->tracksCount();
148 setSceneRect(0, 0, sceneRect().width(), maxHeight);
149 verticalScrollBar()->setMaximum(maxHeight);
150 m_cursorLine = projectscene->addLine(0, 0, 0, maxHeight);
151 m_cursorLine->setZValue(1000);
155 pen1.setColor(palette().text().color());
156 m_cursorLine->setPen(pen1);
157 m_cursorLine->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
159 KIcon razorIcon("edit-cut");
160 m_razorCursor = QCursor(razorIcon.pixmap(22, 22));
162 KIcon spacerIcon("kdenlive-spacer-tool");
163 m_spacerCursor = QCursor(spacerIcon.pixmap(22, 22));
164 verticalScrollBar()->setTracking(true);
165 // Line below was supposed to scroll guides label with scrollbar, not implemented yet
166 //connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slotRefreshGuides()));
167 connect(&m_scrollTimer, SIGNAL(timeout()), this, SLOT(slotCheckMouseScrolling()));
168 m_scrollTimer.setInterval(100);
169 m_scrollTimer.setSingleShot(true);
171 connect(&m_thumbsTimer, SIGNAL(timeout()), this, SLOT(slotFetchNextThumbs()));
172 m_thumbsTimer.setInterval(500);
173 m_thumbsTimer.setSingleShot(true);
176 CustomTrackView::~CustomTrackView()
178 qDeleteAll(m_guides);
180 m_waitingThumbs.clear();
184 void CustomTrackView::keyPressEvent(QKeyEvent * event)
186 if (event->key() == Qt::Key_Up) {
189 } else if (event->key() == Qt::Key_Down) {
192 } else QWidget::keyPressEvent(event);
195 void CustomTrackView::setDocumentModified()
197 m_document->setModified(true);
200 void CustomTrackView::setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition, QActionGroup *clipTypeGroup, QMenu *markermenu)
202 m_timelineContextMenu = timeline;
203 m_timelineContextClipMenu = clip;
204 m_clipTypeGroup = clipTypeGroup;
205 connect(m_timelineContextMenu, SIGNAL(aboutToHide()), this, SLOT(slotResetMenuPosition()));
207 m_markerMenu = new QMenu(i18n("Go to marker..."), this);
208 m_markerMenu->setEnabled(false);
209 markermenu->addMenu(m_markerMenu);
210 connect(m_markerMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotGoToMarker(QAction *)));
211 QList <QAction *> list = m_timelineContextClipMenu->actions();
212 for (int i = 0; i < list.count(); i++) {
213 if (list.at(i)->data().toString() == "paste_effects") m_pasteEffectsAction = list.at(i);
214 else if (list.at(i)->data().toString() == "ungroup_clip") m_ungroupAction = list.at(i);
217 m_timelineContextTransitionMenu = transition;
218 list = m_timelineContextTransitionMenu->actions();
219 for (int i = 0; i < list.count(); i++) {
220 if (list.at(i)->data().toString() == "auto") {
221 m_autoTransition = list.at(i);
226 m_timelineContextMenu->addSeparator();
227 m_deleteGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
228 connect(m_deleteGuide, SIGNAL(triggered()), this, SLOT(slotDeleteTimeLineGuide()));
229 m_timelineContextMenu->addAction(m_deleteGuide);
231 m_editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
232 connect(m_editGuide, SIGNAL(triggered()), this, SLOT(slotEditTimeLineGuide()));
233 m_timelineContextMenu->addAction(m_editGuide);
236 void CustomTrackView::slotDoResetMenuPosition()
238 m_menuPosition = QPoint();
241 void CustomTrackView::slotResetMenuPosition()
243 // after a short time (so that the action is triggered / or menu is closed, we reset the menu pos
244 QTimer::singleShot(300, this, SLOT(slotDoResetMenuPosition()));
247 void CustomTrackView::checkAutoScroll()
249 m_autoScroll = KdenliveSettings::autoscroll();
252 /*sQList <TrackInfo> CustomTrackView::tracksList() const {
253 return m_scene->m_tracksList;
256 void CustomTrackView::checkTrackHeight()
258 if (m_tracksHeight == KdenliveSettings::trackheight()) return;
259 m_tracksHeight = KdenliveSettings::trackheight();
260 emit trackHeightChanged();
261 QList<QGraphicsItem *> itemList = items();
263 Transition *transitionitem;
264 bool snap = KdenliveSettings::snaptopoints();
265 KdenliveSettings::setSnaptopoints(false);
266 for (int i = 0; i < itemList.count(); i++) {
267 if (itemList.at(i)->type() == AVWIDGET) {
268 item = (ClipItem*) itemList.at(i);
269 item->setRect(0, 0, item->rect().width(), m_tracksHeight - 1);
270 item->setPos((qreal) item->startPos().frames(m_document->fps()), (qreal) item->track() * m_tracksHeight + 1);
271 item->resetThumbs(true);
272 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
273 transitionitem = (Transition*) itemList.at(i);
274 transitionitem->setRect(0, 0, transitionitem->rect().width(), m_tracksHeight / 3 * 2 - 1);
275 transitionitem->setPos((qreal) transitionitem->startPos().frames(m_document->fps()), (qreal) transitionitem->track() * m_tracksHeight + m_tracksHeight / 3 * 2);
278 double newHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
279 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight);
281 for (int i = 0; i < m_guides.count(); i++) {
282 QLineF l = m_guides.at(i)->line();
283 l.setP2(QPointF(l.x2(), newHeight));
284 m_guides.at(i)->setLine(l);
287 setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
288 // verticalScrollBar()->setMaximum(m_tracksHeight * m_document->tracksCount());
289 KdenliveSettings::setSnaptopoints(snap);
290 viewport()->update();
293 /** Zoom or move viewport on mousewheel
295 * If mousewheel+Ctrl, zooms in/out on the timeline.
297 * With Ctrl, moves viewport towards end of timeline if down/back,
298 * opposite on up/forward.
300 * See also http://www.kdenlive.org/mantis/view.php?id=265 */
301 void CustomTrackView::wheelEvent(QWheelEvent * e)
303 if (e->modifiers() == Qt::ControlModifier) {
304 if (e->delta() > 0) emit zoomIn();
307 if (e->delta() <= 0) horizontalScrollBar()->setValue(horizontalScrollBar()->value() + horizontalScrollBar()->singleStep());
308 else horizontalScrollBar()->setValue(horizontalScrollBar()->value() - horizontalScrollBar()->singleStep());
312 int CustomTrackView::getPreviousVideoTrack(int track)
314 track = m_document->tracksCount() - track - 1;
316 for (int i = track; i > -1; i--) {
317 if (m_document->trackInfoAt(i).type == VIDEOTRACK) return i + 1;
323 void CustomTrackView::slotFetchNextThumbs()
325 if (!m_waitingThumbs.isEmpty()) {
326 ClipItem *item = m_waitingThumbs.takeFirst();
327 while ((item == NULL) && !m_waitingThumbs.isEmpty()) {
328 item = m_waitingThumbs.takeFirst();
330 if (item) item->slotFetchThumbs();
331 if (!m_waitingThumbs.isEmpty()) m_thumbsTimer.start();
335 void CustomTrackView::slotCheckMouseScrolling()
337 if (m_scrollOffset == 0) {
338 m_scrollTimer.stop();
341 horizontalScrollBar()->setValue(horizontalScrollBar()->value() + m_scrollOffset);
342 m_scrollTimer.start();
345 void CustomTrackView::slotCheckPositionScrolling()
347 // If mouse is at a border of the view, scroll
348 if (m_moveOpMode != SEEK) return;
349 if (mapFromScene(m_cursorPos, 0).x() < 3) {
350 horizontalScrollBar()->setValue(horizontalScrollBar()->value() - 2);
351 QTimer::singleShot(200, this, SLOT(slotCheckPositionScrolling()));
352 setCursorPos(mapToScene(QPoint(-2, 0)).x());
353 } else if (viewport()->width() - 3 < mapFromScene(m_cursorPos + 1, 0).x()) {
354 horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 2);
355 setCursorPos(mapToScene(QPoint(viewport()->width(), 0)).x() + 1);
356 QTimer::singleShot(200, this, SLOT(slotCheckPositionScrolling()));
362 void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
364 int pos = event->x();
365 int mappedXPos = qMax((int)(mapToScene(event->pos()).x() + 0.5), 0);
366 double snappedPos = getSnapPointForPos(mappedXPos);
367 emit mousePosition(mappedXPos);
369 if (event->buttons() & Qt::MidButton) return;
370 if (dragMode() == QGraphicsView::RubberBandDrag || (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL)) {
371 event->setAccepted(true);
373 QGraphicsView::mouseMoveEvent(event);
377 if (event->buttons() != Qt::NoButton) {
378 bool move = (event->pos() - m_clickEvent).manhattanLength() >= QApplication::startDragDistance();
379 if (m_dragItem && m_tool == SELECTTOOL) {
380 if (m_operationMode == MOVE && move) {
381 QGraphicsView::mouseMoveEvent(event);
382 // If mouse is at a border of the view, scroll
384 m_scrollOffset = -30;
385 m_scrollTimer.start();
386 } else if (viewport()->width() - pos < 10) {
388 m_scrollTimer.start();
389 } else if (m_scrollTimer.isActive()) m_scrollTimer.stop();
391 } else if (m_operationMode == RESIZESTART && move) {
392 m_document->renderer()->pause();
393 m_dragItem->resizeStart((int)(snappedPos));
394 } else if (m_operationMode == RESIZEEND && move) {
395 m_document->renderer()->pause();
396 m_dragItem->resizeEnd((int)(snappedPos));
397 } else if (m_operationMode == FADEIN && move) {
398 ((ClipItem*) m_dragItem)->setFadeIn((int)(mappedXPos - m_dragItem->startPos().frames(m_document->fps())));
399 } else if (m_operationMode == FADEOUT && move) {
400 ((ClipItem*) m_dragItem)->setFadeOut((int)(m_dragItem->endPos().frames(m_document->fps()) - mappedXPos));
401 } else if (m_operationMode == KEYFRAME && move) {
402 GenTime keyFramePos = GenTime(mappedXPos, m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart();
403 double pos = mapToScene(event->pos()).toPoint().y();
404 QRectF br = m_dragItem->sceneBoundingRect();
405 double maxh = 100.0 / br.height();
406 pos = (br.bottom() - pos) * maxh;
407 m_dragItem->updateKeyFramePos(keyFramePos, pos);
409 removeTipAnimation();
411 } else if (m_operationMode == MOVEGUIDE) {
412 removeTipAnimation();
413 QGraphicsView::mouseMoveEvent(event);
415 } else if (m_operationMode == SPACER && move && m_selectionGroup) {
417 snappedPos = getSnapPointForPos(mappedXPos + m_spacerOffset);
418 if (snappedPos < 0) snappedPos = 0;
420 // Make sure there is no collision
421 QList<QGraphicsItem *> children = m_selectionGroup->childItems();
422 QPainterPath shape = m_selectionGroup->clipGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0));
423 QList<QGraphicsItem*> collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
424 collidingItems.removeAll(m_selectionGroup);
425 for (int i = 0; i < children.count(); i++) {
426 if (children.at(i)->type() == GROUPWIDGET) {
427 QList<QGraphicsItem *> subchildren = children.at(i)->childItems();
428 for (int j = 0; j < subchildren.count(); j++)
429 collidingItems.removeAll(subchildren.at(j));
431 collidingItems.removeAll(children.at(i));
433 bool collision = false;
435 for (int i = 0; i < collidingItems.count(); i++) {
436 if (!collidingItems.at(i)->isEnabled()) continue;
437 if (collidingItems.at(i)->type() == AVWIDGET && snappedPos < m_selectionGroup->sceneBoundingRect().left()) {
438 AbstractClipItem *item = static_cast <AbstractClipItem *>(collidingItems.at(i));
439 // Moving backward, determine best pos
440 QPainterPath clipPath;
441 clipPath.addRect(item->sceneBoundingRect());
442 QPainterPath res = shape.intersected(clipPath);
443 offset = qMax(offset, (int)(res.boundingRect().width() + 0.5));
446 snappedPos += offset;
447 // make sure we have no collision
448 shape = m_selectionGroup->clipGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0));
449 collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
450 collidingItems.removeAll(m_selectionGroup);
451 for (int i = 0; i < children.count(); i++) {
452 if (children.at(i)->type() == GROUPWIDGET) {
453 QList<QGraphicsItem *> subchildren = children.at(i)->childItems();
454 for (int j = 0; j < subchildren.count(); j++)
455 collidingItems.removeAll(subchildren.at(j));
457 collidingItems.removeAll(children.at(i));
460 for (int i = 0; i < collidingItems.count(); i++) {
461 if (!collidingItems.at(i)->isEnabled()) continue;
462 if (collidingItems.at(i)->type() == AVWIDGET) {
471 shape = m_selectionGroup->transitionGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0));
472 collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
473 collidingItems.removeAll(m_selectionGroup);
474 for (int i = 0; i < children.count(); i++) {
475 if (children.at(i)->type() == GROUPWIDGET) {
476 QList<QGraphicsItem *> subchildren = children.at(i)->childItems();
477 for (int j = 0; j < subchildren.count(); j++)
478 collidingItems.removeAll(subchildren.at(j));
480 collidingItems.removeAll(children.at(i));
484 for (int i = 0; i < collidingItems.count(); i++) {
485 if (collidingItems.at(i)->type() == TRANSITIONWIDGET && snappedPos < m_selectionGroup->sceneBoundingRect().left()) {
486 AbstractClipItem *item = static_cast <AbstractClipItem *>(collidingItems.at(i));
487 // Moving backward, determine best pos
488 QPainterPath clipPath;
489 clipPath.addRect(item->sceneBoundingRect());
490 QPainterPath res = shape.intersected(clipPath);
491 offset = qMax(offset, (int)(res.boundingRect().width() + 0.5));
495 snappedPos += offset;
496 // make sure we have no collision
497 shape = m_selectionGroup->transitionGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0));
498 collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
499 collidingItems.removeAll(m_selectionGroup);
500 for (int i = 0; i < children.count(); i++) {
501 if (children.at(i)->type() == GROUPWIDGET) {
502 QList<QGraphicsItem *> subchildren = children.at(i)->childItems();
503 for (int j = 0; j < subchildren.count(); j++)
504 collidingItems.removeAll(subchildren.at(j));
506 collidingItems.removeAll(children.at(i));
508 for (int i = 0; i < collidingItems.count(); i++) {
509 if (collidingItems.at(i)->type() == TRANSITIONWIDGET) {
517 m_selectionGroup->translate(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0);
518 //m_selectionGroup->setPos(mappedXPos + (((int) m_selectionGroup->boundingRect().topLeft().x() + 0.5) - mappedClick) , m_selectionGroup->pos().y());
522 if (m_tool == RAZORTOOL) {
523 setCursor(m_razorCursor);
524 //QGraphicsView::mouseMoveEvent(event);
526 } else if (m_tool == SPACERTOOL) {
527 setCursor(m_spacerCursor);
531 QList<QGraphicsItem *> itemList = items(event->pos());
532 QGraphicsRectItem *item = NULL;
533 OPERATIONTYPE opMode = NONE;
535 if (itemList.count() == 1 && itemList.at(0)->type() == GUIDEITEM) {
537 } else for (int i = 0; i < itemList.count(); i++) {
538 if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
539 item = (QGraphicsRectItem*) itemList.at(i);
544 if (item && event->buttons() == Qt::NoButton) {
545 AbstractClipItem *clip = static_cast <AbstractClipItem*>(item);
546 if (m_tool == RAZORTOOL) {
547 // razor tool over a clip, display current frame in monitor
548 if (false && !m_blockRefresh && item->type() == AVWIDGET) {
549 //TODO: solve crash when showing frame when moving razor over clip
550 emit showClipFrame(((ClipItem *) item)->baseClip(), QPoint(), mappedXPos - (clip->startPos() - clip->cropStart()).frames(m_document->fps()));
555 opMode = clip->operationMode(mapToScene(event->pos()));
556 const double size = 5;
557 if (opMode == m_moveOpMode) {
558 QGraphicsView::mouseMoveEvent(event);
561 removeTipAnimation();
563 m_moveOpMode = opMode;
564 setTipAnimation(clip, opMode, size);
566 setCursor(Qt::OpenHandCursor);
567 else if (opMode == RESIZESTART)
568 setCursor(KCursor("left_side", Qt::SizeHorCursor));
569 else if (opMode == RESIZEEND)
570 setCursor(KCursor("right_side", Qt::SizeHorCursor));
571 else if (opMode == FADEIN || opMode == FADEOUT) {
572 setCursor(Qt::PointingHandCursor);
573 emit displayMessage(i18n("Drag to add or resize a fade effect."), InformationMessage);
574 } else if (opMode == TRANSITIONSTART || opMode == TRANSITIONEND) {
575 setCursor(Qt::PointingHandCursor);
576 emit displayMessage(i18n("Click to add a transition."), InformationMessage);
577 } else if (opMode == KEYFRAME) {
578 setCursor(Qt::PointingHandCursor);
579 emit displayMessage(i18n("Move keyframe above or below clip to remove it, double click to add a new one."), InformationMessage);
581 } // no clip under mouse
582 else if (m_tool == RAZORTOOL) {
585 } else if (opMode == MOVEGUIDE) {
586 m_moveOpMode = opMode;
587 setCursor(Qt::SplitHCursor);
589 removeTipAnimation();
590 setCursor(Qt::ArrowCursor);
591 if (event->buttons() != Qt::NoButton && event->modifiers() == Qt::NoModifier) {
592 QGraphicsView::mouseMoveEvent(event);
594 setCursorPos(mappedXPos);
595 slotCheckPositionScrolling();
597 } else m_moveOpMode = NONE;
599 QGraphicsView::mouseMoveEvent(event);
603 void CustomTrackView::mousePressEvent(QMouseEvent * event)
605 setFocus(Qt::MouseFocusReason);
606 m_menuPosition = QPoint();
608 // special cases (middle click button or ctrl / shift click
609 if (event->button() == Qt::MidButton) {
611 m_blockRefresh = false;
612 m_operationMode = NONE;
616 if (event->modifiers() & Qt::ShiftModifier) {
617 // Rectangle selection
618 setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
619 setDragMode(QGraphicsView::RubberBandDrag);
620 if (!(event->modifiers() & Qt::ControlModifier)) {
621 resetSelectionGroup();
622 scene()->clearSelection();
624 m_blockRefresh = false;
625 m_operationMode = RUBBERSELECTION;
626 QGraphicsView::mousePressEvent(event);
630 m_blockRefresh = true;
632 bool collision = false;
634 if (m_tool != RAZORTOOL) activateMonitor();
635 else if (m_document->renderer()->playSpeed() != 0.0) {
636 m_document->renderer()->pause();
639 m_clickEvent = event->pos();
641 // check item under mouse
642 QList<QGraphicsItem *> collisionList = items(m_clickEvent);
644 if (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL && collisionList.count() == 0) {
645 // Pressing Ctrl + left mouse button in an empty area scrolls the timeline
646 setDragMode(QGraphicsView::ScrollHandDrag);
647 QGraphicsView::mousePressEvent(event);
648 m_blockRefresh = false;
649 m_operationMode = NONE;
653 // if a guide and a clip were pressed, just select the guide
654 for (int i = 0; i < collisionList.count(); ++i) {
655 if (collisionList.at(i)->type() == GUIDEITEM) {
656 // a guide item was pressed
657 m_dragGuide = (Guide *) collisionList.at(i);
658 if (event->button() == Qt::LeftButton) { // move it
659 m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, true);
661 m_operationMode = MOVEGUIDE;
662 // deselect all clips so that only the guide will move
663 m_scene->clearSelection();
664 resetSelectionGroup(false);
665 updateSnapPoints(NULL);
666 QGraphicsView::mousePressEvent(event);
668 } else // show context menu
673 // Find first clip, transition or group under mouse (when no guides selected)
675 AbstractGroupItem *dragGroup = NULL;
676 AbstractClipItem *collisionClip = NULL;
678 while (!m_dragGuide && ct < collisionList.count()) {
679 if (collisionList.at(ct)->type() == AVWIDGET || collisionList.at(ct)->type() == TRANSITIONWIDGET) {
680 collisionClip = static_cast <AbstractClipItem *>(collisionList.at(ct));
681 if (collisionClip->isItemLocked())
683 if (collisionClip == m_dragItem)
684 collisionClip = NULL;
686 m_dragItem = collisionClip;
688 m_dragItemInfo = m_dragItem->info();
689 if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET && m_dragItem->parentItem() != m_selectionGroup) {
690 // kDebug()<<"// KLIK FOUND GRP: "<<m_dragItem->sceneBoundingRect();
691 dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
698 if (m_dragItem) emit clipItemSelected(NULL);
701 #if QT_VERSION >= 0x040600
702 // Add shadow to dragged item, currently disabled because of painting artifacts
703 //TODO:Â re-enable when fixed
704 /*QGraphicsDropShadowEffect *eff = new QGraphicsDropShadowEffect();
705 eff->setBlurRadius(5);
706 eff->setOffset(3, 3);
707 m_dragItem->setGraphicsEffect(eff);*/
709 if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) {
710 // update transition menu action
711 m_autoTransition->setChecked(static_cast<Transition *>(m_dragItem)->isAutomatic());
712 m_autoTransition->setEnabled(true);
713 } else m_autoTransition->setEnabled(false);
715 // context menu requested
716 if (event->button() == Qt::RightButton) {
718 if (dragGroup) dragGroup->setSelected(true);
719 else if (!m_dragItem->isSelected()) {
720 resetSelectionGroup(false);
721 m_scene->clearSelection();
722 m_dragItem->setSelected(true);
724 } else if (!m_dragGuide) {
725 // check if there is a guide close to mouse click
726 QList<QGraphicsItem *> guidesCollisionList = items(event->pos().x() - 5, event->pos().y(), 10, 2); // a rect of height < 2 does not always collide with the guide
727 for (int i = 0; i < guidesCollisionList.count(); i++) {
728 if (guidesCollisionList.at(i)->type() == GUIDEITEM) {
729 m_dragGuide = static_cast <Guide *>(guidesCollisionList.at(i));
733 // keep this to support multiple guides context menu in the future (?)
734 /*if (guidesCollisionList.at(0)->type() != GUIDEITEM)
735 guidesCollisionList.removeAt(0);
737 if (!guidesCollisionList.isEmpty())
738 m_dragGuide = static_cast <Guide *>(guidesCollisionList.at(0));*/
741 m_operationMode = NONE;
742 displayContextMenu(event->globalPos(), m_dragItem, dragGroup);
743 m_menuPosition = m_clickEvent;
749 // No item under click
750 if (m_dragItem == NULL || m_tool == SPACERTOOL) {
751 resetSelectionGroup(false);
752 setCursor(Qt::ArrowCursor);
753 m_scene->clearSelection();
755 updateClipTypeActions(NULL);
756 if (m_tool == SPACERTOOL) {
757 QList<QGraphicsItem *> selection;
758 if (event->modifiers() == Qt::ControlModifier) {
759 // Ctrl + click, select all items on track after click position
760 int track = (int)(mapToScene(m_clickEvent).y() / m_tracksHeight);
761 if (m_document->trackInfoAt(m_document->tracksCount() - track - 1).isLocked) {
762 // Cannot use spacer on locked track
763 emit displayMessage(i18n("Cannot use spacer in a locked track"), ErrorMessage);
767 QRectF rect(mapToScene(m_clickEvent).x(), track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width() - mapToScene(m_clickEvent).x(), m_tracksHeight / 2 - 2);
770 selection = checkForGroups(rect, &isOk);
772 // groups found on track, do not allow the move
773 emit displayMessage(i18n("Cannot use spacer in a track with a group"), ErrorMessage);
777 kDebug() << "SPACER TOOL + CTRL, SELECTING ALL CLIPS ON TRACK " << track << " WITH SELECTION RECT " << m_clickEvent.x() << "/" << track * m_tracksHeight + 1 << "; " << mapFromScene(sceneRect().width(), 0).x() - m_clickEvent.x() << "/" << m_tracksHeight - 2;
779 // Select all items on all tracks after click position
780 selection = items(event->pos().x(), 1, mapFromScene(sceneRect().width(), 0).x() - event->pos().x(), sceneRect().height());
781 kDebug() << "SELELCTING ELEMENTS WITHIN =" << event->pos().x() << "/" << 1 << ", " << mapFromScene(sceneRect().width(), 0).x() - event->pos().x() << "/" << sceneRect().height();
784 QList <GenTime> offsetList;
785 // create group to hold selected items
786 m_selectionGroup = new AbstractGroupItem(m_document->fps());
787 scene()->addItem(m_selectionGroup);
789 for (int i = 0; i < selection.count(); i++) {
790 if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET)) {
791 AbstractClipItem *item = static_cast<AbstractClipItem *>(selection.at(i));
792 if (item->isItemLocked()) continue;
793 offsetList.append(item->startPos());
794 offsetList.append(item->endPos());
795 m_selectionGroup->addToGroup(selection.at(i));
796 selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
797 } else if (/*selection.at(i)->parentItem() == 0 && */selection.at(i)->type() == GROUPWIDGET) {
798 if (static_cast<AbstractGroupItem *>(selection.at(i))->isItemLocked()) continue;
799 QList<QGraphicsItem *> children = selection.at(i)->childItems();
800 for (int j = 0; j < children.count(); j++) {
801 AbstractClipItem *item = static_cast<AbstractClipItem *>(children.at(j));
802 offsetList.append(item->startPos());
803 offsetList.append(item->endPos());
805 m_selectionGroup->addToGroup(selection.at(i));
806 selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
807 } else if (selection.at(i)->parentItem() && !selection.contains(selection.at(i)->parentItem())) {
808 if (static_cast<AbstractGroupItem *>(selection.at(i)->parentItem())->isItemLocked()) continue;
809 //AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(selection.at(i)->parentItem());
810 m_selectionGroup->addToGroup(selection.at(i)->parentItem());
811 selection.at(i)->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
814 m_spacerOffset = m_selectionGroup->sceneBoundingRect().left() - (int)(mapToScene(m_clickEvent).x());
815 if (!offsetList.isEmpty()) {
817 QList <GenTime> cleandOffsetList;
818 GenTime startOffset = offsetList.takeFirst();
819 for (int k = 0; k < offsetList.size(); k++) {
820 GenTime newoffset = offsetList.at(k) - startOffset;
821 if (newoffset != GenTime() && !cleandOffsetList.contains(newoffset)) {
822 cleandOffsetList.append(newoffset);
825 updateSnapPoints(NULL, cleandOffsetList, true);
827 m_operationMode = SPACER;
829 setCursorPos((int)(mapToScene(event->x(), 0).x()));
831 QGraphicsView::mousePressEvent(event);
836 if (m_tool == RAZORTOOL && m_dragItem) {
837 if (m_dragItem->type() == TRANSITIONWIDGET) {
838 emit displayMessage(i18n("Cannot cut a transition"), ErrorMessage);
842 } else if (m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
843 emit displayMessage(i18n("Cannot cut a clip in a group"), ErrorMessage);
848 AbstractClipItem *clip = static_cast <AbstractClipItem *>(m_dragItem);
849 RazorClipCommand* command = new RazorClipCommand(this, clip->info(), GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()));
850 m_document->renderer()->pause();
851 m_commandStack->push(command);
852 setDocumentModified();
858 bool itemSelected = false;
859 if (m_dragItem->isSelected()) itemSelected = true;
860 else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected()) itemSelected = true;
861 else if (dragGroup && dragGroup->isSelected()) itemSelected = true;
863 if (event->modifiers() == Qt::ControlModifier || itemSelected == false) {
864 if (event->modifiers() != Qt::ControlModifier) {
865 resetSelectionGroup(false);
866 m_scene->clearSelection();
867 // A refresh seems necessary otherwise in zoomed mode, some clips disappear
868 viewport()->update();
869 } else resetSelectionGroup();
871 if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET) {
872 //kDebug()<<"// KLIK FOUND GRP: "<<m_dragItem->sceneBoundingRect();
873 dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
875 bool selected = !m_dragItem->isSelected();
876 if (dragGroup) dragGroup->setSelected(selected);
877 else m_dragItem->setSelected(selected);
879 groupSelectedItems();
880 ClipItem *clip = static_cast <ClipItem *>(m_dragItem);
881 updateClipTypeActions(dragGroup == NULL ? clip : NULL);
882 m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
885 if (collisionClip != NULL || m_dragItem == NULL) {
886 if (m_dragItem && m_dragItem->type() == AVWIDGET && !m_dragItem->isItemLocked()) {
887 ClipItem *selected = static_cast <ClipItem*>(m_dragItem);
888 emit clipItemSelected(selected);
889 } else emit clipItemSelected(NULL);
892 // If clicked item is selected, allow move
893 if (event->modifiers() != Qt::ControlModifier && m_operationMode == NONE) QGraphicsView::mousePressEvent(event);
895 m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y()));
896 m_operationMode = m_dragItem->operationMode(mapToScene(event->pos()));
898 // Update snap points
899 if (m_selectionGroup == NULL) {
900 if (m_operationMode == RESIZEEND || m_operationMode == RESIZESTART) updateSnapPoints(NULL);
901 else updateSnapPoints(m_dragItem);
903 QList <GenTime> offsetList;
904 QList<QGraphicsItem *> children = m_selectionGroup->childItems();
905 for (int i = 0; i < children.count(); i++) {
906 if (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET) {
907 AbstractClipItem *item = static_cast <AbstractClipItem *>(children.at(i));
908 offsetList.append(item->startPos());
909 offsetList.append(item->endPos());
912 if (!offsetList.isEmpty()) {
914 GenTime startOffset = offsetList.takeFirst();
915 QList <GenTime> cleandOffsetList;
916 for (int k = 0; k < offsetList.size(); k++) {
917 GenTime newoffset = offsetList.at(k) - startOffset;
918 if (newoffset != GenTime() && !cleandOffsetList.contains(newoffset)) {
919 cleandOffsetList.append(newoffset);
922 updateSnapPoints(NULL, cleandOffsetList, true);
926 if (m_operationMode == KEYFRAME) {
927 m_dragItem->updateSelectedKeyFrame();
928 m_blockRefresh = false;
930 } else if (m_operationMode == MOVE) {
931 setCursor(Qt::ClosedHandCursor);
932 } else if (m_operationMode == TRANSITIONSTART && event->modifiers() != Qt::ControlModifier) {
934 info.startPos = m_dragItem->startPos();
935 info.track = m_dragItem->track();
936 int transitiontrack = getPreviousVideoTrack(info.track);
937 ClipItem *transitionClip = NULL;
938 if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.startPos.frames(m_document->fps()), m_document->tracksCount() - transitiontrack);
939 if (transitionClip && transitionClip->endPos() < m_dragItem->endPos()) {
940 info.endPos = transitionClip->endPos();
942 GenTime transitionDuration(65, m_document->fps());
943 if (m_dragItem->cropDuration() < transitionDuration) info.endPos = m_dragItem->endPos();
944 else info.endPos = info.startPos + transitionDuration;
946 if (info.endPos == info.startPos) info.endPos = info.startPos + GenTime(65, m_document->fps());
947 // Check there is no other transition at that place
948 double startY = info.track * m_tracksHeight + 1 + m_tracksHeight / 2;
949 QRectF r(info.startPos.frames(m_document->fps()), startY, (info.endPos - info.startPos).frames(m_document->fps()), m_tracksHeight / 2);
950 QList<QGraphicsItem *> selection = m_scene->items(r);
951 bool transitionAccepted = true;
952 for (int i = 0; i < selection.count(); i++) {
953 if (selection.at(i)->type() == TRANSITIONWIDGET) {
954 Transition *tr = static_cast <Transition *>(selection.at(i));
955 if (tr->startPos() - info.startPos > GenTime(5, m_document->fps())) {
956 if (tr->startPos() < info.endPos) info.endPos = tr->startPos();
957 } else transitionAccepted = false;
960 if (transitionAccepted) slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
961 else emit displayMessage(i18n("Cannot add transition"), ErrorMessage);
962 } else if (m_operationMode == TRANSITIONEND && event->modifiers() != Qt::ControlModifier) {
964 info.endPos = GenTime(m_dragItem->endPos().frames(m_document->fps()), m_document->fps());
965 info.track = m_dragItem->track();
966 int transitiontrack = getPreviousVideoTrack(info.track);
967 ClipItem *transitionClip = NULL;
968 if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.endPos.frames(m_document->fps()), m_document->tracksCount() - transitiontrack);
969 if (transitionClip && transitionClip->startPos() > m_dragItem->startPos()) {
970 info.startPos = transitionClip->startPos();
972 GenTime transitionDuration(65, m_document->fps());
973 if (m_dragItem->cropDuration() < transitionDuration) info.startPos = m_dragItem->startPos();
974 else info.startPos = info.endPos - transitionDuration;
976 if (info.endPos == info.startPos) info.startPos = info.endPos - GenTime(65, m_document->fps());
977 QDomElement transition = MainWindow::transitions.getEffectByTag("luma", "dissolve").cloneNode().toElement();
978 EffectsList::setParameter(transition, "reverse", "1");
980 // Check there is no other transition at that place
981 double startY = info.track * m_tracksHeight + 1 + m_tracksHeight / 2;
982 QRectF r(info.startPos.frames(m_document->fps()), startY, (info.endPos - info.startPos).frames(m_document->fps()), m_tracksHeight / 2);
983 QList<QGraphicsItem *> selection = m_scene->items(r);
984 bool transitionAccepted = true;
985 for (int i = 0; i < selection.count(); i++) {
986 if (selection.at(i)->type() == TRANSITIONWIDGET) {
987 Transition *tr = static_cast <Transition *>(selection.at(i));
988 if (info.endPos - tr->endPos() > GenTime(5, m_document->fps())) {
989 if (tr->endPos() > info.startPos) info.startPos = tr->endPos();
990 } else transitionAccepted = false;
993 if (transitionAccepted) slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack, transition);
994 else emit displayMessage(i18n("Cannot add transition"), ErrorMessage);
996 } else if ((m_operationMode == RESIZESTART || m_operationMode == RESIZEEND) && m_selectionGroup) {
997 resetSelectionGroup(false);
998 m_dragItem->setSelected(true);
1001 m_blockRefresh = false;
1003 QGraphicsView::mousePressEvent(event);
1006 void CustomTrackView::rebuildGroup(AbstractGroupItem* group)
1009 QList <QGraphicsItem *> children = group->childItems();
1010 m_document->clipManager()->removeGroup(group);
1011 scene()->destroyItemGroup(group);
1012 for (int i = 0; i < children.count(); i++)
1013 children.at(i)->setSelected(true);
1014 groupSelectedItems(false, true);
1018 void CustomTrackView::resetSelectionGroup(bool selectItems)
1020 if (m_selectionGroup) {
1021 // delete selection group
1022 bool snap = KdenliveSettings::snaptopoints();
1023 KdenliveSettings::setSnaptopoints(false);
1025 QList<QGraphicsItem *> children = m_selectionGroup->childItems();
1026 scene()->destroyItemGroup(m_selectionGroup);
1027 for (int i = 0; i < children.count(); i++) {
1028 if (children.at(i)->parentItem() == 0 && (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)) {
1029 if (!static_cast <AbstractClipItem *>(children.at(i))->isItemLocked()) {
1030 children.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true);
1031 children.at(i)->setSelected(selectItems);
1033 } else if (children.at(i)->type() == GROUPWIDGET) {
1034 children.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true);
1035 children.at(i)->setSelected(selectItems);
1038 m_selectionGroup = NULL;
1039 KdenliveSettings::setSnaptopoints(snap);
1043 void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup)
1045 if (m_selectionGroup) {
1046 kDebug() << "///// ERROR, TRYING TO OVERRIDE EXISTING GROUP";
1049 QList<QGraphicsItem *> selection = m_scene->selectedItems();
1050 if (selection.isEmpty()) return;
1052 // Find top left position of selection
1053 for (int i = 0; i < selection.count(); i++) {
1054 if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
1055 rectUnion = rectUnion.united(selection.at(i)->sceneBoundingRect());
1056 } else if (selection.at(i)->parentItem()) {
1057 rectUnion = rectUnion.united(selection.at(i)->parentItem()->sceneBoundingRect());
1061 if (force || selection.count() > 1) {
1062 bool snap = KdenliveSettings::snaptopoints();
1063 KdenliveSettings::setSnaptopoints(false);
1064 if (createNewGroup) {
1065 AbstractGroupItem *newGroup = m_document->clipManager()->createGroup();
1066 newGroup->setPos(rectUnion.left(), rectUnion.top() - 1);
1067 QPointF diff = newGroup->pos();
1068 newGroup->translate(-diff.x(), -diff.y());
1069 //newGroup->translate((int) -rectUnion.left(), (int) -rectUnion.top() + 1);
1071 scene()->addItem(newGroup);
1073 // Check if we are trying to include a group in a group
1074 QList <AbstractGroupItem *> groups;
1075 for (int i = 0; i < selection.count(); i++) {
1076 if (selection.at(i)->type() == GROUPWIDGET && !groups.contains(static_cast<AbstractGroupItem *>(selection.at(i))))
1077 groups.append(static_cast<AbstractGroupItem *>(selection.at(i)));
1078 else if (selection.at(i)->parentItem() && !groups.contains(static_cast<AbstractGroupItem *>(selection.at(i)->parentItem())))
1079 groups.append(static_cast<AbstractGroupItem *>(selection.at(i)->parentItem()));
1081 if (!groups.isEmpty()) {
1082 // ungroup previous groups
1083 while (!groups.isEmpty()) {
1084 AbstractGroupItem *grp = groups.takeFirst();
1085 m_document->clipManager()->removeGroup(grp);
1086 scene()->destroyItemGroup(grp);
1088 selection = m_scene->selectedItems();
1091 for (int i = 0; i < selection.count(); i++) {
1092 if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) {
1093 newGroup->addToGroup(selection.at(i));
1094 selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
1097 KdenliveSettings::setSnaptopoints(snap);
1099 m_selectionGroup = new AbstractGroupItem(m_document->fps());
1100 m_selectionGroup->setPos(rectUnion.left(), rectUnion.top() - 1);
1101 QPointF diff = m_selectionGroup->pos();
1102 //m_selectionGroup->translate((int) - rectUnion.left(), (int) -rectUnion.top() + 1);
1103 m_selectionGroup->translate(- diff.x(), -diff.y());
1105 scene()->addItem(m_selectionGroup);
1106 for (int i = 0; i < selection.count(); i++) {
1107 if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
1108 m_selectionGroup->addToGroup(selection.at(i));
1109 selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
1112 KdenliveSettings::setSnaptopoints(snap);
1113 if (m_selectionGroup) {
1114 m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps());
1115 m_selectionGroupInfo.track = m_selectionGroup->track();
1118 } else resetSelectionGroup();
1121 void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event)
1123 if (m_dragItem && m_dragItem->hasKeyFrames()) {
1124 /*if (m_moveOpMode == KEYFRAME) {
1125 // user double clicked on a keyframe, open edit dialog
1126 //TODO:Â update for effects with several values per keyframe
1127 QDialog d(parentWidget());
1128 Ui::KeyFrameDialog_UI view;
1130 view.kfr_position->setText(m_document->timecode().getTimecode(GenTime(m_dragItem->selectedKeyFramePos(), m_document->fps()) - m_dragItem->cropStart()));
1131 view.kfr_value->setValue(m_dragItem->selectedKeyFrameValue());
1132 view.kfr_value->setFocus();
1133 if (d.exec() == QDialog::Accepted) {
1134 int pos = m_document->timecode().getFrameCount(view.kfr_position->text());
1135 m_dragItem->updateKeyFramePos(GenTime(pos, m_document->fps()) + m_dragItem->cropStart(), (double) view.kfr_value->value() * m_dragItem->keyFrameFactor());
1136 ClipItem *item = static_cast <ClipItem *>(m_dragItem);
1137 QString previous = item->keyframes(item->selectedEffectIndex());
1138 item->updateKeyframeEffect();
1139 QString next = item->keyframes(item->selectedEffectIndex());
1140 EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
1141 m_commandStack->push(command);
1142 updateEffect(m_document->tracksCount() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
1143 emit clipItemSelected(item, item->selectedEffectIndex());
1148 GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart();
1149 int val = m_dragItem->addKeyFrame(keyFramePos, mapToScene(event->pos()).toPoint().y());
1150 ClipItem * item = static_cast <ClipItem *>(m_dragItem);
1151 //QString previous = item->keyframes(item->selectedEffectIndex());
1152 QDomElement oldEffect = item->selectedEffect().cloneNode().toElement();
1153 item->insertKeyframe(item->getEffectAt(item->selectedEffectIndex()), keyFramePos.frames(m_document->fps()), val);
1154 //item->updateKeyframeEffect();
1155 //QString next = item->keyframes(item->selectedEffectIndex());
1156 QDomElement newEffect = item->selectedEffect().cloneNode().toElement();
1157 EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), oldEffect, newEffect, item->selectedEffectIndex(), false);
1158 //EditKeyFrameCommand *command = new EditKeyFrameCommand(this, m_dragItem->track(), m_dragItem->startPos(), item->selectedEffectIndex(), previous, next, false);
1159 m_commandStack->push(command);
1160 updateEffect(m_document->tracksCount() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
1161 emit clipItemSelected(item, item->selectedEffectIndex());
1163 } else if (m_dragItem && !m_dragItem->isItemLocked()) {
1166 QList<QGraphicsItem *> collisionList = items(event->pos());
1167 if (collisionList.count() == 1 && collisionList.at(0)->type() == GUIDEITEM) {
1168 Guide *editGuide = (Guide *) collisionList.at(0);
1169 if (editGuide) slotEditGuide(editGuide->info());
1174 void CustomTrackView::editItemDuration()
1176 AbstractClipItem *item;
1180 if (m_scene->selectedItems().count() == 1) {
1181 item = static_cast <AbstractClipItem *>(m_scene->selectedItems().at(0));
1183 if (m_scene->selectedItems().empty())
1184 emit displayMessage(i18n("Cannot find clip to edit"), ErrorMessage);
1186 emit displayMessage(i18n("Cannot edit the duration of multiple items"), ErrorMessage);
1192 emit displayMessage(i18n("Cannot find clip to edit"), ErrorMessage);
1196 if (item->type() == GROUPWIDGET || (item->parentItem() && item->parentItem()->type() == GROUPWIDGET)) {
1197 emit displayMessage(i18n("Cannot edit an item in a group"), ErrorMessage);
1201 if (!item->isItemLocked()) {
1204 if (item->type() == TRANSITIONWIDGET)
1205 getTransitionAvailableSpace(item, minimum, maximum);
1207 getClipAvailableSpace(item, minimum, maximum);
1208 //kDebug()<<"// GOT MOVE POS: "<<minimum.frames(25)<<" - "<<maximum.frames(25);
1209 ClipDurationDialog d(item, m_document->timecode(), minimum, maximum, this);
1210 if (d.exec() == QDialog::Accepted) {
1211 ItemInfo clipInfo = item->info();
1212 ItemInfo startInfo = clipInfo;
1213 if (item->type() == TRANSITIONWIDGET) {
1214 // move & resize transition
1215 clipInfo.startPos = d.startPos();
1216 clipInfo.endPos = clipInfo.startPos + d.duration();
1217 clipInfo.track = item->track();
1218 MoveTransitionCommand *command = new MoveTransitionCommand(this, startInfo, clipInfo, true);
1219 m_commandStack->push(command);
1221 // move and resize clip
1222 QUndoCommand *moveCommand = new QUndoCommand();
1223 moveCommand->setText(i18n("Edit clip"));
1224 if (d.duration() < item->cropDuration() || d.cropStart() != clipInfo.cropStart) {
1225 // duration was reduced, so process it first
1226 clipInfo.endPos = clipInfo.startPos + d.duration();
1227 clipInfo.cropStart = d.cropStart();
1228 new ResizeClipCommand(this, startInfo, clipInfo, true, false, moveCommand);
1230 if (d.startPos() != clipInfo.startPos) {
1231 startInfo = clipInfo;
1232 clipInfo.startPos = d.startPos();
1233 clipInfo.endPos = item->endPos() + (clipInfo.startPos - startInfo.startPos);
1234 new MoveClipCommand(this, startInfo, clipInfo, true, moveCommand);
1236 if (d.duration() > item->cropDuration()) {
1237 // duration was increased, so process it after move
1238 startInfo = clipInfo;
1239 clipInfo.endPos = clipInfo.startPos + d.duration();
1240 clipInfo.cropStart = d.cropStart();
1241 new ResizeClipCommand(this, startInfo, clipInfo, true, false, moveCommand);
1243 m_commandStack->push(moveCommand);
1247 emit displayMessage(i18n("Item is locked"), ErrorMessage);
1251 void CustomTrackView::editKeyFrame(const GenTime /*pos*/, const int /*track*/, const int /*index*/, const QString /*keyframes*/)
1253 /*ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), track);
1255 clip->setKeyframes(index, keyframes);
1256 updateEffect(m_document->tracksCount() - clip->track(), clip->startPos(), clip->effectAt(index), index, false);
1257 } else emit displayMessage(i18n("Cannot find clip with keyframe"), ErrorMessage);*/
1261 void CustomTrackView::displayContextMenu(QPoint pos, AbstractClipItem *clip, AbstractGroupItem *group)
1263 m_deleteGuide->setEnabled(m_dragGuide != NULL);
1264 m_editGuide->setEnabled(m_dragGuide != NULL);
1265 m_markerMenu->clear();
1266 m_markerMenu->setEnabled(false);
1268 m_timelineContextMenu->popup(pos);
1269 } else if (group != NULL) {
1270 m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
1271 m_ungroupAction->setEnabled(true);
1272 updateClipTypeActions(NULL);
1273 m_timelineContextClipMenu->popup(pos);
1275 m_ungroupAction->setEnabled(false);
1276 if (clip->type() == AVWIDGET) {
1277 ClipItem *item = static_cast <ClipItem*>(clip);
1278 //build go to marker menu
1279 if (item->baseClip()) {
1280 QList <CommentedTime> markers = item->baseClip()->commentedSnapMarkers();
1281 int offset = item->startPos().frames(m_document->fps());
1282 if (!markers.isEmpty()) {
1283 for (int i = 0; i < markers.count(); i++) {
1284 int pos = (int) markers.at(i).time().frames(m_document->timecode().fps());
1285 QString position = m_document->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
1286 QAction *go = m_markerMenu->addAction(position);
1287 go->setData(pos + offset);
1290 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
1292 updateClipTypeActions(item);
1293 m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
1294 m_timelineContextClipMenu->popup(pos);
1295 } else if (clip->type() == TRANSITIONWIDGET) {
1296 m_timelineContextTransitionMenu->popup(pos);
1301 void CustomTrackView::activateMonitor()
1303 emit activateDocumentMonitor();
1306 void CustomTrackView::insertClipCut(DocClipBase *clip, int in, int out)
1308 resetSelectionGroup();
1310 info.startPos = GenTime();
1311 info.cropStart = GenTime(in, m_document->fps());
1312 info.endPos = GenTime(out - in, m_document->fps());
1313 info.cropDuration = info.endPos - info.startPos;
1316 // Check if clip can be inserted at that position
1317 ItemInfo pasteInfo = info;
1318 pasteInfo.startPos = GenTime(m_cursorPos, m_document->fps());
1319 pasteInfo.endPos = pasteInfo.startPos + info.endPos;
1320 pasteInfo.track = selectedTrack();
1321 if (!canBePastedTo(pasteInfo, AVWIDGET)) {
1322 emit displayMessage(i18n("Cannot insert clip in timeline"), ErrorMessage);
1326 AddTimelineClipCommand *command = new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), pasteInfo, EffectsList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, true, false);
1327 m_commandStack->push(command);
1329 selectClip(true, false);
1330 // Automatic audio split
1331 if (KdenliveSettings::splitaudio())
1335 bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos)
1337 if (data->hasFormat("kdenlive/clip")) {
1339 m_scene->clearSelection();
1340 resetSelectionGroup(false);
1341 QStringList list = QString(data->data("kdenlive/clip")).split(';');
1342 DocClipBase *clip = m_document->getBaseClip(list.at(0));
1344 kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << list.at(0);
1347 QPointF framePos = mapToScene(pos);
1349 info.startPos = GenTime();
1350 info.cropStart = GenTime(list.at(1).toInt(), m_document->fps());
1351 info.endPos = GenTime(list.at(2).toInt() - list.at(1).toInt(), m_document->fps());
1352 info.cropDuration = info.endPos - info.startPos;
1355 // Check if clip can be inserted at that position
1356 ItemInfo pasteInfo = info;
1357 pasteInfo.startPos = GenTime((int)(framePos.x() + 0.5), m_document->fps());
1358 pasteInfo.endPos = pasteInfo.startPos + info.endPos;
1359 pasteInfo.track = (int)(framePos.y() / m_tracksHeight);
1360 framePos.setX((int)(framePos.x() + 0.5));
1361 framePos.setY(pasteInfo.track * m_tracksHeight);
1362 if (!canBePastedTo(pasteInfo, AVWIDGET)) {
1365 m_selectionGroup = new AbstractGroupItem(m_document->fps());
1366 ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1);
1367 m_selectionGroup->addToGroup(item);
1368 item->setFlag(QGraphicsItem::ItemIsMovable, false);
1370 QList <GenTime> offsetList;
1371 offsetList.append(info.endPos);
1372 updateSnapPoints(NULL, offsetList);
1373 m_selectionGroup->setPos(framePos);
1374 scene()->addItem(m_selectionGroup);
1375 m_selectionGroup->setSelected(true);
1377 } else if (data->hasFormat("kdenlive/producerslist")) {
1379 QStringList ids = QString(data->data("kdenlive/producerslist")).split(';');
1380 m_scene->clearSelection();
1381 resetSelectionGroup(false);
1383 QList <GenTime> offsetList;
1384 QList <ItemInfo> infoList;
1385 QPointF framePos = mapToScene(pos);
1386 GenTime start = GenTime((int)(framePos.x() + 0.5), m_document->fps());
1387 int track = (int)(framePos.y() / m_tracksHeight);
1388 framePos.setX((int)(framePos.x() + 0.5));
1389 framePos.setY(track * m_tracksHeight);
1391 // Check if clips can be inserted at that position
1392 for (int i = 0; i < ids.size(); ++i) {
1393 DocClipBase *clip = m_document->getBaseClip(ids.at(i));
1395 kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << ids.at(i);
1399 info.startPos = start;
1400 info.cropDuration = clip->duration();
1401 info.endPos = info.startPos + info.cropDuration;
1403 infoList.append(info);
1404 start += clip->duration();
1406 if (!canBePastedTo(infoList, AVWIDGET)) {
1409 m_selectionGroup = new AbstractGroupItem(m_document->fps());
1411 for (int i = 0; i < ids.size(); ++i) {
1412 DocClipBase *clip = m_document->getBaseClip(ids.at(i));
1414 info.startPos = start;
1415 info.cropDuration = clip->duration();
1416 info.endPos = info.startPos + info.cropDuration;
1418 start += info.cropDuration;
1419 offsetList.append(start);
1420 ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, false);
1421 item->setFlag(QGraphicsItem::ItemIsMovable, false);
1422 m_selectionGroup->addToGroup(item);
1423 if (!clip->isPlaceHolder()) m_waitingThumbs.append(item);
1426 updateSnapPoints(NULL, offsetList);
1427 m_selectionGroup->setPos(framePos);
1428 scene()->addItem(m_selectionGroup);
1429 //m_selectionGroup->setZValue(10);
1430 m_thumbsTimer.start();
1434 // the drag is not a clip (may be effect, ...)
1442 void CustomTrackView::dragEnterEvent(QDragEnterEvent * event)
1444 if (insertDropClips(event->mimeData(), event->pos())) {
1445 event->acceptProposedAction();
1446 } else QGraphicsView::dragEnterEvent(event);
1449 bool CustomTrackView::itemCollision(AbstractClipItem *item, ItemInfo newPos)
1451 QRectF shape = QRectF(newPos.startPos.frames(m_document->fps()), newPos.track * m_tracksHeight + 1, (newPos.endPos - newPos.startPos).frames(m_document->fps()) - 0.02, m_tracksHeight - 1);
1452 QList<QGraphicsItem*> collindingItems = scene()->items(shape, Qt::IntersectsItemShape);
1453 collindingItems.removeAll(item);
1454 if (collindingItems.isEmpty()) return false;
1456 for (int i = 0; i < collindingItems.count(); i++) {
1457 QGraphicsItem *collision = collindingItems.at(i);
1458 if (collision->type() == item->type()) {
1460 kDebug() << "// COLLISIION DETECTED";
1468 void CustomTrackView::slotRefreshEffects(ClipItem *clip)
1470 int track = m_document->tracksCount() - clip->track();
1471 GenTime pos = clip->startPos();
1472 if (!m_document->renderer()->mltRemoveEffect(track, pos, "-1", false, false)) {
1473 emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
1476 bool success = true;
1477 for (int i = 0; i < clip->effectsCount(); i++) {
1478 if (!m_document->renderer()->mltAddEffect(track, pos, clip->getEffectArgs(clip->effectAt(i)), false)) success = false;
1480 if (!success) emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
1481 m_document->renderer()->doRefresh();
1484 void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect)
1486 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
1488 // Special case: speed effect
1489 if (effect.attribute("id") == "speed") {
1490 if (clip->clipType() != VIDEO && clip->clipType() != AV && clip->clipType() != PLAYLIST) {
1491 emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
1494 double speed = EffectsList::parameter(effect, "speed").toDouble() / 100.0;
1495 int strobe = EffectsList::parameter(effect, "strobe").toInt();
1496 if (strobe == 0) strobe = 1;
1497 doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), speed, 1.0, strobe, clip->baseClip()->getId());
1498 EffectsParameterList params = clip->addEffect(effect);
1499 m_document->renderer()->mltAddEffect(track, pos, params);
1500 if (clip->isSelected()) emit clipItemSelected(clip);
1503 EffectsParameterList params = clip->addEffect(effect);
1504 if (!m_document->renderer()->mltAddEffect(track, pos, params))
1505 emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
1506 if (clip->isSelected()) emit clipItemSelected(clip);
1507 } else emit displayMessage(i18n("Cannot find clip to add effect"), ErrorMessage);
1510 void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect)
1512 QString index = effect.attribute("kdenlive_ix");
1513 // Special case: speed effect
1514 if (effect.attribute("id") == "speed") {
1515 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
1517 doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), 1.0, clip->speed(), 1, clip->baseClip()->getId());
1518 clip->deleteEffect(index);
1519 emit clipItemSelected(clip);
1520 m_document->renderer()->mltRemoveEffect(track, pos, index, true);
1524 if (!m_document->renderer()->mltRemoveEffect(track, pos, index, true)) {
1525 kDebug() << "// ERROR REMOV EFFECT: " << index << ", DISABLE: " << effect.attribute("disable");
1526 emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
1529 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
1531 clip->deleteEffect(index);
1532 emit clipItemSelected(clip);
1536 void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem *group)
1538 QList<QGraphicsItem *> itemList = group->childItems();
1539 QUndoCommand *effectCommand = new QUndoCommand();
1541 QDomNode namenode = effect.elementsByTagName("name").item(0);
1542 if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data());
1543 else effectName = i18n("effect");
1544 effectCommand->setText(i18n("Add %1", effectName));
1546 for (int i = 0; i < itemList.count(); i++) {
1547 if (itemList.at(i)->type() == AVWIDGET) {
1548 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1549 if (effect.attribute("type") == "audio") {
1550 // Don't add audio effects on video clips
1551 if (item->isVideoOnly() || (item->clipType() != AUDIO && item->clipType() != AV && item->clipType() != PLAYLIST)) continue;
1552 } else if (effect.hasAttribute("type") == false) {
1553 // Don't add video effect on audio clips
1554 if (item->isAudioOnly() || item->clipType() == AUDIO) continue;
1557 if (effect.attribute("unique", "0") != "0" && item->hasEffect(effect.attribute("tag"), effect.attribute("id")) != -1) {
1558 emit displayMessage(i18n("Effect already present in clip"), ErrorMessage);
1561 if (item->isItemLocked()) {
1564 item->initEffect(effect);
1565 if (effect.attribute("tag") == "ladspa") {
1566 QString ladpsaFile = m_document->getLadspaFile();
1567 initEffects::ladspaEffectFile(ladpsaFile, effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
1568 effect.setAttribute("src", ladpsaFile);
1570 new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), effect, true, effectCommand);
1575 m_commandStack->push(effectCommand);
1576 setDocumentModified();
1577 } else delete effectCommand;
1580 void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
1582 QList<QGraphicsItem *> itemList;
1583 QUndoCommand *effectCommand = new QUndoCommand();
1585 QDomNode namenode = effect.elementsByTagName("name").item(0);
1586 if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data());
1587 else effectName = i18n("effect");
1588 effectCommand->setText(i18n("Add %1", effectName));
1590 if (track == -1) itemList = scene()->selectedItems();
1591 if (itemList.isEmpty()) {
1592 ClipItem *clip = getClipItemAt((int) pos.frames(m_document->fps()), track);
1593 if (clip) itemList.append(clip);
1594 else emit displayMessage(i18n("Select a clip if you want to apply an effect"), ErrorMessage);
1598 for (int i = 0; i < itemList.count(); i++) {
1599 if (itemList.at(i)->type() == GROUPWIDGET) {
1600 QList<QGraphicsItem *> subitems = itemList.at(i)->childItems();
1601 for (int j = 0; j < subitems.count(); j++) {
1602 if (!itemList.contains(subitems.at(j))) itemList.append(subitems.at(j));
1607 for (int i = 0; i < itemList.count(); i++) {
1608 if (itemList.at(i)->type() == AVWIDGET) {
1609 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1610 if (effect.attribute("type") == "audio") {
1611 // Don't add audio effects on video clips
1612 if (item->isVideoOnly() || (item->clipType() != AUDIO && item->clipType() != AV && item->clipType() != PLAYLIST)) {
1613 emit displayMessage(i18n("Cannot add an audio effect to this clip"), ErrorMessage);
1616 } else if (effect.hasAttribute("type") == false) {
1617 // Don't add video effect on audio clips
1618 if (item->isAudioOnly() || item->clipType() == AUDIO) {
1619 emit displayMessage(i18n("Cannot add a video effect to this clip"), ErrorMessage);
1623 if (item->hasEffect(effect.attribute("tag"), effect.attribute("id")) != -1 && effect.attribute("unique", "0") != "0") {
1624 emit displayMessage(i18n("Effect already present in clip"), ErrorMessage);
1627 if (item->isItemLocked()) {
1630 if (effect.attribute("id") == "freeze" && m_cursorPos > item->startPos().frames(m_document->fps()) && m_cursorPos < item->endPos().frames(m_document->fps())) {
1631 item->initEffect(effect, m_cursorPos - item->startPos().frames(m_document->fps()));
1632 } else item->initEffect(effect);
1633 if (effect.attribute("tag") == "ladspa") {
1634 QString ladpsaFile = m_document->getLadspaFile();
1635 initEffects::ladspaEffectFile(ladpsaFile, effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
1636 effect.setAttribute("src", ladpsaFile);
1638 new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), effect, true, effectCommand);
1641 if (effectCommand->childCount() > 0) {
1642 m_commandStack->push(effectCommand);
1643 setDocumentModified();
1644 } else delete effectCommand;
1647 void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect, bool affectGroup)
1649 if (affectGroup && clip->parentItem() && clip->parentItem() == m_selectionGroup) {
1650 //clip is in a group, also remove the effect in other clips of the group
1651 QList<QGraphicsItem *> items = m_selectionGroup->childItems();
1652 QUndoCommand *delCommand = new QUndoCommand();
1654 QDomNode namenode = effect.elementsByTagName("name").item(0);
1655 if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data());
1656 else effectName = i18n("effect");
1657 delCommand->setText(i18n("Delete %1", effectName));
1660 for (int i = 0; i < items.count(); i++) {
1661 if (items.at(i)->type() == GROUPWIDGET) {
1662 QList<QGraphicsItem *> subitems = items.at(i)->childItems();
1663 for (int j = 0; j < subitems.count(); j++) {
1664 if (!items.contains(subitems.at(j))) items.append(subitems.at(j));
1669 for (int i = 0; i < items.count(); i++) {
1670 if (items.at(i)->type() == AVWIDGET) {
1671 ClipItem *item = static_cast <ClipItem *>(items.at(i));
1672 int ix = item->hasEffect(effect.attribute("tag"), effect.attribute("id"));
1674 QDomElement eff = item->effectAt(ix);
1675 new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), eff, false, delCommand);
1679 if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
1680 else delete delCommand;
1683 AddEffectCommand *command = new AddEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effect, false);
1684 m_commandStack->push(command);
1685 setDocumentModified();
1688 void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedEffect, int ix, bool triggeredByUser)
1690 if (insertedEffect.isNull()) {
1691 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
1694 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
1695 QDomElement effect = insertedEffect.cloneNode().toElement();
1697 // Special case: speed effect
1698 if (effect.attribute("id") == "speed") {
1699 if (effect.attribute("disable") == "1") doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), 1.0, clip->speed(), 1, clip->baseClip()->getId());
1701 double speed = EffectsList::parameter(effect, "speed").toDouble() / 100.0;
1702 int strobe = EffectsList::parameter(effect, "strobe").toInt();
1703 if (strobe == 0) strobe = 1;
1704 doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), speed, clip->speed(), strobe, clip->baseClip()->getId());
1706 clip->setEffectAt(ix, effect);
1707 if (ix == clip->selectedEffectIndex()) {
1708 clip->setSelectedEffect(ix);
1709 if (!triggeredByUser) emit clipItemSelected(clip, ix);
1714 EffectsParameterList effectParams = clip->getEffectArgs(effect);
1715 if (effect.attribute("tag") == "ladspa") {
1716 // Update the ladspa affect file
1717 initEffects::ladspaEffectFile(effect.attribute("src"), effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
1719 // check if we are trying to reset a keyframe effect
1720 if (effectParams.hasParam("keyframes") && effectParams.paramValue("keyframes").isEmpty()) {
1721 clip->initEffect(effect);
1722 effectParams = clip->getEffectArgs(effect);
1724 if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - clip->track(), clip->startPos(), effectParams))
1725 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
1727 clip->setEffectAt(ix, effect);
1728 if (ix == clip->selectedEffectIndex()) {
1729 clip->setSelectedEffect(ix);
1730 if (!triggeredByUser) emit clipItemSelected(clip, ix);
1732 if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
1733 // A fade effect was modified, update the clip
1734 if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
1735 int pos = effectParams.paramValue("out").toInt() - effectParams.paramValue("in").toInt();
1736 clip->setFadeIn(pos);
1738 if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
1739 int pos = effectParams.paramValue("out").toInt() - effectParams.paramValue("in").toInt();
1740 clip->setFadeOut(pos);
1744 setDocumentModified();
1747 void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos)
1749 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
1750 if (clip && !clip->effectAt(newPos - 1).isNull() && !clip->effectAt(oldPos - 1).isNull()) {
1751 QDomElement act = clip->effectAt(newPos - 1);
1752 QDomElement before = clip->effectAt(oldPos - 1);
1753 clip->setEffectAt(oldPos - 1, act);
1754 clip->setEffectAt(newPos - 1, before);
1755 // special case: speed effect, which is a pseudo-effect, not appearing in MLT's effects
1756 if (act.attribute("id") == "speed") {
1757 m_document->renderer()->mltUpdateEffectPosition(track, pos, oldPos, newPos);
1758 } else if (before.attribute("id") == "speed") {
1759 m_document->renderer()->mltUpdateEffectPosition(track, pos, newPos, oldPos);
1760 } else m_document->renderer()->mltMoveEffect(track, pos, oldPos, newPos);
1761 emit clipItemSelected(clip, newPos - 1);
1762 setDocumentModified();
1763 } else emit displayMessage(i18n("Cannot move effect"), ErrorMessage);
1766 void CustomTrackView::slotChangeEffectState(ClipItem *clip, int effectPos, bool disable)
1768 QDomElement effect = clip->effectAt(effectPos);
1769 QDomElement oldEffect = effect.cloneNode().toElement();
1771 effect.setAttribute("disable", (int) disable);
1772 EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldEffect, effect, effectPos, true);
1773 m_commandStack->push(command);
1774 setDocumentModified();;
1777 void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos)
1779 MoveEffectCommand *command = new MoveEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), currentPos, newPos);
1780 m_commandStack->push(command);
1781 setDocumentModified();
1784 void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect, int ix)
1786 EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldeffect, effect, ix, true);
1787 m_commandStack->push(command);
1790 void CustomTrackView::slotUpdateClipRegion(ClipItem *clip, int ix, QString region)
1792 QDomElement effect = clip->getEffectAt(ix);
1793 QDomElement oldeffect = effect.cloneNode().toElement();
1794 effect.setAttribute("region", region);
1795 EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldeffect, effect, ix, true);
1796 m_commandStack->push(command);
1799 ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, bool execute)
1803 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
1804 if (!item || cutTime >= item->endPos() || cutTime <= item->startPos()) {
1805 emit displayMessage(i18n("Cannot find clip to cut"), ErrorMessage);
1806 if (item) 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);
1807 else kDebug() << "/// ERROR NO CLIP at: " << info.startPos.frames(m_document->fps()) << ", track: " << info.track;
1808 m_blockRefresh = false;
1811 if (item->parentItem()) {
1812 // Item is part of a group, reset group
1813 resetSelectionGroup();
1815 kDebug() << "///////// CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25);
1817 if (execute) m_document->renderer()->mltCutClip(m_document->tracksCount() - info.track, cutTime);
1818 int cutPos = (int) cutTime.frames(m_document->fps());
1820 newPos.startPos = cutTime;
1821 newPos.endPos = info.endPos;
1822 newPos.cropStart = item->info().cropStart + (cutTime - info.startPos);
1823 newPos.track = info.track;
1824 newPos.cropDuration = newPos.endPos - newPos.startPos;
1826 bool snap = KdenliveSettings::snaptopoints();
1827 KdenliveSettings::setSnaptopoints(false);
1828 ClipItem *dup = item->clone(newPos);
1829 // remove unwanted effects (fade in) from 2nd part of cutted clip
1830 int ix = dup->hasEffect(QString(), "fadein");
1832 QDomElement oldeffect = item->effectAt(ix);
1833 dup->deleteEffect(oldeffect.attribute("kdenlive_ix"));
1835 ix = dup->hasEffect(QString(), "fade_from_black");
1837 QDomElement oldeffect = item->effectAt(ix);
1838 dup->deleteEffect(oldeffect.attribute("kdenlive_ix"));
1840 item->resizeEnd(cutPos);
1841 scene()->addItem(dup);
1842 if (item->checkKeyFrames()) slotRefreshEffects(item);
1843 if (dup->checkKeyFrames()) slotRefreshEffects(dup);
1844 item->baseClip()->addReference();
1845 m_document->updateClip(item->baseClip()->getId());
1846 setDocumentModified();
1847 KdenliveSettings::setSnaptopoints(snap);
1849 //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);
1853 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
1854 ClipItem *dup = getClipItemAt((int) cutTime.frames(m_document->fps()), info.track);
1856 if (!item || !dup || item == dup) {
1857 emit displayMessage(i18n("Cannot find clip to uncut"), ErrorMessage);
1858 m_blockRefresh = false;
1861 if (m_document->renderer()->mltRemoveClip(m_document->tracksCount() - info.track, cutTime) == false) {
1862 emit displayMessage(i18n("Error removing clip at %1 on track %2", m_document->timecode().getTimecodeFromFrames(cutTime.frames(m_document->fps())), info.track), ErrorMessage);
1866 /*kDebug() << "// UNCUTTING CLIPS: ITEM 1 (" << item->startPos().frames(25) << "x" << item->endPos().frames(25) << ")";
1867 kDebug() << "// UNCUTTING CLIPS: ITEM 2 (" << dup->startPos().frames(25) << "x" << dup->endPos().frames(25) << ")";
1868 kDebug() << "// UNCUTTING CLIPS, INFO (" << info.startPos.frames(25) << "x" << info.endPos.frames(25) << ") , CUT: " << cutTime.frames(25);;*/
1869 //deleteClip(dup->info());
1871 bool snap = KdenliveSettings::snaptopoints();
1872 KdenliveSettings::setSnaptopoints(false);
1874 if (dup->isSelected()) emit clipItemSelected(NULL);
1875 dup->baseClip()->removeReference();
1876 m_document->updateClip(dup->baseClip()->getId());
1877 scene()->removeItem(dup);
1880 ItemInfo clipinfo = item->info();
1881 clipinfo.track = m_document->tracksCount() - clipinfo.track;
1882 bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, info.endPos - info.startPos);
1884 item->resizeEnd((int) info.endPos.frames(m_document->fps()));
1885 setDocumentModified();
1887 emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
1888 KdenliveSettings::setSnaptopoints(snap);
1892 //QTimer::singleShot(3000, this, SLOT(slotEnableRefresh()));
1895 void CustomTrackView::slotEnableRefresh()
1897 m_blockRefresh = false;
1900 void CustomTrackView::slotAddTransitionToSelectedClips(QDomElement transition)
1902 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1903 if (itemList.count() == 1) {
1904 if (itemList.at(0)->type() == AVWIDGET) {
1905 ClipItem *item = (ClipItem *) itemList.at(0);
1907 info.track = item->track();
1908 ClipItem *transitionClip = NULL;
1909 const int transitiontrack = getPreviousVideoTrack(info.track);
1910 GenTime pos = GenTime((int)(mapToScene(m_menuPosition).x()), m_document->fps());
1911 if (pos < item->startPos() + item->cropDuration() / 2) {
1912 // add transition to clip start
1913 info.startPos = item->startPos();
1914 if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.startPos.frames(m_document->fps()), m_document->tracksCount() - transitiontrack);
1915 if (transitionClip && transitionClip->endPos() < item->endPos()) {
1916 info.endPos = transitionClip->endPos();
1917 } else info.endPos = info.startPos + GenTime(65, m_document->fps());
1918 // Check there is no other transition at that place
1919 double startY = info.track * m_tracksHeight + 1 + m_tracksHeight / 2;
1920 QRectF r(info.startPos.frames(m_document->fps()), startY, (info.endPos - info.startPos).frames(m_document->fps()), m_tracksHeight / 2);
1921 QList<QGraphicsItem *> selection = m_scene->items(r);
1922 bool transitionAccepted = true;
1923 for (int i = 0; i < selection.count(); i++) {
1924 if (selection.at(i)->type() == TRANSITIONWIDGET) {
1925 Transition *tr = static_cast <Transition *>(selection.at(i));
1926 if (tr->startPos() - info.startPos > GenTime(5, m_document->fps())) {
1927 if (tr->startPos() < info.endPos) info.endPos = tr->startPos();
1928 } else transitionAccepted = false;
1931 if (transitionAccepted) slotAddTransition(item, info, transitiontrack, transition);
1932 else emit displayMessage(i18n("Cannot add transition"), ErrorMessage);
1935 // add transition to clip end
1936 info.endPos = item->endPos();
1937 if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.endPos.frames(m_document->fps()), m_document->tracksCount() - transitiontrack);
1938 if (transitionClip && transitionClip->startPos() > item->startPos()) {
1939 info.startPos = transitionClip->startPos();
1940 } else info.startPos = info.endPos - GenTime(65, m_document->fps());
1941 if (transition.attribute("tag") == "luma") EffectsList::setParameter(transition, "reverse", "1");
1942 else if (transition.attribute("id") == "slide") EffectsList::setParameter(transition, "invert", "1");
1944 // Check there is no other transition at that place
1945 double startY = info.track * m_tracksHeight + 1 + m_tracksHeight / 2;
1946 QRectF r(info.startPos.frames(m_document->fps()), startY, (info.endPos - info.startPos).frames(m_document->fps()), m_tracksHeight / 2);
1947 QList<QGraphicsItem *> selection = m_scene->items(r);
1948 bool transitionAccepted = true;
1949 for (int i = 0; i < selection.count(); i++) {
1950 if (selection.at(i)->type() == TRANSITIONWIDGET) {
1951 Transition *tr = static_cast <Transition *>(selection.at(i));
1952 if (info.endPos - tr->endPos() > GenTime(5, m_document->fps())) {
1953 if (tr->endPos() > info.startPos) info.startPos = tr->endPos();
1954 } else transitionAccepted = false;
1957 if (transitionAccepted) slotAddTransition(item, info, transitiontrack, transition);
1958 else emit displayMessage(i18n("Cannot add transition"), ErrorMessage);
1961 } else for (int i = 0; i < itemList.count(); i++) {
1962 if (itemList.at(i)->type() == AVWIDGET) {
1963 ClipItem *item = (ClipItem *) itemList.at(i);
1965 info.startPos = item->startPos();
1966 info.endPos = info.startPos + GenTime(65, m_document->fps());
1967 info.track = item->track();
1969 // Check there is no other transition at that place
1970 double startY = info.track * m_tracksHeight + 1 + m_tracksHeight / 2;
1971 QRectF r(info.startPos.frames(m_document->fps()), startY, (info.endPos - info.startPos).frames(m_document->fps()), m_tracksHeight / 2);
1972 QList<QGraphicsItem *> selection = m_scene->items(r);
1973 bool transitionAccepted = true;
1974 for (int i = 0; i < selection.count(); i++) {
1975 if (selection.at(i)->type() == TRANSITIONWIDGET) {
1976 Transition *tr = static_cast <Transition *>(selection.at(i));
1977 if (tr->startPos() - info.startPos > GenTime(5, m_document->fps())) {
1978 if (tr->startPos() < info.endPos) info.endPos = tr->startPos();
1979 } else transitionAccepted = false;
1982 int transitiontrack = getPreviousVideoTrack(info.track);
1983 if (transitionAccepted) slotAddTransition(item, info, transitiontrack, transition);
1984 else emit displayMessage(i18n("Cannot add transition"), ErrorMessage);
1989 void CustomTrackView::slotAddTransition(ClipItem* /*clip*/, ItemInfo transitionInfo, int endTrack, QDomElement transition)
1991 if (transitionInfo.startPos >= transitionInfo.endPos) {
1992 emit displayMessage(i18n("Invalid transition"), ErrorMessage);
1995 AddTransitionCommand* command = new AddTransitionCommand(this, transitionInfo, endTrack, transition, false, true);
1996 m_commandStack->push(command);
1997 setDocumentModified();
2000 void CustomTrackView::addTransition(ItemInfo transitionInfo, int endTrack, QDomElement params, bool refresh)
2002 Transition *tr = new Transition(transitionInfo, endTrack, m_document->fps(), params, true);
2003 //kDebug() << "---- ADDING transition " << params.attribute("value");
2004 if (m_document->renderer()->mltAddTransition(tr->transitionTag(), endTrack, m_document->tracksCount() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, tr->toXML(), refresh)) {
2005 scene()->addItem(tr);
2006 setDocumentModified();
2008 emit displayMessage(i18n("Cannot add transition"), ErrorMessage);
2013 void CustomTrackView::deleteTransition(ItemInfo transitionInfo, int endTrack, QDomElement /*params*/, bool refresh)
2015 Transition *item = getTransitionItemAt(transitionInfo.startPos, transitionInfo.track);
2017 emit displayMessage(i18n("Select clip to delete"), ErrorMessage);
2020 m_document->renderer()->mltDeleteTransition(item->transitionTag(), endTrack, m_document->tracksCount() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, item->toXML(), refresh);
2021 if (m_dragItem == item) m_dragItem = NULL;
2023 #if QT_VERSION >= 0x040600
2024 // animate item deletion
2025 item->closeAnimation();
2029 emit transitionItemSelected(NULL);
2030 setDocumentModified();
2033 void CustomTrackView::slotTransitionUpdated(Transition *tr, QDomElement old)
2035 //kDebug() << "TRANS UPDATE, TRACKS: " << old.attribute("transition_btrack") << ", NEW: " << tr->toXML().attribute("transition_btrack");
2036 QDomElement xml = tr->toXML();
2037 if (old.isNull() || xml.isNull()) {
2038 emit displayMessage(i18n("Cannot update transition"), ErrorMessage);
2041 EditTransitionCommand *command = new EditTransitionCommand(this, tr->track(), tr->startPos(), old, xml, false);
2042 m_commandStack->push(command);
2043 setDocumentModified();
2046 void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTransition, QDomElement transition, bool updateTransitionWidget)
2048 Transition *item = getTransitionItemAt(pos, track);
2050 kWarning() << "Unable to find transition at pos :" << pos.frames(m_document->fps()) << ", ON track: " << track;
2054 if (oldTransition.attribute("transition_atrack") != transition.attribute("transition_atrack") || oldTransition.attribute("transition_btrack") != transition.attribute("transition_btrack")) force = true;
2055 m_document->renderer()->mltUpdateTransition(oldTransition.attribute("tag"), transition.attribute("tag"), transition.attribute("transition_btrack").toInt(), m_document->tracksCount() - transition.attribute("transition_atrack").toInt(), item->startPos(), item->endPos(), transition, force);
2056 //kDebug() << "ORIGINAL TRACK: "<< oldTransition.attribute("transition_btrack") << ", NEW TRACK: "<<transition.attribute("transition_btrack");
2057 item->setTransitionParameters(transition);
2058 if (updateTransitionWidget) {
2059 ItemInfo info = item->info();
2061 ClipItem *transitionClip = getClipItemAt(info.startPos, info.track);
2062 if (transitionClip && transitionClip->baseClip()) {
2063 QString size = transitionClip->baseClip()->getProperty("frame_size");
2064 double factor = transitionClip->baseClip()->getProperty("aspect_ratio").toDouble();
2065 if (factor == 0) factor = 1.0;
2066 p.setX((int)(size.section('x', 0, 0).toInt() * factor + 0.5));
2067 p.setY(size.section('x', 1, 1).toInt());
2069 emit transitionItemSelected(item, getPreviousVideoTrack(info.track), p, true);
2071 setDocumentModified();
2074 void CustomTrackView::dragMoveEvent(QDragMoveEvent * event)
2077 const QPointF pos = mapToScene(event->pos());
2078 if (m_selectionGroup) {
2079 m_selectionGroup->setPos(pos);
2080 emit mousePosition((int)(m_selectionGroup->scenePos().x() + 0.5));
2081 event->acceptProposedAction();
2083 // Drag enter was not possible, try again at mouse position
2084 insertDropClips(event->mimeData(), event->pos());
2088 QGraphicsView::dragMoveEvent(event);
2092 void CustomTrackView::dragLeaveEvent(QDragLeaveEvent * event)
2094 if (m_selectionGroup && m_clipDrag) {
2095 m_thumbsTimer.stop();
2096 m_waitingThumbs.clear();
2097 QList<QGraphicsItem *> items = m_selectionGroup->childItems();
2099 scene()->destroyItemGroup(m_selectionGroup);
2100 m_selectionGroup = NULL;
2101 } else QGraphicsView::dragLeaveEvent(event);
2104 void CustomTrackView::dropEvent(QDropEvent * event)
2106 if (m_selectionGroup && m_clipDrag) {
2107 QList<QGraphicsItem *> items = m_selectionGroup->childItems();
2108 resetSelectionGroup();
2109 m_scene->clearSelection();
2110 bool hasVideoClip = false;
2111 QUndoCommand *addCommand = new QUndoCommand();
2112 addCommand->setText(i18n("Add timeline clip"));
2113 QList <ClipItem *> brokenClips;
2115 for (int i = 0; i < items.count(); i++) {
2116 ClipItem *item = static_cast <ClipItem *>(items.at(i));
2117 if (!hasVideoClip && (item->clipType() == AV || item->clipType() == VIDEO)) hasVideoClip = true;
2118 if (items.count() == 1) {
2119 updateClipTypeActions(item);
2121 updateClipTypeActions(NULL);
2124 //TODO: take care of edit mode for undo
2125 item->baseClip()->addReference();
2126 //item->setZValue(item->defaultZValue());
2127 m_document->updateClip(item->baseClip()->getId());
2128 ItemInfo info = item->info();
2130 int tracknumber = m_document->tracksCount() - info.track - 1;
2131 bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
2132 if (isLocked) item->setItemLocked(true);
2133 ItemInfo clipInfo = info;
2134 clipInfo.track = m_document->tracksCount() - item->track();
2135 if (m_document->renderer()->mltInsertClip(clipInfo, item->xml(), item->baseClip()->producer(item->track()), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT) == -1) {
2136 emit displayMessage(i18n("Cannot insert clip in timeline"), ErrorMessage);
2137 brokenClips.append(item);
2140 adjustTimelineClips(m_scene->editMode(), item, ItemInfo(), addCommand);
2142 new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, false, false, addCommand);
2144 if (item->baseClip()->isTransparent() && getTransitionItemAtStart(info.startPos, info.track) == NULL) {
2145 // add transparency transition
2146 QDomElement trans = MainWindow::transitions.getEffectByTag("composite", "composite").cloneNode().toElement();
2147 new AddTransitionCommand(this, info, getPreviousVideoTrack(info.track), trans, false, true, addCommand);
2149 item->setSelected(true);
2151 qDeleteAll(brokenClips);
2152 brokenClips.clear();
2153 if (addCommand->childCount() > 0) m_commandStack->push(addCommand);
2154 else delete addCommand;
2156 // Automatic audio split
2157 if (KdenliveSettings::splitaudio())
2159 setDocumentModified();
2163 QRectF rect(0, 1 * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), 2);
2164 QList<QGraphicsItem *> selection = m_scene->items(rect);
2165 QStringList timelineList;
2167 kDebug()<<"// ITEMS on TRACK: "<<selection.count();
2168 for (int i = 0; i < selection.count(); i++) {
2169 if (selection.at(i)->type() == AVWIDGET) {
2170 ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
2171 int start = clip->startPos().frames(m_document->fps());
2172 int end = clip->endPos().frames(m_document->fps());
2173 timelineList.append(QString::number(start) + "-" + QString::number(end));
2176 kDebug() << "// COMPARE:\n" << timelineList << "\n-------------------";
2179 m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
2180 if (items.count() > 1) groupSelectedItems(true);
2181 event->setDropAction(Qt::MoveAction);
2183 } else QGraphicsView::dropEvent(event);
2187 void CustomTrackView::adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInfo posinfo, QUndoCommand *command)
2189 bool snap = KdenliveSettings::snaptopoints();
2190 KdenliveSettings::setSnaptopoints(false);
2191 if (mode == OVERWRITEEDIT) {
2192 // if we are in overwrite mode, move clips accordingly
2194 if (item == NULL) info = posinfo;
2195 else info = item->info();
2196 QRectF rect(info.startPos.frames(m_document->fps()), info.track * m_tracksHeight + m_tracksHeight / 2, (info.endPos - info.startPos).frames(m_document->fps()) - 1, 5);
2197 QList<QGraphicsItem *> selection = m_scene->items(rect);
2198 if (item) selection.removeAll(item);
2199 for (int i = 0; i < selection.count(); i++) {
2200 if (!selection.at(i)->isEnabled()) continue;
2201 if (selection.at(i)->type() == AVWIDGET) {
2202 ClipItem *clip = static_cast<ClipItem *>(selection.at(i));
2203 if (clip->startPos() < info.startPos) {
2204 if (clip->endPos() > info.endPos) {
2205 ItemInfo clipInfo = clip->info();
2206 ItemInfo dupInfo = clipInfo;
2207 GenTime diff = info.startPos - clipInfo.startPos;
2208 dupInfo.startPos = info.startPos;
2209 dupInfo.cropStart += diff;
2210 dupInfo.cropDuration = clipInfo.endPos - info.startPos;
2211 ItemInfo newdupInfo = dupInfo;
2212 GenTime diff2 = info.endPos - info.startPos;
2213 newdupInfo.startPos = info.endPos;
2214 newdupInfo.cropStart += diff2;
2215 newdupInfo.cropDuration = clipInfo.endPos - info.endPos;
2216 new RazorClipCommand(this, clipInfo, info.startPos, false, command);
2217 new ResizeClipCommand(this, dupInfo, newdupInfo, false, false, command);
2218 ClipItem *dup = cutClip(clipInfo, info.startPos, true, false);
2219 if (dup) dup->resizeStart(info.endPos.frames(m_document->fps()));
2221 ItemInfo newclipInfo = clip->info();
2222 newclipInfo.endPos = info.startPos;
2223 new ResizeClipCommand(this, clip->info(), newclipInfo, false, false, command);
2224 clip->resizeEnd(info.startPos.frames(m_document->fps()));
2226 } else if (clip->endPos() <= info.endPos) {
2227 new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), clip->info(), clip->effectList(), false, false, false, true, command);
2228 scene()->removeItem(clip);
2232 ItemInfo newclipInfo = clip->info();
2233 newclipInfo.startPos = info.endPos;
2234 new ResizeClipCommand(this, clip->info(), newclipInfo, false, false, command);
2235 clip->resizeStart(info.endPos.frames(m_document->fps()));
2239 } else if (mode == INSERTEDIT) {
2240 // if we are in push mode, move clips accordingly
2242 if (item == NULL) info = posinfo;
2243 else info = item->info();
2244 QRectF rect(info.startPos.frames(m_document->fps()), info.track * m_tracksHeight + m_tracksHeight / 2, (info.endPos - info.startPos).frames(m_document->fps()) - 1, 5);
2245 QList<QGraphicsItem *> selection = m_scene->items(rect);
2246 if (item) selection.removeAll(item);
2247 for (int i = 0; i < selection.count(); i++) {
2248 if (selection.at(i)->type() == AVWIDGET) {
2249 ClipItem *clip = static_cast<ClipItem *>(selection.at(i));
2250 if (clip->startPos() < info.startPos) {
2251 if (clip->endPos() > info.startPos) {
2252 ItemInfo clipInfo = clip->info();
2253 ItemInfo dupInfo = clipInfo;
2254 GenTime diff = info.startPos - clipInfo.startPos;
2255 dupInfo.startPos = info.startPos;
2256 dupInfo.cropStart += diff;
2257 dupInfo.cropDuration = clipInfo.endPos - info.startPos;
2258 new RazorClipCommand(this, clipInfo, info.startPos, false, command);
2259 // Commented out; variable dup unused. --granjow
2260 //ClipItem *dup = cutClip(clipInfo, info.startPos, true, false);
2261 cutClip(clipInfo, info.startPos, true, false);
2264 // TODO: add insertspacecommand
2269 KdenliveSettings::setSnaptopoints(snap);
2273 void CustomTrackView::adjustTimelineTransitions(EDITMODE mode, Transition *item, QUndoCommand *command)
2275 if (mode == OVERWRITEEDIT) {
2276 // if we are in overwrite or push mode, move clips accordingly
2277 bool snap = KdenliveSettings::snaptopoints();
2278 KdenliveSettings::setSnaptopoints(false);
2279 ItemInfo info = item->info();
2280 QRectF rect(info.startPos.frames(m_document->fps()), info.track * m_tracksHeight + m_tracksHeight, (info.endPos - info.startPos).frames(m_document->fps()) - 1, 5);
2281 QList<QGraphicsItem *> selection = m_scene->items(rect);
2282 selection.removeAll(item);
2283 for (int i = 0; i < selection.count(); i++) {
2284 if (!selection.at(i)->isEnabled()) continue;
2285 if (selection.at(i)->type() == TRANSITIONWIDGET) {
2286 Transition *tr = static_cast<Transition *>(selection.at(i));
2287 if (tr->startPos() < info.startPos) {
2288 ItemInfo firstPos = tr->info();
2289 ItemInfo newPos = firstPos;
2290 firstPos.endPos = item->startPos();
2291 newPos.startPos = item->endPos();
2292 new MoveTransitionCommand(this, tr->info(), firstPos, true, command);
2293 if (tr->endPos() > info.endPos) {
2295 new AddTransitionCommand(this, newPos, tr->transitionEndTrack(), tr->toXML(), false, true, command);
2297 } else if (tr->endPos() > info.endPos) {
2299 ItemInfo firstPos = tr->info();
2300 firstPos.startPos = item->endPos();
2301 new MoveTransitionCommand(this, tr->info(), firstPos, true, command);
2303 // remove transition
2304 new AddTransitionCommand(this, tr->info(), tr->transitionEndTrack(), tr->toXML(), true, true, command);
2308 KdenliveSettings::setSnaptopoints(snap);
2312 QStringList CustomTrackView::mimeTypes() const
2314 QStringList qstrList;
2315 // list of accepted mime types for drop
2316 qstrList.append("text/plain");
2317 qstrList.append("kdenlive/producerslist");
2318 qstrList.append("kdenlive/clip");
2322 Qt::DropActions CustomTrackView::supportedDropActions() const
2324 // returns what actions are supported when dropping
2325 return Qt::MoveAction;
2328 void CustomTrackView::setDuration(int duration)
2330 int diff = qAbs(duration - sceneRect().width());
2331 if (diff * matrix().m11() > -50) {
2332 if (matrix().m11() < 0.4) setSceneRect(0, 0, (duration + 100 / matrix().m11()), sceneRect().height());
2333 else setSceneRect(0, 0, (duration + 300), sceneRect().height());
2335 m_projectDuration = duration;
2338 int CustomTrackView::duration() const
2340 return m_projectDuration;
2343 void CustomTrackView::addTrack(TrackInfo type, int ix)
2345 if (ix == -1 || ix == m_document->tracksCount()) {
2346 m_document->insertTrack(0, type);
2347 m_document->renderer()->mltInsertTrack(1, type.type == VIDEOTRACK);
2349 m_document->insertTrack(m_document->tracksCount() - ix, type);
2350 // insert track in MLT playlist
2351 m_document->renderer()->mltInsertTrack(m_document->tracksCount() - ix, type.type == VIDEOTRACK);
2353 double startY = ix * m_tracksHeight + 1 + m_tracksHeight / 2;
2354 QRectF r(0, startY, sceneRect().width(), sceneRect().height() - startY);
2355 QList<QGraphicsItem *> selection = m_scene->items(r);
2356 resetSelectionGroup();
2358 m_selectionGroup = new AbstractGroupItem(m_document->fps());
2359 scene()->addItem(m_selectionGroup);
2360 for (int i = 0; i < selection.count(); i++) {
2361 if ((!selection.at(i)->parentItem()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
2362 m_selectionGroup->addToGroup(selection.at(i));
2363 selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
2366 // Move graphic items
2367 m_selectionGroup->translate(0, m_tracksHeight);
2369 // adjust track number
2370 QList<QGraphicsItem *> children = m_selectionGroup->childItems();
2371 for (int i = 0; i < children.count(); i++) {
2372 if (children.at(i)->type() == GROUPWIDGET) {
2373 AbstractGroupItem *grp = static_cast<AbstractGroupItem*>(children.at(i));
2374 children << grp->childItems();
2377 AbstractClipItem *item = static_cast <AbstractClipItem *>(children.at(i));
2379 ItemInfo clipinfo = item->info();
2380 if (item->type() == AVWIDGET) {
2381 ClipItem *clip = static_cast <ClipItem *>(item);
2382 // slowmotion clips are not track dependant, so no need to update them
2383 if (clip->speed() != 1.0) continue;
2384 // We add a move clip command so that we get the correct producer for new track number
2385 if (clip->clipType() == AV || clip->clipType() == AUDIO) {
2386 Mlt::Producer *prod;
2387 if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(clipinfo.track);
2388 else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer();
2389 else prod = clip->baseClip()->producer(clipinfo.track);
2390 if (m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod) == false) {
2391 // problem updating clip
2392 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage);
2395 } else if (item->type() == TRANSITIONWIDGET) {
2396 Transition *tr = static_cast <Transition *>(item);
2397 int track = tr->transitionEndTrack();
2399 tr->updateTransitionEndTrack(getPreviousVideoTrack(clipinfo.track));
2403 resetSelectionGroup(false);
2406 int maxHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
2407 for (int i = 0; i < m_guides.count(); i++) {
2408 QLineF l = m_guides.at(i)->line();
2409 l.setP2(QPointF(l.x2(), maxHeight));
2410 m_guides.at(i)->setLine(l);
2412 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight);
2413 setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
2414 viewport()->update();
2415 emit tracksChanged();
2416 //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged()));
2417 //setFixedHeight(50 * m_tracksCount);
2420 void CustomTrackView::removeTrack(int ix)
2422 // Delete track in MLT playlist
2423 m_document->renderer()->mltDeleteTrack(m_document->tracksCount() - ix);
2424 m_document->deleteTrack(m_document->tracksCount() - ix - 1);
2426 double startY = ix * (m_tracksHeight + 1) + m_tracksHeight / 2;
2427 QRectF r(0, startY, sceneRect().width(), sceneRect().height() - startY);
2428 QList<QGraphicsItem *> selection = m_scene->items(r);
2430 resetSelectionGroup();
2432 m_selectionGroup = new AbstractGroupItem(m_document->fps());
2433 scene()->addItem(m_selectionGroup);
2434 for (int i = 0; i < selection.count(); i++) {
2435 if ((!selection.at(i)->parentItem()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
2436 m_selectionGroup->addToGroup(selection.at(i));
2437 selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
2440 // Move graphic items
2441 qreal ydiff = 0 - (int) m_tracksHeight;
2442 m_selectionGroup->translate(0, ydiff);
2444 // adjust track number
2445 QList<QGraphicsItem *> children = m_selectionGroup->childItems();
2446 //kDebug() << "// FOUND CLIPS TO MOVE: " << children.count();
2447 for (int i = 0; i < children.count(); i++) {
2448 if (children.at(i)->type() == GROUPWIDGET) {
2449 AbstractGroupItem *grp = static_cast<AbstractGroupItem*>(children.at(i));
2450 children << grp->childItems();
2453 if (children.at(i)->type() == AVWIDGET) {
2454 ClipItem *clip = static_cast <ClipItem *>(children.at(i));
2456 ItemInfo clipinfo = clip->info();
2457 // We add a move clip command so that we get the correct producer for new track number
2458 if (clip->clipType() == AV || clip->clipType() == AUDIO) {
2459 Mlt::Producer *prod;
2460 if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(clipinfo.track);
2461 else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer();
2462 else prod = clip->baseClip()->producer(clipinfo.track);
2463 if (!m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod)) {
2464 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage);
2467 } else if (children.at(i)->type() == TRANSITIONWIDGET) {
2468 Transition *tr = static_cast <Transition *>(children.at(i));
2470 int track = tr->transitionEndTrack();
2472 ItemInfo clipinfo = tr->info();
2473 tr->updateTransitionEndTrack(getPreviousVideoTrack(clipinfo.track));
2477 resetSelectionGroup(false);
2479 int maxHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
2480 for (int i = 0; i < m_guides.count(); i++) {
2481 QLineF l = m_guides.at(i)->line();
2482 l.setP2(QPointF(l.x2(), maxHeight));
2483 m_guides.at(i)->setLine(l);
2485 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight);
2486 setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
2488 m_selectedTrack = qMin(m_selectedTrack, m_document->tracksCount() - 1);
2489 viewport()->update();
2490 emit tracksChanged();
2491 //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged()));
2494 void CustomTrackView::configTracks(QList < TrackInfo > trackInfos)
2496 for (int i = 0; i < trackInfos.count(); ++i) {
2497 m_document->setTrackType(i, trackInfos.at(i));
2498 m_document->renderer()->mltChangeTrackState(i + 1, m_document->trackInfoAt(i).isMute, m_document->trackInfoAt(i).isBlind);
2501 QTimer::singleShot(300, this, SIGNAL(trackHeightChanged()));
2502 viewport()->update();
2505 void CustomTrackView::slotSwitchTrackAudio(int ix)
2507 /*for (int i = 0; i < m_document->tracksCount(); i++)
2508 kDebug() << "TRK " << i << " STATE: " << m_document->trackInfoAt(i).isMute << m_document->trackInfoAt(i).isBlind;*/
2509 int tracknumber = m_document->tracksCount() - ix - 1;
2510 m_document->switchTrackAudio(tracknumber, !m_document->trackInfoAt(tracknumber).isMute);
2511 kDebug() << "NEXT TRK STATE: " << m_document->trackInfoAt(tracknumber).isMute << m_document->trackInfoAt(tracknumber).isBlind;
2512 m_document->renderer()->mltChangeTrackState(tracknumber + 1, m_document->trackInfoAt(tracknumber).isMute, m_document->trackInfoAt(tracknumber).isBlind);
2513 setDocumentModified();
2516 void CustomTrackView::slotSwitchTrackLock(int ix)
2518 int tracknumber = m_document->tracksCount() - ix - 1;
2519 LockTrackCommand *command = new LockTrackCommand(this, ix, !m_document->trackInfoAt(tracknumber).isLocked);
2520 m_commandStack->push(command);
2524 void CustomTrackView::lockTrack(int ix, bool lock)
2526 int tracknumber = m_document->tracksCount() - ix - 1;
2527 m_document->switchTrackLock(tracknumber, lock);
2528 emit doTrackLock(ix, lock);
2529 AbstractClipItem *clip = NULL;
2530 QList<QGraphicsItem *> selection = m_scene->items(0, ix * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), m_tracksHeight / 2 - 2);
2532 for (int i = 0; i < selection.count(); i++) {
2533 if (selection.at(i)->type() != AVWIDGET && selection.at(i)->type() != TRANSITIONWIDGET) continue;
2534 if (selection.at(i)->isSelected()) {
2535 if (selection.at(i)->type() == AVWIDGET) emit clipItemSelected(NULL);
2536 else emit transitionItemSelected(NULL);
2538 clip = static_cast <AbstractClipItem *>(selection.at(i));
2539 clip->setItemLocked(lock);
2540 if (clip == m_dragItem)
2543 kDebug() << "NEXT TRK STATE: " << m_document->trackInfoAt(tracknumber).isLocked;
2544 viewport()->update();
2545 setDocumentModified();
2548 void CustomTrackView::slotSwitchTrackVideo(int ix)
2550 int tracknumber = m_document->tracksCount() - ix;
2551 m_document->switchTrackVideo(tracknumber - 1, !m_document->trackInfoAt(tracknumber - 1).isBlind);
2552 m_document->renderer()->mltChangeTrackState(tracknumber, m_document->trackInfoAt(tracknumber - 1).isMute, m_document->trackInfoAt(tracknumber - 1).isBlind);
2553 setDocumentModified();
2556 QList<QGraphicsItem *> CustomTrackView::checkForGroups(const QRectF &rect, bool *ok)
2558 // Check there is no group going over several tracks there, or that would result in timeline corruption
2559 QList<QGraphicsItem *> selection = scene()->items(rect);
2561 int maxHeight = m_tracksHeight * 1.5;
2562 for (int i = 0; i < selection.count(); i++) {
2563 // Check that we don't try to move a group with clips on other tracks
2564 if (selection.at(i)->type() == GROUPWIDGET && (selection.at(i)->boundingRect().height() >= maxHeight)) {
2567 } else if (selection.at(i)->parentItem() && (selection.at(i)->parentItem()->boundingRect().height() >= maxHeight)) {
2575 void CustomTrackView::slotRemoveSpace()
2579 if (m_menuPosition.isNull()) {
2580 pos = GenTime(cursorPos(), m_document->fps());
2582 track = QInputDialog::getInteger(this, i18n("Remove Space"), i18n("Track"), 0, 0, m_document->tracksCount() - 1, 1, &ok);
2585 pos = GenTime((int)(mapToScene(m_menuPosition).x()), m_document->fps());
2586 track = (int)(mapToScene(m_menuPosition).y() / m_tracksHeight);
2589 if (m_document->isTrackLocked(m_document->tracksCount() - track - 1)) {
2590 emit displayMessage(i18n("Cannot remove space in a locked track"), ErrorMessage);
2594 ClipItem *item = getClipItemAt(pos, track);
2596 emit displayMessage(i18n("You must be in an empty space to remove space (time: %1, track: %2)", m_document->timecode().getTimecodeFromFrames(mapToScene(m_menuPosition).x()), track), ErrorMessage);
2599 int length = m_document->renderer()->mltGetSpaceLength(pos, m_document->tracksCount() - track, true);
2600 //kDebug() << "// GOT LENGT; " << length;
2602 emit displayMessage(i18n("You must be in an empty space to remove space (time: %1, track: %2)", m_document->timecode().getTimecodeFromFrames(mapToScene(m_menuPosition).x()), track), ErrorMessage);
2606 // Make sure there is no group in the way
2607 QRectF rect(pos.frames(m_document->fps()), track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width() - pos.frames(m_document->fps()), m_tracksHeight / 2 - 2);
2610 QList<QGraphicsItem *> items = checkForGroups(rect, &isOk);
2612 // groups found on track, do not allow the move
2613 emit displayMessage(i18n("Cannot remove space in a track with a group"), ErrorMessage);
2617 QList<ItemInfo> clipsToMove;
2618 QList<ItemInfo> transitionsToMove;
2620 for (int i = 0; i < items.count(); i++) {
2621 if (items.at(i)->type() == AVWIDGET || items.at(i)->type() == TRANSITIONWIDGET) {
2622 AbstractClipItem *item = static_cast <AbstractClipItem *>(items.at(i));
2623 ItemInfo info = item->info();
2624 if (item->type() == AVWIDGET) {
2625 clipsToMove.append(info);
2626 } else if (item->type() == TRANSITIONWIDGET) {
2627 transitionsToMove.append(info);
2632 InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, GenTime(-length, m_document->fps()), true);
2633 m_commandStack->push(command);
2636 void CustomTrackView::slotInsertSpace()
2640 if (m_menuPosition.isNull()) {
2641 pos = GenTime(cursorPos(), m_document->fps());
2643 pos = GenTime((int)(mapToScene(m_menuPosition).x()), m_document->fps());
2644 track = (int)(mapToScene(m_menuPosition).y() / m_tracksHeight) + 1;
2646 SpacerDialog d(GenTime(65, m_document->fps()), m_document->timecode(), track, m_document->tracksList(), this);
2647 if (d.exec() != QDialog::Accepted) return;
2648 GenTime spaceDuration = d.selectedDuration();
2649 track = d.selectedTrack();
2651 QList<QGraphicsItem *> items;
2653 if (m_document->isTrackLocked(m_document->tracksCount() - track - 1)) {
2654 emit displayMessage(i18n("Cannot insert space in a locked track"), ErrorMessage);
2658 ClipItem *item = getClipItemAt(pos, track);
2659 if (item) pos = item->startPos();
2661 // Make sure there is no group in the way
2662 QRectF rect(pos.frames(m_document->fps()), track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width() - pos.frames(m_document->fps()), m_tracksHeight / 2 - 2);
2664 items = checkForGroups(rect, &isOk);
2666 // groups found on track, do not allow the move
2667 emit displayMessage(i18n("Cannot insert space in a track with a group"), ErrorMessage);
2671 QRectF rect(pos.frames(m_document->fps()), 0, sceneRect().width() - pos.frames(m_document->fps()), m_document->tracksCount() * m_tracksHeight);
2672 items = scene()->items(rect);
2675 QList<ItemInfo> clipsToMove;
2676 QList<ItemInfo> transitionsToMove;
2678 for (int i = 0; i < items.count(); i++) {
2679 if (items.at(i)->type() == AVWIDGET || items.at(i)->type() == TRANSITIONWIDGET) {
2680 AbstractClipItem *item = static_cast <AbstractClipItem *>(items.at(i));
2681 ItemInfo info = item->info();
2682 if (item->type() == AVWIDGET)
2683 clipsToMove.append(info);
2684 else if (item->type() == TRANSITIONWIDGET)
2685 transitionsToMove.append(info);
2689 if (!clipsToMove.isEmpty() || !transitionsToMove.isEmpty()) {
2690 InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, spaceDuration, true);
2691 m_commandStack->push(command);
2695 void CustomTrackView::insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> transToMove, int track, const GenTime duration, const GenTime offset)
2697 int diff = duration.frames(m_document->fps());
2698 resetSelectionGroup();
2699 m_selectionGroup = new AbstractGroupItem(m_document->fps());
2700 scene()->addItem(m_selectionGroup);
2702 Transition *transition;
2704 // Create lists with start pos for each track
2705 QMap <int, int> trackClipStartList;
2706 QMap <int, int> trackTransitionStartList;
2708 for (int i = 1; i < m_document->tracksCount() + 1; i++) {
2709 trackClipStartList[i] = -1;
2710 trackTransitionStartList[i] = -1;
2713 if (!clipsToMove.isEmpty()) for (int i = 0; i < clipsToMove.count(); i++) {
2714 clip = getClipItemAtStart(clipsToMove.at(i).startPos + offset, clipsToMove.at(i).track);
2716 if (clip->parentItem()) {
2717 m_selectionGroup->addToGroup(clip->parentItem());
2718 clip->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
2720 m_selectionGroup->addToGroup(clip);
2721 clip->setFlag(QGraphicsItem::ItemIsMovable, false);
2723 if (trackClipStartList.value(m_document->tracksCount() - clipsToMove.at(i).track) == -1 || clipsToMove.at(i).startPos.frames(m_document->fps()) < trackClipStartList.value(m_document->tracksCount() - clipsToMove.at(i).track))
2724 trackClipStartList[m_document->tracksCount() - clipsToMove.at(i).track] = clipsToMove.at(i).startPos.frames(m_document->fps());
2726 displayMessage(i18n("Cannot move clip at position %1, track %2", m_document->timecode().getTimecodeFromFrames((clipsToMove.at(i).startPos + offset).frames(m_document->fps())), clipsToMove.at(i).track), ErrorMessage);
2729 if (!transToMove.isEmpty()) for (int i = 0; i < transToMove.count(); i++) {
2730 transition = getTransitionItemAtStart(transToMove.at(i).startPos + offset, transToMove.at(i).track);
2732 if (transition->parentItem()) {
2733 m_selectionGroup->addToGroup(transition->parentItem());
2734 transition->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
2736 m_selectionGroup->addToGroup(transition);
2737 transition->setFlag(QGraphicsItem::ItemIsMovable, false);
2739 if (trackTransitionStartList.value(m_document->tracksCount() - transToMove.at(i).track) == -1 || transToMove.at(i).startPos.frames(m_document->fps()) < trackTransitionStartList.value(m_document->tracksCount() - transToMove.at(i).track))
2740 trackTransitionStartList[m_document->tracksCount() - transToMove.at(i).track] = transToMove.at(i).startPos.frames(m_document->fps());
2741 } else emit displayMessage(i18n("Cannot move transition at position %1, track %2", m_document->timecode().getTimecodeFromFrames(transToMove.at(i).startPos.frames(m_document->fps())), transToMove.at(i).track), ErrorMessage);
2743 m_selectionGroup->translate(diff, 0);
2745 // update items coordinates
2746 QList<QGraphicsItem *> itemList = m_selectionGroup->childItems();
2748 for (int i = 0; i < itemList.count(); i++) {
2749 if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
2750 static_cast < AbstractClipItem *>(itemList.at(i))->updateItem();
2751 } else if (itemList.at(i)->type() == GROUPWIDGET) {
2752 QList<QGraphicsItem *> children = itemList.at(i)->childItems();
2753 for (int j = 0; j < children.count(); j++) {
2754 AbstractClipItem * clp = static_cast < AbstractClipItem *>(children.at(j));
2759 resetSelectionGroup(false);
2761 track = m_document->tracksCount() - track;
2762 m_document->renderer()->mltInsertSpace(trackClipStartList, trackTransitionStartList, track, duration, offset);
2765 void CustomTrackView::deleteClip(const QString &clipId)
2767 resetSelectionGroup();
2768 QList<QGraphicsItem *> itemList = items();
2769 QUndoCommand *deleteCommand = new QUndoCommand();
2771 for (int i = 0; i < itemList.count(); i++) {
2772 if (itemList.at(i)->type() == AVWIDGET) {
2773 ClipItem *item = (ClipItem *)itemList.at(i);
2774 if (item->clipProducer() == clipId) {
2776 if (item->parentItem()) {
2777 // Clip is in a group, destroy the group
2778 new GroupClipsCommand(this, QList<ItemInfo>() << item->info(), QList<ItemInfo>(), false, deleteCommand);
2780 new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, true, true, deleteCommand);
2784 deleteCommand->setText(i18np("Delete timeline clip", "Delete timeline clips", count));
2785 if (count == 0) delete deleteCommand;
2786 else m_commandStack->push(deleteCommand);
2789 void CustomTrackView::setCursorPos(int pos, bool seek)
2791 if (pos == m_cursorPos) return;
2792 emit cursorMoved((int)(m_cursorPos), (int)(pos));
2794 if (seek) m_document->renderer()->seek(GenTime(m_cursorPos, m_document->fps()));
2795 else if (m_autoScroll) checkScrolling();
2796 m_cursorLine->setPos(m_cursorPos, 0);
2799 void CustomTrackView::updateCursorPos()
2801 m_cursorLine->setPos(m_cursorPos, 0);
2804 int CustomTrackView::cursorPos()
2806 return (int)(m_cursorPos);
2809 void CustomTrackView::moveCursorPos(int delta)
2811 if (m_cursorPos + delta < 0) delta = 0 - m_cursorPos;
2812 emit cursorMoved((int)(m_cursorPos), (int)((m_cursorPos + delta)));
2813 m_cursorPos += delta;
2814 m_cursorLine->setPos(m_cursorPos, 0);
2815 m_document->renderer()->seek(GenTime(m_cursorPos, m_document->fps()));
2818 void CustomTrackView::initCursorPos(int pos)
2820 emit cursorMoved((int)(m_cursorPos), (int)(pos));
2822 m_cursorLine->setPos(pos, 0);
2826 void CustomTrackView::checkScrolling()
2828 ensureVisible(m_cursorPos, verticalScrollBar()->value() + 10, 2, 2, 50, 0);
2831 void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
2833 if (m_moveOpMode == SEEK) m_moveOpMode = NONE;
2834 QGraphicsView::mouseReleaseEvent(event);
2835 setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
2836 #if QT_VERSION >= 0x040600
2837 if (m_dragItem) m_dragItem->setGraphicsEffect(NULL);
2839 if (m_scrollTimer.isActive()) m_scrollTimer.stop();
2840 if (event->button() == Qt::MidButton) {
2843 setDragMode(QGraphicsView::NoDrag);
2844 if (m_operationMode == MOVEGUIDE) {
2845 setCursor(Qt::ArrowCursor);
2846 m_operationMode = NONE;
2847 m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, false);
2848 GenTime newPos = GenTime(m_dragGuide->pos().x(), m_document->fps());
2849 if (newPos != m_dragGuide->position()) {
2850 EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), newPos, m_dragGuide->label(), false);
2851 m_commandStack->push(command);
2852 m_dragGuide->updateGuide(GenTime(m_dragGuide->pos().x(), m_document->fps()));
2853 qSort(m_guides.begin(), m_guides.end(), sortGuidesList);
2854 m_document->syncGuides(m_guides);
2859 } else if (m_operationMode == SPACER && m_selectionGroup) {
2861 if (event->modifiers() != Qt::ControlModifier) {
2862 // We are moving all tracks
2864 } else track = (int)(mapToScene(m_clickEvent).y() / m_tracksHeight);
2865 GenTime timeOffset = GenTime((int)(m_selectionGroup->scenePos().x()), m_document->fps()) - m_selectionGroupInfo.startPos;
2867 if (timeOffset != GenTime()) {
2868 QList<QGraphicsItem *> items = m_selectionGroup->childItems();
2870 QList<ItemInfo> clipsToMove;
2871 QList<ItemInfo> transitionsToMove;
2873 // Create lists with start pos for each track
2874 QMap <int, int> trackClipStartList;
2875 QMap <int, int> trackTransitionStartList;
2877 for (int i = 1; i < m_document->tracksCount() + 1; i++) {
2878 trackClipStartList[i] = -1;
2879 trackTransitionStartList[i] = -1;
2882 for (int i = 0; i < items.count(); i++) {
2883 if (items.at(i)->type() == GROUPWIDGET)
2884 items += items.at(i)->childItems();
2887 for (int i = 0; i < items.count(); i++) {
2888 if (items.at(i)->type() == AVWIDGET) {
2889 AbstractClipItem *item = static_cast <AbstractClipItem *>(items.at(i));
2890 ItemInfo info = item->info();
2891 clipsToMove.append(info);
2893 if (trackClipStartList.value(m_document->tracksCount() - info.track) == -1 || info.startPos.frames(m_document->fps()) < trackClipStartList.value(m_document->tracksCount() - info.track))
2894 trackClipStartList[m_document->tracksCount() - info.track] = info.startPos.frames(m_document->fps());
2895 } else if (items.at(i)->type() == TRANSITIONWIDGET) {
2896 AbstractClipItem *item = static_cast <AbstractClipItem *>(items.at(i));
2897 ItemInfo info = item->info();
2898 transitionsToMove.append(info);
2900 if (trackTransitionStartList.value(m_document->tracksCount() - info.track) == -1 || info.startPos.frames(m_document->fps()) < trackTransitionStartList.value(m_document->tracksCount() - info.track))
2901 trackTransitionStartList[m_document->tracksCount() - info.track] = info.startPos.frames(m_document->fps());
2905 InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, timeOffset, false);
2906 m_commandStack->push(command);
2907 if (track != -1) track = m_document->tracksCount() - track;
2908 kDebug() << "SPACER TRACK:" << track;
2909 m_document->renderer()->mltInsertSpace(trackClipStartList, trackTransitionStartList, track, timeOffset, GenTime());
2911 resetSelectionGroup(false);
2912 m_operationMode = NONE;
2913 } else if (m_operationMode == RUBBERSELECTION) {
2914 //kDebug() << "// END RUBBER SELECT";
2915 resetSelectionGroup();
2916 groupSelectedItems();
2917 m_operationMode = NONE;
2920 if (m_dragItem == NULL && m_selectionGroup == NULL) {
2921 emit transitionItemSelected(NULL);
2925 if (m_dragItem) info = m_dragItem->info();
2927 if (m_operationMode == MOVE) {
2928 setCursor(Qt::OpenHandCursor);
2929 if (m_dragItem->parentItem() == 0) {
2930 // we are moving one clip, easy
2931 if (m_dragItem->type() == AVWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
2932 ClipItem *item = static_cast <ClipItem *>(m_dragItem);
2933 Mlt::Producer *prod;
2934 if (item->isAudioOnly()) prod = item->baseClip()->audioProducer(m_dragItemInfo.track);
2935 else if (item->isVideoOnly()) prod = item->baseClip()->videoProducer();
2936 else prod = item->baseClip()->producer(m_dragItemInfo.track);
2937 bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - m_dragItem->track()), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(m_dragItem->startPos().frames(m_document->fps())), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
2940 QUndoCommand *moveCommand = new QUndoCommand();
2941 moveCommand->setText(i18n("Move clip"));
2942 adjustTimelineClips(m_scene->editMode(), item, ItemInfo(), moveCommand);
2944 int tracknumber = m_document->tracksCount() - item->track() - 1;
2945 bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
2946 if (isLocked) item->setItemLocked(true);
2947 new MoveClipCommand(this, m_dragItemInfo, info, false, moveCommand);
2948 // Also move automatic transitions (on lower track)
2949 Transition *startTransition = getTransitionItemAtStart(m_dragItemInfo.startPos, m_dragItemInfo.track);
2950 ItemInfo startTrInfo;
2951 ItemInfo newStartTrInfo;
2952 bool moveStartTrans = false;
2953 bool moveEndTrans = false;
2954 if (startTransition && startTransition->isAutomatic()) {
2955 startTrInfo = startTransition->info();
2956 newStartTrInfo = startTrInfo;
2957 newStartTrInfo.track = info.track;
2958 newStartTrInfo.startPos = info.startPos;
2959 if (m_dragItemInfo.track == info.track && !item->baseClip()->isTransparent() && getClipItemAtEnd(newStartTrInfo.endPos, m_document->tracksCount() - startTransition->transitionEndTrack())) {
2960 // transition end should stay the same
2962 // transition end should be adjusted to clip
2963 newStartTrInfo.endPos = newStartTrInfo.endPos + (newStartTrInfo.startPos - startTrInfo.startPos);
2965 if (newStartTrInfo.startPos < newStartTrInfo.endPos) moveStartTrans = true;
2967 if (startTransition == NULL || startTransition->endPos() < m_dragItemInfo.endPos) {
2968 // Check if there is a transition at clip end
2969 Transition *tr = getTransitionItemAtEnd(m_dragItemInfo.endPos, m_dragItemInfo.track);
2970 if (tr && tr->isAutomatic()) {
2971 ItemInfo trInfo = tr->info();
2972 ItemInfo newTrInfo = trInfo;
2973 newTrInfo.track = info.track;
2974 newTrInfo.endPos = m_dragItem->endPos();
2975 if (m_dragItemInfo.track == info.track && !item->baseClip()->isTransparent() && getClipItemAtStart(trInfo.startPos, m_document->tracksCount() - tr->transitionEndTrack())) {
2976 // transition start should stay the same
2978 // transition start should be moved
2979 newTrInfo.startPos = newTrInfo.startPos + (newTrInfo.endPos - trInfo.endPos);
2981 if (newTrInfo.startPos < newTrInfo.endPos) {
2982 moveEndTrans = true;
2983 if (moveStartTrans) {
2984 // we have to move both transitions, remove the start one so that there is no collision
2985 new AddTransitionCommand(this, startTrInfo, startTransition->transitionEndTrack(), startTransition->toXML(), true, true, moveCommand);
2987 adjustTimelineTransitions(m_scene->editMode(), tr, moveCommand);
2988 new MoveTransitionCommand(this, trInfo, newTrInfo, true, moveCommand);
2989 if (moveStartTrans) {
2990 // re-add transition in correct place
2991 int transTrack = startTransition->transitionEndTrack();
2992 if (m_dragItemInfo.track != info.track && !startTransition->forcedTrack()) {
2993 transTrack = getPreviousVideoTrack(info.track);
2995 adjustTimelineTransitions(m_scene->editMode(), startTransition, moveCommand);
2996 new AddTransitionCommand(this, newStartTrInfo, transTrack, startTransition->toXML(), false, true, moveCommand);
3002 if (moveStartTrans && !moveEndTrans) {
3003 adjustTimelineTransitions(m_scene->editMode(), startTransition, moveCommand);
3004 new MoveTransitionCommand(this, startTrInfo, newStartTrInfo, true, moveCommand);
3007 // Also move automatic transitions (on upper track)
3008 Transition *tr = getTransitionItemAtStart(m_dragItemInfo.startPos, m_dragItemInfo.track - 1);
3009 if (m_dragItemInfo.track == info.track && tr && tr->isAutomatic() && (m_document->tracksCount() - tr->transitionEndTrack()) == m_dragItemInfo.track) {
3010 ItemInfo trInfo = tr->info();
3011 ItemInfo newTrInfo = trInfo;
3012 newTrInfo.startPos = m_dragItem->startPos();
3013 ClipItem * upperClip = getClipItemAt(m_dragItemInfo.startPos, m_dragItemInfo.track - 1);
3014 if (!upperClip || !upperClip->baseClip()->isTransparent()) {
3015 if (!getClipItemAtEnd(newTrInfo.endPos, tr->track())) {
3016 // transition end should be adjusted to clip on upper track
3017 newTrInfo.endPos = newTrInfo.endPos + (newTrInfo.startPos - trInfo.startPos);
3019 if (newTrInfo.startPos < newTrInfo.endPos) {
3020 adjustTimelineTransitions(m_scene->editMode(), tr, moveCommand);
3021 new MoveTransitionCommand(this, trInfo, newTrInfo, true, moveCommand);
3025 if (m_dragItemInfo.track == info.track && (tr == NULL || tr->endPos() < m_dragItemInfo.endPos)) {
3026 // Check if there is a transition at clip end
3027 tr = getTransitionItemAtEnd(m_dragItemInfo.endPos, m_dragItemInfo.track - 1);
3028 if (tr && tr->isAutomatic() && (m_document->tracksCount() - tr->transitionEndTrack()) == m_dragItemInfo.track) {
3029 ItemInfo trInfo = tr->info();
3030 ItemInfo newTrInfo = trInfo;
3031 newTrInfo.endPos = m_dragItem->endPos();
3032 kDebug() << "CLIP ENDS AT: " << newTrInfo.endPos.frames(25);
3033 kDebug() << "CLIP STARTS AT: " << newTrInfo.startPos.frames(25);
3034 ClipItem * upperClip = getClipItemAt(m_dragItemInfo.startPos, m_dragItemInfo.track - 1);
3035 if (!upperClip || !upperClip->baseClip()->isTransparent()) {
3036 if (!getClipItemAtStart(trInfo.startPos, tr->track())) {
3037 // transition start should be moved
3038 newTrInfo.startPos = newTrInfo.startPos + (newTrInfo.endPos - trInfo.endPos);
3040 if (newTrInfo.startPos < newTrInfo.endPos) {
3041 adjustTimelineTransitions(m_scene->editMode(), tr, moveCommand);
3042 new MoveTransitionCommand(this, trInfo, newTrInfo, true, moveCommand);
3047 m_commandStack->push(moveCommand);
3048 //checkTrackSequence(m_dragItem->track());
3050 // undo last move and emit error message
3051 bool snap = KdenliveSettings::snaptopoints();
3052 KdenliveSettings::setSnaptopoints(false);
3053 item->setPos((int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(m_dragItemInfo.track * m_tracksHeight + 1));
3054 KdenliveSettings::setSnaptopoints(snap);
3055 emit displayMessage(i18n("Cannot move clip to position %1", m_document->timecode().getTimecodeFromFrames(m_dragItemInfo.startPos.frames(m_document->fps()))), ErrorMessage);
3057 setDocumentModified();
3059 if (m_dragItem->type() == TRANSITIONWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
3060 Transition *transition = static_cast <Transition *>(m_dragItem);
3061 transition->updateTransitionEndTrack(getPreviousVideoTrack(m_dragItem->track()));
3062 if (!m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - m_dragItem->track()), transition->transitionEndTrack(), m_dragItemInfo.startPos, m_dragItemInfo.endPos, info.startPos, info.endPos)) {
3063 // Moving transition failed, revert to previous position
3064 emit displayMessage(i18n("Cannot move transition"), ErrorMessage);
3065 transition->setPos((int) m_dragItemInfo.startPos.frames(m_document->fps()), (m_dragItemInfo.track) * m_tracksHeight + 1);
3067 QUndoCommand *moveCommand = new QUndoCommand();
3068 moveCommand->setText(i18n("Move transition"));
3069 adjustTimelineTransitions(m_scene->editMode(), transition, moveCommand);
3070 new MoveTransitionCommand(this, m_dragItemInfo, info, false, moveCommand);
3071 m_commandStack->push(moveCommand);
3075 // Moving several clips. We need to delete them and readd them to new position,
3076 // or they might overlap each other during the move
3077 QGraphicsItemGroup *group = static_cast <QGraphicsItemGroup *>(m_dragItem->parentItem());
3078 QList<QGraphicsItem *> items = group->childItems();
3080 QList<ItemInfo> clipsToMove;
3081 QList<ItemInfo> transitionsToMove;
3083 GenTime timeOffset = GenTime(m_dragItem->scenePos().x(), m_document->fps()) - m_dragItemInfo.startPos;
3084 const int trackOffset = (int)(m_dragItem->scenePos().y() / m_tracksHeight) - m_dragItemInfo.track;
3085 //kDebug() << "// MOVED SEVERAL CLIPS" << timeOffset.frames(25);
3086 QUndoCommand *moveGroup = new QUndoCommand();
3087 moveGroup->setText(i18n("Move group"));
3088 if (timeOffset != GenTime() || trackOffset != 0) {
3089 // remove items in MLT playlist
3092 int max = items.count();
3093 for (int i = 0; i < max; i++) {
3094 if (items.at(i)->type() == GROUPWIDGET) {
3095 items += items.at(i)->childItems();
3098 m_document->renderer()->blockSignals(true);
3099 for (int i = 0; i < items.count(); i++) {
3100 if (items.at(i)->type() != AVWIDGET && items.at(i)->type() != TRANSITIONWIDGET) continue;
3101 AbstractClipItem *item = static_cast <AbstractClipItem *>(items.at(i));
3102 ItemInfo info = item->info();
3103 if (item->type() == AVWIDGET) {
3104 if (m_document->renderer()->mltRemoveClip(m_document->tracksCount() - info.track, info.startPos) == false) {
3105 // error, clip cannot be removed from playlist
3106 emit displayMessage(i18n("Error removing clip at %1 on track %2", m_document->timecode().getTimecodeFromFrames(info.startPos.frames(m_document->fps())), info.track), ErrorMessage);
3108 clipsToMove.append(info);
3111 transitionsToMove.append(info);
3112 Transition *tr = static_cast <Transition*>(item);
3113 m_document->renderer()->mltDeleteTransition(tr->transitionTag(), tr->transitionEndTrack(), m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML());
3116 m_document->renderer()->blockSignals(false);
3117 for (int i = 0; i < items.count(); i++) {
3118 // re-add items in correct place
3119 if (items.at(i)->type() != AVWIDGET && items.at(i)->type() != TRANSITIONWIDGET) continue;
3120 AbstractClipItem *item = static_cast <AbstractClipItem *>(items.at(i));
3122 ItemInfo info = item->info();
3123 int tracknumber = m_document->tracksCount() - info.track - 1;
3124 bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
3126 group->removeFromGroup(item);
3127 item->setItemLocked(true);
3130 if (item->type() == AVWIDGET) {
3131 ClipItem *clip = static_cast <ClipItem*>(item);
3132 info.track = m_document->tracksCount() - info.track;
3133 Mlt::Producer *prod;
3134 adjustTimelineClips(m_scene->editMode(), clip, ItemInfo(), moveGroup);
3135 if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(info.track);
3136 else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer();
3137 else prod = clip->baseClip()->producer(info.track);
3138 m_document->renderer()->mltInsertClip(info, clip->xml(), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
3139 for (int i = 0; i < clip->effectsCount(); i++) {
3140 m_document->renderer()->mltAddEffect(info.track, info.startPos, clip->getEffectArgs(clip->effectAt(i)), false);
3143 Transition *tr = static_cast <Transition*>(item);
3144 int newTrack = tr->transitionEndTrack();
3145 if (!tr->forcedTrack()) {
3146 newTrack = getPreviousVideoTrack(info.track);
3148 tr->updateTransitionEndTrack(newTrack);
3149 adjustTimelineTransitions(m_scene->editMode(), tr, moveGroup);
3150 m_document->renderer()->mltAddTransition(tr->transitionTag(), newTrack, m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML());
3154 new MoveGroupCommand(this, clipsToMove, transitionsToMove, timeOffset, trackOffset, false, moveGroup);
3155 m_commandStack->push(moveGroup);
3157 //QPointF top = group->sceneBoundingRect().topLeft();
3158 //QPointF oldpos = m_selectionGroup->scenePos();
3159 //kDebug()<<"SELECTION GRP POS: "<<m_selectionGroup->scenePos()<<", TOP: "<<top;
3160 //group->setPos(top);
3161 //TODO: get rid of the 3 lines below
3162 if (m_selectionGroup) {
3163 m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps());
3164 m_selectionGroupInfo.track = m_selectionGroup->track();
3166 setDocumentModified();
3169 m_document->renderer()->doRefresh();
3170 } else if (m_operationMode == RESIZESTART && m_dragItem->startPos() != m_dragItemInfo.startPos) {
3172 prepareResizeClipStart(m_dragItem, m_dragItemInfo, m_dragItem->startPos().frames(m_document->fps()));
3173 } else if (m_operationMode == RESIZEEND && m_dragItem->endPos() != m_dragItemInfo.endPos) {
3175 prepareResizeClipEnd(m_dragItem, m_dragItemInfo, m_dragItem->endPos().frames(m_document->fps()));
3176 } else if (m_operationMode == FADEIN) {
3177 // resize fade in effect
3178 ClipItem * item = static_cast <ClipItem *>(m_dragItem);
3179 int ix = item->hasEffect("volume", "fadein");
3180 int ix2 = item->hasEffect("", "fade_from_black");
3182 QDomElement oldeffect = item->effectAt(ix);
3183 int start = item->cropStart().frames(m_document->fps());
3184 int end = item->fadeIn();
3186 slotDeleteEffect(item, oldeffect, false);
3189 QDomElement effect = oldeffect.cloneNode().toElement();
3190 EffectsList::setParameter(oldeffect, "in", QString::number(start));
3191 EffectsList::setParameter(oldeffect, "out", QString::number(end));
3192 slotUpdateClipEffect(item, effect, oldeffect, ix);
3193 emit clipItemSelected(item, ix);
3195 } else if (item->fadeIn() != 0 && ix2 == -1) {
3197 if (item->isVideoOnly() || (item->clipType() != AUDIO && item->clipType() != AV && item->clipType() != PLAYLIST)) {
3199 effect = MainWindow::videoEffects.getEffectByTag("", "fade_from_black").cloneNode().toElement();
3200 } else effect = MainWindow::audioEffects.getEffectByTag("volume", "fadein").cloneNode().toElement();
3201 EffectsList::setParameter(effect, "out", QString::number(item->fadeIn()));
3202 slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
3205 QDomElement oldeffect = item->effectAt(ix2);
3206 int start = item->cropStart().frames(m_document->fps());
3207 int end = item->fadeIn();
3209 slotDeleteEffect(item, oldeffect, false);
3212 QDomElement effect = oldeffect.cloneNode().toElement();
3213 EffectsList::setParameter(oldeffect, "in", QString::number(start));
3214 EffectsList::setParameter(oldeffect, "out", QString::number(end));
3215 slotUpdateClipEffect(item, effect, oldeffect, ix2);
3216 emit clipItemSelected(item, ix2);
3219 } else if (m_operationMode == FADEOUT) {
3220 // resize fade in effect
3221 ClipItem * item = static_cast <ClipItem *>(m_dragItem);
3222 int ix = item->hasEffect("volume", "fadeout");
3223 int ix2 = item->hasEffect("", "fade_to_black");
3225 QDomElement oldeffect = item->effectAt(ix);
3226 int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
3227 int start = item->fadeOut();
3229 slotDeleteEffect(item, oldeffect, false);
3231 start = end - start;
3232 QDomElement effect = oldeffect.cloneNode().toElement();
3233 EffectsList::setParameter(oldeffect, "in", QString::number(start));
3234 EffectsList::setParameter(oldeffect, "out", QString::number(end));
3235 // kDebug()<<"EDIT FADE OUT : "<<start<<"x"<<end;
3236 slotUpdateClipEffect(item, effect, oldeffect, ix);
3237 emit clipItemSelected(item, ix);
3239 } else if (item->fadeOut() != 0 && ix2 == -1) {
3241 if (item->isVideoOnly() || (item->clipType() != AUDIO && item->clipType() != AV && item->clipType() != PLAYLIST)) {
3243 effect = MainWindow::videoEffects.getEffectByTag("", "fade_to_black").cloneNode().toElement();
3244 } else effect = MainWindow::audioEffects.getEffectByTag("volume", "fadeout").cloneNode().toElement();
3245 EffectsList::setParameter(effect, "in", QString::number(item->fadeOut()));
3246 EffectsList::setParameter(effect, "out", QString::number(0));
3247 slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
3250 QDomElement oldeffect = item->effectAt(ix2);
3251 int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
3252 int start = item->fadeOut();
3254 slotDeleteEffect(item, oldeffect, false);
3256 start = end - start;
3257 QDomElement effect = oldeffect.cloneNode().toElement();
3258 EffectsList::setParameter(oldeffect, "in", QString::number(start));
3259 EffectsList::setParameter(oldeffect, "out", QString::number(end));
3260 // kDebug()<<"EDIT FADE OUT : "<<start<<"x"<<end;
3261 slotUpdateClipEffect(item, effect, oldeffect, ix2);
3262 emit clipItemSelected(item, ix2);
3265 } else if (m_operationMode == KEYFRAME) {
3266 // update the MLT effect
3267 ClipItem * item = static_cast <ClipItem *>(m_dragItem);
3268 QDomElement oldEffect = item->selectedEffect().cloneNode().toElement();
3270 // check if we want to remove keyframe
3271 double val = mapToScene(event->pos()).toPoint().y();
3272 QRectF br = item->sceneBoundingRect();
3273 double maxh = 100.0 / br.height();
3274 val = (br.bottom() - val) * maxh;
3275 int start = item->cropStart().frames(m_document->fps());
3276 int end = (item->cropStart() + item->cropDuration()).frames(m_document->fps()) - 1;
3278 if ((val < -50 || val > 150) && item->editedKeyFramePos() != start && item->editedKeyFramePos() != end) {
3280 item->movedKeyframe(item->getEffectAt(item->selectedEffectIndex()), item->selectedKeyFramePos(), -1, 0);
3282 item->movedKeyframe(item->getEffectAt(item->selectedEffectIndex()), item->selectedKeyFramePos(), item->editedKeyFramePos(), item->editedKeyFrameValue());
3285 QDomElement newEffect = item->selectedEffect().cloneNode().toElement();
3286 //item->updateKeyframeEffect();
3287 //QString next = item->keyframes(item->selectedEffectIndex());
3288 //EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
3289 EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), oldEffect, newEffect, item->selectedEffectIndex(), false);
3291 m_commandStack->push(command);
3292 updateEffect(m_document->tracksCount() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
3293 emit clipItemSelected(item, item->selectedEffectIndex());
3295 if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET && m_dragItem->isSelected()) {
3296 // A transition is selected
3298 ClipItem *transitionClip = getClipItemAt(m_dragItemInfo.startPos, m_dragItemInfo.track);
3299 if (transitionClip && transitionClip->baseClip()) {
3300 QString size = transitionClip->baseClip()->getProperty("frame_size");
3301 double factor = transitionClip->baseClip()->getProperty("aspect_ratio").toDouble();
3302 if (factor == 0) factor = 1.0;
3303 p.setX((int)(size.section('x', 0, 0).toInt() * factor + 0.5));
3304 p.setY(size.section('x', 1, 1).toInt());
3306 emit transitionItemSelected(static_cast <Transition *>(m_dragItem), getPreviousVideoTrack(m_dragItem->track()), p);
3307 } else emit transitionItemSelected(NULL);
3308 if (m_operationMode != NONE && m_operationMode != MOVE) setDocumentModified();
3309 m_operationMode = NONE;
3312 void CustomTrackView::deleteClip(ItemInfo info, bool refresh)
3314 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
3316 if (!item || m_document->renderer()->mltRemoveClip(m_document->tracksCount() - info.track, info.startPos) == false) {
3317 emit displayMessage(i18n("Error removing clip at %1 on track %2", m_document->timecode().getTimecodeFromFrames(info.startPos.frames(m_document->fps())), info.track), ErrorMessage);
3320 if (item->isSelected()) emit clipItemSelected(NULL);
3321 item->baseClip()->removeReference();
3322 m_document->updateClip(item->baseClip()->getId());
3324 /*if (item->baseClip()->isTransparent()) {
3325 // also remove automatic transition
3326 Transition *tr = getTransitionItemAt(info.startPos, info.track);
3327 if (tr && tr->isAutomatic()) {
3328 m_document->renderer()->mltDeleteTransition(tr->transitionTag(), tr->transitionEndTrack(), m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML());
3329 scene()->removeItem(tr);
3333 m_waitingThumbs.removeAll(item);
3334 if (m_dragItem == item) m_dragItem = NULL;
3335 #if QT_VERSION >= 0x040600
3336 // animate item deletion
3337 item->closeAnimation();
3338 /*if (refresh) item->closeAnimation();
3340 // no refresh, means we have several operations chained, we need to delete clip immediatly
3341 // so that it does not get in the way of the other
3350 setDocumentModified();
3351 if (refresh) m_document->renderer()->doRefresh();
3354 void CustomTrackView::deleteSelectedClips()
3356 resetSelectionGroup();
3357 QList<QGraphicsItem *> itemList = scene()->selectedItems();
3358 if (itemList.count() == 0) {
3359 emit displayMessage(i18n("Select clip to delete"), ErrorMessage);
3362 scene()->clearSelection();
3363 QUndoCommand *deleteSelected = new QUndoCommand();
3365 bool resetGroup = false;
3368 int transitionCount = 0;
3369 // expand & destroy groups
3370 for (int i = 0; i < itemList.count(); i++) {
3371 if (itemList.at(i)->type() == GROUPWIDGET) {
3373 QList<QGraphicsItem *> children = itemList.at(i)->childItems();
3374 QList <ItemInfo> clipInfos;
3375 QList <ItemInfo> transitionInfos;
3376 GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
3377 for (int j = 0; j < children.count(); j++) {
3378 if (children.at(j)->type() == AVWIDGET) {
3379 AbstractClipItem *clip = static_cast <AbstractClipItem *>(children.at(j));
3380 if (!clip->isItemLocked()) clipInfos.append(clip->info());
3381 } else if (children.at(j)->type() == TRANSITIONWIDGET) {
3382 AbstractClipItem *clip = static_cast <AbstractClipItem *>(children.at(j));
3383 if (!clip->isItemLocked()) transitionInfos.append(clip->info());
3385 if (itemList.contains(children.at(j))) {
3386 children.removeAt(j);
3390 itemList += children;
3391 if (clipInfos.count() > 0)
3392 new GroupClipsCommand(this, clipInfos, transitionInfos, false, deleteSelected);
3394 } else if (itemList.at(i)->parentItem() && itemList.at(i)->parentItem()->type() == GROUPWIDGET)
3395 itemList.insert(i + 1, itemList.at(i)->parentItem());
3398 for (int i = 0; i < itemList.count(); i++) {
3399 if (itemList.at(i)->type() == AVWIDGET) {
3401 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
3402 if (item->parentItem()) resetGroup = true;
3403 //kDebug()<<"// DELETE CLP AT: "<<item->info().startPos.frames(25);
3404 new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, true, true, deleteSelected);
3405 emit clipItemSelected(NULL);
3406 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
3408 Transition *item = static_cast <Transition *>(itemList.at(i));
3409 //kDebug()<<"// DELETE TRANS AT: "<<item->info().startPos.frames(25);
3410 if (item->parentItem()) resetGroup = true;
3411 new AddTransitionCommand(this, item->info(), item->transitionEndTrack(), item->toXML(), true, true, deleteSelected);
3412 emit transitionItemSelected(NULL);
3415 if (groupCount > 0 && clipCount == 0 && transitionCount == 0)
3416 deleteSelected->setText(i18np("Delete selected group", "Delete selected groups", groupCount));
3417 else if (clipCount > 0 && groupCount == 0 && transitionCount == 0)
3418 deleteSelected->setText(i18np("Delete selected clip", "Delete selected clips", clipCount));
3419 else if (transitionCount > 0 && groupCount == 0 && clipCount == 0)
3420 deleteSelected->setText(i18np("Delete selected transition", "Delete selected transitions", transitionCount));
3421 else deleteSelected->setText(i18n("Delete selected items"));
3422 m_commandStack->push(deleteSelected);
3425 void CustomTrackView::changeClipSpeed()
3427 QList<QGraphicsItem *> itemList = scene()->selectedItems();
3428 if (itemList.count() == 0) {
3429 emit displayMessage(i18n("Select clip to change speed"), ErrorMessage);
3432 QUndoCommand *changeSelected = new QUndoCommand();
3433 changeSelected->setText("Edit clip speed");
3437 for (int i = 0; i < itemList.count(); i++) {
3438 if (itemList.at(i)->type() == AVWIDGET) {
3439 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
3440 ItemInfo info = item->info();
3441 if (percent == -1) percent = QInputDialog::getInteger(this, i18n("Edit Clip Speed"), i18n("New speed (percents)"), item->speed() * 100, 1, 10000, 1, &ok);
3443 double speed = (double) percent / 100.0;
3444 if (item->speed() != speed && (item->clipType() == VIDEO || item->clipType() == AV)) {
3446 //new ChangeSpeedCommand(this, info, item->speed(), speed, item->clipProducer(), changeSelected);
3450 if (count > 0) m_commandStack->push(changeSelected);
3451 else delete changeSelected;
3454 void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, const double speed, const double oldspeed, int strobe, const QString &id)
3456 DocClipBase *baseclip = m_document->clipManager()->getClipById(id);
3457 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
3459 kDebug() << "ERROR: Cannot find clip for speed change";
3460 emit displayMessage(i18n("Cannot find clip for speed change"), ErrorMessage);
3463 info.track = m_document->tracksCount() - item->track();
3465 if (item->isVideoOnly()) endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->videoProducer());
3466 else if (item->isAudioOnly()) endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->audioProducer(item->track()));
3467 else endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->producer());
3469 item->setSpeed(speed, strobe);
3470 item->updateRectGeometry();
3471 if (item->cropDuration().frames(m_document->fps()) != endPos) {
3472 item->resizeEnd((int) info.startPos.frames(m_document->fps()) + endPos - 1);
3474 updatePositionEffects(item, info);
3475 setDocumentModified();
3476 } else emit displayMessage(i18n("Invalid clip"), ErrorMessage);
3479 void CustomTrackView::cutSelectedClips()
3481 QList<QGraphicsItem *> itemList = scene()->selectedItems();
3482 GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
3483 for (int i = 0; i < itemList.count(); i++) {
3484 if (itemList.at(i)->type() == AVWIDGET) {
3485 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
3486 if (item->parentItem() && item->parentItem() != m_selectionGroup) {
3487 emit displayMessage(i18n("Cannot cut a clip in a group"), ErrorMessage);
3488 } else if (currentPos > item->startPos() && currentPos < item->endPos()) {
3489 RazorClipCommand *command = new RazorClipCommand(this, item->info(), currentPos);
3490 m_commandStack->push(command);
3496 void CustomTrackView::groupClips(bool group)
3498 QList<QGraphicsItem *> itemList = scene()->selectedItems();
3499 QList <ItemInfo> clipInfos;
3500 QList <ItemInfo> transitionInfos;
3501 GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
3504 int max = itemList.count();
3505 for (int i = 0; i < max; i++) {
3506 if (itemList.at(i)->type() == GROUPWIDGET) {
3507 itemList += itemList.at(i)->childItems();
3511 for (int i = 0; i < itemList.count(); i++) {
3512 if (itemList.at(i)->type() == AVWIDGET) {
3513 AbstractClipItem *clip = static_cast <AbstractClipItem *>(itemList.at(i));
3514 if (!clip->isItemLocked()) clipInfos.append(clip->info());
3515 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
3516 AbstractClipItem *clip = static_cast <AbstractClipItem *>(itemList.at(i));
3517 if (!clip->isItemLocked()) transitionInfos.append(clip->info());
3520 if (clipInfos.count() > 0) {
3521 GroupClipsCommand *command = new GroupClipsCommand(this, clipInfos, transitionInfos, group);
3522 m_commandStack->push(command);
3526 void CustomTrackView::doGroupClips(QList <ItemInfo> clipInfos, QList <ItemInfo> transitionInfos, bool group)
3528 resetSelectionGroup();
3529 m_scene->clearSelection();
3531 for (int i = 0; i < clipInfos.count(); i++) {
3532 ClipItem *clip = getClipItemAt(clipInfos.at(i).startPos, clipInfos.at(i).track);
3533 if (clip == NULL) continue;
3534 if (clip->parentItem() && clip->parentItem()->type() == GROUPWIDGET) {
3535 AbstractGroupItem *grp = static_cast <AbstractGroupItem *>(clip->parentItem());
3536 m_document->clipManager()->removeGroup(grp);
3537 scene()->destroyItemGroup(grp);
3539 clip->setFlag(QGraphicsItem::ItemIsMovable, true);
3541 for (int i = 0; i < transitionInfos.count(); i++) {
3542 Transition *tr = getTransitionItemAt(transitionInfos.at(i).startPos, transitionInfos.at(i).track);
3543 if (tr == NULL) continue;
3544 if (tr->parentItem() && tr->parentItem()->type() == GROUPWIDGET) {
3545 AbstractGroupItem *grp = static_cast <AbstractGroupItem *>(tr->parentItem());
3546 m_document->clipManager()->removeGroup(grp);
3547 scene()->destroyItemGroup(grp);
3549 tr->setFlag(QGraphicsItem::ItemIsMovable, true);
3551 setDocumentModified();
3555 QList <QGraphicsItemGroup *> groups;
3556 for (int i = 0; i < clipInfos.count(); i++) {
3557 ClipItem *clip = getClipItemAt(clipInfos.at(i).startPos, clipInfos.at(i).track);
3559 clip->setSelected(true);
3562 for (int i = 0; i < transitionInfos.count(); i++) {
3563 Transition *clip = getTransitionItemAt(transitionInfos.at(i).startPos, transitionInfos.at(i).track);
3565 clip->setSelected(true);
3569 groupSelectedItems(false, true);
3570 setDocumentModified();
3573 void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo info, EffectsList effects, bool overwrite, bool push, bool refresh)
3575 DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId);
3576 if (baseclip == NULL) {
3577 emit displayMessage(i18n("No clip copied"), ErrorMessage);
3580 ClipItem *item = new ClipItem(baseclip, info, m_document->fps(), xml.attribute("speed", "1").toDouble(), xml.attribute("strobe", "1").toInt());
3581 item->setEffectList(effects);
3582 if (xml.hasAttribute("audio_only")) item->setAudioOnly(true);
3583 else if (xml.hasAttribute("video_only")) item->setVideoOnly(true);
3584 scene()->addItem(item);
3586 int tracknumber = m_document->tracksCount() - info.track - 1;
3587 bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
3588 if (isLocked) item->setItemLocked(true);
3590 baseclip->addReference();
3591 m_document->updateClip(baseclip->getId());
3592 info.track = m_document->tracksCount() - info.track;
3593 Mlt::Producer *prod;
3594 if (item->isAudioOnly()) prod = baseclip->audioProducer(info.track);
3595 else if (item->isVideoOnly()) prod = baseclip->videoProducer();
3596 else prod = baseclip->producer(info.track);
3597 m_document->renderer()->mltInsertClip(info, xml, prod, overwrite, push);
3598 for (int i = 0; i < item->effectsCount(); i++) {
3599 m_document->renderer()->mltAddEffect(info.track, info.startPos, item->getEffectArgs(item->effectAt(i)), false);
3601 setDocumentModified();
3602 if (refresh) m_document->renderer()->doRefresh();
3603 if (!baseclip->isPlaceHolder()) m_waitingThumbs.append(item);
3604 m_thumbsTimer.start();
3607 void CustomTrackView::slotUpdateClip(const QString &clipId, bool reload)
3609 QList<QGraphicsItem *> list = scene()->items();
3610 ClipItem *clip = NULL;
3611 for (int i = 0; i < list.size(); ++i) {
3612 if (list.at(i)->type() == AVWIDGET) {
3613 clip = static_cast <ClipItem *>(list.at(i));
3614 if (clip->clipProducer() == clipId) {
3615 ItemInfo info = clip->info();
3616 info.track = m_document->tracksCount() - clip->track();
3617 if (reload && !m_document->renderer()->mltUpdateClip(info, clip->xml(), clip->baseClip()->producer())) {
3618 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", info.startPos.frames(m_document->fps()), info.track), ErrorMessage);
3620 clip->refreshClip(true);
3627 ClipItem *CustomTrackView::getClipItemAtEnd(GenTime pos, int track)
3629 int framepos = (int)(pos.frames(m_document->fps()));
3630 QList<QGraphicsItem *> list = scene()->items(QPointF(framepos - 1, track * m_tracksHeight + m_tracksHeight / 2));
3631 ClipItem *clip = NULL;
3632 for (int i = 0; i < list.size(); i++) {
3633 if (!list.at(i)->isEnabled()) continue;
3634 if (list.at(i)->type() == AVWIDGET) {
3635 ClipItem *test = static_cast <ClipItem *>(list.at(i));
3636 if (test->endPos() == pos) clip = test;
3643 ClipItem *CustomTrackView::getClipItemAtStart(GenTime pos, int track)
3645 QList<QGraphicsItem *> list = scene()->items(QPointF(pos.frames(m_document->fps()), track * m_tracksHeight + m_tracksHeight / 2));
3646 ClipItem *clip = NULL;
3647 for (int i = 0; i < list.size(); i++) {
3648 if (!list.at(i)->isEnabled()) continue;
3649 if (list.at(i)->type() == AVWIDGET) {
3650 ClipItem *test = static_cast <ClipItem *>(list.at(i));
3651 if (test->startPos() == pos) clip = test;
3658 ClipItem *CustomTrackView::getClipItemAt(int pos, int track)
3660 const QPointF p(pos, track * m_tracksHeight + m_tracksHeight / 2);
3661 QList<QGraphicsItem *> list = scene()->items(p);
3662 ClipItem *clip = NULL;
3663 for (int i = 0; i < list.size(); i++) {
3664 if (!list.at(i)->isEnabled()) continue;
3665 if (list.at(i)->type() == AVWIDGET) {
3666 clip = static_cast <ClipItem *>(list.at(i));
3673 ClipItem *CustomTrackView::getClipItemAt(GenTime pos, int track)
3675 return getClipItemAt((int) pos.frames(m_document->fps()), track);
3678 Transition *CustomTrackView::getTransitionItemAt(int pos, int track)
3680 const QPointF p(pos, (track + 1) * m_tracksHeight);
3681 QList<QGraphicsItem *> list = scene()->items(p);
3682 Transition *clip = NULL;
3683 for (int i = 0; i < list.size(); i++) {
3684 if (!list.at(i)->isEnabled()) continue;
3685 if (list.at(i)->type() == TRANSITIONWIDGET) {
3686 clip = static_cast <Transition *>(list.at(i));
3693 Transition *CustomTrackView::getTransitionItemAt(GenTime pos, int track)
3695 return getTransitionItemAt(pos.frames(m_document->fps()), track);
3698 Transition *CustomTrackView::getTransitionItemAtEnd(GenTime pos, int track)
3700 int framepos = (int)(pos.frames(m_document->fps()));
3701 const QPointF p(framepos - 1, (track + 1) * m_tracksHeight);
3702 QList<QGraphicsItem *> list = scene()->items(p);
3703 Transition *clip = NULL;
3704 for (int i = 0; i < list.size(); i++) {
3705 if (!list.at(i)->isEnabled()) continue;
3706 if (list.at(i)->type() == TRANSITIONWIDGET) {
3707 Transition *test = static_cast <Transition *>(list.at(i));
3708 if (test->endPos() == pos) clip = test;
3715 Transition *CustomTrackView::getTransitionItemAtStart(GenTime pos, int track)
3717 const QPointF p(pos.frames(m_document->fps()), (track + 1) * m_tracksHeight);
3718 QList<QGraphicsItem *> list = scene()->items(p);
3719 Transition *clip = NULL;
3720 for (int i = 0; i < list.size(); ++i) {
3721 if (!list.at(i)->isEnabled()) continue;
3722 if (list.at(i)->type() == TRANSITIONWIDGET) {
3723 Transition *test = static_cast <Transition *>(list.at(i));
3724 if (test->startPos() == pos) clip = test;
3731 void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end, bool refresh)
3733 if (m_selectionGroup) resetSelectionGroup(false);
3734 ClipItem *item = getClipItemAt((int) start.startPos.frames(m_document->fps()), start.track);
3736 emit displayMessage(i18n("Cannot move clip at time: %1 on track %2", m_document->timecode().getTimecodeFromFrames(start.startPos.frames(m_document->fps())), start.track), ErrorMessage);
3737 kDebug() << "---------------- ERROR, CANNOT find clip to move at.. ";
3740 Mlt::Producer *prod;
3741 if (item->isAudioOnly()) prod = item->baseClip()->audioProducer(end.track);
3742 else if (item->isVideoOnly()) prod = item->baseClip()->videoProducer();
3743 else prod = item->baseClip()->producer(end.track);
3745 bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - start.track), (int)(m_document->tracksCount() - end.track), (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()), prod);
3747 bool snap = KdenliveSettings::snaptopoints();
3748 KdenliveSettings::setSnaptopoints(false);
3749 item->setPos((int) end.startPos.frames(m_document->fps()), (int)(end.track * m_tracksHeight + 1));
3751 int tracknumber = m_document->tracksCount() - end.track - 1;
3752 bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
3753 m_scene->clearSelection();
3754 if (isLocked) item->setItemLocked(true);
3756 if (item->isItemLocked()) item->setItemLocked(false);
3757 item->setSelected(true);
3759 if (item->baseClip()->isTransparent()) {
3760 // Also move automatic transition
3761 Transition *tr = getTransitionItemAt(start.startPos, start.track);
3762 if (tr && tr->isAutomatic()) {
3763 tr->updateTransitionEndTrack(getPreviousVideoTrack(end.track));
3764 m_document->renderer()->mltMoveTransition(tr->transitionTag(), m_document->tracksCount() - start.track, m_document->tracksCount() - end.track, tr->transitionEndTrack(), start.startPos, start.endPos, end.startPos, end.endPos);
3765 tr->setPos((int) end.startPos.frames(m_document->fps()), (int)(end.track * m_tracksHeight + 1));
3768 KdenliveSettings::setSnaptopoints(snap);
3769 setDocumentModified();
3771 // undo last move and emit error message
3772 emit displayMessage(i18n("Cannot move clip to position %1", m_document->timecode().getTimecodeFromFrames(end.startPos.frames(m_document->fps()))), ErrorMessage);
3774 if (refresh) m_document->renderer()->doRefresh();
3775 //kDebug() << " // MOVED CLIP TO: " << end.startPos.frames(25) << ", ITEM START: " << item->startPos().frames(25);
3778 void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> startTransition, const GenTime offset, const int trackOffset, bool reverseMove)
3781 /*kDebug() << "//GRP MOVE, REVERS:" << reverseMove;
3782 kDebug() << "// GROUP MOV; OFFSET: " << offset.frames(25) << ", TK OFF: " << trackOffset;*/
3783 resetSelectionGroup();
3784 m_scene->clearSelection();
3786 m_selectionGroup = new AbstractGroupItem(m_document->fps());
3787 scene()->addItem(m_selectionGroup);
3789 m_document->renderer()->blockSignals(true);
3790 for (int i = 0; i < startClip.count(); i++) {
3792 startClip[i].startPos = startClip.at(i).startPos - offset;
3793 startClip[i].track = startClip.at(i).track - trackOffset;
3795 //kDebug()<<"//LKING FR CLIP AT:"<<startClip.at(i).startPos.frames(25)<<", TK:"<<startClip.at(i).track;
3796 ClipItem *clip = getClipItemAt(startClip.at(i).startPos, startClip.at(i).track);
3798 clip->setItemLocked(false);
3799 if (clip->parentItem()) {
3800 m_selectionGroup->addToGroup(clip->parentItem());
3801 clip->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
3803 m_selectionGroup->addToGroup(clip);
3804 clip->setFlag(QGraphicsItem::ItemIsMovable, false);
3806 m_document->renderer()->mltRemoveClip(m_document->tracksCount() - startClip.at(i).track, startClip.at(i).startPos);
3807 } else kDebug() << "//MISSING CLIP AT: " << startClip.at(i).startPos.frames(25);
3809 for (int i = 0; i < startTransition.count(); i++) {
3811 startTransition[i].startPos = startTransition.at(i).startPos - offset;
3812 startTransition[i].track = startTransition.at(i).track - trackOffset;
3814 Transition *tr = getTransitionItemAt(startTransition.at(i).startPos, startTransition.at(i).track);
3816 tr->setItemLocked(false);
3817 if (tr->parentItem()) {
3818 m_selectionGroup->addToGroup(tr->parentItem());
3819 tr->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
3821 m_selectionGroup->addToGroup(tr);
3822 tr->setFlag(QGraphicsItem::ItemIsMovable, false);
3824 m_document->renderer()->mltDeleteTransition(tr->transitionTag(), tr->transitionEndTrack(), m_document->tracksCount() - startTransition.at(i).track, startTransition.at(i).startPos, startTransition.at(i).endPos, tr->toXML());
3825 } else kDebug() << "//MISSING TRANSITION AT: " << startTransition.at(i).startPos.frames(25);
3827 m_document->renderer()->blockSignals(false);
3829 if (m_selectionGroup) {
3830 bool snap = KdenliveSettings::snaptopoints();
3831 KdenliveSettings::setSnaptopoints(false);
3833 m_selectionGroup->translate(offset.frames(m_document->fps()), trackOffset *(qreal) m_tracksHeight);
3834 //m_selectionGroup->moveBy(offset.frames(m_document->fps()), trackOffset *(qreal) m_tracksHeight);
3836 QList<QGraphicsItem *> children = m_selectionGroup->childItems();
3838 int max = children.count();
3839 for (int i = 0; i < max; i++) {
3840 if (children.at(i)->type() == GROUPWIDGET) {
3841 children += children.at(i)->childItems();
3842 //AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(children.at(i));
3843 //grp->moveBy(offset.frames(m_document->fps()), trackOffset *(qreal) m_tracksHeight);
3844 /*m_document->clipManager()->removeGroup(grp);
3845 m_scene->destroyItemGroup(grp);*/
3846 children.removeAll(children.at(i));
3851 for (int i = 0; i < children.count(); i++) {
3852 // re-add items in correct place
3853 if (children.at(i)->type() != AVWIDGET && children.at(i)->type() != TRANSITIONWIDGET) continue;
3854 AbstractClipItem *item = static_cast <AbstractClipItem *>(children.at(i));
3856 ItemInfo info = item->info();
3857 int tracknumber = m_document->tracksCount() - info.track - 1;
3858 bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
3859 if (isLocked) item->setItemLocked(true);
3860 else if (item->isItemLocked()) item->setItemLocked(false);
3862 if (item->type() == AVWIDGET) {
3863 ClipItem *clip = static_cast <ClipItem*>(item);
3864 info.track = m_document->tracksCount() - info.track;
3865 Mlt::Producer *prod;
3866 if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(info.track);
3867 else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer();
3868 else prod = clip->baseClip()->producer(info.track);
3869 m_document->renderer()->mltInsertClip(info, clip->xml(), prod);
3870 } else if (item->type() == TRANSITIONWIDGET) {
3871 Transition *tr = static_cast <Transition*>(item);
3873 if (!tr->forcedTrack()) newTrack = getPreviousVideoTrack(info.track);
3875 newTrack = tr->transitionEndTrack() + trackOffset;
3876 if (newTrack < 0 || newTrack > m_document->tracksCount()) newTrack = getPreviousVideoTrack(info.track);
3878 tr->updateTransitionEndTrack(newTrack);
3879 m_document->renderer()->mltAddTransition(tr->transitionTag(), newTrack, m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML());
3882 resetSelectionGroup(false);
3883 KdenliveSettings::setSnaptopoints(snap);
3884 m_document->renderer()->doRefresh();
3885 } else kDebug() << "///////// WARNING; NO GROUP TO MOVE";
3888 void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end, bool m_refresh)
3890 Transition *item = getTransitionItemAt(start.startPos, start.track);
3892 emit displayMessage(i18n("Cannot move transition at time: %1 on track %2", m_document->timecode().getTimecodeFromFrames(start.startPos.frames(m_document->fps())), start.track), ErrorMessage);
3893 kDebug() << "---------------- ERROR, CANNOT find transition to move... ";// << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2;
3896 //kDebug() << "---------------- Move TRANSITION FROM: " << startPos.x() << ", END:" << endPos.x() << ",TRACKS: " << oldtrack << " TO " << newtrack;
3897 bool snap = KdenliveSettings::snaptopoints();
3898 KdenliveSettings::setSnaptopoints(false);
3899 //kDebug()<<"/// RESIZE TRANS START: ("<< startPos.x()<<"x"<< startPos.y()<<") / ("<<endPos.x()<<"x"<< endPos.y()<<")";
3900 if (end.endPos - end.startPos == start.endPos - start.startPos) {
3901 // Transition was moved
3902 item->setPos((int) end.startPos.frames(m_document->fps()), (end.track) * m_tracksHeight + 1);
3903 } else if (end.endPos == start.endPos) {
3904 // Transition start resize
3905 item->resizeStart((int) end.startPos.frames(m_document->fps()));
3906 } else if (end.startPos == start.startPos) {
3907 // Transition end resize;
3908 kDebug() << "// resize END: " << end.endPos.frames(m_document->fps());
3909 item->resizeEnd((int) end.endPos.frames(m_document->fps()));
3912 item->setPos((int) end.startPos.frames(m_document->fps()), (end.track) * m_tracksHeight + 1);
3913 item->resizeStart((int) end.startPos.frames(m_document->fps()));
3914 item->resizeEnd((int) end.endPos.frames(m_document->fps()));
3916 //item->moveTransition(GenTime((int) (endPos.x() - startPos.x()), m_document->fps()));
3917 KdenliveSettings::setSnaptopoints(snap);
3918 item->updateTransitionEndTrack(getPreviousVideoTrack(end.track));
3919 m_document->renderer()->mltMoveTransition(item->transitionTag(), m_document->tracksCount() - start.track, m_document->tracksCount() - item->track(), item->transitionEndTrack(), start.startPos, start.endPos, item->startPos(), item->endPos());
3920 if (m_dragItem && m_dragItem == item) {
3922 ClipItem *transitionClip = getClipItemAt(item->startPos(), item->track());
3923 if (transitionClip && transitionClip->baseClip()) {
3924 QString size = transitionClip->baseClip()->getProperty("frame_size");
3925 double factor = transitionClip->baseClip()->getProperty("aspect_ratio").toDouble();
3926 if (factor == 0) factor = 1.0;
3927 p.setX((int)(size.section('x', 0, 0).toInt() * factor + 0.5));
3928 p.setY(size.section('x', 1, 1).toInt());
3930 emit transitionItemSelected(item, getPreviousVideoTrack(item->track()), p);
3932 if (m_refresh) m_document->renderer()->doRefresh();
3933 setDocumentModified();
3936 void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end, bool dontWorry)
3938 bool resizeClipStart = (start.startPos != end.startPos);
3939 ClipItem *item = getClipItemAtStart(start.startPos, start.track);
3941 if (dontWorry) return;
3942 emit displayMessage(i18n("Cannot move clip at time: %1 on track %2", m_document->timecode().getTimecodeFromFrames(start.startPos.frames(m_document->fps())), start.track), ErrorMessage);
3943 kDebug() << "---------------- ERROR, CANNOT find clip to resize at... "; // << startPos;
3946 if (item->parentItem()) {
3947 // Item is part of a group, reset group
3948 resetSelectionGroup();
3951 bool snap = KdenliveSettings::snaptopoints();
3952 KdenliveSettings::setSnaptopoints(false);
3953 if (resizeClipStart) {
3954 ItemInfo clipinfo = item->info();
3955 clipinfo.track = m_document->tracksCount() - clipinfo.track;
3956 bool success = m_document->renderer()->mltResizeClipStart(clipinfo, end.startPos - clipinfo.startPos);
3958 kDebug() << "RESIZE CLP STRAT TO:" << end.startPos.frames(m_document->fps()) << ", OLD ST: " << start.startPos.frames(25);
3959 item->resizeStart((int) end.startPos.frames(m_document->fps()));
3960 updatePositionEffects(item, clipinfo);
3961 } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
3963 ItemInfo clipinfo = item->info();
3964 clipinfo.track = m_document->tracksCount() - clipinfo.track;
3965 bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, end.endPos - clipinfo.startPos);
3967 item->resizeEnd((int) end.endPos.frames(m_document->fps()));
3968 updatePositionEffects(item, clipinfo);
3969 } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
3971 if (!resizeClipStart && end.cropStart != start.cropStart) {
3972 kDebug() << "// RESIZE CROP, DIFF: " << (end.cropStart - start.cropStart).frames(25);
3973 ItemInfo clipinfo = end;
3974 clipinfo.track = m_document->tracksCount() - end.track;
3975 bool success = m_document->renderer()->mltResizeClipCrop(clipinfo, end.cropStart - start.cropStart);
3977 item->setCropStart(end.cropStart);
3978 item->resetThumbs(true);
3981 m_document->renderer()->doRefresh();
3982 KdenliveSettings::setSnaptopoints(snap);
3983 setDocumentModified();
3986 void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo oldInfo, int pos, bool check)
3988 if (pos == oldInfo.startPos.frames(m_document->fps()))
3990 bool snap = KdenliveSettings::snaptopoints();
3992 KdenliveSettings::setSnaptopoints(false);
3993 item->resizeStart(pos);
3994 if (item->startPos().frames(m_document->fps()) != pos) {
3995 item->resizeStart(oldInfo.startPos.frames(m_document->fps()));
3996 emit displayMessage(i18n("Not possible to resize"), ErrorMessage);
3997 KdenliveSettings::setSnaptopoints(snap);
4000 KdenliveSettings::setSnaptopoints(snap);
4002 ItemInfo info = item->info();
4003 if (item->type() == AVWIDGET) {
4004 ItemInfo resizeinfo = oldInfo;
4005 resizeinfo.track = m_document->tracksCount() - resizeinfo.track;
4006 bool success = m_document->renderer()->mltResizeClipStart(resizeinfo, item->startPos() - oldInfo.startPos);
4008 QUndoCommand *resizeCommand = new QUndoCommand();
4009 resizeCommand->setText(i18n("Resize clip"));
4011 // Check if there is an automatic transition on that clip (lower track)
4012 Transition *transition = getTransitionItemAtStart(oldInfo.startPos, oldInfo.track);
4013 if (transition && transition->isAutomatic()) {
4014 ItemInfo trInfo = transition->info();
4015 ItemInfo newTrInfo = trInfo;
4016 newTrInfo.startPos = item->startPos();
4017 if (newTrInfo.startPos < newTrInfo.endPos)
4018 new MoveTransitionCommand(this, trInfo, newTrInfo, true, resizeCommand);
4020 // Check if there is an automatic transition on that clip (upper track)
4021 transition = getTransitionItemAtStart(oldInfo.startPos, oldInfo.track - 1);
4022 if (transition && transition->isAutomatic() && (m_document->tracksCount() - transition->transitionEndTrack()) == oldInfo.track) {
4023 ItemInfo trInfo = transition->info();
4024 ItemInfo newTrInfo = trInfo;
4025 newTrInfo.startPos = item->startPos();
4026 ClipItem * upperClip = getClipItemAt(oldInfo.startPos, oldInfo.track - 1);
4027 if ((!upperClip || !upperClip->baseClip()->isTransparent()) && newTrInfo.startPos < newTrInfo.endPos)
4028 new MoveTransitionCommand(this, trInfo, newTrInfo, true, resizeCommand);
4031 ClipItem *clip = static_cast < ClipItem * >(item);
4032 updatePositionEffects(clip, oldInfo);
4036 QDomElement root = doc.createElement("list");
4037 doc.appendChild(root);
4038 QList <int> indexes;
4039 for (int i = 0; i < clip->effectsCount(); i++) {
4040 QDomElement effect = clip->effectAt(i);
4041 if (EffectsList::hasKeyFrames(effect)) {
4042 doc.appendChild(doc.importNode(effect, true));
4047 if (clip->checkEffectsKeyframesPos(oldInfo.cropStart.frames(m_document->fps()), clip->cropStart().frames(m_document->fps()), true)) {
4048 // Keyframes were modified, updateClip
4049 QDomNodeList effs = doc.elementsByTagName("effect");
4051 // Since we must always resize clip before updating the keyframes, we
4052 // put a resize command before & after checking keyframes so that
4053 // we are sure the resize is performed before whenever we do or undo the action
4055 new ResizeClipCommand(this, oldInfo, info, false, true, resizeCommand);
4056 for (int i = 0; i < indexes.count(); i++) {
4057 new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effs.at(i).cloneNode().toElement(), clip->effectAt(indexes.at(i)), indexes.at(i), false, resizeCommand);
4058 updateEffect(m_document->tracksCount() - clip->track(), clip->startPos(), clip->effectAt(indexes.at(i)), indexes.at(i));
4060 new ResizeClipCommand(this, oldInfo, info, false, true, resizeCommand);
4061 emit clipItemSelected(clip);
4063 new ResizeClipCommand(this, oldInfo, info, false, false, resizeCommand);
4066 m_commandStack->push(resizeCommand);
4068 KdenliveSettings::setSnaptopoints(false);
4069 item->resizeStart((int) oldInfo.startPos.frames(m_document->fps()));
4070 KdenliveSettings::setSnaptopoints(snap);
4071 emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
4073 } else if (item->type() == TRANSITIONWIDGET) {
4074 Transition *transition = static_cast <Transition *>(item);
4075 if (!m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_document->tracksCount() - oldInfo.track), (int)(m_document->tracksCount() - oldInfo.track), transition->transitionEndTrack(), oldInfo.startPos, oldInfo.endPos, info.startPos, info.endPos)) {
4076 // Cannot resize transition
4077 KdenliveSettings::setSnaptopoints(false);
4078 transition->resizeStart((int) oldInfo.startPos.frames(m_document->fps()));
4079 KdenliveSettings::setSnaptopoints(snap);
4080 emit displayMessage(i18n("Cannot resize transition"), ErrorMessage);
4082 MoveTransitionCommand *command = new MoveTransitionCommand(this, oldInfo, info, false);
4083 m_commandStack->push(command);
4087 if (item->parentItem() && item->parentItem() != m_selectionGroup)
4088 rebuildGroup(static_cast <AbstractGroupItem *>(item->parentItem()));
4091 void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldInfo, int pos, bool check)
4093 if (pos == oldInfo.endPos.frames(m_document->fps()))
4095 bool snap = KdenliveSettings::snaptopoints();
4097 KdenliveSettings::setSnaptopoints(false);
4098 item->resizeEnd(pos);
4099 if (item->endPos().frames(m_document->fps()) != pos) {
4100 item->resizeEnd(oldInfo.endPos.frames(m_document->fps()));
4101 emit displayMessage(i18n("Not possible to resize"), ErrorMessage);
4102 KdenliveSettings::setSnaptopoints(snap);
4105 KdenliveSettings::setSnaptopoints(snap);
4107 ItemInfo info = item->info();
4108 if (item->type() == AVWIDGET) {
4109 ItemInfo resizeinfo = info;
4110 resizeinfo.track = m_document->tracksCount() - resizeinfo.track;
4111 bool success = m_document->renderer()->mltResizeClipEnd(resizeinfo, resizeinfo.endPos - resizeinfo.startPos);
4113 QUndoCommand *resizeCommand = new QUndoCommand();
4114 resizeCommand->setText(i18n("Resize clip"));
4116 // Check if there is an automatic transition on that clip (lower track)
4117 Transition *tr = getTransitionItemAtEnd(oldInfo.endPos, oldInfo.track);
4118 if (tr && tr->isAutomatic()) {
4119 ItemInfo trInfo = tr->info();
4120 ItemInfo newTrInfo = trInfo;
4121 newTrInfo.endPos = item->endPos();
4122 if (newTrInfo.endPos > newTrInfo.startPos)
4123 new MoveTransitionCommand(this, trInfo, newTrInfo, true, resizeCommand);
4126 // Check if there is an automatic transition on that clip (upper track)
4127 tr = getTransitionItemAtEnd(oldInfo.endPos, oldInfo.track - 1);
4128 if (tr && tr->isAutomatic() && (m_document->tracksCount() - tr->transitionEndTrack()) == oldInfo.track) {
4129 ItemInfo trInfo = tr->info();
4130 ItemInfo newTrInfo = trInfo;
4131 newTrInfo.endPos = item->endPos();
4132 ClipItem * upperClip = getClipItemAtEnd(oldInfo.endPos, oldInfo.track - 1);
4133 if ((!upperClip || !upperClip->baseClip()->isTransparent()) && newTrInfo.endPos > newTrInfo.startPos)
4134 new MoveTransitionCommand(this, trInfo, newTrInfo, true, resizeCommand);
4139 ClipItem *clip = static_cast < ClipItem * >(item);
4141 QDomElement root = doc.createElement("list");
4142 doc.appendChild(root);
4143 QList <int> indexes;
4144 for (int i = 0; i < clip->effectsCount(); i++) {
4145 QDomElement effect = clip->effectAt(i);
4146 if (EffectsList::hasKeyFrames(effect)) {
4147 doc.appendChild(doc.importNode(effect, true));
4152 if (clip->checkEffectsKeyframesPos((oldInfo.cropStart + oldInfo.endPos - oldInfo.startPos).frames(m_document->fps()) - 1, (clip->cropStart() + clip->cropDuration()).frames(m_document->fps()) - 1, false)) {
4153 // Keyframes were modified, updateClip
4154 QDomNodeList effs = doc.elementsByTagName("effect");
4156 // Since we must always resize clip before updating the keyframes, we
4157 // put a resize command before & after checking keyframes so that
4158 // we are sure the resize is performed before whenever we do or undo the action
4160 new ResizeClipCommand(this, oldInfo, info, false, true, resizeCommand);
4161 for (int i = 0; i < indexes.count(); i++) {
4162 new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effs.at(i).cloneNode().toElement(), clip->effectAt(indexes.at(i)), indexes.at(i), false, resizeCommand);
4163 updateEffect(m_document->tracksCount() - clip->track(), clip->startPos(), clip->effectAt(indexes.at(i)), indexes.at(i));
4165 new ResizeClipCommand(this, oldInfo, info, false, true, resizeCommand);
4166 emit clipItemSelected(clip);
4168 new ResizeClipCommand(this, oldInfo, info, false, false, resizeCommand);
4171 m_commandStack->push(resizeCommand);
4172 updatePositionEffects(clip, oldInfo);
4174 KdenliveSettings::setSnaptopoints(false);
4175 item->resizeEnd((int) oldInfo.endPos.frames(m_document->fps()));
4176 KdenliveSettings::setSnaptopoints(true);
4177 emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
4179 } else if (item->type() == TRANSITIONWIDGET) {
4180 Transition *transition = static_cast <Transition *>(item);
4181 if (!m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_document->tracksCount() - oldInfo.track), (int)(m_document->tracksCount() - oldInfo.track), transition->transitionEndTrack(), oldInfo.startPos, oldInfo.endPos, info.startPos, info.endPos)) {
4182 // Cannot resize transition
4183 KdenliveSettings::setSnaptopoints(false);
4184 transition->resizeEnd((int) oldInfo.endPos.frames(m_document->fps()));
4185 KdenliveSettings::setSnaptopoints(true);
4186 emit displayMessage(i18n("Cannot resize transition"), ErrorMessage);
4188 MoveTransitionCommand *command = new MoveTransitionCommand(this, oldInfo, info, false);
4189 m_commandStack->push(command);
4192 if (item->parentItem() && item->parentItem() != m_selectionGroup)
4193 rebuildGroup(static_cast <AbstractGroupItem *>(item->parentItem()));
4196 void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
4198 int end = item->fadeIn();
4200 // there is a fade in effect
4201 int effectPos = item->hasEffect("volume", "fadein");
4202 if (effectPos != -1) {
4203 QDomElement oldeffect = item->effectAt(effectPos);
4204 int start = item->cropStart().frames(m_document->fps());
4205 int max = item->cropDuration().frames(m_document->fps());
4207 // Make sure the fade effect is not longer than the clip
4208 item->setFadeIn(max);
4209 end = item->fadeIn();
4212 EffectsList::setParameter(oldeffect, "in", QString::number(start));
4213 EffectsList::setParameter(oldeffect, "out", QString::number(end));
4214 if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), item->getEffectArgs(oldeffect)))
4215 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
4216 // if fade effect is displayed, update the effect edit widget with new clip duration
4217 if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
4219 effectPos = item->hasEffect("brightness", "fade_from_black");
4220 if (effectPos != -1) {
4221 QDomElement oldeffect = item->effectAt(effectPos);
4222 int start = item->cropStart().frames(m_document->fps());
4223 int max = item->cropDuration().frames(m_document->fps());
4225 // Make sure the fade effect is not longer than the clip
4226 item->setFadeIn(max);
4227 end = item->fadeIn();
4230 EffectsList::setParameter(oldeffect, "in", QString::number(start));
4231 EffectsList::setParameter(oldeffect, "out", QString::number(end));
4232 if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), item->getEffectArgs(oldeffect)))
4233 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
4234 // if fade effect is displayed, update the effect edit widget with new clip duration
4235 if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
4238 int start = item->fadeOut();
4240 // there is a fade out effect
4241 int effectPos = item->hasEffect("volume", "fadeout");
4242 if (effectPos != -1) {
4243 QDomElement oldeffect = item->effectAt(effectPos);
4244 int max = item->cropDuration().frames(m_document->fps());
4245 int end = max + item->cropStart().frames(m_document->fps());
4247 // Make sure the fade effect is not longer than the clip
4248 item->setFadeOut(max);
4249 start = item->fadeOut();
4251 start = end - start;
4252 EffectsList::setParameter(oldeffect, "in", QString::number(start));
4253 EffectsList::setParameter(oldeffect, "out", QString::number(end));
4254 if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), item->getEffectArgs(oldeffect)))
4255 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
4256 // if fade effect is displayed, update the effect edit widget with new clip duration
4257 if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
4259 effectPos = item->hasEffect("brightness", "fade_to_black");
4260 if (effectPos != -1) {
4261 QDomElement oldeffect = item->effectAt(effectPos);
4262 int max = item->cropDuration().frames(m_document->fps());
4263 int end = max + item->cropStart().frames(m_document->fps());
4265 // Make sure the fade effect is not longer than the clip
4266 item->setFadeOut(max);
4267 start = item->fadeOut();
4269 start = end - start;
4270 EffectsList::setParameter(oldeffect, "in", QString::number(start));
4271 EffectsList::setParameter(oldeffect, "out", QString::number(end));
4272 if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), item->getEffectArgs(oldeffect)))
4273 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
4274 // if fade effect is displayed, update the effect edit widget with new clip duration
4275 if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
4279 int effectPos = item->hasEffect("freeze", "freeze");
4280 if (effectPos != -1) {
4281 // Freeze effect needs to be adjusted with clip resize
4282 int diff = (info.startPos - item->startPos()).frames(m_document->fps());
4283 QDomElement eff = item->getEffectAt(effectPos);
4284 if (!eff.isNull() && diff != 0) {
4285 int freeze_pos = EffectsList::parameter(eff, "frame").toInt() + diff;
4286 EffectsList::setParameter(eff, "frame", QString::number(freeze_pos));
4287 if (item->isSelected() && item->selectedEffect().attribute("id") == "freeze") {
4288 emit clipItemSelected(item, item->selectedEffectIndex());
4293 effectPos = item->hasEffect("affine", "pan_zoom");
4294 if (effectPos != -1) {
4295 QDomElement oldeffect = item->effectAt(effectPos);
4296 int start = item->cropStart().frames(m_document->fps());
4297 int max = start + item->cropDuration().frames(m_document->fps());
4302 oldeffect.setAttribute("in", start);
4303 oldeffect.setAttribute("out", max);
4304 if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), item->getEffectArgs(oldeffect)))
4305 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
4306 // if effect is displayed, update the effect edit widget with new clip duration
4307 if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
4311 double CustomTrackView::getSnapPointForPos(double pos)
4313 return m_scene->getSnapPointForPos(pos, KdenliveSettings::snaptopoints());
4316 void CustomTrackView::updateSnapPoints(AbstractClipItem *selected, QList <GenTime> offsetList, bool skipSelectedItems)
4318 QList <GenTime> snaps;
4319 if (selected && offsetList.isEmpty()) offsetList.append(selected->cropDuration());
4320 QList<QGraphicsItem *> itemList = items();
4321 for (int i = 0; i < itemList.count(); i++) {
4322 if (itemList.at(i) == selected) continue;
4323 if (skipSelectedItems && itemList.at(i)->isSelected()) continue;
4324 if (itemList.at(i)->type() == AVWIDGET) {
4325 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
4326 GenTime start = item->startPos();
4327 GenTime end = item->endPos();
4328 snaps.append(start);
4330 if (!offsetList.isEmpty()) {
4331 for (int j = 0; j < offsetList.size(); j++) {
4332 if (start > offsetList.at(j)) snaps.append(start - offsetList.at(j));
4333 if (end > offsetList.at(j)) snaps.append(end - offsetList.at(j));
4337 QList < GenTime > markers = item->snapMarkers();
4338 for (int j = 0; j < markers.size(); ++j) {
4339 GenTime t = markers.at(j);
4341 if (!offsetList.isEmpty()) {
4342 for (int k = 0; k < offsetList.size(); k++) {
4343 if (t > offsetList.at(k)) snaps.append(t - offsetList.at(k));
4347 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
4348 Transition *transition = static_cast <Transition*>(itemList.at(i));
4349 GenTime start = transition->startPos();
4350 GenTime end = transition->endPos();
4351 snaps.append(start);
4353 if (!offsetList.isEmpty()) {
4354 for (int j = 0; j < offsetList.size(); j++) {
4355 if (start > offsetList.at(j)) snaps.append(start - offsetList.at(j));
4356 if (end > offsetList.at(j)) snaps.append(end - offsetList.at(j));
4362 // add cursor position
4363 GenTime pos = GenTime(m_cursorPos, m_document->fps());
4365 if (!offsetList.isEmpty()) {
4366 for (int j = 0; j < offsetList.size(); j++) {
4367 snaps.append(pos - offsetList.at(j));
4372 for (int i = 0; i < m_guides.count(); i++) {
4373 snaps.append(m_guides.at(i)->position());
4374 if (!offsetList.isEmpty()) {
4375 for (int j = 0; j < offsetList.size(); j++) {
4376 snaps.append(m_guides.at(i)->position() - offsetList.at(j));
4382 m_scene->setSnapList(snaps);
4383 //for (int i = 0; i < m_snapPoints.size(); ++i)
4384 // kDebug() << "SNAP POINT: " << m_snapPoints.at(i).frames(25);
4387 void CustomTrackView::slotSeekToPreviousSnap()
4389 updateSnapPoints(NULL);
4390 GenTime res = m_scene->previousSnapPoint(GenTime(m_cursorPos, m_document->fps()));
4391 setCursorPos((int) res.frames(m_document->fps()));
4395 void CustomTrackView::slotSeekToNextSnap()
4397 updateSnapPoints(NULL);
4398 GenTime res = m_scene->nextSnapPoint(GenTime(m_cursorPos, m_document->fps()));
4399 setCursorPos((int) res.frames(m_document->fps()));
4403 void CustomTrackView::clipStart()
4405 AbstractClipItem *item = getMainActiveClip();
4407 setCursorPos((int) item->startPos().frames(m_document->fps()));
4412 void CustomTrackView::clipEnd()
4414 AbstractClipItem *item = getMainActiveClip();
4416 setCursorPos((int) item->endPos().frames(m_document->fps()) - 1);
4421 void CustomTrackView::slotAddClipMarker(const QString &id, GenTime t, QString c)
4423 QString oldcomment = m_document->clipManager()->getClipById(id)->markerComment(t);
4424 AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, c, id, t);
4425 m_commandStack->push(command);
4428 void CustomTrackView::slotDeleteClipMarker(const QString &comment, const QString &id, const GenTime &position)
4430 AddMarkerCommand *command = new AddMarkerCommand(this, comment, QString(), id, position);
4431 m_commandStack->push(command);
4434 void CustomTrackView::slotDeleteAllClipMarkers(const QString &id)
4436 DocClipBase *base = m_document->clipManager()->getClipById(id);
4437 QList <CommentedTime> markers = base->commentedSnapMarkers();
4439 if (markers.isEmpty()) {
4440 emit displayMessage(i18n("Clip has no markers"), ErrorMessage);
4443 QUndoCommand *deleteMarkers = new QUndoCommand();
4444 deleteMarkers->setText("Delete clip markers");
4446 for (int i = 0; i < markers.size(); i++) {
4447 new AddMarkerCommand(this, markers.at(i).comment(), QString(), id, markers.at(i).time(), deleteMarkers);
4449 m_commandStack->push(deleteMarkers);
4452 void CustomTrackView::addMarker(const QString &id, const GenTime &pos, const QString comment)
4454 DocClipBase *base = m_document->clipManager()->getClipById(id);
4455 if (!comment.isEmpty()) base->addSnapMarker(pos, comment);
4456 else base->deleteSnapMarker(pos);
4457 emit updateClipMarkers(base);
4458 setDocumentModified();
4459 viewport()->update();
4462 int CustomTrackView::hasGuide(int pos, int offset)
4464 for (int i = 0; i < m_guides.count(); i++) {
4465 int guidePos = m_guides.at(i)->position().frames(m_document->fps());
4466 if (qAbs(guidePos - pos) <= offset) return guidePos;
4467 else if (guidePos > pos) return -1;
4472 void CustomTrackView::buildGuidesMenu(QMenu *goMenu) const
4476 double fps = m_document->fps();
4477 for (int i = 0; i < m_guides.count(); i++) {
4478 act = goMenu->addAction(m_guides.at(i)->label() + "/" + Timecode::getStringTimecode(m_guides.at(i)->position().frames(fps), fps));
4479 act->setData(m_guides.at(i)->position().frames(m_document->fps()));
4481 goMenu->setEnabled(!m_guides.isEmpty());
4484 void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const QString &comment)
4486 if (oldPos > GenTime() && pos > GenTime()) {
4488 for (int i = 0; i < m_guides.count(); i++) {
4489 if (m_guides.at(i)->position() == oldPos) {
4490 Guide *item = m_guides.at(i);
4491 item->updateGuide(pos, comment);
4495 } else if (pos > GenTime()) addGuide(pos, comment);
4499 for (int i = 0; i < m_guides.count(); i++) {
4500 if (m_guides.at(i)->position() == oldPos) {
4501 delete m_guides.takeAt(i);
4506 if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
4508 qSort(m_guides.begin(), m_guides.end(), sortGuidesList);
4509 m_document->syncGuides(m_guides);
4512 bool CustomTrackView::addGuide(const GenTime pos, const QString &comment)
4514 for (int i = 0; i < m_guides.count(); i++) {
4515 if (m_guides.at(i)->position() == pos) {
4516 emit displayMessage(i18n("A guide already exists at position %1", m_document->timecode().getTimecodeFromFrames(pos.frames(m_document->fps()))), ErrorMessage);
4520 Guide *g = new Guide(this, pos, comment, m_tracksHeight * m_document->tracksCount() * matrix().m22());
4521 scene()->addItem(g);
4523 qSort(m_guides.begin(), m_guides.end(), sortGuidesList);
4524 m_document->syncGuides(m_guides);
4528 void CustomTrackView::slotAddGuide()
4530 CommentedTime marker(GenTime(m_cursorPos, m_document->fps()), i18n("Guide"));
4531 MarkerDialog d(NULL, marker, m_document->timecode(), i18n("Add Guide"), this);
4532 if (d.exec() != QDialog::Accepted) return;
4533 if (addGuide(d.newMarker().time(), d.newMarker().comment())) {
4534 EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), d.newMarker().time(), d.newMarker().comment(), false);
4535 m_commandStack->push(command);
4539 void CustomTrackView::slotEditGuide(int guidePos)
4542 if (guidePos == -1) pos = GenTime(m_cursorPos, m_document->fps());
4543 else pos = GenTime(guidePos, m_document->fps());
4545 for (int i = 0; i < m_guides.count(); i++) {
4546 if (m_guides.at(i)->position() == pos) {
4547 slotEditGuide(m_guides.at(i)->info());
4552 if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
4555 void CustomTrackView::slotEditGuide(CommentedTime guide)
4557 MarkerDialog d(NULL, guide, m_document->timecode(), i18n("Edit Guide"), this);
4558 if (d.exec() == QDialog::Accepted) {
4559 EditGuideCommand *command = new EditGuideCommand(this, guide.time(), guide.comment(), d.newMarker().time(), d.newMarker().comment(), true);
4560 m_commandStack->push(command);
4565 void CustomTrackView::slotEditTimeLineGuide()
4567 if (m_dragGuide == NULL) return;
4568 CommentedTime guide = m_dragGuide->info();
4569 MarkerDialog d(NULL, guide, m_document->timecode(), i18n("Edit Guide"), this);
4570 if (d.exec() == QDialog::Accepted) {
4571 EditGuideCommand *command = new EditGuideCommand(this, guide.time(), guide.comment(), d.newMarker().time(), d.newMarker().comment(), true);
4572 m_commandStack->push(command);
4576 void CustomTrackView::slotDeleteGuide(int guidePos)
4579 if (guidePos == -1) pos = GenTime(m_cursorPos, m_document->fps());
4580 else pos = GenTime(guidePos, m_document->fps());
4582 for (int i = 0; i < m_guides.count(); i++) {
4583 if (m_guides.at(i)->position() == pos) {
4584 EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true);
4585 m_commandStack->push(command);
4590 if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
4594 void CustomTrackView::slotDeleteTimeLineGuide()
4596 if (m_dragGuide == NULL) return;
4597 EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), GenTime(), QString(), true);
4598 m_commandStack->push(command);
4602 void CustomTrackView::slotDeleteAllGuides()
4604 QUndoCommand *deleteAll = new QUndoCommand();
4605 deleteAll->setText("Delete all guides");
4606 for (int i = 0; i < m_guides.count(); i++) {
4607 new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true, deleteAll);
4609 m_commandStack->push(deleteAll);
4612 void CustomTrackView::setTool(PROJECTTOOL tool)
4617 void CustomTrackView::setScale(double scaleFactor, double verticalScale)
4620 newmatrix = newmatrix.scale(scaleFactor, verticalScale);
4621 m_scene->setScale(scaleFactor, verticalScale);
4622 removeTipAnimation();
4623 double verticalPos = mapToScene(QPoint(0, viewport()->height() / 2)).y();
4624 bool adjust = false;
4625 if (verticalScale != matrix().m22()) adjust = true;
4626 setMatrix(newmatrix);
4628 double newHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
4629 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight);
4630 for (int i = 0; i < m_guides.count(); i++) {
4631 QLineF l = m_guides.at(i)->line();
4632 l.setP2(QPointF(l.x2(), newHeight));
4633 m_guides.at(i)->setLine(l);
4635 setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
4638 int diff = sceneRect().width() - m_projectDuration;
4639 if (diff * newmatrix.m11() < 50) {
4640 if (newmatrix.m11() < 0.4)
4641 setSceneRect(0, 0, (m_projectDuration + 100 / newmatrix.m11()), sceneRect().height());
4643 setSceneRect(0, 0, (m_projectDuration + 300), sceneRect().height());
4645 centerOn(QPointF(cursorPos(), verticalPos));
4648 void CustomTrackView::slotRefreshGuides()
4650 if (KdenliveSettings::showmarkers()) {
4651 for (int i = 0; i < m_guides.count(); i++)
4652 m_guides.at(i)->update();
4656 void CustomTrackView::drawBackground(QPainter * painter, const QRectF &rect)
4658 //kDebug() << "// DRAW BG: " << rect.width();
4659 painter->setClipRect(rect);
4660 KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window);
4661 QPen pen1 = painter->pen();
4662 pen1.setColor(scheme.shade(KColorScheme::DarkShade));
4663 painter->setPen(pen1);
4664 double min = rect.left();
4665 double max = rect.right();
4666 painter->drawLine(QPointF(min, 0), QPointF(max, 0));
4667 int maxTrack = m_document->tracksCount();
4668 QColor lockedColor = scheme.background(KColorScheme::NegativeBackground).color();
4669 QColor audioColor = palette().alternateBase().color();
4670 QColor base = scheme.background(KColorScheme::NormalBackground).color();
4671 for (int i = 0; i < maxTrack; i++) {
4672 TrackInfo info = m_document->trackInfoAt(maxTrack - i - 1);
4673 if (info.isLocked || info.type == AUDIOTRACK || i == m_selectedTrack) {
4674 const QRectF track(min, m_tracksHeight * i + 1, max - min, m_tracksHeight - 1);
4675 if (i == m_selectedTrack)
4676 painter->fillRect(track, scheme.background(KColorScheme::ActiveBackground).color());
4678 painter->fillRect(track, info.isLocked ? lockedColor : audioColor);
4680 painter->drawLine(QPointF(min, m_tracksHeight *(i + 1)), QPointF(max, m_tracksHeight *(i + 1)));
4682 int lowerLimit = m_tracksHeight * maxTrack + 1;
4683 if (height() > lowerLimit) {
4684 const QRectF bg(min, lowerLimit, max - min, height() - lowerLimit);
4685 painter->fillRect(bg, base);
4689 bool CustomTrackView::findString(const QString &text)
4692 for (int i = 0; i < m_searchPoints.size(); ++i) {
4693 marker = m_searchPoints.at(i).comment();
4694 if (marker.contains(text, Qt::CaseInsensitive)) {
4695 setCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()), true);
4696 int vert = verticalScrollBar()->value();
4697 int hor = cursorPos();
4698 ensureVisible(hor, vert + 10, 2, 2, 50, 0);
4706 void CustomTrackView::selectFound(QString track, QString pos)
4708 setCursorPos(m_document->timecode().getFrameCount(pos), true);
4709 slotSelectTrack(track.toInt());
4711 int vert = verticalScrollBar()->value();
4712 int hor = cursorPos();
4713 ensureVisible(hor, vert + 10, 2, 2, 50, 0);
4716 bool CustomTrackView::findNextString(const QString &text)
4719 for (int i = m_findIndex + 1; i < m_searchPoints.size(); ++i) {
4720 marker = m_searchPoints.at(i).comment();
4721 if (marker.contains(text, Qt::CaseInsensitive)) {
4722 setCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()), true);
4723 int vert = verticalScrollBar()->value();
4724 int hor = cursorPos();
4725 ensureVisible(hor, vert + 10, 2, 2, 50, 0);
4734 void CustomTrackView::initSearchStrings()
4736 m_searchPoints.clear();
4737 QList<QGraphicsItem *> itemList = items();
4738 for (int i = 0; i < itemList.count(); i++) {
4739 // parse all clip names
4740 if (itemList.at(i)->type() == AVWIDGET) {
4741 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
4742 GenTime start = item->startPos();
4743 CommentedTime t(start, item->clipName());
4744 m_searchPoints.append(t);
4745 // add all clip markers
4746 QList < CommentedTime > markers = item->commentedSnapMarkers();
4747 m_searchPoints += markers;
4752 for (int i = 0; i < m_guides.count(); i++)
4753 m_searchPoints.append(m_guides.at(i)->info());
4755 qSort(m_searchPoints);
4758 void CustomTrackView::clearSearchStrings()
4760 m_searchPoints.clear();
4764 QList<ItemInfo> CustomTrackView::findId(const QString &clipId)
4766 QList<ItemInfo> matchingInfo;
4767 QList<QGraphicsItem *> itemList = items();
4768 for (int i = 0; i < itemList.count(); i++) {
4769 if (itemList.at(i)->type() == AVWIDGET) {
4770 ClipItem *item = (ClipItem *)itemList.at(i);
4771 if (item->clipProducer() == clipId)
4772 matchingInfo << item->info();
4775 return matchingInfo;
4778 void CustomTrackView::copyClip()
4780 qDeleteAll(m_copiedItems);
4781 m_copiedItems.clear();
4782 QList<QGraphicsItem *> itemList = scene()->selectedItems();
4783 if (itemList.count() == 0) {
4784 emit displayMessage(i18n("Select a clip before copying"), ErrorMessage);
4787 for (int i = 0; i < itemList.count(); i++) {
4788 if (itemList.at(i)->type() == AVWIDGET) {
4789 ClipItem *clip = static_cast <ClipItem *>(itemList.at(i));
4790 ClipItem *clone = clip->clone(clip->info());
4791 m_copiedItems.append(clone);
4792 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
4793 Transition *dup = static_cast <Transition *>(itemList.at(i));
4794 m_copiedItems.append(dup->clone());
4799 bool CustomTrackView::canBePastedTo(ItemInfo info, int type) const
4801 if (m_scene->editMode() != NORMALEDIT) {
4802 // If we are in overwrite mode, always allow the move
4805 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));
4806 QList<QGraphicsItem *> collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect);
4807 for (int i = 0; i < collisions.count(); i++) {
4808 if (collisions.at(i)->type() == type) return false;
4813 bool CustomTrackView::canBePastedTo(QList <ItemInfo> infoList, int type) const
4816 for (int i = 0; i < infoList.count(); i++) {
4817 const QRectF rect((double) infoList.at(i).startPos.frames(m_document->fps()), (double)(infoList.at(i).track * m_tracksHeight + 1), (double)(infoList.at(i).endPos - infoList.at(i).startPos).frames(m_document->fps()), (double)(m_tracksHeight - 1));
4820 QList<QGraphicsItem *> collisions = scene()->items(path);
4821 for (int i = 0; i < collisions.count(); i++) {
4822 if (collisions.at(i)->type() == type) return false;
4827 bool CustomTrackView::canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const
4829 for (int i = 0; i < items.count(); i++) {
4830 ItemInfo info = items.at(i)->info();
4831 info.startPos += offset;
4832 info.endPos += offset;
4833 info.track += trackOffset;
4834 if (!canBePastedTo(info, items.at(i)->type())) return false;
4839 bool CustomTrackView::canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const
4841 QPainterPath movePath;
4842 movePath.moveTo(0, 0);
4844 for (int i = 0; i < items.count(); i++) {
4845 ItemInfo info = items.at(i)->info();
4846 info.startPos = info.startPos + offset;
4847 info.endPos = info.endPos + offset;
4848 info.track = info.track + trackOffset;
4849 if (info.startPos < GenTime()) {
4850 // No clip should go below 0
4853 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));
4854 movePath.addRect(rect);
4856 QList<QGraphicsItem *> collisions = scene()->items(movePath, Qt::IntersectsItemBoundingRect);
4857 for (int i = 0; i < collisions.count(); i++) {
4858 if ((collisions.at(i)->type() == AVWIDGET || collisions.at(i)->type() == TRANSITIONWIDGET) && !items.contains(static_cast <AbstractClipItem *>(collisions.at(i)))) {
4859 kDebug() << " //////////// CLIP COLLISION, MOVE NOT ALLOWED";
4867 void CustomTrackView::pasteClip()
4869 if (m_copiedItems.count() == 0) {
4870 emit displayMessage(i18n("No clip copied"), ErrorMessage);
4874 if (m_menuPosition.isNull()) {
4875 position = mapFromGlobal(QCursor::pos());
4876 if (!contentsRect().contains(position) || mapToScene(position).y() / m_tracksHeight > m_document->tracksCount()) {
4877 emit displayMessage(i18n("Cannot paste selected clips"), ErrorMessage);
4880 } else position = m_menuPosition;
4882 GenTime pos = GenTime((int)(mapToScene(position).x()), m_document->fps());
4883 int track = (int)(mapToScene(position).y() / m_tracksHeight);
4885 GenTime leftPos = m_copiedItems.at(0)->startPos();
4886 int lowerTrack = m_copiedItems.at(0)->track();
4887 int upperTrack = m_copiedItems.at(0)->track();
4888 for (int i = 1; i < m_copiedItems.count(); i++) {
4889 if (m_copiedItems.at(i)->startPos() < leftPos) leftPos = m_copiedItems.at(i)->startPos();
4890 if (m_copiedItems.at(i)->track() < lowerTrack) lowerTrack = m_copiedItems.at(i)->track();
4891 if (m_copiedItems.at(i)->track() > upperTrack) upperTrack = m_copiedItems.at(i)->track();
4894 GenTime offset = pos - leftPos;
4895 int trackOffset = track - lowerTrack;
4897 if (lowerTrack + trackOffset < 0) trackOffset = 0 - lowerTrack;
4898 if (upperTrack + trackOffset > m_document->tracksCount() - 1) trackOffset = m_document->tracksCount() - upperTrack - 1;
4899 if (!canBePasted(m_copiedItems, offset, trackOffset)) {
4900 emit displayMessage(i18n("Cannot paste selected clips"), ErrorMessage);
4903 QUndoCommand *pasteClips = new QUndoCommand();
4904 pasteClips->setText("Paste clips");
4906 for (int i = 0; i < m_copiedItems.count(); i++) {
4907 // parse all clip names
4908 if (m_copiedItems.at(i) && m_copiedItems.at(i)->type() == AVWIDGET) {
4909 ClipItem *clip = static_cast <ClipItem *>(m_copiedItems.at(i));
4910 ItemInfo info = clip->info();
4911 info.startPos += offset;
4912 info.endPos += offset;
4913 info.track += trackOffset;
4914 if (canBePastedTo(info, AVWIDGET)) {
4915 new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), info, clip->effectList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, true, false, pasteClips);
4916 } else emit displayMessage(i18n("Cannot paste clip to selected place"), ErrorMessage);
4917 } else if (m_copiedItems.at(i) && m_copiedItems.at(i)->type() == TRANSITIONWIDGET) {
4918 Transition *tr = static_cast <Transition *>(m_copiedItems.at(i));
4920 info.startPos = tr->startPos() + offset;
4921 info.endPos = tr->endPos() + offset;
4922 info.track = tr->track() + trackOffset;
4923 int transitionEndTrack;
4924 if (!tr->forcedTrack()) transitionEndTrack = getPreviousVideoTrack(info.track);
4925 else transitionEndTrack = tr->transitionEndTrack();
4926 if (canBePastedTo(info, TRANSITIONWIDGET)) {
4927 if (info.startPos >= info.endPos) {
4928 emit displayMessage(i18n("Invalid transition"), ErrorMessage);
4929 } else new AddTransitionCommand(this, info, transitionEndTrack, tr->toXML(), false, true, pasteClips);
4930 } else emit displayMessage(i18n("Cannot paste transition to selected place"), ErrorMessage);
4933 m_commandStack->push(pasteClips);
4936 void CustomTrackView::pasteClipEffects()
4938 if (m_copiedItems.count() != 1 || m_copiedItems.at(0)->type() != AVWIDGET) {
4939 emit displayMessage(i18n("You must copy exactly one clip before pasting effects"), ErrorMessage);
4942 ClipItem *clip = static_cast < ClipItem *>(m_copiedItems.at(0));
4944 QUndoCommand *paste = new QUndoCommand();
4945 paste->setText("Paste effects");
4947 QList<QGraphicsItem *> clips = scene()->selectedItems();
4950 for (int i = 0; i < clips.count(); ++i) {
4951 if (clips.at(i)->type() == GROUPWIDGET) {
4952 QList<QGraphicsItem *> children = clips.at(i)->childItems();
4953 for (int j = 0; j < children.count(); j++) {
4954 if (children.at(j)->type() == AVWIDGET && !clips.contains(children.at(j))) {
4955 clips.append(children.at(j));
4962 for (int i = 0; i < clips.count(); ++i) {
4963 if (clips.at(i)->type() == AVWIDGET) {
4964 ClipItem *item = static_cast < ClipItem *>(clips.at(i));
4965 for (int j = 0; j < clip->effectsCount(); j++) {
4966 QDomElement eff = clip->effectAt(j);
4967 if (eff.attribute("unique", "0") == "0" || item->hasEffect(eff.attribute("tag"), eff.attribute("id")) == -1) {
4968 adjustKeyfames(clip->cropStart(), item->cropStart(), item->cropDuration(), eff);
4969 new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), eff, true, paste);
4974 if (paste->childCount() > 0) m_commandStack->push(paste);
4977 //adjust effects (fades, ...)
4978 for (int i = 0; i < clips.count(); ++i) {
4979 if (clips.at(i)->type() == AVWIDGET) {
4980 ClipItem *item = static_cast < ClipItem *>(clips.at(i));
4981 updatePositionEffects(item, item->info());
4987 void CustomTrackView::adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime duration, QDomElement xml)
4989 // parse parameters to check if we need to adjust to the new crop start
4990 int diff = (newstart - oldstart).frames(m_document->fps());
4991 int max = (newstart + duration).frames(m_document->fps());
4992 QDomNodeList params = xml.elementsByTagName("parameter");
4993 for (int i = 0; i < params.count(); i++) {
4994 QDomElement e = params.item(i).toElement();
4995 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
4996 QString def = e.attribute("default");
4997 // Effect has a keyframe type parameter, we need to adjust the values
4998 QStringList keys = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
4999 QStringList newKeyFrames;
5000 foreach(const QString &str, keys) {
5001 int pos = str.section(':', 0, 0).toInt();
5002 double val = str.section(':', 1, 1).toDouble();
5005 newKeyFrames.append(QString::number(max) + ':' + QString::number(val));
5007 } else newKeyFrames.append(QString::number(pos) + ':' + QString::number(val));
5009 //kDebug()<<"ORIGIN: "<<keys<<", FIXED: "<<newKeyFrames;
5010 e.setAttribute("keyframes", newKeyFrames.join(";"));
5015 ClipItem *CustomTrackView::getClipUnderCursor() const
5017 QRectF rect((double) m_cursorPos, 0.0, 1.0, (double)(m_tracksHeight * m_document->tracksCount()));
5018 QList<QGraphicsItem *> collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect);
5019 for (int i = 0; i < collisions.count(); i++) {
5020 if (collisions.at(i)->type() == AVWIDGET) {
5021 return static_cast < ClipItem *>(collisions.at(i));
5027 AbstractClipItem *CustomTrackView::getMainActiveClip() const
5029 QList<QGraphicsItem *> clips = scene()->selectedItems();
5030 if (clips.isEmpty()) {
5031 return getClipUnderCursor();
5033 AbstractClipItem *item = NULL;
5034 for (int i = 0; i < clips.count(); ++i) {
5035 if (clips.at(i)->type() == AVWIDGET) {
5036 item = static_cast < AbstractClipItem *>(clips.at(i));
5037 if (clips.count() > 1 && item->startPos().frames(m_document->fps()) <= m_cursorPos && item->endPos().frames(m_document->fps()) >= m_cursorPos) break;
5040 if (item) return item;
5045 ClipItem *CustomTrackView::getActiveClipUnderCursor(bool allowOutsideCursor) const
5047 QList<QGraphicsItem *> clips = scene()->selectedItems();
5048 if (clips.isEmpty()) {
5049 return getClipUnderCursor();
5052 // remove all items in the list that are not clips
5053 for (int i = 0; i < clips.count();) {
5054 if (clips.at(i)->type() != AVWIDGET) clips.removeAt(i);
5057 if (clips.count() == 1 && allowOutsideCursor) return static_cast < ClipItem *>(clips.at(0));
5058 for (int i = 0; i < clips.count(); ++i) {
5059 if (clips.at(i)->type() == AVWIDGET) {
5060 item = static_cast < ClipItem *>(clips.at(i));
5061 if (item->startPos().frames(m_document->fps()) <= m_cursorPos && item->endPos().frames(m_document->fps()) >= m_cursorPos)
5069 void CustomTrackView::setInPoint()
5071 AbstractClipItem *clip = getActiveClipUnderCursor(true);
5073 if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) {
5076 emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
5080 prepareResizeClipStart(clip, clip->info(), m_cursorPos, true);
5083 void CustomTrackView::setOutPoint()
5085 AbstractClipItem *clip = getActiveClipUnderCursor(true);
5087 if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) {
5090 emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
5094 prepareResizeClipEnd(clip, clip->info(), m_cursorPos, true);
5097 void CustomTrackView::slotUpdateAllThumbs()
5099 if (!isEnabled()) return;
5100 QList<QGraphicsItem *> itemList = items();
5101 //if (itemList.isEmpty()) return;
5103 const QString thumbBase = m_document->projectFolder().path() + "/thumbs/";
5104 for (int i = 0; i < itemList.count(); i++) {
5105 if (itemList.at(i)->type() == AVWIDGET) {
5106 item = static_cast <ClipItem *>(itemList.at(i));
5107 if (item->clipType() != COLOR && item->clipType() != AUDIO) {
5108 // Check if we have a cached thumbnail
5109 if (item->clipType() == IMAGE || item->clipType() == TEXT) {
5110 QString thumb = thumbBase + item->baseClip()->getClipHash() + "_0.png";
5111 if (QFile::exists(thumb)) {
5113 if (pix.isNull()) KIO::NetAccess::del(KUrl(thumb), this);
5114 item->slotSetStartThumb(pix);
5117 QString startThumb = thumbBase + item->baseClip()->getClipHash() + '_';
5118 QString endThumb = startThumb;
5119 startThumb.append(QString::number(item->speedIndependantCropStart().frames(m_document->fps())) + ".png");
5120 endThumb.append(QString::number((item->speedIndependantCropStart() + item->speedIndependantCropDuration()).frames(m_document->fps()) - 1) + ".png");
5121 if (QFile::exists(startThumb)) {
5122 QPixmap pix(startThumb);
5123 if (pix.isNull()) KIO::NetAccess::del(KUrl(startThumb), this);
5124 item->slotSetStartThumb(pix);
5126 if (QFile::exists(endThumb)) {
5127 QPixmap pix(endThumb);
5128 if (pix.isNull()) KIO::NetAccess::del(KUrl(endThumb), this);
5129 item->slotSetEndThumb(pix);
5133 item->refreshClip(false);
5134 //qApp->processEvents();
5137 viewport()->update();
5140 void CustomTrackView::saveThumbnails()
5142 QList<QGraphicsItem *> itemList = items();
5144 QString thumbBase = m_document->projectFolder().path() + "/thumbs/";
5145 for (int i = 0; i < itemList.count(); i++) {
5146 if (itemList.at(i)->type() == AVWIDGET) {
5147 item = static_cast <ClipItem *>(itemList.at(i));
5148 if (item->clipType() != COLOR) {
5149 // Check if we have a cached thumbnail
5150 if (item->clipType() == IMAGE || item->clipType() == TEXT || item->clipType() == AUDIO) {
5151 QString thumb = thumbBase + item->baseClip()->getClipHash() + "_0.png";
5152 if (!QFile::exists(thumb)) {
5153 QPixmap pix(item->startThumb());
5157 QString startThumb = thumbBase + item->baseClip()->getClipHash() + '_';
5158 QString endThumb = startThumb;
5159 startThumb.append(QString::number(item->speedIndependantCropStart().frames(m_document->fps())) + ".png");
5160 endThumb.append(QString::number((item->speedIndependantCropStart() + item->speedIndependantCropDuration()).frames(m_document->fps()) - 1) + ".png");
5161 if (!QFile::exists(startThumb)) {
5162 QPixmap pix(item->startThumb());
5163 pix.save(startThumb);
5165 if (!QFile::exists(endThumb)) {
5166 QPixmap pix(item->endThumb());
5176 void CustomTrackView::slotInsertTrack(int ix)
5178 TrackDialog d(m_document, parentWidget());
5179 d.comboTracks->setCurrentIndex(ix);
5180 d.label->setText(i18n("Insert track"));
5181 d.setWindowTitle(i18n("Insert New Track"));
5183 if (d.exec() == QDialog::Accepted) {
5184 ix = d.comboTracks->currentIndex();
5185 if (d.before_select->currentIndex() == 1)
5188 info.isMute = false;
5189 info.isLocked = false;
5190 if (d.video_track->isChecked()) {
5191 info.type = VIDEOTRACK;
5192 info.isBlind = false;
5194 info.type = AUDIOTRACK;
5195 info.isBlind = true;
5197 AddTrackCommand *addTrack = new AddTrackCommand(this, ix, info, true);
5198 m_commandStack->push(addTrack);
5199 setDocumentModified();
5203 void CustomTrackView::slotDeleteTrack(int ix)
5205 if (m_document->tracksCount() < 2) return;
5206 TrackDialog d(m_document, parentWidget());
5207 d.comboTracks->setCurrentIndex(ix);
5208 d.label->setText(i18n("Delete track"));
5209 d.before_select->setHidden(true);
5210 d.setWindowTitle(i18n("Delete Track"));
5211 d.video_track->setHidden(true);
5212 d.audio_track->setHidden(true);
5213 if (d.exec() == QDialog::Accepted) {
5214 ix = d.comboTracks->currentIndex();
5215 TrackInfo info = m_document->trackInfoAt(m_document->tracksCount() - ix - 1);
5216 deleteTimelineTrack(ix, info);
5217 setDocumentModified();
5218 /*AddTrackCommand* command = new AddTrackCommand(this, ix, info, false);
5219 m_commandStack->push(command);*/
5223 void CustomTrackView::slotConfigTracks(int ix)
5225 TracksConfigDialog d(m_document, ix, parentWidget());
5226 if (d.exec() == QDialog::Accepted) {
5227 ConfigTracksCommand *configTracks = new ConfigTracksCommand(this, m_document->tracksList(), d.tracksList());
5228 m_commandStack->push(configTracks);
5229 QList <int> toDelete = d.deletedTracks();
5230 for (int i = 0; i < toDelete.count(); ++i) {
5231 TrackInfo info = m_document->trackInfoAt(m_document->tracksCount() - toDelete.at(i) + i - 1);
5232 deleteTimelineTrack(toDelete.at(i) - i, info);
5234 setDocumentModified();
5238 void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo)
5240 if (m_document->tracksCount() < 2) return;
5241 double startY = ix * m_tracksHeight + 1 + m_tracksHeight / 2;
5242 QRectF r(0, startY, sceneRect().width(), m_tracksHeight / 2 - 1);
5243 QList<QGraphicsItem *> selection = m_scene->items(r);
5244 QUndoCommand *deleteTrack = new QUndoCommand();
5245 deleteTrack->setText("Delete track");
5247 // Delete all clips in selected track
5248 for (int i = 0; i < selection.count(); i++) {
5249 if (selection.at(i)->type() == AVWIDGET) {
5250 ClipItem *item = static_cast <ClipItem *>(selection.at(i));
5251 new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, false, true, deleteTrack);
5252 m_scene->removeItem(item);
5255 } else if (selection.at(i)->type() == TRANSITIONWIDGET) {
5256 Transition *item = static_cast <Transition *>(selection.at(i));
5257 new AddTransitionCommand(this, item->info(), item->transitionEndTrack(), item->toXML(), true, false, deleteTrack);
5258 m_scene->removeItem(item);
5264 new AddTrackCommand(this, ix, trackinfo, false, deleteTrack);
5265 m_commandStack->push(deleteTrack);
5268 void CustomTrackView::autoTransition()
5270 QList<QGraphicsItem *> itemList = scene()->selectedItems();
5271 if (itemList.count() != 1 || itemList.at(0)->type() != TRANSITIONWIDGET) {
5272 emit displayMessage(i18n("You must select one transition for this action"), ErrorMessage);
5275 Transition *tr = static_cast <Transition*>(itemList.at(0));
5276 tr->setAutomatic(!tr->isAutomatic());
5277 QDomElement transition = tr->toXML();
5278 m_document->renderer()->mltUpdateTransition(transition.attribute("tag"), transition.attribute("tag"), transition.attribute("transition_btrack").toInt(), m_document->tracksCount() - transition.attribute("transition_atrack").toInt(), tr->startPos(), tr->endPos(), transition);
5279 setDocumentModified();
5283 QStringList CustomTrackView::getLadspaParams(QDomElement effect) const
5286 QDomNodeList params = effect.elementsByTagName("parameter");
5287 for (int i = 0; i < params.count(); i++) {
5288 QDomElement e = params.item(i).toElement();
5289 if (!e.isNull() && e.attribute("type") == "constant") {
5290 if (e.hasAttribute("factor")) {
5291 double factor = e.attribute("factor").toDouble();
5292 double value = e.attribute("value").toDouble();
5293 value = value / factor;
5294 result.append(QString::number(value));
5295 } else result.append(e.attribute("value"));
5301 void CustomTrackView::clipNameChanged(const QString id, const QString name)
5303 QList<QGraphicsItem *> list = scene()->items();
5304 ClipItem *clip = NULL;
5305 for (int i = 0; i < list.size(); ++i) {
5306 if (list.at(i)->type() == AVWIDGET) {
5307 clip = static_cast <ClipItem *>(list.at(i));
5308 if (clip->clipProducer() == id) {
5309 clip->setClipName(name);
5313 viewport()->update();
5316 void CustomTrackView::getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum)
5318 minimum = GenTime();
5319 maximum = GenTime();
5320 QList<QGraphicsItem *> selection;
5321 selection = m_scene->items(0, item->track() * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), 2);
5322 selection.removeAll(item);
5323 for (int i = 0; i < selection.count(); i++) {
5324 AbstractClipItem *clip = static_cast <AbstractClipItem *>(selection.at(i));
5325 if (clip && clip->type() == AVWIDGET) {
5326 if (clip->endPos() <= item->startPos() && clip->endPos() > minimum) minimum = clip->endPos();
5327 if (clip->startPos() > item->startPos() && (clip->startPos() < maximum || maximum == GenTime())) maximum = clip->startPos();
5332 void CustomTrackView::getTransitionAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum)
5334 minimum = GenTime();
5335 maximum = GenTime();
5336 QList<QGraphicsItem *> selection;
5337 selection = m_scene->items(0, (item->track() + 1) * m_tracksHeight, sceneRect().width(), 2);
5338 selection.removeAll(item);
5339 for (int i = 0; i < selection.count(); i++) {
5340 AbstractClipItem *clip = static_cast <AbstractClipItem *>(selection.at(i));
5341 if (clip && clip->type() == TRANSITIONWIDGET) {
5342 if (clip->endPos() <= item->startPos() && clip->endPos() > minimum) minimum = clip->endPos();
5343 if (clip->startPos() > item->startPos() && (clip->startPos() < maximum || maximum == GenTime())) maximum = clip->startPos();
5348 void CustomTrackView::loadGroups(const QDomNodeList groups)
5350 for (int i = 0; i < groups.count(); i++) {
5351 QDomNodeList children = groups.at(i).childNodes();
5352 scene()->clearSelection();
5353 for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
5354 QDomNode n = children.item(nodeindex);
5355 QDomElement elem = n.toElement();
5356 int pos = elem.attribute("position").toInt();
5357 int track = elem.attribute("track").toInt();
5358 if (elem.tagName() == "clipitem") {
5359 ClipItem *clip = getClipItemAt(pos, track); //m_document->tracksCount() - transitiontrack);
5360 if (clip) clip->setSelected(true);
5362 Transition *clip = getTransitionItemAt(pos, track); //m_document->tracksCount() - transitiontrack);
5363 if (clip) clip->setSelected(true);
5366 groupSelectedItems(false, true);
5370 void CustomTrackView::splitAudio()
5372 resetSelectionGroup();
5373 QList<QGraphicsItem *> selection = scene()->selectedItems();
5374 if (selection.isEmpty()) {
5375 emit displayMessage(i18n("You must select at least one clip for this action"), ErrorMessage);
5378 QUndoCommand *splitCommand = new QUndoCommand();
5379 splitCommand->setText(i18n("Split audio"));
5380 for (int i = 0; i < selection.count(); i++) {
5381 if (selection.at(i)->type() == AVWIDGET) {
5382 ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
5383 if (clip->clipType() == AV || clip->clipType() == PLAYLIST) {
5384 if (clip->parentItem()) {
5385 emit displayMessage(i18n("Cannot split audio of grouped clips"), ErrorMessage);
5387 new SplitAudioCommand(this, clip->track(), clip->startPos(), splitCommand);
5392 if (splitCommand->childCount() > 0)
5393 m_commandStack->push(splitCommand);
5396 void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split)
5398 ClipItem *clip = getClipItemAt(pos, track);
5400 kDebug() << "// Cannot find clip to split!!!";
5404 int start = pos.frames(m_document->fps());
5405 int freetrack = m_document->tracksCount() - track - 1;
5406 for (; freetrack > 0; freetrack--) {
5407 kDebug() << "// CHK DOC TRK:" << freetrack << ", DUR:" << m_document->renderer()->mltTrackDuration(freetrack);
5408 if (m_document->trackInfoAt(freetrack - 1).type == AUDIOTRACK && !m_document->trackInfoAt(freetrack - 1).isLocked) {
5409 kDebug() << "// CHK DOC TRK:" << freetrack << ", DUR:" << m_document->renderer()->mltTrackDuration(freetrack);
5410 if (m_document->renderer()->mltTrackDuration(freetrack) < start || m_document->renderer()->mltGetSpaceLength(pos, freetrack, false) >= clip->cropDuration().frames(m_document->fps())) {
5411 kDebug() << "FOUND SPACE ON TRK: " << freetrack;
5416 kDebug() << "GOT TRK: " << track;
5417 if (freetrack == 0) {
5418 emit displayMessage(i18n("No empty space to put clip audio"), ErrorMessage);
5420 ItemInfo info = clip->info();
5421 info.track = m_document->tracksCount() - freetrack;
5422 addClip(clip->xml(), clip->clipProducer(), info, clip->effectList());
5423 scene()->clearSelection();
5424 clip->setSelected(true);
5425 ClipItem *audioClip = getClipItemAt(start, info.track);
5427 clip->setVideoOnly(true);
5428 if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == false) {
5429 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
5431 if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, start, clip->baseClip()->audioProducer(info.track)) == false) {
5432 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, info.track), ErrorMessage);
5434 audioClip->setSelected(true);
5435 audioClip->setAudioOnly(true);
5436 groupSelectedItems(false, true);
5440 // unsplit clip: remove audio part and change video part to normal clip
5441 if (clip->parentItem() == NULL || clip->parentItem()->type() != GROUPWIDGET) {
5442 kDebug() << "//CANNOT FIND CLP GRP";
5445 AbstractGroupItem *grp = static_cast <AbstractGroupItem *>(clip->parentItem());
5446 QList<QGraphicsItem *> children = grp->childItems();
5447 if (children.count() != 2) {
5448 kDebug() << "//SOMETHING IS WRONG WITH CLP GRP";
5451 for (int i = 0; i < children.count(); i++) {
5452 if (children.at(i) != clip) {
5453 ClipItem *clp = static_cast <ClipItem *>(children.at(i));
5454 ItemInfo info = clip->info();
5455 deleteClip(clp->info());
5456 clip->setVideoOnly(false);
5457 if (!m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, info.startPos.frames(m_document->fps()), clip->baseClip()->producer(info.track))) {
5458 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", info.startPos.frames(m_document->fps()), info.track), ErrorMessage);
5463 clip->setFlag(QGraphicsItem::ItemIsMovable, true);
5464 m_document->clipManager()->removeGroup(grp);
5465 scene()->destroyItemGroup(grp);
5469 void CustomTrackView::setVideoOnly()
5471 resetSelectionGroup();
5472 QList<QGraphicsItem *> selection = scene()->selectedItems();
5473 if (selection.isEmpty()) {
5474 emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
5477 QUndoCommand *videoCommand = new QUndoCommand();
5478 videoCommand->setText(i18n("Video only"));
5479 for (int i = 0; i < selection.count(); i++) {
5480 if (selection.at(i)->type() == AVWIDGET) {
5481 ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
5482 if (clip->clipType() == AV || clip->clipType() == PLAYLIST) {
5483 if (clip->parentItem()) {
5484 emit displayMessage(i18n("Cannot change grouped clips"), ErrorMessage);
5486 new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), true, false, clip->isVideoOnly(), clip->isAudioOnly(), videoCommand);
5491 m_commandStack->push(videoCommand);
5494 void CustomTrackView::setAudioOnly()
5496 resetSelectionGroup();
5497 QList<QGraphicsItem *> selection = scene()->selectedItems();
5498 if (selection.isEmpty()) {
5499 emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
5502 QUndoCommand *videoCommand = new QUndoCommand();
5503 videoCommand->setText(i18n("Audio only"));
5504 for (int i = 0; i < selection.count(); i++) {
5505 if (selection.at(i)->type() == AVWIDGET) {
5506 ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
5507 if (clip->clipType() == AV || clip->clipType() == PLAYLIST) {
5508 if (clip->parentItem()) {
5509 emit displayMessage(i18n("Cannot change grouped clips"), ErrorMessage);
5511 new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), false, true, clip->isVideoOnly(), clip->isAudioOnly(), videoCommand);
5516 m_commandStack->push(videoCommand);
5519 void CustomTrackView::setAudioAndVideo()
5521 resetSelectionGroup();
5522 QList<QGraphicsItem *> selection = scene()->selectedItems();
5523 if (selection.isEmpty()) {
5524 emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
5527 QUndoCommand *videoCommand = new QUndoCommand();
5528 videoCommand->setText(i18n("Audio and Video"));
5529 for (int i = 0; i < selection.count(); i++) {
5530 if (selection.at(i)->type() == AVWIDGET) {
5531 ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
5532 if (clip->clipType() == AV || clip->clipType() == PLAYLIST) {
5533 if (clip->parentItem()) {
5534 emit displayMessage(i18n("Cannot change grouped clips"), ErrorMessage);
5536 new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), false, false, clip->isVideoOnly(), clip->isAudioOnly(), videoCommand);
5541 m_commandStack->push(videoCommand);
5544 void CustomTrackView::doChangeClipType(const GenTime &pos, int track, bool videoOnly, bool audioOnly)
5546 ClipItem *clip = getClipItemAt(pos, track);
5548 kDebug() << "// Cannot find clip to split!!!";
5552 int start = pos.frames(m_document->fps());
5553 clip->setVideoOnly(true);
5554 clip->setAudioOnly(false);
5555 if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == false) {
5556 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
5558 } else if (audioOnly) {
5559 int start = pos.frames(m_document->fps());
5560 clip->setAudioOnly(true);
5561 clip->setVideoOnly(false);
5562 if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->audioProducer(track)) == false) {
5563 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
5566 int start = pos.frames(m_document->fps());
5567 clip->setAudioOnly(false);
5568 clip->setVideoOnly(false);
5569 if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->producer(track)) == false) {
5570 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
5574 setDocumentModified();
5577 void CustomTrackView::updateClipTypeActions(ClipItem *clip)
5579 if (clip == NULL || (clip->clipType() != AV && clip->clipType() != PLAYLIST)) {
5580 m_clipTypeGroup->setEnabled(false);
5582 m_clipTypeGroup->setEnabled(true);
5583 QList <QAction *> actions = m_clipTypeGroup->actions();
5585 if (clip->isAudioOnly()) lookup = "clip_audio_only";
5586 else if (clip->isVideoOnly()) lookup = "clip_video_only";
5587 else lookup = "clip_audio_and_video";
5588 for (int i = 0; i < actions.count(); i++) {
5589 if (actions.at(i)->data().toString() == lookup) {
5590 actions.at(i)->setChecked(true);
5597 void CustomTrackView::slotGoToMarker(QAction *action)
5599 int pos = action->data().toInt();
5600 setCursorPos(pos, true);
5603 void CustomTrackView::reloadTransitionLumas()
5607 QDomElement lumaTransition = MainWindow::transitions.getEffectByTag("luma", "luma");
5608 QDomNodeList params = lumaTransition.elementsByTagName("parameter");
5609 for (int i = 0; i < params.count(); i++) {
5610 QDomElement e = params.item(i).toElement();
5611 if (e.attribute("tag") == "resource") {
5612 lumaNames = e.attribute("paramlistdisplay");
5613 lumaFiles = e.attribute("paramlist");
5618 QList<QGraphicsItem *> itemList = items();
5619 Transition *transitionitem;
5620 QDomElement transitionXml;
5621 for (int i = 0; i < itemList.count(); i++) {
5622 if (itemList.at(i)->type() == TRANSITIONWIDGET) {
5623 transitionitem = static_cast <Transition*>(itemList.at(i));
5624 transitionXml = transitionitem->toXML();
5625 if (transitionXml.attribute("id") == "luma" && transitionXml.attribute("tag") == "luma") {
5626 QDomNodeList params = transitionXml.elementsByTagName("parameter");
5627 for (int i = 0; i < params.count(); i++) {
5628 QDomElement e = params.item(i).toElement();
5629 if (e.attribute("tag") == "resource") {
5630 e.setAttribute("paramlistdisplay", lumaNames);
5631 e.setAttribute("paramlist", lumaFiles);
5636 if (transitionXml.attribute("id") == "composite" && transitionXml.attribute("tag") == "composite") {
5637 QDomNodeList params = transitionXml.elementsByTagName("parameter");
5638 for (int i = 0; i < params.count(); i++) {
5639 QDomElement e = params.item(i).toElement();
5640 if (e.attribute("tag") == "luma") {
5641 e.setAttribute("paramlistdisplay", lumaNames);
5642 e.setAttribute("paramlist", lumaFiles);
5649 emit transitionItemSelected(NULL);
5652 double CustomTrackView::fps() const
5654 return m_document->fps();
5657 void CustomTrackView::updateProjectFps()
5659 // update all clips to the new fps
5660 resetSelectionGroup();
5661 scene()->clearSelection();
5663 QList<QGraphicsItem *> itemList = items();
5664 for (int i = 0; i < itemList.count(); i++) {
5665 // remove all items and re-add them one by one
5666 if (itemList.at(i) != m_cursorLine && itemList.at(i)->parentItem() == NULL) m_scene->removeItem(itemList.at(i));
5668 for (int i = 0; i < itemList.count(); i++) {
5669 if (itemList.at(i)->parentItem() == 0 && (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET)) {
5670 AbstractClipItem *clip = static_cast <AbstractClipItem *>(itemList.at(i));
5671 clip->updateFps(m_document->fps());
5672 m_scene->addItem(clip);
5673 } else if (itemList.at(i)->type() == GROUPWIDGET) {
5674 AbstractGroupItem *grp = static_cast <AbstractGroupItem *>(itemList.at(i));
5675 QList<QGraphicsItem *> children = grp->childItems();
5676 for (int j = 0; j < children.count(); j++) {
5677 if (children.at(j)->type() == AVWIDGET || children.at(j)->type() == TRANSITIONWIDGET) {
5678 AbstractClipItem *clip = static_cast <AbstractClipItem *>(children.at(j));
5679 clip->setFlag(QGraphicsItem::ItemIsMovable, true);
5680 clip->updateFps(m_document->fps());
5683 m_document->clipManager()->removeGroup(grp);
5684 m_scene->addItem(grp);
5685 scene()->destroyItemGroup(grp);
5686 for (int j = 0; j < children.count(); j++) {
5687 if (children.at(j)->type() == AVWIDGET || children.at(j)->type() == TRANSITIONWIDGET) {
5688 //children.at(j)->setParentItem(0);
5689 children.at(j)->setSelected(true);
5692 groupSelectedItems(true, true);
5693 } else if (itemList.at(i)->type() == GUIDEITEM) {
5694 Guide *g = static_cast<Guide *>(itemList.at(i));
5696 m_scene->addItem(g);
5699 viewport()->update();
5702 void CustomTrackView::slotTrackDown()
5704 if (m_selectedTrack > m_document->tracksCount() - 2) m_selectedTrack = 0;
5705 else m_selectedTrack++;
5706 emit updateTrackHeaders();
5707 QRectF rect(mapToScene(QPoint(10, 0)).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight);
5708 ensureVisible(rect, 0, 0);
5709 viewport()->update();
5712 void CustomTrackView::slotTrackUp()
5714 if (m_selectedTrack > 0) m_selectedTrack--;
5715 else m_selectedTrack = m_document->tracksCount() - 1;
5716 emit updateTrackHeaders();
5717 QRectF rect(mapToScene(QPoint(10, 0)).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight);
5718 ensureVisible(rect, 0, 0);
5719 viewport()->update();
5722 int CustomTrackView::selectedTrack() const
5724 return m_selectedTrack;
5727 QStringList CustomTrackView::selectedClips() const
5729 QStringList clipIds;
5730 QList<QGraphicsItem *> selection = m_scene->selectedItems();
5731 for (int i = 0; i < selection.count(); i++) {
5732 if (selection.at(i)->type() == AVWIDGET) {
5733 ClipItem *item = (ClipItem *)selection.at(i);
5734 clipIds << item->clipProducer();
5740 QList<ClipItem *> CustomTrackView::selectedClipItems() const
5742 QList<ClipItem *> clips;
5743 QList<QGraphicsItem *> selection = m_scene->selectedItems();
5744 for (int i = 0; i < selection.count(); i++) {
5745 if (selection.at(i)->type() == AVWIDGET) {
5746 clips.append((ClipItem *)selection.at(i));
5752 void CustomTrackView::slotSelectTrack(int ix)
5754 m_selectedTrack = qMax(0, ix);
5755 m_selectedTrack = qMin(ix, m_document->tracksCount() - 1);
5756 emit updateTrackHeaders();
5757 QRectF rect(mapToScene(QPoint(10, 0)).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight);
5758 ensureVisible(rect, 0, 0);
5759 viewport()->update();
5762 void CustomTrackView::selectClip(bool add, bool group, int track, int pos)
5765 if (track != -1 && pos != -1)
5766 rect = QRectF(pos, track * m_tracksHeight + m_tracksHeight / 2, 1, 1);
5768 rect = QRectF(m_cursorPos, m_selectedTrack * m_tracksHeight + m_tracksHeight / 2, 1, 1);
5769 QList<QGraphicsItem *> selection = m_scene->items(rect);
5770 resetSelectionGroup(group);
5771 if (!group) m_scene->clearSelection();
5772 for (int i = 0; i < selection.count(); i++) {
5773 if (selection.at(i)->type() == AVWIDGET) {
5774 selection.at(i)->setSelected(add);
5778 if (group) groupSelectedItems();
5781 void CustomTrackView::selectTransition(bool add, bool group)
5783 QRectF rect(m_cursorPos, m_selectedTrack * m_tracksHeight + m_tracksHeight, 1, 1);
5784 QList<QGraphicsItem *> selection = m_scene->items(rect);
5785 resetSelectionGroup(group);
5786 if (!group) m_scene->clearSelection();
5787 for (int i = 0; i < selection.count(); i++) {
5788 if (selection.at(i)->type() == TRANSITIONWIDGET) {
5789 selection.at(i)->setSelected(add);
5793 if (group) groupSelectedItems();
5796 QStringList CustomTrackView::extractTransitionsLumas()
5799 QList<QGraphicsItem *> itemList = items();
5800 Transition *transitionitem;
5801 QDomElement transitionXml;
5802 for (int i = 0; i < itemList.count(); i++) {
5803 if (itemList.at(i)->type() == TRANSITIONWIDGET) {
5804 transitionitem = static_cast <Transition*>(itemList.at(i));
5805 transitionXml = transitionitem->toXML();
5806 QString luma = EffectsList::parameter(transitionXml, "luma");
5807 if (!luma.isEmpty()) urls << luma;
5813 void CustomTrackView::setEditMode(EDITMODE mode)
5815 m_scene->setEditMode(mode);
5818 void CustomTrackView::checkTrackSequence(int track)
5820 QList <int> times = m_document->renderer()->checkTrackSequence(m_document->tracksCount() - track);
5821 //track = m_document->tracksCount() -track;
5822 QRectF rect(0, track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), 2);
5823 QList<QGraphicsItem *> selection = m_scene->items(rect);
5824 QList <int> timelineList;
5825 timelineList.append(0);
5826 for (int i = 0; i < selection.count(); i++) {
5827 if (selection.at(i)->type() == AVWIDGET) {
5828 ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
5829 int start = clip->startPos().frames(m_document->fps());
5830 int end = clip->endPos().frames(m_document->fps());
5831 if (!timelineList.contains(start)) timelineList.append(start);
5832 if (!timelineList.contains(end)) timelineList.append(end);
5835 qSort(timelineList);
5836 kDebug() << "// COMPARE:\n" << times << "\n" << timelineList << "\n-------------------";
5837 if (times != timelineList) KMessageBox::sorry(this, i18n("error"), i18n("TRACTOR"));
5840 void CustomTrackView::insertZoneOverwrite(QStringList data, int in)
5842 if (data.isEmpty()) return;
5843 DocClipBase *clip = m_document->getBaseClip(data.at(0));
5845 info.startPos = GenTime(in, m_document->fps());
5846 info.cropStart = GenTime(data.at(1).toInt(), m_document->fps());
5847 info.endPos = info.startPos + GenTime(data.at(2).toInt(), m_document->fps()) - info.cropStart;
5848 info.cropDuration = info.endPos - info.startPos;
5849 info.track = m_selectedTrack;
5850 QUndoCommand *addCommand = new QUndoCommand();
5851 addCommand->setText(i18n("Insert clip"));
5852 adjustTimelineClips(OVERWRITEEDIT, NULL, info, addCommand);
5853 new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), info, EffectsList(), true, false, true, false, addCommand);
5854 m_commandStack->push(addCommand);
5856 selectClip(true, false, m_selectedTrack, in);
5857 // Automatic audio split
5858 if (KdenliveSettings::splitaudio())
5862 void CustomTrackView::clearSelection()
5864 resetSelectionGroup();
5865 scene()->clearSelection();
5867 emit clipItemSelected(NULL);
5870 void CustomTrackView::updatePalette()
5875 pen1.setColor(palette().text().color());
5876 m_cursorLine->setPen(pen1);
5880 void CustomTrackView::removeTipAnimation()
5883 scene()->removeItem(m_visualTip);
5884 m_animationTimer->stop();
5892 void CustomTrackView::setTipAnimation(AbstractClipItem *clip, OPERATIONTYPE mode, const double size)
5894 if (m_visualTip == NULL) {
5895 QRectF rect = clip->sceneBoundingRect();
5896 m_animation = new QGraphicsItemAnimation;
5897 m_animation->setTimeLine(m_animationTimer);
5898 m_animation->setScaleAt(1, 1, 1);
5903 m_visualTip = new QGraphicsEllipseItem(-size, -size, size * 2, size * 2);
5904 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
5905 ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen);
5907 m_visualTip->setPos(rect.x() + ((ClipItem *) clip)->fadeIn(), rect.y());
5909 m_visualTip->setPos(rect.right() - ((ClipItem *) clip)->fadeOut(), rect.y());
5911 m_animation->setScaleAt(.5, 2, 2);
5915 polygon << QPoint(0, - size * 2);
5916 if (mode == RESIZESTART)
5917 polygon << QPoint(size * 2, 0);
5919 polygon << QPoint(- size * 2, 0);
5920 polygon << QPoint(0, size * 2);
5921 polygon << QPoint(0, - size * 2);
5923 m_visualTip = new QGraphicsPolygonItem(polygon);
5924 ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
5925 ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen);
5926 if (mode == RESIZESTART)
5927 m_visualTip->setPos(rect.x(), rect.y() + rect.height() / 2);
5929 m_visualTip->setPos(rect.right(), rect.y() + rect.height() / 2);
5931 m_animation->setScaleAt(.5, 2, 1);
5933 case TRANSITIONSTART:
5935 polygon << QPoint(0, - size * 2);
5936 if (mode == TRANSITIONSTART)
5937 polygon << QPoint(size * 2, 0);
5939 polygon << QPoint(- size * 2, 0);
5940 polygon << QPoint(0, 0);
5941 polygon << QPoint(0, - size * 2);
5943 m_visualTip = new QGraphicsPolygonItem(polygon);
5944 ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
5945 ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen);
5946 if (mode == TRANSITIONSTART)
5947 m_visualTip->setPos(rect.x(), rect.bottom());
5949 m_visualTip->setPos(rect.right(), rect.bottom());
5951 m_animation->setScaleAt(.5, 2, 2);
5958 m_visualTip->setFlags(QGraphicsItem::ItemIgnoresTransformations);
5959 m_visualTip->setZValue(100);
5960 scene()->addItem(m_visualTip);
5961 m_animation->setItem(m_visualTip);
5962 m_animationTimer->start();