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, int track, GenTime startpos, const QRectF & rect, GenTime duration, double fps)
43 : 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) {
45 // kDebug() << "******* CREATING NEW TML CLIP, DUR: " << duration;
47 m_startPos = startpos;
49 m_xml = clip->toXML();
50 m_clipName = clip->name();
51 m_producer = clip->getId();
52 m_clipType = clip->clipType();
53 m_cropStart = GenTime();
54 m_maxDuration = duration;
55 if (duration != GenTime()) m_cropDuration = duration;
56 else m_cropDuration = m_maxDuration;
58 audioThumbReady = clip->audioThumbCreated();
60 m_cropStart = xml.attribute("in", 0).toInt();
61 m_maxDuration = xml.attribute("duration", 0).toInt();
62 if (m_maxDuration == 0) m_maxDuration = xml.attribute("out", 0).toInt() - m_cropStart;
64 if (duration != -1) m_cropDuration = duration;
65 else m_cropDuration = m_maxDuration;*/
68 setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
69 setAcceptsHoverEvents(true);
70 connect(this , SIGNAL(prepareAudioThumb(double, QPainterPath, int, int)) , this, SLOT(slotPrepareAudioThumb(double, QPainterPath, int, int)));
72 setBrush(QColor(141, 166, 215));
73 if (m_clipType == VIDEO || m_clipType == AV) {
75 connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int)));
76 connect(clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));
77 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
78 QTimer::singleShot(300, this, SLOT(slotFetchThumbs()));
80 startThumbTimer = new QTimer(this);
81 startThumbTimer->setSingleShot(true);
82 connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb()));
83 endThumbTimer = new QTimer(this);
84 endThumbTimer->setSingleShot(true);
85 connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb()));
87 } else if (m_clipType == COLOR) {
88 m_maxDuration = GenTime(10000, m_fps);
89 QString colour = m_xml.attribute("colour");
90 colour = colour.replace(0, 2, "#");
91 setBrush(QColor(colour.left(7)));
92 } else if (m_clipType == IMAGE) {
93 m_maxDuration = GenTime(10000, m_fps);
94 m_startPix = KThumb::getImage(KUrl(m_xml.attribute("resource")), (int)(50 * KdenliveSettings::project_display_ratio()), 50);
95 } else if (m_clipType == AUDIO) {
96 connect(clip, SIGNAL(gotAudioData()), this, SLOT(slotGotAudioData()));
101 ClipItem::~ClipItem() {
102 if (startThumbTimer) delete startThumbTimer;
103 if (endThumbTimer) delete endThumbTimer;
106 void ClipItem::resetThumbs() {
108 audioThumbCachePic.clear();
111 void ClipItem::slotFetchThumbs() {
112 m_thumbsRequested += 2;
113 emit getThumb((int)m_cropStart.frames(m_fps), (int)(m_cropStart + m_cropDuration).frames(m_fps));
116 void ClipItem::slotGetStartThumb() {
118 emit getThumb((int)m_cropStart.frames(m_fps), -1);
121 void ClipItem::slotGetEndThumb() {
123 emit getThumb(-1, (int)(m_cropStart + m_cropDuration).frames(m_fps));
126 void ClipItem::slotThumbReady(int frame, QPixmap pix) {
127 if (m_thumbsRequested == 0) return;
128 if (frame == m_cropStart.frames(m_fps)) m_startPix = pix;
134 void ClipItem::slotGotAudioData() {
135 audioThumbReady = true;
139 int ClipItem::type() const {
143 DocClipBase *ClipItem::baseClip() {
147 QDomElement ClipItem::xml() const {
151 int ClipItem::clipType() {
155 QString ClipItem::clipName() {
159 int ClipItem::clipProducer() {
163 void ClipItem::flashClip() {
164 if (m_timeLine == 0) {
165 m_timeLine = new QTimeLine(750, this);
166 connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(animate(qreal)));
171 void ClipItem::animate(qreal value) {
177 void ClipItem::paint(QPainter *painter,
178 const QStyleOptionGraphicsItem *option,
180 painter->setOpacity(m_opacity);
181 QBrush paintColor = brush();
183 if (isSelected()) paintColor = QBrush(QColor(79, 93, 121));
185 double scale = br.width() / m_cropDuration.frames(m_fps);
186 QRect rectInView = visibleRect();//this is the rect that is visible by the user
188 if (rectInView.isNull())
190 QPainterPath clippath;
191 clippath.addRect(rectInView);
193 int startpixel = (int)(rectInView.x() - rect().x()); //start and endpixel that is viewable from rect()
197 int endpixel = rectInView.width() + rectInView.x();
201 //painter->setRenderHints(QPainter::Antialiasing);
203 QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
205 painter->setClipRect(option->exposedRect);
207 // build path around clip
209 QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
211 painter->setClipPath(resultClipPath.intersected(clippath), Qt::IntersectClip);
212 //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
213 painter->fillRect(br.intersected(rectInView), paintColor);
214 //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
217 if (!m_startPix.isNull() && KdenliveSettings::videothumbnails()) {
218 if (m_clipType == IMAGE) {
219 painter->drawPixmap(QPointF(br.x() + br.width() - m_startPix.width(), br.y()), m_startPix);
220 QLineF l(br.x() + br.width() - m_startPix.width(), br.y(), br.x() + br.width() - m_startPix.width(), br.y() + br.height());
221 painter->drawLine(l);
223 painter->drawPixmap(QPointF(br.x() + br.width() - m_endPix.width(), br.y()), m_endPix);
224 QLineF l(br.x() + br.width() - m_endPix.width(), br.y(), br.x() + br.width() - m_endPix.width(), br.y() + br.height());
225 painter->drawLine(l);
228 painter->drawPixmap(QPointF(br.x(), br.y()), m_startPix);
229 QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
230 painter->drawLine(l2);
233 // draw audio thumbnails
234 if ((m_clipType == AV || m_clipType == AUDIO) && audioThumbReady && KdenliveSettings::audiothumbnails()) {
236 QPainterPath path = m_clipType == AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
237 if (m_clipType == AV) painter->fillPath(path, QBrush(QColor(200, 200, 200, 140)));
240 if (scale != framePixelWidth)
241 audioThumbCachePic.clear();
242 emit prepareAudioThumb(scale, path, startpixel, endpixel + 200);//200 more for less missing parts before repaint after scrolling
243 int cropLeft = (int)((m_cropStart).frames(m_fps) * scale);
244 for (int startCache = startpixel - startpixel % 100; startCache < endpixel + 300;startCache += 100) {
245 if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
246 painter->drawPixmap((int)(roundRectPathUpper.united(roundRectPathLower).boundingRect().x() + startCache - cropLeft), (int)(path.boundingRect().y()), audioThumbCachePic[startCache]);
251 // draw start / end fades
254 fades = QBrush(QColor(200, 50, 50, 150));
255 } else fades = QBrush(QColor(200, 200, 200, 200));
257 if (m_startFade != 0) {
258 QPainterPath fadeInPath;
259 fadeInPath.moveTo(br.x() , br.y());
260 fadeInPath.lineTo(br.x() , br.y() + br.height());
261 fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
262 fadeInPath.closeSubpath();
263 painter->fillPath(fadeInPath, fades);
265 QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
266 painter->drawLine(l);
269 if (m_endFade != 0) {
270 QPainterPath fadeOutPath;
271 fadeOutPath.moveTo(br.x() + br.width(), br.y());
272 fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
273 fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
274 fadeOutPath.closeSubpath();
275 painter->fillPath(fadeOutPath, fades);
277 QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
278 painter->drawLine(l);
282 QPen pen = painter->pen();
283 pen.setColor(Qt::white);
284 //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
286 // Draw effects names
287 QString effects = effectNames().join(" / ");
288 if (!effects.isEmpty()) {
289 painter->setPen(pen);
290 QFont font = painter->font();
291 QFont smallFont = font;
292 smallFont.setPointSize(8);
293 painter->setFont(smallFont);
294 QRectF txtBounding = painter->boundingRect(br, Qt::AlignLeft | Qt::AlignTop, " " + effects + " ");
295 painter->fillRect(txtBounding, QBrush(QColor(0, 0, 0, 150)));
296 painter->drawText(txtBounding, Qt::AlignCenter, effects);
297 pen.setColor(Qt::black);
298 painter->setPen(pen);
299 painter->setFont(font);
302 // For testing puspose only: draw transitions count
304 painter->setPen(pen);
305 QFont font = painter->font();
306 QFont smallFont = font;
307 smallFont.setPointSize(8);
308 painter->setFont(smallFont);
309 QString txt = " Transitions: " + QString::number(m_transitionsList.count()) + " ";
310 QRectF txtBoundin = painter->boundingRect(br, Qt::AlignRight | Qt::AlignTop, txt);
311 painter->fillRect(txtBoundin, QBrush(QColor(0, 0, 0, 150)));
312 painter->drawText(txtBoundin, Qt::AlignCenter, txt);
313 pen.setColor(Qt::black);
314 painter->setPen(pen);
315 painter->setFont(font);
319 QRectF txtBounding = painter->boundingRect(br, Qt::AlignHCenter | Qt::AlignTop, " " + m_clipName + " ");
320 painter->fillRect(txtBounding, QBrush(QColor(255, 255, 255, 150)));
321 painter->drawText(txtBounding, Qt::AlignCenter, m_clipName);
323 // draw frame around clip
325 pen.setColor(Qt::red);
328 pen.setColor(Qt::black);
331 painter->setPen(pen);
332 painter->setClipRect(option->exposedRect);
333 painter->drawPath(resultClipPath.intersected(clippath));
335 //painter->fillRect(startpixel,0,startpixel+endpixel,(int)br.height(), QBrush(QColor(255,255,255,150)));
336 //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
338 /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
339 painter->drawRect(recta);
340 painter->drawLine(rect().x() + 1, rect().y(), rect().x() + 1, rect().y() + rect().height());
341 painter->drawLine(rect().x() + rect().width(), rect().y(), rect().x() + rect().width(), rect().y() + rect().height());
342 painter->setPen(QPen(Qt::black, 1.0));
343 painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
344 painter->drawLine(rect().x(), rect().y() + rect().height(), rect().x() + rect().width(), rect().y() + rect().height());*/
346 //QGraphicsRectItem::paint(painter, option, widget);
347 //QPen pen(Qt::green, 1.0 / size.x() + 0.5);
348 //painter->setPen(pen);
349 //painter->drawLine(rect().x(), rect().y(), rect().x() + rect().width(), rect().y());
350 //kDebug()<<"ITEM REPAINT RECT: "<<boundingRect().width();
351 //painter->drawText(rect(), Qt::AlignCenter, m_name);
352 // painter->drawRect(boundingRect());
353 //painter->drawRoundRect(-10, -10, 20, 20);
355 painter->setPen(QPen(Qt::black));
356 painter->setBrush(QBrush(Qt::yellow));
357 painter->drawEllipse((int)(br.x() + 10), (int)(br.y() + br.height() / 2 - 5) , 10, 10);
358 painter->drawEllipse((int)(br.x() + br.width() - 20), (int)(br.y() + br.height() / 2 - 5), 10, 10);
363 OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) {
364 if (abs((int)(pos.x() - (rect().x() + scale * m_startFade))) < 6 && abs((int)(pos.y() - rect().y())) < 6) return FADEIN;
365 else if (abs((int)(pos.x() - rect().x())) < 6) return RESIZESTART;
366 else if (abs((int)(pos.x() - (rect().x() + rect().width() - scale * m_endFade))) < 6 && abs((int)(pos.y() - rect().y())) < 6) return FADEOUT;
367 else if (abs((int)(pos.x() - (rect().x() + rect().width()))) < 6) return RESIZEEND;
368 else if (abs((int)(pos.x() - (rect().x() + 10))) < 6 && abs((int)(pos.y() - (rect().y() + rect().height() / 2 - 5))) < 6) return TRANSITIONSTART;
369 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;
374 void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, QPainterPath path, int startpixel, int endpixel) {
377 QRectF re = path.boundingRect();
379 //if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
381 for (int startCache = startpixel - startpixel % 100;startCache + 100 < endpixel ;startCache += 100) {
382 //kDebug() << "creating " << startCache;
383 //if (framePixelWidth!=pixelForOneFrame ||
384 if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache))
386 if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) {
387 audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height()));
388 audioThumbCachePic[startCache].fill(QColor(200, 200, 200, 0));
390 bool fullAreaDraw = pixelForOneFrame < 10;
391 QMap<int, QPainterPath > positiveChannelPaths;
392 QMap<int, QPainterPath > negativeChannelPaths;
393 QPainter pixpainter(&audioThumbCachePic[startCache]);
395 audiopen.setWidth(0);
396 pixpainter.setPen(audiopen);
397 //pixpainter.setRenderHint(QPainter::Antialiasing,true);
398 //pixpainter.drawLine(0,0,100,re.height());
399 int channelHeight = audioThumbCachePic[startCache].height() / channels;
401 for (int i = 0;i < channels;i++) {
403 positiveChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
404 negativeChannelPaths[i].moveTo(0, channelHeight*i + channelHeight / 2);
407 for (int samples = 0;samples <= 100;samples++) {
408 double frame = (double)(samples + startCache - 0) / pixelForOneFrame;
409 int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE
410 if (frame < 0 || sample < 0 || sample > 19)
412 QMap<int, QByteArray> frame_channel_data = baseClip()->audioFrameChache[(int)frame];
414 for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) {
416 int y = channelHeight * channel + channelHeight / 2;
417 int delta = (int)(frame_channel_data[channel][sample] - 127 / 2) * channelHeight / 64;
419 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + qAbs(delta));
420 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - qAbs(delta));
422 positiveChannelPaths[channel].lineTo(samples, 0.1 + y + delta);
423 negativeChannelPaths[channel].lineTo(samples, 0.1 + y - delta);
426 for (int channel = 0;channel < channels ;channel++)
427 if (fullAreaDraw && samples == 100) {
428 positiveChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
429 negativeChannelPaths[channel].lineTo(samples, channelHeight*channel + channelHeight / 2);
430 positiveChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
431 negativeChannelPaths[channel].lineTo(0, channelHeight*channel + channelHeight / 2);
435 if (m_clipType != AV) pixpainter.setBrush(QBrush(QColor(200, 200, 100)));
437 pixpainter.setPen(QPen(QColor(0, 0, 0)));
438 pixpainter.setBrush(QBrush(QColor(60, 60, 60)));
440 for (int i = 0;i < channels;i++) {
442 //pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
443 pixpainter.drawPath(positiveChannelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
445 pixpainter.drawPath(positiveChannelPaths[i]);
448 //audioThumbWasDrawn=true;
449 framePixelWidth = pixelForOneFrame;
456 void ClipItem::setFadeIn(int pos, double scale) {
457 int oldIn = m_startFade;
458 if (pos < 0) pos = 0;
459 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
461 if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height());
462 else update(rect().x(), rect().y(), pos * scale, rect().height());
465 void ClipItem::setFadeOut(int pos, double scale) {
466 int oldOut = m_endFade;
467 if (pos < 0) pos = 0;
468 if (pos > m_cropDuration.frames(m_fps)) pos = (int)(m_cropDuration.frames(m_fps) / 2);
470 if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height());
471 else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
477 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
478 /*m_resizeMode = operationMode(event->pos());
479 if (m_resizeMode == MOVE) {
480 m_maxTrack = scene()->sceneRect().height();
481 m_grabPoint = (int) (event->pos().x() - rect().x());
483 QGraphicsRectItem::mousePressEvent(event);
487 void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
489 QGraphicsRectItem::mouseReleaseEvent(event);
493 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
499 void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
504 void ClipItem::resizeStart(int posx, double scale) {
505 AbstractClipItem::resizeStart(posx, scale);
506 if (m_hasThumbs) startThumbTimer->start(100);
509 void ClipItem::resizeEnd(int posx, double scale) {
510 AbstractClipItem::resizeEnd(posx, scale);
511 if (m_hasThumbs) endThumbTimer->start(100);
515 void ClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
518 int ClipItem::effectsCounter() {
519 return m_effectsCounter++;
522 int ClipItem::effectsCount() {
523 return m_effectList.size();
526 QStringList ClipItem::effectNames() {
527 return m_effectList.effectNames();
530 QDomElement ClipItem::effectAt(int ix) {
531 return m_effectList.at(ix);
534 void ClipItem::setEffectAt(int ix, QDomElement effect) {
535 kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
536 m_effectList.insert(ix, effect);
537 m_effectList.removeAt(ix + 1);
538 update(boundingRect());
541 QMap <QString, QString> ClipItem::addEffect(QDomElement effect) {
542 QMap <QString, QString> effectParams;
543 m_effectList.append(effect);
544 effectParams["tag"] = effect.attribute("tag");
545 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
546 QString state = effect.attribute("disabled");
547 if (!state.isEmpty()) effectParams["disabled"] = state;
548 QDomNodeList params = effect.elementsByTagName("parameter");
549 for (int i = 0; i < params.count(); i++) {
550 QDomElement e = params.item(i).toElement();
552 effectParams[e.attribute("name")] = e.attribute("value");
554 if (!e.attribute("factor").isEmpty()) {
555 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
559 update(boundingRect());
563 QMap <QString, QString> ClipItem::getEffectArgs(QDomElement effect) {
564 QMap <QString, QString> effectParams;
565 effectParams["tag"] = effect.attribute("tag");
566 effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
567 QString state = effect.attribute("disabled");
568 if (!state.isEmpty()) effectParams["disabled"] = state;
569 QDomNodeList params = effect.elementsByTagName("parameter");
570 for (int i = 0; i < params.count(); i++) {
571 QDomElement e = params.item(i).toElement();
572 if (e.attribute("name").contains(";")) {
573 QString format = e.attribute("format");
574 QStringList separators = format.split("%d", QString::SkipEmptyParts);
575 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
577 QTextStream txtNeu(&neu);
578 if (values.size() > 0)
579 txtNeu << (int)values[0].toDouble();
580 for (int i = 0;i < separators.size() && i + 1 < values.size();i++) {
581 txtNeu << separators[i];
582 txtNeu << (int)(values[i+1].toDouble());
584 effectParams["start"] = neu;
587 effectParams[e.attribute("name")] = e.attribute("value");
589 if (!e.attribute("factor").isEmpty()) {
590 effectParams[e.attribute("name")] = QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
596 void ClipItem::deleteEffect(QString index) {
597 for (int i = 0; i < m_effectList.size(); ++i) {
598 if (m_effectList.at(i).attribute("kdenlive_ix") == index) {
599 m_effectList.removeAt(i);
604 update(boundingRect());
608 void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
609 QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
611 doc.setContent(effects, true);
612 QDomElement e = doc.documentElement();
613 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
614 if (view) view->slotAddEffect(e, m_startPos, m_track);
618 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
619 event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
622 void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
625 void ClipItem::addTransition(Transition* t) {
626 m_transitionsList.append(t);
627 CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
629 QDomElement e = doc.documentElement();
630 if (view) view->slotAddTransition(this, t->toXML() , t->startPos(), track());
634 void CustomTrackView::mousePressEvent ( QMouseEvent * event )
636 int pos = event->x();
637 if (event->modifiers() == Qt::ControlModifier)
638 setDragMode(QGraphicsView::ScrollHandDrag);
639 else if (event->modifiers() == Qt::ShiftModifier)
640 setDragMode(QGraphicsView::RubberBandDrag);
642 QGraphicsItem * item = itemAt(event->pos());
645 else emit cursorMoved((int) mapToScene(event->x(), 0).x());
648 QGraphicsView::mousePressEvent(event);
651 void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
653 QGraphicsView::mouseReleaseEvent(event);
654 setDragMode(QGraphicsView::NoDrag);
658 #include "clipitem.moc"