]> git.sesse.net Git - kdenlive/blobdiff - src/abstractclipitem.cpp
cleanup
[kdenlive] / src / abstractclipitem.cpp
index 47905faad8b9e4728944d093d3d11cb797a5dc38..2583962247bbd59c935ec56dbffbfbf019e26442 100644 (file)
@@ -44,6 +44,7 @@ AbstractClipItem::AbstractClipItem(const ItemInfo info, const QRectF& rect, doub
     setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
 #if QT_VERSION >= 0x040600
     setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
+    setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
 #endif
 }
 
@@ -124,14 +125,15 @@ void AbstractClipItem::updateRectGeometry()
     setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
 }
 
-void AbstractClipItem::resizeStart(int posx)
+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 && cropStart() + durationDiff < GenTime()) {
-        durationDiff = GenTime() - cropStart();
+    if (type() == AVWIDGET) {
+        if (hasSizeLimit && cropStart() + durationDiff < GenTime())
+            durationDiff = GenTime() - cropStart();
     } else if (durationDiff >= cropDuration()) {
         return;
         if (cropDuration() > GenTime(3, m_fps)) durationDiff = GenTime(3, m_fps);
@@ -149,7 +151,6 @@ void AbstractClipItem::resizeStart(int posx)
     moveBy(durationDiff.frames(m_fps), 0);
 
     if (m_info.startPos != GenTime(posx, m_fps)) {
-        kDebug() << "__ RESIZE START OFFSET: ";
         //kDebug()<<"//////  WARNING, DIFF IN XPOS: "<<pos().x()<<" == "<<m_startPos.frames(m_fps);
         GenTime diff = m_info.startPos - GenTime((int) posx, m_fps);
 
@@ -241,7 +242,7 @@ GenTime AbstractClipItem::maxDuration() const
 
 void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/)
 {
-    if (m_keyframes.count() < 2) return;
+    if (m_keyframes.count() < 1) return;
     QRectF br = rect();
     double maxw = br.width() / cropDuration().frames(m_fps);
     double maxh = br.height() / 100.0 * m_keyframeFactor;
@@ -272,12 +273,19 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/)
     y1 = br.bottom() - i.value() * maxh;
     QLineF l2;
     while (i != m_keyframes.constEnd()) {
-        if (i.key() == m_selectedKeyframe) color = QColor(Qt::red);
+        if (i.key() == m_editedKeyframe) color = QColor(Qt::red);
         else color = QColor(Qt::blue);
         ++i;
-        if (i == m_keyframes.constEnd()) break;
-        x2 = br.x() + maxw * (i.key() - cropStart().frames(m_fps));
-        y2 = br.bottom() - i.value() * maxh;
+        if (i == m_keyframes.constEnd() && m_keyframes.count() != 1) {
+            break;
+        }
+        if (m_keyframes.count() == 1) {
+            x2 = br.right();
+            y2 = y1;
+        } else {
+            x2 = br.x() + maxw * (i.key() - cropStart().frames(m_fps));
+            y2 = br.bottom() - i.value() * maxh;
+        }
         QLineF l(x1, y1, x2, y2);
         l2 = painter->matrix().map(l);
         painter->drawLine(l2);
@@ -299,7 +307,7 @@ int AbstractClipItem::mouseOverKeyFrames(QPointF pos, double maxOffset)
     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) {
+    if (m_keyframes.count() > 0) {
         QMap<int, int>::const_iterator i = m_keyframes.constBegin();
         double x1;
         double y1;
@@ -328,44 +336,41 @@ void AbstractClipItem::updateSelectedKeyFrame()
     update(br.x() + maxw *(m_selectedKeyframe - cropStart().frames(m_fps)) - 3, br.bottom() - m_keyframes[m_selectedKeyframe] * maxh - 3, 12, 12);
 }
 
-int AbstractClipItem::selectedKeyFramePos() const
+int AbstractClipItem::editedKeyFramePos() const
 {
     return m_editedKeyframe;
 }
 
+double AbstractClipItem::editedKeyFrameValue() const
+{
+    return m_keyframes.value(m_editedKeyframe);
+}
+
+int AbstractClipItem::selectedKeyFramePos() const
+{
+    return m_selectedKeyframe;
+}
+
 double AbstractClipItem::selectedKeyFrameValue() const
 {
-    return m_keyframes[m_editedKeyframe];
+    return m_keyframes.value(m_selectedKeyframe);
 }
 
 void AbstractClipItem::updateKeyFramePos(const GenTime pos, const double value)
 {
-    if (!m_keyframes.contains(m_selectedKeyframe)) return;
+    if (!m_keyframes.contains(m_editedKeyframe)) return;
     int newpos = (int) pos.frames(m_fps);
     int start = cropStart().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) {
-        // remove kexframe if it is dragged outside
-        m_keyframes.remove(m_selectedKeyframe);
-        m_selectedKeyframe = -1;
-        update();
-        return;
-    }
-    if (value > 150 && m_selectedKeyframe != start && m_selectedKeyframe != end) {
-        // remove kexframe if it is dragged outside
-        m_keyframes.remove(m_selectedKeyframe);
-        m_selectedKeyframe = -1;
-        update();
-        return;
-    }
+
     double newval = qMax(value, 0.0);
     newval = qMin(newval, 100.0);
     newval = newval / m_keyframeFactor;
-    if (m_selectedKeyframe != newpos) m_keyframes.remove(m_selectedKeyframe);
+    if (m_editedKeyframe != newpos) m_keyframes.remove(m_editedKeyframe);
     m_keyframes[newpos] = (int) newval;
-    m_selectedKeyframe = newpos;
+    m_editedKeyframe = newpos;
     update();
 }
 
@@ -374,7 +379,7 @@ double AbstractClipItem::keyFrameFactor() const
     return m_keyframeFactor;
 }
 
-void AbstractClipItem::addKeyFrame(const GenTime pos, const double value)
+int AbstractClipItem::addKeyFrame(const GenTime pos, const double value)
 {
     QRectF br = sceneBoundingRect();
     double maxh = 100.0 / br.height() / m_keyframeFactor;
@@ -384,6 +389,7 @@ void AbstractClipItem::addKeyFrame(const GenTime pos, const double value)
     m_keyframes[newpos] = newval;
     m_selectedKeyframe = newpos;
     update();
+    return newval;
 }
 
 bool AbstractClipItem::hasKeyFrames() const