]> git.sesse.net Git - kdenlive/commitdiff
smoother scaling
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 8 Mar 2008 17:00:37 +0000 (17:00 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 8 Mar 2008 17:00:37 +0000 (17:00 +0000)
svn path=/branches/KDE4/; revision=2017

src/customruler.cpp
src/customtrackview.cpp
src/customtrackview.h
src/trackview.cpp

index 12a0c06530fe039710537f23edb30589c2049e68..866e54e88af04aaa5facef2380f5cc1eff874745 100644 (file)
@@ -89,13 +89,13 @@ CustomRuler::CustomRuler(Timecode tc, CustomTrackView *parent)
 // virtual
 void CustomRuler::mousePressEvent(QMouseEvent * event) {
     int pos = (event->x() + offset());
-    m_view->setCursorPos(pos);
+    m_view->setCursorPos(pos / pixelPerMark() / FRAME_SIZE);
 }
 
 // virtual
 void CustomRuler::mouseMoveEvent(QMouseEvent * event) {
     int pos = (event->x() + offset());
-    m_view->setCursorPos(pos);
+    m_view->setCursorPos(pos / pixelPerMark() / FRAME_SIZE);
 }
 
 void CustomRuler::slotMoveRuler(int newPos) {
index 5ca28d0da6b521b4e00e530ae6e854ae30319bcd..44a1737530a53bc3ac8ca016ce6efd71f0499c7e 100644 (file)
@@ -292,7 +292,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
         } else {
             m_moveOpMode = NONE;
             if (event->buttons() != Qt::NoButton) {
-                setCursorPos((int) mapToScene(event->pos().x(), 0).x());
+                setCursorPos((int) mapToScene(event->pos().x(), 0).x() / m_scale);
             }
             if (m_visualTip) {
                 if (m_animation) delete m_animation;
@@ -358,7 +358,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) {
             for (int i = 0; i < itemList.count(); i++)
                 itemList.at(i)->setSelected(false);
             emit clipItemSelected(NULL);
-            setCursorPos((int) mapToScene(event->x(), 0).x());
+            setCursorPos((int) mapToScene(event->x(), 0).x() / m_scale);
         }
     }
     updateSnapPoints(m_dragItem);
@@ -554,16 +554,19 @@ void CustomTrackView::deleteClip(int clipId) {
 }
 
 void CustomTrackView::setCursorPos(int pos, bool seek) {
-    emit cursorMoved(m_cursorPos, pos);
+    emit cursorMoved(m_cursorPos * m_scale, pos * m_scale);
     m_cursorPos = pos;
-    m_cursorLine->setPos(pos, 0);
-    int frame =  pos / m_scale;
-    if (seek) m_document->renderer()->seek(GenTime(frame, m_document->fps()));
+    m_cursorLine->setPos(pos * m_scale, 0);
+    if (seek) m_document->renderer()->seek(GenTime(pos, m_document->fps()));
     else if (m_autoScroll && m_scale < 50) checkScrolling();
 }
 
+void CustomTrackView::updateCursorPos() {
+    m_cursorLine->setPos(m_cursorPos * m_scale, 0);
+}
+
 int CustomTrackView::cursorPos() {
-    return m_cursorPos;
+    return m_cursorPos * m_scale;
 }
 
 void CustomTrackView::checkScrolling() {
@@ -571,7 +574,7 @@ void CustomTrackView::checkScrolling() {
     int delta = rectInView.width() / 3;
     int max = rectInView.right() + horizontalScrollBar()->value() - delta;
     //kDebug() << "CURSOR POS: "<<m_cursorPos<< "Scale: "<<m_scale;
-    if (m_cursorPos >= max) horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 1 + m_scale);
+    if (m_cursorPos * m_scale >= max) horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 1 + m_scale);
 }
 
 void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
@@ -711,25 +714,20 @@ void CustomTrackView::updateSnapPoints(ClipItem *selected) {
 
 void CustomTrackView::setScale(double scaleFactor) {
     //scale(scaleFactor, scaleFactor);
+    double pos = cursorPos() / m_scale;
     m_scale = scaleFactor;
     kDebug() << " HHHHHHHH  SCALING: " << m_scale;
     QList<QGraphicsItem *> itemList = items();
-    scene()->setSceneRect(0, 0, (m_projectDuration + 500) * m_scale, scene()->sceneRect().height()); //50 *
 
     for (int i = 0; i < itemList.count(); i++) {
         if (itemList.at(i)->type() == 70000) {
             ClipItem *clip = (ClipItem *)itemList.at(i);
             clip->setRect(clip->startPos().frames(m_document->fps()) * m_scale, clip->rect().y(), clip->duration().frames(m_document->fps()) * m_scale, clip->rect().height());
         }
-        /*else if (itemList.at(i)->type() == 70001) {
-        LabelItem *label = (LabelItem *)itemList.at(i);
-        QGraphicsItem *parent = label->parentItem();
-        QRectF r = label->boundingRect();
-        QRectF p = parent->boundingRect();
-        label->setPos(p.x() + p.width() / 2 - r.width() / 2, p.y() + p.height() / 2 - r.height() / 2);
-        //label->setRect(clip->startPos() * m_scale, clip->rect().y(), clip->duration() * m_scale, clip->rect().height());
-        }*/
     }
+    updateCursorPos();
+    centerOn(QPointF(cursorPos(), 50));
+    scene()->setSceneRect(0, 0, (m_projectDuration + 500) * m_scale, scene()->sceneRect().height());
 }
 
 void CustomTrackView::drawBackground(QPainter * painter, const QRectF & rect) {
index d3f8b618acfcce3e5d89d5f3f83ef6ce37f0376f..ca4ad9d77286a1d14d44ae8443068b2da73d98c7 100644 (file)
@@ -55,6 +55,7 @@ public:
 
 public slots:
     void setCursorPos(int pos, bool seek = true);
+    void updateCursorPos();
     void slotDeleteEffect(ClipItem *clip, QDomElement effect);
     void slotChangeEffectState(ClipItem *clip, QDomElement effect, bool disable);
     void slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect);
index bbf2c464052a28ad07fd3df16eee1903a1f76ed2..170d759861dca1d9cdcaf87dd657f01ba72b8f62 100644 (file)
@@ -116,21 +116,19 @@ void TrackView::slotDeleteClip(int clipId) {
 }
 
 void TrackView::setCursorPos(int pos) {
-    m_trackview->setCursorPos(pos * m_scale);
+    m_trackview->setCursorPos(pos);
 }
 
 void TrackView::moveCursorPos(int pos) {
-    m_trackview->setCursorPos(pos * m_scale, false);
+    m_trackview->setCursorPos(pos, false);
 }
 
 void TrackView::slotChangeZoom(int factor) {
-    double pos = m_trackview->cursorPos() / m_scale;
+
     m_ruler->setPixelPerMark(factor);
     m_scale = (double) FRAME_SIZE / m_ruler->comboScale[factor]; // m_ruler->comboScale[m_currentZoom] /
     m_currentZoom = factor;
     m_trackview->setScale(m_scale);
-    m_trackview->setCursorPos(pos * m_scale, false);
-    m_trackview->centerOn(QPointF(m_trackview->cursorPos(), 50));
 }
 
 const double TrackView::zoomFactor() const {