]> git.sesse.net Git - kdenlive/blobdiff - src/abstractclipitem.cpp
Fix bug with space in render file name:
[kdenlive] / src / abstractclipitem.cpp
index 09d837a1b88e9ead91bf37d4631686917008ad17..8fb767be27c83b8fa7548537e5776f389a10c172 100644 (file)
@@ -36,6 +36,7 @@ AbstractClipItem::AbstractClipItem(const ItemInfo info, const QRectF& rect, doub
         m_editedKeyframe(-1),
         m_selectedKeyframe(0),
         m_keyframeFactor(1),
+        m_keyframeOffset(0),
         m_fps(fps)
 #if QT_VERSION >= 0x040600
         , m_closeAnimation(NULL)
@@ -129,7 +130,6 @@ void AbstractClipItem::resizeStart(int posx, bool hasSizeLimit)
 {
     GenTime durationDiff = GenTime(posx, m_fps) - m_info.startPos;
     if (durationDiff == GenTime()) return;
-    //kDebug() << "-- RESCALE DIFF=" << durationDiff.frames(25) << ", CLIP: " << startPos().frames(25) << "-" << endPos().frames(25);
 
     if (type() == AVWIDGET && hasSizeLimit && (cropStart() + durationDiff < GenTime())) {
         durationDiff = GenTime() - cropStart();
@@ -253,17 +253,16 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/)
     QRectF br = rect();
     double maxw = br.width() / cropDuration().frames(m_fps);
     double maxh = br.height() / 100.0 * m_keyframeFactor;
-    double x1;
-    double y1;
-    double x2;
-    double y2;
+    double start = cropStart().frames(m_fps);
+    double x1, y1, x2, y2;
+    bool antialiasing = painter->renderHints() & QPainter::Antialiasing;
 
     // draw line showing default value
     bool active = isSelected() || (parentItem() && parentItem()->isSelected());
     if (active) {
         x1 = br.x();
         x2 = br.right();
-        y1 = br.bottom() - m_keyframeDefault * maxh;
+        y1 = br.bottom() - (m_keyframeDefault - m_keyframeOffset) * maxh;
         QLineF l(x1, y1, x2, y1);
         QLineF l2 = painter->matrix().map(l);
         painter->setPen(QColor(168, 168, 168, 180));
@@ -271,14 +270,22 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/)
         painter->setPen(QColor(108, 108, 108, 180));
         painter->drawLine(l2.translated(0, 1));
         painter->setPen(QColor(Qt::white));
+        painter->setRenderHint(QPainter::Antialiasing);
     }
 
     // draw keyframes
     QMap<int, int>::const_iterator i = m_keyframes.constBegin();
     QColor color(Qt::blue);
-    x1 = br.x() + maxw * (i.key() - cropStart().frames(m_fps));
-    y1 = br.bottom() - i.value() * maxh;
     QLineF l2;
+    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) {
+        QLineF l(br.x(), y1, x1, y1);
+        l2 = painter->matrix().map(l);
+        painter->drawLine(l2);
+    }
     while (i != m_keyframes.constEnd()) {
         if (i.key() == m_editedKeyframe)
             color = QColor(Qt::red);
@@ -292,8 +299,8 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/)
             x2 = br.right();
             y2 = y1;
         } else {
-            x2 = br.x() + maxw * (i.key() - cropStart().frames(m_fps));
-            y2 = br.bottom() - i.value() * maxh;
+            x2 = br.x() + maxw * (i.key() - start);
+            y2 = br.bottom() - (i.value() - m_keyframeOffset) * maxh;
         }
         QLineF l(x1, y1, x2, y2);
         l2 = painter->matrix().map(l);
@@ -305,10 +312,19 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/)
         x1 = x2;
         y1 = y2;
     }
-    if (active) {
+
+    // make sure line ends at clip end
+    if (x1 != br.right()) {
+        QLineF l(x1, y1, br.right(), y1);
+        painter->drawLine(painter->matrix().map(l));
+    }
+
+    if (active && m_keyframes.count() > 1) {
         const QRectF frame(l2.x2() - 3, l2.y2() - 3, 6, 6);
         painter->fillRect(frame, color);
     }
+
+    painter->setRenderHint(QPainter::Antialiasing, antialiasing);
 }
 
 int AbstractClipItem::mouseOverKeyFrames(QPointF pos, double maxOffset)
@@ -322,9 +338,9 @@ int AbstractClipItem::mouseOverKeyFrames(QPointF pos, double maxOffset)
         double y1;
         while (i != m_keyframes.constEnd()) {
             x1 = br.x() + maxw * (i.key() - cropStart().frames(m_fps));
-            y1 = br.bottom() - i.value() * maxh;
+            y1 = br.bottom() - (i.value() - m_keyframeOffset) * maxh;
             if (qAbs(pos.x() - x1) < maxOffset && qAbs(pos.y() - y1) < 10) {
-                setToolTip('[' + QString::number((GenTime(i.key(), m_fps) - cropStart()).seconds(), 'f', 2) + i18n("seconds") + ", " + QString::number(i.value(), 'f', 1) + "%]");
+                setToolTip('[' + QString::number((GenTime(i.key(), m_fps) - cropStart()).seconds(), 'f', 2) + i18n("seconds") + ", " + QString::number(i.value(), 'f', 1) + "]");
                 return i.key();
             } else if (x1 > pos.x()) {
                 break;
@@ -343,9 +359,9 @@ void AbstractClipItem::updateSelectedKeyFrame()
     QRectF br = sceneBoundingRect();
     double maxw = br.width() / cropDuration().frames(m_fps);
     double maxh = br.height() / 100.0 * m_keyframeFactor;
-    update(br.x() + maxw *(m_selectedKeyframe - cropStart().frames(m_fps)) - 3, br.bottom() - m_keyframes[m_selectedKeyframe] * maxh - 3, 12, 12);
+    update(br.x() + maxw *(m_selectedKeyframe - cropStart().frames(m_fps)) - 3, br.bottom() - (m_keyframes.value(m_selectedKeyframe) - m_keyframeOffset) * maxh - 3, 12, 12);
     m_selectedKeyframe = m_editedKeyframe;
-    update(br.x() + maxw *(m_selectedKeyframe - cropStart().frames(m_fps)) - 3, br.bottom() - m_keyframes[m_selectedKeyframe] * maxh - 3, 12, 12);
+    update(br.x() + maxw *(m_selectedKeyframe - cropStart().frames(m_fps)) - 3, br.bottom() - (m_keyframes.value(m_selectedKeyframe) - m_keyframeOffset) * maxh - 3, 12, 12);
 }
 
 int AbstractClipItem::editedKeyFramePos() const
@@ -392,7 +408,7 @@ void AbstractClipItem::updateKeyFramePos(const GenTime pos, const double value)
 
     double newval = qMax(value, 0.0);
     newval = qMin(newval, 100.0);
-    newval = newval / m_keyframeFactor;
+    newval = newval / m_keyframeFactor + m_keyframeOffset;
     if (m_editedKeyframe != newpos)
         m_keyframes.remove(m_editedKeyframe);
     m_keyframes[newpos] = (int) newval;
@@ -405,11 +421,16 @@ double AbstractClipItem::keyFrameFactor() const
     return m_keyframeFactor;
 }
 
+int AbstractClipItem::keyFrameNumber() const
+{
+    return m_keyframes.count();
+}
+
 int AbstractClipItem::addKeyFrame(const GenTime pos, const double value)
 {
     QRectF br = sceneBoundingRect();
     double maxh = 100.0 / br.height() / m_keyframeFactor;
-    int newval = (br.bottom() - value) * maxh;
+    int newval = (br.bottom() - value) * maxh + m_keyframeOffset;
     //kDebug() << "Rect: " << br << "/ SCENE: " << sceneBoundingRect() << ", VALUE: " << value << ", MAX: " << maxh << ", NEWVAL: " << newval;
     int newpos = (int) pos.frames(m_fps) ;
     m_keyframes[newpos] = newval;