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, double speed, 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(speed), 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 if (m_speed == 1.0) m_clipName = clip->name();
51 m_clipName = clip->name() + " - " + QString::number(m_speed * 100, 'f', 0) + "%";
52 m_cropDuration = m_cropDuration * m_speed;
54 m_producer = clip->getId();
55 m_clipType = clip->clipType();
56 m_cropStart = info.cropStart;
57 m_maxDuration = clip->maxDuration();
59 audioThumbReady = clip->audioThumbCreated();
62 m_cropStart = xml.attribute("in", 0).toInt();
63 m_maxDuration = xml.attribute("duration", 0).toInt();
64 if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
66 if (duration != -1) m_cropDuration = duration;
67 else m_cropDuration = m_maxDuration;*/
70 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
71 setAcceptsHoverEvents(true);
72 connect(this , SIGNAL(prepareAudioThumb(double, int, int, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int)));
74 setBrush(QColor(141, 166, 215));
75 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
77 startThumbTimer = new QTimer(this);
78 startThumbTimer->setSingleShot(true);
79 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
80 endThumbTimer = new QTimer(this);
81 endThumbTimer->setSingleShot(true);
82 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
84 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
85 //connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(getVideoThumbs(int, int)));
87 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
88 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
89 if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs()));
91 /*if (m_clip->producer()) {
92 videoThumbProducer.init(this, m_clip->producer(), KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio(), KdenliveSettings::trackheight());
95 } else if (m_clipType == COLOR) {
96 QString colour = clip->getProperty("colour");
97 colour = colour.replace(0, 2, "#");
98 setBrush(QColor(colour.left(7)));
99 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
100 m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
101 m_endPix = m_startPix;
102 } else if (m_clipType == AUDIO) {
103 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
108 ClipItem::~ClipItem() {
109 if (startThumbTimer) delete startThumbTimer;
110 if (endThumbTimer) delete endThumbTimer;
111 if (m_timeLine) m_timeLine;
114 ClipItem *ClipItem::clone(ItemInfo info) const {
115 ClipItem *duplicate = new ClipItem(m_clip, info, m_fps, m_speed);
116 if (info.cropStart == cropStart()) duplicate->slotSetStartThumb(m_startPix);
117 if (info.cropStart + (info.endPos - info.startPos) == m_cropStart + m_cropDuration) duplicate->slotSetEndThumb(m_endPix);
118 kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
119 duplicate->setEffectList(m_effectList.clone());
120 //duplicate->setSpeed(m_speed);
124 void ClipItem::setEffectList(const EffectsList effectList) {
125 m_effectList = effectList;
126 m_effectNames = m_effectList.effectNames().join(" / ");
129 const EffectsList ClipItem::effectList() {
133 int ClipItem::selectedEffectIndex() const {
134 return m_selectedEffect;
137 void ClipItem::initEffect(QDomElement effect) {
138 // the kdenlive_ix int is used to identify an effect in mlt's playlist, should
140 if (effect.attribute("kdenlive_ix").toInt() == 0)
141 effect.setAttribute("kdenlive_ix", QString::number(effectsCounter()));
142 // init keyframes if required
143 QDomNodeList params = effect.elementsByTagName("parameter");
144 for (int i = 0; i < params.count(); i++) {
145 QDomElement e = params.item(i).toElement();
146 kDebug() << "// inint eff: " << e.attribute("name");
147 if (!e.isNull() && e.attribute("type") == "keyframe") {
148 QString def = e.attribute("default");
149 // Effect has a keyframe type parameter, we need to set the values
150 if (e.attribute("keyframes").isEmpty()) {
151 e.setAttribute("keyframes", QString::number(m_cropStart.frames(m_fps)) + ":" + def + ";" + QString::number((m_cropStart + m_cropDuration).frames(m_fps)) + ":" + def);
152 //kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
158 if (effect.attribute("tag") == "volume") {
159 if (effect.attribute("id") == "fadeout") {
160 int end = (duration() + cropStart()).frames(m_fps);
161 int start = end - EffectsList::parameter(effect, "in").toInt();
162 EffectsList::setParameter(effect, "in", QString::number(start));
163 EffectsList::setParameter(effect, "out", QString::number(end));
164 } else if (effect.attribute("id") == "fadein") {
165 int start = cropStart().frames(m_fps);
166 int end = start + EffectsList::parameter(effect, "out").toInt();
167 EffectsList::setParameter(effect, "in", QString::number(start));
168 EffectsList::setParameter(effect, "out", QString::number(end));
173 bool ClipItem::checkKeyFrames() {
174 bool clipEffectsModified = false;
175 for (int ix = 0; ix < m_effectList.count(); ix ++) {
176 QString kfr = keyframes(ix);
177 if (!kfr.isEmpty()) {
178 const QStringList keyframes = kfr.split(";", QString::SkipEmptyParts);
179 QStringList newKeyFrames;
180 bool cutKeyFrame = false;
181 bool modified = false;
183 double lastValue = -1;
184 int start = m_cropStart.frames(m_fps);
185 int end = (m_cropStart + m_cropDuration).frames(m_fps);
186 foreach(const QString str, keyframes) {
187 int pos = str.section(":", 0, 0).toInt();
188 double val = str.section(":", 1, 1).toDouble();
189 if (pos - start < 0) {
190 // a keyframe is defined before the start of the clip
192 } else if (cutKeyFrame) {
193 // create new keyframe at clip start, calculate interpolated value
195 int diff = pos - lastPos;
196 double ratio = (double)(start - lastPos) / diff;
197 double newValue = lastValue + (val - lastValue) * ratio;
198 newKeyFrames.append(QString::number(start) + ":" + QString::number(newValue));
205 // create new keyframe at clip end, calculate interpolated value
206 int diff = pos - lastPos;
208 double ratio = (double)(end - lastPos) / diff;
209 double newValue = lastValue + (val - lastValue) * ratio;
210 newKeyFrames.append(QString::number(end) + ":" + QString::number(newValue));
215 newKeyFrames.append(QString::number(pos) + ":" + QString::number(val));
223 setKeyframes(ix, newKeyFrames.join(";"));
224 clipEffectsModified = true;
228 return clipEffectsModified;
231 void ClipItem::setKeyframes(const int ix, const QString keyframes) {
232 QDomElement effect = effectAt(ix);
233 if (effect.attribute("disabled") == "1") return;
234 QDomNodeList params = effect.elementsByTagName("parameter");
235 for (int i = 0; i < params.count(); i++) {
236 QDomElement e = params.item(i).toElement();
237 if (!e.isNull() && e.attribute("type") == "keyframe") {
238 e.setAttribute("keyframes", keyframes);
239 if (ix == m_selectedEffect) {
241 double max = e.attribute("max").toDouble();
242 double min = e.attribute("min").toDouble();
243 m_keyframeFactor = 100.0 / (max - min);
244 m_keyframeDefault = e.attribute("default").toDouble();
246 const QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
247 foreach(const QString str, keyframes) {
248 int pos = str.section(":", 0, 0).toInt();
249 double val = str.section(":", 1, 1).toDouble();
250 m_keyframes[pos] = val;
261 void ClipItem::setSelectedEffect(const int ix) {
262 m_selectedEffect = ix;
263 QDomElement effect = effectAt(m_selectedEffect);
264 QDomNodeList params = effect.elementsByTagName("parameter");
265 if (effect.attribute("disabled") != "1")
266 for (int i = 0; i < params.count(); i++) {
267 QDomElement e = params.item(i).toElement();
268 if (!e.isNull() && e.attribute("type") == "keyframe") {
270 double max = e.attribute("max").toDouble();
271 double min = e.attribute("min").toDouble();
272 m_keyframeFactor = 100.0 / (max - min);
273 m_keyframeDefault = e.attribute("default").toDouble();
275 const QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
276 foreach(const QString str, keyframes) {
277 int pos = str.section(":", 0, 0).toInt();
278 double val = str.section(":", 1, 1).toDouble();
279 m_keyframes[pos] = val;
285 if (!m_keyframes.isEmpty()) {
291 QString ClipItem::keyframes(const int index) {
293 QDomElement effect = effectAt(index);
294 QDomNodeList params = effect.elementsByTagName("parameter");
296 for (int i = 0; i < params.count(); i++) {
297 QDomElement e = params.item(i).toElement();
298 if (!e.isNull() && e.attribute("type") == "keyframe") {
299 result = e.attribute("keyframes");
306 void ClipItem::updateKeyframeEffect() {
307 // regenerate xml parameter from the clip keyframes
308 QDomElement effect = effectAt(m_selectedEffect);
309 if (effect.attribute("disabled") == "1") return;
310 QDomNodeList params = effect.elementsByTagName("parameter");
312 for (int i = 0; i < params.count(); i++) {
313 QDomElement e = params.item(i).toElement();
314 if (!e.isNull() && e.attribute("type") == "keyframe") {
316 if (m_keyframes.count() > 1) {
317 QMap<int, double>::const_iterator i = m_keyframes.constBegin();
320 while (i != m_keyframes.constEnd()) {
321 keyframes.append(QString::number(i.key()) + ":" + QString::number(i.value()) + ";");
325 // Effect has a keyframe type parameter, we need to set the values
326 //kDebug() << "::::::::::::::: SETTING EFFECT KEYFRAMES: " << keyframes;
327 e.setAttribute("keyframes", keyframes);
333 QDomElement ClipItem::selectedEffect() {
334 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
335 return effectAt(m_selectedEffect);
338 void ClipItem::resetThumbs() {
339 m_startPix = QPixmap();
340 m_endPix = QPixmap();
342 audioThumbCachePic.clear();
346 void ClipItem::refreshClip() {
347 m_maxDuration = m_clip->maxDuration();
348 if (m_clipType == COLOR) {
349 QString colour = m_clip->getProperty("colour");
350 colour = colour.replace(0, 2, "#");
351 setBrush(QColor(colour.left(7)));
352 } else slotFetchThumbs();
355 void ClipItem::slotFetchThumbs() {
356 if (m_endPix.isNull() && m_startPix.isNull()) {
357 m_startThumbRequested = true;
358 m_endThumbRequested = true;
359 emit getThumb((int)cropStart().frames(m_fps), (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
361 if (m_endPix.isNull()) {
364 if (m_startPix.isNull()) {
370 if (m_endPix.isNull() && m_startPix.isNull()) {
371 int frame1 = (int)m_cropStart.frames(m_fps);
372 int frame2 = (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1;
373 //videoThumbProducer.setThumbFrames(m_clip->producer(), frame1, frame2);
374 //videoThumbProducer.start(QThread::LowestPriority);
376 if (m_endPix.isNull()) slotGetEndThumb();
377 else slotGetStartThumb();
380 } else if (m_startPix.isNull()) slotGetStartThumb();*/
383 void ClipItem::slotGetStartThumb() {
384 m_startThumbRequested = true;
385 emit getThumb((int)cropStart().frames(m_fps), -1);
386 //videoThumbProducer.setThumbFrames(m_clip->producer(), (int)m_cropStart.frames(m_fps), - 1);
387 //videoThumbProducer.start(QThread::LowestPriority);
390 void ClipItem::slotGetEndThumb() {
391 m_endThumbRequested = true;
392 emit getThumb(-1, (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
393 //videoThumbProducer.setThumbFrames(m_clip->producer(), -1, (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1);
394 //videoThumbProducer.start(QThread::LowestPriority);
398 void ClipItem::slotSetStartThumb(QImage img) {
399 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
400 QPixmap pix = QPixmap::fromImage(img);
402 QRectF r = sceneBoundingRect();
403 r.setRight(pix.width() + 2);
408 void ClipItem::slotSetEndThumb(QImage img) {
409 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
410 QPixmap pix = QPixmap::fromImage(img);
412 QRectF r = sceneBoundingRect();
413 r.setLeft(r.right() - pix.width() - 2);
418 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
419 if (scene() == NULL) return;
420 QRectF r = sceneBoundingRect();
421 double width = m_startPix.width() / projectScene()->scale();
422 if (m_startThumbRequested && frame == cropStart().frames(m_fps)) {
424 m_startThumbRequested = false;
425 double height = r.height();
426 update(r.x(), r.y(), width, height);
427 } else if (m_endThumbRequested && frame == (cropStart() + cropDuration()).frames(m_fps) - 1) {
429 m_endThumbRequested = false;
430 double height = r.height();
431 update(r.right() - width, r.y(), width, height);
435 void ClipItem::slotSetStartThumb(const QPixmap pix) {
439 void ClipItem::slotSetEndThumb(const QPixmap pix) {
443 QPixmap ClipItem::startThumb() const {
447 QPixmap ClipItem::endThumb() const {
451 void ClipItem::slotGotAudioData() {
452 audioThumbReady = true;
453 if (m_clipType == AV) {
454 QRectF r = boundingRect();
455 r.setTop(r.top() + r.height() / 2 - 1);
460 int ClipItem::type() const {
464 DocClipBase *ClipItem::baseClip() const {
468 QDomElement ClipItem::xml() const {
469 QDomElement xml = m_clip->toXML();
470 if (m_speed != 1.0) xml.setAttribute("speed", m_speed);
474 int ClipItem::clipType() const {
478 QString ClipItem::clipName() const {
482 void ClipItem::setClipName(const QString &name) {
486 const QString &ClipItem::clipProducer() const {
490 void ClipItem::flashClip() {
491 if (m_timeLine == 0) {
492 m_timeLine = new QTimeLine(750, this);
493 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
494 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
499 void ClipItem::animate(qreal value) {
500 QRectF r = boundingRect();
506 void ClipItem::paint(QPainter *painter,
507 const QStyleOptionGraphicsItem *option,
509 /*if (parentItem()) m_opacity = 0.5;
510 else m_opacity = 1.0;
511 painter->setOpacity(m_opacity);*/
512 QBrush paintColor = brush();
513 if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
515 QRectF exposed = option->exposedRect;
516 QRectF mapped = painter->matrix().mapRect(br);
518 const double itemWidth = br.width();
519 const double itemHeight = br.height();
520 const double scale = option->matrix.m11();
523 //painter->setRenderHints(QPainter::Antialiasing);
525 //QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
526 painter->setClipRect(exposed);
528 //build path around clip
529 //QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
530 //painter->fillPath(resultClipPath, paintColor);
531 painter->fillRect(exposed, paintColor);
533 //painter->setClipPath(resultClipPath, Qt::IntersectClip);
536 painter->setMatrixEnabled(false);
538 if (KdenliveSettings::videothumbnails()) {
539 QPen pen = painter->pen();
540 pen.setStyle(Qt::DotLine);
541 pen.setColor(Qt::white);
542 painter->setPen(pen);
543 if (m_clipType == IMAGE && !m_startPix.isNull()) {
544 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_startPix.width(), 0);
545 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_startPix.width(), 0);
546 painter->drawPixmap(p1, m_startPix);
548 painter->drawLine(l);
549 } else if (!m_endPix.isNull()) {
550 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_endPix.width(), 0);
551 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_endPix.width(), 0);
552 painter->drawPixmap(p1, m_endPix);
554 painter->drawLine(l);
556 if (!m_startPix.isNull()) {
557 QPointF p1 = painter->matrix().map(QPointF(0, 0));
558 QPointF p2 = painter->matrix().map(QPointF(0, itemHeight));
559 painter->drawPixmap(p1, m_startPix);
560 QLineF l2(p1.x() + m_startPix.width(), p1.y(), p2.x() + m_startPix.width(), p2.y());
561 painter->drawLine(l2);
563 painter->setPen(Qt::black);
566 // draw audio thumbnails
567 if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && ((m_clipType == AV && exposed.bottom() > (itemHeight / 2)) || m_clipType == AUDIO) && audioThumbReady) {
569 double startpixel = exposed.left();
572 double endpixel = exposed.right();
575 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
577 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
579 if (m_clipType == AV) {
581 re.setTop(re.y() + re.height() / 2);
582 mappedRect = painter->matrix().mapRect(re);
583 //painter->fillRect(mappedRect, QBrush(QColor(200, 200, 200, 140)));
584 } else mappedRect = mapped;
586 int channels = baseClip()->getProperty("channels").toInt();
587 if (scale != framePixelWidth)
588 audioThumbCachePic.clear();
589 double cropLeft = m_cropStart.frames(m_fps);
590 const int clipStart = mappedRect.x();
591 const int mappedStartPixel = painter->matrix().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
592 const int mappedEndPixel = painter->matrix().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
593 cropLeft = cropLeft * scale;
596 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
599 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
600 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
601 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), audioThumbCachePic[startCache]);
606 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
607 QList < CommentedTime >::Iterator it = markers.begin();
610 const int markerwidth = 4;
612 markerBrush = QBrush(QColor(120, 120, 0, 140));
613 QPen pen = painter->pen();
614 pen.setColor(QColor(255, 255, 255, 200));
615 pen.setStyle(Qt::DotLine);
616 painter->setPen(pen);
617 for (; it != markers.end(); ++it) {
618 pos = (*it).time() - cropStart();
619 if (pos > GenTime()) {
620 if (pos > duration()) break;
621 QLineF l(br.x() + pos.frames(m_fps), br.y() + 5, br.x() + pos.frames(m_fps), br.bottom() - 5);
622 QLineF l2 = painter->matrix().map(l);
623 //framepos = scale * pos.frames(m_fps);
624 //QLineF l(framepos, 5, framepos, itemHeight - 5);
625 painter->drawLine(l2);
626 if (KdenliveSettings::showmarkers()) {
627 framepos = br.x() + pos.frames(m_fps);
628 const QRectF r1(framepos + 0.04, 10, itemWidth - framepos - 2, itemHeight - 10);
629 const QRectF r2 = painter->matrix().mapRect(r1);
630 const QRectF txtBounding = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, " " + (*it).comment() + " ");
633 path.addRoundedRect(txtBounding, 3, 3);
634 painter->fillPath(path, markerBrush);
635 painter->drawText(txtBounding, Qt::AlignCenter, (*it).comment());
637 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
640 pen.setColor(Qt::black);
641 pen.setStyle(Qt::SolidLine);
642 painter->setPen(pen);
644 // draw start / end fades
647 fades = QBrush(QColor(200, 50, 50, 150));
648 } else fades = QBrush(QColor(200, 200, 200, 200));
650 if (m_startFade != 0) {
651 QPainterPath fadeInPath;
652 fadeInPath.moveTo(0, 0);
653 fadeInPath.lineTo(0, itemHeight);
654 fadeInPath.lineTo(m_startFade, 0);
655 fadeInPath.closeSubpath();
656 QPainterPath f1 = painter->matrix().map(fadeInPath);
657 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
658 /*if (isSelected()) {
659 QLineF l(m_startFade * scale, 0, 0, itemHeight);
660 painter->drawLine(l);
663 if (m_endFade != 0) {
664 QPainterPath fadeOutPath;
665 fadeOutPath.moveTo(itemWidth, 0);
666 fadeOutPath.lineTo(itemWidth, itemHeight);
667 fadeOutPath.lineTo(itemWidth - m_endFade, 0);
668 fadeOutPath.closeSubpath();
669 QPainterPath f1 = painter->matrix().map(fadeOutPath);
670 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
671 /*if (isSelected()) {
672 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
673 painter->drawLine(l);
677 // Draw effects names
678 if (!m_effectNames.isEmpty() && itemWidth * scale > 40) {
679 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
680 txtBounding.setRight(txtBounding.right() + 15);
681 painter->setPen(Qt::white);
682 QBrush markerBrush(Qt::SolidPattern);
683 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
684 qreal value = m_timeLine->currentValue();
685 txtBounding.setWidth(txtBounding.width() * value);
686 markerBrush.setColor(QColor(50 + 200 * (1.0 - value), 50, 50, 100 + 50 * value));
687 } else markerBrush.setColor(QColor(50, 50, 50, 150));
689 path.addRoundedRect(txtBounding, 4, 4);
690 painter->fillPath(path/*.intersected(resultClipPath)*/, markerBrush);
691 painter->drawText(txtBounding, Qt::AlignCenter, m_effectNames);
692 painter->setPen(Qt::black);
696 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignHCenter | Qt::AlignVCenter, " " + m_clipName + " ");
697 painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
698 //painter->setPen(QColor(0, 0, 0, 180));
699 //painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
700 txtBounding.translate(QPointF(1, 1));
701 painter->setPen(QColor(255, 255, 255, 255));
702 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
705 // draw transition handles on hover
706 if (m_hover && itemWidth * scale > 40) {
707 QPointF p1 = painter->matrix().map(QPointF(0, itemHeight / 2)) + QPointF(10, 0);
708 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
709 p1 = painter->matrix().map(QPointF(itemWidth, itemHeight / 2)) - QPointF(22, 0);
710 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
714 // draw frame around clip
716 pen.setColor(Qt::red);
719 pen.setColor(Qt::black);
723 // draw effect or transition keyframes
724 if (itemWidth > 20) drawKeyFrames(painter, exposed);
726 painter->setMatrixEnabled(true);
730 //kDebug()<<"/// ITEM PAINTING:: exposed="<<exposed<<", RECT = "<<rect();
732 // expand clip rect to allow correct painting of clip border
733 exposed.setRight(exposed.right() + 1 / scale + 0.5);
734 exposed.setBottom(exposed.bottom() + 1);
735 painter->setClipRect(exposed);
736 painter->setPen(pen);
737 painter->drawRect(br);
741 OPERATIONTYPE ClipItem::operationMode(QPointF pos) {
742 if (isItemLocked()) return NONE;
745 m_editedKeyframe = mouseOverKeyFrames(pos);
746 if (m_editedKeyframe != -1) return KEYFRAME;
748 QRectF rect = sceneBoundingRect();
749 const double scale = projectScene()->scale();
750 double maximumOffset = 6 / scale;
752 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
753 if (m_startFade == 0) setToolTip(i18n("Add audio fade"));
754 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_startFade, m_fps).seconds()));
756 } else if (pos.x() - rect.x() < maximumOffset) {
757 setToolTip(i18n("Crop from start: %1s", cropStart().seconds()));
759 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
760 if (m_endFade == 0) setToolTip(i18n("Add audio fade"));
761 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_endFade, m_fps).seconds()));
763 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width()))) < maximumOffset) {
764 setToolTip(i18n("Clip duration: %1s", duration().seconds()));
766 } else if (qAbs((int)(pos.x() - (rect.x() + 16 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
767 setToolTip(i18n("Add transition"));
768 return TRANSITIONSTART;
769 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - 21 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
770 setToolTip(i18n("Add transition"));
771 return TRANSITIONEND;
773 setToolTip(QString());
777 QList <GenTime> ClipItem::snapMarkers() const {
778 QList < GenTime > snaps;
779 QList < GenTime > markers = baseClip()->snapMarkers();
783 for (int i = 0; i < markers.size(); i++) {
784 pos = markers.at(i) - cropStart();
785 if (pos > GenTime()) {
786 if (pos > duration()) break;
787 else snaps.append(pos + startPos());
793 QList <CommentedTime> ClipItem::commentedSnapMarkers() const {
794 QList < CommentedTime > snaps;
795 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
799 for (int i = 0; i < markers.size(); i++) {
800 pos = markers.at(i).time() - cropStart();
801 if (pos > GenTime()) {
802 if (pos > duration()) break;
803 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
809 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels) {
810 QRectF re = sceneBoundingRect();
811 if (m_clipType == AV) re.setTop(re.y() + re.height() / 2);
813 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
814 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
816 for (int startCache = startpixel - startpixel % 100;startCache < endpixel;startCache += 100) {
817 //kDebug() << "creating " << startCache;
818 //if (framePixelWidth!=pixelForOneFrame ||
819 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
821 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
822 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
823 audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
825 bool fullAreaDraw = pixelForOneFrame < 10;
826 QMap<int, QPainterPath > positiveChannelPaths;
827 QMap<int, QPainterPath > negativeChannelPaths;
828 QPainter pixpainter(&audioThumbCachePic[startCache]);
830 audiopen.setWidth(0);
831 pixpainter.setPen(audiopen);
832 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
833 //pixpainter.drawLine(0,0,100,re.height());
834 // Bail out, if caller provided invalid data
836 kWarning() << "Unable to draw image with " << channels << "number of channels";
840 int channelHeight = audioThumbCachePic[startCache].height() / channels;
842 for (int i = 0;i < channels;i++) {
844 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
845 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
848 for (int samples = 0;samples <= 100;samples++) {
849 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
850 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
851 if (frame < 0 || sample < 0 || sample > 19)
853 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
855 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
857 int y = channelHeight * channel + channelHeight / 2;
858 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
860 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
861 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
863 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
864 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
867 for (int channel = 0;channel < channels ;channel++)
868 if (fullAreaDraw && samples == 100) {
869 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
870 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
871 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
872 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
876 if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
878 pixpainter.setPen(QPen(QColor(0, 0, 0)));
879 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
881 for (int i = 0;i < channels;i++) {
883 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
884 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
886 pixpainter.drawPath(positiveChannelPaths[i]);
889 //audioThumbWasDrawn=true;
890 framePixelWidth = pixelForOneFrame;
895 uint ClipItem::fadeIn() const {
899 uint ClipItem::fadeOut() const {
904 void ClipItem::setFadeIn(int pos) {
905 if (pos == m_startFade) return;
906 int oldIn = m_startFade;
907 if (pos < 0) pos = 0;
908 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
910 QRectF rect = boundingRect();
911 update(rect.x(), rect.y(), qMax(oldIn, pos), rect.height());
914 void ClipItem::setFadeOut(int pos) {
915 if (pos == m_endFade) return;
916 int oldOut = m_endFade;
917 if (pos < 0) pos = 0;
918 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
920 QRectF rect = boundingRect();
921 update(rect.x() + rect.width() - qMax(oldOut, pos), rect.y(), qMax(oldOut, pos), rect.height());
926 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
927 /*m_resizeMode = operationMode(event->pos());
928 if (m_resizeMode == MOVE) {
929 m_maxTrack = scene()->sceneRect().height();
930 m_grabPoint = (int) (event->pos().x() - rect().x());
932 QGraphicsRectItem::mousePressEvent(event);
936 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
938 QGraphicsRectItem::mouseReleaseEvent(event);
942 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e) {
943 //if (e->pos().x() < 20) m_hover = true;
944 if (isItemLocked()) return;
946 QRectF r = boundingRect();
947 double width = 35 / projectScene()->scale();
948 double height = r.height() / 2;
949 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
950 update(r.x(), r.y() + height, width, height);
951 update(r.right() - width, r.y() + height, width, height);
955 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
956 if (isItemLocked()) return;
958 QRectF r = boundingRect();
959 double width = 35 / projectScene()->scale();
960 double height = r.height() / 2;
961 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
962 update(r.x(), r.y() + height, width, height);
963 update(r.right() - width, r.y() + height, width, height);
966 void ClipItem::resizeStart(int posx, double speed) {
967 const int min = (startPos() - cropStart()).frames(m_fps);
968 if (posx < min) posx = min;
969 if (posx == startPos().frames(m_fps)) return;
970 const int previous = cropStart().frames(m_fps);
971 AbstractClipItem::resizeStart(posx, m_speed);
972 if ((int) cropStart().frames(m_fps) != previous) {
973 checkEffectsKeyframesPos(previous, cropStart().frames(m_fps), true);
974 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
975 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
976 startThumbTimer->start(150);
981 void ClipItem::resizeEnd(int posx, double speed, bool updateKeyFrames) {
982 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps) + 1;
983 if (posx > max) posx = max;
984 if (posx == endPos().frames(m_fps)) return;
985 //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
986 const int previous = (cropStart() + duration()).frames(m_fps);
987 AbstractClipItem::resizeEnd(posx, m_speed);
988 if ((int)(cropStart() + duration()).frames(m_fps) != previous) {
989 if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false);
990 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
991 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
992 endThumbTimer->start(150);
998 void ClipItem::checkEffectsKeyframesPos(const int previous, const int current, bool fromStart) {
999 for (int i = 0; i < m_effectList.size(); i++) {
1000 QDomElement effect = m_effectList.at(i);
1001 QDomNodeList params = effect.elementsByTagName("parameter");
1002 for (int j = 0; j < params.count(); j++) {
1003 QDomElement e = params.item(i).toElement();
1004 if (e.attribute("type") == "keyframe") {
1005 // parse keyframes and adjust values
1006 const QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
1007 QMap <int, double> kfr;
1010 foreach(const QString str, keyframes) {
1011 pos = str.section(":", 0, 0).toInt();
1012 val = str.section(":", 1, 1).toDouble();
1013 if (pos == previous) kfr[current] = val;
1015 if (fromStart && pos >= current) kfr[pos] = val;
1016 else if (!fromStart && pos <= current) kfr[pos] = val;
1020 QMap<int, double>::const_iterator k = kfr.constBegin();
1021 while (k != kfr.constEnd()) {
1022 newkfr.append(QString::number(k.key()) + ":" + QString::number(k.value()) + ";");
1025 e.setAttribute("keyframes", newkfr);
1030 if (m_selectedEffect >= 0) setSelectedEffect(m_selectedEffect);
1034 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value) {
1035 if (change == ItemPositionChange && scene()) {
1036 // calculate new position.
1037 if (parentItem()) return pos();
1038 QPointF newPos = value.toPointF();
1039 //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1040 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1041 xpos = qMax(xpos, 0);
1043 int newTrack = newPos.y() / KdenliveSettings::trackheight();
1044 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1045 newTrack = qMax(newTrack, 0);
1046 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1047 // Only one clip is moving
1048 QRectF sceneShape = rect();
1049 sceneShape.translate(newPos);
1050 QList<QGraphicsItem*> items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1051 items.removeAll(this);
1052 bool forwardMove = newPos.x() > pos().x();
1054 if (!items.isEmpty()) {
1055 for (int i = 0; i < items.count(); i++) {
1056 if (items.at(i)->type() == type()) {
1058 QPointF otherPos = items.at(i)->pos();
1059 if ((int) otherPos.y() != (int) pos().y()) {
1063 offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps)));
1065 offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
1070 sceneShape.translate(QPointF(-offset, 0));
1071 newPos.setX(newPos.x() - offset);
1073 sceneShape.translate(QPointF(offset, 0));
1074 newPos.setX(newPos.x() + offset);
1076 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1077 subitems.removeAll(this);
1078 for (int j = 0; j < subitems.count(); j++) {
1079 if (subitems.at(j)->type() == type()) {
1080 m_startPos = GenTime((int) pos().x(), m_fps);
1087 m_startPos = GenTime((int) newPos.x(), m_fps);
1093 m_startPos = GenTime((int) newPos.x(), m_fps);
1094 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1097 return QGraphicsItem::itemChange(change, value);
1101 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1104 int ClipItem::effectsCounter() {
1105 return effectsCount() + 1;
1108 int ClipItem::effectsCount() {
1109 return m_effectList.size();
1112 int ClipItem::hasEffect(const QString &tag, const QString &id) const {
1113 return m_effectList.hasEffect(tag, id);
1116 QStringList ClipItem::effectNames() {
1117 return m_effectList.effectNames();
1120 QDomElement ClipItem::effectAt(int ix) {
1121 if (ix > m_effectList.count() - 1 || ix < 0) return QDomElement();
1122 return m_effectList.at(ix);
1125 void ClipItem::setEffectAt(int ix, QDomElement effect) {
1126 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1127 effect.setAttribute("kdenlive_ix", ix + 1);
1128 m_effectList.insert(ix, effect);
1129 m_effectList.removeAt(ix + 1);
1130 m_effectNames = m_effectList.effectNames().join(" / ");
1131 if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fadeout") update(boundingRect());
1133 QRectF r = boundingRect();
1139 EffectsParameterList ClipItem::addEffect(QDomElement effect, bool animate) {
1141 bool needRepaint = false;
1143 doc.appendChild(doc.importNode(effect, true));
1144 kDebug() << "/////// CLIPÂ ADD EFFECT: " << doc.toString();*/
1145 m_effectList.append(effect);
1147 EffectsParameterList parameters;
1148 parameters.addParam("tag", effect.attribute("tag"));
1149 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1150 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1152 QString state = effect.attribute("disabled");
1153 if (!state.isEmpty()) {
1154 parameters.addParam("disabled", state);
1157 QString effectId = effect.attribute("id");
1158 if (effectId.isEmpty()) effectId = effect.attribute("tag");
1159 parameters.addParam("id", effectId);
1161 QDomNodeList params = effect.elementsByTagName("parameter");
1163 for (int i = 0; i < params.count(); i++) {
1164 QDomElement e = params.item(i).toElement();
1166 if (e.attribute("type") == "keyframe") {
1167 parameters.addParam("keyframes", e.attribute("keyframes"));
1168 parameters.addParam("max", e.attribute("max"));
1169 parameters.addParam("min", e.attribute("min"));
1170 parameters.addParam("factor", e.attribute("factor", "1"));
1171 parameters.addParam("starttag", e.attribute("starttag", "start"));
1172 parameters.addParam("endtag", e.attribute("endtag", "end"));
1175 double f = e.attribute("factor", "1").toDouble();
1178 parameters.addParam(e.attribute("name"), e.attribute("value"));
1180 // check if it is a fade effect
1181 if (effectId == "fadein") {
1183 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1184 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1185 } else if (effectId == "fadeout") {
1187 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1188 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1191 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / f));
1195 m_effectNames = m_effectList.effectNames().join(" / ");
1196 if (fade > 0) m_startFade = fade;
1197 else if (fade < 0) m_endFade = -fade;
1198 if (needRepaint) update(boundingRect());
1201 } else if (!needRepaint) {
1202 QRectF r = boundingRect();
1206 if (m_selectedEffect == -1) {
1207 m_selectedEffect = 0;
1208 setSelectedEffect(m_selectedEffect);
1213 EffectsParameterList ClipItem::getEffectArgs(QDomElement effect) {
1214 EffectsParameterList parameters;
1215 parameters.addParam("tag", effect.attribute("tag"));
1216 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1217 parameters.addParam("id", effect.attribute("id"));
1218 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1219 QString state = effect.attribute("disabled");
1220 if (!state.isEmpty()) {
1221 parameters.addParam("disabled", state);
1224 QDomNodeList params = effect.elementsByTagName("parameter");
1225 for (int i = 0; i < params.count(); i++) {
1226 QDomElement e = params.item(i).toElement();
1227 //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
1228 if (e.attribute("type") == "keyframe") {
1229 kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
1230 parameters.addParam("keyframes", e.attribute("keyframes"));
1231 parameters.addParam("max", e.attribute("max"));
1232 parameters.addParam("min", e.attribute("min"));
1233 parameters.addParam("factor", e.attribute("factor", "1"));
1234 parameters.addParam("starttag", e.attribute("starttag", "start"));
1235 parameters.addParam("endtag", e.attribute("endtag", "end"));
1236 } else if (e.attribute("namedesc").contains(";")) {
1237 QString format = e.attribute("format");
1238 QStringList separators = format.split("%d", QString::SkipEmptyParts);
1239 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
1241 QTextStream txtNeu(&neu);
1242 if (values.size() > 0)
1243 txtNeu << (int)values[0].toDouble();
1244 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
1245 txtNeu << separators[i];
1246 txtNeu << (int)(values[i+1].toDouble());
1248 parameters.addParam("start", neu);
1250 if (e.attribute("factor", "1") != "1") {
1251 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / e.attribute("factor").toDouble()));
1253 parameters.addParam(e.attribute("name"), e.attribute("value"));
1260 void ClipItem::deleteEffect(QString index) {
1261 bool needRepaint = false;
1263 for (int i = 0; i < m_effectList.size(); ++i) {
1264 ix = m_effectList.at(i).attribute("kdenlive_ix");
1266 if (m_effectList.at(i).attribute("id") == "fadein") {
1269 } else if (m_effectList.at(i).attribute("id") == "fadeout") {
1273 m_effectList.removeAt(i);
1275 } else if (ix.toInt() > index.toInt()) {
1276 m_effectList[i].setAttribute("kdenlive_ix", ix.toInt() - 1);
1279 m_effectNames = m_effectList.effectNames().join(" / ");
1280 if (needRepaint) update(boundingRect());
1284 double ClipItem::speed() const {
1288 void ClipItem::setSpeed(const double speed) {
1290 if (m_speed == 1.0) m_clipName = baseClip()->name();
1291 else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + "%";
1295 GenTime ClipItem::maxDuration() const {
1296 return m_maxDuration / m_speed;
1299 GenTime ClipItem::cropStart() const {
1300 return m_cropStart / m_speed;
1303 GenTime ClipItem::cropDuration() const {
1304 return m_cropDuration / m_speed;
1307 GenTime ClipItem::endPos() const {
1308 return m_startPos + cropDuration();
1312 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
1313 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
1315 doc.setContent(effects, true);
1316 QDomElement e = doc.documentElement();
1317 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1318 if (view) view->slotAddEffect(e, m_startPos, track());
1322 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
1323 if (isItemLocked()) event->setAccepted(false);
1324 else event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
1327 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
1330 void ClipItem::addTransition(Transition* t) {
1331 m_transitionsList.append(t);
1332 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1334 QDomElement e = doc.documentElement();
1335 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1339 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
1341 int pos = event->x();
1342 if (event->modifiers() == Qt::ControlModifier)
1343 setDragMode(QGraphicsView::ScrollHandDrag);
1344 else if (event->modifiers() == Qt::ShiftModifier)
1345 setDragMode(QGraphicsView::RubberBandDrag);
1347 QGraphicsItem * item = itemAt(event->pos());
1350 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
1353 QGraphicsView::mousePressEvent(event);
1356 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
1358 QGraphicsView::mouseReleaseEvent(event);
1359 setDragMode(QGraphicsView::NoDrag);
1363 #include "clipitem.moc"