1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
24 #include <QStyleOptionGraphicsItem>
25 #include <QGraphicsScene>
26 #include <QGraphicsView>
29 #include <QApplication>
33 #include <mlt++/Mlt.h>
36 #include "customtrackview.h"
39 #include "kdenlivesettings.h"
41 ClipItem::ClipItem(DocClipBase *clip, int track, int startpos, const QRectF & rect, int duration)
42 : 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(1),audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_thumbsRequested(0)
45 kDebug()<<"******* CREATING NEW TML CLIP, DUR: "<<duration;
46 m_xml = clip->toXML();
47 m_clipName = clip->name();
48 m_producer = clip->getId();
49 m_clipType = clip->clipType();
51 m_maxDuration = duration;
52 if (duration != -1) m_cropDuration = duration;
53 else m_cropDuration = m_maxDuration;
54 setAcceptDrops (true);
55 audioThumbReady = clip->audioThumbCreated();
57 m_cropStart = xml.attribute("in", 0).toInt();
58 m_maxDuration = xml.attribute("duration", 0).toInt();
59 if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
61 if (duration != -1) m_cropDuration = duration;
62 else m_cropDuration = m_maxDuration;*/
65 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemClipsChildrenToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
66 connect (this , SIGNAL (prepareAudioThumb(double,QPainterPath,int,int)) , this, SLOT (slotPrepareAudioThumb(double,QPainterPath,int,int)));
68 setBrush(QColor(100, 100, 150));
69 if (m_clipType == VIDEO || m_clipType == AV) {
71 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
72 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
73 connect(clip, SIGNAL (gotAudioData()), this, SLOT (slotGotAudioData()));
74 QTimer::singleShot(300, this, SLOT(slotFetchThumbs()));
76 startThumbTimer = new QTimer(this);
77 startThumbTimer->setSingleShot(true);
78 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
79 endThumbTimer = new QTimer(this);
80 endThumbTimer->setSingleShot(true);
81 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
84 else if (m_clipType == COLOR) {
85 QString colour = m_xml.attribute("colour");
86 colour = colour.replace(0, 2, "#");
87 setBrush(QColor(colour.left(7)));
89 else if (m_clipType == IMAGE) {
90 m_startPix = KThumb::getImage(KUrl(m_xml.attribute("resource")), 50 * KdenliveSettings::project_display_ratio(), 50);
92 else if (m_clipType == AUDIO) {
93 connect(clip, SIGNAL (gotAudioData()), this, SLOT (slotGotAudioData()));
100 if (startThumbTimer) delete startThumbTimer;
101 if (endThumbTimer) delete endThumbTimer;
104 void ClipItem::slotFetchThumbs()
106 m_thumbsRequested += 2;
107 emit getThumb(m_cropStart, m_cropStart + m_cropDuration);
110 void ClipItem::slotGetStartThumb()
113 emit getThumb(m_cropStart, -1);
116 void ClipItem::slotGetEndThumb()
119 emit getThumb(-1, m_cropStart + m_cropDuration);
122 void ClipItem::slotThumbReady(int frame, QPixmap pix)
124 if (m_thumbsRequested == 0) return;
125 if (frame == m_cropStart) m_startPix = pix;
131 void ClipItem::slotGotAudioData(){
132 audioThumbReady=true;
136 int ClipItem::type () const
141 DocClipBase *ClipItem::baseClip()
146 QDomElement ClipItem::xml() const
151 int ClipItem::clipType()
156 QString ClipItem::clipName()
161 int ClipItem::clipProducer()
166 int ClipItem::maxDuration()
168 return m_maxDuration;
171 int ClipItem::duration()
173 return m_cropDuration;
176 int ClipItem::startPos()
181 int ClipItem::cropStart()
186 int ClipItem::endPos()
188 return m_startPos + m_cropDuration;
191 void ClipItem::flashClip()
193 if (m_timeLine == 0) {
194 m_timeLine = new QTimeLine(750, this);
195 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
200 void ClipItem::animate(qreal value)
207 void ClipItem::paint(QPainter *painter,
208 const QStyleOptionGraphicsItem *option,
211 painter->setOpacity(m_opacity);
212 QBrush paintColor = brush();
213 if (isSelected()) paintColor = QBrush(QColor(150, 50, 100));
215 QRect rectInView;//this is the rect that is visible by the user
216 if (scene()->views().size()>0){
217 rectInView=scene()->views()[0]->viewport()->rect();
218 rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(),scene()->views()[0]->verticalScrollBar()->value());
219 rectInView.adjust(-10,-10,10,10);//make view rect 10 pixel greater on each site, or repaint after scroll event
220 //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value();
222 if (rectInView.isNull())
224 QPainterPath clippath;
225 clippath.addRect(rectInView);
226 int startpixel=rectInView.x()-rect().x();//start and endpixel that is viewable from rect()
229 int endpixel=rectInView.width()+rectInView.x();
233 painter->setRenderHints(QPainter::Antialiasing);
234 QPainterPath roundRectPathUpper,roundRectPathLower;
235 double roundingY = 20;
236 double roundingX = 20;
238 painter->setClipRect(option->exposedRect);
239 if (roundingX > br.width() / 2) roundingX = br.width() / 2;
240 //kDebug()<<"-----PAINTING, SCAL: "<<scale<<", height: "<<br.height();
241 roundRectPathUpper.moveTo(br.x() + br .width() - offset, br.y() + br.height()/2 - offset);
242 roundRectPathUpper.arcTo(br.x() + br .width() - roundingX - offset, br.y(), roundingX, roundingY, 0.0, 90.0);
243 roundRectPathUpper.lineTo(br.x() + roundingX, br.y());
244 roundRectPathUpper.arcTo(br.x() + offset, br.y(), roundingX, roundingY, 90.0, 90.0);
245 roundRectPathUpper.lineTo(br.x() + offset, br.y() + br.height()/2 - offset);
246 roundRectPathUpper.closeSubpath();
248 roundRectPathLower.moveTo(br.x() + offset, br.y() + br.height()/2 - offset);
249 roundRectPathLower.arcTo(br.x() + offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 180.0, 90.0);
250 roundRectPathLower.lineTo(br.x() + br .width() - roundingX, br.y() + br.height() - offset);
251 roundRectPathLower.arcTo(br.x() + br .width() - roundingX - offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 270.0, 90.0);
252 roundRectPathLower.lineTo(br.x() + br .width() - offset, br.y()+ br.height()/2 - offset);
253 roundRectPathLower.closeSubpath();
255 painter->setClipPath(roundRectPathUpper.united(roundRectPathLower).intersected(clippath), Qt::IntersectClip);
256 //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
257 painter->fillRect(br.intersected(rectInView), paintColor);
258 //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
261 if (!m_startPix.isNull()) {
262 if (m_clipType == IMAGE) {
263 painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
264 QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
265 painter->drawLine(l);
267 painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
268 QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
269 painter->drawLine(l);
272 painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
273 QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
274 painter->drawLine(l2);
276 if ( ( m_clipType == AV || m_clipType==AUDIO || true) && audioThumbReady ){
278 QPainterPath path= m_clipType==AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
279 painter->fillPath(path,QBrush(QColor(200,200,200,127)));
282 double pixelForOneFrame=(double)br.width()/duration();
283 if (pixelForOneFrame!=framePixelWidth)
284 audioThumbCachePic.clear();
285 emit prepareAudioThumb(pixelForOneFrame,path,startpixel,endpixel+200);//200 more for less missing parts before repaint after scrolling
287 for (int startCache=startpixel-startpixel%100; startCache < endpixel+300;startCache+=100){
288 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull() )
289 painter->drawPixmap(path.boundingRect().x()+startCache,path.boundingRect().y(),audioThumbCachePic[startCache]);
294 // draw start / end fades
295 double scale = br.width() / m_cropDuration;
298 fades = QBrush(QColor(200, 50, 50, 150));
300 else fades = QBrush(QColor(200, 200, 200, 200));
302 if (m_startFade != 0) {
303 QPainterPath fadeInPath;
304 fadeInPath.moveTo(br.x() - offset, br.y());
305 fadeInPath.lineTo(br.x() - offset, br.y() + br.height());
306 fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
307 fadeInPath.closeSubpath();
308 painter->fillPath(fadeInPath, fades);
310 QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
311 painter->drawLine(l);
314 if (m_endFade != 0) {
315 QPainterPath fadeOutPath;
316 fadeOutPath.moveTo(br.x() + br.width(), br.y());
317 fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
318 fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
319 fadeOutPath.closeSubpath();
320 painter->fillPath(fadeOutPath, fades);
322 QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
323 painter->drawLine(l);
327 QPen pen = painter->pen();
328 pen.setColor(Qt::white);
329 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
331 QString effects = effectNames().join(" / ");
332 if (!effects.isEmpty()) {
333 painter->setPen(pen);
334 QFont font = painter->font();
335 QFont smallFont = font;
336 smallFont.setPointSize(8);
337 painter->setFont(smallFont);
338 QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " ");
339 painter->fillRect(txtBounding, QBrush(QColor(0,0,0,150)));
340 painter->drawText(txtBounding, Qt::AlignCenter, effects);
341 pen.setColor(Qt::black);
342 painter->setPen(pen);
343 painter->setFont(font);
346 pen.setColor(Qt::red);
347 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
348 if (isSelected()) painter->setPen(pen);
349 painter->setClipRect(option->exposedRect);
350 painter->drawPath(roundRectPathUpper.united(roundRectPathLower).intersected(clippath));
352 QRectF txtBounding = painter->boundingRect(br, Qt::AlignCenter, " " + m_clipName + " ");
353 painter->fillRect(txtBounding, QBrush(QColor(255,255,255,150)));
354 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
357 //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150)));
358 //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
360 /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
361 painter->drawRect(recta);
362 painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
363 painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
364 painter->setPen(QPen(Qt::black, 1.0));
365 painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
366 painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
368 //QGraphicsRectItem::paint(painter, option, widget);
369 //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
370 //painter->setPen(pen);
371 //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
372 //kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
373 //painter->drawText(rect(), Qt::AlignCenter, m_name);
374 // painter->drawRect(boundingRect());
375 //painter->drawRoundRect(-10, -10, 20, 20);
379 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale)
381 if (abs(pos.x() - (rect().x() + scale * m_startFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEIN;
382 else if (abs(pos.x() - rect().x()) < 6) return RESIZESTART;
383 else if (abs(pos.x() - (rect().x() + rect().width() - scale * m_endFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEOUT;
384 else if (abs(pos.x() - (rect().x() + rect().width())) < 6) return RESIZEEND;
388 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame,QPainterPath path,int startpixel, int endpixel){
391 QRectF re=path.boundingRect();
393 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
395 for (int startCache=startpixel-startpixel%100;startCache+100<endpixel ;startCache+=100){
396 //kDebug() << "creating " << startCache;
397 //if (framePixelWidth!=pixelForOneFrame ||
398 if (framePixelWidth==pixelForOneFrame && audioThumbCachePic.contains(startCache))
400 if (audioThumbCachePic[startCache].isNull() || framePixelWidth!=pixelForOneFrame){
401 audioThumbCachePic[startCache]=QPixmap(100,re.height());
402 audioThumbCachePic[startCache].fill(QColor(200,200,200,127));
404 bool fullAreaDraw=pixelForOneFrame<10;
405 QMap<int,QPainterPath > positiveChannelPaths;
406 QMap<int,QPainterPath > negativeChannelPaths;
407 QPainter pixpainter(&audioThumbCachePic[startCache]);
409 audiopen.setWidth(0);
410 pixpainter.setPen(audiopen);
411 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
412 //pixpainter.drawLine(0,0,100,re.height());
413 int channelHeight=audioThumbCachePic[startCache].height()/channels;
415 for (int i=0;i<channels;i++){
417 positiveChannelPaths[i].moveTo(0,channelHeight*i+ channelHeight/2);
418 negativeChannelPaths[i].moveTo(0,channelHeight*i+ channelHeight/2);
421 for (int samples=0;samples<=100;samples++){
422 double frame=(double)(samples+startCache-0)/pixelForOneFrame;
423 int sample=(frame-(int)(frame))*20 ;// AUDIO_FRAME_SIZE
424 if (frame<0 || sample< 0 || sample>19 )
426 QMap<int,QByteArray> frame_channel_data=baseClip()->audioFrameChache[(int)frame];
428 for (int channel=0;channel<channels && frame_channel_data[channel].size()> 0;channel++){
430 int y=channelHeight*channel+ channelHeight/2;
431 int delta=(int)(frame_channel_data[channel][sample] -127/2 ) * channelHeight/ 64;
433 positiveChannelPaths[channel].lineTo(samples,0.1+y+qAbs( delta ));
434 negativeChannelPaths[channel].lineTo(samples,0.1+y-qAbs( delta ));
436 positiveChannelPaths[channel].lineTo(samples,0.1+y+delta);
437 negativeChannelPaths[channel].lineTo(samples,0.1+y-delta);
440 for (int channel=0;channel<channels ;channel++)
441 if (fullAreaDraw && samples==100){
442 positiveChannelPaths[channel].lineTo(samples,channelHeight*channel+ channelHeight/2);
443 negativeChannelPaths[channel].lineTo(samples,channelHeight*channel+ channelHeight/2);
444 positiveChannelPaths[channel].lineTo(0,channelHeight*channel+ channelHeight/2);
445 negativeChannelPaths[channel].lineTo(0,channelHeight*channel+ channelHeight/2);
449 for (int i=0;i<channels;i++){
451 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
452 pixpainter.setBrush(QBrush(QColor(200,200,100,200)));
453 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
455 pixpainter.drawPath(positiveChannelPaths[i]);
458 //audioThumbWasDrawn=true;
459 framePixelWidth=pixelForOneFrame;
464 int ClipItem::fadeIn() const
469 int ClipItem::fadeOut() const
474 void ClipItem::setFadeIn(int pos, double scale)
476 int oldIn = m_startFade;
477 if (pos < 0) pos = 0;
478 if (pos > m_cropDuration) pos = m_cropDuration / 2;
480 if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
481 else update(rect().x(), rect().y(), pos * scale, rect().height());
484 void ClipItem::setFadeOut(int pos, double scale)
486 int oldOut = m_endFade;
487 if (pos < 0) pos = 0;
488 if (pos > m_cropDuration) pos = m_cropDuration / 2;
490 if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
491 else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
497 void ClipItem::mousePressEvent ( QGraphicsSceneMouseEvent * event )
499 /*m_resizeMode = operationMode(event->pos());
500 if (m_resizeMode == MOVE) {
501 m_maxTrack = scene()->sceneRect().height();
502 m_grabPoint = (int) (event->pos().x() - rect().x());
504 QGraphicsRectItem::mousePressEvent(event);
508 void ClipItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
511 QGraphicsRectItem::mouseReleaseEvent(event);
514 void ClipItem::moveTo(int x, double scale, double offset, int newTrack)
516 double origX = rect().x();
517 double origY = rect().y();
520 setRect(x * scale, origY + offset, rect().width(), rect().height());
521 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
522 if (collisionList.size() == 0) m_track = newTrack;
523 for (int i = 0; i < collisionList.size(); ++i) {
524 QGraphicsItem *item = collisionList.at(i);
525 if (item->type() == 70000)
529 QRectF other = ((QGraphicsRectItem *)item)->rect();
530 if (x < m_startPos) {
531 kDebug()<<"COLLISION, MOVING TO------";
532 m_startPos = ((ClipItem *)item)->endPos() + 1;
533 origX = m_startPos * scale;
536 kDebug()<<"COLLISION, MOVING TO+++";
537 m_startPos = ((ClipItem *)item)->startPos() - m_cropDuration;
538 origX = m_startPos * scale;
541 setRect(origX, origY, rect().width(), rect().height());
552 /* QList <QGraphicsItem *> childrenList = QGraphicsItem::children();
553 for (int i = 0; i < childrenList.size(); ++i) {
554 childrenList.at(i)->moveBy(rect().x() - origX , offset);
558 void ClipItem::resizeStart(int posx, double scale)
560 int durationDiff = posx - m_startPos;
561 if (durationDiff == 0) return;
562 kDebug()<<"-- RESCALE: CROP="<<m_cropStart<<", DIFF = "<<durationDiff;
563 if (m_cropStart + durationDiff < 0) {
564 durationDiff = -m_cropStart;
566 else if (durationDiff >= m_cropDuration) {
567 durationDiff = m_cropDuration - 3;
569 m_startPos += durationDiff;
570 m_cropStart += durationDiff;
571 m_cropDuration -= durationDiff;
572 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
573 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
574 for (int i = 0; i < collisionList.size(); ++i) {
575 QGraphicsItem *item = collisionList.at(i);
576 if (item->type() == 70000)
578 int diff = ((ClipItem *)item)->endPos() + 1 - m_startPos;
579 setRect((m_startPos + diff) * scale, rect().y(), (m_cropDuration - diff) * scale, rect().height());
582 m_cropDuration -= diff;
586 if (m_hasThumbs) startThumbTimer->start(100);
589 void ClipItem::resizeEnd(int posx, double scale)
591 int durationDiff = posx - endPos();
592 if (durationDiff == 0) return;
593 kDebug()<<"-- RESCALE: CROP="<<m_cropStart<<", DIFF = "<<durationDiff;
594 if (m_cropDuration + durationDiff <= 0) {
595 durationDiff = - (m_cropDuration - 3);
597 else if (m_cropDuration + durationDiff >= m_maxDuration) {
598 durationDiff = m_maxDuration - m_cropDuration;
600 m_cropDuration += durationDiff;
601 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
602 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
603 for (int i = 0; i < collisionList.size(); ++i) {
604 QGraphicsItem *item = collisionList.at(i);
605 if (item->type() == 70000)
607 int diff = ((ClipItem *)item)->startPos() - 1 - startPos();
608 m_cropDuration = diff;
609 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
613 if (m_hasThumbs) endThumbTimer->start(100);
617 void ClipItem::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
621 int ClipItem::track()
626 void ClipItem::setTrack(int track)
631 int ClipItem::effectsCounter()
633 return m_effectsCounter++;
636 int ClipItem::effectsCount()
638 return m_effectList.size();
641 QStringList ClipItem::effectNames()
643 return m_effectList.effectNames();
646 QDomElement ClipItem::effectAt(int ix)
648 return m_effectList.at(ix);
651 void ClipItem::setEffectAt(int ix, QDomElement effect)
653 kDebug()<<"CHange EFFECT AT: "<<ix<<", CURR: "<<m_effectList.at(ix).attribute("tag")<<", NEW: "<<effect.attribute("tag");
654 m_effectList.insert(ix, effect);
655 m_effectList.removeAt(ix + 1);
656 update(boundingRect());
659 QMap <QString, QString> ClipItem::addEffect(QDomElement effect)
661 QMap <QString, QString> effectParams;
662 m_effectList.append(effect);
663 effectParams["tag"] = effect.attribute("tag");
664 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
665 QString state = effect.attribute("disabled");
666 if (!state.isEmpty()) effectParams["disabled"] = state;
667 QDomNodeList params = effect.elementsByTagName("parameter");
668 for (int i = 0; i < params.count(); i++) {
669 QDomElement e = params.item(i).toElement();
671 effectParams[e.attribute("name")] = e.attribute("value");
673 if (!e.attribute("factor").isEmpty()){
674 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble()/e.attribute("factor").toDouble());
678 update(boundingRect());
682 QMap <QString, QString> ClipItem::getEffectArgs(QDomElement effect)
684 QMap <QString, QString> effectParams;
685 effectParams["tag"] = effect.attribute("tag");
686 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
687 QString state = effect.attribute("disabled");
688 if (!state.isEmpty()) effectParams["disabled"] = state;
689 QDomNodeList params = effect.elementsByTagName("parameter");
690 for (int i = 0; i < params.count(); i++) {
691 QDomElement e = params.item(i).toElement();
692 if (e.attribute("name").contains(";")){
693 QString format=e.attribute("format");
694 QStringList separators=format.split("%d",QString::SkipEmptyParts);
695 QStringList values=e.attribute("value").split(QRegExp("[,:;x]"));
697 QTextStream txtNeu(&neu);
699 txtNeu << (int)values[0].toDouble();
700 for (int i=0;i<separators.size() && i+1<values.size();i++){
701 txtNeu << separators[i];
702 txtNeu << (int)(values[i+1].toDouble());
704 effectParams["start"]=neu;
707 effectParams[e.attribute("name")] = e.attribute("value");
709 if (!e.attribute("factor").isEmpty()){
710 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble()/e.attribute("factor").toDouble());
716 void ClipItem::deleteEffect(QString index)
718 for (int i = 0; i < m_effectList.size(); ++i) {
719 if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
720 m_effectList.removeAt(i);
725 update(boundingRect());
729 void ClipItem::dropEvent ( QGraphicsSceneDragDropEvent * event )
731 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
733 doc.setContent(effects, true);
734 QDomElement e = doc.documentElement();
735 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
736 if (view) view->slotAddEffect(e, GenTime(m_startPos, 25), m_track);
740 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
742 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
745 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
752 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
754 int pos = event->x();
755 if (event->modifiers() == Qt::ControlModifier)
756 setDragMode(QGraphicsView::ScrollHandDrag);
757 else if (event->modifiers() == Qt::ShiftModifier)
758 setDragMode(QGraphicsView::RubberBandDrag);
760 QGraphicsItem * item = itemAt(event->pos());
763 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
766 QGraphicsView::mousePressEvent(event);
769 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
771 QGraphicsView::mouseReleaseEvent(event);
772 setDragMode(QGraphicsView::NoDrag);
776 #include "clipitem.moc"