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)));
#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__;
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<SceneCoordinate>()))
- emit coordinateUpdated(value.value<SceneCoordinate>());
+ emit coordinateUpdated(value.value<SceneCoordinate>(), 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));
}
/**
* @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.
*/
static MapScroller &getInstance();
+ /**
+ * @brief Set flag for kinetic scroll
+ *
+ * @param isKineticScroll Set to true if starting a kinetic scroll
+ */
+ void setKineticScrollFlag(bool isKineticScroll);
+
/*******************************************************************************
* 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
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()
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();
}
}
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();
}
}
m_internalScenePosition.y()));
QPointF endValue = QPointF(m_internalScenePosition) + effectSceneDistance;
m_scroller->setEndValue(SceneCoordinate(endValue.x(), endValue.y()));
+ m_scroller->setKineticScrollFlag(true);
m_scroller->start();
}
}
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)
void MapView::updateCenterShift()
{
- qWarning() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__;
m_centerHorizontalShiftPoint = QPointF(m_centerHorizontalShiftViewPixels * (1.0 / viewScale()),
0);
* 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