]> git.sesse.net Git - kdenlive/commitdiff
Fixes to clip fades
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 26 Jan 2008 15:03:39 +0000 (15:03 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 26 Jan 2008 15:03:39 +0000 (15:03 +0000)
svn path=/branches/KDE4/; revision=1823

src/clipitem.cpp
src/clipitem.h
src/customtrackview.cpp
src/trackview.cpp

index da4a72f0b28dba323ced9dabb2878e28fddf012a..d8e0c59f87ee1e41719d2784d8813a74cd34b144 100644 (file)
@@ -34,7 +34,7 @@
 #include "kdenlivesettings.h"
 
 ClipItem::ClipItem(QDomElement xml, int track, int startpos, const QRectF & rect, int duration)
-    : QGraphicsRectItem(rect), m_xml(xml), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_track(track), m_startPos(startpos), m_thumbProd(NULL), startThumbTimer(NULL), endThumbTimer(NULL)
+    : QGraphicsRectItem(rect), m_xml(xml), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_track(track), m_startPos(startpos), m_thumbProd(NULL), startThumbTimer(NULL), endThumbTimer(NULL), m_startFade(0), m_endFade(0)
 {
   //setToolTip(name);
 
@@ -198,6 +198,40 @@ int ClipItem::endPos()
       QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
       painter->drawLine(l2);
     }
+
+    // draw start / end fades
+    double scale = br.width() / m_cropDuration;
+    QBrush fades;
+    if (isSelected()) {
+      fades = QBrush(QColor(200, 50, 50, 150));
+    }
+    else fades = QBrush(QColor(200, 200, 200, 150));
+
+    if (m_startFade != 0) {
+      QPainterPath fadeInPath;
+      fadeInPath.moveTo(br.x() - offset, br.y());
+      fadeInPath.lineTo(br.x() - offset, br.y() + br.height());
+      fadeInPath.lineTo(br.x() + m_startFade * scale, br.y());
+      fadeInPath.closeSubpath();
+      painter->fillPath(fadeInPath, fades);
+      if (isSelected()) {
+       QLineF l(br.x() + m_startFade * scale, br.y(), br.x(), br.y() + br.height());
+       painter->drawLine(l);
+      }
+    }
+    if (m_endFade != 0) {
+      QPainterPath fadeOutPath;
+      fadeOutPath.moveTo(br.x() + br.width(), br.y());
+      fadeOutPath.lineTo(br.x() + br.width(), br.y() + br.height());
+      fadeOutPath.lineTo(br.x() + br.width() - m_endFade * scale, br.y());
+      fadeOutPath.closeSubpath();
+      painter->fillPath(fadeOutPath, fades);
+      if (isSelected()) {
+       QLineF l(br.x() + br.width() - m_endFade * scale, br.y(), br.x() + br.width(), br.y() + br.height());
+       painter->drawLine(l);
+      }
+    }
+
     painter->setClipRect(option->exposedRect);
     QPen pen = painter->pen();
     pen.setColor(Qt::red);
@@ -231,28 +265,55 @@ int ClipItem::endPos()
  }
 
 
-OPERATIONTYPE ClipItem::operationMode(QPointF pos)
+OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale)
 {
-    if (abs(pos.x() - rect().x()) < 6) {
-      if (abs(pos.y() - rect().y()) < 6) return FADEIN;
-      return RESIZESTART;
-    }
-    else if (abs(pos.x() - (rect().x() + rect().width())) < 6) {
-      if (abs(pos.y() - rect().y()) < 6) return FADEOUT;
-      return RESIZEEND;
-    }
+    if (abs(pos.x() - (rect().x() + scale * m_startFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEIN;
+    else if (abs(pos.x() - rect().x()) < 6) return RESIZESTART;
+    else if (abs(pos.x() - (rect().x() + rect().width() - scale * m_endFade)) < 6 && abs(pos.y() - rect().y()) < 6) return FADEOUT;
+    else if (abs(pos.x() - (rect().x() + rect().width())) < 6) return RESIZEEND;
     return MOVE;
 }
 
+int ClipItem::fadeIn() const
+{
+  return m_startFade;
+}
+
+int ClipItem::fadeOut() const
+{
+  return m_endFade;
+}
+
+void ClipItem::setFadeIn(int pos, double scale)
+{
+  int oldIn = m_startFade;
+  if (pos < 0) pos = 0;
+  if (pos > m_cropDuration) pos = m_cropDuration / 2;
+  m_startFade = pos;
+  if (oldIn > pos) update(rect().x(), rect().y(), oldIn * scale, rect().height()); 
+  else update(rect().x(), rect().y(), pos * scale, rect().height());
+}
+
+void ClipItem::setFadeOut(int pos, double scale)
+{
+  int oldOut = m_endFade;
+  if (pos < 0) pos = 0;
+  if (pos > m_cropDuration) pos = m_cropDuration / 2;
+  m_endFade = pos;
+  if (oldOut > pos) update(rect().x() + rect().width() - pos * scale, rect().y(), pos * scale, rect().height()); 
+  else update(rect().x() + rect().width() - oldOut * scale, rect().y(), oldOut * scale, rect().height());
+
+}
+
 
 // virtual
  void ClipItem::mousePressEvent ( QGraphicsSceneMouseEvent * event ) 
  {
-    m_resizeMode = operationMode(event->pos());
+    /*m_resizeMode = operationMode(event->pos());
     if (m_resizeMode == MOVE) {
       m_maxTrack = scene()->sceneRect().height();
       m_grabPoint = (int) (event->pos().x() - rect().x());
-    }
+    }*/
     QGraphicsRectItem::mousePressEvent(event);
  }
 
index ce44a7eec275b606c65061a5988d72b830824fce..098ad574383642cb44639851d88043be5ab9dfd8 100644 (file)
@@ -43,7 +43,7 @@ class ClipItem : public QObject, public QGraphicsRectItem
     void moveTo(int x, double scale, double offset, int newTrack);
     void resizeStart(int posx, double scale);
     void resizeEnd(int posx, double scale);
-    OPERATIONTYPE operationMode(QPointF pos);
+    OPERATIONTYPE operationMode(QPointF pos, double scale);
     int clipProducer();
     int clipType();
     QString clipName();
@@ -54,6 +54,10 @@ class ClipItem : public QObject, public QGraphicsRectItem
     int endPos();
     int duration();
     QDomElement xml() const;
+    int fadeIn() const;
+    int fadeOut() const;
+    void setFadeOut(int pos, double scale);
+    void setFadeIn(int pos, double scale);
 
   protected:
     virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
@@ -79,6 +83,8 @@ class ClipItem : public QObject, public QGraphicsRectItem
     KThumb *m_thumbProd;
     QTimer *startThumbTimer;
     QTimer *endThumbTimer;
+    uint m_startFade;
+    uint m_endFade;
 
   private slots:
     void slotThumbReady(int frame, QPixmap pix);
index 8ab4773cae7f7e2cbf3959b7acc17ba6b335f825..ae047716e3088900f551a109188665a3da82e635 100644 (file)
@@ -111,6 +111,15 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
          int pos = mapToScene(event->pos()).x();
          m_dragItem->resizeEnd(pos / m_scale, m_scale);
        }
+       else if (m_operationMode == FADEIN) {
+         int pos = mapToScene(event->pos()).x() / m_scale;
+         m_dragItem->setFadeIn(pos - m_dragItem->startPos(), m_scale);
+       }
+       else if (m_operationMode == FADEOUT) {
+         int pos = mapToScene(event->pos()).x() / m_scale;
+         m_dragItem->setFadeOut(m_dragItem->endPos() - pos, m_scale);
+       }
+
        if (m_animation) delete m_animation;
        m_animation = NULL;
        if (m_visualTip) delete m_visualTip;
@@ -131,7 +140,7 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
     if (item) {
       ClipItem *clip = (ClipItem*) item;
       double size = mapToScene(QPoint(8, 0)).x();
-      OPERATIONTYPE opMode = clip->operationMode(mapToScene(event->pos()));
+      OPERATIONTYPE opMode = clip->operationMode(mapToScene(event->pos()), m_scale);
       if (opMode == m_moveOpMode) {
        QGraphicsView::mouseMoveEvent(event);
        return;
@@ -193,7 +202,7 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
       }
       else if (opMode == FADEIN) {
        if (m_visualTip == NULL) {
-         m_visualTip = new QGraphicsEllipseItem(clip->rect().x() - size, clip->rect().y() - 8, size * 2, 16);
+         m_visualTip = new QGraphicsEllipseItem(clip->rect().x() + clip->fadeIn() * m_scale - size, clip->rect().y() - 8, size * 2, 16);
          ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
          ((QGraphicsEllipseItem*) m_visualTip)->setPen(QPen(Qt::transparent));
          m_visualTip->setZValue (100);
@@ -203,7 +212,7 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
          m_visualTip->setPos(0, 0);
          double scale = 2.0;
          m_animation->setScaleAt(.5, scale, scale);
-         m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale, clip->rect().y() - clip->rect().y() * scale));
+         m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale -  clip->fadeIn() * m_scale, clip->rect().y() - clip->rect().y() * scale));
          scale = 1.0;
          m_animation->setScaleAt(1, scale, scale);
          m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, clip->rect().y() - clip->rect().y() * scale));
@@ -214,7 +223,7 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
       }
       else if (opMode == FADEOUT) {
        if (m_visualTip == NULL) {
-         m_visualTip = new QGraphicsEllipseItem(clip->rect().x() + clip->rect().width() - size, clip->rect().y() - 8, size*2, 16);
+         m_visualTip = new QGraphicsEllipseItem(clip->rect().x() + clip->rect().width() - clip->fadeOut() * m_scale - size, clip->rect().y() - 8, size*2, 16);
          ((QGraphicsEllipseItem*) m_visualTip)->setBrush(m_tipColor);
          ((QGraphicsEllipseItem*) m_visualTip)->setPen(QPen(Qt::transparent));
          m_visualTip->setZValue (100);
@@ -224,7 +233,7 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
          m_visualTip->setPos(0, 0);
          double scale = 2.0;
          m_animation->setScaleAt(.5, scale, scale);      
-         m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->rect().width(), clip->rect().y() - clip->rect().y() * scale));
+         m_animation->setPosAt(.5, QPointF(clip->rect().x() - clip->rect().x() * scale - clip->rect().width() + clip->fadeOut() * m_scale, clip->rect().y() - clip->rect().y() * scale));
          scale = 1.0;
          m_animation->setScaleAt(1, scale, scale);
          m_animation->setPosAt(1, QPointF(clip->rect().x() - clip->rect().x() * scale, clip->rect().y() - clip->rect().y() * scale));
@@ -264,7 +273,7 @@ void CustomTrackView::mousePressEvent ( QMouseEvent * event )
       if (item->type() == 70000) {
        m_dragItem = (ClipItem *) item;
        m_clickPoint = mapToScene(event->pos()).x() - m_dragItem->startPos() * m_scale;
-       m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())));
+       m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale);
        if (m_operationMode == MOVE || m_operationMode == RESIZESTART) m_startPos = QPointF(m_dragItem->startPos(), m_dragItem->track());
        else if (m_operationMode == RESIZEEND) m_startPos = QPointF(m_dragItem->endPos(), m_dragItem->track());
        kDebug()<<"//////// ITEM CLICKED: "<<m_startPos;
@@ -409,6 +418,7 @@ void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
     ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->endPos(), m_dragItem->track()), false, false);
     m_commandStack->push(command);
   }
+  m_operationMode = NONE;
   m_dragItem = NULL; 
 }
 
index 9a5e0984e687399c43d13a60774daac72c323d0c..54c78caf75d8f042372be2f0b74b2c511a086ce2 100644 (file)
@@ -71,7 +71,7 @@ TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
   connect(m_trackview, SIGNAL(zoomOut ()), this, SLOT(slotZoomOut()));
   connect(m_trackview->horizontalScrollBar(), SIGNAL(sliderMoved( int )), m_ruler, SLOT(slotMoveRuler( int )));
 
-  view->horizontalSlider->setValue(0);
+  view->horizontalSlider->setValue(4);
   m_currentZoom = view->horizontalSlider->value();
   m_trackview->initView();
 }