From: Sami Rämö Date: Mon, 23 Aug 2010 12:46:55 +0000 (+0300) Subject: Fixed a jump in the map when moving from dragging to kinetic effect X-Git-Tag: v2.0b-1~38^2~11 X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;ds=sidebyside;h=9451926d02109607904921248a6ad1f3dc178e08;p=situare Fixed a jump in the map when moving from dragging to kinetic effect - Also cleaning up --- diff --git a/src/map/mapengine.cpp b/src/map/mapengine.cpp index a5c3d0b..2414c91 100644 --- a/src/map/mapengine.cpp +++ b/src/map/mapengine.cpp @@ -101,8 +101,8 @@ MapEngine::MapEngine(QObject *parent) m_scroller = &MapScroller::getInstance(); - connect(m_scroller, SIGNAL(coordinateUpdated(SceneCoordinate)), - this, SLOT(setCenterPosition(SceneCoordinate))); + connect(m_scroller, SIGNAL(coordinateUpdated(SceneCoordinate, bool)), + this, SLOT(setCenterPosition(SceneCoordinate, bool))); connect(m_scroller, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), this, SLOT(scrollerStateChanged(QAbstractAnimation::State))); diff --git a/src/map/mapscroller.cpp b/src/map/mapscroller.cpp index 8e04137..ff18a11 100644 --- a/src/map/mapscroller.cpp +++ b/src/map/mapscroller.cpp @@ -26,11 +26,19 @@ #include "mapscroller.h" +///////////////////////////////////////////////////////////////////////////// // scene coordinate interpolator function is not part of this class namespace +///////////////////////////////////////////////////////////////////////////// QVariant sceneCoordinateInterpolator(const SceneCoordinate &start, const SceneCoordinate &end, qreal progress); +MapScroller::MapScroller() + : m_isKineticScroll(false) +{ + qDebug() << __PRETTY_FUNCTION__; +} + MapScroller& MapScroller::getInstance() { qDebug() << __PRETTY_FUNCTION__; @@ -41,18 +49,34 @@ MapScroller& MapScroller::getInstance() return instance; } +void MapScroller::setKineticScrollFlag(bool isKineticScroll) +{ + qDebug() << __PRETTY_FUNCTION__; + + m_isKineticScroll = isKineticScroll; +} + void MapScroller::updateCurrentValue(const QVariant &value) { qDebug() << __PRETTY_FUNCTION__; if ((state() == QAbstractAnimation::Running) && (value.canConvert())) - emit coordinateUpdated(value.value()); + emit coordinateUpdated(value.value(), m_isKineticScroll); + else + m_isKineticScroll = false; + + // NOTE: m_isKineticScroll is cleared when new animation values are set, because this method is + // called then and state() is QAbstractAnimation::Stopped } +///////////////////////////////////////////////////////////////////////////// // scene coordinate interpolator function is not part of this class namespace +///////////////////////////////////////////////////////////////////////////// QVariant sceneCoordinateInterpolator(const SceneCoordinate &start, const SceneCoordinate &end, qreal progress) { + qDebug() << __PRETTY_FUNCTION__; + return SceneCoordinate(start + progress * (end - start)); } diff --git a/src/map/mapscroller.h b/src/map/mapscroller.h index 8f666f1..d12923d 100644 --- a/src/map/mapscroller.h +++ b/src/map/mapscroller.h @@ -45,7 +45,7 @@ private: /** * @brief Constructor in not accessible because class is using singleton design pattern. */ - MapScroller() {} + MapScroller(); /** * @brief Destructor in not accessible because class is using singleton design pattern. @@ -89,6 +89,13 @@ public: */ static MapScroller &getInstance(); + /** + * @brief Set flag for kinetic scroll + * + * @param isKineticScroll Set to true if starting a kinetic scroll + */ + void setKineticScrollFlag(bool isKineticScroll); + /******************************************************************************* * SIGNALS ******************************************************************************/ @@ -97,8 +104,15 @@ signals: * @brief Signal if emitted when coordinate value is updated * * @param coordinate New coordinate value + * @param isKineticScroll True if currently running a kinetic scroll animation */ - void coordinateUpdated(SceneCoordinate coordinate); + void coordinateUpdated(SceneCoordinate coordinate, bool isKineticScroll); + +/******************************************************************************* + * DATA MEMBERS + ******************************************************************************/ +private: + bool m_isKineticScroll; ///< Is the current animation a kinetic scroll animation? }; #endif // MAPSCROLLER_H diff --git a/src/map/mapview.cpp b/src/map/mapview.cpp index 4fbcb0c..400b878 100644 --- a/src/map/mapview.cpp +++ b/src/map/mapview.cpp @@ -68,9 +68,8 @@ MapView::MapView(QWidget *parent) m_centerShiftAnimation = new QPropertyAnimation(this, "viewShift", this); if (m_centerShiftAnimation) { m_centerShiftAnimation->setStartValue(0.0); - m_centerShiftAnimation->setDuration(KINETIC_SCROLL_TIME_MS); + m_centerShiftAnimation->setDuration(ZOOM_TIME_MS); } - } MapView::~MapView() @@ -97,13 +96,10 @@ void MapView::centerToSceneCoordinates(const SceneCoordinate &coordinate, bool i void MapView::disableCenterShift() { - qWarning() << __PRETTY_FUNCTION__; - -// toggleCenterShift(false); + qDebug() << __PRETTY_FUNCTION__; if (m_centerShiftAnimation) { m_centerShiftAnimation->setDirection(QAbstractAnimation::Backward); - qWarning() << __PRETTY_FUNCTION__ << "starting animation"; m_centerShiftAnimation->start(); } } @@ -118,13 +114,10 @@ void MapView::doubleTapZoomFinished() void MapView::enableCenterShift() { - qWarning() << __PRETTY_FUNCTION__; - -// toggleCenterShift(true); + qDebug() << __PRETTY_FUNCTION__; if (m_centerShiftAnimation) { m_centerShiftAnimation->setDirection(QAbstractAnimation::Forward); - qWarning() << __PRETTY_FUNCTION__ << "starting animation"; m_centerShiftAnimation->start(); } } @@ -246,6 +239,7 @@ void MapView::mouseReleaseEvent(QMouseEvent *event) m_internalScenePosition.y())); QPointF endValue = QPointF(m_internalScenePosition) + effectSceneDistance; m_scroller->setEndValue(SceneCoordinate(endValue.x(), endValue.y())); + m_scroller->setKineticScrollFlag(true); m_scroller->start(); } } @@ -261,11 +255,8 @@ void MapView::resizeEvent(QResizeEvent *event) if (m_centerShiftAnimation) { m_centerShiftAnimation->setEndValue(event->size().width() / 4); + updateCenterShift(); } - - qWarning() << __PRETTY_FUNCTION__ << "animation end value:" << m_centerShiftAnimation->endValue().toReal(); - - updateCenterShift(); } void MapView::setViewScale(qreal viewScale) @@ -307,7 +298,7 @@ void MapView::setZoomLevel(int zoomLevel) void MapView::updateCenterShift() { - qWarning() << __PRETTY_FUNCTION__; + qDebug() << __PRETTY_FUNCTION__; m_centerHorizontalShiftPoint = QPointF(m_centerHorizontalShiftViewPixels * (1.0 / viewScale()), 0); diff --git a/src/map/mapview.h b/src/map/mapview.h index aab39f3..cc93931 100644 --- a/src/map/mapview.h +++ b/src/map/mapview.h @@ -248,28 +248,27 @@ signals: * DATA MEMBERS ******************************************************************************/ private: - bool m_doubleTapZoomRunning; ///< Double tap zoom running flag + bool m_doubleTapZoomRunning; ///< Double tap zoom running flag - int m_dragTime[VALUES]; ///< Table of mouse event durations - int m_index; ///< Index of mouse event values tables - int m_zoomLevel; ///< Current zoom level + int m_dragTime[VALUES]; ///< Table of mouse event durations + int m_index; ///< Current index of mouse event values table + int m_zoomLevel; ///< Current zoom level - qreal m_centerHorizontalShiftViewPixels; - qreal m_kineticMaxViewDistance; ///< Maximum kinetic scroll distance in view pixels + qreal m_centerHorizontalShiftViewPixels; ///< Center point horizontal shift in the view + qreal m_kineticMaxViewDistance; ///< Maximum kinetic scroll distance in view pixels QParallelAnimationGroup *m_scrollAndZoomAnimation; ///< Double click zoom animation - QPoint m_dragMovement[VALUES]; ///< Table of mouse event distances - QPoint m_internalScenePosition; ///< New center position - QPoint m_lastMouseEventScenePosition; ///< Previous mouse event position in the scene - QPoint m_lastMouseEventViewPosition; ///< Previous mouse event position in the view + QPoint m_dragMovement[VALUES]; ///< Table of mouse event distances + QPoint m_internalScenePosition; ///< New center position (used for dragging) + QPoint m_lastMouseEventScenePosition; ///< Previous mouse event position in the scene + QPoint m_lastMouseEventViewPosition; ///< Previous mouse event position in the view - QPointF m_centerHorizontalShiftPoint; ///< Current amount of center point shifting - QPointF m_centerHorizontalShiftEndValue; + QPointF m_centerHorizontalShiftPoint; ///< Current amount of center point shifting - QPropertyAnimation *m_zoomAnimation; ///< Zoom animation + QPropertyAnimation *m_zoomAnimation; ///< Zoom animation - QTime m_time; ///< Elapsed times in mouse events + QTime m_time; ///< Elapsed time between mouse events QPropertyAnimation *m_centerShiftAnimation; ///< Animation for shifting the center point