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