]> git.sesse.net Git - kdenlive/blobdiff - src/abstractclipitem.cpp
improve keyframe grabbing in timeline
[kdenlive] / src / abstractclipitem.cpp
index 32c2d3c9459bee8b8161916cdc9a88fd3ab72ec2..90b0c8fcfaec532e5a3cbbd4920b35399c60056f 100644 (file)
@@ -142,7 +142,7 @@ void AbstractClipItem::resizeStart(int posx, double speed)
         }*/
 }
 
-void AbstractClipItem::resizeEnd(int posx, double speed, bool /*updateKeyFrames*/)
+void AbstractClipItem::resizeEnd(int posx, double speed)
 {
     GenTime durationDiff = GenTime(posx, m_fps) - endPos();
     if (durationDiff == GenTime()) return;
@@ -245,9 +245,9 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/)
     }
 }
 
-int AbstractClipItem::mouseOverKeyFrames(QPointF pos)
+int AbstractClipItem::mouseOverKeyFrames(QPointF pos, double maxOffset)
 {
-    QRectF br = sceneBoundingRect();
+    const QRectF br = sceneBoundingRect();
     double maxw = br.width() / cropDuration().frames(m_fps);
     double maxh = br.height() / 100.0 * m_keyframeFactor;
     if (m_keyframes.count() > 1) {
@@ -257,7 +257,7 @@ int AbstractClipItem::mouseOverKeyFrames(QPointF pos)
         while (i != m_keyframes.constEnd()) {
             x1 = br.x() + maxw * (i.key() - cropStart().frames(m_fps));
             y1 = br.bottom() - i.value() * maxh;
-            if (qAbs(pos.x() - x1) < 6 && qAbs(pos.y() - y1) < 6) {
+            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) + "%]");
                 return i.key();
             } else if (x1 > pos.x()) break;
@@ -294,7 +294,7 @@ void AbstractClipItem::updateKeyFramePos(const GenTime pos, const double value)
     if (!m_keyframes.contains(m_selectedKeyframe)) return;
     int newpos = (int) pos.frames(m_fps);
     int start = cropStart().frames(m_fps);
-    int end = (cropStart() + cropDuration()).frames(m_fps);
+    int end = (cropStart() + cropDuration()).frames(m_fps) - 1;
     newpos = qMax(newpos, start);
     newpos = qMin(newpos, end);
     if (value < -50 && m_selectedKeyframe != start && m_selectedKeyframe != end) {
@@ -330,7 +330,7 @@ void 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;
-    kDebug() << "Rect: " << br << "/ SCENE: " << sceneBoundingRect() << ", VALUE: " << value << ", MAX: " << maxh << ", NEWVAL: " << newval;
+    //kDebug() << "Rect: " << br << "/ SCENE: " << sceneBoundingRect() << ", VALUE: " << value << ", MAX: " << maxh << ", NEWVAL: " << newval;
     int newpos = (int) pos.frames(m_fps) ;
     m_keyframes[newpos] = newval;
     m_selectedKeyframe = newpos;