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 m_startPix(QPixmap()),
49 m_startThumbTimer(NULL),
50 m_endThumbTimer(NULL),
53 m_startThumbRequested(false),
54 m_endThumbRequested(false),
60 setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double)(KdenliveSettings::trackheight() - 2));
61 setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1);
63 m_videoPix = KIcon("kdenlive-show-video").pixmap(QSize(16, 16));
64 m_audioPix = KIcon("kdenlive-show-audio").pixmap(QSize(16, 16));
66 if (m_speed == 1.0) m_clipName = clip->name();
68 m_clipName = clip->name() + " - " + QString::number(m_speed * 100, 'f', 0) + '%';
69 m_cropDuration = m_cropDuration * m_speed;
71 m_producer = clip->getId();
72 m_clipType = clip->clipType();
73 m_cropStart = info.cropStart;
74 m_maxDuration = clip->maxDuration();
76 m_audioThumbReady = clip->audioThumbCreated();
78 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
79 //setAcceptsHoverEvents(true);
80 connect(this , SIGNAL(prepareAudioThumb(double, int, int, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int)));
82 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
83 setBrush(QColor(141, 166, 215));
85 m_startThumbTimer = new QTimer(this);
86 m_startThumbTimer->setSingleShot(true);
87 connect(m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
88 m_endThumbTimer = new QTimer(this);
89 m_endThumbTimer->setSingleShot(true);
90 connect(m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
92 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
93 //connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(getVideoThumbs(int, int)));
95 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
96 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
97 if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs()));
99 /*if (m_clip->producer()) {
100 videoThumbProducer.init(this, m_clip->producer(), KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio(), KdenliveSettings::trackheight());
103 } else if (m_clipType == COLOR) {
104 QString colour = clip->getProperty("colour");
105 colour = colour.replace(0, 2, "#");
106 setBrush(QColor(colour.left(7)));
107 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
108 setBrush(QColor(141, 166, 215));
109 //m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
110 } else if (m_clipType == AUDIO) {
111 setBrush(QColor(141, 215, 166));
112 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
117 ClipItem::~ClipItem()
120 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
121 disconnect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
122 disconnect(m_clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
124 delete m_startThumbTimer;
125 delete m_endThumbTimer;
129 ClipItem *ClipItem::clone(ItemInfo info) const
131 ClipItem *duplicate = new ClipItem(m_clip, info, m_fps, m_speed);
132 if (m_clipType == IMAGE || m_clipType == TEXT) duplicate->slotSetStartThumb(m_startPix);
134 if (info.cropStart == m_cropStart) duplicate->slotSetStartThumb(m_startPix);
135 if (info.cropStart + (info.endPos - info.startPos) == m_cropStart + m_cropDuration) duplicate->slotSetEndThumb(m_endPix);
137 //kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
138 duplicate->setEffectList(m_effectList.clone());
139 duplicate->setVideoOnly(m_videoOnly);
140 duplicate->setAudioOnly(m_audioOnly);
141 //duplicate->setSpeed(m_speed);
145 void ClipItem::setEffectList(const EffectsList effectList)
147 m_effectList = effectList;
148 m_effectNames = m_effectList.effectNames().join(" / ");
149 if (!m_effectList.isEmpty()) setSelectedEffect(0);
152 const EffectsList ClipItem::effectList()
157 int ClipItem::selectedEffectIndex() const
159 return m_selectedEffect;
162 void ClipItem::initEffect(QDomElement effect)
164 // the kdenlive_ix int is used to identify an effect in mlt's playlist, should
166 if (effect.attribute("kdenlive_ix").toInt() == 0)
167 effect.setAttribute("kdenlive_ix", QString::number(effectsCounter()));
168 // init keyframes if required
169 QDomNodeList params = effect.elementsByTagName("parameter");
170 for (int i = 0; i < params.count(); i++) {
171 QDomElement e = params.item(i).toElement();
172 kDebug() << "// init eff: " << e.attribute("name");
173 if (!e.isNull() && e.attribute("type") == "keyframe") {
174 QString def = e.attribute("default");
175 // Effect has a keyframe type parameter, we need to set the values
176 if (e.attribute("keyframes").isEmpty()) {
177 e.setAttribute("keyframes", QString::number(cropStart().frames(m_fps)) + ':' + def + ';' + QString::number((cropStart() + cropDuration()).frames(m_fps)) + ':' + def);
178 //kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
183 if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
184 if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
185 int end = (cropDuration() + cropStart()).frames(m_fps);
187 if (effect.attribute("id") == "fadeout") {
188 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
189 int effectDuration = EffectsList::parameter(effect, "in").toInt();
190 if (effectDuration > cropDuration().frames(m_fps)) {
191 effectDuration = cropDuration().frames(m_fps) / 2;
193 start -= effectDuration;
195 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
196 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
198 } else if (effect.attribute("id") == "fade_to_black") {
199 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
200 int effectDuration = EffectsList::parameter(effect, "in").toInt();
201 if (effectDuration > cropDuration().frames(m_fps)) {
202 effectDuration = cropDuration().frames(m_fps) / 2;
204 start -= effectDuration;
206 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
207 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
210 EffectsList::setParameter(effect, "in", QString::number(start));
211 EffectsList::setParameter(effect, "out", QString::number(end));
212 } else if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
213 int start = cropStart().frames(m_fps);
215 if (effect.attribute("id") == "fadein") {
216 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
217 int effectDuration = EffectsList::parameter(effect, "out").toInt();
218 if (effectDuration > cropDuration().frames(m_fps)) {
219 effectDuration = cropDuration().frames(m_fps) / 2;
221 end += effectDuration;
223 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fade_from_black"), "out").toInt();
224 } else if (effect.attribute("id") == "fade_from_black") {
225 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
226 int effectDuration = EffectsList::parameter(effect, "out").toInt();
227 if (effectDuration > cropDuration().frames(m_fps)) {
228 effectDuration = cropDuration().frames(m_fps) / 2;
230 end += effectDuration;
232 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fadein"), "out").toInt();
234 EffectsList::setParameter(effect, "in", QString::number(start));
235 EffectsList::setParameter(effect, "out", QString::number(end));
240 bool ClipItem::checkKeyFrames()
242 bool clipEffectsModified = false;
243 for (int ix = 0; ix < m_effectList.count(); ix ++) {
244 QString kfr = keyframes(ix);
245 if (!kfr.isEmpty()) {
246 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
247 QStringList newKeyFrames;
248 bool cutKeyFrame = false;
249 bool modified = false;
251 double lastValue = -1;
252 int start = m_cropStart.frames(m_fps);
253 int end = (m_cropStart + m_cropDuration).frames(m_fps);
254 foreach(const QString &str, keyframes) {
255 int pos = str.section(':', 0, 0).toInt();
256 double val = str.section(':', 1, 1).toDouble();
257 if (pos - start < 0) {
258 // a keyframe is defined before the start of the clip
260 } else if (cutKeyFrame) {
261 // create new keyframe at clip start, calculate interpolated value
263 int diff = pos - lastPos;
264 double ratio = (double)(start - lastPos) / diff;
265 double newValue = lastValue + (val - lastValue) * ratio;
266 newKeyFrames.append(QString::number(start) + ':' + QString::number(newValue));
273 // create new keyframe at clip end, calculate interpolated value
274 int diff = pos - lastPos;
276 double ratio = (double)(end - lastPos) / diff;
277 double newValue = lastValue + (val - lastValue) * ratio;
278 newKeyFrames.append(QString::number(end) + ':' + QString::number(newValue));
283 newKeyFrames.append(QString::number(pos) + ':' + QString::number(val));
291 setKeyframes(ix, newKeyFrames.join(";"));
292 clipEffectsModified = true;
296 return clipEffectsModified;
299 void ClipItem::setKeyframes(const int ix, const QString keyframes)
301 QDomElement effect = effectAt(ix);
302 if (effect.attribute("disabled") == "1") return;
303 QDomNodeList params = effect.elementsByTagName("parameter");
304 for (int i = 0; i < params.count(); i++) {
305 QDomElement e = params.item(i).toElement();
306 if (!e.isNull() && e.attribute("type") == "keyframe") {
307 e.setAttribute("keyframes", keyframes);
308 if (ix == m_selectedEffect) {
310 double max = e.attribute("max").toDouble();
311 double min = e.attribute("min").toDouble();
312 m_keyframeFactor = 100.0 / (max - min);
313 m_keyframeDefault = e.attribute("default").toDouble();
315 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
316 foreach(const QString &str, keyframes) {
317 int pos = str.section(':', 0, 0).toInt();
318 double val = str.section(':', 1, 1).toDouble();
319 m_keyframes[pos] = val;
330 void ClipItem::setSelectedEffect(const int ix)
332 m_selectedEffect = ix;
333 QDomElement effect = effectAt(m_selectedEffect);
334 if (effect.isNull() == false) {
335 QDomNodeList params = effect.elementsByTagName("parameter");
336 if (effect.attribute("disabled") != "1")
337 for (int i = 0; i < params.count(); i++) {
338 QDomElement e = params.item(i).toElement();
339 if (!e.isNull() && e.attribute("type") == "keyframe") {
341 double max = e.attribute("max").toDouble();
342 double min = e.attribute("min").toDouble();
343 m_keyframeFactor = 100.0 / (max - min);
344 m_keyframeDefault = e.attribute("default").toDouble();
346 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
347 foreach(const QString &str, keyframes) {
348 int pos = str.section(':', 0, 0).toInt();
349 double val = str.section(':', 1, 1).toDouble();
350 m_keyframes[pos] = val;
357 if (!m_keyframes.isEmpty()) {
363 QString ClipItem::keyframes(const int index)
366 QDomElement effect = effectAt(index);
367 QDomNodeList params = effect.elementsByTagName("parameter");
369 for (int i = 0; i < params.count(); i++) {
370 QDomElement e = params.item(i).toElement();
371 if (!e.isNull() && e.attribute("type") == "keyframe") {
372 result = e.attribute("keyframes");
379 void ClipItem::updateKeyframeEffect()
381 // regenerate xml parameter from the clip keyframes
382 QDomElement effect = effectAt(m_selectedEffect);
383 if (effect.attribute("disabled") == "1") return;
384 QDomNodeList params = effect.elementsByTagName("parameter");
386 for (int i = 0; i < params.count(); i++) {
387 QDomElement e = params.item(i).toElement();
388 if (!e.isNull() && e.attribute("type") == "keyframe") {
390 if (m_keyframes.count() > 1) {
391 QMap<int, double>::const_iterator i = m_keyframes.constBegin();
392 while (i != m_keyframes.constEnd()) {
393 keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
397 // Effect has a keyframe type parameter, we need to set the values
398 //kDebug() << "::::::::::::::: SETTING EFFECT KEYFRAMES: " << keyframes;
399 e.setAttribute("keyframes", keyframes);
405 QDomElement ClipItem::selectedEffect()
407 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
408 return effectAt(m_selectedEffect);
411 void ClipItem::resetThumbs(bool clearExistingThumbs)
413 if (clearExistingThumbs) {
414 m_startPix = QPixmap();
415 m_endPix = QPixmap();
416 m_audioThumbCachePic.clear();
422 void ClipItem::refreshClip(bool checkDuration)
424 if (checkDuration && (m_maxDuration != m_clip->maxDuration())) {
425 m_maxDuration = m_clip->maxDuration();
426 if (m_clipType != IMAGE && m_clipType != TEXT && m_clipType != COLOR) {
427 if (m_maxDuration != GenTime() && m_cropStart + m_cropDuration > m_maxDuration) {
428 // Clip duration changed, make sure to stay in correct range
429 if (m_cropStart > m_maxDuration) {
430 m_cropStart = GenTime();
431 m_cropDuration = qMin(m_cropDuration, m_maxDuration);
432 updateRectGeometry();
434 m_cropDuration = m_maxDuration;
435 updateRectGeometry();
440 if (m_clipType == COLOR) {
441 QString colour = m_clip->getProperty("colour");
442 colour = colour.replace(0, 2, "#");
443 setBrush(QColor(colour.left(7)));
444 } else resetThumbs(checkDuration);
447 void ClipItem::slotFetchThumbs()
449 if (m_clipType == IMAGE || m_clipType == TEXT) {
450 if (m_startPix.isNull()) {
451 m_startPix = KThumb::getImage(KUrl(m_clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
457 if (m_endPix.isNull() && m_startPix.isNull()) {
458 m_startThumbRequested = true;
459 m_endThumbRequested = true;
460 emit getThumb((int)cropStart().frames(m_fps), (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
462 if (m_endPix.isNull()) {
465 if (m_startPix.isNull()) {
471 if (m_endPix.isNull() && m_startPix.isNull()) {
472 int frame1 = (int)m_cropStart.frames(m_fps);
473 int frame2 = (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1;
474 //videoThumbProducer.setThumbFrames(m_clip->producer(), frame1, frame2);
475 //videoThumbProducer.start(QThread::LowestPriority);
477 if (m_endPix.isNull()) slotGetEndThumb();
478 else slotGetStartThumb();
481 } else if (m_startPix.isNull()) slotGetStartThumb();*/
484 void ClipItem::slotGetStartThumb()
486 m_startThumbRequested = true;
487 emit getThumb((int)cropStart().frames(m_fps), -1);
488 //videoThumbProducer.setThumbFrames(m_clip->producer(), (int)m_cropStart.frames(m_fps), - 1);
489 //videoThumbProducer.start(QThread::LowestPriority);
492 void ClipItem::slotGetEndThumb()
494 m_endThumbRequested = true;
495 emit getThumb(-1, (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
496 //videoThumbProducer.setThumbFrames(m_clip->producer(), -1, (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1);
497 //videoThumbProducer.start(QThread::LowestPriority);
501 void ClipItem::slotSetStartThumb(QImage img)
503 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
504 QPixmap pix = QPixmap::fromImage(img);
506 QRectF r = sceneBoundingRect();
507 r.setRight(pix.width() + 2);
512 void ClipItem::slotSetEndThumb(QImage img)
514 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
515 QPixmap pix = QPixmap::fromImage(img);
517 QRectF r = sceneBoundingRect();
518 r.setLeft(r.right() - pix.width() - 2);
523 void ClipItem::slotThumbReady(int frame, QPixmap pix)
525 if (scene() == NULL) return;
526 QRectF r = boundingRect();
527 double width = pix.width() / projectScene()->scale().x();
528 if (m_startThumbRequested && frame == cropStart().frames(m_fps)) {
530 m_startThumbRequested = false;
531 update(r.left(), r.top(), width, pix.height());
532 } else if (m_endThumbRequested && frame == (cropStart() + cropDuration()).frames(m_fps) - 1) {
534 m_endThumbRequested = false;
535 update(r.right() - width, r.y(), width, pix.height());
539 void ClipItem::slotSetStartThumb(const QPixmap pix)
544 void ClipItem::slotSetEndThumb(const QPixmap pix)
549 QPixmap ClipItem::startThumb() const
554 QPixmap ClipItem::endThumb() const
559 void ClipItem::slotGotAudioData()
561 m_audioThumbReady = true;
562 if (m_clipType == AV && !isAudioOnly()) {
563 QRectF r = boundingRect();
564 r.setTop(r.top() + r.height() / 2 - 1);
569 int ClipItem::type() const
574 DocClipBase *ClipItem::baseClip() const
579 QDomElement ClipItem::xml() const
581 QDomElement xml = m_clip->toXML();
582 if (m_speed != 1.0) xml.setAttribute("speed", m_speed);
583 if (m_audioOnly) xml.setAttribute("audio_only", 1);
584 else if (m_videoOnly) xml.setAttribute("video_only", 1);
588 int ClipItem::clipType() const
593 QString ClipItem::clipName() const
598 void ClipItem::setClipName(const QString &name)
603 const QString &ClipItem::clipProducer() const
608 void ClipItem::flashClip()
610 if (m_timeLine == 0) {
611 m_timeLine = new QTimeLine(750, this);
612 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
613 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
618 void ClipItem::animate(qreal /*value*/)
620 QRectF r = boundingRect();
626 void ClipItem::paint(QPainter *painter,
627 const QStyleOptionGraphicsItem *option,
630 /*if (parentItem()) m_opacity = 0.5;
631 else m_opacity = 1.0;
632 painter->setOpacity(m_opacity);*/
634 if (parentItem()) paintColor = QColor(255, 248, 149);
635 else paintColor = brush().color();
636 if (isSelected() || (parentItem() && parentItem()->isSelected())) paintColor = paintColor.darker();
638 QRectF exposed = option->exposedRect;
639 QRectF mapped = painter->matrix().mapRect(br);
641 const double itemWidth = br.width();
642 const double itemHeight = br.height();
643 const double scale = option->matrix.m11();
644 const double vscale = option->matrix.m22();
645 const qreal xoffset = pen().widthF() / scale;
647 //painter->setRenderHints(QPainter::Antialiasing);
649 //QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
650 painter->setClipRect(exposed);
652 //Fill clip rectangle
653 /*QRectF bgRect = br;
654 bgRect.setLeft(br.left() + xoffset);*/
655 painter->fillRect(exposed, paintColor);
657 //painter->setClipPath(resultClipPath, Qt::IntersectClip);
661 if (KdenliveSettings::videothumbnails() && !isAudioOnly()) {
662 QPen pen = painter->pen();
663 pen.setColor(QColor(255, 255, 255, 150));
664 painter->setPen(pen);
665 if ((m_clipType == IMAGE || m_clipType == TEXT) && !m_startPix.isNull()) {
666 double left = itemWidth - m_startPix.width() * vscale / scale;
667 QRectF pixrect(left, 0.0, m_startPix.width() * vscale / scale, m_startPix.height());
668 QRectF source(0.0, 0.0, (double) m_startPix.width(), (double) m_startPix.height());
669 painter->drawPixmap(pixrect, m_startPix, source);
670 QLineF l2(left, 0, left, m_startPix.height());
671 painter->drawLine(l2);
672 } else if (!m_endPix.isNull()) {
673 double left = itemWidth - m_endPix.width() * vscale / scale;
674 QRectF pixrect(left, 0.0, m_endPix.width() * vscale / scale, m_endPix.height());
675 QRectF source(0.0, 0.0, (double) m_endPix.width(), (double) m_endPix.height());
676 painter->drawPixmap(pixrect, m_endPix, source);
677 QLineF l2(left, 0, left, m_startPix.height());
678 painter->drawLine(l2);
680 if (!m_startPix.isNull()) {
681 double right = m_startPix.width() * vscale / scale;
682 QRectF pixrect(0.0, 0.0, right, m_startPix.height());
683 QRectF source(0.0, 0.0, (double) m_startPix.width(), (double) m_startPix.height());
684 painter->drawPixmap(pixrect, m_startPix, source);
685 QLineF l2(right, 0, right, m_startPix.height());
686 painter->drawLine(l2);
688 painter->setPen(Qt::black);
690 painter->setMatrixEnabled(false);
692 // draw audio thumbnails
693 if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (itemHeight / 2) || isAudioOnly())) || m_clipType == AUDIO) && m_audioThumbReady) {
695 double startpixel = exposed.left();
698 double endpixel = exposed.right();
701 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
703 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
705 if (m_clipType == AV && !isAudioOnly()) {
707 mappedRect = painter->matrix().mapRect(re);
708 mappedRect.setTop(mappedRect.bottom() - re.height() / 2);
709 } else mappedRect = mapped;
711 int channels = baseClip()->getProperty("channels").toInt();
712 if (scale != m_framePixelWidth)
713 m_audioThumbCachePic.clear();
714 double cropLeft = m_cropStart.frames(m_fps);
715 const int clipStart = mappedRect.x();
716 const int mappedStartPixel = painter->matrix().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
717 const int mappedEndPixel = painter->matrix().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
718 cropLeft = cropLeft * scale;
721 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
724 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
725 if (m_audioThumbCachePic.contains(startCache) && !m_audioThumbCachePic[startCache].isNull())
726 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), m_audioThumbCachePic[startCache]);
731 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
732 QList < CommentedTime >::Iterator it = markers.begin();
736 markerBrush = QBrush(QColor(120, 120, 0, 140));
737 QPen pen = painter->pen();
738 pen.setColor(QColor(255, 255, 255, 200));
739 pen.setStyle(Qt::DotLine);
740 painter->setPen(pen);
741 for (; it != markers.end(); ++it) {
742 pos = (*it).time() / m_speed - cropStart();
743 if (pos > GenTime()) {
744 if (pos > cropDuration()) break;
745 QLineF l(br.x() + pos.frames(m_fps), br.y(), br.x() + pos.frames(m_fps), br.bottom());
746 QLineF l2 = painter->matrix().map(l);
747 //framepos = scale * pos.frames(m_fps);
748 //QLineF l(framepos, 5, framepos, itemHeight - 5);
749 painter->drawLine(l2);
750 if (KdenliveSettings::showmarkers()) {
751 framepos = br.x() + pos.frames(m_fps);
752 const QRectF r1(framepos + 0.04, 10, itemWidth - framepos - 2, itemHeight - 10);
753 const QRectF r2 = painter->matrix().mapRect(r1);
754 const QRectF txtBounding = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, ' ' + (*it).comment() + ' ');
755 painter->setBrush(markerBrush);
756 painter->setPen(Qt::NoPen);
757 painter->drawRoundedRect(txtBounding, 3, 3);
758 painter->setPen(Qt::white);
759 painter->drawText(txtBounding, Qt::AlignCenter, (*it).comment());
761 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
764 pen.setColor(Qt::black);
765 pen.setStyle(Qt::SolidLine);
766 painter->setPen(pen);
768 // draw start / end fades
771 fades = QBrush(QColor(200, 50, 50, 150));
772 } else fades = QBrush(QColor(200, 200, 200, 200));
774 if (m_startFade != 0) {
775 QPainterPath fadeInPath;
776 fadeInPath.moveTo(0, 0);
777 fadeInPath.lineTo(0, itemHeight);
778 fadeInPath.lineTo(m_startFade, 0);
779 fadeInPath.closeSubpath();
780 QPainterPath f1 = painter->matrix().map(fadeInPath);
781 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
782 /*if (isSelected()) {
783 QLineF l(m_startFade * scale, 0, 0, itemHeight);
784 painter->drawLine(l);
787 if (m_endFade != 0) {
788 QPainterPath fadeOutPath;
789 fadeOutPath.moveTo(itemWidth, 0);
790 fadeOutPath.lineTo(itemWidth, itemHeight);
791 fadeOutPath.lineTo(itemWidth - m_endFade, 0);
792 fadeOutPath.closeSubpath();
793 QPainterPath f1 = painter->matrix().map(fadeOutPath);
794 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
795 /*if (isSelected()) {
796 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
797 painter->drawLine(l);
801 // Draw effects names
802 if (!m_effectNames.isEmpty() && itemWidth * scale > 40) {
803 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
804 txtBounding.setRight(txtBounding.right() + 15);
805 painter->setPen(Qt::white);
806 QBrush markerBrush(Qt::SolidPattern);
807 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
808 qreal value = m_timeLine->currentValue();
809 txtBounding.setWidth(txtBounding.width() * value);
810 markerBrush.setColor(QColor(50 + 200 *(1.0 - value), 50, 50, 100 + 50 * value));
811 } else markerBrush.setColor(QColor(50, 50, 50, 150));
812 painter->setBrush(markerBrush);
813 painter->setPen(Qt::NoPen);
814 painter->drawRoundedRect(txtBounding, 3, 3);
815 painter->setPen(Qt::white);
816 painter->drawText(txtBounding, Qt::AlignCenter, m_effectNames);
817 painter->setPen(Qt::black);
821 QColor frameColor(Qt::black);
823 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
824 frameColor = QColor(Qt::red);
827 frameColor.setAlpha(150);
828 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignHCenter | Qt::AlignVCenter, ' ' + m_clipName + ' ');
829 painter->fillRect(txtBounding, frameColor);
830 //painter->setPen(QColor(0, 0, 0, 180));
831 //painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
833 painter->drawPixmap(txtBounding.topLeft() - QPointF(17, -1), m_videoPix);
834 } else if (m_audioOnly) {
835 painter->drawPixmap(txtBounding.topLeft() - QPointF(17, -1), m_audioPix);
837 txtBounding.translate(QPointF(1, 1));
838 painter->setPen(QColor(255, 255, 255, 255));
839 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
842 // draw transition handles on hover
843 /*if (m_hover && itemWidth * scale > 40) {
844 QPointF p1 = painter->matrix().map(QPointF(0, itemHeight / 2)) + QPointF(10, 0);
845 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
846 p1 = painter->matrix().map(QPointF(itemWidth, itemHeight / 2)) - QPointF(22, 0);
847 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
850 // draw effect or transition keyframes
851 if (mapped.width() > 20) drawKeyFrames(painter, exposed);
853 painter->setMatrixEnabled(true);
856 // expand clip rect to allow correct painting of clip border
858 exposed.setRight(exposed.right() + xoffset + 0.5);
859 exposed.setBottom(exposed.bottom() + 1);
860 painter->setClipRect(exposed);
862 frameColor.setAlpha(alphaBase);
863 painter->setPen(frameColor);
864 QLineF line(br.left() + xoffset, br.top(), br.right() - xoffset, br.top());
865 painter->drawLine(line);
867 frameColor.setAlpha(alphaBase * 2);
868 painter->setPen(frameColor);
869 line.setLine(br.right(), br.top() + 1.0, br.right(), br.bottom() - 1.0);
870 painter->drawLine(line);
871 line.setLine(br.right() - xoffset, br.bottom(), br.left() + xoffset, br.bottom());
872 painter->drawLine(line);
873 line.setLine(br.left(), br.bottom() - 1.0, br.left(), br.top() + 1.0);
874 painter->drawLine(line);
876 painter->setPen(QColor(255, 255, 255, 60));
877 line.setLine(br.right() - xoffset, br.bottom() - 1.0, br.left() + xoffset, br.bottom() - 1.0);
878 painter->drawLine(line);
879 //painter->drawRect(br);
883 OPERATIONTYPE ClipItem::operationMode(QPointF pos)
885 if (isItemLocked()) return NONE;
887 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
888 m_editedKeyframe = mouseOverKeyFrames(pos);
889 if (m_editedKeyframe != -1) return KEYFRAME;
891 QRectF rect = sceneBoundingRect();
892 const double scale = projectScene()->scale().x();
893 double maximumOffset = 6 / scale;
894 int addtransitionOffset = 10;
895 // Don't allow add transition if track height is very small
896 if (rect.height() < 30) addtransitionOffset = 0;
898 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
899 if (m_startFade == 0) setToolTip(i18n("Add audio fade"));
900 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_startFade, m_fps).seconds()));
902 } else if (pos.x() - rect.x() < maximumOffset && (rect.bottom() - pos.y() > addtransitionOffset)) {
903 setToolTip(i18n("Crop from start: %1s", cropStart().seconds()));
905 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
906 if (m_endFade == 0) setToolTip(i18n("Add audio fade"));
907 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_endFade, m_fps).seconds()));
909 } else if ((rect.right() - pos.x() < maximumOffset) && (rect.bottom() - pos.y() > addtransitionOffset)) {
910 setToolTip(i18n("Clip duration: %1s", cropDuration().seconds()));
912 } else if ((pos.x() - rect.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
913 setToolTip(i18n("Add transition"));
914 return TRANSITIONSTART;
915 } else if ((rect.right() - pos.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
916 setToolTip(i18n("Add transition"));
917 return TRANSITIONEND;
919 setToolTip(QString());
923 QList <GenTime> ClipItem::snapMarkers() const
925 QList < GenTime > snaps;
926 QList < GenTime > markers = baseClip()->snapMarkers();
929 for (int i = 0; i < markers.size(); i++) {
930 pos = markers.at(i) / m_speed - cropStart();
931 if (pos > GenTime()) {
932 if (pos > cropDuration()) break;
933 else snaps.append(pos + startPos());
939 QList <CommentedTime> ClipItem::commentedSnapMarkers() const
941 QList < CommentedTime > snaps;
942 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
945 for (int i = 0; i < markers.size(); i++) {
946 pos = markers.at(i).time() / m_speed - cropStart();
947 if (pos > GenTime()) {
948 if (pos > cropDuration()) break;
949 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
955 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels)
957 QRectF re = sceneBoundingRect();
958 if (m_clipType == AV && !isAudioOnly()) re.setTop(re.y() + re.height() / 2);
960 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
961 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
963 for (int startCache = startpixel - startpixel % 100; startCache < endpixel; startCache += 100) {
964 //kDebug() << "creating " << startCache;
965 //if (framePixelWidth!=pixelForOneFrame ||
966 if (m_framePixelWidth == pixelForOneFrame && m_audioThumbCachePic.contains(startCache))
968 if (m_audioThumbCachePic[startCache].isNull() || m_framePixelWidth != pixelForOneFrame) {
969 m_audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
970 m_audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
972 bool fullAreaDraw = pixelForOneFrame < 10;
973 QMap<int, QPainterPath > positiveChannelPaths;
974 QMap<int, QPainterPath > negativeChannelPaths;
975 QPainter pixpainter(&m_audioThumbCachePic[startCache]);
977 audiopen.setWidth(0);
978 pixpainter.setPen(audiopen);
979 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
980 //pixpainter.drawLine(0,0,100,re.height());
981 // Bail out, if caller provided invalid data
983 kWarning() << "Unable to draw image with " << channels << "number of channels";
987 int channelHeight = m_audioThumbCachePic[startCache].height() / channels;
989 for (int i = 0; i < channels; i++) {
991 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
992 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
995 for (int samples = 0; samples <= 100; samples++) {
996 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
997 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
998 if (frame < 0 || sample < 0 || sample > 19)
1000 QMap<int, QByteArray> frame_channel_data = baseClip()->m_audioFrameCache[(int)frame];
1002 for (int channel = 0; channel < channels && frame_channel_data[channel].size() > 0; channel++) {
1004 int y = channelHeight * channel + channelHeight / 2;
1005 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
1007 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
1008 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
1010 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
1011 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
1014 for (int channel = 0; channel < channels ; channel++)
1015 if (fullAreaDraw && samples == 100) {
1016 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
1017 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
1018 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
1019 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
1023 pixpainter.setPen(QPen(QColor(0, 0, 0)));
1024 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
1026 for (int i = 0; i < channels; i++) {
1028 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
1029 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
1031 pixpainter.drawPath(positiveChannelPaths[i]);
1034 //audioThumbWasDrawn=true;
1035 m_framePixelWidth = pixelForOneFrame;
1040 int ClipItem::fadeIn() const
1045 int ClipItem::fadeOut() const
1051 void ClipItem::setFadeIn(int pos)
1053 if (pos == m_startFade) return;
1054 int oldIn = m_startFade;
1055 if (pos < 0) pos = 0;
1056 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
1058 QRectF rect = boundingRect();
1059 update(rect.x(), rect.y(), qMax(oldIn, pos), rect.height());
1062 void ClipItem::setFadeOut(int pos)
1064 if (pos == m_endFade) return;
1065 int oldOut = m_endFade;
1066 if (pos < 0) pos = 0;
1067 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
1069 QRectF rect = boundingRect();
1070 update(rect.x() + rect.width() - qMax(oldOut, pos), rect.y(), qMax(oldOut, pos), rect.height());
1076 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
1078 //if (e->pos().x() < 20) m_hover = true;
1080 if (isItemLocked()) return;
1082 QRectF r = boundingRect();
1083 double width = 35 / projectScene()->scale().x();
1084 double height = r.height() / 2;
1085 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1086 update(r.x(), r.y() + height, width, height);
1087 update(r.right() - width, r.y() + height, width, height);
1091 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
1093 if (isItemLocked()) return;
1095 QRectF r = boundingRect();
1096 double width = 35 / projectScene()->scale().x();
1097 double height = r.height() / 2;
1098 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1099 update(r.x(), r.y() + height, width, height);
1100 update(r.right() - width, r.y() + height, width, height);
1104 void ClipItem::resizeStart(int posx, double /*speed*/)
1106 const int min = (startPos() - cropStart()).frames(m_fps);
1107 if (posx < min) posx = min;
1108 if (posx == startPos().frames(m_fps)) return;
1109 const int previous = cropStart().frames(m_fps);
1110 AbstractClipItem::resizeStart(posx, m_speed);
1111 if ((int) cropStart().frames(m_fps) != previous) {
1112 checkEffectsKeyframesPos(previous, cropStart().frames(m_fps), true);
1113 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1114 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
1115 m_startThumbTimer->start(150);
1120 void ClipItem::resizeEnd(int posx, double /*speed*/, bool updateKeyFrames)
1122 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps);
1123 if (posx > max && maxDuration() != GenTime()) posx = max;
1124 if (posx == endPos().frames(m_fps)) return;
1125 //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
1126 const int previous = (cropStart() + cropDuration()).frames(m_fps);
1127 AbstractClipItem::resizeEnd(posx, m_speed);
1128 if ((int)(cropStart() + cropDuration()).frames(m_fps) != previous) {
1129 if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + cropDuration()).frames(m_fps), false);
1130 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1131 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
1132 m_endThumbTimer->start(150);
1138 void ClipItem::checkEffectsKeyframesPos(const int previous, const int current, bool fromStart)
1140 for (int i = 0; i < m_effectList.size(); i++) {
1141 QDomElement effect = m_effectList.at(i);
1142 QDomNodeList params = effect.elementsByTagName("parameter");
1143 for (int j = 0; j < params.count(); j++) {
1144 QDomElement e = params.item(i).toElement();
1145 if (e.attribute("type") == "keyframe") {
1146 // parse keyframes and adjust values
1147 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1148 QMap <int, double> kfr;
1151 foreach(const QString &str, keyframes) {
1152 pos = str.section(':', 0, 0).toInt();
1153 val = str.section(':', 1, 1).toDouble();
1154 if (pos == previous) kfr[current] = val;
1156 if (fromStart && pos >= current) kfr[pos] = val;
1157 else if (!fromStart && pos <= current) kfr[pos] = val;
1161 QMap<int, double>::const_iterator k = kfr.constBegin();
1162 while (k != kfr.constEnd()) {
1163 newkfr.append(QString::number(k.key()) + ':' + QString::number(k.value()) + ';');
1166 e.setAttribute("keyframes", newkfr);
1171 if (m_selectedEffect >= 0) setSelectedEffect(m_selectedEffect);
1175 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
1177 if (change == ItemPositionChange && scene()) {
1178 // calculate new position.
1179 //if (parentItem()) return pos();
1180 QPointF newPos = value.toPointF();
1181 //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1182 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1183 xpos = qMax(xpos, 0);
1185 int newTrack = newPos.y() / KdenliveSettings::trackheight();
1186 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1187 newTrack = qMax(newTrack, 0);
1188 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1189 // Only one clip is moving
1190 QRectF sceneShape = rect();
1191 sceneShape.translate(newPos);
1192 QList<QGraphicsItem*> items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1193 items.removeAll(this);
1194 bool forwardMove = newPos.x() > pos().x();
1196 if (!items.isEmpty()) {
1197 for (int i = 0; i < items.count(); i++) {
1198 if (items.at(i)->type() == type()) {
1200 QPointF otherPos = items.at(i)->pos();
1201 if ((int) otherPos.y() != (int) pos().y()) {
1205 offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps)));
1207 offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
1212 sceneShape.translate(QPointF(-offset, 0));
1213 newPos.setX(newPos.x() - offset);
1215 sceneShape.translate(QPointF(offset, 0));
1216 newPos.setX(newPos.x() + offset);
1218 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1219 subitems.removeAll(this);
1220 for (int j = 0; j < subitems.count(); j++) {
1221 if (subitems.at(j)->type() == type()) {
1222 m_startPos = GenTime((int) pos().x(), m_fps);
1229 m_startPos = GenTime((int) newPos.x(), m_fps);
1235 m_startPos = GenTime((int) newPos.x(), m_fps);
1236 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1239 return QGraphicsItem::itemChange(change, value);
1243 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1246 int ClipItem::effectsCounter()
1248 return effectsCount() + 1;
1251 int ClipItem::effectsCount()
1253 return m_effectList.size();
1256 int ClipItem::hasEffect(const QString &tag, const QString &id) const
1258 return m_effectList.hasEffect(tag, id);
1261 QStringList ClipItem::effectNames()
1263 return m_effectList.effectNames();
1266 QDomElement ClipItem::effectAt(int ix)
1268 if (ix > m_effectList.count() - 1 || ix < 0) return QDomElement();
1269 return m_effectList.at(ix);
1272 void ClipItem::setEffectAt(int ix, QDomElement effect)
1274 if (ix < 0 || ix > (m_effectList.count() - 1)) {
1275 kDebug() << "Invalid effect index: " << ix;
1278 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1279 effect.setAttribute("kdenlive_ix", ix + 1);
1280 m_effectList.insert(ix, effect);
1281 m_effectList.removeAt(ix + 1);
1282 m_effectNames = m_effectList.effectNames().join(" / ");
1283 QString id = effect.attribute("id");
1284 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1285 update(boundingRect());
1287 QRectF r = boundingRect();
1293 EffectsParameterList ClipItem::addEffect(QDomElement effect, bool animate)
1296 bool needRepaint = false;
1298 doc.appendChild(doc.importNode(effect, true));
1299 kDebug() << "/////// CLIPÂ ADD EFFECT: " << doc.toString();*/
1300 m_effectList.append(effect);
1302 EffectsParameterList parameters;
1303 parameters.addParam("tag", effect.attribute("tag"));
1304 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1305 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1307 QString state = effect.attribute("disabled");
1308 if (!state.isEmpty()) {
1309 parameters.addParam("disabled", state);
1312 QString effectId = effect.attribute("id");
1313 if (effectId.isEmpty()) effectId = effect.attribute("tag");
1314 parameters.addParam("id", effectId);
1316 QDomNodeList params = effect.elementsByTagName("parameter");
1318 for (int i = 0; i < params.count(); i++) {
1319 QDomElement e = params.item(i).toElement();
1321 if (e.attribute("type") == "keyframe") {
1322 parameters.addParam("keyframes", e.attribute("keyframes"));
1323 parameters.addParam("max", e.attribute("max"));
1324 parameters.addParam("min", e.attribute("min"));
1325 parameters.addParam("factor", e.attribute("factor", "1"));
1326 parameters.addParam("starttag", e.attribute("starttag", "start"));
1327 parameters.addParam("endtag", e.attribute("endtag", "end"));
1330 double f = e.attribute("factor", "1").toDouble();
1333 parameters.addParam(e.attribute("name"), e.attribute("value"));
1335 // check if it is a fade effect
1336 if (effectId == "fadein") {
1338 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
1339 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1340 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1342 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
1343 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1344 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1346 } else if (effectId == "fade_from_black") {
1348 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
1349 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1350 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1352 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
1353 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1354 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1356 } else if (effectId == "fadeout") {
1358 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
1359 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1360 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1362 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
1363 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1364 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1366 } else if (effectId == "fade_to_black") {
1368 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
1369 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1370 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1372 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
1373 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1374 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1378 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / f));
1382 m_effectNames = m_effectList.effectNames().join(" / ");
1383 if (fade > 0) m_startFade = fade;
1384 else if (fade < 0) m_endFade = -fade;
1385 if (needRepaint) update(boundingRect());
1388 } else if (!needRepaint) {
1389 QRectF r = boundingRect();
1393 if (m_selectedEffect == -1) {
1394 setSelectedEffect(0);
1399 EffectsParameterList ClipItem::getEffectArgs(QDomElement effect)
1401 EffectsParameterList parameters;
1402 parameters.addParam("tag", effect.attribute("tag"));
1403 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1404 parameters.addParam("id", effect.attribute("id"));
1405 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1406 QString state = effect.attribute("disabled");
1407 if (!state.isEmpty()) {
1408 parameters.addParam("disabled", state);
1411 QDomNodeList params = effect.elementsByTagName("parameter");
1412 for (int i = 0; i < params.count(); i++) {
1413 QDomElement e = params.item(i).toElement();
1414 //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
1415 if (e.attribute("type") == "keyframe") {
1416 kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
1417 parameters.addParam("keyframes", e.attribute("keyframes"));
1418 parameters.addParam("max", e.attribute("max"));
1419 parameters.addParam("min", e.attribute("min"));
1420 parameters.addParam("factor", e.attribute("factor", "1"));
1421 parameters.addParam("starttag", e.attribute("starttag", "start"));
1422 parameters.addParam("endtag", e.attribute("endtag", "end"));
1423 } else if (e.attribute("namedesc").contains(';')) {
1424 QString format = e.attribute("format");
1425 QStringList separators = format.split("%d", QString::SkipEmptyParts);
1426 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
1428 QTextStream txtNeu(&neu);
1429 if (values.size() > 0)
1430 txtNeu << (int)values[0].toDouble();
1431 for (int i = 0; i < separators.size() && i + 1 < values.size(); i++) {
1432 txtNeu << separators[i];
1433 txtNeu << (int)(values[i+1].toDouble());
1435 parameters.addParam("start", neu);
1437 if (e.attribute("factor", "1") != "1") {
1438 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / e.attribute("factor").toDouble()));
1440 parameters.addParam(e.attribute("name"), e.attribute("value"));
1447 void ClipItem::deleteEffect(QString index)
1449 bool needRepaint = false;
1452 for (int i = 0; i < m_effectList.size(); ++i) {
1453 ix = m_effectList.at(i).attribute("kdenlive_ix");
1455 QString effectId = m_effectList.at(i).attribute("id");
1456 if ((effectId == "fadein" && hasEffect(QString(), "fade_from_black") == -1) ||
1457 (effectId == "fade_from_black" && hasEffect(QString(), "fadein") == -1)) {
1460 } else if ((effectId == "fadeout" && hasEffect(QString(), "fade_to_black") == -1) ||
1461 (effectId == "fade_to_black" && hasEffect(QString(), "fadeout") == -1)) {
1465 m_effectList.removeAt(i);
1467 } else if (ix.toInt() > index.toInt()) {
1468 m_effectList[i].setAttribute("kdenlive_ix", ix.toInt() - 1);
1471 m_effectNames = m_effectList.effectNames().join(" / ");
1472 if (m_effectList.isEmpty() || m_selectedEffect - 1 == index.toInt()) {
1473 // Current effect was removed
1474 if (index.toInt() > m_effectList.count() - 1) {
1475 setSelectedEffect(m_effectList.count() - 1);
1476 } else setSelectedEffect(index.toInt());
1478 if (needRepaint) update();
1482 double ClipItem::speed() const
1487 void ClipItem::setSpeed(const double speed)
1490 if (m_speed == 1.0) m_clipName = baseClip()->name();
1491 else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + '%';
1495 GenTime ClipItem::maxDuration() const
1497 return m_maxDuration / m_speed;
1500 GenTime ClipItem::cropStart() const
1502 return m_cropStart / m_speed;
1505 GenTime ClipItem::cropDuration() const
1507 return m_cropDuration / m_speed;
1510 GenTime ClipItem::endPos() const
1512 return m_startPos + cropDuration();
1516 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
1518 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
1520 doc.setContent(effects, true);
1521 QDomElement e = doc.documentElement();
1522 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1523 if (view) view->slotAddEffect(e, m_startPos, track());
1527 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
1529 if (isItemLocked()) event->setAccepted(false);
1530 else event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
1533 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
1538 void ClipItem::addTransition(Transition* t)
1540 m_transitionsList.append(t);
1541 //CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1543 QDomElement e = doc.documentElement();
1544 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1547 void ClipItem::setVideoOnly(bool force)
1549 m_videoOnly = force;
1552 void ClipItem::setAudioOnly(bool force)
1554 m_audioOnly = force;
1555 if (m_audioOnly) setBrush(QColor(141, 215, 166));
1556 else setBrush(QColor(141, 166, 215));
1557 m_audioThumbCachePic.clear();
1560 bool ClipItem::isAudioOnly() const
1565 bool ClipItem::isVideoOnly() const
1571 #include "clipitem.moc"