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 if (!e.isNull() && e.attribute("type") == "keyframe") {
143 QString def = e.attribute("default");
144 // Effect has a keyframe type parameter, we need to set the values
145 if (e.attribute("keyframes").isEmpty()) {
146 e.setAttribute("keyframes", QString::number(m_cropStart.frames(m_fps)) + ":" + def + ";" + QString::number((m_cropStart + m_cropDuration).frames(m_fps)) + ":" + def);
147 //kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
153 if (effect.attribute("tag") == "volume") {
154 if (effect.attribute("id") == "fadeout") {
155 int end = (duration() + cropStart()).frames(m_fps);
156 int start = end - EffectsList::parameter(effect, "in").toInt();
157 EffectsList::setParameter(effect, "in", QString::number(start));
158 EffectsList::setParameter(effect, "out", QString::number(end));
159 } else if (effect.attribute("id") == "fadein") {
160 int start = cropStart().frames(m_fps);
161 int end = start + EffectsList::parameter(effect, "out").toInt();
162 EffectsList::setParameter(effect, "in", QString::number(start));
163 EffectsList::setParameter(effect, "out", QString::number(end));
168 bool ClipItem::checkKeyFrames() {
169 bool clipEffectsModified = false;
170 for (int ix = 0; ix < m_effectList.count(); ix ++) {
171 QString kfr = keyframes(ix);
172 if (!kfr.isEmpty()) {
173 const QStringList keyframes = kfr.split(";", QString::SkipEmptyParts);
174 QStringList newKeyFrames;
175 bool cutKeyFrame = false;
176 bool modified = false;
178 double lastValue = -1;
179 int start = m_cropStart.frames(m_fps);
180 int end = (m_cropStart + m_cropDuration).frames(m_fps);
181 foreach(const QString str, keyframes) {
182 int pos = str.section(":", 0, 0).toInt();
183 double val = str.section(":", 1, 1).toDouble();
184 if (pos - start < 0) {
185 // a keyframe is defined before the start of the clip
187 } else if (cutKeyFrame) {
188 // create new keyframe at clip start, calculate interpolated value
190 int diff = pos - lastPos;
191 double ratio = (double)(start - lastPos) / diff;
192 double newValue = lastValue + (val - lastValue) * ratio;
193 newKeyFrames.append(QString::number(start) + ":" + QString::number(newValue));
200 // create new keyframe at clip end, calculate interpolated value
201 int diff = pos - lastPos;
203 double ratio = (double)(end - lastPos) / diff;
204 double newValue = lastValue + (val - lastValue) * ratio;
205 newKeyFrames.append(QString::number(end) + ":" + QString::number(newValue));
210 newKeyFrames.append(QString::number(pos) + ":" + QString::number(val));
218 setKeyframes(ix, newKeyFrames.join(";"));
219 clipEffectsModified = true;
223 return clipEffectsModified;
226 void ClipItem::setKeyframes(const int ix, const QString keyframes) {
227 QDomElement effect = effectAt(ix);
228 if (effect.attribute("disabled") == "1") return;
229 QDomNodeList params = effect.elementsByTagName("parameter");
230 for (int i = 0; i < params.count(); i++) {
231 QDomElement e = params.item(i).toElement();
232 if (!e.isNull() && e.attribute("type") == "keyframe") {
233 e.setAttribute("keyframes", keyframes);
234 if (ix == m_selectedEffect) {
236 double max = e.attribute("max").toDouble();
237 double min = e.attribute("min").toDouble();
238 m_keyframeFactor = 100.0 / (max - min);
239 m_keyframeDefault = e.attribute("default").toDouble();
241 const QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
242 foreach(const QString str, keyframes) {
243 int pos = str.section(":", 0, 0).toInt();
244 double val = str.section(":", 1, 1).toDouble();
245 m_keyframes[pos] = val;
256 void ClipItem::setSelectedEffect(const int ix) {
257 m_selectedEffect = ix;
258 QDomElement effect = effectAt(m_selectedEffect);
259 QDomNodeList params = effect.elementsByTagName("parameter");
260 if (effect.attribute("disabled") != "1")
261 for (int i = 0; i < params.count(); i++) {
262 QDomElement e = params.item(i).toElement();
263 if (!e.isNull() && e.attribute("type") == "keyframe") {
265 double max = e.attribute("max").toDouble();
266 double min = e.attribute("min").toDouble();
267 m_keyframeFactor = 100.0 / (max - min);
268 m_keyframeDefault = e.attribute("default").toDouble();
270 const QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
271 foreach(const QString str, keyframes) {
272 int pos = str.section(":", 0, 0).toInt();
273 double val = str.section(":", 1, 1).toDouble();
274 m_keyframes[pos] = val;
280 if (!m_keyframes.isEmpty()) {
286 QString ClipItem::keyframes(const int index) {
288 QDomElement effect = effectAt(index);
289 QDomNodeList params = effect.elementsByTagName("parameter");
291 for (int i = 0; i < params.count(); i++) {
292 QDomElement e = params.item(i).toElement();
293 if (!e.isNull() && e.attribute("type") == "keyframe") {
294 result = e.attribute("keyframes");
301 void ClipItem::updateKeyframeEffect() {
302 // regenerate xml parameter from the clip keyframes
303 QDomElement effect = effectAt(m_selectedEffect);
304 if (effect.attribute("disabled") == "1") return;
305 QDomNodeList params = effect.elementsByTagName("parameter");
307 for (int i = 0; i < params.count(); i++) {
308 QDomElement e = params.item(i).toElement();
309 if (!e.isNull() && e.attribute("type") == "keyframe") {
311 if (m_keyframes.count() > 1) {
312 QMap<int, double>::const_iterator i = m_keyframes.constBegin();
315 while (i != m_keyframes.constEnd()) {
316 keyframes.append(QString::number(i.key()) + ":" + QString::number(i.value()) + ";");
320 // Effect has a keyframe type parameter, we need to set the values
321 //kDebug() << "::::::::::::::: SETTING EFFECT KEYFRAMES: " << keyframes;
322 e.setAttribute("keyframes", keyframes);
328 QDomElement ClipItem::selectedEffect() {
329 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
330 return effectAt(m_selectedEffect);
333 void ClipItem::resetThumbs() {
334 m_startPix = QPixmap();
335 m_endPix = QPixmap();
337 audioThumbCachePic.clear();
341 void ClipItem::refreshClip() {
342 m_maxDuration = m_clip->maxDuration();
343 if (m_clipType == COLOR) {
344 QString colour = m_clip->getProperty("colour");
345 colour = colour.replace(0, 2, "#");
346 setBrush(QColor(colour.left(7)));
347 } else slotFetchThumbs();
350 void ClipItem::slotFetchThumbs() {
351 if (m_endPix.isNull() && m_startPix.isNull()) {
352 m_startThumbRequested = true;
353 m_endThumbRequested = true;
354 emit getThumb((int)cropStart().frames(m_fps), (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
356 if (m_endPix.isNull()) {
359 if (m_startPix.isNull()) {
365 if (m_endPix.isNull() && m_startPix.isNull()) {
366 int frame1 = (int)m_cropStart.frames(m_fps);
367 int frame2 = (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1;
368 //videoThumbProducer.setThumbFrames(m_clip->producer(), frame1, frame2);
369 //videoThumbProducer.start(QThread::LowestPriority);
371 if (m_endPix.isNull()) slotGetEndThumb();
372 else slotGetStartThumb();
375 } else if (m_startPix.isNull()) slotGetStartThumb();*/
378 void ClipItem::slotGetStartThumb() {
379 m_startThumbRequested = true;
380 emit getThumb((int)cropStart().frames(m_fps), -1);
381 //videoThumbProducer.setThumbFrames(m_clip->producer(), (int)m_cropStart.frames(m_fps), - 1);
382 //videoThumbProducer.start(QThread::LowestPriority);
385 void ClipItem::slotGetEndThumb() {
386 m_endThumbRequested = true;
387 emit getThumb(-1, (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
388 //videoThumbProducer.setThumbFrames(m_clip->producer(), -1, (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1);
389 //videoThumbProducer.start(QThread::LowestPriority);
393 void ClipItem::slotSetStartThumb(QImage img) {
394 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
395 QPixmap pix = QPixmap::fromImage(img);
397 QRectF r = sceneBoundingRect();
398 r.setRight(pix.width() + 2);
403 void ClipItem::slotSetEndThumb(QImage img) {
404 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
405 QPixmap pix = QPixmap::fromImage(img);
407 QRectF r = sceneBoundingRect();
408 r.setLeft(r.right() - pix.width() - 2);
413 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
414 if (scene() == NULL) return;
415 QRectF r = sceneBoundingRect();
416 double width = m_startPix.width() / projectScene()->scale();
417 if (m_startThumbRequested && frame == cropStart().frames(m_fps)) {
419 m_startThumbRequested = false;
420 double height = r.height();
421 update(r.x(), r.y(), width, height);
422 } else if (m_endThumbRequested && frame == (cropStart() + cropDuration()).frames(m_fps) - 1) {
424 m_endThumbRequested = false;
425 double height = r.height();
426 update(r.right() - width, r.y(), width, height);
430 void ClipItem::slotSetStartThumb(const QPixmap pix) {
434 void ClipItem::slotSetEndThumb(const QPixmap pix) {
438 QPixmap ClipItem::startThumb() const {
442 QPixmap ClipItem::endThumb() const {
446 void ClipItem::slotGotAudioData() {
447 audioThumbReady = true;
448 if (m_clipType == AV) {
449 QRectF r = boundingRect();
450 r.setTop(r.top() + r.height() / 2 - 1);
455 int ClipItem::type() const {
459 DocClipBase *ClipItem::baseClip() const {
463 QDomElement ClipItem::xml() const {
464 return m_clip->toXML();
467 int ClipItem::clipType() const {
471 QString ClipItem::clipName() const {
475 const QString &ClipItem::clipProducer() const {
479 void ClipItem::flashClip() {
480 if (m_timeLine == 0) {
481 m_timeLine = new QTimeLine(750, this);
482 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
483 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
488 void ClipItem::animate(qreal value) {
489 QRectF r = boundingRect();
495 void ClipItem::paint(QPainter *painter,
496 const QStyleOptionGraphicsItem *option,
498 painter->setOpacity(m_opacity);
499 QBrush paintColor = brush();
500 if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
502 QRectF exposed = option->exposedRect;
503 QRectF mapped = painter->matrix().mapRect(br);
505 const double itemWidth = br.width();
506 const double itemHeight = br.height();
507 const double scale = option->matrix.m11();
510 //painter->setRenderHints(QPainter::Antialiasing);
512 //QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
513 painter->setClipRect(exposed);
515 //build path around clip
516 //QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
517 //painter->fillPath(resultClipPath, paintColor);
518 painter->fillRect(exposed, paintColor);
520 //painter->setClipPath(resultClipPath, Qt::IntersectClip);
523 painter->setMatrixEnabled(false);
525 if (KdenliveSettings::videothumbnails()) {
526 QPen pen = painter->pen();
527 pen.setStyle(Qt::DotLine);
528 pen.setColor(Qt::white);
529 painter->setPen(pen);
530 if (m_clipType == IMAGE && !m_startPix.isNull()) {
531 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_startPix.width(), 0);
532 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_startPix.width(), 0);
533 painter->drawPixmap(p1, m_startPix);
535 painter->drawLine(l);
536 } else if (!m_endPix.isNull()) {
537 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_endPix.width(), 0);
538 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_endPix.width(), 0);
539 painter->drawPixmap(p1, m_endPix);
541 painter->drawLine(l);
543 if (!m_startPix.isNull()) {
544 QPointF p1 = painter->matrix().map(QPointF(0, 0));
545 QPointF p2 = painter->matrix().map(QPointF(0, itemHeight));
546 painter->drawPixmap(p1, m_startPix);
547 QLineF l2(p1.x() + m_startPix.width(), p1.y(), p2.x() + m_startPix.width(), p2.y());
548 painter->drawLine(l2);
550 painter->setPen(Qt::black);
553 // draw audio thumbnails
554 if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && ((m_clipType == AV && exposed.bottom() > (itemHeight / 2)) || m_clipType == AUDIO) && audioThumbReady) {
556 double startpixel = exposed.left();
559 double endpixel = exposed.right();
562 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
564 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
566 if (m_clipType == AV) {
568 re.setTop(re.y() + re.height() / 2);
569 mappedRect = painter->matrix().mapRect(re);
570 //painter->fillRect(mappedRect, QBrush(QColor(200, 200, 200, 140)));
571 } else mappedRect = mapped;
573 int channels = baseClip()->getProperty("channels").toInt();
574 if (scale != framePixelWidth)
575 audioThumbCachePic.clear();
576 double cropLeft = m_cropStart.frames(m_fps);
577 const int clipStart = mappedRect.x();
578 const int mappedStartPixel = painter->matrix().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
579 const int mappedEndPixel = painter->matrix().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
580 cropLeft = cropLeft * scale;
583 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
586 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
587 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
588 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), audioThumbCachePic[startCache]);
593 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
594 QList < CommentedTime >::Iterator it = markers.begin();
597 const int markerwidth = 4;
599 markerBrush = QBrush(QColor(120, 120, 0, 140));
600 QPen pen = painter->pen();
601 pen.setColor(QColor(255, 255, 255, 200));
602 pen.setStyle(Qt::DotLine);
603 painter->setPen(pen);
604 for (; it != markers.end(); ++it) {
605 pos = (*it).time() - cropStart();
606 if (pos > GenTime()) {
607 if (pos > duration()) break;
608 QLineF l(br.x() + pos.frames(m_fps), br.y() + 5, br.x() + pos.frames(m_fps), br.bottom() - 5);
609 QLineF l2 = painter->matrix().map(l);
610 //framepos = scale * pos.frames(m_fps);
611 //QLineF l(framepos, 5, framepos, itemHeight - 5);
612 painter->drawLine(l2);
613 if (KdenliveSettings::showmarkers()) {
614 framepos = br.x() + pos.frames(m_fps);
615 const QRectF r1(framepos + 0.04, 10, itemWidth - framepos - 2, itemHeight - 10);
616 const QRectF r2 = painter->matrix().mapRect(r1);
617 const QRectF txtBounding = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, " " + (*it).comment() + " ");
620 path.addRoundedRect(txtBounding, 3, 3);
621 painter->fillPath(path, markerBrush);
622 painter->drawText(txtBounding, Qt::AlignCenter, (*it).comment());
624 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
627 pen.setColor(Qt::black);
628 pen.setStyle(Qt::SolidLine);
629 painter->setPen(pen);
631 // draw start / end fades
634 fades = QBrush(QColor(200, 50, 50, 150));
635 } else fades = QBrush(QColor(200, 200, 200, 200));
637 if (m_startFade != 0) {
638 QPainterPath fadeInPath;
639 fadeInPath.moveTo(0, 0);
640 fadeInPath.lineTo(0, itemHeight);
641 fadeInPath.lineTo(m_startFade, 0);
642 fadeInPath.closeSubpath();
643 QPainterPath f1 = painter->matrix().map(fadeInPath);
644 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
645 /*if (isSelected()) {
646 QLineF l(m_startFade * scale, 0, 0, itemHeight);
647 painter->drawLine(l);
650 if (m_endFade != 0) {
651 QPainterPath fadeOutPath;
652 fadeOutPath.moveTo(itemWidth, 0);
653 fadeOutPath.lineTo(itemWidth, itemHeight);
654 fadeOutPath.lineTo(itemWidth - m_endFade, 0);
655 fadeOutPath.closeSubpath();
656 QPainterPath f1 = painter->matrix().map(fadeOutPath);
657 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
658 /*if (isSelected()) {
659 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
660 painter->drawLine(l);
664 // Draw effects names
665 if (!m_effectNames.isEmpty() && itemWidth * scale > 40) {
666 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
667 txtBounding.setRight(txtBounding.right() + 15);
668 painter->setPen(Qt::white);
669 QBrush markerBrush(Qt::SolidPattern);
670 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
671 qreal value = m_timeLine->currentValue();
672 txtBounding.setWidth(txtBounding.width() * value);
673 markerBrush.setColor(QColor(50 + 200 * (1.0 - value), 50, 50, 100 + 50 * value));
674 } else markerBrush.setColor(QColor(50, 50, 50, 150));
676 path.addRoundedRect(txtBounding, 4, 4);
677 painter->fillPath(path/*.intersected(resultClipPath)*/, markerBrush);
678 painter->drawText(txtBounding, Qt::AlignCenter, m_effectNames);
679 painter->setPen(Qt::black);
683 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignHCenter | Qt::AlignVCenter, " " + m_clipName + " ");
684 painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
685 //painter->setPen(QColor(0, 0, 0, 180));
686 //painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
687 txtBounding.translate(QPointF(1, 1));
688 painter->setPen(QColor(255, 255, 255, 255));
689 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
692 // draw transition handles on hover
693 if (m_hover && itemWidth * scale > 40) {
694 QPointF p1 = painter->matrix().map(QPointF(0, itemHeight / 2)) + QPointF(10, 0);
695 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
696 p1 = painter->matrix().map(QPointF(itemWidth, itemHeight / 2)) - QPointF(22, 0);
697 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
701 // draw frame around clip
703 pen.setColor(Qt::red);
706 pen.setColor(Qt::black);
710 // draw effect or transition keyframes
711 if (itemWidth > 20) drawKeyFrames(painter, exposed);
713 painter->setMatrixEnabled(true);
717 //kDebug()<<"/// ITEM PAINTING:: exposed="<<exposed<<", RECT = "<<rect();
719 // expand clip rect to allow correct painting of clip border
720 exposed.setRight(exposed.right() + 1 / scale + 0.5);
721 exposed.setBottom(exposed.bottom() + 1);
722 painter->setClipRect(exposed);
723 painter->setPen(pen);
724 painter->drawRect(br);
728 OPERATIONTYPE ClipItem::operationMode(QPointF pos) {
730 m_editedKeyframe = mouseOverKeyFrames(pos);
731 if (m_editedKeyframe != -1) return KEYFRAME;
733 QRectF rect = sceneBoundingRect();
734 const double scale = projectScene()->scale();
735 double maximumOffset = 6 / scale;
737 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
738 if (m_startFade == 0) setToolTip(i18n("Add audio fade"));
739 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_startFade, m_fps).seconds()));
741 } else if (pos.x() - rect.x() < maximumOffset) {
742 setToolTip(i18n("Crop from start: %1s", cropStart().seconds()));
744 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
745 if (m_endFade == 0) setToolTip(i18n("Add audio fade"));
746 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_endFade, m_fps).seconds()));
748 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width()))) < maximumOffset) {
749 setToolTip(i18n("Clip duration: %1s", duration().seconds()));
751 } else if (qAbs((int)(pos.x() - (rect.x() + 16 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
752 setToolTip(i18n("Add transition"));
753 return TRANSITIONSTART;
754 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - 21 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
755 setToolTip(i18n("Add transition"));
756 return TRANSITIONEND;
758 setToolTip(QString());
762 QList <GenTime> ClipItem::snapMarkers() const {
763 QList < GenTime > snaps;
764 QList < GenTime > markers = baseClip()->snapMarkers();
768 for (int i = 0; i < markers.size(); i++) {
769 pos = markers.at(i) - cropStart();
770 if (pos > GenTime()) {
771 if (pos > duration()) break;
772 else snaps.append(pos + startPos());
778 QList <CommentedTime> ClipItem::commentedSnapMarkers() const {
779 QList < CommentedTime > snaps;
780 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
784 for (int i = 0; i < markers.size(); i++) {
785 pos = markers.at(i).time() - cropStart();
786 if (pos > GenTime()) {
787 if (pos > duration()) break;
788 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
794 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels) {
795 QRectF re = sceneBoundingRect();
796 if (m_clipType == AV) re.setTop(re.y() + re.height() / 2);
798 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
799 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
801 for (int startCache = startpixel - startpixel % 100;startCache < endpixel;startCache += 100) {
802 //kDebug() << "creating " << startCache;
803 //if (framePixelWidth!=pixelForOneFrame ||
804 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
806 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
807 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
808 audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
810 bool fullAreaDraw = pixelForOneFrame < 10;
811 QMap<int, QPainterPath > positiveChannelPaths;
812 QMap<int, QPainterPath > negativeChannelPaths;
813 QPainter pixpainter(&audioThumbCachePic[startCache]);
815 audiopen.setWidth(0);
816 pixpainter.setPen(audiopen);
817 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
818 //pixpainter.drawLine(0,0,100,re.height());
819 // Bail out, if caller provided invalid data
821 kWarning() << "Unable to draw image with " << channels << "number of channels";
825 int channelHeight = audioThumbCachePic[startCache].height() / channels;
827 for (int i = 0;i < channels;i++) {
829 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
830 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
833 for (int samples = 0;samples <= 100;samples++) {
834 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
835 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
836 if (frame < 0 || sample < 0 || sample > 19)
838 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
840 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
842 int y = channelHeight * channel + channelHeight / 2;
843 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
845 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
846 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
848 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
849 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
852 for (int channel = 0;channel < channels ;channel++)
853 if (fullAreaDraw && samples == 100) {
854 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
855 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
856 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
857 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
861 if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
863 pixpainter.setPen(QPen(QColor(0, 0, 0)));
864 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
866 for (int i = 0;i < channels;i++) {
868 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
869 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
871 pixpainter.drawPath(positiveChannelPaths[i]);
874 //audioThumbWasDrawn=true;
875 framePixelWidth = pixelForOneFrame;
880 uint ClipItem::fadeIn() const {
884 uint ClipItem::fadeOut() const {
889 void ClipItem::setFadeIn(int pos) {
890 if (pos == m_startFade) return;
891 int oldIn = m_startFade;
892 if (pos < 0) pos = 0;
893 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
895 QRectF rect = boundingRect();
896 update(rect.x(), rect.y(), qMax(oldIn, pos), rect.height());
899 void ClipItem::setFadeOut(int pos) {
900 if (pos == m_endFade) return;
901 int oldOut = m_endFade;
902 if (pos < 0) pos = 0;
903 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
905 QRectF rect = boundingRect();
906 update(rect.x() + rect.width() - qMax(oldOut, pos), rect.y(), qMax(oldOut, pos), rect.height());
911 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
912 /*m_resizeMode = operationMode(event->pos());
913 if (m_resizeMode == MOVE) {
914 m_maxTrack = scene()->sceneRect().height();
915 m_grabPoint = (int) (event->pos().x() - rect().x());
917 QGraphicsRectItem::mousePressEvent(event);
921 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
923 QGraphicsRectItem::mouseReleaseEvent(event);
927 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e) {
928 //if (e->pos().x() < 20) m_hover = true;
930 QRectF r = boundingRect();
931 double width = 35 / projectScene()->scale();
932 double height = r.height() / 2;
933 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
934 update(r.x(), r.y() + height, width, height);
935 update(r.right() - width, r.y() + height, width, height);
939 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
941 QRectF r = boundingRect();
942 double width = 35 / projectScene()->scale();
943 double height = r.height() / 2;
944 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
945 update(r.x(), r.y() + height, width, height);
946 update(r.right() - width, r.y() + height, width, height);
949 void ClipItem::resizeStart(int posx, double speed) {
950 const int min = (startPos() - cropStart()).frames(m_fps);
951 if (posx < min) posx = min;
952 if (posx == startPos().frames(m_fps)) return;
953 const int previous = cropStart().frames(m_fps);
954 AbstractClipItem::resizeStart(posx, m_speed);
955 checkEffectsKeyframesPos(previous, cropStart().frames(m_fps), true);
956 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
957 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
958 startThumbTimer->start(100);
962 void ClipItem::resizeEnd(int posx, double speed, bool updateKeyFrames) {
963 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps) + 1;
964 if (posx > max) posx = max;
965 if (posx == endPos().frames(m_fps)) return;
966 //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
967 const int previous = (cropStart() + duration()).frames(m_fps);
968 AbstractClipItem::resizeEnd(posx, m_speed);
969 if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false);
970 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
971 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
972 endThumbTimer->start(100);
977 void ClipItem::checkEffectsKeyframesPos(const int previous, const int current, bool fromStart) {
978 for (int i = 0; i < m_effectList.size(); i++) {
979 QDomElement effect = m_effectList.at(i);
980 QDomNodeList params = effect.elementsByTagName("parameter");
981 for (int j = 0; j < params.count(); j++) {
982 QDomElement e = params.item(i).toElement();
983 if (e.attribute("type") == "keyframe") {
984 // parse keyframes and adjust values
985 const QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
986 QMap <int, double> kfr;
989 foreach(const QString str, keyframes) {
990 pos = str.section(":", 0, 0).toInt();
991 val = str.section(":", 1, 1).toDouble();
992 if (pos == previous) kfr[current] = val;
994 if (fromStart && pos >= current) kfr[pos] = val;
995 else if (!fromStart && pos <= current) kfr[pos] = val;
999 QMap<int, double>::const_iterator k = kfr.constBegin();
1000 while (k != kfr.constEnd()) {
1001 newkfr.append(QString::number(k.key()) + ":" + QString::number(k.value()) + ";");
1004 e.setAttribute("keyframes", newkfr);
1009 if (m_selectedEffect >= 0) setSelectedEffect(m_selectedEffect);
1013 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value) {
1014 if (change == ItemPositionChange && scene()) {
1015 // calculate new position.
1016 if (group()) return pos();
1017 QPointF newPos = value.toPointF();
1018 // kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1019 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1020 xpos = qMax(xpos, 0);
1022 int newTrack = newPos.y() / KdenliveSettings::trackheight();
1023 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1024 newTrack = qMax(newTrack, 0);
1025 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1026 // Only one clip is moving
1027 QRectF sceneShape = rect();
1028 sceneShape.translate(newPos);
1029 QList<QGraphicsItem*> items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1030 items.removeAll(this);
1032 if (!items.isEmpty()) {
1033 for (int i = 0; i < items.count(); i++) {
1034 if (items.at(i)->type() == type()) {
1036 QPointF otherPos = items.at(i)->pos();
1037 if ((int) otherPos.y() != (int) pos().y()) {
1040 if (pos().x() < otherPos.x()) {
1041 // move clip just before colliding clip
1042 int npos = (static_cast < AbstractClipItem* >(items.at(i))->startPos() - m_cropDuration).frames(m_fps);
1043 // check we don't run into another clip
1045 sceneShape = rect();
1046 sceneShape.translate(newPos);
1047 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1048 items.removeAll(this);
1049 for (int j = 0; j < subitems.count(); j++) {
1050 if (subitems.at(j)->type() == type()) return pos();
1053 // get pos just after colliding clip
1054 int npos = static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps);
1055 // check we don't run into another clip
1057 sceneShape = rect();
1058 sceneShape.translate(newPos);
1059 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1060 items.removeAll(this);
1061 for (int j = 0; j < subitems.count(); j++) {
1062 if (subitems.at(j)->type() == type()) return pos();
1066 m_startPos = GenTime((int) newPos.x(), m_fps);
1072 m_startPos = GenTime((int) newPos.x(), m_fps);
1073 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1076 return QGraphicsItem::itemChange(change, value);
1080 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1083 int ClipItem::effectsCounter() {
1084 return effectsCount() + 1;
1087 int ClipItem::effectsCount() {
1088 return m_effectList.size();
1091 int ClipItem::hasEffect(const QString &tag, const QString &id) const {
1092 return m_effectList.hasEffect(tag, id);
1095 QStringList ClipItem::effectNames() {
1096 return m_effectList.effectNames();
1099 QDomElement ClipItem::effectAt(int ix) {
1100 if (ix > m_effectList.count() - 1 || ix < 0) return QDomElement();
1101 return m_effectList.at(ix);
1104 void ClipItem::setEffectAt(int ix, QDomElement effect) {
1105 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1106 effect.setAttribute("kdenlive_ix", ix + 1);
1107 m_effectList.insert(ix, effect);
1108 m_effectList.removeAt(ix + 1);
1109 m_effectNames = m_effectList.effectNames().join(" / ");
1110 if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fadeout") update(boundingRect());
1112 QRectF r = boundingRect();
1118 QHash <QString, QString> ClipItem::addEffect(QDomElement effect, bool animate) {
1119 QHash <QString, QString> effectParams;
1120 bool needRepaint = false;
1122 doc.appendChild(doc.importNode(effect, true));
1123 kDebug() << "/////// CLIPÂ ADD EFFECT: " << doc.toString();*/
1124 m_effectList.append(effect);
1125 effectParams["tag"] = effect.attribute("tag");
1126 QString effectId = effect.attribute("id");
1127 if (effectId.isEmpty()) effectId = effect.attribute("tag");
1128 effectParams["id"] = effectId;
1129 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
1130 QString state = effect.attribute("disabled");
1131 if (!state.isEmpty()) effectParams["disabled"] = state;
1132 QDomNodeList params = effect.elementsByTagName("parameter");
1134 for (int i = 0; i < params.count(); i++) {
1135 QDomElement e = params.item(i).toElement();
1137 if (e.attribute("type") == "keyframe") {
1138 effectParams["keyframes"] = e.attribute("keyframes");
1139 effectParams["min"] = e.attribute("min");
1140 effectParams["max"] = e.attribute("max");
1141 effectParams["factor"] = e.attribute("factor", "1");
1142 effectParams["starttag"] = e.attribute("starttag", "start");
1143 effectParams["endtag"] = e.attribute("endtag", "end");
1146 double f = e.attribute("factor", "1").toDouble();
1149 effectParams[e.attribute("name")] = e.attribute("value");
1150 // check if it is a fade effect
1151 if (effectId == "fadein") {
1153 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1154 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1155 } else if (effectId == "fadeout") {
1157 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1158 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1161 effectParams[e.attribute("name")] = QString::number(e.attribute("value").toDouble() / f);
1165 m_effectNames = m_effectList.effectNames().join(" / ");
1166 if (fade > 0) m_startFade = fade;
1167 else if (fade < 0) m_endFade = -fade;
1168 if (needRepaint) update(boundingRect());
1171 } else if (!needRepaint) {
1172 QRectF r = boundingRect();
1176 if (m_selectedEffect == -1) {
1177 m_selectedEffect = 0;
1178 setSelectedEffect(m_selectedEffect);
1180 return effectParams;
1183 QHash <QString, QString> ClipItem::getEffectArgs(QDomElement effect) {
1184 QHash <QString, QString> effectParams;
1185 effectParams["tag"] = effect.attribute("tag");
1186 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
1187 effectParams["id"] = effect.attribute("id");
1188 QString state = effect.attribute("disabled");
1189 if (!state.isEmpty()) effectParams["disabled"] = state;
1190 QDomNodeList params = effect.elementsByTagName("parameter");
1191 for (int i = 0; i < params.count(); i++) {
1192 QDomElement e = params.item(i).toElement();
1193 //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
1194 if (e.attribute("type") == "keyframe") {
1195 kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
1196 effectParams["keyframes"] = e.attribute("keyframes");
1197 effectParams["max"] = e.attribute("max");
1198 effectParams["min"] = e.attribute("min");
1199 effectParams["factor"] = e.attribute("factor", "1");
1200 effectParams["starttag"] = e.attribute("starttag", "start");
1201 effectParams["endtag"] = e.attribute("endtag", "end");
1202 } else if (e.attribute("namedesc").contains(";")) {
1203 QString format = e.attribute("format");
1204 QStringList separators = format.split("%d", QString::SkipEmptyParts);
1205 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
1207 QTextStream txtNeu(&neu);
1208 if (values.size() > 0)
1209 txtNeu << (int)values[0].toDouble();
1210 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
1211 txtNeu << separators[i];
1212 txtNeu << (int)(values[i+1].toDouble());
1214 effectParams["start"] = neu;
1216 if (e.attribute("factor", "1") != "1")
1217 effectParams[e.attribute("name")] = QString::number(e.attribute("value").toDouble() / e.attribute("factor").toDouble());
1218 else effectParams[e.attribute("name")] = e.attribute("value");
1221 return effectParams;
1224 void ClipItem::deleteEffect(QString index) {
1225 bool needRepaint = false;
1227 for (int i = 0; i < m_effectList.size(); ++i) {
1228 ix = m_effectList.at(i).attribute("kdenlive_ix");
1230 if (m_effectList.at(i).attribute("id") == "fadein") {
1233 } else if (m_effectList.at(i).attribute("id") == "fadeout") {
1237 m_effectList.removeAt(i);
1238 } else if (ix.toInt() > index.toInt()) m_effectList[i].setAttribute("kdenlive_ix", ix.toInt() - 1);
1240 m_effectNames = m_effectList.effectNames().join(" / ");
1241 if (needRepaint) update(boundingRect());
1245 double ClipItem::speed() const {
1249 void ClipItem::setSpeed(const double speed) {
1251 if (m_speed == 1.0) m_clipName = baseClip()->name();
1252 else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + "%";
1256 GenTime ClipItem::maxDuration() const {
1257 return m_maxDuration / m_speed;
1260 GenTime ClipItem::cropStart() const {
1261 return m_cropStart / m_speed;
1264 GenTime ClipItem::cropDuration() const {
1265 return m_cropDuration / m_speed;
1268 GenTime ClipItem::endPos() const {
1269 return m_startPos + cropDuration();
1273 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
1274 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
1276 doc.setContent(effects, true);
1277 QDomElement e = doc.documentElement();
1278 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1279 if (view) view->slotAddEffect(e, m_startPos, track());
1283 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
1284 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
1287 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
1290 void ClipItem::addTransition(Transition* t) {
1291 m_transitionsList.append(t);
1292 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1294 QDomElement e = doc.documentElement();
1295 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1299 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
1301 int pos = event->x();
1302 if (event->modifiers() == Qt::ControlModifier)
1303 setDragMode(QGraphicsView::ScrollHandDrag);
1304 else if (event->modifiers() == Qt::ShiftModifier)
1305 setDragMode(QGraphicsView::RubberBandDrag);
1307 QGraphicsItem * item = itemAt(event->pos());
1310 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
1313 QGraphicsView::mousePressEvent(event);
1316 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
1318 QGraphicsView::mouseReleaseEvent(event);
1319 setDragMode(QGraphicsView::NoDrag);
1323 #include "clipitem.moc"