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, GenTime startpos, const QRectF & rect, GenTime duration, double fps)
42 : AbstractClipItem(rect), 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 // kDebug() << "******* CREATING NEW TML CLIP, DUR: " << duration;
46 m_startPos = startpos;
48 m_xml = clip->toXML();
49 m_clipName = clip->name();
50 m_producer = clip->getId();
51 m_clipType = clip->clipType();
52 m_cropStart = GenTime();
53 m_maxDuration = duration;
54 if (duration != GenTime()) m_cropDuration = duration;
55 else m_cropDuration = m_maxDuration;
57 audioThumbReady = clip->audioThumbCreated();
59 m_cropStart = xml.attribute("in", 0).toInt();
60 m_maxDuration = xml.attribute("duration", 0).toInt();
61 if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
63 if (duration != -1) m_cropDuration = duration;
64 else m_cropDuration = m_maxDuration;*/
67 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
68 setAcceptsHoverEvents(true);
69 connect(this , SIGNAL(prepareAudioThumb(double, QPainterPath, int, int)) , this, SLOT(slotPrepareAudioThumb(double, QPainterPath, int, int)));
71 setBrush(QColor(141, 166, 215));
72 if (m_clipType == VIDEO || m_clipType == AV) {
74 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
75 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
76 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
77 QTimer::singleShot(300, this, SLOT(slotFetchThumbs()));
79 startThumbTimer = new QTimer(this);
80 startThumbTimer->setSingleShot(true);
81 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
82 endThumbTimer = new QTimer(this);
83 endThumbTimer->setSingleShot(true);
84 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
86 } else if (m_clipType == COLOR) {
87 m_maxDuration = GenTime(10000, m_fps);
88 QString colour = m_xml.attribute("colour");
89 colour = colour.replace(0, 2, "#");
90 setBrush(QColor(colour.left(7)));
91 } else if (m_clipType == IMAGE) {
92 m_maxDuration = GenTime(10000, m_fps);
93 m_startPix = KThumb::getImage(KUrl(m_xml.attribute("resource")), (int)(50 * KdenliveSettings::project_display_ratio()), 50);
94 } else if (m_clipType == AUDIO) {
95 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
100 ClipItem::~ClipItem() {
101 if (startThumbTimer) delete startThumbTimer;
102 if (endThumbTimer) delete endThumbTimer;
105 void ClipItem::slotFetchThumbs() {
106 m_thumbsRequested += 2;
107 emit getThumb((int)m_cropStart.frames(m_fps), (int)(m_cropStart + m_cropDuration).frames(m_fps));
110 void ClipItem::slotGetStartThumb() {
112 emit getThumb((int)m_cropStart.frames(m_fps), -1);
115 void ClipItem::slotGetEndThumb() {
117 emit getThumb(-1, (int)(m_cropStart + m_cropDuration).frames(m_fps));
120 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
121 if (m_thumbsRequested == 0) return;
122 if (frame == m_cropStart.frames(m_fps)) m_startPix = pix;
128 void ClipItem::slotGotAudioData() {
129 audioThumbReady = true;
133 int ClipItem::type() const {
137 DocClipBase *ClipItem::baseClip() {
141 QDomElement ClipItem::xml() const {
145 int ClipItem::clipType() {
149 QString ClipItem::clipName() {
153 int ClipItem::clipProducer() {
157 void ClipItem::flashClip() {
158 if (m_timeLine == 0) {
159 m_timeLine = new QTimeLine(750, this);
160 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
165 void ClipItem::animate(qreal value) {
171 void ClipItem::paint(QPainter *painter,
172 const QStyleOptionGraphicsItem *option,
174 painter->setOpacity(m_opacity);
175 QBrush paintColor = brush();
177 if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
179 double scale = br.width() / m_cropDuration.frames(m_fps);
180 QRect rectInView;//this is the rect that is visible by the user
181 if (scene()->views().size() > 0) {
182 rectInView = scene()->views()[0]->viewport()->rect();
183 rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(), scene()->views()[0]->verticalScrollBar()->value());
184 rectInView.adjust(-10, -10, 10, 10);//make view rect 10 pixel greater on each site, or repaint after scroll event
185 //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value();
187 if (rectInView.isNull())
189 QPainterPath clippath;
190 clippath.addRect(rectInView);
192 int startpixel = (int)(rectInView.x() - rect().x()); //start and endpixel that is viewable from rect()
196 int endpixel = rectInView.width() + rectInView.x();
200 //painter->setRenderHints(QPainter::Antialiasing);
202 QPainterPath roundRectPathUpper, roundRectPathLower;
203 double roundingY = 20;
204 double roundingX = 20;
206 painter->setClipRect(option->exposedRect);
207 if (roundingX > br.width() / 2) roundingX = br.width() / 2;
209 int br_endx = (int)(br.x() + br .width() - offset);
210 int br_startx = (int)(br.x() + offset);
211 int br_starty = (int)(br.y());
212 int br_halfy = (int)(br.y() + br.height() / 2 - offset);
213 int br_endy = (int)(br.y() + br.height());
214 int left_upper = 0, left_lower = 0, right_upper = 0, right_lower = 0;
216 if (m_hover && false) {
217 if (!true) /*TRANSITIONSTART to upper clip*/
219 if (!false) /*TRANSITIONSTART to lower clip*/
221 if (!true) /*TRANSITIONEND to upper clip*/
223 if (!false) /*TRANSITIONEND to lower clip*/
227 // build path around clip
228 roundRectPathUpper.moveTo(br_endx - right_upper , br_halfy);
229 roundRectPathUpper.arcTo(br_endx - roundingX - right_upper , br_starty , roundingX, roundingY, 0.0, 90.0);
230 roundRectPathUpper.lineTo(br_startx + roundingX + left_upper, br_starty);
231 roundRectPathUpper.arcTo(br_startx + left_upper, br_starty , roundingX, roundingY, 90.0, 90.0);
232 roundRectPathUpper.lineTo(br_startx + left_upper, br_halfy);
234 roundRectPathLower.moveTo(br_startx + left_lower, br_halfy);
235 roundRectPathLower.arcTo(br_startx + left_lower, br_endy - roundingY , roundingX, roundingY, 180.0, 90.0);
236 roundRectPathLower.lineTo(br_endx - roundingX - right_lower , br_endy);
237 roundRectPathLower.arcTo(br_endx - roundingX - right_lower , br_endy - roundingY, roundingX, roundingY, 270.0, 90.0);
238 roundRectPathLower.lineTo(br_endx - right_lower , br_halfy);
240 QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
242 painter->setClipPath(resultClipPath.intersected(clippath), Qt::IntersectClip);
243 //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
244 painter->fillRect(br.intersected(rectInView), paintColor);
245 //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
248 if (!m_startPix.isNull() && KdenliveSettings::videothumbnails()) {
249 if (m_clipType == IMAGE) {
250 painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
251 QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
252 painter->drawLine(l);
254 painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
255 QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
256 painter->drawLine(l);
259 painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
260 QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
261 painter->drawLine(l2);
264 // draw audio thumbnails
265 if ((m_clipType == AV || m_clipType == AUDIO) && audioThumbReady && KdenliveSettings::audiothumbnails()) {
267 QPainterPath path = m_clipType == AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
268 if (m_clipType == AV) painter->fillPath(path, QBrush(QColor(200, 200, 200, 140)));
271 if (scale != framePixelWidth)
272 audioThumbCachePic.clear();
273 emit prepareAudioThumb(scale, path, startpixel, endpixel + 200);//200 more for less missing parts before repaint after scrolling
274 int cropLeft = (m_cropStart).frames(m_fps) * scale;
275 for (int startCache = startpixel - startpixel % 100; startCache < endpixel + 300;startCache += 100) {
276 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
277 painter->drawPixmap((int)(roundRectPathUpper.united(roundRectPathLower).boundingRect().x() + startCache - cropLeft), (int)(path.boundingRect().y()), audioThumbCachePic[startCache]);
282 // draw start / end fades
285 fades = QBrush(QColor(200, 50, 50, 150));
286 } else fades = QBrush(QColor(200, 200, 200, 200));
288 if (m_startFade != 0) {
289 QPainterPath fadeInPath;
290 fadeInPath.moveTo(br.x() - offset, br.y());
291 fadeInPath.lineTo(br.x() - offset, br.y() + br.height());
292 fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
293 fadeInPath.closeSubpath();
294 painter->fillPath(fadeInPath, fades);
296 QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
297 painter->drawLine(l);
300 if (m_endFade != 0) {
301 QPainterPath fadeOutPath;
302 fadeOutPath.moveTo(br.x() + br.width(), br.y());
303 fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
304 fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
305 fadeOutPath.closeSubpath();
306 painter->fillPath(fadeOutPath, fades);
308 QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
309 painter->drawLine(l);
313 QPen pen = painter->pen();
314 pen.setColor(Qt::white);
315 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
317 // Draw effects names
318 QString effects = effectNames().join(" / ");
319 if (!effects.isEmpty()) {
320 painter->setPen(pen);
321 QFont font = painter->font();
322 QFont smallFont = font;
323 smallFont.setPointSize(8);
324 painter->setFont(smallFont);
325 QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " ");
326 painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
327 painter->drawText(txtBounding, Qt::AlignCenter, effects);
328 pen.setColor(Qt::black);
329 painter->setPen(pen);
330 painter->setFont(font);
333 // For testing puspose only: draw transitions count
335 painter->setPen(pen);
336 QFont font = painter->font();
337 QFont smallFont = font;
338 smallFont.setPointSize(8);
339 painter->setFont(smallFont);
340 QString txt = " Transitions: " + QString::number(m_transitionsList.count()) + " ";
341 QRectF txtBoundin = painter->boundingRect(br, Qt::AlignRight | Qt::AlignTop, txt);
342 painter->fillRect(txtBoundin, QBrush(QColor(0, 0, 0, 150)));
343 painter->drawText(txtBoundin, Qt::AlignCenter, txt);
344 pen.setColor(Qt::black);
345 painter->setPen(pen);
346 painter->setFont(font);
350 QRectF txtBounding = painter->boundingRect(br, Qt::AlignHCenter | Qt::AlignTop, " " + m_clipName + " ");
351 painter->fillRect(txtBounding, QBrush(QColor(255, 255, 255, 150)));
352 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
354 // draw frame around clip
355 pen.setColor(Qt::red);
357 if (isSelected()) painter->setPen(pen);
358 painter->setClipRect(option->exposedRect);
359 painter->drawPath(resultClipPath.intersected(clippath));
361 //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150)));
362 //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
364 /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
365 painter->drawRect(recta);
366 painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
367 painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
368 painter->setPen(QPen(Qt::black, 1.0));
369 painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
370 painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
372 //QGraphicsRectItem::paint(painter, option, widget);
373 //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
374 //painter->setPen(pen);
375 //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
376 //kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
377 //painter->drawText(rect(), Qt::AlignCenter, m_name);
378 // painter->drawRect(boundingRect());
379 //painter->drawRoundRect(-10, -10, 20, 20);
381 painter->setPen(QPen(Qt::black));
382 painter->setBrush(QBrush(Qt::yellow));
383 painter->drawEllipse((int)(br.x() + 10), (int)(br.y() + br.height() / 2 - 5) , 10, 10);
384 painter->drawEllipse((int)(br.x() + br.width() - 20), (int)(br.y() + br.height() / 2 - 5), 10, 10);
389 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) {
390 if (abs((int)(pos.x() - (rect().x() + scale * m_startFade))) < 6 && abs((int)(pos.y() - rect().y())) < 6) return FADEIN;
391 else if (abs((int)(pos.x() - rect().x())) < 6) return RESIZESTART;
392 else if (abs((int)(pos.x() - (rect().x() + rect().width() - scale * m_endFade))) < 6 && abs((int)(pos.y() - rect().y())) < 6) return FADEOUT;
393 else if (abs((int)(pos.x() - (rect().x() + rect().width()))) < 6) return RESIZEEND;
394 else if (abs((int)(pos.x() - (rect().x() + 10))) < 6 && abs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONSTART;
395 else if (abs((int)(pos.x() - (rect().x() + rect().width() - 20))) < 6 && abs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONEND;
400 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, QPainterPath path, int startpixel, int endpixel) {
403 QRectF re = path.boundingRect();
405 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
407 for (int startCache = startpixel - startpixel % 100;startCache + 100 < endpixel ;startCache += 100) {
408 //kDebug() << "creating " << startCache;
409 //if (framePixelWidth!=pixelForOneFrame ||
410 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
412 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
413 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
414 audioThumbCachePic[startCache].fill(QColor(200, 200, 200, 0));
416 bool fullAreaDraw = pixelForOneFrame < 10;
417 QMap<int, QPainterPath > positiveChannelPaths;
418 QMap<int, QPainterPath > negativeChannelPaths;
419 QPainter pixpainter(&audioThumbCachePic[startCache]);
421 audiopen.setWidth(0);
422 pixpainter.setPen(audiopen);
423 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
424 //pixpainter.drawLine(0,0,100,re.height());
425 int channelHeight = audioThumbCachePic[startCache].height() / channels;
427 for (int i = 0;i < channels;i++) {
429 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
430 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
433 for (int samples = 0;samples <= 100;samples++) {
434 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
435 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
436 if (frame < 0 || sample < 0 || sample > 19)
438 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
440 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
442 int y = channelHeight * channel + channelHeight / 2;
443 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
445 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
446 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
448 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
449 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
452 for (int channel = 0;channel < channels ;channel++)
453 if (fullAreaDraw && samples == 100) {
454 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
455 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
456 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
457 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
461 if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
463 pixpainter.setPen(QPen(QColor(0, 0, 0)));
464 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
466 for (int i = 0;i < channels;i++) {
468 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
469 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
471 pixpainter.drawPath(positiveChannelPaths[i]);
474 //audioThumbWasDrawn=true;
475 framePixelWidth = pixelForOneFrame;
482 void ClipItem::setFadeIn(int pos, double scale) {
483 int oldIn = m_startFade;
484 if (pos < 0) pos = 0;
485 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
487 if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
488 else update(rect().x(), rect().y(), pos * scale, rect().height());
491 void ClipItem::setFadeOut(int pos, double scale) {
492 int oldOut = m_endFade;
493 if (pos < 0) pos = 0;
494 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
496 if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
497 else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
503 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
504 /*m_resizeMode = operationMode(event->pos());
505 if (m_resizeMode == MOVE) {
506 m_maxTrack = scene()->sceneRect().height();
507 m_grabPoint = (int) (event->pos().x() - rect().x());
509 QGraphicsRectItem::mousePressEvent(event);
513 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
515 QGraphicsRectItem::mouseReleaseEvent(event);
519 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
525 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
530 void ClipItem::resizeStart(int posx, double scale) {
531 AbstractClipItem::resizeStart(posx, scale);
532 if (m_hasThumbs) startThumbTimer->start(100);
535 void ClipItem::resizeEnd(int posx, double scale) {
536 AbstractClipItem::resizeEnd(posx, scale);
537 if (m_hasThumbs) endThumbTimer->start(100);
541 void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
544 int ClipItem::effectsCounter() {
545 return m_effectsCounter++;
548 int ClipItem::effectsCount() {
549 return m_effectList.size();
552 QStringList ClipItem::effectNames() {
553 return m_effectList.effectNames();
556 QDomElement ClipItem::effectAt(int ix) {
557 return m_effectList.at(ix);
560 void ClipItem::setEffectAt(int ix, QDomElement effect) {
561 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
562 m_effectList.insert(ix, effect);
563 m_effectList.removeAt(ix + 1);
564 update(boundingRect());
567 QMap <QString, QString> ClipItem::addEffect(QDomElement effect) {
568 QMap <QString, QString> effectParams;
569 m_effectList.append(effect);
570 effectParams["tag"] = effect.attribute("tag");
571 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
572 QString state = effect.attribute("disabled");
573 if (!state.isEmpty()) effectParams["disabled"] = state;
574 QDomNodeList params = effect.elementsByTagName("parameter");
575 for (int i = 0; i < params.count(); i++) {
576 QDomElement e = params.item(i).toElement();
578 effectParams[e.attribute("name")] = e.attribute("value");
580 if (!e.attribute("factor").isEmpty()) {
581 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
585 update(boundingRect());
589 QMap <QString, QString> ClipItem::getEffectArgs(QDomElement effect) {
590 QMap <QString, QString> effectParams;
591 effectParams["tag"] = effect.attribute("tag");
592 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
593 QString state = effect.attribute("disabled");
594 if (!state.isEmpty()) effectParams["disabled"] = state;
595 QDomNodeList params = effect.elementsByTagName("parameter");
596 for (int i = 0; i < params.count(); i++) {
597 QDomElement e = params.item(i).toElement();
598 if (e.attribute("name").contains(";")) {
599 QString format = e.attribute("format");
600 QStringList separators = format.split("%d", QString::SkipEmptyParts);
601 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
603 QTextStream txtNeu(&neu);
604 if (values.size() > 0)
605 txtNeu << (int)values[0].toDouble();
606 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
607 txtNeu << separators[i];
608 txtNeu << (int)(values[i+1].toDouble());
610 effectParams["start"] = neu;
613 effectParams[e.attribute("name")] = e.attribute("value");
615 if (!e.attribute("factor").isEmpty()) {
616 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
622 void ClipItem::deleteEffect(QString index) {
623 for (int i = 0; i < m_effectList.size(); ++i) {
624 if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
625 m_effectList.removeAt(i);
630 update(boundingRect());
634 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
635 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
637 doc.setContent(effects, true);
638 QDomElement e = doc.documentElement();
639 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
640 if (view) view->slotAddEffect(e, m_startPos, m_track);
644 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
645 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
648 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
651 void ClipItem::addTransition(Transition* t) {
652 m_transitionsList.append(t);
653 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
655 QDomElement e = doc.documentElement();
656 if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
660 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
662 int pos = event->x();
663 if (event->modifiers() == Qt::ControlModifier)
664 setDragMode(QGraphicsView::ScrollHandDrag);
665 else if (event->modifiers() == Qt::ShiftModifier)
666 setDragMode(QGraphicsView::RubberBandDrag);
668 QGraphicsItem * item = itemAt(event->pos());
671 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
674 QGraphicsView::mousePressEvent(event);
677 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
679 QGraphicsView::mouseReleaseEvent(event);
680 setDragMode(QGraphicsView::NoDrag);
684 #include "clipitem.moc"