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>
34 #include "customtrackview.h"
36 #include "docclipbase.h"
37 #include "transition.h"
39 #include "kdenlivesettings.h"
42 ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double scale, double fps)
43 : AbstractClipItem(info, QRectF()), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), m_effectsCounter(1), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_thumbsRequested(0), m_hover(false) {
44 QRectF rect((double) info.startPos.frames(fps) * scale, (double)(info.track * KdenliveSettings::trackheight() + 1), (double)(info.endPos - info.startPos).frames(fps) * scale, (double)(KdenliveSettings::trackheight() - 1));
46 kDebug() << "///// NEW CLIP RECT: " << rect;
48 m_clipName = clip->name();
49 m_producer = clip->getId();
50 m_clipType = clip->clipType();
51 m_cropStart = GenTime();
53 m_maxDuration = clip->maxDuration();
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::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
66 setAcceptsHoverEvents(true);
67 connect(this , SIGNAL(prepareAudioThumb(double, QPainterPath, int, int)) , this, SLOT(slotPrepareAudioThumb(double, QPainterPath, int, int)));
69 setBrush(QColor(141, 166, 215));
70 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW) {
72 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
73 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
74 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
75 QTimer::singleShot(300, this, SLOT(slotFetchThumbs()));
77 startThumbTimer = new QTimer(this);
78 startThumbTimer->setSingleShot(true);
79 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
80 endThumbTimer = new QTimer(this);
81 endThumbTimer->setSingleShot(true);
82 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
83 } else if (m_clipType == COLOR) {
84 QString colour = clip->getProperty("colour");
85 colour = colour.replace(0, 2, "#");
86 setBrush(QColor(colour.left(7)));
87 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
88 m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(50 * KdenliveSettings::project_display_ratio()), 50);
89 m_endPix = m_startPix;
90 } else if (m_clipType == AUDIO) {
91 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
96 ClipItem::~ClipItem() {
97 if (startThumbTimer) delete startThumbTimer;
98 if (endThumbTimer) delete endThumbTimer;
101 void ClipItem::resetThumbs() {
103 audioThumbCachePic.clear();
107 void ClipItem::refreshClip() {
108 m_maxDuration = m_clip->maxDuration();
109 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW) slotFetchThumbs();
110 else if (m_clipType == COLOR) {
111 QString colour = m_clip->getProperty("colour");
112 colour = colour.replace(0, 2, "#");
113 setBrush(QColor(colour.left(7)));
114 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
115 m_startPix = KThumb::getImage(KUrl(m_clip->getProperty("resource")), (int)(50 * KdenliveSettings::project_display_ratio()), 50);
116 m_endPix = m_startPix;
120 void ClipItem::slotFetchThumbs() {
121 m_thumbsRequested += 2;
122 emit getThumb((int)m_cropStart.frames(m_fps), (int)(m_cropStart + m_cropDuration).frames(m_fps));
125 void ClipItem::slotGetStartThumb() {
127 emit getThumb((int)m_cropStart.frames(m_fps), -1);
130 void ClipItem::slotGetEndThumb() {
132 emit getThumb(-1, (int)(m_cropStart + m_cropDuration).frames(m_fps));
135 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
136 if (m_thumbsRequested == 0) return;
137 if (frame == m_cropStart.frames(m_fps)) m_startPix = pix;
143 void ClipItem::slotGotAudioData() {
144 audioThumbReady = true;
148 int ClipItem::type() const {
152 DocClipBase *ClipItem::baseClip() {
156 QDomElement ClipItem::xml() const {
157 return m_clip->toXML();
160 int ClipItem::clipType() {
164 QString ClipItem::clipName() {
168 int ClipItem::clipProducer() {
172 void ClipItem::flashClip() {
173 if (m_timeLine == 0) {
174 m_timeLine = new QTimeLine(750, this);
175 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
180 void ClipItem::animate(qreal value) {
186 void ClipItem::paint(QPainter *painter,
187 const QStyleOptionGraphicsItem *option,
189 painter->setOpacity(m_opacity);
190 QBrush paintColor = brush();
192 if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
194 double scale = br.width() / m_cropDuration.frames(m_fps);
195 QRect rectInView = visibleRect();//this is the rect that is visible by the user
197 if (rectInView.isNull())
199 QPainterPath clippath;
200 clippath.addRect(rectInView);
202 int startpixel = (int)(rectInView.x() - rect().x()); //start and endpixel that is viewable from rect()
206 int endpixel = rectInView.width() + rectInView.x();
210 //painter->setRenderHints(QPainter::Antialiasing);
212 QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
214 painter->setClipRect(option->exposedRect);
216 // build path around clip
218 QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
220 painter->setClipPath(resultClipPath.intersected(clippath), Qt::IntersectClip);
221 //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
222 painter->fillRect(br.intersected(rectInView), paintColor);
223 //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
226 if (!m_startPix.isNull() && KdenliveSettings::videothumbnails()) {
227 if (m_clipType == IMAGE) {
228 painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
229 QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
230 painter->drawLine(l);
232 painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
233 QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
234 painter->drawLine(l);
237 painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
238 QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
239 painter->drawLine(l2);
242 // draw audio thumbnails
243 if ((m_clipType == AV || m_clipType == AUDIO) && audioThumbReady && KdenliveSettings::audiothumbnails()) {
245 QPainterPath path = m_clipType == AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
246 if (m_clipType == AV) painter->fillPath(path, QBrush(QColor(200, 200, 200, 140)));
249 if (scale != framePixelWidth)
250 audioThumbCachePic.clear();
251 emit prepareAudioThumb(scale, path, startpixel, endpixel + 200);//200 more for less missing parts before repaint after scrolling
252 int cropLeft = (int)((m_cropStart).frames(m_fps) * scale);
253 for (int startCache = startpixel - startpixel % 100; startCache < endpixel + 300;startCache += 100) {
254 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
255 painter->drawPixmap((int)(roundRectPathUpper.united(roundRectPathLower).boundingRect().x() + startCache - cropLeft), (int)(path.boundingRect().y()), audioThumbCachePic[startCache]);
260 // draw start / end fades
263 fades = QBrush(QColor(200, 50, 50, 150));
264 } else fades = QBrush(QColor(200, 200, 200, 200));
266 if (m_startFade != 0) {
267 QPainterPath fadeInPath;
268 fadeInPath.moveTo(br.x() , br.y());
269 fadeInPath.lineTo(br.x() , br.y() + br.height());
270 fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
271 fadeInPath.closeSubpath();
272 painter->fillPath(fadeInPath, fades);
274 QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
275 painter->drawLine(l);
278 if (m_endFade != 0) {
279 QPainterPath fadeOutPath;
280 fadeOutPath.moveTo(br.x() + br.width(), br.y());
281 fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
282 fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
283 fadeOutPath.closeSubpath();
284 painter->fillPath(fadeOutPath, fades);
286 QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
287 painter->drawLine(l);
291 QPen pen = painter->pen();
292 pen.setColor(Qt::white);
293 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
295 // Draw effects names
296 QString effects = effectNames().join(" / ");
297 if (!effects.isEmpty()) {
298 painter->setPen(pen);
299 QFont font = painter->font();
300 QFont smallFont = font;
301 smallFont.setPointSize(8);
302 painter->setFont(smallFont);
303 QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " ");
304 painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
305 painter->drawText(txtBounding, Qt::AlignCenter, effects);
306 pen.setColor(Qt::black);
307 painter->setPen(pen);
308 painter->setFont(font);
311 // For testing puspose only: draw transitions count
313 painter->setPen(pen);
314 QFont font = painter->font();
315 QFont smallFont = font;
316 smallFont.setPointSize(8);
317 painter->setFont(smallFont);
318 QString txt = " Transitions: " + QString::number(m_transitionsList.count()) + " ";
319 QRectF txtBoundin = painter->boundingRect(br, Qt::AlignRight | Qt::AlignTop, txt);
320 painter->fillRect(txtBoundin, QBrush(QColor(0, 0, 0, 150)));
321 painter->drawText(txtBoundin, Qt::AlignCenter, txt);
322 pen.setColor(Qt::black);
323 painter->setPen(pen);
324 painter->setFont(font);
328 QRectF txtBounding = painter->boundingRect(br, Qt::AlignHCenter | Qt::AlignTop, " " + m_clipName + " ");
329 painter->fillRect(txtBounding, QBrush(QColor(255, 255, 255, 150)));
330 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
332 // draw frame around clip
334 pen.setColor(Qt::red);
337 pen.setColor(Qt::black);
340 painter->setPen(pen);
341 painter->setClipRect(option->exposedRect);
342 painter->drawPath(resultClipPath.intersected(clippath));
344 //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150)));
345 //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
347 /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
348 painter->drawRect(recta);
349 painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
350 painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
351 painter->setPen(QPen(Qt::black, 1.0));
352 painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
353 painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
355 //QGraphicsRectItem::paint(painter, option, widget);
356 //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
357 //painter->setPen(pen);
358 //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
359 //kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
360 //painter->drawText(rect(), Qt::AlignCenter, m_name);
361 // painter->drawRect(boundingRect());
362 //painter->drawRoundRect(-10, -10, 20, 20);
364 int pointy = (int)(br.y() + br.height() / 2 - 5);
365 int pointx1 = (int)(br.x() + 10);
366 int pointx2 = (int)(br.x() + br.width() - 20);
368 painter->setPen(QPen(Qt::black));
369 painter->setBrush(QBrush(QColor(50, 50, 0)));
371 QRadialGradient gradient(pointx1 + 5, pointy + 5 , 5, 2, 2);
372 gradient.setColorAt(0.2, Qt::white);
373 gradient.setColorAt(0.8, Qt::yellow);
374 gradient.setColorAt(1, Qt::black);
375 painter->setBrush(gradient);
377 painter->drawEllipse(pointx1, pointy , 10, 10);
379 QRadialGradient gradient1(pointx2 + 5, pointy + 5 , 5, 2, 2);
380 gradient1.setColorAt(0.2, Qt::white);
381 gradient1.setColorAt(0.8, Qt::yellow);
382 gradient1.setColorAt(1, Qt::black);
383 painter->setBrush(gradient1);
384 painter->drawEllipse(pointx2, pointy, 10, 10);
390 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) {
391 if (qAbs((int)(pos.x() - (rect().x() + scale * m_startFade))) < 6 && qAbs((int)(pos.y() - rect().y())) < 6) return FADEIN;
392 else if (qAbs((int)(pos.x() - rect().x())) < 6) return RESIZESTART;
393 else if (qAbs((int)(pos.x() - (rect().x() + rect().width() - scale * m_endFade))) < 6 && qAbs((int)(pos.y() - rect().y())) < 6) return FADEOUT;
394 else if (qAbs((int)(pos.x() - (rect().x() + rect().width()))) < 6) return RESIZEEND;
395 else if (qAbs((int)(pos.x() - (rect().x() + 10))) < 6 && qAbs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONSTART;
396 else if (qAbs((int)(pos.x() - (rect().x() + rect().width() - 20))) < 6 && qAbs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONEND;
401 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, QPainterPath path, int startpixel, int endpixel) {
404 QRectF re = path.boundingRect();
406 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
408 for (int startCache = startpixel - startpixel % 100;startCache + 100 < endpixel ;startCache += 100) {
409 //kDebug() << "creating " << startCache;
410 //if (framePixelWidth!=pixelForOneFrame ||
411 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
413 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
414 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
415 audioThumbCachePic[startCache].fill(QColor(200, 200, 200, 0));
417 bool fullAreaDraw = pixelForOneFrame < 10;
418 QMap<int, QPainterPath > positiveChannelPaths;
419 QMap<int, QPainterPath > negativeChannelPaths;
420 QPainter pixpainter(&audioThumbCachePic[startCache]);
422 audiopen.setWidth(0);
423 pixpainter.setPen(audiopen);
424 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
425 //pixpainter.drawLine(0,0,100,re.height());
426 int channelHeight = audioThumbCachePic[startCache].height() / channels;
428 for (int i = 0;i < channels;i++) {
430 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
431 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
434 for (int samples = 0;samples <= 100;samples++) {
435 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
436 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
437 if (frame < 0 || sample < 0 || sample > 19)
439 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
441 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
443 int y = channelHeight * channel + channelHeight / 2;
444 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
446 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
447 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
449 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
450 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
453 for (int channel = 0;channel < channels ;channel++)
454 if (fullAreaDraw && samples == 100) {
455 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
456 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
457 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
458 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
462 if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
464 pixpainter.setPen(QPen(QColor(0, 0, 0)));
465 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
467 for (int i = 0;i < channels;i++) {
469 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
470 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
472 pixpainter.drawPath(positiveChannelPaths[i]);
475 //audioThumbWasDrawn=true;
476 framePixelWidth = pixelForOneFrame;
483 void ClipItem::setFadeIn(int pos, double scale) {
484 int oldIn = m_startFade;
485 if (pos < 0) pos = 0;
486 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
488 if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
489 else update(rect().x(), rect().y(), pos * scale, rect().height());
492 void ClipItem::setFadeOut(int pos, double scale) {
493 int oldOut = m_endFade;
494 if (pos < 0) pos = 0;
495 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
497 if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
498 else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
504 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
505 /*m_resizeMode = operationMode(event->pos());
506 if (m_resizeMode == MOVE) {
507 m_maxTrack = scene()->sceneRect().height();
508 m_grabPoint = (int) (event->pos().x() - rect().x());
510 QGraphicsRectItem::mousePressEvent(event);
514 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
516 QGraphicsRectItem::mouseReleaseEvent(event);
520 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
526 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
531 void ClipItem::resizeStart(int posx, double scale) {
532 AbstractClipItem::resizeStart(posx, scale);
533 if (m_hasThumbs) startThumbTimer->start(100);
536 void ClipItem::resizeEnd(int posx, double scale) {
537 AbstractClipItem::resizeEnd(posx, scale);
538 if (m_hasThumbs) endThumbTimer->start(100);
542 void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
545 int ClipItem::effectsCounter() {
546 return m_effectsCounter++;
549 int ClipItem::effectsCount() {
550 return m_effectList.size();
553 QStringList ClipItem::effectNames() {
554 return m_effectList.effectNames();
557 QDomElement ClipItem::effectAt(int ix) {
558 return m_effectList.at(ix);
561 void ClipItem::setEffectAt(int ix, QDomElement effect) {
562 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
563 m_effectList.insert(ix, effect);
564 m_effectList.removeAt(ix + 1);
565 update(boundingRect());
568 QMap <QString, QString> ClipItem::addEffect(QDomElement effect, bool animate) {
569 QMap <QString, QString> effectParams;
571 doc.appendChild(doc.importNode(effect, true));
572 kDebug() << "/////// CLIP ADD EFFECT: "<< doc.toString();*/
573 m_effectList.append(effect);
574 effectParams["tag"] = effect.attribute("tag");
575 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
576 QString state = effect.attribute("disabled");
577 if (!state.isEmpty()) effectParams["disabled"] = state;
578 QDomNodeList params = effect.elementsByTagName("parameter");
579 for (int i = 0; i < params.count(); i++) {
580 QDomElement e = params.item(i).toElement();
582 effectParams[e.attribute("name")] = e.attribute("value");
584 if (!e.attribute("factor").isEmpty()) {
585 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
588 if (animate) flashClip();
589 update(boundingRect());
593 QMap <QString, QString> ClipItem::getEffectArgs(QDomElement effect) {
594 QMap <QString, QString> effectParams;
595 effectParams["tag"] = effect.attribute("tag");
596 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
597 QString state = effect.attribute("disabled");
598 if (!state.isEmpty()) effectParams["disabled"] = state;
599 QDomNodeList params = effect.elementsByTagName("parameter");
600 for (int i = 0; i < params.count(); i++) {
601 QDomElement e = params.item(i).toElement();
602 if (e.attribute("namedesc").contains(";")) {
603 QString format = e.attribute("format");
604 QStringList separators = format.split("%d", QString::SkipEmptyParts);
605 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
607 QTextStream txtNeu(&neu);
608 if (values.size() > 0)
609 txtNeu << (int)values[0].toDouble();
610 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
611 txtNeu << separators[i];
612 txtNeu << (int)(values[i+1].toDouble());
614 effectParams["start"] = neu;
617 effectParams[e.attribute("name")] = e.attribute("value");
619 if (!e.attribute("factor").isEmpty()) {
620 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
626 void ClipItem::deleteEffect(QString index) {
627 for (int i = 0; i < m_effectList.size(); ++i) {
628 if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
629 m_effectList.removeAt(i);
634 update(boundingRect());
638 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
639 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
641 doc.setContent(effects, true);
642 QDomElement e = doc.documentElement();
643 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
644 if (view) view->slotAddEffect(e, m_startPos, track());
648 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
649 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
652 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
655 void ClipItem::addTransition(Transition* t) {
656 m_transitionsList.append(t);
657 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
659 QDomElement e = doc.documentElement();
660 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
664 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
666 int pos = event->x();
667 if (event->modifiers() == Qt::ControlModifier)
668 setDragMode(QGraphicsView::ScrollHandDrag);
669 else if (event->modifiers() == Qt::ShiftModifier)
670 setDragMode(QGraphicsView::RubberBandDrag);
672 QGraphicsItem * item = itemAt(event->pos());
675 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
678 QGraphicsView::mousePressEvent(event);
681 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
683 QGraphicsView::mouseReleaseEvent(event);
684 setDragMode(QGraphicsView::NoDrag);
688 #include "clipitem.moc"