]> git.sesse.net Git - kdenlive/blob - src/customtrackview.cpp
Some new actions: delete all guides, delete all markers, fix crash in delete clip...
[kdenlive] / src / customtrackview.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20 #include <QMouseEvent>
21 #include <QStylePainter>
22 #include <QGraphicsItem>
23 #include <QDomDocument>
24 #include <QScrollBar>
25 #include <QApplication>
26 #include <QInputDialog>
27
28 #include <KDebug>
29 #include <KLocale>
30 #include <KUrl>
31 #include <KIcon>
32 #include <KCursor>
33
34 #include "customtrackview.h"
35 #include "docclipbase.h"
36 #include "clipitem.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"
53 #include "clipitem.h"
54 #include "customtrackview.h"
55 #include "clipmanager.h"
56 #include "renderer.h"
57 #include "markerdialog.h"
58 #include "mainwindow.h"
59 #include "ui_keyframedialog_ui.h"
60 #include "clipdurationdialog.h"
61
62
63 //TODO:
64 // disable animation if user asked it in KDE's global settings
65 // http://lists.kde.org/?l=kde-commits&m=120398724717624&w=2
66 // needs something like below (taken from dolphin)
67 // #include <kglobalsettings.h>
68 // const bool animate = KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects;
69 // const int duration = animate ? 1500 : 1;
70
71 CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent)
72         : 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), m_findIndex(0) {
73     if (doc) m_commandStack = doc->commandStack();
74     else m_commandStack == NULL;
75     setMouseTracking(true);
76     setAcceptDrops(true);
77     m_animationTimer = new QTimeLine(800);
78     m_animationTimer->setFrameRange(0, 5);
79     m_animationTimer->setUpdateInterval(100);
80     m_animationTimer->setLoopCount(0);
81     m_tipColor = QColor(0, 192, 0, 200);
82     QColor border = QColor(255, 255, 255, 100);
83     m_tipPen.setColor(border);
84     m_tipPen.setWidth(3);
85     setContentsMargins(0, 0, 0, 0);
86     if (projectscene) {
87         m_cursorLine = projectscene->addLine(0, 0, 0, m_tracksHeight);
88         m_cursorLine->setFlags(QGraphicsItem::ItemIsMovable);
89         m_cursorLine->setZValue(1000);
90     }
91
92     KIcon razorIcon("edit-cut");
93     m_razorCursor = QCursor(razorIcon.pixmap(22, 22));
94     verticalScrollBar()->setTracking(true);
95     connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slotRefreshGuides()));
96 }
97
98 CustomTrackView::~CustomTrackView() {
99     qDeleteAll(m_guides);
100 }
101
102
103 void CustomTrackView::setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition) {
104     m_timelineContextMenu = timeline;
105     m_timelineContextClipMenu = clip;
106     m_timelineContextTransitionMenu = transition;
107 }
108
109 void CustomTrackView::checkAutoScroll() {
110     m_autoScroll = KdenliveSettings::autoscroll();
111 }
112
113 QList <TrackInfo> CustomTrackView::tracksList() const {
114     return m_tracksList;
115 }
116
117 void CustomTrackView::checkTrackHeight() {
118     if (m_tracksHeight == KdenliveSettings::trackheight()) return;
119     m_tracksHeight = KdenliveSettings::trackheight();
120     emit trackHeightChanged();
121     QList<QGraphicsItem *> itemList = items();
122     ClipItem *item;
123     Transition *transitionitem;
124     for (int i = 0; i < itemList.count(); i++) {
125         if (itemList.at(i)->type() == AVWIDGET) {
126             item = (ClipItem*) itemList.at(i);
127             item->setRect(item->rect().x(), item->track() * m_tracksHeight, item->rect().width(), m_tracksHeight - 1);
128             item->resetThumbs();
129         } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
130             transitionitem = (Transition*) itemList.at(i);
131             transitionitem->setRect(transitionitem->rect().x(), transitionitem->track() * m_tracksHeight + m_tracksHeight / 2, transitionitem->rect().width(), m_tracksHeight - 1);
132         }
133     }
134     m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_tracksList.count());
135
136     for (int i = 0; i < m_guides.count(); i++) {
137         QLineF l = m_guides.at(i)->line();
138         l.setP2(QPointF(l.x2(), m_tracksHeight * m_tracksList.count()));
139         m_guides.at(i)->setLine(l);
140     }
141
142     setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_tracksList.count());
143     verticalScrollBar()->setMaximum(m_tracksHeight * m_tracksList.count());
144     update();
145 }
146
147 // virtual
148 void CustomTrackView::resizeEvent(QResizeEvent * event) {
149     QGraphicsView::resizeEvent(event);
150 }
151
152 // virtual
153 void CustomTrackView::wheelEvent(QWheelEvent * e) {
154     if (e->modifiers() == Qt::ControlModifier) {
155         if (e->delta() > 0) emit zoomIn();
156         else emit zoomOut();
157     } else {
158         if (e->delta() > 0) horizontalScrollBar()->setValue(horizontalScrollBar()->value() + horizontalScrollBar()->singleStep());
159         else  horizontalScrollBar()->setValue(horizontalScrollBar()->value() - horizontalScrollBar()->singleStep());
160     }
161 }
162
163 int CustomTrackView::getPreviousVideoTrack(int track) {
164     track = m_tracksList.count() - track - 1;
165     track --;
166     for (int i = track; i > -1; i--) {
167         if (m_tracksList.at(i).type == VIDEOTRACK) return i + 1;
168     }
169     return 0;
170 }
171
172 // virtual
173
174 void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
175     int pos = event->x();
176     emit mousePosition((int)(mapToScene(event->pos()).x() / m_scale));
177     if (event->buttons() & Qt::MidButton) return;
178     if (event->buttons() != Qt::NoButton) {
179         if (m_dragItem && m_tool == SELECTTOOL) { //event->button() == Qt::LeftButton) {
180             // a button was pressed, delete visual tips
181             if (m_operationMode == MOVE && (event->pos() - m_clickEvent).manhattanLength() >= QApplication::startDragDistance()) {
182                 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint.x());
183                 //kDebug() << "///////  MOVE CLIP, EVENT Y: "<<m_clickPoint.y();//<<event->scenePos().y()<<", SCENE HEIGHT: "<<scene()->sceneRect().height();
184                 int moveTrack = (int)  mapToScene(event->pos() - QPoint(0, (m_dragItem->type() == TRANSITIONWIDGET ? m_dragItem->boundingRect().height() / 2 : 0))).y() / m_tracksHeight;
185                 int currentTrack = m_dragItem->track();
186
187                 if (moveTrack > 1000) moveTrack = 0;
188                 else if (moveTrack > m_tracksList.count() - 1) moveTrack = m_tracksList.count() - 1;
189                 else if (moveTrack < 0) moveTrack = 0;
190
191                 int offset = moveTrack - currentTrack;
192                 if (offset != 0) offset = m_tracksHeight * offset;
193                 m_dragItem->moveTo((int)(snappedPos / m_scale), m_scale, offset, moveTrack);
194             } else if (m_operationMode == RESIZESTART) {
195                 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x());
196                 m_dragItem->resizeStart((int)(snappedPos / m_scale), m_scale);
197             } else if (m_operationMode == RESIZEEND) {
198                 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x());
199                 m_dragItem->resizeEnd((int)(snappedPos / m_scale), m_scale);
200             } else if (m_operationMode == FADEIN) {
201                 int pos = (int)(mapToScene(event->pos()).x() / m_scale);
202                 ((ClipItem*) m_dragItem)->setFadeIn((int)(pos - m_dragItem->startPos().frames(m_document->fps())), m_scale);
203             } else if (m_operationMode == FADEOUT) {
204                 int pos = (int)(mapToScene(event->pos()).x() / m_scale);
205                 ((ClipItem*) m_dragItem)->setFadeOut((int)(m_dragItem->endPos().frames(m_document->fps()) - pos), m_scale);
206             } else if (m_operationMode == KEYFRAME) {
207                 GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x() / m_scale), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart();
208                 double pos = mapToScene(event->pos()).toPoint().y();
209                 QRectF br = m_dragItem->rect();
210                 double maxh = 100.0 / br.height();
211                 pos = (br.bottom() - pos) * maxh;
212                 m_dragItem->updateKeyFramePos(keyFramePos, pos);
213             }
214
215             if (m_animation) delete m_animation;
216             m_animation = NULL;
217             if (m_visualTip) delete m_visualTip;
218             m_visualTip = NULL;
219             QGraphicsView::mouseMoveEvent(event);
220             return;
221         } else if (m_operationMode == MOVEGUIDE) {
222             if (m_animation) delete m_animation;
223             m_animation = NULL;
224             if (m_visualTip) delete m_visualTip;
225             m_visualTip = NULL;
226             QGraphicsView::mouseMoveEvent(event);
227             return;
228         }
229     }
230
231     if (m_tool == RAZORTOOL) {
232         setCursor(m_razorCursor);
233         //QGraphicsView::mouseMoveEvent(event);
234         //return;
235     }
236
237     QList<QGraphicsItem *> itemList = items(event->pos());
238     QGraphicsRectItem *item = NULL;
239     OPERATIONTYPE opMode = NONE;
240
241     if (itemList.count() == 1 && itemList.at(0)->type() == GUIDEITEM) {
242         opMode = MOVEGUIDE;
243     } else for (int i = 0; i < itemList.count(); i++) {
244             if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
245                 item = (QGraphicsRectItem*) itemList.at(i);
246                 break;
247             }
248         }
249
250     if (item && event->buttons() == Qt::NoButton) {
251         AbstractClipItem *clip = (AbstractClipItem*) item;
252         if (m_tool == RAZORTOOL) {
253             // razor tool over a clip, display current frame in monitor
254             if (item->type() == AVWIDGET) {
255                 emit showClipFrame(((ClipItem *) item)->baseClip(), mapToScene(event->pos()).x() / m_scale - (clip->startPos() - clip->cropStart()).frames(m_document->fps()));
256             }
257             QGraphicsView::mouseMoveEvent(event);
258             return;
259         }
260         opMode = clip->operationMode(mapToScene(event->pos()), m_scale);
261         double size = 8;
262         if (opMode == m_moveOpMode) {
263             QGraphicsView::mouseMoveEvent(event);
264             return;
265         } else {
266             if (m_visualTip) {
267                 if (m_animation) delete m_animation;
268                 m_animation = NULL;
269                 m_animationTimer->stop();
270                 delete m_visualTip;
271                 m_visualTip = NULL;
272             }
273         }
274         m_moveOpMode = opMode;
275         if (opMode == MOVE) {
276             setCursor(Qt::OpenHandCursor);
277         } else if (opMode == RESIZESTART) {
278             setCursor(KCursor("left_side", Qt::SizeHorCursor));
279             if (m_visualTip == NULL) {
280                 QPolygon polygon;
281                 polygon << QPoint((int)clip->rect().x(), (int)(clip->rect().y() + clip->rect().height() / 2 - size * 2));
282                 polygon << QPoint((int)(clip->rect().x() + size * 2), (int)(clip->rect().y() + clip->rect().height() / 2));
283                 polygon << QPoint((int)clip->rect().x(), (int)(clip->rect().y() + clip->rect().height() / 2 + size * 2));
284                 polygon << QPoint((int)clip->rect().x(), (int)(clip->rect().y() + clip->rect().height() / 2 - size * 2));
285
286                 m_visualTip = new QGraphicsPolygonItem(polygon);
287                 ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
288                 ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen);
289                 m_visualTip->setZValue(100);
290                 m_animation = new QGraphicsItemAnimation;
291                 m_animation->setItem(m_visualTip);
292                 m_animation->setTimeLine(m_animationTimer);
293                 m_visualTip->setPos(0, 0);
294                 double scale = 2.0;
295                 m_animation->setScaleAt(.5, scale, 1);
296                 m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
297                 scale = 1.0;
298                 m_animation->setScaleAt(1, scale, 1);
299                 m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
300                 scene()->addItem(m_visualTip);
301                 m_animationTimer->start();
302             }
303         } else if (opMode == RESIZEEND) {
304             setCursor(KCursor("right_side", Qt::SizeHorCursor));
305             if (m_visualTip == NULL) {
306                 QPolygon polygon;
307                 polygon << QPoint((int)(clip->rect().x() + clip->rect().width()), (int)(clip->rect().y() + clip->rect().height() / 2 - size * 2));
308                 polygon << QPoint((int)(clip->rect().x() + clip->rect().width() - size * 2), (int)(clip->rect().y() + clip->rect().height() / 2));
309                 polygon << QPoint((int)(clip->rect().x() + clip->rect().width()), (int)(clip->rect().y() + clip->rect().height() / 2 + size * 2));
310                 polygon << QPoint((int)(clip->rect().x() + clip->rect().width()), (int)(clip->rect().y() + clip->rect().height() / 2 - size * 2));
311
312                 m_visualTip = new QGraphicsPolygonItem(polygon);
313                 ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
314                 ((QGraphicsPolygonItem*) m_visualTip)->setPen(m_tipPen);
315
316                 m_visualTip->setZValue(100);
317                 m_animation = new QGraphicsItemAnimation;
318                 m_animation->setItem(m_visualTip);
319                 m_animation->setTimeLine(m_animationTimer);
320                 m_visualTip->setPos(0, 0);
321                 double scale = 2.0;
322                 m_animation->setScaleAt(.5, scale, 1);
323                 m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->rect().width(), 0));
324                 scale = 1.0;
325                 m_animation->setScaleAt(1, scale, 1);
326                 m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, 0));
327                 scene()->addItem(m_visualTip);
328                 m_animationTimer->start();
329             }
330         } else if (opMode == FADEIN) {
331             if (m_visualTip == NULL) {
332                 ClipItem *item = (ClipItem *) clip;
333                 m_visualTip = new QGraphicsEllipseItem(item->rect().x() + item->fadeIn() * m_scale - size, item->rect().y() - 8, size * 2, 16);
334                 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
335                 ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen);
336                 m_visualTip->setZValue(100);
337                 m_animation = new QGraphicsItemAnimation;
338                 m_animation->setItem(m_visualTip);
339                 m_animation->setTimeLine(m_animationTimer);
340                 m_visualTip->setPos(0, 0);
341                 double scale = 2.0;
342                 m_animation->setScaleAt(.5, scale, scale);
343                 m_animation->setPosAt(.5, QPointF(item->rect().x() - item->rect().x() * scale -  item->fadeIn() * m_scale, item->rect().y() - item->rect().y() * scale));
344                 scale = 1.0;
345                 m_animation->setScaleAt(1, scale, scale);
346                 m_animation->setPosAt(1, QPointF(item->rect().x() - item->rect().x() * scale, item->rect().y() - item->rect().y() * scale));
347                 scene()->addItem(m_visualTip);
348                 m_animationTimer->start();
349             }
350             setCursor(Qt::PointingHandCursor);
351         } else if (opMode == FADEOUT) {
352             if (m_visualTip == NULL) {
353                 ClipItem *item = (ClipItem *) clip;
354                 m_visualTip = new QGraphicsEllipseItem(item->rect().x() + item->rect().width() - item->fadeOut() * m_scale - size, item->rect().y() - 8, size*2, 16);
355                 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
356                 ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen);
357                 m_visualTip->setZValue(100);
358                 m_animation = new QGraphicsItemAnimation;
359                 m_animation->setItem(m_visualTip);
360                 m_animation->setTimeLine(m_animationTimer);
361                 m_visualTip->setPos(0, 0);
362                 double scale = 2.0;
363                 m_animation->setScaleAt(.5, scale, scale);
364                 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));
365                 scale = 1.0;
366                 m_animation->setScaleAt(1, scale, scale);
367                 m_animation->setPosAt(1, QPointF(item->rect().x() - item->rect().x() * scale, item->rect().y() - item->rect().y() * scale));
368                 scene()->addItem(m_visualTip);
369                 m_animationTimer->start();
370             }
371             setCursor(Qt::PointingHandCursor);
372         } else if (opMode == TRANSITIONSTART) {
373             if (m_visualTip == NULL) {
374                 m_visualTip = new QGraphicsEllipseItem(-5, -5 , 10, 10);
375                 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
376                 ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen);
377                 m_visualTip->setZValue(100);
378                 m_animation = new QGraphicsItemAnimation;
379                 m_animation->setItem(m_visualTip);
380                 m_animation->setTimeLine(m_animationTimer);
381                 m_visualTip->setPos(clip->rect().x() + 10, clip->rect().y() + clip->rect().height() / 2 + 12);
382                 double scale = 2.0;
383                 m_animation->setScaleAt(.5, scale, scale);
384                 scale = 1.0;
385                 m_animation->setScaleAt(1, scale, scale);
386                 scene()->addItem(m_visualTip);
387                 m_animationTimer->start();
388             }
389             setCursor(Qt::PointingHandCursor);
390         } else if (opMode == TRANSITIONEND) {
391             if (m_visualTip == NULL) {
392                 m_visualTip = new QGraphicsEllipseItem(-5, -5 , 10, 10);
393                 ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
394                 ((QGraphicsEllipseItem*) m_visualTip)->setPen(m_tipPen);
395                 m_visualTip->setZValue(100);
396                 m_animation = new QGraphicsItemAnimation;
397                 m_animation->setItem(m_visualTip);
398                 m_animation->setTimeLine(m_animationTimer);
399                 m_visualTip->setPos(clip->rect().x() + clip->rect().width() - 10 , clip->rect().y() + clip->rect().height() / 2 + 12);
400                 double scale = 2.0;
401                 m_animation->setScaleAt(.5, scale, scale);
402                 scale = 1.0;
403                 m_animation->setScaleAt(1, scale, scale);
404                 scene()->addItem(m_visualTip);
405                 m_animationTimer->start();
406             }
407             setCursor(Qt::PointingHandCursor);
408         } else if (opMode == KEYFRAME) {
409             setCursor(Qt::PointingHandCursor);
410         }
411     } // no clip under mouse
412     else if (m_tool == RAZORTOOL) {
413         QGraphicsView::mouseMoveEvent(event);
414         return;
415     } else if (opMode == MOVEGUIDE) {
416         m_moveOpMode = opMode;
417         setCursor(Qt::SplitHCursor);
418     } else {
419         m_moveOpMode = NONE;
420         if (event->buttons() != Qt::NoButton && event->modifiers() == Qt::NoModifier) {
421             setCursorPos((int)(mapToScene(event->pos().x(), 0).x() / m_scale));
422         }
423         if (m_visualTip) {
424             if (m_animation) delete m_animation;
425             m_animationTimer->stop();
426             m_animation = NULL;
427             delete m_visualTip;
428             m_visualTip = NULL;
429
430         }
431         setCursor(Qt::ArrowCursor);
432     }
433     QGraphicsView::mouseMoveEvent(event);
434 }
435
436 // virtual
437 void CustomTrackView::mousePressEvent(QMouseEvent * event) {
438     activateMonitor();
439     m_clickEvent = event->pos();
440     if (event->button() == Qt::MidButton) {
441         m_document->renderer()->switchPlay();
442         return;
443     }
444     if (event->modifiers() == Qt::ControlModifier) {
445         setDragMode(QGraphicsView::ScrollHandDrag);
446         QGraphicsView::mousePressEvent(event);
447         return;
448     } else if (event->modifiers() == Qt::ShiftModifier) {
449         setDragMode(QGraphicsView::RubberBandDrag);
450         QGraphicsView::mousePressEvent(event);
451         return;
452     } else {
453         bool collision = false;
454         QList<QGraphicsItem *> collisionList = items(event->pos());
455         if (collisionList.count() == 1 && collisionList.at(0)->type() == GUIDEITEM) {
456             // a guide item was pressed
457             collisionList.at(0)->setFlag(QGraphicsItem::ItemIsMovable, true);
458             m_dragItem = NULL;
459             m_dragGuide = (Guide *) collisionList.at(0);
460             collision = true;
461             m_operationMode = MOVEGUIDE;
462             // deselect all clips so that only the guide will move
463             QList<QGraphicsItem *> clips = scene()->selectedItems();
464             for (int i = 0; i < clips.count(); ++i)
465                 clips.at(i)->setSelected(false);
466             updateSnapPoints(NULL);
467             QGraphicsView::mousePressEvent(event);
468         } else for (int i = 0; i < collisionList.count(); ++i) {
469                 QGraphicsItem *item = collisionList.at(i);
470                 if (item->type() == AVWIDGET || item->type() == TRANSITIONWIDGET) {
471                     if (m_tool == RAZORTOOL) {
472                         if (item->type() == TRANSITIONWIDGET) {
473                             emit displayMessage(i18n("Cannot cut a transition"), ErrorMessage);
474                             return;
475                         }
476                         AbstractClipItem *clip = (AbstractClipItem *) item;
477                         ItemInfo info;
478                         info.startPos = clip->startPos();
479                         info.endPos = clip->endPos();
480                         info.track = clip->track();
481                         RazorClipCommand* command = new RazorClipCommand(this, info, GenTime((int)(mapToScene(event->pos()).x() / m_scale), m_document->fps()), true);
482                         m_commandStack->push(command);
483                         m_document->setModified(true);
484                         return;
485                     }
486                     // select item
487                     if (!item->isSelected()) {
488                         QList<QGraphicsItem *> itemList = items();
489                         for (int i = 0; i < itemList.count(); i++) {
490                             itemList.at(i)->setSelected(false);
491                             itemList.at(i)->update();
492                         }
493                         item->setSelected(true);
494                         item->update();
495                     }
496
497                     m_dragItem = (AbstractClipItem *) item;
498
499                     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()));
500                     m_dragItemInfo.startPos = m_dragItem->startPos();
501                     m_dragItemInfo.endPos = m_dragItem->endPos();
502                     m_dragItemInfo.track = m_dragItem->track();
503
504                     m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale);
505                     if (m_operationMode == KEYFRAME) {
506                         m_dragItem->updateSelectedKeyFrame();
507                         return;
508                     } else if (m_operationMode == MOVE) setCursor(Qt::ClosedHandCursor);
509                     else if (m_operationMode == TRANSITIONSTART) {
510                         ItemInfo info;
511                         info.startPos = m_dragItem->startPos();
512                         info.track = m_dragItem->track();
513                         int transitiontrack = getPreviousVideoTrack(info.track);
514                         ClipItem *transitionClip = NULL;
515                         if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.startPos.frames(m_document->fps()), m_tracksList.count() - transitiontrack);
516                         if (transitionClip && transitionClip->endPos() < m_dragItem->endPos()) {
517                             info.endPos = transitionClip->endPos();
518                         } else info.endPos = info.startPos + GenTime(2.5);
519
520                         slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
521                     } else if (m_operationMode == TRANSITIONEND) {
522                         ItemInfo info;
523                         info.endPos = m_dragItem->endPos();
524                         info.track = m_dragItem->track();
525                         int transitiontrack = getPreviousVideoTrack(info.track);
526                         ClipItem *transitionClip = NULL;
527                         if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.endPos.frames(m_document->fps()), m_tracksList.count() - transitiontrack);
528                         if (transitionClip && transitionClip->startPos() > m_dragItem->startPos()) {
529                             info.startPos = transitionClip->startPos();
530                         } else info.startPos = info.endPos - GenTime(2.5);
531                         slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
532                     }
533                     updateSnapPoints(m_dragItem);
534                     collision = true;
535                     break;
536                 }
537             }
538         if (!collision) {
539             kDebug() << "//////// NO ITEM FOUND ON CLICK";
540             m_dragItem = NULL;
541             setCursor(Qt::ArrowCursor);
542             QList<QGraphicsItem *> itemList = items();
543             for (int i = 0; i < itemList.count(); i++)
544                 itemList.at(i)->setSelected(false);
545             //emit clipItemSelected(NULL);
546             if (event->button() == Qt::RightButton) {
547                 displayContextMenu(event->globalPos());
548             } else setCursorPos((int)(mapToScene(event->x(), 0).x() / m_scale));
549         } else if (event->button() == Qt::RightButton) {
550             m_operationMode = NONE;
551             displayContextMenu(event->globalPos(), m_dragItem);
552             m_dragItem = NULL;
553         }
554         if (m_dragItem && m_dragItem->type() == AVWIDGET) emit clipItemSelected((ClipItem*) m_dragItem);
555         else emit clipItemSelected(NULL);
556     }
557     //kDebug()<<pos;
558     //QGraphicsView::mousePressEvent(event);
559 }
560
561 void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) {
562     if (m_dragItem && m_dragItem->hasKeyFrames()) {
563         if (m_moveOpMode == KEYFRAME) {
564             // user double clicked on a keyframe, open edit dialog
565             QDialog d(parentWidget());
566             Ui::KeyFrameDialog_UI view;
567             view.setupUi(&d);
568             view.kfr_position->setText(m_document->timecode().getTimecode(GenTime(m_dragItem->selectedKeyFramePos(), m_document->fps()) - m_dragItem->cropStart(), m_document->fps()));
569             view.kfr_value->setValue(m_dragItem->selectedKeyFrameValue());
570             view.kfr_value->setFocus();
571             if (d.exec() == QDialog::Accepted) {
572                 int pos = m_document->timecode().getFrameCount(view.kfr_position->text(), m_document->fps());
573                 m_dragItem->updateKeyFramePos(GenTime(pos, m_document->fps()) + m_dragItem->cropStart(), (double) view.kfr_value->value() * m_dragItem->keyFrameFactor());
574                 ClipItem *item = (ClipItem *)m_dragItem;
575                 QString previous = item->keyframes(item->selectedEffectIndex());
576                 item->updateKeyframeEffect();
577                 QString next = item->keyframes(item->selectedEffectIndex());
578                 EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
579                 m_commandStack->push(command);
580                 updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
581             }
582
583         } else  {
584             // add keyframe
585             GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x() / m_scale), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart();
586             m_dragItem->addKeyFrame(keyFramePos, mapToScene(event->pos()).toPoint().y());
587             ClipItem * item = (ClipItem *) m_dragItem;
588             QString previous = item->keyframes(item->selectedEffectIndex());
589             item->updateKeyframeEffect();
590             QString next = item->keyframes(item->selectedEffectIndex());
591             EditKeyFrameCommand *command = new EditKeyFrameCommand(this, m_dragItem->track(), m_dragItem->startPos(), item->selectedEffectIndex(), previous, next, false);
592             m_commandStack->push(command);
593             updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
594         }
595     } else if (m_dragItem) {
596         ClipDurationDialog d(m_dragItem, m_document->timecode(), this);
597         if (d.exec() == QDialog::Accepted) {
598             if (d.startPos() != m_dragItem->startPos()) {
599                 if (m_dragItem->type() == AVWIDGET) {
600                     ItemInfo startInfo;
601                     startInfo.startPos = m_dragItem->startPos();
602                     startInfo.endPos = m_dragItem->endPos();
603                     startInfo.track = m_dragItem->track();
604                     ItemInfo endInfo;
605                     endInfo.startPos = d.startPos();
606                     endInfo.endPos = m_dragItem->endPos() + (endInfo.startPos - startInfo.startPos);
607                     endInfo.track = m_dragItem->track();
608                     MoveClipCommand *command = new MoveClipCommand(this, startInfo, endInfo, true);
609                     m_commandStack->push(command);
610                 } else {
611                     //TODO: move transition
612                 }
613             }
614             if (d.duration() != m_dragItem->duration()) {
615                 if (m_dragItem->type() == AVWIDGET) {
616                     ItemInfo startInfo;
617                     startInfo.startPos = m_dragItem->startPos();
618                     startInfo.endPos = m_dragItem->endPos();
619                     startInfo.track = m_dragItem->track();
620                     ItemInfo endInfo;
621                     endInfo.startPos = startInfo.startPos;
622                     endInfo.endPos = endInfo.startPos + d.duration();
623                     endInfo.track = m_dragItem->track();
624                     ResizeClipCommand *command = new ResizeClipCommand(this, startInfo, endInfo, true);
625                     m_commandStack->push(command);
626                 } else {
627                     //TODO: resize transition
628                 }
629             }
630         }
631     } else {
632         QList<QGraphicsItem *> collisionList = items(event->pos());
633         if (collisionList.count() == 1 && collisionList.at(0)->type() == GUIDEITEM) {
634             Guide *editGuide = (Guide *) collisionList.at(0);
635             if (editGuide) slotEditGuide(editGuide->info());
636         }
637     }
638 }
639
640
641 void CustomTrackView::editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes) {
642     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), track);
643     if (clip) {
644         clip->setKeyframes(index, keyframes);
645         updateEffect(m_tracksList.count() - clip->track(), clip->startPos(), clip->effectAt(index), index);
646     } else emit displayMessage(i18n("Cannot find clip with keyframe"), ErrorMessage);
647 }
648
649
650 void CustomTrackView::displayContextMenu(QPoint pos, AbstractClipItem *clip) {
651     if (clip == NULL) m_timelineContextMenu->popup(pos);
652     else if (clip->type() == AVWIDGET) m_timelineContextClipMenu->popup(pos);
653     else if (clip->type() == TRANSITIONWIDGET) m_timelineContextTransitionMenu->popup(pos);
654 }
655
656 void CustomTrackView::activateMonitor() {
657     emit activateDocumentMonitor();
658 }
659
660 void CustomTrackView::dragEnterEvent(QDragEnterEvent * event) {
661     if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
662         kDebug() << "///////////////  DRAG ENTERED, TEXT: " << event->mimeData()->data("kdenlive/producerslist");
663         QStringList ids = QString(event->mimeData()->data("kdenlive/producerslist")).split(";");
664         //TODO: drop of several clips
665         for (int i = 0; i < ids.size(); ++i) {
666         }
667         DocClipBase *clip = m_document->getBaseClip(ids.at(0).toInt());
668         if (clip == NULL) kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << ids.at(0).toInt();
669         addItem(clip, event->pos());
670         event->acceptProposedAction();
671     } else QGraphicsView::dragEnterEvent(event);
672 }
673
674 void CustomTrackView::slotRefreshEffects(ClipItem *clip) {
675     int track = m_tracksList.count() - clip->track();
676     GenTime pos = clip->startPos();
677     if (!m_document->renderer()->mltRemoveEffect(track, pos, "-1", false)) {
678         emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
679         return;
680     }
681     bool success = true;
682     for (int i = 0; i < clip->effectsCount(); i++) {
683         if (!m_document->renderer()->mltAddEffect(track, pos, clip->getEffectArgs(clip->effectAt(i)), false)) success = false;
684     }
685     if (!success) emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
686     m_document->renderer()->doRefresh();
687 }
688
689 void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) {
690     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
691     if (clip) {
692         QMap <QString, QString> effectParams = clip->addEffect(effect);
693         if (!m_document->renderer()->mltAddEffect(track, pos, effectParams))
694             emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
695         emit clipItemSelected(clip);
696     } else emit displayMessage(i18n("Cannot find clip to add effect"), ErrorMessage);
697 }
698
699 void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) {
700     QString index = effect.attribute("kdenlive_ix");
701     if (!m_document->renderer()->mltRemoveEffect(track, pos, index)) {
702         emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
703         return;
704     }
705     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
706     if (clip) {
707         clip->deleteEffect(index);
708         emit clipItemSelected(clip);
709     }
710 }
711
712 void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) {
713     QList<QGraphicsItem *> itemList;
714     if (track == -1) itemList = scene()->selectedItems();
715     if (itemList.isEmpty()) {
716         ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, track);
717         if (clip) itemList.append(clip);
718         else emit displayMessage(i18n("Select a clip if you want to apply an effect"), ErrorMessage);
719     }
720     kDebug() << "// REQUESTING EFFECT ON CLIP: " << pos.frames(25) << ", TRK: " << track << "SELECTED ITEMS: " << itemList.count();
721     for (int i = 0; i < itemList.count(); i++) {
722         if (itemList.at(i)->type() == AVWIDGET) {
723             ClipItem *item = (ClipItem *)itemList.at(i);
724             item->initEffect(effect);
725             AddEffectCommand *command = new AddEffectCommand(this, m_tracksList.count() - item->track(), item->startPos(), effect, true);
726             m_commandStack->push(command);
727         }
728     }
729     m_document->setModified(true);
730 }
731
732 void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect) {
733     AddEffectCommand *command = new AddEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), effect, false);
734     m_commandStack->push(command);
735     m_document->setModified(true);
736 }
737
738 void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect, int ix) {
739     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
740     if (clip) {
741         QMap <QString, QString> effectParams = clip->getEffectArgs(effect);
742         if (effectParams.value("disabled") == "1") {
743             if (m_document->renderer()->mltRemoveEffect(track, pos, effectParams.value("kdenlive_ix"))) {
744                 kDebug() << "//////  DISABLING EFFECT: " << index << ", CURRENTLA: " << clip->selectedEffectIndex();
745             } else emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
746         } else if (!m_document->renderer()->mltEditEffect(m_tracksList.count() - clip->track(), clip->startPos(), effectParams))
747             emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
748         if (ix == clip->selectedEffectIndex()) {
749             clip->setSelectedEffect(clip->selectedEffectIndex());
750         }
751     }
752     m_document->setModified(true);
753 }
754
755 void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos) {
756     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
757     if (clip) {
758         m_document->renderer()->mltMoveEffect(track, pos, oldPos, newPos);
759     }
760     m_document->setModified(true);
761 }
762
763 void CustomTrackView::slotChangeEffectState(ClipItem *clip, int effectPos, bool disable) {
764     QDomElement effect = clip->effectAt(effectPos);
765     QDomElement oldEffect = effect.cloneNode().toElement();
766     effect.setAttribute("disabled", disable);
767     EditEffectCommand *command = new EditEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), oldEffect, effect, effectPos, true);
768     m_commandStack->push(command);
769     m_document->setModified(true);
770 }
771
772 void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos) {
773     MoveEffectCommand *command = new MoveEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), currentPos, newPos, true);
774     m_commandStack->push(command);
775     m_document->setModified(true);
776 }
777
778 void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect, int ix) {
779     EditEffectCommand *command = new EditEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), oldeffect, effect, ix, true);
780     m_commandStack->push(command);
781 }
782
783 void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) {
784     if (cut) {
785         // cut clip
786         ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
787         if (!item) {
788             emit displayMessage(i18n("Cannot find clip to cut"), ErrorMessage);
789             return;
790         }
791         int cutPos = (int) cutTime.frames(m_document->fps());
792         ItemInfo newPos;
793         newPos.startPos = cutTime;
794         newPos.endPos = info.endPos;
795         newPos.track = info.track;
796         item->resizeEnd(cutPos, m_scale);
797         ClipItem *dup = new ClipItem(item->baseClip(), newPos, item->cropStart() + (cutTime - info.startPos), m_scale, m_document->fps());
798         scene()->addItem(dup);
799         m_document->renderer()->mltCutClip(m_tracksList.count() - info.track, cutTime);
800         item->baseClip()->addReference();
801         m_document->updateClip(item->baseClip()->getId());
802     } else {
803         // uncut clip
804         ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
805         ClipItem *dup = getClipItemAt((int) cutTime.frames(m_document->fps()), info.track);
806         if (!item || !dup) {
807             emit displayMessage(i18n("Cannot find clip to uncut"), ErrorMessage);
808             return;
809         }
810         delete dup;
811         item->baseClip()->removeReference();
812         m_document->updateClip(item->baseClip()->getId());
813         item->resizeEnd((int) info.endPos.frames(m_document->fps()), m_scale);
814         m_document->renderer()->mltRemoveClip(m_tracksList.count() - info.track, cutTime);
815         m_document->renderer()->mltResizeClipEnd(m_tracksList.count() - info.track, info.startPos, item->cropStart(), item->cropStart() + info.endPos - info.startPos);
816     }
817 }
818
819
820 void CustomTrackView::slotAddTransitionToSelectedClips(QDomElement transition) {
821     QList<QGraphicsItem *> itemList = scene()->selectedItems();
822     for (int i = 0; i < itemList.count(); i++) {
823         if (itemList.at(i)->type() == AVWIDGET) {
824             ClipItem *item = (ClipItem *) itemList.at(i);
825             ItemInfo info;
826             info.startPos = item->startPos();
827             info.endPos = info.startPos + GenTime(2.5);
828             info.track = item->track();
829             int transitiontrack = getPreviousVideoTrack(info.track);
830             slotAddTransition(item, info, transitiontrack, transition);
831         }
832     }
833 }
834
835 void CustomTrackView::slotAddTransition(ClipItem* clip, ItemInfo transitionInfo, int endTrack, QDomElement transition) {
836     AddTransitionCommand* command = new AddTransitionCommand(this, transitionInfo, endTrack, transition, false, true);
837     m_commandStack->push(command);
838     m_document->setModified(true);
839 }
840
841 void CustomTrackView::addTransition(ItemInfo transitionInfo, int endTrack, QDomElement params) {
842     Transition *tr = new Transition(transitionInfo, endTrack, m_scale, m_document->fps(), params);
843     scene()->addItem(tr);
844
845     //kDebug() << "---- ADDING transition " << e.attribute("tag") << ", on tracks " << m_tracksList.count() - e.attribute("transition_track").toInt() << " / " << getPreviousVideoTrack(e.attribute("transition_track").toInt());
846     m_document->renderer()->mltAddTransition(tr->transitionTag(), endTrack, m_tracksList.count() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, tr->toXML());
847     m_document->setModified(true);
848 }
849
850 void CustomTrackView::deleteTransition(ItemInfo transitionInfo, int endTrack, QDomElement params) {
851     Transition *item = getTransitionItemAt((int)transitionInfo.startPos.frames(m_document->fps()) + 1, transitionInfo.track);
852     m_document->renderer()->mltDeleteTransition(item->transitionTag(), endTrack, m_tracksList.count() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, item->toXML());
853     delete item;
854     emit transitionItemSelected(NULL);
855     m_document->setModified(true);
856 }
857
858 void CustomTrackView::slotTransitionUpdated(Transition *tr, QDomElement old) {
859     EditTransitionCommand *command = new EditTransitionCommand(this, tr->track(), tr->startPos(), old, tr->toXML() , true);
860     m_commandStack->push(command);
861     m_document->setModified(true);
862 }
863
864 void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTransition, QDomElement transition) {
865     Transition *item = getTransitionItemAt((int)pos.frames(m_document->fps()) + 1, track);
866     if (!item) {
867         kWarning() << "Unable to find transition at pos :" << pos.frames(m_document->fps()) << ", ON track: " << track;
868         return;
869     }
870     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);
871     item->setTransitionParameters(transition);
872     m_document->setModified(true);
873 }
874
875 void CustomTrackView::addItem(DocClipBase *clip, QPoint pos) {
876     ItemInfo info;
877     info.startPos = GenTime((int)(mapToScene(pos).x() / m_scale), m_document->fps());
878     info.endPos = info.startPos + clip->duration();
879     info.track = (int)(pos.y() / m_tracksHeight);
880     //kDebug()<<"------------  ADDING CLIP ITEM----: "<<info.startPos.frames(25)<<", "<<info.endPos.frames(25)<<", "<<info.track;
881     m_dropItem = new ClipItem(clip, info, GenTime(), m_scale, m_document->fps());
882     scene()->addItem(m_dropItem);
883 }
884
885
886 void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) {
887     event->setDropAction(Qt::IgnoreAction);
888     if (m_dropItem) {
889         int track = (int)(mapToScene(event->pos()).y() / m_tracksHeight);  //) * (m_scale * 50) + m_scale;
890         m_dropItem->moveTo((int)(mapToScene(event->pos()).x() / m_scale), m_scale, (int)((track - m_dropItem->track()) * m_tracksHeight), track);
891         event->setDropAction(Qt::MoveAction);
892         if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
893             event->acceptProposedAction();
894         }
895     } else {
896         QGraphicsView::dragMoveEvent(event);
897     }
898 }
899
900 void CustomTrackView::dragLeaveEvent(QDragLeaveEvent * event) {
901     if (m_dropItem) {
902         delete m_dropItem;
903         m_dropItem = NULL;
904     } else QGraphicsView::dragLeaveEvent(event);
905 }
906
907 void CustomTrackView::dropEvent(QDropEvent * event) {
908     if (m_dropItem) {
909         ItemInfo info;
910         info.startPos = m_dropItem->startPos();
911         info.endPos = m_dropItem->endPos();
912         info.track = m_dropItem->track();
913         AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->clipProducer(), info, false, false);
914         m_commandStack->push(command);
915         m_dropItem->baseClip()->addReference();
916         m_document->updateClip(m_dropItem->baseClip()->getId());
917         // kDebug()<<"IIIIIIIIIIIIIIIIIIIIIIII TRAX CNT: "<<m_tracksList.count()<<", DROP: "<<m_dropItem->track();
918         m_document->renderer()->mltInsertClip(m_tracksList.count() - m_dropItem->track(), m_dropItem->startPos(), m_dropItem->xml());
919         m_document->setModified(true);
920     } else QGraphicsView::dropEvent(event);
921     m_dropItem = NULL;
922 }
923
924
925 QStringList CustomTrackView::mimeTypes() const {
926     QStringList qstrList;
927     // list of accepted mime types for drop
928     qstrList.append("text/plain");
929     qstrList.append("kdenlive/producerslist");
930     return qstrList;
931 }
932
933 Qt::DropActions CustomTrackView::supportedDropActions() const {
934     // returns what actions are supported when dropping
935     return Qt::MoveAction;
936 }
937
938 void CustomTrackView::setDuration(int duration) {
939     kDebug() << "/////////////  PRO DUR: " << duration << ", SCALE. " << (m_projectDuration + 500) * m_scale << ", height: " << 50 * m_tracksList.count();
940     m_projectDuration = duration;
941     setSceneRect(0, 0, (m_projectDuration + 100) * m_scale, sceneRect().height());
942 }
943
944 int CustomTrackView::duration() const {
945     return m_projectDuration;
946 }
947
948 void CustomTrackView::addTrack(TrackInfo type) {
949     m_tracksList << type;
950     m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_tracksList.count());
951     setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_tracksList.count());
952     verticalScrollBar()->setMaximum(m_tracksHeight * m_tracksList.count());
953     //setFixedHeight(50 * m_tracksCount);
954 }
955
956 void CustomTrackView::removeTrack() {
957     // TODO: implement track deletion
958     //m_tracksCount--;
959     m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_tracksList.count());
960 }
961
962
963 void CustomTrackView::slotSwitchTrackAudio(int ix) {
964     int tracknumber = m_tracksList.count() - ix;
965     kDebug() << "/////  MUTING TRK: " << ix << "; PL NUM: " << tracknumber;
966     m_tracksList[tracknumber - 1].isMute = !m_tracksList.at(tracknumber - 1).isMute;
967     m_document->renderer()->mltChangeTrackState(tracknumber, m_tracksList.at(tracknumber - 1).isMute, m_tracksList.at(tracknumber - 1).isBlind);
968 }
969
970 void CustomTrackView::slotSwitchTrackVideo(int ix) {
971     int tracknumber = m_tracksList.count() - ix;
972     m_tracksList[tracknumber - 1].isBlind = !m_tracksList.at(tracknumber - 1).isBlind;
973     m_document->renderer()->mltChangeTrackState(tracknumber, m_tracksList.at(tracknumber - 1).isMute, m_tracksList.at(tracknumber - 1).isBlind);
974 }
975
976 void CustomTrackView::deleteClip(int clipId) {
977     QList<QGraphicsItem *> itemList = items();
978     for (int i = 0; i < itemList.count(); i++) {
979         if (itemList.at(i)->type() == AVWIDGET) {
980             ClipItem *item = (ClipItem *)itemList.at(i);
981             if (item->clipProducer() == clipId) {
982                 ItemInfo info;
983                 info.startPos = item->startPos();
984                 info.endPos = item->endPos();
985                 info.track = item->track();
986                 AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), info, true, true);
987                 m_commandStack->push(command);
988                 //delete item;
989             }
990         }
991     }
992 }
993
994 void CustomTrackView::setCursorPos(int pos, bool seek) {
995     emit cursorMoved((int)(m_cursorPos * m_scale), (int)(pos * m_scale));
996     m_cursorPos = pos;
997     m_cursorLine->setPos(pos * m_scale, 0);
998     if (seek) m_document->renderer()->seek(GenTime(pos, m_document->fps()));
999     else if (m_autoScroll && m_scale < 50) checkScrolling();
1000 }
1001
1002 void CustomTrackView::updateCursorPos() {
1003     m_cursorLine->setPos(m_cursorPos * m_scale, 0);
1004 }
1005
1006 int CustomTrackView::cursorPos() {
1007     return (int)(m_cursorPos * m_scale);
1008 }
1009
1010 void CustomTrackView::moveCursorPos(int delta) {
1011     if (m_cursorPos + delta < 0) delta = 0 - m_cursorPos;
1012     emit cursorMoved((int)(m_cursorPos * m_scale), (int)((m_cursorPos + delta) * m_scale));
1013     m_cursorPos += delta;
1014     m_cursorLine->setPos(m_cursorPos * m_scale, 0);
1015     m_document->renderer()->seek(GenTime(m_cursorPos, m_document->fps()));
1016     //if (m_autoScroll && m_scale < 50) checkScrolling();
1017 }
1018
1019 void CustomTrackView::checkScrolling() {
1020     int vert = verticalScrollBar()->value();
1021     int hor = cursorPos();
1022     ensureVisible(hor, vert + 10, 2, 2, 50, 0);
1023     //centerOn(QPointF(cursorPos(), m_tracksHeight));
1024     /*QRect rectInView = viewport()->rect();
1025     int delta = rectInView.width() / 3;
1026     int max = rectInView.right() + horizontalScrollBar()->value() - delta;
1027     //kDebug() << "CURSOR POS: "<<m_cursorPos<< "Scale: "<<m_scale;
1028     if (m_cursorPos * m_scale >= max) horizontalScrollBar()->setValue((int)(horizontalScrollBar()->value() + 1 + m_scale));*/
1029 }
1030
1031 void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
1032     if (event->button() == Qt::MidButton) {
1033         return;
1034     }
1035     QGraphicsView::mouseReleaseEvent(event);
1036     setDragMode(QGraphicsView::NoDrag);
1037     if (m_operationMode == MOVEGUIDE) {
1038         setCursor(Qt::ArrowCursor);
1039         m_operationMode = NONE;
1040         m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, false);
1041         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);
1042         m_commandStack->push(command);
1043         m_dragGuide->updateGuide(GenTime(m_dragGuide->pos().x() / m_scale, m_document->fps()));
1044         m_dragGuide = NULL;
1045         m_dragItem = NULL;
1046         return;
1047     }
1048     if (m_dragItem == NULL) {
1049         emit transitionItemSelected(NULL);
1050         return;
1051     }
1052     ItemInfo info;
1053     info.startPos = m_dragItem->startPos();
1054     info.endPos = m_dragItem->endPos();
1055     info.track = m_dragItem->track();
1056
1057     if (m_operationMode == MOVE) {
1058         setCursor(Qt::OpenHandCursor);
1059         // move clip
1060         if (m_dragItem->type() == AVWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
1061             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())));
1062             if (success) {
1063                 MoveClipCommand *command = new MoveClipCommand(this, m_dragItemInfo, info, false);
1064                 m_commandStack->push(command);
1065             } else {
1066                 // undo last move and emit error message
1067                 MoveClipCommand *command = new MoveClipCommand(this, info, m_dragItemInfo, true);
1068                 m_commandStack->push(command);
1069                 emit displayMessage(i18n("Cannot move clip to position %1seconds", QString::number(m_dragItemInfo.startPos.seconds(), 'g', 2)), ErrorMessage);
1070             }
1071         }
1072         if (m_dragItem->type() == TRANSITIONWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
1073             MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false);
1074             m_commandStack->push(command);
1075             Transition *transition = (Transition *) m_dragItem;
1076             transition->updateTransitionEndTrack(getPreviousVideoTrack(m_dragItem->track()));
1077             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);
1078         }
1079
1080     } else if (m_operationMode == RESIZESTART && m_dragItem->startPos() != m_dragItemInfo.startPos) {
1081         // resize start
1082         if (m_dragItem->type() == AVWIDGET) {
1083             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());
1084             updateClipFade((ClipItem *) m_dragItem);
1085             ResizeClipCommand *command = new ResizeClipCommand(this, m_dragItemInfo, info, false);
1086             m_commandStack->push(command);
1087         } else if (m_dragItem->type() == TRANSITIONWIDGET) {
1088             MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false);
1089             m_commandStack->push(command);
1090             Transition *transition = (Transition *) m_dragItem;
1091             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);
1092         }
1093
1094         //m_document->renderer()->doRefresh();
1095     } else if (m_operationMode == RESIZEEND && m_dragItem->endPos() != m_dragItemInfo.endPos) {
1096         // resize end
1097         if (m_dragItem->type() == AVWIDGET) {
1098             ResizeClipCommand *command = new ResizeClipCommand(this, m_dragItemInfo, info, false);
1099             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());
1100             m_commandStack->push(command);
1101         } else if (m_dragItem->type() == TRANSITIONWIDGET) {
1102             MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false);
1103             m_commandStack->push(command);
1104             Transition *transition = (Transition *) m_dragItem;
1105             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);
1106         }
1107         //m_document->renderer()->doRefresh();
1108     } else if (m_operationMode == FADEIN) {
1109         // resize fade in effect
1110         ClipItem * item = (ClipItem *) m_dragItem;
1111         QStringList clipeffects = item->effectNames();
1112         if (clipeffects.contains(i18n("Fade in"))) {
1113             int ix = clipeffects.indexOf(i18n("Fade in"));
1114             QDomElement oldeffect = item->effectAt(ix);
1115             int start = item->cropStart().frames(m_document->fps());
1116             int end = item->fadeIn();
1117             if (end == 0) {
1118                 slotDeleteEffect(item, oldeffect);
1119             } else {
1120                 end += start;
1121                 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade in");
1122                 EffectsList::setParameter(effect, "in", QString::number(start));
1123                 EffectsList::setParameter(effect, "out", QString::number(end));
1124                 slotUpdateClipEffect(item, oldeffect, effect, ix);
1125             }
1126         } else if (item->fadeIn() != 0) {
1127             QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade in");
1128             int start = item->cropStart().frames(m_document->fps());
1129             int end = item->fadeIn() + start;
1130             EffectsList::setParameter(effect, "in", QString::number(start));
1131             EffectsList::setParameter(effect, "out", QString::number(end));
1132             slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
1133         }
1134     } else if (m_operationMode == FADEOUT) {
1135         // resize fade in effect
1136         ClipItem * item = (ClipItem *) m_dragItem;
1137         QStringList clipeffects = item->effectNames();
1138         if (clipeffects.contains(i18n("Fade out"))) {
1139             int ix = clipeffects.indexOf(i18n("Fade out"));
1140             QDomElement oldeffect = item->effectAt(ix);
1141             int end = (item->duration() + item->cropStart()).frames(m_document->fps());
1142             int start = item->fadeOut();
1143             if (start == 0) {
1144                 slotDeleteEffect(item, oldeffect);
1145             } else {
1146                 start = end - start;
1147                 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade out");
1148                 EffectsList::setParameter(effect, "in", QString::number(start));
1149                 EffectsList::setParameter(effect, "out", QString::number(end));
1150                 slotUpdateClipEffect(item, oldeffect, effect, ix);
1151             }
1152         } else if (item->fadeOut() != 0) {
1153             QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade out");
1154             int end = (item->duration() + item->cropStart()).frames(m_document->fps());
1155             int start = end - item->fadeOut();
1156             EffectsList::setParameter(effect, "in", QString::number(start));
1157             EffectsList::setParameter(effect, "out", QString::number(end));
1158             slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
1159         }
1160     } else if (m_operationMode == KEYFRAME) {
1161         // update the MLT effect
1162         ClipItem * item = (ClipItem *) m_dragItem;
1163         QString previous = item->keyframes(item->selectedEffectIndex());
1164         item->updateKeyframeEffect();
1165         QString next = item->keyframes(item->selectedEffectIndex());
1166         EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
1167         m_commandStack->push(command);
1168         updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
1169     }
1170
1171     emit transitionItemSelected((m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) ? (Transition*) m_dragItem : NULL);
1172     m_document->setModified(true);
1173     m_operationMode = NONE;
1174 }
1175
1176 void CustomTrackView::deleteClip(ItemInfo info) {
1177     ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
1178     if (!item) {
1179         kDebug() << "----------------  ERROR, CANNOT find clip to move at...";// << rect.x();
1180         return;
1181     }
1182     if (item->isSelected()) emit clipItemSelected(NULL);
1183     item->baseClip()->removeReference();
1184     m_document->updateClip(item->baseClip()->getId());
1185     delete item;
1186     m_document->renderer()->mltRemoveClip(m_tracksList.count() - info.track, info.startPos);
1187     m_document->renderer()->doRefresh();
1188 }
1189
1190 void CustomTrackView::deleteSelectedClips() {
1191
1192     QUndoCommand *deleteSelected = new QUndoCommand();
1193     deleteSelected->setText("Delete selected items");
1194
1195     QList<QGraphicsItem *> itemList = scene()->selectedItems();
1196     for (int i = 0; i < itemList.count(); i++) {
1197         if (itemList.at(i)->type() == AVWIDGET) {
1198             ClipItem *item = (ClipItem *) itemList.at(i);
1199             ItemInfo info;
1200             info.startPos = item->startPos();
1201             info.endPos = item->endPos();
1202             info.track = item->track();
1203             new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), info, true, true, deleteSelected);
1204         } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
1205             Transition *item = (Transition *) itemList.at(i);
1206             ItemInfo info;
1207             info.startPos = item->startPos();
1208             info.endPos = item->endPos();
1209             info.track = item->track();
1210             new AddTransitionCommand(this, info, item->transitionEndTrack(), QDomElement(), true, true, deleteSelected);
1211         }
1212     }
1213     m_commandStack->push(deleteSelected);
1214 }
1215
1216 void CustomTrackView::cutSelectedClips() {
1217     QList<QGraphicsItem *> itemList = scene()->selectedItems();
1218     GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
1219     for (int i = 0; i < itemList.count(); i++) {
1220         if (itemList.at(i)->type() == AVWIDGET) {
1221             ClipItem *item = (ClipItem *) itemList.at(i);
1222             ItemInfo info;
1223             info.startPos = item->startPos();
1224             info.endPos = item->endPos();
1225             if (currentPos > info.startPos && currentPos <  info.endPos) {
1226                 info.track = item->track();
1227                 RazorClipCommand *command = new RazorClipCommand(this, info, currentPos, true);
1228                 m_commandStack->push(command);
1229             }
1230         }
1231     }
1232 }
1233
1234 void CustomTrackView::addClip(QDomElement xml, int clipId, ItemInfo info) {
1235     DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId);
1236     int crop = xml.attribute("in").toInt();
1237     ClipItem *item = new ClipItem(baseclip, info, GenTime(crop, m_document->fps()), m_scale, m_document->fps());
1238     scene()->addItem(item);
1239     baseclip->addReference();
1240     m_document->updateClip(baseclip->getId());
1241     m_document->renderer()->mltInsertClip(m_tracksList.count() - info.track, info.startPos, xml);
1242     m_document->renderer()->doRefresh();
1243 }
1244
1245 void CustomTrackView::slotUpdateClip(int clipId) {
1246     QList<QGraphicsItem *> list = scene()->items();
1247     ClipItem *clip = NULL;
1248     for (int i = 0; i < list.size(); ++i) {
1249         if (list.at(i)->type() == AVWIDGET) {
1250             clip = static_cast <ClipItem *>(list.at(i));
1251             if (clip->clipProducer() == clipId) {
1252                 clip->refreshClip();
1253                 m_document->renderer()->mltUpdateClip(m_tracksList.count() - clip->track(), clip->startPos(), clip->xml());
1254             }
1255         }
1256     }
1257 }
1258
1259 ClipItem *CustomTrackView::getClipItemAt(int pos, int track) {
1260     QList<QGraphicsItem *> list = scene()->items(QPointF(pos * m_scale, track * m_tracksHeight + m_tracksHeight / 2));
1261     ClipItem *clip = NULL;
1262     for (int i = 0; i < list.size(); ++i) {
1263         if (list.at(i)->type() == AVWIDGET) {
1264             clip = static_cast <ClipItem *>(list.at(i));
1265             break;
1266         }
1267     }
1268     return clip;
1269 }
1270
1271 ClipItem *CustomTrackView::getClipItemAt(GenTime pos, int track) {
1272     int framepos = (int)(pos.frames(m_document->fps()) * m_scale);
1273     return getClipItemAt(framepos, track);
1274 }
1275
1276 Transition *CustomTrackView::getTransitionItemAt(int pos, int track) {
1277     QList<QGraphicsItem *> list = scene()->items(QPointF(pos * m_scale, (track + 1) * m_tracksHeight));
1278     Transition *clip = NULL;
1279     for (int i = 0; i < list.size(); ++i) {
1280         if (list.at(i)->type() == TRANSITIONWIDGET) {
1281             clip = static_cast <Transition *>(list.at(i));
1282             break;
1283         }
1284     }
1285     return clip;
1286 }
1287
1288 Transition *CustomTrackView::getTransitionItemAt(GenTime pos, int track) {
1289     int framepos = (int)(pos.frames(m_document->fps()) * m_scale);
1290     return getTransitionItemAt(framepos, track);
1291 }
1292
1293 void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end) {
1294     ClipItem *item = getClipItemAt((int) start.startPos.frames(m_document->fps()) + 1, start.track);
1295     if (!item) {
1296         emit displayMessage(i18n("Cannot move clip at time: %1s on track %2", QString::number(start.startPos.seconds(), 'g', 2), start.track), ErrorMessage);
1297         kDebug() << "----------------  ERROR, CANNOT find clip to move at.. ";// << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2;
1298         return;
1299     }
1300     //kDebug() << "----------------  Move CLIP FROM: " << startPos.x() << ", END:" << endPos.x() << ",TRACKS: " << startPos.y() << " TO " << endPos.y();
1301
1302     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()));
1303     if (success) {
1304         item->moveTo((int) end.startPos.frames(m_document->fps()), m_scale, (int)((end.track - start.track) * m_tracksHeight), end.track);
1305     } else {
1306         // undo last move and emit error message
1307         emit displayMessage(i18n("Cannot move clip to position %1seconds", QString::number(end.startPos.seconds(), 'g', 2)), ErrorMessage);
1308     }
1309 }
1310
1311 void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end) {
1312     Transition *item = getTransitionItemAt((int)start.startPos.frames(m_document->fps()) + 1, start.track);
1313     if (!item) {
1314         emit displayMessage(i18n("Cannot move transition at time: %1s on track %2", start.startPos.seconds(), start.track), ErrorMessage);
1315         kDebug() << "----------------  ERROR, CANNOT find transition to move... ";// << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2;
1316         return;
1317     }
1318     //kDebug() << "----------------  Move TRANSITION FROM: " << startPos.x() << ", END:" << endPos.x() << ",TRACKS: " << oldtrack << " TO " << newtrack;
1319
1320     //kDebug()<<"///  RESIZE TRANS START: ("<< startPos.x()<<"x"<< startPos.y()<<") / ("<<endPos.x()<<"x"<< endPos.y()<<")";
1321     if (end.endPos - end.startPos == start.endPos - start.startPos) {
1322         // Transition was moved
1323         item->moveTo((int) end.startPos.frames(m_document->fps()), m_scale, (end.track - start.track) * m_tracksHeight, end.track);
1324     } else if (end.endPos == start.endPos) {
1325         // Transition start resize
1326         item->resizeStart((int) end.startPos.frames(m_document->fps()), m_scale);
1327     } else {
1328         // Transition end resize;
1329         item->resizeEnd((int) end.endPos.frames(m_document->fps()), m_scale);
1330     }
1331     //item->moveTransition(GenTime((int) (endPos.x() - startPos.x()), m_document->fps()));
1332     item->updateTransitionEndTrack(getPreviousVideoTrack(end.track));
1333     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);
1334 }
1335
1336 void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end) {
1337     int offset = 0;
1338     bool resizeClipStart = true;
1339     if (start.startPos == end.startPos) resizeClipStart = false;
1340     /*if (resizeClipStart) offset = 1;
1341     else offset = -1;*/
1342     ClipItem *item = getClipItemAt((int)(start.startPos.frames(m_document->fps()) + offset), start.track);
1343     if (!item) {
1344         emit displayMessage(i18n("Cannot move clip at time: %1s on track %2", start.startPos.seconds(), start.track), ErrorMessage);
1345         kDebug() << "----------------  ERROR, CANNOT find clip to resize at... "; // << startPos;
1346         return;
1347     }
1348     if (resizeClipStart) {
1349         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);
1350         item->resizeStart((int) end.startPos.frames(m_document->fps()), m_scale);
1351         updateClipFade(item);
1352     } else {
1353         m_document->renderer()->mltResizeClipEnd(m_tracksList.count() - item->track(), item->startPos(), item->cropStart(), item->cropStart() + end.endPos - item->startPos());
1354         item->resizeEnd((int) end.endPos.frames(m_document->fps()), m_scale);
1355         updateClipFade(item, true);
1356     }
1357     m_document->renderer()->doRefresh();
1358 }
1359
1360 void CustomTrackView::updateClipFade(ClipItem * item, bool updateFadeOut) {
1361     if (!updateFadeOut) {
1362         int end = item->fadeIn();
1363         if (end != 0) {
1364             // there is a fade in effect
1365             QStringList clipeffects = item->effectNames();
1366             QDomElement oldeffect = item->effectAt(clipeffects.indexOf("Fade in"));
1367             int start = item->cropStart().frames(m_document->fps());
1368             end += start;
1369             EffectsList::setParameter(oldeffect, "in", QString::number(start));
1370             EffectsList::setParameter(oldeffect, "out", QString::number(end));
1371             QMap <QString, QString> effectParams = item->getEffectArgs(oldeffect);
1372             if (!m_document->renderer()->mltEditEffect(m_tracksList.count() - item->track(), item->startPos(), effectParams))
1373                 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
1374         }
1375     } else {
1376         int start = item->fadeOut();
1377         if (start != 0) {
1378             // there is a fade in effect
1379             QStringList clipeffects = item->effectNames();
1380             QDomElement oldeffect = item->effectAt(clipeffects.indexOf("Fade out"));
1381             int end = (item->duration() - item->cropStart()).frames(m_document->fps());
1382             start = end - start;
1383             EffectsList::setParameter(oldeffect, "in", QString::number(start));
1384             EffectsList::setParameter(oldeffect, "out", QString::number(end));
1385             QMap <QString, QString> effectParams = item->getEffectArgs(oldeffect);
1386             if (m_document->renderer()->mltEditEffect(m_tracksList.count() - item->track(), item->startPos(), effectParams))
1387                 emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
1388         }
1389     }
1390 }
1391
1392 double CustomTrackView::getSnapPointForPos(double pos) {
1393     for (int i = 0; i < m_snapPoints.size(); ++i) {
1394         if (abs((int)(pos - m_snapPoints.at(i).frames(m_document->fps()) * m_scale)) < 10) {
1395             //kDebug()<<" FOUND SNAP POINT AT: "<<m_snapPoints.at(i)<<", current pos: "<<pos / m_scale;
1396             return m_snapPoints.at(i).frames(m_document->fps()) * m_scale + 0.5;
1397         }
1398         if (m_snapPoints.at(i).frames(m_document->fps() * m_scale) > pos) break;
1399     }
1400     return pos;
1401 }
1402
1403 void CustomTrackView::updateSnapPoints(AbstractClipItem *selected) {
1404     m_snapPoints.clear();
1405     if (!KdenliveSettings::snaptopoints()) return;
1406     GenTime offset;
1407     if (selected) offset = selected->duration();
1408     QList<QGraphicsItem *> itemList = items();
1409     for (int i = 0; i < itemList.count(); i++) {
1410         if (itemList.at(i)->type() == AVWIDGET && itemList.at(i) != selected) {
1411             ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1412             GenTime start = item->startPos();
1413             GenTime end = item->endPos();
1414             m_snapPoints.append(start);
1415             m_snapPoints.append(end);
1416             QList < GenTime > markers = item->snapMarkers();
1417             for (int i = 0; i < markers.size(); ++i) {
1418                 GenTime t = markers.at(i);
1419                 m_snapPoints.append(t);
1420                 if (t > offset) m_snapPoints.append(t - offset);
1421             }
1422             if (offset != GenTime()) {
1423                 if (start > offset) m_snapPoints.append(start - offset);
1424                 if (end > offset) m_snapPoints.append(end - offset);
1425             }
1426         } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
1427             Transition *transition = static_cast <Transition*>(itemList.at(i));
1428             GenTime start = transition->startPos();
1429             GenTime end = transition->endPos();
1430             m_snapPoints.append(start);
1431             m_snapPoints.append(end);
1432             if (offset != GenTime()) {
1433                 if (start > offset) m_snapPoints.append(start - offset);
1434                 if (end > offset) m_snapPoints.append(end - offset);
1435             }
1436         }
1437     }
1438
1439     // add cursor position
1440     GenTime pos = GenTime(m_cursorPos, m_document->fps());
1441     m_snapPoints.append(pos);
1442     if (offset != GenTime()) m_snapPoints.append(pos - offset);
1443
1444     // add guides
1445     for (int i = 0; i < m_guides.count(); i++) {
1446         m_snapPoints.append(m_guides.at(i)->position());
1447         if (offset != GenTime()) m_snapPoints.append(m_guides.at(i)->position() - offset);
1448     }
1449
1450     qSort(m_snapPoints);
1451     //for (int i = 0; i < m_snapPoints.size(); ++i)
1452     //    kDebug() << "SNAP POINT: " << m_snapPoints.at(i).frames(25);
1453 }
1454
1455 void CustomTrackView::slotSeekToPreviousSnap() {
1456     updateSnapPoints(NULL);
1457     GenTime pos = GenTime(m_cursorPos, m_document->fps());
1458     GenTime res = GenTime();
1459     for (int i = 0; i < m_snapPoints.size(); ++i) {
1460         if (m_snapPoints.at(i) >= pos) {
1461             if (i == 0) i = 1;
1462             res = m_snapPoints.at(i - 1);
1463             break;
1464         }
1465     }
1466     setCursorPos((int) res.frames(m_document->fps()));
1467     checkScrolling();
1468 }
1469
1470 void CustomTrackView::slotSeekToNextSnap() {
1471     updateSnapPoints(NULL);
1472     GenTime pos = GenTime(m_cursorPos, m_document->fps());
1473     GenTime res = GenTime(m_projectDuration, m_document->fps());
1474     for (int i = 0; i < m_snapPoints.size(); ++i) {
1475         if (m_snapPoints.at(i) > pos) {
1476             res = m_snapPoints.at(i);
1477             break;
1478         }
1479     }
1480     setCursorPos((int) res.frames(m_document->fps()));
1481     checkScrolling();
1482 }
1483
1484 void CustomTrackView::clipStart() {
1485     QList<QGraphicsItem *> itemList = scene()->selectedItems();
1486     for (int i = 0; i < itemList.count(); i++) {
1487         if (itemList.at(i)->type() == AVWIDGET) {
1488             ClipItem *item = (ClipItem *) itemList.at(i);
1489             setCursorPos((int) item->startPos().frames(m_document->fps()));
1490             checkScrolling();
1491             break;
1492         }
1493     }
1494 }
1495
1496 void CustomTrackView::clipEnd() {
1497     QList<QGraphicsItem *> itemList = scene()->selectedItems();
1498     for (int i = 0; i < itemList.count(); i++) {
1499         if (itemList.at(i)->type() == AVWIDGET) {
1500             ClipItem *item = (ClipItem *) itemList.at(i);
1501             setCursorPos((int) item->endPos().frames(m_document->fps()));
1502             checkScrolling();
1503             break;
1504         }
1505     }
1506 }
1507
1508 void CustomTrackView::slotAddClipMarker() {
1509     QList<QGraphicsItem *> itemList = scene()->selectedItems();
1510     if (itemList.count() != 1) {
1511         emit displayMessage(i18n("Cannot add marker if more than one clip is selected"), ErrorMessage);
1512         kDebug() << "// CANNOT ADD MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1513         return;
1514     }
1515     AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1516     if (item->type() != AVWIDGET) return;
1517     GenTime pos = GenTime(m_cursorPos, m_document->fps());
1518     if (item->startPos() > pos || item->endPos() < pos) return;
1519     ClipItem *clip = (ClipItem *) item;
1520     int id = clip->baseClip()->getId();
1521     GenTime position = pos - item->startPos() + item->cropStart();
1522     CommentedTime marker(position, i18n("Marker"));
1523     MarkerDialog d(clip->baseClip(), marker, m_document->timecode(), this);
1524     if (d.exec() == QDialog::Accepted) {
1525         slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1526     }
1527 }
1528
1529 void CustomTrackView::slotAddClipMarker(int id, GenTime t, QString c) {
1530     QString oldcomment = m_document->clipManager()->getClipById(id)->markerComment(t);
1531     AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, c, id, t, true);
1532     m_commandStack->push(command);
1533 }
1534
1535 void CustomTrackView::slotDeleteClipMarker() {
1536     QList<QGraphicsItem *> itemList = scene()->selectedItems();
1537     if (itemList.count() != 1) {
1538         emit displayMessage(i18n("Cannot delete marker if more than one clip is selected"), ErrorMessage);
1539         kDebug() << "// CANNOT DELETE MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1540         return;
1541     }
1542     AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1543     if (item->type() != AVWIDGET) {
1544         emit displayMessage(i18n("No clip selected"), ErrorMessage);
1545         return;
1546     }
1547     GenTime pos = GenTime(m_cursorPos, m_document->fps());
1548     if (item->startPos() > pos || item->endPos() < pos) {
1549         emit displayMessage(i18n("No selected clip at cursor time"), ErrorMessage);
1550         return;
1551     }
1552     ClipItem *clip = (ClipItem *) item;
1553     int id = clip->baseClip()->getId();
1554     GenTime position = pos - item->startPos() + item->cropStart();
1555     QString comment = clip->baseClip()->markerComment(position);
1556     if (comment.isEmpty()) {
1557         emit displayMessage(i18n("No marker found at cursor time"), ErrorMessage);
1558         return;
1559     }
1560     AddMarkerCommand *command = new AddMarkerCommand(this, comment, QString(), id, position, true);
1561     m_commandStack->push(command);
1562 }
1563
1564 void CustomTrackView::slotDeleteAllClipMarkers() {
1565     QList<QGraphicsItem *> itemList = scene()->selectedItems();
1566     if (itemList.count() != 1) {
1567         emit displayMessage(i18n("Cannot delete marker if more than one clip is selected"), ErrorMessage);
1568         kDebug() << "// CANNOT DELETE MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1569         return;
1570     }
1571     AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1572     if (item->type() != AVWIDGET) {
1573         emit displayMessage(i18n("No clip selected"), ErrorMessage);
1574         return;
1575     }
1576
1577     ClipItem *clip = static_cast <ClipItem *>(item);
1578     QList <CommentedTime> markers = clip->baseClip()->commentedSnapMarkers();
1579
1580     if (markers.isEmpty()) {
1581         emit displayMessage(i18n("Clip has no markers"), ErrorMessage);
1582         return;
1583     }
1584     int id = clip->baseClip()->getId();
1585     QUndoCommand *deleteMarkers = new QUndoCommand();
1586     deleteMarkers->setText("Delete clip markers");
1587
1588     for (int i = 0; i < markers.size(); i++) {
1589         new AddMarkerCommand(this, markers.at(i).comment(), QString(), id, markers.at(i).time(), true, deleteMarkers);
1590     }
1591     m_commandStack->push(deleteMarkers);
1592 }
1593
1594 void CustomTrackView::slotEditClipMarker() {
1595     QList<QGraphicsItem *> itemList = scene()->selectedItems();
1596     if (itemList.count() != 1) {
1597         emit displayMessage(i18n("Cannot edit marker if more than one clip is selected"), ErrorMessage);
1598         kDebug() << "// CANNOT DELETE MARKER IF MORE TAN ONE CLIP IS SELECTED....";
1599         return;
1600     }
1601     AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
1602     if (item->type() != AVWIDGET) {
1603         emit displayMessage(i18n("No clip at cursor time"), ErrorMessage);
1604         return;
1605     }
1606     GenTime pos = GenTime(m_cursorPos, m_document->fps());
1607     if (item->startPos() > pos || item->endPos() < pos) {
1608         emit displayMessage(i18n("No selected clip at cursor time"), ErrorMessage);
1609         return;
1610     }
1611     ClipItem *clip = (ClipItem *) item;
1612     int id = clip->baseClip()->getId();
1613     GenTime position = pos - item->startPos() + item->cropStart();
1614     QString oldcomment = clip->baseClip()->markerComment(position);
1615     if (oldcomment.isEmpty()) {
1616         emit displayMessage(i18n("No marker found at cursor time"), ErrorMessage);
1617         return;
1618     }
1619
1620     CommentedTime marker(position, oldcomment);
1621     MarkerDialog d(clip->baseClip(), marker, m_document->timecode(), this);
1622     if (d.exec() == QDialog::Accepted) {
1623         if (d.newMarker().time() == position) {
1624             // marker position was not changed, only text
1625             AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, d.newMarker().comment(), id, position, true);
1626             m_commandStack->push(command);
1627         } else {
1628             // marker text and position were changed, remove previous marker and add new one
1629             AddMarkerCommand *command1 = new AddMarkerCommand(this, oldcomment, QString(), id, position, true);
1630             AddMarkerCommand *command2 = new AddMarkerCommand(this, QString(), d.newMarker().comment(), id, d.newMarker().time(), true);
1631             m_commandStack->push(command1);
1632             m_commandStack->push(command2);
1633         }
1634     }
1635 }
1636
1637 void CustomTrackView::addMarker(const int id, const GenTime &pos, const QString comment) {
1638     DocClipBase *base = m_document->clipManager()->getClipById(id);
1639     if (!comment.isEmpty()) base->addSnapMarker(pos, comment);
1640     else base->deleteSnapMarker(pos);
1641     m_document->setModified(true);
1642     viewport()->update();
1643 }
1644
1645
1646
1647 void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const QString &comment) {
1648     if (oldPos > GenTime() && pos > GenTime()) {
1649         // move guide
1650         for (int i = 0; i < m_guides.count(); i++) {
1651             if (m_guides.at(i)->position() == oldPos) {
1652                 Guide *item = m_guides.at(i);
1653                 item->updateGuide(pos, comment);
1654                 break;
1655             }
1656         }
1657     } else if (pos > GenTime()) addGuide(pos, comment);
1658     else {
1659         // remove guide
1660         bool found = false;
1661         for (int i = 0; i < m_guides.count(); i++) {
1662             if (m_guides.at(i)->position() == oldPos) {
1663                 Guide *item = m_guides.takeAt(i);
1664                 delete item;
1665                 found = true;
1666                 break;
1667             }
1668         }
1669         if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
1670     }
1671 }
1672
1673 bool CustomTrackView::addGuide(const GenTime pos, const QString &comment) {
1674     for (int i = 0; i < m_guides.count(); i++) {
1675         if (m_guides.at(i)->position() == pos) {
1676             emit displayMessage(i18n("A guide already exists at that position"), ErrorMessage);
1677             return false;
1678         }
1679     }
1680     Guide *g = new Guide(this, pos, comment, m_scale, m_document->fps(), m_tracksHeight * m_tracksList.count());
1681     scene()->addItem(g);
1682     m_guides.append(g);
1683     return true;
1684 }
1685
1686 void CustomTrackView::slotAddGuide() {
1687     CommentedTime marker(GenTime(m_cursorPos, m_document->fps()), i18n("Guide"));
1688     MarkerDialog d(NULL, marker, m_document->timecode(), this);
1689     if (d.exec() != QDialog::Accepted) return;
1690     if (addGuide(d.newMarker().time(), d.newMarker().comment())) {
1691         EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), d.newMarker().time(), d.newMarker().comment(), false);
1692         m_commandStack->push(command);
1693     }
1694 }
1695
1696 void CustomTrackView::slotEditGuide() {
1697     GenTime pos = GenTime(m_cursorPos, m_document->fps());
1698     bool found = false;
1699     for (int i = 0; i < m_guides.count(); i++) {
1700         if (m_guides.at(i)->position() == pos) {
1701             slotEditGuide(m_guides.at(i)->info());
1702             found = true;
1703             break;
1704         }
1705     }
1706     if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
1707 }
1708
1709 void CustomTrackView::slotEditGuide(CommentedTime guide) {
1710     MarkerDialog d(NULL, guide, m_document->timecode(), this);
1711     if (d.exec() == QDialog::Accepted) {
1712         EditGuideCommand *command = new EditGuideCommand(this, guide.time(), guide.comment(), d.newMarker().time(), d.newMarker().comment(), true);
1713         m_commandStack->push(command);
1714     }
1715 }
1716
1717
1718 void CustomTrackView::slotDeleteGuide() {
1719     GenTime pos = GenTime(m_cursorPos, m_document->fps());
1720     bool found = false;
1721     for (int i = 0; i < m_guides.count(); i++) {
1722         if (m_guides.at(i)->position() == pos) {
1723             EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true);
1724             m_commandStack->push(command);
1725             found = true;
1726             break;
1727         }
1728     }
1729     if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
1730 }
1731
1732 void CustomTrackView::slotDeleteAllGuides() {
1733     QUndoCommand *deleteAll = new QUndoCommand();
1734     deleteAll->setText("Delete all guides");
1735     for (int i = 0; i < m_guides.count(); i++) {
1736         EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true, deleteAll);
1737     }
1738     m_commandStack->push(deleteAll);
1739 }
1740
1741 void CustomTrackView::setTool(PROJECTTOOL tool) {
1742     m_tool = tool;
1743 }
1744
1745 void CustomTrackView::setScale(double scaleFactor) {
1746     //scale(scaleFactor, scaleFactor);
1747     m_animationTimer->stop();
1748     if (m_visualTip) {
1749         delete m_visualTip;
1750         m_visualTip = NULL;
1751     }
1752     if (m_animation) {
1753         delete m_animation;
1754         m_animation = NULL;
1755     }
1756     double pos = cursorPos() / m_scale;
1757     m_scale = scaleFactor;
1758     int vert = verticalScrollBar()->value();
1759     kDebug() << " HHHHHHHH  SCALING: " << m_scale;
1760     QList<QGraphicsItem *> itemList = items();
1761     for (int i = 0; i < itemList.count(); i++) {
1762         if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
1763             AbstractClipItem *clip = (AbstractClipItem *)itemList.at(i);
1764             clip->setRect(clip->startPos().frames(m_document->fps()) * m_scale, clip->rect().y(), clip->duration().frames(m_document->fps()) * m_scale, clip->rect().height());
1765         }
1766     }
1767
1768     for (int i = 0; i < m_guides.count(); i++) {
1769         m_guides.at(i)->updatePosition(m_scale);
1770     }
1771
1772     setSceneRect(0, 0, (m_projectDuration + 100) * m_scale, sceneRect().height());
1773     updateCursorPos();
1774     centerOn(QPointF(cursorPos(), m_tracksHeight));
1775     verticalScrollBar()->setValue(vert);
1776 }
1777
1778 void CustomTrackView::slotRefreshGuides() {
1779     if (KdenliveSettings::showmarkers()) {
1780         kDebug() << "// refresh GUIDES";
1781         for (int i = 0; i < m_guides.count(); i++) {
1782             m_guides.at(i)->update();
1783         }
1784     }
1785 }
1786
1787 void CustomTrackView::drawBackground(QPainter * painter, const QRectF & rect) {
1788     QRect rectInView = viewport()->rect();
1789     rectInView.moveTo(horizontalScrollBar()->value(), verticalScrollBar()->value());
1790
1791     QColor base = palette().button().color();
1792     painter->setClipRect(rect);
1793     painter->drawLine(rectInView.left(), 0, rectInView.right(), 0);
1794     uint max = m_tracksList.count();
1795     for (uint i = 0; i < max;i++) {
1796         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)));
1797         painter->drawLine(rectInView.left(), m_tracksHeight * (i + 1), rectInView.right(), m_tracksHeight * (i + 1));
1798         //painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i + 1));
1799     }
1800     int lowerLimit = m_tracksHeight * m_tracksList.count() + 1;
1801     if (height() > lowerLimit)
1802         painter->fillRect(QRectF(rectInView.left(), lowerLimit, rectInView.width(), height() - lowerLimit), QBrush(base));
1803 }
1804
1805 QDomElement CustomTrackView::xmlInfo() {
1806     QDomDocument doc;
1807     QDomElement e;
1808     QDomElement guides = doc.createElement("guides");
1809     for (int i = 0; i < m_guides.count(); i++) {
1810         e = doc.createElement("guide");
1811         e.setAttribute("time", m_guides.at(i)->position().ms() / 1000);
1812         e.setAttribute("comment", m_guides.at(i)->label());
1813         guides.appendChild(e);
1814     }
1815     return guides;
1816 }
1817
1818 bool CustomTrackView::findString(const QString &text) {
1819     QString marker;
1820     for (int i = 0; i < m_searchPoints.size(); ++i) {
1821         marker = m_searchPoints.at(i).comment();
1822         if (marker.contains(text, Qt::CaseInsensitive)) {
1823             setCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()), true);
1824             int vert = verticalScrollBar()->value();
1825             int hor = cursorPos();
1826             ensureVisible(hor, vert + 10, 2, 2, 50, 0);
1827             m_findIndex = i;
1828             return true;
1829         }
1830     }
1831     return false;
1832 }
1833
1834 bool CustomTrackView::findNextString(const QString &text) {
1835     QString marker;
1836     for (int i = m_findIndex + 1; i < m_searchPoints.size(); ++i) {
1837         marker = m_searchPoints.at(i).comment();
1838         if (marker.contains(text, Qt::CaseInsensitive)) {
1839             setCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()), true);
1840             int vert = verticalScrollBar()->value();
1841             int hor = cursorPos();
1842             ensureVisible(hor, vert + 10, 2, 2, 50, 0);
1843             m_findIndex = i;
1844             return true;
1845         }
1846     }
1847     m_findIndex = -1;
1848     return false;
1849 }
1850
1851 void CustomTrackView::initSearchStrings() {
1852     m_searchPoints.clear();
1853     QList<QGraphicsItem *> itemList = items();
1854     for (int i = 0; i < itemList.count(); i++) {
1855         // parse all clip names
1856         if (itemList.at(i)->type() == AVWIDGET) {
1857             ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
1858             GenTime start = item->startPos();
1859             CommentedTime t(start, item->clipName());
1860             m_searchPoints.append(t);
1861             // add all clip markers
1862             QList < CommentedTime > markers = item->commentedSnapMarkers();
1863             m_searchPoints += markers;
1864         }
1865     }
1866
1867     // add guides
1868     for (int i = 0; i < m_guides.count(); i++) {
1869         m_searchPoints.append(m_guides.at(i)->info());
1870     }
1871
1872     qSort(m_searchPoints);
1873 }
1874
1875 void CustomTrackView::clearSearchStrings() {
1876     m_searchPoints.clear();
1877     m_findIndex = 0;
1878 }
1879
1880 /*
1881 void CustomTrackView::drawForeground ( QPainter * painter, const QRectF & rect )
1882 {
1883   //kDebug()<<"/////  DRAWING FB: "<<rect.x()<<", width: "<<rect.width();
1884   painter->fillRect(rect, QColor(50, rand() % 250,50,100));
1885   painter->drawLine(m_cursorPos, rect.y(), m_cursorPos, rect.y() + rect.height());
1886 }
1887 */
1888 #include "customtrackview.moc"