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 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
34 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
36 m_zoomAnimation = new QPropertyAnimation(this, "viewScale", this);
37 connect(m_zoomAnimation, SIGNAL(finished()), this, SIGNAL(viewZoomFinished()));
40 void MapView::setZoomLevel(int zoomLevel)
42 m_zoomAnimation->stop();
43 m_zoomAnimation->setDuration(ZOOM_TIME);
44 m_zoomAnimation->setStartValue(viewScale());
45 m_zoomAnimation->setEndValue(pow(2, zoomLevel - MAX_MAP_ZOOM_LEVEL));
47 m_zoomAnimation->start();
50 qreal MapView::currentScale()
52 QTransform currentTransform = transform();
53 return currentTransform.m11();
56 qreal MapView::viewScale()
58 QTransform currentTransform = transform();
59 return currentTransform.m11();
62 void MapView::setViewScale(qreal viewScale)
65 transform.scale(viewScale, viewScale);
66 setTransform(transform);
67 emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
70 void MapView::mouseMoveEvent(QMouseEvent *event)
72 m_scenePosition += m_mousePosition - mapToScene(event->pos()).toPoint();
74 emit viewScrolled(m_scenePosition);
75 qDebug() << __PRETTY_FUNCTION__ << "m_scenePosition:" << m_scenePosition;
77 m_mousePosition = mapToScene(event->pos()).toPoint();
78 emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
81 void MapView::mousePressEvent(QMouseEvent *event)
83 QGraphicsView::mousePressEvent(event);
85 m_mousePosition = mapToScene(event->pos()).toPoint();
86 m_scenePosition = mapToScene(width() / 2 - 1, height() / 2 - 1).toPoint();
89 void MapView::centerToSceneCoordinates(QPoint sceneCoordinate)
91 qDebug() << __PRETTY_FUNCTION__ << "sceneCoordinate" << sceneCoordinate;
92 centerOn(sceneCoordinate);
95 void MapView::resizeEvent(QResizeEvent *event)
97 qDebug() << __PRETTY_FUNCTION__ << event->size();
98 emit viewResized(event->size());
99 emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());