1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
22 #include "customtrackview.h"
23 #include "customtrackscene.h"
25 #include "docclipbase.h"
26 #include "transition.h"
27 #include "kdenlivesettings.h"
35 #include <QStyleOptionGraphicsItem>
36 #include <QGraphicsScene>
39 ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, bool generateThumbs)
40 : AbstractClipItem(info, QRectF(), fps), 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()), m_videoOnly(false), m_audioOnly(false) {
42 setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double)(KdenliveSettings::trackheight() - 2));
43 setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1);
45 m_videoPix = KIcon("video-x-generic").pixmap(QSize(15, 15));
46 m_audioPix = KIcon("audio-x-generic").pixmap(QSize(15, 15));
48 if (m_speed == 1.0) m_clipName = clip->name();
50 m_clipName = clip->name() + " - " + QString::number(m_speed * 100, 'f', 0) + '%';
51 m_cropDuration = m_cropDuration * m_speed;
53 m_producer = clip->getId();
54 m_clipType = clip->clipType();
55 m_cropStart = info.cropStart;
56 m_maxDuration = clip->maxDuration();
58 audioThumbReady = clip->audioThumbCreated();
61 m_cropStart = xml.attribute("in", 0).toInt();
62 m_maxDuration = xml.attribute("duration", 0).toInt();
63 if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
65 if (duration != -1) m_cropDuration = duration;
66 else m_cropDuration = m_maxDuration;*/
69 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
70 setAcceptsHoverEvents(true);
71 connect(this , SIGNAL(prepareAudioThumb(double, int, int, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int)));
73 setBrush(QColor(141, 166, 215));
74 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
76 startThumbTimer = new QTimer(this);
77 startThumbTimer->setSingleShot(true);
78 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
79 endThumbTimer = new QTimer(this);
80 endThumbTimer->setSingleShot(true);
81 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
83 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
84 //connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(getVideoThumbs(int, int)));
86 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
87 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
88 if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs()));
90 /*if (m_clip->producer()) {
91 videoThumbProducer.init(this, m_clip->producer(), KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio(), KdenliveSettings::trackheight());
94 } else if (m_clipType == COLOR) {
95 QString colour = clip->getProperty("colour");
96 colour = colour.replace(0, 2, "#");
97 setBrush(QColor(colour.left(7)));
98 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
99 m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
100 m_endPix = m_startPix;
101 } else if (m_clipType == AUDIO) {
102 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
107 ClipItem::~ClipItem() {
108 if (startThumbTimer) delete startThumbTimer;
109 if (endThumbTimer) delete endThumbTimer;
110 if (m_timeLine) delete m_timeLine;
113 ClipItem *ClipItem::clone(ItemInfo info) const {
114 ClipItem *duplicate = new ClipItem(m_clip, info, m_fps, m_speed);
115 if (info.cropStart == m_cropStart) duplicate->slotSetStartThumb(m_startPix);
116 if (info.cropStart + (info.endPos - info.startPos) == m_cropStart + m_cropDuration) duplicate->slotSetEndThumb(m_endPix);
117 kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
118 duplicate->setEffectList(m_effectList.clone());
119 //duplicate->setSpeed(m_speed);
123 void ClipItem::setEffectList(const EffectsList effectList) {
124 m_effectList = effectList;
125 m_effectNames = m_effectList.effectNames().join(" / ");
128 const EffectsList ClipItem::effectList() {
132 int ClipItem::selectedEffectIndex() const {
133 return m_selectedEffect;
136 void ClipItem::initEffect(QDomElement effect) {
137 // the kdenlive_ix int is used to identify an effect in mlt's playlist, should
139 if (effect.attribute("kdenlive_ix").toInt() == 0)
140 effect.setAttribute("kdenlive_ix", QString::number(effectsCounter()));
141 // init keyframes if required
142 QDomNodeList params = effect.elementsByTagName("parameter");
143 for (int i = 0; i < params.count(); i++) {
144 QDomElement e = params.item(i).toElement();
145 kDebug() << "// inint eff: " << e.attribute("name");
146 if (!e.isNull() && e.attribute("type") == "keyframe") {
147 QString def = e.attribute("default");
148 // Effect has a keyframe type parameter, we need to set the values
149 if (e.attribute("keyframes").isEmpty()) {
150 e.setAttribute("keyframes", QString::number(m_cropStart.frames(m_fps)) + ':' + def + ';' + QString::number((m_cropStart + m_cropDuration).frames(m_fps)) + ':' + def);
151 //kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
157 if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
158 if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
159 int end = (duration() + cropStart()).frames(m_fps);
161 if (effect.attribute("id") == "fadeout") {
162 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
163 start -= EffectsList::parameter(effect, "in").toInt();
165 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
166 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
168 } else if (effect.attribute("id") == "fade_to_black") {
169 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
170 start -= EffectsList::parameter(effect, "in").toInt();
172 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
173 start -= EffectsList::parameter(fadeout, "out").toInt() - EffectsList::parameter(fadeout, "in").toInt();
176 EffectsList::setParameter(effect, "in", QString::number(start));
177 EffectsList::setParameter(effect, "out", QString::number(end));
178 } else if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
179 int start = cropStart().frames(m_fps);
181 if (effect.attribute("id") == "fadein") {
182 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1)
183 end += EffectsList::parameter(effect, "out").toInt();
185 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fade_from_black"), "out").toInt();
186 } else if (effect.attribute("id") == "fade_from_black") {
187 if (m_effectList.hasEffect(QString(), "fadein") == -1)
188 end += EffectsList::parameter(effect, "out").toInt();
190 end += EffectsList::parameter(m_effectList.getEffectByTag(QString(), "fadein"), "out").toInt();
192 EffectsList::setParameter(effect, "in", QString::number(start));
193 EffectsList::setParameter(effect, "out", QString::number(end));
198 bool ClipItem::checkKeyFrames() {
199 bool clipEffectsModified = false;
200 for (int ix = 0; ix < m_effectList.count(); ix ++) {
201 QString kfr = keyframes(ix);
202 if (!kfr.isEmpty()) {
203 const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
204 QStringList newKeyFrames;
205 bool cutKeyFrame = false;
206 bool modified = false;
208 double lastValue = -1;
209 int start = m_cropStart.frames(m_fps);
210 int end = (m_cropStart + m_cropDuration).frames(m_fps);
211 foreach(const QString &str, keyframes) {
212 int pos = str.section(':', 0, 0).toInt();
213 double val = str.section(':', 1, 1).toDouble();
214 if (pos - start < 0) {
215 // a keyframe is defined before the start of the clip
217 } else if (cutKeyFrame) {
218 // create new keyframe at clip start, calculate interpolated value
220 int diff = pos - lastPos;
221 double ratio = (double)(start - lastPos) / diff;
222 double newValue = lastValue + (val - lastValue) * ratio;
223 newKeyFrames.append(QString::number(start) + ':' + QString::number(newValue));
230 // create new keyframe at clip end, calculate interpolated value
231 int diff = pos - lastPos;
233 double ratio = (double)(end - lastPos) / diff;
234 double newValue = lastValue + (val - lastValue) * ratio;
235 newKeyFrames.append(QString::number(end) + ':' + QString::number(newValue));
240 newKeyFrames.append(QString::number(pos) + ':' + QString::number(val));
248 setKeyframes(ix, newKeyFrames.join(";"));
249 clipEffectsModified = true;
253 return clipEffectsModified;
256 void ClipItem::setKeyframes(const int ix, const QString keyframes) {
257 QDomElement effect = effectAt(ix);
258 if (effect.attribute("disabled") == "1") return;
259 QDomNodeList params = effect.elementsByTagName("parameter");
260 for (int i = 0; i < params.count(); i++) {
261 QDomElement e = params.item(i).toElement();
262 if (!e.isNull() && e.attribute("type") == "keyframe") {
263 e.setAttribute("keyframes", keyframes);
264 if (ix == m_selectedEffect) {
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;
286 void ClipItem::setSelectedEffect(const int ix) {
287 m_selectedEffect = ix;
288 QDomElement effect = effectAt(m_selectedEffect);
289 QDomNodeList params = effect.elementsByTagName("parameter");
290 if (effect.attribute("disabled") != "1")
291 for (int i = 0; i < params.count(); i++) {
292 QDomElement e = params.item(i).toElement();
293 if (!e.isNull() && e.attribute("type") == "keyframe") {
295 double max = e.attribute("max").toDouble();
296 double min = e.attribute("min").toDouble();
297 m_keyframeFactor = 100.0 / (max - min);
298 m_keyframeDefault = e.attribute("default").toDouble();
300 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
301 foreach(const QString &str, keyframes) {
302 int pos = str.section(':', 0, 0).toInt();
303 double val = str.section(':', 1, 1).toDouble();
304 m_keyframes[pos] = val;
310 if (!m_keyframes.isEmpty()) {
316 QString ClipItem::keyframes(const int index) {
318 QDomElement effect = effectAt(index);
319 QDomNodeList params = effect.elementsByTagName("parameter");
321 for (int i = 0; i < params.count(); i++) {
322 QDomElement e = params.item(i).toElement();
323 if (!e.isNull() && e.attribute("type") == "keyframe") {
324 result = e.attribute("keyframes");
331 void ClipItem::updateKeyframeEffect() {
332 // regenerate xml parameter from the clip keyframes
333 QDomElement effect = effectAt(m_selectedEffect);
334 if (effect.attribute("disabled") == "1") return;
335 QDomNodeList params = effect.elementsByTagName("parameter");
337 for (int i = 0; i < params.count(); i++) {
338 QDomElement e = params.item(i).toElement();
339 if (!e.isNull() && e.attribute("type") == "keyframe") {
341 if (m_keyframes.count() > 1) {
342 QMap<int, double>::const_iterator i = m_keyframes.constBegin();
343 while (i != m_keyframes.constEnd()) {
344 keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
348 // Effect has a keyframe type parameter, we need to set the values
349 //kDebug() << "::::::::::::::: SETTING EFFECT KEYFRAMES: " << keyframes;
350 e.setAttribute("keyframes", keyframes);
356 QDomElement ClipItem::selectedEffect() {
357 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
358 return effectAt(m_selectedEffect);
361 void ClipItem::resetThumbs() {
362 m_startPix = QPixmap();
363 m_endPix = QPixmap();
365 audioThumbCachePic.clear();
369 void ClipItem::refreshClip() {
370 m_maxDuration = m_clip->maxDuration();
371 if (m_clipType == COLOR) {
372 QString colour = m_clip->getProperty("colour");
373 colour = colour.replace(0, 2, "#");
374 setBrush(QColor(colour.left(7)));
375 } else slotFetchThumbs();
378 void ClipItem::slotFetchThumbs() {
379 if (m_endPix.isNull() && m_startPix.isNull()) {
380 m_startThumbRequested = true;
381 m_endThumbRequested = true;
382 emit getThumb((int)cropStart().frames(m_fps), (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
384 if (m_endPix.isNull()) {
387 if (m_startPix.isNull()) {
393 if (m_endPix.isNull() && m_startPix.isNull()) {
394 int frame1 = (int)m_cropStart.frames(m_fps);
395 int frame2 = (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1;
396 //videoThumbProducer.setThumbFrames(m_clip->producer(), frame1, frame2);
397 //videoThumbProducer.start(QThread::LowestPriority);
399 if (m_endPix.isNull()) slotGetEndThumb();
400 else slotGetStartThumb();
403 } else if (m_startPix.isNull()) slotGetStartThumb();*/
406 void ClipItem::slotGetStartThumb() {
407 m_startThumbRequested = true;
408 emit getThumb((int)cropStart().frames(m_fps), -1);
409 //videoThumbProducer.setThumbFrames(m_clip->producer(), (int)m_cropStart.frames(m_fps), - 1);
410 //videoThumbProducer.start(QThread::LowestPriority);
413 void ClipItem::slotGetEndThumb() {
414 m_endThumbRequested = true;
415 emit getThumb(-1, (int)(cropStart() + cropDuration()).frames(m_fps) - 1);
416 //videoThumbProducer.setThumbFrames(m_clip->producer(), -1, (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1);
417 //videoThumbProducer.start(QThread::LowestPriority);
421 void ClipItem::slotSetStartThumb(QImage img) {
422 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
423 QPixmap pix = QPixmap::fromImage(img);
425 QRectF r = sceneBoundingRect();
426 r.setRight(pix.width() + 2);
431 void ClipItem::slotSetEndThumb(QImage img) {
432 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
433 QPixmap pix = QPixmap::fromImage(img);
435 QRectF r = sceneBoundingRect();
436 r.setLeft(r.right() - pix.width() - 2);
441 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
442 if (scene() == NULL) return;
443 QRectF r = sceneBoundingRect();
444 double width = m_startPix.width() / projectScene()->scale();
445 if (m_startThumbRequested && frame == cropStart().frames(m_fps)) {
447 m_startThumbRequested = false;
448 double height = r.height();
449 update(r.x(), r.y(), width, height);
450 } else if (m_endThumbRequested && frame == (cropStart() + cropDuration()).frames(m_fps) - 1) {
452 m_endThumbRequested = false;
453 double height = r.height();
454 update(r.right() - width, r.y(), width, height);
458 void ClipItem::slotSetStartThumb(const QPixmap pix) {
462 void ClipItem::slotSetEndThumb(const QPixmap pix) {
466 QPixmap ClipItem::startThumb() const {
470 QPixmap ClipItem::endThumb() const {
474 void ClipItem::slotGotAudioData() {
475 audioThumbReady = true;
476 if (m_clipType == AV) {
477 QRectF r = boundingRect();
478 r.setTop(r.top() + r.height() / 2 - 1);
483 int ClipItem::type() const {
487 DocClipBase *ClipItem::baseClip() const {
491 QDomElement ClipItem::xml() const {
492 QDomElement xml = m_clip->toXML();
493 if (m_speed != 1.0) xml.setAttribute("speed", m_speed);
497 int ClipItem::clipType() const {
501 QString ClipItem::clipName() const {
505 void ClipItem::setClipName(const QString &name) {
509 const QString &ClipItem::clipProducer() const {
513 void ClipItem::flashClip() {
514 if (m_timeLine == 0) {
515 m_timeLine = new QTimeLine(750, this);
516 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
517 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
522 void ClipItem::animate(qreal /*value*/) {
523 QRectF r = boundingRect();
529 void ClipItem::paint(QPainter *painter,
530 const QStyleOptionGraphicsItem *option,
532 /*if (parentItem()) m_opacity = 0.5;
533 else m_opacity = 1.0;
534 painter->setOpacity(m_opacity);*/
536 if (parentItem()) paintColor = QBrush(QColor(255, 248, 149));
537 else paintColor = brush();
538 if (isSelected() || parentItem() && parentItem()->isSelected()) paintColor = QBrush(paintColor.color().darker());
540 QRectF exposed = option->exposedRect;
541 QRectF mapped = painter->matrix().mapRect(br);
543 const double itemWidth = br.width();
544 const double itemHeight = br.height();
545 const double scale = option->matrix.m11();
548 //painter->setRenderHints(QPainter::Antialiasing);
550 //QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
551 painter->setClipRect(exposed);
553 //build path around clip
554 //QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
555 //painter->fillPath(resultClipPath, paintColor);
556 painter->fillRect(exposed, paintColor);
558 //painter->setClipPath(resultClipPath, Qt::IntersectClip);
561 painter->setMatrixEnabled(false);
563 if (KdenliveSettings::videothumbnails()) {
564 QPen pen = painter->pen();
565 pen.setStyle(Qt::DotLine);
566 pen.setColor(Qt::white);
567 painter->setPen(pen);
568 if (m_clipType == IMAGE && !m_startPix.isNull()) {
569 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_startPix.width(), 0);
570 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_startPix.width(), 0);
571 painter->drawPixmap(p1, m_startPix);
573 painter->drawLine(l);
574 } else if (!m_endPix.isNull()) {
575 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_endPix.width(), 0);
576 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_endPix.width(), 0);
577 painter->drawPixmap(p1, m_endPix);
579 painter->drawLine(l);
581 if (!m_startPix.isNull()) {
582 QPointF p1 = painter->matrix().map(QPointF(0, 0));
583 QPointF p2 = painter->matrix().map(QPointF(0, itemHeight));
584 painter->drawPixmap(p1, m_startPix);
585 QLineF l2(p1.x() + m_startPix.width(), p1.y(), p2.x() + m_startPix.width(), p2.y());
586 painter->drawLine(l2);
588 painter->setPen(Qt::black);
591 // draw audio thumbnails
592 if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && ((m_clipType == AV && exposed.bottom() > (itemHeight / 2)) || m_clipType == AUDIO) && audioThumbReady) {
594 double startpixel = exposed.left();
597 double endpixel = exposed.right();
600 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
602 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
604 if (m_clipType == AV) {
606 re.setTop(re.y() + re.height() / 2);
607 mappedRect = painter->matrix().mapRect(re);
608 //painter->fillRect(mappedRect, QBrush(QColor(200, 200, 200, 140)));
609 } else mappedRect = mapped;
611 int channels = baseClip()->getProperty("channels").toInt();
612 if (scale != framePixelWidth)
613 audioThumbCachePic.clear();
614 double cropLeft = m_cropStart.frames(m_fps);
615 const int clipStart = mappedRect.x();
616 const int mappedStartPixel = painter->matrix().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
617 const int mappedEndPixel = painter->matrix().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
618 cropLeft = cropLeft * scale;
621 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
624 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
625 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
626 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), audioThumbCachePic[startCache]);
631 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
632 QList < CommentedTime >::Iterator it = markers.begin();
636 markerBrush = QBrush(QColor(120, 120, 0, 140));
637 QPen pen = painter->pen();
638 pen.setColor(QColor(255, 255, 255, 200));
639 pen.setStyle(Qt::DotLine);
640 painter->setPen(pen);
641 for (; it != markers.end(); ++it) {
642 pos = (*it).time() - cropStart();
643 if (pos > GenTime()) {
644 if (pos > duration()) break;
645 QLineF l(br.x() + pos.frames(m_fps), br.y() + 5, br.x() + pos.frames(m_fps), br.bottom() - 5);
646 QLineF l2 = painter->matrix().map(l);
647 //framepos = scale * pos.frames(m_fps);
648 //QLineF l(framepos, 5, framepos, itemHeight - 5);
649 painter->drawLine(l2);
650 if (KdenliveSettings::showmarkers()) {
651 framepos = br.x() + pos.frames(m_fps);
652 const QRectF r1(framepos + 0.04, 10, itemWidth - framepos - 2, itemHeight - 10);
653 const QRectF r2 = painter->matrix().mapRect(r1);
654 const QRectF txtBounding = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, ' ' + (*it).comment() + ' ');
657 path.addRoundedRect(txtBounding, 3, 3);
658 painter->fillPath(path, markerBrush);
659 painter->drawText(txtBounding, Qt::AlignCenter, (*it).comment());
661 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
664 pen.setColor(Qt::black);
665 pen.setStyle(Qt::SolidLine);
666 painter->setPen(pen);
668 // draw start / end fades
671 fades = QBrush(QColor(200, 50, 50, 150));
672 } else fades = QBrush(QColor(200, 200, 200, 200));
674 if (m_startFade != 0) {
675 QPainterPath fadeInPath;
676 fadeInPath.moveTo(0, 0);
677 fadeInPath.lineTo(0, itemHeight);
678 fadeInPath.lineTo(m_startFade, 0);
679 fadeInPath.closeSubpath();
680 QPainterPath f1 = painter->matrix().map(fadeInPath);
681 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
682 /*if (isSelected()) {
683 QLineF l(m_startFade * scale, 0, 0, itemHeight);
684 painter->drawLine(l);
687 if (m_endFade != 0) {
688 QPainterPath fadeOutPath;
689 fadeOutPath.moveTo(itemWidth, 0);
690 fadeOutPath.lineTo(itemWidth, itemHeight);
691 fadeOutPath.lineTo(itemWidth - m_endFade, 0);
692 fadeOutPath.closeSubpath();
693 QPainterPath f1 = painter->matrix().map(fadeOutPath);
694 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
695 /*if (isSelected()) {
696 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
697 painter->drawLine(l);
701 // Draw effects names
702 if (!m_effectNames.isEmpty() && itemWidth * scale > 40) {
703 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
704 txtBounding.setRight(txtBounding.right() + 15);
705 painter->setPen(Qt::white);
706 QBrush markerBrush(Qt::SolidPattern);
707 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
708 qreal value = m_timeLine->currentValue();
709 txtBounding.setWidth(txtBounding.width() * value);
710 markerBrush.setColor(QColor(50 + 200 * (1.0 - value), 50, 50, 100 + 50 * value));
711 } else markerBrush.setColor(QColor(50, 50, 50, 150));
713 path.addRoundedRect(txtBounding, 4, 4);
714 painter->fillPath(path/*.intersected(resultClipPath)*/, markerBrush);
715 painter->drawText(txtBounding, Qt::AlignCenter, m_effectNames);
716 painter->setPen(Qt::black);
721 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignHCenter | Qt::AlignVCenter, ' ' + m_clipName + ' ');
722 painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
723 //painter->setPen(QColor(0, 0, 0, 180));
724 //painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
726 painter->drawPixmap(txtBounding.topLeft() - QPointF(17, -1), m_videoPix);
727 } else if (m_audioOnly) {
728 painter->drawPixmap(txtBounding.topLeft() - QPointF(17, -1), m_audioPix);
730 txtBounding.translate(QPointF(1, 1));
731 painter->setPen(QColor(255, 255, 255, 255));
732 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
735 // draw transition handles on hover
736 if (m_hover && itemWidth * scale > 40) {
737 QPointF p1 = painter->matrix().map(QPointF(0, itemHeight / 2)) + QPointF(10, 0);
738 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
739 p1 = painter->matrix().map(QPointF(itemWidth, itemHeight / 2)) - QPointF(22, 0);
740 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
744 // draw frame around clip
745 if (isSelected() || parentItem() && parentItem()->isSelected()) {
746 pen.setColor(Qt::red);
748 pen.setColor(Qt::black);
751 // draw effect or transition keyframes
752 if (itemWidth > 20) drawKeyFrames(painter, exposed);
754 painter->setMatrixEnabled(true);
757 // expand clip rect to allow correct painting of clip border
758 exposed.setRight(exposed.right() + 1 / scale + 0.5);
759 exposed.setBottom(exposed.bottom() + 1);
760 painter->setClipRect(exposed);
761 painter->setPen(pen);
762 painter->drawRect(br);
766 OPERATIONTYPE ClipItem::operationMode(QPointF pos) {
767 if (isItemLocked()) return NONE;
770 m_editedKeyframe = mouseOverKeyFrames(pos);
771 if (m_editedKeyframe != -1) return KEYFRAME;
773 QRectF rect = sceneBoundingRect();
774 const double scale = projectScene()->scale();
775 double maximumOffset = 6 / scale;
777 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
778 if (m_startFade == 0) setToolTip(i18n("Add audio fade"));
779 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_startFade, m_fps).seconds()));
781 } else if (pos.x() - rect.x() < maximumOffset) {
782 setToolTip(i18n("Crop from start: %1s", cropStart().seconds()));
784 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
785 if (m_endFade == 0) setToolTip(i18n("Add audio fade"));
786 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_endFade, m_fps).seconds()));
788 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width()))) < maximumOffset) {
789 setToolTip(i18n("Clip duration: %1s", duration().seconds()));
791 } else if (qAbs((int)(pos.x() - (rect.x() + 16 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
792 setToolTip(i18n("Add transition"));
793 return TRANSITIONSTART;
794 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - 21 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
795 setToolTip(i18n("Add transition"));
796 return TRANSITIONEND;
798 setToolTip(QString());
802 QList <GenTime> ClipItem::snapMarkers() const {
803 QList < GenTime > snaps;
804 QList < GenTime > markers = baseClip()->snapMarkers();
807 for (int i = 0; i < markers.size(); i++) {
808 pos = markers.at(i) - cropStart();
809 if (pos > GenTime()) {
810 if (pos > duration()) break;
811 else snaps.append(pos + startPos());
817 QList <CommentedTime> ClipItem::commentedSnapMarkers() const {
818 QList < CommentedTime > snaps;
819 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
822 for (int i = 0; i < markers.size(); i++) {
823 pos = markers.at(i).time() - cropStart();
824 if (pos > GenTime()) {
825 if (pos > duration()) break;
826 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
832 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels) {
833 QRectF re = sceneBoundingRect();
834 if (m_clipType == AV) re.setTop(re.y() + re.height() / 2);
836 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
837 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
839 for (int startCache = startpixel - startpixel % 100;startCache < endpixel;startCache += 100) {
840 //kDebug() << "creating " << startCache;
841 //if (framePixelWidth!=pixelForOneFrame ||
842 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
844 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
845 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
846 audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
848 bool fullAreaDraw = pixelForOneFrame < 10;
849 QMap<int, QPainterPath > positiveChannelPaths;
850 QMap<int, QPainterPath > negativeChannelPaths;
851 QPainter pixpainter(&audioThumbCachePic[startCache]);
853 audiopen.setWidth(0);
854 pixpainter.setPen(audiopen);
855 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
856 //pixpainter.drawLine(0,0,100,re.height());
857 // Bail out, if caller provided invalid data
859 kWarning() << "Unable to draw image with " << channels << "number of channels";
863 int channelHeight = audioThumbCachePic[startCache].height() / channels;
865 for (int i = 0;i < channels;i++) {
867 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
868 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
871 for (int samples = 0;samples <= 100;samples++) {
872 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
873 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
874 if (frame < 0 || sample < 0 || sample > 19)
876 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
878 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
880 int y = channelHeight * channel + channelHeight / 2;
881 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
883 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
884 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
886 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
887 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
890 for (int channel = 0;channel < channels ;channel++)
891 if (fullAreaDraw && samples == 100) {
892 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
893 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
894 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
895 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
899 if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
901 pixpainter.setPen(QPen(QColor(0, 0, 0)));
902 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
904 for (int i = 0;i < channels;i++) {
906 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
907 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
909 pixpainter.drawPath(positiveChannelPaths[i]);
912 //audioThumbWasDrawn=true;
913 framePixelWidth = pixelForOneFrame;
918 uint ClipItem::fadeIn() const {
922 uint ClipItem::fadeOut() const {
927 void ClipItem::setFadeIn(int pos) {
928 if (pos == m_startFade) return;
929 int oldIn = m_startFade;
930 if (pos < 0) pos = 0;
931 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
933 QRectF rect = boundingRect();
934 update(rect.x(), rect.y(), qMax(oldIn, pos), rect.height());
937 void ClipItem::setFadeOut(int pos) {
938 if (pos == m_endFade) return;
939 int oldOut = m_endFade;
940 if (pos < 0) pos = 0;
941 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps));
943 QRectF rect = boundingRect();
944 update(rect.x() + rect.width() - qMax(oldOut, pos), rect.y(), qMax(oldOut, pos), rect.height());
949 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
950 /*m_resizeMode = operationMode(event->pos());
951 if (m_resizeMode == MOVE) {
952 m_maxTrack = scene()->sceneRect().height();
953 m_grabPoint = (int) (event->pos().x() - rect().x());
955 QGraphicsRectItem::mousePressEvent(event);
959 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
961 QGraphicsRectItem::mouseReleaseEvent(event);
965 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent */*e*/) {
966 //if (e->pos().x() < 20) m_hover = true;
967 if (isItemLocked()) return;
969 QRectF r = boundingRect();
970 double width = 35 / projectScene()->scale();
971 double height = r.height() / 2;
972 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
973 update(r.x(), r.y() + height, width, height);
974 update(r.right() - width, r.y() + height, width, height);
978 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
979 if (isItemLocked()) return;
981 QRectF r = boundingRect();
982 double width = 35 / projectScene()->scale();
983 double height = r.height() / 2;
984 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
985 update(r.x(), r.y() + height, width, height);
986 update(r.right() - width, r.y() + height, width, height);
989 void ClipItem::resizeStart(int posx, double /*speed*/) {
990 const int min = (startPos() - cropStart()).frames(m_fps);
991 if (posx < min) posx = min;
992 if (posx == startPos().frames(m_fps)) return;
993 const int previous = cropStart().frames(m_fps);
994 AbstractClipItem::resizeStart(posx, m_speed);
995 if ((int) cropStart().frames(m_fps) != previous) {
996 checkEffectsKeyframesPos(previous, cropStart().frames(m_fps), true);
997 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
998 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
999 startThumbTimer->start(150);
1004 void ClipItem::resizeEnd(int posx, double /*speed*/, bool updateKeyFrames) {
1005 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps) + 1;
1006 if (posx > max) posx = max;
1007 if (posx == endPos().frames(m_fps)) return;
1008 //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
1009 const int previous = (cropStart() + duration()).frames(m_fps);
1010 AbstractClipItem::resizeEnd(posx, m_speed);
1011 if ((int)(cropStart() + duration()).frames(m_fps) != previous) {
1012 if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false);
1013 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
1014 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
1015 endThumbTimer->start(150);
1021 void ClipItem::checkEffectsKeyframesPos(const int previous, const int current, bool fromStart) {
1022 for (int i = 0; i < m_effectList.size(); i++) {
1023 QDomElement effect = m_effectList.at(i);
1024 QDomNodeList params = effect.elementsByTagName("parameter");
1025 for (int j = 0; j < params.count(); j++) {
1026 QDomElement e = params.item(i).toElement();
1027 if (e.attribute("type") == "keyframe") {
1028 // parse keyframes and adjust values
1029 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
1030 QMap <int, double> kfr;
1033 foreach(const QString &str, keyframes) {
1034 pos = str.section(':', 0, 0).toInt();
1035 val = str.section(':', 1, 1).toDouble();
1036 if (pos == previous) kfr[current] = val;
1038 if (fromStart && pos >= current) kfr[pos] = val;
1039 else if (!fromStart && pos <= current) kfr[pos] = val;
1043 QMap<int, double>::const_iterator k = kfr.constBegin();
1044 while (k != kfr.constEnd()) {
1045 newkfr.append(QString::number(k.key()) + ':' + QString::number(k.value()) + ';');
1048 e.setAttribute("keyframes", newkfr);
1053 if (m_selectedEffect >= 0) setSelectedEffect(m_selectedEffect);
1057 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value) {
1058 if (change == ItemPositionChange && scene()) {
1059 // calculate new position.
1060 //if (parentItem()) return pos();
1061 QPointF newPos = value.toPointF();
1062 //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
1063 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
1064 xpos = qMax(xpos, 0);
1066 int newTrack = newPos.y() / KdenliveSettings::trackheight();
1067 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
1068 newTrack = qMax(newTrack, 0);
1069 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1070 // Only one clip is moving
1071 QRectF sceneShape = rect();
1072 sceneShape.translate(newPos);
1073 QList<QGraphicsItem*> items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1074 items.removeAll(this);
1075 bool forwardMove = newPos.x() > pos().x();
1077 if (!items.isEmpty()) {
1078 for (int i = 0; i < items.count(); i++) {
1079 if (items.at(i)->type() == type()) {
1081 QPointF otherPos = items.at(i)->pos();
1082 if ((int) otherPos.y() != (int) pos().y()) {
1086 offset = qMax(offset, (int)(newPos.x() - (static_cast < AbstractClipItem* >(items.at(i))->startPos() - cropDuration()).frames(m_fps)));
1088 offset = qMax(offset, (int)((static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps)) - newPos.x()));
1093 sceneShape.translate(QPointF(-offset, 0));
1094 newPos.setX(newPos.x() - offset);
1096 sceneShape.translate(QPointF(offset, 0));
1097 newPos.setX(newPos.x() + offset);
1099 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1100 subitems.removeAll(this);
1101 for (int j = 0; j < subitems.count(); j++) {
1102 if (subitems.at(j)->type() == type()) {
1103 m_startPos = GenTime((int) pos().x(), m_fps);
1110 m_startPos = GenTime((int) newPos.x(), m_fps);
1116 m_startPos = GenTime((int) newPos.x(), m_fps);
1117 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1120 return QGraphicsItem::itemChange(change, value);
1124 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1127 int ClipItem::effectsCounter() {
1128 return effectsCount() + 1;
1131 int ClipItem::effectsCount() {
1132 return m_effectList.size();
1135 int ClipItem::hasEffect(const QString &tag, const QString &id) const {
1136 return m_effectList.hasEffect(tag, id);
1139 QStringList ClipItem::effectNames() {
1140 return m_effectList.effectNames();
1143 QDomElement ClipItem::effectAt(int ix) {
1144 if (ix > m_effectList.count() - 1 || ix < 0) return QDomElement();
1145 return m_effectList.at(ix);
1148 void ClipItem::setEffectAt(int ix, QDomElement effect) {
1149 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1150 effect.setAttribute("kdenlive_ix", ix + 1);
1151 m_effectList.insert(ix, effect);
1152 m_effectList.removeAt(ix + 1);
1153 m_effectNames = m_effectList.effectNames().join(" / ");
1154 QString id = effect.attribute("id");
1155 if (id == "fadein" || id == "fadeout" || id == "fade_from_black" || id == "fade_to_black")
1156 update(boundingRect());
1158 QRectF r = boundingRect();
1164 EffectsParameterList ClipItem::addEffect(QDomElement effect, bool animate) {
1166 bool needRepaint = false;
1168 doc.appendChild(doc.importNode(effect, true));
1169 kDebug() << "/////// CLIPÂ ADD EFFECT: " << doc.toString();*/
1170 m_effectList.append(effect);
1172 EffectsParameterList parameters;
1173 parameters.addParam("tag", effect.attribute("tag"));
1174 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1175 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1177 QString state = effect.attribute("disabled");
1178 if (!state.isEmpty()) {
1179 parameters.addParam("disabled", state);
1182 QString effectId = effect.attribute("id");
1183 if (effectId.isEmpty()) effectId = effect.attribute("tag");
1184 parameters.addParam("id", effectId);
1186 QDomNodeList params = effect.elementsByTagName("parameter");
1188 for (int i = 0; i < params.count(); i++) {
1189 QDomElement e = params.item(i).toElement();
1191 if (e.attribute("type") == "keyframe") {
1192 parameters.addParam("keyframes", e.attribute("keyframes"));
1193 parameters.addParam("max", e.attribute("max"));
1194 parameters.addParam("min", e.attribute("min"));
1195 parameters.addParam("factor", e.attribute("factor", "1"));
1196 parameters.addParam("starttag", e.attribute("starttag", "start"));
1197 parameters.addParam("endtag", e.attribute("endtag", "end"));
1200 double f = e.attribute("factor", "1").toDouble();
1203 parameters.addParam(e.attribute("name"), e.attribute("value"));
1205 // check if it is a fade effect
1206 if (effectId == "fadein") {
1208 if (m_effectList.hasEffect(QString(), "fade_from_black") == -1) {
1209 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1210 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1212 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fade_from_black");
1213 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1214 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1216 } else if (effectId == "fade_from_black") {
1218 if (m_effectList.hasEffect(QString(), "fadein") == -1) {
1219 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1220 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1222 QDomElement fadein = m_effectList.getEffectByTag(QString(), "fadein");
1223 if (fadein.attribute("name") == "out") fade += fadein.attribute("value").toInt();
1224 else if (fadein.attribute("name") == "in") fade -= fadein.attribute("value").toInt();
1226 } else if (effectId == "fadeout") {
1228 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
1229 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1230 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1232 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fade_to_black");
1233 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1234 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1236 } else if (effectId == "fade_to_black") {
1238 if (m_effectList.hasEffect(QString(), "fadeout") == -1) {
1239 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1240 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1242 QDomElement fadeout = m_effectList.getEffectByTag(QString(), "fadeout");
1243 if (fadeout.attribute("name") == "out") fade -= fadeout.attribute("value").toInt();
1244 else if (fadeout.attribute("name") == "in") fade += fadeout.attribute("value").toInt();
1248 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / f));
1252 m_effectNames = m_effectList.effectNames().join(" / ");
1253 if (fade > 0) m_startFade = fade;
1254 else if (fade < 0) m_endFade = -fade;
1255 if (needRepaint) update(boundingRect());
1258 } else if (!needRepaint) {
1259 QRectF r = boundingRect();
1263 if (m_selectedEffect == -1) {
1264 m_selectedEffect = 0;
1265 setSelectedEffect(m_selectedEffect);
1270 EffectsParameterList ClipItem::getEffectArgs(QDomElement effect) {
1271 EffectsParameterList parameters;
1272 parameters.addParam("tag", effect.attribute("tag"));
1273 parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
1274 parameters.addParam("id", effect.attribute("id"));
1275 if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
1276 QString state = effect.attribute("disabled");
1277 if (!state.isEmpty()) {
1278 parameters.addParam("disabled", state);
1281 QDomNodeList params = effect.elementsByTagName("parameter");
1282 for (int i = 0; i < params.count(); i++) {
1283 QDomElement e = params.item(i).toElement();
1284 //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
1285 if (e.attribute("type") == "keyframe") {
1286 kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
1287 parameters.addParam("keyframes", e.attribute("keyframes"));
1288 parameters.addParam("max", e.attribute("max"));
1289 parameters.addParam("min", e.attribute("min"));
1290 parameters.addParam("factor", e.attribute("factor", "1"));
1291 parameters.addParam("starttag", e.attribute("starttag", "start"));
1292 parameters.addParam("endtag", e.attribute("endtag", "end"));
1293 } else if (e.attribute("namedesc").contains(';')) {
1294 QString format = e.attribute("format");
1295 QStringList separators = format.split("%d", QString::SkipEmptyParts);
1296 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
1298 QTextStream txtNeu(&neu);
1299 if (values.size() > 0)
1300 txtNeu << (int)values[0].toDouble();
1301 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
1302 txtNeu << separators[i];
1303 txtNeu << (int)(values[i+1].toDouble());
1305 parameters.addParam("start", neu);
1307 if (e.attribute("factor", "1") != "1") {
1308 parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / e.attribute("factor").toDouble()));
1310 parameters.addParam(e.attribute("name"), e.attribute("value"));
1317 void ClipItem::deleteEffect(QString index) {
1318 bool needRepaint = false;
1321 for (int i = 0; i < m_effectList.size(); ++i) {
1322 ix = m_effectList.at(i).attribute("kdenlive_ix");
1324 QString effectId = m_effectList.at(i).attribute("id");
1325 if ((effectId == "fadein" && hasEffect(QString(), "fade_from_black") == -1) ||
1326 (effectId == "fade_from_black" && hasEffect(QString(), "fadein") == -1)) {
1329 } else if ((effectId == "fadeout" && hasEffect(QString(), "fade_to_black") == -1) ||
1330 (effectId == "fade_to_black" && hasEffect(QString(), "fadeout") == -1)) {
1334 m_effectList.removeAt(i);
1336 } else if (ix.toInt() > index.toInt()) {
1337 m_effectList[i].setAttribute("kdenlive_ix", ix.toInt() - 1);
1340 m_effectNames = m_effectList.effectNames().join(" / ");
1341 if (needRepaint) update(boundingRect());
1345 double ClipItem::speed() const {
1349 void ClipItem::setSpeed(const double speed) {
1351 if (m_speed == 1.0) m_clipName = baseClip()->name();
1352 else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + '%';
1356 GenTime ClipItem::maxDuration() const {
1357 return m_maxDuration / m_speed;
1360 GenTime ClipItem::cropStart() const {
1361 return m_cropStart / m_speed;
1364 GenTime ClipItem::cropDuration() const {
1365 return m_cropDuration / m_speed;
1368 GenTime ClipItem::endPos() const {
1369 return m_startPos + cropDuration();
1373 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
1374 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
1376 doc.setContent(effects, true);
1377 QDomElement e = doc.documentElement();
1378 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1379 if (view) view->slotAddEffect(e, m_startPos, track());
1383 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
1384 if (isItemLocked()) event->setAccepted(false);
1385 else event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
1388 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
1392 void ClipItem::addTransition(Transition* t) {
1393 m_transitionsList.append(t);
1394 //CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1396 QDomElement e = doc.documentElement();
1397 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1400 void ClipItem::setVideoOnly(bool force) {
1401 m_videoOnly = force;
1404 void ClipItem::setAudioOnly(bool force) {
1405 m_audioOnly = force;
1408 bool ClipItem::isAudioOnly() const {
1412 bool ClipItem::isVideoOnly() const {
1419 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
1421 int pos = event->x();
1422 if (event->modifiers() == Qt::ControlModifier)
1423 setDragMode(QGraphicsView::ScrollHandDrag);
1424 else if (event->modifiers() == Qt::ShiftModifier)
1425 setDragMode(QGraphicsView::RubberBandDrag);
1427 QGraphicsItem * item = itemAt(event->pos());
1430 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
1433 QGraphicsView::mousePressEvent(event);
1436 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
1438 QGraphicsView::mouseReleaseEvent(event);
1439 setDragMode(QGraphicsView::NoDrag);
1443 #include "clipitem.moc"