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>
38 #include "kdenlivesettings.h"
40 ClipItem::ClipItem(DocClipBase *clip, int track, int startpos, const QRectF & rect, int duration)
41 : 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)
44 kDebug()<<"******* CREATING NEW TML CLIP, DUR: "<<duration;
45 m_xml = clip->toXML();
46 m_clipName = clip->name();
47 m_producer = clip->getId();
48 m_clipType = clip->clipType();
50 m_maxDuration = duration;
51 if (duration != -1) m_cropDuration = duration;
52 else m_cropDuration = m_maxDuration;
53 setAcceptDrops (true);
56 m_cropStart = xml.attribute("in", 0).toInt();
57 m_maxDuration = xml.attribute("duration", 0).toInt();
58 if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
60 if (duration != -1) m_cropDuration = duration;
61 else m_cropDuration = m_maxDuration;*/
64 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemClipsChildrenToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
65 connect (this , SIGNAL (prepareAudioThumb(double,QPainterPath,int,int)) , this, SLOT (slotPrepareAudioThumb(double,QPainterPath,int,int)));
66 setBrush(QColor(100, 100, 150));
67 if (m_clipType == VIDEO || m_clipType == AV) {
69 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
70 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
71 connect(clip, SIGNAL (gotAudioData()), this, SLOT (slotGotAudioData()));
72 QTimer::singleShot(300, this, SLOT(slotFetchThumbs()));
74 startThumbTimer = new QTimer(this);
75 startThumbTimer->setSingleShot(true);
76 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
77 endThumbTimer = new QTimer(this);
78 endThumbTimer->setSingleShot(true);
79 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
82 else if (m_clipType == COLOR) {
83 QString colour = m_xml.attribute("colour");
84 colour = colour.replace(0, 2, "#");
85 setBrush(QColor(colour.left(7)));
87 else if (m_clipType == IMAGE) {
88 m_startPix = KThumb::getImage(KUrl(m_xml.attribute("resource")), 50 * KdenliveSettings::project_display_ratio(), 50);
95 if (startThumbTimer) delete startThumbTimer;
96 if (endThumbTimer) delete endThumbTimer;
99 void ClipItem::slotFetchThumbs()
101 emit getThumb(m_cropStart, m_cropStart + m_cropDuration);
104 void ClipItem::slotGetStartThumb()
106 emit getThumb(m_cropStart, -1);
109 void ClipItem::slotGetEndThumb()
111 emit getThumb(-1, m_cropStart + m_cropDuration);
114 void ClipItem::slotThumbReady(int frame, QPixmap pix)
116 if (frame == m_cropStart) m_startPix = pix;
121 void ClipItem::slotGotAudioData(){
122 audioThumbReady=true;
126 int ClipItem::type () const
131 DocClipBase *ClipItem::baseClip()
136 QDomElement ClipItem::xml() const
141 int ClipItem::clipType()
146 QString ClipItem::clipName()
151 int ClipItem::clipProducer()
156 int ClipItem::maxDuration()
158 return m_maxDuration;
161 int ClipItem::duration()
163 return m_cropDuration;
166 int ClipItem::startPos()
171 int ClipItem::cropStart()
176 int ClipItem::endPos()
178 return m_startPos + m_cropDuration;
181 void ClipItem::flashClip()
183 if (m_timeLine == 0) {
184 m_timeLine = new QTimeLine(750, this);
185 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
190 void ClipItem::animate(qreal value)
197 void ClipItem::paint(QPainter *painter,
198 const QStyleOptionGraphicsItem *option,
201 painter->setOpacity(m_opacity);
202 QBrush paintColor = brush();
203 if (isSelected()) paintColor = QBrush(QColor(150, 50, 100));
205 QRect rectInView;//this is the rect that is visible by the user
206 if (scene()->views().size()>0){
207 rectInView=scene()->views()[0]->viewport()->rect();
208 rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(),scene()->views()[0]->verticalScrollBar()->value());
209 rectInView.adjust(-10,-10,10,10);//make view rect 10 pixel greater on each site, or repaint after scroll event
210 //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value();
212 if (rectInView.isNull())
214 QPainterPath clippath;
215 clippath.addRect(rectInView);
216 int startpixel=rectInView.x()-rect().x();//start and endpixel that is viewable from rect()
219 int endpixel=rectInView.width()+rectInView.x();
223 painter->setRenderHints(QPainter::Antialiasing);
224 QPainterPath roundRectPathUpper,roundRectPathLower;
225 double roundingY = 20;
226 double roundingX = 20;
228 painter->setClipRect(option->exposedRect);
229 if (roundingX > br.width() / 2) roundingX = br.width() / 2;
230 //kDebug()<<"-----PAINTING, SCAL: "<<scale<<", height: "<<br.height();
231 roundRectPathUpper.moveTo(br.x() + br .width() - offset, br.y() + br.height()/2 - offset);
232 roundRectPathUpper.arcTo(br.x() + br .width() - roundingX - offset, br.y(), roundingX, roundingY, 0.0, 90.0);
233 roundRectPathUpper.lineTo(br.x() + roundingX, br.y());
234 roundRectPathUpper.arcTo(br.x() + offset, br.y(), roundingX, roundingY, 90.0, 90.0);
235 roundRectPathUpper.lineTo(br.x() + offset, br.y() + br.height()/2 - offset);
236 roundRectPathUpper.closeSubpath();
238 roundRectPathLower.moveTo(br.x() + offset, br.y() + br.height()/2 - offset);
239 roundRectPathLower.arcTo(br.x() + offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 180.0, 90.0);
240 roundRectPathLower.lineTo(br.x() + br .width() - roundingX, br.y() + br.height() - offset);
241 roundRectPathLower.arcTo(br.x() + br .width() - roundingX - offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 270.0, 90.0);
242 roundRectPathLower.lineTo(br.x() + br .width() - offset, br.y()+ br.height()/2 - offset);
243 roundRectPathLower.closeSubpath();
245 painter->setClipPath(roundRectPathUpper.united(roundRectPathLower).intersected(clippath), Qt::IntersectClip);
246 //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
247 painter->fillRect(br.intersected(rectInView), paintColor);
248 //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
251 if (!m_startPix.isNull()) {
252 if (m_clipType == IMAGE) {
253 painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
254 QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
255 painter->drawLine(l);
257 painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
258 QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
259 painter->drawLine(l);
262 painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
263 QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
264 painter->drawLine(l2);
266 if ( ( m_clipType == AV || m_clipType==AUDIO ||true) && audioThumbReady ){
268 QPainterPath path= m_clipType==AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
269 painter->fillPath(path,QBrush(QColor(200,200,200,127)));
272 double pixelForOneFrame=(double)br.width()/duration();
274 emit prepareAudioThumb(pixelForOneFrame,path,startpixel,endpixel+200);//200 more for less missing parts before repaint after scrolling
276 for (int startCache=startpixel-startpixel%100; startCache < endpixel+300;startCache+=100){
277 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull() )
278 painter->drawPixmap(path.boundingRect().x()+startCache,path.boundingRect().y(),audioThumbCachePic[startCache]);
283 // draw start / end fades
284 double scale = br.width() / m_cropDuration;
287 fades = QBrush(QColor(200, 50, 50, 150));
289 else fades = QBrush(QColor(200, 200, 200, 200));
291 if (m_startFade != 0) {
292 QPainterPath fadeInPath;
293 fadeInPath.moveTo(br.x() - offset, br.y());
294 fadeInPath.lineTo(br.x() - offset, br.y() + br.height());
295 fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
296 fadeInPath.closeSubpath();
297 painter->fillPath(fadeInPath, fades);
299 QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
300 painter->drawLine(l);
303 if (m_endFade != 0) {
304 QPainterPath fadeOutPath;
305 fadeOutPath.moveTo(br.x() + br.width(), br.y());
306 fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
307 fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
308 fadeOutPath.closeSubpath();
309 painter->fillPath(fadeOutPath, fades);
311 QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
312 painter->drawLine(l);
316 QPen pen = painter->pen();
317 pen.setColor(Qt::white);
318 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
320 QString effects = effectNames().join(" / ");
321 if (!effects.isEmpty()) {
322 painter->setPen(pen);
323 QFont font = painter->font();
324 QFont smallFont = font;
325 smallFont.setPointSize(8);
326 painter->setFont(smallFont);
327 QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " ");
328 painter->fillRect(txtBounding, QBrush(QColor(0,0,0,150)));
329 painter->drawText(txtBounding, Qt::AlignCenter, effects);
330 pen.setColor(Qt::black);
331 painter->setPen(pen);
332 painter->setFont(font);
335 pen.setColor(Qt::red);
336 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
337 if (isSelected()) painter->setPen(pen);
338 painter->setClipRect(option->exposedRect);
339 painter->drawPath(roundRectPathUpper.united(roundRectPathLower).intersected(clippath));
341 QRectF txtBounding = painter->boundingRect(br, Qt::AlignCenter, " " + m_clipName + " ");
342 painter->fillRect(txtBounding, QBrush(QColor(255,255,255,150)));
343 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
346 //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150)));
347 //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
349 /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
350 painter->drawRect(recta);
351 painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
352 painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
353 painter->setPen(QPen(Qt::black, 1.0));
354 painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
355 painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
357 //QGraphicsRectItem::paint(painter, option, widget);
358 //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
359 //painter->setPen(pen);
360 //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
361 //kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
362 //painter->drawText(rect(), Qt::AlignCenter, m_name);
363 // painter->drawRect(boundingRect());
364 //painter->drawRoundRect(-10, -10, 20, 20);
368 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale)
370 if (abs(pos.x() - (rect().x() + scale * m_startFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEIN;
371 else if (abs(pos.x() - rect().x()) < 6) return RESIZESTART;
372 else if (abs(pos.x() - (rect().x() + rect().width() - scale * m_endFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEOUT;
373 else if (abs(pos.x() - (rect().x() + rect().width())) < 6) return RESIZEEND;
377 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame,QPainterPath path,int startpixel, int endpixel){
380 QRectF re=path.boundingRect();
382 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
384 for (int startCache=startpixel-startpixel%100;startCache+100<endpixel ;startCache+=100){
385 //kDebug() << "creating " << startCache;
386 //if (framePixelWidth!=pixelForOneFrame ||
387 if (framePixelWidth==pixelForOneFrame && audioThumbCachePic.contains(startCache))
389 if (audioThumbCachePic[startCache].isNull() || framePixelWidth!=pixelForOneFrame){
390 audioThumbCachePic[startCache]=QPixmap(100,re.height());
391 audioThumbCachePic[startCache].fill(QColor(200,200,200,127));
393 bool fullAreaDraw=pixelForOneFrame<10;
394 QMap<int,QPainterPath > positiveChannelPaths;
395 QMap<int,QPainterPath > negativeChannelPaths;
396 QPainter pixpainter(&audioThumbCachePic[startCache]);
398 audiopen.setWidth(0);
399 pixpainter.setPen(audiopen);
400 pixpainter.setRenderHint(QPainter::Antialiasing,true);
401 //pixpainter.drawLine(0,0,100,re.height());
402 int channelHeight=audioThumbCachePic[startCache].height()/channels;
404 for (int i=0;i<channels;i++){
406 positiveChannelPaths[i].moveTo(0,channelHeight*i+ channelHeight/2);
407 negativeChannelPaths[i].moveTo(0,channelHeight*i+ channelHeight/2);
410 for (int samples=0;samples<=100;samples++){
411 double frame=(double)(samples+startCache-0)/pixelForOneFrame;
412 int sample=(frame-(int)(frame))*20 ;// AUDIO_FRAME_SIZE
413 if (frame<0 || sample< 0 || sample>19 )
415 QMap<int,QByteArray> frame_channel_data=baseClip()->audioFrameChache[(int)frame];
417 for (int channel=0;channel<channels && frame_channel_data[channel].size()> 0;channel++){
419 int y=channelHeight*channel+ channelHeight/2;
420 int delta=(int)(frame_channel_data[channel][sample] -127/2 ) * channelHeight/ 64;
422 positiveChannelPaths[channel].lineTo(samples,0.1+y+qAbs( delta ));
423 negativeChannelPaths[channel].lineTo(samples,0.1+y-qAbs( delta ));
425 positiveChannelPaths[channel].lineTo(samples,0.1+y+delta);
426 negativeChannelPaths[channel].lineTo(samples,0.1+y-delta);
430 for (int i=0;i<channels;i++){
432 pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
433 pixpainter.setBrush(QBrush(QColor(200,200,100,200)));
434 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
436 pixpainter.drawPath(positiveChannelPaths[i]);
439 //audioThumbWasDrawn=true;
440 framePixelWidth=pixelForOneFrame;
445 int ClipItem::fadeIn() const
450 int ClipItem::fadeOut() const
455 void ClipItem::setFadeIn(int pos, double scale)
457 int oldIn = m_startFade;
458 if (pos < 0) pos = 0;
459 if (pos > m_cropDuration) pos = m_cropDuration / 2;
461 if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
462 else update(rect().x(), rect().y(), pos * scale, rect().height());
465 void ClipItem::setFadeOut(int pos, double scale)
467 int oldOut = m_endFade;
468 if (pos < 0) pos = 0;
469 if (pos > m_cropDuration) pos = m_cropDuration / 2;
471 if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
472 else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
478 void ClipItem::mousePressEvent ( QGraphicsSceneMouseEvent * event )
480 /*m_resizeMode = operationMode(event->pos());
481 if (m_resizeMode == MOVE) {
482 m_maxTrack = scene()->sceneRect().height();
483 m_grabPoint = (int) (event->pos().x() - rect().x());
485 QGraphicsRectItem::mousePressEvent(event);
489 void ClipItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
492 QGraphicsRectItem::mouseReleaseEvent(event);
495 void ClipItem::moveTo(int x, double scale, double offset, int newTrack)
497 double origX = rect().x();
498 double origY = rect().y();
501 setRect(x * scale, origY + offset, rect().width(), rect().height());
502 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
503 if (collisionList.size() == 0) m_track = newTrack;
504 for (int i = 0; i < collisionList.size(); ++i) {
505 QGraphicsItem *item = collisionList.at(i);
506 if (item->type() == 70000)
510 QRectF other = ((QGraphicsRectItem *)item)->rect();
511 if (x < m_startPos) {
512 kDebug()<<"COLLISION, MOVING TO------";
513 m_startPos = ((ClipItem *)item)->endPos() + 1;
514 origX = m_startPos * scale;
517 kDebug()<<"COLLISION, MOVING TO+++";
518 m_startPos = ((ClipItem *)item)->startPos() - m_cropDuration;
519 origX = m_startPos * scale;
522 setRect(origX, origY, rect().width(), rect().height());
533 /* QList <QGraphicsItem *> childrenList = QGraphicsItem::children();
534 for (int i = 0; i < childrenList.size(); ++i) {
535 childrenList.at(i)->moveBy(rect().x() - origX , offset);
539 void ClipItem::resizeStart(int posx, double scale)
541 int durationDiff = posx - m_startPos;
542 if (durationDiff == 0) return;
543 kDebug()<<"-- RESCALE: CROP="<<m_cropStart<<", DIFF = "<<durationDiff;
544 if (m_cropStart + durationDiff < 0) {
545 durationDiff = -m_cropStart;
547 else if (durationDiff >= m_cropDuration) {
548 durationDiff = m_cropDuration - 3;
550 m_startPos += durationDiff;
551 m_cropStart += durationDiff;
552 m_cropDuration -= durationDiff;
553 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
554 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
555 for (int i = 0; i < collisionList.size(); ++i) {
556 QGraphicsItem *item = collisionList.at(i);
557 if (item->type() == 70000)
559 int diff = ((ClipItem *)item)->endPos() + 1 - m_startPos;
560 setRect((m_startPos + diff) * scale, rect().y(), (m_cropDuration - diff) * scale, rect().height());
563 m_cropDuration -= diff;
567 if (m_hasThumbs) startThumbTimer->start(100);
570 void ClipItem::resizeEnd(int posx, double scale)
572 int durationDiff = posx - endPos();
573 if (durationDiff == 0) return;
574 kDebug()<<"-- RESCALE: CROP="<<m_cropStart<<", DIFF = "<<durationDiff;
575 if (m_cropDuration + durationDiff <= 0) {
576 durationDiff = - (m_cropDuration - 3);
578 else if (m_cropDuration + durationDiff >= m_maxDuration) {
579 durationDiff = m_maxDuration - m_cropDuration;
581 m_cropDuration += durationDiff;
582 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
583 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
584 for (int i = 0; i < collisionList.size(); ++i) {
585 QGraphicsItem *item = collisionList.at(i);
586 if (item->type() == 70000)
588 int diff = ((ClipItem *)item)->startPos() - 1 - startPos();
589 m_cropDuration = diff;
590 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
594 if (m_hasThumbs) endThumbTimer->start(100);
598 void ClipItem::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
602 int ClipItem::track()
607 void ClipItem::setTrack(int track)
612 int ClipItem::effectsCounter()
614 return m_effectsCounter++;
617 int ClipItem::effectsCount()
619 return m_effectList.size();
622 QStringList ClipItem::effectNames()
624 return m_effectList.effectNames();
627 QDomElement ClipItem::effectAt(int ix)
629 return m_effectList.at(ix);
632 void ClipItem::setEffectAt(int ix, QDomElement effect)
634 kDebug()<<"CHange EFFECT AT: "<<ix<<", CURR: "<<m_effectList.at(ix).attribute("tag")<<", NEW: "<<effect.attribute("tag");
635 m_effectList.insert(ix, effect);
636 m_effectList.removeAt(ix + 1);
637 update(boundingRect());
640 QMap <QString, QString> ClipItem::addEffect(QDomElement effect)
642 QMap <QString, QString> effectParams;
643 m_effectList.append(effect);
644 effectParams["tag"] = effect.attribute("tag");
645 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
646 QString state = effect.attribute("disabled");
647 if (!state.isEmpty()) effectParams["disabled"] = state;
648 QDomNodeList params = effect.elementsByTagName("parameter");
649 for (int i = 0; i < params.count(); i++) {
650 QDomElement e = params.item(i).toElement();
652 effectParams[e.attribute("name")] = e.attribute("value");
655 update(boundingRect());
659 QMap <QString, QString> ClipItem::getEffectArgs(QDomElement effect)
661 QMap <QString, QString> effectParams;
662 effectParams["tag"] = effect.attribute("tag");
663 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
664 QString state = effect.attribute("disabled");
665 if (!state.isEmpty()) effectParams["disabled"] = state;
666 QDomNodeList params = effect.elementsByTagName("parameter");
667 for (int i = 0; i < params.count(); i++) {
668 QDomElement e = params.item(i).toElement();
669 if (e.attribute("name").contains(";")){
670 QString format=e.attribute("format");
671 QStringList separators=format.split("%d",QString::SkipEmptyParts);
672 QStringList values=e.attribute("value").split(QRegExp("[,:;x]"));
674 QTextStream txtNeu(&neu);
676 txtNeu << (int)values[0].toDouble();
677 for (int i=0;i<separators.size() && i+1<values.size();i++){
678 txtNeu << separators[i];
679 txtNeu << (int)(values[i+1].toDouble());
681 effectParams["start"]=neu;
684 effectParams[e.attribute("name")] = e.attribute("value");
689 void ClipItem::deleteEffect(QString index)
691 for (int i = 0; i < m_effectList.size(); ++i) {
692 if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
693 m_effectList.removeAt(i);
698 update(boundingRect());
702 void ClipItem::dropEvent ( QGraphicsSceneDragDropEvent * event )
704 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
706 doc.setContent(effects, true);
707 QDomElement e = doc.documentElement();
708 if (QApplication::activeWindow())
709 QApplication::postEvent(QApplication::activeWindow(), new EffectEvent(GenTime(m_startPos, 25), m_track, e, (QEvent::Type)10010));
713 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
715 kDebug()<<"DRAG EVNET, FORMAT: "<<event->mimeData()->formats();
716 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
719 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
726 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
728 int pos = event->x();
729 if (event->modifiers() == Qt::ControlModifier)
730 setDragMode(QGraphicsView::ScrollHandDrag);
731 else if (event->modifiers() == Qt::ShiftModifier)
732 setDragMode(QGraphicsView::RubberBandDrag);
734 QGraphicsItem * item = itemAt(event->pos());
737 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
740 QGraphicsView::mousePressEvent(event);
743 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
745 QGraphicsView::mouseReleaseEvent(event);
746 setDragMode(QGraphicsView::NoDrag);
750 #include "clipitem.moc"