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),
46 startThumbTimer(NULL),
48 audioThumbWasDrawn(false),
51 m_startThumbRequested(false),
52 m_endThumbRequested(false),
59 m_startPix(QPixmap()),
65 setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double)(KdenliveSettings::trackheight() - 2));
66 setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1);
68 m_videoPix = KIcon("kdenlive-show-video").pixmap(QSize(16, 16));
69 m_audioPix = KIcon("kdenlive-show-audio").pixmap(QSize(16, 16));
71 if (m_speed == 1.0) m_clipName = clip->name();
73 m_clipName = clip->name() + " - " + QString::number(m_speed * 100, 'f', 0) + '%';
74 m_cropDuration = m_cropDuration * m_speed;
76 m_producer = clip->getId();
77 m_clipType = clip->clipType();
78 m_cropStart = info.cropStart;
79 m_maxDuration = clip->maxDuration();
81 audioThumbReady = clip->audioThumbCreated();
84 m_cropStart = xml.attribute("in", 0).toInt();
85 m_maxDuration = xml.attribute("duration", 0).toInt();
86 if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
88 if (duration != -1) m_cropDuration = duration;
89 else m_cropDuration = m_maxDuration;*/
92 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
93 setAcceptsHoverEvents(true);
94 connect(this , SIGNAL(prepareAudioThumb(double, int, int, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int)));
96 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
97 setBrush(QColor(141, 166, 215));
99 startThumbTimer = new QTimer(this);
100 startThumbTimer->setSingleShot(true);
101 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
102 endThumbTimer = new QTimer(this);
103 endThumbTimer->setSingleShot(true);
104 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
106 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
107 //connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(getVideoThumbs(int, int)));
109 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
110 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
111 if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs()));
113 /*if (m_clip->producer()) {
114 videoThumbProducer.init(this, m_clip->producer(), KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio(), KdenliveSettings::trackheight());
117 } else if (m_clipType == COLOR) {
118 QString colour = clip->getProperty("colour");
119 colour = colour.replace(0, 2, "#");
120 setBrush(QColor(colour.left(7)));
121 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
122 setBrush(QColor(141, 166, 215));
123 m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
124 m_endPix = m_startPix;
125 } else if (m_clipType == AUDIO) {
126 setBrush(QColor(141, 215, 166));
127 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
132 ClipItem::~ClipItem()
134 if (startThumbTimer) delete startThumbTimer;
135 if (endThumbTimer) delete endThumbTimer;
136 if (m_timeLine) delete m_timeLine;
139 ClipItem *ClipItem::clone(ItemInfo info) const
141 ClipItem *duplicate = new ClipItem(m_clip, info, m_fps, m_speed);
142 if (info.cropStart == m_cropStart) duplicate->slotSetStartThumb(m_startPix);
143 if (info.cropStart + (info.endPos - info.startPos) == m_cropStart + m_cropDuration) duplicate->slotSetEndThumb(m_endPix);
144 kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
145 duplicate->setEffectList(m_effectList.clone());
146 //duplicate->setSpeed(m_speed);
150 void ClipItem::setEffectList(const EffectsList effectList)
152 m_effectList = effectList;
153 m_effectNames = m_effectList.effectNames().join(" / ");
156 const EffectsList ClipItem::effectList()
161 int ClipItem::selectedEffectIndex() const
163 return m_selectedEffect;
166 void ClipItem::initEffect(QDomElement effect)
168 // the kdenlive_ix int is used to identify an effect in mlt's playlist, should
170 if (effect.attribute("kdenlive_ix").toInt() == 0)
171 effect.setAttribute("kdenlive_ix", QString::number(effectsCounter()));
172 // init keyframes if required
173 QDomNodeList params = effect.elementsByTagName("parameter");
174 for (int i = 0; i < params.count(); i++) {
175 QDomElement e = params.item(i).toElement();
176 kDebug() << "// inint eff: " << e.attribute("name");
177 if (!e.isNull() && e.attribute("type") == "keyframe") {
178 QString def = e.attribute("default");
179 // Effect has a keyframe type parameter, we need to set the values
180 if (e.attribute("keyframes").isEmpty()) {
181 e.setAttribute("keyframes", QString::number(m_cropStart.frames(m_fps)) + ':' + def + ';' + QString::number((m_cropStart + m_cropDuration).frames(m_fps)) + ':' + def);
182 //kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
188 if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
189 if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
190 int end = (duration() + cropStart()).frames(m_fps);
192 if (effect.attribute("id") == "fadeout") {
193 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
194 start -= EffectsList::parameter(effect, "in").toInt();
196 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
197 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
199 } else if (effect.attribute("id") == "fade_to_black") {
200 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
201 start -= EffectsList::parameter(effect, "in").toInt();
203 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
204 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
207 EffectsList::setParameter(effect, "in", QString::number(start));
208 EffectsList::setParameter(effect, "out", QString::number(end));
209 } else if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
210 int start = cropStart().frames(m_fps);
212 if (effect.attribute("id") == "fadein") {
213 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1)
214 end += EffectsList::parameter(effect, "out").toInt();
216 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fade_from_black"), "out").toInt();
217 } else if (effect.attribute("id") == "fade_from_black") {
218 if (m_effectList.hasEffect(QString(), "fadein") == -1)
219 end += EffectsList::parameter(effect, "out").toInt();
221 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fadein"), "out").toInt();
223 EffectsList::setParameter(effect, "in", QString::number(start));
224 EffectsList::setParameter(effect, "out", QString::number(end));
229 bool ClipItem::checkKeyFrames()
231 bool clipEffectsModified = false;
232 for (int ix = 0; ix < m_effectList.count(); ix ++) {
233 QString kfr = keyframes(ix);
234 if (!kfr.isEmpty()) {
235 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
236 QStringList newKeyFrames;
237 bool cutKeyFrame = false;
238 bool modified = false;
240 double lastValue = -1;
241 int start = m_cropStart.frames(m_fps);
242 int end = (m_cropStart + m_cropDuration).frames(m_fps);
243 foreach(const QString &str, keyframes) {
244 int pos = str.section(':', 0, 0).toInt();
245 double val = str.section(':', 1, 1).toDouble();
246 if (pos - start < 0) {
247 // a keyframe is defined before the start of the clip
249 } else if (cutKeyFrame) {
250 // create new keyframe at clip start, calculate interpolated value
252 int diff = pos - lastPos;
253 double ratio = (double)(start - lastPos) / diff;
254 double newValue = lastValue + (val - lastValue) * ratio;
255 newKeyFrames.append(QString::number(start) + ':' + QString::number(newValue));
262 // create new keyframe at clip end, calculate interpolated value
263 int diff = pos - lastPos;
265 double ratio = (double)(end - lastPos) / diff;
266 double newValue = lastValue + (val - lastValue) * ratio;
267 newKeyFrames.append(QString::number(end) + ':' + QString::number(newValue));
272 newKeyFrames.append(QString::number(pos) + ':' + QString::number(val));
280 setKeyframes(ix, newKeyFrames.join(";"));
281 clipEffectsModified = true;
285 return clipEffectsModified;
288 void ClipItem::setKeyframes(const int ix, const QString keyframes)
290 QDomElement effect = effectAt(ix);
291 if (effect.attribute("disabled") == "1") return;
292 QDomNodeList params = effect.elementsByTagName("parameter");
293 for (int i = 0; i < params.count(); i++) {
294 QDomElement e = params.item(i).toElement();
295 if (!e.isNull() && e.attribute("type") == "keyframe") {
296 e.setAttribute("keyframes", keyframes);
297 if (ix == m_selectedEffect) {
299 double max = e.attribute("max").toDouble();
300 double min = e.attribute("min").toDouble();
301 m_keyframeFactor = 100.0 / (max - min);
302 m_keyframeDefault = e.attribute("default").toDouble();
304 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
305 foreach(const QString &str, keyframes) {
306 int pos = str.section(':', 0, 0).toInt();
307 double val = str.section(':', 1, 1).toDouble();
308 m_keyframes[pos] = val;
319 void ClipItem::setSelectedEffect(const int ix)
321 m_selectedEffect = ix;
322 QDomElement effect = effectAt(m_selectedEffect);
323 QDomNodeList params = effect.elementsByTagName("parameter");
324 if (effect.attribute("disabled") != "1")
325 for (int i = 0; i < params.count(); i++) {
326 QDomElement e = params.item(i).toElement();
327 if (!e.isNull() && e.attribute("type") == "keyframe") {
329 double max = e.attribute("max").toDouble();
330 double min = e.attribute("min").toDouble();
331 m_keyframeFactor = 100.0 / (max - min);
332 m_keyframeDefault = e.attribute("default").toDouble();
334 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
335 foreach(const QString &str, keyframes) {
336 int pos = str.section(':', 0, 0).toInt();
337 double val = str.section(':', 1, 1).toDouble();
338 m_keyframes[pos] = val;
344 if (!m_keyframes.isEmpty()) {
350 QString ClipItem::keyframes(const int index)
353 QDomElement effect = effectAt(index);
354 QDomNodeList params = effect.elementsByTagName("parameter");
356 for (int i = 0; i < params.count(); i++) {
357 QDomElement e = params.item(i).toElement();
358 if (!e.isNull() && e.attribute("type") == "keyframe") {
359 result = e.attribute("keyframes");
366 void ClipItem::updateKeyframeEffect()
368 // regenerate xml parameter from the clip keyframes
369 QDomElement effect = effectAt(m_selectedEffect);
370 if (effect.attribute("disabled") == "1") return;
371 QDomNodeList params = effect.elementsByTagName("parameter");
373 for (int i = 0; i < params.count(); i++) {
374 QDomElement e = params.item(i).toElement();
375 if (!e.isNull() && e.attribute("type") == "keyframe") {
377 if (m_keyframes.count() > 1) {
378 QMap<int, double>::const_iterator i = m_keyframes.constBegin();
379 while (i != m_keyframes.constEnd()) {
380 keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
384 // Effect has a keyframe type parameter, we need to set the values
385 //kDebug() << "::::::::::::::: SETTING EFFECT KEYFRAMES: " << keyframes;
386 e.setAttribute("keyframes", keyframes);
392 QDomElement ClipItem::selectedEffect()
394 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
395 return effectAt(m_selectedEffect);
398 void ClipItem::resetThumbs()
400 m_startPix = QPixmap();
401 m_endPix = QPixmap();
403 audioThumbCachePic.clear();
407 void ClipItem::refreshClip()
409 m_maxDuration = m_clip->maxDuration();
410 if (m_clipType == COLOR) {
411 QString colour = m_clip->getProperty("colour");
412 colour = colour.replace(0, 2, "#");
413 setBrush(QColor(colour.left(7)));
414 } else slotFetchThumbs();
417 void ClipItem::slotFetchThumbs()
419 if (m_endPix.isNull() && m_startPix.isNull()) {
420 m_startThumbRequested = true;
421 m_endThumbRequested = true;
422 emit getThumb((int)cropStart().frames(m_fps), (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
424 if (m_endPix.isNull()) {
427 if (m_startPix.isNull()) {
433 if (m_endPix.isNull() && m_startPix.isNull()) {
434 int frame1 = (int)m_cropStart.frames(m_fps);
435 int frame2 = (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1;
436 //videoThumbProducer.setThumbFrames(m_clip->producer(), frame1, frame2);
437 //videoThumbProducer.start(QThread::LowestPriority);
439 if (m_endPix.isNull()) slotGetEndThumb();
440 else slotGetStartThumb();
443 } else if (m_startPix.isNull()) slotGetStartThumb();*/
446 void ClipItem::slotGetStartThumb()
448 m_startThumbRequested = true;
449 emit getThumb((int)cropStart().frames(m_fps), -1);
450 //videoThumbProducer.setThumbFrames(m_clip->producer(), (int)m_cropStart.frames(m_fps), - 1);
451 //videoThumbProducer.start(QThread::LowestPriority);
454 void ClipItem::slotGetEndThumb()
456 m_endThumbRequested = true;
457 emit getThumb(-1, (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
458 //videoThumbProducer.setThumbFrames(m_clip->producer(), -1, (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1);
459 //videoThumbProducer.start(QThread::LowestPriority);
463 void ClipItem::slotSetStartThumb(QImage img)
465 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
466 QPixmap pix = QPixmap::fromImage(img);
468 QRectF r = sceneBoundingRect();
469 r.setRight(pix.width() + 2);
474 void ClipItem::slotSetEndThumb(QImage img)
476 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
477 QPixmap pix = QPixmap::fromImage(img);
479 QRectF r = sceneBoundingRect();
480 r.setLeft(r.right() - pix.width() - 2);
485 void ClipItem::slotThumbReady(int frame, QPixmap pix)
487 if (scene() == NULL) return;
488 QRectF r = sceneBoundingRect();
489 double width = m_startPix.width() / projectScene()->scale();
490 if (m_startThumbRequested && frame == cropStart().frames(m_fps)) {
492 m_startThumbRequested = false;
493 double height = r.height();
494 update(r.x(), r.y(), width, height);
495 } else if (m_endThumbRequested && frame == (cropStart() + cropDuration()).frames(m_fps) - 1) {
497 m_endThumbRequested = false;
498 double height = r.height();
499 update(r.right() - width, r.y(), width, height);
503 void ClipItem::slotSetStartThumb(const QPixmap pix)
508 void ClipItem::slotSetEndThumb(const QPixmap pix)
513 QPixmap ClipItem::startThumb() const
518 QPixmap ClipItem::endThumb() const
523 void ClipItem::slotGotAudioData()
525 audioThumbReady = true;
526 if (m_clipType == AV && !isAudioOnly()) {
527 QRectF r = boundingRect();
528 r.setTop(r.top() + r.height() / 2 - 1);
533 int ClipItem::type() const
538 DocClipBase *ClipItem::baseClip() const
543 QDomElement ClipItem::xml() const
545 QDomElement xml = m_clip->toXML();
546 if (m_speed != 1.0) xml.setAttribute("speed", m_speed);
550 int ClipItem::clipType() const
555 QString ClipItem::clipName() const
560 void ClipItem::setClipName(const QString &name)
565 const QString &ClipItem::clipProducer() const
570 void ClipItem::flashClip()
572 if (m_timeLine == 0) {
573 m_timeLine = new QTimeLine(750, this);
574 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
575 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
580 void ClipItem::animate(qreal /*value*/)
582 QRectF r = boundingRect();
588 void ClipItem::paint(QPainter *painter,
589 const QStyleOptionGraphicsItem *option,
592 /*if (parentItem()) m_opacity = 0.5;
593 else m_opacity = 1.0;
594 painter->setOpacity(m_opacity);*/
596 if (parentItem()) paintColor = QColor(255, 248, 149);
597 else paintColor = brush().color();
598 if (isSelected() || (parentItem() && parentItem()->isSelected())) paintColor = paintColor.darker();
600 QRectF exposed = option->exposedRect;
601 QRectF mapped = painter->matrix().mapRect(br);
603 const double itemWidth = br.width();
604 const double itemHeight = br.height();
605 const double scale = option->matrix.m11();
606 const qreal xoffset = pen().widthF() / scale;
608 //painter->setRenderHints(QPainter::Antialiasing);
610 //QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
611 painter->setClipRect(exposed);
613 //Fill clip rectangle
615 bgRect.setLeft(br.left() + xoffset);
616 painter->fillRect(bgRect, paintColor);
618 //painter->setClipPath(resultClipPath, Qt::IntersectClip);
621 painter->setMatrixEnabled(false);
623 if (KdenliveSettings::videothumbnails() && !isAudioOnly()) {
624 QPen pen = painter->pen();
625 pen.setColor(QColor(255, 255, 255, 150));
626 painter->setPen(pen);
627 if (m_clipType == IMAGE && !m_startPix.isNull()) {
628 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_startPix.width(), 0);
629 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_startPix.width(), 0);
630 painter->drawPixmap(p1, m_startPix);
632 painter->drawLine(l);
633 } else if (!m_endPix.isNull()) {
634 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_endPix.width(), 0);
635 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_endPix.width(), 0);
636 painter->drawPixmap(p1, m_endPix);
638 painter->drawLine(l);
640 if (!m_startPix.isNull()) {
641 QPointF p1 = painter->matrix().map(QPointF(0, 0)) + QPointF(1.0, 0);
642 QPointF p2 = painter->matrix().map(QPointF(0, itemHeight)) + QPointF(1.0, 0);
643 painter->drawPixmap(p1, m_startPix);
644 QLineF l2(p1.x() + m_startPix.width(), p1.y(), p2.x() + m_startPix.width(), p2.y());
645 painter->drawLine(l2);
647 painter->setPen(Qt::black);
650 // draw audio thumbnails
651 if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (itemHeight / 2) || isAudioOnly())) || m_clipType == AUDIO) && audioThumbReady) {
653 double startpixel = exposed.left();
656 double endpixel = exposed.right();
659 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
661 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
663 if (m_clipType == AV && !isAudioOnly()) {
665 re.setTop(re.y() + re.height() / 2);
666 mappedRect = painter->matrix().mapRect(re);
667 //painter->fillRect(mappedRect, QBrush(QColor(200, 200, 200, 140)));
668 } else mappedRect = mapped;
670 int channels = baseClip()->getProperty("channels").toInt();
671 if (scale != framePixelWidth)
672 audioThumbCachePic.clear();
673 double cropLeft = m_cropStart.frames(m_fps);
674 const int clipStart = mappedRect.x();
675 const int mappedStartPixel = painter->matrix().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
676 const int mappedEndPixel = painter->matrix().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
677 cropLeft = cropLeft * scale;
680 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
683 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
684 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
685 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), audioThumbCachePic[startCache]);
690 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
691 QList < CommentedTime >::Iterator it = markers.begin();
695 markerBrush = QBrush(QColor(120, 120, 0, 140));
696 QPen pen = painter->pen();
697 pen.setColor(QColor(255, 255, 255, 200));
698 pen.setStyle(Qt::DotLine);
699 painter->setPen(pen);
700 for (; it != markers.end(); ++it) {
701 pos = (*it).time() - cropStart();
702 if (pos > GenTime()) {
703 if (pos > duration()) break;
704 QLineF l(br.x() + pos.frames(m_fps), br.y() + 5, br.x() + pos.frames(m_fps), br.bottom() - 5);
705 QLineF l2 = painter->matrix().map(l);
706 //framepos = scale * pos.frames(m_fps);
707 //QLineF l(framepos, 5, framepos, itemHeight - 5);
708 painter->drawLine(l2);
709 if (KdenliveSettings::showmarkers()) {
710 framepos = br.x() + pos.frames(m_fps);
711 const QRectF r1(framepos + 0.04, 10, itemWidth - framepos - 2, itemHeight - 10);
712 const QRectF r2 = painter->matrix().mapRect(r1);
713 const QRectF txtBounding = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, ' ' + (*it).comment() + ' ');
714 painter->setBrush(markerBrush);
715 painter->setPen(Qt::NoPen);
716 painter->drawRoundedRect(txtBounding, 3, 3);
717 painter->setPen(Qt::white);
718 painter->drawText(txtBounding, Qt::AlignCenter, (*it).comment());
720 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
723 pen.setColor(Qt::black);
724 pen.setStyle(Qt::SolidLine);
725 painter->setPen(pen);
727 // draw start / end fades
730 fades = QBrush(QColor(200, 50, 50, 150));
731 } else fades = QBrush(QColor(200, 200, 200, 200));
733 if (m_startFade != 0) {
734 QPainterPath fadeInPath;
735 fadeInPath.moveTo(0, 0);
736 fadeInPath.lineTo(0, itemHeight);
737 fadeInPath.lineTo(m_startFade, 0);
738 fadeInPath.closeSubpath();
739 QPainterPath f1 = painter->matrix().map(fadeInPath);
740 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
741 /*if (isSelected()) {
742 QLineF l(m_startFade * scale, 0, 0, itemHeight);
743 painter->drawLine(l);
746 if (m_endFade != 0) {
747 QPainterPath fadeOutPath;
748 fadeOutPath.moveTo(itemWidth, 0);
749 fadeOutPath.lineTo(itemWidth, itemHeight);
750 fadeOutPath.lineTo(itemWidth - m_endFade, 0);
751 fadeOutPath.closeSubpath();
752 QPainterPath f1 = painter->matrix().map(fadeOutPath);
753 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
754 /*if (isSelected()) {
755 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
756 painter->drawLine(l);
760 // Draw effects names
761 if (!m_effectNames.isEmpty() && itemWidth * scale > 40) {
762 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
763 txtBounding.setRight(txtBounding.right() + 15);
764 painter->setPen(Qt::white);
765 QBrush markerBrush(Qt::SolidPattern);
766 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
767 qreal value = m_timeLine->currentValue();
768 txtBounding.setWidth(txtBounding.width() * value);
769 markerBrush.setColor(QColor(50 + 200 * (1.0 - value), 50, 50, 100 + 50 * value));
770 } else markerBrush.setColor(QColor(50, 50, 50, 150));
771 painter->setBrush(markerBrush);
772 painter->setPen(Qt::NoPen);
773 painter->drawRoundedRect(txtBounding, 3, 3);
774 painter->setPen(Qt::white);
775 painter->drawText(txtBounding, Qt::AlignCenter, m_effectNames);
776 painter->setPen(Qt::black);
780 // draw frame around clip
781 QColor frameColor(Qt::black);
783 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
784 frameColor = QColor(Qt::red);
787 frameColor.setAlpha(150);
788 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignHCenter | Qt::AlignVCenter, ' ' + m_clipName + ' ');
789 painter->fillRect(txtBounding, frameColor);
790 //painter->setPen(QColor(0, 0, 0, 180));
791 //painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
793 painter->drawPixmap(txtBounding.topLeft() - QPointF(17, -1), m_videoPix);
794 } else if (m_audioOnly) {
795 painter->drawPixmap(txtBounding.topLeft() - QPointF(17, -1), m_audioPix);
797 txtBounding.translate(QPointF(1, 1));
798 painter->setPen(QColor(255, 255, 255, 255));
799 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
802 // draw transition handles on hover
803 if (m_hover && itemWidth * scale > 40) {
804 QPointF p1 = painter->matrix().map(QPointF(0, itemHeight / 2)) + QPointF(10, 0);
805 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
806 p1 = painter->matrix().map(QPointF(itemWidth, itemHeight / 2)) - QPointF(22, 0);
807 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
810 // draw effect or transition keyframes
811 if (itemWidth > 20) drawKeyFrames(painter, exposed);
813 painter->setMatrixEnabled(true);
816 // expand clip rect to allow correct painting of clip border
818 exposed.setRight(exposed.right() + xoffset + 0.5);
819 exposed.setBottom(exposed.bottom() + 1);
820 painter->setClipRect(exposed);
822 frameColor.setAlpha(alphaBase);
823 painter->setPen(frameColor);
824 QLineF line(br.left() + xoffset, br.top(), br.right() - xoffset, br.top());
825 painter->drawLine(line);
827 frameColor.setAlpha(alphaBase * 2);
828 painter->setPen(frameColor);
829 line.setLine(br.right(), br.top() + 1.0, br.right(), br.bottom() - 1.0);
830 painter->drawLine(line);
831 line.setLine(br.right() - xoffset, br.bottom(), br.left() + xoffset, br.bottom());
832 painter->drawLine(line);
833 line.setLine(br.left(), br.bottom() - 1.0, br.left(), br.top() + 1.0);
834 painter->drawLine(line);
836 painter->setPen(QColor(255, 255, 255, 60));
837 line.setLine(br.right() - xoffset, br.bottom() - 1.0, br.left() + xoffset, br.bottom() - 1.0);
838 painter->drawLine(line);
839 //painter->drawRect(br);
843 OPERATIONTYPE ClipItem::operationMode(QPointF pos)
845 if (isItemLocked()) return NONE;
848 m_editedKeyframe = mouseOverKeyFrames(pos);
849 if (m_editedKeyframe != -1) return KEYFRAME;
851 QRectF rect = sceneBoundingRect();
852 const double scale = projectScene()->scale();
853 double maximumOffset = 6 / scale;
855 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
856 if (m_startFade == 0) setToolTip(i18n("Add audio fade"));
857 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_startFade, m_fps).seconds()));
859 } else if (pos.x() - rect.x() < maximumOffset) {
860 setToolTip(i18n("Crop from start: %1s", cropStart().seconds()));
862 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
863 if (m_endFade == 0) setToolTip(i18n("Add audio fade"));
864 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_endFade, m_fps).seconds()));
866 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width()))) < maximumOffset) {
867 setToolTip(i18n("Clip duration: %1s", duration().seconds()));
869 } else if (qAbs((int)(pos.x() - (rect.x() + 16 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
870 setToolTip(i18n("Add transition"));
871 return TRANSITIONSTART;
872 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - 21 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
873 setToolTip(i18n("Add transition"));
874 return TRANSITIONEND;
876 setToolTip(QString());
880 QList <GenTime> ClipItem::snapMarkers() const
882 QList < GenTime > snaps;
883 QList < GenTime > markers = baseClip()->snapMarkers();
886 for (int i = 0; i < markers.size(); i++) {
887 pos = markers.at(i) - cropStart();
888 if (pos > GenTime()) {
889 if (pos > duration()) break;
890 else snaps.append(pos + startPos());
896 QList <CommentedTime> ClipItem::commentedSnapMarkers() const
898 QList < CommentedTime > snaps;
899 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
902 for (int i = 0; i < markers.size(); i++) {
903 pos = markers.at(i).time() - cropStart();
904 if (pos > GenTime()) {
905 if (pos > duration()) break;
906 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
912 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels)
914 QRectF re = sceneBoundingRect();
915 if (m_clipType == AV && !isAudioOnly()) re.setTop(re.y() + re.height() / 2);
917 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
918 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
920 for (int startCache = startpixel - startpixel % 100;startCache < endpixel;startCache += 100) {
921 //kDebug() << "creating " << startCache;
922 //if (framePixelWidth!=pixelForOneFrame ||
923 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
925 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
926 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
927 audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
929 bool fullAreaDraw = pixelForOneFrame < 10;
930 QMap<int, QPainterPath > positiveChannelPaths;
931 QMap<int, QPainterPath > negativeChannelPaths;
932 QPainter pixpainter(&audioThumbCachePic[startCache]);
934 audiopen.setWidth(0);
935 pixpainter.setPen(audiopen);
936 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
937 //pixpainter.drawLine(0,0,100,re.height());
938 // Bail out, if caller provided invalid data
940 kWarning() << "Unable to draw image with " << channels << "number of channels";
944 int channelHeight = audioThumbCachePic[startCache].height() / channels;
946 for (int i = 0;i < channels;i++) {
948 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
949 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
952 for (int samples = 0;samples <= 100;samples++) {
953 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
954 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
955 if (frame < 0 || sample < 0 || sample > 19)
957 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
959 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
961 int y = channelHeight * channel + channelHeight / 2;
962 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
964 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
965 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
967 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
968 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
971 for (int channel = 0;channel < channels ;channel++)
972 if (fullAreaDraw && samples == 100) {
973 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
974 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
975 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
976 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
980 pixpainter.setPen(QPen(QColor(0, 0, 0)));
981 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
983 for (int i = 0;i < channels;i++) {
985 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
986 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
988 pixpainter.drawPath(positiveChannelPaths[i]);
991 //audioThumbWasDrawn=true;
992 framePixelWidth = pixelForOneFrame;
997 uint ClipItem::fadeIn() const
1002 uint ClipItem::fadeOut() const
1008 void ClipItem::setFadeIn(int pos)
1010 if (pos == m_startFade) return;
1011 int oldIn = m_startFade;
1012 if (pos < 0) pos = 0;
1013 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
1015 QRectF rect = boundingRect();
1016 update(rect.x(), rect.y(), qMax(oldIn, pos), rect.height());
1019 void ClipItem::setFadeOut(int pos)
1021 if (pos == m_endFade) return;
1022 int oldOut = m_endFade;
1023 if (pos < 0) pos = 0;
1024 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
1026 QRectF rect = boundingRect();
1027 update(rect.x() + rect.width() - qMax(oldOut, pos), rect.y(), qMax(oldOut, pos), rect.height());
1032 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event)
1034 /*m_resizeMode = operationMode(event->pos());
1035 if (m_resizeMode == MOVE) {
1036 m_maxTrack = scene()->sceneRect().height();
1037 m_grabPoint = (int) (event->pos().x() - rect().x());
1039 QGraphicsRectItem::mousePressEvent(event);
1043 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
1045 m_resizeMode = NONE;
1046 QGraphicsRectItem::mouseReleaseEvent(event);
1050 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent */*e*/)
1052 //if (e->pos().x() < 20) m_hover = true;
1053 if (isItemLocked()) return;
1055 QRectF r = boundingRect();
1056 double width = 35 / projectScene()->scale();
1057 double height = r.height() / 2;
1058 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1059 update(r.x(), r.y() + height, width, height);
1060 update(r.right() - width, r.y() + height, width, height);
1064 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
1066 if (isItemLocked()) return;
1068 QRectF r = boundingRect();
1069 double width = 35 / projectScene()->scale();
1070 double height = r.height() / 2;
1071 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1072 update(r.x(), r.y() + height, width, height);
1073 update(r.right() - width, r.y() + height, width, height);
1076 void ClipItem::resizeStart(int posx, double /*speed*/)
1078 const int min = (startPos() - cropStart()).frames(m_fps);
1079 if (posx < min) posx = min;
1080 if (posx == startPos().frames(m_fps)) return;
1081 const int previous = cropStart().frames(m_fps);
1082 AbstractClipItem::resizeStart(posx, m_speed);
1083 if ((int) cropStart().frames(m_fps) != previous) {
1084 checkEffectsKeyframesPos(previous, cropStart().frames(m_fps), true);
1085 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1086 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
1087 startThumbTimer->start(150);
1092 void ClipItem::resizeEnd(int posx, double /*speed*/, bool updateKeyFrames)
1094 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps) + 1;
1095 if (posx > max) posx = max;
1096 if (posx == endPos().frames(m_fps)) return;
1097 //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
1098 const int previous = (cropStart() + duration()).frames(m_fps);
1099 AbstractClipItem::resizeEnd(posx, m_speed);
1100 if ((int)(cropStart() + duration()).frames(m_fps) != previous) {
1101 if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false);
1102 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1103 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
1104 endThumbTimer->start(150);
1110 void ClipItem::checkEffectsKeyframesPos(const int previous, const int current, bool fromStart)
1112 for (int i = 0; i < m_effectList.size(); i++) {
1113 QDomElement effect = m_effectList.at(i);
1114 QDomNodeList params = effect.elementsByTagName("parameter");
1115 for (int j = 0; j < params.count(); j++) {
1116 QDomElement e = params.item(i).toElement();
1117 if (e.attribute("type") == "keyframe") {
1118 // parse keyframes and adjust values
1119 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1120 QMap <int, double> kfr;
1123 foreach(const QString &str, keyframes) {
1124 pos = str.section(':', 0, 0).toInt();
1125 val = str.section(':', 1, 1).toDouble();
1126 if (pos == previous) kfr[current] = val;
1128 if (fromStart && pos >= current) kfr[pos] = val;
1129 else if (!fromStart && pos <= current) kfr[pos] = val;
1133 QMap<int, double>::const_iterator k = kfr.constBegin();
1134 while (k != kfr.constEnd()) {
1135 newkfr.append(QString::number(k.key()) + ':' + QString::number(k.value()) + ';');
1138 e.setAttribute("keyframes", newkfr);
1143 if (m_selectedEffect >= 0) setSelectedEffect(m_selectedEffect);
1147 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
1149 if (change == ItemPositionChange && scene()) {
1150 // calculate new position.
1151 //if (parentItem()) return pos();
1152 QPointF newPos = value.toPointF();
1153 //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1154 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1155 xpos = qMax(xpos, 0);
1157 int newTrack = newPos.y() / KdenliveSettings::trackheight();
1158 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1159 newTrack = qMax(newTrack, 0);
1160 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1161 // Only one clip is moving
1162 QRectF sceneShape = rect();
1163 sceneShape.translate(newPos);
1164 QList<QGraphicsItem*> items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1165 items.removeAll(this);
1166 bool forwardMove = newPos.x() > pos().x();
1168 if (!items.isEmpty()) {
1169 for (int i = 0; i < items.count(); i++) {
1170 if (items.at(i)->type() == type()) {
1172 QPointF otherPos = items.at(i)->pos();
1173 if ((int) otherPos.y() != (int) pos().y()) {
1177 offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps)));
1179 offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
1184 sceneShape.translate(QPointF(-offset, 0));
1185 newPos.setX(newPos.x() - offset);
1187 sceneShape.translate(QPointF(offset, 0));
1188 newPos.setX(newPos.x() + offset);
1190 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1191 subitems.removeAll(this);
1192 for (int j = 0; j < subitems.count(); j++) {
1193 if (subitems.at(j)->type() == type()) {
1194 m_startPos = GenTime((int) pos().x(), m_fps);
1201 m_startPos = GenTime((int) newPos.x(), m_fps);
1207 m_startPos = GenTime((int) newPos.x(), m_fps);
1208 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1211 return QGraphicsItem::itemChange(change, value);
1215 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1218 int ClipItem::effectsCounter()
1220 return effectsCount() + 1;
1223 int ClipItem::effectsCount()
1225 return m_effectList.size();
1228 int ClipItem::hasEffect(const QString &tag, const QString &id) const
1230 return m_effectList.hasEffect(tag, id);
1233 QStringList ClipItem::effectNames()
1235 return m_effectList.effectNames();
1238 QDomElement ClipItem::effectAt(int ix)
1240 if (ix > m_effectList.count() - 1 || ix < 0) return QDomElement();
1241 return m_effectList.at(ix);
1244 void ClipItem::setEffectAt(int ix, QDomElement effect)
1246 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1247 effect.setAttribute("kdenlive_ix", ix + 1);
1248 m_effectList.insert(ix, effect);
1249 m_effectList.removeAt(ix + 1);
1250 m_effectNames = m_effectList.effectNames().join(" / ");
1251 QString id = effect.attribute("id");
1252 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1253 update(boundingRect());
1255 QRectF r = boundingRect();
1261 EffectsParameterList ClipItem::addEffect(QDomElement effect, bool animate)
1264 bool needRepaint = false;
1266 doc.appendChild(doc.importNode(effect, true));
1267 kDebug() << "/////// CLIPÂ ADD EFFECT: " << doc.toString();*/
1268 m_effectList.append(effect);
1270 EffectsParameterList parameters;
1271 parameters.addParam("tag", effect.attribute("tag"));
1272 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1273 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1275 QString state = effect.attribute("disabled");
1276 if (!state.isEmpty()) {
1277 parameters.addParam("disabled", state);
1280 QString effectId = effect.attribute("id");
1281 if (effectId.isEmpty()) effectId = effect.attribute("tag");
1282 parameters.addParam("id", effectId);
1284 QDomNodeList params = effect.elementsByTagName("parameter");
1286 for (int i = 0; i < params.count(); i++) {
1287 QDomElement e = params.item(i).toElement();
1289 if (e.attribute("type") == "keyframe") {
1290 parameters.addParam("keyframes", e.attribute("keyframes"));
1291 parameters.addParam("max", e.attribute("max"));
1292 parameters.addParam("min", e.attribute("min"));
1293 parameters.addParam("factor", e.attribute("factor", "1"));
1294 parameters.addParam("starttag", e.attribute("starttag", "start"));
1295 parameters.addParam("endtag", e.attribute("endtag", "end"));
1298 double f = e.attribute("factor", "1").toDouble();
1301 parameters.addParam(e.attribute("name"), e.attribute("value"));
1303 // check if it is a fade effect
1304 if (effectId == "fadein") {
1306 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
1307 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1308 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1310 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
1311 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1312 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1314 } else if (effectId == "fade_from_black") {
1316 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
1317 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1318 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1320 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
1321 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1322 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1324 } else if (effectId == "fadeout") {
1326 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
1327 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1328 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1330 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
1331 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1332 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1334 } else if (effectId == "fade_to_black") {
1336 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
1337 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1338 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1340 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
1341 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1342 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1346 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / f));
1350 m_effectNames = m_effectList.effectNames().join(" / ");
1351 if (fade > 0) m_startFade = fade;
1352 else if (fade < 0) m_endFade = -fade;
1353 if (needRepaint) update(boundingRect());
1356 } else if (!needRepaint) {
1357 QRectF r = boundingRect();
1361 if (m_selectedEffect == -1) {
1362 m_selectedEffect = 0;
1363 setSelectedEffect(m_selectedEffect);
1368 EffectsParameterList ClipItem::getEffectArgs(QDomElement effect)
1370 EffectsParameterList parameters;
1371 parameters.addParam("tag", effect.attribute("tag"));
1372 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1373 parameters.addParam("id", effect.attribute("id"));
1374 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1375 QString state = effect.attribute("disabled");
1376 if (!state.isEmpty()) {
1377 parameters.addParam("disabled", state);
1380 QDomNodeList params = effect.elementsByTagName("parameter");
1381 for (int i = 0; i < params.count(); i++) {
1382 QDomElement e = params.item(i).toElement();
1383 //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
1384 if (e.attribute("type") == "keyframe") {
1385 kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
1386 parameters.addParam("keyframes", e.attribute("keyframes"));
1387 parameters.addParam("max", e.attribute("max"));
1388 parameters.addParam("min", e.attribute("min"));
1389 parameters.addParam("factor", e.attribute("factor", "1"));
1390 parameters.addParam("starttag", e.attribute("starttag", "start"));
1391 parameters.addParam("endtag", e.attribute("endtag", "end"));
1392 } else if (e.attribute("namedesc").contains(';')) {
1393 QString format = e.attribute("format");
1394 QStringList separators = format.split("%d", QString::SkipEmptyParts);
1395 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
1397 QTextStream txtNeu(&neu);
1398 if (values.size() > 0)
1399 txtNeu << (int)values[0].toDouble();
1400 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
1401 txtNeu << separators[i];
1402 txtNeu << (int)(values[i+1].toDouble());
1404 parameters.addParam("start", neu);
1406 if (e.attribute("factor", "1") != "1") {
1407 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / e.attribute("factor").toDouble()));
1409 parameters.addParam(e.attribute("name"), e.attribute("value"));
1416 void ClipItem::deleteEffect(QString index)
1418 bool needRepaint = false;
1421 for (int i = 0; i < m_effectList.size(); ++i) {
1422 ix = m_effectList.at(i).attribute("kdenlive_ix");
1424 QString effectId = m_effectList.at(i).attribute("id");
1425 if ((effectId == "fadein" && hasEffect(QString(), "fade_from_black") == -1) ||
1426 (effectId == "fade_from_black" && hasEffect(QString(), "fadein") == -1)) {
1429 } else if ((effectId == "fadeout" && hasEffect(QString(), "fade_to_black") == -1) ||
1430 (effectId == "fade_to_black" && hasEffect(QString(), "fadeout") == -1)) {
1434 m_effectList.removeAt(i);
1436 } else if (ix.toInt() > index.toInt()) {
1437 m_effectList[i].setAttribute("kdenlive_ix", ix.toInt() - 1);
1440 m_effectNames = m_effectList.effectNames().join(" / ");
1441 if (needRepaint) update(boundingRect());
1445 double ClipItem::speed() const
1450 void ClipItem::setSpeed(const double speed)
1453 if (m_speed == 1.0) m_clipName = baseClip()->name();
1454 else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + '%';
1458 GenTime ClipItem::maxDuration() const
1460 return m_maxDuration / m_speed;
1463 GenTime ClipItem::cropStart() const
1465 return m_cropStart / m_speed;
1468 GenTime ClipItem::cropDuration() const
1470 return m_cropDuration / m_speed;
1473 GenTime ClipItem::endPos() const
1475 return m_startPos + cropDuration();
1479 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
1481 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
1483 doc.setContent(effects, true);
1484 QDomElement e = doc.documentElement();
1485 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1486 if (view) view->slotAddEffect(e, m_startPos, track());
1490 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
1492 if (isItemLocked()) event->setAccepted(false);
1493 else event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
1496 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
1501 void ClipItem::addTransition(Transition* t)
1503 m_transitionsList.append(t);
1504 //CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1506 QDomElement e = doc.documentElement();
1507 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1510 void ClipItem::setVideoOnly(bool force)
1512 m_videoOnly = force;
1515 void ClipItem::setAudioOnly(bool force)
1517 m_audioOnly = force;
1518 if (m_audioOnly) setBrush(QColor(141, 215, 166));
1519 else setBrush(QColor(141, 166, 215));
1520 audioThumbCachePic.clear();
1523 bool ClipItem::isAudioOnly() const
1528 bool ClipItem::isVideoOnly() const
1536 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
1538 int pos = event->x();
1539 if (event->modifiers() == Qt::ControlModifier)
1540 setDragMode(QGraphicsView::ScrollHandDrag);
1541 else if (event->modifiers() == Qt::ShiftModifier)
1542 setDragMode(QGraphicsView::RubberBandDrag);
1544 QGraphicsItem * item = itemAt(event->pos());
1547 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
1550 QGraphicsView::mousePressEvent(event);
1553 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
1555 QGraphicsView::mouseReleaseEvent(event);
1556 setDragMode(QGraphicsView::NoDrag);
1560 #include "clipitem.moc"