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(0),audioThumbWasDrawn(false),m_opacity(1.0), m_timeLine(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();
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;
62 if (duration != -1) m_cropDuration = duration;
63 else m_cropDuration = m_maxDuration;*/
66 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemClipsChildrenToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
67 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 emit getThumb(m_cropStart, m_cropStart + m_cropDuration);
109 void ClipItem::slotGetStartThumb()
111 emit getThumb(m_cropStart, -1);
114 void ClipItem::slotGetEndThumb()
116 emit getThumb(-1, m_cropStart + m_cropDuration);
119 void ClipItem::slotThumbReady(int frame, QPixmap pix)
121 if (frame == m_cropStart) m_startPix = pix;
126 void ClipItem::slotGotAudioData(){
127 audioThumbReady=true;
131 int ClipItem::type () const
136 DocClipBase *ClipItem::baseClip()
141 QDomElement ClipItem::xml() const
146 int ClipItem::clipType()
151 QString ClipItem::clipName()
156 int ClipItem::clipProducer()
161 int ClipItem::maxDuration()
163 return m_maxDuration;
166 int ClipItem::duration()
168 return m_cropDuration;
171 int ClipItem::startPos()
176 int ClipItem::cropStart()
181 int ClipItem::endPos()
183 return m_startPos + m_cropDuration;
186 void ClipItem::flashClip()
188 if (m_timeLine == 0) {
189 m_timeLine = new QTimeLine(750, this);
190 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
195 void ClipItem::animate(qreal value)
202 void ClipItem::paint(QPainter *painter,
203 const QStyleOptionGraphicsItem *option,
206 painter->setOpacity(m_opacity);
207 QBrush paintColor = brush();
208 if (isSelected()) paintColor = QBrush(QColor(150, 50, 100));
210 QRect rectInView;//this is the rect that is visible by the user
211 if (scene()->views().size()>0){
212 rectInView=scene()->views()[0]->viewport()->rect();
213 rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(),scene()->views()[0]->verticalScrollBar()->value());
214 rectInView.adjust(-10,-10,10,10);//make view rect 10 pixel greater on each site, or repaint after scroll event
215 //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value();
217 if (rectInView.isNull())
219 QPainterPath clippath;
220 clippath.addRect(rectInView);
221 int startpixel=rectInView.x()-rect().x();//start and endpixel that is viewable from rect()
224 int endpixel=rectInView.width()+rectInView.x();
228 painter->setRenderHints(QPainter::Antialiasing);
229 QPainterPath roundRectPathUpper,roundRectPathLower;
230 double roundingY = 20;
231 double roundingX = 20;
233 painter->setClipRect(option->exposedRect);
234 if (roundingX > br.width() / 2) roundingX = br.width() / 2;
235 //kDebug()<<"-----PAINTING, SCAL: "<<scale<<", height: "<<br.height();
236 roundRectPathUpper.moveTo(br.x() + br .width() - offset, br.y() + br.height()/2 - offset);
237 roundRectPathUpper.arcTo(br.x() + br .width() - roundingX - offset, br.y(), roundingX, roundingY, 0.0, 90.0);
238 roundRectPathUpper.lineTo(br.x() + roundingX, br.y());
239 roundRectPathUpper.arcTo(br.x() + offset, br.y(), roundingX, roundingY, 90.0, 90.0);
240 roundRectPathUpper.lineTo(br.x() + offset, br.y() + br.height()/2 - offset);
241 roundRectPathUpper.closeSubpath();
243 roundRectPathLower.moveTo(br.x() + offset, br.y() + br.height()/2 - offset);
244 roundRectPathLower.arcTo(br.x() + offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 180.0, 90.0);
245 roundRectPathLower.lineTo(br.x() + br .width() - roundingX, br.y() + br.height() - offset);
246 roundRectPathLower.arcTo(br.x() + br .width() - roundingX - offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 270.0, 90.0);
247 roundRectPathLower.lineTo(br.x() + br .width() - offset, br.y()+ br.height()/2 - offset);
248 roundRectPathLower.closeSubpath();
250 painter->setClipPath(roundRectPathUpper.united(roundRectPathLower).intersected(clippath), Qt::IntersectClip);
251 //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
252 painter->fillRect(br.intersected(rectInView), paintColor);
253 //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
256 if (!m_startPix.isNull()) {
257 if (m_clipType == IMAGE) {
258 painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
259 QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
260 painter->drawLine(l);
262 painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
263 QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
264 painter->drawLine(l);
267 painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
268 QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
269 painter->drawLine(l2);
271 if ( ( m_clipType == AV || m_clipType==AUDIO || true) && audioThumbReady ){
273 QPainterPath path= m_clipType==AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
274 painter->fillPath(path,QBrush(QColor(200,200,200,127)));
277 double pixelForOneFrame=(double)br.width()/duration();
279 emit prepareAudioThumb(pixelForOneFrame,path,startpixel,endpixel+200);//200 more for less missing parts before repaint after scrolling
281 for (int startCache=startpixel-startpixel%100; startCache < endpixel+300;startCache+=100){
282 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull() )
283 painter->drawPixmap(path.boundingRect().x()+startCache,path.boundingRect().y(),audioThumbCachePic[startCache]);
288 // draw start / end fades
289 double scale = br.width() / m_cropDuration;
292 fades = QBrush(QColor(200, 50, 50, 150));
294 else fades = QBrush(QColor(200, 200, 200, 200));
296 if (m_startFade != 0) {
297 QPainterPath fadeInPath;
298 fadeInPath.moveTo(br.x() - offset, br.y());
299 fadeInPath.lineTo(br.x() - offset, br.y() + br.height());
300 fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
301 fadeInPath.closeSubpath();
302 painter->fillPath(fadeInPath, fades);
304 QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
305 painter->drawLine(l);
308 if (m_endFade != 0) {
309 QPainterPath fadeOutPath;
310 fadeOutPath.moveTo(br.x() + br.width(), br.y());
311 fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
312 fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
313 fadeOutPath.closeSubpath();
314 painter->fillPath(fadeOutPath, fades);
316 QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
317 painter->drawLine(l);
321 QPen pen = painter->pen();
322 pen.setColor(Qt::white);
323 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
325 QString effects = effectNames().join(" / ");
326 if (!effects.isEmpty()) {
327 painter->setPen(pen);
328 QFont font = painter->font();
329 QFont smallFont = font;
330 smallFont.setPointSize(8);
331 painter->setFont(smallFont);
332 QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " ");
333 painter->fillRect(txtBounding, QBrush(QColor(0,0,0,150)));
334 painter->drawText(txtBounding, Qt::AlignCenter, effects);
335 pen.setColor(Qt::black);
336 painter->setPen(pen);
337 painter->setFont(font);
340 pen.setColor(Qt::red);
341 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
342 if (isSelected()) painter->setPen(pen);
343 painter->setClipRect(option->exposedRect);
344 painter->drawPath(roundRectPathUpper.united(roundRectPathLower).intersected(clippath));
346 QRectF txtBounding = painter->boundingRect(br, Qt::AlignCenter, " " + m_clipName + " ");
347 painter->fillRect(txtBounding, QBrush(QColor(255,255,255,150)));
348 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
351 //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150)));
352 //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
354 /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
355 painter->drawRect(recta);
356 painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
357 painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
358 painter->setPen(QPen(Qt::black, 1.0));
359 painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
360 painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
362 //QGraphicsRectItem::paint(painter, option, widget);
363 //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
364 //painter->setPen(pen);
365 //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
366 //kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
367 //painter->drawText(rect(), Qt::AlignCenter, m_name);
368 // painter->drawRect(boundingRect());
369 //painter->drawRoundRect(-10, -10, 20, 20);
373 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale)
375 if (abs(pos.x() - (rect().x() + scale * m_startFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEIN;
376 else if (abs(pos.x() - rect().x()) < 6) return RESIZESTART;
377 else if (abs(pos.x() - (rect().x() + rect().width() - scale * m_endFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEOUT;
378 else if (abs(pos.x() - (rect().x() + rect().width())) < 6) return RESIZEEND;
382 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame,QPainterPath path,int startpixel, int endpixel){
385 QRectF re=path.boundingRect();
387 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
389 for (int startCache=startpixel-startpixel%100;startCache+100<endpixel ;startCache+=100){
390 //kDebug() << "creating " << startCache;
391 //if (framePixelWidth!=pixelForOneFrame ||
392 if (framePixelWidth==pixelForOneFrame && audioThumbCachePic.contains(startCache))
394 if (audioThumbCachePic[startCache].isNull() || framePixelWidth!=pixelForOneFrame){
395 audioThumbCachePic[startCache]=QPixmap(100,re.height());
396 audioThumbCachePic[startCache].fill(QColor(200,200,200,127));
398 bool fullAreaDraw=pixelForOneFrame<10;
399 QMap<int,QPainterPath > positiveChannelPaths;
400 QMap<int,QPainterPath > negativeChannelPaths;
401 QPainter pixpainter(&audioThumbCachePic[startCache]);
403 audiopen.setWidth(0);
404 pixpainter.setPen(audiopen);
405 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
406 //pixpainter.drawLine(0,0,100,re.height());
407 int channelHeight=audioThumbCachePic[startCache].height()/channels;
409 for (int i=0;i<channels;i++){
411 positiveChannelPaths[i].moveTo(0,channelHeight*i+ channelHeight/2);
412 negativeChannelPaths[i].moveTo(0,channelHeight*i+ channelHeight/2);
415 for (int samples=0;samples<=100;samples++){
416 double frame=(double)(samples+startCache-0)/pixelForOneFrame;
417 int sample=(frame-(int)(frame))*20 ;// AUDIO_FRAME_SIZE
418 if (frame<0 || sample< 0 || sample>19 )
420 QMap<int,QByteArray> frame_channel_data=baseClip()->audioFrameChache[(int)frame];
422 for (int channel=0;channel<channels && frame_channel_data[channel].size()> 0;channel++){
424 int y=channelHeight*channel+ channelHeight/2;
425 int delta=(int)(frame_channel_data[channel][sample] -127/2 ) * channelHeight/ 64;
427 positiveChannelPaths[channel].lineTo(samples,0.1+y+qAbs( delta ));
428 negativeChannelPaths[channel].lineTo(samples,0.1+y-qAbs( delta ));
430 positiveChannelPaths[channel].lineTo(samples,0.1+y+delta);
431 negativeChannelPaths[channel].lineTo(samples,0.1+y-delta);
436 for (int i=0;i<channels;i++){
438 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
439 pixpainter.setBrush(QBrush(QColor(200,200,100,200)));
440 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
442 pixpainter.drawPath(positiveChannelPaths[i]);
445 //audioThumbWasDrawn=true;
446 framePixelWidth=pixelForOneFrame;
451 int ClipItem::fadeIn() const
456 int ClipItem::fadeOut() const
461 void ClipItem::setFadeIn(int pos, double scale)
463 int oldIn = m_startFade;
464 if (pos < 0) pos = 0;
465 if (pos > m_cropDuration) pos = m_cropDuration / 2;
467 if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
468 else update(rect().x(), rect().y(), pos * scale, rect().height());
471 void ClipItem::setFadeOut(int pos, double scale)
473 int oldOut = m_endFade;
474 if (pos < 0) pos = 0;
475 if (pos > m_cropDuration) pos = m_cropDuration / 2;
477 if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
478 else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
484 void ClipItem::mousePressEvent ( QGraphicsSceneMouseEvent * event )
486 /*m_resizeMode = operationMode(event->pos());
487 if (m_resizeMode == MOVE) {
488 m_maxTrack = scene()->sceneRect().height();
489 m_grabPoint = (int) (event->pos().x() - rect().x());
491 QGraphicsRectItem::mousePressEvent(event);
495 void ClipItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
498 QGraphicsRectItem::mouseReleaseEvent(event);
501 void ClipItem::moveTo(int x, double scale, double offset, int newTrack)
503 double origX = rect().x();
504 double origY = rect().y();
507 setRect(x * scale, origY + offset, rect().width(), rect().height());
508 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
509 if (collisionList.size() == 0) m_track = newTrack;
510 for (int i = 0; i < collisionList.size(); ++i) {
511 QGraphicsItem *item = collisionList.at(i);
512 if (item->type() == 70000)
516 QRectF other = ((QGraphicsRectItem *)item)->rect();
517 if (x < m_startPos) {
518 kDebug()<<"COLLISION, MOVING TO------";
519 m_startPos = ((ClipItem *)item)->endPos() + 1;
520 origX = m_startPos * scale;
523 kDebug()<<"COLLISION, MOVING TO+++";
524 m_startPos = ((ClipItem *)item)->startPos() - m_cropDuration;
525 origX = m_startPos * scale;
528 setRect(origX, origY, rect().width(), rect().height());
539 /* QList <QGraphicsItem *> childrenList = QGraphicsItem::children();
540 for (int i = 0; i < childrenList.size(); ++i) {
541 childrenList.at(i)->moveBy(rect().x() - origX , offset);
545 void ClipItem::resizeStart(int posx, double scale)
547 int durationDiff = posx - m_startPos;
548 if (durationDiff == 0) return;
549 kDebug()<<"-- RESCALE: CROP="<<m_cropStart<<", DIFF = "<<durationDiff;
550 if (m_cropStart + durationDiff < 0) {
551 durationDiff = -m_cropStart;
553 else if (durationDiff >= m_cropDuration) {
554 durationDiff = m_cropDuration - 3;
556 m_startPos += durationDiff;
557 m_cropStart += durationDiff;
558 m_cropDuration -= durationDiff;
559 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
560 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
561 for (int i = 0; i < collisionList.size(); ++i) {
562 QGraphicsItem *item = collisionList.at(i);
563 if (item->type() == 70000)
565 int diff = ((ClipItem *)item)->endPos() + 1 - m_startPos;
566 setRect((m_startPos + diff) * scale, rect().y(), (m_cropDuration - diff) * scale, rect().height());
569 m_cropDuration -= diff;
573 if (m_hasThumbs) startThumbTimer->start(100);
576 void ClipItem::resizeEnd(int posx, double scale)
578 int durationDiff = posx - endPos();
579 if (durationDiff == 0) return;
580 kDebug()<<"-- RESCALE: CROP="<<m_cropStart<<", DIFF = "<<durationDiff;
581 if (m_cropDuration + durationDiff <= 0) {
582 durationDiff = - (m_cropDuration - 3);
584 else if (m_cropDuration + durationDiff >= m_maxDuration) {
585 durationDiff = m_maxDuration - m_cropDuration;
587 m_cropDuration += durationDiff;
588 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
589 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
590 for (int i = 0; i < collisionList.size(); ++i) {
591 QGraphicsItem *item = collisionList.at(i);
592 if (item->type() == 70000)
594 int diff = ((ClipItem *)item)->startPos() - 1 - startPos();
595 m_cropDuration = diff;
596 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
600 if (m_hasThumbs) endThumbTimer->start(100);
604 void ClipItem::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
608 int ClipItem::track()
613 void ClipItem::setTrack(int track)
618 int ClipItem::effectsCounter()
620 return m_effectsCounter++;
623 int ClipItem::effectsCount()
625 return m_effectList.size();
628 QStringList ClipItem::effectNames()
630 return m_effectList.effectNames();
633 QDomElement ClipItem::effectAt(int ix)
635 return m_effectList.at(ix);
638 void ClipItem::setEffectAt(int ix, QDomElement effect)
640 kDebug()<<"CHange EFFECT AT: "<<ix<<", CURR: "<<m_effectList.at(ix).attribute("tag")<<", NEW: "<<effect.attribute("tag");
641 m_effectList.insert(ix, effect);
642 m_effectList.removeAt(ix + 1);
643 update(boundingRect());
646 QMap <QString, QString> ClipItem::addEffect(QDomElement effect)
648 QMap <QString, QString> effectParams;
649 m_effectList.append(effect);
650 effectParams["tag"] = effect.attribute("tag");
651 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
652 QString state = effect.attribute("disabled");
653 if (!state.isEmpty()) effectParams["disabled"] = state;
654 QDomNodeList params = effect.elementsByTagName("parameter");
655 for (int i = 0; i < params.count(); i++) {
656 QDomElement e = params.item(i).toElement();
658 effectParams[e.attribute("name")] = e.attribute("value");
661 update(boundingRect());
665 QMap <QString, QString> ClipItem::getEffectArgs(QDomElement effect)
667 QMap <QString, QString> effectParams;
668 effectParams["tag"] = effect.attribute("tag");
669 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
670 QString state = effect.attribute("disabled");
671 if (!state.isEmpty()) effectParams["disabled"] = state;
672 QDomNodeList params = effect.elementsByTagName("parameter");
673 for (int i = 0; i < params.count(); i++) {
674 QDomElement e = params.item(i).toElement();
675 if (e.attribute("name").contains(";")){
676 QString format=e.attribute("format");
677 QStringList separators=format.split("%d",QString::SkipEmptyParts);
678 QStringList values=e.attribute("value").split(QRegExp("[,:;x]"));
680 QTextStream txtNeu(&neu);
682 txtNeu << (int)values[0].toDouble();
683 for (int i=0;i<separators.size() && i+1<values.size();i++){
684 txtNeu << separators[i];
685 txtNeu << (int)(values[i+1].toDouble());
687 effectParams["start"]=neu;
690 effectParams[e.attribute("name")] = e.attribute("value");
695 void ClipItem::deleteEffect(QString index)
697 for (int i = 0; i < m_effectList.size(); ++i) {
698 if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
699 m_effectList.removeAt(i);
704 update(boundingRect());
708 void ClipItem::dropEvent ( QGraphicsSceneDragDropEvent * event )
710 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
712 doc.setContent(effects, true);
713 QDomElement e = doc.documentElement();
714 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
715 if (view) view->slotAddEffect(e, GenTime(m_startPos, 25), m_track);
719 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
721 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
724 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
731 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
733 int pos = event->x();
734 if (event->modifiers() == Qt::ControlModifier)
735 setDragMode(QGraphicsView::ScrollHandDrag);
736 else if (event->modifiers() == Qt::ShiftModifier)
737 setDragMode(QGraphicsView::RubberBandDrag);
739 QGraphicsItem * item = itemAt(event->pos());
742 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
745 QGraphicsView::mousePressEvent(event);
748 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
750 QGraphicsView::mouseReleaseEvent(event);
751 setDragMode(QGraphicsView::NoDrag);
755 #include "clipitem.moc"