1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
24 #include <QStyleOptionGraphicsItem>
25 #include <QGraphicsScene>
26 #include <QGraphicsView>
29 #include <QApplication>
34 #include "customtrackview.h"
35 #include "customtrackscene.h"
37 #include "docclipbase.h"
38 #include "transition.h"
39 #include "kdenlivesettings.h"
43 ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, bool generateThumbs)
44 : AbstractClipItem(info, QRectF(), fps), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_startThumbRequested(false), m_endThumbRequested(false), m_startFade(0), m_endFade(0), m_hover(false), m_selectedEffect(-1), m_speed(1.0), framePixelWidth(0), m_startPix(QPixmap()), m_endPix(QPixmap()) {
46 setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double)(KdenliveSettings::trackheight() - 2));
47 setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1);
49 m_clipName = clip->name();
50 m_producer = clip->getId();
51 m_clipType = clip->clipType();
52 m_cropStart = info.cropStart;
53 m_maxDuration = clip->maxDuration();
55 audioThumbReady = clip->audioThumbCreated();
58 m_cropStart = xml.attribute("in", 0).toInt();
59 m_maxDuration = xml.attribute("duration", 0).toInt();
60 if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
62 if (duration != -1) m_cropDuration = duration;
63 else m_cropDuration = m_maxDuration;*/
66 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
67 setAcceptsHoverEvents(true);
68 connect(this , SIGNAL(prepareAudioThumb(double, int, int, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int)));
70 setBrush(QColor(141, 166, 215));
71 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
73 startThumbTimer = new QTimer(this);
74 startThumbTimer->setSingleShot(true);
75 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
76 endThumbTimer = new QTimer(this);
77 endThumbTimer->setSingleShot(true);
78 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
80 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
81 //connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(getVideoThumbs(int, int)));
83 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
84 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
85 if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs()));
87 /*if (m_clip->producer()) {
88 videoThumbProducer.init(this, m_clip->producer(), KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio(), KdenliveSettings::trackheight());
91 } else if (m_clipType == COLOR) {
92 QString colour = clip->getProperty("colour");
93 colour = colour.replace(0, 2, "#");
94 setBrush(QColor(colour.left(7)));
95 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
96 m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
97 m_endPix = m_startPix;
98 } else if (m_clipType == AUDIO) {
99 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
104 ClipItem::~ClipItem() {
105 if (startThumbTimer) delete startThumbTimer;
106 if (endThumbTimer) delete endThumbTimer;
107 if (m_timeLine) m_timeLine;
110 ClipItem *ClipItem::clone(ItemInfo info) const {
111 ClipItem *duplicate = new ClipItem(m_clip, info, m_fps);
112 if (info.cropStart == cropStart()) duplicate->slotSetStartThumb(m_startPix);
113 if (info.cropStart + (info.endPos - info.startPos) == m_cropStart + m_cropDuration) duplicate->slotSetEndThumb(m_endPix);
114 kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
115 duplicate->setEffectList(m_effectList.clone());
116 duplicate->setSpeed(m_speed);
120 void ClipItem::setEffectList(const EffectsList effectList) {
121 m_effectList = effectList;
122 m_effectNames = m_effectList.effectNames().join(" / ");
125 const EffectsList ClipItem::effectList() {
129 int ClipItem::selectedEffectIndex() const {
130 return m_selectedEffect;
133 void ClipItem::initEffect(QDomElement effect) {
134 // the kdenlive_ix int is used to identify an effect in mlt's playlist, should
136 if (effect.attribute("kdenlive_ix").toInt() == 0)
137 effect.setAttribute("kdenlive_ix", QString::number(effectsCounter()));
138 // init keyframes if required
139 QDomNodeList params = effect.elementsByTagName("parameter");
140 for (int i = 0; i < params.count(); i++) {
141 QDomElement e = params.item(i).toElement();
142 kDebug() << "// inint eff: " << e.attribute("name");
143 if (!e.isNull() && e.attribute("type") == "keyframe") {
144 QString def = e.attribute("default");
145 // Effect has a keyframe type parameter, we need to set the values
146 if (e.attribute("keyframes").isEmpty()) {
147 e.setAttribute("keyframes", QString::number(m_cropStart.frames(m_fps)) + ":" + def + ";" + QString::number((m_cropStart + m_cropDuration).frames(m_fps)) + ":" + def);
148 //kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
154 if (effect.attribute("tag") == "volume") {
155 if (effect.attribute("id") == "fadeout") {
156 int end = (duration() + cropStart()).frames(m_fps);
157 int start = end - EffectsList::parameter(effect, "in").toInt();
158 EffectsList::setParameter(effect, "in", QString::number(start));
159 EffectsList::setParameter(effect, "out", QString::number(end));
160 } else if (effect.attribute("id") == "fadein") {
161 int start = cropStart().frames(m_fps);
162 int end = start + EffectsList::parameter(effect, "out").toInt();
163 EffectsList::setParameter(effect, "in", QString::number(start));
164 EffectsList::setParameter(effect, "out", QString::number(end));
169 bool ClipItem::checkKeyFrames() {
170 bool clipEffectsModified = false;
171 for (int ix = 0; ix < m_effectList.count(); ix ++) {
172 QString kfr = keyframes(ix);
173 if (!kfr.isEmpty()) {
174 const QStringList keyframes = kfr.split(";", QString::SkipEmptyParts);
175 QStringList newKeyFrames;
176 bool cutKeyFrame = false;
177 bool modified = false;
179 double lastValue = -1;
180 int start = m_cropStart.frames(m_fps);
181 int end = (m_cropStart + m_cropDuration).frames(m_fps);
182 foreach(const QString str, keyframes) {
183 int pos = str.section(":", 0, 0).toInt();
184 double val = str.section(":", 1, 1).toDouble();
185 if (pos - start < 0) {
186 // a keyframe is defined before the start of the clip
188 } else if (cutKeyFrame) {
189 // create new keyframe at clip start, calculate interpolated value
191 int diff = pos - lastPos;
192 double ratio = (double)(start - lastPos) / diff;
193 double newValue = lastValue + (val - lastValue) * ratio;
194 newKeyFrames.append(QString::number(start) + ":" + QString::number(newValue));
201 // create new keyframe at clip end, calculate interpolated value
202 int diff = pos - lastPos;
204 double ratio = (double)(end - lastPos) / diff;
205 double newValue = lastValue + (val - lastValue) * ratio;
206 newKeyFrames.append(QString::number(end) + ":" + QString::number(newValue));
211 newKeyFrames.append(QString::number(pos) + ":" + QString::number(val));
219 setKeyframes(ix, newKeyFrames.join(";"));
220 clipEffectsModified = true;
224 return clipEffectsModified;
227 void ClipItem::setKeyframes(const int ix, const QString keyframes) {
228 QDomElement effect = effectAt(ix);
229 if (effect.attribute("disabled") == "1") return;
230 QDomNodeList params = effect.elementsByTagName("parameter");
231 for (int i = 0; i < params.count(); i++) {
232 QDomElement e = params.item(i).toElement();
233 if (!e.isNull() && e.attribute("type") == "keyframe") {
234 e.setAttribute("keyframes", keyframes);
235 if (ix == m_selectedEffect) {
237 double max = e.attribute("max").toDouble();
238 double min = e.attribute("min").toDouble();
239 m_keyframeFactor = 100.0 / (max - min);
240 m_keyframeDefault = e.attribute("default").toDouble();
242 const QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
243 foreach(const QString str, keyframes) {
244 int pos = str.section(":", 0, 0).toInt();
245 double val = str.section(":", 1, 1).toDouble();
246 m_keyframes[pos] = val;
257 void ClipItem::setSelectedEffect(const int ix) {
258 m_selectedEffect = ix;
259 QDomElement effect = effectAt(m_selectedEffect);
260 QDomNodeList params = effect.elementsByTagName("parameter");
261 if (effect.attribute("disabled") != "1")
262 for (int i = 0; i < params.count(); i++) {
263 QDomElement e = params.item(i).toElement();
264 if (!e.isNull() && e.attribute("type") == "keyframe") {
266 double max = e.attribute("max").toDouble();
267 double min = e.attribute("min").toDouble();
268 m_keyframeFactor = 100.0 / (max - min);
269 m_keyframeDefault = e.attribute("default").toDouble();
271 const QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
272 foreach(const QString str, keyframes) {
273 int pos = str.section(":", 0, 0).toInt();
274 double val = str.section(":", 1, 1).toDouble();
275 m_keyframes[pos] = val;
281 if (!m_keyframes.isEmpty()) {
287 QString ClipItem::keyframes(const int index) {
289 QDomElement effect = effectAt(index);
290 QDomNodeList params = effect.elementsByTagName("parameter");
292 for (int i = 0; i < params.count(); i++) {
293 QDomElement e = params.item(i).toElement();
294 if (!e.isNull() && e.attribute("type") == "keyframe") {
295 result = e.attribute("keyframes");
302 void ClipItem::updateKeyframeEffect() {
303 // regenerate xml parameter from the clip keyframes
304 QDomElement effect = effectAt(m_selectedEffect);
305 if (effect.attribute("disabled") == "1") return;
306 QDomNodeList params = effect.elementsByTagName("parameter");
308 for (int i = 0; i < params.count(); i++) {
309 QDomElement e = params.item(i).toElement();
310 if (!e.isNull() && e.attribute("type") == "keyframe") {
312 if (m_keyframes.count() > 1) {
313 QMap<int, double>::const_iterator i = m_keyframes.constBegin();
316 while (i != m_keyframes.constEnd()) {
317 keyframes.append(QString::number(i.key()) + ":" + QString::number(i.value()) + ";");
321 // Effect has a keyframe type parameter, we need to set the values
322 //kDebug() << "::::::::::::::: SETTING EFFECT KEYFRAMES: " << keyframes;
323 e.setAttribute("keyframes", keyframes);
329 QDomElement ClipItem::selectedEffect() {
330 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
331 return effectAt(m_selectedEffect);
334 void ClipItem::resetThumbs() {
335 m_startPix = QPixmap();
336 m_endPix = QPixmap();
338 audioThumbCachePic.clear();
342 void ClipItem::refreshClip() {
343 m_maxDuration = m_clip->maxDuration();
344 if (m_clipType == COLOR) {
345 QString colour = m_clip->getProperty("colour");
346 colour = colour.replace(0, 2, "#");
347 setBrush(QColor(colour.left(7)));
348 } else slotFetchThumbs();
351 void ClipItem::slotFetchThumbs() {
352 if (m_endPix.isNull() && m_startPix.isNull()) {
353 m_startThumbRequested = true;
354 m_endThumbRequested = true;
355 emit getThumb((int)cropStart().frames(m_fps), (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
357 if (m_endPix.isNull()) {
360 if (m_startPix.isNull()) {
366 if (m_endPix.isNull() && m_startPix.isNull()) {
367 int frame1 = (int)m_cropStart.frames(m_fps);
368 int frame2 = (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1;
369 //videoThumbProducer.setThumbFrames(m_clip->producer(), frame1, frame2);
370 //videoThumbProducer.start(QThread::LowestPriority);
372 if (m_endPix.isNull()) slotGetEndThumb();
373 else slotGetStartThumb();
376 } else if (m_startPix.isNull()) slotGetStartThumb();*/
379 void ClipItem::slotGetStartThumb() {
380 m_startThumbRequested = true;
381 emit getThumb((int)cropStart().frames(m_fps), -1);
382 //videoThumbProducer.setThumbFrames(m_clip->producer(), (int)m_cropStart.frames(m_fps), - 1);
383 //videoThumbProducer.start(QThread::LowestPriority);
386 void ClipItem::slotGetEndThumb() {
387 m_endThumbRequested = true;
388 emit getThumb(-1, (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
389 //videoThumbProducer.setThumbFrames(m_clip->producer(), -1, (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1);
390 //videoThumbProducer.start(QThread::LowestPriority);
394 void ClipItem::slotSetStartThumb(QImage img) {
395 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
396 QPixmap pix = QPixmap::fromImage(img);
398 QRectF r = sceneBoundingRect();
399 r.setRight(pix.width() + 2);
404 void ClipItem::slotSetEndThumb(QImage img) {
405 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
406 QPixmap pix = QPixmap::fromImage(img);
408 QRectF r = sceneBoundingRect();
409 r.setLeft(r.right() - pix.width() - 2);
414 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
415 if (scene() == NULL) return;
416 QRectF r = sceneBoundingRect();
417 double width = m_startPix.width() / projectScene()->scale();
418 if (m_startThumbRequested && frame == cropStart().frames(m_fps)) {
420 m_startThumbRequested = false;
421 double height = r.height();
422 update(r.x(), r.y(), width, height);
423 } else if (m_endThumbRequested && frame == (cropStart() + cropDuration()).frames(m_fps) - 1) {
425 m_endThumbRequested = false;
426 double height = r.height();
427 update(r.right() - width, r.y(), width, height);
431 void ClipItem::slotSetStartThumb(const QPixmap pix) {
435 void ClipItem::slotSetEndThumb(const QPixmap pix) {
439 QPixmap ClipItem::startThumb() const {
443 QPixmap ClipItem::endThumb() const {
447 void ClipItem::slotGotAudioData() {
448 audioThumbReady = true;
449 if (m_clipType == AV) {
450 QRectF r = boundingRect();
451 r.setTop(r.top() + r.height() / 2 - 1);
456 int ClipItem::type() const {
460 DocClipBase *ClipItem::baseClip() const {
464 QDomElement ClipItem::xml() const {
465 return m_clip->toXML();
468 int ClipItem::clipType() const {
472 QString ClipItem::clipName() const {
476 const QString &ClipItem::clipProducer() const {
480 void ClipItem::flashClip() {
481 if (m_timeLine == 0) {
482 m_timeLine = new QTimeLine(750, this);
483 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
484 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
489 void ClipItem::animate(qreal value) {
490 QRectF r = boundingRect();
496 void ClipItem::paint(QPainter *painter,
497 const QStyleOptionGraphicsItem *option,
499 /*if (parentItem()) m_opacity = 0.5;
500 else m_opacity = 1.0;
501 painter->setOpacity(m_opacity);*/
502 QBrush paintColor = brush();
503 if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
505 QRectF exposed = option->exposedRect;
506 QRectF mapped = painter->matrix().mapRect(br);
508 const double itemWidth = br.width();
509 const double itemHeight = br.height();
510 const double scale = option->matrix.m11();
513 //painter->setRenderHints(QPainter::Antialiasing);
515 //QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
516 painter->setClipRect(exposed);
518 //build path around clip
519 //QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
520 //painter->fillPath(resultClipPath, paintColor);
521 painter->fillRect(exposed, paintColor);
523 //painter->setClipPath(resultClipPath, Qt::IntersectClip);
526 painter->setMatrixEnabled(false);
528 if (KdenliveSettings::videothumbnails()) {
529 QPen pen = painter->pen();
530 pen.setStyle(Qt::DotLine);
531 pen.setColor(Qt::white);
532 painter->setPen(pen);
533 if (m_clipType == IMAGE && !m_startPix.isNull()) {
534 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_startPix.width(), 0);
535 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_startPix.width(), 0);
536 painter->drawPixmap(p1, m_startPix);
538 painter->drawLine(l);
539 } else if (!m_endPix.isNull()) {
540 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_endPix.width(), 0);
541 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_endPix.width(), 0);
542 painter->drawPixmap(p1, m_endPix);
544 painter->drawLine(l);
546 if (!m_startPix.isNull()) {
547 QPointF p1 = painter->matrix().map(QPointF(0, 0));
548 QPointF p2 = painter->matrix().map(QPointF(0, itemHeight));
549 painter->drawPixmap(p1, m_startPix);
550 QLineF l2(p1.x() + m_startPix.width(), p1.y(), p2.x() + m_startPix.width(), p2.y());
551 painter->drawLine(l2);
553 painter->setPen(Qt::black);
556 // draw audio thumbnails
557 if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && ((m_clipType == AV && exposed.bottom() > (itemHeight / 2)) || m_clipType == AUDIO) && audioThumbReady) {
559 double startpixel = exposed.left();
562 double endpixel = exposed.right();
565 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
567 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
569 if (m_clipType == AV) {
571 re.setTop(re.y() + re.height() / 2);
572 mappedRect = painter->matrix().mapRect(re);
573 //painter->fillRect(mappedRect, QBrush(QColor(200, 200, 200, 140)));
574 } else mappedRect = mapped;
576 int channels = baseClip()->getProperty("channels").toInt();
577 if (scale != framePixelWidth)
578 audioThumbCachePic.clear();
579 double cropLeft = m_cropStart.frames(m_fps);
580 const int clipStart = mappedRect.x();
581 const int mappedStartPixel = painter->matrix().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
582 const int mappedEndPixel = painter->matrix().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
583 cropLeft = cropLeft * scale;
586 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
589 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
590 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
591 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), audioThumbCachePic[startCache]);
596 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
597 QList < CommentedTime >::Iterator it = markers.begin();
600 const int markerwidth = 4;
602 markerBrush = QBrush(QColor(120, 120, 0, 140));
603 QPen pen = painter->pen();
604 pen.setColor(QColor(255, 255, 255, 200));
605 pen.setStyle(Qt::DotLine);
606 painter->setPen(pen);
607 for (; it != markers.end(); ++it) {
608 pos = (*it).time() - cropStart();
609 if (pos > GenTime()) {
610 if (pos > duration()) break;
611 QLineF l(br.x() + pos.frames(m_fps), br.y() + 5, br.x() + pos.frames(m_fps), br.bottom() - 5);
612 QLineF l2 = painter->matrix().map(l);
613 //framepos = scale * pos.frames(m_fps);
614 //QLineF l(framepos, 5, framepos, itemHeight - 5);
615 painter->drawLine(l2);
616 if (KdenliveSettings::showmarkers()) {
617 framepos = br.x() + pos.frames(m_fps);
618 const QRectF r1(framepos + 0.04, 10, itemWidth - framepos - 2, itemHeight - 10);
619 const QRectF r2 = painter->matrix().mapRect(r1);
620 const QRectF txtBounding = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, " " + (*it).comment() + " ");
623 path.addRoundedRect(txtBounding, 3, 3);
624 painter->fillPath(path, markerBrush);
625 painter->drawText(txtBounding, Qt::AlignCenter, (*it).comment());
627 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
630 pen.setColor(Qt::black);
631 pen.setStyle(Qt::SolidLine);
632 painter->setPen(pen);
634 // draw start / end fades
637 fades = QBrush(QColor(200, 50, 50, 150));
638 } else fades = QBrush(QColor(200, 200, 200, 200));
640 if (m_startFade != 0) {
641 QPainterPath fadeInPath;
642 fadeInPath.moveTo(0, 0);
643 fadeInPath.lineTo(0, itemHeight);
644 fadeInPath.lineTo(m_startFade, 0);
645 fadeInPath.closeSubpath();
646 QPainterPath f1 = painter->matrix().map(fadeInPath);
647 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
648 /*if (isSelected()) {
649 QLineF l(m_startFade * scale, 0, 0, itemHeight);
650 painter->drawLine(l);
653 if (m_endFade != 0) {
654 QPainterPath fadeOutPath;
655 fadeOutPath.moveTo(itemWidth, 0);
656 fadeOutPath.lineTo(itemWidth, itemHeight);
657 fadeOutPath.lineTo(itemWidth - m_endFade, 0);
658 fadeOutPath.closeSubpath();
659 QPainterPath f1 = painter->matrix().map(fadeOutPath);
660 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
661 /*if (isSelected()) {
662 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
663 painter->drawLine(l);
667 // Draw effects names
668 if (!m_effectNames.isEmpty() && itemWidth * scale > 40) {
669 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
670 txtBounding.setRight(txtBounding.right() + 15);
671 painter->setPen(Qt::white);
672 QBrush markerBrush(Qt::SolidPattern);
673 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
674 qreal value = m_timeLine->currentValue();
675 txtBounding.setWidth(txtBounding.width() * value);
676 markerBrush.setColor(QColor(50 + 200 * (1.0 - value), 50, 50, 100 + 50 * value));
677 } else markerBrush.setColor(QColor(50, 50, 50, 150));
679 path.addRoundedRect(txtBounding, 4, 4);
680 painter->fillPath(path/*.intersected(resultClipPath)*/, markerBrush);
681 painter->drawText(txtBounding, Qt::AlignCenter, m_effectNames);
682 painter->setPen(Qt::black);
686 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignHCenter | Qt::AlignVCenter, " " + m_clipName + " ");
687 painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
688 //painter->setPen(QColor(0, 0, 0, 180));
689 //painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
690 txtBounding.translate(QPointF(1, 1));
691 painter->setPen(QColor(255, 255, 255, 255));
692 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
695 // draw transition handles on hover
696 if (m_hover && itemWidth * scale > 40) {
697 QPointF p1 = painter->matrix().map(QPointF(0, itemHeight / 2)) + QPointF(10, 0);
698 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
699 p1 = painter->matrix().map(QPointF(itemWidth, itemHeight / 2)) - QPointF(22, 0);
700 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
704 // draw frame around clip
706 pen.setColor(Qt::red);
709 pen.setColor(Qt::black);
713 // draw effect or transition keyframes
714 if (itemWidth > 20) drawKeyFrames(painter, exposed);
716 painter->setMatrixEnabled(true);
720 //kDebug()<<"/// ITEM PAINTING:: exposed="<<exposed<<", RECT = "<<rect();
722 // expand clip rect to allow correct painting of clip border
723 exposed.setRight(exposed.right() + 1 / scale + 0.5);
724 exposed.setBottom(exposed.bottom() + 1);
725 painter->setClipRect(exposed);
726 painter->setPen(pen);
727 painter->drawRect(br);
731 OPERATIONTYPE ClipItem::operationMode(QPointF pos) {
733 m_editedKeyframe = mouseOverKeyFrames(pos);
734 if (m_editedKeyframe != -1) return KEYFRAME;
736 QRectF rect = sceneBoundingRect();
737 const double scale = projectScene()->scale();
738 double maximumOffset = 6 / scale;
740 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
741 if (m_startFade == 0) setToolTip(i18n("Add audio fade"));
742 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_startFade, m_fps).seconds()));
744 } else if (pos.x() - rect.x() < maximumOffset) {
745 setToolTip(i18n("Crop from start: %1s", cropStart().seconds()));
747 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
748 if (m_endFade == 0) setToolTip(i18n("Add audio fade"));
749 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_endFade, m_fps).seconds()));
751 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width()))) < maximumOffset) {
752 setToolTip(i18n("Clip duration: %1s", duration().seconds()));
754 } else if (qAbs((int)(pos.x() - (rect.x() + 16 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
755 setToolTip(i18n("Add transition"));
756 return TRANSITIONSTART;
757 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - 21 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
758 setToolTip(i18n("Add transition"));
759 return TRANSITIONEND;
761 setToolTip(QString());
765 QList <GenTime> ClipItem::snapMarkers() const {
766 QList < GenTime > snaps;
767 QList < GenTime > markers = baseClip()->snapMarkers();
771 for (int i = 0; i < markers.size(); i++) {
772 pos = markers.at(i) - cropStart();
773 if (pos > GenTime()) {
774 if (pos > duration()) break;
775 else snaps.append(pos + startPos());
781 QList <CommentedTime> ClipItem::commentedSnapMarkers() const {
782 QList < CommentedTime > snaps;
783 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
787 for (int i = 0; i < markers.size(); i++) {
788 pos = markers.at(i).time() - cropStart();
789 if (pos > GenTime()) {
790 if (pos > duration()) break;
791 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
797 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels) {
798 QRectF re = sceneBoundingRect();
799 if (m_clipType == AV) re.setTop(re.y() + re.height() / 2);
801 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
802 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
804 for (int startCache = startpixel - startpixel % 100;startCache < endpixel;startCache += 100) {
805 //kDebug() << "creating " << startCache;
806 //if (framePixelWidth!=pixelForOneFrame ||
807 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
809 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
810 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
811 audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
813 bool fullAreaDraw = pixelForOneFrame < 10;
814 QMap<int, QPainterPath > positiveChannelPaths;
815 QMap<int, QPainterPath > negativeChannelPaths;
816 QPainter pixpainter(&audioThumbCachePic[startCache]);
818 audiopen.setWidth(0);
819 pixpainter.setPen(audiopen);
820 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
821 //pixpainter.drawLine(0,0,100,re.height());
822 // Bail out, if caller provided invalid data
824 kWarning() << "Unable to draw image with " << channels << "number of channels";
828 int channelHeight = audioThumbCachePic[startCache].height() / channels;
830 for (int i = 0;i < channels;i++) {
832 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
833 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
836 for (int samples = 0;samples <= 100;samples++) {
837 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
838 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
839 if (frame < 0 || sample < 0 || sample > 19)
841 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
843 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
845 int y = channelHeight * channel + channelHeight / 2;
846 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
848 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
849 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
851 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
852 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
855 for (int channel = 0;channel < channels ;channel++)
856 if (fullAreaDraw && samples == 100) {
857 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
858 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
859 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
860 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
864 if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
866 pixpainter.setPen(QPen(QColor(0, 0, 0)));
867 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
869 for (int i = 0;i < channels;i++) {
871 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
872 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
874 pixpainter.drawPath(positiveChannelPaths[i]);
877 //audioThumbWasDrawn=true;
878 framePixelWidth = pixelForOneFrame;
883 uint ClipItem::fadeIn() const {
887 uint ClipItem::fadeOut() const {
892 void ClipItem::setFadeIn(int pos) {
893 if (pos == m_startFade) return;
894 int oldIn = m_startFade;
895 if (pos < 0) pos = 0;
896 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
898 QRectF rect = boundingRect();
899 update(rect.x(), rect.y(), qMax(oldIn, pos), rect.height());
902 void ClipItem::setFadeOut(int pos) {
903 if (pos == m_endFade) return;
904 int oldOut = m_endFade;
905 if (pos < 0) pos = 0;
906 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
908 QRectF rect = boundingRect();
909 update(rect.x() + rect.width() - qMax(oldOut, pos), rect.y(), qMax(oldOut, pos), rect.height());
914 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
915 /*m_resizeMode = operationMode(event->pos());
916 if (m_resizeMode == MOVE) {
917 m_maxTrack = scene()->sceneRect().height();
918 m_grabPoint = (int) (event->pos().x() - rect().x());
920 QGraphicsRectItem::mousePressEvent(event);
924 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
926 QGraphicsRectItem::mouseReleaseEvent(event);
930 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e) {
931 //if (e->pos().x() < 20) m_hover = true;
933 QRectF r = boundingRect();
934 double width = 35 / projectScene()->scale();
935 double height = r.height() / 2;
936 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
937 update(r.x(), r.y() + height, width, height);
938 update(r.right() - width, r.y() + height, width, height);
942 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
944 QRectF r = boundingRect();
945 double width = 35 / projectScene()->scale();
946 double height = r.height() / 2;
947 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
948 update(r.x(), r.y() + height, width, height);
949 update(r.right() - width, r.y() + height, width, height);
952 void ClipItem::resizeStart(int posx, double speed) {
953 const int min = (startPos() - cropStart()).frames(m_fps);
954 if (posx < min) posx = min;
955 if (posx == startPos().frames(m_fps)) return;
956 const int previous = cropStart().frames(m_fps);
957 AbstractClipItem::resizeStart(posx, m_speed);
958 if ((int) cropStart().frames(m_fps) != previous) {
959 checkEffectsKeyframesPos(previous, cropStart().frames(m_fps), true);
960 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
961 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
962 startThumbTimer->start(150);
967 void ClipItem::resizeEnd(int posx, double speed, bool updateKeyFrames) {
968 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps) + 1;
969 if (posx > max) posx = max;
970 if (posx == endPos().frames(m_fps)) return;
971 //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
972 const int previous = (cropStart() + duration()).frames(m_fps);
973 AbstractClipItem::resizeEnd(posx, m_speed);
974 if ((int)(cropStart() + duration()).frames(m_fps) != previous) {
975 if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false);
976 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
977 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
978 endThumbTimer->start(150);
984 void ClipItem::checkEffectsKeyframesPos(const int previous, const int current, bool fromStart) {
985 for (int i = 0; i < m_effectList.size(); i++) {
986 QDomElement effect = m_effectList.at(i);
987 QDomNodeList params = effect.elementsByTagName("parameter");
988 for (int j = 0; j < params.count(); j++) {
989 QDomElement e = params.item(i).toElement();
990 if (e.attribute("type") == "keyframe") {
991 // parse keyframes and adjust values
992 const QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
993 QMap <int, double> kfr;
996 foreach(const QString str, keyframes) {
997 pos = str.section(":", 0, 0).toInt();
998 val = str.section(":", 1, 1).toDouble();
999 if (pos == previous) kfr[current] = val;
1001 if (fromStart && pos >= current) kfr[pos] = val;
1002 else if (!fromStart && pos <= current) kfr[pos] = val;
1006 QMap<int, double>::const_iterator k = kfr.constBegin();
1007 while (k != kfr.constEnd()) {
1008 newkfr.append(QString::number(k.key()) + ":" + QString::number(k.value()) + ";");
1011 e.setAttribute("keyframes", newkfr);
1016 if (m_selectedEffect >= 0) setSelectedEffect(m_selectedEffect);
1020 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value) {
1021 if (change == ItemPositionChange && scene()) {
1022 // calculate new position.
1023 if (parentItem()) return pos();
1024 QPointF newPos = value.toPointF();
1025 //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1026 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1027 xpos = qMax(xpos, 0);
1029 int newTrack = newPos.y() / KdenliveSettings::trackheight();
1030 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1031 newTrack = qMax(newTrack, 0);
1032 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1033 // Only one clip is moving
1034 QRectF sceneShape = rect();
1035 sceneShape.translate(newPos);
1036 QList<QGraphicsItem*> items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1037 items.removeAll(this);
1038 bool forwardMove = newPos.x() > pos().x();
1040 if (!items.isEmpty()) {
1041 for (int i = 0; i < items.count(); i++) {
1042 if (items.at(i)->type() == type()) {
1044 QPointF otherPos = items.at(i)->pos();
1045 if ((int) otherPos.y() != (int) pos().y()) {
1049 offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - m_cropDuration).frames(m_fps)));
1051 offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
1056 sceneShape.translate(QPointF(-offset, 0));
1057 newPos.setX(newPos.x() - offset);
1059 sceneShape.translate(QPointF(offset, 0));
1060 newPos.setX(newPos.x() + offset);
1062 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1063 subitems.removeAll(this);
1064 for (int j = 0; j < subitems.count(); j++) {
1065 if (subitems.at(j)->type() == type()) {
1066 m_startPos = GenTime((int) pos().x(), m_fps);
1073 m_startPos = GenTime((int) newPos.x(), m_fps);
1079 m_startPos = GenTime((int) newPos.x(), m_fps);
1080 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1083 return QGraphicsItem::itemChange(change, value);
1087 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1090 int ClipItem::effectsCounter() {
1091 return effectsCount() + 1;
1094 int ClipItem::effectsCount() {
1095 return m_effectList.size();
1098 int ClipItem::hasEffect(const QString &tag, const QString &id) const {
1099 return m_effectList.hasEffect(tag, id);
1102 QStringList ClipItem::effectNames() {
1103 return m_effectList.effectNames();
1106 QDomElement ClipItem::effectAt(int ix) {
1107 if (ix > m_effectList.count() - 1 || ix < 0) return QDomElement();
1108 return m_effectList.at(ix);
1111 void ClipItem::setEffectAt(int ix, QDomElement effect) {
1112 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1113 effect.setAttribute("kdenlive_ix", ix + 1);
1114 m_effectList.insert(ix, effect);
1115 m_effectList.removeAt(ix + 1);
1116 m_effectNames = m_effectList.effectNames().join(" / ");
1117 if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fadeout") update(boundingRect());
1119 QRectF r = boundingRect();
1125 EffectsParameterList ClipItem::addEffect(QDomElement effect, bool animate) {
1127 bool needRepaint = false;
1129 doc.appendChild(doc.importNode(effect, true));
1130 kDebug() << "/////// CLIPÂ ADD EFFECT: " << doc.toString();*/
1131 m_effectList.append(effect);
1133 EffectsParameterList parameters;
1134 parameters.addParam("tag", effect.attribute("tag"));
1135 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1136 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1138 QString state = effect.attribute("disabled");
1139 if (!state.isEmpty()) {
1140 parameters.addParam("disabled", state);
1143 QString effectId = effect.attribute("id");
1144 if (effectId.isEmpty()) effectId = effect.attribute("tag");
1145 parameters.addParam("id", effectId);
1147 QDomNodeList params = effect.elementsByTagName("parameter");
1149 for (int i = 0; i < params.count(); i++) {
1150 QDomElement e = params.item(i).toElement();
1152 if (e.attribute("type") == "keyframe") {
1153 parameters.addParam("keyframes", e.attribute("keyframes"));
1154 parameters.addParam("max", e.attribute("max"));
1155 parameters.addParam("min", e.attribute("min"));
1156 parameters.addParam("factor", e.attribute("factor", "1"));
1157 parameters.addParam("starttag", e.attribute("starttag", "start"));
1158 parameters.addParam("endtag", e.attribute("endtag", "end"));
1161 double f = e.attribute("factor", "1").toDouble();
1164 parameters.addParam(e.attribute("name"), e.attribute("value"));
1166 // check if it is a fade effect
1167 if (effectId == "fadein") {
1169 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1170 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1171 } else if (effectId == "fadeout") {
1173 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1174 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1177 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / f));
1181 m_effectNames = m_effectList.effectNames().join(" / ");
1182 if (fade > 0) m_startFade = fade;
1183 else if (fade < 0) m_endFade = -fade;
1184 if (needRepaint) update(boundingRect());
1187 } else if (!needRepaint) {
1188 QRectF r = boundingRect();
1192 if (m_selectedEffect == -1) {
1193 m_selectedEffect = 0;
1194 setSelectedEffect(m_selectedEffect);
1199 EffectsParameterList ClipItem::getEffectArgs(QDomElement effect) {
1200 EffectsParameterList parameters;
1201 parameters.addParam("tag", effect.attribute("tag"));
1202 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1203 parameters.addParam("id", effect.attribute("id"));
1204 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1205 QString state = effect.attribute("disabled");
1206 if (!state.isEmpty()) {
1207 parameters.addParam("disabled", state);
1210 QDomNodeList params = effect.elementsByTagName("parameter");
1211 for (int i = 0; i < params.count(); i++) {
1212 QDomElement e = params.item(i).toElement();
1213 //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
1214 if (e.attribute("type") == "keyframe") {
1215 kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
1216 parameters.addParam("keyframes", e.attribute("keyframes"));
1217 parameters.addParam("max", e.attribute("max"));
1218 parameters.addParam("min", e.attribute("min"));
1219 parameters.addParam("factor", e.attribute("factor", "1"));
1220 parameters.addParam("starttag", e.attribute("starttag", "start"));
1221 parameters.addParam("endtag", e.attribute("endtag", "end"));
1222 } else if (e.attribute("namedesc").contains(";")) {
1223 QString format = e.attribute("format");
1224 QStringList separators = format.split("%d", QString::SkipEmptyParts);
1225 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
1227 QTextStream txtNeu(&neu);
1228 if (values.size() > 0)
1229 txtNeu << (int)values[0].toDouble();
1230 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
1231 txtNeu << separators[i];
1232 txtNeu << (int)(values[i+1].toDouble());
1234 parameters.addParam("start", neu);
1236 if (e.attribute("factor", "1") != "1") {
1237 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / e.attribute("factor").toDouble()));
1239 parameters.addParam(e.attribute("name"), e.attribute("value"));
1246 void ClipItem::deleteEffect(QString index) {
1247 bool needRepaint = false;
1249 for (int i = 0; i < m_effectList.size(); ++i) {
1250 ix = m_effectList.at(i).attribute("kdenlive_ix");
1252 if (m_effectList.at(i).attribute("id") == "fadein") {
1255 } else if (m_effectList.at(i).attribute("id") == "fadeout") {
1259 m_effectList.removeAt(i);
1260 } else if (ix.toInt() > index.toInt()) m_effectList[i].setAttribute("kdenlive_ix", ix.toInt() - 1);
1262 m_effectNames = m_effectList.effectNames().join(" / ");
1263 if (needRepaint) update(boundingRect());
1267 double ClipItem::speed() const {
1271 void ClipItem::setSpeed(const double speed) {
1273 if (m_speed == 1.0) m_clipName = baseClip()->name();
1274 else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + "%";
1278 GenTime ClipItem::maxDuration() const {
1279 return m_maxDuration / m_speed;
1282 GenTime ClipItem::cropStart() const {
1283 return m_cropStart / m_speed;
1286 GenTime ClipItem::cropDuration() const {
1287 return m_cropDuration / m_speed;
1290 GenTime ClipItem::endPos() const {
1291 return m_startPos + cropDuration();
1295 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
1296 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
1298 doc.setContent(effects, true);
1299 QDomElement e = doc.documentElement();
1300 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1301 if (view) view->slotAddEffect(e, m_startPos, track());
1305 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
1306 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
1309 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
1312 void ClipItem::addTransition(Transition* t) {
1313 m_transitionsList.append(t);
1314 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1316 QDomElement e = doc.documentElement();
1317 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1321 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
1323 int pos = event->x();
1324 if (event->modifiers() == Qt::ControlModifier)
1325 setDragMode(QGraphicsView::ScrollHandDrag);
1326 else if (event->modifiers() == Qt::ShiftModifier)
1327 setDragMode(QGraphicsView::RubberBandDrag);
1329 QGraphicsItem * item = itemAt(event->pos());
1332 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
1335 QGraphicsView::mousePressEvent(event);
1338 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
1340 QGraphicsView::mouseReleaseEvent(event);
1341 setDragMode(QGraphicsView::NoDrag);
1345 #include "clipitem.moc"