1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
22 #include "customtrackview.h"
23 #include "customtrackscene.h"
25 #include "docclipbase.h"
26 #include "transition.h"
27 #include "kdenlivesettings.h"
35 #include <QStyleOptionGraphicsItem>
36 #include <QGraphicsScene>
39 ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, bool generateThumbs) :
40 AbstractClipItem(info, QRectF(), fps),
47 m_startPix(QPixmap()),
50 m_startThumbTimer(NULL),
51 m_endThumbTimer(NULL),
54 m_startThumbRequested(false),
55 m_endThumbRequested(false),
61 setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double)(KdenliveSettings::trackheight() - 2));
62 setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1);
64 m_videoPix = KIcon("kdenlive-show-video").pixmap(QSize(16, 16));
65 m_audioPix = KIcon("kdenlive-show-audio").pixmap(QSize(16, 16));
67 if (m_speed == 1.0) m_clipName = clip->name();
69 m_clipName = clip->name() + " - " + QString::number(m_speed * 100, 'f', 0) + '%';
70 m_cropDuration = m_cropDuration * m_speed;
72 m_producer = clip->getId();
73 m_clipType = clip->clipType();
74 m_cropStart = info.cropStart;
75 m_maxDuration = clip->maxDuration();
77 m_audioThumbReady = clip->audioThumbCreated();
80 m_cropStart = xml.attribute("in", 0).toInt();
81 m_maxDuration = xml.attribute("duration", 0).toInt();
82 if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
84 if (duration != -1) m_cropDuration = duration;
85 else m_cropDuration = m_maxDuration;*/
88 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
89 setAcceptsHoverEvents(true);
90 connect(this , SIGNAL(prepareAudioThumb(double, int, int, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int)));
92 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
93 setBrush(QColor(141, 166, 215));
95 m_startThumbTimer = new QTimer(this);
96 m_startThumbTimer->setSingleShot(true);
97 connect(m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
98 m_endThumbTimer = new QTimer(this);
99 m_endThumbTimer->setSingleShot(true);
100 connect(m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
102 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
103 //connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(getVideoThumbs(int, int)));
105 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
106 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
107 if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs()));
109 /*if (m_clip->producer()) {
110 videoThumbProducer.init(this, m_clip->producer(), KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio(), KdenliveSettings::trackheight());
113 } else if (m_clipType == COLOR) {
114 QString colour = clip->getProperty("colour");
115 colour = colour.replace(0, 2, "#");
116 setBrush(QColor(colour.left(7)));
117 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
118 setBrush(QColor(141, 166, 215));
119 m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
120 m_endPix = m_startPix;
121 } else if (m_clipType == AUDIO) {
122 setBrush(QColor(141, 215, 166));
123 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
128 ClipItem::~ClipItem()
130 delete m_startThumbTimer;
131 delete m_endThumbTimer;
135 ClipItem *ClipItem::clone(ItemInfo info) const
137 ClipItem *duplicate = new ClipItem(m_clip, info, m_fps, m_speed);
138 if (info.cropStart == m_cropStart) duplicate->slotSetStartThumb(m_startPix);
139 if (info.cropStart + (info.endPos - info.startPos) == m_cropStart + m_cropDuration) duplicate->slotSetEndThumb(m_endPix);
140 kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
141 duplicate->setEffectList(m_effectList.clone());
142 //duplicate->setSpeed(m_speed);
146 void ClipItem::setEffectList(const EffectsList effectList)
148 m_effectList = effectList;
149 m_effectNames = m_effectList.effectNames().join(" / ");
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() << "// inint 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(m_cropStart.frames(m_fps)) + ':' + def + ';' + QString::number((m_cropStart + m_cropDuration).frames(m_fps)) + ':' + def);
178 //kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
184 if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
185 if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
186 int end = (duration() + cropStart()).frames(m_fps);
188 if (effect.attribute("id") == "fadeout") {
189 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
190 start -= EffectsList::parameter(effect, "in").toInt();
192 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
193 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
195 } else if (effect.attribute("id") == "fade_to_black") {
196 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
197 start -= EffectsList::parameter(effect, "in").toInt();
199 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
200 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
203 EffectsList::setParameter(effect, "in", QString::number(start));
204 EffectsList::setParameter(effect, "out", QString::number(end));
205 } else if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
206 int start = cropStart().frames(m_fps);
208 if (effect.attribute("id") == "fadein") {
209 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1)
210 end += EffectsList::parameter(effect, "out").toInt();
212 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fade_from_black"), "out").toInt();
213 } else if (effect.attribute("id") == "fade_from_black") {
214 if (m_effectList.hasEffect(QString(), "fadein") == -1)
215 end += EffectsList::parameter(effect, "out").toInt();
217 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fadein"), "out").toInt();
219 EffectsList::setParameter(effect, "in", QString::number(start));
220 EffectsList::setParameter(effect, "out", QString::number(end));
225 bool ClipItem::checkKeyFrames()
227 bool clipEffectsModified = false;
228 for (int ix = 0; ix < m_effectList.count(); ix ++) {
229 QString kfr = keyframes(ix);
230 if (!kfr.isEmpty()) {
231 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
232 QStringList newKeyFrames;
233 bool cutKeyFrame = false;
234 bool modified = false;
236 double lastValue = -1;
237 int start = m_cropStart.frames(m_fps);
238 int end = (m_cropStart + m_cropDuration).frames(m_fps);
239 foreach(const QString &str, keyframes) {
240 int pos = str.section(':', 0, 0).toInt();
241 double val = str.section(':', 1, 1).toDouble();
242 if (pos - start < 0) {
243 // a keyframe is defined before the start of the clip
245 } else if (cutKeyFrame) {
246 // create new keyframe at clip start, calculate interpolated value
248 int diff = pos - lastPos;
249 double ratio = (double)(start - lastPos) / diff;
250 double newValue = lastValue + (val - lastValue) * ratio;
251 newKeyFrames.append(QString::number(start) + ':' + QString::number(newValue));
258 // create new keyframe at clip end, calculate interpolated value
259 int diff = pos - lastPos;
261 double ratio = (double)(end - lastPos) / diff;
262 double newValue = lastValue + (val - lastValue) * ratio;
263 newKeyFrames.append(QString::number(end) + ':' + QString::number(newValue));
268 newKeyFrames.append(QString::number(pos) + ':' + QString::number(val));
276 setKeyframes(ix, newKeyFrames.join(";"));
277 clipEffectsModified = true;
281 return clipEffectsModified;
284 void ClipItem::setKeyframes(const int ix, const QString keyframes)
286 QDomElement effect = effectAt(ix);
287 if (effect.attribute("disabled") == "1") return;
288 QDomNodeList params = effect.elementsByTagName("parameter");
289 for (int i = 0; i < params.count(); i++) {
290 QDomElement e = params.item(i).toElement();
291 if (!e.isNull() && e.attribute("type") == "keyframe") {
292 e.setAttribute("keyframes", keyframes);
293 if (ix == m_selectedEffect) {
295 double max = e.attribute("max").toDouble();
296 double min = e.attribute("min").toDouble();
297 m_keyframeFactor = 100.0 / (max - min);
298 m_keyframeDefault = e.attribute("default").toDouble();
300 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
301 foreach(const QString &str, keyframes) {
302 int pos = str.section(':', 0, 0).toInt();
303 double val = str.section(':', 1, 1).toDouble();
304 m_keyframes[pos] = val;
315 void ClipItem::setSelectedEffect(const int ix)
317 m_selectedEffect = ix;
318 QDomElement effect = effectAt(m_selectedEffect);
319 QDomNodeList params = effect.elementsByTagName("parameter");
320 if (effect.attribute("disabled") != "1")
321 for (int i = 0; i < params.count(); i++) {
322 QDomElement e = params.item(i).toElement();
323 if (!e.isNull() && e.attribute("type") == "keyframe") {
325 double max = e.attribute("max").toDouble();
326 double min = e.attribute("min").toDouble();
327 m_keyframeFactor = 100.0 / (max - min);
328 m_keyframeDefault = e.attribute("default").toDouble();
330 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
331 foreach(const QString &str, keyframes) {
332 int pos = str.section(':', 0, 0).toInt();
333 double val = str.section(':', 1, 1).toDouble();
334 m_keyframes[pos] = val;
340 if (!m_keyframes.isEmpty()) {
346 QString ClipItem::keyframes(const int index)
349 QDomElement effect = effectAt(index);
350 QDomNodeList params = effect.elementsByTagName("parameter");
352 for (int i = 0; i < params.count(); i++) {
353 QDomElement e = params.item(i).toElement();
354 if (!e.isNull() && e.attribute("type") == "keyframe") {
355 result = e.attribute("keyframes");
362 void ClipItem::updateKeyframeEffect()
364 // regenerate xml parameter from the clip keyframes
365 QDomElement effect = effectAt(m_selectedEffect);
366 if (effect.attribute("disabled") == "1") return;
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") {
373 if (m_keyframes.count() > 1) {
374 QMap<int, double>::const_iterator i = m_keyframes.constBegin();
375 while (i != m_keyframes.constEnd()) {
376 keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
380 // Effect has a keyframe type parameter, we need to set the values
381 //kDebug() << "::::::::::::::: SETTING EFFECT KEYFRAMES: " << keyframes;
382 e.setAttribute("keyframes", keyframes);
388 QDomElement ClipItem::selectedEffect()
390 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
391 return effectAt(m_selectedEffect);
394 void ClipItem::resetThumbs()
396 m_startPix = QPixmap();
397 m_endPix = QPixmap();
399 m_audioThumbCachePic.clear();
403 void ClipItem::refreshClip()
405 m_maxDuration = m_clip->maxDuration();
406 if (m_clipType == COLOR) {
407 QString colour = m_clip->getProperty("colour");
408 colour = colour.replace(0, 2, "#");
409 setBrush(QColor(colour.left(7)));
410 } else slotFetchThumbs();
413 void ClipItem::slotFetchThumbs()
415 if (m_endPix.isNull() && m_startPix.isNull()) {
416 m_startThumbRequested = true;
417 m_endThumbRequested = true;
418 emit getThumb((int)cropStart().frames(m_fps), (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
420 if (m_endPix.isNull()) {
423 if (m_startPix.isNull()) {
429 if (m_endPix.isNull() && m_startPix.isNull()) {
430 int frame1 = (int)m_cropStart.frames(m_fps);
431 int frame2 = (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1;
432 //videoThumbProducer.setThumbFrames(m_clip->producer(), frame1, frame2);
433 //videoThumbProducer.start(QThread::LowestPriority);
435 if (m_endPix.isNull()) slotGetEndThumb();
436 else slotGetStartThumb();
439 } else if (m_startPix.isNull()) slotGetStartThumb();*/
442 void ClipItem::slotGetStartThumb()
444 m_startThumbRequested = true;
445 emit getThumb((int)cropStart().frames(m_fps), -1);
446 //videoThumbProducer.setThumbFrames(m_clip->producer(), (int)m_cropStart.frames(m_fps), - 1);
447 //videoThumbProducer.start(QThread::LowestPriority);
450 void ClipItem::slotGetEndThumb()
452 m_endThumbRequested = true;
453 emit getThumb(-1, (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
454 //videoThumbProducer.setThumbFrames(m_clip->producer(), -1, (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1);
455 //videoThumbProducer.start(QThread::LowestPriority);
459 void ClipItem::slotSetStartThumb(QImage img)
461 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
462 QPixmap pix = QPixmap::fromImage(img);
464 QRectF r = sceneBoundingRect();
465 r.setRight(pix.width() + 2);
470 void ClipItem::slotSetEndThumb(QImage img)
472 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
473 QPixmap pix = QPixmap::fromImage(img);
475 QRectF r = sceneBoundingRect();
476 r.setLeft(r.right() - pix.width() - 2);
481 void ClipItem::slotThumbReady(int frame, QPixmap pix)
483 if (scene() == NULL) return;
484 QRectF r = sceneBoundingRect();
485 double width = m_startPix.width() / projectScene()->scale();
486 if (m_startThumbRequested && frame == cropStart().frames(m_fps)) {
488 m_startThumbRequested = false;
489 double height = r.height();
490 update(r.x(), r.y(), width, height);
491 } else if (m_endThumbRequested && frame == (cropStart() + cropDuration()).frames(m_fps) - 1) {
493 m_endThumbRequested = false;
494 double height = r.height();
495 update(r.right() - width, r.y(), width, height);
499 void ClipItem::slotSetStartThumb(const QPixmap pix)
504 void ClipItem::slotSetEndThumb(const QPixmap pix)
509 QPixmap ClipItem::startThumb() const
514 QPixmap ClipItem::endThumb() const
519 void ClipItem::slotGotAudioData()
521 m_audioThumbReady = true;
522 if (m_clipType == AV && !isAudioOnly()) {
523 QRectF r = boundingRect();
524 r.setTop(r.top() + r.height() / 2 - 1);
529 int ClipItem::type() const
534 DocClipBase *ClipItem::baseClip() const
539 QDomElement ClipItem::xml() const
541 QDomElement xml = m_clip->toXML();
542 if (m_speed != 1.0) xml.setAttribute("speed", m_speed);
546 int ClipItem::clipType() const
551 QString ClipItem::clipName() const
556 void ClipItem::setClipName(const QString &name)
561 const QString &ClipItem::clipProducer() const
566 void ClipItem::flashClip()
568 if (m_timeLine == 0) {
569 m_timeLine = new QTimeLine(750, this);
570 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
571 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
576 void ClipItem::animate(qreal /*value*/)
578 QRectF r = boundingRect();
584 void ClipItem::paint(QPainter *painter,
585 const QStyleOptionGraphicsItem *option,
588 /*if (parentItem()) m_opacity = 0.5;
589 else m_opacity = 1.0;
590 painter->setOpacity(m_opacity);*/
592 if (parentItem()) paintColor = QColor(255, 248, 149);
593 else paintColor = brush().color();
594 if (isSelected() || (parentItem() && parentItem()->isSelected())) paintColor = paintColor.darker();
596 QRectF exposed = option->exposedRect;
597 QRectF mapped = painter->matrix().mapRect(br);
599 const double itemWidth = br.width();
600 const double itemHeight = br.height();
601 const double scale = option->matrix.m11();
602 const qreal xoffset = pen().widthF() / scale;
604 //painter->setRenderHints(QPainter::Antialiasing);
606 //QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
607 painter->setClipRect(exposed);
609 //Fill clip rectangle
611 bgRect.setLeft(br.left() + xoffset);
612 painter->fillRect(bgRect, paintColor);
614 //painter->setClipPath(resultClipPath, Qt::IntersectClip);
617 painter->setMatrixEnabled(false);
619 if (KdenliveSettings::videothumbnails() && !isAudioOnly()) {
620 QPen pen = painter->pen();
621 pen.setColor(QColor(255, 255, 255, 150));
622 painter->setPen(pen);
623 if (m_clipType == IMAGE && !m_startPix.isNull()) {
624 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_startPix.width(), 0);
625 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_startPix.width(), 0);
626 painter->drawPixmap(p1, m_startPix);
628 painter->drawLine(l);
629 } else if (!m_endPix.isNull()) {
630 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_endPix.width(), 0);
631 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_endPix.width(), 0);
632 painter->drawPixmap(p1, m_endPix);
634 painter->drawLine(l);
636 if (!m_startPix.isNull()) {
637 QPointF p1 = painter->matrix().map(QPointF(0, 0)) + QPointF(1.0, 0);
638 QPointF p2 = painter->matrix().map(QPointF(0, itemHeight)) + QPointF(1.0, 0);
639 painter->drawPixmap(p1, m_startPix);
640 QLineF l2(p1.x() + m_startPix.width(), p1.y(), p2.x() + m_startPix.width(), p2.y());
641 painter->drawLine(l2);
643 painter->setPen(Qt::black);
646 // draw audio thumbnails
647 if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (itemHeight / 2) || isAudioOnly())) || m_clipType == AUDIO) && m_audioThumbReady) {
649 double startpixel = exposed.left();
652 double endpixel = exposed.right();
655 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
657 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
659 if (m_clipType == AV && !isAudioOnly()) {
661 re.setTop(re.y() + re.height() / 2);
662 mappedRect = painter->matrix().mapRect(re);
663 //painter->fillRect(mappedRect, QBrush(QColor(200, 200, 200, 140)));
664 } else mappedRect = mapped;
666 int channels = baseClip()->getProperty("channels").toInt();
667 if (scale != m_framePixelWidth)
668 m_audioThumbCachePic.clear();
669 double cropLeft = m_cropStart.frames(m_fps);
670 const int clipStart = mappedRect.x();
671 const int mappedStartPixel = painter->matrix().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
672 const int mappedEndPixel = painter->matrix().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
673 cropLeft = cropLeft * scale;
676 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
679 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
680 if (m_audioThumbCachePic.contains(startCache) && !m_audioThumbCachePic[startCache].isNull())
681 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), m_audioThumbCachePic[startCache]);
686 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
687 QList < CommentedTime >::Iterator it = markers.begin();
691 markerBrush = QBrush(QColor(120, 120, 0, 140));
692 QPen pen = painter->pen();
693 pen.setColor(QColor(255, 255, 255, 200));
694 pen.setStyle(Qt::DotLine);
695 painter->setPen(pen);
696 for (; it != markers.end(); ++it) {
697 pos = (*it).time() - cropStart();
698 if (pos > GenTime()) {
699 if (pos > duration()) break;
700 QLineF l(br.x() + pos.frames(m_fps), br.y() + 5, br.x() + pos.frames(m_fps), br.bottom() - 5);
701 QLineF l2 = painter->matrix().map(l);
702 //framepos = scale * pos.frames(m_fps);
703 //QLineF l(framepos, 5, framepos, itemHeight - 5);
704 painter->drawLine(l2);
705 if (KdenliveSettings::showmarkers()) {
706 framepos = br.x() + pos.frames(m_fps);
707 const QRectF r1(framepos + 0.04, 10, itemWidth - framepos - 2, itemHeight - 10);
708 const QRectF r2 = painter->matrix().mapRect(r1);
709 const QRectF txtBounding = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, ' ' + (*it).comment() + ' ');
710 painter->setBrush(markerBrush);
711 painter->setPen(Qt::NoPen);
712 painter->drawRoundedRect(txtBounding, 3, 3);
713 painter->setPen(Qt::white);
714 painter->drawText(txtBounding, Qt::AlignCenter, (*it).comment());
716 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
719 pen.setColor(Qt::black);
720 pen.setStyle(Qt::SolidLine);
721 painter->setPen(pen);
723 // draw start / end fades
726 fades = QBrush(QColor(200, 50, 50, 150));
727 } else fades = QBrush(QColor(200, 200, 200, 200));
729 if (m_startFade != 0) {
730 QPainterPath fadeInPath;
731 fadeInPath.moveTo(0, 0);
732 fadeInPath.lineTo(0, itemHeight);
733 fadeInPath.lineTo(m_startFade, 0);
734 fadeInPath.closeSubpath();
735 QPainterPath f1 = painter->matrix().map(fadeInPath);
736 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
737 /*if (isSelected()) {
738 QLineF l(m_startFade * scale, 0, 0, itemHeight);
739 painter->drawLine(l);
742 if (m_endFade != 0) {
743 QPainterPath fadeOutPath;
744 fadeOutPath.moveTo(itemWidth, 0);
745 fadeOutPath.lineTo(itemWidth, itemHeight);
746 fadeOutPath.lineTo(itemWidth - m_endFade, 0);
747 fadeOutPath.closeSubpath();
748 QPainterPath f1 = painter->matrix().map(fadeOutPath);
749 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
750 /*if (isSelected()) {
751 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
752 painter->drawLine(l);
756 // Draw effects names
757 if (!m_effectNames.isEmpty() && itemWidth * scale > 40) {
758 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
759 txtBounding.setRight(txtBounding.right() + 15);
760 painter->setPen(Qt::white);
761 QBrush markerBrush(Qt::SolidPattern);
762 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
763 qreal value = m_timeLine->currentValue();
764 txtBounding.setWidth(txtBounding.width() * value);
765 markerBrush.setColor(QColor(50 + 200 * (1.0 - value), 50, 50, 100 + 50 * value));
766 } else markerBrush.setColor(QColor(50, 50, 50, 150));
767 painter->setBrush(markerBrush);
768 painter->setPen(Qt::NoPen);
769 painter->drawRoundedRect(txtBounding, 3, 3);
770 painter->setPen(Qt::white);
771 painter->drawText(txtBounding, Qt::AlignCenter, m_effectNames);
772 painter->setPen(Qt::black);
776 // draw frame around clip
777 QColor frameColor(Qt::black);
779 if (isSelected() || (parentItem() && parentItem()->isSelected())) {
780 frameColor = QColor(Qt::red);
783 frameColor.setAlpha(150);
784 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignHCenter | Qt::AlignVCenter, ' ' + m_clipName + ' ');
785 painter->fillRect(txtBounding, frameColor);
786 //painter->setPen(QColor(0, 0, 0, 180));
787 //painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
789 painter->drawPixmap(txtBounding.topLeft() - QPointF(17, -1), m_videoPix);
790 } else if (m_audioOnly) {
791 painter->drawPixmap(txtBounding.topLeft() - QPointF(17, -1), m_audioPix);
793 txtBounding.translate(QPointF(1, 1));
794 painter->setPen(QColor(255, 255, 255, 255));
795 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
798 // draw transition handles on hover
799 if (m_hover && itemWidth * scale > 40) {
800 QPointF p1 = painter->matrix().map(QPointF(0, itemHeight / 2)) + QPointF(10, 0);
801 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
802 p1 = painter->matrix().map(QPointF(itemWidth, itemHeight / 2)) - QPointF(22, 0);
803 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
806 // draw effect or transition keyframes
807 if (itemWidth > 20) drawKeyFrames(painter, exposed);
809 painter->setMatrixEnabled(true);
812 // expand clip rect to allow correct painting of clip border
814 exposed.setRight(exposed.right() + xoffset + 0.5);
815 exposed.setBottom(exposed.bottom() + 1);
816 painter->setClipRect(exposed);
818 frameColor.setAlpha(alphaBase);
819 painter->setPen(frameColor);
820 QLineF line(br.left() + xoffset, br.top(), br.right() - xoffset, br.top());
821 painter->drawLine(line);
823 frameColor.setAlpha(alphaBase * 2);
824 painter->setPen(frameColor);
825 line.setLine(br.right(), br.top() + 1.0, br.right(), br.bottom() - 1.0);
826 painter->drawLine(line);
827 line.setLine(br.right() - xoffset, br.bottom(), br.left() + xoffset, br.bottom());
828 painter->drawLine(line);
829 line.setLine(br.left(), br.bottom() - 1.0, br.left(), br.top() + 1.0);
830 painter->drawLine(line);
832 painter->setPen(QColor(255, 255, 255, 60));
833 line.setLine(br.right() - xoffset, br.bottom() - 1.0, br.left() + xoffset, br.bottom() - 1.0);
834 painter->drawLine(line);
835 //painter->drawRect(br);
839 OPERATIONTYPE ClipItem::operationMode(QPointF pos)
841 if (isItemLocked()) return NONE;
844 m_editedKeyframe = mouseOverKeyFrames(pos);
845 if (m_editedKeyframe != -1) return KEYFRAME;
847 QRectF rect = sceneBoundingRect();
848 const double scale = projectScene()->scale();
849 double maximumOffset = 6 / scale;
851 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
852 if (m_startFade == 0) setToolTip(i18n("Add audio fade"));
853 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_startFade, m_fps).seconds()));
855 } else if (pos.x() - rect.x() < maximumOffset) {
856 setToolTip(i18n("Crop from start: %1s", cropStart().seconds()));
858 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
859 if (m_endFade == 0) setToolTip(i18n("Add audio fade"));
860 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_endFade, m_fps).seconds()));
862 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width()))) < maximumOffset) {
863 setToolTip(i18n("Clip duration: %1s", duration().seconds()));
865 } else if (qAbs((int)(pos.x() - (rect.x() + 16 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
866 setToolTip(i18n("Add transition"));
867 return TRANSITIONSTART;
868 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - 21 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
869 setToolTip(i18n("Add transition"));
870 return TRANSITIONEND;
872 setToolTip(QString());
876 QList <GenTime> ClipItem::snapMarkers() const
878 QList < GenTime > snaps;
879 QList < GenTime > markers = baseClip()->snapMarkers();
882 for (int i = 0; i < markers.size(); i++) {
883 pos = markers.at(i) - cropStart();
884 if (pos > GenTime()) {
885 if (pos > duration()) break;
886 else snaps.append(pos + startPos());
892 QList <CommentedTime> ClipItem::commentedSnapMarkers() const
894 QList < CommentedTime > snaps;
895 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
898 for (int i = 0; i < markers.size(); i++) {
899 pos = markers.at(i).time() - cropStart();
900 if (pos > GenTime()) {
901 if (pos > duration()) break;
902 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
908 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels)
910 QRectF re = sceneBoundingRect();
911 if (m_clipType == AV && !isAudioOnly()) re.setTop(re.y() + re.height() / 2);
913 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
914 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
916 for (int startCache = startpixel - startpixel % 100;startCache < endpixel;startCache += 100) {
917 //kDebug() << "creating " << startCache;
918 //if (framePixelWidth!=pixelForOneFrame ||
919 if (m_framePixelWidth == pixelForOneFrame && m_audioThumbCachePic.contains(startCache))
921 if (m_audioThumbCachePic[startCache].isNull() || m_framePixelWidth != pixelForOneFrame) {
922 m_audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
923 m_audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
925 bool fullAreaDraw = pixelForOneFrame < 10;
926 QMap<int, QPainterPath > positiveChannelPaths;
927 QMap<int, QPainterPath > negativeChannelPaths;
928 QPainter pixpainter(&m_audioThumbCachePic[startCache]);
930 audiopen.setWidth(0);
931 pixpainter.setPen(audiopen);
932 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
933 //pixpainter.drawLine(0,0,100,re.height());
934 // Bail out, if caller provided invalid data
936 kWarning() << "Unable to draw image with " << channels << "number of channels";
940 int channelHeight = m_audioThumbCachePic[startCache].height() / channels;
942 for (int i = 0;i < channels;i++) {
944 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
945 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
948 for (int samples = 0;samples <= 100;samples++) {
949 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
950 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
951 if (frame < 0 || sample < 0 || sample > 19)
953 QMap<int, QByteArray> frame_channel_data = baseClip()->m_audioFrameCache[(int)frame];
955 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
957 int y = channelHeight * channel + channelHeight / 2;
958 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
960 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
961 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
963 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
964 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
967 for (int channel = 0;channel < channels ;channel++)
968 if (fullAreaDraw && samples == 100) {
969 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
970 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
971 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
972 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
976 pixpainter.setPen(QPen(QColor(0, 0, 0)));
977 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
979 for (int i = 0;i < channels;i++) {
981 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
982 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
984 pixpainter.drawPath(positiveChannelPaths[i]);
987 //audioThumbWasDrawn=true;
988 m_framePixelWidth = pixelForOneFrame;
993 int ClipItem::fadeIn() const
998 int ClipItem::fadeOut() const
1004 void ClipItem::setFadeIn(int pos)
1006 if (pos == m_startFade) return;
1007 int oldIn = m_startFade;
1008 if (pos < 0) pos = 0;
1009 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
1011 QRectF rect = boundingRect();
1012 update(rect.x(), rect.y(), qMax(oldIn, pos), rect.height());
1015 void ClipItem::setFadeOut(int pos)
1017 if (pos == m_endFade) return;
1018 int oldOut = m_endFade;
1019 if (pos < 0) pos = 0;
1020 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
1022 QRectF rect = boundingRect();
1023 update(rect.x() + rect.width() - qMax(oldOut, pos), rect.y(), qMax(oldOut, pos), rect.height());
1028 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event)
1030 /*m_resizeMode = operationMode(event->pos());
1031 if (m_resizeMode == MOVE) {
1032 m_maxTrack = scene()->sceneRect().height();
1033 m_grabPoint = (int) (event->pos().x() - rect().x());
1035 QGraphicsRectItem::mousePressEvent(event);
1039 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
1041 m_resizeMode = NONE;
1042 QGraphicsRectItem::mouseReleaseEvent(event);
1046 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent */*e*/)
1048 //if (e->pos().x() < 20) m_hover = true;
1049 if (isItemLocked()) return;
1051 QRectF r = boundingRect();
1052 double width = 35 / projectScene()->scale();
1053 double height = r.height() / 2;
1054 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1055 update(r.x(), r.y() + height, width, height);
1056 update(r.right() - width, r.y() + height, width, height);
1060 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
1062 if (isItemLocked()) return;
1064 QRectF r = boundingRect();
1065 double width = 35 / projectScene()->scale();
1066 double height = r.height() / 2;
1067 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
1068 update(r.x(), r.y() + height, width, height);
1069 update(r.right() - width, r.y() + height, width, height);
1072 void ClipItem::resizeStart(int posx, double /*speed*/)
1074 const int min = (startPos() - cropStart()).frames(m_fps);
1075 if (posx < min) posx = min;
1076 if (posx == startPos().frames(m_fps)) return;
1077 const int previous = cropStart().frames(m_fps);
1078 AbstractClipItem::resizeStart(posx, m_speed);
1079 if ((int) cropStart().frames(m_fps) != previous) {
1080 checkEffectsKeyframesPos(previous, cropStart().frames(m_fps), true);
1081 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1082 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
1083 m_startThumbTimer->start(150);
1088 void ClipItem::resizeEnd(int posx, double /*speed*/, bool updateKeyFrames)
1090 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps) + 1;
1091 if (posx > max) posx = max;
1092 if (posx == endPos().frames(m_fps)) return;
1093 //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
1094 const int previous = (cropStart() + duration()).frames(m_fps);
1095 AbstractClipItem::resizeEnd(posx, m_speed);
1096 if ((int)(cropStart() + duration()).frames(m_fps) != previous) {
1097 if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false);
1098 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1099 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
1100 m_endThumbTimer->start(150);
1106 void ClipItem::checkEffectsKeyframesPos(const int previous, const int current, bool fromStart)
1108 for (int i = 0; i < m_effectList.size(); i++) {
1109 QDomElement effect = m_effectList.at(i);
1110 QDomNodeList params = effect.elementsByTagName("parameter");
1111 for (int j = 0; j < params.count(); j++) {
1112 QDomElement e = params.item(i).toElement();
1113 if (e.attribute("type") == "keyframe") {
1114 // parse keyframes and adjust values
1115 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1116 QMap <int, double> kfr;
1119 foreach(const QString &str, keyframes) {
1120 pos = str.section(':', 0, 0).toInt();
1121 val = str.section(':', 1, 1).toDouble();
1122 if (pos == previous) kfr[current] = val;
1124 if (fromStart && pos >= current) kfr[pos] = val;
1125 else if (!fromStart && pos <= current) kfr[pos] = val;
1129 QMap<int, double>::const_iterator k = kfr.constBegin();
1130 while (k != kfr.constEnd()) {
1131 newkfr.append(QString::number(k.key()) + ':' + QString::number(k.value()) + ';');
1134 e.setAttribute("keyframes", newkfr);
1139 if (m_selectedEffect >= 0) setSelectedEffect(m_selectedEffect);
1143 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
1145 if (change == ItemPositionChange && scene()) {
1146 // calculate new position.
1147 //if (parentItem()) return pos();
1148 QPointF newPos = value.toPointF();
1149 //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1150 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1151 xpos = qMax(xpos, 0);
1153 int newTrack = newPos.y() / KdenliveSettings::trackheight();
1154 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1155 newTrack = qMax(newTrack, 0);
1156 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1157 // Only one clip is moving
1158 QRectF sceneShape = rect();
1159 sceneShape.translate(newPos);
1160 QList<QGraphicsItem*> items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1161 items.removeAll(this);
1162 bool forwardMove = newPos.x() > pos().x();
1164 if (!items.isEmpty()) {
1165 for (int i = 0; i < items.count(); i++) {
1166 if (items.at(i)->type() == type()) {
1168 QPointF otherPos = items.at(i)->pos();
1169 if ((int) otherPos.y() != (int) pos().y()) {
1173 offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps)));
1175 offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
1180 sceneShape.translate(QPointF(-offset, 0));
1181 newPos.setX(newPos.x() - offset);
1183 sceneShape.translate(QPointF(offset, 0));
1184 newPos.setX(newPos.x() + offset);
1186 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1187 subitems.removeAll(this);
1188 for (int j = 0; j < subitems.count(); j++) {
1189 if (subitems.at(j)->type() == type()) {
1190 m_startPos = GenTime((int) pos().x(), m_fps);
1197 m_startPos = GenTime((int) newPos.x(), m_fps);
1203 m_startPos = GenTime((int) newPos.x(), m_fps);
1204 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1207 return QGraphicsItem::itemChange(change, value);
1211 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1214 int ClipItem::effectsCounter()
1216 return effectsCount() + 1;
1219 int ClipItem::effectsCount()
1221 return m_effectList.size();
1224 int ClipItem::hasEffect(const QString &tag, const QString &id) const
1226 return m_effectList.hasEffect(tag, id);
1229 QStringList ClipItem::effectNames()
1231 return m_effectList.effectNames();
1234 QDomElement ClipItem::effectAt(int ix)
1236 if (ix > m_effectList.count() - 1 || ix < 0) return QDomElement();
1237 return m_effectList.at(ix);
1240 void ClipItem::setEffectAt(int ix, QDomElement effect)
1242 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1243 effect.setAttribute("kdenlive_ix", ix + 1);
1244 m_effectList.insert(ix, effect);
1245 m_effectList.removeAt(ix + 1);
1246 m_effectNames = m_effectList.effectNames().join(" / ");
1247 QString id = effect.attribute("id");
1248 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1249 update(boundingRect());
1251 QRectF r = boundingRect();
1257 EffectsParameterList ClipItem::addEffect(QDomElement effect, bool animate)
1260 bool needRepaint = false;
1262 doc.appendChild(doc.importNode(effect, true));
1263 kDebug() << "/////// CLIPÂ ADD EFFECT: " << doc.toString();*/
1264 m_effectList.append(effect);
1266 EffectsParameterList parameters;
1267 parameters.addParam("tag", effect.attribute("tag"));
1268 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1269 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1271 QString state = effect.attribute("disabled");
1272 if (!state.isEmpty()) {
1273 parameters.addParam("disabled", state);
1276 QString effectId = effect.attribute("id");
1277 if (effectId.isEmpty()) effectId = effect.attribute("tag");
1278 parameters.addParam("id", effectId);
1280 QDomNodeList params = effect.elementsByTagName("parameter");
1282 for (int i = 0; i < params.count(); i++) {
1283 QDomElement e = params.item(i).toElement();
1285 if (e.attribute("type") == "keyframe") {
1286 parameters.addParam("keyframes", e.attribute("keyframes"));
1287 parameters.addParam("max", e.attribute("max"));
1288 parameters.addParam("min", e.attribute("min"));
1289 parameters.addParam("factor", e.attribute("factor", "1"));
1290 parameters.addParam("starttag", e.attribute("starttag", "start"));
1291 parameters.addParam("endtag", e.attribute("endtag", "end"));
1294 double f = e.attribute("factor", "1").toDouble();
1297 parameters.addParam(e.attribute("name"), e.attribute("value"));
1299 // check if it is a fade effect
1300 if (effectId == "fadein") {
1302 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
1303 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1304 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1306 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
1307 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1308 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1310 } else if (effectId == "fade_from_black") {
1312 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
1313 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1314 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1316 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
1317 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1318 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1320 } else if (effectId == "fadeout") {
1322 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
1323 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1324 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1326 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
1327 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1328 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1330 } else if (effectId == "fade_to_black") {
1332 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
1333 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1334 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1336 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
1337 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1338 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1342 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / f));
1346 m_effectNames = m_effectList.effectNames().join(" / ");
1347 if (fade > 0) m_startFade = fade;
1348 else if (fade < 0) m_endFade = -fade;
1349 if (needRepaint) update(boundingRect());
1352 } else if (!needRepaint) {
1353 QRectF r = boundingRect();
1357 if (m_selectedEffect == -1) {
1358 m_selectedEffect = 0;
1359 setSelectedEffect(m_selectedEffect);
1364 EffectsParameterList ClipItem::getEffectArgs(QDomElement effect)
1366 EffectsParameterList parameters;
1367 parameters.addParam("tag", effect.attribute("tag"));
1368 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1369 parameters.addParam("id", effect.attribute("id"));
1370 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1371 QString state = effect.attribute("disabled");
1372 if (!state.isEmpty()) {
1373 parameters.addParam("disabled", state);
1376 QDomNodeList params = effect.elementsByTagName("parameter");
1377 for (int i = 0; i < params.count(); i++) {
1378 QDomElement e = params.item(i).toElement();
1379 //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
1380 if (e.attribute("type") == "keyframe") {
1381 kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
1382 parameters.addParam("keyframes", e.attribute("keyframes"));
1383 parameters.addParam("max", e.attribute("max"));
1384 parameters.addParam("min", e.attribute("min"));
1385 parameters.addParam("factor", e.attribute("factor", "1"));
1386 parameters.addParam("starttag", e.attribute("starttag", "start"));
1387 parameters.addParam("endtag", e.attribute("endtag", "end"));
1388 } else if (e.attribute("namedesc").contains(';')) {
1389 QString format = e.attribute("format");
1390 QStringList separators = format.split("%d", QString::SkipEmptyParts);
1391 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
1393 QTextStream txtNeu(&neu);
1394 if (values.size() > 0)
1395 txtNeu << (int)values[0].toDouble();
1396 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
1397 txtNeu << separators[i];
1398 txtNeu << (int)(values[i+1].toDouble());
1400 parameters.addParam("start", neu);
1402 if (e.attribute("factor", "1") != "1") {
1403 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / e.attribute("factor").toDouble()));
1405 parameters.addParam(e.attribute("name"), e.attribute("value"));
1412 void ClipItem::deleteEffect(QString index)
1414 bool needRepaint = false;
1417 for (int i = 0; i < m_effectList.size(); ++i) {
1418 ix = m_effectList.at(i).attribute("kdenlive_ix");
1420 QString effectId = m_effectList.at(i).attribute("id");
1421 if ((effectId == "fadein" && hasEffect(QString(), "fade_from_black") == -1) ||
1422 (effectId == "fade_from_black" && hasEffect(QString(), "fadein") == -1)) {
1425 } else if ((effectId == "fadeout" && hasEffect(QString(), "fade_to_black") == -1) ||
1426 (effectId == "fade_to_black" && hasEffect(QString(), "fadeout") == -1)) {
1430 m_effectList.removeAt(i);
1432 } else if (ix.toInt() > index.toInt()) {
1433 m_effectList[i].setAttribute("kdenlive_ix", ix.toInt() - 1);
1436 m_effectNames = m_effectList.effectNames().join(" / ");
1437 if (needRepaint) update(boundingRect());
1441 double ClipItem::speed() const
1446 void ClipItem::setSpeed(const double speed)
1449 if (m_speed == 1.0) m_clipName = baseClip()->name();
1450 else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + '%';
1454 GenTime ClipItem::maxDuration() const
1456 return m_maxDuration / m_speed;
1459 GenTime ClipItem::cropStart() const
1461 return m_cropStart / m_speed;
1464 GenTime ClipItem::cropDuration() const
1466 return m_cropDuration / m_speed;
1469 GenTime ClipItem::endPos() const
1471 return m_startPos + cropDuration();
1475 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
1477 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
1479 doc.setContent(effects, true);
1480 QDomElement e = doc.documentElement();
1481 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1482 if (view) view->slotAddEffect(e, m_startPos, track());
1486 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
1488 if (isItemLocked()) event->setAccepted(false);
1489 else event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
1492 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
1497 void ClipItem::addTransition(Transition* t)
1499 m_transitionsList.append(t);
1500 //CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1502 QDomElement e = doc.documentElement();
1503 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1506 void ClipItem::setVideoOnly(bool force)
1508 m_videoOnly = force;
1511 void ClipItem::setAudioOnly(bool force)
1513 m_audioOnly = force;
1514 if (m_audioOnly) setBrush(QColor(141, 215, 166));
1515 else setBrush(QColor(141, 166, 215));
1516 m_audioThumbCachePic.clear();
1519 bool ClipItem::isAudioOnly() const
1524 bool ClipItem::isVideoOnly() const
1532 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
1534 int pos = event->x();
1535 if (event->modifiers() == Qt::ControlModifier)
1536 setDragMode(QGraphicsView::ScrollHandDrag);
1537 else if (event->modifiers() == Qt::ShiftModifier)
1538 setDragMode(QGraphicsView::RubberBandDrag);
1540 QGraphicsItem * item = itemAt(event->pos());
1543 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
1546 QGraphicsView::mousePressEvent(event);
1549 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
1551 QGraphicsView::mouseReleaseEvent(event);
1552 setDragMode(QGraphicsView::NoDrag);
1556 #include "clipitem.moc"