]> git.sesse.net Git - kdenlive/commitdiff
Fix snapping to clip borders
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 8 Mar 2008 17:31:12 +0000 (17:31 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 8 Mar 2008 17:31:12 +0000 (17:31 +0000)
svn path=/branches/KDE4/; revision=2018

src/customtrackview.cpp
src/customtrackview.h

index 44a1737530a53bc3ac8ca016ce6efd71f0499c7e..8719fbf755d5b7b4f8b74ee3efe0a73c0b6b4b2b 100644 (file)
@@ -97,7 +97,6 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
             // a button was pressed, delete visual tips
             if (m_operationMode == MOVE) {
                 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint);
-                double moveX = snappedPos; //mapToScene(event->pos()).x();
                 //kDebug()<<"///////  MOVE CLIP, EVENTĀ Y: "<<event->scenePos().y()<<", SCENE HEIGHT: "<<scene()->sceneRect().height();
                 int moveTrack = (int)  mapToScene(event->pos()).y() / 50;
                 int currentTrack = m_dragItem->track();
@@ -107,13 +106,13 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
 
                 int offset = moveTrack - currentTrack;
                 if (offset != 0) offset = 50 * offset;
-                m_dragItem->moveTo(moveX / m_scale, m_scale, offset, moveTrack);
+                m_dragItem->moveTo(snappedPos / m_scale, m_scale, offset, moveTrack);
             } else if (m_operationMode == RESIZESTART) {
-                int pos = mapToScene(event->pos()).x();
-                m_dragItem->resizeStart(pos / m_scale, m_scale);
+                double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x());
+                m_dragItem->resizeStart(snappedPos / m_scale, m_scale);
             } else if (m_operationMode == RESIZEEND) {
-                int pos = mapToScene(event->pos()).x();
-                m_dragItem->resizeEnd(pos / m_scale, m_scale);
+                double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x());
+                m_dragItem->resizeEnd(snappedPos / m_scale, m_scale);
             } else if (m_operationMode == FADEIN) {
                 int pos = mapToScene(event->pos()).x() / m_scale;
                 m_dragItem->setFadeIn(pos - m_dragItem->startPos().frames(m_document->fps()), m_scale);
@@ -671,44 +670,36 @@ void CustomTrackView::resizeClip(const QPointF &startPos, const QPointF &endPos,
 
 double CustomTrackView::getSnapPointForPos(double pos) {
     for (int i = 0; i < m_snapPoints.size(); ++i) {
-        //kDebug()<<"SNAP POINT: "<<m_snapPoints.at(i);
-        if (abs(pos - m_snapPoints.at(i) * m_scale) < 6 * m_scale) {
+        if (abs(pos - m_snapPoints.at(i).frames(m_document->fps()) * m_scale) < 10) {
             //kDebug()<<" FOUNDĀ SNAP POINT AT: "<<m_snapPoints.at(i)<<", current pos: "<<pos / m_scale;
-            return m_snapPoints.at(i) * m_scale + 0.5;
+            return m_snapPoints.at(i).frames(m_document->fps()) * m_scale + 0.5;
         }
-        if (m_snapPoints.at(i) > pos) break;
+        if (m_snapPoints.at(i).frames(m_document->fps() * m_scale) > pos) break;
     }
     return pos;
 }
 
 void CustomTrackView::updateSnapPoints(ClipItem *selected) {
     m_snapPoints.clear();
-    int offset = 0;
-    if (selected) offset = selected->duration().frames(m_document->fps());
+    GenTime offset;
+    if (selected) offset = selected->duration();
     QList<QGraphicsItem *> itemList = items();
     for (int i = 0; i < itemList.count(); i++) {
         if (itemList.at(i)->type() == 70000 && itemList.at(i) != selected) {
             ClipItem *item = (ClipItem *)itemList.at(i);
-            int start = item->startPos().frames(m_document->fps());
-            int fadein = item->fadeIn() + start;
-            int end = item->endPos().frames(m_document->fps());
-            int fadeout = end - item->fadeOut();
+            GenTime start = item->startPos();
+            GenTime end = item->endPos();
             m_snapPoints.append(start);
-            if (fadein != start) m_snapPoints.append(fadein);
             m_snapPoints.append(end);
-            if (fadeout != end) m_snapPoints.append(fadeout);
-            if (offset != 0) {
-                m_snapPoints.append(start - offset);
-                if (fadein != start) m_snapPoints.append(fadein - offset);
-                m_snapPoints.append(end - offset);
-                if (fadeout != end) m_snapPoints.append(fadeout - offset);
+            if (offset != GenTime()) {
+                if (start > offset) m_snapPoints.append(start - offset);
+                if (end > offset) m_snapPoints.append(end - offset);
             }
         }
     }
-    kDebug() << " GOT SNAPPOINTS TOTAL: " << m_snapPoints.count();
     qSort(m_snapPoints);
-    for (int i = 0; i < m_snapPoints.size(); ++i)
-        kDebug() << "SNAP POINT: " << m_snapPoints.at(i);
+    //for (int i = 0; i < m_snapPoints.size(); ++i)
+    //    kDebug() << "SNAP POINT: " << m_snapPoints.at(i).frames(25);
 }
 
 
index ca4ad9d77286a1d14d44ae8443068b2da73d98c7..f8ddb10544911f380ef2e0fb28537f4c86af19b5 100644 (file)
@@ -94,7 +94,7 @@ private:
     QPen m_tipPen;
     double m_scale;
     int m_clickPoint;
-    QList <int> m_snapPoints;
+    QList <GenTime> m_snapPoints;
     void updateSnapPoints(ClipItem *selected);
     double getSnapPointForPos(double pos);
     ClipItem *getClipItemAt(int pos, int track);