From f800d9feb67417ce2c48ff1f37ae6c32d51daeb8 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sat, 8 Mar 2008 17:00:37 +0000 Subject: [PATCH] smoother scaling svn path=/branches/KDE4/; revision=2017 --- src/customruler.cpp | 4 ++-- src/customtrackview.cpp | 32 +++++++++++++++----------------- src/customtrackview.h | 1 + src/trackview.cpp | 8 +++----- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/customruler.cpp b/src/customruler.cpp index 12a0c065..866e54e8 100644 --- a/src/customruler.cpp +++ b/src/customruler.cpp @@ -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) { diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 5ca28d0d..44a17375 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -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: "<= 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 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) { diff --git a/src/customtrackview.h b/src/customtrackview.h index d3f8b618..ca4ad9d7 100644 --- a/src/customtrackview.h +++ b/src/customtrackview.h @@ -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); diff --git a/src/trackview.cpp b/src/trackview.cpp index bbf2c464..170d7598 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -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 { -- 2.39.2