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 GenTime ClipItem::cropStart() const {
161 void ClipItem::flashClip() {
162 if (m_timeLine == 0) {
163 m_timeLine = new QTimeLine(750, this);
164 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
169 void ClipItem::animate(qreal value) {
175 void ClipItem::paint(QPainter *painter,
176 const QStyleOptionGraphicsItem *option,
178 painter->setOpacity(m_opacity);
179 QBrush paintColor = brush();
181 if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
183 double scale = br.width() / m_cropDuration.frames(m_fps);
184 QRect rectInView;//this is the rect that is visible by the user
185 if (scene()->views().size() > 0) {
186 rectInView = scene()->views()[0]->viewport()->rect();
187 rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(), scene()->views()[0]->verticalScrollBar()->value());
188 rectInView.adjust(-10, -10, 10, 10);//make view rect 10 pixel greater on each site, or repaint after scroll event
189 //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value();
191 if (rectInView.isNull())
193 QPainterPath clippath;
194 clippath.addRect(rectInView);
196 int startpixel = (int)(rectInView.x() - rect().x()); //start and endpixel that is viewable from rect()
200 int endpixel = rectInView.width() + rectInView.x();
204 //painter->setRenderHints(QPainter::Antialiasing);
206 QPainterPath roundRectPathUpper, roundRectPathLower;
207 double roundingY = 20;
208 double roundingX = 20;
210 painter->setClipRect(option->exposedRect);
211 if (roundingX > br.width() / 2) roundingX = br.width() / 2;
213 int br_endx = (int)(br.x() + br .width() - offset);
214 int br_startx = (int)(br.x() + offset);
215 int br_starty = (int)(br.y());
216 int br_halfy = (int)(br.y() + br.height() / 2 - offset);
217 int br_endy = (int)(br.y() + br.height());
218 int left_upper = 0, left_lower = 0, right_upper = 0, right_lower = 0;
220 if (m_hover && false) {
221 if (!true) /*TRANSITIONSTART to upper clip*/
223 if (!false) /*TRANSITIONSTART to lower clip*/
225 if (!true) /*TRANSITIONEND to upper clip*/
227 if (!false) /*TRANSITIONEND to lower clip*/
231 // build path around clip
232 roundRectPathUpper.moveTo(br_endx - right_upper , br_halfy);
233 roundRectPathUpper.arcTo(br_endx - roundingX - right_upper , br_starty , roundingX, roundingY, 0.0, 90.0);
234 roundRectPathUpper.lineTo(br_startx + roundingX + left_upper, br_starty);
235 roundRectPathUpper.arcTo(br_startx + left_upper, br_starty , roundingX, roundingY, 90.0, 90.0);
236 roundRectPathUpper.lineTo(br_startx + left_upper, br_halfy);
238 roundRectPathLower.moveTo(br_startx + left_lower, br_halfy);
239 roundRectPathLower.arcTo(br_startx + left_lower, br_endy - roundingY , roundingX, roundingY, 180.0, 90.0);
240 roundRectPathLower.lineTo(br_endx - roundingX - right_lower , br_endy);
241 roundRectPathLower.arcTo(br_endx - roundingX - right_lower , br_endy - roundingY, roundingX, roundingY, 270.0, 90.0);
242 roundRectPathLower.lineTo(br_endx - right_lower , br_halfy);
244 QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
246 painter->setClipPath(resultClipPath.intersected(clippath), Qt::IntersectClip);
247 //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
248 painter->fillRect(br.intersected(rectInView), paintColor);
249 //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
252 if (!m_startPix.isNull() && KdenliveSettings::videothumbnails()) {
253 if (m_clipType == IMAGE) {
254 painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
255 QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
256 painter->drawLine(l);
258 painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
259 QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
260 painter->drawLine(l);
263 painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
264 QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
265 painter->drawLine(l2);
268 // draw audio thumbnails
269 if ((m_clipType == AV || m_clipType == AUDIO) && audioThumbReady && KdenliveSettings::audiothumbnails()) {
271 QPainterPath path = m_clipType == AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
272 if (m_clipType == AV) painter->fillPath(path, QBrush(QColor(200, 200, 200, 140)));
275 if (scale != framePixelWidth)
276 audioThumbCachePic.clear();
277 emit prepareAudioThumb(scale, path, startpixel, endpixel + 200);//200 more for less missing parts before repaint after scrolling
278 int cropLeft = (m_cropStart).frames(m_fps) * scale;
279 for (int startCache = startpixel - startpixel % 100; startCache < endpixel + 300;startCache += 100) {
280 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
281 painter->drawPixmap((int)(roundRectPathUpper.united(roundRectPathLower).boundingRect().x() + startCache - cropLeft), (int)(path.boundingRect().y()), audioThumbCachePic[startCache]);
286 // draw start / end fades
289 fades = QBrush(QColor(200, 50, 50, 150));
290 } else fades = QBrush(QColor(200, 200, 200, 200));
292 if (m_startFade != 0) {
293 QPainterPath fadeInPath;
294 fadeInPath.moveTo(br.x() - offset, br.y());
295 fadeInPath.lineTo(br.x() - offset, br.y() + br.height());
296 fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
297 fadeInPath.closeSubpath();
298 painter->fillPath(fadeInPath, fades);
300 QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
301 painter->drawLine(l);
304 if (m_endFade != 0) {
305 QPainterPath fadeOutPath;
306 fadeOutPath.moveTo(br.x() + br.width(), br.y());
307 fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
308 fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
309 fadeOutPath.closeSubpath();
310 painter->fillPath(fadeOutPath, fades);
312 QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
313 painter->drawLine(l);
317 QPen pen = painter->pen();
318 pen.setColor(Qt::white);
319 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
321 // Draw effects names
322 QString effects = effectNames().join(" / ");
323 if (!effects.isEmpty()) {
324 painter->setPen(pen);
325 QFont font = painter->font();
326 QFont smallFont = font;
327 smallFont.setPointSize(8);
328 painter->setFont(smallFont);
329 QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " ");
330 painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
331 painter->drawText(txtBounding, Qt::AlignCenter, effects);
332 pen.setColor(Qt::black);
333 painter->setPen(pen);
334 painter->setFont(font);
337 // For testing puspose only: draw transitions count
339 painter->setPen(pen);
340 QFont font = painter->font();
341 QFont smallFont = font;
342 smallFont.setPointSize(8);
343 painter->setFont(smallFont);
344 QString txt = " Transitions: " + QString::number(m_transitionsList.count()) + " ";
345 QRectF txtBoundin = painter->boundingRect(br, Qt::AlignRight | Qt::AlignTop, txt);
346 painter->fillRect(txtBoundin, QBrush(QColor(0, 0, 0, 150)));
347 painter->drawText(txtBoundin, Qt::AlignCenter, txt);
348 pen.setColor(Qt::black);
349 painter->setPen(pen);
350 painter->setFont(font);
354 QRectF txtBounding = painter->boundingRect(br, Qt::AlignHCenter | Qt::AlignTop, " " + m_clipName + " ");
355 painter->fillRect(txtBounding, QBrush(QColor(255, 255, 255, 150)));
356 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
358 // draw frame around clip
359 pen.setColor(Qt::red);
361 if (isSelected()) painter->setPen(pen);
362 painter->setClipRect(option->exposedRect);
363 painter->drawPath(resultClipPath.intersected(clippath));
365 //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150)));
366 //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
368 /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
369 painter->drawRect(recta);
370 painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
371 painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
372 painter->setPen(QPen(Qt::black, 1.0));
373 painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
374 painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
376 //QGraphicsRectItem::paint(painter, option, widget);
377 //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
378 //painter->setPen(pen);
379 //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
380 //kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
381 //painter->drawText(rect(), Qt::AlignCenter, m_name);
382 // painter->drawRect(boundingRect());
383 //painter->drawRoundRect(-10, -10, 20, 20);
385 painter->setPen(QPen(Qt::black));
386 painter->setBrush(QBrush(Qt::yellow));
387 painter->drawEllipse((int)(br.x() + 10), (int)(br.y() + br.height() / 2 - 5) , 10, 10);
388 painter->drawEllipse((int)(br.x() + br.width() - 20), (int)(br.y() + br.height() / 2 - 5), 10, 10);
393 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) {
394 if (abs((int)(pos.x() - (rect().x() + scale * m_startFade))) < 6 && abs((int)(pos.y() - rect().y())) < 6) return FADEIN;
395 else if (abs((int)(pos.x() - rect().x())) < 6) return RESIZESTART;
396 else if (abs((int)(pos.x() - (rect().x() + rect().width() - scale * m_endFade))) < 6 && abs((int)(pos.y() - rect().y())) < 6) return FADEOUT;
397 else if (abs((int)(pos.x() - (rect().x() + rect().width()))) < 6) return RESIZEEND;
398 else if (abs((int)(pos.x() - (rect().x() + 10))) < 6 && abs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONSTART;
399 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;
404 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, QPainterPath path, int startpixel, int endpixel) {
407 QRectF re = path.boundingRect();
409 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
411 for (int startCache = startpixel - startpixel % 100;startCache + 100 < endpixel ;startCache += 100) {
412 //kDebug() << "creating " << startCache;
413 //if (framePixelWidth!=pixelForOneFrame ||
414 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
416 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
417 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
418 audioThumbCachePic[startCache].fill(QColor(200, 200, 200, 0));
420 bool fullAreaDraw = pixelForOneFrame < 10;
421 QMap<int, QPainterPath > positiveChannelPaths;
422 QMap<int, QPainterPath > negativeChannelPaths;
423 QPainter pixpainter(&audioThumbCachePic[startCache]);
425 audiopen.setWidth(0);
426 pixpainter.setPen(audiopen);
427 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
428 //pixpainter.drawLine(0,0,100,re.height());
429 int channelHeight = audioThumbCachePic[startCache].height() / channels;
431 for (int i = 0;i < channels;i++) {
433 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
434 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
437 for (int samples = 0;samples <= 100;samples++) {
438 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
439 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
440 if (frame < 0 || sample < 0 || sample > 19)
442 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
444 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
446 int y = channelHeight * channel + channelHeight / 2;
447 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
449 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
450 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
452 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
453 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
456 for (int channel = 0;channel < channels ;channel++)
457 if (fullAreaDraw && samples == 100) {
458 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
459 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
460 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
461 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
465 if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
467 pixpainter.setPen(QPen(QColor(0, 0, 0)));
468 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
470 for (int i = 0;i < channels;i++) {
472 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
473 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
475 pixpainter.drawPath(positiveChannelPaths[i]);
478 //audioThumbWasDrawn=true;
479 framePixelWidth = pixelForOneFrame;
486 void ClipItem::setFadeIn(int pos, double scale) {
487 int oldIn = m_startFade;
488 if (pos < 0) pos = 0;
489 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
491 if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
492 else update(rect().x(), rect().y(), pos * scale, rect().height());
495 void ClipItem::setFadeOut(int pos, double scale) {
496 int oldOut = m_endFade;
497 if (pos < 0) pos = 0;
498 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
500 if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
501 else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
507 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
508 /*m_resizeMode = operationMode(event->pos());
509 if (m_resizeMode == MOVE) {
510 m_maxTrack = scene()->sceneRect().height();
511 m_grabPoint = (int) (event->pos().x() - rect().x());
513 QGraphicsRectItem::mousePressEvent(event);
517 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
519 QGraphicsRectItem::mouseReleaseEvent(event);
523 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
529 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
534 void ClipItem::resizeStart(int posx, double scale) {
535 AbstractClipItem::resizeStart(posx, scale);
536 if (m_hasThumbs) startThumbTimer->start(100);
539 void ClipItem::resizeEnd(int posx, double scale) {
540 AbstractClipItem::resizeEnd(posx, scale);
541 if (m_hasThumbs) endThumbTimer->start(100);
545 void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
548 int ClipItem::effectsCounter() {
549 return m_effectsCounter++;
552 int ClipItem::effectsCount() {
553 return m_effectList.size();
556 QStringList ClipItem::effectNames() {
557 return m_effectList.effectNames();
560 QDomElement ClipItem::effectAt(int ix) {
561 return m_effectList.at(ix);
564 void ClipItem::setEffectAt(int ix, QDomElement effect) {
565 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
566 m_effectList.insert(ix, effect);
567 m_effectList.removeAt(ix + 1);
568 update(boundingRect());
571 QMap <QString, QString> ClipItem::addEffect(QDomElement effect) {
572 QMap <QString, QString> effectParams;
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());
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("name").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, m_track);
648 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
649 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
652 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
658 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
660 int pos = event->x();
661 if (event->modifiers() == Qt::ControlModifier)
662 setDragMode(QGraphicsView::ScrollHandDrag);
663 else if (event->modifiers() == Qt::ShiftModifier)
664 setDragMode(QGraphicsView::RubberBandDrag);
666 QGraphicsItem * item = itemAt(event->pos());
669 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
672 QGraphicsView::mousePressEvent(event);
675 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
677 QGraphicsView::mouseReleaseEvent(event);
678 setDragMode(QGraphicsView::NoDrag);
682 #include "clipitem.moc"