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>
33 #include <mlt++/Mlt.h>
36 #include "customtrackview.h"
39 #include "kdenlivesettings.h"
41 ClipItem::ClipItem(DocClipBase *clip, int track, int startpos, const QRectF & rect, int duration)
42 : QGraphicsRectItem(rect), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_track(track), m_startPos(startpos), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), m_startFade(0), m_endFade(0), m_effectsCounter(1), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_thumbsRequested(0) {
44 kDebug() << "******* CREATING NEW TML CLIP, DUR: " << duration;
45 m_xml = clip->toXML();
46 m_clipName = clip->name();
47 m_producer = clip->getId();
48 m_clipType = clip->clipType();
50 m_maxDuration = duration;
51 if (duration != -1) m_cropDuration = duration;
52 else m_cropDuration = m_maxDuration;
54 audioThumbReady = clip->audioThumbCreated();
56 m_cropStart = xml.attribute("in", 0).toInt();
57 m_maxDuration = xml.attribute("duration", 0).toInt();
58 if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
60 if (duration != -1) m_cropDuration = duration;
61 else m_cropDuration = m_maxDuration;*/
64 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemClipsChildrenToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
65 connect(this , SIGNAL(prepareAudioThumb(double, QPainterPath, int, int)) , this, SLOT(slotPrepareAudioThumb(double, QPainterPath, int, int)));
67 setBrush(QColor(100, 100, 150));
68 if (m_clipType == VIDEO || m_clipType == AV) {
70 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
71 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
72 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
73 QTimer::singleShot(300, this, SLOT(slotFetchThumbs()));
75 startThumbTimer = new QTimer(this);
76 startThumbTimer->setSingleShot(true);
77 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
78 endThumbTimer = new QTimer(this);
79 endThumbTimer->setSingleShot(true);
80 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
82 } else if (m_clipType == COLOR) {
83 QString colour = m_xml.attribute("colour");
84 colour = colour.replace(0, 2, "#");
85 setBrush(QColor(colour.left(7)));
86 } else if (m_clipType == IMAGE) {
87 m_startPix = KThumb::getImage(KUrl(m_xml.attribute("resource")), 50 * KdenliveSettings::project_display_ratio(), 50);
88 } else if (m_clipType == AUDIO) {
89 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
94 ClipItem::~ClipItem() {
95 if (startThumbTimer) delete startThumbTimer;
96 if (endThumbTimer) delete endThumbTimer;
99 void ClipItem::slotFetchThumbs() {
100 m_thumbsRequested += 2;
101 emit getThumb(m_cropStart, m_cropStart + m_cropDuration);
104 void ClipItem::slotGetStartThumb() {
106 emit getThumb(m_cropStart, -1);
109 void ClipItem::slotGetEndThumb() {
111 emit getThumb(-1, m_cropStart + m_cropDuration);
114 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
115 if (m_thumbsRequested == 0) return;
116 if (frame == m_cropStart) m_startPix = pix;
122 void ClipItem::slotGotAudioData() {
123 audioThumbReady = true;
127 int ClipItem::type() const {
131 DocClipBase *ClipItem::baseClip() {
135 QDomElement ClipItem::xml() const {
139 int ClipItem::clipType() {
143 QString ClipItem::clipName() {
147 int ClipItem::clipProducer() {
151 int ClipItem::maxDuration() {
152 return m_maxDuration;
155 int ClipItem::duration() {
156 return m_cropDuration;
159 int ClipItem::startPos() {
163 int ClipItem::cropStart() {
167 int ClipItem::endPos() {
168 return m_startPos + m_cropDuration;
171 void ClipItem::flashClip() {
172 if (m_timeLine == 0) {
173 m_timeLine = new QTimeLine(750, this);
174 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
179 void ClipItem::animate(qreal value) {
185 void ClipItem::paint(QPainter *painter,
186 const QStyleOptionGraphicsItem *option,
188 painter->setOpacity(m_opacity);
189 QBrush paintColor = brush();
190 if (isSelected()) paintColor = QBrush(QColor(150, 50, 100));
192 QRect rectInView;//this is the rect that is visible by the user
193 if (scene()->views().size() > 0) {
194 rectInView = scene()->views()[0]->viewport()->rect();
195 rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(), scene()->views()[0]->verticalScrollBar()->value());
196 rectInView.adjust(-10, -10, 10, 10);//make view rect 10 pixel greater on each site, or repaint after scroll event
197 //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value();
199 if (rectInView.isNull())
201 QPainterPath clippath;
202 clippath.addRect(rectInView);
203 int startpixel = rectInView.x() - rect().x();//start and endpixel that is viewable from rect()
206 int endpixel = rectInView.width() + rectInView.x();
210 painter->setRenderHints(QPainter::Antialiasing);
211 QPainterPath roundRectPathUpper, roundRectPathLower;
212 double roundingY = 20;
213 double roundingX = 20;
215 painter->setClipRect(option->exposedRect);
216 if (roundingX > br.width() / 2) roundingX = br.width() / 2;
217 //kDebug()<<"-----PAINTING, SCAL: "<<scale<<", height: "<<br.height();
218 roundRectPathUpper.moveTo(br.x() + br .width() - offset, br.y() + br.height() / 2 - offset);
219 roundRectPathUpper.arcTo(br.x() + br .width() - roundingX - offset, br.y(), roundingX, roundingY, 0.0, 90.0);
220 roundRectPathUpper.lineTo(br.x() + roundingX, br.y());
221 roundRectPathUpper.arcTo(br.x() + offset, br.y(), roundingX, roundingY, 90.0, 90.0);
222 roundRectPathUpper.lineTo(br.x() + offset, br.y() + br.height() / 2 - offset);
223 roundRectPathUpper.closeSubpath();
225 roundRectPathLower.moveTo(br.x() + offset, br.y() + br.height() / 2 - offset);
226 roundRectPathLower.arcTo(br.x() + offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 180.0, 90.0);
227 roundRectPathLower.lineTo(br.x() + br .width() - roundingX, br.y() + br.height() - offset);
228 roundRectPathLower.arcTo(br.x() + br .width() - roundingX - offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 270.0, 90.0);
229 roundRectPathLower.lineTo(br.x() + br .width() - offset, br.y() + br.height() / 2 - offset);
230 roundRectPathLower.closeSubpath();
232 painter->setClipPath(roundRectPathUpper.united(roundRectPathLower).intersected(clippath), Qt::IntersectClip);
233 //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
234 painter->fillRect(br.intersected(rectInView), paintColor);
235 //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
238 if (!m_startPix.isNull()) {
239 if (m_clipType == IMAGE) {
240 painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
241 QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
242 painter->drawLine(l);
244 painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
245 QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
246 painter->drawLine(l);
249 painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
250 QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
251 painter->drawLine(l2);
253 if ((m_clipType == AV || m_clipType == AUDIO || true) && audioThumbReady) {
255 QPainterPath path = m_clipType == AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
256 painter->fillPath(path, QBrush(QColor(200, 200, 200, 127)));
259 double pixelForOneFrame = (double)br.width() / duration();
260 if (pixelForOneFrame != framePixelWidth)
261 audioThumbCachePic.clear();
262 emit prepareAudioThumb(pixelForOneFrame, path, startpixel, endpixel + 200);//200 more for less missing parts before repaint after scrolling
264 for (int startCache = startpixel - startpixel % 100; startCache < endpixel + 300;startCache += 100) {
265 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
266 painter->drawPixmap(path.boundingRect().x() + startCache, path.boundingRect().y(), audioThumbCachePic[startCache]);
271 // draw start / end fades
272 double scale = br.width() / m_cropDuration;
275 fades = QBrush(QColor(200, 50, 50, 150));
276 } else fades = QBrush(QColor(200, 200, 200, 200));
278 if (m_startFade != 0) {
279 QPainterPath fadeInPath;
280 fadeInPath.moveTo(br.x() - offset, br.y());
281 fadeInPath.lineTo(br.x() - offset, br.y() + br.height());
282 fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
283 fadeInPath.closeSubpath();
284 painter->fillPath(fadeInPath, fades);
286 QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
287 painter->drawLine(l);
290 if (m_endFade != 0) {
291 QPainterPath fadeOutPath;
292 fadeOutPath.moveTo(br.x() + br.width(), br.y());
293 fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
294 fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
295 fadeOutPath.closeSubpath();
296 painter->fillPath(fadeOutPath, fades);
298 QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
299 painter->drawLine(l);
303 QPen pen = painter->pen();
304 pen.setColor(Qt::white);
305 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
307 QString effects = effectNames().join(" / ");
308 if (!effects.isEmpty()) {
309 painter->setPen(pen);
310 QFont font = painter->font();
311 QFont smallFont = font;
312 smallFont.setPointSize(8);
313 painter->setFont(smallFont);
314 QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " ");
315 painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
316 painter->drawText(txtBounding, Qt::AlignCenter, effects);
317 pen.setColor(Qt::black);
318 painter->setPen(pen);
319 painter->setFont(font);
322 pen.setColor(Qt::red);
323 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
324 if (isSelected()) painter->setPen(pen);
325 painter->setClipRect(option->exposedRect);
326 painter->drawPath(roundRectPathUpper.united(roundRectPathLower).intersected(clippath));
328 QRectF txtBounding = painter->boundingRect(br, Qt::AlignCenter, " " + m_clipName + " ");
329 painter->fillRect(txtBounding, QBrush(QColor(255, 255, 255, 150)));
330 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
333 //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150)));
334 //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
336 /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
337 painter->drawRect(recta);
338 painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
339 painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
340 painter->setPen(QPen(Qt::black, 1.0));
341 painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
342 painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
344 //QGraphicsRectItem::paint(painter, option, widget);
345 //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
346 //painter->setPen(pen);
347 //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
348 //kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
349 //painter->drawText(rect(), Qt::AlignCenter, m_name);
350 // painter->drawRect(boundingRect());
351 //painter->drawRoundRect(-10, -10, 20, 20);
355 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) {
356 if (abs(pos.x() - (rect().x() + scale * m_startFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEIN;
357 else if (abs(pos.x() - rect().x()) < 6) return RESIZESTART;
358 else if (abs(pos.x() - (rect().x() + rect().width() - scale * m_endFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEOUT;
359 else if (abs(pos.x() - (rect().x() + rect().width())) < 6) return RESIZEEND;
363 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, QPainterPath path, int startpixel, int endpixel) {
366 QRectF re = path.boundingRect();
368 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
370 for (int startCache = startpixel - startpixel % 100;startCache + 100 < endpixel ;startCache += 100) {
371 //kDebug() << "creating " << startCache;
372 //if (framePixelWidth!=pixelForOneFrame ||
373 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
375 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
376 audioThumbCachePic[startCache] = QPixmap(100, re.height());
377 audioThumbCachePic[startCache].fill(QColor(200, 200, 200, 127));
379 bool fullAreaDraw = pixelForOneFrame < 10;
380 QMap<int, QPainterPath > positiveChannelPaths;
381 QMap<int, QPainterPath > negativeChannelPaths;
382 QPainter pixpainter(&audioThumbCachePic[startCache]);
384 audiopen.setWidth(0);
385 pixpainter.setPen(audiopen);
386 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
387 //pixpainter.drawLine(0,0,100,re.height());
388 int channelHeight = audioThumbCachePic[startCache].height() / channels;
390 for (int i = 0;i < channels;i++) {
392 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
393 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
396 for (int samples = 0;samples <= 100;samples++) {
397 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
398 int sample = (frame - (int)(frame)) * 20 ;// AUDIO_FRAME_SIZE
399 if (frame < 0 || sample < 0 || sample > 19)
401 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
403 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
405 int y = channelHeight * channel + channelHeight / 2;
406 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
408 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
409 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
411 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
412 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
415 for (int channel = 0;channel < channels ;channel++)
416 if (fullAreaDraw && samples == 100) {
417 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
418 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
419 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
420 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
424 for (int i = 0;i < channels;i++) {
426 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
427 pixpainter.setBrush(QBrush(QColor(200, 200, 100, 200)));
428 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
430 pixpainter.drawPath(positiveChannelPaths[i]);
433 //audioThumbWasDrawn=true;
434 framePixelWidth = pixelForOneFrame;
439 int ClipItem::fadeIn() const {
443 int ClipItem::fadeOut() const {
447 void ClipItem::setFadeIn(int pos, double scale) {
448 int oldIn = m_startFade;
449 if (pos < 0) pos = 0;
450 if (pos > m_cropDuration) pos = m_cropDuration / 2;
452 if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
453 else update(rect().x(), rect().y(), pos * scale, rect().height());
456 void ClipItem::setFadeOut(int pos, double scale) {
457 int oldOut = m_endFade;
458 if (pos < 0) pos = 0;
459 if (pos > m_cropDuration) pos = m_cropDuration / 2;
461 if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
462 else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
468 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
469 /*m_resizeMode = operationMode(event->pos());
470 if (m_resizeMode == MOVE) {
471 m_maxTrack = scene()->sceneRect().height();
472 m_grabPoint = (int) (event->pos().x() - rect().x());
474 QGraphicsRectItem::mousePressEvent(event);
478 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
480 QGraphicsRectItem::mouseReleaseEvent(event);
483 void ClipItem::moveTo(int x, double scale, double offset, int newTrack) {
484 double origX = rect().x();
485 double origY = rect().y();
488 setRect(x * scale, origY + offset, rect().width(), rect().height());
489 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
490 if (collisionList.size() == 0) m_track = newTrack;
491 for (int i = 0; i < collisionList.size(); ++i) {
492 QGraphicsItem *item = collisionList.at(i);
493 if (item->type() == 70000) {
495 QRectF other = ((QGraphicsRectItem *)item)->rect();
496 if (x < m_startPos) {
497 kDebug() << "COLLISION, MOVING TO------";
498 m_startPos = ((ClipItem *)item)->endPos() + 1;
499 origX = m_startPos * scale;
501 kDebug() << "COLLISION, MOVING TO+++";
502 m_startPos = ((ClipItem *)item)->startPos() - m_cropDuration;
503 origX = m_startPos * scale;
506 setRect(origX, origY, rect().width(), rect().height());
517 /* QList <QGraphicsItem *> childrenList = QGraphicsItem::children();
518 for (int i = 0; i < childrenList.size(); ++i) {
519 childrenList.at(i)->moveBy(rect().x() - origX , offset);
523 void ClipItem::resizeStart(int posx, double scale) {
524 int durationDiff = posx - m_startPos;
525 if (durationDiff == 0) return;
526 kDebug() << "-- RESCALE: CROP=" << m_cropStart << ", DIFF = " << durationDiff;
527 if (m_cropStart + durationDiff < 0) {
528 durationDiff = -m_cropStart;
529 } else if (durationDiff >= m_cropDuration) {
530 durationDiff = m_cropDuration - 3;
532 m_startPos += durationDiff;
533 m_cropStart += durationDiff;
534 m_cropDuration -= durationDiff;
535 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
536 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
537 for (int i = 0; i < collisionList.size(); ++i) {
538 QGraphicsItem *item = collisionList.at(i);
539 if (item->type() == 70000) {
540 int diff = ((ClipItem *)item)->endPos() + 1 - m_startPos;
541 setRect((m_startPos + diff) * scale, rect().y(), (m_cropDuration - diff) * scale, rect().height());
544 m_cropDuration -= diff;
548 if (m_hasThumbs) startThumbTimer->start(100);
551 void ClipItem::resizeEnd(int posx, double scale) {
552 int durationDiff = posx - endPos();
553 if (durationDiff == 0) return;
554 kDebug() << "-- RESCALE: CROP=" << m_cropStart << ", DIFF = " << durationDiff;
555 if (m_cropDuration + durationDiff <= 0) {
556 durationDiff = - (m_cropDuration - 3);
557 } else if (m_cropDuration + durationDiff >= m_maxDuration) {
558 durationDiff = m_maxDuration - m_cropDuration;
560 m_cropDuration += durationDiff;
561 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
562 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
563 for (int i = 0; i < collisionList.size(); ++i) {
564 QGraphicsItem *item = collisionList.at(i);
565 if (item->type() == 70000) {
566 int diff = ((ClipItem *)item)->startPos() - 1 - startPos();
567 m_cropDuration = diff;
568 setRect(m_startPos * scale, rect().y(), m_cropDuration * scale, rect().height());
572 if (m_hasThumbs) endThumbTimer->start(100);
576 void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
579 int ClipItem::track() {
583 void ClipItem::setTrack(int track) {
587 int ClipItem::effectsCounter() {
588 return m_effectsCounter++;
591 int ClipItem::effectsCount() {
592 return m_effectList.size();
595 QStringList ClipItem::effectNames() {
596 return m_effectList.effectNames();
599 QDomElement ClipItem::effectAt(int ix) {
600 return m_effectList.at(ix);
603 void ClipItem::setEffectAt(int ix, QDomElement effect) {
604 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
605 m_effectList.insert(ix, effect);
606 m_effectList.removeAt(ix + 1);
607 update(boundingRect());
610 QMap <QString, QString> ClipItem::addEffect(QDomElement effect) {
611 QMap <QString, QString> effectParams;
612 m_effectList.append(effect);
613 effectParams["tag"] = effect.attribute("tag");
614 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
615 QString state = effect.attribute("disabled");
616 if (!state.isEmpty()) effectParams["disabled"] = state;
617 QDomNodeList params = effect.elementsByTagName("parameter");
618 for (int i = 0; i < params.count(); i++) {
619 QDomElement e = params.item(i).toElement();
621 effectParams[e.attribute("name")] = e.attribute("value");
623 if (!e.attribute("factor").isEmpty()) {
624 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
628 update(boundingRect());
632 QMap <QString, QString> ClipItem::getEffectArgs(QDomElement effect) {
633 QMap <QString, QString> effectParams;
634 effectParams["tag"] = effect.attribute("tag");
635 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
636 QString state = effect.attribute("disabled");
637 if (!state.isEmpty()) effectParams["disabled"] = state;
638 QDomNodeList params = effect.elementsByTagName("parameter");
639 for (int i = 0; i < params.count(); i++) {
640 QDomElement e = params.item(i).toElement();
641 if (e.attribute("name").contains(";")) {
642 QString format = e.attribute("format");
643 QStringList separators = format.split("%d", QString::SkipEmptyParts);
644 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
646 QTextStream txtNeu(&neu);
647 if (values.size() > 0)
648 txtNeu << (int)values[0].toDouble();
649 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
650 txtNeu << separators[i];
651 txtNeu << (int)(values[i+1].toDouble());
653 effectParams["start"] = neu;
656 effectParams[e.attribute("name")] = e.attribute("value");
658 if (!e.attribute("factor").isEmpty()) {
659 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
665 void ClipItem::deleteEffect(QString index) {
666 for (int i = 0; i < m_effectList.size(); ++i) {
667 if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
668 m_effectList.removeAt(i);
673 update(boundingRect());
677 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
678 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
680 doc.setContent(effects, true);
681 QDomElement e = doc.documentElement();
682 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
683 if (view) view->slotAddEffect(e, GenTime(m_startPos, 25), m_track);
687 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
688 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
691 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
697 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
699 int pos = event->x();
700 if (event->modifiers() == Qt::ControlModifier)
701 setDragMode(QGraphicsView::ScrollHandDrag);
702 else if (event->modifiers() == Qt::ShiftModifier)
703 setDragMode(QGraphicsView::RubberBandDrag);
705 QGraphicsItem * item = itemAt(event->pos());
708 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
711 QGraphicsView::mousePressEvent(event);
714 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
716 QGraphicsView::mouseReleaseEvent(event);
717 setDragMode(QGraphicsView::NoDrag);
721 #include "clipitem.moc"