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