X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fclipitem.cpp;h=4f93bef4df350ab6d516d3c57aee295632676641;hb=19c22f0dbbd0b8a356fcafc782000aa93e4fc2f1;hp=3cbd39ed7de18ef8dec5474f8a9d4aa491646a29;hpb=c07f14e650677ea7cea6eaa57b6e6d1da29a6826;p=kdenlive diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 3cbd39ed..4f93bef4 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -36,8 +36,26 @@ #include #include -ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, bool generateThumbs) - : AbstractClipItem(info, QRectF(), fps), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), audioThumbWasDrawn(false), m_opacity(1.0), m_timeLine(0), m_startThumbRequested(false), m_endThumbRequested(false), m_startFade(0), m_endFade(0), m_hover(false), m_selectedEffect(-1), m_speed(speed), framePixelWidth(0), m_startPix(QPixmap()), m_endPix(QPixmap()), m_videoOnly(false), m_audioOnly(false) +ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, bool generateThumbs) : + AbstractClipItem(info, QRectF(), fps), + m_clip(clip), + m_resizeMode(NONE), + m_startFade(0), + m_endFade(0), + m_audioOnly(false), + m_videoOnly(false), + m_startPix(QPixmap()), + m_endPix(QPixmap()), + m_hasThumbs(false), + m_startThumbTimer(NULL), + m_endThumbTimer(NULL), + m_selectedEffect(-1), + m_timeLine(0), + m_startThumbRequested(false), + m_endThumbRequested(false), + m_hover(false), + m_speed(speed), + m_framePixelWidth(0) { setZValue(1); setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double)(KdenliveSettings::trackheight() - 2)); @@ -56,7 +74,7 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, b m_cropStart = info.cropStart; m_maxDuration = clip->maxDuration(); setAcceptDrops(true); - audioThumbReady = clip->audioThumbCreated(); + m_audioThumbReady = clip->audioThumbCreated(); /* m_cropStart = xml.attribute("in", 0).toInt(); @@ -74,12 +92,12 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, b if (m_clipType == VIDEO || m_clipType == AV || m_clipType == SLIDESHOW || m_clipType == PLAYLIST) { setBrush(QColor(141, 166, 215)); m_hasThumbs = true; - startThumbTimer = new QTimer(this); - startThumbTimer->setSingleShot(true); - connect(startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb())); - endThumbTimer = new QTimer(this); - endThumbTimer->setSingleShot(true); - connect(endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb())); + m_startThumbTimer = new QTimer(this); + m_startThumbTimer->setSingleShot(true); + connect(m_startThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetStartThumb())); + m_endThumbTimer = new QTimer(this); + m_endThumbTimer->setSingleShot(true); + connect(m_endThumbTimer, SIGNAL(timeout()), this, SLOT(slotGetEndThumb())); connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(extractImage(int, int))); //connect(this, SIGNAL(getThumb(int, int)), clip->thumbProducer(), SLOT(getVideoThumbs(int, int))); @@ -109,9 +127,9 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, b ClipItem::~ClipItem() { - if (startThumbTimer) delete startThumbTimer; - if (endThumbTimer) delete endThumbTimer; - if (m_timeLine) delete m_timeLine; + delete m_startThumbTimer; + delete m_endThumbTimer; + delete m_timeLine; } ClipItem *ClipItem::clone(ItemInfo info) const @@ -121,6 +139,8 @@ ClipItem *ClipItem::clone(ItemInfo info) const if (info.cropStart + (info.endPos - info.startPos) == m_cropStart + m_cropDuration) duplicate->slotSetEndThumb(m_endPix); kDebug() << "// CLoning clip: " << (info.cropStart + (info.endPos - info.startPos)).frames(m_fps) << ", CURRENT end: " << (cropStart() + duration()).frames(m_fps); duplicate->setEffectList(m_effectList.clone()); + duplicate->setVideoOnly(m_videoOnly); + duplicate->setAudioOnly(m_audioOnly); //duplicate->setSpeed(m_speed); return duplicate; } @@ -378,13 +398,28 @@ void ClipItem::resetThumbs() m_startPix = QPixmap(); m_endPix = QPixmap(); slotFetchThumbs(); - audioThumbCachePic.clear(); + m_audioThumbCachePic.clear(); } -void ClipItem::refreshClip() +void ClipItem::refreshClip(bool checkDuration) { - m_maxDuration = m_clip->maxDuration(); + if (checkDuration && (m_maxDuration != m_clip->maxDuration())) { + m_maxDuration = m_clip->maxDuration(); + if (m_clipType != IMAGE && m_clipType != TEXT && m_clipType != COLOR) { + if (m_cropStart + m_cropDuration > m_maxDuration) { + // Clip duration changed, make sure to stay in correct range + if (m_cropStart > m_maxDuration) { + m_cropStart = GenTime(); + m_cropDuration = qMin(m_cropDuration, m_maxDuration); + updateRectGeometry(); + } else { + m_cropDuration = m_maxDuration; + updateRectGeometry(); + } + } + } + } if (m_clipType == COLOR) { QString colour = m_clip->getProperty("colour"); colour = colour.replace(0, 2, "#"); @@ -500,7 +535,7 @@ QPixmap ClipItem::endThumb() const void ClipItem::slotGotAudioData() { - audioThumbReady = true; + m_audioThumbReady = true; if (m_clipType == AV && !isAudioOnly()) { QRectF r = boundingRect(); r.setTop(r.top() + r.height() / 2 - 1); @@ -522,6 +557,8 @@ QDomElement ClipItem::xml() const { QDomElement xml = m_clip->toXML(); if (m_speed != 1.0) xml.setAttribute("speed", m_speed); + if (m_audioOnly) xml.setAttribute("audio_only", 1); + else if (m_videoOnly) xml.setAttribute("video_only", 1); return xml; } @@ -589,9 +626,9 @@ void ClipItem::paint(QPainter *painter, painter->setClipRect(exposed); //Fill clip rectangle - QRectF bgRect = br; - bgRect.setLeft(br.left() + xoffset); - painter->fillRect(bgRect, paintColor); + /*QRectF bgRect = br; + bgRect.setLeft(br.left() + xoffset);*/ + painter->fillRect(exposed, paintColor); //painter->setClipPath(resultClipPath, Qt::IntersectClip); @@ -626,7 +663,7 @@ void ClipItem::paint(QPainter *painter, } // draw audio thumbnails - if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (itemHeight / 2) || isAudioOnly())) || m_clipType == AUDIO) && audioThumbReady) { + if (KdenliveSettings::audiothumbnails() && m_speed == 1.0 && !isVideoOnly() && ((m_clipType == AV && (exposed.bottom() > (itemHeight / 2) || isAudioOnly())) || m_clipType == AUDIO) && m_audioThumbReady) { double startpixel = exposed.left(); if (startpixel < 0) @@ -646,8 +683,8 @@ void ClipItem::paint(QPainter *painter, } else mappedRect = mapped; int channels = baseClip()->getProperty("channels").toInt(); - if (scale != framePixelWidth) - audioThumbCachePic.clear(); + if (scale != m_framePixelWidth) + m_audioThumbCachePic.clear(); double cropLeft = m_cropStart.frames(m_fps); const int clipStart = mappedRect.x(); const int mappedStartPixel = painter->matrix().map(QPointF(startpixel + cropLeft, 0)).x() - clipStart; @@ -659,8 +696,8 @@ void ClipItem::paint(QPainter *painter, } for (int startCache = mappedStartPixel - (mappedStartPixel) % 100; startCache < mappedEndPixel; startCache += 100) { - if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull()) - painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), audioThumbCachePic[startCache]); + if (m_audioThumbCachePic.contains(startCache) && !m_audioThumbCachePic[startCache].isNull()) + painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), m_audioThumbCachePic[startCache]); } } @@ -689,10 +726,10 @@ void ClipItem::paint(QPainter *painter, const QRectF r1(framepos + 0.04, 10, itemWidth - framepos - 2, itemHeight - 10); const QRectF r2 = painter->matrix().mapRect(r1); const QRectF txtBounding = painter->boundingRect(r2, Qt::AlignLeft | Qt::AlignTop, ' ' + (*it).comment() + ' '); - - QPainterPath path; - path.addRoundedRect(txtBounding, 3, 3); - painter->fillPath(path, markerBrush); + painter->setBrush(markerBrush); + painter->setPen(Qt::NoPen); + painter->drawRoundedRect(txtBounding, 3, 3); + painter->setPen(Qt::white); painter->drawText(txtBounding, Qt::AlignCenter, (*it).comment()); } //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150))); @@ -746,15 +783,15 @@ void ClipItem::paint(QPainter *painter, txtBounding.setWidth(txtBounding.width() * value); markerBrush.setColor(QColor(50 + 200 * (1.0 - value), 50, 50, 100 + 50 * value)); } else markerBrush.setColor(QColor(50, 50, 50, 150)); - QPainterPath path; - path.addRoundedRect(txtBounding, 4, 4); - painter->fillPath(path/*.intersected(resultClipPath)*/, markerBrush); + painter->setBrush(markerBrush); + painter->setPen(Qt::NoPen); + painter->drawRoundedRect(txtBounding, 3, 3); + painter->setPen(Qt::white); painter->drawText(txtBounding, Qt::AlignCenter, m_effectNames); painter->setPen(Qt::black); } // Draw clip name - // draw frame around clip QColor frameColor(Qt::black); int alphaBase = 60; if (isSelected() || (parentItem() && parentItem()->isSelected())) { @@ -897,16 +934,16 @@ void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, in for (int startCache = startpixel - startpixel % 100;startCache < endpixel;startCache += 100) { //kDebug() << "creating " << startCache; //if (framePixelWidth!=pixelForOneFrame || - if (framePixelWidth == pixelForOneFrame && audioThumbCachePic.contains(startCache)) + if (m_framePixelWidth == pixelForOneFrame && m_audioThumbCachePic.contains(startCache)) continue; - if (audioThumbCachePic[startCache].isNull() || framePixelWidth != pixelForOneFrame) { - audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height())); - audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140)); + if (m_audioThumbCachePic[startCache].isNull() || m_framePixelWidth != pixelForOneFrame) { + m_audioThumbCachePic[startCache] = QPixmap(100, (int)(re.height())); + m_audioThumbCachePic[startCache].fill(QColor(180, 180, 200, 140)); } bool fullAreaDraw = pixelForOneFrame < 10; QMap positiveChannelPaths; QMap negativeChannelPaths; - QPainter pixpainter(&audioThumbCachePic[startCache]); + QPainter pixpainter(&m_audioThumbCachePic[startCache]); QPen audiopen; audiopen.setWidth(0); pixpainter.setPen(audiopen); @@ -918,7 +955,7 @@ void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, in return; } - int channelHeight = audioThumbCachePic[startCache].height() / channels; + int channelHeight = m_audioThumbCachePic[startCache].height() / channels; for (int i = 0;i < channels;i++) { @@ -931,7 +968,7 @@ void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, in int sample = (int)((frame - (int)(frame)) * 20); // AUDIO_FRAME_SIZE if (frame < 0 || sample < 0 || sample > 19) continue; - QMap frame_channel_data = baseClip()->audioFrameChache[(int)frame]; + QMap frame_channel_data = baseClip()->m_audioFrameCache[(int)frame]; for (int channel = 0;channel < channels && frame_channel_data[channel].size() > 0;channel++) { @@ -966,17 +1003,17 @@ void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, in } } //audioThumbWasDrawn=true; - framePixelWidth = pixelForOneFrame; + m_framePixelWidth = pixelForOneFrame; //} } -uint ClipItem::fadeIn() const +int ClipItem::fadeIn() const { return m_startFade; } -uint ClipItem::fadeOut() const +int ClipItem::fadeOut() const { return m_endFade; } @@ -1061,14 +1098,14 @@ void ClipItem::resizeStart(int posx, double /*speed*/) checkEffectsKeyframesPos(previous, cropStart().frames(m_fps), true); if (m_hasThumbs && KdenliveSettings::videothumbnails()) { /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/ - startThumbTimer->start(150); + m_startThumbTimer->start(150); } } } void ClipItem::resizeEnd(int posx, double /*speed*/, bool updateKeyFrames) { - const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps) + 1; + const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps); if (posx > max) posx = max; if (posx == endPos().frames(m_fps)) return; //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps); @@ -1078,7 +1115,7 @@ void ClipItem::resizeEnd(int posx, double /*speed*/, bool updateKeyFrames) if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false); if (m_hasThumbs && KdenliveSettings::videothumbnails()) { /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/ - endThumbTimer->start(150); + m_endThumbTimer->start(150); } } } @@ -1494,7 +1531,7 @@ void ClipItem::setAudioOnly(bool force) m_audioOnly = force; if (m_audioOnly) setBrush(QColor(141, 215, 166)); else setBrush(QColor(141, 166, 215)); - audioThumbCachePic.clear(); + m_audioThumbCachePic.clear(); } bool ClipItem::isAudioOnly() const @@ -1508,30 +1545,4 @@ bool ClipItem::isVideoOnly() const } -// virtual -/* -void CustomTrackView::mousePressEvent ( QMouseEvent * event ) -{ - int pos = event->x(); - if (event->modifiers() == Qt::ControlModifier) - setDragMode(QGraphicsView::ScrollHandDrag); - else if (event->modifiers() == Qt::ShiftModifier) - setDragMode(QGraphicsView::RubberBandDrag); - else { - QGraphicsItem * item = itemAt(event->pos()); - if (item) { - } - else emit cursorMoved((int) mapToScene(event->x(), 0).x()); - } - kDebug()<