1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include <QMouseEvent>
21 #include <QStylePainter>
22 #include <QGraphicsItem>
23 #include <QDomDocument>
25 #include <QApplication>
26 #include <QInputDialog>
34 #include "customtrackview.h"
35 #include "docclipbase.h"
37 #include "definitions.h"
38 #include "moveclipcommand.h"
39 #include "movetransitioncommand.h"
40 #include "resizeclipcommand.h"
41 #include "editguidecommand.h"
42 #include "addtimelineclipcommand.h"
43 #include "addeffectcommand.h"
44 #include "editeffectcommand.h"
45 #include "moveeffectcommand.h"
46 #include "addtransitioncommand.h"
47 #include "edittransitioncommand.h"
48 #include "editkeyframecommand.h"
49 #include "addmarkercommand.h"
50 #include "razorclipcommand.h"
51 #include "kdenlivesettings.h"
52 #include "transition.h"
54 #include "customtrackview.h"
55 #include "clipmanager.h"
57 #include "markerdialog.h"
58 #include "mainwindow.h"
59 #include "ui_keyframedialog_ui.h"
63 // disable animation if user asked it in KDE's global settings
64 // http://lists.kde.org/?l=kde-commits&m=120398724717624&w=2
65 // needs something like below (taken from dolphin)
66 // #include <kglobalsettings.h>
67 // const bool animate = KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects;
68 // const int duration = animate ? 1500 : 1;
70 CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent)
71 : QGraphicsView(projectscene, parent), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(QPoint()), m_document(doc), m_autoScroll(KdenliveSettings::autoscroll()), m_tracksHeight(KdenliveSettings::trackheight()), m_tool(SELECTTOOL), m_dragGuide(NULL) {
72 if (doc) m_commandStack = doc->commandStack();
73 else m_commandStack == NULL;
74 setMouseTracking(true);
76 m_animationTimer = new QTimeLine(800);
77 m_animationTimer->setFrameRange(0, 5);
78 m_animationTimer->setUpdateInterval(100);
79 m_animationTimer->setLoopCount(0);
80 m_tipColor = QColor(0, 192, 0, 200);
81 QColor border = QColor(255, 255, 255, 100);
82 m_tipPen.setColor(border);
84 setContentsMargins(0, 0, 0, 0);
86 m_cursorLine = projectscene->addLine(0, 0, 0, m_tracksHeight);
87 m_cursorLine->setFlags(QGraphicsItem::ItemIsMovable);
88 m_cursorLine->setZValue(1000);
91 KIcon razorIcon("edit-cut");
92 m_razorCursor = QCursor(razorIcon.pixmap(22, 22));
95 CustomTrackView::~CustomTrackView() {
100 void CustomTrackView::setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition) {
101 m_timelineContextMenu = timeline;
102 m_timelineContextClipMenu = clip;
103 m_timelineContextTransitionMenu = transition;
106 void CustomTrackView::checkAutoScroll() {
107 m_autoScroll = KdenliveSettings::autoscroll();
110 QList <TrackInfo> CustomTrackView::tracksList() const {
114 void CustomTrackView::checkTrackHeight() {
115 if (m_tracksHeight == KdenliveSettings::trackheight()) return;
116 m_tracksHeight = KdenliveSettings::trackheight();
117 emit trackHeightChanged();
118 QList<QGraphicsItem *> itemList = items();
120 Transition *transitionitem;
121 for (int i = 0; i < itemList.count(); i++) {
122 if (itemList.at(i)->type() == AVWIDGET) {
123 item = (ClipItem*) itemList.at(i);
124 item->setRect(item->rect().x(), item->track() * m_tracksHeight, item->rect().width(), m_tracksHeight - 1);
126 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
127 transitionitem = (Transition*) itemList.at(i);
128 transitionitem->setRect(transitionitem->rect().x(), transitionitem->track() * m_tracksHeight + m_tracksHeight / 2, transitionitem->rect().width(), m_tracksHeight - 1);
131 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_tracksList.count());
133 for (int i = 0; i < m_guides.count(); i++) {
134 QLineF l = m_guides.at(i)->line();
135 l.setP2(QPointF(l.x2(), m_tracksHeight * m_tracksList.count()));
136 m_guides.at(i)->setLine(l);
139 setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_tracksList.count());
140 verticalScrollBar()->setMaximum(m_tracksHeight * m_tracksList.count());
145 void CustomTrackView::resizeEvent(QResizeEvent * event) {
146 QGraphicsView::resizeEvent(event);
150 void CustomTrackView::wheelEvent(QWheelEvent * e) {
151 if (e->modifiers() == Qt::ControlModifier) {
152 if (e->delta() > 0) emit zoomIn();
155 if (e->delta() > 0) horizontalScrollBar()->setValue(horizontalScrollBar()->value() + horizontalScrollBar()->singleStep());
156 else horizontalScrollBar()->setValue(horizontalScrollBar()->value() - horizontalScrollBar()->singleStep());
160 int CustomTrackView::getPreviousVideoTrack(int track) {
161 track = m_tracksList.count() - track - 1;
163 for (int i = track; i > -1; i--) {
164 if (m_tracksList.at(i).type == VIDEOTRACK) return i + 1;
171 void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
172 int pos = event->x();
173 emit mousePosition((int)(mapToScene(event->pos()).x() / m_scale));
174 if (event->buttons() & Qt::MidButton) return;
175 if (event->buttons() != Qt::NoButton) {
176 if (m_dragItem && m_tool == SELECTTOOL) { //event->button() == Qt::LeftButton) {
177 // a button was pressed, delete visual tips
178 if (m_operationMode == MOVE && (event->pos() - m_clickEvent).manhattanLength() >= QApplication::startDragDistance()) {
179 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint.x());
180 //kDebug() << "/////// MOVE CLIP, EVENT Y: "<<m_clickPoint.y();//<<event->scenePos().y()<<", SCENE HEIGHT: "<<scene()->sceneRect().height();
181 int moveTrack = (int) mapToScene(event->pos() + QPoint(0, (m_dragItem->type() == TRANSITIONWIDGET ? - m_clickPoint.y() : 0))).y() / m_tracksHeight;
182 int currentTrack = m_dragItem->track();
184 if (moveTrack > 1000)moveTrack = 0;
185 else if (moveTrack > m_tracksList.count() - 1) moveTrack = m_tracksList.count() - 1;
186 else if (moveTrack < 0) moveTrack = 0;
188 int offset = moveTrack - currentTrack;
189 if (offset != 0) offset = m_tracksHeight * offset;
190 m_dragItem->moveTo((int)(snappedPos / m_scale), m_scale, offset, moveTrack);
191 } else if (m_operationMode == RESIZESTART) {
192 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x());
193 m_dragItem->resizeStart((int)(snappedPos / m_scale), m_scale);
194 } else if (m_operationMode == RESIZEEND) {
195 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x());
196 m_dragItem->resizeEnd((int)(snappedPos / m_scale), m_scale);
197 } else if (m_operationMode == FADEIN) {
198 int pos = (int)(mapToScene(event->pos()).x() / m_scale);
199 ((ClipItem*) m_dragItem)->setFadeIn((int)(pos - m_dragItem->startPos().frames(m_document->fps())), m_scale);
200 } else if (m_operationMode == FADEOUT) {
201 int pos = (int)(mapToScene(event->pos()).x() / m_scale);
202 ((ClipItem*) m_dragItem)->setFadeOut((int)(m_dragItem->endPos().frames(m_document->fps()) - pos), m_scale);
203 } else if (m_operationMode == KEYFRAME) {
204 GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x() / m_scale), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart();
205 double pos = mapToScene(event->pos()).toPoint().y();
206 QRectF br = m_dragItem->rect();
207 double maxh = 100.0 / br.height();
208 pos = (br.bottom() - pos) * maxh;
209 m_dragItem->updateKeyFramePos(keyFramePos, pos);
212 if (m_animation) delete m_animation;
214 if (m_visualTip) delete m_visualTip;
216 QGraphicsView::mouseMoveEvent(event);
218 } else if (m_operationMode == MOVEGUIDE) {
219 if (m_animation) delete m_animation;
221 if (m_visualTip) delete m_visualTip;
223 QGraphicsView::mouseMoveEvent(event);
228 if (m_tool == RAZORTOOL) {
229 setCursor(m_razorCursor);
230 //QGraphicsView::mouseMoveEvent(event);
234 QList<QGraphicsItem *> itemList = items(event->pos());
235 QGraphicsRectItem *item = NULL;
236 OPERATIONTYPE opMode = NONE;
238 if (itemList.count() == 1 && itemList.at(0)->type() == GUIDEITEM) {
240 } else for (int i = 0; i < itemList.count(); i++) {
241 if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
242 item = (QGraphicsRectItem*) itemList.at(i);
247 if (item && event->buttons() == Qt::NoButton) {
248 AbstractClipItem *clip = (AbstractClipItem*) item;
249 if (m_tool == RAZORTOOL) {
250 // razor tool over a clip, display current frame in monitor
251 if (item->type() == AVWIDGET) {
252 emit showClipFrame(((ClipItem *) item)->baseClip(), mapToScene(event->pos()).x() / m_scale - (clip->startPos() - clip->cropStart()).frames(m_document->fps()));
254 QGraphicsView::mouseMoveEvent(event);
257 opMode = clip->operationMode(mapToScene(event->pos()), m_scale);
259 if (opMode == m_moveOpMode) {
260 QGraphicsView::mouseMoveEvent(event);
264 if (m_animation) delete m_animation;
266 m_animationTimer->stop();
271 m_moveOpMode = opMode;
272 if (opMode == MOVE) {
273 setCursor(Qt::OpenHandCursor);
274 } else if (opMode == RESIZESTART) {
275 setCursor(KCursor("left_side", Qt::SizeHorCursor));
276 if (m_visualTip == NULL) {
278 polygon << QPoint((int)clip->rect().x(), (int)(clip->rect().y() + clip->rect().height() / 2 - size * 2));
279 polygon << QPoint((int)(clip->rect().x() + size * 2), (int)(clip->rect().y() + clip->rect().height() / 2));
280 polygon << QPoint((int)clip->rect().x(), (int)(clip->rect().y() + clip->rect().height() / 2 + size * 2));
281 polygon << QPoint((int)clip->rect().x(), (int)(clip->rect().y() + clip->rect().height() / 2 - size * 2));
283 m_visualTip = new QGraphicsPolygonItem(polygon);
284 ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
285 ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen);
286 m_visualTip->setZValue(100);
287 m_animation = new QGraphicsItemAnimation;
288 m_animation->setItem(m_visualTip);
289 m_animation->setTimeLine(m_animationTimer);
290 m_visualTip->setPos(0, 0);
292 m_animation->setScaleAt(.5, scale, 1);
293 m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
295 m_animation->setScaleAt(1, scale, 1);
296 m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
297 scene()->addItem(m_visualTip);
298 m_animationTimer->start();
300 } else if (opMode == RESIZEEND) {
301 setCursor(KCursor("right_side", Qt::SizeHorCursor));
302 if (m_visualTip == NULL) {
304 polygon << QPoint((int)(clip->rect().x() + clip->rect().width()), (int)(clip->rect().y() + clip->rect().height() / 2 - size * 2));
305 polygon << QPoint((int)(clip->rect().x() + clip->rect().width() - size * 2), (int)(clip->rect().y() + clip->rect().height() / 2));
306 polygon << QPoint((int)(clip->rect().x() + clip->rect().width()), (int)(clip->rect().y() + clip->rect().height() / 2 + size * 2));
307 polygon << QPoint((int)(clip->rect().x() + clip->rect().width()), (int)(clip->rect().y() + clip->rect().height() / 2 - size * 2));
309 m_visualTip = new QGraphicsPolygonItem(polygon);
310 ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
311 ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen);
313 m_visualTip->setZValue(100);
314 m_animation = new QGraphicsItemAnimation;
315 m_animation->setItem(m_visualTip);
316 m_animation->setTimeLine(m_animationTimer);
317 m_visualTip->setPos(0, 0);
319 m_animation->setScaleAt(.5, scale, 1);
320 m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->rect().width(), 0));
322 m_animation->setScaleAt(1, scale, 1);
323 m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
324 scene()->addItem(m_visualTip);
325 m_animationTimer->start();
327 } else if (opMode == FADEIN) {
328 if (m_visualTip == NULL) {
329 ClipItem *item = (ClipItem *) clip;
330 m_visualTip = new QGraphicsEllipseItem(item->rect().x() + item->fadeIn() * m_scale - size, item->rect().y() - 8, size * 2, 16);
331 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
332 ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen);
333 m_visualTip->setZValue(100);
334 m_animation = new QGraphicsItemAnimation;
335 m_animation->setItem(m_visualTip);
336 m_animation->setTimeLine(m_animationTimer);
337 m_visualTip->setPos(0, 0);
339 m_animation->setScaleAt(.5, scale, scale);
340 m_animation->setPosAt(.5, QPointF(item->rect().x() - item->rect().x() * scale - item->fadeIn() * m_scale, item->rect().y() - item->rect().y() * scale));
342 m_animation->setScaleAt(1, scale, scale);
343 m_animation->setPosAt(1, QPointF(item->rect().x() - item->rect().x() * scale, item->rect().y() - item->rect().y() * scale));
344 scene()->addItem(m_visualTip);
345 m_animationTimer->start();
347 setCursor(Qt::PointingHandCursor);
348 } else if (opMode == FADEOUT) {
349 if (m_visualTip == NULL) {
350 ClipItem *item = (ClipItem *) clip;
351 m_visualTip = new QGraphicsEllipseItem(item->rect().x() + item->rect().width() - item->fadeOut() * m_scale - size, item->rect().y() - 8, size*2, 16);
352 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
353 ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen);
354 m_visualTip->setZValue(100);
355 m_animation = new QGraphicsItemAnimation;
356 m_animation->setItem(m_visualTip);
357 m_animation->setTimeLine(m_animationTimer);
358 m_visualTip->setPos(0, 0);
360 m_animation->setScaleAt(.5, scale, scale);
361 m_animation->setPosAt(.5, QPointF(item->rect().x() - item->rect().x() * scale - item->rect().width() + item->fadeOut() * m_scale, item->rect().y() - item->rect().y() * scale));
363 m_animation->setScaleAt(1, scale, scale);
364 m_animation->setPosAt(1, QPointF(item->rect().x() - item->rect().x() * scale, item->rect().y() - item->rect().y() * scale));
365 scene()->addItem(m_visualTip);
366 m_animationTimer->start();
368 setCursor(Qt::PointingHandCursor);
369 } else if (opMode == TRANSITIONSTART) {
370 if (m_visualTip == NULL) {
371 m_visualTip = new QGraphicsEllipseItem(-5, -5 , 10, 10);
372 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
373 ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen);
374 m_visualTip->setZValue(100);
375 m_animation = new QGraphicsItemAnimation;
376 m_animation->setItem(m_visualTip);
377 m_animation->setTimeLine(m_animationTimer);
378 m_visualTip->setPos(clip->rect().x() + 10, clip->rect().y() + clip->rect().height() / 2 + 12);
380 m_animation->setScaleAt(.5, scale, scale);
382 m_animation->setScaleAt(1, scale, scale);
383 scene()->addItem(m_visualTip);
384 m_animationTimer->start();
386 setCursor(Qt::PointingHandCursor);
387 } else if (opMode == TRANSITIONEND) {
388 if (m_visualTip == NULL) {
389 m_visualTip = new QGraphicsEllipseItem(-5, -5 , 10, 10);
390 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
391 ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen);
392 m_visualTip->setZValue(100);
393 m_animation = new QGraphicsItemAnimation;
394 m_animation->setItem(m_visualTip);
395 m_animation->setTimeLine(m_animationTimer);
396 m_visualTip->setPos(clip->rect().x() + clip->rect().width() - 10 , clip->rect().y() + clip->rect().height() / 2 + 12);
398 m_animation->setScaleAt(.5, scale, scale);
400 m_animation->setScaleAt(1, scale, scale);
401 scene()->addItem(m_visualTip);
402 m_animationTimer->start();
404 setCursor(Qt::PointingHandCursor);
405 } else if (opMode == KEYFRAME) {
406 setCursor(Qt::PointingHandCursor);
408 } // no clip under mouse
409 else if (m_tool == RAZORTOOL) {
410 QGraphicsView::mouseMoveEvent(event);
413 else if (opMode == MOVEGUIDE) {
414 m_moveOpMode = opMode;
415 setCursor(Qt::SplitHCursor);
418 if (event->buttons() != Qt::NoButton && event->modifiers() == Qt::NoModifier) {
419 setCursorPos((int)(mapToScene(event->pos().x(), 0).x() / m_scale));
422 if (m_animation) delete m_animation;
423 m_animationTimer->stop();
429 setCursor(Qt::ArrowCursor);
431 QGraphicsView::mouseMoveEvent(event);
435 void CustomTrackView::mousePressEvent(QMouseEvent * event) {
437 m_clickEvent = event->pos();
438 if (event->button() == Qt::MidButton) {
439 m_document->renderer()->switchPlay();
442 if (event->modifiers() == Qt::ControlModifier) {
443 setDragMode(QGraphicsView::ScrollHandDrag);
444 QGraphicsView::mousePressEvent(event);
446 } else if (event->modifiers() == Qt::ShiftModifier) {
447 setDragMode(QGraphicsView::RubberBandDrag);
448 QGraphicsView::mousePressEvent(event);
451 bool collision = false;
452 QList<QGraphicsItem *> collisionList = items(event->pos());
453 if (collisionList.count() == 1 && collisionList.at(0)->type() == GUIDEITEM) {
454 // a guide item was pressed
455 collisionList.at(0)->setFlag(QGraphicsItem::ItemIsMovable, true);
457 m_dragGuide = (Guide *) collisionList.at(0);
459 m_operationMode = MOVEGUIDE;
460 // deselect all clips so that only the guide will move
461 QList<QGraphicsItem *> clips = scene()->selectedItems();
462 for (int i = 0; i < clips.count(); ++i)
463 clips.at(i)->setSelected(false);
464 updateSnapPoints(NULL);
465 QGraphicsView::mousePressEvent(event);
466 } else for (int i = 0; i < collisionList.count(); ++i) {
467 QGraphicsItem *item = collisionList.at(i);
468 if (item->type() == AVWIDGET || item->type() == TRANSITIONWIDGET) {
469 if (m_tool == RAZORTOOL) {
470 if (item->type() == TRANSITIONWIDGET) {
471 emit displayMessage(i18n("Cannot cut a transition"), ErrorMessage);
474 AbstractClipItem *clip = (AbstractClipItem *) item;
476 info.startPos = clip->startPos();
477 info.endPos = clip->endPos();
478 info.track = clip->track();
479 RazorClipCommand* command = new RazorClipCommand(this, info, GenTime((int)(mapToScene(event->pos()).x() / m_scale), m_document->fps()), true);
480 m_commandStack->push(command);
481 m_document->setModified(true);
485 if (!item->isSelected()) {
486 QList<QGraphicsItem *> itemList = items();
487 for (int i = 0; i < itemList.count(); i++) {
488 itemList.at(i)->setSelected(false);
489 itemList.at(i)->update();
491 item->setSelected(true);
495 m_dragItem = (AbstractClipItem *) item;
497 m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps()) * m_scale), (int)(event->pos().y() - m_dragItem->rect().top()));
498 m_dragItemInfo.startPos = m_dragItem->startPos();
499 m_dragItemInfo.endPos = m_dragItem->endPos();
500 m_dragItemInfo.track = m_dragItem->track();
502 m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale);
503 if (m_operationMode == KEYFRAME) {
504 m_dragItem->updateSelectedKeyFrame();
506 } else if (m_operationMode == MOVE) setCursor(Qt::ClosedHandCursor);
507 else if (m_operationMode == TRANSITIONSTART) {
509 info.startPos = m_dragItem->startPos();
510 info.track = m_dragItem->track();
511 int transitiontrack = getPreviousVideoTrack(info.track);
512 ClipItem *transitionClip = NULL;
513 if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.startPos.frames(m_document->fps()), m_tracksList.count() - transitiontrack);
514 if (transitionClip && transitionClip->endPos() < m_dragItem->endPos()) {
515 info.endPos = transitionClip->endPos();
516 } else info.endPos = info.startPos + GenTime(2.5);
518 slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
519 } else if (m_operationMode == TRANSITIONEND) {
521 info.endPos = m_dragItem->endPos();
522 info.track = m_dragItem->track();
523 int transitiontrack = getPreviousVideoTrack(info.track);
524 ClipItem *transitionClip = NULL;
525 if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.endPos.frames(m_document->fps()), m_tracksList.count() - transitiontrack);
526 if (transitionClip && transitionClip->startPos() > m_dragItem->startPos()) {
527 info.startPos = transitionClip->startPos();
528 } else info.startPos = info.endPos - GenTime(2.5);
529 slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
531 updateSnapPoints(m_dragItem);
537 kDebug() << "//////// NO ITEM FOUND ON CLICK";
539 setCursor(Qt::ArrowCursor);
540 QList<QGraphicsItem *> itemList = items();
541 for (int i = 0; i < itemList.count(); i++)
542 itemList.at(i)->setSelected(false);
543 //emit clipItemSelected(NULL);
544 if (event->button() == Qt::RightButton) {
545 displayContextMenu(event->globalPos());
546 } else setCursorPos((int)(mapToScene(event->x(), 0).x() / m_scale));
547 } else if (event->button() == Qt::RightButton) {
548 m_operationMode = NONE;
549 displayContextMenu(event->globalPos(), m_dragItem);
552 if (m_dragItem && m_dragItem->type() == AVWIDGET) emit clipItemSelected((ClipItem*) m_dragItem);
553 else emit clipItemSelected(NULL);
556 //QGraphicsView::mousePressEvent(event);
559 void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) {
560 if (m_dragItem && m_dragItem->hasKeyFrames()) {
561 if (m_moveOpMode == KEYFRAME) {
562 // user double clicked on a keyframe, open edit dialog
563 QDialog d(parentWidget());
564 Ui::KeyFrameDialog_UI view;
566 view.kfr_position->setText(m_document->timecode().getTimecode(GenTime(m_dragItem->selectedKeyFramePos(), m_document->fps()) - m_dragItem->cropStart(), m_document->fps()));
567 view.kfr_value->setValue(m_dragItem->selectedKeyFrameValue());
568 view.kfr_value->setFocus();
569 if (d.exec() == QDialog::Accepted) {
570 int pos = m_document->timecode().getFrameCount(view.kfr_position->text(), m_document->fps());
571 m_dragItem->updateKeyFramePos(GenTime(pos, m_document->fps()) + m_dragItem->cropStart(), (double) view.kfr_value->value() * m_dragItem->keyFrameFactor());
572 ClipItem *item = (ClipItem *)m_dragItem;
573 QString previous = item->keyframes(item->selectedEffectIndex());
574 item->updateKeyframeEffect();
575 QString next = item->keyframes(item->selectedEffectIndex());
576 EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
577 m_commandStack->push(command);
578 updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect());
583 GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x() / m_scale), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart();
584 m_dragItem->addKeyFrame(keyFramePos, mapToScene(event->pos()).toPoint().y());
585 ClipItem * item = (ClipItem *) m_dragItem;
586 QString previous = item->keyframes(item->selectedEffectIndex());
587 item->updateKeyframeEffect();
588 QString next = item->keyframes(item->selectedEffectIndex());
589 EditKeyFrameCommand *command = new EditKeyFrameCommand(this, m_dragItem->track(), m_dragItem->startPos(), item->selectedEffectIndex(), previous, next, false);
590 m_commandStack->push(command);
591 updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect());
597 void CustomTrackView::editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes) {
598 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), track);
600 clip->setKeyframes(index, keyframes);
601 updateEffect(m_tracksList.count() - clip->track(), clip->startPos(), clip->effectAt(index));
603 else emit displayMessage(i18n("Cannot find clip with keyframe"), ErrorMessage);
607 void CustomTrackView::displayContextMenu(QPoint pos, AbstractClipItem *clip) {
608 if (clip == NULL) m_timelineContextMenu->popup(pos);
609 else if (clip->type() == AVWIDGET) m_timelineContextClipMenu->popup(pos);
610 else if (clip->type() == TRANSITIONWIDGET) m_timelineContextTransitionMenu->popup(pos);
613 void CustomTrackView::activateMonitor() {
614 emit activateDocumentMonitor();
617 void CustomTrackView::dragEnterEvent(QDragEnterEvent * event) {
618 if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
619 kDebug() << "/////////////// DRAG ENTERED, TEXT: " << event->mimeData()->data("kdenlive/producerslist");
620 QStringList ids = QString(event->mimeData()->data("kdenlive/producerslist")).split(";");
621 //TODO: drop of several clips
622 for (int i = 0; i < ids.size(); ++i) {
624 DocClipBase *clip = m_document->getBaseClip(ids.at(0).toInt());
625 if (clip == NULL) kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << ids.at(0).toInt();
626 addItem(clip, event->pos());
627 event->acceptProposedAction();
628 } else QGraphicsView::dragEnterEvent(event);
631 void CustomTrackView::slotRefreshEffects(ClipItem *clip) {
632 int track = m_tracksList.count() - clip->track();
633 GenTime pos = clip->startPos();
634 m_document->renderer()->mltRemoveEffect(track, pos, "-1", false);
635 for (int i = 0; i < clip->effectsCount(); i++) {
636 m_document->renderer()->mltAddEffect(track, pos, clip->getEffectArgs(clip->effectAt(i)), false);
638 m_document->renderer()->doRefresh();
641 void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) {
642 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
644 QMap <QString, QString> effectParams = clip->addEffect(effect);
645 m_document->renderer()->mltAddEffect(track, pos, effectParams);
646 emit clipItemSelected(clip);
650 void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) {
651 QString index = effect.attribute("kdenlive_ix");
652 m_document->renderer()->mltRemoveEffect(track, pos, index);
653 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
655 clip->deleteEffect(index);
656 emit clipItemSelected(clip);
660 void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) {
661 QList<QGraphicsItem *> itemList;
662 if (track == -1) itemList = scene()->selectedItems();
663 if (itemList.isEmpty()) {
664 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, track);
665 if (clip) itemList.append(clip);
666 else emit displayMessage(i18n("Select a clip if you want to apply an effect"), ErrorMessage);
668 kDebug() << "// REQUESTING EFFECT ON CLIP: " << pos.frames(25) << ", TRK: " << track << "SELECTED ITEMS: " << itemList.count();
669 for (int i = 0; i < itemList.count(); i++) {
670 if (itemList.at(i)->type() == AVWIDGET) {
671 ClipItem *item = (ClipItem *)itemList.at(i);
672 item->initEffect(effect);
673 AddEffectCommand *command = new AddEffectCommand(this, m_tracksList.count() - item->track(), item->startPos(), effect, true);
674 m_commandStack->push(command);
677 m_document->setModified(true);
680 void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect) {
681 AddEffectCommand *command = new AddEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), effect, false);
682 m_commandStack->push(command);
683 m_document->setModified(true);
686 void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect) {
687 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
689 QMap <QString, QString> effectParams = clip->getEffectArgs(effect);
690 if (effectParams.value("disabled") == "1") {
691 QString index = effectParams.value("kdenlive_ix");
692 m_document->renderer()->mltRemoveEffect(track, pos, index);
693 } else m_document->renderer()->mltEditEffect(m_tracksList.count() - clip->track(), clip->startPos(), effectParams);
695 m_document->setModified(true);
698 void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos) {
699 ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
701 m_document->renderer()->mltMoveEffect(track, pos, oldPos, newPos);
703 m_document->setModified(true);
706 void CustomTrackView::slotChangeEffectState(ClipItem *clip, QDomElement effect, bool disable) {
707 QDomElement oldEffect = effect.cloneNode().toElement();
708 effect.setAttribute("disabled", disable);
709 EditEffectCommand *command = new EditEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), oldEffect, effect, true);
710 m_commandStack->push(command);
711 m_document->setModified(true);
714 void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos) {
715 MoveEffectCommand *command = new MoveEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), currentPos, newPos, true);
716 m_commandStack->push(command);
717 m_document->setModified(true);
720 void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect) {
721 EditEffectCommand *command = new EditEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), oldeffect, effect, true);
722 m_commandStack->push(command);
725 void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) {
728 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
729 int cutPos = (int) cutTime.frames(m_document->fps());
731 newPos.startPos = cutTime;
732 newPos.endPos = info.endPos;
733 newPos.track = info.track;
734 ClipItem *dup = new ClipItem(item->baseClip(), newPos, item->cropStart(), m_scale, m_document->fps());
735 dup->setCropStart(dup->cropStart() + (cutTime - info.startPos));
736 item->resizeEnd(cutPos, m_scale);
737 scene()->addItem(dup);
738 m_document->renderer()->mltCutClip(m_tracksList.count() - info.track, cutTime);
741 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
742 ClipItem *dup = getClipItemAt((int) cutTime.frames(m_document->fps()), info.track);
744 item->resizeEnd((int) info.endPos.frames(m_document->fps()), m_scale);
745 m_document->renderer()->mltRemoveClip(m_tracksList.count() - info.track, cutTime);
746 m_document->renderer()->mltResizeClipEnd(m_tracksList.count() - info.track, info.startPos, item->cropStart(), item->cropStart() + info.endPos - info.startPos);
751 void CustomTrackView::slotAddTransitionToSelectedClips(QDomElement transition) {
752 QList<QGraphicsItem *> itemList = scene()->selectedItems();
753 for (int i = 0; i < itemList.count(); i++) {
754 if (itemList.at(i)->type() == AVWIDGET) {
755 ClipItem *item = (ClipItem *) itemList.at(i);
757 info.startPos = item->startPos();
758 info.endPos = info.startPos + GenTime(2.5);
759 info.track = item->track();
760 int transitiontrack = getPreviousVideoTrack(info.track);
761 slotAddTransition(item, info, transitiontrack, transition);
766 void CustomTrackView::slotAddTransition(ClipItem* clip, ItemInfo transitionInfo, int endTrack, QDomElement transition) {
767 AddTransitionCommand* command = new AddTransitionCommand(this, transitionInfo, endTrack, transition, false, true);
768 m_commandStack->push(command);
769 m_document->setModified(true);
772 void CustomTrackView::addTransition(ItemInfo transitionInfo, int endTrack, QDomElement params) {
773 Transition *tr = new Transition(transitionInfo, endTrack, m_scale, m_document->fps(), params);
774 scene()->addItem(tr);
776 //kDebug() << "---- ADDING transition " << e.attribute("tag") << ", on tracks " << m_tracksList.count() - e.attribute("transition_track").toInt() << " / " << getPreviousVideoTrack(e.attribute("transition_track").toInt());
777 m_document->renderer()->mltAddTransition(tr->transitionTag(), endTrack, m_tracksList.count() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, tr->toXML());
778 m_document->setModified(true);
781 void CustomTrackView::deleteTransition(ItemInfo transitionInfo, int endTrack, QDomElement params) {
782 Transition *item = getTransitionItemAt((int)transitionInfo.startPos.frames(m_document->fps()) + 1, transitionInfo.track);
783 m_document->renderer()->mltDeleteTransition(item->transitionTag(), endTrack, m_tracksList.count() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, item->toXML());
785 emit transitionItemSelected(NULL);
786 m_document->setModified(true);
789 void CustomTrackView::slotTransitionUpdated(Transition *tr, QDomElement old) {
790 EditTransitionCommand *command = new EditTransitionCommand(this, tr->track(), tr->startPos(), old, tr->toXML() , true);
791 m_commandStack->push(command);
792 m_document->setModified(true);
795 void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTransition, QDomElement transition) {
796 Transition *item = getTransitionItemAt((int)pos.frames(m_document->fps()) + 1, track);
798 kWarning() << "Unable to find transition at pos :" << pos.frames(m_document->fps()) << ", ON track: " << track;
801 m_document->renderer()->mltUpdateTransition(oldTransition.attribute("tag"), transition.attribute("tag"), transition.attribute("transition_btrack").toInt(), m_tracksList.count() - transition.attribute("transition_atrack").toInt(), item->startPos(), item->endPos(), transition);
802 m_document->setModified(true);
805 void CustomTrackView::addItem(DocClipBase *clip, QPoint pos) {
807 info.startPos = GenTime((int)(mapToScene(pos).x() / m_scale), m_document->fps());
808 info.endPos = info.startPos + clip->duration();
809 info.track = (int)(pos.y() / m_tracksHeight);
810 //kDebug()<<"------------ ADDING CLIP ITEM----: "<<info.startPos.frames(25)<<", "<<info.endPos.frames(25)<<", "<<info.track;
811 m_dropItem = new ClipItem(clip, info, GenTime(), m_scale, m_document->fps());
812 scene()->addItem(m_dropItem);
816 void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) {
817 event->setDropAction(Qt::IgnoreAction);
819 int track = (int)(mapToScene(event->pos()).y() / m_tracksHeight); //) * (m_scale * 50) + m_scale;
820 m_dropItem->moveTo((int)(mapToScene(event->pos()).x() / m_scale), m_scale, (int)((track - m_dropItem->track()) * m_tracksHeight), track);
821 event->setDropAction(Qt::MoveAction);
822 if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
823 event->acceptProposedAction();
826 QGraphicsView::dragMoveEvent(event);
830 void CustomTrackView::dragLeaveEvent(QDragLeaveEvent * event) {
834 } else QGraphicsView::dragLeaveEvent(event);
837 void CustomTrackView::dropEvent(QDropEvent * event) {
840 info.startPos = m_dropItem->startPos();
841 info.endPos = m_dropItem->endPos();
842 info.track = m_dropItem->track();
843 AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->clipProducer(), info, false, false);
844 m_commandStack->push(command);
845 m_dropItem->baseClip()->addReference();
846 m_document->updateClip(m_dropItem->baseClip()->getId());
847 // kDebug()<<"IIIIIIIIIIIIIIIIIIIIIIII TRAX CNT: "<<m_tracksList.count()<<", DROP: "<<m_dropItem->track();
848 m_document->renderer()->mltInsertClip(m_tracksList.count() - m_dropItem->track(), m_dropItem->startPos(), m_dropItem->xml());
849 m_document->setModified(true);
850 } else QGraphicsView::dropEvent(event);
855 QStringList CustomTrackView::mimeTypes() const {
856 QStringList qstrList;
857 // list of accepted mime types for drop
858 qstrList.append("text/plain");
859 qstrList.append("kdenlive/producerslist");
863 Qt::DropActions CustomTrackView::supportedDropActions() const {
864 // returns what actions are supported when dropping
865 return Qt::MoveAction;
868 void CustomTrackView::setDuration(int duration) {
869 kDebug() << "///////////// PRO DUR: " << duration << ", SCALE. " << (m_projectDuration + 500) * m_scale << ", height: " << 50 * m_tracksList.count();
870 m_projectDuration = duration;
871 setSceneRect(0, 0, (m_projectDuration + 100) * m_scale, sceneRect().height());
874 int CustomTrackView::duration() const {
875 return m_projectDuration;
878 void CustomTrackView::addTrack(TrackInfo type) {
879 m_tracksList << type;
880 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_tracksList.count());
881 setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_tracksList.count());
882 verticalScrollBar()->setMaximum(m_tracksHeight * m_tracksList.count());
883 //setFixedHeight(50 * m_tracksCount);
886 void CustomTrackView::removeTrack() {
887 // TODO: implement track deletion
889 m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_tracksList.count());
893 void CustomTrackView::slotSwitchTrackAudio(int ix) {
894 int tracknumber = m_tracksList.count() - ix;
895 kDebug() << "///// MUTING TRK: " << ix << "; PL NUM: " << tracknumber;
896 m_tracksList[tracknumber - 1].isMute = !m_tracksList.at(tracknumber - 1).isMute;
897 m_document->renderer()->mltChangeTrackState(tracknumber, m_tracksList.at(tracknumber - 1).isMute, m_tracksList.at(tracknumber - 1).isBlind);
900 void CustomTrackView::slotSwitchTrackVideo(int ix) {
901 int tracknumber = m_tracksList.count() - ix;
902 m_tracksList[tracknumber - 1].isBlind = !m_tracksList.at(tracknumber - 1).isBlind;
903 m_document->renderer()->mltChangeTrackState(tracknumber, m_tracksList.at(tracknumber - 1).isMute, m_tracksList.at(tracknumber - 1).isBlind);
906 void CustomTrackView::deleteClip(int clipId) {
907 QList<QGraphicsItem *> itemList = items();
908 for (int i = 0; i < itemList.count(); i++) {
909 if (itemList.at(i)->type() == AVWIDGET) {
910 ClipItem *item = (ClipItem *)itemList.at(i);
911 if (item->clipProducer() == clipId) {
913 info.startPos = item->startPos();
914 info.endPos = item->endPos();
915 info.track = item->track();
916 AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), info, true, true);
917 m_commandStack->push(command);
924 void CustomTrackView::setCursorPos(int pos, bool seek) {
925 emit cursorMoved((int)(m_cursorPos * m_scale), (int)(pos * m_scale));
927 m_cursorLine->setPos(pos * m_scale, 0);
928 if (seek) m_document->renderer()->seek(GenTime(pos, m_document->fps()));
929 else if (m_autoScroll && m_scale < 50) checkScrolling();
932 void CustomTrackView::updateCursorPos() {
933 m_cursorLine->setPos(m_cursorPos * m_scale, 0);
936 int CustomTrackView::cursorPos() {
937 return (int)(m_cursorPos * m_scale);
940 void CustomTrackView::moveCursorPos(int delta) {
941 emit cursorMoved((int)(m_cursorPos * m_scale), (int)((m_cursorPos + delta) * m_scale));
942 m_cursorPos += delta;
943 m_cursorLine->setPos(m_cursorPos * m_scale, 0);
944 m_document->renderer()->seek(GenTime(m_cursorPos, m_document->fps()));
945 //if (m_autoScroll && m_scale < 50) checkScrolling();
948 void CustomTrackView::checkScrolling() {
949 QRect rectInView = viewport()->rect();
950 int delta = rectInView.width() / 3;
951 int max = rectInView.right() + horizontalScrollBar()->value() - delta;
952 //kDebug() << "CURSOR POS: "<<m_cursorPos<< "Scale: "<<m_scale;
953 if (m_cursorPos * m_scale >= max) horizontalScrollBar()->setValue((int)(horizontalScrollBar()->value() + 1 + m_scale));
956 void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
957 if (event->button() == Qt::MidButton) {
960 QGraphicsView::mouseReleaseEvent(event);
961 setDragMode(QGraphicsView::NoDrag);
962 if (m_operationMode == MOVEGUIDE) {
963 setCursor(Qt::ArrowCursor);
964 m_operationMode = NONE;
965 m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, false);
966 EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), GenTime(m_dragGuide->pos().x() / m_scale, m_document->fps()), m_dragGuide->label(), false);
967 m_commandStack->push(command);
968 m_dragGuide->update(GenTime(m_dragGuide->pos().x() / m_scale, m_document->fps()));
973 if (m_dragItem == NULL) {
974 emit transitionItemSelected(NULL);
978 info.startPos = m_dragItem->startPos();
979 info.endPos = m_dragItem->endPos();
980 info.track = m_dragItem->track();
982 if (m_operationMode == MOVE) {
983 setCursor(Qt::OpenHandCursor);
985 if (m_dragItem->type() == AVWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
986 bool success = m_document->renderer()->mltMoveClip((int)(m_tracksList.count() - m_dragItemInfo.track), (int)(m_tracksList.count() - m_dragItem->track()), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(m_dragItem->startPos().frames(m_document->fps())));
988 MoveClipCommand *command = new MoveClipCommand(this, m_dragItemInfo, info, false);
989 m_commandStack->push(command);
992 // undo last move and emit error message
993 MoveClipCommand *command = new MoveClipCommand(this, info, m_dragItemInfo, true);
994 m_commandStack->push(command);
995 emit displayMessage(i18n("Cannot move clip to requested position"), ErrorMessage);
998 if (m_dragItem->type() == TRANSITIONWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
999 MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false);
1000 m_commandStack->push(command);
1001 Transition *transition = (Transition *) m_dragItem;
1002 transition->updateTransitionEndTrack(getPreviousVideoTrack(m_dragItem->track()));
1003 m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_tracksList.count() - m_dragItemInfo.track), (int)(m_tracksList.count() - m_dragItem->track()), transition->transitionEndTrack(), m_dragItemInfo.startPos, m_dragItemInfo.endPos, info.startPos, info.endPos);
1006 } else if (m_operationMode == RESIZESTART && m_dragItem->startPos() != m_dragItemInfo.startPos) {
1008 if (m_dragItem->type() == AVWIDGET) {
1009 m_document->renderer()->mltResizeClipStart(m_tracksList.count() - m_dragItem->track(), m_dragItem->endPos(), m_dragItem->startPos(), m_dragItemInfo.startPos, m_dragItem->cropStart(), m_dragItem->cropStart() + m_dragItem->endPos() - m_dragItem->startPos());
1010 updateClipFade((ClipItem *) m_dragItem);
1011 ResizeClipCommand *command = new ResizeClipCommand(this, m_dragItemInfo, info, false);
1012 m_commandStack->push(command);
1013 } else if (m_dragItem->type() == TRANSITIONWIDGET) {
1014 MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false);
1015 m_commandStack->push(command);
1016 Transition *transition = (Transition *) m_dragItem;
1017 m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_tracksList.count() - m_dragItemInfo.track), (int)(m_tracksList.count() - m_dragItemInfo.track), 0, m_dragItemInfo.startPos, m_dragItemInfo.endPos, info.startPos, info.endPos);
1020 //m_document->renderer()->doRefresh();
1021 } else if (m_operationMode == RESIZEEND && m_dragItem->endPos() != m_dragItemInfo.endPos) {
1023 if (m_dragItem->type() == AVWIDGET) {
1024 ResizeClipCommand *command = new ResizeClipCommand(this, m_dragItemInfo, info, false);
1025 m_document->renderer()->mltResizeClipEnd(m_tracksList.count() - m_dragItem->track(), m_dragItem->startPos(), m_dragItem->cropStart(), m_dragItem->cropStart() + m_dragItem->endPos() - m_dragItem->startPos());
1026 m_commandStack->push(command);
1027 } else if (m_dragItem->type() == TRANSITIONWIDGET) {
1028 MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false);
1029 m_commandStack->push(command);
1030 Transition *transition = (Transition *) m_dragItem;
1031 m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_tracksList.count() - m_dragItemInfo.track), (int)(m_tracksList.count() - m_dragItemInfo.track), 0, m_dragItemInfo.startPos, m_dragItemInfo.endPos, info.startPos, info.endPos);
1033 //m_document->renderer()->doRefresh();
1034 } else if (m_operationMode == FADEIN) {
1035 // resize fade in effect
1036 ClipItem * item = (ClipItem *) m_dragItem;
1037 QStringList clipeffects = item->effectNames();
1038 if (clipeffects.contains(i18n("Fade in"))) {
1039 QDomElement oldeffect = item->effectAt(clipeffects.indexOf("Fade in"));
1040 int start = item->cropStart().frames(m_document->fps());
1041 int end = item->fadeIn();
1043 slotDeleteEffect(item, oldeffect);
1046 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade in");
1047 EffectsList::setParameter(effect, "in", QString::number(start));
1048 EffectsList::setParameter(effect, "out", QString::number(end));
1049 slotUpdateClipEffect(item, oldeffect, effect);
1051 } else if (item->fadeIn() != 0) {
1052 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade in");
1053 int start = item->cropStart().frames(m_document->fps());
1054 int end = item->fadeIn() + start;
1055 EffectsList::setParameter(effect, "in", QString::number(start));
1056 EffectsList::setParameter(effect, "out", QString::number(end));
1057 slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
1059 } else if (m_operationMode == FADEOUT) {
1060 // resize fade in effect
1061 ClipItem * item = (ClipItem *) m_dragItem;
1062 QStringList clipeffects = item->effectNames();
1063 if (clipeffects.contains(i18n("Fade out"))) {
1064 QDomElement oldeffect = item->effectAt(clipeffects.indexOf("Fade out"));
1065 int end = (item->duration() + item->cropStart()).frames(m_document->fps());
1066 int start = item->fadeOut();
1068 slotDeleteEffect(item, oldeffect);
1070 start = end - start;
1071 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade out");
1072 EffectsList::setParameter(effect, "in", QString::number(start));
1073 EffectsList::setParameter(effect, "out", QString::number(end));
1074 slotUpdateClipEffect(item, oldeffect, effect);
1076 } else if (item->fadeOut() != 0) {
1077 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade out");
1078 int end = (item->duration() + item->cropStart()).frames(m_document->fps());
1079 int start = end - item->fadeOut();
1080 EffectsList::setParameter(effect, "in", QString::number(start));
1081 EffectsList::setParameter(effect, "out", QString::number(end));
1082 slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
1084 } else if (m_operationMode == KEYFRAME) {
1085 // update the MLT effect
1086 ClipItem * item = (ClipItem *) m_dragItem;
1087 QString previous = item->keyframes(item->selectedEffectIndex());
1088 item->updateKeyframeEffect();
1089 QString next = item->keyframes(item->selectedEffectIndex());
1090 EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
1091 m_commandStack->push(command);
1092 updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect());
1095 emit transitionItemSelected((m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) ? (Transition*) m_dragItem : NULL);
1096 m_document->setModified(true);
1097 m_operationMode = NONE;
1100 void CustomTrackView::deleteClip(ItemInfo info) {
1101 ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
1103 kDebug() << "---------------- ERROR, CANNOT find clip to move at...";// << rect.x();
1106 if (item->isSelected()) emit clipItemSelected(NULL);
1107 item->baseClip()->removeReference();
1108 m_document->updateClip(item->baseClip()->getId());
1110 m_document->renderer()->mltRemoveClip(m_tracksList.count() - info.track, info.startPos);
1111 m_document->renderer()->doRefresh();
1114 void CustomTrackView::deleteSelectedClips() {
1115 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1116 for (int i = 0; i < itemList.count(); i++) {
1117 if (itemList.at(i)->type() == AVWIDGET) {
1118 ClipItem *item = (ClipItem *) itemList.at(i);
1120 info.startPos = item->startPos();
1121 info.endPos = item->endPos();
1122 info.track = item->track();
1123 AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), info, true, true);
1124 m_commandStack->push(command);
1125 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
1126 Transition *item = (Transition *) itemList.at(i);
1128 info.startPos = item->startPos();
1129 info.endPos = item->endPos();
1130 info.track = item->track();
1131 AddTransitionCommand *command = new AddTransitionCommand(this, info, item->transitionEndTrack(), QDomElement(), true, true);
1132 m_commandStack->push(command);
1137 void CustomTrackView::cutSelectedClips() {
1138 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1139 GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
1140 for (int i = 0; i < itemList.count(); i++) {
1141 if (itemList.at(i)->type() == AVWIDGET) {
1142 ClipItem *item = (ClipItem *) itemList.at(i);
1144 info.startPos = item->startPos();
1145 info.endPos = item->endPos();
1146 if (currentPos > info.startPos && currentPos < info.endPos) {
1147 info.track = item->track();
1148 RazorClipCommand *command = new RazorClipCommand(this, info, currentPos, true);
1149 m_commandStack->push(command);
1155 void CustomTrackView::addClip(QDomElement xml, int clipId, ItemInfo info) {
1156 DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId);
1157 int crop = xml.attribute("in").toInt();
1158 ClipItem *item = new ClipItem(baseclip, info, GenTime(crop, m_document->fps()), m_scale, m_document->fps());
1159 scene()->addItem(item);
1160 baseclip->addReference();
1161 m_document->updateClip(baseclip->getId());
1162 m_document->renderer()->mltInsertClip(m_tracksList.count() - info.track, info.startPos, xml);
1163 m_document->renderer()->doRefresh();
1166 void CustomTrackView::slotUpdateClip(int clipId) {
1167 QList<QGraphicsItem *> list = scene()->items();
1168 ClipItem *clip = NULL;
1169 for (int i = 0; i < list.size(); ++i) {
1170 if (list.at(i)->type() == AVWIDGET) {
1171 clip = static_cast <ClipItem *>(list.at(i));
1172 if (clip->clipProducer() == clipId) {
1173 clip->refreshClip();
1174 m_document->renderer()->mltUpdateClip(m_tracksList.count() - clip->track(), clip->startPos(), clip->xml());
1180 ClipItem *CustomTrackView::getClipItemAt(int pos, int track) {
1181 QList<QGraphicsItem *> list = scene()->items(QPointF(pos * m_scale, track * m_tracksHeight + m_tracksHeight / 2));
1182 ClipItem *clip = NULL;
1183 for (int i = 0; i < list.size(); ++i) {
1184 if (list.at(i)->type() == AVWIDGET) {
1185 clip = static_cast <ClipItem *>(list.at(i));
1192 ClipItem *CustomTrackView::getClipItemAt(GenTime pos, int track) {
1193 int framepos = (int)(pos.frames(m_document->fps()) * m_scale);
1194 return getClipItemAt(framepos, track);
1197 Transition *CustomTrackView::getTransitionItemAt(int pos, int track) {
1198 QList<QGraphicsItem *> list = scene()->items(QPointF(pos * m_scale, (track + 1) * m_tracksHeight));
1199 Transition *clip = NULL;
1200 for (int i = 0; i < list.size(); ++i) {
1201 if (list.at(i)->type() == TRANSITIONWIDGET) {
1202 clip = static_cast <Transition *>(list.at(i));
1209 Transition *CustomTrackView::getTransitionItemAt(GenTime pos, int track) {
1210 int framepos = (int)(pos.frames(m_document->fps()) * m_scale);
1211 return getTransitionItemAt(framepos, track);
1214 void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end) {
1215 ClipItem *item = getClipItemAt((int) start.startPos.frames(m_document->fps()) + 1, start.track);
1217 emit displayMessage(i18n("Cannot move clip at time: %1s on track %2", start.startPos.seconds(), start.track), ErrorMessage);
1218 kDebug() << "---------------- ERROR, CANNOT find clip to move at.. ";// << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2;
1221 //kDebug() << "---------------- Move CLIP FROM: " << startPos.x() << ", END:" << endPos.x() << ",TRACKS: " << startPos.y() << " TO " << endPos.y();
1223 bool success = m_document->renderer()->mltMoveClip((int)(m_tracksList.count() - start.track), (int)(m_tracksList.count() - end.track), (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()));
1225 item->moveTo((int) end.startPos.frames(m_document->fps()), m_scale, (int)((end.track - start.track) * m_tracksHeight), end.track);
1228 // undo last move and emit error message
1229 emit displayMessage(i18n("Cannot move clip to requested position"), ErrorMessage);
1233 void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end) {
1234 Transition *item = getTransitionItemAt((int)start.startPos.frames(m_document->fps()) + 1, start.track);
1236 emit displayMessage(i18n("Cannot move transition at time: %1s on track %2", start.startPos.seconds(), start.track), ErrorMessage);
1237 kDebug() << "---------------- ERROR, CANNOT find transition to move... ";// << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2;
1240 //kDebug() << "---------------- Move TRANSITION FROM: " << startPos.x() << ", END:" << endPos.x() << ",TRACKS: " << oldtrack << " TO " << newtrack;
1242 //kDebug()<<"/// RESIZE TRANS START: ("<< startPos.x()<<"x"<< startPos.y()<<") / ("<<endPos.x()<<"x"<< endPos.y()<<")";
1243 if (end.endPos - end.startPos == start.endPos - start.startPos) {
1244 // Transition was moved
1245 item->moveTo((int) end.startPos.frames(m_document->fps()), m_scale, (end.track - start.track) * m_tracksHeight, end.track);
1246 } else if (end.endPos == start.endPos) {
1247 // Transition start resize
1248 item->resizeStart((int) end.startPos.frames(m_document->fps()), m_scale);
1250 // Transition end resize;
1251 item->resizeEnd((int) end.endPos.frames(m_document->fps()), m_scale);
1253 //item->moveTransition(GenTime((int) (endPos.x() - startPos.x()), m_document->fps()));
1254 item->updateTransitionEndTrack(getPreviousVideoTrack(end.track));
1255 m_document->renderer()->mltMoveTransition(item->transitionTag(), m_tracksList.count() - start.track, m_tracksList.count() - end.track, item->transitionEndTrack(), start.startPos, start.endPos, end.startPos, end.endPos);
1258 void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end) {
1260 bool resizeClipStart = true;
1261 if (start.startPos == end.startPos) resizeClipStart = false;
1262 if (resizeClipStart) offset = 1;
1264 ClipItem *item = getClipItemAt((int)(start.startPos.frames(m_document->fps()) + offset), start.track);
1266 emit displayMessage(i18n("Cannot move clip at time: %1s on track %2", start.startPos.seconds(), start.track), ErrorMessage);
1267 kDebug() << "---------------- ERROR, CANNOT find clip to resize at... "; // << startPos;
1270 if (resizeClipStart) {
1271 m_document->renderer()->mltResizeClipStart(m_tracksList.count() - item->track(), item->endPos(), end.startPos, item->startPos(), item->cropStart() + end.startPos - start.startPos, item->cropStart() + end.startPos - start.startPos + item->endPos() - end.startPos);
1272 item->resizeStart((int) end.startPos.frames(m_document->fps()), m_scale);
1273 updateClipFade(item);
1275 m_document->renderer()->mltResizeClipEnd(m_tracksList.count() - item->track(), item->startPos(), item->cropStart(), item->cropStart() + end.startPos - item->startPos());
1276 item->resizeEnd((int) end.startPos.frames(m_document->fps()), m_scale);
1277 updateClipFade(item, true);
1279 m_document->renderer()->doRefresh();
1282 void CustomTrackView::updateClipFade(ClipItem * item, bool updateFadeOut) {
1283 if (!updateFadeOut) {
1284 int end = item->fadeIn();
1286 // there is a fade in effect
1287 QStringList clipeffects = item->effectNames();
1288 QDomElement oldeffect = item->effectAt(clipeffects.indexOf("Fade in"));
1289 int start = item->cropStart().frames(m_document->fps());
1291 EffectsList::setParameter(oldeffect, "in", QString::number(start));
1292 EffectsList::setParameter(oldeffect, "out", QString::number(end));
1293 QMap <QString, QString> effectParams = item->getEffectArgs(oldeffect);
1294 m_document->renderer()->mltEditEffect(m_tracksList.count() - item->track(), item->startPos(), effectParams);
1297 int start = item->fadeOut();
1299 // there is a fade in effect
1300 QStringList clipeffects = item->effectNames();
1301 QDomElement oldeffect = item->effectAt(clipeffects.indexOf("Fade out"));
1302 int end = (item->duration() - item->cropStart()).frames(m_document->fps());
1303 start = end - start;
1304 EffectsList::setParameter(oldeffect, "in", QString::number(start));
1305 EffectsList::setParameter(oldeffect, "out", QString::number(end));
1306 QMap <QString, QString> effectParams = item->getEffectArgs(oldeffect);
1307 m_document->renderer()->mltEditEffect(m_tracksList.count() - item->track(), item->startPos(), effectParams);
1312 double CustomTrackView::getSnapPointForPos(double pos) {
1313 for (int i = 0; i < m_snapPoints.size(); ++i) {
1314 if (abs((int)(pos - m_snapPoints.at(i).frames(m_document->fps()) * m_scale)) < 10) {
1315 //kDebug()<<" FOUND SNAP POINT AT: "<<m_snapPoints.at(i)<<", current pos: "<<pos / m_scale;
1316 return m_snapPoints.at(i).frames(m_document->fps()) * m_scale + 0.5;
1318 if (m_snapPoints.at(i).frames(m_document->fps() * m_scale) > pos) break;
1323 void CustomTrackView::updateSnapPoints(AbstractClipItem *selected) {
1324 m_snapPoints.clear();
1325 if (!KdenliveSettings::snaptopoints()) return;
1327 if (selected) offset = selected->duration();
1328 QList<QGraphicsItem *> itemList = items();
1329 for (int i = 0; i < itemList.count(); i++) {
1330 if (itemList.at(i)->type() == AVWIDGET && itemList.at(i) != selected) {
1331 ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1332 GenTime start = item->startPos();
1333 GenTime end = item->endPos();
1334 m_snapPoints.append(start);
1335 m_snapPoints.append(end);
1336 QList < GenTime > markers = item->snapMarkers();
1337 for (int i = 0; i < markers.size(); ++i) {
1338 GenTime t = markers.at(i);
1339 m_snapPoints.append(t);
1340 if (t > offset) m_snapPoints.append(t - offset);
1342 if (offset != GenTime()) {
1343 if (start > offset) m_snapPoints.append(start - offset);
1344 if (end > offset) m_snapPoints.append(end - offset);
1346 } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
1347 Transition *transition = static_cast <Transition*>(itemList.at(i));
1348 GenTime start = transition->startPos();
1349 GenTime end = transition->endPos();
1350 m_snapPoints.append(start);
1351 m_snapPoints.append(end);
1352 if (offset != GenTime()) {
1353 if (start > offset) m_snapPoints.append(start - offset);
1354 if (end > offset) m_snapPoints.append(end - offset);
1359 // add cursor position
1360 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1361 m_snapPoints.append(pos);
1362 if (offset != GenTime()) m_snapPoints.append(pos - offset);
1365 for (int i = 0; i < m_guides.count(); i++) {
1366 m_snapPoints.append(m_guides.at(i)->position());
1367 if (offset != GenTime()) m_snapPoints.append(m_guides.at(i)->position() - offset);
1370 qSort(m_snapPoints);
1371 //for (int i = 0; i < m_snapPoints.size(); ++i)
1372 // kDebug() << "SNAP POINT: " << m_snapPoints.at(i).frames(25);
1375 void CustomTrackView::slotSeekToPreviousSnap() {
1376 updateSnapPoints(NULL);
1377 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1378 GenTime res = GenTime();
1379 for (int i = 0; i < m_snapPoints.size(); ++i) {
1380 if (m_snapPoints.at(i) >= pos) {
1382 res = m_snapPoints.at(i - 1);
1386 setCursorPos((int) res.frames(m_document->fps()));
1389 void CustomTrackView::slotSeekToNextSnap() {
1390 updateSnapPoints(NULL);
1391 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1392 GenTime res = GenTime(m_projectDuration, m_document->fps());
1393 for (int i = 0; i < m_snapPoints.size(); ++i) {
1394 if (m_snapPoints.at(i) > pos) {
1395 res = m_snapPoints.at(i);
1399 setCursorPos((int) res.frames(m_document->fps()));
1402 void CustomTrackView::slotAddClipMarker() {
1403 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1404 if (itemList.count() != 1) {
1405 emit displayMessage(i18n("Cannot add marker if more than one clip is selected"), ErrorMessage);
1406 kDebug() << "// CANNOT ADD MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1409 AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1410 if (item->type() != AVWIDGET) return;
1411 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1412 if (item->startPos() > pos || item->endPos() < pos) return;
1413 ClipItem *clip = (ClipItem *) item;
1414 int id = clip->baseClip()->getId();
1415 GenTime position = pos - item->startPos() + item->cropStart();
1416 CommentedTime marker(position, i18n("Marker"));
1417 MarkerDialog d(clip->baseClip(), marker, m_document->timecode(), this);
1418 if (d.exec() == QDialog::Accepted) {
1419 slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1423 void CustomTrackView::slotAddClipMarker(int id, GenTime t, QString c) {
1424 QString oldcomment = m_document->clipManager()->getClipById(id)->markerComment(t);
1425 AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, c, id, t, true);
1426 m_commandStack->push(command);
1429 void CustomTrackView::slotDeleteClipMarker() {
1430 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1431 if (itemList.count() != 1) {
1432 emit displayMessage(i18n("Cannot delete marker if more than one clip is selected"), ErrorMessage);
1433 kDebug() << "// CANNOT DELETE MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1436 AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1437 if (item->type() != AVWIDGET) {
1438 emit displayMessage(i18n("No clip at cursor time"), ErrorMessage);
1441 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1442 if (item->startPos() > pos || item->endPos() < pos) {
1443 emit displayMessage(i18n("No selected clip at cursor time"), ErrorMessage);
1446 ClipItem *clip = (ClipItem *) item;
1447 int id = clip->baseClip()->getId();
1448 GenTime position = pos - item->startPos() + item->cropStart();
1449 QString comment = clip->baseClip()->markerComment(position);
1450 if (comment.isEmpty()) {
1451 emit displayMessage(i18n("No marker found at cursor time"), ErrorMessage);
1454 AddMarkerCommand *command = new AddMarkerCommand(this, comment, QString(), id, position, true);
1455 m_commandStack->push(command);
1458 void CustomTrackView::slotEditClipMarker() {
1459 QList<QGraphicsItem *> itemList = scene()->selectedItems();
1460 if (itemList.count() != 1) {
1461 emit displayMessage(i18n("Cannot edit marker if more than one clip is selected"), ErrorMessage);
1462 kDebug() << "// CANNOT DELETE MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1465 AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1466 if (item->type() != AVWIDGET) {
1467 emit displayMessage(i18n("No clip at cursor time"), ErrorMessage);
1470 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1471 if (item->startPos() > pos || item->endPos() < pos) {
1472 emit displayMessage(i18n("No selected clip at cursor time"), ErrorMessage);
1475 ClipItem *clip = (ClipItem *) item;
1476 int id = clip->baseClip()->getId();
1477 GenTime position = pos - item->startPos() + item->cropStart();
1478 QString oldcomment = clip->baseClip()->markerComment(position);
1479 if (oldcomment.isEmpty()) {
1480 emit displayMessage(i18n("No marker found at cursor time"), ErrorMessage);
1484 CommentedTime marker(position, oldcomment);
1485 MarkerDialog d(clip->baseClip(), marker, m_document->timecode(), this);
1486 if (d.exec() == QDialog::Accepted) {
1487 if (d.newMarker().time() == position) {
1488 // marker position was not changed, only text
1489 AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, d.newMarker().comment(), id, position, true);
1490 m_commandStack->push(command);
1492 // marker text and position were changed, remove previous marker and add new one
1493 AddMarkerCommand *command1 = new AddMarkerCommand(this, oldcomment, QString(), id, position, true);
1494 AddMarkerCommand *command2 = new AddMarkerCommand(this, QString(), d.newMarker().comment(), id, d.newMarker().time(), true);
1495 m_commandStack->push(command1);
1496 m_commandStack->push(command2);
1501 void CustomTrackView::addMarker(const int id, const GenTime &pos, const QString comment) {
1502 DocClipBase *base = m_document->clipManager()->getClipById(id);
1503 if (!comment.isEmpty()) base->addSnapMarker(pos, comment);
1504 else base->deleteSnapMarker(pos);
1505 m_document->setModified(true);
1506 viewport()->update();
1511 void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const QString &comment) {
1512 if (oldPos > GenTime() && pos > GenTime()) {
1514 for (int i = 0; i < m_guides.count(); i++) {
1515 kDebug() << "// LOOKING FOR GUIDE (" << i << "): " << m_guides.at(i)->position().frames(25) << ", LOOK: " << oldPos.frames(25) << "x" << pos.frames(25);
1516 if (m_guides.at(i)->position() == oldPos) {
1517 Guide *item = m_guides.at(i);
1518 item->update(pos, comment);
1519 item->updatePosition(m_scale);
1523 } else if (pos > GenTime()) addGuide(pos, comment);
1527 for (int i = 0; i < m_guides.count(); i++) {
1528 if (m_guides.at(i)->position() == oldPos) {
1529 Guide *item = m_guides.takeAt(i);
1535 if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
1539 bool CustomTrackView::addGuide(const GenTime pos, const QString &comment) {
1540 for (int i = 0; i < m_guides.count(); i++) {
1541 if (m_guides.at(i)->position() == pos) {
1542 emit displayMessage(i18n("A guide already exists at that position"), ErrorMessage);
1546 Guide *g = new Guide(this, pos, comment, m_scale, m_document->fps(), m_tracksHeight * m_tracksList.count());
1547 scene()->addItem(g);
1552 void CustomTrackView::slotAddGuide() {
1553 if (addGuide(GenTime(m_cursorPos, m_document->fps()), i18n("guide"))) {
1554 EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), GenTime(m_cursorPos, m_document->fps()), i18n("guide"), false);
1555 m_commandStack->push(command);
1559 void CustomTrackView::slotDeleteGuide() {
1560 GenTime pos = GenTime(m_cursorPos, m_document->fps());
1562 for (int i = 0; i < m_guides.count(); i++) {
1563 if (m_guides.at(i)->position() == pos) {
1564 EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true);
1565 m_commandStack->push(command);
1570 if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
1573 void CustomTrackView::setTool(PROJECTTOOL tool) {
1577 void CustomTrackView::setScale(double scaleFactor) {
1578 //scale(scaleFactor, scaleFactor);
1579 m_animationTimer->stop();
1588 double pos = cursorPos() / m_scale;
1589 m_scale = scaleFactor;
1590 int vert = verticalScrollBar()->value();
1591 kDebug() << " HHHHHHHH SCALING: " << m_scale;
1592 QList<QGraphicsItem *> itemList = items();
1593 for (int i = 0; i < itemList.count(); i++) {
1594 if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
1595 AbstractClipItem *clip = (AbstractClipItem *)itemList.at(i);
1596 clip->setRect(clip->startPos().frames(m_document->fps()) * m_scale, clip->rect().y(), clip->duration().frames(m_document->fps()) * m_scale, clip->rect().height());
1600 for (int i = 0; i < m_guides.count(); i++) {
1601 m_guides.at(i)->updatePosition(m_scale);
1604 setSceneRect(0, 0, (m_projectDuration + 100) * m_scale, sceneRect().height());
1606 centerOn(QPointF(cursorPos(), m_tracksHeight));
1607 verticalScrollBar()->setValue(vert);
1610 void CustomTrackView::drawBackground(QPainter * painter, const QRectF & rect) {
1611 QRect rectInView = viewport()->rect();
1612 rectInView.moveTo(horizontalScrollBar()->value(), verticalScrollBar()->value());
1614 QColor base = palette().button().color();
1615 painter->setClipRect(rect);
1616 painter->drawLine(rectInView.left(), 0, rectInView.right(), 0);
1617 uint max = m_tracksList.count();
1618 for (uint i = 0; i < max;i++) {
1619 if (m_tracksList.at(max - i - 1).type == AUDIOTRACK) painter->fillRect(rectInView.left(), m_tracksHeight * i + 1, rectInView.right() - rectInView.left() + 1, m_tracksHeight - 1, QBrush(QColor(240, 240, 255)));
1620 painter->drawLine(rectInView.left(), m_tracksHeight * (i + 1), rectInView.right(), m_tracksHeight * (i + 1));
1621 //painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i + 1));
1623 int lowerLimit = m_tracksHeight * m_tracksList.count() + 1;
1624 if (height() > lowerLimit)
1625 painter->fillRect(QRectF(rectInView.left(), lowerLimit, rectInView.width(), height() - lowerLimit), QBrush(base));
1628 QDomElement CustomTrackView::xmlInfo() {
1631 QDomElement guides = doc.createElement("guides");
1632 for (int i = 0; i < m_guides.count(); i++) {
1633 e = doc.createElement("guide");
1634 e.setAttribute("time", m_guides.at(i)->position().ms() / 1000);
1635 e.setAttribute("comment", m_guides.at(i)->label());
1636 guides.appendChild(e);
1642 void CustomTrackView::drawForeground ( QPainter * painter, const QRectF & rect )
1644 //kDebug()<<"///// DRAWING FB: "<<rect.x()<<", width: "<<rect.width();
1645 painter->fillRect(rect, QColor(50, rand() % 250,50,100));
1646 painter->drawLine(m_cursorPos, rect.y(), m_cursorPos, rect.y() + rect.height());
1649 #include "customtrackview.moc"