#include <QDebug>
#include <QMouseEvent>
++#include <QParallelAnimationGroup>
#include "mapcommon.h"
+ #include "mapscroller.h"
+
#include "mapview.h"
+ const qreal MS_PER_S = 1000;
+
+ // const values for tuning the kinetic scroll effect
+ const int KINETIC_MIN_DRAG_LENGTH_VIEW_PIXELS = 30;
+ const int KINETIC_MAX_TIME_FROM_LAST_MOUSE_EVENT_MS = 100;
+ const int KINETIC_SCROLL_TIME_MS = 750;
+ const qreal KINETIC_SPEED_TO_DISTANCE_FACTOR = 0.15 * sqrt(KINETIC_SCROLL_TIME_MS / MS_PER_S);
+
MapView::MapView(QWidget *parent)
: QGraphicsView(parent)
{
m_zoomAnimation = new QPropertyAnimation(this, "viewScale", this);
connect(m_zoomAnimation, SIGNAL(finished()),
this, SIGNAL(viewZoomFinished()));
- connect(m_zoomAnimation, SIGNAL(finished()),
- this, SLOT(disableAnchor()));
setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing);
+
+ m_scroller = &MapScroller::getInstance();
++
++ m_group = new QParallelAnimationGroup(this);
++
++ m_group->addAnimation(m_zoomAnimation);
++ m_group->addAnimation(m_scroller);
}
void MapView::centerToSceneCoordinates(QPoint sceneCoordinate)
centerOn(sceneCoordinate);
}
+void MapView::mouseDoubleClickEvent(QMouseEvent *event)
+{
+ qWarning() << __PRETTY_FUNCTION__ << event->pos().x() << event->pos().y();
+ qWarning() << __PRETTY_FUNCTION__ << mapToScene(event->pos()).toPoint().x() <<
+ mapToScene(event->pos()).toPoint().y();
+
- QPoint centerPosition = mapToScene(QPoint(width() / 2, height() / 2)).toPoint();
++ QPoint centerPosition = mapToScene(QPoint(width() / 2 - 1, height() / 2 - 1)).toPoint();
+ QPoint pressPosition = mapToScene(event->pos()).toPoint();
+ QPoint scenePosition = centerPosition - ((centerPosition - pressPosition) / 2);
+
- setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
- emit zoomIn();
- // translate(event->pos().x() / 2, event->pos().y() / 2);
- // emit viewScrolled(scenePosition);
- // setTransformationAnchor(QGraphicsView::AnchorViewCenter);
- }
++ m_zoomAnimation->setDuration(KINETIC_SCROLL_TIME_MS);
++ m_zoomAnimation->setStartValue(viewScale());
++ m_zoomAnimation->setEndValue(pow(2, ++m_zoomLevel - MAX_MAP_ZOOM_LEVEL));
++ m_zoomAnimation->setEasingCurve(QEasingCurve::OutCirc);
+
- void MapView::keyPressEvent(QKeyEvent *event)
- {
- if (event->key() == Qt::Key_Space)
- setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
++ m_scroller->setDuration(KINETIC_SCROLL_TIME_MS);
++ m_scroller->setStartValue(centerPosition);
++ m_scroller->setEndValue(scenePosition);
++
++ m_group->start();
++
++ emit zoomIn();
+}
+
void MapView::mouseMoveEvent(QMouseEvent *event)
{
- m_scenePosition += m_mousePosition - mapToScene(event->pos()).toPoint();
+ m_scenePosition += m_mouseLastScenePosition - mapToScene(event->pos()).toPoint();
+ qWarning() << __PRETTY_FUNCTION__;
+
qDebug() << __PRETTY_FUNCTION__ << "m_scenePosition:" << m_scenePosition;
+ if (m_index >= VALUES)
+ m_index = 0;
+
+ m_dragMovement[m_index] = m_mouseLastViewPosition - event->pos();
+ m_dragTime[m_index] = m_time.elapsed();
+ m_time.start();
+ m_index++;
+
emit viewScrolled(m_scenePosition);
- m_mousePosition = mapToScene(event->pos()).toPoint();
+ m_mouseLastScenePosition = mapToScene(event->pos()).toPoint();
+ m_mouseLastViewPosition = event->pos();
}
void MapView::mousePressEvent(QMouseEvent *event)
{
+ qWarning() << __PRETTY_FUNCTION__;
qDebug() << __PRETTY_FUNCTION__;
+ m_time.start();
+
+ m_scroller->stop();
+
QGraphicsView::mousePressEvent(event);
- m_mousePosition = mapToScene(event->pos()).toPoint();
+ m_mouseLastScenePosition = mapToScene(event->pos()).toPoint();
+ m_mouseLastViewPosition = event->pos();
m_scenePosition = mapToScene(width() / 2 - 1, height() / 2 - 1).toPoint();
+
+ for (int i = 0; i < VALUES; i++) {
+ m_dragMovement[i] = QPoint();
+ m_dragTime[i] = 0;
+ }
+ m_index = 0;
}
void MapView::mouseReleaseEvent(QMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
- if (m_zoomAnimation) {
+ m_zoomLevel = zoomLevel;
+
- if (m_zoomAnimation) {
++ if (m_zoomAnimation && (m_zoomAnimation->state() == QAbstractAnimation::Stopped)) {
m_zoomAnimation->stop();
m_zoomAnimation->setDuration(ZOOM_TIME);
m_zoomAnimation->setStartValue(viewScale());
#define MAPVIEW_H
#include <QGraphicsView>
+ #include <QTime>
class QPropertyAnimation;
++class QParallelAnimationGroup;
+
+ class MapScroller;
+
+ #define VALUES 4
/**
* @brief Map view widget
******************************************************************************/
protected:
/**
+ * @brief Event handler for mouse double click event
+ *
+ * Emits zoomIn signal.
+ * @param event QMouseEvent
+ */
+ void mouseDoubleClickEvent(QMouseEvent *event);
+
+ /**
+ * @brief Called when view is resized.
+ *
+ * @param event resize event
+ */
+ void resizeEvent(QResizeEvent *event);
+
+ private:
+ /**
* @brief Event handler for mouse move events
*
* Does calculate mouse movement delta from last event position and new view center
*/
void viewZoomFinished();
- /**
- * @brief Signal for zooming in.
- */
+ void zoomIn();
+
/*******************************************************************************
* DATA MEMBERS
******************************************************************************/
private:
- QPoint m_mousePosition; ///< Previous mouse event position
+ int m_dragTime[VALUES]; ///< Table of mouse event durations
+ int m_index; ///< Index of mouse event values tables
+ int m_zoomLevel; ///< Current zoom level
+
+ QPoint m_dragMovement[VALUES]; ///< Table of mouse event distances
+ QPoint m_mouseLastScenePosition; ///< Previous mouse event position in the scene
+ QPoint m_mouseLastViewPosition; ///< Previous mouse event position in the view
QPoint m_scenePosition; ///< New center position
+
QPropertyAnimation *m_zoomAnimation; ///< Zoom animation
+
+ QTime m_time; ///< Elapsed times in mouse events
+
+ MapScroller *m_scroller; ///< Kinetic scroller
++
++ QParallelAnimationGroup *m_group;
};
#endif // MAPVIEW_H
HEADERS += network/networkhandlerprivate.h
QT += dbus
CONFIG += icd2
-- SOURCES += gps/gpspositionprivateliblocation.cpp \
-- gps/liblocationwrapper.cpp \
-- gps/geopositioninfo.cpp \
-- gps/geocoordinate.cpp
-- HEADERS += gps/gpspositionprivateliblocation.h \
-- gps/liblocationwrapper.h \
-- gps/geopositioninfo.h \
-- gps/geocoordinate.h
-- CONFIG += link_pkgconfig
-- PKGCONFIG += glib-2.0 liblocation
++# SOURCES += gps/gpspositionprivateliblocation.cpp \
++# gps/liblocationwrapper.cpp \
++# gps/geopositioninfo.cpp \
++# gps/geocoordinate.cpp
++# HEADERS += gps/gpspositionprivateliblocation.h \
++# gps/liblocationwrapper.h \
++# gps/geopositioninfo.h \
++# gps/geocoordinate.h
++# CONFIG += link_pkgconfig
++# PKGCONFIG += glib-2.0 liblocation
++ SOURCES += gps/gpspositionprivatestub.cpp
++ HEADERS += gps/gpspositionprivatestub.h
} else {
SOURCES += gps/gpspositionprivatestub.cpp \
network/networkhandlerprivatestub.cpp