]> git.sesse.net Git - kdenlive/blobdiff - src/abstractclipitem.cpp
Fix display of font / outline color in buttons
[kdenlive] / src / abstractclipitem.cpp
index 584ffab2bd3cddf925245ba95663e8188a7974d0..6584428fb56d3526ae3f44886226740092981904 100644 (file)
 AbstractClipItem::AbstractClipItem(const ItemInfo info, const QRectF& rect, double fps) :
         QObject(),
         QGraphicsRectItem(rect),
-       m_info(info),
+        m_info(info),
         m_editedKeyframe(-1),
         m_selectedKeyframe(0),
         m_keyframeFactor(1),
         m_fps(fps)
+#if QT_VERSION >= 0x040600
+        , m_closeAnimation(NULL)
+#endif
 {
     setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+#if QT_VERSION >= 0x040600
+    setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
+#endif
+}
+
+AbstractClipItem::~AbstractClipItem()
+{
+#if QT_VERSION >= 0x040600
+    if (m_closeAnimation) delete m_closeAnimation;
+#endif
+}
+
+void AbstractClipItem::closeAnimation()
+{
+#if QT_VERSION >= 0x040600
+    if (m_closeAnimation) return;
+    setEnabled(false);
+    m_closeAnimation = new QPropertyAnimation(this, "rect");
+    connect(m_closeAnimation, SIGNAL(finished()), this, SLOT(deleteLater()));
+    m_closeAnimation->setDuration(200);
+    QRectF r = rect();
+    QRectF r2 = r;
+    r2.setLeft(r.left() + r.width() / 2);
+    r2.setTop(r.top() + r.height() / 2);
+    r2.setWidth(1);
+    r2.setHeight(1);
+    m_closeAnimation->setStartValue(r);
+    m_closeAnimation->setEndValue(r2);
+    m_closeAnimation->setEasingCurve(QEasingCurve::InQuad);
+    m_closeAnimation->start();
+#endif
 }
 
 ItemInfo AbstractClipItem::info() const
@@ -49,6 +83,11 @@ ItemInfo AbstractClipItem::info() const
     return info;
 }
 
+int AbstractClipItem::defaultZValue() const
+{
+    return 2;
+}
+
 GenTime AbstractClipItem::endPos() const
 {
     return m_info.startPos + m_info.cropDuration;
@@ -85,7 +124,7 @@ void AbstractClipItem::updateRectGeometry()
     setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
 }
 
-void AbstractClipItem::resizeStart(int posx, double speed)
+void AbstractClipItem::resizeStart(int posx)
 {
     GenTime durationDiff = GenTime(posx, m_fps) - m_info.startPos;
     if (durationDiff == GenTime()) return;
@@ -100,26 +139,23 @@ void AbstractClipItem::resizeStart(int posx, double speed)
     }
     //kDebug()<<"// DURATION DIFF: "<<durationDiff.frames(25)<<", POS: "<<pos().x();
     m_info.startPos += durationDiff;
-    GenTime originalDiff = GenTime((int) (durationDiff.frames(m_fps) * speed + 0.5), m_fps); 
-    
+
     if (type() == AVWIDGET) {
-       m_info.cropStart += durationDiff;
-       m_info.originalcropStart += originalDiff;
+        m_info.cropStart += durationDiff;
     }
-    m_info.cropDuration = m_info.cropDuration - originalDiff;
 
+    m_info.cropDuration = m_info.cropDuration - durationDiff;
     setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
     moveBy(durationDiff.frames(m_fps), 0);
-    //setPos(m_startPos.frames(m_fps), pos().y());
-    if ((int) scenePos().x() != posx) {
+
+    if (m_info.startPos != GenTime(posx, m_fps)) {
         //kDebug()<<"//////  WARNING, DIFF IN XPOS: "<<pos().x()<<" == "<<m_startPos.frames(m_fps);
-        GenTime diff = GenTime((int) pos().x() - posx, m_fps);
-       GenTime originalDiff = GenTime((int) (diff.frames(m_fps) * speed + 0.5), m_fps); 
+        GenTime diff = m_info.startPos - GenTime((int) posx, m_fps);
+
         if (type() == AVWIDGET) {
-           m_info.cropStart += diff;
-           m_info.originalcropStart += originalDiff;
-       }
-        m_info.cropDuration = m_info.cropDuration - originalDiff;
+            m_info.cropStart += diff;
+        }
+        m_info.cropDuration = m_info.cropDuration - diff;
         setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
         //kDebug()<<"// NEW START: "<<m_startPos.frames(25)<<", NW DUR: "<<m_cropDuration.frames(25);
     }
@@ -146,27 +182,28 @@ void AbstractClipItem::resizeStart(int posx, double speed)
         }*/
 }
 
-void AbstractClipItem::resizeEnd(int posx, double speed)
+void AbstractClipItem::resizeEnd(int posx)
 {
     GenTime durationDiff = GenTime(posx, m_fps) - endPos();
     if (durationDiff == GenTime()) return;
-    //kDebug() << "// DUR DIFF1:" << durationDiff.frames(25) << ", ADJUSTED: " << durationDiff.frames(25) * speed << ", SPED:" << speed;
     if (cropDuration() + durationDiff <= GenTime()) {
         durationDiff = GenTime() - (cropDuration() - GenTime(3, m_fps));
     }
-    //kDebug() << "// DUR DIFF2:" << durationDiff.frames(25) << ", ADJUSTED: " << durationDiff.frames(25) * speed << ", SPED:" << speed;
-    m_info.cropDuration += GenTime((int) (durationDiff.frames(m_fps) * speed + 0.5), m_fps);
+
+    m_info.cropDuration += durationDiff;
+
     setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
     if (durationDiff > GenTime()) {
         QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
         for (int i = 0; i < collisionList.size(); ++i) {
+            if (!collisionList.at(i)->isEnabled()) continue;
             QGraphicsItem *item = collisionList.at(i);
             if (item->type() == type() && item->pos().x() > pos().x()) {
-                /*kDebug() << "/////////  COLLISION DETECTED!!!!!!!!!";
+                kDebug() << "/////////  COLLISION DETECTED!!!!!!!!!";
                 kDebug() << "/////////  CURRENT: " << startPos().frames(25) << "x" << endPos().frames(25) << ", RECT: " << rect() << "-" << pos();
-                kDebug() << "/////////  COLLISION: " << ((AbstractClipItem *)item)->startPos().frames(25) << "x" << ((AbstractClipItem *)item)->endPos().frames(25) << ", RECT: " << ((AbstractClipItem *)item)->rect() << "-" << item->pos();*/
-                GenTime diff = ((AbstractClipItem *)item)->startPos() - GenTime(1, m_fps) - startPos();
-                m_info.cropDuration = GenTime((int) (diff.frames(m_fps) * speed + 0.5), m_fps);
+                kDebug() << "/////////  COLLISION: " << ((AbstractClipItem *)item)->startPos().frames(25) << "x" << ((AbstractClipItem *)item)->endPos().frames(25) << ", RECT: " << ((AbstractClipItem *)item)->rect() << "-" << item->pos();
+                GenTime diff = ((AbstractClipItem *)item)->startPos() - startPos();
+                m_info.cropDuration = diff;
                 setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
                 break;
             }
@@ -203,7 +240,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;
@@ -237,9 +274,16 @@ void AbstractClipItem::drawKeyFrames(QPainter *painter, QRectF /*exposedRect*/)
         if (i.key() == m_selectedKeyframe) 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);
@@ -261,7 +305,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;
@@ -297,7 +341,7 @@ int AbstractClipItem::selectedKeyFramePos() const
 
 double AbstractClipItem::selectedKeyFrameValue() const
 {
-    return m_keyframes[m_editedKeyframe];
+    return m_keyframes.value(m_editedKeyframe);
 }
 
 void AbstractClipItem::updateKeyFramePos(const GenTime pos, const double value)
@@ -328,6 +372,7 @@ void AbstractClipItem::updateKeyFramePos(const GenTime pos, const double value)
     if (m_selectedKeyframe != newpos) m_keyframes.remove(m_selectedKeyframe);
     m_keyframes[newpos] = (int) newval;
     m_selectedKeyframe = newpos;
+
     update();
 }
 
@@ -376,7 +421,10 @@ void AbstractClipItem::setItemLocked(bool locked)
         setSelected(false);
         setFlag(QGraphicsItem::ItemIsMovable, false);
         setFlag(QGraphicsItem::ItemIsSelectable, false);
-    } else setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+    } else {
+        setFlag(QGraphicsItem::ItemIsMovable, true);
+        setFlag(QGraphicsItem::ItemIsSelectable, true);
+    }
 }
 
 bool AbstractClipItem::isItemLocked() const