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, GenTime startpos, const QRectF & rect, GenTime duration, double fps)
42 : AbstractClipItem(rect), 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 // kDebug() << "******* CREATING NEW TML CLIP, DUR: " << duration;
46 m_startPos = startpos;
48 m_xml = clip->toXML();
49 m_clipName = clip->name();
50 m_producer = clip->getId();
51 m_clipType = clip->clipType();
52 m_cropStart = GenTime();
53 m_maxDuration = duration;
54 if (duration != GenTime()) m_cropDuration = duration;
55 else m_cropDuration = m_maxDuration;
57 audioThumbReady = clip->audioThumbCreated();
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) {
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()));
86 } else if (m_clipType == COLOR) {
87 m_maxDuration = GenTime(10000, m_fps);
88 QString colour = m_xml.attribute("colour");
89 colour = colour.replace(0, 2, "#");
90 setBrush(QColor(colour.left(7)));
91 } else if (m_clipType == IMAGE) {
92 m_maxDuration = GenTime(10000, m_fps);
93 m_startPix = KThumb::getImage(KUrl(m_xml.attribute("resource")), (int)(50 * KdenliveSettings::project_display_ratio()), 50);
94 } else if (m_clipType == AUDIO) {
95 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
100 ClipItem::~ClipItem() {
101 if (startThumbTimer) delete startThumbTimer;
102 if (endThumbTimer) delete endThumbTimer;
105 void ClipItem::slotFetchThumbs() {
106 m_thumbsRequested += 2;
107 emit getThumb((int)m_cropStart.frames(m_fps), (int)(m_cropStart + m_cropDuration).frames(m_fps));
110 void ClipItem::slotGetStartThumb() {
112 emit getThumb((int)m_cropStart.frames(m_fps), -1);
115 void ClipItem::slotGetEndThumb() {
117 emit getThumb(-1, (int)(m_cropStart + m_cropDuration).frames(m_fps));
120 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
121 if (m_thumbsRequested == 0) return;
122 if (frame == m_cropStart.frames(m_fps)) m_startPix = pix;
128 void ClipItem::slotGotAudioData() {
129 audioThumbReady = true;
133 int ClipItem::type() const {
137 DocClipBase *ClipItem::baseClip() {
141 QDomElement ClipItem::xml() const {
145 int ClipItem::clipType() {
149 QString ClipItem::clipName() {
153 int ClipItem::clipProducer() {
157 GenTime ClipItem::maxDuration() const {
158 return m_maxDuration;
161 GenTime ClipItem::cropStart() const {
165 void ClipItem::flashClip() {
166 if (m_timeLine == 0) {
167 m_timeLine = new QTimeLine(750, this);
168 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
173 void ClipItem::animate(qreal value) {
179 void ClipItem::paint(QPainter *painter,
180 const QStyleOptionGraphicsItem *option,
182 painter->setOpacity(m_opacity);
183 QBrush paintColor = brush();
185 if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
187 double scale = br.width() / m_cropDuration.frames(m_fps);
188 QRect rectInView;//this is the rect that is visible by the user
189 if (scene()->views().size() > 0) {
190 rectInView = scene()->views()[0]->viewport()->rect();
191 rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(), scene()->views()[0]->verticalScrollBar()->value());
192 rectInView.adjust(-10, -10, 10, 10);//make view rect 10 pixel greater on each site, or repaint after scroll event
193 //kDebug() << scene()->views()[0]->viewport()->rect() << " " << scene()->views()[0]->horizontalScrollBar()->value();
195 if (rectInView.isNull())
197 QPainterPath clippath;
198 clippath.addRect(rectInView);
200 int startpixel = (int)(rectInView.x() - rect().x()); //start and endpixel that is viewable from rect()
204 int endpixel = rectInView.width() + rectInView.x();
208 //painter->setRenderHints(QPainter::Antialiasing);
210 QPainterPath roundRectPathUpper, roundRectPathLower;
211 double roundingY = 20;
212 double roundingX = 20;
214 painter->setClipRect(option->exposedRect);
215 if (roundingX > br.width() / 2) roundingX = br.width() / 2;
217 int br_endx = (int)(br.x() + br .width() - offset);
218 int br_startx = (int)(br.x() + offset);
219 int br_starty = (int)(br.y());
220 int br_halfy = (int)(br.y() + br.height() / 2 - offset);
221 int br_endy = (int)(br.y() + br.height());
222 int left_upper = 0, left_lower = 0, right_upper = 0, right_lower = 0;
224 if (m_hover && false) {
225 if (!true) /*TRANSITIONSTART to upper clip*/
227 if (!false) /*TRANSITIONSTART to lower clip*/
229 if (!true) /*TRANSITIONEND to upper clip*/
231 if (!false) /*TRANSITIONEND to lower clip*/
235 // build path around clip
236 roundRectPathUpper.moveTo(br_endx - right_upper , br_halfy);
237 roundRectPathUpper.arcTo(br_endx - roundingX - right_upper , br_starty , roundingX, roundingY, 0.0, 90.0);
238 roundRectPathUpper.lineTo(br_startx + roundingX + left_upper, br_starty);
239 roundRectPathUpper.arcTo(br_startx + left_upper, br_starty , roundingX, roundingY, 90.0, 90.0);
240 roundRectPathUpper.lineTo(br_startx + left_upper, br_halfy);
242 roundRectPathLower.moveTo(br_startx + left_lower, br_halfy);
243 roundRectPathLower.arcTo(br_startx + left_lower, br_endy - roundingY , roundingX, roundingY, 180.0, 90.0);
244 roundRectPathLower.lineTo(br_endx - roundingX - right_lower , br_endy);
245 roundRectPathLower.arcTo(br_endx - roundingX - right_lower , br_endy - roundingY, roundingX, roundingY, 270.0, 90.0);
246 roundRectPathLower.lineTo(br_endx - right_lower , br_halfy);
248 QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
250 painter->setClipPath(resultClipPath.intersected(clippath), Qt::IntersectClip);
251 //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
252 painter->fillRect(br.intersected(rectInView), paintColor);
253 //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
256 if (!m_startPix.isNull() && KdenliveSettings::videothumbnails()) {
257 if (m_clipType == IMAGE) {
258 painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
259 QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
260 painter->drawLine(l);
262 painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
263 QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
264 painter->drawLine(l);
267 painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
268 QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
269 painter->drawLine(l2);
272 // draw audio thumbnails
273 if ((m_clipType == AV || m_clipType == AUDIO) && audioThumbReady && KdenliveSettings::audiothumbnails()) {
275 QPainterPath path = m_clipType == AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
276 if (m_clipType == AV) painter->fillPath(path, QBrush(QColor(200, 200, 200, 140)));
279 if (scale != framePixelWidth)
280 audioThumbCachePic.clear();
281 emit prepareAudioThumb(scale, path, startpixel, endpixel + 200);//200 more for less missing parts before repaint after scrolling
282 int cropLeft = (m_cropStart).frames(m_fps) * scale;
283 for (int startCache = startpixel - startpixel % 100; startCache < endpixel + 300;startCache += 100) {
284 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
285 painter->drawPixmap((int)(roundRectPathUpper.united(roundRectPathLower).boundingRect().x() + startCache - cropLeft), (int)(path.boundingRect().y()), audioThumbCachePic[startCache]);
290 // draw start / end fades
293 fades = QBrush(QColor(200, 50, 50, 150));
294 } else fades = QBrush(QColor(200, 200, 200, 200));
296 if (m_startFade != 0) {
297 QPainterPath fadeInPath;
298 fadeInPath.moveTo(br.x() - offset, br.y());
299 fadeInPath.lineTo(br.x() - offset, br.y() + br.height());
300 fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
301 fadeInPath.closeSubpath();
302 painter->fillPath(fadeInPath, fades);
304 QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
305 painter->drawLine(l);
308 if (m_endFade != 0) {
309 QPainterPath fadeOutPath;
310 fadeOutPath.moveTo(br.x() + br.width(), br.y());
311 fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
312 fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
313 fadeOutPath.closeSubpath();
314 painter->fillPath(fadeOutPath, fades);
316 QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
317 painter->drawLine(l);
321 QPen pen = painter->pen();
322 pen.setColor(Qt::white);
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);
341 // For testing puspose only: draw transitions count
343 painter->setPen(pen);
344 QFont font = painter->font();
345 QFont smallFont = font;
346 smallFont.setPointSize(8);
347 painter->setFont(smallFont);
348 QString txt = " Transitions: " + QString::number(m_transitionsList.count()) + " ";
349 QRectF txtBoundin = painter->boundingRect(br, Qt::AlignRight | Qt::AlignTop, txt);
350 painter->fillRect(txtBoundin, QBrush(QColor(0, 0, 0, 150)));
351 painter->drawText(txtBoundin, Qt::AlignCenter, txt);
352 pen.setColor(Qt::black);
353 painter->setPen(pen);
354 painter->setFont(font);
358 QRectF txtBounding = painter->boundingRect(br, Qt::AlignHCenter | Qt::AlignTop, " " + m_clipName + " ");
359 painter->fillRect(txtBounding, QBrush(QColor(255, 255, 255, 150)));
360 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
362 // draw frame around clip
363 pen.setColor(Qt::red);
365 if (isSelected()) painter->setPen(pen);
366 painter->setClipRect(option->exposedRect);
367 painter->drawPath(resultClipPath.intersected(clippath));
369 //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150)));
370 //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
372 /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
373 painter->drawRect(recta);
374 painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
375 painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
376 painter->setPen(QPen(Qt::black, 1.0));
377 painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
378 painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
380 //QGraphicsRectItem::paint(painter, option, widget);
381 //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
382 //painter->setPen(pen);
383 //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
384 //kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
385 //painter->drawText(rect(), Qt::AlignCenter, m_name);
386 // painter->drawRect(boundingRect());
387 //painter->drawRoundRect(-10, -10, 20, 20);
389 painter->setPen(QPen(Qt::black));
390 painter->setBrush(QBrush(Qt::yellow));
391 painter->drawEllipse((int)(br.x() + 10), (int)(br.y() + br.height() / 2 - 5) , 10, 10);
392 painter->drawEllipse((int)(br.x() + br.width() - 20), (int)(br.y() + br.height() / 2 - 5), 10, 10);
397 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) {
398 if (abs((int)(pos.x() - (rect().x() + scale * m_startFade))) < 6 && abs((int)(pos.y() - rect().y())) < 6) return FADEIN;
399 else if (abs((int)(pos.x() - rect().x())) < 6) return RESIZESTART;
400 else if (abs((int)(pos.x() - (rect().x() + rect().width() - scale * m_endFade))) < 6 && abs((int)(pos.y() - rect().y())) < 6) return FADEOUT;
401 else if (abs((int)(pos.x() - (rect().x() + rect().width()))) < 6) return RESIZEEND;
402 else if (abs((int)(pos.x() - (rect().x() + 10))) < 6 && abs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONSTART;
403 else if (abs((int)(pos.x() - (rect().x() + rect().width() - 20))) < 6 && abs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONEND;
408 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, QPainterPath path, int startpixel, int endpixel) {
411 QRectF re = path.boundingRect();
413 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
415 for (int startCache = startpixel - startpixel % 100;startCache + 100 < endpixel ;startCache += 100) {
416 //kDebug() << "creating " << startCache;
417 //if (framePixelWidth!=pixelForOneFrame ||
418 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
420 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
421 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
422 audioThumbCachePic[startCache].fill(QColor(200, 200, 200, 0));
424 bool fullAreaDraw = pixelForOneFrame < 10;
425 QMap<int, QPainterPath > positiveChannelPaths;
426 QMap<int, QPainterPath > negativeChannelPaths;
427 QPainter pixpainter(&audioThumbCachePic[startCache]);
429 audiopen.setWidth(0);
430 pixpainter.setPen(audiopen);
431 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
432 //pixpainter.drawLine(0,0,100,re.height());
433 int channelHeight = audioThumbCachePic[startCache].height() / channels;
435 for (int i = 0;i < channels;i++) {
437 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
438 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
441 for (int samples = 0;samples <= 100;samples++) {
442 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
443 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
444 if (frame < 0 || sample < 0 || sample > 19)
446 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
448 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
450 int y = channelHeight * channel + channelHeight / 2;
451 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
453 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
454 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
456 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
457 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
460 for (int channel = 0;channel < channels ;channel++)
461 if (fullAreaDraw && samples == 100) {
462 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
463 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
464 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
465 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
469 if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
471 pixpainter.setPen(QPen(QColor(0, 0, 0)));
472 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
474 for (int i = 0;i < channels;i++) {
476 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
477 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
479 pixpainter.drawPath(positiveChannelPaths[i]);
482 //audioThumbWasDrawn=true;
483 framePixelWidth = pixelForOneFrame;
490 void ClipItem::setFadeIn(int pos, double scale) {
491 int oldIn = m_startFade;
492 if (pos < 0) pos = 0;
493 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
495 if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
496 else update(rect().x(), rect().y(), pos * scale, rect().height());
499 void ClipItem::setFadeOut(int pos, double scale) {
500 int oldOut = m_endFade;
501 if (pos < 0) pos = 0;
502 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
504 if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
505 else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
511 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
512 /*m_resizeMode = operationMode(event->pos());
513 if (m_resizeMode == MOVE) {
514 m_maxTrack = scene()->sceneRect().height();
515 m_grabPoint = (int) (event->pos().x() - rect().x());
517 QGraphicsRectItem::mousePressEvent(event);
521 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
523 QGraphicsRectItem::mouseReleaseEvent(event);
527 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
533 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
538 void ClipItem::resizeStart(int posx, double scale) {
539 GenTime durationDiff = GenTime(posx, m_fps) - m_startPos;
540 if (durationDiff == GenTime()) return;
541 //kDebug() << "-- RESCALE: CROP=" << m_cropStart << ", DIFF = " << durationDiff;
542 if (m_cropStart + durationDiff < GenTime()) {
543 durationDiff = GenTime() - m_cropStart;
544 } else if (durationDiff >= m_cropDuration) {
545 durationDiff = m_cropDuration - GenTime(3, m_fps);
547 m_startPos += durationDiff;
548 m_cropStart += durationDiff;
549 m_cropDuration = m_cropDuration - durationDiff;
550 setRect(m_startPos.frames(m_fps) * scale, rect().y(), m_cropDuration.frames(m_fps) * scale, rect().height());
551 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
552 for (int i = 0; i < collisionList.size(); ++i) {
553 QGraphicsItem *item = collisionList.at(i);
554 if (item->type() == 70000) {
555 GenTime diff = ((ClipItem *)item)->endPos() + GenTime(1, m_fps) - m_startPos;
556 setRect((m_startPos + diff).frames(m_fps) * scale, rect().y(), (m_cropDuration - diff).frames(m_fps) * scale, rect().height());
559 m_cropDuration = m_cropDuration - diff;
563 if (m_hasThumbs) startThumbTimer->start(100);
566 void ClipItem::resizeEnd(int posx, double scale) {
567 GenTime durationDiff = GenTime(posx, m_fps) - endPos();
568 if (durationDiff == GenTime()) return;
569 //kDebug() << "-- RESCALE: CROP=" << m_cropStart << ", DIFF = " << durationDiff;
570 if (m_cropDuration + durationDiff <= GenTime()) {
571 durationDiff = GenTime() - (m_cropDuration - GenTime(3, m_fps));
572 } else if (m_cropStart + m_cropDuration + durationDiff >= m_maxDuration) {
573 durationDiff = m_maxDuration - m_cropDuration - m_cropStart;
575 m_cropDuration += durationDiff;
576 setRect(m_startPos.frames(m_fps) * scale, rect().y(), m_cropDuration.frames(m_fps) * scale, rect().height());
577 QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
578 for (int i = 0; i < collisionList.size(); ++i) {
579 QGraphicsItem *item = collisionList.at(i);
580 if (item->type() == 70000) {
581 GenTime diff = ((ClipItem *)item)->startPos() - GenTime(1, m_fps) - startPos();
582 m_cropDuration = diff;
583 setRect(m_startPos.frames(m_fps) * scale, rect().y(), m_cropDuration.frames(m_fps) * scale, rect().height());
587 if (m_hasThumbs) endThumbTimer->start(100);
591 void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
594 int ClipItem::effectsCounter() {
595 return m_effectsCounter++;
598 int ClipItem::effectsCount() {
599 return m_effectList.size();
602 QStringList ClipItem::effectNames() {
603 return m_effectList.effectNames();
606 QDomElement ClipItem::effectAt(int ix) {
607 return m_effectList.at(ix);
610 void ClipItem::setEffectAt(int ix, QDomElement effect) {
611 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
612 m_effectList.insert(ix, effect);
613 m_effectList.removeAt(ix + 1);
614 update(boundingRect());
617 QMap <QString, QString> ClipItem::addEffect(QDomElement effect) {
618 QMap <QString, QString> effectParams;
619 m_effectList.append(effect);
620 effectParams["tag"] = effect.attribute("tag");
621 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
622 QString state = effect.attribute("disabled");
623 if (!state.isEmpty()) effectParams["disabled"] = state;
624 QDomNodeList params = effect.elementsByTagName("parameter");
625 for (int i = 0; i < params.count(); i++) {
626 QDomElement e = params.item(i).toElement();
628 effectParams[e.attribute("name")] = e.attribute("value");
630 if (!e.attribute("factor").isEmpty()) {
631 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
635 update(boundingRect());
639 QMap <QString, QString> ClipItem::getEffectArgs(QDomElement effect) {
640 QMap <QString, QString> effectParams;
641 effectParams["tag"] = effect.attribute("tag");
642 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
643 QString state = effect.attribute("disabled");
644 if (!state.isEmpty()) effectParams["disabled"] = state;
645 QDomNodeList params = effect.elementsByTagName("parameter");
646 for (int i = 0; i < params.count(); i++) {
647 QDomElement e = params.item(i).toElement();
648 if (e.attribute("name").contains(";")) {
649 QString format = e.attribute("format");
650 QStringList separators = format.split("%d", QString::SkipEmptyParts);
651 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
653 QTextStream txtNeu(&neu);
654 if (values.size() > 0)
655 txtNeu << (int)values[0].toDouble();
656 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
657 txtNeu << separators[i];
658 txtNeu << (int)(values[i+1].toDouble());
660 effectParams["start"] = neu;
663 effectParams[e.attribute("name")] = e.attribute("value");
665 if (!e.attribute("factor").isEmpty()) {
666 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
672 void ClipItem::deleteEffect(QString index) {
673 for (int i = 0; i < m_effectList.size(); ++i) {
674 if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
675 m_effectList.removeAt(i);
680 update(boundingRect());
684 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
685 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
687 doc.setContent(effects, true);
688 QDomElement e = doc.documentElement();
689 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
690 if (view) view->slotAddEffect(e, m_startPos, m_track);
694 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
695 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
698 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
704 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
706 int pos = event->x();
707 if (event->modifiers() == Qt::ControlModifier)
708 setDragMode(QGraphicsView::ScrollHandDrag);
709 else if (event->modifiers() == Qt::ShiftModifier)
710 setDragMode(QGraphicsView::RubberBandDrag);
712 QGraphicsItem * item = itemAt(event->pos());
715 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
718 QGraphicsView::mousePressEvent(event);
721 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
723 QGraphicsView::mouseReleaseEvent(event);
724 setDragMode(QGraphicsView::NoDrag);
728 #include "clipitem.moc"