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),audioThumbReady(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);
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)));
67 setBrush(QColor(100, 100, 150));
68 if (m_clipType == VIDEO || m_clipType == AV) {
70 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
71 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
72 connect(clip, SIGNAL (gotAudioData()), this, SLOT (slotGotAudioData()));
73 QTimer::singleShot(300, this, SLOT(slotFetchThumbs()));
75 startThumbTimer = new QTimer(this);
76 startThumbTimer->setSingleShot(true);
77 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
78 endThumbTimer = new QTimer(this);
79 endThumbTimer->setSingleShot(true);
80 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
83 else if (m_clipType == COLOR) {
84 QString colour = m_xml.attribute("colour");
85 colour = colour.replace(0, 2, "#");
86 setBrush(QColor(colour.left(7)));
88 else if (m_clipType == IMAGE) {
89 m_startPix = KThumb::getImage(KUrl(m_xml.attribute("resource")), 50 * KdenliveSettings::project_display_ratio(), 50);
91 else if (m_clipType == AUDIO) {
92 connect(clip, SIGNAL (gotAudioData()), this, SLOT (slotGotAudioData()));
99 if (startThumbTimer) delete startThumbTimer;
100 if (endThumbTimer) delete endThumbTimer;
103 void ClipItem::slotFetchThumbs()
105 emit getThumb(m_cropStart, m_cropStart + m_cropDuration);
108 void ClipItem::slotGetStartThumb()
110 emit getThumb(m_cropStart, -1);
113 void ClipItem::slotGetEndThumb()
115 emit getThumb(-1, m_cropStart + m_cropDuration);
118 void ClipItem::slotThumbReady(int frame, QPixmap pix)
120 if (frame == m_cropStart) m_startPix = pix;
125 void ClipItem::slotGotAudioData(){
126 audioThumbReady=true;
130 int ClipItem::type () const
135 DocClipBase *ClipItem::baseClip()
140 QDomElement ClipItem::xml() const
145 int ClipItem::clipType()
150 QString ClipItem::clipName()
155 int ClipItem::clipProducer()
160 int ClipItem::maxDuration()
162 return m_maxDuration;
165 int ClipItem::duration()
167 return m_cropDuration;
170 int ClipItem::startPos()
175 int ClipItem::cropStart()
180 int ClipItem::endPos()
182 return m_startPos + m_cropDuration;
185 void ClipItem::flashClip()
187 if (m_timeLine == 0) {
188 m_timeLine = new QTimeLine(750, this);
189 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
194 void ClipItem::animate(qreal value)
201 void ClipItem::paint(QPainter *painter,
202 const QStyleOptionGraphicsItem *option,
205 painter->setOpacity(m_opacity);
206 QBrush paintColor = brush();
207 if (isSelected()) paintColor = QBrush(QColor(150, 50, 100));
209 QRect rectInView;//this is the rect that is visible by the user
210 if (scene()->views().size()>0){
211 rectInView=scene()->views()[0]->viewport()->rect();
212 rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(),scene()->views()[0]->verticalScrollBar()->value());
213 rectInView.adjust(-10,-10,10,10);//make view rect 10 pixel greater on each site, or repaint after scroll event
214 //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value();
216 if (rectInView.isNull())
218 QPainterPath clippath;
219 clippath.addRect(rectInView);
220 int startpixel=rectInView.x()-rect().x();//start and endpixel that is viewable from rect()
223 int endpixel=rectInView.width()+rectInView.x();
227 painter->setRenderHints(QPainter::Antialiasing);
228 QPainterPath roundRectPathUpper,roundRectPathLower;
229 double roundingY = 20;
230 double roundingX = 20;
232 painter->setClipRect(option->exposedRect);
233 if (roundingX > br.width() / 2) roundingX = br.width() / 2;
234 //kDebug()<<"-----PAINTING, SCAL: "<<scale<<", height: "<<br.height();
235 roundRectPathUpper.moveTo(br.x() + br .width() - offset, br.y() + br.height()/2 - offset);
236 roundRectPathUpper.arcTo(br.x() + br .width() - roundingX - offset, br.y(), roundingX, roundingY, 0.0, 90.0);
237 roundRectPathUpper.lineTo(br.x() + roundingX, br.y());
238 roundRectPathUpper.arcTo(br.x() + offset, br.y(), roundingX, roundingY, 90.0, 90.0);
239 roundRectPathUpper.lineTo(br.x() + offset, br.y() + br.height()/2 - offset);
240 roundRectPathUpper.closeSubpath();
242 roundRectPathLower.moveTo(br.x() + offset, br.y() + br.height()/2 - offset);
243 roundRectPathLower.arcTo(br.x() + offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 180.0, 90.0);
244 roundRectPathLower.lineTo(br.x() + br .width() - roundingX, br.y() + br.height() - offset);
245 roundRectPathLower.arcTo(br.x() + br .width() - roundingX - offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 270.0, 90.0);
246 roundRectPathLower.lineTo(br.x() + br .width() - offset, br.y()+ br.height()/2 - offset);
247 roundRectPathLower.closeSubpath();
249 painter->setClipPath(roundRectPathUpper.united(roundRectPathLower).intersected(clippath), Qt::IntersectClip);
250 //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
251 painter->fillRect(br.intersected(rectInView), paintColor);
252 //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
255 if (!m_startPix.isNull()) {
256 if (m_clipType == IMAGE) {
257 painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
258 QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
259 painter->drawLine(l);
261 painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
262 QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
263 painter->drawLine(l);
266 painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
267 QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
268 painter->drawLine(l2);
270 if ( ( m_clipType == AV || m_clipType==AUDIO ||true) && audioThumbReady ){
272 QPainterPath path= m_clipType==AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
273 painter->fillPath(path,QBrush(QColor(200,200,200,127)));
276 double pixelForOneFrame=(double)br.width()/duration();
278 emit prepareAudioThumb(pixelForOneFrame,path,startpixel,endpixel+200);//200 more for less missing parts before repaint after scrolling
280 for (int startCache=startpixel-startpixel%100; startCache < endpixel+300;startCache+=100){
281 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull() )
282 painter->drawPixmap(path.boundingRect().x()+startCache,path.boundingRect().y(),audioThumbCachePic[startCache]);
287 // draw start / end fades
288 double scale = br.width() / m_cropDuration;
291 fades = QBrush(QColor(200, 50, 50, 150));
293 else fades = QBrush(QColor(200, 200, 200, 200));
295 if (m_startFade != 0) {
296 QPainterPath fadeInPath;
297 fadeInPath.moveTo(br.x() - offset, br.y());
298 fadeInPath.lineTo(br.x() - offset, br.y() + br.height());
299 fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
300 fadeInPath.closeSubpath();
301 painter->fillPath(fadeInPath, fades);
303 QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
304 painter->drawLine(l);
307 if (m_endFade != 0) {
308 QPainterPath fadeOutPath;
309 fadeOutPath.moveTo(br.x() + br.width(), br.y());
310 fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
311 fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
312 fadeOutPath.closeSubpath();
313 painter->fillPath(fadeOutPath, fades);
315 QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
316 painter->drawLine(l);
320 QPen pen = painter->pen();
321 pen.setColor(Qt::white);
322 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
324 QString effects = effectNames().join(" / ");
325 if (!effects.isEmpty()) {
326 painter->setPen(pen);
327 QFont font = painter->font();
328 QFont smallFont = font;
329 smallFont.setPointSize(8);
330 painter->setFont(smallFont);
331 QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " ");
332 painter->fillRect(txtBounding, QBrush(QColor(0,0,0,150)));
333 painter->drawText(txtBounding, Qt::AlignCenter, effects);
334 pen.setColor(Qt::black);
335 painter->setPen(pen);
336 painter->setFont(font);
339 pen.setColor(Qt::red);
340 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
341 if (isSelected()) painter->setPen(pen);
342 painter->setClipRect(option->exposedRect);
343 painter->drawPath(roundRectPathUpper.united(roundRectPathLower).intersected(clippath));
345 QRectF txtBounding = painter->boundingRect(br, Qt::AlignCenter, " " + m_clipName + " ");
346 painter->fillRect(txtBounding, QBrush(QColor(255,255,255,150)));
347 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
350 //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150)));
351 //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
353 /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
354 painter->drawRect(recta);
355 painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
356 painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
357 painter->setPen(QPen(Qt::black, 1.0));
358 painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
359 painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
361 //QGraphicsRectItem::paint(painter, option, widget);
362 //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
363 //painter->setPen(pen);
364 //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
365 //kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
366 //painter->drawText(rect(), Qt::AlignCenter, m_name);
367 // painter->drawRect(boundingRect());
368 //painter->drawRoundRect(-10, -10, 20, 20);
372 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale)
374 if (abs(pos.x() - (rect().x() + scale * m_startFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEIN;
375 else if (abs(pos.x() - rect().x()) < 6) return RESIZESTART;
376 else if (abs(pos.x() - (rect().x() + rect().width() - scale * m_endFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEOUT;
377 else if (abs(pos.x() - (rect().x() + rect().width())) < 6) return RESIZEEND;
381 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame,QPainterPath path,int startpixel, int endpixel){
384 QRectF re=path.boundingRect();
386 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
388 for (int startCache=startpixel-startpixel%100;startCache+100<endpixel ;startCache+=100){
389 //kDebug() << "creating " << startCache;
390 //if (framePixelWidth!=pixelForOneFrame ||
391 if (framePixelWidth==pixelForOneFrame && audioThumbCachePic.contains(startCache))
393 if (audioThumbCachePic[startCache].isNull() || framePixelWidth!=pixelForOneFrame){
394 audioThumbCachePic[startCache]=QPixmap(100,re.height());
395 audioThumbCachePic[startCache].fill(QColor(200,200,200,127));
397 bool fullAreaDraw=pixelForOneFrame<10;
398 QMap<int,QPainterPath > positiveChannelPaths;
399 QMap<int,QPainterPath > negativeChannelPaths;
400 QPainter pixpainter(&audioThumbCachePic[startCache]);
402 audiopen.setWidth(0);
403 pixpainter.setPen(audiopen);
404 pixpainter.setRenderHint(QPainter::Antialiasing,true);
405 //pixpainter.drawLine(0,0,100,re.height());
406 int channelHeight=audioThumbCachePic[startCache].height()/channels;
408 for (int i=0;i<channels;i++){
410 positiveChannelPaths[i].moveTo(0,channelHeight*i+ channelHeight/2);
411 negativeChannelPaths[i].moveTo(0,channelHeight*i+ channelHeight/2);
414 for (int samples=0;samples<=100;samples++){
415 double frame=(double)(samples+startCache-0)/pixelForOneFrame;
416 int sample=(frame-(int)(frame))*20 ;// AUDIO_FRAME_SIZE
417 if (frame<0 || sample< 0 || sample>19 )
419 QMap<int,QByteArray> frame_channel_data=baseClip()->audioFrameChache[(int)frame];
421 for (int channel=0;channel<channels && frame_channel_data[channel].size()> 0;channel++){
423 int y=channelHeight*channel+ channelHeight/2;
424 int delta=(int)(frame_channel_data[channel][sample] -127/2 ) * channelHeight/ 64;
426 positiveChannelPaths[channel].lineTo(samples,0.1+y+qAbs( delta ));
427 negativeChannelPaths[channel].lineTo(samples,0.1+y-qAbs( delta ));
429 positiveChannelPaths[channel].lineTo(samples,0.1+y+delta);
430 negativeChannelPaths[channel].lineTo(samples,0.1+y-delta);
434 for (int i=0;i<channels;i++){
436 pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
437 pixpainter.setBrush(QBrush(QColor(200,200,100,200)));
438 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
440 pixpainter.drawPath(positiveChannelPaths[i]);
443 //audioThumbWasDrawn=true;
444 framePixelWidth=pixelForOneFrame;
449 int ClipItem::fadeIn() const
454 int ClipItem::fadeOut() const
459 void ClipItem::setFadeIn(int pos, double scale)
461 int oldIn = m_startFade;
462 if (pos < 0) pos = 0;
463 if (pos > m_cropDuration) pos = m_cropDuration / 2;
465 if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
466 else update(rect().x(), rect().y(), pos * scale, rect().height());
469 void ClipItem::setFadeOut(int pos, double scale)
471 int oldOut = m_endFade;
472 if (pos < 0) pos = 0;
473 if (pos > m_cropDuration) pos = m_cropDuration / 2;
475 if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
476 else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
482 void ClipItem::mousePressEvent ( QGraphicsSceneMouseEvent * event )
484 /*m_resizeMode = operationMode(event->pos());
485 if (m_resizeMode == MOVE) {
486 m_maxTrack = scene()->sceneRect().height();
487 m_grabPoint = (int) (event->pos().x() - rect().x());
489 QGraphicsRectItem::mousePressEvent(event);
493 void ClipItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
496 QGraphicsRectItem::mouseReleaseEvent(event);
499 void ClipItem::moveTo(int x, double scale, double offset, int newTrack)
501 double origX = rect().x();
502 double origY = rect().y();
505 setRect(x * scale, origY + offset, rect().width(), rect().height());
506 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
507 if (collisionList.size() == 0) m_track = newTrack;
508 for (int i = 0; i < collisionList.size(); ++i) {
509 QGraphicsItem *item = collisionList.at(i);
510 if (item->type() == 70000)
514 QRectF other = ((QGraphicsRectItem *)item)->rect();
515 if (x < m_startPos) {
516 kDebug()<<"COLLISION, MOVING TO------";
517 m_startPos = ((ClipItem *)item)->endPos() + 1;
518 origX = m_startPos * scale;
521 kDebug()<<"COLLISION, MOVING TO+++";
522 m_startPos = ((ClipItem *)item)->startPos() - m_cropDuration;
523 origX = m_startPos * scale;
526 setRect(origX, origY, rect().width(), rect().height());
537 /* QList <QGraphicsItem *> childrenList = QGraphicsItem::children();
538 for (int i = 0; i < childrenList.size(); ++i) {
539 childrenList.at(i)->moveBy(rect().x() - origX , offset);
543 void ClipItem::resizeStart(int posx, double scale)
545 int durationDiff = posx - m_startPos;
546 if (durationDiff == 0) return;
547 kDebug()<<"-- RESCALE: CROP="<<m_cropStart<<", DIFF = "<<durationDiff;
548 if (m_cropStart + durationDiff < 0) {
549 durationDiff = -m_cropStart;
551 else if (durationDiff >= m_cropDuration) {
552 durationDiff = m_cropDuration - 3;
554 m_startPos += durationDiff;
555 m_cropStart += durationDiff;
556 m_cropDuration -= durationDiff;
557 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
558 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
559 for (int i = 0; i < collisionList.size(); ++i) {
560 QGraphicsItem *item = collisionList.at(i);
561 if (item->type() == 70000)
563 int diff = ((ClipItem *)item)->endPos() + 1 - m_startPos;
564 setRect((m_startPos + diff) * scale, rect().y(), (m_cropDuration - diff) * scale, rect().height());
567 m_cropDuration -= diff;
571 if (m_hasThumbs) startThumbTimer->start(100);
574 void ClipItem::resizeEnd(int posx, double scale)
576 int durationDiff = posx - endPos();
577 if (durationDiff == 0) return;
578 kDebug()<<"-- RESCALE: CROP="<<m_cropStart<<", DIFF = "<<durationDiff;
579 if (m_cropDuration + durationDiff <= 0) {
580 durationDiff = - (m_cropDuration - 3);
582 else if (m_cropDuration + durationDiff >= m_maxDuration) {
583 durationDiff = m_maxDuration - m_cropDuration;
585 m_cropDuration += durationDiff;
586 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
587 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
588 for (int i = 0; i < collisionList.size(); ++i) {
589 QGraphicsItem *item = collisionList.at(i);
590 if (item->type() == 70000)
592 int diff = ((ClipItem *)item)->startPos() - 1 - startPos();
593 m_cropDuration = diff;
594 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
598 if (m_hasThumbs) endThumbTimer->start(100);
602 void ClipItem::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
606 int ClipItem::track()
611 void ClipItem::setTrack(int track)
616 int ClipItem::effectsCounter()
618 return m_effectsCounter++;
621 int ClipItem::effectsCount()
623 return m_effectList.size();
626 QStringList ClipItem::effectNames()
628 return m_effectList.effectNames();
631 QDomElement ClipItem::effectAt(int ix)
633 return m_effectList.at(ix);
636 void ClipItem::setEffectAt(int ix, QDomElement effect)
638 kDebug()<<"CHange EFFECT AT: "<<ix<<", CURR: "<<m_effectList.at(ix).attribute("tag")<<", NEW: "<<effect.attribute("tag");
639 m_effectList.insert(ix, effect);
640 m_effectList.removeAt(ix + 1);
641 update(boundingRect());
644 QMap <QString, QString> ClipItem::addEffect(QDomElement effect)
646 QMap <QString, QString> effectParams;
647 m_effectList.append(effect);
648 effectParams["tag"] = effect.attribute("tag");
649 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
650 QString state = effect.attribute("disabled");
651 if (!state.isEmpty()) effectParams["disabled"] = state;
652 QDomNodeList params = effect.elementsByTagName("parameter");
653 for (int i = 0; i < params.count(); i++) {
654 QDomElement e = params.item(i).toElement();
656 effectParams[e.attribute("name")] = e.attribute("value");
659 update(boundingRect());
663 QMap <QString, QString> ClipItem::getEffectArgs(QDomElement effect)
665 QMap <QString, QString> effectParams;
666 effectParams["tag"] = effect.attribute("tag");
667 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
668 QString state = effect.attribute("disabled");
669 if (!state.isEmpty()) effectParams["disabled"] = state;
670 QDomNodeList params = effect.elementsByTagName("parameter");
671 for (int i = 0; i < params.count(); i++) {
672 QDomElement e = params.item(i).toElement();
673 if (e.attribute("name").contains(";")){
674 QString format=e.attribute("format");
675 QStringList separators=format.split("%d",QString::SkipEmptyParts);
676 QStringList values=e.attribute("value").split(QRegExp("[,:;x]"));
678 QTextStream txtNeu(&neu);
680 txtNeu << (int)values[0].toDouble();
681 for (int i=0;i<separators.size() && i+1<values.size();i++){
682 txtNeu << separators[i];
683 txtNeu << (int)(values[i+1].toDouble());
685 effectParams["start"]=neu;
688 effectParams[e.attribute("name")] = e.attribute("value");
693 void ClipItem::deleteEffect(QString index)
695 for (int i = 0; i < m_effectList.size(); ++i) {
696 if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
697 m_effectList.removeAt(i);
702 update(boundingRect());
706 void ClipItem::dropEvent ( QGraphicsSceneDragDropEvent * event )
708 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
710 doc.setContent(effects, true);
711 QDomElement e = doc.documentElement();
712 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
713 if (view) view->slotAddEffect(e, GenTime(m_startPos, 25), m_track);
717 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
719 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
722 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
729 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
731 int pos = event->x();
732 if (event->modifiers() == Qt::ControlModifier)
733 setDragMode(QGraphicsView::ScrollHandDrag);
734 else if (event->modifiers() == Qt::ShiftModifier)
735 setDragMode(QGraphicsView::RubberBandDrag);
737 QGraphicsItem * item = itemAt(event->pos());
740 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
743 QGraphicsView::mousePressEvent(event);
746 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
748 QGraphicsView::mouseReleaseEvent(event);
749 setDragMode(QGraphicsView::NoDrag);
753 #include "clipitem.moc"