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()), 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_hover(false) {
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));
46 //kDebug() << "///// NEW CLIP RECT: " << rect;
48 m_clipName = clip->name();
49 m_producer = clip->getId();
50 m_clipType = clip->clipType();
51 m_cropStart = cropStart;
53 m_maxDuration = clip->maxDuration();
55 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, QPainterPath, int, int)) , this, SLOT(slotPrepareAudioThumb(double, QPainterPath, int, int)));
69 setBrush(QColor(141, 166, 215));
70 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW) {
72 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
73 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
74 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
75 QTimer::singleShot(300, this, SLOT(slotFetchThumbs()));
77 startThumbTimer = new QTimer(this);
78 startThumbTimer->setSingleShot(true);
79 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
80 endThumbTimer = new QTimer(this);
81 endThumbTimer->setSingleShot(true);
82 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
83 } else if (m_clipType == COLOR) {
84 QString colour = clip->getProperty("colour");
85 colour = colour.replace(0, 2, "#");
86 setBrush(QColor(colour.left(7)));
87 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
88 m_startPix = KThumb::getImage(KUrl(clip->getProperty("resource")), (int)(50 * KdenliveSettings::project_display_ratio()), 50);
89 m_endPix = m_startPix;
90 } else if (m_clipType == AUDIO) {
91 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
96 ClipItem::~ClipItem() {
97 if (startThumbTimer) delete startThumbTimer;
98 if (endThumbTimer) delete endThumbTimer;
101 void ClipItem::resetThumbs() {
103 audioThumbCachePic.clear();
107 void ClipItem::refreshClip() {
108 m_maxDuration = m_clip->maxDuration();
109 if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW) slotFetchThumbs();
110 else if (m_clipType == COLOR) {
111 QString colour = m_clip->getProperty("colour");
112 colour = colour.replace(0, 2, "#");
113 setBrush(QColor(colour.left(7)));
114 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
115 m_startPix = KThumb::getImage(KUrl(m_clip->getProperty("resource")), (int)(50 * KdenliveSettings::project_display_ratio()), 50);
116 m_endPix = m_startPix;
120 void ClipItem::slotFetchThumbs() {
121 m_thumbsRequested += 2;
122 emit getThumb((int)m_cropStart.frames(m_fps), (int)(m_cropStart + m_cropDuration).frames(m_fps));
125 void ClipItem::slotGetStartThumb() {
127 emit getThumb((int)m_cropStart.frames(m_fps), -1);
130 void ClipItem::slotGetEndThumb() {
132 emit getThumb(-1, (int)(m_cropStart + m_cropDuration).frames(m_fps));
135 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
136 if (m_thumbsRequested == 0) return;
137 if (frame == m_cropStart.frames(m_fps)) m_startPix = pix;
143 void ClipItem::slotGotAudioData() {
144 audioThumbReady = true;
148 int ClipItem::type() const {
152 DocClipBase *ClipItem::baseClip() {
156 QDomElement ClipItem::xml() const {
157 return m_clip->toXML();
160 int ClipItem::clipType() {
164 QString ClipItem::clipName() {
168 int ClipItem::clipProducer() {
172 void ClipItem::flashClip() {
173 if (m_timeLine == 0) {
174 m_timeLine = new QTimeLine(750, this);
175 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
180 void ClipItem::animate(qreal value) {
186 void ClipItem::paint(QPainter *painter,
187 const QStyleOptionGraphicsItem *option,
189 painter->setOpacity(m_opacity);
190 QBrush paintColor = brush();
191 if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
193 double scale = br.width() / m_cropDuration.frames(m_fps);
194 QRect rectInView = visibleRect();//this is the rect that is visible by the user
196 if (rectInView.isNull())
198 QPainterPath clippath;
199 clippath.addRect(rectInView);
201 int startpixel = (int)(rectInView.x() - rect().x()); //start and endpixel that is viewable from rect()
205 int endpixel = rectInView.width() + rectInView.x();
209 //painter->setRenderHints(QPainter::Antialiasing);
211 QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
212 painter->setClipRect(option->exposedRect);
214 // build path around clip
216 QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
218 painter->setClipPath(resultClipPath.intersected(clippath), Qt::IntersectClip);
219 //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
220 painter->fillRect(br.intersected(rectInView), paintColor);
221 //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
224 if (!m_startPix.isNull() && KdenliveSettings::videothumbnails()) {
225 if (m_clipType == IMAGE) {
226 painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
227 QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
228 painter->drawLine(l);
230 painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
231 QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
232 painter->drawLine(l);
235 painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
236 QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
237 painter->drawLine(l2);
240 // draw audio thumbnails
241 if ((m_clipType == AV || m_clipType == AUDIO) && audioThumbReady && KdenliveSettings::audiothumbnails()) {
243 QPainterPath path = m_clipType == AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
244 if (m_clipType == AV) painter->fillPath(path, QBrush(QColor(200, 200, 200, 140)));
247 if (scale != framePixelWidth)
248 audioThumbCachePic.clear();
249 emit prepareAudioThumb(scale, path, startpixel, endpixel + 200);//200 more for less missing parts before repaint after scrolling
250 int cropLeft = (int)((m_cropStart).frames(m_fps) * scale);
251 for (int startCache = startpixel - startpixel % 100; startCache < endpixel + 300;startCache += 100) {
252 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
253 painter->drawPixmap((int)(roundRectPathUpper.united(roundRectPathLower).boundingRect().x() + startCache - cropLeft), (int)(path.boundingRect().y()), audioThumbCachePic[startCache]);
258 QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
259 QList < CommentedTime >::Iterator it = markers.begin();
262 const int markerwidth = 4;
264 markerBrush = QBrush(QColor(120, 120, 0, 100));
265 QPen pen = painter->pen();
266 pen.setColor(QColor(255, 255, 255, 200));
267 pen.setStyle(Qt::DotLine);
268 painter->setPen(pen);
269 for (; it != markers.end(); ++it) {
270 pos = (*it).time() - cropStart();
271 if (pos > GenTime()) {
272 if (pos > duration()) break;
273 framepos = scale * pos.frames(m_fps);
274 QLineF l(br.x() + framepos, br.y() + 5, br.x() + framepos, br.y() + br.height() - 5);
275 painter->drawLine(l);
276 if (KdenliveSettings::showmarkers()) {
277 const QRectF txtBounding = painter->boundingRect(br.x() + framepos + 1, br.y() + 5, br.width() - framepos - 2, br.height() - 10, Qt::AlignLeft | Qt::AlignTop, " " + (*it).comment() + " ");
279 path.addRoundedRect(txtBounding, 3, 3);
280 painter->fillPath(path, markerBrush);
281 painter->drawText(txtBounding, Qt::AlignCenter, (*it).comment());
283 //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
286 pen.setColor(Qt::black);
287 pen.setStyle(Qt::SolidLine);
291 // draw start / end fades
294 fades = QBrush(QColor(200, 50, 50, 150));
295 } else fades = QBrush(QColor(200, 200, 200, 200));
297 if (m_startFade != 0) {
298 QPainterPath fadeInPath;
299 fadeInPath.moveTo(br.x() , br.y());
300 fadeInPath.lineTo(br.x() , br.y() + br.height());
301 fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
302 fadeInPath.closeSubpath();
303 painter->fillPath(fadeInPath, fades);
305 QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
306 painter->drawLine(l);
309 if (m_endFade != 0) {
310 QPainterPath fadeOutPath;
311 fadeOutPath.moveTo(br.x() + br.width(), br.y());
312 fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
313 fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
314 fadeOutPath.closeSubpath();
315 painter->fillPath(fadeOutPath, fades);
317 QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
318 painter->drawLine(l);
323 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
325 // Draw effects names
326 QString effects = effectNames().join(" / ");
327 if (!effects.isEmpty()) {
328 painter->setPen(pen);
329 QFont font = painter->font();
330 QFont smallFont = font;
331 smallFont.setPointSize(8);
332 painter->setFont(smallFont);
333 QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " ");
334 painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
335 painter->drawText(txtBounding, Qt::AlignCenter, effects);
336 pen.setColor(Qt::black);
337 painter->setPen(pen);
338 painter->setFont(font);
342 // For testing puspose only: draw transitions count
344 painter->setPen(pen);
345 QFont font = painter->font();
346 QFont smallFont = font;
347 smallFont.setPointSize(8);
348 painter->setFont(smallFont);
349 QString txt = " Transitions: " + QString::number(m_transitionsList.count()) + " ";
350 QRectF txtBoundin = painter->boundingRect(br, Qt::AlignRight | Qt::AlignTop, txt);
351 painter->fillRect(txtBoundin, QBrush(QColor(0, 0, 0, 150)));
352 painter->drawText(txtBoundin, Qt::AlignCenter, txt);
353 pen.setColor(Qt::black);
354 painter->setPen(pen);
355 painter->setFont(font);
360 QRectF txtBounding = painter->boundingRect(br, Qt::AlignHCenter | Qt::AlignTop, " " + m_clipName + " ");
361 painter->fillRect(txtBounding, QBrush(QColor(255, 255, 255, 150)));
362 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
364 // draw frame around clip
366 pen.setColor(Qt::red);
369 pen.setColor(Qt::black);
372 painter->setPen(pen);
373 painter->setClipRect(option->exposedRect);
374 painter->drawPath(resultClipPath.intersected(clippath));
376 //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150)));
377 //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
379 /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
380 painter->drawRect(recta);
381 painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
382 painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
383 painter->setPen(QPen(Qt::black, 1.0));
384 painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
385 painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
387 //QGraphicsRectItem::paint(painter, option, widget);
388 //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
389 //painter->setPen(pen);
390 //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
391 //kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
392 //painter->drawText(rect(), Qt::AlignCenter, m_name);
393 // painter->drawRect(boundingRect());
394 //painter->drawRoundRect(-10, -10, 20, 20);
396 int pointy = (int)(br.y() + br.height() / 2 - 5);
397 int pointx1 = (int)(br.x() + 10);
398 int pointx2 = (int)(br.x() + br.width() - 20);
400 painter->setPen(QPen(Qt::black));
401 painter->setBrush(QBrush(QColor(50, 50, 0)));
403 QRadialGradient gradient(pointx1 + 5, pointy + 5 , 5, 2, 2);
404 gradient.setColorAt(0.2, Qt::white);
405 gradient.setColorAt(0.8, Qt::yellow);
406 gradient.setColorAt(1, Qt::black);
407 painter->setBrush(gradient);
409 painter->drawEllipse(pointx1, pointy , 10, 10);
411 QRadialGradient gradient1(pointx2 + 5, pointy + 5 , 5, 2, 2);
412 gradient1.setColorAt(0.2, Qt::white);
413 gradient1.setColorAt(0.8, Qt::yellow);
414 gradient1.setColorAt(1, Qt::black);
415 painter->setBrush(gradient1);
416 painter->drawEllipse(pointx2, pointy, 10, 10);
422 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) {
423 if (qAbs((int)(pos.x() - (rect().x() + scale * m_startFade))) < 6 && qAbs((int)(pos.y() - rect().y())) < 6) return FADEIN;
424 else if (qAbs((int)(pos.x() - rect().x())) < 6) return RESIZESTART;
425 else if (qAbs((int)(pos.x() - (rect().x() + rect().width() - scale * m_endFade))) < 6 && qAbs((int)(pos.y() - rect().y())) < 6) return FADEOUT;
426 else if (qAbs((int)(pos.x() - (rect().x() + rect().width()))) < 6) return RESIZEEND;
427 else if (qAbs((int)(pos.x() - (rect().x() + 10))) < 6 && qAbs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONSTART;
428 else if (qAbs((int)(pos.x() - (rect().x() + rect().width() - 20))) < 6 && qAbs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONEND;
433 QList <GenTime> ClipItem::snapMarkers() {
434 QList < GenTime > snaps;
435 QList < GenTime > markers = baseClip()->snapMarkers();
439 for (int i = 0; i < markers.size(); i++) {
440 pos = markers.at(i) - cropStart();
441 if (pos > GenTime()) {
442 if (pos > duration()) break;
443 else snaps.append(pos + startPos());
449 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, QPainterPath path, int startpixel, int endpixel) {
452 QRectF re = path.boundingRect();
454 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
456 for (int startCache = startpixel - startpixel % 100;startCache + 100 < endpixel ;startCache += 100) {
457 //kDebug() << "creating " << startCache;
458 //if (framePixelWidth!=pixelForOneFrame ||
459 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
461 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
462 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
463 audioThumbCachePic[startCache].fill(QColor(200, 200, 200, 0));
465 bool fullAreaDraw = pixelForOneFrame < 10;
466 QMap<int, QPainterPath > positiveChannelPaths;
467 QMap<int, QPainterPath > negativeChannelPaths;
468 QPainter pixpainter(&audioThumbCachePic[startCache]);
470 audiopen.setWidth(0);
471 pixpainter.setPen(audiopen);
472 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
473 //pixpainter.drawLine(0,0,100,re.height());
474 int channelHeight = audioThumbCachePic[startCache].height() / channels;
476 for (int i = 0;i < channels;i++) {
478 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
479 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
482 for (int samples = 0;samples <= 100;samples++) {
483 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
484 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
485 if (frame < 0 || sample < 0 || sample > 19)
487 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
489 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
491 int y = channelHeight * channel + channelHeight / 2;
492 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
494 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
495 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
497 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
498 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
501 for (int channel = 0;channel < channels ;channel++)
502 if (fullAreaDraw && samples == 100) {
503 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
504 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
505 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
506 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
510 if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
512 pixpainter.setPen(QPen(QColor(0, 0, 0)));
513 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
515 for (int i = 0;i < channels;i++) {
517 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
518 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
520 pixpainter.drawPath(positiveChannelPaths[i]);
523 //audioThumbWasDrawn=true;
524 framePixelWidth = pixelForOneFrame;
531 void ClipItem::setFadeIn(int pos, double scale) {
532 int oldIn = m_startFade;
533 if (pos < 0) pos = 0;
534 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
536 if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
537 else update(rect().x(), rect().y(), pos * scale, rect().height());
540 void ClipItem::setFadeOut(int pos, double scale) {
541 int oldOut = m_endFade;
542 if (pos < 0) pos = 0;
543 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
545 if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
546 else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
551 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
552 /*m_resizeMode = operationMode(event->pos());
553 if (m_resizeMode == MOVE) {
554 m_maxTrack = scene()->sceneRect().height();
555 m_grabPoint = (int) (event->pos().x() - rect().x());
557 QGraphicsRectItem::mousePressEvent(event);
561 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
563 QGraphicsRectItem::mouseReleaseEvent(event);
567 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
573 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
578 void ClipItem::resizeStart(int posx, double scale) {
579 AbstractClipItem::resizeStart(posx, scale);
580 if (m_hasThumbs) startThumbTimer->start(100);
583 void ClipItem::resizeEnd(int posx, double scale) {
584 AbstractClipItem::resizeEnd(posx, scale);
585 if (m_hasThumbs) endThumbTimer->start(100);
589 void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
592 int ClipItem::effectsCounter() {
593 return m_effectsCounter++;
596 int ClipItem::effectsCount() {
597 return m_effectList.size();
600 QStringList ClipItem::effectNames() {
601 return m_effectList.effectNames();
604 QDomElement ClipItem::effectAt(int ix) {
605 return m_effectList.at(ix);
608 void ClipItem::setEffectAt(int ix, QDomElement effect) {
609 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
610 m_effectList.insert(ix, effect);
611 m_effectList.removeAt(ix + 1);
612 update(boundingRect());
615 QMap <QString, QString> ClipItem::addEffect(QDomElement effect, bool animate) {
616 QMap <QString, QString> effectParams;
618 doc.appendChild(doc.importNode(effect, true));
619 kDebug() << "/////// CLIP ADD EFFECT: "<< doc.toString();*/
620 m_effectList.append(effect);
621 effectParams["tag"] = effect.attribute("tag");
622 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
623 QString state = effect.attribute("disabled");
624 if (!state.isEmpty()) effectParams["disabled"] = state;
625 QDomNodeList params = effect.elementsByTagName("parameter");
626 for (int i = 0; i < params.count(); i++) {
627 QDomElement e = params.item(i).toElement();
629 effectParams[e.attribute("name")] = e.attribute("value");
631 if (!e.attribute("factor").isEmpty()) {
632 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
635 if (animate) flashClip();
636 update(boundingRect());
640 QMap <QString, QString> ClipItem::getEffectArgs(QDomElement effect) {
641 QMap <QString, QString> effectParams;
642 effectParams["tag"] = effect.attribute("tag");
643 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
644 QString state = effect.attribute("disabled");
645 if (!state.isEmpty()) effectParams["disabled"] = state;
646 QDomNodeList params = effect.elementsByTagName("parameter");
647 for (int i = 0; i < params.count(); i++) {
648 QDomElement e = params.item(i).toElement();
649 if (e.attribute("namedesc").contains(";")) {
650 QString format = e.attribute("format");
651 QStringList separators = format.split("%d", QString::SkipEmptyParts);
652 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
654 QTextStream txtNeu(&neu);
655 if (values.size() > 0)
656 txtNeu << (int)values[0].toDouble();
657 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
658 txtNeu << separators[i];
659 txtNeu << (int)(values[i+1].toDouble());
661 effectParams["start"] = neu;
664 effectParams[e.attribute("name")] = e.attribute("value");
666 if (!e.attribute("factor").isEmpty()) {
667 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
673 void ClipItem::deleteEffect(QString index) {
674 for (int i = 0; i < m_effectList.size(); ++i) {
675 if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
676 m_effectList.removeAt(i);
681 update(boundingRect());
685 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
686 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
688 doc.setContent(effects, true);
689 QDomElement e = doc.documentElement();
690 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
691 if (view) view->slotAddEffect(e, m_startPos, track());
695 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
696 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
699 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
702 void ClipItem::addTransition(Transition* t) {
703 m_transitionsList.append(t);
704 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
706 QDomElement e = doc.documentElement();
707 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
711 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
713 int pos = event->x();
714 if (event->modifiers() == Qt::ControlModifier)
715 setDragMode(QGraphicsView::ScrollHandDrag);
716 else if (event->modifiers() == Qt::ShiftModifier)
717 setDragMode(QGraphicsView::RubberBandDrag);
719 QGraphicsItem * item = itemAt(event->pos());
722 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
725 QGraphicsView::mousePressEvent(event);
728 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
730 QGraphicsView::mouseReleaseEvent(event);
731 setDragMode(QGraphicsView::NoDrag);
735 #include "clipitem.moc"