2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 #include <QMouseEvent>
27 #include "mapcommon.h"
30 MapView::MapView(QWidget *parent)
31 : QGraphicsView(parent)
33 qDebug() << __PRETTY_FUNCTION__;
35 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
36 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
38 m_zoomAnimation = new QPropertyAnimation(this, "viewScale", this);
39 connect(m_zoomAnimation, SIGNAL(finished()), this, SIGNAL(viewZoomFinished()));
42 void MapView::setZoomLevel(int zoomLevel)
44 qDebug() << __PRETTY_FUNCTION__;
46 m_zoomAnimation->stop();
47 m_zoomAnimation->setDuration(ZOOM_TIME);
48 m_zoomAnimation->setStartValue(viewScale());
49 m_zoomAnimation->setEndValue(pow(2, zoomLevel - MAX_MAP_ZOOM_LEVEL));
51 m_zoomAnimation->start();
54 qreal MapView::currentScale()
56 qDebug() << __PRETTY_FUNCTION__;
58 QTransform currentTransform = transform();
59 return currentTransform.m11();
62 qreal MapView::viewScale()
64 qDebug() << __PRETTY_FUNCTION__;
66 QTransform currentTransform = transform();
67 return currentTransform.m11();
70 void MapView::setViewScale(qreal viewScale)
72 qDebug() << __PRETTY_FUNCTION__;
75 transform.scale(viewScale, viewScale);
76 setTransform(transform);
77 emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
80 void MapView::mouseMoveEvent(QMouseEvent *event)
82 m_scenePosition += m_mousePosition - mapToScene(event->pos()).toPoint();
84 qDebug() << __PRETTY_FUNCTION__ << "m_scenePosition:" << m_scenePosition;
86 emit viewScrolled(m_scenePosition);
88 m_mousePosition = mapToScene(event->pos()).toPoint();
89 emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
92 void MapView::mousePressEvent(QMouseEvent *event)
94 qDebug() << __PRETTY_FUNCTION__;
96 QGraphicsView::mousePressEvent(event);
98 m_mousePosition = mapToScene(event->pos()).toPoint();
99 m_scenePosition = mapToScene(width() / 2 - 1, height() / 2 - 1).toPoint();
102 void MapView::centerToSceneCoordinates(QPoint sceneCoordinate)
104 qDebug() << __PRETTY_FUNCTION__ << "sceneCoordinate" << sceneCoordinate;
105 centerOn(sceneCoordinate);
108 void MapView::resizeEvent(QResizeEvent *event)
110 qDebug() << __PRETTY_FUNCTION__ << event->size();
111 emit viewResized(event->size());
112 emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());