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 ***************************************************************************/
22 #include "customtrackview.h"
23 #include "customtrackscene.h"
25 #include "docclipbase.h"
26 #include "transition.h"
27 #include "kdenlivesettings.h"
35 #include <QStyleOptionGraphicsItem>
36 #include <QGraphicsScene>
39 ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, bool generateThumbs) :
40 AbstractClipItem(info, QRectF(), fps),
47 m_startPix(QPixmap()),
50 m_startThumbTimer(NULL),
51 m_endThumbTimer(NULL),
54 m_startThumbRequested(false),
55 m_endThumbRequested(false),
61 setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double)(KdenliveSettings::trackheight() - 2));
62 setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1);
64 m_videoPix = KIcon("kdenlive-show-video").pixmap(QSize(16, 16));
65 m_audioPix = KIcon("kdenlive-show-audio").pixmap(QSize(16, 16));
67 if (m_speed == 1.0) m_clipName = clip->name();
69 m_clipName = clip->name() + " - " + QString::number(m_speed * 100, 'f', 0) + '%';
70 m_cropDuration = m_cropDuration * m_speed;
72 m_producer = clip->getId();
73 m_clipType = clip->clipType();
74 m_cropStart = info.cropStart;
75 m_maxDuration = clip->maxDuration();
77 m_audioThumbReady = clip->audioThumbCreated();
80 m_cropStart = xml.attribute("in", 0).toInt();
81 m_maxDuration = xml.attribute("duration", 0).toInt();
82 if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
84 if (duration != -1) m_cropDuration = duration;
85 else m_cropDuration = m_maxDuration;*/
88 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
89 setAcceptsHoverEvents(true);
90 connect(this , SIGNAL(prepareAudioThumb(double, int, int, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int)));
92 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
93 setBrush(QColor(141, 166, 215));
95 m_startThumbTimer = new QTimer(this);
96 m_startThumbTimer->setSingleShot(true);
97 connect(m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
98 m_endThumbTimer = new QTimer(this);
99 m_endThumbTimer->setSingleShot(true);
100 connect(m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
102 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
103 //connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(getVideoThumbs(int, int)));
105 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
106 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
107 if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs()));
109 /*if (m_clip->producer()) {
110 videoThumbProducer.init(this, m_clip->producer(), KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio(), KdenliveSettings::trackheight());
113 } else if (m_clipType == COLOR) {
114 QString colour = clip->getProperty("colour");
115 colour = colour.replace(0, 2, "#");
116 setBrush(QColor(colour.left(7)));
117 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
118 setBrush(QColor(141, 166, 215));
119 m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
120 m_endPix = m_startPix;
121 } else if (m_clipType == AUDIO) {
122 setBrush(QColor(141, 215, 166));
123 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
128 ClipItem::~ClipItem()
130 delete m_startThumbTimer;
131 delete m_endThumbTimer;
135 ClipItem *ClipItem::clone(ItemInfo info) const
137 ClipItem *duplicate = new ClipItem(m_clip, info, m_fps, m_speed);
138 if (info.cropStart == m_cropStart) duplicate->slotSetStartThumb(m_startPix);
139 if (info.cropStart + (info.endPos - info.startPos) == m_cropStart + m_cropDuration) duplicate->slotSetEndThumb(m_endPix);
140 kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
141 duplicate->setEffectList(m_effectList.clone());
142 duplicate->setVideoOnly(m_videoOnly);
143 duplicate->setAudioOnly(m_audioOnly);
144 //duplicate->setSpeed(m_speed);
148 void ClipItem::setEffectList(const EffectsList effectList)
150 m_effectList = effectList;
151 m_effectNames = m_effectList.effectNames().join(" / ");
154 const EffectsList ClipItem::effectList()
159 int ClipItem::selectedEffectIndex() const
161 return m_selectedEffect;
164 void ClipItem::initEffect(QDomElement effect)
166 // the kdenlive_ix int is used to identify an effect in mlt's playlist, should
168 if (effect.attribute("kdenlive_ix").toInt() == 0)
169 effect.setAttribute("kdenlive_ix", QString::number(effectsCounter()));
170 // init keyframes if required
171 QDomNodeList params = effect.elementsByTagName("parameter");
172 for (int i = 0; i < params.count(); i++) {
173 QDomElement e = params.item(i).toElement();
174 kDebug() << "// inint eff: " << e.attribute("name");
175 if (!e.isNull() && e.attribute("type") == "keyframe") {
176 QString def = e.attribute("default");
177 // Effect has a keyframe type parameter, we need to set the values
178 if (e.attribute("keyframes").isEmpty()) {
179 e.setAttribute("keyframes", QString::number(m_cropStart.frames(m_fps)) + ':' + def + ';' + QString::number((m_cropStart + m_cropDuration).frames(m_fps)) + ':' + def);
180 //kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
186 if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
187 if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
188 int end = (duration() + cropStart()).frames(m_fps);
190 if (effect.attribute("id") == "fadeout") {
191 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
192 start -= EffectsList::parameter(effect, "in").toInt();
194 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
195 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
197 } else if (effect.attribute("id") == "fade_to_black") {
198 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
199 start -= EffectsList::parameter(effect, "in").toInt();
201 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
202 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
205 EffectsList::setParameter(effect, "in", QString::number(start));
206 EffectsList::setParameter(effect, "out", QString::number(end));
207 } else if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
208 int start = cropStart().frames(m_fps);
210 if (effect.attribute("id") == "fadein") {
211 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1)
212 end += EffectsList::parameter(effect, "out").toInt();
214 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fade_from_black"), "out").toInt();
215 } else if (effect.attribute("id") == "fade_from_black") {
216 if (m_effectList.hasEffect(QString(), "fadein") == -1)
217 end += EffectsList::parameter(effect, "out").toInt();
219 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fadein"), "out").toInt();
221 EffectsList::setParameter(effect, "in", QString::number(start));
222 EffectsList::setParameter(effect, "out", QString::number(end));
227 bool ClipItem::checkKeyFrames()
229 bool clipEffectsModified = false;
230 for (int ix = 0; ix < m_effectList.count(); ix ++) {
231 QString kfr = keyframes(ix);
232 if (!kfr.isEmpty()) {
233 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
234 QStringList newKeyFrames;
235 bool cutKeyFrame = false;
236 bool modified = false;
238 double lastValue = -1;
239 int start = m_cropStart.frames(m_fps);
240 int end = (m_cropStart + m_cropDuration).frames(m_fps);
241 foreach(const QString &str, keyframes) {
242 int pos = str.section(':', 0, 0).toInt();
243 double val = str.section(':', 1, 1).toDouble();
244 if (pos - start < 0) {
245 // a keyframe is defined before the start of the clip
247 } else if (cutKeyFrame) {
248 // create new keyframe at clip start, calculate interpolated value
250 int diff = pos - lastPos;
251 double ratio = (double)(start - lastPos) / diff;
252 double newValue = lastValue + (val - lastValue) * ratio;
253 newKeyFrames.append(QString::number(start) + ':' + QString::number(newValue));
260 // create new keyframe at clip end, calculate interpolated value
261 int diff = pos - lastPos;
263 double ratio = (double)(end - lastPos) / diff;
264 double newValue = lastValue + (val - lastValue) * ratio;
265 newKeyFrames.append(QString::number(end) + ':' + QString::number(newValue));
270 newKeyFrames.append(QString::number(pos) + ':' + QString::number(val));
278 setKeyframes(ix, newKeyFrames.join(";"));
279 clipEffectsModified = true;
283 return clipEffectsModified;
286 void ClipItem::setKeyframes(const int ix, const QString keyframes)
288 QDomElement effect = effectAt(ix);
289 if (effect.attribute("disabled") == "1") return;
290 QDomNodeList params = effect.elementsByTagName("parameter");
291 for (int i = 0; i < params.count(); i++) {
292 QDomElement e = params.item(i).toElement();
293 if (!e.isNull() && e.attribute("type") == "keyframe") {
294 e.setAttribute("keyframes", keyframes);
295 if (ix == m_selectedEffect) {
297 double max = e.attribute("max").toDouble();
298 double min = e.attribute("min").toDouble();
299 m_keyframeFactor = 100.0 / (max - min);
300 m_keyframeDefault = e.attribute("default").toDouble();
302 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
303 foreach(const QString &str, keyframes) {
304 int pos = str.section(':', 0, 0).toInt();
305 double val = str.section(':', 1, 1).toDouble();
306 m_keyframes[pos] = val;
317 void ClipItem::setSelectedEffect(const int ix)
319 m_selectedEffect = ix;
320 QDomElement effect = effectAt(m_selectedEffect);
321 QDomNodeList params = effect.elementsByTagName("parameter");
322 if (effect.attribute("disabled") != "1")
323 for (int i = 0; i < params.count(); i++) {
324 QDomElement e = params.item(i).toElement();
325 if (!e.isNull() && e.attribute("type") == "keyframe") {
327 double max = e.attribute("max").toDouble();
328 double min = e.attribute("min").toDouble();
329 m_keyframeFactor = 100.0 / (max - min);
330 m_keyframeDefault = e.attribute("default").toDouble();
332 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
333 foreach(const QString &str, keyframes) {
334 int pos = str.section(':', 0, 0).toInt();
335 double val = str.section(':', 1, 1).toDouble();
336 m_keyframes[pos] = val;
342 if (!m_keyframes.isEmpty()) {
348 QString ClipItem::keyframes(const int index)
351 QDomElement effect = effectAt(index);
352 QDomNodeList params = effect.elementsByTagName("parameter");
354 for (int i = 0; i < params.count(); i++) {
355 QDomElement e = params.item(i).toElement();
356 if (!e.isNull() && e.attribute("type") == "keyframe") {
357 result = e.attribute("keyframes");
364 void ClipItem::updateKeyframeEffect()
366 // regenerate xml parameter from the clip keyframes
367 QDomElement effect = effectAt(m_selectedEffect);
368 if (effect.attribute("disabled") == "1") return;
369 QDomNodeList params = effect.elementsByTagName("parameter");
371 for (int i = 0; i < params.count(); i++) {
372 QDomElement e = params.item(i).toElement();
373 if (!e.isNull() && e.attribute("type") == "keyframe") {
375 if (m_keyframes.count() > 1) {
376 QMap<int, double>::const_iterator i = m_keyframes.constBegin();
377 while (i != m_keyframes.constEnd()) {
378 keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
382 // Effect has a keyframe type parameter, we need to set the values
383 //kDebug() << "::::::::::::::: SETTING EFFECT KEYFRAMES: " << keyframes;
384 e.setAttribute("keyframes", keyframes);
390 QDomElement ClipItem::selectedEffect()
392 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
393 return effectAt(m_selectedEffect);
396 void ClipItem::resetThumbs()
398 m_startPix = QPixmap();
399 m_endPix = QPixmap();
401 m_audioThumbCachePic.clear();
405 void ClipItem::refreshClip(bool checkDuration)
407 if (checkDuration && (m_maxDuration != m_clip->maxDuration())) {
408 m_maxDuration = m_clip->maxDuration();
409 if (m_clipType != IMAGE && m_clipType != TEXT && m_clipType != COLOR) {
410 if (m_cropStart + m_cropDuration > m_maxDuration) {
411 // Clip duration changed, make sure to stay in correct range
412 if (m_cropStart > m_maxDuration) {
413 m_cropStart = GenTime();
414 m_cropDuration = qMin(m_cropDuration, m_maxDuration);
415 updateRectGeometry();
417 m_cropDuration = m_maxDuration;
418 updateRectGeometry();
423 if (m_clipType == COLOR) {
424 QString colour = m_clip->getProperty("colour");
425 colour = colour.replace(0, 2, "#");
426 setBrush(QColor(colour.left(7)));
427 } else slotFetchThumbs();
430 void ClipItem::slotFetchThumbs()
432 if (m_endPix.isNull() && m_startPix.isNull()) {
433 m_startThumbRequested = true;
434 m_endThumbRequested = true;
435 emit getThumb((int)cropStart().frames(m_fps), (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
437 if (m_endPix.isNull()) {
440 if (m_startPix.isNull()) {
446 if (m_endPix.isNull() && m_startPix.isNull()) {
447 int frame1 = (int)m_cropStart.frames(m_fps);
448 int frame2 = (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1;
449 //videoThumbProducer.setThumbFrames(m_clip->producer(), frame1, frame2);
450 //videoThumbProducer.start(QThread::LowestPriority);
452 if (m_endPix.isNull()) slotGetEndThumb();
453 else slotGetStartThumb();
456 } else if (m_startPix.isNull()) slotGetStartThumb();*/
459 void ClipItem::slotGetStartThumb()
461 m_startThumbRequested = true;
462 emit getThumb((int)cropStart().frames(m_fps), -1);
463 //videoThumbProducer.setThumbFrames(m_clip->producer(), (int)m_cropStart.frames(m_fps), - 1);
464 //videoThumbProducer.start(QThread::LowestPriority);
467 void ClipItem::slotGetEndThumb()
469 m_endThumbRequested = true;
470 emit getThumb(-1, (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
471 //videoThumbProducer.setThumbFrames(m_clip->producer(), -1, (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1);
472 //videoThumbProducer.start(QThread::LowestPriority);
476 void ClipItem::slotSetStartThumb(QImage img)
478 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
479 QPixmap pix = QPixmap::fromImage(img);
481 QRectF r = sceneBoundingRect();
482 r.setRight(pix.width() + 2);
487 void ClipItem::slotSetEndThumb(QImage img)
489 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
490 QPixmap pix = QPixmap::fromImage(img);
492 QRectF r = sceneBoundingRect();
493 r.setLeft(r.right() - pix.width() - 2);
498 void ClipItem::slotThumbReady(int frame, QPixmap pix)
500 if (scene() == NULL) return;
501 QRectF r = sceneBoundingRect();
502 double width = m_startPix.width() / projectScene()->scale();
503 if (m_startThumbRequested && frame == cropStart().frames(m_fps)) {
505 m_startThumbRequested = false;
506 double height = r.height();
507 update(r.x(), r.y(), width, height);
508 } else if (m_endThumbRequested && frame == (cropStart() + cropDuration()).frames(m_fps) - 1) {
510 m_endThumbRequested = false;
511 double height = r.height();
512 update(r.right() - width, r.y(), width, height);
516 void ClipItem::slotSetStartThumb(const QPixmap pix)
521 void ClipItem::slotSetEndThumb(const QPixmap pix)
526 QPixmap ClipItem::startThumb() const
531 QPixmap ClipItem::endThumb() const
536 void ClipItem::slotGotAudioData()
538 m_audioThumbReady = true;
539 if (m_clipType == AV && !isAudioOnly()) {
540 QRectF r = boundingRect();
541 r.setTop(r.top() + r.height() / 2 - 1);
546 int ClipItem::type() const
551 DocClipBase *ClipItem::baseClip() const
556 QDomElement ClipItem::xml() const
558 QDomElement xml = m_clip->toXML();
559 if (m_speed != 1.0) xml.setAttribute("speed", m_speed);
560 if (m_audioOnly) xml.setAttribute("audio_only", 1);
561 else if (m_videoOnly) xml.setAttribute("video_only", 1);
565 int ClipItem::clipType() const
570 QString ClipItem::clipName() const
575 void ClipItem::setClipName(const QString &name)
580 const QString &ClipItem::clipProducer() const
585 void ClipItem::flashClip()
587 if (m_timeLine == 0) {
588 m_timeLine = new QTimeLine(750, this);
589 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
590 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
595 void ClipItem::animate(qreal /*value*/)
597 QRectF r = boundingRect();
603 void ClipItem::paint(QPainter *painter,
604 const QStyleOptionGraphicsItem *option,
607 /*if (parentItem()) m_opacity = 0.5;
608 else m_opacity = 1.0;
609 painter->setOpacity(m_opacity);*/
611 if (parentItem()) paintColor = QColor(255, 248, 149);
612 else paintColor = brush().color();
613 if (isSelected() || (parentItem() && parentItem()->isSelected())) paintColor = paintColor.darker();
615 QRectF exposed = option->exposedRect;
616 QRectF mapped = painter->matrix().mapRect(br);
618 const double itemWidth = br.width();
619 const double itemHeight = br.height();
620 const double scale = option->matrix.m11();
621 const qreal xoffset = pen().widthF() / scale;
623 //painter->setRenderHints(QPainter::Antialiasing);
625 //QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
626 painter->setClipRect(exposed);
628 //Fill clip rectangle
630 bgRect.setLeft(br.left() + xoffset);
631 painter->fillRect(bgRect, paintColor);
633 //painter->setClipPath(resultClipPath, Qt::IntersectClip);
636 painter->setMatrixEnabled(false);
638 if (KdenliveSettings::videothumbnails() && !isAudioOnly()) {
639 QPen pen = painter->pen();
640 pen.setColor(QColor(255, 255, 255, 150));
641 painter->setPen(pen);
642 if (m_clipType == IMAGE && !m_startPix.isNull()) {
643 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_startPix.width(), 0);
644 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_startPix.width(), 0);
645 painter->drawPixmap(p1, m_startPix);
647 painter->drawLine(l);
648 } else if (!m_endPix.isNull()) {
649 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_endPix.width(), 0);
650 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_endPix.width(), 0);
651 painter->drawPixmap(p1, m_endPix);
653 painter->drawLine(l);
655 if (!m_startPix.isNull()) {
656 QPointF p1 = painter->matrix().map(QPointF(0, 0)) + QPointF(1.0, 0);
657 QPointF p2 = painter->matrix().map(QPointF(0, itemHeight)) + QPointF(1.0, 0);
658 painter->drawPixmap(p1, m_startPix);
659 QLineF l2(p1.x() + m_startPix.width(), p1.y(), p2.x() + m_startPix.width(), p2.y());
660 painter->drawLine(l2);
662 painter->setPen(Qt::black);
665 // draw audio thumbnails
666 if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (itemHeight / 2) || isAudioOnly())) || m_clipType == AUDIO) && m_audioThumbReady) {
668 double startpixel = exposed.left();
671 double endpixel = exposed.right();
674 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
676 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
678 if (m_clipType == AV && !isAudioOnly()) {
680 re.setTop(re.y() + re.height() / 2);
681 mappedRect = painter->matrix().mapRect(re);
682 //painter->fillRect(mappedRect, QBrush(QColor(200, 200, 200, 140)));
683 } else mappedRect = mapped;
685 int channels = baseClip()->getProperty("channels").toInt();
686 if (scale != m_framePixelWidth)
687 m_audioThumbCachePic.clear();
688 double cropLeft = m_cropStart.frames(m_fps);
689 const int clipStart = mappedRect.x();
690 const int mappedStartPixel = painter->matrix().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
691 const int mappedEndPixel = painter->matrix().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
692 cropLeft = cropLeft * scale;
695 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
698 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
699 if (m_audioThumbCachePic.contains(startCache) && !m_audioThumbCachePic[startCache].isNull())
700 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), m_audioThumbCachePic[startCache]);
705 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
706 QList < CommentedTime >::Iterator it = markers.begin();
710 markerBrush = QBrush(QColor(120, 120, 0, 140));
711 QPen pen = painter->pen();
712 pen.setColor(QColor(255, 255, 255, 200));
713 pen.setStyle(Qt::DotLine);
714 painter->setPen(pen);
715 for (; it != markers.end(); ++it) {
716 pos = (*it).time() - cropStart();
717 if (pos > GenTime()) {
718 if (pos > duration()) break;
719 QLineF l(br.x() + pos.frames(m_fps), br.y() + 5, br.x() + pos.frames(m_fps), br.bottom() - 5);
720 QLineF l2 = painter->matrix().map(l);
721 //framepos = scale * pos.frames(m_fps);
722 //QLineF l(framepos, 5, framepos, itemHeight - 5);
723 painter->drawLine(l2);
724 if (KdenliveSettings::showmarkers()) {
725 framepos = br.x() + pos.frames(m_fps);
726 const QRectF r1(framepos + 0.04, 10, itemWidth - framepos - 2, itemHeight - 10);
727 const QRectF r2 = painter->matrix().mapRect(r1);
728 const QRectF txtBounding = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, ' ' + (*it).comment() + ' ');
729 painter->setBrush(markerBrush);
730 painter->setPen(Qt::NoPen);
731 painter->drawRoundedRect(txtBounding, 3, 3);
732 painter->setPen(Qt::white);
733 painter->drawText(txtBounding, Qt::AlignCenter, (*it).comment());
735 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
738 pen.setColor(Qt::black);
739 pen.setStyle(Qt::SolidLine);
740 painter->setPen(pen);
742 // draw start / end fades
745 fades = QBrush(QColor(200, 50, 50, 150));
746 } else fades = QBrush(QColor(200, 200, 200, 200));
748 if (m_startFade != 0) {
749 QPainterPath fadeInPath;
750 fadeInPath.moveTo(0, 0);
751 fadeInPath.lineTo(0, itemHeight);
752 fadeInPath.lineTo(m_startFade, 0);
753 fadeInPath.closeSubpath();
754 QPainterPath f1 = painter->matrix().map(fadeInPath);
755 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
756 /*if (isSelected()) {
757 QLineF l(m_startFade * scale, 0, 0, itemHeight);
758 painter->drawLine(l);
761 if (m_endFade != 0) {
762 QPainterPath fadeOutPath;
763 fadeOutPath.moveTo(itemWidth, 0);
764 fadeOutPath.lineTo(itemWidth, itemHeight);
765 fadeOutPath.lineTo(itemWidth - m_endFade, 0);
766 fadeOutPath.closeSubpath();
767 QPainterPath f1 = painter->matrix().map(fadeOutPath);
768 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
769 /*if (isSelected()) {
770 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
771 painter->drawLine(l);
775 // Draw effects names
776 if (!m_effectNames.isEmpty() && itemWidth * scale > 40) {
777 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
778 txtBounding.setRight(txtBounding.right() + 15);
779 painter->setPen(Qt::white);
780 QBrush markerBrush(Qt::SolidPattern);
781 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
782 qreal value = m_timeLine->currentValue();
783 txtBounding.setWidth(txtBounding.width() * value);
784 markerBrush.setColor(QColor(50 + 200 * (1.0 - value), 50, 50, 100 + 50 * value));
785 } else markerBrush.setColor(QColor(50, 50, 50, 150));
786 painter->setBrush(markerBrush);
787 painter->setPen(Qt::NoPen);
788 painter->drawRoundedRect(txtBounding, 3, 3);
789 painter->setPen(Qt::white);
790 painter->drawText(txtBounding, Qt::AlignCenter, m_effectNames);
791 painter->setPen(Qt::black);
795 // draw frame around clip
796 QColor frameColor(Qt::black);
798 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
799 frameColor = QColor(Qt::red);
802 frameColor.setAlpha(150);
803 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignHCenter | Qt::AlignVCenter, ' ' + m_clipName + ' ');
804 painter->fillRect(txtBounding, frameColor);
805 //painter->setPen(QColor(0, 0, 0, 180));
806 //painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
808 painter->drawPixmap(txtBounding.topLeft() - QPointF(17, -1), m_videoPix);
809 } else if (m_audioOnly) {
810 painter->drawPixmap(txtBounding.topLeft() - QPointF(17, -1), m_audioPix);
812 txtBounding.translate(QPointF(1, 1));
813 painter->setPen(QColor(255, 255, 255, 255));
814 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
817 // draw transition handles on hover
818 if (m_hover && itemWidth * scale > 40) {
819 QPointF p1 = painter->matrix().map(QPointF(0, itemHeight / 2)) + QPointF(10, 0);
820 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
821 p1 = painter->matrix().map(QPointF(itemWidth, itemHeight / 2)) - QPointF(22, 0);
822 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
825 // draw effect or transition keyframes
826 if (itemWidth > 20) drawKeyFrames(painter, exposed);
828 painter->setMatrixEnabled(true);
831 // expand clip rect to allow correct painting of clip border
833 exposed.setRight(exposed.right() + xoffset + 0.5);
834 exposed.setBottom(exposed.bottom() + 1);
835 painter->setClipRect(exposed);
837 frameColor.setAlpha(alphaBase);
838 painter->setPen(frameColor);
839 QLineF line(br.left() + xoffset, br.top(), br.right() - xoffset, br.top());
840 painter->drawLine(line);
842 frameColor.setAlpha(alphaBase * 2);
843 painter->setPen(frameColor);
844 line.setLine(br.right(), br.top() + 1.0, br.right(), br.bottom() - 1.0);
845 painter->drawLine(line);
846 line.setLine(br.right() - xoffset, br.bottom(), br.left() + xoffset, br.bottom());
847 painter->drawLine(line);
848 line.setLine(br.left(), br.bottom() - 1.0, br.left(), br.top() + 1.0);
849 painter->drawLine(line);
851 painter->setPen(QColor(255, 255, 255, 60));
852 line.setLine(br.right() - xoffset, br.bottom() - 1.0, br.left() + xoffset, br.bottom() - 1.0);
853 painter->drawLine(line);
854 //painter->drawRect(br);
858 OPERATIONTYPE ClipItem::operationMode(QPointF pos)
860 if (isItemLocked()) return NONE;
863 m_editedKeyframe = mouseOverKeyFrames(pos);
864 if (m_editedKeyframe != -1) return KEYFRAME;
866 QRectF rect = sceneBoundingRect();
867 const double scale = projectScene()->scale();
868 double maximumOffset = 6 / scale;
870 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
871 if (m_startFade == 0) setToolTip(i18n("Add audio fade"));
872 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_startFade, m_fps).seconds()));
874 } else if (pos.x() - rect.x() < maximumOffset) {
875 setToolTip(i18n("Crop from start: %1s", cropStart().seconds()));
877 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
878 if (m_endFade == 0) setToolTip(i18n("Add audio fade"));
879 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_endFade, m_fps).seconds()));
881 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width()))) < maximumOffset) {
882 setToolTip(i18n("Clip duration: %1s", duration().seconds()));
884 } else if (qAbs((int)(pos.x() - (rect.x() + 16 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
885 setToolTip(i18n("Add transition"));
886 return TRANSITIONSTART;
887 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - 21 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
888 setToolTip(i18n("Add transition"));
889 return TRANSITIONEND;
891 setToolTip(QString());
895 QList <GenTime> ClipItem::snapMarkers() const
897 QList < GenTime > snaps;
898 QList < GenTime > markers = baseClip()->snapMarkers();
901 for (int i = 0; i < markers.size(); i++) {
902 pos = markers.at(i) - cropStart();
903 if (pos > GenTime()) {
904 if (pos > duration()) break;
905 else snaps.append(pos + startPos());
911 QList <CommentedTime> ClipItem::commentedSnapMarkers() const
913 QList < CommentedTime > snaps;
914 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
917 for (int i = 0; i < markers.size(); i++) {
918 pos = markers.at(i).time() - cropStart();
919 if (pos > GenTime()) {
920 if (pos > duration()) break;
921 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
927 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels)
929 QRectF re = sceneBoundingRect();
930 if (m_clipType == AV && !isAudioOnly()) re.setTop(re.y() + re.height() / 2);
932 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
933 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
935 for (int startCache = startpixel - startpixel % 100;startCache < endpixel;startCache += 100) {
936 //kDebug() << "creating " << startCache;
937 //if (framePixelWidth!=pixelForOneFrame ||
938 if (m_framePixelWidth == pixelForOneFrame && m_audioThumbCachePic.contains(startCache))
940 if (m_audioThumbCachePic[startCache].isNull() || m_framePixelWidth != pixelForOneFrame) {
941 m_audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
942 m_audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
944 bool fullAreaDraw = pixelForOneFrame < 10;
945 QMap<int, QPainterPath > positiveChannelPaths;
946 QMap<int, QPainterPath > negativeChannelPaths;
947 QPainter pixpainter(&m_audioThumbCachePic[startCache]);
949 audiopen.setWidth(0);
950 pixpainter.setPen(audiopen);
951 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
952 //pixpainter.drawLine(0,0,100,re.height());
953 // Bail out, if caller provided invalid data
955 kWarning() << "Unable to draw image with " << channels << "number of channels";
959 int channelHeight = m_audioThumbCachePic[startCache].height() / channels;
961 for (int i = 0;i < channels;i++) {
963 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
964 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
967 for (int samples = 0;samples <= 100;samples++) {
968 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
969 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
970 if (frame < 0 || sample < 0 || sample > 19)
972 QMap<int, QByteArray> frame_channel_data = baseClip()->m_audioFrameCache[(int)frame];
974 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
976 int y = channelHeight * channel + channelHeight / 2;
977 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
979 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
980 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
982 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
983 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
986 for (int channel = 0;channel < channels ;channel++)
987 if (fullAreaDraw && samples == 100) {
988 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
989 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
990 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
991 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
995 pixpainter.setPen(QPen(QColor(0, 0, 0)));
996 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
998 for (int i = 0;i < channels;i++) {
1000 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
1001 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
1003 pixpainter.drawPath(positiveChannelPaths[i]);
1006 //audioThumbWasDrawn=true;
1007 m_framePixelWidth = pixelForOneFrame;
1012 int ClipItem::fadeIn() const
1017 int ClipItem::fadeOut() const
1023 void ClipItem::setFadeIn(int pos)
1025 if (pos == m_startFade) return;
1026 int oldIn = m_startFade;
1027 if (pos < 0) pos = 0;
1028 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
1030 QRectF rect = boundingRect();
1031 update(rect.x(), rect.y(), qMax(oldIn, pos), rect.height());
1034 void ClipItem::setFadeOut(int pos)
1036 if (pos == m_endFade) return;
1037 int oldOut = m_endFade;
1038 if (pos < 0) pos = 0;
1039 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
1041 QRectF rect = boundingRect();
1042 update(rect.x() + rect.width() - qMax(oldOut, pos), rect.y(), qMax(oldOut, pos), rect.height());
1047 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event)
1049 /*m_resizeMode = operationMode(event->pos());
1050 if (m_resizeMode == MOVE) {
1051 m_maxTrack = scene()->sceneRect().height();
1052 m_grabPoint = (int) (event->pos().x() - rect().x());
1054 QGraphicsRectItem::mousePressEvent(event);
1058 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
1060 m_resizeMode = NONE;
1061 QGraphicsRectItem::mouseReleaseEvent(event);
1065 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent */*e*/)
1067 //if (e->pos().x() < 20) m_hover = true;
1068 if (isItemLocked()) return;
1070 QRectF r = boundingRect();
1071 double width = 35 / projectScene()->scale();
1072 double height = r.height() / 2;
1073 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1074 update(r.x(), r.y() + height, width, height);
1075 update(r.right() - width, r.y() + height, width, height);
1079 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
1081 if (isItemLocked()) return;
1083 QRectF r = boundingRect();
1084 double width = 35 / projectScene()->scale();
1085 double height = r.height() / 2;
1086 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1087 update(r.x(), r.y() + height, width, height);
1088 update(r.right() - width, r.y() + height, width, height);
1091 void ClipItem::resizeStart(int posx, double /*speed*/)
1093 const int min = (startPos() - cropStart()).frames(m_fps);
1094 if (posx < min) posx = min;
1095 if (posx == startPos().frames(m_fps)) return;
1096 const int previous = cropStart().frames(m_fps);
1097 AbstractClipItem::resizeStart(posx, m_speed);
1098 if ((int) cropStart().frames(m_fps) != previous) {
1099 checkEffectsKeyframesPos(previous, cropStart().frames(m_fps), true);
1100 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1101 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
1102 m_startThumbTimer->start(150);
1107 void ClipItem::resizeEnd(int posx, double /*speed*/, bool updateKeyFrames)
1109 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps) + 1;
1110 if (posx > max) posx = max;
1111 if (posx == endPos().frames(m_fps)) return;
1112 //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
1113 const int previous = (cropStart() + duration()).frames(m_fps);
1114 AbstractClipItem::resizeEnd(posx, m_speed);
1115 if ((int)(cropStart() + duration()).frames(m_fps) != previous) {
1116 if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false);
1117 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1118 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
1119 m_endThumbTimer->start(150);
1125 void ClipItem::checkEffectsKeyframesPos(const int previous, const int current, bool fromStart)
1127 for (int i = 0; i < m_effectList.size(); i++) {
1128 QDomElement effect = m_effectList.at(i);
1129 QDomNodeList params = effect.elementsByTagName("parameter");
1130 for (int j = 0; j < params.count(); j++) {
1131 QDomElement e = params.item(i).toElement();
1132 if (e.attribute("type") == "keyframe") {
1133 // parse keyframes and adjust values
1134 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1135 QMap <int, double> kfr;
1138 foreach(const QString &str, keyframes) {
1139 pos = str.section(':', 0, 0).toInt();
1140 val = str.section(':', 1, 1).toDouble();
1141 if (pos == previous) kfr[current] = val;
1143 if (fromStart && pos >= current) kfr[pos] = val;
1144 else if (!fromStart && pos <= current) kfr[pos] = val;
1148 QMap<int, double>::const_iterator k = kfr.constBegin();
1149 while (k != kfr.constEnd()) {
1150 newkfr.append(QString::number(k.key()) + ':' + QString::number(k.value()) + ';');
1153 e.setAttribute("keyframes", newkfr);
1158 if (m_selectedEffect >= 0) setSelectedEffect(m_selectedEffect);
1162 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
1164 if (change == ItemPositionChange && scene()) {
1165 // calculate new position.
1166 //if (parentItem()) return pos();
1167 QPointF newPos = value.toPointF();
1168 //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1169 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1170 xpos = qMax(xpos, 0);
1172 int newTrack = newPos.y() / KdenliveSettings::trackheight();
1173 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1174 newTrack = qMax(newTrack, 0);
1175 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1176 // Only one clip is moving
1177 QRectF sceneShape = rect();
1178 sceneShape.translate(newPos);
1179 QList<QGraphicsItem*> items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1180 items.removeAll(this);
1181 bool forwardMove = newPos.x() > pos().x();
1183 if (!items.isEmpty()) {
1184 for (int i = 0; i < items.count(); i++) {
1185 if (items.at(i)->type() == type()) {
1187 QPointF otherPos = items.at(i)->pos();
1188 if ((int) otherPos.y() != (int) pos().y()) {
1192 offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps)));
1194 offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
1199 sceneShape.translate(QPointF(-offset, 0));
1200 newPos.setX(newPos.x() - offset);
1202 sceneShape.translate(QPointF(offset, 0));
1203 newPos.setX(newPos.x() + offset);
1205 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1206 subitems.removeAll(this);
1207 for (int j = 0; j < subitems.count(); j++) {
1208 if (subitems.at(j)->type() == type()) {
1209 m_startPos = GenTime((int) pos().x(), m_fps);
1216 m_startPos = GenTime((int) newPos.x(), m_fps);
1222 m_startPos = GenTime((int) newPos.x(), m_fps);
1223 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1226 return QGraphicsItem::itemChange(change, value);
1230 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1233 int ClipItem::effectsCounter()
1235 return effectsCount() + 1;
1238 int ClipItem::effectsCount()
1240 return m_effectList.size();
1243 int ClipItem::hasEffect(const QString &tag, const QString &id) const
1245 return m_effectList.hasEffect(tag, id);
1248 QStringList ClipItem::effectNames()
1250 return m_effectList.effectNames();
1253 QDomElement ClipItem::effectAt(int ix)
1255 if (ix > m_effectList.count() - 1 || ix < 0) return QDomElement();
1256 return m_effectList.at(ix);
1259 void ClipItem::setEffectAt(int ix, QDomElement effect)
1261 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1262 effect.setAttribute("kdenlive_ix", ix + 1);
1263 m_effectList.insert(ix, effect);
1264 m_effectList.removeAt(ix + 1);
1265 m_effectNames = m_effectList.effectNames().join(" / ");
1266 QString id = effect.attribute("id");
1267 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1268 update(boundingRect());
1270 QRectF r = boundingRect();
1276 EffectsParameterList ClipItem::addEffect(QDomElement effect, bool animate)
1279 bool needRepaint = false;
1281 doc.appendChild(doc.importNode(effect, true));
1282 kDebug() << "/////// CLIPÂ ADD EFFECT: " << doc.toString();*/
1283 m_effectList.append(effect);
1285 EffectsParameterList parameters;
1286 parameters.addParam("tag", effect.attribute("tag"));
1287 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1288 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1290 QString state = effect.attribute("disabled");
1291 if (!state.isEmpty()) {
1292 parameters.addParam("disabled", state);
1295 QString effectId = effect.attribute("id");
1296 if (effectId.isEmpty()) effectId = effect.attribute("tag");
1297 parameters.addParam("id", effectId);
1299 QDomNodeList params = effect.elementsByTagName("parameter");
1301 for (int i = 0; i < params.count(); i++) {
1302 QDomElement e = params.item(i).toElement();
1304 if (e.attribute("type") == "keyframe") {
1305 parameters.addParam("keyframes", e.attribute("keyframes"));
1306 parameters.addParam("max", e.attribute("max"));
1307 parameters.addParam("min", e.attribute("min"));
1308 parameters.addParam("factor", e.attribute("factor", "1"));
1309 parameters.addParam("starttag", e.attribute("starttag", "start"));
1310 parameters.addParam("endtag", e.attribute("endtag", "end"));
1313 double f = e.attribute("factor", "1").toDouble();
1316 parameters.addParam(e.attribute("name"), e.attribute("value"));
1318 // check if it is a fade effect
1319 if (effectId == "fadein") {
1321 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
1322 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1323 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1325 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
1326 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1327 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1329 } else if (effectId == "fade_from_black") {
1331 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
1332 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1333 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1335 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
1336 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1337 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1339 } else if (effectId == "fadeout") {
1341 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
1342 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1343 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1345 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
1346 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1347 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1349 } else if (effectId == "fade_to_black") {
1351 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
1352 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1353 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1355 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
1356 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1357 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1361 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / f));
1365 m_effectNames = m_effectList.effectNames().join(" / ");
1366 if (fade > 0) m_startFade = fade;
1367 else if (fade < 0) m_endFade = -fade;
1368 if (needRepaint) update(boundingRect());
1371 } else if (!needRepaint) {
1372 QRectF r = boundingRect();
1376 if (m_selectedEffect == -1) {
1377 m_selectedEffect = 0;
1378 setSelectedEffect(m_selectedEffect);
1383 EffectsParameterList ClipItem::getEffectArgs(QDomElement effect)
1385 EffectsParameterList parameters;
1386 parameters.addParam("tag", effect.attribute("tag"));
1387 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1388 parameters.addParam("id", effect.attribute("id"));
1389 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1390 QString state = effect.attribute("disabled");
1391 if (!state.isEmpty()) {
1392 parameters.addParam("disabled", state);
1395 QDomNodeList params = effect.elementsByTagName("parameter");
1396 for (int i = 0; i < params.count(); i++) {
1397 QDomElement e = params.item(i).toElement();
1398 //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
1399 if (e.attribute("type") == "keyframe") {
1400 kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
1401 parameters.addParam("keyframes", e.attribute("keyframes"));
1402 parameters.addParam("max", e.attribute("max"));
1403 parameters.addParam("min", e.attribute("min"));
1404 parameters.addParam("factor", e.attribute("factor", "1"));
1405 parameters.addParam("starttag", e.attribute("starttag", "start"));
1406 parameters.addParam("endtag", e.attribute("endtag", "end"));
1407 } else if (e.attribute("namedesc").contains(';')) {
1408 QString format = e.attribute("format");
1409 QStringList separators = format.split("%d", QString::SkipEmptyParts);
1410 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
1412 QTextStream txtNeu(&neu);
1413 if (values.size() > 0)
1414 txtNeu << (int)values[0].toDouble();
1415 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
1416 txtNeu << separators[i];
1417 txtNeu << (int)(values[i+1].toDouble());
1419 parameters.addParam("start", neu);
1421 if (e.attribute("factor", "1") != "1") {
1422 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / e.attribute("factor").toDouble()));
1424 parameters.addParam(e.attribute("name"), e.attribute("value"));
1431 void ClipItem::deleteEffect(QString index)
1433 bool needRepaint = false;
1436 for (int i = 0; i < m_effectList.size(); ++i) {
1437 ix = m_effectList.at(i).attribute("kdenlive_ix");
1439 QString effectId = m_effectList.at(i).attribute("id");
1440 if ((effectId == "fadein" && hasEffect(QString(), "fade_from_black") == -1) ||
1441 (effectId == "fade_from_black" && hasEffect(QString(), "fadein") == -1)) {
1444 } else if ((effectId == "fadeout" && hasEffect(QString(), "fade_to_black") == -1) ||
1445 (effectId == "fade_to_black" && hasEffect(QString(), "fadeout") == -1)) {
1449 m_effectList.removeAt(i);
1451 } else if (ix.toInt() > index.toInt()) {
1452 m_effectList[i].setAttribute("kdenlive_ix", ix.toInt() - 1);
1455 m_effectNames = m_effectList.effectNames().join(" / ");
1456 if (needRepaint) update(boundingRect());
1460 double ClipItem::speed() const
1465 void ClipItem::setSpeed(const double speed)
1468 if (m_speed == 1.0) m_clipName = baseClip()->name();
1469 else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + '%';
1473 GenTime ClipItem::maxDuration() const
1475 return m_maxDuration / m_speed;
1478 GenTime ClipItem::cropStart() const
1480 return m_cropStart / m_speed;
1483 GenTime ClipItem::cropDuration() const
1485 return m_cropDuration / m_speed;
1488 GenTime ClipItem::endPos() const
1490 return m_startPos + cropDuration();
1494 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
1496 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
1498 doc.setContent(effects, true);
1499 QDomElement e = doc.documentElement();
1500 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1501 if (view) view->slotAddEffect(e, m_startPos, track());
1505 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
1507 if (isItemLocked()) event->setAccepted(false);
1508 else event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
1511 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
1516 void ClipItem::addTransition(Transition* t)
1518 m_transitionsList.append(t);
1519 //CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1521 QDomElement e = doc.documentElement();
1522 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1525 void ClipItem::setVideoOnly(bool force)
1527 m_videoOnly = force;
1530 void ClipItem::setAudioOnly(bool force)
1532 m_audioOnly = force;
1533 if (m_audioOnly) setBrush(QColor(141, 215, 166));
1534 else setBrush(QColor(141, 166, 215));
1535 m_audioThumbCachePic.clear();
1538 bool ClipItem::isAudioOnly() const
1543 bool ClipItem::isVideoOnly() const
1549 #include "clipitem.moc"