1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
24 #include <QStyleOptionGraphicsItem>
25 #include <QGraphicsScene>
26 #include <QGraphicsView>
29 #include <QApplication>
34 #include "customtrackview.h"
35 #include "customtrackscene.h"
37 #include "docclipbase.h"
38 #include "transition.h"
39 #include "kdenlivesettings.h"
43 ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, bool generateThumbs)
44 : AbstractClipItem(info, QRectF(), fps), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_startThumbRequested(false), m_endThumbRequested(false), m_startFade(0), m_endFade(0), m_hover(false), m_selectedEffect(-1), m_speed(1.0), framePixelWidth(0), m_startPix(QPixmap()), m_endPix(QPixmap()) {
45 setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (qreal)(KdenliveSettings::trackheight() - 2));
46 setPos((qreal) info.startPos.frames(fps), (qreal)(info.track * KdenliveSettings::trackheight()) + 1);
48 m_clipName = clip->name();
49 m_producer = clip->getId();
50 m_clipType = clip->clipType();
51 m_cropStart = info.cropStart;
52 m_maxDuration = clip->maxDuration();
54 audioThumbReady = clip->audioThumbCreated();
57 m_cropStart = xml.attribute("in", 0).toInt();
58 m_maxDuration = xml.attribute("duration", 0).toInt();
59 if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
61 if (duration != -1) m_cropDuration = duration;
62 else m_cropDuration = m_maxDuration;*/
65 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
66 setAcceptsHoverEvents(true);
67 connect(this , SIGNAL(prepareAudioThumb(double, int, int, int)) , this, SLOT(slotPrepareAudioThumb(double, int, int, int)));
69 setBrush(QColor(141, 166, 215));
70 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) {
72 startThumbTimer = new QTimer(this);
73 startThumbTimer->setSingleShot(true);
74 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
75 endThumbTimer = new QTimer(this);
76 endThumbTimer->setSingleShot(true);
77 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
79 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
80 //connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(getVideoThumbs(int, int)));
82 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
83 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
84 if (generateThumbs) QTimer::singleShot(200, this, SLOT(slotFetchThumbs()));
86 /*if (m_clip->producer()) {
87 videoThumbProducer.init(this, m_clip->producer(), KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio(), KdenliveSettings::trackheight());
90 } else if (m_clipType == COLOR) {
91 QString colour = clip->getProperty("colour");
92 colour = colour.replace(0, 2, "#");
93 setBrush(QColor(colour.left(7)));
94 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
95 m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(KdenliveSettings::trackheight() * KdenliveSettings::project_display_ratio()), KdenliveSettings::trackheight());
96 m_endPix = m_startPix;
97 } else if (m_clipType == AUDIO) {
98 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
103 ClipItem::~ClipItem() {
104 if (startThumbTimer) delete startThumbTimer;
105 if (endThumbTimer) delete endThumbTimer;
106 if (m_timeLine) m_timeLine;
109 ClipItem *ClipItem::clone(ItemInfo info) const {
110 ClipItem *duplicate = new ClipItem(m_clip, info, m_fps);
111 if (info.cropStart == cropStart()) duplicate->slotSetStartThumb(m_startPix);
112 if (info.cropStart + (info.endPos - info.startPos) == m_cropStart + m_cropDuration) duplicate->slotSetEndThumb(m_endPix);
113 kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps);
114 duplicate->setEffectList(m_effectList.clone());
115 duplicate->setSpeed(m_speed);
119 void ClipItem::setEffectList(const EffectsList effectList) {
120 m_effectList = effectList;
121 m_effectNames = m_effectList.effectNames().join(" / ");
124 const EffectsList ClipItem::effectList() {
128 int ClipItem::selectedEffectIndex() const {
129 return m_selectedEffect;
132 void ClipItem::initEffect(QDomElement effect) {
133 // the kdenlive_ix int is used to identify an effect in mlt's playlist, should
135 if (effect.attribute("kdenlive_ix").toInt() == 0)
136 effect.setAttribute("kdenlive_ix", QString::number(effectsCounter()));
137 // init keyframes if required
138 QDomNodeList params = effect.elementsByTagName("parameter");
139 for (int i = 0; i < params.count(); i++) {
140 QDomElement e = params.item(i).toElement();
141 if (!e.isNull() && e.attribute("type") == "keyframe") {
142 QString def = e.attribute("default");
143 // Effect has a keyframe type parameter, we need to set the values
144 if (e.attribute("keyframes").isEmpty()) {
145 e.setAttribute("keyframes", QString::number(m_cropStart.frames(m_fps)) + ":" + def + ";" + QString::number((m_cropStart + m_cropDuration).frames(m_fps)) + ":" + def);
146 //kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
153 bool ClipItem::checkKeyFrames() {
154 bool clipEffectsModified = false;
155 for (int ix = 0; ix < m_effectList.count(); ix ++) {
156 QString kfr = keyframes(ix);
157 if (!kfr.isEmpty()) {
158 const QStringList keyframes = kfr.split(";", QString::SkipEmptyParts);
159 QStringList newKeyFrames;
160 bool cutKeyFrame = false;
161 bool modified = false;
163 double lastValue = -1;
164 int start = m_cropStart.frames(m_fps);
165 int end = (m_cropStart + m_cropDuration).frames(m_fps);
166 foreach(const QString str, keyframes) {
167 int pos = str.section(":", 0, 0).toInt();
168 double val = str.section(":", 1, 1).toDouble();
169 if (pos - start < 0) {
170 // a keyframe is defined before the start of the clip
172 } else if (cutKeyFrame) {
173 // create new keyframe at clip start, calculate interpolated value
175 int diff = pos - lastPos;
176 double ratio = (double)(start - lastPos) / diff;
177 double newValue = lastValue + (val - lastValue) * ratio;
178 newKeyFrames.append(QString::number(start) + ":" + QString::number(newValue));
185 // create new keyframe at clip end, calculate interpolated value
186 int diff = pos - lastPos;
188 double ratio = (double)(end - lastPos) / diff;
189 double newValue = lastValue + (val - lastValue) * ratio;
190 newKeyFrames.append(QString::number(end) + ":" + QString::number(newValue));
195 newKeyFrames.append(QString::number(pos) + ":" + QString::number(val));
203 setKeyframes(ix, newKeyFrames.join(";"));
204 clipEffectsModified = true;
208 return clipEffectsModified;
211 void ClipItem::setKeyframes(const int ix, const QString keyframes) {
212 QDomElement effect = effectAt(ix);
213 if (effect.attribute("disabled") == "1") return;
214 QDomNodeList params = effect.elementsByTagName("parameter");
215 for (int i = 0; i < params.count(); i++) {
216 QDomElement e = params.item(i).toElement();
217 if (!e.isNull() && e.attribute("type") == "keyframe") {
218 e.setAttribute("keyframes", keyframes);
219 if (ix == m_selectedEffect) {
221 double max = e.attribute("max").toDouble();
222 double min = e.attribute("min").toDouble();
223 m_keyframeFactor = 100.0 / (max - min);
224 m_keyframeDefault = e.attribute("default").toDouble();
226 const QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
227 foreach(const QString str, keyframes) {
228 int pos = str.section(":", 0, 0).toInt();
229 double val = str.section(":", 1, 1).toDouble();
230 m_keyframes[pos] = val;
241 void ClipItem::setSelectedEffect(const int ix) {
242 m_selectedEffect = ix;
243 QDomElement effect = effectAt(m_selectedEffect);
244 QDomNodeList params = effect.elementsByTagName("parameter");
245 if (effect.attribute("disabled") != "1")
246 for (int i = 0; i < params.count(); i++) {
247 QDomElement e = params.item(i).toElement();
248 if (!e.isNull() && e.attribute("type") == "keyframe") {
250 double max = e.attribute("max").toDouble();
251 double min = e.attribute("min").toDouble();
252 m_keyframeFactor = 100.0 / (max - min);
253 m_keyframeDefault = e.attribute("default").toDouble();
255 const QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
256 foreach(const QString str, keyframes) {
257 int pos = str.section(":", 0, 0).toInt();
258 double val = str.section(":", 1, 1).toDouble();
259 m_keyframes[pos] = val;
265 if (!m_keyframes.isEmpty()) {
271 QString ClipItem::keyframes(const int index) {
273 QDomElement effect = effectAt(index);
274 QDomNodeList params = effect.elementsByTagName("parameter");
276 for (int i = 0; i < params.count(); i++) {
277 QDomElement e = params.item(i).toElement();
278 if (!e.isNull() && e.attribute("type") == "keyframe") {
279 result = e.attribute("keyframes");
286 void ClipItem::updateKeyframeEffect() {
287 // regenerate xml parameter from the clip keyframes
288 QDomElement effect = effectAt(m_selectedEffect);
289 if (effect.attribute("disabled") == "1") return;
290 QDomNodeList params = effect.elementsByTagName("parameter");
292 for (int i = 0; i < params.count(); i++) {
293 QDomElement e = params.item(i).toElement();
294 if (!e.isNull() && e.attribute("type") == "keyframe") {
296 if (m_keyframes.count() > 1) {
297 QMap<int, double>::const_iterator i = m_keyframes.constBegin();
300 while (i != m_keyframes.constEnd()) {
301 keyframes.append(QString::number(i.key()) + ":" + QString::number(i.value()) + ";");
305 // Effect has a keyframe type parameter, we need to set the values
306 //kDebug() << "::::::::::::::: SETTING EFFECT KEYFRAMES: " << keyframes;
307 e.setAttribute("keyframes", keyframes);
313 QDomElement ClipItem::selectedEffect() {
314 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
315 return effectAt(m_selectedEffect);
318 void ClipItem::resetThumbs() {
319 m_startPix = QPixmap();
320 m_endPix = QPixmap();
322 audioThumbCachePic.clear();
326 void ClipItem::refreshClip() {
327 m_maxDuration = m_clip->maxDuration();
328 if (m_clipType == COLOR) {
329 QString colour = m_clip->getProperty("colour");
330 colour = colour.replace(0, 2, "#");
331 setBrush(QColor(colour.left(7)));
332 } else slotFetchThumbs();
335 void ClipItem::slotFetchThumbs() {
336 if (m_endPix.isNull() && m_startPix.isNull()) {
337 m_startThumbRequested = true;
338 m_endThumbRequested = true;
339 emit getThumb((int)m_cropStart.frames(m_fps), (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1);
341 if (m_endPix.isNull()) {
344 if (m_startPix.isNull()) {
350 if (m_endPix.isNull() && m_startPix.isNull()) {
351 int frame1 = (int)m_cropStart.frames(m_fps);
352 int frame2 = (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1;
353 //videoThumbProducer.setThumbFrames(m_clip->producer(), frame1, frame2);
354 //videoThumbProducer.start(QThread::LowestPriority);
356 if (m_endPix.isNull()) slotGetEndThumb();
357 else slotGetStartThumb();
360 } else if (m_startPix.isNull()) slotGetStartThumb();*/
363 void ClipItem::slotGetStartThumb() {
364 m_startThumbRequested = true;
365 emit getThumb((int)m_cropStart.frames(m_fps), -1);
366 //videoThumbProducer.setThumbFrames(m_clip->producer(), (int)m_cropStart.frames(m_fps), - 1);
367 //videoThumbProducer.start(QThread::LowestPriority);
370 void ClipItem::slotGetEndThumb() {
371 m_endThumbRequested = true;
372 emit getThumb(-1, (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1);
373 //videoThumbProducer.setThumbFrames(m_clip->producer(), -1, (int)(m_cropStart + m_cropDuration).frames(m_fps) - 1);
374 //videoThumbProducer.start(QThread::LowestPriority);
378 void ClipItem::slotSetStartThumb(QImage img) {
379 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
380 QPixmap pix = QPixmap::fromImage(img);
382 QRectF r = sceneBoundingRect();
383 r.setRight(pix.width() + 2);
388 void ClipItem::slotSetEndThumb(QImage img) {
389 if (!img.isNull() && img.format() == QImage::Format_ARGB32) {
390 QPixmap pix = QPixmap::fromImage(img);
392 QRectF r = sceneBoundingRect();
393 r.setLeft(r.right() - pix.width() - 2);
398 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
399 if (scene() == NULL) return;
400 QRectF r = sceneBoundingRect();
401 double width = m_startPix.width() / projectScene()->scale();
402 if (m_startThumbRequested && frame == m_cropStart.frames(m_fps)) {
404 m_startThumbRequested = false;
405 double height = r.height();
406 update(r.x(), r.y(), width, height);
407 } else if (m_endThumbRequested && frame == (m_cropStart + m_cropDuration).frames(m_fps) - 1) {
409 m_endThumbRequested = false;
410 double height = r.height();
411 update(r.right() - width, r.y(), width, height);
415 void ClipItem::slotSetStartThumb(QPixmap pix) {
419 void ClipItem::slotSetEndThumb(QPixmap pix) {
423 void ClipItem::slotGotAudioData() {
424 audioThumbReady = true;
425 if (m_clipType == AV) {
426 QRectF r = boundingRect();
427 r.setTop(r.top() + r.height() / 2 - 1);
432 int ClipItem::type() const {
436 DocClipBase *ClipItem::baseClip() const {
440 QDomElement ClipItem::xml() const {
441 return m_clip->toXML();
444 int ClipItem::clipType() const {
448 QString ClipItem::clipName() const {
452 const QString &ClipItem::clipProducer() const {
456 void ClipItem::flashClip() {
457 if (m_timeLine == 0) {
458 m_timeLine = new QTimeLine(750, this);
459 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
460 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
465 void ClipItem::animate(qreal value) {
466 QRectF r = boundingRect();
472 void ClipItem::paint(QPainter *painter,
473 const QStyleOptionGraphicsItem *option,
475 painter->setOpacity(m_opacity);
476 QBrush paintColor = brush();
477 if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
479 QRectF exposed = option->exposedRect;
480 QRectF mapped = painter->matrix().mapRect(br);
482 const double itemWidth = br.width();
483 const double itemHeight = br.height();
484 const double scale = option->matrix.m11();
487 //painter->setRenderHints(QPainter::Antialiasing);
489 //QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
490 painter->setClipRect(exposed);
492 // build path around clip
493 //QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
494 //painter->fillPath(resultClipPath, paintColor);
495 painter->fillRect(br, paintColor);
497 //painter->setClipPath(resultClipPath, Qt::IntersectClip);
500 painter->setMatrixEnabled(false);
502 if (KdenliveSettings::videothumbnails()) {
503 QPen pen = painter->pen();
504 pen.setStyle(Qt::DotLine);
505 pen.setColor(Qt::white);
506 painter->setPen(pen);
507 if (m_clipType == IMAGE && !m_startPix.isNull()) {
508 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_startPix.width(), 0);
509 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_startPix.width(), 0);
510 painter->drawPixmap(p1, m_startPix);
512 painter->drawLine(l);
513 } else if (!m_endPix.isNull()) {
514 QPointF p1 = painter->matrix().map(QPointF(itemWidth, 0)) - QPointF(m_endPix.width(), 0);
515 QPointF p2 = painter->matrix().map(QPointF(itemWidth, itemHeight)) - QPointF(m_endPix.width(), 0);
516 painter->drawPixmap(p1, m_endPix);
518 painter->drawLine(l);
520 if (!m_startPix.isNull()) {
521 QPointF p1 = painter->matrix().map(QPointF(0, 0));
522 QPointF p2 = painter->matrix().map(QPointF(0, itemHeight));
523 painter->drawPixmap(p1, m_startPix);
524 QLineF l2(p1.x() + m_startPix.width(), p1.y(), p2.x() + m_startPix.width(), p2.y());
525 painter->drawLine(l2);
527 painter->setPen(Qt::black);
530 // draw audio thumbnails
531 if (KdenliveSettings::audiothumbnails() && ((m_clipType == AV && exposed.bottom() > (itemHeight / 2)) || m_clipType == AUDIO) && audioThumbReady) {
533 double startpixel = exposed.left();
536 double endpixel = exposed.right();
539 //kDebug()<<"/// REPAINTING AUDIO THMBS ZONE: "<<startpixel<<"x"<<endpixel;
541 /*QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;*/
543 if (m_clipType == AV) {
545 re.setTop(re.y() + re.height() / 2);
546 mappedRect = painter->matrix().mapRect(re);
547 //painter->fillRect(mappedRect, QBrush(QColor(200, 200, 200, 140)));
548 } else mappedRect = mapped;
550 int channels = baseClip()->getProperty("channels").toInt();
551 if (scale != framePixelWidth)
552 audioThumbCachePic.clear();
553 double cropLeft = m_cropStart.frames(m_fps);
554 const int clipStart = mappedRect.x();
555 const int mappedStartPixel = painter->matrix().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart;
556 const int mappedEndPixel = painter->matrix().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
557 cropLeft = cropLeft * scale;
560 emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
563 for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) {
564 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
565 painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), audioThumbCachePic[startCache]);
570 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
571 QList < CommentedTime >::Iterator it = markers.begin();
574 const int markerwidth = 4;
576 markerBrush = QBrush(QColor(120, 120, 0, 140));
577 QPen pen = painter->pen();
578 pen.setColor(QColor(255, 255, 255, 200));
579 pen.setStyle(Qt::DotLine);
580 painter->setPen(pen);
581 for (; it != markers.end(); ++it) {
582 pos = (*it).time() - cropStart();
583 if (pos > GenTime()) {
584 if (pos > duration()) break;
585 QLineF l(br.x() + pos.frames(m_fps), br.y() + 5, br.x() + pos.frames(m_fps), br.bottom() - 5);
586 QLineF l2 = painter->matrix().map(l);
587 //framepos = scale * pos.frames(m_fps);
588 //QLineF l(framepos, 5, framepos, itemHeight - 5);
589 painter->drawLine(l2);
590 if (KdenliveSettings::showmarkers()) {
591 framepos = br.x() + pos.frames(m_fps);
592 const QRectF r1(framepos + 0.04, 10, itemWidth - framepos - 2, itemHeight - 10);
593 const QRectF r2 = painter->matrix().mapRect(r1);
594 const QRectF txtBounding = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, " " + (*it).comment() + " ");
597 path.addRoundedRect(txtBounding, 3, 3);
598 painter->fillPath(path, markerBrush);
599 painter->drawText(txtBounding, Qt::AlignCenter, (*it).comment());
601 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
604 pen.setColor(Qt::black);
605 pen.setStyle(Qt::SolidLine);
606 painter->setPen(pen);
608 // draw start / end fades
611 fades = QBrush(QColor(200, 50, 50, 150));
612 } else fades = QBrush(QColor(200, 200, 200, 200));
614 if (m_startFade != 0) {
615 QPainterPath fadeInPath;
616 fadeInPath.moveTo(0, 0);
617 fadeInPath.lineTo(0, itemHeight);
618 fadeInPath.lineTo(m_startFade, 0);
619 fadeInPath.closeSubpath();
620 QPainterPath f1 = painter->matrix().map(fadeInPath);
621 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
622 /*if (isSelected()) {
623 QLineF l(m_startFade * scale, 0, 0, itemHeight);
624 painter->drawLine(l);
627 if (m_endFade != 0) {
628 QPainterPath fadeOutPath;
629 fadeOutPath.moveTo(itemWidth, 0);
630 fadeOutPath.lineTo(itemWidth, itemHeight);
631 fadeOutPath.lineTo(itemWidth - m_endFade, 0);
632 fadeOutPath.closeSubpath();
633 QPainterPath f1 = painter->matrix().map(fadeOutPath);
634 painter->fillPath(f1/*.intersected(resultClipPath)*/, fades);
635 /*if (isSelected()) {
636 QLineF l(itemWidth - m_endFade * scale, 0, itemWidth, itemHeight);
637 painter->drawLine(l);
641 // Draw effects names
642 if (!m_effectNames.isEmpty() && itemWidth * scale > 40) {
643 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
644 txtBounding.setRight(txtBounding.right() + 15);
645 painter->setPen(Qt::white);
646 QBrush markerBrush(Qt::SolidPattern);
647 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
648 qreal value = m_timeLine->currentValue();
649 txtBounding.setWidth(txtBounding.width() * value);
650 markerBrush.setColor(QColor(50 + 200 * (1.0 - value), 50, 50, 100 + 50 * value));
651 } else markerBrush.setColor(QColor(50, 50, 50, 150));
653 path.addRoundedRect(txtBounding, 4, 4);
654 painter->fillPath(path/*.intersected(resultClipPath)*/, markerBrush);
655 painter->drawText(txtBounding, Qt::AlignCenter, m_effectNames);
656 painter->setPen(Qt::black);
660 QRectF txtBounding = painter->boundingRect(mapped, Qt::AlignHCenter | Qt::AlignVCenter, " " + m_clipName + " ");
661 painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
662 //painter->setPen(QColor(0, 0, 0, 180));
663 //painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
664 txtBounding.translate(QPointF(1, 1));
665 painter->setPen(QColor(255, 255, 255, 255));
666 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
669 // draw transition handles on hover
670 if (m_hover && itemWidth * scale > 40) {
671 QPointF p1 = painter->matrix().map(QPointF(0, itemHeight / 2)) + QPointF(10, 0);
672 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
673 p1 = painter->matrix().map(QPointF(itemWidth, itemHeight / 2)) - QPointF(22, 0);
674 painter->drawPixmap(p1, projectScene()->m_transitionPixmap);
678 // draw frame around clip
680 pen.setColor(Qt::red);
683 pen.setColor(Qt::black);
687 // draw effect or transition keyframes
688 if (itemWidth > 20) drawKeyFrames(painter, exposed);
690 painter->setMatrixEnabled(true);
694 //kDebug()<<"/// ITEM PAINTING:: exposed="<<exposed<<", RECT = "<<rect();
696 // expand clip rect to allow correct painting of clip border
697 exposed.setRight(exposed.right() + 1 / scale + 0.5);
698 exposed.setBottom(exposed.bottom() + 1);
699 painter->setClipRect(exposed);
700 painter->setPen(pen);
701 painter->drawRect(br);
705 OPERATIONTYPE ClipItem::operationMode(QPointF pos) {
707 m_editedKeyframe = mouseOverKeyFrames(pos);
708 if (m_editedKeyframe != -1) return KEYFRAME;
710 QRectF rect = sceneBoundingRect();
711 const double scale = projectScene()->scale();
712 double maximumOffset = 6 / scale;
714 if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
715 if (m_startFade == 0) setToolTip(i18n("Add audio fade"));
716 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_startFade, m_fps).seconds()));
718 } else if (pos.x() - rect.x() < maximumOffset) {
719 setToolTip(i18n("Crop from start: %1s", cropStart().seconds()));
721 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - m_endFade))) < maximumOffset && qAbs((int)(pos.y() - rect.y())) < 6) {
722 if (m_endFade == 0) setToolTip(i18n("Add audio fade"));
723 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_endFade, m_fps).seconds()));
725 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width()))) < maximumOffset) {
726 setToolTip(i18n("Clip duration: %1s", duration().seconds()));
728 } else if (qAbs((int)(pos.x() - (rect.x() + 16 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
729 setToolTip(i18n("Add transition"));
730 return TRANSITIONSTART;
731 } else if (qAbs((int)(pos.x() - (rect.x() + rect.width() - 21 / scale))) < maximumOffset && qAbs((int)(pos.y() - (rect.y() + rect.height() / 2 + 9))) < 6) {
732 setToolTip(i18n("Add transition"));
733 return TRANSITIONEND;
735 setToolTip(QString());
739 QList <GenTime> ClipItem::snapMarkers() const {
740 QList < GenTime > snaps;
741 QList < GenTime > markers = baseClip()->snapMarkers();
745 for (int i = 0; i < markers.size(); i++) {
746 pos = markers.at(i) - cropStart();
747 if (pos > GenTime()) {
748 if (pos > duration()) break;
749 else snaps.append(pos + startPos());
755 QList <CommentedTime> ClipItem::commentedSnapMarkers() const {
756 QList < CommentedTime > snaps;
757 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
761 for (int i = 0; i < markers.size(); i++) {
762 pos = markers.at(i).time() - cropStart();
763 if (pos > GenTime()) {
764 if (pos > duration()) break;
765 else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
771 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels) {
772 QRectF re = sceneBoundingRect();
773 if (m_clipType == AV) re.setTop(re.y() + re.height() / 2);
775 //kDebug() << "// PREP AUDIO THMB FRMO : scale:" << pixelForOneFrame<< ", from: " << startpixel << ", to: " << endpixel;
776 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
778 for (int startCache = startpixel - startpixel % 100;startCache < endpixel;startCache += 100) {
779 //kDebug() << "creating " << startCache;
780 //if (framePixelWidth!=pixelForOneFrame ||
781 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
783 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
784 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
785 audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140));
787 bool fullAreaDraw = pixelForOneFrame < 10;
788 QMap<int, QPainterPath > positiveChannelPaths;
789 QMap<int, QPainterPath > negativeChannelPaths;
790 QPainter pixpainter(&audioThumbCachePic[startCache]);
792 audiopen.setWidth(0);
793 pixpainter.setPen(audiopen);
794 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
795 //pixpainter.drawLine(0,0,100,re.height());
796 // Bail out, if caller provided invalid data
798 kWarning() << "Unable to draw image with " << channels << "number of channels";
802 int channelHeight = audioThumbCachePic[startCache].height() / channels;
804 for (int i = 0;i < channels;i++) {
806 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
807 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
810 for (int samples = 0;samples <= 100;samples++) {
811 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
812 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
813 if (frame < 0 || sample < 0 || sample > 19)
815 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
817 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
819 int y = channelHeight * channel + channelHeight / 2;
820 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
822 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
823 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
825 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
826 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
829 for (int channel = 0;channel < channels ;channel++)
830 if (fullAreaDraw && samples == 100) {
831 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
832 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
833 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
834 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
838 if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
840 pixpainter.setPen(QPen(QColor(0, 0, 0)));
841 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
843 for (int i = 0;i < channels;i++) {
845 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
846 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
848 pixpainter.drawPath(positiveChannelPaths[i]);
851 //audioThumbWasDrawn=true;
852 framePixelWidth = pixelForOneFrame;
857 uint ClipItem::fadeIn() const {
861 uint ClipItem::fadeOut() const {
866 void ClipItem::setFadeIn(int pos) {
867 int oldIn = m_startFade;
868 if (pos < 0) pos = 0;
869 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
871 QRectF rect = boundingRect();
872 update(rect.x(), rect.y(), qMax(oldIn, pos), rect.height());
875 void ClipItem::setFadeOut(int pos) {
876 int oldOut = m_endFade;
877 if (pos < 0) pos = 0;
878 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
880 QRectF rect = boundingRect();
881 update(rect.x() + rect.width() - qMax(oldOut, pos), rect.y(), pos, rect.height());
886 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
887 /*m_resizeMode = operationMode(event->pos());
888 if (m_resizeMode == MOVE) {
889 m_maxTrack = scene()->sceneRect().height();
890 m_grabPoint = (int) (event->pos().x() - rect().x());
892 QGraphicsRectItem::mousePressEvent(event);
896 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
898 QGraphicsRectItem::mouseReleaseEvent(event);
902 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e) {
903 //if (e->pos().x() < 20) m_hover = true;
905 QRectF r = boundingRect();
906 double width = 35 / projectScene()->scale();
907 double height = r.height() / 2;
908 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
909 update(r.x(), r.y() + height, width, height);
910 update(r.right() - width, r.y() + height, width, height);
914 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
916 QRectF r = boundingRect();
917 double width = 35 / projectScene()->scale();
918 double height = r.height() / 2;
919 //WARNING: seems like it generates a full repaint of the clip, maybe not so good...
920 update(r.x(), r.y() + height, width, height);
921 update(r.right() - width, r.y() + height, width, height);
924 void ClipItem::resizeStart(int posx) {
925 const int min = (startPos() - cropStart()).frames(m_fps);
926 if (posx < min) posx = min;
927 if (posx == startPos().frames(m_fps)) return;
928 const int previous = cropStart().frames(m_fps);
929 AbstractClipItem::resizeStart(posx);
930 checkEffectsKeyframesPos(previous, cropStart().frames(m_fps), true);
931 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
932 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
933 startThumbTimer->start(100);
937 void ClipItem::resizeEnd(int posx, bool updateKeyFrames) {
938 const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps) + 1;
939 if (posx > max) posx = max;
940 if (posx == endPos().frames(m_fps)) return;
941 const int previous = (cropStart() + duration()).frames(m_fps);
942 AbstractClipItem::resizeEnd(posx);
943 if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false);
944 if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
945 /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
946 endThumbTimer->start(100);
951 void ClipItem::checkEffectsKeyframesPos(const int previous, const int current, bool fromStart) {
952 for (int i = 0; i < m_effectList.size(); i++) {
953 QDomElement effect = m_effectList.at(i);
954 QDomNodeList params = effect.elementsByTagName("parameter");
955 for (int j = 0; j < params.count(); j++) {
956 QDomElement e = params.item(i).toElement();
957 if (e.attribute("type") == "keyframe") {
958 // parse keyframes and adjust values
959 const QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
960 QMap <int, double> kfr;
963 foreach(const QString str, keyframes) {
964 pos = str.section(":", 0, 0).toInt();
965 val = str.section(":", 1, 1).toDouble();
966 if (pos == previous) kfr[current] = val;
968 if (fromStart && pos >= current) kfr[pos] = val;
969 else if (!fromStart && pos <= current) kfr[pos] = val;
973 QMap<int, double>::const_iterator k = kfr.constBegin();
974 while (k != kfr.constEnd()) {
975 newkfr.append(QString::number(k.key()) + ":" + QString::number(k.value()) + ";");
978 e.setAttribute("keyframes", newkfr);
983 if (m_selectedEffect >= 0) setSelectedEffect(m_selectedEffect);
988 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value) {
989 if (change == ItemPositionChange && scene()) {
990 // calculate new position.
991 if (group() != 0) return pos();
992 QPointF newPos = value.toPointF();
993 //kDebug() << "/// MOVING CLIP ITEM.------------";
994 int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
995 xpos = qMax(xpos, 0);
997 int newTrack = (newPos.y() + KdenliveSettings::trackheight() / 2) / KdenliveSettings::trackheight();
998 newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
999 newTrack = qMax(newTrack, 0);
1000 newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1));
1001 // Only one clip is moving
1002 QRectF sceneShape = rect();
1003 sceneShape.translate(newPos);
1004 QList<QGraphicsItem*> items = scene()->items(sceneShape, Qt::IntersectsItemShape);
1005 items.removeAll(this);
1007 if (!items.isEmpty()) {
1008 for (int i = 0; i < items.count(); i++) {
1009 if (items.at(i)->type() == type()) {
1011 QPointF otherPos = items.at(i)->pos();
1012 if ((int) otherPos.y() != (int) pos().y()) return pos();
1013 if (pos().x() < otherPos.x()) {
1014 // move clip just before colliding clip
1015 int npos = (static_cast < AbstractClipItem* >(items.at(i))->startPos() - m_cropDuration).frames(m_fps);
1016 // check we don't run into another clip
1018 sceneShape = rect();
1019 sceneShape.translate(newPos);
1020 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1021 items.removeAll(this);
1022 for (int j = 0; j < subitems.count(); j++) {
1023 if (subitems.at(j)->type() == type()) return pos();
1026 // get pos just after colliding clip
1027 int npos = static_cast < AbstractClipItem* >(items.at(i))->endPos().frames(m_fps);
1028 // check we don't run into another clip
1030 sceneShape = rect();
1031 sceneShape.translate(newPos);
1032 QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
1033 items.removeAll(this);
1034 for (int j = 0; j < subitems.count(); j++) {
1035 if (subitems.at(j)->type() == type()) return pos();
1039 m_startPos = GenTime((int) newPos.x(), m_fps);
1045 m_startPos = GenTime((int) newPos.x(), m_fps);
1046 //kDebug()<<"// ITEM NEW POS: "<<newPos.x()<<", mapped: "<<mapToScene(newPos.x(), 0).x();
1049 return QGraphicsItem::itemChange(change, value);
1053 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
1056 int ClipItem::effectsCounter() {
1057 return effectsCount() + 1;
1060 int ClipItem::effectsCount() {
1061 return m_effectList.size();
1064 int ClipItem::hasEffect(const QString &tag, const QString &id) const {
1065 return m_effectList.hasEffect(tag, id);
1068 QStringList ClipItem::effectNames() {
1069 return m_effectList.effectNames();
1072 QDomElement ClipItem::effectAt(int ix) {
1073 if (ix > m_effectList.count() - 1 || ix < 0) return QDomElement();
1074 return m_effectList.at(ix);
1077 void ClipItem::setEffectAt(int ix, QDomElement effect) {
1078 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
1079 effect.setAttribute("kdenlive_ix", ix + 1);
1080 m_effectList.insert(ix, effect);
1081 m_effectList.removeAt(ix + 1);
1082 m_effectNames = m_effectList.effectNames().join(" / ");
1083 if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fadeout") update(boundingRect());
1085 QRectF r = boundingRect();
1091 QHash <QString, QString> ClipItem::addEffect(QDomElement effect, bool animate) {
1092 QHash <QString, QString> effectParams;
1093 bool needRepaint = false;
1095 doc.appendChild(doc.importNode(effect, true));
1096 kDebug() << "/////// CLIP ADD EFFECT: " << doc.toString();*/
1097 m_effectList.append(effect);
1098 effectParams["tag"] = effect.attribute("tag");
1099 QString effectId = effect.attribute("id");
1100 if (effectId.isEmpty()) effectId = effect.attribute("tag");
1101 effectParams["id"] = effectId;
1102 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
1103 QString state = effect.attribute("disabled");
1104 if (!state.isEmpty()) effectParams["disabled"] = state;
1105 QDomNodeList params = effect.elementsByTagName("parameter");
1107 for (int i = 0; i < params.count(); i++) {
1108 QDomElement e = params.item(i).toElement();
1110 if (e.attribute("type") == "keyframe") {
1111 effectParams["keyframes"] = e.attribute("keyframes");
1112 effectParams["min"] = e.attribute("min");
1113 effectParams["max"] = e.attribute("max");
1114 effectParams["factor"] = e.attribute("factor", "1");
1115 effectParams["starttag"] = e.attribute("starttag", "start");
1116 effectParams["endtag"] = e.attribute("endtag", "end");
1119 double f = e.attribute("factor", "1").toDouble();
1122 effectParams[e.attribute("name")] = e.attribute("value");
1123 // check if it is a fade effect
1124 if (effectId == "fadein") {
1126 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
1127 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
1128 } else if (effectId == "fadeout") {
1130 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
1131 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
1134 effectParams[e.attribute("name")] = QString::number(e.attribute("value").toDouble() / f);
1138 m_effectNames = m_effectList.effectNames().join(" / ");
1139 if (fade > 0) m_startFade = fade;
1140 else if (fade < 0) m_endFade = -fade;
1141 if (needRepaint) update(boundingRect());
1144 } else if (!needRepaint) {
1145 QRectF r = boundingRect();
1149 if (m_selectedEffect == -1) {
1150 m_selectedEffect = 0;
1151 setSelectedEffect(m_selectedEffect);
1153 return effectParams;
1156 QHash <QString, QString> ClipItem::getEffectArgs(QDomElement effect) {
1157 QHash <QString, QString> effectParams;
1158 effectParams["tag"] = effect.attribute("tag");
1159 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
1160 effectParams["id"] = effect.attribute("id");
1161 QString state = effect.attribute("disabled");
1162 if (!state.isEmpty()) effectParams["disabled"] = state;
1163 QDomNodeList params = effect.elementsByTagName("parameter");
1164 for (int i = 0; i < params.count(); i++) {
1165 QDomElement e = params.item(i).toElement();
1166 //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
1167 if (e.attribute("type") == "keyframe") {
1168 kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
1169 effectParams["keyframes"] = e.attribute("keyframes");
1170 effectParams["max"] = e.attribute("max");
1171 effectParams["min"] = e.attribute("min");
1172 effectParams["factor"] = e.attribute("factor", "1");
1173 effectParams["starttag"] = e.attribute("starttag", "start");
1174 effectParams["endtag"] = e.attribute("endtag", "end");
1175 } else if (e.attribute("namedesc").contains(";")) {
1176 QString format = e.attribute("format");
1177 QStringList separators = format.split("%d", QString::SkipEmptyParts);
1178 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
1180 QTextStream txtNeu(&neu);
1181 if (values.size() > 0)
1182 txtNeu << (int)values[0].toDouble();
1183 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
1184 txtNeu << separators[i];
1185 txtNeu << (int)(values[i+1].toDouble());
1187 effectParams["start"] = neu;
1189 if (e.attribute("factor", "1") != "1")
1190 effectParams[e.attribute("name")] = QString::number(e.attribute("value").toDouble() / e.attribute("factor").toDouble());
1191 else effectParams[e.attribute("name")] = e.attribute("value");
1194 return effectParams;
1197 void ClipItem::deleteEffect(QString index) {
1198 bool needRepaint = false;
1200 for (int i = 0; i < m_effectList.size(); ++i) {
1201 ix = m_effectList.at(i).attribute("kdenlive_ix");
1203 if (m_effectList.at(i).attribute("id") == "fadein") {
1206 } else if (m_effectList.at(i).attribute("id") == "fadeout") {
1210 m_effectList.removeAt(i);
1211 } else if (ix.toInt() > index.toInt()) m_effectList[i].setAttribute("kdenlive_ix", ix.toInt() - 1);
1213 m_effectNames = m_effectList.effectNames().join(" / ");
1214 if (needRepaint) update(boundingRect());
1218 double ClipItem::speed() const {
1222 void ClipItem::setSpeed(const double speed) {
1224 if (m_speed == 1.0) m_clipName = baseClip()->name();
1225 else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + "%";
1229 GenTime ClipItem::maxDuration() const {
1230 return m_maxDuration / m_speed;
1234 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
1235 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
1237 doc.setContent(effects, true);
1238 QDomElement e = doc.documentElement();
1239 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1240 if (view) view->slotAddEffect(e, m_startPos, track());
1244 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
1245 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
1248 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
1251 void ClipItem::addTransition(Transition* t) {
1252 m_transitionsList.append(t);
1253 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
1255 QDomElement e = doc.documentElement();
1256 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
1260 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
1262 int pos = event->x();
1263 if (event->modifiers() == Qt::ControlModifier)
1264 setDragMode(QGraphicsView::ScrollHandDrag);
1265 else if (event->modifiers() == Qt::ShiftModifier)
1266 setDragMode(QGraphicsView::RubberBandDrag);
1268 QGraphicsItem * item = itemAt(event->pos());
1271 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
1274 QGraphicsView::mousePressEvent(event);
1277 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
1279 QGraphicsView::mouseReleaseEvent(event);
1280 setDragMode(QGraphicsView::NoDrag);
1284 #include "clipitem.moc"