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"
36 #include "docclipbase.h"
37 #include "transition.h"
39 #include "kdenlivesettings.h"
42 ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, GenTime cropStart, double scale, double fps)
43 : AbstractClipItem(info, QRectF(), fps), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), m_effectsCounter(1), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_thumbsRequested(0), m_startFade(0), m_endFade(0), m_hover(false), m_selectedEffect(-1) {
44 QRectF rect((double) info.startPos.frames(fps) * scale, (double)(info.track * KdenliveSettings::trackheight() + 1), (double)(info.endPos - info.startPos).frames(fps) * scale, (double)(KdenliveSettings::trackheight() - 1));
47 m_clipName = clip->name();
48 m_producer = clip->getId();
49 m_clipType = clip->clipType();
50 m_cropStart = cropStart;
51 m_maxDuration = clip->maxDuration();
53 audioThumbReady = clip->audioThumbCreated();
54 /*m_keyframes[0] = 50;
57 m_keyframes[100] = 10;*/
59 m_cropStart = xml.attribute("in", 0).toInt();
60 m_maxDuration = xml.attribute("duration", 0).toInt();
61 if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
63 if (duration != -1) m_cropDuration = duration;
64 else m_cropDuration = m_maxDuration;*/
67 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
68 setAcceptsHoverEvents(true);
69 connect(this , SIGNAL(prepareAudioThumb(double, QPainterPath, int, int)) , this, SLOT(slotPrepareAudioThumb(double, QPainterPath, int, int)));
71 setBrush(QColor(141, 166, 215));
72 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW) {
74 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
75 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
76 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
77 QTimer::singleShot(300, this, SLOT(slotFetchThumbs()));
79 startThumbTimer = new QTimer(this);
80 startThumbTimer->setSingleShot(true);
81 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
82 endThumbTimer = new QTimer(this);
83 endThumbTimer->setSingleShot(true);
84 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
85 } else if (m_clipType == COLOR) {
86 QString colour = clip->getProperty("colour");
87 colour = colour.replace(0, 2, "#");
88 setBrush(QColor(colour.left(7)));
89 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
90 m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(50 * KdenliveSettings::project_display_ratio()), 50);
91 m_endPix = m_startPix;
92 } else if (m_clipType == AUDIO) {
93 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
98 ClipItem::~ClipItem() {
99 if (startThumbTimer) delete startThumbTimer;
100 if (endThumbTimer) delete endThumbTimer;
103 int ClipItem::selectedEffectIndex() const {
104 return m_selectedEffect;
107 void ClipItem::setSelectedEffect(int ix) {
108 //if (ix == m_selectedEffect) return;
109 m_selectedEffect = ix;
110 QDomElement effect = effectAt(m_selectedEffect);
111 QDomNodeList params = effect.elementsByTagName("parameter");
113 for (int i = 0; i < params.count(); i++) {
114 QDomElement e = params.item(i).toElement();
115 if (!e.isNull() && e.attribute("type") == "keyframe") {
116 int max = e.attribute("max").toInt();
117 int min = e.attribute("min").toInt();
118 int def = e.attribute("default").toInt();
119 int factor = e.attribute("factor").toInt();
120 if (factor == 0) factor = 1;
122 // Effect has a keyframe type parameter, we need to set the values
123 if (e.attribute("keyframes").isEmpty()) {
124 // no keyframes defined, set up 2 keyframes (start and end) with default value.
125 m_keyframes[0] = 100 * def / (max - min);
126 m_keyframes[100] = 100 * def / (max - min);
129 QStringList keyframes = e.attribute("keyframes").split(";");
130 foreach(QString str, keyframes) {
131 if (!str.isEmpty()) {
132 int pos = str.section(":", 0, 0).toInt();
133 int val = str.section(":", 1, 1).toInt();
134 /*int frame = (int) (pos * 100 / m_cropDuration.frames(m_fps));
135 int value = (int) (((val * factor) - min) * 100 * factor / (max - min));*/
136 m_keyframes[pos] = val;
144 if (!m_keyframes.isEmpty()) {
150 void ClipItem::updateKeyframeEffect() {
151 QDomElement effect = effectAt(m_selectedEffect);
152 QDomNodeList params = effect.elementsByTagName("parameter");
154 for (int i = 0; i < params.count(); i++) {
155 QDomElement e = params.item(i).toElement();
156 if (!e.isNull() && e.attribute("type") == "keyframe") {
157 int max = e.attribute("max").toInt();
158 int min = e.attribute("min").toInt();
159 int def = e.attribute("default").toInt();
160 int factor = e.attribute("factor").toInt();
161 if (factor == 0) factor = 1;
164 if (m_keyframes.count() > 1) {
165 QMap<int, int>::const_iterator i = m_keyframes.constBegin();
168 while (i != m_keyframes.constEnd()) {
169 keyframes.append(QString::number(i.key()) + ":" + QString::number(i.value()) + ";");
170 /*x1 = m_cropDuration.frames(m_fps) * i.key() / 100.0;
171 y1 = (min + i.value() * (max - min) / 100.0) / factor;
172 keyframes.append(QString::number(x1) + ":" + QString::number(y1) + ";");*/
176 // Effect has a keyframe type parameter, we need to set the values
177 kDebug() << "::::::::::::::: SETTING EFFECT KEYFRAMES: " << keyframes;
178 e.setAttribute("keyframes", keyframes);
184 QDomElement ClipItem::selectedEffect() {
185 if (m_selectedEffect == -1 || m_effectList.isEmpty()) return QDomElement();
186 return effectAt(m_selectedEffect);
189 void ClipItem::resetThumbs() {
191 audioThumbCachePic.clear();
195 void ClipItem::refreshClip() {
196 m_maxDuration = m_clip->maxDuration();
197 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW) slotFetchThumbs();
198 else if (m_clipType == COLOR) {
199 QString colour = m_clip->getProperty("colour");
200 colour = colour.replace(0, 2, "#");
201 setBrush(QColor(colour.left(7)));
202 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
203 m_startPix = KThumb::getImage(KUrl(m_clip->getProperty("resource")), (int)(50 * KdenliveSettings::project_display_ratio()), 50);
204 m_endPix = m_startPix;
208 void ClipItem::slotFetchThumbs() {
209 m_thumbsRequested += 2;
210 emit getThumb((int)m_cropStart.frames(m_fps), (int)(m_cropStart + m_cropDuration).frames(m_fps));
213 void ClipItem::slotGetStartThumb() {
215 emit getThumb((int)m_cropStart.frames(m_fps), -1);
218 void ClipItem::slotGetEndThumb() {
220 emit getThumb(-1, (int)(m_cropStart + m_cropDuration).frames(m_fps));
223 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
224 if (m_thumbsRequested == 0) return;
225 if (frame == m_cropStart.frames(m_fps)) {
227 QRectF r = boundingRect();
228 r.setRight(pix.width() + 2);
232 QRectF r = boundingRect();
233 r.setLeft(r.right() - pix.width() - 2);
239 void ClipItem::slotGotAudioData() {
240 audioThumbReady = true;
241 if (m_clipType == AV) {
242 QRectF r = boundingRect();
243 r.setTop(r.top() + r.height() / 2 - 1);
248 int ClipItem::type() const {
252 DocClipBase *ClipItem::baseClip() const {
256 QDomElement ClipItem::xml() const {
257 return m_clip->toXML();
260 int ClipItem::clipType() const {
264 QString ClipItem::clipName() const {
268 int ClipItem::clipProducer() const {
272 void ClipItem::flashClip() {
273 if (m_timeLine == 0) {
274 m_timeLine = new QTimeLine(750, this);
275 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve);
276 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
281 void ClipItem::animate(qreal value) {
282 QRectF r = boundingRect();
288 void ClipItem::paint(QPainter *painter,
289 const QStyleOptionGraphicsItem *option,
291 painter->setOpacity(m_opacity);
292 QBrush paintColor = brush();
293 if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
295 double scale = br.width() / m_cropDuration.frames(m_fps);
297 // kDebug()<<"/// EXPOSED RECT: "<<option->exposedRect.x()<<" X "<<option->exposedRect.right();
299 int startpixel = (int)option->exposedRect.x() - rect().x();
303 int endpixel = (int)option->exposedRect.right() - rect().x();
307 //painter->setRenderHints(QPainter::Antialiasing);
309 QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
310 painter->setClipRect(option->exposedRect);
312 // build path around clip
313 QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
314 painter->fillPath(resultClipPath, paintColor);
316 painter->setClipPath(resultClipPath, Qt::IntersectClip);
318 if (!m_startPix.isNull() && KdenliveSettings::videothumbnails()) {
319 if (m_clipType == IMAGE) {
320 painter->drawPixmap(QPointF(br.right() - m_startPix.width(), br.y()), m_startPix);
321 QLine l(br.right() - m_startPix.width(), br.y(), br.right() - m_startPix.width(), br.y() + br.height());
322 painter->drawLine(l);
324 painter->drawPixmap(QPointF(br.right() - m_endPix.width(), br.y()), m_endPix);
325 QLine l(br.right() - m_endPix.width(), br.y(), br.right() - m_endPix.width(), br.y() + br.height());
326 painter->drawLine(l);
329 painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
330 QLine l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
331 painter->drawLine(l2);
334 // draw audio thumbnails
335 if (KdenliveSettings::audiothumbnails() && ((m_clipType == AV && option->exposedRect.bottom() > br.height() / 2) || m_clipType == AUDIO) && audioThumbReady) {
337 QPainterPath path = m_clipType == AV ? roundRectPathLower : resultClipPath;
338 if (m_clipType == AV) painter->fillPath(path, QBrush(QColor(200, 200, 200, 140)));
341 if (scale != framePixelWidth)
342 audioThumbCachePic.clear();
343 emit prepareAudioThumb(scale, path, startpixel, endpixel + 200);//200 more for less missing parts before repaint after scrolling
344 int cropLeft = (int)((m_cropStart).frames(m_fps) * scale);
345 for (int startCache = startpixel - startpixel % 100; startCache < endpixel + 300;startCache += 100) {
346 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
347 painter->drawPixmap((int)(roundRectPathUpper.united(roundRectPathLower).boundingRect().x() + startCache - cropLeft), (int)(path.boundingRect().y()), audioThumbCachePic[startCache]);
352 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
353 QList < CommentedTime >::Iterator it = markers.begin();
356 const int markerwidth = 4;
358 markerBrush = QBrush(QColor(120, 120, 0, 100));
359 QPen pen = painter->pen();
360 pen.setColor(QColor(255, 255, 255, 200));
361 pen.setStyle(Qt::DotLine);
362 painter->setPen(pen);
363 for (; it != markers.end(); ++it) {
364 pos = (*it).time() - cropStart();
365 if (pos > GenTime()) {
366 if (pos > duration()) break;
367 framepos = scale * pos.frames(m_fps);
368 QLineF l(br.x() + framepos, br.y() + 5, br.x() + framepos, br.y() + br.height() - 5);
369 painter->drawLine(l);
370 if (KdenliveSettings::showmarkers()) {
371 const QRectF txtBounding = painter->boundingRect(br.x() + framepos + 1, br.y() + 10, br.width() - framepos - 2, br.height() - 10, Qt::AlignLeft | Qt::AlignTop, " " + (*it).comment() + " ");
373 path.addRoundedRect(txtBounding, 3, 3);
374 painter->fillPath(path, markerBrush);
375 painter->drawText(txtBounding, Qt::AlignCenter, (*it).comment());
377 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
380 pen.setColor(Qt::black);
381 pen.setStyle(Qt::SolidLine);
382 painter->setPen(pen);
384 // draw start / end fades
387 fades = QBrush(QColor(200, 50, 50, 150));
388 } else fades = QBrush(QColor(200, 200, 200, 200));
390 if (m_startFade != 0) {
391 QPainterPath fadeInPath;
392 fadeInPath.moveTo(br.x() , br.y());
393 fadeInPath.lineTo(br.x() , br.bottom());
394 fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
395 fadeInPath.closeSubpath();
396 painter->fillPath(fadeInPath/*.intersected(resultClipPath)*/, fades);
398 QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.bottom());
399 painter->drawLine(l);
402 if (m_endFade != 0) {
403 QPainterPath fadeOutPath;
404 fadeOutPath.moveTo(br.right(), br.y());
405 fadeOutPath.lineTo(br.right(), br.bottom());
406 fadeOutPath.lineTo(br.right() - m_endFade * scale, br.y());
407 fadeOutPath.closeSubpath();
408 painter->fillPath(fadeOutPath/*.intersected(resultClipPath)*/, fades);
410 QLineF l(br.right() - m_endFade * scale, br.y(), br.x() + br.width(), br.bottom());
411 painter->drawLine(l);
415 // Draw effects names
416 if (!m_effectNames.isEmpty() && br.width() > 30) {
417 QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, m_effectNames);
418 txtBounding.setRight(txtBounding.right() + 15);
419 painter->setPen(Qt::white);
420 QBrush markerBrush(Qt::SolidPattern);
421 if (m_timeLine && m_timeLine->state() == QTimeLine::Running) {
422 qreal value = m_timeLine->currentValue();
423 txtBounding.setWidth(txtBounding.width() * value);
424 markerBrush.setColor(QColor(50 + 200 * (1.0 - value), 50, 50, 100 + 50 * value));
425 } else markerBrush.setColor(QColor(50, 50, 50, 150));
427 path.addRoundedRect(txtBounding, 4, 4);
428 painter->fillPath(path/*.intersected(resultClipPath)*/, markerBrush);
429 painter->drawText(txtBounding, Qt::AlignCenter, m_effectNames);
430 painter->setPen(Qt::black);
434 QRectF txtBounding = painter->boundingRect(br, Qt::AlignHCenter | Qt::AlignTop, " " + m_clipName + " ");
435 //painter->fillRect(txtBounding, QBrush(QColor(255, 255, 255, 150)));
436 painter->setPen(QColor(0, 0, 0, 180));
437 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
438 txtBounding.translate(QPointF(1, 1));
439 painter->setPen(QColor(255, 255, 255, 255));
440 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
441 // draw frame around clip
443 pen.setColor(Qt::red);
446 pen.setColor(Qt::black);
451 // draw effect or transition keyframes
452 if (br.width() > 20) drawKeyFrames(painter, option->exposedRect);
455 painter->setClipRect(option->exposedRect);
456 painter->setPen(pen);
457 //painter->setClipRect(option->exposedRect);
458 painter->drawPath(resultClipPath);
460 if (m_hover && br.width() > 30) {
461 painter->setBrush(QColor(180, 180, 50, 180)); //gradient);
463 // draw transitions handles
464 QPainterPath transitionHandle;
465 const int handle_size = 4;
466 transitionHandle.moveTo(0, 0);
467 transitionHandle.lineTo(handle_size, handle_size);
468 transitionHandle.lineTo(handle_size * 2, 0);
469 transitionHandle.lineTo(handle_size * 3, handle_size);
470 transitionHandle.lineTo(handle_size * 2, handle_size * 2);
471 transitionHandle.lineTo(handle_size * 3, handle_size * 3);
472 transitionHandle.lineTo(0, handle_size * 3);
473 transitionHandle.closeSubpath();
474 int pointy = (int)(br.y() + br.height() / 2);
475 int pointx1 = (int)(br.x() + 10);
476 int pointx2 = (int)(br.x() + br.width() - (10 + handle_size * 3));
478 painter->setPen(QPen(Qt::black));
479 painter->setBrush(QBrush(QColor(50, 50, 0)));
481 /*QRadialGradient gradient(pointx1 + 5, pointy + 5 , 5, 2, 2);
482 gradient.setColorAt(0.2, Qt::white);
483 gradient.setColorAt(0.8, Qt::yellow);
484 gradient.setColorAt(1, Qt::black);*/
487 painter->translate(pointx1, pointy);
488 painter->drawPath(transitionHandle); //Ellipse(0, 0 , 10, 10);
489 painter->translate(-pointx1, -pointy);
491 /* QRadialGradient gradient1(pointx2 + 5, pointy + 5 , 5, 2, 2);
492 gradient1.setColorAt(0.2, Qt::white);
493 gradient1.setColorAt(0.8, Qt::yellow);
494 gradient1.setColorAt(1, Qt::black);
495 painter->setBrush(gradient1);*/
496 painter->translate(pointx2, pointy);
499 //painter->setMatrix(m);
500 painter->drawPath(transitionHandle); // Ellipse(0, 0, 10, 10);
501 //painter->setMatrix(m);
502 painter->translate(- pointx2, -pointy);
507 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) {
509 m_editedKeyframe = mouseOverKeyFrames(pos);
510 if (m_editedKeyframe != -1) return KEYFRAME;
512 if (qAbs((int)(pos.x() - (rect().x() + scale * m_startFade))) < 6 && qAbs((int)(pos.y() - rect().y())) < 6) {
513 if (m_startFade == 0) setToolTip(i18n("Add audio fade"));
514 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_startFade, m_fps).seconds()));
516 } else if (qAbs((int)(pos.x() - rect().x())) < 6) {
517 setToolTip(i18n("Crop from start: %1s", cropStart().seconds()));
519 } else if (qAbs((int)(pos.x() - (rect().x() + rect().width() - scale * m_endFade))) < 6 && qAbs((int)(pos.y() - rect().y())) < 6) {
520 if (m_endFade == 0) setToolTip(i18n("Add audio fade"));
521 else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_endFade, m_fps).seconds()));
523 } else if (qAbs((int)(pos.x() - (rect().x() + rect().width()))) < 6) {
524 setToolTip(i18n("Clip duration: %1s", duration().seconds()));
526 } else if (qAbs((int)(pos.x() - (rect().x() + 16))) < 10 && qAbs((int)(pos.y() - (rect().y() + rect().height() / 2 + 5))) < 8) {
527 setToolTip(i18n("Add transition"));
528 return TRANSITIONSTART;
529 } else if (qAbs((int)(pos.x() - (rect().x() + rect().width() - 21))) < 10 && qAbs((int)(pos.y() - (rect().y() + rect().height() / 2 + 5))) < 8) {
530 setToolTip(i18n("Add transition"));
531 return TRANSITIONEND;
533 setToolTip(QString());
537 QList <GenTime> ClipItem::snapMarkers() const {
538 QList < GenTime > snaps;
539 QList < GenTime > markers = baseClip()->snapMarkers();
543 for (int i = 0; i < markers.size(); i++) {
544 pos = markers.at(i) - cropStart();
545 if (pos > GenTime()) {
546 if (pos > duration()) break;
547 else snaps.append(pos + startPos());
553 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, QPainterPath path, int startpixel, int endpixel) {
556 QRectF re = path.boundingRect();
558 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
560 for (int startCache = startpixel - startpixel % 100;startCache + 100 < endpixel ;startCache += 100) {
561 //kDebug() << "creating " << startCache;
562 //if (framePixelWidth!=pixelForOneFrame ||
563 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
565 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
566 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
567 audioThumbCachePic[startCache].fill(QColor(200, 200, 200, 0));
569 bool fullAreaDraw = pixelForOneFrame < 10;
570 QMap<int, QPainterPath > positiveChannelPaths;
571 QMap<int, QPainterPath > negativeChannelPaths;
572 QPainter pixpainter(&audioThumbCachePic[startCache]);
574 audiopen.setWidth(0);
575 pixpainter.setPen(audiopen);
576 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
577 //pixpainter.drawLine(0,0,100,re.height());
578 int channelHeight = audioThumbCachePic[startCache].height() / channels;
580 for (int i = 0;i < channels;i++) {
582 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
583 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
586 for (int samples = 0;samples <= 100;samples++) {
587 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
588 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
589 if (frame < 0 || sample < 0 || sample > 19)
591 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
593 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
595 int y = channelHeight * channel + channelHeight / 2;
596 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
598 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
599 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
601 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
602 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
605 for (int channel = 0;channel < channels ;channel++)
606 if (fullAreaDraw && samples == 100) {
607 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
608 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
609 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
610 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
614 if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
616 pixpainter.setPen(QPen(QColor(0, 0, 0)));
617 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
619 for (int i = 0;i < channels;i++) {
621 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
622 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
624 pixpainter.drawPath(positiveChannelPaths[i]);
627 //audioThumbWasDrawn=true;
628 framePixelWidth = pixelForOneFrame;
633 uint ClipItem::fadeIn() const {
637 uint ClipItem::fadeOut() const {
642 void ClipItem::setFadeIn(int pos, double scale) {
643 int oldIn = m_startFade;
644 if (pos < 0) pos = 0;
645 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
647 update(rect().x(), rect().y(), qMax(oldIn, pos) * scale, rect().height());
650 void ClipItem::setFadeOut(int pos, double scale) {
651 int oldOut = m_endFade;
652 if (pos < 0) pos = 0;
653 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
655 update(rect().x() + rect().width() - qMax(oldOut, pos) * scale, rect().y(), pos * scale, rect().height());
660 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
661 /*m_resizeMode = operationMode(event->pos());
662 if (m_resizeMode == MOVE) {
663 m_maxTrack = scene()->sceneRect().height();
664 m_grabPoint = (int) (event->pos().x() - rect().x());
666 QGraphicsRectItem::mousePressEvent(event);
670 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
672 QGraphicsRectItem::mouseReleaseEvent(event);
676 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
678 QRectF r = boundingRect();
679 qreal width = qMin(25.0, r.width());
680 update(r.x(), r.y(), width, r.height());
681 update(r.right() - width, r.y(), width, r.height());
685 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
687 QRectF r = boundingRect();
688 qreal width = qMin(25.0, r.width());
689 update(r.x(), r.y(), width, r.height());
690 update(r.right() - width, r.y(), width, r.height());
693 void ClipItem::resizeStart(int posx, double scale) {
694 AbstractClipItem::resizeStart(posx, scale);
695 if (m_hasThumbs && KdenliveSettings::videothumbnails()) startThumbTimer->start(100);
698 void ClipItem::resizeEnd(int posx, double scale) {
699 AbstractClipItem::resizeEnd(posx, scale);
700 if (m_hasThumbs && KdenliveSettings::videothumbnails()) endThumbTimer->start(100);
704 /*void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
707 int ClipItem::effectsCounter() {
708 return m_effectsCounter++;
711 int ClipItem::effectsCount() {
712 return m_effectList.size();
715 QStringList ClipItem::effectNames() {
716 return m_effectList.effectNames();
719 QDomElement ClipItem::effectAt(int ix) {
720 if (ix > m_effectList.count() - 1 || ix < 0) return QDomElement();
721 return m_effectList.at(ix);
724 void ClipItem::setEffectAt(int ix, QDomElement effect) {
725 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
726 m_effectList.insert(ix, effect);
727 m_effectList.removeAt(ix + 1);
728 m_effectNames = m_effectList.effectNames().join(" / ");
729 if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fadeout") update(boundingRect());
731 QRectF r = boundingRect();
737 QMap <QString, QString> ClipItem::addEffect(QDomElement effect, bool animate) {
738 QMap <QString, QString> effectParams;
739 bool needRepaint = false;
741 doc.appendChild(doc.importNode(effect, true));
742 kDebug() << "/////// CLIP ADD EFFECT: "<< doc.toString();*/
743 m_effectList.append(effect);
744 effectParams["tag"] = effect.attribute("tag");
745 QString effectId = effect.attribute("id");
746 if (effectId.isEmpty()) effectId = effect.attribute("tag");
747 effectParams["id"] = effectId;
748 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
749 QString state = effect.attribute("disabled");
750 if (!state.isEmpty()) effectParams["disabled"] = state;
751 QDomNodeList params = effect.elementsByTagName("parameter");
753 for (int i = 0; i < params.count(); i++) {
754 QDomElement e = params.item(i).toElement();
756 if (e.attribute("factor").isEmpty()) {
757 effectParams[e.attribute("name")] = e.attribute("value");
758 // check if it is a fade effect
759 if (effectId == "fadein") {
761 if (e.attribute("name") == "out") fade += e.attribute("value").toInt();
762 else if (e.attribute("name") == "in") fade -= e.attribute("value").toInt();
763 } else if (effectId == "fadeout") {
765 if (e.attribute("name") == "out") fade -= e.attribute("value").toInt();
766 else if (e.attribute("name") == "in") fade += e.attribute("value").toInt();
769 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
773 m_effectNames = m_effectList.effectNames().join(" / ");
774 if (fade > 0) m_startFade = fade;
775 else if (fade < 0) m_endFade = -fade;
776 if (needRepaint) update(boundingRect());
779 } else if (!needRepaint) {
780 QRectF r = boundingRect();
787 QMap <QString, QString> ClipItem::getEffectArgs(QDomElement effect) {
788 QMap <QString, QString> effectParams;
789 effectParams["tag"] = effect.attribute("tag");
790 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
791 effectParams["id"] = effect.attribute("id");
792 QString state = effect.attribute("disabled");
793 if (!state.isEmpty()) effectParams["disabled"] = state;
794 QDomNodeList params = effect.elementsByTagName("parameter");
795 for (int i = 0; i < params.count(); i++) {
796 QDomElement e = params.item(i).toElement();
797 kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
798 if (e.attribute("type") == "keyframe") {
799 kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
800 effectParams["keyframes"] = e.attribute("keyframes");
801 effectParams["max"] = e.attribute("max");
802 effectParams["min"] = e.attribute("min");
803 effectParams["factor"] = e.attribute("factor");
804 effectParams["starttag"] = e.attribute("starttag");
805 effectParams["endtag"] = e.attribute("endtag");
806 } else if (e.attribute("namedesc").contains(";")) {
807 QString format = e.attribute("format");
808 QStringList separators = format.split("%d", QString::SkipEmptyParts);
809 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
811 QTextStream txtNeu(&neu);
812 if (values.size() > 0)
813 txtNeu << (int)values[0].toDouble();
814 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
815 txtNeu << separators[i];
816 txtNeu << (int)(values[i+1].toDouble());
818 effectParams["start"] = neu;
819 } else if (!e.isNull()) {
820 if (!e.attribute("factor").isEmpty())
821 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("value")].toDouble() / e.attribute("factor").toDouble());
822 else effectParams[e.attribute("name")] = e.attribute("value");
828 void ClipItem::deleteEffect(QString index) {
829 bool needRepaint = false;
830 for (int i = 0; i < m_effectList.size(); ++i) {
831 if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
832 if (m_effectList.at(i).attribute("id") == "fadein") {
835 } else if (m_effectList.at(i).attribute("id") == "fadeout") {
839 m_effectList.removeAt(i);
843 m_effectNames = m_effectList.effectNames().join(" / ");
844 if (needRepaint) update(boundingRect());
849 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
850 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
852 doc.setContent(effects, true);
853 QDomElement e = doc.documentElement();
854 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
855 if (view) view->slotAddEffect(e, m_startPos, track());
859 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
860 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
863 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
866 void ClipItem::addTransition(Transition* t) {
867 m_transitionsList.append(t);
868 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
870 QDomElement e = doc.documentElement();
871 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
875 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
877 int pos = event->x();
878 if (event->modifiers() == Qt::ControlModifier)
879 setDragMode(QGraphicsView::ScrollHandDrag);
880 else if (event->modifiers() == Qt::ShiftModifier)
881 setDragMode(QGraphicsView::RubberBandDrag);
883 QGraphicsItem * item = itemAt(event->pos());
886 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
889 QGraphicsView::mousePressEvent(event);
892 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
894 QGraphicsView::mouseReleaseEvent(event);
895 setDragMode(QGraphicsView::NoDrag);
899 #include "clipitem.moc"