]> git.sesse.net Git - kdenlive/blobdiff - src/clipitem.cpp
clips now respect maximum length
[kdenlive] / src / clipitem.cpp
index 68691aa8497a440621f31e6b1084107347c2ea91..ef36bd3ea862f59621ecf0b24e60a061924f42d9 100644 (file)
 
 #include "clipitem.h"
 
-ClipItem::ClipItem(int clipType, QString name, int producer, const QRectF & rect)
-    : QGraphicsRectItem(rect), m_resizeMode(0), m_grabPoint(0), m_producer(producer)
+ClipItem::ClipItem(int clipType, QString name, int producer, int maxDuration, const QRectF & rect)
+    : QGraphicsRectItem(rect), m_resizeMode(0), m_grabPoint(0), m_clipType(clipType), m_clipName(name), m_producer(producer), m_cropStart(0), m_cropDuration(maxDuration), m_maxDuration(maxDuration)
 {
   setToolTip(name);
   //setCursor(Qt::SizeHorCursor);
   setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemClipsChildrenToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
-  //producer = "sjis isjisjsi sij ssao sa sao ";
   m_label = new LabelItem( name, this);
   QRectF textRect = m_label->boundingRect();
   m_textWidth = textRect.width();
@@ -45,6 +44,26 @@ int ClipItem::type () const
   return 70000;
 }
 
+int ClipItem::clipType()
+{
+  return m_clipType;
+}
+
+QString ClipItem::clipName()
+{
+  return m_clipName;
+}
+
+int ClipItem::clipProducer()
+{
+  return m_producer;
+}
+
+int ClipItem::maxDuration()
+{
+  return m_maxDuration;
+}
+
 // virtual 
  void ClipItem::paint(QPainter *painter,
                            const QStyleOptionGraphicsItem *option,
@@ -130,7 +149,10 @@ int ClipItem::operationMode(QPointF pos)
     double originalX = rect().x();
     double originalWidth = rect().width();
     if (m_resizeMode == 1) {
-      kDebug()<<"MOVE CLIP START TO: "<<event->scenePos();
+      if (m_cropStart - (originalX - moveX) < 0) moveX = originalX - m_cropStart;
+      if (originalX + rect().width() - moveX < 1) moveX = originalX + rect().width() + 2;
+      m_cropStart -= originalX - moveX;
+      kDebug()<<"MOVE CLIP START TO: "<<event->scenePos()<<", CROP: "<<m_cropStart;
       setRect(moveX, rect().y(), originalX + rect().width() - moveX, rect().height());
       QList <QGraphicsItem *> childrenList = children();
       for (int i = 0; i < childrenList.size(); ++i) {
@@ -139,10 +161,13 @@ int ClipItem::operationMode(QPointF pos)
       return;
     }
     if (m_resizeMode == 2) {
-      setRect(originalX, rect().y(), moveX - originalX, rect().height());
+      int newWidth = moveX - originalX;
+      if (newWidth < 1) newWidth = 2;
+      if (newWidth > m_maxDuration) newWidth = m_maxDuration;
+      setRect(originalX, rect().y(), newWidth, rect().height());
       QList <QGraphicsItem *> childrenList = children();
       for (int i = 0; i < childrenList.size(); ++i) {
-       childrenList.at(i)->moveBy((moveX - originalX - originalWidth) / 2 , 0);
+       childrenList.at(i)->moveBy((newWidth - originalWidth) / 2 , 0);
       }
       return;
     }