MapView::MapView(QWidget *parent)
: QGraphicsView(parent),
- m_centerShiftEnabled(false),
m_doubleTapZoomRunning(false)
{
qDebug() << __PRETTY_FUNCTION__;
m_scrollAndZoomAnimation->addAnimation(m_zoomAnimation);
connect(m_scrollAndZoomAnimation, SIGNAL(finished()),
this, SLOT(doubleTapZoomFinished()));
+
+ m_centerShiftAnimation = new QPropertyAnimation(this, "viewShift", this);
+ if (m_centerShiftAnimation) {
+ m_centerShiftAnimation->setStartValue(0.0);
+ m_centerShiftAnimation->setDuration(KINETIC_SCROLL_TIME_MS);
+ }
+
}
MapView::~MapView()
m_lastSetScenePosition = coordinate;
if (!isUserDragAction) {
- target += m_centerHorizontalShift;
+ target += m_centerHorizontalShiftPoint;
}
centerOn(target);
void MapView::disableCenterShift()
{
- qDebug() << __PRETTY_FUNCTION__;
+ qWarning() << __PRETTY_FUNCTION__;
- toggleCenterShift(false);
+// toggleCenterShift(false);
+
+ if (m_centerShiftAnimation) {
+ m_centerShiftAnimation->setDirection(QAbstractAnimation::Backward);
+ qWarning() << __PRETTY_FUNCTION__ << "starting animation";
+ m_centerShiftAnimation->start();
+ }
}
void MapView::doubleTapZoomFinished()
void MapView::enableCenterShift()
{
- qDebug() << __PRETTY_FUNCTION__;
+ qWarning() << __PRETTY_FUNCTION__;
+
+// toggleCenterShift(true);
- toggleCenterShift(true);
+ if (m_centerShiftAnimation) {
+ m_centerShiftAnimation->setDirection(QAbstractAnimation::Forward);
+ qWarning() << __PRETTY_FUNCTION__ << "starting animation";
+ m_centerShiftAnimation->start();
+ }
}
void MapView::mouseDoubleClickEvent(QMouseEvent *event)
emit viewResized(event->size());
+ if (m_centerShiftAnimation) {
+ m_centerShiftAnimation->setEndValue(event->size().width() / 4);
+ }
+
+ qWarning() << __PRETTY_FUNCTION__ << "animation end value:" << m_centerShiftAnimation->endValue().toReal();
+
updateCenterShift();
}
QTransform transform;
transform.scale(viewScale, viewScale);
setTransform(transform);
+
+ updateCenterShift();
+}
+
+void MapView::setViewShift(qreal viewShift)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_centerHorizontalShiftViewPixels = viewShift;
+
+ updateCenterShift();
}
void MapView::setZoomLevel(int zoomLevel)
m_zoomAnimation->start();
}
-
- updateCenterShift();
}
-void MapView::toggleCenterShift(bool enabled)
+void MapView::updateCenterShift()
{
- qWarning() << __PRETTY_FUNCTION__ << enabled;
+ qWarning() << __PRETTY_FUNCTION__;
- m_centerShiftEnabled = enabled;
- updateCenterShift();
+ m_centerHorizontalShiftPoint = QPointF(m_centerHorizontalShiftViewPixels * (1.0 / viewScale()),
+ 0);
centerToSceneCoordinates(m_lastSetScenePosition);
}
-void MapView::updateCenterShift()
+qreal MapView::viewScale() const
{
qDebug() << __PRETTY_FUNCTION__;
- int shift = 0;
-
- if (m_centerShiftEnabled)
- shift = 200;
-
- m_centerHorizontalShift = QPointF(shift * (1 << (OSM_MAX_ZOOM_LEVEL - m_zoomLevel)), 0);
+ return transform().m11();
}
-qreal MapView::viewScale()
+qreal MapView::viewShift() const
{
qDebug() << __PRETTY_FUNCTION__;
- return transform().m11();
+ return m_centerHorizontalShiftViewPixels;
}
#include "coordinates/scenecoordinate.h"
-class QPropertyAnimation;
class QParallelAnimationGroup;
+class QPropertyAnimation;
class MapScroller;
*/
Q_PROPERTY(qreal viewScale READ viewScale WRITE setViewScale)
+ /**
+ * @brief View shifting
+ *
+ * @property viewShift
+ */
+ Q_PROPERTY(qreal viewShift READ viewShift WRITE setViewShift)
+
public:
/**
* @brief Constructor
void setViewScale(qreal viewScale);
/**
+ * @brief Set new view shifting
+ *
+ * @param viewShift New shifting amount
+ */
+ void setViewShift(qreal viewShift);
+
+ /**
* @brief Toggles the shifting of the center point
*
* @param enabled True if shifting is enabled
*
* @return Current view scaling factor
*/
- qreal viewScale();
+ qreal viewScale() const;
+
+ /**
+ * @brief Get current view shifting
+ *
+ * @return Current view shifting amount
+ */
+ qreal viewShift() const;
/*******************************************************************************
* SIGNALS
* DATA MEMBERS
******************************************************************************/
private:
- bool m_centerShiftEnabled; ///< Is the center point shifting enabled?
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
+ qreal m_centerHorizontalShiftViewPixels;
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
- QPointF m_centerHorizontalShift; ///< Current amount of center point shifting
+ QPointF m_centerHorizontalShiftPoint; ///< Current amount of center point shifting
+ QPointF m_centerHorizontalShiftEndValue;
- QParallelAnimationGroup *m_scrollAndZoomAnimation; ///< Double click zoom animation
QPropertyAnimation *m_zoomAnimation; ///< Zoom animation
QTime m_time; ///< Elapsed times in mouse events
+ QPropertyAnimation *m_centerShiftAnimation; ///< Animation for shifting the center point
+
MapScroller *m_scroller; ///< Kinetic scroller
SceneCoordinate m_lastSetScenePosition; ///< Last center point coordinate set by MapEngine
};