X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fmap%2Fmapview.cpp;h=15de9cb422df5d9a741ae418b4aab64a300a0b06;hb=443c20f86835babe9598079261e87624fd467899;hp=7eb3195a54d174261f0e453b45a713661c155e15;hpb=0c5c42bb7625adfe63db20fdbbd251b7b1d23b3b;p=situare diff --git a/src/map/mapview.cpp b/src/map/mapview.cpp index 7eb3195..15de9cb 100644 --- a/src/map/mapview.cpp +++ b/src/map/mapview.cpp @@ -28,36 +28,21 @@ #include #endif // Q_WS_MAEMO_5 -#ifdef Q_WS_MAEMO_5 - #include -#endif // Q_WS_MAEMO_5 - -#include "common.h" +#include "mapcommon.h" #include "mapview.h" -MapView::MapView(QWidget *parent) : QGraphicsView(parent) +MapView::MapView(QWidget *parent) + : QGraphicsView(parent) + , m_timerID(NULL) { /** * Use OpenGL for desktop to gain some performance in map view. * OpenGL can't be used in scratchbox. */ #ifndef Q_WS_MAEMO_5 - setViewport(new QGLWidget); + setViewport(new QGLWidget(QGLFormat(QGL::DoubleBuffer))); #endif // !Q_WS_MAEMO_5 -/** - * Use kinetic scrolling for Maemo5 and QGraphicsViews drag mode - * ScrollHandDrag for other environments - */ -#ifdef Q_WS_MAEMO_5 - QAbstractKineticScroller *scroller = property("kineticScroller") - .value(); - if (scroller) - scroller->setEnabled(true); -#else - setDragMode(QGraphicsView::ScrollHandDrag); -#endif // Q_WS_MAEMO_5 - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); } @@ -65,34 +50,45 @@ MapView::MapView(QWidget *parent) : QGraphicsView(parent) void MapView::setZoomLevel(int zoomLevel) { m_zoomTargetScale = pow(2, zoomLevel - MAX_MAP_ZOOM_LEVEL); - m_zoomScaleDelta = (m_zoomTargetScale - currentScale()) / (ZOOM_FPS * ZOOM_TIME); + m_zoomScaleDelta = (m_zoomTargetScale - currentScale()) / (ZOOM_FPS * (ZOOM_TIME / 1000)); + + if (m_timerID) + killTimer(m_timerID); - startTimer(1000/ZOOM_FPS); + m_timerID = startTimer(1000/ZOOM_FPS); } void MapView::timerEvent(QTimerEvent *event) { - qreal scaleFactor = currentScale(); - -// qDebug() << __PRETTY_FUNCTION__ -// << "abs(m_zoomTargetScale - scaleFactor)" << fabs(m_zoomTargetScale - scaleFactor) -// << "abs(m_zoomScaleDelta)" << fabs(m_zoomScaleDelta); - - if (fabs(m_zoomTargetScale - scaleFactor) <= fabs(m_zoomScaleDelta)) { - scaleFactor = m_zoomTargetScale; - killTimer(event->timerId()); + if (event->timerId() == m_timerID) { + bool finished = false; + qreal scaleFactor = currentScale(); + +// qDebug() << __PRETTY_FUNCTION__ +// << "abs(m_zoomTargetScale - scaleFactor)" << fabs(m_zoomTargetScale - scaleFactor) +// << "abs(m_zoomScaleDelta)" << fabs(m_zoomScaleDelta); + + if (fabs(m_zoomTargetScale - scaleFactor) <= fabs(m_zoomScaleDelta)) { + scaleFactor = m_zoomTargetScale; + killTimer(event->timerId()); + finished = true; + } + else { + scaleFactor += m_zoomScaleDelta; + } + +// qDebug() << __PRETTY_FUNCTION__ << "currentScale:" << currentScale() +// << "m_zoomScaleDelta" << m_zoomScaleDelta +// << "scaleFactor:" << scaleFactor; + + QTransform transform; + transform.scale(scaleFactor, scaleFactor); + setTransform(transform); + emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint()); + + if (finished && m_zoomScaleDelta > 0) + emit viewZoomInFinished(); } - else { - scaleFactor += m_zoomScaleDelta; - } - -// qDebug() << __PRETTY_FUNCTION__ << "currentScale:" << currentScale() -// << "m_zoomScaleDelta" << m_zoomScaleDelta -// << "scaleFactor:" << scaleFactor; - - QTransform transform; - transform.scale(scaleFactor, scaleFactor); - setTransform(transform); } qreal MapView::currentScale() @@ -101,38 +97,34 @@ qreal MapView::currentScale() return currentTransform.m11(); } -void MapView::scrollContentsBy (int dx, int dy) +void MapView::mouseMoveEvent(QMouseEvent *event) +{ + m_scenePosition += m_mousePosition - mapToScene(event->pos()).toPoint(); + + emit viewScrolled(m_scenePosition); +// qDebug() << __PRETTY_FUNCTION__ << "m_scenePosition:" << m_scenePosition; + + m_mousePosition = mapToScene(event->pos()).toPoint(); + emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint()); +} + +void MapView::mousePressEvent(QMouseEvent *event) { - qDebug() << __PRETTY_FUNCTION__ << "dx:" << dx << "dy:" << dy; + QGraphicsView::mousePressEvent(event); - QGraphicsView::scrollContentsBy(dx, dy); + m_mousePosition = mapToScene(event->pos()).toPoint(); + m_scenePosition = mapToScene(width() / 2 - 1, height() / 2 - 1).toPoint(); } -//void MapView::mouseMoveEvent(QMouseEvent *event) -//{ -// m_scenePosition += m_mousePosition - mapToScene(event->pos()); -// -// emit viewScrolled(m_scenePosition); -// //qDebug() << __PRETTY_FUNCTION__ << "m_scenePosition" << m_scenePosition; -// -// m_mousePosition = mapToScene(event->pos()); -//} -// -//void MapView::mousePressEvent(QMouseEvent *event) -//{ -// m_mousePosition = mapToScene(event->pos()); -// m_scenePosition = mapToScene(width() / 2 - 1, height() / 2 - 1); -//} - - -void MapView::centerToSceneCoordinates(QPointF sceneCoordinate) +void MapView::centerToSceneCoordinates(QPoint sceneCoordinate) { - //qDebug() << __PRETTY_FUNCTION__ << "sceneCoordinate" << sceneCoordinate; +// qDebug() << __PRETTY_FUNCTION__ << "sceneCoordinate" << sceneCoordinate; centerOn(sceneCoordinate); } void MapView::resizeEvent(QResizeEvent *event) { - qDebug() << "Resize event: " << event->size(); +// qDebug() << "Resize event: " << event->size(); emit viewResized(event->size()); + emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint()); }