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::resetThumbs() {
107 audioThumbCachePic.clear();
110 void ClipItem::slotFetchThumbs() {
111 m_thumbsRequested += 2;
112 emit getThumb((int)m_cropStart.frames(m_fps), (int)(m_cropStart + m_cropDuration).frames(m_fps));
115 void ClipItem::slotGetStartThumb() {
117 emit getThumb((int)m_cropStart.frames(m_fps), -1);
120 void ClipItem::slotGetEndThumb() {
122 emit getThumb(-1, (int)(m_cropStart + m_cropDuration).frames(m_fps));
125 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
126 if (m_thumbsRequested == 0) return;
127 if (frame == m_cropStart.frames(m_fps)) m_startPix = pix;
133 void ClipItem::slotGotAudioData() {
134 audioThumbReady = true;
138 int ClipItem::type() const {
142 DocClipBase *ClipItem::baseClip() {
146 QDomElement ClipItem::xml() const {
150 int ClipItem::clipType() {
154 QString ClipItem::clipName() {
158 int ClipItem::clipProducer() {
162 void ClipItem::flashClip() {
163 if (m_timeLine == 0) {
164 m_timeLine = new QTimeLine(750, this);
165 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
170 void ClipItem::animate(qreal value) {
176 void ClipItem::paint(QPainter *painter,
177 const QStyleOptionGraphicsItem *option,
179 painter->setOpacity(m_opacity);
180 QBrush paintColor = brush();
182 if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
184 double scale = br.width() / m_cropDuration.frames(m_fps);
185 QRect rectInView;//this is the rect that is visible by the user
186 if (scene()->views().size() > 0) {
187 rectInView = scene()->views()[0]->viewport()->rect();
188 rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(), scene()->views()[0]->verticalScrollBar()->value());
189 rectInView.adjust(-10, -10, 10, 10);//make view rect 10 pixel greater on each site, or repaint after scroll event
190 //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value();
192 if (rectInView.isNull())
194 QPainterPath clippath;
195 clippath.addRect(rectInView);
197 int startpixel = (int)(rectInView.x() - rect().x()); //start and endpixel that is viewable from rect()
201 int endpixel = rectInView.width() + rectInView.x();
205 //painter->setRenderHints(QPainter::Antialiasing);
207 QPainterPath roundRectPathUpper, roundRectPathLower;
208 double roundingY = 20;
209 double roundingX = 20;
211 painter->setClipRect(option->exposedRect);
212 if (roundingX > br.width() / 2) roundingX = br.width() / 2;
214 int br_endx = (int)(br.x() + br .width() - offset);
215 int br_startx = (int)(br.x() + offset);
216 int br_starty = (int)(br.y());
217 int br_halfy = (int)(br.y() + br.height() / 2 - offset);
218 int br_endy = (int)(br.y() + br.height());
219 int left_upper = 0, left_lower = 0, right_upper = 0, right_lower = 0;
221 if (m_hover && false) {
222 if (!true) /*TRANSITIONSTART to upper clip*/
224 if (!false) /*TRANSITIONSTART to lower clip*/
226 if (!true) /*TRANSITIONEND to upper clip*/
228 if (!false) /*TRANSITIONEND to lower clip*/
232 // build path around clip
233 roundRectPathUpper.moveTo(br_endx - right_upper , br_halfy);
234 roundRectPathUpper.arcTo(br_endx - roundingX - right_upper , br_starty , roundingX, roundingY, 0.0, 90.0);
235 roundRectPathUpper.lineTo(br_startx + roundingX + left_upper, br_starty);
236 roundRectPathUpper.arcTo(br_startx + left_upper, br_starty , roundingX, roundingY, 90.0, 90.0);
237 roundRectPathUpper.lineTo(br_startx + left_upper, br_halfy);
239 roundRectPathLower.moveTo(br_startx + left_lower, br_halfy);
240 roundRectPathLower.arcTo(br_startx + left_lower, br_endy - roundingY , roundingX, roundingY, 180.0, 90.0);
241 roundRectPathLower.lineTo(br_endx - roundingX - right_lower , br_endy);
242 roundRectPathLower.arcTo(br_endx - roundingX - right_lower , br_endy - roundingY, roundingX, roundingY, 270.0, 90.0);
243 roundRectPathLower.lineTo(br_endx - right_lower , br_halfy);
245 QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
247 painter->setClipPath(resultClipPath.intersected(clippath), Qt::IntersectClip);
248 //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
249 painter->fillRect(br.intersected(rectInView), paintColor);
250 //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
253 if (!m_startPix.isNull() && KdenliveSettings::videothumbnails()) {
254 if (m_clipType == IMAGE) {
255 painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
256 QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
257 painter->drawLine(l);
259 painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
260 QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
261 painter->drawLine(l);
264 painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
265 QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
266 painter->drawLine(l2);
269 // draw audio thumbnails
270 if ((m_clipType == AV || m_clipType == AUDIO) && audioThumbReady && KdenliveSettings::audiothumbnails()) {
272 QPainterPath path = m_clipType == AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
273 if (m_clipType == AV) painter->fillPath(path, QBrush(QColor(200, 200, 200, 140)));
276 if (scale != framePixelWidth)
277 audioThumbCachePic.clear();
278 emit prepareAudioThumb(scale, path, startpixel, endpixel + 200);//200 more for less missing parts before repaint after scrolling
279 int cropLeft = (m_cropStart).frames(m_fps) * scale;
280 for (int startCache = startpixel - startpixel % 100; startCache < endpixel + 300;startCache += 100) {
281 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
282 painter->drawPixmap((int)(roundRectPathUpper.united(roundRectPathLower).boundingRect().x() + startCache - cropLeft), (int)(path.boundingRect().y()), audioThumbCachePic[startCache]);
287 // draw start / end fades
290 fades = QBrush(QColor(200, 50, 50, 150));
291 } else fades = QBrush(QColor(200, 200, 200, 200));
293 if (m_startFade != 0) {
294 QPainterPath fadeInPath;
295 fadeInPath.moveTo(br.x() - offset, br.y());
296 fadeInPath.lineTo(br.x() - offset, br.y() + br.height());
297 fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
298 fadeInPath.closeSubpath();
299 painter->fillPath(fadeInPath, fades);
301 QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
302 painter->drawLine(l);
305 if (m_endFade != 0) {
306 QPainterPath fadeOutPath;
307 fadeOutPath.moveTo(br.x() + br.width(), br.y());
308 fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
309 fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
310 fadeOutPath.closeSubpath();
311 painter->fillPath(fadeOutPath, fades);
313 QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
314 painter->drawLine(l);
318 QPen pen = painter->pen();
319 pen.setColor(Qt::white);
320 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
322 // Draw effects names
323 QString effects = effectNames().join(" / ");
324 if (!effects.isEmpty()) {
325 painter->setPen(pen);
326 QFont font = painter->font();
327 QFont smallFont = font;
328 smallFont.setPointSize(8);
329 painter->setFont(smallFont);
330 QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " ");
331 painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
332 painter->drawText(txtBounding, Qt::AlignCenter, effects);
333 pen.setColor(Qt::black);
334 painter->setPen(pen);
335 painter->setFont(font);
338 // For testing puspose only: draw transitions count
340 painter->setPen(pen);
341 QFont font = painter->font();
342 QFont smallFont = font;
343 smallFont.setPointSize(8);
344 painter->setFont(smallFont);
345 QString txt = " Transitions: " + QString::number(m_transitionsList.count()) + " ";
346 QRectF txtBoundin = painter->boundingRect(br, Qt::AlignRight | Qt::AlignTop, txt);
347 painter->fillRect(txtBoundin, QBrush(QColor(0, 0, 0, 150)));
348 painter->drawText(txtBoundin, Qt::AlignCenter, txt);
349 pen.setColor(Qt::black);
350 painter->setPen(pen);
351 painter->setFont(font);
355 QRectF txtBounding = painter->boundingRect(br, Qt::AlignHCenter | Qt::AlignTop, " " + m_clipName + " ");
356 painter->fillRect(txtBounding, QBrush(QColor(255, 255, 255, 150)));
357 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
359 // draw frame around clip
360 pen.setColor(Qt::red);
362 if (isSelected()) painter->setPen(pen);
363 painter->setClipRect(option->exposedRect);
364 painter->drawPath(resultClipPath.intersected(clippath));
366 //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150)));
367 //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
369 /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
370 painter->drawRect(recta);
371 painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
372 painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
373 painter->setPen(QPen(Qt::black, 1.0));
374 painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
375 painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
377 //QGraphicsRectItem::paint(painter, option, widget);
378 //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
379 //painter->setPen(pen);
380 //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
381 //kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
382 //painter->drawText(rect(), Qt::AlignCenter, m_name);
383 // painter->drawRect(boundingRect());
384 //painter->drawRoundRect(-10, -10, 20, 20);
386 painter->setPen(QPen(Qt::black));
387 painter->setBrush(QBrush(Qt::yellow));
388 painter->drawEllipse((int)(br.x() + 10), (int)(br.y() + br.height() / 2 - 5) , 10, 10);
389 painter->drawEllipse((int)(br.x() + br.width() - 20), (int)(br.y() + br.height() / 2 - 5), 10, 10);
394 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) {
395 if (abs((int)(pos.x() - (rect().x() + scale * m_startFade))) < 6 && abs((int)(pos.y() - rect().y())) < 6) return FADEIN;
396 else if (abs((int)(pos.x() - rect().x())) < 6) return RESIZESTART;
397 else if (abs((int)(pos.x() - (rect().x() + rect().width() - scale * m_endFade))) < 6 && abs((int)(pos.y() - rect().y())) < 6) return FADEOUT;
398 else if (abs((int)(pos.x() - (rect().x() + rect().width()))) < 6) return RESIZEEND;
399 else if (abs((int)(pos.x() - (rect().x() + 10))) < 6 && abs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONSTART;
400 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;
405 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, QPainterPath path, int startpixel, int endpixel) {
408 QRectF re = path.boundingRect();
410 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
412 for (int startCache = startpixel - startpixel % 100;startCache + 100 < endpixel ;startCache += 100) {
413 //kDebug() << "creating " << startCache;
414 //if (framePixelWidth!=pixelForOneFrame ||
415 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
417 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
418 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
419 audioThumbCachePic[startCache].fill(QColor(200, 200, 200, 0));
421 bool fullAreaDraw = pixelForOneFrame < 10;
422 QMap<int, QPainterPath > positiveChannelPaths;
423 QMap<int, QPainterPath > negativeChannelPaths;
424 QPainter pixpainter(&audioThumbCachePic[startCache]);
426 audiopen.setWidth(0);
427 pixpainter.setPen(audiopen);
428 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
429 //pixpainter.drawLine(0,0,100,re.height());
430 int channelHeight = audioThumbCachePic[startCache].height() / channels;
432 for (int i = 0;i < channels;i++) {
434 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
435 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
438 for (int samples = 0;samples <= 100;samples++) {
439 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
440 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
441 if (frame < 0 || sample < 0 || sample > 19)
443 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
445 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
447 int y = channelHeight * channel + channelHeight / 2;
448 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
450 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
451 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
453 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
454 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
457 for (int channel = 0;channel < channels ;channel++)
458 if (fullAreaDraw && samples == 100) {
459 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
460 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
461 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
462 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
466 if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
468 pixpainter.setPen(QPen(QColor(0, 0, 0)));
469 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
471 for (int i = 0;i < channels;i++) {
473 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
474 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
476 pixpainter.drawPath(positiveChannelPaths[i]);
479 //audioThumbWasDrawn=true;
480 framePixelWidth = pixelForOneFrame;
487 void ClipItem::setFadeIn(int pos, double scale) {
488 int oldIn = m_startFade;
489 if (pos < 0) pos = 0;
490 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
492 if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
493 else update(rect().x(), rect().y(), pos * scale, rect().height());
496 void ClipItem::setFadeOut(int pos, double scale) {
497 int oldOut = m_endFade;
498 if (pos < 0) pos = 0;
499 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
501 if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
502 else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
508 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
509 /*m_resizeMode = operationMode(event->pos());
510 if (m_resizeMode == MOVE) {
511 m_maxTrack = scene()->sceneRect().height();
512 m_grabPoint = (int) (event->pos().x() - rect().x());
514 QGraphicsRectItem::mousePressEvent(event);
518 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
520 QGraphicsRectItem::mouseReleaseEvent(event);
524 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
530 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
535 void ClipItem::resizeStart(int posx, double scale) {
536 AbstractClipItem::resizeStart(posx, scale);
537 if (m_hasThumbs) startThumbTimer->start(100);
540 void ClipItem::resizeEnd(int posx, double scale) {
541 AbstractClipItem::resizeEnd(posx, scale);
542 if (m_hasThumbs) endThumbTimer->start(100);
546 void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
549 int ClipItem::effectsCounter() {
550 return m_effectsCounter++;
553 int ClipItem::effectsCount() {
554 return m_effectList.size();
557 QStringList ClipItem::effectNames() {
558 return m_effectList.effectNames();
561 QDomElement ClipItem::effectAt(int ix) {
562 return m_effectList.at(ix);
565 void ClipItem::setEffectAt(int ix, QDomElement effect) {
566 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
567 m_effectList.insert(ix, effect);
568 m_effectList.removeAt(ix + 1);
569 update(boundingRect());
572 QMap <QString, QString> ClipItem::addEffect(QDomElement effect) {
573 QMap <QString, QString> effectParams;
574 m_effectList.append(effect);
575 effectParams["tag"] = effect.attribute("tag");
576 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
577 QString state = effect.attribute("disabled");
578 if (!state.isEmpty()) effectParams["disabled"] = state;
579 QDomNodeList params = effect.elementsByTagName("parameter");
580 for (int i = 0; i < params.count(); i++) {
581 QDomElement e = params.item(i).toElement();
583 effectParams[e.attribute("name")] = e.attribute("value");
585 if (!e.attribute("factor").isEmpty()) {
586 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
590 update(boundingRect());
594 QMap <QString, QString> ClipItem::getEffectArgs(QDomElement effect) {
595 QMap <QString, QString> effectParams;
596 effectParams["tag"] = effect.attribute("tag");
597 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
598 QString state = effect.attribute("disabled");
599 if (!state.isEmpty()) effectParams["disabled"] = state;
600 QDomNodeList params = effect.elementsByTagName("parameter");
601 for (int i = 0; i < params.count(); i++) {
602 QDomElement e = params.item(i).toElement();
603 if (e.attribute("name").contains(";")) {
604 QString format = e.attribute("format");
605 QStringList separators = format.split("%d", QString::SkipEmptyParts);
606 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
608 QTextStream txtNeu(&neu);
609 if (values.size() > 0)
610 txtNeu << (int)values[0].toDouble();
611 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
612 txtNeu << separators[i];
613 txtNeu << (int)(values[i+1].toDouble());
615 effectParams["start"] = neu;
618 effectParams[e.attribute("name")] = e.attribute("value");
620 if (!e.attribute("factor").isEmpty()) {
621 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
627 void ClipItem::deleteEffect(QString index) {
628 for (int i = 0; i < m_effectList.size(); ++i) {
629 if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
630 m_effectList.removeAt(i);
635 update(boundingRect());
639 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
640 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
642 doc.setContent(effects, true);
643 QDomElement e = doc.documentElement();
644 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
645 if (view) view->slotAddEffect(e, m_startPos, m_track);
649 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
650 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
653 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
656 void ClipItem::addTransition(Transition* t) {
657 m_transitionsList.append(t);
658 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
660 QDomElement e = doc.documentElement();
661 if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
665 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
667 int pos = event->x();
668 if (event->modifiers() == Qt::ControlModifier)
669 setDragMode(QGraphicsView::ScrollHandDrag);
670 else if (event->modifiers() == Qt::ShiftModifier)
671 setDragMode(QGraphicsView::RubberBandDrag);
673 QGraphicsItem * item = itemAt(event->pos());
676 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
679 QGraphicsView::mousePressEvent(event);
682 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
684 QGraphicsView::mouseReleaseEvent(event);
685 setDragMode(QGraphicsView::NoDrag);
689 #include "clipitem.moc"