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"
61 #include "rebuildgroupcommand.h"
62 #include "razorgroupcommand.h"
63 #include "profilesdialog.h"
70 #include <KMessageBox>
71 #include <KIO/NetAccess>
73 #include <QMouseEvent>
74 #include <QStylePainter>
75 #include <QGraphicsItem>
76 #include <QDomDocument>
78 #include <QApplication>
79 #include <QInputDialog>
82 #if QT_VERSION >= 0x040600
83 #include <QGraphicsDropShadowEffect>
86 bool sortGuidesList(const Guide *g1 , const Guide *g2)
88 return (*g1).position() < (*g2).position();
93 // disable animation if user asked it in KDE's global settings
94 // http://lists.kde.org/?l=kde-commits&m=120398724717624&w=2
95 // needs something like below (taken from dolphin)
96 // #include <kglobalsettings.h>
97 // const bool animate = KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects;
98 // const int duration = animate ? 1500 : 1;
100 CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscene, QWidget *parent) :
101 QGraphicsView(projectscene, parent),
102 m_tracksHeight(KdenliveSettings::trackheight()),
103 m_projectDuration(0),
106 m_scene(projectscene),
108 m_operationMode(NONE),
115 m_autoScroll(KdenliveSettings::autoscroll()),
116 m_pasteEffectsAction(NULL),
117 m_ungroupAction(NULL),
124 m_blockRefresh(false),
125 m_selectionGroup(NULL),
127 m_controlModifier(false)
130 m_commandStack = doc->commandStack();
132 m_commandStack = NULL;
134 setMouseTracking(true);
135 setAcceptDrops(true);
136 setFrameShape(QFrame::NoFrame);
138 //setCacheMode(QGraphicsView::CacheBackground);
139 setAutoFillBackground(false);
140 setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
141 setContentsMargins(0, 0, 0, 0);
143 m_activeTrackBrush = KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
145 pixmapCache = new KPixmapCache("kdenlive-thumbs");
147 m_animationTimer = new QTimeLine(800);
148 m_animationTimer->setFrameRange(0, 5);
149 m_animationTimer->setUpdateInterval(100);
150 m_animationTimer->setLoopCount(0);
152 m_tipColor = QColor(0, 192, 0, 200);
153 m_tipPen.setColor(QColor(255, 255, 255, 100));
154 m_tipPen.setWidth(3);
156 const int maxHeight = m_tracksHeight * m_document->tracksCount();
157 setSceneRect(0, 0, sceneRect().width(), maxHeight);
158 verticalScrollBar()->setMaximum(maxHeight);
159 verticalScrollBar()->setTracking(true);
160 // repaint guides when using vertical scroll
161 connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slotRefreshGuides()));
163 m_cursorLine = projectscene->addLine(0, 0, 0, maxHeight);
164 m_cursorLine->setZValue(1000);
167 pen1.setColor(palette().text().color());
168 m_cursorLine->setPen(pen1);
169 m_cursorLine->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
171 connect(&m_scrollTimer, SIGNAL(timeout()), this, SLOT(slotCheckMouseScrolling()));
172 m_scrollTimer.setInterval(100);
173 m_scrollTimer.setSingleShot(true);
175 connect(&m_thumbsTimer, SIGNAL(timeout()), this, SLOT(slotFetchNextThumbs()));
176 m_thumbsTimer.setInterval(500);
177 m_thumbsTimer.setSingleShot(true);
179 KIcon razorIcon("edit-cut");
180 m_razorCursor = QCursor(razorIcon.pixmap(22, 22));
182 KIcon spacerIcon("kdenlive-spacer-tool");
183 m_spacerCursor = QCursor(spacerIcon.pixmap(22, 22));
186 CustomTrackView::~CustomTrackView()
188 qDeleteAll(m_guides);
190 m_waitingThumbs.clear();
194 void CustomTrackView::keyPressEvent(QKeyEvent * event)
196 if (event->key() == Qt::Key_Up) {
199 } else if (event->key() == Qt::Key_Down) {
202 } else QWidget::keyPressEvent(event);
205 void CustomTrackView::setDocumentModified()
207 m_document->setModified(true);
210 void CustomTrackView::setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition, QActionGroup *clipTypeGroup, QMenu *markermenu)
212 m_timelineContextMenu = timeline;
213 m_timelineContextClipMenu = clip;
214 m_clipTypeGroup = clipTypeGroup;
215 connect(m_timelineContextMenu, SIGNAL(aboutToHide()), this, SLOT(slotResetMenuPosition()));
217 m_markerMenu = new QMenu(i18n("Go to marker..."), this);
218 m_markerMenu->setEnabled(false);
219 markermenu->addMenu(m_markerMenu);
220 connect(m_markerMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotGoToMarker(QAction *)));
221 QList <QAction *> list = m_timelineContextClipMenu->actions();
222 for (int i = 0; i < list.count(); i++) {
223 if (list.at(i)->data().toString() == "paste_effects") m_pasteEffectsAction = list.at(i);
224 else if (list.at(i)->data().toString() == "ungroup_clip") m_ungroupAction = list.at(i);
227 m_timelineContextTransitionMenu = transition;
228 list = m_timelineContextTransitionMenu->actions();
229 for (int i = 0; i < list.count(); i++) {
230 if (list.at(i)->data().toString() == "auto") {
231 m_autoTransition = list.at(i);
236 m_timelineContextMenu->addSeparator();
237 m_deleteGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
238 connect(m_deleteGuide, SIGNAL(triggered()), this, SLOT(slotDeleteTimeLineGuide()));
239 m_timelineContextMenu->addAction(m_deleteGuide);
241 m_editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
242 connect(m_editGuide, SIGNAL(triggered()), this, SLOT(slotEditTimeLineGuide()));
243 m_timelineContextMenu->addAction(m_editGuide);
246 void CustomTrackView::slotDoResetMenuPosition()
248 m_menuPosition = QPoint();
251 void CustomTrackView::slotResetMenuPosition()
253 // after a short time (so that the action is triggered / or menu is closed, we reset the menu pos
254 QTimer::singleShot(300, this, SLOT(slotDoResetMenuPosition()));
257 void CustomTrackView::checkAutoScroll()
259 m_autoScroll = KdenliveSettings::autoscroll();
262 /*sQList <TrackInfo> CustomTrackView::tracksList() const {
263 return m_scene->m_tracksList;
266 void CustomTrackView::checkTrackHeight()
268 if (m_tracksHeight == KdenliveSettings::trackheight()) return;
269 m_tracksHeight = KdenliveSettings::trackheight();
270 emit trackHeightChanged();
271 QList<QGraphicsItem *> itemList = items();
273 Transition *transitionitem;
274 bool snap = KdenliveSettings::snaptopoints();
275 KdenliveSettings::setSnaptopoints(false);
276 for (int i = 0; i < itemList.count(); i++) {
277 if (itemList.at(i)->type() == AVWIDGET) {
278 item = (ClipItem*) itemList.at(i);
279 item->setRect(0, 0, item->rect().width(), m_tracksHeight - 1);
280 item->setPos((qreal) item->startPos().frames(m_document->fps()), (qreal) item->track() * m_tracksHeight + 1);
281 item->resetThumbs(true);
282 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
283 transitionitem = (Transition*) itemList.at(i);
284 transitionitem->setRect(0, 0, transitionitem->rect().width(), m_tracksHeight / 3 * 2 - 1);
285 transitionitem->setPos((qreal) transitionitem->startPos().frames(m_document->fps()), (qreal) transitionitem->track() * m_tracksHeight + m_tracksHeight / 3 * 2);
288 double newHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
289 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight - 1);
291 for (int i = 0; i < m_guides.count(); i++) {
292 QLineF l = m_guides.at(i)->line();
293 l.setP2(QPointF(l.x2(), newHeight));
294 m_guides.at(i)->setLine(l);
297 setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
298 // verticalScrollBar()->setMaximum(m_tracksHeight * m_document->tracksCount());
299 KdenliveSettings::setSnaptopoints(snap);
300 viewport()->update();
303 /** Zoom or move viewport on mousewheel
305 * If mousewheel+Ctrl, zooms in/out on the timeline.
307 * With Ctrl, moves viewport towards end of timeline if down/back,
308 * opposite on up/forward.
310 * See also http://www.kdenlive.org/mantis/view.php?id=265 */
311 void CustomTrackView::wheelEvent(QWheelEvent * e)
313 if (e->modifiers() == Qt::ControlModifier) {
314 if (e->delta() > 0) emit zoomIn();
317 if (e->delta() <= 0) horizontalScrollBar()->setValue(horizontalScrollBar()->value() + horizontalScrollBar()->singleStep());
318 else horizontalScrollBar()->setValue(horizontalScrollBar()->value() - horizontalScrollBar()->singleStep());
322 int CustomTrackView::getPreviousVideoTrack(int track)
324 track = m_document->tracksCount() - track - 1;
326 for (int i = track; i > -1; i--) {
327 if (m_document->trackInfoAt(i).type == VIDEOTRACK) return i + 1;
333 void CustomTrackView::slotFetchNextThumbs()
335 if (!m_waitingThumbs.isEmpty()) {
336 ClipItem *item = m_waitingThumbs.takeFirst();
337 while (item == NULL && !m_waitingThumbs.isEmpty()) {
338 item = m_waitingThumbs.takeFirst();
340 if (item) item->slotFetchThumbs();
341 if (!m_waitingThumbs.isEmpty()) m_thumbsTimer.start();
345 void CustomTrackView::slotCheckMouseScrolling()
347 if (m_scrollOffset == 0) {
348 m_scrollTimer.stop();
351 horizontalScrollBar()->setValue(horizontalScrollBar()->value() + m_scrollOffset);
352 m_scrollTimer.start();
355 void CustomTrackView::slotCheckPositionScrolling()
357 // If mouse is at a border of the view, scroll
358 if (m_moveOpMode != SEEK) return;
359 if (mapFromScene(m_cursorPos, 0).x() < 3) {
360 horizontalScrollBar()->setValue(horizontalScrollBar()->value() - 2);
361 QTimer::singleShot(200, this, SLOT(slotCheckPositionScrolling()));
362 setCursorPos(mapToScene(QPoint(-2, 0)).x());
363 } else if (viewport()->width() - 3 < mapFromScene(m_cursorPos + 1, 0).x()) {
364 horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 2);
365 setCursorPos(mapToScene(QPoint(viewport()->width(), 0)).x() + 1);
366 QTimer::singleShot(200, this, SLOT(slotCheckPositionScrolling()));
372 void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
374 int pos = event->x();
375 int mappedXPos = qMax((int)(mapToScene(event->pos()).x() + 0.5), 0);
377 double snappedPos = getSnapPointForPos(mappedXPos);
378 emit mousePosition(mappedXPos);
380 if (event->buttons() & Qt::MidButton) return;
381 if (dragMode() == QGraphicsView::RubberBandDrag || (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL && m_operationMode != RESIZESTART && m_operationMode != RESIZEEND)) {
382 event->setAccepted(true);
384 QGraphicsView::mouseMoveEvent(event);
388 if (event->buttons() != Qt::NoButton) {
389 bool move = (event->pos() - m_clickEvent).manhattanLength() >= QApplication::startDragDistance();
390 if (m_dragItem && m_tool == SELECTTOOL) {
391 if (m_operationMode == MOVE && move) {
392 QGraphicsView::mouseMoveEvent(event);
393 // If mouse is at a border of the view, scroll
395 m_scrollOffset = -30;
396 m_scrollTimer.start();
397 } else if (viewport()->width() - pos < 10) {
399 m_scrollTimer.start();
400 } else if (m_scrollTimer.isActive()) {
401 m_scrollTimer.stop();
403 } else if (m_operationMode == RESIZESTART && move) {
404 m_document->renderer()->pause();
405 if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
406 AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
408 parent->resizeStart((int)(snappedPos - m_dragItemInfo.startPos.frames(m_document->fps())));
410 m_dragItem->resizeStart((int)(snappedPos));
412 QString crop = m_document->timecode().getDisplayTimecode(m_dragItem->cropStart(), KdenliveSettings::frametimecode());
413 QString duration = m_document->timecode().getDisplayTimecode(m_dragItem->cropDuration(), KdenliveSettings::frametimecode());
414 QString offset = m_document->timecode().getDisplayTimecode(m_dragItem->cropStart() - m_dragItemInfo.cropStart, KdenliveSettings::frametimecode());
415 emit displayMessage(i18n("Crop from start:") + ' ' + crop + ' ' + i18n("Duration:") + ' ' + duration + ' ' + i18n("Offset:") + ' ' + offset, InformationMessage);
416 } else if (m_operationMode == RESIZEEND && move) {
417 m_document->renderer()->pause();
418 if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
419 AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
421 parent->resizeEnd((int)(snappedPos - m_dragItemInfo.endPos.frames(m_document->fps())));
423 m_dragItem->resizeEnd((int)(snappedPos));
425 QString duration = m_document->timecode().getDisplayTimecode(m_dragItem->cropDuration(), KdenliveSettings::frametimecode());
426 QString offset = m_document->timecode().getDisplayTimecode(m_dragItem->cropDuration() - m_dragItemInfo.cropDuration, KdenliveSettings::frametimecode());
427 emit displayMessage(i18n("Duration:") + ' ' + duration + ' ' + i18n("Offset:") + ' ' + offset, InformationMessage);
428 } else if (m_operationMode == FADEIN && move) {
429 ((ClipItem*) m_dragItem)->setFadeIn((int)(mappedXPos - m_dragItem->startPos().frames(m_document->fps())));
430 } else if (m_operationMode == FADEOUT && move) {
431 ((ClipItem*) m_dragItem)->setFadeOut((int)(m_dragItem->endPos().frames(m_document->fps()) - mappedXPos));
432 } else if (m_operationMode == KEYFRAME && move) {
433 GenTime keyFramePos = GenTime(mappedXPos, m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart();
434 double pos = mapToScene(event->pos()).toPoint().y();
435 QRectF br = m_dragItem->sceneBoundingRect();
436 double maxh = 100.0 / br.height();
437 pos = (br.bottom() - pos) * maxh;
438 m_dragItem->updateKeyFramePos(keyFramePos, pos);
439 QString position = m_document->timecode().getDisplayTimecodeFromFrames(m_dragItem->editedKeyFramePos(), KdenliveSettings::frametimecode());
440 emit displayMessage(position + " : " + QString::number(m_dragItem->editedKeyFrameValue()), InformationMessage);
442 removeTipAnimation();
444 } else if (m_operationMode == MOVEGUIDE) {
445 removeTipAnimation();
446 QGraphicsView::mouseMoveEvent(event);
448 } else if (m_operationMode == SPACER && move && m_selectionGroup) {
450 snappedPos = getSnapPointForPos(mappedXPos + m_spacerOffset);
451 if (snappedPos < 0) snappedPos = 0;
453 // Make sure there is no collision
454 QList<QGraphicsItem *> children = m_selectionGroup->childItems();
455 QPainterPath shape = m_selectionGroup->clipGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0));
456 QList<QGraphicsItem*> collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
457 collidingItems.removeAll(m_selectionGroup);
458 for (int i = 0; i < children.count(); i++) {
459 if (children.at(i)->type() == GROUPWIDGET) {
460 QList<QGraphicsItem *> subchildren = children.at(i)->childItems();
461 for (int j = 0; j < subchildren.count(); j++)
462 collidingItems.removeAll(subchildren.at(j));
464 collidingItems.removeAll(children.at(i));
466 bool collision = false;
468 for (int i = 0; i < collidingItems.count(); i++) {
469 if (!collidingItems.at(i)->isEnabled()) continue;
470 if (collidingItems.at(i)->type() == AVWIDGET && snappedPos < m_selectionGroup->sceneBoundingRect().left()) {
471 AbstractClipItem *item = static_cast <AbstractClipItem *>(collidingItems.at(i));
472 // Moving backward, determine best pos
473 QPainterPath clipPath;
474 clipPath.addRect(item->sceneBoundingRect());
475 QPainterPath res = shape.intersected(clipPath);
476 offset = qMax(offset, (int)(res.boundingRect().width() + 0.5));
479 snappedPos += offset;
480 // make sure we have no collision
481 shape = m_selectionGroup->clipGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0));
482 collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
483 collidingItems.removeAll(m_selectionGroup);
484 for (int i = 0; i < children.count(); i++) {
485 if (children.at(i)->type() == GROUPWIDGET) {
486 QList<QGraphicsItem *> subchildren = children.at(i)->childItems();
487 for (int j = 0; j < subchildren.count(); j++)
488 collidingItems.removeAll(subchildren.at(j));
490 collidingItems.removeAll(children.at(i));
493 for (int i = 0; i < collidingItems.count(); i++) {
494 if (!collidingItems.at(i)->isEnabled()) continue;
495 if (collidingItems.at(i)->type() == AVWIDGET) {
504 shape = m_selectionGroup->transitionGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0));
505 collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
506 collidingItems.removeAll(m_selectionGroup);
507 for (int i = 0; i < children.count(); i++) {
508 if (children.at(i)->type() == GROUPWIDGET) {
509 QList<QGraphicsItem *> subchildren = children.at(i)->childItems();
510 for (int j = 0; j < subchildren.count(); j++)
511 collidingItems.removeAll(subchildren.at(j));
513 collidingItems.removeAll(children.at(i));
517 for (int i = 0; i < collidingItems.count(); i++) {
518 if (collidingItems.at(i)->type() == TRANSITIONWIDGET && snappedPos < m_selectionGroup->sceneBoundingRect().left()) {
519 AbstractClipItem *item = static_cast <AbstractClipItem *>(collidingItems.at(i));
520 // Moving backward, determine best pos
521 QPainterPath clipPath;
522 clipPath.addRect(item->sceneBoundingRect());
523 QPainterPath res = shape.intersected(clipPath);
524 offset = qMax(offset, (int)(res.boundingRect().width() + 0.5));
528 snappedPos += offset;
529 // make sure we have no collision
530 shape = m_selectionGroup->transitionGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0));
531 collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
532 collidingItems.removeAll(m_selectionGroup);
533 for (int i = 0; i < children.count(); i++) {
534 if (children.at(i)->type() == GROUPWIDGET) {
535 QList<QGraphicsItem *> subchildren = children.at(i)->childItems();
536 for (int j = 0; j < subchildren.count(); j++)
537 collidingItems.removeAll(subchildren.at(j));
539 collidingItems.removeAll(children.at(i));
541 for (int i = 0; i < collidingItems.count(); i++) {
542 if (collidingItems.at(i)->type() == TRANSITIONWIDGET) {
550 m_selectionGroup->translate(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0);
551 //m_selectionGroup->setPos(mappedXPos + (((int) m_selectionGroup->boundingRect().topLeft().x() + 0.5) - mappedClick) , m_selectionGroup->pos().y());
555 if (m_tool == RAZORTOOL) {
556 setCursor(m_razorCursor);
557 //QGraphicsView::mouseMoveEvent(event);
559 } else if (m_tool == SPACERTOOL) {
560 setCursor(m_spacerCursor);
564 QList<QGraphicsItem *> itemList = items(event->pos());
565 QGraphicsRectItem *item = NULL;
566 OPERATIONTYPE opMode = NONE;
568 if (itemList.count() == 1 && itemList.at(0)->type() == GUIDEITEM) {
570 } else for (int i = 0; i < itemList.count(); i++) {
571 if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
572 item = (QGraphicsRectItem*) itemList.at(i);
577 if (item && event->buttons() == Qt::NoButton) {
578 AbstractClipItem *clip = static_cast <AbstractClipItem*>(item);
579 if (m_tool == RAZORTOOL) {
580 // razor tool over a clip, display current frame in monitor
581 if (false && !m_blockRefresh && item->type() == AVWIDGET) {
582 //TODO: solve crash when showing frame when moving razor over clip
583 emit showClipFrame(((ClipItem *) item)->baseClip(), QPoint(), mappedXPos - (clip->startPos() - clip->cropStart()).frames(m_document->fps()));
588 opMode = clip->operationMode(mapToScene(event->pos()));
589 const double size = 5;
590 if (opMode == m_moveOpMode) {
591 QGraphicsView::mouseMoveEvent(event);
594 removeTipAnimation();
596 m_moveOpMode = opMode;
597 setTipAnimation(clip, opMode, size);
599 if (item->type() == AVWIDGET)
600 ci = static_cast <ClipItem *>(item);
602 if (opMode == MOVE) {
603 setCursor(Qt::OpenHandCursor);
605 message = ci->clipName() + i18n(":");
606 message.append(i18n(" Position:") + m_document->timecode().getDisplayTimecode(ci->info().startPos, KdenliveSettings::frametimecode()));
607 message.append(i18n(" Duration:") + m_document->timecode().getDisplayTimecode(ci->cropDuration(), KdenliveSettings::frametimecode()));
608 if (clip->parentItem() && clip->parentItem()->type() == GROUPWIDGET) {
609 AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(clip->parentItem());
610 if (clip->parentItem() == m_selectionGroup)
611 message.append(i18n(" Selection duration:"));
613 message.append(i18n(" Group duration:"));
614 message.append(m_document->timecode().getDisplayTimecode(parent->duration(), KdenliveSettings::frametimecode()));
615 if (parent->parentItem() && parent->parentItem()->type() == GROUPWIDGET) {
616 AbstractGroupItem *parent2 = static_cast <AbstractGroupItem *>(parent->parentItem());
617 message.append(i18n(" Selection duration:") + m_document->timecode().getDisplayTimecode(parent2->duration(), KdenliveSettings::frametimecode()));
621 } else if (opMode == RESIZESTART) {
622 setCursor(KCursor("left_side", Qt::SizeHorCursor));
624 message = i18n("Crop from start: ") + m_document->timecode().getDisplayTimecode(ci->cropStart(), KdenliveSettings::frametimecode());
625 if (item->type() == AVWIDGET && item->parentItem() && item->parentItem() != m_selectionGroup)
626 message.append(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once."));
627 } else if (opMode == RESIZEEND) {
628 setCursor(KCursor("right_side", Qt::SizeHorCursor));
630 message = i18n("Duration: ") + m_document->timecode().getDisplayTimecode(ci->cropDuration(), KdenliveSettings::frametimecode());
631 if (item->type() == AVWIDGET && item->parentItem() && item->parentItem() != m_selectionGroup)
632 message.append(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once."));
633 } else if (opMode == FADEIN || opMode == FADEOUT) {
634 setCursor(Qt::PointingHandCursor);
635 if (ci && opMode == FADEIN && ci->fadeIn()) {
636 message = i18n("Fade in duration: ");
637 message.append(m_document->timecode().getDisplayTimecodeFromFrames(ci->fadeIn(), KdenliveSettings::frametimecode()));
638 } else if (ci && opMode == FADEOUT && ci->fadeOut()) {
639 message = i18n("Fade out duration: ");
640 message.append(m_document->timecode().getDisplayTimecodeFromFrames(ci->fadeOut(), KdenliveSettings::frametimecode()));
642 message = i18n("Drag to add or resize a fade effect.");
644 } else if (opMode == TRANSITIONSTART || opMode == TRANSITIONEND) {
645 setCursor(Qt::PointingHandCursor);
646 message = i18n("Click to add a transition.");
647 } else if (opMode == KEYFRAME) {
648 setCursor(Qt::PointingHandCursor);
649 emit displayMessage(i18n("Move keyframe above or below clip to remove it, double click to add a new one."), InformationMessage);
652 if (!message.isEmpty())
653 emit displayMessage(message, InformationMessage);
654 } // no clip under mouse
655 else if (m_tool == RAZORTOOL) {
658 } else if (opMode == MOVEGUIDE) {
659 m_moveOpMode = opMode;
660 setCursor(Qt::SplitHCursor);
662 removeTipAnimation();
663 setCursor(Qt::ArrowCursor);
664 if (event->buttons() != Qt::NoButton && event->modifiers() == Qt::NoModifier) {
665 QGraphicsView::mouseMoveEvent(event);
667 setCursorPos(mappedXPos);
668 slotCheckPositionScrolling();
670 } else m_moveOpMode = NONE;
672 QGraphicsView::mouseMoveEvent(event);
676 void CustomTrackView::mousePressEvent(QMouseEvent * event)
678 setFocus(Qt::MouseFocusReason);
679 m_menuPosition = QPoint();
681 // special cases (middle click button or ctrl / shift click
682 if (event->button() == Qt::MidButton) {
684 m_blockRefresh = false;
685 m_operationMode = NONE;
689 if (event->modifiers() & Qt::ShiftModifier) {
690 // Rectangle selection
691 setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
692 setDragMode(QGraphicsView::RubberBandDrag);
693 if (!(event->modifiers() & Qt::ControlModifier)) {
694 resetSelectionGroup();
695 scene()->clearSelection();
697 m_blockRefresh = false;
698 m_operationMode = RUBBERSELECTION;
699 QGraphicsView::mousePressEvent(event);
703 m_blockRefresh = true;
705 bool collision = false;
707 if (m_tool != RAZORTOOL) activateMonitor();
708 else if (m_document->renderer()->playSpeed() != 0.0) {
709 m_document->renderer()->pause();
712 m_clickEvent = event->pos();
714 // check item under mouse
715 QList<QGraphicsItem *> collisionList = items(m_clickEvent);
717 if (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL && collisionList.count() == 0) {
718 // Pressing Ctrl + left mouse button in an empty area scrolls the timeline
719 setDragMode(QGraphicsView::ScrollHandDrag);
720 QGraphicsView::mousePressEvent(event);
721 m_blockRefresh = false;
722 m_operationMode = NONE;
726 // if a guide and a clip were pressed, just select the guide
727 for (int i = 0; i < collisionList.count(); ++i) {
728 if (collisionList.at(i)->type() == GUIDEITEM) {
729 // a guide item was pressed
730 m_dragGuide = (Guide *) collisionList.at(i);
731 if (event->button() == Qt::LeftButton) { // move it
732 m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, true);
734 m_operationMode = MOVEGUIDE;
735 // deselect all clips so that only the guide will move
736 m_scene->clearSelection();
737 resetSelectionGroup(false);
738 updateSnapPoints(NULL);
739 QGraphicsView::mousePressEvent(event);
741 } else // show context menu
746 // Find first clip, transition or group under mouse (when no guides selected)
748 AbstractGroupItem *dragGroup = NULL;
749 AbstractClipItem *collisionClip = NULL;
751 while (!m_dragGuide && ct < collisionList.count()) {
752 if (collisionList.at(ct)->type() == AVWIDGET || collisionList.at(ct)->type() == TRANSITIONWIDGET) {
753 collisionClip = static_cast <AbstractClipItem *>(collisionList.at(ct));
754 if (collisionClip->isItemLocked())
756 if (collisionClip == m_dragItem)
757 collisionClip = NULL;
759 m_dragItem = collisionClip;
761 m_dragItemInfo = m_dragItem->info();
762 if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET && m_dragItem->parentItem() != m_selectionGroup) {
763 // kDebug()<<"// KLIK FOUND GRP: "<<m_dragItem->sceneBoundingRect();
764 dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
771 if (m_dragItem) emit clipItemSelected(NULL);
774 #if QT_VERSION >= 0x040600
775 // Add shadow to dragged item, currently disabled because of painting artifacts
776 //TODO: re-enable when fixed
777 /*QGraphicsDropShadowEffect *eff = new QGraphicsDropShadowEffect();
778 eff->setBlurRadius(5);
779 eff->setOffset(3, 3);
780 m_dragItem->setGraphicsEffect(eff);*/
782 if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) {
783 // update transition menu action
784 m_autoTransition->setChecked(static_cast<Transition *>(m_dragItem)->isAutomatic());
785 m_autoTransition->setEnabled(true);
786 } else m_autoTransition->setEnabled(false);
788 // context menu requested
789 if (event->button() == Qt::RightButton) {
791 if (dragGroup) dragGroup->setSelected(true);
792 else if (!m_dragItem->isSelected()) {
793 resetSelectionGroup(false);
794 m_scene->clearSelection();
795 m_dragItem->setSelected(true);
797 } else if (!m_dragGuide) {
798 // check if there is a guide close to mouse click
799 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
800 for (int i = 0; i < guidesCollisionList.count(); i++) {
801 if (guidesCollisionList.at(i)->type() == GUIDEITEM) {
802 m_dragGuide = static_cast <Guide *>(guidesCollisionList.at(i));
806 // keep this to support multiple guides context menu in the future (?)
807 /*if (guidesCollisionList.at(0)->type() != GUIDEITEM)
808 guidesCollisionList.removeAt(0);
810 if (!guidesCollisionList.isEmpty())
811 m_dragGuide = static_cast <Guide *>(guidesCollisionList.at(0));*/
814 m_operationMode = NONE;
815 displayContextMenu(event->globalPos(), m_dragItem, dragGroup);
816 m_menuPosition = m_clickEvent;
822 // No item under click
823 if (m_dragItem == NULL || m_tool == SPACERTOOL) {
824 resetSelectionGroup(false);
825 setCursor(Qt::ArrowCursor);
826 m_scene->clearSelection();
828 updateClipTypeActions(NULL);
829 if (m_tool == SPACERTOOL) {
830 QList<QGraphicsItem *> selection;
831 if (event->modifiers() == Qt::ControlModifier) {
832 // Ctrl + click, select all items on track after click position
833 int track = (int)(mapToScene(m_clickEvent).y() / m_tracksHeight);
834 if (m_document->trackInfoAt(m_document->tracksCount() - track - 1).isLocked) {
835 // Cannot use spacer on locked track
836 emit displayMessage(i18n("Cannot use spacer in a locked track"), ErrorMessage);
840 QRectF rect(mapToScene(m_clickEvent).x(), track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width() - mapToScene(m_clickEvent).x(), m_tracksHeight / 2 - 2);
843 selection = checkForGroups(rect, &isOk);
845 // groups found on track, do not allow the move
846 emit displayMessage(i18n("Cannot use spacer in a track with a group"), ErrorMessage);
850 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;
852 // Select all items on all tracks after click position
853 selection = items(event->pos().x(), 1, mapFromScene(sceneRect().width(), 0).x() - event->pos().x(), sceneRect().height());
854 kDebug() << "SELELCTING ELEMENTS WITHIN =" << event->pos().x() << "/" << 1 << ", " << mapFromScene(sceneRect().width(), 0).x() - event->pos().x() << "/" << sceneRect().height();
857 QList <GenTime> offsetList;
858 // create group to hold selected items
859 m_selectionGroup = new AbstractGroupItem(m_document->fps());
860 scene()->addItem(m_selectionGroup);
862 for (int i = 0; i < selection.count(); i++) {
863 if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET)) {
864 AbstractClipItem *item = static_cast<AbstractClipItem *>(selection.at(i));
865 if (item->isItemLocked()) continue;
866 offsetList.append(item->startPos());
867 offsetList.append(item->endPos());
868 m_selectionGroup->addToGroup(selection.at(i));
869 selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
870 } else if (/*selection.at(i)->parentItem() == 0 && */selection.at(i)->type() == GROUPWIDGET) {
871 if (static_cast<AbstractGroupItem *>(selection.at(i))->isItemLocked()) continue;
872 QList<QGraphicsItem *> children = selection.at(i)->childItems();
873 for (int j = 0; j < children.count(); j++) {
874 AbstractClipItem *item = static_cast<AbstractClipItem *>(children.at(j));
875 offsetList.append(item->startPos());
876 offsetList.append(item->endPos());
878 m_selectionGroup->addToGroup(selection.at(i));
879 selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
880 } else if (selection.at(i)->parentItem() && !selection.contains(selection.at(i)->parentItem())) {
881 if (static_cast<AbstractGroupItem *>(selection.at(i)->parentItem())->isItemLocked()) continue;
882 //AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(selection.at(i)->parentItem());
883 m_selectionGroup->addToGroup(selection.at(i)->parentItem());
884 selection.at(i)->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
887 m_spacerOffset = m_selectionGroup->sceneBoundingRect().left() - (int)(mapToScene(m_clickEvent).x());
888 if (!offsetList.isEmpty()) {
890 QList <GenTime> cleandOffsetList;
891 GenTime startOffset = offsetList.takeFirst();
892 for (int k = 0; k < offsetList.size(); k++) {
893 GenTime newoffset = offsetList.at(k) - startOffset;
894 if (newoffset != GenTime() && !cleandOffsetList.contains(newoffset)) {
895 cleandOffsetList.append(newoffset);
898 updateSnapPoints(NULL, cleandOffsetList, true);
900 m_operationMode = SPACER;
902 setCursorPos((int)(mapToScene(event->x(), 0).x()));
904 QGraphicsView::mousePressEvent(event);
909 if (m_tool == RAZORTOOL && m_dragItem) {
910 GenTime cutPos = GenTime((int)(mapToScene(event->pos()).x()), m_document->fps());
911 if (m_dragItem->type() == TRANSITIONWIDGET) {
912 emit displayMessage(i18n("Cannot cut a transition"), ErrorMessage);
914 m_document->renderer()->pause();
915 if (m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
916 razorGroup((AbstractGroupItem *)m_dragItem->parentItem(), cutPos);
918 AbstractClipItem *clip = static_cast <AbstractClipItem *>(m_dragItem);
919 RazorClipCommand* command = new RazorClipCommand(this, clip->info(), cutPos);
920 m_commandStack->push(command);
922 setDocumentModified();
929 bool itemSelected = false;
930 if (m_dragItem->isSelected())
932 else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected())
934 else if (dragGroup && dragGroup->isSelected())
937 if (event->modifiers() == Qt::ControlModifier || itemSelected == false) {
938 if (event->modifiers() != Qt::ControlModifier) {
939 resetSelectionGroup(false);
940 m_scene->clearSelection();
941 // A refresh seems necessary otherwise in zoomed mode, some clips disappear
942 viewport()->update();
943 } else resetSelectionGroup();
945 if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET) {
946 dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
948 bool selected = !m_dragItem->isSelected();
950 dragGroup->setSelected(selected);
952 m_dragItem->setSelected(selected);
954 groupSelectedItems();
955 ClipItem *clip = static_cast <ClipItem *>(m_dragItem);
956 updateClipTypeActions(dragGroup == NULL ? clip : NULL);
957 m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
960 if (collisionClip != NULL || m_dragItem == NULL) {
961 if (m_dragItem && m_dragItem->type() == AVWIDGET && !m_dragItem->isItemLocked()) {
962 ClipItem *selected = static_cast <ClipItem*>(m_dragItem);
963 emit clipItemSelected(selected);
965 emit clipItemSelected(NULL);
969 // If clicked item is selected, allow move
970 if (event->modifiers() != Qt::ControlModifier && m_operationMode == NONE) QGraphicsView::mousePressEvent(event);
972 m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y()));
973 m_operationMode = m_dragItem->operationMode(mapToScene(event->pos()));
974 m_controlModifier = (event->modifiers() == Qt::ControlModifier);
976 // Update snap points
977 if (m_selectionGroup == NULL) {
978 if (m_operationMode == RESIZEEND || m_operationMode == RESIZESTART)
979 updateSnapPoints(NULL);
981 updateSnapPoints(m_dragItem);
983 QList <GenTime> offsetList;
984 QList<QGraphicsItem *> children = m_selectionGroup->childItems();
985 for (int i = 0; i < children.count(); i++) {
986 if (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET) {
987 AbstractClipItem *item = static_cast <AbstractClipItem *>(children.at(i));
988 offsetList.append(item->startPos());
989 offsetList.append(item->endPos());
992 if (!offsetList.isEmpty()) {
994 GenTime startOffset = offsetList.takeFirst();
995 QList <GenTime> cleandOffsetList;
996 for (int k = 0; k < offsetList.size(); k++) {
997 GenTime newoffset = offsetList.at(k) - startOffset;
998 if (newoffset != GenTime() && !cleandOffsetList.contains(newoffset)) {
999 cleandOffsetList.append(newoffset);
1002 updateSnapPoints(NULL, cleandOffsetList, true);
1006 if (m_operationMode == KEYFRAME) {
1007 m_dragItem->updateSelectedKeyFrame();
1008 m_blockRefresh = false;
1010 } else if (m_operationMode == MOVE) {
1011 setCursor(Qt::ClosedHandCursor);
1012 } else if (m_operationMode == TRANSITIONSTART && event->modifiers() != Qt::ControlModifier) {
1014 info.startPos = m_dragItem->startPos();
1015 info.track = m_dragItem->track();
1016 int transitiontrack = getPreviousVideoTrack(info.track);
1017 ClipItem *transitionClip = NULL;
1018 if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.startPos.frames(m_document->fps()), m_document->tracksCount() - transitiontrack);
1019 if (transitionClip && transitionClip->endPos() < m_dragItem->endPos()) {
1020 info.endPos = transitionClip->endPos();
1022 GenTime transitionDuration(65, m_document->fps());
1023 if (m_dragItem->cropDuration() < transitionDuration)
1024 info.endPos = m_dragItem->endPos();
1026 info.endPos = info.startPos + transitionDuration;
1028 if (info.endPos == info.startPos) info.endPos = info.startPos + GenTime(65, m_document->fps());
1029 // Check there is no other transition at that place
1030 double startY = info.track * m_tracksHeight + 1 + m_tracksHeight / 2;
1031 QRectF r(info.startPos.frames(m_document->fps()), startY, (info.endPos - info.startPos).frames(m_document->fps()), m_tracksHeight / 2);
1032 QList<QGraphicsItem *> selection = m_scene->items(r);
1033 bool transitionAccepted = true;
1034 for (int i = 0; i < selection.count(); i++) {
1035 if (selection.at(i)->type() == TRANSITIONWIDGET) {
1036 Transition *tr = static_cast <Transition *>(selection.at(i));
1037 if (tr->startPos() - info.startPos > GenTime(5, m_document->fps())) {
1038 if (tr->startPos() < info.endPos) info.endPos = tr->startPos();
1039 } else transitionAccepted = false;
1042 if (transitionAccepted) slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
1043 else emit displayMessage(i18n("Cannot add transition"), ErrorMessage);
1044 } else if (m_operationMode == TRANSITIONEND && event->modifiers() != Qt::ControlModifier) {
1046 info.endPos = GenTime(m_dragItem->endPos().frames(m_document->fps()), m_document->fps());
1047 info.track = m_dragItem->track();
1048 int transitiontrack = getPreviousVideoTrack(info.track);
1049 ClipItem *transitionClip = NULL;
1050 if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.endPos.frames(m_document->fps()), m_document->tracksCount() - transitiontrack);
1051 if (transitionClip && transitionClip->startPos() > m_dragItem->startPos()) {
1052 info.startPos = transitionClip->startPos();
1054 GenTime transitionDuration(65, m_document->fps());
1055 if (m_dragItem->cropDuration() < transitionDuration) info.startPos = m_dragItem->startPos();
1056 else info.startPos = info.endPos - transitionDuration;
1058 if (info.endPos == info.startPos) info.startPos = info.endPos - GenTime(65, m_document->fps());
1059 QDomElement transition = MainWindow::transitions.getEffectByTag("luma", "dissolve").cloneNode().toElement();
1060 EffectsList::setParameter(transition, "reverse", "1");
1062 // Check there is no other transition at that place
1063 double startY = info.track * m_tracksHeight + 1 + m_tracksHeight / 2;
1064 QRectF r(info.startPos.frames(m_document->fps()), startY, (info.endPos - info.startPos).frames(m_document->fps()), m_tracksHeight / 2);
1065 QList<QGraphicsItem *> selection = m_scene->items(r);
1066 bool transitionAccepted = true;
1067 for (int i = 0; i < selection.count(); i++) {
1068 if (selection.at(i)->type() == TRANSITIONWIDGET) {
1069 Transition *tr = static_cast <Transition *>(selection.at(i));
1070 if (info.endPos - tr->endPos() > GenTime(5, m_document->fps())) {
1071 if (tr->endPos() > info.startPos) info.startPos = tr->endPos();
1072 } else transitionAccepted = false;
1075 if (transitionAccepted) slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack, transition);
1076 else emit displayMessage(i18n("Cannot add transition"), ErrorMessage);
1078 } else if ((m_operationMode == RESIZESTART || m_operationMode == RESIZEEND) && m_selectionGroup) {
1079 resetSelectionGroup(false);
1080 m_dragItem->setSelected(true);
1083 m_blockRefresh = false;
1085 QGraphicsView::mousePressEvent(event);
1088 void CustomTrackView::rebuildGroup(int childTrack, GenTime childPos)
1090 const QPointF p((int)childPos.frames(m_document->fps()), childTrack * m_tracksHeight + m_tracksHeight / 2);
1091 QList<QGraphicsItem *> list = scene()->items(p);
1092 AbstractGroupItem *group = NULL;
1093 for (int i = 0; i < list.size(); i++) {
1094 if (!list.at(i)->isEnabled()) continue;
1095 if (list.at(i)->type() == GROUPWIDGET) {
1096 group = static_cast <AbstractGroupItem *>(list.at(i));
1100 rebuildGroup(group);
1103 void CustomTrackView::rebuildGroup(AbstractGroupItem *group)
1106 resetSelectionGroup(false);
1107 m_scene->clearSelection();
1109 QList <QGraphicsItem *> children = group->childItems();
1110 m_document->clipManager()->removeGroup(group);
1111 scene()->destroyItemGroup(group);
1112 for (int i = 0; i < children.count(); i++)
1113 children.at(i)->setSelected(true);
1114 groupSelectedItems(false, true);
1118 void CustomTrackView::resetSelectionGroup(bool selectItems)
1120 if (m_selectionGroup) {
1121 // delete selection group
1122 bool snap = KdenliveSettings::snaptopoints();
1123 KdenliveSettings::setSnaptopoints(false);
1125 QList<QGraphicsItem *> children = m_selectionGroup->childItems();
1126 scene()->destroyItemGroup(m_selectionGroup);
1127 for (int i = 0; i < children.count(); i++) {
1128 if (children.at(i)->parentItem() == 0 && (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)) {
1129 if (!static_cast <AbstractClipItem *>(children.at(i))->isItemLocked()) {
1130 children.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true);
1131 children.at(i)->setSelected(selectItems);
1133 } else if (children.at(i)->type() == GROUPWIDGET) {
1134 children.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true);
1135 children.at(i)->setSelected(selectItems);
1139 m_selectionGroup = NULL;
1140 KdenliveSettings::setSnaptopoints(snap);
1144 void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup)
1146 if (m_selectionGroup) {
1147 kDebug() << "///// ERROR, TRYING TO OVERRIDE EXISTING GROUP";
1150 QList<QGraphicsItem *> selection = m_scene->selectedItems();
1151 if (selection.isEmpty()) return;
1153 // Find top left position of selection
1154 for (int i = 0; i < selection.count(); i++) {
1155 if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
1156 rectUnion = rectUnion.united(selection.at(i)->sceneBoundingRect());
1157 } else if (selection.at(i)->parentItem()) {
1158 rectUnion = rectUnion.united(selection.at(i)->parentItem()->sceneBoundingRect());
1162 if (force || selection.count() > 1) {
1163 bool snap = KdenliveSettings::snaptopoints();
1164 KdenliveSettings::setSnaptopoints(false);
1165 if (createNewGroup) {
1166 AbstractGroupItem *newGroup = m_document->clipManager()->createGroup();
1167 newGroup->setPos(rectUnion.left(), rectUnion.top() - 1);
1168 QPointF diff = newGroup->pos();
1169 newGroup->translate(-diff.x(), -diff.y());
1170 //newGroup->translate((int) -rectUnion.left(), (int) -rectUnion.top() + 1);
1172 scene()->addItem(newGroup);
1174 // Check if we are trying to include a group in a group
1175 QList <AbstractGroupItem *> groups;
1176 for (int i = 0; i < selection.count(); i++) {
1177 if (selection.at(i)->type() == GROUPWIDGET && !groups.contains(static_cast<AbstractGroupItem *>(selection.at(i))))
1178 groups.append(static_cast<AbstractGroupItem *>(selection.at(i)));
1179 else if (selection.at(i)->parentItem() && !groups.contains(static_cast<AbstractGroupItem *>(selection.at(i)->parentItem())))
1180 groups.append(static_cast<AbstractGroupItem *>(selection.at(i)->parentItem()));
1182 if (!groups.isEmpty()) {
1183 // ungroup previous groups
1184 while (!groups.isEmpty()) {
1185 AbstractGroupItem *grp = groups.takeFirst();
1186 m_document->clipManager()->removeGroup(grp);
1187 scene()->destroyItemGroup(grp);
1189 selection = m_scene->selectedItems();
1192 for (int i = 0; i < selection.count(); i++) {
1193 if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) {
1194 newGroup->addToGroup(selection.at(i));
1195 selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
1198 KdenliveSettings::setSnaptopoints(snap);
1200 m_selectionGroup = new AbstractGroupItem(m_document->fps());
1201 m_selectionGroup->setPos(rectUnion.left(), rectUnion.top() - 1);
1202 QPointF diff = m_selectionGroup->pos();
1203 //m_selectionGroup->translate((int) - rectUnion.left(), (int) -rectUnion.top() + 1);
1204 m_selectionGroup->translate(- diff.x(), -diff.y());
1206 scene()->addItem(m_selectionGroup);
1207 for (int i = 0; i < selection.count(); i++) {
1208 if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
1209 m_selectionGroup->addToGroup(selection.at(i));
1210 selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
1213 KdenliveSettings::setSnaptopoints(snap);
1214 if (m_selectionGroup) {
1215 m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps());
1216 m_selectionGroupInfo.track = m_selectionGroup->track();
1219 } else resetSelectionGroup();
1222 void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event)
1224 if (m_dragItem && m_dragItem->hasKeyFrames()) {
1225 /*if (m_moveOpMode == KEYFRAME) {
1226 // user double clicked on a keyframe, open edit dialog
1227 //TODO: update for effects with several values per keyframe
1228 QDialog d(parentWidget());
1229 Ui::KeyFrameDialog_UI view;
1231 view.kfr_position->setText(m_document->timecode().getTimecode(GenTime(m_dragItem->selectedKeyFramePos(), m_document->fps()) - m_dragItem->cropStart()));
1232 view.kfr_value->setValue(m_dragItem->selectedKeyFrameValue());
1233 view.kfr_value->setFocus();
1234 if (d.exec() == QDialog::Accepted) {
1235 int pos = m_document->timecode().getFrameCount(view.kfr_position->text());
1236 m_dragItem->updateKeyFramePos(GenTime(pos, m_document->fps()) + m_dragItem->cropStart(), (double) view.kfr_value->value() * m_dragItem->keyFrameFactor());
1237 ClipItem *item = static_cast <ClipItem *>(m_dragItem);
1238 QString previous = item->keyframes(item->selectedEffectIndex());
1239 item->updateKeyframeEffect();
1240 QString next = item->keyframes(item->selectedEffectIndex());
1241 EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
1242 m_commandStack->push(command);
1243 updateEffect(m_document->tracksCount() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
1244 emit clipItemSelected(item, item->selectedEffectIndex());
1249 GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart();
1250 int val = m_dragItem->addKeyFrame(keyFramePos, mapToScene(event->pos()).toPoint().y());
1251 ClipItem * item = static_cast <ClipItem *>(m_dragItem);
1252 //QString previous = item->keyframes(item->selectedEffectIndex());
1253 QDomElement oldEffect = item->selectedEffect().cloneNode().toElement();
1254 item->insertKeyframe(item->getEffectAt(item->selectedEffectIndex()), keyFramePos.frames(m_document->fps()), val);
1255 //item->updateKeyframeEffect();
1256 //QString next = item->keyframes(item->selectedEffectIndex());
1257 QDomElement newEffect = item->selectedEffect().cloneNode().toElement();
1258 EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), oldEffect, newEffect, item->selectedEffectIndex(), false);
1259 //EditKeyFrameCommand *command = new EditKeyFrameCommand(this, m_dragItem->track(), m_dragItem->startPos(), item->selectedEffectIndex(), previous, next, false);
1260 m_commandStack->push(command);
1261 updateEffect(m_document->tracksCount() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
1262 emit clipItemSelected(item, item->selectedEffectIndex());
1264 } else if (m_dragItem && !m_dragItem->isItemLocked()) {
1267 QList<QGraphicsItem *> collisionList = items(event->pos());
1268 if (collisionList.count() == 1 && collisionList.at(0)->type() == GUIDEITEM) {
1269 Guide *editGuide = (Guide *) collisionList.at(0);
1270 if (editGuide) slotEditGuide(editGuide->info());
1275 void CustomTrackView::editItemDuration()
1277 AbstractClipItem *item;
1281 if (m_scene->selectedItems().count() == 1) {
1282 item = static_cast <AbstractClipItem *>(m_scene->selectedItems().at(0));
1284 if (m_scene->selectedItems().empty())
1285 emit displayMessage(i18n("Cannot find clip to edit"), ErrorMessage);
1287 emit displayMessage(i18n("Cannot edit the duration of multiple items"), ErrorMessage);
1293 emit displayMessage(i18n("Cannot find clip to edit"), ErrorMessage);
1297 if (item->type() == GROUPWIDGET || (item->parentItem() && item->parentItem()->type() == GROUPWIDGET)) {
1298 emit displayMessage(i18n("Cannot edit an item in a group"), ErrorMessage);
1302 if (!item->isItemLocked()) {
1305 if (item->type() == TRANSITIONWIDGET)
1306 getTransitionAvailableSpace(item, minimum, maximum);
1308 getClipAvailableSpace(item, minimum, maximum);
1310 ClipDurationDialog d(item, m_document->timecode(), minimum, maximum, this);
1311 if (d.exec() == QDialog::Accepted) {
1312 ItemInfo clipInfo = item->info();
1313 ItemInfo startInfo = clipInfo;
1314 if (item->type() == TRANSITIONWIDGET) {
1315 // move & resize transition
1316 clipInfo.startPos = d.startPos();
1317 clipInfo.endPos = clipInfo.startPos + d.duration();
1318 clipInfo.track = item->track();
1319 MoveTransitionCommand *command = new MoveTransitionCommand(this, startInfo, clipInfo, true);
1320 updateTrackDuration(clipInfo.track, command);
1321 m_commandStack->push(command);
1323 // move and resize clip
1324 QUndoCommand *moveCommand = new QUndoCommand();
1325 moveCommand->setText(i18n("Edit clip"));
1326 if (d.duration() < item->cropDuration() || d.cropStart() != clipInfo.cropStart) {
1327 // duration was reduced, so process it first
1328 clipInfo.endPos = clipInfo.startPos + d.duration();
1329 clipInfo.cropStart = d.cropStart();
1330 new ResizeClipCommand(this, startInfo, clipInfo, true, false, moveCommand);
1332 if (d.startPos() != clipInfo.startPos) {
1333 startInfo = clipInfo;
1334 clipInfo.startPos = d.startPos();
1335 clipInfo.endPos = item->endPos() + (clipInfo.startPos - startInfo.startPos);
1336 new MoveClipCommand(this, startInfo, clipInfo, true, moveCommand);
1338 if (d.duration() > item->cropDuration()) {
1339 // duration was increased, so process it after move
1340 startInfo = clipInfo;
1341 clipInfo.endPos = clipInfo.startPos + d.duration();
1342 clipInfo.cropStart = d.cropStart();
1343 new ResizeClipCommand(this, startInfo, clipInfo, true, false, moveCommand);
1345 updateTrackDuration(clipInfo.track, moveCommand);
1346 m_commandStack->push(moveCommand);
1350 emit displayMessage(i18n("Item is locked"), ErrorMessage);
1354 void CustomTrackView::editKeyFrame(const GenTime /*pos*/, const int /*track*/, const int /*index*/, const QString /*keyframes*/)
1356 /*ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), track);
1358 clip->setKeyframes(index, keyframes);
1359 updateEffect(m_document->tracksCount() - clip->track(), clip->startPos(), clip->effectAt(index), index, false);
1360 } else emit displayMessage(i18n("Cannot find clip with keyframe"), ErrorMessage);*/
1364 void CustomTrackView::displayContextMenu(QPoint pos, AbstractClipItem *clip, AbstractGroupItem *group)
1366 m_deleteGuide->setEnabled(m_dragGuide != NULL);
1367 m_editGuide->setEnabled(m_dragGuide != NULL);
1368 m_markerMenu->clear();
1369 m_markerMenu->setEnabled(false);
1371 m_timelineContextMenu->popup(pos);
1372 } else if (group != NULL) {
1373 m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
1374 m_ungroupAction->setEnabled(true);
1375 updateClipTypeActions(NULL);
1376 m_timelineContextClipMenu->popup(pos);
1378 m_ungroupAction->setEnabled(false);
1379 if (clip->type() == AVWIDGET) {
1380 ClipItem *item = static_cast <ClipItem*>(clip);
1381 //build go to marker menu
1382 if (item->baseClip()) {
1383 QList <CommentedTime> markers = item->baseClip()->commentedSnapMarkers();
1384 int offset = item->startPos().frames(m_document->fps());
1385 if (!markers.isEmpty()) {
1386 for (int i = 0; i < markers.count(); i++) {
1387 int pos = (int) markers.at(i).time().frames(m_document->timecode().fps());
1388 QString position = m_document->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
1389 QAction *go = m_markerMenu->addAction(position);
1390 go->setData(pos + offset);
1393 m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
1395 updateClipTypeActions(item);
1396 m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
1397 m_timelineContextClipMenu->popup(pos);
1398 } else if (clip->type() == TRANSITIONWIDGET) {
1399 m_timelineContextTransitionMenu->popup(pos);
1404 void CustomTrackView::activateMonitor()
1406 emit activateDocumentMonitor();
1409 void CustomTrackView::insertClipCut(DocClipBase *clip, int in, int out)
1411 resetSelectionGroup();
1413 info.startPos = GenTime();
1414 info.cropStart = GenTime(in, m_document->fps());
1415 info.endPos = GenTime(out - in, m_document->fps());
1416 info.cropDuration = info.endPos - info.startPos;
1419 // Check if clip can be inserted at that position
1420 ItemInfo pasteInfo = info;
1421 pasteInfo.startPos = GenTime(m_cursorPos, m_document->fps());
1422 pasteInfo.endPos = pasteInfo.startPos + info.endPos;
1423 pasteInfo.track = selectedTrack();
1424 if (!canBePastedTo(pasteInfo, AVWIDGET)) {
1425 emit displayMessage(i18n("Cannot insert clip in timeline"), ErrorMessage);
1429 AddTimelineClipCommand *command = new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), pasteInfo, EffectsList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, true, false);
1430 updateTrackDuration(pasteInfo.track, command);
1431 m_commandStack->push(command);
1433 selectClip(true, false);
1434 // Automatic audio split
1435 if (KdenliveSettings::splitaudio())
1439 bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos)
1441 if (data->hasFormat("kdenlive/clip")) {
1443 m_scene->clearSelection();
1444 resetSelectionGroup(false);
1445 QStringList list = QString(data->data("kdenlive/clip")).split(';');
1446 DocClipBase *clip = m_document->getBaseClip(list.at(0));
1448 kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << list.at(0);
1451 if (clip->producer() == NULL) {
1452 emit displayMessage(i18n("Clip not ready"), ErrorMessage);
1455 QPointF framePos = mapToScene(pos);
1457 info.startPos = GenTime();
1458 info.cropStart = GenTime(list.at(1).toInt(), m_document->fps());
1459 info.endPos = GenTime(list.at(2).toInt() - list.at(1).toInt(), m_document->fps());
1460 info.cropDuration = info.endPos - info.startPos;
1463 // Check if clip can be inserted at that position
1464 ItemInfo pasteInfo = info;
1465 pasteInfo.startPos = GenTime((int)(framePos.x() + 0.5), m_document->fps());
1466 pasteInfo.endPos = pasteInfo.startPos + info.endPos;
1467 pasteInfo.track = (int)(framePos.y() / m_tracksHeight);
1468 framePos.setX((int)(framePos.x() + 0.5));
1469 framePos.setY(pasteInfo.track * m_tracksHeight);
1470 if (!canBePastedTo(pasteInfo, AVWIDGET)) {
1473 m_selectionGroup = new AbstractGroupItem(m_document->fps());
1474 ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1);
1475 m_selectionGroup->addToGroup(item);
1476 item->setFlag(QGraphicsItem::ItemIsMovable, false);
1478 QList <GenTime> offsetList;
1479 offsetList.append(info.endPos);
1480 updateSnapPoints(NULL, offsetList);
1481 m_selectionGroup->setPos(framePos);
1482 scene()->addItem(m_selectionGroup);
1483 m_selectionGroup->setSelected(true);
1485 } else if (data->hasFormat("kdenlive/producerslist")) {
1487 QStringList ids = QString(data->data("kdenlive/producerslist")).split(';');
1488 m_scene->clearSelection();
1489 resetSelectionGroup(false);
1491 QList <GenTime> offsetList;
1492 QList <ItemInfo> infoList;
1493 QPointF framePos = mapToScene(pos);
1494 GenTime start = GenTime((int)(framePos.x() + 0.5), m_document->fps());
1495 int track = (int)(framePos.y() / m_tracksHeight);
1496 framePos.setX((int)(framePos.x() + 0.5));
1497 framePos.setY(track * m_tracksHeight);
1499 // Check if clips can be inserted at that position
1500 for (int i = 0; i < ids.size(); ++i) {
1501 DocClipBase *clip = m_document->getBaseClip(ids.at(i));
1503 kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << ids.at(i);
1506 if (clip->producer() == NULL) {
1507 emit displayMessage(i18n("Clip not ready"), ErrorMessage);
1511 info.startPos = start;
1512 info.cropDuration = clip->duration();
1513 info.endPos = info.startPos + info.cropDuration;
1515 infoList.append(info);
1516 start += clip->duration();
1518 if (!canBePastedTo(infoList, AVWIDGET)) {
1521 m_selectionGroup = new AbstractGroupItem(m_document->fps());
1523 for (int i = 0; i < ids.size(); ++i) {
1524 DocClipBase *clip = m_document->getBaseClip(ids.at(i));
1526 info.startPos = start;
1527 info.cropDuration = clip->duration();
1528 info.endPos = info.startPos + info.cropDuration;
1530 start += info.cropDuration;
1531 offsetList.append(start);
1532 ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, false);
1533 item->setFlag(QGraphicsItem::ItemIsMovable, false);
1534 m_selectionGroup->addToGroup(item);
1535 if (!clip->isPlaceHolder()) m_waitingThumbs.append(item);
1538 updateSnapPoints(NULL, offsetList);
1539 m_selectionGroup->setPos(framePos);
1540 scene()->addItem(m_selectionGroup);
1541 //m_selectionGroup->setZValue(10);
1542 m_thumbsTimer.start();
1546 // the drag is not a clip (may be effect, ...)
1554 void CustomTrackView::dragEnterEvent(QDragEnterEvent * event)
1556 if (insertDropClips(event->mimeData(), event->pos())) {
1557 event->acceptProposedAction();
1558 } else QGraphicsView::dragEnterEvent(event);
1561 bool CustomTrackView::itemCollision(AbstractClipItem *item, ItemInfo newPos)
1563 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);
1564 QList<QGraphicsItem*> collindingItems = scene()->items(shape, Qt::IntersectsItemShape);
1565 collindingItems.removeAll(item);
1566 if (collindingItems.isEmpty()) return false;
1568 for (int i = 0; i < collindingItems.count(); i++) {
1569 QGraphicsItem *collision = collindingItems.at(i);
1570 if (collision->type() == item->type()) {
1572 kDebug() << "// COLLISIION DETECTED";
1580 void CustomTrackView::slotRefreshEffects(ClipItem *clip)
1582 int track = m_document->tracksCount() - clip->track();
1583 GenTime pos = clip->startPos();
1584 if (!m_document->renderer()->mltRemoveEffect(track, pos, "-1", false, false)) {
1585 emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
1588 bool success = true;
1589 for (int i = 0; i < clip->effectsCount(); i++) {
1590 if (!m_document->renderer()->mltAddEffect(track, pos, getEffectArgs(clip->effectAt(i)), false)) success = false;
1592 if (!success) emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
1593 m_document->renderer()->doRefresh();
1596 void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect)
1598 if (pos < GenTime()) {
1601 m_document->addTrackEffect(track - 1, effect);
1602 m_document->renderer()->mltAddTrackEffect(track, getEffectArgs(effect));
1603 emit updateTrackEffectState(track - 1);
1604 emit showTrackEffects(track, m_document->trackInfoAt(track - 1));
1607 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
1609 // Special case: speed effect
1610 if (effect.attribute("id") == "speed") {
1611 if (clip->clipType() != VIDEO && clip->clipType() != AV && clip->clipType() != PLAYLIST) {
1612 emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
1615 double speed = EffectsList::parameter(effect, "speed").toDouble() / 100.0;
1616 int strobe = EffectsList::parameter(effect, "strobe").toInt();
1617 if (strobe == 0) strobe = 1;
1618 doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), speed, 1.0, strobe, clip->baseClip()->getId());
1619 EffectsParameterList params = clip->addEffect(effect);
1620 m_document->renderer()->mltAddEffect(track, pos, params);
1621 if (clip->isSelected()) emit clipItemSelected(clip);
1624 EffectsParameterList params = clip->addEffect(effect);
1625 if (!m_document->renderer()->mltAddEffect(track, pos, params))
1626 emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
1627 if (clip->isSelected()) emit clipItemSelected(clip);
1628 } else emit displayMessage(i18n("Cannot find clip to add effect"), ErrorMessage);
1631 void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect)
1633 QString index = effect.attribute("kdenlive_ix");
1634 if (pos < GenTime()) {
1635 // Delete track effect
1636 if (m_document->renderer()->mltRemoveTrackEffect(track, index, true)) {
1637 m_document->removeTrackEffect(track - 1, effect);
1639 else emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
1640 emit updateTrackEffectState(track - 1);
1641 emit showTrackEffects(track, m_document->trackInfoAt(track - 1));
1644 // Special case: speed effect
1645 if (effect.attribute("id") == "speed") {
1646 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
1648 doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), 1.0, clip->speed(), 1, clip->baseClip()->getId());
1649 clip->deleteEffect(index);
1650 emit clipItemSelected(clip);
1651 m_document->renderer()->mltRemoveEffect(track, pos, index, true);
1655 if (!m_document->renderer()->mltRemoveEffect(track, pos, index, true)) {
1656 kDebug() << "// ERROR REMOV EFFECT: " << index << ", DISABLE: " << effect.attribute("disable");
1657 emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
1660 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
1662 clip->deleteEffect(index);
1663 emit clipItemSelected(clip);
1667 void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem *group)
1669 QList<QGraphicsItem *> itemList = group->childItems();
1670 QUndoCommand *effectCommand = new QUndoCommand();
1672 QDomNode namenode = effect.elementsByTagName("name").item(0);
1673 if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data());
1674 else effectName = i18n("effect");
1675 effectCommand->setText(i18n("Add %1", effectName));
1677 for (int i = 0; i < itemList.count(); i++) {
1678 if (itemList.at(i)->type() == AVWIDGET) {
1679 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1680 if (effect.attribute("type") == "audio") {
1681 // Don't add audio effects on video clips
1682 if (item->isVideoOnly() || (item->clipType() != AUDIO && item->clipType() != AV && item->clipType() != PLAYLIST)) continue;
1683 } else if (effect.hasAttribute("type") == false) {
1684 // Don't add video effect on audio clips
1685 if (item->isAudioOnly() || item->clipType() == AUDIO) continue;
1688 if (effect.attribute("unique", "0") != "0" && item->hasEffect(effect.attribute("tag"), effect.attribute("id")) != -1) {
1689 emit displayMessage(i18n("Effect already present in clip"), ErrorMessage);
1692 if (item->isItemLocked()) {
1695 item->initEffect(effect);
1696 if (effect.attribute("tag") == "ladspa") {
1697 QString ladpsaFile = m_document->getLadspaFile();
1698 initEffects::ladspaEffectFile(ladpsaFile, effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
1699 effect.setAttribute("src", ladpsaFile);
1701 new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), effect, true, effectCommand);
1706 m_commandStack->push(effectCommand);
1707 setDocumentModified();
1708 } else delete effectCommand;
1711 void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
1713 QList<QGraphicsItem *> itemList;
1714 QUndoCommand *effectCommand = new QUndoCommand();
1716 QDomNode namenode = effect.elementsByTagName("name").item(0);
1717 if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data());
1718 else effectName = i18n("effect");
1719 effectCommand->setText(i18n("Add %1", effectName));
1721 if (track == -1) itemList = scene()->selectedItems();
1722 if (itemList.isEmpty()) {
1723 ClipItem *clip = getClipItemAt((int) pos.frames(m_document->fps()), track);
1724 if (clip) itemList.append(clip);
1725 else emit displayMessage(i18n("Select a clip if you want to apply an effect"), ErrorMessage);
1729 for (int i = 0; i < itemList.count(); i++) {
1730 if (itemList.at(i)->type() == GROUPWIDGET) {
1731 QList<QGraphicsItem *> subitems = itemList.at(i)->childItems();
1732 for (int j = 0; j < subitems.count(); j++) {
1733 if (!itemList.contains(subitems.at(j))) itemList.append(subitems.at(j));
1738 for (int i = 0; i < itemList.count(); i++) {
1739 if (itemList.at(i)->type() == AVWIDGET) {
1740 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1741 if (effect.attribute("type") == "audio") {
1742 // Don't add audio effects on video clips
1743 if (item->isVideoOnly() || (item->clipType() != AUDIO && item->clipType() != AV && item->clipType() != PLAYLIST)) {
1744 /* do not show error message when item is part of a group as the user probably knows what he does then
1745 * and the message is annoying when working with the split audio feature */
1746 if (!item->parentItem() || item->parentItem() == m_selectionGroup)
1747 emit displayMessage(i18n("Cannot add an audio effect to this clip"), ErrorMessage);
1750 } else if (effect.attribute("type") == "video" || !effect.hasAttribute("type")) {
1751 // Don't add video effect on audio clips
1752 if (item->isAudioOnly() || item->clipType() == AUDIO) {
1753 /* do not show error message when item is part of a group as the user probably knows what he does then
1754 * and the message is annoying when working with the split audio feature */
1755 if (!item->parentItem() || item->parentItem() == m_selectionGroup)
1756 emit displayMessage(i18n("Cannot add a video effect to this clip"), ErrorMessage);
1760 if (item->hasEffect(effect.attribute("tag"), effect.attribute("id")) != -1 && effect.attribute("unique", "0") != "0") {
1761 emit displayMessage(i18n("Effect already present in clip"), ErrorMessage);
1764 if (item->isItemLocked()) {
1768 if (effect.attribute("id") == "freeze" && m_cursorPos > item->startPos().frames(m_document->fps()) && m_cursorPos < item->endPos().frames(m_document->fps())) {
1769 item->initEffect(effect, m_cursorPos - item->startPos().frames(m_document->fps()));
1771 item->initEffect(effect);
1774 if (effect.attribute("tag") == "ladspa") {
1775 QString ladpsaFile = m_document->getLadspaFile();
1776 initEffects::ladspaEffectFile(ladpsaFile, effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
1777 effect.setAttribute("src", ladpsaFile);
1779 new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), effect, true, effectCommand);
1782 if (effectCommand->childCount() > 0) {
1783 m_commandStack->push(effectCommand);
1784 setDocumentModified();
1785 if (effectCommand->childCount() == 1) {
1786 // Display newly added clip effect
1787 for (int i = 0; i < itemList.count(); i++) {
1788 if (itemList.at(i)->type() == AVWIDGET) {
1789 ClipItem *clip = static_cast<ClipItem *>(itemList.at(i));
1790 if (!clip->isSelected()) {
1792 clip->setSelected(true);
1794 clip->setSelectedEffect(clip->effectsCount() - 1);
1795 emit clipItemSelected(clip, clip->effectsCount() - 1);
1800 } else delete effectCommand;
1803 void CustomTrackView::slotDeleteEffect(ClipItem *clip, int track, QDomElement effect, bool affectGroup)
1806 // delete track effect
1807 AddEffectCommand *command = new AddEffectCommand(this, track, GenTime(-1), effect, false);
1808 m_commandStack->push(command);
1809 setDocumentModified();
1812 if (affectGroup && clip->parentItem() && clip->parentItem() == m_selectionGroup) {
1813 //clip is in a group, also remove the effect in other clips of the group
1814 QList<QGraphicsItem *> items = m_selectionGroup->childItems();
1815 QUndoCommand *delCommand = new QUndoCommand();
1817 QDomNode namenode = effect.elementsByTagName("name").item(0);
1818 if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data());
1819 else effectName = i18n("effect");
1820 delCommand->setText(i18n("Delete %1", effectName));
1823 for (int i = 0; i < items.count(); i++) {
1824 if (items.at(i)->type() == GROUPWIDGET) {
1825 QList<QGraphicsItem *> subitems = items.at(i)->childItems();
1826 for (int j = 0; j < subitems.count(); j++) {
1827 if (!items.contains(subitems.at(j))) items.append(subitems.at(j));
1832 for (int i = 0; i < items.count(); i++) {
1833 if (items.at(i)->type() == AVWIDGET) {
1834 ClipItem *item = static_cast <ClipItem *>(items.at(i));
1835 int ix = item->hasEffect(effect.attribute("tag"), effect.attribute("id"));
1837 QDomElement eff = item->effectAt(ix);
1838 new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), eff, false, delCommand);
1842 if (delCommand->childCount() > 0)
1843 m_commandStack->push(delCommand);
1846 setDocumentModified();
1849 AddEffectCommand *command = new AddEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effect, false);
1850 m_commandStack->push(command);
1851 setDocumentModified();
1854 void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedEffect, int ix, bool triggeredByUser)
1856 if (insertedEffect.isNull()) {
1857 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
1860 QDomElement effect = insertedEffect.cloneNode().toElement();
1861 //kDebug() << "// update effect ix: " << effect.attribute("kdenlive_ix")<<", TRACK: "<<track;
1862 if (pos < GenTime()) {
1863 // editing a track effect
1864 EffectsParameterList effectParams = getEffectArgs(effect);
1865 if (effect.attribute("tag") == "ladspa") {
1866 // Update the ladspa affect file
1867 initEffects::ladspaEffectFile(effect.attribute("src"), effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
1869 // check if we are trying to reset a keyframe effect
1870 if (effectParams.hasParam("keyframes") && effectParams.paramValue("keyframes").isEmpty()) {
1871 //clip->initEffect(effect);
1872 effectParams = getEffectArgs(effect);
1874 if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - track, pos, effectParams))
1875 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
1876 m_document->setTrackEffect(m_document->tracksCount() - track - 1, ix, effect);
1877 emit updateTrackEffectState(track);
1878 setDocumentModified();
1882 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
1884 // Special case: speed effect
1885 if (effect.attribute("id") == "speed") {
1886 if (effect.attribute("disable") == "1") doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), 1.0, clip->speed(), 1, clip->baseClip()->getId());
1888 double speed = EffectsList::parameter(effect, "speed").toDouble() / 100.0;
1889 int strobe = EffectsList::parameter(effect, "strobe").toInt();
1890 if (strobe == 0) strobe = 1;
1891 doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), speed, clip->speed(), strobe, clip->baseClip()->getId());
1893 clip->setEffectAt(ix, effect);
1894 if (ix == clip->selectedEffectIndex()) {
1895 clip->setSelectedEffect(ix);
1896 if (!triggeredByUser) emit clipItemSelected(clip, ix);
1901 EffectsParameterList effectParams = getEffectArgs(effect);
1902 if (effect.attribute("tag") == "ladspa") {
1903 // Update the ladspa affect file
1904 initEffects::ladspaEffectFile(effect.attribute("src"), effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
1906 // check if we are trying to reset a keyframe effect
1907 if (effectParams.hasParam("keyframes") && effectParams.paramValue("keyframes").isEmpty()) {
1908 clip->initEffect(effect);
1909 effectParams = getEffectArgs(effect);
1911 if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - clip->track(), clip->startPos(), effectParams))
1912 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
1914 clip->setEffectAt(ix, effect);
1915 if (ix == clip->selectedEffectIndex()) {
1916 clip->setSelectedEffect(ix);
1917 if (!triggeredByUser) emit clipItemSelected(clip, ix);
1919 if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
1920 // A fade effect was modified, update the clip
1921 if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
1922 int pos = effectParams.paramValue("out").toInt() - effectParams.paramValue("in").toInt();
1923 clip->setFadeIn(pos);
1925 if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
1926 int pos = effectParams.paramValue("out").toInt() - effectParams.paramValue("in").toInt();
1927 clip->setFadeOut(pos);
1931 setDocumentModified();
1934 void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos)
1936 if (pos < GenTime()) {
1937 // Moving track effect
1938 QDomElement act = m_document->getTrackEffect(m_document->tracksCount() - track - 1, newPos - 1);
1939 QDomElement before = m_document->getTrackEffect(m_document->tracksCount() - track - 1, oldPos - 1);
1941 if (!act.isNull() && !before.isNull()) {
1942 m_document->setTrackEffect(m_document->tracksCount() - track - 1, oldPos - 1, act);
1943 m_document->setTrackEffect(m_document->tracksCount() - track - 1, newPos - 1, before);
1944 m_document->renderer()->mltMoveEffect(m_document->tracksCount() - track, pos, oldPos, newPos);
1945 emit showTrackEffects(m_document->tracksCount() - track, m_document->trackInfoAt(m_document->tracksCount() - track - 1));
1946 } else emit displayMessage(i18n("Cannot move effect"), ErrorMessage);
1949 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
1950 if (clip && !clip->effectAt(newPos - 1).isNull() && !clip->effectAt(oldPos - 1).isNull()) {
1951 QDomElement act = clip->effectAt(newPos - 1);
1952 QDomElement before = clip->effectAt(oldPos - 1);
1953 clip->setEffectAt(oldPos - 1, act);
1954 clip->setEffectAt(newPos - 1, before);
1955 // special case: speed effect, which is a pseudo-effect, not appearing in MLT's effects
1956 if (act.attribute("id") == "speed") {
1957 m_document->renderer()->mltUpdateEffectPosition(track, pos, oldPos, newPos);
1958 } else if (before.attribute("id") == "speed") {
1959 m_document->renderer()->mltUpdateEffectPosition(track, pos, newPos, oldPos);
1960 } else m_document->renderer()->mltMoveEffect(track, pos, oldPos, newPos);
1961 emit clipItemSelected(clip, newPos - 1);
1962 setDocumentModified();
1963 } else emit displayMessage(i18n("Cannot move effect"), ErrorMessage);
1966 void CustomTrackView::slotChangeEffectState(ClipItem *clip, int track, int effectPos, bool disable)
1968 EditEffectCommand *command;
1970 if (clip == NULL) effect = m_document->getTrackEffect(track - 1, effectPos);
1971 else effect = clip->effectAt(effectPos);
1972 QDomElement oldEffect = effect.cloneNode().toElement();
1973 effect.setAttribute("disable", (int) disable);
1977 // editing track effect
1978 command = new EditEffectCommand(this, m_document->tracksCount() - track, GenTime(-1), oldEffect, effect, effectPos, true);
1980 command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldEffect, effect, effectPos, true);
1982 m_commandStack->push(command);
1983 setDocumentModified();;
1986 void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int track, int currentPos, int newPos)
1988 MoveEffectCommand *command;
1990 // editing track effect
1991 command = new MoveEffectCommand(this, m_document->tracksCount() - track, GenTime(-1), currentPos, newPos);
1992 } else command = new MoveEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), currentPos, newPos);
1993 m_commandStack->push(command);
1994 setDocumentModified();
1997 void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, int track, QDomElement oldeffect, QDomElement effect, int ix)
1999 EditEffectCommand *command;
2000 if (clip) command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldeffect, effect, ix, true);
2001 else command = new EditEffectCommand(this, m_document->tracksCount() - track, GenTime(-1), oldeffect, effect, ix, true);
2002 m_commandStack->push(command);
2005 void CustomTrackView::slotUpdateClipRegion(ClipItem *clip, int ix, QString region)
2007 QDomElement effect = clip->getEffectAt(ix);
2008 QDomElement oldeffect = effect.cloneNode().toElement();
2009 effect.setAttribute("region", region);
2010 EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldeffect, effect, ix, true);
2011 m_commandStack->push(command);
2014 ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, bool execute)
2018 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
2019 if (!item || cutTime >= item->endPos() || cutTime <= item->startPos()) {
2020 emit displayMessage(i18n("Cannot find clip to cut"), ErrorMessage);
2022 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);
2024 kDebug() << "/// ERROR NO CLIP at: " << info.startPos.frames(m_document->fps()) << ", track: " << info.track;
2025 m_blockRefresh = false;
2029 kDebug() << "///////// CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25);
2031 if (execute) m_document->renderer()->mltCutClip(m_document->tracksCount() - info.track, cutTime);
2032 int cutPos = (int) cutTime.frames(m_document->fps());
2034 newPos.startPos = cutTime;
2035 newPos.endPos = info.endPos;
2036 newPos.cropStart = item->info().cropStart + (cutTime - info.startPos);
2037 newPos.track = info.track;
2038 newPos.cropDuration = newPos.endPos - newPos.startPos;
2040 bool snap = KdenliveSettings::snaptopoints();
2041 KdenliveSettings::setSnaptopoints(false);
2042 ClipItem *dup = item->clone(newPos);
2043 // remove unwanted effects (fade in) from 2nd part of cutted clip
2044 int ix = dup->hasEffect(QString(), "fadein");
2046 QDomElement oldeffect = item->effectAt(ix);
2047 dup->deleteEffect(oldeffect.attribute("kdenlive_ix"));
2049 ix = dup->hasEffect(QString(), "fade_from_black");
2051 QDomElement oldeffect = item->effectAt(ix);
2052 dup->deleteEffect(oldeffect.attribute("kdenlive_ix"));
2054 item->resizeEnd(cutPos);
2055 scene()->addItem(dup);
2056 if (item->checkKeyFrames())
2057 slotRefreshEffects(item);
2058 if (dup->checkKeyFrames())
2059 slotRefreshEffects(dup);
2061 updatePanZoom(item);
2062 updatePanZoom(dup, cutTime - item->startPos());
2064 item->baseClip()->addReference();
2065 m_document->updateClip(item->baseClip()->getId());
2066 setDocumentModified();
2067 KdenliveSettings::setSnaptopoints(snap);
2069 //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);
2073 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
2074 ClipItem *dup = getClipItemAt((int) cutTime.frames(m_document->fps()), info.track);
2076 if (!item || !dup || item == dup) {
2077 emit displayMessage(i18n("Cannot find clip to uncut"), ErrorMessage);
2078 m_blockRefresh = false;
2081 if (m_document->renderer()->mltRemoveClip(m_document->tracksCount() - info.track, cutTime) == false) {
2082 emit displayMessage(i18n("Error removing clip at %1 on track %2", m_document->timecode().getTimecodeFromFrames(cutTime.frames(m_document->fps())), info.track), ErrorMessage);
2086 /*kDebug() << "// UNCUTTING CLIPS: ITEM 1 (" << item->startPos().frames(25) << "x" << item->endPos().frames(25) << ")";
2087 kDebug() << "// UNCUTTING CLIPS: ITEM 2 (" << dup->startPos().frames(25) << "x" << dup->endPos().frames(25) << ")";
2088 kDebug() << "// UNCUTTING CLIPS, INFO (" << info.startPos.frames(25) << "x" << info.endPos.frames(25) << ") , CUT: " << cutTime.frames(25);;*/
2089 //deleteClip(dup->info());
2091 bool snap = KdenliveSettings::snaptopoints();
2092 KdenliveSettings::setSnaptopoints(false);
2093 m_waitingThumbs.removeAll(dup);
2094 if (dup->isSelected()) emit clipItemSelected(NULL);
2095 dup->baseClip()->removeReference();
2096 m_document->updateClip(dup->baseClip()->getId());
2097 scene()->removeItem(dup);
2101 ItemInfo clipinfo = item->info();
2102 clipinfo.track = m_document->tracksCount() - clipinfo.track;
2103 bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, info.endPos - info.startPos);
2105 item->resizeEnd((int) info.endPos.frames(m_document->fps()));
2107 updatePanZoom(item);
2109 setDocumentModified();
2111 emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
2113 KdenliveSettings::setSnaptopoints(snap);
2116 //QTimer::singleShot(3000, this, SLOT(slotEnableRefresh()));
2119 void CustomTrackView::slotEnableRefresh()
2121 m_blockRefresh = false;
2124 void CustomTrackView::slotAddTransitionToSelectedClips(QDomElement transition)
2126 QList<QGraphicsItem *> itemList = scene()->selectedItems();
2127 if (itemList.count() == 1) {
2128 if (itemList.at(0)->type() == AVWIDGET) {
2129 ClipItem *item = (ClipItem *) itemList.at(0);
2131 info.track = item->track();
2132 ClipItem *transitionClip = NULL;
2133 const int transitiontrack = getPreviousVideoTrack(info.track);
2134 GenTime pos = GenTime((int)(mapToScene(m_menuPosition).x()), m_document->fps());
2135 if (pos < item->startPos() + item->cropDuration() / 2) {
2136 // add transition to clip start
2137 info.startPos = item->startPos();
2138 if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.startPos.frames(m_document->fps()), m_document->tracksCount() - transitiontrack);
2139 if (transitionClip && transitionClip->endPos() < item->endPos()) {
2140 info.endPos = transitionClip->endPos();
2141 } else info.endPos = info.startPos + GenTime(65, m_document->fps());
2142 // Check there is no other transition at that place
2143 double startY = info.track * m_tracksHeight + 1 + m_tracksHeight / 2;
2144 QRectF r(info.startPos.frames(m_document->fps()), startY, (info.endPos - info.startPos).frames(m_document->fps()), m_tracksHeight / 2);
2145 QList<QGraphicsItem *> selection = m_scene->items(r);
2146 bool transitionAccepted = true;
2147 for (int i = 0; i < selection.count(); i++) {
2148 if (selection.at(i)->type() == TRANSITIONWIDGET) {
2149 Transition *tr = static_cast <Transition *>(selection.at(i));
2150 if (tr->startPos() - info.startPos > GenTime(5, m_document->fps())) {
2151 if (tr->startPos() < info.endPos) info.endPos = tr->startPos();
2152 } else transitionAccepted = false;
2155 if (transitionAccepted) slotAddTransition(item, info, transitiontrack, transition);
2156 else emit displayMessage(i18n("Cannot add transition"), ErrorMessage);
2159 // add transition to clip end
2160 info.endPos = item->endPos();
2161 if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.endPos.frames(m_document->fps()), m_document->tracksCount() - transitiontrack);
2162 if (transitionClip && transitionClip->startPos() > item->startPos()) {
2163 info.startPos = transitionClip->startPos();
2164 } else info.startPos = info.endPos - GenTime(65, m_document->fps());
2165 if (transition.attribute("tag") == "luma") EffectsList::setParameter(transition, "reverse", "1");
2166 else if (transition.attribute("id") == "slide") EffectsList::setParameter(transition, "invert", "1");
2168 // Check there is no other transition at that place
2169 double startY = info.track * m_tracksHeight + 1 + m_tracksHeight / 2;
2170 QRectF r(info.startPos.frames(m_document->fps()), startY, (info.endPos - info.startPos).frames(m_document->fps()), m_tracksHeight / 2);
2171 QList<QGraphicsItem *> selection = m_scene->items(r);
2172 bool transitionAccepted = true;
2173 for (int i = 0; i < selection.count(); i++) {
2174 if (selection.at(i)->type() == TRANSITIONWIDGET) {
2175 Transition *tr = static_cast <Transition *>(selection.at(i));
2176 if (info.endPos - tr->endPos() > GenTime(5, m_document->fps())) {
2177 if (tr->endPos() > info.startPos) info.startPos = tr->endPos();
2178 } else transitionAccepted = false;
2181 if (transitionAccepted) slotAddTransition(item, info, transitiontrack, transition);
2182 else emit displayMessage(i18n("Cannot add transition"), ErrorMessage);
2185 } else for (int i = 0; i < itemList.count(); i++) {
2186 if (itemList.at(i)->type() == AVWIDGET) {
2187 ClipItem *item = (ClipItem *) itemList.at(i);
2189 info.startPos = item->startPos();
2190 info.endPos = info.startPos + GenTime(65, m_document->fps());
2191 info.track = item->track();
2193 // Check there is no other transition at that place
2194 double startY = info.track * m_tracksHeight + 1 + m_tracksHeight / 2;
2195 QRectF r(info.startPos.frames(m_document->fps()), startY, (info.endPos - info.startPos).frames(m_document->fps()), m_tracksHeight / 2);
2196 QList<QGraphicsItem *> selection = m_scene->items(r);
2197 bool transitionAccepted = true;
2198 for (int i = 0; i < selection.count(); i++) {
2199 if (selection.at(i)->type() == TRANSITIONWIDGET) {
2200 Transition *tr = static_cast <Transition *>(selection.at(i));
2201 if (tr->startPos() - info.startPos > GenTime(5, m_document->fps())) {
2202 if (tr->startPos() < info.endPos) info.endPos = tr->startPos();
2203 } else transitionAccepted = false;
2206 int transitiontrack = getPreviousVideoTrack(info.track);
2207 if (transitionAccepted) slotAddTransition(item, info, transitiontrack, transition);
2208 else emit displayMessage(i18n("Cannot add transition"), ErrorMessage);
2213 void CustomTrackView::slotAddTransition(ClipItem* /*clip*/, ItemInfo transitionInfo, int endTrack, QDomElement transition)
2215 if (transitionInfo.startPos >= transitionInfo.endPos) {
2216 emit displayMessage(i18n("Invalid transition"), ErrorMessage);
2219 AddTransitionCommand* command = new AddTransitionCommand(this, transitionInfo, endTrack, transition, false, true);
2220 m_commandStack->push(command);
2221 setDocumentModified();
2224 void CustomTrackView::addTransition(ItemInfo transitionInfo, int endTrack, QDomElement params, bool refresh)
2226 Transition *tr = new Transition(transitionInfo, endTrack, m_document->fps(), params, true);
2227 //kDebug() << "---- ADDING transition " << params.attribute("value");
2228 if (m_document->renderer()->mltAddTransition(tr->transitionTag(), endTrack, m_document->tracksCount() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, tr->toXML(), refresh)) {
2229 scene()->addItem(tr);
2230 setDocumentModified();
2232 emit displayMessage(i18n("Cannot add transition"), ErrorMessage);
2237 void CustomTrackView::deleteTransition(ItemInfo transitionInfo, int endTrack, QDomElement /*params*/, bool refresh)
2239 Transition *item = getTransitionItemAt(transitionInfo.startPos, transitionInfo.track);
2241 emit displayMessage(i18n("Select clip to delete"), ErrorMessage);
2244 m_document->renderer()->mltDeleteTransition(item->transitionTag(), endTrack, m_document->tracksCount() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, item->toXML(), refresh);
2245 if (m_dragItem == item) m_dragItem = NULL;
2247 #if QT_VERSION >= 0x040600
2248 // animate item deletion
2249 item->closeAnimation();
2253 emit transitionItemSelected(NULL);
2254 setDocumentModified();
2257 void CustomTrackView::slotTransitionUpdated(Transition *tr, QDomElement old)
2259 //kDebug() << "TRANS UPDATE, TRACKS: " << old.attribute("transition_btrack") << ", NEW: " << tr->toXML().attribute("transition_btrack");
2260 QDomElement xml = tr->toXML();
2261 if (old.isNull() || xml.isNull()) {
2262 emit displayMessage(i18n("Cannot update transition"), ErrorMessage);
2265 EditTransitionCommand *command = new EditTransitionCommand(this, tr->track(), tr->startPos(), old, xml, false);
2266 updateTrackDuration(tr->track(), command);
2267 m_commandStack->push(command);
2268 setDocumentModified();
2271 void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTransition, QDomElement transition, bool updateTransitionWidget)
2273 Transition *item = getTransitionItemAt(pos, track);
2275 kWarning() << "Unable to find transition at pos :" << pos.frames(m_document->fps()) << ", ON track: " << track;
2280 if (oldTransition.attribute("transition_atrack") != transition.attribute("transition_atrack") || oldTransition.attribute("transition_btrack") != transition.attribute("transition_btrack"))
2282 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);
2283 //kDebug() << "ORIGINAL TRACK: "<< oldTransition.attribute("transition_btrack") << ", NEW TRACK: "<<transition.attribute("transition_btrack");
2284 item->setTransitionParameters(transition);
2285 if (updateTransitionWidget) {
2286 ItemInfo info = item->info();
2288 ClipItem *transitionClip = getClipItemAt(info.startPos, info.track);
2289 if (transitionClip && transitionClip->baseClip()) {
2290 QString size = transitionClip->baseClip()->getProperty("frame_size");
2291 double factor = transitionClip->baseClip()->getProperty("aspect_ratio").toDouble();
2292 if (factor == 0) factor = 1.0;
2293 p.setX((int)(size.section('x', 0, 0).toInt() * factor + 0.5));
2294 p.setY(size.section('x', 1, 1).toInt());
2296 emit transitionItemSelected(item, getPreviousVideoTrack(info.track), p, true);
2298 setDocumentModified();
2301 void CustomTrackView::dragMoveEvent(QDragMoveEvent * event)
2304 const QPointF pos = mapToScene(event->pos());
2305 if (m_selectionGroup) {
2306 m_selectionGroup->setPos(pos);
2307 emit mousePosition((int)(m_selectionGroup->scenePos().x() + 0.5));
2308 event->acceptProposedAction();
2310 // Drag enter was not possible, try again at mouse position
2311 insertDropClips(event->mimeData(), event->pos());
2315 QGraphicsView::dragMoveEvent(event);
2319 void CustomTrackView::dragLeaveEvent(QDragLeaveEvent * event)
2321 if (m_selectionGroup && m_clipDrag) {
2322 m_thumbsTimer.stop();
2323 m_waitingThumbs.clear();
2324 QList<QGraphicsItem *> items = m_selectionGroup->childItems();
2326 scene()->destroyItemGroup(m_selectionGroup);
2327 m_selectionGroup = NULL;
2328 } else QGraphicsView::dragLeaveEvent(event);
2331 void CustomTrackView::dropEvent(QDropEvent * event)
2333 if (m_selectionGroup && m_clipDrag) {
2334 QList<QGraphicsItem *> items = m_selectionGroup->childItems();
2335 resetSelectionGroup();
2336 m_scene->clearSelection();
2337 bool hasVideoClip = false;
2338 QUndoCommand *addCommand = new QUndoCommand();
2339 addCommand->setText(i18n("Add timeline clip"));
2340 QList <ClipItem *> brokenClips;
2342 for (int i = 0; i < items.count(); i++) {
2343 ClipItem *item = static_cast <ClipItem *>(items.at(i));
2344 if (!hasVideoClip && (item->clipType() == AV || item->clipType() == VIDEO)) hasVideoClip = true;
2345 if (items.count() == 1) {
2346 updateClipTypeActions(item);
2348 updateClipTypeActions(NULL);
2351 //TODO: take care of edit mode for undo
2352 item->baseClip()->addReference();
2353 //item->setZValue(item->defaultZValue());
2354 m_document->updateClip(item->baseClip()->getId());
2355 ItemInfo info = item->info();
2357 int tracknumber = m_document->tracksCount() - info.track - 1;
2358 bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
2359 if (isLocked) item->setItemLocked(true);
2360 ItemInfo clipInfo = info;
2361 clipInfo.track = m_document->tracksCount() - item->track();
2363 int worked = m_document->renderer()->mltInsertClip(clipInfo, item->xml(), item->baseClip()->producer(item->track()), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
2365 emit displayMessage(i18n("Cannot insert clip in timeline"), ErrorMessage);
2366 brokenClips.append(item);
2369 adjustTimelineClips(m_scene->editMode(), item, ItemInfo(), addCommand);
2371 new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, false, false, addCommand);
2372 updateTrackDuration(info.track, addCommand);
2374 if (item->baseClip()->isTransparent() && getTransitionItemAtStart(info.startPos, info.track) == NULL) {
2375 // add transparency transition
2376 QDomElement trans = MainWindow::transitions.getEffectByTag("composite", "composite").cloneNode().toElement();
2377 new AddTransitionCommand(this, info, getPreviousVideoTrack(info.track), trans, false, true, addCommand);
2379 item->setSelected(true);
2381 qDeleteAll(brokenClips);
2382 brokenClips.clear();
2383 if (addCommand->childCount() > 0) m_commandStack->push(addCommand);
2384 else delete addCommand;
2386 // Automatic audio split
2387 if (KdenliveSettings::splitaudio())
2389 setDocumentModified();
2393 QRectF rect(0, 1 * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), 2);
2394 QList<QGraphicsItem *> selection = m_scene->items(rect);
2395 QStringList timelineList;
2397 kDebug()<<"// ITEMS on TRACK: "<<selection.count();
2398 for (int i = 0; i < selection.count(); i++) {
2399 if (selection.at(i)->type() == AVWIDGET) {
2400 ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
2401 int start = clip->startPos().frames(m_document->fps());
2402 int end = clip->endPos().frames(m_document->fps());
2403 timelineList.append(QString::number(start) + "-" + QString::number(end));
2406 kDebug() << "// COMPARE:\n" << timelineList << "\n-------------------";
2409 m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
2410 if (items.count() > 1) {
2411 groupSelectedItems(true);
2412 } else if (items.count() == 1) {
2413 m_dragItem = static_cast <AbstractClipItem *>(items.at(0));
2414 emit clipItemSelected((ClipItem*)m_dragItem);
2416 event->setDropAction(Qt::MoveAction);
2418 } else QGraphicsView::dropEvent(event);
2422 void CustomTrackView::adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInfo posinfo, QUndoCommand *command)
2424 bool snap = KdenliveSettings::snaptopoints();
2425 KdenliveSettings::setSnaptopoints(false);
2426 if (mode == OVERWRITEEDIT) {
2427 // if we are in overwrite mode, move clips accordingly
2429 if (item == NULL) info = posinfo;
2430 else info = item->info();
2431 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);
2432 QList<QGraphicsItem *> selection = m_scene->items(rect);
2433 if (item) selection.removeAll(item);
2434 for (int i = 0; i < selection.count(); i++) {
2435 if (!selection.at(i)->isEnabled()) continue;
2436 if (selection.at(i)->type() == AVWIDGET) {
2437 ClipItem *clip = static_cast<ClipItem *>(selection.at(i));
2438 if (clip->startPos() < info.startPos) {
2439 if (clip->endPos() > info.endPos) {
2440 ItemInfo clipInfo = clip->info();
2441 ItemInfo dupInfo = clipInfo;
2442 GenTime diff = info.startPos - clipInfo.startPos;
2443 dupInfo.startPos = info.startPos;
2444 dupInfo.cropStart += diff;
2445 dupInfo.cropDuration = clipInfo.endPos - info.startPos;
2446 ItemInfo newdupInfo = dupInfo;
2447 GenTime diff2 = info.endPos - info.startPos;
2448 newdupInfo.startPos = info.endPos;
2449 newdupInfo.cropStart += diff2;
2450 newdupInfo.cropDuration = clipInfo.endPos - info.endPos;
2451 new RazorClipCommand(this, clipInfo, info.startPos, false, command);
2452 new ResizeClipCommand(this, dupInfo, newdupInfo, false, false, command);
2453 ClipItem *dup = cutClip(clipInfo, info.startPos, true, false);
2454 if (dup) dup->resizeStart(info.endPos.frames(m_document->fps()));
2456 ItemInfo newclipInfo = clip->info();
2457 newclipInfo.endPos = info.startPos;
2458 new ResizeClipCommand(this, clip->info(), newclipInfo, false, false, command);
2459 clip->resizeEnd(info.startPos.frames(m_document->fps()));
2461 } else if (clip->endPos() <= info.endPos) {
2462 new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), clip->info(), clip->effectList(), false, false, false, true, command);
2463 m_waitingThumbs.removeAll(clip);
2464 scene()->removeItem(clip);
2468 ItemInfo newclipInfo = clip->info();
2469 newclipInfo.startPos = info.endPos;
2470 new ResizeClipCommand(this, clip->info(), newclipInfo, false, false, command);
2471 clip->resizeStart(info.endPos.frames(m_document->fps()));
2475 } else if (mode == INSERTEDIT) {
2476 // if we are in push mode, move clips accordingly
2478 if (item == NULL) info = posinfo;
2479 else info = item->info();
2480 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);
2481 QList<QGraphicsItem *> selection = m_scene->items(rect);
2482 if (item) selection.removeAll(item);
2483 for (int i = 0; i < selection.count(); i++) {
2484 if (selection.at(i)->type() == AVWIDGET) {
2485 ClipItem *clip = static_cast<ClipItem *>(selection.at(i));
2486 if (clip->startPos() < info.startPos) {
2487 if (clip->endPos() > info.startPos) {
2488 ItemInfo clipInfo = clip->info();
2489 ItemInfo dupInfo = clipInfo;
2490 GenTime diff = info.startPos - clipInfo.startPos;
2491 dupInfo.startPos = info.startPos;
2492 dupInfo.cropStart += diff;
2493 dupInfo.cropDuration = clipInfo.endPos - info.startPos;
2494 new RazorClipCommand(this, clipInfo, info.startPos, false, command);
2495 // Commented out; variable dup unused. --granjow
2496 //ClipItem *dup = cutClip(clipInfo, info.startPos, true, false);
2497 cutClip(clipInfo, info.startPos, true, false);
2500 // TODO: add insertspacecommand
2505 KdenliveSettings::setSnaptopoints(snap);
2509 void CustomTrackView::adjustTimelineTransitions(EDITMODE mode, Transition *item, QUndoCommand *command)
2511 if (mode == OVERWRITEEDIT) {
2512 // if we are in overwrite or push mode, move clips accordingly
2513 bool snap = KdenliveSettings::snaptopoints();
2514 KdenliveSettings::setSnaptopoints(false);
2515 ItemInfo info = item->info();
2516 QRectF rect(info.startPos.frames(m_document->fps()), info.track * m_tracksHeight + m_tracksHeight, (info.endPos - info.startPos).frames(m_document->fps()) - 1, 5);
2517 QList<QGraphicsItem *> selection = m_scene->items(rect);
2518 selection.removeAll(item);
2519 for (int i = 0; i < selection.count(); i++) {
2520 if (!selection.at(i)->isEnabled()) continue;
2521 if (selection.at(i)->type() == TRANSITIONWIDGET) {
2522 Transition *tr = static_cast<Transition *>(selection.at(i));
2523 if (tr->startPos() < info.startPos) {
2524 ItemInfo firstPos = tr->info();
2525 ItemInfo newPos = firstPos;
2526 firstPos.endPos = item->startPos();
2527 newPos.startPos = item->endPos();
2528 new MoveTransitionCommand(this, tr->info(), firstPos, true, command);
2529 if (tr->endPos() > info.endPos) {
2531 new AddTransitionCommand(this, newPos, tr->transitionEndTrack(), tr->toXML(), false, true, command);
2533 } else if (tr->endPos() > info.endPos) {
2535 ItemInfo firstPos = tr->info();
2536 firstPos.startPos = item->endPos();
2537 new MoveTransitionCommand(this, tr->info(), firstPos, true, command);
2539 // remove transition
2540 new AddTransitionCommand(this, tr->info(), tr->transitionEndTrack(), tr->toXML(), true, true, command);
2544 KdenliveSettings::setSnaptopoints(snap);
2548 QStringList CustomTrackView::mimeTypes() const
2550 QStringList qstrList;
2551 // list of accepted mime types for drop
2552 qstrList.append("text/plain");
2553 qstrList.append("kdenlive/producerslist");
2554 qstrList.append("kdenlive/clip");
2558 Qt::DropActions CustomTrackView::supportedDropActions() const
2560 // returns what actions are supported when dropping
2561 return Qt::MoveAction;
2564 void CustomTrackView::setDuration(int duration)
2566 int diff = qAbs(duration - sceneRect().width());
2567 if (diff * matrix().m11() > -50) {
2568 if (matrix().m11() < 0.4) setSceneRect(0, 0, (duration + 100 / matrix().m11()), sceneRect().height());
2569 else setSceneRect(0, 0, (duration + 300), sceneRect().height());
2571 m_projectDuration = duration;
2574 int CustomTrackView::duration() const
2576 return m_projectDuration;
2579 void CustomTrackView::addTrack(TrackInfo type, int ix)
2581 if (ix == -1 || ix == m_document->tracksCount()) {
2582 m_document->insertTrack(0, type);
2583 m_document->renderer()->mltInsertTrack(1, type.type == VIDEOTRACK);
2585 m_document->insertTrack(m_document->tracksCount() - ix, type);
2586 // insert track in MLT playlist
2587 m_document->renderer()->mltInsertTrack(m_document->tracksCount() - ix, type.type == VIDEOTRACK);
2589 double startY = ix * m_tracksHeight + 1 + m_tracksHeight / 2;
2590 QRectF r(0, startY, sceneRect().width(), sceneRect().height() - startY);
2591 QList<QGraphicsItem *> selection = m_scene->items(r);
2592 resetSelectionGroup();
2594 m_selectionGroup = new AbstractGroupItem(m_document->fps());
2595 scene()->addItem(m_selectionGroup);
2596 for (int i = 0; i < selection.count(); i++) {
2597 if ((!selection.at(i)->parentItem()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
2598 m_selectionGroup->addToGroup(selection.at(i));
2599 selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
2602 // Move graphic items
2603 m_selectionGroup->translate(0, m_tracksHeight);
2605 // adjust track number
2606 QList<QGraphicsItem *> children = m_selectionGroup->childItems();
2607 for (int i = 0; i < children.count(); i++) {
2608 if (children.at(i)->type() == GROUPWIDGET) {
2609 AbstractGroupItem *grp = static_cast<AbstractGroupItem*>(children.at(i));
2610 children << grp->childItems();
2613 AbstractClipItem *item = static_cast <AbstractClipItem *>(children.at(i));
2615 ItemInfo clipinfo = item->info();
2616 if (item->type() == AVWIDGET) {
2617 ClipItem *clip = static_cast <ClipItem *>(item);
2618 // slowmotion clips are not track dependant, so no need to update them
2619 if (clip->speed() != 1.0) continue;
2620 // We add a move clip command so that we get the correct producer for new track number
2621 if (clip->clipType() == AV || clip->clipType() == AUDIO) {
2622 Mlt::Producer *prod = clip->getProducer(clipinfo.track);
2623 if (m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod) == false) {
2624 // problem updating clip
2625 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage);
2628 } else if (item->type() == TRANSITIONWIDGET) {
2629 Transition *tr = static_cast <Transition *>(item);
2630 int track = tr->transitionEndTrack();
2632 tr->updateTransitionEndTrack(getPreviousVideoTrack(clipinfo.track));
2636 resetSelectionGroup(false);
2639 int maxHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
2640 for (int i = 0; i < m_guides.count(); i++) {
2641 QLineF l = m_guides.at(i)->line();
2642 l.setP2(QPointF(l.x2(), maxHeight));
2643 m_guides.at(i)->setLine(l);
2646 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight - 1);
2647 setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
2648 viewport()->update();
2649 //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged()));
2650 //setFixedHeight(50 * m_tracksCount);
2652 updateTrackNames(ix, true);
2655 void CustomTrackView::removeTrack(int ix)
2657 // Delete track in MLT playlist
2658 m_document->renderer()->mltDeleteTrack(m_document->tracksCount() - ix);
2659 m_document->deleteTrack(m_document->tracksCount() - ix - 1);
2661 double startY = ix * (m_tracksHeight + 1) + m_tracksHeight / 2;
2662 QRectF r(0, startY, sceneRect().width(), sceneRect().height() - startY);
2663 QList<QGraphicsItem *> selection = m_scene->items(r);
2665 resetSelectionGroup();
2667 m_selectionGroup = new AbstractGroupItem(m_document->fps());
2668 scene()->addItem(m_selectionGroup);
2669 for (int i = 0; i < selection.count(); i++) {
2670 if ((!selection.at(i)->parentItem()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
2671 m_selectionGroup->addToGroup(selection.at(i));
2672 selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
2675 // Move graphic items
2676 qreal ydiff = 0 - (int) m_tracksHeight;
2677 m_selectionGroup->translate(0, ydiff);
2679 // adjust track number
2680 QList<QGraphicsItem *> children = m_selectionGroup->childItems();
2681 //kDebug() << "// FOUND CLIPS TO MOVE: " << children.count();
2682 for (int i = 0; i < children.count(); i++) {
2683 if (children.at(i)->type() == GROUPWIDGET) {
2684 AbstractGroupItem *grp = static_cast<AbstractGroupItem*>(children.at(i));
2685 children << grp->childItems();
2688 if (children.at(i)->type() == AVWIDGET) {
2689 ClipItem *clip = static_cast <ClipItem *>(children.at(i));
2691 ItemInfo clipinfo = clip->info();
2692 // We add a move clip command so that we get the correct producer for new track number
2693 if (clip->clipType() == AV || clip->clipType() == AUDIO) {
2694 Mlt::Producer *prod = clip->getProducer(clipinfo.track);
2695 if (!m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod)) {
2696 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage);
2699 } else if (children.at(i)->type() == TRANSITIONWIDGET) {
2700 Transition *tr = static_cast <Transition *>(children.at(i));
2702 int track = tr->transitionEndTrack();
2704 ItemInfo clipinfo = tr->info();
2705 tr->updateTransitionEndTrack(getPreviousVideoTrack(clipinfo.track));
2709 resetSelectionGroup(false);
2711 int maxHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
2712 for (int i = 0; i < m_guides.count(); i++) {
2713 QLineF l = m_guides.at(i)->line();
2714 l.setP2(QPointF(l.x2(), maxHeight));
2715 m_guides.at(i)->setLine(l);
2717 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight - 1);
2718 setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
2720 m_selectedTrack = qMin(m_selectedTrack, m_document->tracksCount() - 1);
2721 viewport()->update();
2723 updateTrackNames(ix, false);
2724 //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged()));
2727 void CustomTrackView::configTracks(QList < TrackInfo > trackInfos)
2729 for (int i = 0; i < trackInfos.count(); ++i) {
2730 m_document->setTrackType(i, trackInfos.at(i));
2731 m_document->renderer()->mltChangeTrackState(i + 1, m_document->trackInfoAt(i).isMute, m_document->trackInfoAt(i).isBlind);
2732 lockTrack(m_document->tracksCount() - i - 1, m_document->trackInfoAt(i).isLocked, false);
2735 viewport()->update();
2736 emit trackHeightChanged();
2739 void CustomTrackView::slotSwitchTrackAudio(int ix)
2741 /*for (int i = 0; i < m_document->tracksCount(); i++)
2742 kDebug() << "TRK " << i << " STATE: " << m_document->trackInfoAt(i).isMute << m_document->trackInfoAt(i).isBlind;*/
2743 int tracknumber = m_document->tracksCount() - ix - 1;
2744 m_document->switchTrackAudio(tracknumber, !m_document->trackInfoAt(tracknumber).isMute);
2745 kDebug() << "NEXT TRK STATE: " << m_document->trackInfoAt(tracknumber).isMute << m_document->trackInfoAt(tracknumber).isBlind;
2746 m_document->renderer()->mltChangeTrackState(tracknumber + 1, m_document->trackInfoAt(tracknumber).isMute, m_document->trackInfoAt(tracknumber).isBlind);
2747 setDocumentModified();
2750 void CustomTrackView::slotSwitchTrackLock(int ix)
2752 int tracknumber = m_document->tracksCount() - ix - 1;
2753 LockTrackCommand *command = new LockTrackCommand(this, ix, !m_document->trackInfoAt(tracknumber).isLocked);
2754 m_commandStack->push(command);
2758 void CustomTrackView::lockTrack(int ix, bool lock, bool requestUpdate)
2760 int tracknumber = m_document->tracksCount() - ix - 1;
2761 m_document->switchTrackLock(tracknumber, lock);
2763 emit doTrackLock(ix, lock);
2764 AbstractClipItem *clip = NULL;
2765 QList<QGraphicsItem *> selection = m_scene->items(0, ix * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), m_tracksHeight / 2 - 2);
2767 for (int i = 0; i < selection.count(); i++) {
2768 if (selection.at(i)->type() == GROUPWIDGET && (AbstractGroupItem *)selection.at(i) != m_selectionGroup) {
2769 if (selection.at(i)->parentItem() && m_selectionGroup) {
2770 selection.removeAll((QGraphicsItem*)m_selectionGroup);
2771 resetSelectionGroup();
2774 bool changeGroupLock = true;
2775 bool hasClipOnTrack = false;
2776 QList <QGraphicsItem *> children = selection.at(i)->childItems();
2777 for (int j = 0; j < children.count(); ++j) {
2778 if (children.at(j)->isSelected()) {
2779 if (children.at(j)->type() == AVWIDGET)
2780 emit clipItemSelected(NULL);
2781 else if (children.at(j)->type() == TRANSITIONWIDGET)
2782 emit transitionItemSelected(NULL);
2787 AbstractClipItem * child = static_cast <AbstractClipItem *>(children.at(j));
2788 if (child == m_dragItem)
2791 // only unlock group, if it is not locked by another track too
2792 if (!lock && child->track() != ix && m_document->trackInfoAt(m_document->tracksCount() - child->track() - 1).isLocked)
2793 changeGroupLock = false;
2795 // only (un-)lock if at least one clip is on the track
2796 if (child->track() == ix)
2797 hasClipOnTrack = true;
2799 if (changeGroupLock && hasClipOnTrack)
2800 ((AbstractGroupItem*)selection.at(i))->setItemLocked(lock);
2801 } else if((selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET)) {
2802 if (selection.at(i)->parentItem()) {
2803 if (selection.at(i)->parentItem() == m_selectionGroup) {
2804 selection.removeAll((QGraphicsItem*)m_selectionGroup);
2805 resetSelectionGroup();
2807 // groups are handled separately
2812 if (selection.at(i)->isSelected()) {
2813 if (selection.at(i)->type() == AVWIDGET)
2814 emit clipItemSelected(NULL);
2816 emit transitionItemSelected(NULL);
2818 clip = static_cast <AbstractClipItem *>(selection.at(i));
2819 clip->setItemLocked(lock);
2820 if (clip == m_dragItem)
2824 kDebug() << "NEXT TRK STATE: " << m_document->trackInfoAt(tracknumber).isLocked;
2825 viewport()->update();
2826 setDocumentModified();
2829 void CustomTrackView::slotSwitchTrackVideo(int ix)
2831 int tracknumber = m_document->tracksCount() - ix;
2832 m_document->switchTrackVideo(tracknumber - 1, !m_document->trackInfoAt(tracknumber - 1).isBlind);
2833 m_document->renderer()->mltChangeTrackState(tracknumber, m_document->trackInfoAt(tracknumber - 1).isMute, m_document->trackInfoAt(tracknumber - 1).isBlind);
2834 setDocumentModified();
2837 QList<QGraphicsItem *> CustomTrackView::checkForGroups(const QRectF &rect, bool *ok)
2839 // Check there is no group going over several tracks there, or that would result in timeline corruption
2840 QList<QGraphicsItem *> selection = scene()->items(rect);
2842 int maxHeight = m_tracksHeight * 1.5;
2843 for (int i = 0; i < selection.count(); i++) {
2844 // Check that we don't try to move a group with clips on other tracks
2845 if (selection.at(i)->type() == GROUPWIDGET && (selection.at(i)->boundingRect().height() >= maxHeight)) {
2848 } else if (selection.at(i)->parentItem() && (selection.at(i)->parentItem()->boundingRect().height() >= maxHeight)) {
2856 void CustomTrackView::slotRemoveSpace()
2860 if (m_menuPosition.isNull()) {
2861 pos = GenTime(cursorPos(), m_document->fps());
2863 track = QInputDialog::getInteger(this, i18n("Remove Space"), i18n("Track"), 0, 0, m_document->tracksCount() - 1, 1, &ok);
2866 pos = GenTime((int)(mapToScene(m_menuPosition).x()), m_document->fps());
2867 track = (int)(mapToScene(m_menuPosition).y() / m_tracksHeight);
2870 if (m_document->isTrackLocked(m_document->tracksCount() - track - 1)) {
2871 emit displayMessage(i18n("Cannot remove space in a locked track"), ErrorMessage);
2875 ClipItem *item = getClipItemAt(pos, track);
2877 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);
2880 int length = m_document->renderer()->mltGetSpaceLength(pos, m_document->tracksCount() - track, true);
2881 //kDebug() << "// GOT LENGT; " << length;
2883 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);
2887 // Make sure there is no group in the way
2888 QRectF rect(pos.frames(m_document->fps()), track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width() - pos.frames(m_document->fps()), m_tracksHeight / 2 - 2);
2891 QList<QGraphicsItem *> items = checkForGroups(rect, &isOk);
2893 // groups found on track, do not allow the move
2894 emit displayMessage(i18n("Cannot remove space in a track with a group"), ErrorMessage);
2898 QList<ItemInfo> clipsToMove;
2899 QList<ItemInfo> transitionsToMove;
2901 for (int i = 0; i < items.count(); i++) {
2902 if (items.at(i)->type() == AVWIDGET || items.at(i)->type() == TRANSITIONWIDGET) {
2903 AbstractClipItem *item = static_cast <AbstractClipItem *>(items.at(i));
2904 ItemInfo info = item->info();
2905 if (item->type() == AVWIDGET) {
2906 clipsToMove.append(info);
2907 } else if (item->type() == TRANSITIONWIDGET) {
2908 transitionsToMove.append(info);
2913 InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, GenTime(-length, m_document->fps()), true);
2914 updateTrackDuration(track, command);
2915 m_commandStack->push(command);
2918 void CustomTrackView::slotInsertSpace()
2922 if (m_menuPosition.isNull()) {
2923 pos = GenTime(cursorPos(), m_document->fps());
2925 pos = GenTime((int)(mapToScene(m_menuPosition).x()), m_document->fps());
2926 track = (int)(mapToScene(m_menuPosition).y() / m_tracksHeight) + 1;
2928 SpacerDialog d(GenTime(65, m_document->fps()), m_document->timecode(), track, m_document->tracksList(), this);
2929 if (d.exec() != QDialog::Accepted) return;
2930 GenTime spaceDuration = d.selectedDuration();
2931 track = d.selectedTrack();
2933 QList<QGraphicsItem *> items;
2935 if (m_document->isTrackLocked(m_document->tracksCount() - track - 1)) {
2936 emit displayMessage(i18n("Cannot insert space in a locked track"), ErrorMessage);
2940 ClipItem *item = getClipItemAt(pos, track);
2941 if (item) pos = item->startPos();
2943 // Make sure there is no group in the way
2944 QRectF rect(pos.frames(m_document->fps()), track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width() - pos.frames(m_document->fps()), m_tracksHeight / 2 - 2);
2946 items = checkForGroups(rect, &isOk);
2948 // groups found on track, do not allow the move
2949 emit displayMessage(i18n("Cannot insert space in a track with a group"), ErrorMessage);
2953 QRectF rect(pos.frames(m_document->fps()), 0, sceneRect().width() - pos.frames(m_document->fps()), m_document->tracksCount() * m_tracksHeight);
2954 items = scene()->items(rect);
2957 QList<ItemInfo> clipsToMove;
2958 QList<ItemInfo> transitionsToMove;
2960 for (int i = 0; i < items.count(); i++) {
2961 if (items.at(i)->type() == AVWIDGET || items.at(i)->type() == TRANSITIONWIDGET) {
2962 AbstractClipItem *item = static_cast <AbstractClipItem *>(items.at(i));
2963 ItemInfo info = item->info();
2964 if (item->type() == AVWIDGET)
2965 clipsToMove.append(info);
2966 else if (item->type() == TRANSITIONWIDGET)
2967 transitionsToMove.append(info);
2971 if (!clipsToMove.isEmpty() || !transitionsToMove.isEmpty()) {
2972 InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, spaceDuration, true);
2973 updateTrackDuration(track, command);
2974 m_commandStack->push(command);
2978 void CustomTrackView::insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> transToMove, int track, const GenTime duration, const GenTime offset)
2980 int diff = duration.frames(m_document->fps());
2981 resetSelectionGroup();
2982 m_selectionGroup = new AbstractGroupItem(m_document->fps());
2983 scene()->addItem(m_selectionGroup);
2985 Transition *transition;
2987 // Create lists with start pos for each track
2988 QMap <int, int> trackClipStartList;
2989 QMap <int, int> trackTransitionStartList;
2991 for (int i = 1; i < m_document->tracksCount() + 1; i++) {
2992 trackClipStartList[i] = -1;
2993 trackTransitionStartList[i] = -1;
2996 if (!clipsToMove.isEmpty()) for (int i = 0; i < clipsToMove.count(); i++) {
2997 clip = getClipItemAtStart(clipsToMove.at(i).startPos + offset, clipsToMove.at(i).track);
2999 if (clip->parentItem()) {
3000 m_selectionGroup->addToGroup(clip->parentItem());
3001 clip->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
3003 m_selectionGroup->addToGroup(clip);
3004 clip->setFlag(QGraphicsItem::ItemIsMovable, false);
3006 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))
3007 trackClipStartList[m_document->tracksCount() - clipsToMove.at(i).track] = clipsToMove.at(i).startPos.frames(m_document->fps());
3009 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);
3012 if (!transToMove.isEmpty()) for (int i = 0; i < transToMove.count(); i++) {
3013 transition = getTransitionItemAtStart(transToMove.at(i).startPos + offset, transToMove.at(i).track);
3015 if (transition->parentItem()) {
3016 m_selectionGroup->addToGroup(transition->parentItem());
3017 transition->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
3019 m_selectionGroup->addToGroup(transition);
3020 transition->setFlag(QGraphicsItem::ItemIsMovable, false);
3022 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))
3023 trackTransitionStartList[m_document->tracksCount() - transToMove.at(i).track] = transToMove.at(i).startPos.frames(m_document->fps());
3024 } 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);
3026 m_selectionGroup->translate(diff, 0);
3028 // update items coordinates
3029 QList<QGraphicsItem *> itemList = m_selectionGroup->childItems();
3031 for (int i = 0; i < itemList.count(); i++) {
3032 if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
3033 static_cast < AbstractClipItem *>(itemList.at(i))->updateItem();
3034 } else if (itemList.at(i)->type() == GROUPWIDGET) {
3035 QList<QGraphicsItem *> children = itemList.at(i)->childItems();
3036 for (int j = 0; j < children.count(); j++) {
3037 AbstractClipItem * clp = static_cast < AbstractClipItem *>(children.at(j));
3042 resetSelectionGroup(false);
3044 track = m_document->tracksCount() - track;
3045 m_document->renderer()->mltInsertSpace(trackClipStartList, trackTransitionStartList, track, duration, offset);
3048 void CustomTrackView::deleteClip(const QString &clipId)
3050 resetSelectionGroup();
3051 QList<QGraphicsItem *> itemList = items();
3052 QUndoCommand *deleteCommand = new QUndoCommand();
3054 for (int i = 0; i < itemList.count(); i++) {
3055 if (itemList.at(i)->type() == AVWIDGET) {
3056 ClipItem *item = (ClipItem *)itemList.at(i);
3057 if (item->clipProducer() == clipId) {
3059 if (item->parentItem()) {
3060 // Clip is in a group, destroy the group
3061 new GroupClipsCommand(this, QList<ItemInfo>() << item->info(), QList<ItemInfo>(), false, deleteCommand);
3063 new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, true, true, deleteCommand);
3067 deleteCommand->setText(i18np("Delete timeline clip", "Delete timeline clips", count));
3069 delete deleteCommand;
3071 updateTrackDuration(-1, deleteCommand);
3072 m_commandStack->push(deleteCommand);
3076 void CustomTrackView::setCursorPos(int pos, bool seek)
3078 if (pos == m_cursorPos) return;
3079 emit cursorMoved((int)(m_cursorPos), (int)(pos));
3081 if (seek) m_document->renderer()->seek(m_cursorPos);
3082 else if (m_autoScroll) checkScrolling();
3083 m_cursorLine->setPos(m_cursorPos, 0);
3086 void CustomTrackView::updateCursorPos()
3088 m_cursorLine->setPos(m_cursorPos, 0);
3091 int CustomTrackView::cursorPos()
3093 return (int)(m_cursorPos);
3096 void CustomTrackView::moveCursorPos(int delta)
3098 if (m_cursorPos + delta < 0) delta = 0 - m_cursorPos;
3099 emit cursorMoved((int)(m_cursorPos), (int)((m_cursorPos + delta)));
3100 m_cursorPos += delta;
3101 m_cursorLine->setPos(m_cursorPos, 0);
3102 m_document->renderer()->seek(m_cursorPos);
3105 void CustomTrackView::initCursorPos(int pos)
3107 emit cursorMoved((int)(m_cursorPos), (int)(pos));
3109 m_cursorLine->setPos(pos, 0);
3113 void CustomTrackView::checkScrolling()
3115 ensureVisible(m_cursorPos, verticalScrollBar()->value() + 10, 2, 2, 50, 0);
3118 void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
3120 if (m_moveOpMode == SEEK) m_moveOpMode = NONE;
3121 QGraphicsView::mouseReleaseEvent(event);
3122 setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
3123 #if QT_VERSION >= 0x040600
3124 if (m_dragItem) m_dragItem->setGraphicsEffect(NULL);
3126 if (m_scrollTimer.isActive()) m_scrollTimer.stop();
3127 if (event->button() == Qt::MidButton) {
3130 setDragMode(QGraphicsView::NoDrag);
3131 if (m_operationMode == MOVEGUIDE) {
3132 setCursor(Qt::ArrowCursor);
3133 m_operationMode = NONE;
3134 m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, false);
3135 GenTime newPos = GenTime(m_dragGuide->pos().x(), m_document->fps());
3136 if (newPos != m_dragGuide->position()) {
3137 EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), newPos, m_dragGuide->label(), false);
3138 m_commandStack->push(command);
3139 m_dragGuide->updateGuide(GenTime(m_dragGuide->pos().x(), m_document->fps()));
3140 qSort(m_guides.begin(), m_guides.end(), sortGuidesList);
3141 m_document->syncGuides(m_guides);
3146 } else if (m_operationMode == SPACER && m_selectionGroup) {
3148 if (event->modifiers() != Qt::ControlModifier) {
3149 // We are moving all tracks
3151 } else track = (int)(mapToScene(m_clickEvent).y() / m_tracksHeight);
3152 GenTime timeOffset = GenTime((int)(m_selectionGroup->scenePos().x()), m_document->fps()) - m_selectionGroupInfo.startPos;
3154 if (timeOffset != GenTime()) {
3155 QList<QGraphicsItem *> items = m_selectionGroup->childItems();
3157 QList<ItemInfo> clipsToMove;
3158 QList<ItemInfo> transitionsToMove;
3160 // Create lists with start pos for each track
3161 QMap <int, int> trackClipStartList;
3162 QMap <int, int> trackTransitionStartList;
3164 for (int i = 1; i < m_document->tracksCount() + 1; i++) {
3165 trackClipStartList[i] = -1;
3166 trackTransitionStartList[i] = -1;
3169 for (int i = 0; i < items.count(); i++) {
3170 if (items.at(i)->type() == GROUPWIDGET)
3171 items += items.at(i)->childItems();
3174 for (int i = 0; i < items.count(); i++) {
3175 if (items.at(i)->type() == AVWIDGET) {
3176 AbstractClipItem *item = static_cast <AbstractClipItem *>(items.at(i));
3177 ItemInfo info = item->info();
3178 clipsToMove.append(info);
3180 if (trackClipStartList.value(m_document->tracksCount() - info.track) == -1 || info.startPos.frames(m_document->fps()) < trackClipStartList.value(m_document->tracksCount() - info.track))
3181 trackClipStartList[m_document->tracksCount() - info.track] = info.startPos.frames(m_document->fps());
3182 } else if (items.at(i)->type() == TRANSITIONWIDGET) {
3183 AbstractClipItem *item = static_cast <AbstractClipItem *>(items.at(i));
3184 ItemInfo info = item->info();
3185 transitionsToMove.append(info);
3187 if (trackTransitionStartList.value(m_document->tracksCount() - info.track) == -1 || info.startPos.frames(m_document->fps()) < trackTransitionStartList.value(m_document->tracksCount() - info.track))
3188 trackTransitionStartList[m_document->tracksCount() - info.track] = info.startPos.frames(m_document->fps());
3191 if (!clipsToMove.isEmpty() || !transitionsToMove.isEmpty()) {
3192 InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, timeOffset, false);
3193 updateTrackDuration(track, command);
3194 m_commandStack->push(command);
3195 if (track != -1) track = m_document->tracksCount() - track;
3196 kDebug() << "SPACER TRACK:" << track;
3197 m_document->renderer()->mltInsertSpace(trackClipStartList, trackTransitionStartList, track, timeOffset, GenTime());
3198 setDocumentModified();
3201 resetSelectionGroup(false);
3202 m_operationMode = NONE;
3203 } else if (m_operationMode == RUBBERSELECTION) {
3204 resetSelectionGroup();
3205 groupSelectedItems();
3206 m_operationMode = NONE;
3209 if (m_dragItem == NULL && m_selectionGroup == NULL) {
3210 emit transitionItemSelected(NULL);
3214 if (m_dragItem) info = m_dragItem->info();
3216 if (m_operationMode == MOVE) {
3217 setCursor(Qt::OpenHandCursor);
3218 if (m_dragItem->parentItem() == 0) {
3219 // we are moving one clip, easy
3220 if (m_dragItem->type() == AVWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
3221 ClipItem *item = static_cast <ClipItem *>(m_dragItem);
3222 Mlt::Producer *prod = item->getProducer(info.track);
3223 bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - info.track), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(info.startPos.frames(m_document->fps())), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
3226 QUndoCommand *moveCommand = new QUndoCommand();
3227 moveCommand->setText(i18n("Move clip"));
3228 adjustTimelineClips(m_scene->editMode(), item, ItemInfo(), moveCommand);
3230 int tracknumber = m_document->tracksCount() - item->track() - 1;
3231 bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
3232 if (isLocked) item->setItemLocked(true);
3233 new MoveClipCommand(this, m_dragItemInfo, info, false, moveCommand);
3234 // Also move automatic transitions (on lower track)
3235 Transition *startTransition = getTransitionItemAtStart(m_dragItemInfo.startPos, m_dragItemInfo.track);
3236 ItemInfo startTrInfo;
3237 ItemInfo newStartTrInfo;
3238 bool moveStartTrans = false;
3239 bool moveEndTrans = false;
3240 if (startTransition && startTransition->isAutomatic()) {
3241 startTrInfo = startTransition->info();
3242 newStartTrInfo = startTrInfo;
3243 newStartTrInfo.track = info.track;
3244 newStartTrInfo.startPos = info.startPos;
3245 if (m_dragItemInfo.track == info.track && !item->baseClip()->isTransparent() && getClipItemAtEnd(newStartTrInfo.endPos, m_document->tracksCount() - startTransition->transitionEndTrack())) {
3246 // transition end should stay the same
3248 // transition end should be adjusted to clip
3249 newStartTrInfo.endPos = newStartTrInfo.endPos + (newStartTrInfo.startPos - startTrInfo.startPos);
3251 if (newStartTrInfo.startPos < newStartTrInfo.endPos) moveStartTrans = true;
3253 if (startTransition == NULL || startTransition->endPos() < m_dragItemInfo.endPos) {
3254 // Check if there is a transition at clip end
3255 Transition *tr = getTransitionItemAtEnd(m_dragItemInfo.endPos, m_dragItemInfo.track);
3256 if (tr && tr->isAutomatic()) {
3257 ItemInfo trInfo = tr->info();
3258 ItemInfo newTrInfo = trInfo;
3259 newTrInfo.track = info.track;
3260 newTrInfo.endPos = m_dragItem->endPos();
3261 if (m_dragItemInfo.track == info.track && !item->baseClip()->isTransparent() && getClipItemAtStart(trInfo.startPos, m_document->tracksCount() - tr->transitionEndTrack())) {
3262 // transition start should stay the same
3264 // transition start should be moved
3265 newTrInfo.startPos = newTrInfo.startPos + (newTrInfo.endPos - trInfo.endPos);
3267 if (newTrInfo.startPos < newTrInfo.endPos) {
3268 moveEndTrans = true;
3269 if (moveStartTrans) {
3270 // we have to move both transitions, remove the start one so that there is no collision
3271 new AddTransitionCommand(this, startTrInfo, startTransition->transitionEndTrack(), startTransition->toXML(), true, true, moveCommand);
3273 adjustTimelineTransitions(m_scene->editMode(), tr, moveCommand);
3274 new MoveTransitionCommand(this, trInfo, newTrInfo, true, moveCommand);
3275 if (moveStartTrans) {
3276 // re-add transition in correct place
3277 int transTrack = startTransition->transitionEndTrack();
3278 if (m_dragItemInfo.track != info.track && !startTransition->forcedTrack()) {
3279 transTrack = getPreviousVideoTrack(info.track);
3281 adjustTimelineTransitions(m_scene->editMode(), startTransition, moveCommand);
3282 new AddTransitionCommand(this, newStartTrInfo, transTrack, startTransition->toXML(), false, true, moveCommand);
3288 if (moveStartTrans && !moveEndTrans) {
3289 adjustTimelineTransitions(m_scene->editMode(), startTransition, moveCommand);
3290 new MoveTransitionCommand(this, startTrInfo, newStartTrInfo, true, moveCommand);
3293 // Also move automatic transitions (on upper track)
3294 Transition *tr = getTransitionItemAtStart(m_dragItemInfo.startPos, m_dragItemInfo.track - 1);
3295 if (m_dragItemInfo.track == info.track && tr && tr->isAutomatic() && (m_document->tracksCount() - tr->transitionEndTrack()) == m_dragItemInfo.track) {
3296 ItemInfo trInfo = tr->info();
3297 ItemInfo newTrInfo = trInfo;
3298 newTrInfo.startPos = m_dragItem->startPos();
3299 ClipItem * upperClip = getClipItemAt(m_dragItemInfo.startPos, m_dragItemInfo.track - 1);
3300 if (!upperClip || !upperClip->baseClip()->isTransparent()) {
3301 if (!getClipItemAtEnd(newTrInfo.endPos, tr->track())) {
3302 // transition end should be adjusted to clip on upper track
3303 newTrInfo.endPos = newTrInfo.endPos + (newTrInfo.startPos - trInfo.startPos);
3305 if (newTrInfo.startPos < newTrInfo.endPos) {
3306 adjustTimelineTransitions(m_scene->editMode(), tr, moveCommand);
3307 new MoveTransitionCommand(this, trInfo, newTrInfo, true, moveCommand);
3311 if (m_dragItemInfo.track == info.track && (tr == NULL || tr->endPos() < m_dragItemInfo.endPos)) {
3312 // Check if there is a transition at clip end
3313 tr = getTransitionItemAtEnd(m_dragItemInfo.endPos, m_dragItemInfo.track - 1);
3314 if (tr && tr->isAutomatic() && (m_document->tracksCount() - tr->transitionEndTrack()) == m_dragItemInfo.track) {
3315 ItemInfo trInfo = tr->info();
3316 ItemInfo newTrInfo = trInfo;
3317 newTrInfo.endPos = m_dragItem->endPos();
3318 kDebug() << "CLIP ENDS AT: " << newTrInfo.endPos.frames(25);
3319 kDebug() << "CLIP STARTS AT: " << newTrInfo.startPos.frames(25);
3320 ClipItem * upperClip = getClipItemAt(m_dragItemInfo.startPos, m_dragItemInfo.track - 1);
3321 if (!upperClip || !upperClip->baseClip()->isTransparent()) {
3322 if (!getClipItemAtStart(trInfo.startPos, tr->track())) {
3323 // transition start should be moved
3324 newTrInfo.startPos = newTrInfo.startPos + (newTrInfo.endPos - trInfo.endPos);
3326 if (newTrInfo.startPos < newTrInfo.endPos) {
3327 adjustTimelineTransitions(m_scene->editMode(), tr, moveCommand);
3328 new MoveTransitionCommand(this, trInfo, newTrInfo, true, moveCommand);
3333 updateTrackDuration(info.track, moveCommand);
3334 if (m_dragItemInfo.track != info.track)
3335 updateTrackDuration(m_dragItemInfo.track, moveCommand);
3336 m_commandStack->push(moveCommand);
3337 //checkTrackSequence(m_dragItem->track());
3339 // undo last move and emit error message
3340 bool snap = KdenliveSettings::snaptopoints();
3341 KdenliveSettings::setSnaptopoints(false);
3342 item->setPos((int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(m_dragItemInfo.track * m_tracksHeight + 1));
3343 KdenliveSettings::setSnaptopoints(snap);
3344 emit displayMessage(i18n("Cannot move clip to position %1", m_document->timecode().getTimecodeFromFrames(m_dragItemInfo.startPos.frames(m_document->fps()))), ErrorMessage);
3346 setDocumentModified();
3347 } else if (m_dragItem->type() == TRANSITIONWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
3348 Transition *transition = static_cast <Transition *>(m_dragItem);
3349 transition->updateTransitionEndTrack(getPreviousVideoTrack(m_dragItem->track()));
3350 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)) {
3351 // Moving transition failed, revert to previous position
3352 emit displayMessage(i18n("Cannot move transition"), ErrorMessage);
3353 transition->setPos((int) m_dragItemInfo.startPos.frames(m_document->fps()), (m_dragItemInfo.track) * m_tracksHeight + 1);
3355 QUndoCommand *moveCommand = new QUndoCommand();
3356 moveCommand->setText(i18n("Move transition"));
3357 adjustTimelineTransitions(m_scene->editMode(), transition, moveCommand);
3358 new MoveTransitionCommand(this, m_dragItemInfo, info, false, moveCommand);
3359 updateTrackDuration(info.track, moveCommand);
3360 if (m_dragItemInfo.track != info.track)
3361 updateTrackDuration(m_dragItemInfo.track, moveCommand);
3362 m_commandStack->push(moveCommand);
3363 setDocumentModified();
3367 // Moving several clips. We need to delete them and readd them to new position,
3368 // or they might overlap each other during the move
3369 QGraphicsItemGroup *group;
3370 if (m_selectionGroup)
3371 group = static_cast <QGraphicsItemGroup *>(m_selectionGroup);
3373 group = static_cast <QGraphicsItemGroup *>(m_dragItem->parentItem());
3374 QList<QGraphicsItem *> items = group->childItems();
3376 QList<ItemInfo> clipsToMove;
3377 QList<ItemInfo> transitionsToMove;
3379 GenTime timeOffset = GenTime(m_dragItem->scenePos().x(), m_document->fps()) - m_dragItemInfo.startPos;
3380 const int trackOffset = (int)(m_dragItem->scenePos().y() / m_tracksHeight) - m_dragItemInfo.track;
3382 QUndoCommand *moveGroup = new QUndoCommand();
3383 moveGroup->setText(i18n("Move group"));
3384 if (timeOffset != GenTime() || trackOffset != 0) {
3385 // remove items in MLT playlist
3388 int max = items.count();
3389 for (int i = 0; i < max; i++) {
3390 if (items.at(i)->type() == GROUPWIDGET) {
3391 items += items.at(i)->childItems();
3394 m_document->renderer()->blockSignals(true);
3395 for (int i = 0; i < items.count(); i++) {
3396 if (items.at(i)->type() != AVWIDGET && items.at(i)->type() != TRANSITIONWIDGET) continue;
3397 AbstractClipItem *item = static_cast <AbstractClipItem *>(items.at(i));
3398 ItemInfo info = item->info();
3399 if (item->type() == AVWIDGET) {
3400 if (m_document->renderer()->mltRemoveClip(m_document->tracksCount() - info.track, info.startPos) == false) {
3401 // error, clip cannot be removed from playlist
3402 emit displayMessage(i18n("Error removing clip at %1 on track %2", m_document->timecode().getTimecodeFromFrames(info.startPos.frames(m_document->fps())), info.track), ErrorMessage);
3404 clipsToMove.append(info);
3407 transitionsToMove.append(info);
3408 Transition *tr = static_cast <Transition*>(item);
3409 m_document->renderer()->mltDeleteTransition(tr->transitionTag(), tr->transitionEndTrack(), m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML());
3412 m_document->renderer()->blockSignals(false);
3413 for (int i = 0; i < items.count(); i++) {
3414 // re-add items in correct place
3415 if (items.at(i)->type() != AVWIDGET && items.at(i)->type() != TRANSITIONWIDGET) continue;
3416 AbstractClipItem *item = static_cast <AbstractClipItem *>(items.at(i));
3418 ItemInfo info = item->info();
3419 int tracknumber = m_document->tracksCount() - info.track - 1;
3420 bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
3422 group->removeFromGroup(item);
3423 item->setItemLocked(true);
3426 if (item->type() == AVWIDGET) {
3427 ClipItem *clip = static_cast <ClipItem*>(item);
3428 info.track = m_document->tracksCount() - info.track;
3429 adjustTimelineClips(m_scene->editMode(), clip, ItemInfo(), moveGroup);
3430 m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(info.track), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
3431 for (int i = 0; i < clip->effectsCount(); i++) {
3432 m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false);
3435 Transition *tr = static_cast <Transition*>(item);
3436 int newTrack = tr->transitionEndTrack();
3437 if (!tr->forcedTrack()) {
3438 newTrack = getPreviousVideoTrack(info.track);
3440 tr->updateTransitionEndTrack(newTrack);
3441 adjustTimelineTransitions(m_scene->editMode(), tr, moveGroup);
3442 m_document->renderer()->mltAddTransition(tr->transitionTag(), newTrack, m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML());
3445 new MoveGroupCommand(this, clipsToMove, transitionsToMove, timeOffset, trackOffset, false, moveGroup);
3446 updateTrackDuration(-1, moveGroup);
3447 m_commandStack->push(moveGroup);
3449 //QPointF top = group->sceneBoundingRect().topLeft();
3450 //QPointF oldpos = m_selectionGroup->scenePos();
3451 //kDebug()<<"SELECTION GRP POS: "<<m_selectionGroup->scenePos()<<", TOP: "<<top;
3452 //group->setPos(top);
3453 //TODO: get rid of the 3 lines below
3454 if (m_selectionGroup) {
3455 m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps());
3456 m_selectionGroupInfo.track = m_selectionGroup->track();
3458 for (int i = 0; i < items.count(); ++i) {
3459 if (items.at(i)->type() == GROUPWIDGET) {
3460 rebuildGroup((AbstractGroupItem*)items.at(i));
3465 for (int i = 0; i < items.count(); ++i) {
3467 items.at(i)->setSelected(true);
3468 if (items.at(i)->parentItem())
3469 items.at(i)->parentItem()->setSelected(true);
3472 resetSelectionGroup();
3473 groupSelectedItems();
3475 rebuildGroup((AbstractGroupItem *)group);
3477 setDocumentModified();
3480 m_document->renderer()->doRefresh();
3481 } else if (m_operationMode == RESIZESTART && m_dragItem->startPos() != m_dragItemInfo.startPos) {
3483 if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
3484 AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
3486 QUndoCommand *resizeCommand = new QUndoCommand();
3487 resizeCommand->setText(i18n("Resize group"));
3488 QList <QGraphicsItem *> items = parent->childItems();
3489 QList <ItemInfo> infos = parent->resizeInfos();
3490 parent->clearResizeInfos();
3492 for (int i = 0; i < items.count(); ++i) {
3493 AbstractClipItem *item = static_cast<AbstractClipItem *>(items.at(i));
3494 if (item && item->type() == AVWIDGET) {
3495 ItemInfo info = infos.at(itemcount);
3496 prepareResizeClipStart(item, info, item->startPos().frames(m_document->fps()), false, resizeCommand);
3500 m_commandStack->push(resizeCommand);
3503 prepareResizeClipStart(m_dragItem, m_dragItemInfo, m_dragItem->startPos().frames(m_document->fps()));
3505 } else if (m_operationMode == RESIZEEND && m_dragItem->endPos() != m_dragItemInfo.endPos) {
3507 if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
3508 AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
3510 QUndoCommand *resizeCommand = new QUndoCommand();
3511 resizeCommand->setText(i18n("Resize group"));
3512 QList <QGraphicsItem *> items = parent->childItems();
3513 QList <ItemInfo> infos = parent->resizeInfos();
3514 parent->clearResizeInfos();
3516 for (int i = 0; i < items.count(); ++i) {
3517 AbstractClipItem *item = static_cast<AbstractClipItem *>(items.at(i));
3518 if (item && item->type() == AVWIDGET) {
3519 ItemInfo info = infos.at(itemcount);
3520 prepareResizeClipEnd(item, info, item->endPos().frames(m_document->fps()), false, resizeCommand);
3524 updateTrackDuration(-1, resizeCommand);
3525 m_commandStack->push(resizeCommand);
3528 prepareResizeClipEnd(m_dragItem, m_dragItemInfo, m_dragItem->endPos().frames(m_document->fps()));
3530 } else if (m_operationMode == FADEIN) {
3531 // resize fade in effect
3532 ClipItem * item = static_cast <ClipItem *>(m_dragItem);
3533 int ix = item->hasEffect("volume", "fadein");
3534 int ix2 = item->hasEffect("", "fade_from_black");
3536 QDomElement oldeffect = item->effectAt(ix);
3537 int start = item->cropStart().frames(m_document->fps());
3538 int end = item->fadeIn();
3540 slotDeleteEffect(item, -1, oldeffect, false);
3543 QDomElement effect = oldeffect.cloneNode().toElement();
3544 EffectsList::setParameter(oldeffect, "in", QString::number(start));
3545 EffectsList::setParameter(oldeffect, "out", QString::number(end));
3546 slotUpdateClipEffect(item, -1, effect, oldeffect, ix);
3547 emit clipItemSelected(item, ix);
3549 } else if (item->fadeIn() != 0 && ix2 == -1) {
3551 if (item->isVideoOnly() || (item->clipType() != AUDIO && item->clipType() != AV && item->clipType() != PLAYLIST)) {
3553 effect = MainWindow::videoEffects.getEffectByTag("", "fade_from_black").cloneNode().toElement();
3554 } else effect = MainWindow::audioEffects.getEffectByTag("volume", "fadein").cloneNode().toElement();
3555 EffectsList::setParameter(effect, "out", QString::number(item->fadeIn()));
3556 slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
3559 QDomElement oldeffect = item->effectAt(ix2);
3560 int start = item->cropStart().frames(m_document->fps());
3561 int end = item->fadeIn();
3563 slotDeleteEffect(item, -1, oldeffect, false);
3566 QDomElement effect = oldeffect.cloneNode().toElement();
3567 EffectsList::setParameter(oldeffect, "in", QString::number(start));
3568 EffectsList::setParameter(oldeffect, "out", QString::number(end));
3569 slotUpdateClipEffect(item, -1, effect, oldeffect, ix2);
3570 emit clipItemSelected(item, ix2);
3573 } else if (m_operationMode == FADEOUT) {
3574 // resize fade in effect
3575 ClipItem * item = static_cast <ClipItem *>(m_dragItem);
3576 int ix = item->hasEffect("volume", "fadeout");
3577 int ix2 = item->hasEffect("", "fade_to_black");
3579 QDomElement oldeffect = item->effectAt(ix);
3580 int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
3581 int start = item->fadeOut();
3583 slotDeleteEffect(item, -1, oldeffect, false);
3585 start = end - start;
3586 QDomElement effect = oldeffect.cloneNode().toElement();
3587 EffectsList::setParameter(oldeffect, "in", QString::number(start));
3588 EffectsList::setParameter(oldeffect, "out", QString::number(end));
3589 // kDebug()<<"EDIT FADE OUT : "<<start<<"x"<<end;
3590 slotUpdateClipEffect(item, -1, effect, oldeffect, ix);
3591 emit clipItemSelected(item, ix);
3593 } else if (item->fadeOut() != 0 && ix2 == -1) {
3595 if (item->isVideoOnly() || (item->clipType() != AUDIO && item->clipType() != AV && item->clipType() != PLAYLIST)) {
3597 effect = MainWindow::videoEffects.getEffectByTag("", "fade_to_black").cloneNode().toElement();
3598 } else effect = MainWindow::audioEffects.getEffectByTag("volume", "fadeout").cloneNode().toElement();
3599 EffectsList::setParameter(effect, "in", QString::number(item->fadeOut()));
3600 EffectsList::setParameter(effect, "out", QString::number(0));
3601 slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
3604 QDomElement oldeffect = item->effectAt(ix2);
3605 int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
3606 int start = item->fadeOut();
3608 slotDeleteEffect(item, -1, oldeffect, false);
3610 start = end - start;
3611 QDomElement effect = oldeffect.cloneNode().toElement();
3612 EffectsList::setParameter(oldeffect, "in", QString::number(start));
3613 EffectsList::setParameter(oldeffect, "out", QString::number(end));
3614 // kDebug()<<"EDIT FADE OUT : "<<start<<"x"<<end;
3615 slotUpdateClipEffect(item, -1, effect, oldeffect, ix2);
3616 emit clipItemSelected(item, ix2);
3619 } else if (m_operationMode == KEYFRAME) {
3620 // update the MLT effect
3621 ClipItem * item = static_cast <ClipItem *>(m_dragItem);
3622 QDomElement oldEffect = item->selectedEffect().cloneNode().toElement();
3624 // check if we want to remove keyframe
3625 double val = mapToScene(event->pos()).toPoint().y();
3626 QRectF br = item->sceneBoundingRect();
3627 double maxh = 100.0 / br.height();
3628 val = (br.bottom() - val) * maxh;
3629 int start = item->cropStart().frames(m_document->fps());
3630 int end = (item->cropStart() + item->cropDuration()).frames(m_document->fps()) - 1;
3632 if ((val < -50 || val > 150) && item->editedKeyFramePos() != start && item->editedKeyFramePos() != end && item->keyFrameNumber() > 1) {
3634 item->movedKeyframe(item->getEffectAt(item->selectedEffectIndex()), item->selectedKeyFramePos(), -1, 0);
3636 item->movedKeyframe(item->getEffectAt(item->selectedEffectIndex()), item->selectedKeyFramePos(), item->editedKeyFramePos(), item->editedKeyFrameValue());
3639 QDomElement newEffect = item->selectedEffect().cloneNode().toElement();
3640 //item->updateKeyframeEffect();
3641 //QString next = item->keyframes(item->selectedEffectIndex());
3642 //EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
3643 EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), oldEffect, newEffect, item->selectedEffectIndex(), false);
3645 m_commandStack->push(command);
3646 updateEffect(m_document->tracksCount() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
3647 emit clipItemSelected(item, item->selectedEffectIndex());
3649 if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET && m_dragItem->isSelected()) {
3650 // A transition is selected
3652 ClipItem *transitionClip = getClipItemAt(m_dragItemInfo.startPos, m_dragItemInfo.track);
3653 if (transitionClip && transitionClip->baseClip()) {
3654 QString size = transitionClip->baseClip()->getProperty("frame_size");
3655 double factor = transitionClip->baseClip()->getProperty("aspect_ratio").toDouble();
3656 if (factor == 0) factor = 1.0;
3657 p.setX((int)(size.section('x', 0, 0).toInt() * factor + 0.5));
3658 p.setY(size.section('x', 1, 1).toInt());
3660 emit transitionItemSelected(static_cast <Transition *>(m_dragItem), getPreviousVideoTrack(m_dragItem->track()), p);
3661 } else emit transitionItemSelected(NULL);
3662 if (m_operationMode != NONE && m_operationMode != MOVE) setDocumentModified();
3663 m_operationMode = NONE;
3666 void CustomTrackView::deleteClip(ItemInfo info, bool refresh)
3668 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
3670 if (!item || m_document->renderer()->mltRemoveClip(m_document->tracksCount() - info.track, info.startPos) == false) {
3671 emit displayMessage(i18n("Error removing clip at %1 on track %2", m_document->timecode().getTimecodeFromFrames(info.startPos.frames(m_document->fps())), info.track), ErrorMessage);
3674 m_waitingThumbs.removeAll(item);
3675 if (item->isSelected()) emit clipItemSelected(NULL);
3676 item->baseClip()->removeReference();
3677 m_document->updateClip(item->baseClip()->getId());
3679 /*if (item->baseClip()->isTransparent()) {
3680 // also remove automatic transition
3681 Transition *tr = getTransitionItemAt(info.startPos, info.track);
3682 if (tr && tr->isAutomatic()) {
3683 m_document->renderer()->mltDeleteTransition(tr->transitionTag(), tr->transitionEndTrack(), m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML());
3684 scene()->removeItem(tr);
3689 if (m_dragItem == item) m_dragItem = NULL;
3691 #if QT_VERSION >= 0x040600
3692 // animate item deletion
3693 item->closeAnimation();
3694 /*if (refresh) item->closeAnimation();
3696 // no refresh, means we have several operations chained, we need to delete clip immediatly
3697 // so that it does not get in the way of the other
3706 setDocumentModified();
3707 if (refresh) m_document->renderer()->doRefresh();
3710 void CustomTrackView::deleteSelectedClips()
3712 resetSelectionGroup();
3713 QList<QGraphicsItem *> itemList = scene()->selectedItems();
3714 if (itemList.count() == 0) {
3715 emit displayMessage(i18n("Select clip to delete"), ErrorMessage);
3718 scene()->clearSelection();
3719 QUndoCommand *deleteSelected = new QUndoCommand();
3721 bool resetGroup = false;
3724 int transitionCount = 0;
3725 // expand & destroy groups
3726 for (int i = 0; i < itemList.count(); i++) {
3727 if (itemList.at(i)->type() == GROUPWIDGET) {
3729 QList<QGraphicsItem *> children = itemList.at(i)->childItems();
3730 QList <ItemInfo> clipInfos;
3731 QList <ItemInfo> transitionInfos;
3732 GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
3733 for (int j = 0; j < children.count(); j++) {
3734 if (children.at(j)->type() == AVWIDGET) {
3735 AbstractClipItem *clip = static_cast <AbstractClipItem *>(children.at(j));
3736 if (!clip->isItemLocked()) clipInfos.append(clip->info());
3737 } else if (children.at(j)->type() == TRANSITIONWIDGET) {
3738 AbstractClipItem *clip = static_cast <AbstractClipItem *>(children.at(j));
3739 if (!clip->isItemLocked()) transitionInfos.append(clip->info());
3741 if (itemList.contains(children.at(j))) {
3742 children.removeAt(j);
3746 itemList += children;
3747 if (clipInfos.count() > 0)
3748 new GroupClipsCommand(this, clipInfos, transitionInfos, false, deleteSelected);
3750 } else if (itemList.at(i)->parentItem() && itemList.at(i)->parentItem()->type() == GROUPWIDGET)
3751 itemList.insert(i + 1, itemList.at(i)->parentItem());
3754 for (int i = 0; i < itemList.count(); i++) {
3755 if (itemList.at(i)->type() == AVWIDGET) {
3757 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
3758 if (item->parentItem()) resetGroup = true;
3759 //kDebug()<<"// DELETE CLP AT: "<<item->info().startPos.frames(25);
3760 new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, true, true, deleteSelected);
3761 emit clipItemSelected(NULL);
3762 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
3764 Transition *item = static_cast <Transition *>(itemList.at(i));
3765 //kDebug()<<"// DELETE TRANS AT: "<<item->info().startPos.frames(25);
3766 if (item->parentItem()) resetGroup = true;
3767 new AddTransitionCommand(this, item->info(), item->transitionEndTrack(), item->toXML(), true, true, deleteSelected);
3768 emit transitionItemSelected(NULL);
3771 if (groupCount > 0 && clipCount == 0 && transitionCount == 0)
3772 deleteSelected->setText(i18np("Delete selected group", "Delete selected groups", groupCount));
3773 else if (clipCount > 0 && groupCount == 0 && transitionCount == 0)
3774 deleteSelected->setText(i18np("Delete selected clip", "Delete selected clips", clipCount));
3775 else if (transitionCount > 0 && groupCount == 0 && clipCount == 0)
3776 deleteSelected->setText(i18np("Delete selected transition", "Delete selected transitions", transitionCount));
3777 else deleteSelected->setText(i18n("Delete selected items"));
3778 updateTrackDuration(-1, deleteSelected);
3779 m_commandStack->push(deleteSelected);
3782 void CustomTrackView::changeClipSpeed()
3784 QList<QGraphicsItem *> itemList = scene()->selectedItems();
3785 if (itemList.count() == 0) {
3786 emit displayMessage(i18n("Select clip to change speed"), ErrorMessage);
3789 QUndoCommand *changeSelected = new QUndoCommand();
3790 changeSelected->setText("Edit clip speed");
3794 for (int i = 0; i < itemList.count(); i++) {
3795 if (itemList.at(i)->type() == AVWIDGET) {
3796 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
3797 ItemInfo info = item->info();
3798 if (percent == -1) percent = QInputDialog::getInteger(this, i18n("Edit Clip Speed"), i18n("New speed (percents)"), item->speed() * 100, 1, 10000, 1, &ok);
3800 double speed = (double) percent / 100.0;
3801 if (item->speed() != speed && (item->clipType() == VIDEO || item->clipType() == AV)) {
3803 //new ChangeSpeedCommand(this, info, item->speed(), speed, item->clipProducer(), changeSelected);
3807 if (count > 0) m_commandStack->push(changeSelected);
3808 else delete changeSelected;
3811 void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, const double speed, const double oldspeed, int strobe, const QString &id)
3814 //DocClipBase *baseclip = m_document->clipManager()->getClipById(id);
3816 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
3818 kDebug() << "ERROR: Cannot find clip for speed change";
3819 emit displayMessage(i18n("Cannot find clip for speed change"), ErrorMessage);
3822 info.track = m_document->tracksCount() - item->track();
3823 int endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, item->getProducer(item->track(), false));
3825 item->setSpeed(speed, strobe);
3826 item->updateRectGeometry();
3827 if (item->cropDuration().frames(m_document->fps()) != endPos)
3828 item->resizeEnd((int) info.startPos.frames(m_document->fps()) + endPos - 1);
3829 updatePositionEffects(item, info);
3830 setDocumentModified();
3832 emit displayMessage(i18n("Invalid clip"), ErrorMessage);
3836 void CustomTrackView::cutSelectedClips()
3838 QList<QGraphicsItem *> itemList = scene()->selectedItems();
3839 QList<AbstractGroupItem *> groups;
3840 GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
3841 for (int i = 0; i < itemList.count(); ++i) {
3842 if (!itemList.at(i))
3844 if (itemList.at(i)->type() == AVWIDGET) {
3845 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
3846 if (item->parentItem() && item->parentItem() != m_selectionGroup) {
3847 AbstractGroupItem *group = static_cast <AbstractGroupItem *>(item->parentItem());
3848 if (!groups.contains(group))
3850 } else if (currentPos > item->startPos() && currentPos < item->endPos()) {
3851 RazorClipCommand *command = new RazorClipCommand(this, item->info(), currentPos);
3852 m_commandStack->push(command);
3854 } else if (itemList.at(i)->type() == GROUPWIDGET && itemList.at(i) != m_selectionGroup) {
3855 AbstractGroupItem *group = static_cast<AbstractGroupItem *>(itemList.at(i));
3856 if (!groups.contains(group))
3861 for (int i = 0; i < groups.count(); ++i)
3862 razorGroup(groups.at(i), currentPos);
3865 void CustomTrackView::razorGroup(AbstractGroupItem* group, GenTime cutPos)
3868 QList <QGraphicsItem *> children = group->childItems();
3869 QList <ItemInfo> clips1, transitions1;
3870 QList <ItemInfo> clipsCut, transitionsCut;
3871 QList <ItemInfo> clips2, transitions2;
3872 for (int i = 0; i < children.count(); ++i) {
3873 children.at(i)->setSelected(false);
3874 AbstractClipItem *child = static_cast <AbstractClipItem *>(children.at(i));
3875 if (child->type() == AVWIDGET) {
3876 if (cutPos > child->endPos())
3877 clips1 << child->info();
3878 else if (cutPos < child->startPos())
3879 clips2 << child->info();
3881 clipsCut << child->info();
3883 if (cutPos > child->endPos())
3884 transitions1 << child->info();
3885 else if (cutPos < child->startPos())
3886 transitions2 << child->info();
3888 transitionsCut << child->info();
3891 if (clipsCut.isEmpty() && transitionsCut.isEmpty() && ((clips1.isEmpty() && transitions1.isEmpty()) || (clips2.isEmpty() && transitions2.isEmpty())))
3893 RazorGroupCommand *command = new RazorGroupCommand(this, clips1, transitions1, clipsCut, transitionsCut, clips2, transitions2, cutPos);
3894 m_commandStack->push(command);
3898 void CustomTrackView::slotRazorGroup(QList <ItemInfo> clips1, QList <ItemInfo> transitions1, QList <ItemInfo> clipsCut, QList <ItemInfo> transitionsCut, QList <ItemInfo> clips2, QList <ItemInfo> transitions2, GenTime cutPos, bool cut)
3901 for (int i = 0; i < clipsCut.count(); ++i) {
3902 ClipItem *clip = getClipItemAt(clipsCut.at(i).startPos.frames(m_document->fps()), clipsCut.at(i).track);
3904 ClipItem *clipBehind = cutClip(clipsCut.at(i), cutPos, true);
3905 clips1 << clip->info();
3906 if (clipBehind != NULL)
3907 clips2 << clipBehind->info();
3910 /* TODO: cut transitionsCut
3911 * For now just append them to group1 */
3912 transitions1 << transitionsCut;
3913 doGroupClips(clips1, transitions1, true);
3914 doGroupClips(clips2, transitions2, true);
3916 /* we might also just use clipsCut.at(0)->parentItem().
3917 * Do this loop just in case something went wrong during cut */
3918 for (int i = 0; i < clipsCut.count(); ++i) {
3919 ClipItem *clip = getClipItemAt(cutPos.frames(m_document->fps()), clipsCut.at(i).track);
3920 if (clip && clip->parentItem() && clip->parentItem()->type() == GROUPWIDGET) {
3921 AbstractGroupItem *group = static_cast <AbstractGroupItem *>(clip->parentItem());
3922 QList <QGraphicsItem *> children = group->childItems();
3923 QList <ItemInfo> groupClips;
3924 QList <ItemInfo> groupTrans;
3925 for (int j = 0; j < children.count(); ++j) {
3926 if (children.at(j)->type() == AVWIDGET)
3927 groupClips << ((AbstractClipItem *)children.at(j))->info();
3928 else if (children.at(j)->type() == TRANSITIONWIDGET)
3929 groupTrans << ((AbstractClipItem *)children.at(j))->info();
3931 doGroupClips(groupClips, groupTrans, false);
3935 for (int i = 0; i < clipsCut.count(); ++i)
3936 cutClip(clipsCut.at(i), cutPos, false);
3937 // TODO: uncut transitonsCut
3938 doGroupClips(QList <ItemInfo>() << clips1 << clipsCut << clips2, QList <ItemInfo>() << transitions1 << transitionsCut << transitions2, true);
3942 void CustomTrackView::groupClips(bool group)
3944 QList<QGraphicsItem *> itemList = scene()->selectedItems();
3945 QList <ItemInfo> clipInfos;
3946 QList <ItemInfo> transitionInfos;
3947 GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
3950 int max = itemList.count();
3951 for (int i = 0; i < max; i++) {
3952 if (itemList.at(i)->type() == GROUPWIDGET) {
3953 itemList += itemList.at(i)->childItems();
3957 for (int i = 0; i < itemList.count(); i++) {
3958 if (itemList.at(i)->type() == AVWIDGET) {
3959 AbstractClipItem *clip = static_cast <AbstractClipItem *>(itemList.at(i));
3960 if (!clip->isItemLocked()) clipInfos.append(clip->info());
3961 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
3962 AbstractClipItem *clip = static_cast <AbstractClipItem *>(itemList.at(i));
3963 if (!clip->isItemLocked()) transitionInfos.append(clip->info());
3966 if (clipInfos.count() > 0) {
3967 GroupClipsCommand *command = new GroupClipsCommand(this, clipInfos, transitionInfos, group);
3968 m_commandStack->push(command);
3972 void CustomTrackView::doGroupClips(QList <ItemInfo> clipInfos, QList <ItemInfo> transitionInfos, bool group)
3974 resetSelectionGroup();
3975 m_scene->clearSelection();
3977 for (int i = 0; i < clipInfos.count(); i++) {
3978 ClipItem *clip = getClipItemAt(clipInfos.at(i).startPos, clipInfos.at(i).track);
3979 if (clip == NULL) continue;
3980 if (clip->parentItem() && clip->parentItem()->type() == GROUPWIDGET) {
3981 AbstractGroupItem *grp = static_cast <AbstractGroupItem *>(clip->parentItem());
3982 m_document->clipManager()->removeGroup(grp);
3983 scene()->destroyItemGroup(grp);
3985 clip->setFlag(QGraphicsItem::ItemIsMovable, true);
3987 for (int i = 0; i < transitionInfos.count(); i++) {
3988 Transition *tr = getTransitionItemAt(transitionInfos.at(i).startPos, transitionInfos.at(i).track);
3989 if (tr == NULL) continue;
3990 if (tr->parentItem() && tr->parentItem()->type() == GROUPWIDGET) {
3991 AbstractGroupItem *grp = static_cast <AbstractGroupItem *>(tr->parentItem());
3992 m_document->clipManager()->removeGroup(grp);
3993 scene()->destroyItemGroup(grp);
3995 tr->setFlag(QGraphicsItem::ItemIsMovable, true);
3997 setDocumentModified();
4001 QList <QGraphicsItemGroup *> groups;
4002 for (int i = 0; i < clipInfos.count(); i++) {
4003 ClipItem *clip = getClipItemAt(clipInfos.at(i).startPos, clipInfos.at(i).track);
4005 clip->setSelected(true);
4008 for (int i = 0; i < transitionInfos.count(); i++) {
4009 Transition *clip = getTransitionItemAt(transitionInfos.at(i).startPos, transitionInfos.at(i).track);
4011 clip->setSelected(true);
4014 groupSelectedItems(false, true);
4015 setDocumentModified();
4018 void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo info, EffectsList effects, bool overwrite, bool push, bool refresh)
4020 DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId);
4021 if (baseclip == NULL) {
4022 emit displayMessage(i18n("No clip copied"), ErrorMessage);
4026 if (baseclip->producer() == NULL) {
4027 // If the clip has no producer, we must wait until it is created...
4029 emit displayMessage(i18n("Waiting for clip..."), InformationMessage);
4030 emit forceClipProcessing(clipId);
4031 qApp->processEvents();
4032 for (int i = 0; i < 3; i++) {
4033 if (baseclip->producer() == NULL) {
4034 m_producerNotReady.wait(&m_mutex, 500 + 500 * i);
4037 if (baseclip->producer() == NULL) {
4038 emit displayMessage(i18n("Cannot insert clip..."), ErrorMessage);
4042 emit displayMessage(QString(), InformationMessage);
4046 ClipItem *item = new ClipItem(baseclip, info, m_document->fps(), xml.attribute("speed", "1").toDouble(), xml.attribute("strobe", "1").toInt());
4047 item->setEffectList(effects);
4048 if (xml.hasAttribute("audio_only")) item->setAudioOnly(true);
4049 else if (xml.hasAttribute("video_only")) item->setVideoOnly(true);
4050 scene()->addItem(item);
4052 int tracknumber = m_document->tracksCount() - info.track - 1;
4053 bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
4054 if (isLocked) item->setItemLocked(true);
4056 baseclip->addReference();
4057 m_document->updateClip(baseclip->getId());
4058 info.track = m_document->tracksCount() - info.track;
4059 m_document->renderer()->mltInsertClip(info, xml, item->getProducer(info.track), overwrite, push);
4060 for (int i = 0; i < item->effectsCount(); i++) {
4061 m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(item->effectAt(i)), false);
4063 setDocumentModified();
4065 m_document->renderer()->doRefresh();
4066 if (!baseclip->isPlaceHolder())
4067 m_waitingThumbs.append(item);
4068 m_thumbsTimer.start();
4071 void CustomTrackView::slotUpdateClip(const QString &clipId, bool reload)
4073 QList<QGraphicsItem *> list = scene()->items();
4074 ClipItem *clip = NULL;
4075 for (int i = 0; i < list.size(); ++i) {
4076 if (list.at(i)->type() == AVWIDGET) {
4077 clip = static_cast <ClipItem *>(list.at(i));
4078 if (clip->clipProducer() == clipId) {
4079 ItemInfo info = clip->info();
4080 info.track = m_document->tracksCount() - clip->track();
4081 if (reload && !m_document->renderer()->mltUpdateClip(info, clip->xml(), clip->baseClip()->producer(info.track))) {
4082 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", info.startPos.frames(m_document->fps()), info.track), ErrorMessage);
4084 clip->refreshClip(true, true);
4090 ClipItem *CustomTrackView::getClipItemAtEnd(GenTime pos, int track)
4092 int framepos = (int)(pos.frames(m_document->fps()));
4093 QList<QGraphicsItem *> list = scene()->items(QPointF(framepos - 1, track * m_tracksHeight + m_tracksHeight / 2));
4094 ClipItem *clip = NULL;
4095 for (int i = 0; i < list.size(); i++) {
4096 if (!list.at(i)->isEnabled()) continue;
4097 if (list.at(i)->type() == AVWIDGET) {
4098 ClipItem *test = static_cast <ClipItem *>(list.at(i));
4099 if (test->endPos() == pos) clip = test;
4106 ClipItem *CustomTrackView::getClipItemAtStart(GenTime pos, int track)
4108 QList<QGraphicsItem *> list = scene()->items(QPointF(pos.frames(m_document->fps()), track * m_tracksHeight + m_tracksHeight / 2));
4109 ClipItem *clip = NULL;
4110 for (int i = 0; i < list.size(); i++) {
4111 if (!list.at(i)->isEnabled()) continue;
4112 if (list.at(i)->type() == AVWIDGET) {
4113 ClipItem *test = static_cast <ClipItem *>(list.at(i));
4114 if (test->startPos() == pos) clip = test;
4121 ClipItem *CustomTrackView::getClipItemAt(int pos, int track)
4123 const QPointF p(pos, track * m_tracksHeight + m_tracksHeight / 2);
4124 QList<QGraphicsItem *> list = scene()->items(p);
4125 ClipItem *clip = NULL;
4126 for (int i = 0; i < list.size(); i++) {
4127 if (!list.at(i)->isEnabled()) continue;
4128 if (list.at(i)->type() == AVWIDGET) {
4129 clip = static_cast <ClipItem *>(list.at(i));
4136 ClipItem *CustomTrackView::getClipItemAt(GenTime pos, int track)
4138 return getClipItemAt((int) pos.frames(m_document->fps()), track);
4141 Transition *CustomTrackView::getTransitionItemAt(int pos, int track)
4143 const QPointF p(pos, (track + 1) * m_tracksHeight);
4144 QList<QGraphicsItem *> list = scene()->items(p);
4145 Transition *clip = NULL;
4146 for (int i = 0; i < list.size(); i++) {
4147 if (!list.at(i)->isEnabled()) continue;
4148 if (list.at(i)->type() == TRANSITIONWIDGET) {
4149 clip = static_cast <Transition *>(list.at(i));
4156 Transition *CustomTrackView::getTransitionItemAt(GenTime pos, int track)
4158 return getTransitionItemAt(pos.frames(m_document->fps()), track);
4161 Transition *CustomTrackView::getTransitionItemAtEnd(GenTime pos, int track)
4163 int framepos = (int)(pos.frames(m_document->fps()));
4164 const QPointF p(framepos - 1, (track + 1) * m_tracksHeight);
4165 QList<QGraphicsItem *> list = scene()->items(p);
4166 Transition *clip = NULL;
4167 for (int i = 0; i < list.size(); i++) {
4168 if (!list.at(i)->isEnabled()) continue;
4169 if (list.at(i)->type() == TRANSITIONWIDGET) {
4170 Transition *test = static_cast <Transition *>(list.at(i));
4171 if (test->endPos() == pos) clip = test;
4178 Transition *CustomTrackView::getTransitionItemAtStart(GenTime pos, int track)
4180 const QPointF p(pos.frames(m_document->fps()), (track + 1) * m_tracksHeight);
4181 QList<QGraphicsItem *> list = scene()->items(p);
4182 Transition *clip = NULL;
4183 for (int i = 0; i < list.size(); ++i) {
4184 if (!list.at(i)->isEnabled()) continue;
4185 if (list.at(i)->type() == TRANSITIONWIDGET) {
4186 Transition *test = static_cast <Transition *>(list.at(i));
4187 if (test->startPos() == pos) clip = test;
4194 void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end, bool refresh)
4196 if (m_selectionGroup) resetSelectionGroup(false);
4197 ClipItem *item = getClipItemAt((int) start.startPos.frames(m_document->fps()), start.track);
4199 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);
4200 kDebug() << "---------------- ERROR, CANNOT find clip to move at.. ";
4203 Mlt::Producer *prod = item->getProducer(end.track);
4205 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);
4207 bool snap = KdenliveSettings::snaptopoints();
4208 KdenliveSettings::setSnaptopoints(false);
4209 item->setPos((int) end.startPos.frames(m_document->fps()), (int)(end.track * m_tracksHeight + 1));
4211 int tracknumber = m_document->tracksCount() - end.track - 1;
4212 bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
4213 m_scene->clearSelection();
4214 if (isLocked) item->setItemLocked(true);
4216 if (item->isItemLocked()) item->setItemLocked(false);
4217 item->setSelected(true);
4219 if (item->baseClip()->isTransparent()) {
4220 // Also move automatic transition
4221 Transition *tr = getTransitionItemAt(start.startPos, start.track);
4222 if (tr && tr->isAutomatic()) {
4223 tr->updateTransitionEndTrack(getPreviousVideoTrack(end.track));
4224 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);
4225 tr->setPos((int) end.startPos.frames(m_document->fps()), (int)(end.track * m_tracksHeight + 1));
4228 KdenliveSettings::setSnaptopoints(snap);
4229 setDocumentModified();
4231 // undo last move and emit error message
4232 emit displayMessage(i18n("Cannot move clip to position %1", m_document->timecode().getTimecodeFromFrames(end.startPos.frames(m_document->fps()))), ErrorMessage);
4234 if (refresh) m_document->renderer()->doRefresh();
4237 void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> startTransition, const GenTime offset, const int trackOffset, bool reverseMove)
4240 resetSelectionGroup();
4241 m_scene->clearSelection();
4243 m_selectionGroup = new AbstractGroupItem(m_document->fps());
4244 scene()->addItem(m_selectionGroup);
4246 m_document->renderer()->blockSignals(true);
4247 for (int i = 0; i < startClip.count(); i++) {
4249 startClip[i].startPos = startClip.at(i).startPos - offset;
4250 startClip[i].track = startClip.at(i).track - trackOffset;
4252 ClipItem *clip = getClipItemAt(startClip.at(i).startPos, startClip.at(i).track);
4254 clip->setItemLocked(false);
4255 if (clip->parentItem()) {
4256 m_selectionGroup->addToGroup(clip->parentItem());
4257 clip->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
4259 m_selectionGroup->addToGroup(clip);
4260 clip->setFlag(QGraphicsItem::ItemIsMovable, false);
4262 m_document->renderer()->mltRemoveClip(m_document->tracksCount() - startClip.at(i).track, startClip.at(i).startPos);
4263 } else kDebug() << "//MISSING CLIP AT: " << startClip.at(i).startPos.frames(25);
4265 for (int i = 0; i < startTransition.count(); i++) {
4267 startTransition[i].startPos = startTransition.at(i).startPos - offset;
4268 startTransition[i].track = startTransition.at(i).track - trackOffset;
4270 Transition *tr = getTransitionItemAt(startTransition.at(i).startPos, startTransition.at(i).track);
4272 tr->setItemLocked(false);
4273 if (tr->parentItem()) {
4274 m_selectionGroup->addToGroup(tr->parentItem());
4275 tr->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
4277 m_selectionGroup->addToGroup(tr);
4278 tr->setFlag(QGraphicsItem::ItemIsMovable, false);
4280 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());
4281 } else kDebug() << "//MISSING TRANSITION AT: " << startTransition.at(i).startPos.frames(25);
4283 m_document->renderer()->blockSignals(false);
4285 if (m_selectionGroup) {
4286 bool snap = KdenliveSettings::snaptopoints();
4287 KdenliveSettings::setSnaptopoints(false);
4289 m_selectionGroup->translate(offset.frames(m_document->fps()), trackOffset *(qreal) m_tracksHeight);
4290 //m_selectionGroup->moveBy(offset.frames(m_document->fps()), trackOffset *(qreal) m_tracksHeight);
4292 QList<QGraphicsItem *> children = m_selectionGroup->childItems();
4294 int max = children.count();
4295 for (int i = 0; i < max; i++) {
4296 if (children.at(i)->type() == GROUPWIDGET) {
4297 children += children.at(i)->childItems();
4298 //AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(children.at(i));
4299 //grp->moveBy(offset.frames(m_document->fps()), trackOffset *(qreal) m_tracksHeight);
4300 /*m_document->clipManager()->removeGroup(grp);
4301 m_scene->destroyItemGroup(grp);*/
4302 children.removeAll(children.at(i));
4307 for (int i = 0; i < children.count(); i++) {
4308 // re-add items in correct place
4309 if (children.at(i)->type() != AVWIDGET && children.at(i)->type() != TRANSITIONWIDGET) continue;
4310 AbstractClipItem *item = static_cast <AbstractClipItem *>(children.at(i));
4312 ItemInfo info = item->info();
4313 int tracknumber = m_document->tracksCount() - info.track - 1;
4314 bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
4316 item->setItemLocked(true);
4317 else if (item->isItemLocked())
4318 item->setItemLocked(false);
4320 if (item->type() == AVWIDGET) {
4321 ClipItem *clip = static_cast <ClipItem*>(item);
4322 info.track = m_document->tracksCount() - info.track;
4323 m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(info.track));
4324 for (int i = 0; i < clip->effectsCount(); i++) {
4325 m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false);
4327 } else if (item->type() == TRANSITIONWIDGET) {
4328 Transition *tr = static_cast <Transition*>(item);
4330 if (!tr->forcedTrack()) {
4331 newTrack = getPreviousVideoTrack(info.track);
4333 newTrack = tr->transitionEndTrack() + trackOffset;
4334 if (newTrack < 0 || newTrack > m_document->tracksCount()) newTrack = getPreviousVideoTrack(info.track);
4336 tr->updateTransitionEndTrack(newTrack);
4337 m_document->renderer()->mltAddTransition(tr->transitionTag(), newTrack, m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML());
4341 resetSelectionGroup(false);
4343 for (int i = 0; i < children.count(); i++) {
4344 if (children.at(i)->parentItem())
4345 rebuildGroup((AbstractGroupItem*)children.at(i)->parentItem());
4349 KdenliveSettings::setSnaptopoints(snap);
4350 m_document->renderer()->doRefresh();
4351 } else kDebug() << "///////// WARNING; NO GROUP TO MOVE";
4354 void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end, bool m_refresh)
4356 Transition *item = getTransitionItemAt(start.startPos, start.track);
4358 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);
4359 kDebug() << "---------------- ERROR, CANNOT find transition to move... ";// << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2;
4363 bool snap = KdenliveSettings::snaptopoints();
4364 KdenliveSettings::setSnaptopoints(false);
4366 if (end.endPos - end.startPos == start.endPos - start.startPos) {
4367 // Transition was moved
4368 item->setPos((int) end.startPos.frames(m_document->fps()), (end.track) * m_tracksHeight + 1);
4369 } else if (end.endPos == start.endPos) {
4370 // Transition start resize
4371 item->resizeStart((int) end.startPos.frames(m_document->fps()));
4372 } else if (end.startPos == start.startPos) {
4373 // Transition end resize;
4374 kDebug() << "// resize END: " << end.endPos.frames(m_document->fps());
4375 item->resizeEnd((int) end.endPos.frames(m_document->fps()));
4378 item->setPos((int) end.startPos.frames(m_document->fps()), (end.track) * m_tracksHeight + 1);
4379 item->resizeStart((int) end.startPos.frames(m_document->fps()));
4380 item->resizeEnd((int) end.endPos.frames(m_document->fps()));
4382 //item->moveTransition(GenTime((int) (endPos.x() - startPos.x()), m_document->fps()));
4383 KdenliveSettings::setSnaptopoints(snap);
4384 item->updateTransitionEndTrack(getPreviousVideoTrack(end.track));
4385 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());
4386 if (m_dragItem && m_dragItem == item) {
4388 ClipItem *transitionClip = getClipItemAt(item->startPos(), item->track());
4389 if (transitionClip && transitionClip->baseClip()) {
4390 QString size = transitionClip->baseClip()->getProperty("frame_size");
4391 double factor = transitionClip->baseClip()->getProperty("aspect_ratio").toDouble();
4392 if (factor == 0) factor = 1.0;
4393 p.setX((int)(size.section('x', 0, 0).toInt() * factor + 0.5));
4394 p.setY(size.section('x', 1, 1).toInt());
4396 emit transitionItemSelected(item, getPreviousVideoTrack(item->track()), p);
4398 if (m_refresh) m_document->renderer()->doRefresh();
4399 setDocumentModified();
4402 void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end, bool dontWorry)
4404 bool resizeClipStart = (start.startPos != end.startPos);
4405 ClipItem *item = getClipItemAtStart(start.startPos, start.track);
4407 if (dontWorry) return;
4408 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);
4409 kDebug() << "---------------- ERROR, CANNOT find clip to resize at... "; // << startPos;
4412 if (item->parentItem()) {
4413 // Item is part of a group, reset group
4414 resetSelectionGroup();
4417 bool snap = KdenliveSettings::snaptopoints();
4418 KdenliveSettings::setSnaptopoints(false);
4420 if (resizeClipStart) {
4421 ItemInfo clipinfo = item->info();
4422 clipinfo.track = m_document->tracksCount() - clipinfo.track;
4423 bool success = m_document->renderer()->mltResizeClipStart(clipinfo, end.startPos - clipinfo.startPos);
4425 kDebug() << "RESIZE CLP STRAT TO:" << end.startPos.frames(m_document->fps()) << ", OLD ST: " << start.startPos.frames(25);
4426 item->resizeStart((int) end.startPos.frames(m_document->fps()));
4427 updatePositionEffects(item, clipinfo);
4428 } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
4430 ItemInfo clipinfo = item->info();
4431 clipinfo.track = m_document->tracksCount() - clipinfo.track;
4432 bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, end.endPos - clipinfo.startPos);
4434 item->resizeEnd((int) end.endPos.frames(m_document->fps()));
4435 updatePositionEffects(item, clipinfo);
4436 } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
4438 if (!resizeClipStart && end.cropStart != start.cropStart) {
4439 kDebug() << "// RESIZE CROP, DIFF: " << (end.cropStart - start.cropStart).frames(25);
4440 ItemInfo clipinfo = end;
4441 clipinfo.track = m_document->tracksCount() - end.track;
4442 bool success = m_document->renderer()->mltResizeClipCrop(clipinfo, end.cropStart - start.cropStart);
4444 item->setCropStart(end.cropStart);
4445 item->resetThumbs(true);
4448 m_document->renderer()->doRefresh();
4449 KdenliveSettings::setSnaptopoints(snap);
4450 setDocumentModified();
4453 void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo oldInfo, int pos, bool check, QUndoCommand *command)
4455 if (pos == oldInfo.startPos.frames(m_document->fps()))
4457 bool snap = KdenliveSettings::snaptopoints();
4459 KdenliveSettings::setSnaptopoints(false);
4460 item->resizeStart(pos);
4461 if (item->startPos().frames(m_document->fps()) != pos) {
4462 item->resizeStart(oldInfo.startPos.frames(m_document->fps()));
4463 emit displayMessage(i18n("Not possible to resize"), ErrorMessage);
4464 KdenliveSettings::setSnaptopoints(snap);
4467 KdenliveSettings::setSnaptopoints(snap);
4470 bool hasParentCommand = false;
4472 hasParentCommand = true;
4474 command = new QUndoCommand();
4475 command->setText(i18n("Resize clip start"));
4478 // do this here, too, because otherwise undo won't update the group
4479 if (item->parentItem() && item->parentItem() != m_selectionGroup)
4480 new RebuildGroupCommand(this, item->info().track, item->endPos() - GenTime(1, m_document->fps()), command);
4482 ItemInfo info = item->info();
4483 if (item->type() == AVWIDGET) {
4484 ItemInfo resizeinfo = oldInfo;
4485 resizeinfo.track = m_document->tracksCount() - resizeinfo.track;
4486 bool success = m_document->renderer()->mltResizeClipStart(resizeinfo, item->startPos() - oldInfo.startPos);
4488 // Check if there is an automatic transition on that clip (lower track)
4489 Transition *transition = getTransitionItemAtStart(oldInfo.startPos, oldInfo.track);
4490 if (transition && transition->isAutomatic()) {
4491 ItemInfo trInfo = transition->info();
4492 ItemInfo newTrInfo = trInfo;
4493 newTrInfo.startPos = item->startPos();
4494 if (newTrInfo.startPos < newTrInfo.endPos)
4495 new MoveTransitionCommand(this, trInfo, newTrInfo, true, command);
4497 // Check if there is an automatic transition on that clip (upper track)
4498 transition = getTransitionItemAtStart(oldInfo.startPos, oldInfo.track - 1);
4499 if (transition && transition->isAutomatic() && (m_document->tracksCount() - transition->transitionEndTrack()) == oldInfo.track) {
4500 ItemInfo trInfo = transition->info();
4501 ItemInfo newTrInfo = trInfo;
4502 newTrInfo.startPos = item->startPos();
4503 ClipItem * upperClip = getClipItemAt(oldInfo.startPos, oldInfo.track - 1);
4504 if ((!upperClip || !upperClip->baseClip()->isTransparent()) && newTrInfo.startPos < newTrInfo.endPos)
4505 new MoveTransitionCommand(this, trInfo, newTrInfo, true, command);
4509 * TODO: cleanup the effect update process
4511 ClipItem *clip = static_cast < ClipItem * >(item);
4513 updatePositionEffects(clip, oldInfo);
4517 QDomElement root = doc.createElement("list");
4518 doc.appendChild(root);
4519 QList <int> indexes;
4520 for (int i = 0; i < clip->effectsCount(); i++) {
4521 QDomElement effect = clip->effectAt(i);
4522 if (EffectsList::hasKeyFrames(effect)) {
4523 doc.appendChild(doc.importNode(effect, true));
4528 if (clip->checkEffectsKeyframesPos(oldInfo.cropStart.frames(m_document->fps()), clip->cropStart().frames(m_document->fps()), true)) {
4529 // Keyframes were modified, updateClip
4530 QDomNodeList effs = doc.elementsByTagName("effect");
4532 // Since we must always resize clip before updating the keyframes, we
4533 // put a resize command before & after checking keyframes so that
4534 // we are sure the resize is performed before whenever we do or undo the action
4536 new ResizeClipCommand(this, oldInfo, info, false, true, command);
4537 for (int i = 0; i < indexes.count(); i++) {
4538 new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effs.at(i).cloneNode().toElement(), clip->effectAt(indexes.at(i)), indexes.at(i), false, command);
4539 updateEffect(m_document->tracksCount() - clip->track(), clip->startPos(), clip->effectAt(indexes.at(i)), indexes.at(i));
4541 new ResizeClipCommand(this, oldInfo, info, false, true, command);
4542 emit clipItemSelected(clip);
4544 new ResizeClipCommand(this, oldInfo, info, false, false, command);
4547 KdenliveSettings::setSnaptopoints(false);
4548 item->resizeStart((int) oldInfo.startPos.frames(m_document->fps()));
4549 KdenliveSettings::setSnaptopoints(snap);
4550 emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
4552 } else if (item->type() == TRANSITIONWIDGET) {
4553 Transition *transition = static_cast <Transition *>(item);
4554 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)) {
4555 // Cannot resize transition
4556 KdenliveSettings::setSnaptopoints(false);
4557 transition->resizeStart((int) oldInfo.startPos.frames(m_document->fps()));
4558 KdenliveSettings::setSnaptopoints(snap);
4559 emit displayMessage(i18n("Cannot resize transition"), ErrorMessage);
4561 MoveTransitionCommand *moveCommand = new MoveTransitionCommand(this, oldInfo, info, false, command);
4562 if (command == NULL)
4563 m_commandStack->push(moveCommand);
4567 if (item->parentItem() && item->parentItem() != m_selectionGroup)
4568 new RebuildGroupCommand(this, item->info().track, item->endPos() - GenTime(1, m_document->fps()), command);
4570 if (!hasParentCommand)
4571 m_commandStack->push(command);
4574 void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldInfo, int pos, bool check, QUndoCommand *command)
4576 if (pos == oldInfo.endPos.frames(m_document->fps()))
4578 bool snap = KdenliveSettings::snaptopoints();
4580 KdenliveSettings::setSnaptopoints(false);
4581 item->resizeEnd(pos);
4582 if (item->endPos().frames(m_document->fps()) != pos) {
4583 item->resizeEnd(oldInfo.endPos.frames(m_document->fps()));
4584 emit displayMessage(i18n("Not possible to resize"), ErrorMessage);
4585 KdenliveSettings::setSnaptopoints(snap);
4588 KdenliveSettings::setSnaptopoints(snap);
4591 bool hasParentCommand = false;
4593 hasParentCommand = true;
4595 command = new QUndoCommand();
4598 // do this here, too, because otherwise undo won't update the group
4599 if (item->parentItem() && item->parentItem() != m_selectionGroup)
4600 new RebuildGroupCommand(this, item->info().track, item->startPos(), command);
4602 ItemInfo info = item->info();
4603 if (item->type() == AVWIDGET) {
4604 if (!hasParentCommand) command->setText(i18n("Resize clip end"));
4605 ItemInfo resizeinfo = info;
4606 resizeinfo.track = m_document->tracksCount() - resizeinfo.track;
4607 bool success = m_document->renderer()->mltResizeClipEnd(resizeinfo, resizeinfo.cropDuration);
4609 // Check if there is an automatic transition on that clip (lower track)
4610 Transition *tr = getTransitionItemAtEnd(oldInfo.endPos, oldInfo.track);
4611 if (tr && tr->isAutomatic()) {
4612 ItemInfo trInfo = tr->info();
4613 ItemInfo newTrInfo = trInfo;
4614 newTrInfo.endPos = item->endPos();
4615 if (newTrInfo.endPos > newTrInfo.startPos)
4616 new MoveTransitionCommand(this, trInfo, newTrInfo, true, command);
4619 // Check if there is an automatic transition on that clip (upper track)
4620 tr = getTransitionItemAtEnd(oldInfo.endPos, oldInfo.track - 1);
4621 if (tr && tr->isAutomatic() && (m_document->tracksCount() - tr->transitionEndTrack()) == oldInfo.track) {
4622 ItemInfo trInfo = tr->info();
4623 ItemInfo newTrInfo = trInfo;
4624 newTrInfo.endPos = item->endPos();
4625 ClipItem * upperClip = getClipItemAtEnd(oldInfo.endPos, oldInfo.track - 1);
4626 if ((!upperClip || !upperClip->baseClip()->isTransparent()) && newTrInfo.endPos > newTrInfo.startPos)
4627 new MoveTransitionCommand(this, trInfo, newTrInfo, true, command);
4631 ClipItem *clip = static_cast < ClipItem * >(item);
4633 updatePositionEffects(clip, oldInfo);
4637 QDomElement root = doc.createElement("list");
4638 doc.appendChild(root);
4639 QList <int> indexes;
4640 for (int i = 0; i < clip->effectsCount(); i++) {
4641 QDomElement effect = clip->effectAt(i);
4642 if (EffectsList::hasKeyFrames(effect)) {
4643 doc.appendChild(doc.importNode(effect, true));
4648 if (clip->checkEffectsKeyframesPos((oldInfo.cropStart + oldInfo.endPos - oldInfo.startPos).frames(m_document->fps()) - 1, (clip->cropStart() + clip->cropDuration()).frames(m_document->fps()) - 1, false)) {
4649 // Keyframes were modified, updateClip
4650 QDomNodeList effs = doc.elementsByTagName("effect");
4652 // Since we must always resize clip before updating the keyframes, we
4653 // put a resize command before & after checking keyframes so that
4654 // we are sure the resize is performed before whenever we do or undo the action
4656 new ResizeClipCommand(this, oldInfo, info, false, true, command);
4657 for (int i = 0; i < indexes.count(); i++) {
4658 new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effs.at(i).cloneNode().toElement(), clip->effectAt(indexes.at(i)), indexes.at(i), false, command);
4659 updateEffect(m_document->tracksCount() - clip->track(), clip->startPos(), clip->effectAt(indexes.at(i)), indexes.at(i));
4661 new ResizeClipCommand(this, oldInfo, info, false, true, command);
4662 emit clipItemSelected(clip);
4664 new ResizeClipCommand(this, oldInfo, info, false, false, command);
4667 KdenliveSettings::setSnaptopoints(false);
4668 item->resizeEnd((int) oldInfo.endPos.frames(m_document->fps()));
4669 KdenliveSettings::setSnaptopoints(true);
4670 emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
4672 } else if (item->type() == TRANSITIONWIDGET) {
4673 if (!hasParentCommand) command->setText(i18n("Resize transition end"));
4674 Transition *transition = static_cast <Transition *>(item);
4675 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)) {
4676 // Cannot resize transition
4677 KdenliveSettings::setSnaptopoints(false);
4678 transition->resizeEnd((int) oldInfo.endPos.frames(m_document->fps()));
4679 KdenliveSettings::setSnaptopoints(true);
4680 emit displayMessage(i18n("Cannot resize transition"), ErrorMessage);
4682 // Check transition keyframes
4683 QDomElement old = transition->toXML();
4684 if (transition->updateKeyframes()) {
4685 QDomElement xml = transition->toXML();
4686 m_document->renderer()->mltUpdateTransition(xml.attribute("tag"), xml.attribute("tag"), xml.attribute("transition_btrack").toInt(), m_document->tracksCount() - xml.attribute("transition_atrack").toInt(), transition->startPos(), transition->endPos(), xml);
4687 new EditTransitionCommand(this, transition->track(), transition->startPos(), old, xml, false, command);
4689 new MoveTransitionCommand(this, oldInfo, info, false, command);
4692 if (item->parentItem() && item->parentItem() != m_selectionGroup)
4693 new RebuildGroupCommand(this, item->info().track, item->startPos(), command);
4695 if (!hasParentCommand) {
4696 updateTrackDuration(oldInfo.track, command);
4697 m_commandStack->push(command);
4701 void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
4703 int end = item->fadeIn();
4705 // there is a fade in effect
4706 int effectPos = item->hasEffect("volume", "fadein");
4707 if (effectPos != -1) {
4708 QDomElement oldeffect = item->effectAt(effectPos);
4709 int start = item->cropStart().frames(m_document->fps());
4710 int max = item->cropDuration().frames(m_document->fps());
4712 // Make sure the fade effect is not longer than the clip
4713 item->setFadeIn(max);
4714 end = item->fadeIn();
4717 EffectsList::setParameter(oldeffect, "in", QString::number(start));
4718 EffectsList::setParameter(oldeffect, "out", QString::number(end));
4719 if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect)))
4720 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
4721 // if fade effect is displayed, update the effect edit widget with new clip duration
4722 if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
4724 effectPos = item->hasEffect("brightness", "fade_from_black");
4725 if (effectPos != -1) {
4726 QDomElement oldeffect = item->effectAt(effectPos);
4727 int start = item->cropStart().frames(m_document->fps());
4728 int max = item->cropDuration().frames(m_document->fps());
4730 // Make sure the fade effect is not longer than the clip
4731 item->setFadeIn(max);
4732 end = item->fadeIn();
4735 EffectsList::setParameter(oldeffect, "in", QString::number(start));
4736 EffectsList::setParameter(oldeffect, "out", QString::number(end));
4737 if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect)))
4738 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
4739 // if fade effect is displayed, update the effect edit widget with new clip duration
4740 if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
4743 int start = item->fadeOut();
4745 // there is a fade out effect
4746 int effectPos = item->hasEffect("volume", "fadeout");
4747 if (effectPos != -1) {
4748 QDomElement oldeffect = item->effectAt(effectPos);
4749 int max = item->cropDuration().frames(m_document->fps());
4750 int end = max + item->cropStart().frames(m_document->fps());
4752 // Make sure the fade effect is not longer than the clip
4753 item->setFadeOut(max);
4754 start = item->fadeOut();
4756 start = end - start;
4757 EffectsList::setParameter(oldeffect, "in", QString::number(start));
4758 EffectsList::setParameter(oldeffect, "out", QString::number(end));
4759 if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect)))
4760 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
4761 // if fade effect is displayed, update the effect edit widget with new clip duration
4762 if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
4764 effectPos = item->hasEffect("brightness", "fade_to_black");
4765 if (effectPos != -1) {
4766 QDomElement oldeffect = item->effectAt(effectPos);
4767 int max = item->cropDuration().frames(m_document->fps());
4768 int end = max + item->cropStart().frames(m_document->fps());
4770 // Make sure the fade effect is not longer than the clip
4771 item->setFadeOut(max);
4772 start = item->fadeOut();
4774 start = end - start;
4775 EffectsList::setParameter(oldeffect, "in", QString::number(start));
4776 EffectsList::setParameter(oldeffect, "out", QString::number(end));
4777 if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect)))
4778 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
4779 // if fade effect is displayed, update the effect edit widget with new clip duration
4780 if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
4784 int effectPos = item->hasEffect("freeze", "freeze");
4785 if (effectPos != -1) {
4786 // Freeze effect needs to be adjusted with clip resize
4787 int diff = (info.startPos - item->startPos()).frames(m_document->fps());
4788 QDomElement eff = item->getEffectAt(effectPos);
4789 if (!eff.isNull() && diff != 0) {
4790 int freeze_pos = EffectsList::parameter(eff, "frame").toInt() + diff;
4791 EffectsList::setParameter(eff, "frame", QString::number(freeze_pos));
4792 if (item->isSelected() && item->selectedEffect().attribute("id") == "freeze") {
4793 emit clipItemSelected(item, item->selectedEffectIndex());
4798 updatePanZoom(item);
4801 double CustomTrackView::getSnapPointForPos(double pos)
4803 return m_scene->getSnapPointForPos(pos, KdenliveSettings::snaptopoints());
4806 void CustomTrackView::updateSnapPoints(AbstractClipItem *selected, QList <GenTime> offsetList, bool skipSelectedItems)
4808 QList <GenTime> snaps;
4809 if (selected && offsetList.isEmpty()) offsetList.append(selected->cropDuration());
4810 QList<QGraphicsItem *> itemList = items();
4811 for (int i = 0; i < itemList.count(); i++) {
4812 if (itemList.at(i) == selected) continue;
4813 if (skipSelectedItems && itemList.at(i)->isSelected()) continue;
4814 if (itemList.at(i)->type() == AVWIDGET) {
4815 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
4816 GenTime start = item->startPos();
4817 GenTime end = item->endPos();
4818 snaps.append(start);
4820 if (!offsetList.isEmpty()) {
4821 for (int j = 0; j < offsetList.size(); j++) {
4822 if (start > offsetList.at(j)) snaps.append(start - offsetList.at(j));
4823 if (end > offsetList.at(j)) snaps.append(end - offsetList.at(j));
4827 QList < GenTime > markers = item->snapMarkers();
4828 for (int j = 0; j < markers.size(); ++j) {
4829 GenTime t = markers.at(j);
4831 if (!offsetList.isEmpty()) {
4832 for (int k = 0; k < offsetList.size(); k++) {
4833 if (t > offsetList.at(k)) snaps.append(t - offsetList.at(k));
4837 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
4838 Transition *transition = static_cast <Transition*>(itemList.at(i));
4839 GenTime start = transition->startPos();
4840 GenTime end = transition->endPos();
4841 snaps.append(start);
4843 if (!offsetList.isEmpty()) {
4844 for (int j = 0; j < offsetList.size(); j++) {
4845 if (start > offsetList.at(j)) snaps.append(start - offsetList.at(j));
4846 if (end > offsetList.at(j)) snaps.append(end - offsetList.at(j));
4852 // add cursor position
4853 GenTime pos = GenTime(m_cursorPos, m_document->fps());
4855 if (!offsetList.isEmpty()) {
4856 for (int j = 0; j < offsetList.size(); j++) {
4857 snaps.append(pos - offsetList.at(j));
4862 for (int i = 0; i < m_guides.count(); i++) {
4863 snaps.append(m_guides.at(i)->position());
4864 if (!offsetList.isEmpty()) {
4865 for (int j = 0; j < offsetList.size(); j++) {
4866 snaps.append(m_guides.at(i)->position() - offsetList.at(j));
4872 QPoint z = m_document->zone();
4873 snaps.append(GenTime(z.x(), m_document->fps()));
4874 snaps.append(GenTime(z.y(), m_document->fps()));
4877 m_scene->setSnapList(snaps);
4878 //for (int i = 0; i < m_snapPoints.size(); ++i)
4879 // kDebug() << "SNAP POINT: " << m_snapPoints.at(i).frames(25);
4882 void CustomTrackView::slotSeekToPreviousSnap()
4884 updateSnapPoints(NULL);
4885 GenTime res = m_scene->previousSnapPoint(GenTime(m_cursorPos, m_document->fps()));
4886 setCursorPos((int) res.frames(m_document->fps()));
4890 void CustomTrackView::slotSeekToNextSnap()
4892 updateSnapPoints(NULL);
4893 GenTime res = m_scene->nextSnapPoint(GenTime(m_cursorPos, m_document->fps()));
4894 setCursorPos((int) res.frames(m_document->fps()));
4898 void CustomTrackView::clipStart()
4900 AbstractClipItem *item = getMainActiveClip();
4902 setCursorPos((int) item->startPos().frames(m_document->fps()));
4907 void CustomTrackView::clipEnd()
4909 AbstractClipItem *item = getMainActiveClip();
4911 setCursorPos((int) item->endPos().frames(m_document->fps()) - 1);
4916 void CustomTrackView::slotAddClipMarker(const QString &id, GenTime t, QString c)
4918 QString oldcomment = m_document->clipManager()->getClipById(id)->markerComment(t);
4919 AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, c, id, t);
4920 m_commandStack->push(command);
4923 void CustomTrackView::slotDeleteClipMarker(const QString &comment, const QString &id, const GenTime &position)
4925 AddMarkerCommand *command = new AddMarkerCommand(this, comment, QString(), id, position);
4926 m_commandStack->push(command);
4929 void CustomTrackView::slotDeleteAllClipMarkers(const QString &id)
4931 DocClipBase *base = m_document->clipManager()->getClipById(id);
4932 QList <CommentedTime> markers = base->commentedSnapMarkers();
4934 if (markers.isEmpty()) {
4935 emit displayMessage(i18n("Clip has no markers"), ErrorMessage);
4938 QUndoCommand *deleteMarkers = new QUndoCommand();
4939 deleteMarkers->setText("Delete clip markers");
4941 for (int i = 0; i < markers.size(); i++) {
4942 new AddMarkerCommand(this, markers.at(i).comment(), QString(), id, markers.at(i).time(), deleteMarkers);
4944 m_commandStack->push(deleteMarkers);
4947 void CustomTrackView::addMarker(const QString &id, const GenTime &pos, const QString comment)
4949 DocClipBase *base = m_document->clipManager()->getClipById(id);
4950 if (!comment.isEmpty()) base->addSnapMarker(pos, comment);
4951 else base->deleteSnapMarker(pos);
4952 emit updateClipMarkers(base);
4953 setDocumentModified();
4954 viewport()->update();
4957 int CustomTrackView::hasGuide(int pos, int offset)
4959 for (int i = 0; i < m_guides.count(); i++) {
4960 int guidePos = m_guides.at(i)->position().frames(m_document->fps());
4961 if (qAbs(guidePos - pos) <= offset) return guidePos;
4962 else if (guidePos > pos) return -1;
4967 void CustomTrackView::buildGuidesMenu(QMenu *goMenu) const
4971 double fps = m_document->fps();
4972 for (int i = 0; i < m_guides.count(); i++) {
4973 act = goMenu->addAction(m_guides.at(i)->label() + "/" + Timecode::getStringTimecode(m_guides.at(i)->position().frames(fps), fps));
4974 act->setData(m_guides.at(i)->position().frames(m_document->fps()));
4976 goMenu->setEnabled(!m_guides.isEmpty());
4979 void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const QString &comment)
4981 if (oldPos > GenTime() && pos > GenTime()) {
4983 for (int i = 0; i < m_guides.count(); i++) {
4984 if (m_guides.at(i)->position() == oldPos) {
4985 Guide *item = m_guides.at(i);
4986 item->updateGuide(pos, comment);
4990 } else if (pos > GenTime()) addGuide(pos, comment);
4994 for (int i = 0; i < m_guides.count(); i++) {
4995 if (m_guides.at(i)->position() == oldPos) {
4996 delete m_guides.takeAt(i);
5001 if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
5003 qSort(m_guides.begin(), m_guides.end(), sortGuidesList);
5004 m_document->syncGuides(m_guides);
5007 bool CustomTrackView::addGuide(const GenTime pos, const QString &comment)
5009 for (int i = 0; i < m_guides.count(); i++) {
5010 if (m_guides.at(i)->position() == pos) {
5011 emit displayMessage(i18n("A guide already exists at position %1", m_document->timecode().getTimecodeFromFrames(pos.frames(m_document->fps()))), ErrorMessage);
5015 Guide *g = new Guide(this, pos, comment, m_tracksHeight * m_document->tracksCount() * matrix().m22());
5016 scene()->addItem(g);
5018 qSort(m_guides.begin(), m_guides.end(), sortGuidesList);
5019 m_document->syncGuides(m_guides);
5023 void CustomTrackView::slotAddGuide(bool dialog)
5025 CommentedTime marker(GenTime(m_cursorPos, m_document->fps()), i18n("Guide"));
5027 MarkerDialog d(NULL, marker, m_document->timecode(), i18n("Add Guide"), this);
5028 if (d.exec() != QDialog::Accepted) return;
5029 marker = d.newMarker();
5032 marker.setComment(m_document->timecode().getDisplayTimecodeFromFrames(m_cursorPos, false));
5034 if (addGuide(marker.time(), marker.comment())) {
5035 EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), marker.time(), marker.comment(), false);
5036 m_commandStack->push(command);
5040 void CustomTrackView::slotEditGuide(int guidePos)
5043 if (guidePos == -1) pos = GenTime(m_cursorPos, m_document->fps());
5044 else pos = GenTime(guidePos, m_document->fps());
5046 for (int i = 0; i < m_guides.count(); i++) {
5047 if (m_guides.at(i)->position() == pos) {
5048 slotEditGuide(m_guides.at(i)->info());
5053 if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
5056 void CustomTrackView::slotEditGuide(CommentedTime guide)
5058 MarkerDialog d(NULL, guide, m_document->timecode(), i18n("Edit Guide"), this);
5059 if (d.exec() == QDialog::Accepted) {
5060 EditGuideCommand *command = new EditGuideCommand(this, guide.time(), guide.comment(), d.newMarker().time(), d.newMarker().comment(), true);
5061 m_commandStack->push(command);
5066 void CustomTrackView::slotEditTimeLineGuide()
5068 if (m_dragGuide == NULL) return;
5069 CommentedTime guide = m_dragGuide->info();
5070 MarkerDialog d(NULL, guide, m_document->timecode(), i18n("Edit Guide"), this);
5071 if (d.exec() == QDialog::Accepted) {
5072 EditGuideCommand *command = new EditGuideCommand(this, guide.time(), guide.comment(), d.newMarker().time(), d.newMarker().comment(), true);
5073 m_commandStack->push(command);
5077 void CustomTrackView::slotDeleteGuide(int guidePos)
5080 if (guidePos == -1) pos = GenTime(m_cursorPos, m_document->fps());
5081 else pos = GenTime(guidePos, m_document->fps());
5083 for (int i = 0; i < m_guides.count(); i++) {
5084 if (m_guides.at(i)->position() == pos) {
5085 EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true);
5086 m_commandStack->push(command);
5091 if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
5095 void CustomTrackView::slotDeleteTimeLineGuide()
5097 if (m_dragGuide == NULL) return;
5098 EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), GenTime(), QString(), true);
5099 m_commandStack->push(command);
5103 void CustomTrackView::slotDeleteAllGuides()
5105 QUndoCommand *deleteAll = new QUndoCommand();
5106 deleteAll->setText("Delete all guides");
5107 for (int i = 0; i < m_guides.count(); i++) {
5108 new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true, deleteAll);
5110 m_commandStack->push(deleteAll);
5113 void CustomTrackView::setTool(PROJECTTOOL tool)
5118 void CustomTrackView::setScale(double scaleFactor, double verticalScale)
5121 newmatrix = newmatrix.scale(scaleFactor, verticalScale);
5122 m_scene->setScale(scaleFactor, verticalScale);
5123 removeTipAnimation();
5124 bool adjust = false;
5125 if (verticalScale != matrix().m22()) adjust = true;
5126 setMatrix(newmatrix);
5128 double newHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
5129 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight - 1);
5130 for (int i = 0; i < m_guides.count(); i++) {
5131 QLineF l = m_guides.at(i)->line();
5132 l.setP2(QPointF(l.x2(), newHeight));
5133 m_guides.at(i)->setLine(l);
5135 setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount());
5138 int diff = sceneRect().width() - m_projectDuration;
5139 if (diff * newmatrix.m11() < 50) {
5140 if (newmatrix.m11() < 0.4)
5141 setSceneRect(0, 0, (m_projectDuration + 100 / newmatrix.m11()), sceneRect().height());
5143 setSceneRect(0, 0, (m_projectDuration + 300), sceneRect().height());
5145 double verticalPos = mapToScene(QPoint(0, viewport()->height() / 2)).y();
5146 centerOn(QPointF(cursorPos(), verticalPos));
5149 void CustomTrackView::slotRefreshGuides()
5151 if (KdenliveSettings::showmarkers()) {
5152 for (int i = 0; i < m_guides.count(); i++)
5153 m_guides.at(i)->update();
5157 void CustomTrackView::drawBackground(QPainter * painter, const QRectF &rect)
5159 painter->setClipRect(rect);
5160 QPen pen1 = painter->pen();
5161 pen1.setColor(palette().dark().color());
5162 painter->setPen(pen1);
5163 double min = rect.left();
5164 double max = rect.right();
5165 painter->drawLine(QPointF(min, 0), QPointF(max, 0));
5166 int maxTrack = m_document->tracksCount();
5167 QColor lockedColor = palette().button().color();
5168 QColor audioColor = palette().alternateBase().color();
5169 for (int i = 0; i < maxTrack; i++) {
5170 TrackInfo info = m_document->trackInfoAt(maxTrack - i - 1);
5171 if (info.isLocked || info.type == AUDIOTRACK || i == m_selectedTrack) {
5172 const QRectF track(min, m_tracksHeight * i + 1, max - min, m_tracksHeight - 1);
5173 if (i == m_selectedTrack)
5174 painter->fillRect(track, m_activeTrackBrush.brush(this));
5176 painter->fillRect(track, info.isLocked ? lockedColor : audioColor);
5178 painter->drawLine(QPointF(min, m_tracksHeight *(i + 1)), QPointF(max, m_tracksHeight *(i + 1)));
5182 bool CustomTrackView::findString(const QString &text)
5185 for (int i = 0; i < m_searchPoints.size(); ++i) {
5186 marker = m_searchPoints.at(i).comment();
5187 if (marker.contains(text, Qt::CaseInsensitive)) {
5188 setCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()), true);
5189 int vert = verticalScrollBar()->value();
5190 int hor = cursorPos();
5191 ensureVisible(hor, vert + 10, 2, 2, 50, 0);
5199 void CustomTrackView::selectFound(QString track, QString pos)
5201 setCursorPos(m_document->timecode().getFrameCount(pos), true);
5202 slotSelectTrack(track.toInt());
5204 int vert = verticalScrollBar()->value();
5205 int hor = cursorPos();
5206 ensureVisible(hor, vert + 10, 2, 2, 50, 0);
5209 bool CustomTrackView::findNextString(const QString &text)
5212 for (int i = m_findIndex + 1; i < m_searchPoints.size(); ++i) {
5213 marker = m_searchPoints.at(i).comment();
5214 if (marker.contains(text, Qt::CaseInsensitive)) {
5215 setCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()), true);
5216 int vert = verticalScrollBar()->value();
5217 int hor = cursorPos();
5218 ensureVisible(hor, vert + 10, 2, 2, 50, 0);
5227 void CustomTrackView::initSearchStrings()
5229 m_searchPoints.clear();
5230 QList<QGraphicsItem *> itemList = items();
5231 for (int i = 0; i < itemList.count(); i++) {
5232 // parse all clip names
5233 if (itemList.at(i)->type() == AVWIDGET) {
5234 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
5235 GenTime start = item->startPos();
5236 CommentedTime t(start, item->clipName());
5237 m_searchPoints.append(t);
5238 // add all clip markers
5239 QList < CommentedTime > markers = item->commentedSnapMarkers();
5240 m_searchPoints += markers;
5245 for (int i = 0; i < m_guides.count(); i++)
5246 m_searchPoints.append(m_guides.at(i)->info());
5248 qSort(m_searchPoints);
5251 void CustomTrackView::clearSearchStrings()
5253 m_searchPoints.clear();
5257 QList<ItemInfo> CustomTrackView::findId(const QString &clipId)
5259 QList<ItemInfo> matchingInfo;
5260 QList<QGraphicsItem *> itemList = items();
5261 for (int i = 0; i < itemList.count(); i++) {
5262 if (itemList.at(i)->type() == AVWIDGET) {
5263 ClipItem *item = (ClipItem *)itemList.at(i);
5264 if (item->clipProducer() == clipId)
5265 matchingInfo << item->info();
5268 return matchingInfo;
5271 void CustomTrackView::copyClip()
5273 qDeleteAll(m_copiedItems);
5274 m_copiedItems.clear();
5275 QList<QGraphicsItem *> itemList = scene()->selectedItems();
5276 if (itemList.count() == 0) {
5277 emit displayMessage(i18n("Select a clip before copying"), ErrorMessage);
5280 for (int i = 0; i < itemList.count(); i++) {
5281 if (itemList.at(i)->type() == AVWIDGET) {
5282 ClipItem *clip = static_cast <ClipItem *>(itemList.at(i));
5283 ClipItem *clone = clip->clone(clip->info());
5284 m_copiedItems.append(clone);
5285 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
5286 Transition *dup = static_cast <Transition *>(itemList.at(i));
5287 m_copiedItems.append(dup->clone());
5292 bool CustomTrackView::canBePastedTo(ItemInfo info, int type) const
5294 if (m_scene->editMode() != NORMALEDIT) {
5295 // If we are in overwrite mode, always allow the move
5298 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));
5299 QList<QGraphicsItem *> collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect);
5300 for (int i = 0; i < collisions.count(); i++) {
5301 if (collisions.at(i)->type() == type) return false;
5306 bool CustomTrackView::canBePastedTo(QList <ItemInfo> infoList, int type) const
5309 for (int i = 0; i < infoList.count(); i++) {
5310 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));
5313 QList<QGraphicsItem *> collisions = scene()->items(path);
5314 for (int i = 0; i < collisions.count(); i++) {
5315 if (collisions.at(i)->type() == type) return false;
5320 bool CustomTrackView::canBePasted(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const
5322 for (int i = 0; i < items.count(); i++) {
5323 ItemInfo info = items.at(i)->info();
5324 info.startPos += offset;
5325 info.endPos += offset;
5326 info.track += trackOffset;
5327 if (!canBePastedTo(info, items.at(i)->type())) return false;
5332 bool CustomTrackView::canBeMoved(QList<AbstractClipItem *> items, GenTime offset, int trackOffset) const
5334 QPainterPath movePath;
5335 movePath.moveTo(0, 0);
5337 for (int i = 0; i < items.count(); i++) {
5338 ItemInfo info = items.at(i)->info();
5339 info.startPos = info.startPos + offset;
5340 info.endPos = info.endPos + offset;
5341 info.track = info.track + trackOffset;
5342 if (info.startPos < GenTime()) {
5343 // No clip should go below 0
5346 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));
5347 movePath.addRect(rect);
5349 QList<QGraphicsItem *> collisions = scene()->items(movePath, Qt::IntersectsItemBoundingRect);
5350 for (int i = 0; i < collisions.count(); i++) {
5351 if ((collisions.at(i)->type() == AVWIDGET || collisions.at(i)->type() == TRANSITIONWIDGET) && !items.contains(static_cast <AbstractClipItem *>(collisions.at(i)))) {
5352 kDebug() << " //////////// CLIP COLLISION, MOVE NOT ALLOWED";
5360 void CustomTrackView::pasteClip()
5362 if (m_copiedItems.count() == 0) {
5363 emit displayMessage(i18n("No clip copied"), ErrorMessage);
5368 GenTime pos = GenTime(-1);
5369 if (m_menuPosition.isNull()) {
5370 position = mapFromGlobal(QCursor::pos());
5371 if (!contentsRect().contains(position) || mapToScene(position).y() / m_tracksHeight > m_document->tracksCount()) {
5372 track = m_selectedTrack;
5373 pos = GenTime(m_cursorPos, m_document->fps());
5374 /*emit displayMessage(i18n("Cannot paste selected clips"), ErrorMessage);
5378 position = m_menuPosition;
5381 if (pos == GenTime(-1))
5382 pos = GenTime((int)(mapToScene(position).x()), m_document->fps());
5384 track = (int)(mapToScene(position).y() / m_tracksHeight);
5386 GenTime leftPos = m_copiedItems.at(0)->startPos();
5387 int lowerTrack = m_copiedItems.at(0)->track();
5388 int upperTrack = m_copiedItems.at(0)->track();
5389 for (int i = 1; i < m_copiedItems.count(); i++) {
5390 if (m_copiedItems.at(i)->startPos() < leftPos) leftPos = m_copiedItems.at(i)->startPos();
5391 if (m_copiedItems.at(i)->track() < lowerTrack) lowerTrack = m_copiedItems.at(i)->track();
5392 if (m_copiedItems.at(i)->track() > upperTrack) upperTrack = m_copiedItems.at(i)->track();
5395 GenTime offset = pos - leftPos;
5396 int trackOffset = track - lowerTrack;
5398 if (lowerTrack + trackOffset < 0) trackOffset = 0 - lowerTrack;
5399 if (upperTrack + trackOffset > m_document->tracksCount() - 1) trackOffset = m_document->tracksCount() - upperTrack - 1;
5400 if (!canBePasted(m_copiedItems, offset, trackOffset)) {
5401 emit displayMessage(i18n("Cannot paste selected clips"), ErrorMessage);
5404 QUndoCommand *pasteClips = new QUndoCommand();
5405 pasteClips->setText("Paste clips");
5407 for (int i = 0; i < m_copiedItems.count(); i++) {
5408 // parse all clip names
5409 if (m_copiedItems.at(i) && m_copiedItems.at(i)->type() == AVWIDGET) {
5410 ClipItem *clip = static_cast <ClipItem *>(m_copiedItems.at(i));
5411 ItemInfo info = clip->info();
5412 info.startPos += offset;
5413 info.endPos += offset;
5414 info.track += trackOffset;
5415 if (canBePastedTo(info, AVWIDGET)) {
5416 new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), info, clip->effectList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, true, false, pasteClips);
5417 } else emit displayMessage(i18n("Cannot paste clip to selected place"), ErrorMessage);
5418 } else if (m_copiedItems.at(i) && m_copiedItems.at(i)->type() == TRANSITIONWIDGET) {
5419 Transition *tr = static_cast <Transition *>(m_copiedItems.at(i));
5421 info.startPos = tr->startPos() + offset;
5422 info.endPos = tr->endPos() + offset;
5423 info.track = tr->track() + trackOffset;
5424 int transitionEndTrack;
5425 if (!tr->forcedTrack()) transitionEndTrack = getPreviousVideoTrack(info.track);
5426 else transitionEndTrack = tr->transitionEndTrack();
5427 if (canBePastedTo(info, TRANSITIONWIDGET)) {
5428 if (info.startPos >= info.endPos) {
5429 emit displayMessage(i18n("Invalid transition"), ErrorMessage);
5430 } else new AddTransitionCommand(this, info, transitionEndTrack, tr->toXML(), false, true, pasteClips);
5431 } else emit displayMessage(i18n("Cannot paste transition to selected place"), ErrorMessage);
5434 updateTrackDuration(-1, pasteClips);
5435 m_commandStack->push(pasteClips);
5438 void CustomTrackView::pasteClipEffects()
5440 if (m_copiedItems.count() != 1 || m_copiedItems.at(0)->type() != AVWIDGET) {
5441 emit displayMessage(i18n("You must copy exactly one clip before pasting effects"), ErrorMessage);
5444 ClipItem *clip = static_cast < ClipItem *>(m_copiedItems.at(0));
5446 QUndoCommand *paste = new QUndoCommand();
5447 paste->setText("Paste effects");
5449 QList<QGraphicsItem *> clips = scene()->selectedItems();
5452 for (int i = 0; i < clips.count(); ++i) {
5453 if (clips.at(i)->type() == GROUPWIDGET) {
5454 QList<QGraphicsItem *> children = clips.at(i)->childItems();
5455 for (int j = 0; j < children.count(); j++) {
5456 if (children.at(j)->type() == AVWIDGET && !clips.contains(children.at(j))) {
5457 clips.append(children.at(j));
5463 for (int i = 0; i < clips.count(); ++i) {
5464 if (clips.at(i)->type() == AVWIDGET) {
5465 ClipItem *item = static_cast < ClipItem *>(clips.at(i));
5466 for (int j = 0; j < clip->effectsCount(); j++) {
5467 QDomElement eff = clip->effectAt(j);
5468 if (eff.attribute("unique", "0") == "0" || item->hasEffect(eff.attribute("tag"), eff.attribute("id")) == -1) {
5469 adjustKeyfames(clip->cropStart(), item->cropStart(), item->cropDuration(), eff);
5470 new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), eff, true, paste);
5475 if (paste->childCount() > 0) m_commandStack->push(paste);
5478 //adjust effects (fades, ...)
5479 for (int i = 0; i < clips.count(); ++i) {
5480 if (clips.at(i)->type() == AVWIDGET) {
5481 ClipItem *item = static_cast < ClipItem *>(clips.at(i));
5482 updatePositionEffects(item, item->info());
5488 void CustomTrackView::adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime duration, QDomElement xml)
5490 // parse parameters to check if we need to adjust to the new crop start
5491 int diff = (newstart - oldstart).frames(m_document->fps());
5492 int max = (newstart + duration).frames(m_document->fps());
5493 QDomNodeList params = xml.elementsByTagName("parameter");
5494 for (int i = 0; i < params.count(); i++) {
5495 QDomElement e = params.item(i).toElement();
5496 if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
5497 QString def = e.attribute("default");
5498 // Effect has a keyframe type parameter, we need to adjust the values
5499 QStringList keys = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
5500 QStringList newKeyFrames;
5501 foreach(const QString &str, keys) {
5502 int pos = str.section(':', 0, 0).toInt();
5503 double val = str.section(':', 1, 1).toDouble();
5506 newKeyFrames.append(QString::number(max) + ':' + QString::number(val));
5508 } else newKeyFrames.append(QString::number(pos) + ':' + QString::number(val));
5510 //kDebug()<<"ORIGIN: "<<keys<<", FIXED: "<<newKeyFrames;
5511 e.setAttribute("keyframes", newKeyFrames.join(";"));
5516 ClipItem *CustomTrackView::getClipUnderCursor() const
5518 QRectF rect((double) m_cursorPos, 0.0, 1.0, (double)(m_tracksHeight * m_document->tracksCount()));
5519 QList<QGraphicsItem *> collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect);
5520 for (int i = 0; i < collisions.count(); i++) {
5521 if (collisions.at(i)->type() == AVWIDGET) {
5522 return static_cast < ClipItem *>(collisions.at(i));
5528 AbstractClipItem *CustomTrackView::getMainActiveClip() const
5530 QList<QGraphicsItem *> clips = scene()->selectedItems();
5531 if (clips.isEmpty()) {
5532 return getClipUnderCursor();
5534 AbstractClipItem *item = NULL;
5535 for (int i = 0; i < clips.count(); ++i) {
5536 if (clips.at(i)->type() == AVWIDGET) {
5537 item = static_cast < AbstractClipItem *>(clips.at(i));
5538 if (clips.count() > 1 && item->startPos().frames(m_document->fps()) <= m_cursorPos && item->endPos().frames(m_document->fps()) >= m_cursorPos) break;
5541 if (item) return item;
5546 ClipItem *CustomTrackView::getActiveClipUnderCursor(bool allowOutsideCursor) const
5548 QList<QGraphicsItem *> clips = scene()->selectedItems();
5549 if (clips.isEmpty()) {
5550 return getClipUnderCursor();
5553 // remove all items in the list that are not clips
5554 for (int i = 0; i < clips.count();) {
5555 if (clips.at(i)->type() != AVWIDGET) clips.removeAt(i);
5558 if (clips.count() == 1 && allowOutsideCursor) return static_cast < ClipItem *>(clips.at(0));
5559 for (int i = 0; i < clips.count(); ++i) {
5560 if (clips.at(i)->type() == AVWIDGET) {
5561 item = static_cast < ClipItem *>(clips.at(i));
5562 if (item->startPos().frames(m_document->fps()) <= m_cursorPos && item->endPos().frames(m_document->fps()) >= m_cursorPos)
5570 void CustomTrackView::setInPoint()
5572 AbstractClipItem *clip = getActiveClipUnderCursor(true);
5574 if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) {
5577 emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
5581 prepareResizeClipStart(clip, clip->info(), m_cursorPos, true);
5584 void CustomTrackView::setOutPoint()
5586 AbstractClipItem *clip = getActiveClipUnderCursor(true);
5588 if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) {
5591 emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
5595 prepareResizeClipEnd(clip, clip->info(), m_cursorPos, true);
5598 void CustomTrackView::slotUpdateAllThumbs()
5600 if (!isEnabled()) return;
5601 QList<QGraphicsItem *> itemList = items();
5602 //if (itemList.isEmpty()) return;
5604 const QString thumbBase = m_document->projectFolder().path() + "/thumbs/";
5605 for (int i = 0; i < itemList.count(); i++) {
5606 if (itemList.at(i)->type() == AVWIDGET) {
5607 item = static_cast <ClipItem *>(itemList.at(i));
5608 if (item && item->isEnabled() && item->clipType() != COLOR && item->clipType() != AUDIO) {
5609 // Check if we have a cached thumbnail
5610 if (item->clipType() == IMAGE || item->clipType() == TEXT) {
5611 QString thumb = thumbBase + item->baseClip()->getClipHash() + "_0.png";
5612 if (QFile::exists(thumb)) {
5614 if (pix.isNull()) KIO::NetAccess::del(KUrl(thumb), this);
5615 item->slotSetStartThumb(pix);
5618 QString startThumb = thumbBase + item->baseClip()->getClipHash() + '_';
5619 QString endThumb = startThumb;
5620 startThumb.append(QString::number(item->speedIndependantCropStart().frames(m_document->fps())) + ".png");
5621 endThumb.append(QString::number((item->speedIndependantCropStart() + item->speedIndependantCropDuration()).frames(m_document->fps()) - 1) + ".png");
5622 if (QFile::exists(startThumb)) {
5623 QPixmap pix(startThumb);
5624 if (pix.isNull()) KIO::NetAccess::del(KUrl(startThumb), this);
5625 item->slotSetStartThumb(pix);
5627 if (QFile::exists(endThumb)) {
5628 QPixmap pix(endThumb);
5629 if (pix.isNull()) KIO::NetAccess::del(KUrl(endThumb), this);
5630 item->slotSetEndThumb(pix);
5633 item->refreshClip(false, false);
5637 viewport()->update();
5640 void CustomTrackView::saveThumbnails()
5642 QList<QGraphicsItem *> itemList = items();
5644 QString thumbBase = m_document->projectFolder().path() + "/thumbs/";
5645 for (int i = 0; i < itemList.count(); i++) {
5646 if (itemList.at(i)->type() == AVWIDGET) {
5647 item = static_cast <ClipItem *>(itemList.at(i));
5648 if (item->clipType() != COLOR) {
5649 // Check if we have a cached thumbnail
5650 if (item->clipType() == IMAGE || item->clipType() == TEXT || item->clipType() == AUDIO) {
5651 QString thumb = thumbBase + item->baseClip()->getClipHash() + "_0.png";
5652 if (!QFile::exists(thumb)) {
5653 QPixmap pix(item->startThumb());
5657 QString startThumb = thumbBase + item->baseClip()->getClipHash() + '_';
5658 QString endThumb = startThumb;
5659 startThumb.append(QString::number(item->speedIndependantCropStart().frames(m_document->fps())) + ".png");
5660 endThumb.append(QString::number((item->speedIndependantCropStart() + item->speedIndependantCropDuration()).frames(m_document->fps()) - 1) + ".png");
5661 if (!QFile::exists(startThumb)) {
5662 QPixmap pix(item->startThumb());
5663 pix.save(startThumb);
5665 if (!QFile::exists(endThumb)) {
5666 QPixmap pix(item->endThumb());
5676 void CustomTrackView::slotInsertTrack(int ix)
5678 TrackDialog d(m_document, parentWidget());
5679 d.comboTracks->setCurrentIndex(ix);
5680 d.label->setText(i18n("Insert track"));
5681 d.setWindowTitle(i18n("Insert New Track"));
5683 if (d.exec() == QDialog::Accepted) {
5684 ix = d.comboTracks->currentIndex();
5685 if (d.before_select->currentIndex() == 1)
5689 info.isMute = false;
5690 info.isLocked = false;
5691 if (d.video_track->isChecked()) {
5692 info.type = VIDEOTRACK;
5693 info.isBlind = false;
5695 info.type = AUDIOTRACK;
5696 info.isBlind = true;
5698 AddTrackCommand *addTrack = new AddTrackCommand(this, ix, info, true);
5699 m_commandStack->push(addTrack);
5700 setDocumentModified();
5704 void CustomTrackView::slotDeleteTrack(int ix)
5706 if (m_document->tracksCount() < 2) return;
5707 TrackDialog d(m_document, parentWidget());
5708 d.comboTracks->setCurrentIndex(ix);
5709 d.label->setText(i18n("Delete track"));
5710 d.before_select->setHidden(true);
5711 d.setWindowTitle(i18n("Delete Track"));
5712 d.video_track->setHidden(true);
5713 d.audio_track->setHidden(true);
5714 if (d.exec() == QDialog::Accepted) {
5715 ix = d.comboTracks->currentIndex();
5716 TrackInfo info = m_document->trackInfoAt(m_document->tracksCount() - ix - 1);
5717 deleteTimelineTrack(ix, info);
5718 setDocumentModified();
5719 /*AddTrackCommand* command = new AddTrackCommand(this, ix, info, false);
5720 m_commandStack->push(command);*/
5724 void CustomTrackView::slotConfigTracks(int ix)
5726 TracksConfigDialog d(m_document, ix, parentWidget());
5727 if (d.exec() == QDialog::Accepted) {
5728 ConfigTracksCommand *configTracks = new ConfigTracksCommand(this, m_document->tracksList(), d.tracksList());
5729 m_commandStack->push(configTracks);
5730 QList <int> toDelete = d.deletedTracks();
5731 for (int i = 0; i < toDelete.count(); ++i) {
5732 TrackInfo info = m_document->trackInfoAt(m_document->tracksCount() - toDelete.at(i) + i - 1);
5733 deleteTimelineTrack(toDelete.at(i) - i, info);
5735 setDocumentModified();
5739 void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo)
5741 if (m_document->tracksCount() < 2) return;
5742 double startY = ix * m_tracksHeight + 1 + m_tracksHeight / 2;
5743 QRectF r(0, startY, sceneRect().width(), m_tracksHeight / 2 - 1);
5744 QList<QGraphicsItem *> selection = m_scene->items(r);
5745 QUndoCommand *deleteTrack = new QUndoCommand();
5746 deleteTrack->setText("Delete track");
5748 // Delete all clips in selected track
5749 for (int i = 0; i < selection.count(); i++) {
5750 if (selection.at(i)->type() == AVWIDGET) {
5751 ClipItem *item = static_cast <ClipItem *>(selection.at(i));
5752 new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, false, true, deleteTrack);
5753 m_waitingThumbs.removeAll(item);
5754 m_scene->removeItem(item);
5757 } else if (selection.at(i)->type() == TRANSITIONWIDGET) {
5758 Transition *item = static_cast <Transition *>(selection.at(i));
5759 new AddTransitionCommand(this, item->info(), item->transitionEndTrack(), item->toXML(), true, false, deleteTrack);
5760 m_scene->removeItem(item);
5766 new AddTrackCommand(this, ix, trackinfo, false, deleteTrack);
5767 m_commandStack->push(deleteTrack);
5770 void CustomTrackView::autoTransition()
5772 QList<QGraphicsItem *> itemList = scene()->selectedItems();
5773 if (itemList.count() != 1 || itemList.at(0)->type() != TRANSITIONWIDGET) {
5774 emit displayMessage(i18n("You must select one transition for this action"), ErrorMessage);
5777 Transition *tr = static_cast <Transition*>(itemList.at(0));
5778 tr->setAutomatic(!tr->isAutomatic());
5779 QDomElement transition = tr->toXML();
5780 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);
5781 setDocumentModified();
5785 QStringList CustomTrackView::getLadspaParams(QDomElement effect) const
5788 QDomNodeList params = effect.elementsByTagName("parameter");
5789 for (int i = 0; i < params.count(); i++) {
5790 QDomElement e = params.item(i).toElement();
5791 if (!e.isNull() && e.attribute("type") == "constant") {
5792 if (e.hasAttribute("factor")) {
5793 double factor = e.attribute("factor").toDouble();
5794 double value = e.attribute("value").toDouble();
5795 value = value / factor;
5796 result.append(QString::number(value));
5797 } else result.append(e.attribute("value"));
5803 void CustomTrackView::clipNameChanged(const QString id, const QString name)
5805 QList<QGraphicsItem *> list = scene()->items();
5806 ClipItem *clip = NULL;
5807 for (int i = 0; i < list.size(); ++i) {
5808 if (list.at(i)->type() == AVWIDGET) {
5809 clip = static_cast <ClipItem *>(list.at(i));
5810 if (clip->clipProducer() == id) {
5811 clip->setClipName(name);
5815 viewport()->update();
5818 void CustomTrackView::getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum)
5820 minimum = GenTime();
5821 maximum = GenTime();
5822 QList<QGraphicsItem *> selection;
5823 selection = m_scene->items(0, item->track() * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), 2);
5824 selection.removeAll(item);
5825 for (int i = 0; i < selection.count(); i++) {
5826 AbstractClipItem *clip = static_cast <AbstractClipItem *>(selection.at(i));
5827 if (clip && clip->type() == AVWIDGET) {
5828 if (clip->endPos() <= item->startPos() && clip->endPos() > minimum) minimum = clip->endPos();
5829 if (clip->startPos() > item->startPos() && (clip->startPos() < maximum || maximum == GenTime())) maximum = clip->startPos();
5834 void CustomTrackView::getTransitionAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum)
5836 minimum = GenTime();
5837 maximum = GenTime();
5838 QList<QGraphicsItem *> selection;
5839 selection = m_scene->items(0, (item->track() + 1) * m_tracksHeight, sceneRect().width(), 2);
5840 selection.removeAll(item);
5841 for (int i = 0; i < selection.count(); i++) {
5842 AbstractClipItem *clip = static_cast <AbstractClipItem *>(selection.at(i));
5843 if (clip && clip->type() == TRANSITIONWIDGET) {
5844 if (clip->endPos() <= item->startPos() && clip->endPos() > minimum) minimum = clip->endPos();
5845 if (clip->startPos() > item->startPos() && (clip->startPos() < maximum || maximum == GenTime())) maximum = clip->startPos();
5850 void CustomTrackView::loadGroups(const QDomNodeList groups)
5852 for (int i = 0; i < groups.count(); i++) {
5853 QDomNodeList children = groups.at(i).childNodes();
5854 scene()->clearSelection();
5855 for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
5856 QDomElement elem = children.item(nodeindex).toElement();
5857 int pos = elem.attribute("position").toInt();
5858 int track = elem.attribute("track").toInt();
5859 if (elem.tagName() == "clipitem") {
5860 ClipItem *clip = getClipItemAt(pos, track); //m_document->tracksCount() - transitiontrack);
5861 if (clip) clip->setSelected(true);
5863 Transition *clip = getTransitionItemAt(pos, track); //m_document->tracksCount() - transitiontrack);
5864 if (clip) clip->setSelected(true);
5867 groupSelectedItems(false, true);
5871 void CustomTrackView::splitAudio()
5873 resetSelectionGroup();
5874 QList<QGraphicsItem *> selection = scene()->selectedItems();
5875 if (selection.isEmpty()) {
5876 emit displayMessage(i18n("You must select at least one clip for this action"), ErrorMessage);
5879 QUndoCommand *splitCommand = new QUndoCommand();
5880 splitCommand->setText(i18n("Split audio"));
5881 for (int i = 0; i < selection.count(); i++) {
5882 if (selection.at(i)->type() == AVWIDGET) {
5883 ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
5884 if (clip->clipType() == AV || clip->clipType() == PLAYLIST) {
5885 if (clip->parentItem()) {
5886 emit displayMessage(i18n("Cannot split audio of grouped clips"), ErrorMessage);
5888 new SplitAudioCommand(this, clip->track(), clip->startPos(), splitCommand);
5893 if (splitCommand->childCount()) {
5894 updateTrackDuration(-1, splitCommand);
5895 m_commandStack->push(splitCommand);
5899 void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split)
5901 ClipItem *clip = getClipItemAt(pos, track);
5903 kDebug() << "// Cannot find clip to split!!!";
5907 int start = pos.frames(m_document->fps());
5908 int freetrack = m_document->tracksCount() - track - 1;
5910 // do not split audio when we are on an audio track
5911 if (m_document->trackInfoAt(freetrack).type == AUDIOTRACK)
5914 for (; freetrack > 0; freetrack--) {
5915 //kDebug() << "// CHK DOC TRK:" << freetrack << ", DUR:" << m_document->renderer()->mltTrackDuration(freetrack);
5916 if (m_document->trackInfoAt(freetrack - 1).type == AUDIOTRACK && !m_document->trackInfoAt(freetrack - 1).isLocked) {
5917 //kDebug() << "// CHK DOC TRK:" << freetrack << ", DUR:" << m_document->renderer()->mltTrackDuration(freetrack);
5918 if (m_document->renderer()->mltTrackDuration(freetrack) < start || m_document->renderer()->mltGetSpaceLength(pos, freetrack, false) >= clip->cropDuration().frames(m_document->fps())) {
5919 //kDebug() << "FOUND SPACE ON TRK: " << freetrack;
5924 kDebug() << "GOT TRK: " << track;
5925 if (freetrack == 0) {
5926 emit displayMessage(i18n("No empty space to put clip audio"), ErrorMessage);
5928 ItemInfo info = clip->info();
5929 info.track = m_document->tracksCount() - freetrack;
5930 addClip(clip->xml(), clip->clipProducer(), info, clip->effectList());
5931 scene()->clearSelection();
5932 clip->setSelected(true);
5933 ClipItem *audioClip = getClipItemAt(start, info.track);
5935 clip->setVideoOnly(true);
5936 if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == false) {
5937 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
5939 if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, start, clip->baseClip()->audioProducer(info.track)) == false) {
5940 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, info.track), ErrorMessage);
5942 audioClip->setSelected(true);
5943 audioClip->setAudioOnly(true);
5944 groupSelectedItems(false, true);
5948 // unsplit clip: remove audio part and change video part to normal clip
5949 if (clip->parentItem() == NULL || clip->parentItem()->type() != GROUPWIDGET) {
5950 kDebug() << "//CANNOT FIND CLP GRP";
5953 AbstractGroupItem *grp = static_cast <AbstractGroupItem *>(clip->parentItem());
5954 QList<QGraphicsItem *> children = grp->childItems();
5955 if (children.count() != 2) {
5956 kDebug() << "//SOMETHING IS WRONG WITH CLP GRP";
5959 for (int i = 0; i < children.count(); i++) {
5960 if (children.at(i) != clip) {
5961 ClipItem *clp = static_cast <ClipItem *>(children.at(i));
5962 ItemInfo info = clip->info();
5963 deleteClip(clp->info());
5964 clip->setVideoOnly(false);
5965 if (!m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, info.startPos.frames(m_document->fps()), clip->baseClip()->producer(info.track))) {
5966 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", info.startPos.frames(m_document->fps()), info.track), ErrorMessage);
5971 clip->setFlag(QGraphicsItem::ItemIsMovable, true);
5972 m_document->clipManager()->removeGroup(grp);
5973 scene()->destroyItemGroup(grp);
5977 void CustomTrackView::setVideoOnly()
5979 resetSelectionGroup();
5980 QList<QGraphicsItem *> selection = scene()->selectedItems();
5981 if (selection.isEmpty()) {
5982 emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
5985 QUndoCommand *videoCommand = new QUndoCommand();
5986 videoCommand->setText(i18n("Video only"));
5987 for (int i = 0; i < selection.count(); i++) {
5988 if (selection.at(i)->type() == AVWIDGET) {
5989 ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
5990 if (clip->clipType() == AV || clip->clipType() == PLAYLIST) {
5991 if (clip->parentItem()) {
5992 emit displayMessage(i18n("Cannot change grouped clips"), ErrorMessage);
5994 new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), true, false, clip->isVideoOnly(), clip->isAudioOnly(), videoCommand);
5999 m_commandStack->push(videoCommand);
6002 void CustomTrackView::setAudioOnly()
6004 resetSelectionGroup();
6005 QList<QGraphicsItem *> selection = scene()->selectedItems();
6006 if (selection.isEmpty()) {
6007 emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
6010 QUndoCommand *videoCommand = new QUndoCommand();
6011 videoCommand->setText(i18n("Audio only"));
6012 for (int i = 0; i < selection.count(); i++) {
6013 if (selection.at(i)->type() == AVWIDGET) {
6014 ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
6015 if (clip->clipType() == AV || clip->clipType() == PLAYLIST) {
6016 if (clip->parentItem()) {
6017 emit displayMessage(i18n("Cannot change grouped clips"), ErrorMessage);
6019 new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), false, true, clip->isVideoOnly(), clip->isAudioOnly(), videoCommand);
6024 m_commandStack->push(videoCommand);
6027 void CustomTrackView::setAudioAndVideo()
6029 resetSelectionGroup();
6030 QList<QGraphicsItem *> selection = scene()->selectedItems();
6031 if (selection.isEmpty()) {
6032 emit displayMessage(i18n("You must select one clip for this action"), ErrorMessage);
6035 QUndoCommand *videoCommand = new QUndoCommand();
6036 videoCommand->setText(i18n("Audio and Video"));
6037 for (int i = 0; i < selection.count(); i++) {
6038 if (selection.at(i)->type() == AVWIDGET) {
6039 ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
6040 if (clip->clipType() == AV || clip->clipType() == PLAYLIST) {
6041 if (clip->parentItem()) {
6042 emit displayMessage(i18n("Cannot change grouped clips"), ErrorMessage);
6044 new ChangeClipTypeCommand(this, clip->track(), clip->startPos(), false, false, clip->isVideoOnly(), clip->isAudioOnly(), videoCommand);
6049 m_commandStack->push(videoCommand);
6052 void CustomTrackView::doChangeClipType(const GenTime &pos, int track, bool videoOnly, bool audioOnly)
6054 ClipItem *clip = getClipItemAt(pos, track);
6056 kDebug() << "// Cannot find clip to split!!!";
6060 int start = pos.frames(m_document->fps());
6061 clip->setVideoOnly(true);
6062 clip->setAudioOnly(false);
6063 if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == false) {
6064 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
6066 } else if (audioOnly) {
6067 int start = pos.frames(m_document->fps());
6068 clip->setAudioOnly(true);
6069 clip->setVideoOnly(false);
6070 if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->audioProducer(track)) == false) {
6071 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
6074 int start = pos.frames(m_document->fps());
6075 clip->setAudioOnly(false);
6076 clip->setVideoOnly(false);
6077 if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->producer(track)) == false) {
6078 emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
6082 setDocumentModified();
6085 void CustomTrackView::updateClipTypeActions(ClipItem *clip)
6087 if (clip == NULL || (clip->clipType() != AV && clip->clipType() != PLAYLIST)) {
6088 m_clipTypeGroup->setEnabled(false);
6090 m_clipTypeGroup->setEnabled(true);
6091 QList <QAction *> actions = m_clipTypeGroup->actions();
6093 if (clip->isAudioOnly()) lookup = "clip_audio_only";
6094 else if (clip->isVideoOnly()) lookup = "clip_video_only";
6095 else lookup = "clip_audio_and_video";
6096 for (int i = 0; i < actions.count(); i++) {
6097 if (actions.at(i)->data().toString() == lookup) {
6098 actions.at(i)->setChecked(true);
6105 void CustomTrackView::slotGoToMarker(QAction *action)
6107 int pos = action->data().toInt();
6108 setCursorPos(pos, true);
6111 void CustomTrackView::reloadTransitionLumas()
6115 QDomElement lumaTransition = MainWindow::transitions.getEffectByTag("luma", "luma");
6116 QDomNodeList params = lumaTransition.elementsByTagName("parameter");
6117 for (int i = 0; i < params.count(); i++) {
6118 QDomElement e = params.item(i).toElement();
6119 if (e.attribute("tag") == "resource") {
6120 lumaNames = e.attribute("paramlistdisplay");
6121 lumaFiles = e.attribute("paramlist");
6126 QList<QGraphicsItem *> itemList = items();
6127 Transition *transitionitem;
6128 QDomElement transitionXml;
6129 for (int i = 0; i < itemList.count(); i++) {
6130 if (itemList.at(i)->type() == TRANSITIONWIDGET) {
6131 transitionitem = static_cast <Transition*>(itemList.at(i));
6132 transitionXml = transitionitem->toXML();
6133 if (transitionXml.attribute("id") == "luma" && transitionXml.attribute("tag") == "luma") {
6134 QDomNodeList params = transitionXml.elementsByTagName("parameter");
6135 for (int i = 0; i < params.count(); i++) {
6136 QDomElement e = params.item(i).toElement();
6137 if (e.attribute("tag") == "resource") {
6138 e.setAttribute("paramlistdisplay", lumaNames);
6139 e.setAttribute("paramlist", lumaFiles);
6144 if (transitionXml.attribute("id") == "composite" && transitionXml.attribute("tag") == "composite") {
6145 QDomNodeList params = transitionXml.elementsByTagName("parameter");
6146 for (int i = 0; i < params.count(); i++) {
6147 QDomElement e = params.item(i).toElement();
6148 if (e.attribute("tag") == "luma") {
6149 e.setAttribute("paramlistdisplay", lumaNames);
6150 e.setAttribute("paramlist", lumaFiles);
6157 emit transitionItemSelected(NULL);
6160 double CustomTrackView::fps() const
6162 return m_document->fps();
6165 void CustomTrackView::updateProjectFps()
6167 // update all clips to the new fps
6168 resetSelectionGroup();
6169 scene()->clearSelection();
6171 QList<QGraphicsItem *> itemList = items();
6172 for (int i = 0; i < itemList.count(); i++) {
6173 // remove all items and re-add them one by one
6174 if (itemList.at(i) != m_cursorLine && itemList.at(i)->parentItem() == NULL) m_scene->removeItem(itemList.at(i));
6176 for (int i = 0; i < itemList.count(); i++) {
6177 if (itemList.at(i)->parentItem() == 0 && (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET)) {
6178 AbstractClipItem *clip = static_cast <AbstractClipItem *>(itemList.at(i));
6179 clip->updateFps(m_document->fps());
6180 m_scene->addItem(clip);
6181 } else if (itemList.at(i)->type() == GROUPWIDGET) {
6182 AbstractGroupItem *grp = static_cast <AbstractGroupItem *>(itemList.at(i));
6183 QList<QGraphicsItem *> children = grp->childItems();
6184 for (int j = 0; j < children.count(); j++) {
6185 if (children.at(j)->type() == AVWIDGET || children.at(j)->type() == TRANSITIONWIDGET) {
6186 AbstractClipItem *clip = static_cast <AbstractClipItem *>(children.at(j));
6187 clip->setFlag(QGraphicsItem::ItemIsMovable, true);
6188 clip->updateFps(m_document->fps());
6191 m_document->clipManager()->removeGroup(grp);
6192 m_scene->addItem(grp);
6193 scene()->destroyItemGroup(grp);
6194 scene()->clearSelection();
6195 for (int j = 0; j < children.count(); j++) {
6196 if (children.at(j)->type() == AVWIDGET || children.at(j)->type() == TRANSITIONWIDGET) {
6197 //children.at(j)->setParentItem(0);
6198 children.at(j)->setSelected(true);
6201 groupSelectedItems(true, true);
6202 } else if (itemList.at(i)->type() == GUIDEITEM) {
6203 Guide *g = static_cast<Guide *>(itemList.at(i));
6205 m_scene->addItem(g);
6208 viewport()->update();
6211 void CustomTrackView::slotTrackDown()
6213 if (m_selectedTrack > m_document->tracksCount() - 2) m_selectedTrack = 0;
6214 else m_selectedTrack++;
6215 emit updateTrackHeaders();
6216 QRectF rect(mapToScene(QPoint(10, 0)).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight);
6217 ensureVisible(rect, 0, 0);
6218 viewport()->update();
6221 void CustomTrackView::slotTrackUp()
6223 if (m_selectedTrack > 0) m_selectedTrack--;
6224 else m_selectedTrack = m_document->tracksCount() - 1;
6225 emit updateTrackHeaders();
6226 QRectF rect(mapToScene(QPoint(10, 0)).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight);
6227 ensureVisible(rect, 0, 0);
6228 viewport()->update();
6231 int CustomTrackView::selectedTrack() const
6233 return m_selectedTrack;
6236 QStringList CustomTrackView::selectedClips() const
6238 QStringList clipIds;
6239 QList<QGraphicsItem *> selection = m_scene->selectedItems();
6240 for (int i = 0; i < selection.count(); i++) {
6241 if (selection.at(i)->type() == AVWIDGET) {
6242 ClipItem *item = (ClipItem *)selection.at(i);
6243 clipIds << item->clipProducer();
6249 QList<ClipItem *> CustomTrackView::selectedClipItems() const
6251 QList<ClipItem *> clips;
6252 QList<QGraphicsItem *> selection = m_scene->selectedItems();
6253 for (int i = 0; i < selection.count(); i++) {
6254 if (selection.at(i)->type() == AVWIDGET) {
6255 clips.append((ClipItem *)selection.at(i));
6261 void CustomTrackView::slotSelectTrack(int ix)
6263 m_selectedTrack = qMax(0, ix);
6264 m_selectedTrack = qMin(ix, m_document->tracksCount() - 1);
6265 emit updateTrackHeaders();
6266 QRectF rect(mapToScene(QPoint(10, 0)).x(), m_selectedTrack * m_tracksHeight, 10, m_tracksHeight);
6267 ensureVisible(rect, 0, 0);
6268 viewport()->update();
6271 void CustomTrackView::selectClip(bool add, bool group, int track, int pos)
6274 if (track != -1 && pos != -1)
6275 rect = QRectF(pos, track * m_tracksHeight + m_tracksHeight / 2, 1, 1);
6277 rect = QRectF(m_cursorPos, m_selectedTrack * m_tracksHeight + m_tracksHeight / 2, 1, 1);
6278 QList<QGraphicsItem *> selection = m_scene->items(rect);
6279 resetSelectionGroup(group);
6280 if (!group) m_scene->clearSelection();
6281 for (int i = 0; i < selection.count(); i++) {
6282 if (selection.at(i)->type() == AVWIDGET) {
6283 selection.at(i)->setSelected(add);
6287 if (group) groupSelectedItems();
6290 void CustomTrackView::selectTransition(bool add, bool group)
6292 QRectF rect(m_cursorPos, m_selectedTrack * m_tracksHeight + m_tracksHeight, 1, 1);
6293 QList<QGraphicsItem *> selection = m_scene->items(rect);
6294 resetSelectionGroup(group);
6295 if (!group) m_scene->clearSelection();
6296 for (int i = 0; i < selection.count(); i++) {
6297 if (selection.at(i)->type() == TRANSITIONWIDGET) {
6298 selection.at(i)->setSelected(add);
6302 if (group) groupSelectedItems();
6305 QStringList CustomTrackView::extractTransitionsLumas()
6308 QList<QGraphicsItem *> itemList = items();
6309 Transition *transitionitem;
6310 QDomElement transitionXml;
6311 for (int i = 0; i < itemList.count(); i++) {
6312 if (itemList.at(i)->type() == TRANSITIONWIDGET) {
6313 transitionitem = static_cast <Transition*>(itemList.at(i));
6314 transitionXml = transitionitem->toXML();
6315 QString luma = EffectsList::parameter(transitionXml, "luma");
6316 if (!luma.isEmpty()) urls << luma;
6322 void CustomTrackView::setEditMode(EDITMODE mode)
6324 m_scene->setEditMode(mode);
6327 void CustomTrackView::checkTrackSequence(int track)
6329 QList <int> times = m_document->renderer()->checkTrackSequence(m_document->tracksCount() - track);
6330 //track = m_document->tracksCount() -track;
6331 QRectF rect(0, track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), 2);
6332 QList<QGraphicsItem *> selection = m_scene->items(rect);
6333 QList <int> timelineList;
6334 timelineList.append(0);
6335 for (int i = 0; i < selection.count(); i++) {
6336 if (selection.at(i)->type() == AVWIDGET) {
6337 ClipItem *clip = static_cast <ClipItem *>(selection.at(i));
6338 int start = clip->startPos().frames(m_document->fps());
6339 int end = clip->endPos().frames(m_document->fps());
6340 if (!timelineList.contains(start)) timelineList.append(start);
6341 if (!timelineList.contains(end)) timelineList.append(end);
6344 qSort(timelineList);
6345 kDebug() << "// COMPARE:\n" << times << "\n" << timelineList << "\n-------------------";
6346 if (times != timelineList) KMessageBox::sorry(this, i18n("error"), i18n("TRACTOR"));
6349 void CustomTrackView::insertZoneOverwrite(QStringList data, int in)
6351 if (data.isEmpty()) return;
6352 DocClipBase *clip = m_document->getBaseClip(data.at(0));
6354 info.startPos = GenTime(in, m_document->fps());
6355 info.cropStart = GenTime(data.at(1).toInt(), m_document->fps());
6356 info.endPos = info.startPos + GenTime(data.at(2).toInt(), m_document->fps()) - info.cropStart;
6357 info.cropDuration = info.endPos - info.startPos;
6358 info.track = m_selectedTrack;
6359 QUndoCommand *addCommand = new QUndoCommand();
6360 addCommand->setText(i18n("Insert clip"));
6361 adjustTimelineClips(OVERWRITEEDIT, NULL, info, addCommand);
6362 new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), info, EffectsList(), true, false, true, false, addCommand);
6363 updateTrackDuration(info.track, addCommand);
6364 m_commandStack->push(addCommand);
6366 selectClip(true, false, m_selectedTrack, in);
6367 // Automatic audio split
6368 if (KdenliveSettings::splitaudio())
6372 void CustomTrackView::clearSelection()
6374 resetSelectionGroup();
6375 scene()->clearSelection();
6377 emit clipItemSelected(NULL);
6380 void CustomTrackView::updatePalette()
6382 m_activeTrackBrush = KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
6386 pen1.setColor(palette().text().color());
6387 m_cursorLine->setPen(pen1);
6389 emit tracksChanged();
6392 void CustomTrackView::removeTipAnimation()
6395 scene()->removeItem(m_visualTip);
6396 m_animationTimer->stop();
6404 void CustomTrackView::setTipAnimation(AbstractClipItem *clip, OPERATIONTYPE mode, const double size)
6406 if (m_visualTip == NULL) {
6407 QRectF rect = clip->sceneBoundingRect();
6408 m_animation = new QGraphicsItemAnimation;
6409 m_animation->setTimeLine(m_animationTimer);
6410 m_animation->setScaleAt(1, 1, 1);
6415 m_visualTip = new QGraphicsEllipseItem(-size, -size, size * 2, size * 2);
6416 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
6417 ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen);
6419 m_visualTip->setPos(rect.x() + ((ClipItem *) clip)->fadeIn(), rect.y());
6421 m_visualTip->setPos(rect.right() - ((ClipItem *) clip)->fadeOut(), rect.y());
6423 m_animation->setScaleAt(.5, 2, 2);
6427 polygon << QPoint(0, - size * 2);
6428 if (mode == RESIZESTART)
6429 polygon << QPoint(size * 2, 0);
6431 polygon << QPoint(- size * 2, 0);
6432 polygon << QPoint(0, size * 2);
6433 polygon << QPoint(0, - size * 2);
6435 m_visualTip = new QGraphicsPolygonItem(polygon);
6436 ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
6437 ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen);
6438 if (mode == RESIZESTART)
6439 m_visualTip->setPos(rect.x(), rect.y() + rect.height() / 2);
6441 m_visualTip->setPos(rect.right(), rect.y() + rect.height() / 2);
6443 m_animation->setScaleAt(.5, 2, 1);
6445 case TRANSITIONSTART:
6447 polygon << QPoint(0, - size * 2);
6448 if (mode == TRANSITIONSTART)
6449 polygon << QPoint(size * 2, 0);
6451 polygon << QPoint(- size * 2, 0);
6452 polygon << QPoint(0, 0);
6453 polygon << QPoint(0, - size * 2);
6455 m_visualTip = new QGraphicsPolygonItem(polygon);
6456 ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
6457 ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen);
6458 if (mode == TRANSITIONSTART)
6459 m_visualTip->setPos(rect.x(), rect.bottom());
6461 m_visualTip->setPos(rect.right(), rect.bottom());
6463 m_animation->setScaleAt(.5, 2, 2);
6470 m_visualTip->setFlags(QGraphicsItem::ItemIgnoresTransformations);
6471 m_visualTip->setZValue(100);
6472 scene()->addItem(m_visualTip);
6473 m_animation->setItem(m_visualTip);
6474 m_animationTimer->start();
6478 bool CustomTrackView::hasAudio(int track) const
6480 QRectF rect(0, (double)(track * m_tracksHeight + 1), (double) sceneRect().width(), (double)(m_tracksHeight - 1));
6481 QList<QGraphicsItem *> collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect);
6482 QGraphicsItem *item;
6483 for (int i = 0; i < collisions.count(); i++) {
6484 item = collisions.at(i);
6485 if (!item->isEnabled()) continue;
6486 if (item->type() == AVWIDGET) {
6487 ClipItem *clip = static_cast <ClipItem *>(item);
6488 if (!clip->isVideoOnly() && (clip->clipType() == AUDIO || clip->clipType() == AV || clip->clipType() == PLAYLIST)) return true;
6494 void CustomTrackView::slotAddTrackEffect(const QDomElement effect, int ix)
6496 AddEffectCommand *command = new AddEffectCommand(this, m_document->tracksCount() - ix, GenTime(-1), effect, true);
6497 m_commandStack->push(command);
6498 setDocumentModified();
6502 EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect)
6504 EffectsParameterList parameters;
6505 parameters.addParam("tag", effect.attribute("tag"));
6506 if (effect.hasAttribute("region")) parameters.addParam("region", effect.attribute("region"));
6507 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
6508 parameters.addParam("id", effect.attribute("id"));
6509 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
6510 if (effect.hasAttribute("disable")) parameters.addParam("disable", effect.attribute("disable"));
6511 if (effect.hasAttribute("in")) parameters.addParam("in", effect.attribute("in"));
6512 if (effect.hasAttribute("out")) parameters.addParam("out", effect.attribute("out"));
6514 QDomNodeList params = effect.elementsByTagName("parameter");
6515 for (int i = 0; i < params.count(); i++) {
6516 QDomElement e = params.item(i).toElement();
6517 //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
6518 if (e.attribute("type") == "simplekeyframe") {
6520 QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
6521 double factor = e.attribute("factor", "1").toDouble();
6522 for (int j = 0; j < values.count(); j++) {
6523 QString pos = values.at(j).section(':', 0, 0);
6524 double val = values.at(j).section(':', 1, 1).toDouble() / factor;
6525 values[j] = pos + "=" + QString::number(val);
6527 // kDebug() << "/ / / /SENDING KEYFR:" << values;
6528 parameters.addParam(e.attribute("name"), values.join(";"));
6529 /*parameters.addParam(e.attribute("name"), e.attribute("keyframes").replace(":", "="));
6530 parameters.addParam("max", e.attribute("max"));
6531 parameters.addParam("min", e.attribute("min"));
6532 parameters.addParam("factor", e.attribute("factor", "1"));*/
6533 } else if (e.attribute("type") == "keyframe") {
6534 kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
6535 parameters.addParam("keyframes", e.attribute("keyframes"));
6536 parameters.addParam("max", e.attribute("max"));
6537 parameters.addParam("min", e.attribute("min"));
6538 parameters.addParam("factor", e.attribute("factor", "1"));
6539 parameters.addParam("starttag", e.attribute("starttag", "start"));
6540 parameters.addParam("endtag", e.attribute("endtag", "end"));
6541 } else if (e.attribute("namedesc").contains(';')) {
6542 QString format = e.attribute("format");
6543 QStringList separators = format.split("%d", QString::SkipEmptyParts);
6544 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
6546 QTextStream txtNeu(&neu);
6547 if (values.size() > 0)
6548 txtNeu << (int)values[0].toDouble();
6549 for (int i = 0; i < separators.size() && i + 1 < values.size(); i++) {
6550 txtNeu << separators[i];
6551 txtNeu << (int)(values[i+1].toDouble());
6553 parameters.addParam("start", neu);
6555 if (e.attribute("factor", "1") != "1") {
6557 if (e.attribute("factor").startsWith('%')) {
6558 fact = ProfilesDialog::getStringEval(m_document->mltProfile(), e.attribute("factor"));
6559 } else fact = e.attribute("factor", "1").toDouble();
6560 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact));
6562 parameters.addParam(e.attribute("name"), e.attribute("value"));
6569 void CustomTrackView::updatePanZoom(ClipItem* item, GenTime cutPos)
6571 QList <int> effects = item->updatePanZoom(m_document->width(), m_document->height(), cutPos.frames(m_document->fps()));
6572 for (int i = 0; i < effects.count(); ++i) {
6573 if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(item->effectAt(effects.at(i)))))
6574 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
6576 // if effect is displayed, update the effect edit widget with new clip duration
6577 /*if (item->isSelected() && effects.at(i) == item->selectedEffectIndex())
6578 emit clipItemSelected(item, effects.at(i));*/
6580 // update always, otherwise there might problems when resizing groups
6581 if (effects.count() > 0)
6582 emit clipItemSelected(item, item->selectedEffectIndex());
6585 void CustomTrackView::updateTrackNames(int track, bool added)
6587 QList <TrackInfo> tracks = m_document->tracksList();
6588 int max = tracks.count();
6589 int docTrack = max - track - 1;
6591 // count number of tracks of each type
6592 int videoTracks = 0;
6593 int audioTracks = 0;
6594 for (int i = max - 1; i >= 0; --i) {
6595 TrackInfo info = tracks.at(i);
6596 if (info.type == VIDEOTRACK)
6601 if (i <= docTrack) {
6602 QString type = (info.type == VIDEOTRACK ? "Video " : "Audio ");
6603 int typeNumber = (info.type == VIDEOTRACK ? videoTracks : audioTracks);
6606 if (i == docTrack || info.trackName == type + QString::number(typeNumber - 1)) {
6607 info.trackName = type + QString::number(typeNumber);
6608 m_document->setTrackType(i, info);
6611 if (info.trackName == type + QString::number(typeNumber + 1)) {
6612 info.trackName = type + QString::number(typeNumber);
6613 m_document->setTrackType(i, info);
6618 emit tracksChanged();
6621 void CustomTrackView::updateTrackDuration(int track, QUndoCommand *command)
6627 tracks << m_document->tracksCount() - track - 1;
6629 // negative track number -> update all tracks
6630 for (int i = 0; i < m_document->tracksCount(); ++i)
6634 for (int i = 0; i < tracks.count(); ++i) {
6636 // t + 1 because of black background track
6637 duration = m_document->renderer()->mltTrackDuration(t + 1);
6638 if (duration != m_document->trackDuration(t)) {
6639 m_document->setTrackDuration(t, duration);
6642 EffectsList effects = m_document->getTrackEffects(t);
6643 for (int j = 0; j < effects.count(); ++j) {
6645 * - lookout for keyframable parameters and update them so all keyframes are in the new range (0 - duration)
6646 * - update the effectstack if necessary
6653 void CustomTrackView::slotRefreshThumbs(const QString &id, bool resetThumbs)
6655 QList<QGraphicsItem *> list = scene()->items();
6656 ClipItem *clip = NULL;
6657 for (int i = 0; i < list.size(); ++i) {
6658 if (list.at(i)->type() == AVWIDGET) {
6659 clip = static_cast <ClipItem *>(list.at(i));
6660 if (clip->clipProducer() == id) {
6661 clip->refreshClip(true, resetThumbs);