]> git.sesse.net Git - kdenlive/blob - src/clipitem.cpp
removed warnings to see real warning messages (except customtrackview)
[kdenlive] / src / clipitem.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
21
22 #include <QPainter>
23 #include <QTimer>
24 #include <QStyleOptionGraphicsItem>
25 #include <QGraphicsScene>
26 #include <QGraphicsView>
27 #include <QScrollBar>
28 #include <QMimeData>
29 #include <QApplication>
30
31 #include <KDebug>
32
33 #include <mlt++/Mlt.h>
34
35 #include "clipitem.h"
36 #include "customtrackview.h"
37 #include "renderer.h"
38 #include "docclipbase.h"
39 #include "transition.h"
40 #include "events.h"
41 #include "kdenlivesettings.h"
42 #include "kthumb.h"
43
44 ClipItem::ClipItem(DocClipBase *clip, int track, GenTime startpos, const QRectF & rect, GenTime duration, double fps)
45         : AbstractClipItem(rect), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), m_effectsCounter(1), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_thumbsRequested(0), m_hover(false) {
46     //setToolTip(name);
47     // kDebug() << "*******  CREATING NEW TML CLIP, DUR: " << duration;
48     m_fps = fps;
49     m_startPos = startpos;
50     m_track = track;
51     m_xml = clip->toXML();
52     m_clipName = clip->name();
53     m_producer = clip->getId();
54     m_clipType = clip->clipType();
55     m_cropStart = GenTime();
56     m_maxDuration = duration;
57     if (duration != GenTime()) m_cropDuration = duration;
58     else m_cropDuration = m_maxDuration;
59     setAcceptDrops(true);
60     audioThumbReady = clip->audioThumbCreated();
61     /*
62       m_cropStart = xml.attribute("in", 0).toInt();
63       m_maxDuration = xml.attribute("duration", 0).toInt();
64       if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
65
66       if (duration != -1) m_cropDuration = duration;
67       else m_cropDuration = m_maxDuration;*/
68
69
70     setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
71     setAcceptsHoverEvents(true);
72     connect(this , SIGNAL(prepareAudioThumb(double, QPainterPath, int, int)) , this, SLOT(slotPrepareAudioThumb(double, QPainterPath, int, int)));
73
74     setBrush(QColor(141, 166, 215));
75     if (m_clipType == VIDEO || m_clipType == AV) {
76         m_hasThumbs = true;
77         connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
78         connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
79         connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
80         QTimer::singleShot(300, this, SLOT(slotFetchThumbs()));
81
82         startThumbTimer = new QTimer(this);
83         startThumbTimer->setSingleShot(true);
84         connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
85         endThumbTimer = new QTimer(this);
86         endThumbTimer->setSingleShot(true);
87         connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
88
89     } else if (m_clipType == COLOR) {
90         m_maxDuration = GenTime(10000, m_fps);
91         QString colour = m_xml.attribute("colour");
92         colour = colour.replace(0, 2, "#");
93         setBrush(QColor(colour.left(7)));
94     } else if (m_clipType == IMAGE) {
95         m_maxDuration = GenTime(10000, m_fps);
96         m_startPix = KThumb::getImage(KUrl(m_xml.attribute("resource")), (int)(50 * KdenliveSettings::project_display_ratio()), 50);
97     } else if (m_clipType == AUDIO) {
98         connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
99     }
100 }
101
102
103 ClipItem::~ClipItem() {
104     if (startThumbTimer) delete startThumbTimer;
105     if (endThumbTimer) delete endThumbTimer;
106 }
107
108 void ClipItem::resetThumbs() {
109     slotFetchThumbs();
110     audioThumbCachePic.clear();
111 }
112
113 void ClipItem::slotFetchThumbs() {
114     m_thumbsRequested += 2;
115     emit getThumb((int)m_cropStart.frames(m_fps), (int)(m_cropStart + m_cropDuration).frames(m_fps));
116 }
117
118 void ClipItem::slotGetStartThumb() {
119     m_thumbsRequested++;
120     emit getThumb((int)m_cropStart.frames(m_fps), -1);
121 }
122
123 void ClipItem::slotGetEndThumb() {
124     m_thumbsRequested++;
125     emit getThumb(-1, (int)(m_cropStart + m_cropDuration).frames(m_fps));
126 }
127
128 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
129     if (m_thumbsRequested == 0) return;
130     if (frame == m_cropStart.frames(m_fps)) m_startPix = pix;
131     else m_endPix = pix;
132     update();
133     m_thumbsRequested--;
134 }
135
136 void ClipItem::slotGotAudioData() {
137     audioThumbReady = true;
138     update();
139 }
140
141 int ClipItem::type() const {
142     return AVWIDGET;
143 }
144
145 DocClipBase *ClipItem::baseClip() {
146     return m_clip;
147 }
148
149 QDomElement ClipItem::xml() const {
150     return m_xml;
151 }
152
153 int ClipItem::clipType() {
154     return m_clipType;
155 }
156
157 QString ClipItem::clipName() {
158     return m_clipName;
159 }
160
161 int ClipItem::clipProducer() {
162     return m_producer;
163 }
164
165 void ClipItem::flashClip() {
166     if (m_timeLine == 0) {
167         m_timeLine = new QTimeLine(750, this);
168         connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
169     }
170     m_timeLine->start();
171 }
172
173 void ClipItem::animate(qreal value) {
174     m_opacity = value;
175     update();
176 }
177
178 // virtual
179 void ClipItem::paint(QPainter *painter,
180                      const QStyleOptionGraphicsItem *option,
181                      QWidget *widget) {
182     painter->setOpacity(m_opacity);
183     QBrush paintColor = brush();
184
185     if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
186     QRectF br = rect();
187     double scale = br.width() / m_cropDuration.frames(m_fps);
188     QRect rectInView = visibleRect();//this is the rect that is visible by the user
189
190     if (rectInView.isNull())
191         return;
192     QPainterPath clippath;
193     clippath.addRect(rectInView);
194
195     int startpixel = (int)(rectInView.x() - rect().x()); //start and endpixel that is viewable from rect()
196
197     if (startpixel < 0)
198         startpixel = 0;
199     int endpixel = rectInView.width() + rectInView.x();
200     if (endpixel < 0)
201         endpixel = 0;
202
203     //painter->setRenderHints(QPainter::Antialiasing);
204
205     QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
206
207     painter->setClipRect(option->exposedRect);
208
209     // build path around clip
210
211     QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
212
213     painter->setClipPath(resultClipPath.intersected(clippath), Qt::IntersectClip);
214     //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
215     painter->fillRect(br.intersected(rectInView), paintColor);
216     //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
217
218     // draw thumbnails
219     if (!m_startPix.isNull() && KdenliveSettings::videothumbnails()) {
220         if (m_clipType == IMAGE) {
221             painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
222             QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
223             painter->drawLine(l);
224         } else {
225             painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
226             QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
227             painter->drawLine(l);
228         }
229
230         painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
231         QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
232         painter->drawLine(l2);
233     }
234
235     // draw audio thumbnails
236     if ((m_clipType == AV || m_clipType == AUDIO) && audioThumbReady && KdenliveSettings::audiothumbnails()) {
237
238         QPainterPath path = m_clipType == AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
239         if (m_clipType == AV) painter->fillPath(path, QBrush(QColor(200, 200, 200, 140)));
240
241         int channels = 2;
242         if (scale != framePixelWidth)
243             audioThumbCachePic.clear();
244         emit prepareAudioThumb(scale, path, startpixel, endpixel + 200);//200 more for less missing parts before repaint after scrolling
245         int cropLeft = (int)((m_cropStart).frames(m_fps) * scale);
246         for (int startCache = startpixel - startpixel % 100; startCache < endpixel + 300;startCache += 100) {
247             if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
248                 painter->drawPixmap((int)(roundRectPathUpper.united(roundRectPathLower).boundingRect().x() + startCache - cropLeft), (int)(path.boundingRect().y()), audioThumbCachePic[startCache]);
249         }
250
251     }
252
253     // draw start / end fades
254     QBrush fades;
255     if (isSelected()) {
256         fades = QBrush(QColor(200, 50, 50, 150));
257     } else fades = QBrush(QColor(200, 200, 200, 200));
258
259     if (m_startFade != 0) {
260         QPainterPath fadeInPath;
261         fadeInPath.moveTo(br.x() , br.y());
262         fadeInPath.lineTo(br.x() , br.y() + br.height());
263         fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
264         fadeInPath.closeSubpath();
265         painter->fillPath(fadeInPath, fades);
266         if (isSelected()) {
267             QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
268             painter->drawLine(l);
269         }
270     }
271     if (m_endFade != 0) {
272         QPainterPath fadeOutPath;
273         fadeOutPath.moveTo(br.x() + br.width(), br.y());
274         fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
275         fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
276         fadeOutPath.closeSubpath();
277         painter->fillPath(fadeOutPath, fades);
278         if (isSelected()) {
279             QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
280             painter->drawLine(l);
281         }
282     }
283
284     QPen pen = painter->pen();
285     pen.setColor(Qt::white);
286     //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
287
288     // Draw effects names
289     QString effects = effectNames().join(" / ");
290     if (!effects.isEmpty()) {
291         painter->setPen(pen);
292         QFont font = painter->font();
293         QFont smallFont = font;
294         smallFont.setPointSize(8);
295         painter->setFont(smallFont);
296         QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " ");
297         painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
298         painter->drawText(txtBounding, Qt::AlignCenter, effects);
299         pen.setColor(Qt::black);
300         painter->setPen(pen);
301         painter->setFont(font);
302     }
303
304     // For testing puspose only: draw transitions count
305     {
306         painter->setPen(pen);
307         QFont font = painter->font();
308         QFont smallFont = font;
309         smallFont.setPointSize(8);
310         painter->setFont(smallFont);
311         QString txt = " Transitions: " + QString::number(m_transitionsList.count()) + " ";
312         QRectF txtBoundin = painter->boundingRect(br, Qt::AlignRight | Qt::AlignTop, txt);
313         painter->fillRect(txtBoundin, QBrush(QColor(0, 0, 0, 150)));
314         painter->drawText(txtBoundin, Qt::AlignCenter, txt);
315         pen.setColor(Qt::black);
316         painter->setPen(pen);
317         painter->setFont(font);
318     }
319
320     // Draw clip name
321     QRectF txtBounding = painter->boundingRect(br, Qt::AlignHCenter | Qt::AlignTop, " " + m_clipName + " ");
322     painter->fillRect(txtBounding, QBrush(QColor(255, 255, 255, 150)));
323     painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
324
325     // draw frame around clip
326     if (isSelected()) {
327         pen.setColor(Qt::red);
328         pen.setWidth(2);
329     } else {
330         pen.setColor(Qt::black);
331         pen.setWidth(1);
332     }
333     painter->setPen(pen);
334     painter->setClipRect(option->exposedRect);
335     painter->drawPath(resultClipPath.intersected(clippath));
336
337     //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(),  QBrush(QColor(255,255,255,150)));
338     //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
339
340     /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
341     painter->drawRect(recta);
342     painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
343     painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
344     painter->setPen(QPen(Qt::black, 1.0));
345     painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
346     painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
347
348     //QGraphicsRectItem::paint(painter, option, widget);
349     //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
350     //painter->setPen(pen);
351     //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
352     //kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
353     //painter->drawText(rect(), Qt::AlignCenter, m_name);
354     // painter->drawRect(boundingRect());
355     //painter->drawRoundRect(-10, -10, 20, 20);
356     if (m_hover) {
357         painter->setPen(QPen(Qt::black));
358         painter->setBrush(QBrush(Qt::yellow));
359         painter->drawEllipse((int)(br.x() + 10), (int)(br.y() + br.height() / 2 - 5) , 10, 10);
360         painter->drawEllipse((int)(br.x() + br.width() - 20), (int)(br.y() + br.height() / 2 - 5), 10, 10);
361     }
362 }
363
364
365 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) {
366     if (abs((int)(pos.x() - (rect().x() + scale * m_startFade))) < 6 && abs((int)(pos.y() - rect().y())) < 6) return FADEIN;
367     else if (abs((int)(pos.x() - rect().x())) < 6) return RESIZESTART;
368     else if (abs((int)(pos.x() - (rect().x() + rect().width() - scale * m_endFade))) < 6 && abs((int)(pos.y() - rect().y())) < 6) return FADEOUT;
369     else if (abs((int)(pos.x() - (rect().x() + rect().width()))) < 6) return RESIZEEND;
370     else if (abs((int)(pos.x() - (rect().x() + 10))) < 6 && abs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONSTART;
371     else if (abs((int)(pos.x() - (rect().x() + rect().width() - 20))) < 6 && abs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONEND;
372
373     return MOVE;
374 }
375
376 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, QPainterPath path, int startpixel, int endpixel) {
377     int channels = 2;
378
379     QRectF re = path.boundingRect();
380
381     //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
382
383     for (int startCache = startpixel - startpixel % 100;startCache + 100 < endpixel ;startCache += 100) {
384         //kDebug() << "creating " << startCache;
385         //if (framePixelWidth!=pixelForOneFrame  ||
386         if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
387             continue;
388         if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
389             audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
390             audioThumbCachePic[startCache].fill(QColor(200, 200, 200, 0));
391         }
392         bool fullAreaDraw = pixelForOneFrame < 10;
393         QMap<int, QPainterPath > positiveChannelPaths;
394         QMap<int, QPainterPath > negativeChannelPaths;
395         QPainter pixpainter(&audioThumbCachePic[startCache]);
396         QPen audiopen;
397         audiopen.setWidth(0);
398         pixpainter.setPen(audiopen);
399         //pixpainter.setRenderHint(QPainter::Antialiasing,true);
400         //pixpainter.drawLine(0,0,100,re.height());
401         int channelHeight = audioThumbCachePic[startCache].height() / channels;
402
403         for (int i = 0;i < channels;i++) {
404
405             positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
406             negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
407         }
408
409         for (int samples = 0;samples <= 100;samples++) {
410             double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
411             int sample = (int)((frame - (int)(frame)) * 20);   // AUDIO_FRAME_SIZE
412             if (frame < 0 || sample < 0 || sample > 19)
413                 continue;
414             QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
415
416             for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
417
418                 int y = channelHeight * channel + channelHeight / 2;
419                 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2)  * channelHeight / 64;
420                 if (fullAreaDraw) {
421                     positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
422                     negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
423                 } else {
424                     positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
425                     negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
426                 }
427             }
428             for (int channel = 0;channel < channels ;channel++)
429                 if (fullAreaDraw && samples == 100) {
430                     positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
431                     negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
432                     positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
433                     negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
434                 }
435
436         }
437         if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
438         else {
439             pixpainter.setPen(QPen(QColor(0, 0, 0)));
440             pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
441         }
442         for (int i = 0;i < channels;i++) {
443             if (fullAreaDraw) {
444                 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
445                 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
446             } else
447                 pixpainter.drawPath(positiveChannelPaths[i]);
448         }
449     }
450     //audioThumbWasDrawn=true;
451     framePixelWidth = pixelForOneFrame;
452
453     //}
454 }
455
456
457
458 void ClipItem::setFadeIn(int pos, double scale) {
459     int oldIn = m_startFade;
460     if (pos < 0) pos = 0;
461     if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
462     m_startFade = pos;
463     if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
464     else update(rect().x(), rect().y(), pos * scale, rect().height());
465 }
466
467 void ClipItem::setFadeOut(int pos, double scale) {
468     int oldOut = m_endFade;
469     if (pos < 0) pos = 0;
470     if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
471     m_endFade = pos;
472     if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
473     else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
474
475 }
476
477
478 // virtual
479 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
480     /*m_resizeMode = operationMode(event->pos());
481     if (m_resizeMode == MOVE) {
482       m_maxTrack = scene()->sceneRect().height();
483       m_grabPoint = (int) (event->pos().x() - rect().x());
484     }*/
485     QGraphicsRectItem::mousePressEvent(event);
486 }
487
488 // virtual
489 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
490     m_resizeMode = NONE;
491     QGraphicsRectItem::mouseReleaseEvent(event);
492 }
493
494 //virtual
495 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
496     m_hover = true;
497     update();
498 }
499
500 //virtual
501 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
502     m_hover = false;
503     update();
504 }
505
506 void ClipItem::resizeStart(int posx, double scale) {
507     AbstractClipItem::resizeStart(posx, scale);
508     if (m_hasThumbs) startThumbTimer->start(100);
509 }
510
511 void ClipItem::resizeEnd(int posx, double scale) {
512     AbstractClipItem::resizeEnd(posx, scale);
513     if (m_hasThumbs) endThumbTimer->start(100);
514 }
515
516 // virtual
517 void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
518 }
519
520 int ClipItem::effectsCounter() {
521     return m_effectsCounter++;
522 }
523
524 int ClipItem::effectsCount() {
525     return m_effectList.size();
526 }
527
528 QStringList ClipItem::effectNames() {
529     return m_effectList.effectNames();
530 }
531
532 QDomElement ClipItem::effectAt(int ix) {
533     return m_effectList.at(ix);
534 }
535
536 void ClipItem::setEffectAt(int ix, QDomElement effect) {
537     kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
538     m_effectList.insert(ix, effect);
539     m_effectList.removeAt(ix + 1);
540     update(boundingRect());
541 }
542
543 QMap <QString, QString> ClipItem::addEffect(QDomElement effect) {
544     QMap <QString, QString> effectParams;
545     m_effectList.append(effect);
546     effectParams["tag"] = effect.attribute("tag");
547     effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
548     QString state = effect.attribute("disabled");
549     if (!state.isEmpty()) effectParams["disabled"] = state;
550     QDomNodeList params = effect.elementsByTagName("parameter");
551     for (int i = 0; i < params.count(); i++) {
552         QDomElement e = params.item(i).toElement();
553         if (!e.isNull()) {
554             effectParams[e.attribute("name")] = e.attribute("value");
555         }
556         if (!e.attribute("factor").isEmpty()) {
557             effectParams[e.attribute("name")] =  QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
558         }
559     }
560     flashClip();
561     update(boundingRect());
562     return effectParams;
563 }
564
565 QMap <QString, QString> ClipItem::getEffectArgs(QDomElement effect) {
566     QMap <QString, QString> effectParams;
567     effectParams["tag"] = effect.attribute("tag");
568     effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
569     QString state = effect.attribute("disabled");
570     if (!state.isEmpty()) effectParams["disabled"] = state;
571     QDomNodeList params = effect.elementsByTagName("parameter");
572     for (int i = 0; i < params.count(); i++) {
573         QDomElement e = params.item(i).toElement();
574         if (e.attribute("name").contains(";")) {
575             QString format = e.attribute("format");
576             QStringList separators = format.split("%d", QString::SkipEmptyParts);
577             QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
578             QString neu;
579             QTextStream txtNeu(&neu);
580             if (values.size() > 0)
581                 txtNeu << (int)values[0].toDouble();
582             for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
583                 txtNeu << separators[i];
584                 txtNeu << (int)(values[i+1].toDouble());
585             }
586             effectParams["start"] = neu;
587         } else
588             if (!e.isNull()) {
589                 effectParams[e.attribute("name")] = e.attribute("value");
590             }
591         if (!e.attribute("factor").isEmpty()) {
592             effectParams[e.attribute("name")] =  QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
593         }
594     }
595     return effectParams;
596 }
597
598 void ClipItem::deleteEffect(QString index) {
599     for (int i = 0; i < m_effectList.size(); ++i) {
600         if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
601             m_effectList.removeAt(i);
602             break;
603         }
604     }
605     flashClip();
606     update(boundingRect());
607 }
608
609 //virtual
610 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
611     QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
612     QDomDocument doc;
613     doc.setContent(effects, true);
614     QDomElement e = doc.documentElement();
615     CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
616     if (view) view->slotAddEffect(e, m_startPos, m_track);
617 }
618
619 //virtual
620 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
621     event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
622 }
623
624 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
625     Q_UNUSED(event);
626 }
627 void ClipItem::addTransition(Transition* t) {
628     m_transitionsList.append(t);
629     CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
630     QDomDocument doc;
631     QDomElement e = doc.documentElement();
632     if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
633 }
634 // virtual
635 /*
636 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
637 {
638   int pos = event->x();
639   if (event->modifiers() == Qt::ControlModifier)
640     setDragMode(QGraphicsView::ScrollHandDrag);
641   else if (event->modifiers() == Qt::ShiftModifier)
642     setDragMode(QGraphicsView::RubberBandDrag);
643   else {
644     QGraphicsItem * item = itemAt(event->pos());
645     if (item) {
646     }
647     else emit cursorMoved((int) mapToScene(event->x(), 0).x());
648   }
649   kDebug()<<pos;
650   QGraphicsView::mousePressEvent(event);
651 }
652
653 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
654 {
655   QGraphicsView::mouseReleaseEvent(event);
656   setDragMode(QGraphicsView::NoDrag);
657 }
658 */
659
660 #include "clipitem.moc"