From: Jean-Baptiste Mardelle Date: Wed, 29 Jun 2011 21:16:48 +0000 (+0000) Subject: Fix drawing of "keyframe" effects (effect is not apply before first keyframe nor... X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=a142111d51186bd642bfd1717fa26ab818f46e7d;p=kdenlive Fix drawing of "keyframe" effects (effect is not apply before first keyframe nor after the last one svn path=/trunk/kdenlive/; revision=5747 --- diff --git a/src/abstractclipitem.cpp b/src/abstractclipitem.cpp index f0e8061b..d294df38 100644 --- a/src/abstractclipitem.cpp +++ b/src/abstractclipitem.cpp @@ -246,7 +246,7 @@ GenTime AbstractClipItem::maxDuration() const return m_maxDuration; } -void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/) +void AbstractClipItem::drawKeyFrames(QPainter *painter, bool limitedKeyFrames) { if (m_keyframes.count() < 1) return; @@ -262,6 +262,12 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/) if (active) { x1 = br.x(); x2 = br.right(); + if (limitedKeyFrames) { + QMap::const_iterator end = m_keyframes.constEnd(); + end--; + x2 = x1 + maxw * (end.key() - start); + x1 += maxw * (m_keyframes.constBegin().key() - start); + } y1 = br.bottom() - (m_keyframeDefault - m_keyframeOffset) * maxh; QLineF l(x1, y1, x2, y1); QLineF l2 = painter->matrix().map(l); @@ -280,8 +286,10 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/) x1 = br.x() + maxw * (i.key() - start); y1 = br.bottom() - (i.value() - m_keyframeOffset) * maxh; + + // make sure line begins with clip beginning - if (i.key() != start) { + if (!limitedKeyFrames && i.key() != start) { QLineF l(br.x(), y1, x1, y1); l2 = painter->matrix().map(l); painter->drawLine(l2); @@ -314,7 +322,7 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/) } // make sure line ends at clip end - if (x1 != br.right()) { + if (!limitedKeyFrames && x1 != br.right()) { QLineF l(x1, y1, br.right(), y1); painter->drawLine(painter->matrix().map(l)); } diff --git a/src/abstractclipitem.h b/src/abstractclipitem.h index bf554e0b..ff59dec8 100644 --- a/src/abstractclipitem.h +++ b/src/abstractclipitem.h @@ -115,8 +115,13 @@ protected: /** The (keyframe) parameter that is visible and editable in timeline (on the clip) */ int m_visibleParam; double m_fps; - //QRect visibleRect(); - void drawKeyFrames(QPainter *painter, QRectF exposedRect); + /** @brief Draw the keyframes of a clip + * @param painter The painter device for the clip + * @param limitedKeyFrames The keyframes can be of type "keyframe" or "simplekeyframe". In the + * "simplekeyframe" type, the effect always starts on clip start and ends on clip end. With the + * "keyframe" type, the effect starts on the first keyframe and ends on the last keyframe + */ + void drawKeyFrames(QPainter *painter, bool limitedKeyFrames); int mouseOverKeyFrames(QPointF pos, double maxOffset); virtual void mousePressEvent(QGraphicsSceneMouseEvent * event); diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 4bf64cb1..0e85b25c 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -57,7 +57,8 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, i //m_hover(false), m_speed(speed), m_strobe(strobe), - m_framePixelWidth(0) + m_framePixelWidth(0), + m_limitedKeyFrames(false) { setZValue(2); setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double) itemHeight()); @@ -433,6 +434,7 @@ void ClipItem::setSelectedEffect(const int ix) QDomElement e = params.item(i).toElement(); if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && e.attribute("intimeline") == "1") { m_keyframes.clear(); + m_limitedKeyFrames = e.attribute("type") == "keyframe"; m_visibleParam = i; double max = e.attribute("max").toDouble(); double min = e.attribute("min").toDouble(); @@ -940,7 +942,7 @@ void ClipItem::paint(QPainter *painter, painter->setPen(QPen(Qt::lightGray)); // draw effect or transition keyframes - if (mapped.width() > 20) drawKeyFrames(painter, exposed); + if (mapped.width() > 20) drawKeyFrames(painter, m_limitedKeyFrames); //painter->setMatrixEnabled(true); @@ -1716,6 +1718,7 @@ void ClipItem::updateKeyframes(QDomElement effect) setSelectedEffect(m_selectedEffect); return; } + m_limitedKeyFrames = e.attribute("type") == "keyframe"; const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts); foreach(const QString &str, keyframes) { int pos = str.section(':', 0, 0).toInt(); diff --git a/src/clipitem.h b/src/clipitem.h index 7e49dfdb..4ff7c4e0 100644 --- a/src/clipitem.h +++ b/src/clipitem.h @@ -226,6 +226,9 @@ private: QPixmap m_videoPix; QPixmap m_audioPix; + /** @brief Keyframes type can be "keyframe" or "simplekeyframe" which have to be painted differently. + * True if keyframe type is "keyframe" */ + bool m_limitedKeyFrames; private slots: void slotGetStartThumb();