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, 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_xml = clip->toXML();
49 m_clipName = clip->name();
50 m_producer = clip->getId();
51 m_clipType = clip->clipType();
52 m_cropStart = GenTime();
54 m_maxDuration = m_cropDuration;
56 audioThumbReady = clip->audioThumbCreated();
58 m_cropStart = xml.attribute("in", 0).toInt();
59 m_maxDuration = xml.attribute("duration", 0).toInt();
60 if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
62 if (duration != -1) m_cropDuration = duration;
63 else m_cropDuration = m_maxDuration;*/
66 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
67 setAcceptsHoverEvents(true);
68 connect(this , SIGNAL(prepareAudioThumb(double, QPainterPath, int, int)) , this, SLOT(slotPrepareAudioThumb(double, QPainterPath, int, int)));
70 setBrush(QColor(141, 166, 215));
71 if (m_clipType == VIDEO || m_clipType == AV) {
73 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
74 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
75 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
76 QTimer::singleShot(300, this, SLOT(slotFetchThumbs()));
78 startThumbTimer = new QTimer(this);
79 startThumbTimer->setSingleShot(true);
80 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
81 endThumbTimer = new QTimer(this);
82 endThumbTimer->setSingleShot(true);
83 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
85 } else if (m_clipType == COLOR) {
86 m_maxDuration = GenTime(10000, m_fps);
87 QString colour = m_xml.attribute("colour");
88 colour = colour.replace(0, 2, "#");
89 setBrush(QColor(colour.left(7)));
90 } else if (m_clipType == IMAGE || m_clipType == TEXT) {
91 m_maxDuration = GenTime(10000, m_fps);
92 m_startPix = KThumb::getImage(KUrl(m_xml.attribute("resource")), (int)(50 * KdenliveSettings::project_display_ratio()), 50);
93 m_endPix = m_startPix;
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::resetThumbs() {
107 audioThumbCachePic.clear();
110 void ClipItem::slotFetchThumbs() {
111 m_thumbsRequested += 2;
112 emit getThumb((int)m_cropStart.frames(m_fps), (int)(m_cropStart + m_cropDuration).frames(m_fps));
115 void ClipItem::slotGetStartThumb() {
117 emit getThumb((int)m_cropStart.frames(m_fps), -1);
120 void ClipItem::slotGetEndThumb() {
122 emit getThumb(-1, (int)(m_cropStart + m_cropDuration).frames(m_fps));
125 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
126 if (m_thumbsRequested == 0) return;
127 if (frame == m_cropStart.frames(m_fps)) m_startPix = pix;
133 void ClipItem::slotGotAudioData() {
134 audioThumbReady = true;
138 int ClipItem::type() const {
142 DocClipBase *ClipItem::baseClip() {
146 QDomElement ClipItem::xml() const {
150 int ClipItem::clipType() {
154 QString ClipItem::clipName() {
158 int ClipItem::clipProducer() {
162 void ClipItem::flashClip() {
163 if (m_timeLine == 0) {
164 m_timeLine = new QTimeLine(750, this);
165 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
170 void ClipItem::animate(qreal value) {
176 void ClipItem::paint(QPainter *painter,
177 const QStyleOptionGraphicsItem *option,
179 painter->setOpacity(m_opacity);
180 QBrush paintColor = brush();
182 if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
184 double scale = br.width() / m_cropDuration.frames(m_fps);
185 QRect rectInView = visibleRect();//this is the rect that is visible by the user
187 if (rectInView.isNull())
189 QPainterPath clippath;
190 clippath.addRect(rectInView);
192 int startpixel = (int)(rectInView.x() - rect().x()); //start and endpixel that is viewable from rect()
196 int endpixel = rectInView.width() + rectInView.x();
200 //painter->setRenderHints(QPainter::Antialiasing);
202 QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
204 painter->setClipRect(option->exposedRect);
206 // build path around clip
208 QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
210 painter->setClipPath(resultClipPath.intersected(clippath), Qt::IntersectClip);
211 //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
212 painter->fillRect(br.intersected(rectInView), paintColor);
213 //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
216 if (!m_startPix.isNull() && KdenliveSettings::videothumbnails()) {
217 if (m_clipType == IMAGE) {
218 painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
219 QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
220 painter->drawLine(l);
222 painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
223 QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
224 painter->drawLine(l);
227 painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
228 QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
229 painter->drawLine(l2);
232 // draw audio thumbnails
233 if ((m_clipType == AV || m_clipType == AUDIO) && audioThumbReady && KdenliveSettings::audiothumbnails()) {
235 QPainterPath path = m_clipType == AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
236 if (m_clipType == AV) painter->fillPath(path, QBrush(QColor(200, 200, 200, 140)));
239 if (scale != framePixelWidth)
240 audioThumbCachePic.clear();
241 emit prepareAudioThumb(scale, path, startpixel, endpixel + 200);//200 more for less missing parts before repaint after scrolling
242 int cropLeft = (int)((m_cropStart).frames(m_fps) * scale);
243 for (int startCache = startpixel - startpixel % 100; startCache < endpixel + 300;startCache += 100) {
244 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
245 painter->drawPixmap((int)(roundRectPathUpper.united(roundRectPathLower).boundingRect().x() + startCache - cropLeft), (int)(path.boundingRect().y()), audioThumbCachePic[startCache]);
250 // draw start / end fades
253 fades = QBrush(QColor(200, 50, 50, 150));
254 } else fades = QBrush(QColor(200, 200, 200, 200));
256 if (m_startFade != 0) {
257 QPainterPath fadeInPath;
258 fadeInPath.moveTo(br.x() , br.y());
259 fadeInPath.lineTo(br.x() , br.y() + br.height());
260 fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
261 fadeInPath.closeSubpath();
262 painter->fillPath(fadeInPath, fades);
264 QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
265 painter->drawLine(l);
268 if (m_endFade != 0) {
269 QPainterPath fadeOutPath;
270 fadeOutPath.moveTo(br.x() + br.width(), br.y());
271 fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
272 fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
273 fadeOutPath.closeSubpath();
274 painter->fillPath(fadeOutPath, fades);
276 QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
277 painter->drawLine(l);
281 QPen pen = painter->pen();
282 pen.setColor(Qt::white);
283 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
285 // Draw effects names
286 QString effects = effectNames().join(" / ");
287 if (!effects.isEmpty()) {
288 painter->setPen(pen);
289 QFont font = painter->font();
290 QFont smallFont = font;
291 smallFont.setPointSize(8);
292 painter->setFont(smallFont);
293 QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " ");
294 painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
295 painter->drawText(txtBounding, Qt::AlignCenter, effects);
296 pen.setColor(Qt::black);
297 painter->setPen(pen);
298 painter->setFont(font);
301 // For testing puspose only: draw transitions count
303 painter->setPen(pen);
304 QFont font = painter->font();
305 QFont smallFont = font;
306 smallFont.setPointSize(8);
307 painter->setFont(smallFont);
308 QString txt = " Transitions: " + QString::number(m_transitionsList.count()) + " ";
309 QRectF txtBoundin = painter->boundingRect(br, Qt::AlignRight | Qt::AlignTop, txt);
310 painter->fillRect(txtBoundin, QBrush(QColor(0, 0, 0, 150)));
311 painter->drawText(txtBoundin, Qt::AlignCenter, txt);
312 pen.setColor(Qt::black);
313 painter->setPen(pen);
314 painter->setFont(font);
318 QRectF txtBounding = painter->boundingRect(br, Qt::AlignHCenter | Qt::AlignTop, " " + m_clipName + " ");
319 painter->fillRect(txtBounding, QBrush(QColor(255, 255, 255, 150)));
320 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
322 // draw frame around clip
324 pen.setColor(Qt::red);
327 pen.setColor(Qt::black);
330 painter->setPen(pen);
331 painter->setClipRect(option->exposedRect);
332 painter->drawPath(resultClipPath.intersected(clippath));
334 //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150)));
335 //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
337 /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
338 painter->drawRect(recta);
339 painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
340 painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
341 painter->setPen(QPen(Qt::black, 1.0));
342 painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
343 painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
345 //QGraphicsRectItem::paint(painter, option, widget);
346 //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
347 //painter->setPen(pen);
348 //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
349 //kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
350 //painter->drawText(rect(), Qt::AlignCenter, m_name);
351 // painter->drawRect(boundingRect());
352 //painter->drawRoundRect(-10, -10, 20, 20);
354 int pointy = (int)(br.y() + br.height() / 2 - 5);
355 int pointx1 = (int)(br.x() + 10);
356 int pointx2 = (int)(br.x() + br.width() - 20);
358 painter->setPen(QPen(Qt::black));
359 painter->setBrush(QBrush(QColor(50, 50, 0)));
361 QRadialGradient gradient(pointx1 + 5, pointy + 5 , 5, 2, 2);
362 gradient.setColorAt(0.2, Qt::white);
363 gradient.setColorAt(0.8, Qt::yellow);
364 gradient.setColorAt(1, Qt::black);
365 painter->setBrush(gradient);
367 painter->drawEllipse(pointx1, pointy , 10, 10);
369 QRadialGradient gradient1(pointx2 + 5, pointy + 5 , 5, 2, 2);
370 gradient1.setColorAt(0.2, Qt::white);
371 gradient1.setColorAt(0.8, Qt::yellow);
372 gradient1.setColorAt(1, Qt::black);
373 painter->setBrush(gradient1);
374 painter->drawEllipse(pointx2, pointy, 10, 10);
380 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) {
381 if (abs((int)(pos.x() - (rect().x() + scale * m_startFade))) < 6 && abs((int)(pos.y() - rect().y())) < 6) return FADEIN;
382 else if (abs((int)(pos.x() - rect().x())) < 6) return RESIZESTART;
383 else if (abs((int)(pos.x() - (rect().x() + rect().width() - scale * m_endFade))) < 6 && abs((int)(pos.y() - rect().y())) < 6) return FADEOUT;
384 else if (abs((int)(pos.x() - (rect().x() + rect().width()))) < 6) return RESIZEEND;
385 else if (abs((int)(pos.x() - (rect().x() + 10))) < 6 && abs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONSTART;
386 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;
391 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, QPainterPath path, int startpixel, int endpixel) {
394 QRectF re = path.boundingRect();
396 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
398 for (int startCache = startpixel - startpixel % 100;startCache + 100 < endpixel ;startCache += 100) {
399 //kDebug() << "creating " << startCache;
400 //if (framePixelWidth!=pixelForOneFrame ||
401 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
403 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
404 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
405 audioThumbCachePic[startCache].fill(QColor(200, 200, 200, 0));
407 bool fullAreaDraw = pixelForOneFrame < 10;
408 QMap<int, QPainterPath > positiveChannelPaths;
409 QMap<int, QPainterPath > negativeChannelPaths;
410 QPainter pixpainter(&audioThumbCachePic[startCache]);
412 audiopen.setWidth(0);
413 pixpainter.setPen(audiopen);
414 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
415 //pixpainter.drawLine(0,0,100,re.height());
416 int channelHeight = audioThumbCachePic[startCache].height() / channels;
418 for (int i = 0;i < channels;i++) {
420 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
421 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
424 for (int samples = 0;samples <= 100;samples++) {
425 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
426 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
427 if (frame < 0 || sample < 0 || sample > 19)
429 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
431 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
433 int y = channelHeight * channel + channelHeight / 2;
434 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
436 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
437 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
439 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
440 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
443 for (int channel = 0;channel < channels ;channel++)
444 if (fullAreaDraw && samples == 100) {
445 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
446 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
447 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
448 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
452 if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
454 pixpainter.setPen(QPen(QColor(0, 0, 0)));
455 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
457 for (int i = 0;i < channels;i++) {
459 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
460 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
462 pixpainter.drawPath(positiveChannelPaths[i]);
465 //audioThumbWasDrawn=true;
466 framePixelWidth = pixelForOneFrame;
473 void ClipItem::setFadeIn(int pos, double scale) {
474 int oldIn = m_startFade;
475 if (pos < 0) pos = 0;
476 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
478 if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
479 else update(rect().x(), rect().y(), pos * scale, rect().height());
482 void ClipItem::setFadeOut(int pos, double scale) {
483 int oldOut = m_endFade;
484 if (pos < 0) pos = 0;
485 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
487 if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
488 else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
494 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
495 /*m_resizeMode = operationMode(event->pos());
496 if (m_resizeMode == MOVE) {
497 m_maxTrack = scene()->sceneRect().height();
498 m_grabPoint = (int) (event->pos().x() - rect().x());
500 QGraphicsRectItem::mousePressEvent(event);
504 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
506 QGraphicsRectItem::mouseReleaseEvent(event);
510 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
516 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
521 void ClipItem::resizeStart(int posx, double scale) {
522 AbstractClipItem::resizeStart(posx, scale);
523 if (m_hasThumbs) startThumbTimer->start(100);
526 void ClipItem::resizeEnd(int posx, double scale) {
527 AbstractClipItem::resizeEnd(posx, scale);
528 if (m_hasThumbs) endThumbTimer->start(100);
532 void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
535 int ClipItem::effectsCounter() {
536 return m_effectsCounter++;
539 int ClipItem::effectsCount() {
540 return m_effectList.size();
543 QStringList ClipItem::effectNames() {
544 return m_effectList.effectNames();
547 QDomElement ClipItem::effectAt(int ix) {
548 return m_effectList.at(ix);
551 void ClipItem::setEffectAt(int ix, QDomElement effect) {
552 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
553 m_effectList.insert(ix, effect);
554 m_effectList.removeAt(ix + 1);
555 update(boundingRect());
558 QMap <QString, QString> ClipItem::addEffect(QDomElement effect) {
559 QMap <QString, QString> effectParams;
560 m_effectList.append(effect);
561 effectParams["tag"] = effect.attribute("tag");
562 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
563 QString state = effect.attribute("disabled");
564 if (!state.isEmpty()) effectParams["disabled"] = state;
565 QDomNodeList params = effect.elementsByTagName("parameter");
566 for (int i = 0; i < params.count(); i++) {
567 QDomElement e = params.item(i).toElement();
569 effectParams[e.attribute("name")] = e.attribute("value");
571 if (!e.attribute("factor").isEmpty()) {
572 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
576 update(boundingRect());
580 QMap <QString, QString> ClipItem::getEffectArgs(QDomElement effect) {
581 QMap <QString, QString> effectParams;
582 effectParams["tag"] = effect.attribute("tag");
583 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
584 QString state = effect.attribute("disabled");
585 if (!state.isEmpty()) effectParams["disabled"] = state;
586 QDomNodeList params = effect.elementsByTagName("parameter");
587 for (int i = 0; i < params.count(); i++) {
588 QDomElement e = params.item(i).toElement();
589 if (e.attribute("namedesc").contains(";")) {
590 QString format = e.attribute("format");
591 QStringList separators = format.split("%d", QString::SkipEmptyParts);
592 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
594 QTextStream txtNeu(&neu);
595 if (values.size() > 0)
596 txtNeu << (int)values[0].toDouble();
597 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
598 txtNeu << separators[i];
599 txtNeu << (int)(values[i+1].toDouble());
601 effectParams["start"] = neu;
604 effectParams[e.attribute("name")] = e.attribute("value");
606 if (!e.attribute("factor").isEmpty()) {
607 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
613 void ClipItem::deleteEffect(QString index) {
614 for (int i = 0; i < m_effectList.size(); ++i) {
615 if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
616 m_effectList.removeAt(i);
621 update(boundingRect());
625 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
626 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
628 doc.setContent(effects, true);
629 QDomElement e = doc.documentElement();
630 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
631 if (view) view->slotAddEffect(e, m_startPos, track());
635 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
636 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
639 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
642 void ClipItem::addTransition(Transition* t) {
643 m_transitionsList.append(t);
644 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
646 QDomElement e = doc.documentElement();
647 //if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
651 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
653 int pos = event->x();
654 if (event->modifiers() == Qt::ControlModifier)
655 setDragMode(QGraphicsView::ScrollHandDrag);
656 else if (event->modifiers() == Qt::ShiftModifier)
657 setDragMode(QGraphicsView::RubberBandDrag);
659 QGraphicsItem * item = itemAt(event->pos());
662 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
665 QGraphicsView::mousePressEvent(event);
668 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
670 QGraphicsView::mouseReleaseEvent(event);
671 setDragMode(QGraphicsView::NoDrag);
675 #include "clipitem.moc"