2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
6 Pekka Nissinen - pekka.nissinen@ixonos.com
8 Situare is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 Situare is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Situare; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
26 #include <QMouseEvent>
28 #include "mapcommon.h"
31 MapView::MapView(QWidget *parent)
32 : QGraphicsView(parent)
34 qDebug() << __PRETTY_FUNCTION__;
36 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
37 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
39 m_zoomAnimation = new QPropertyAnimation(this, "viewScale", this);
40 connect(m_zoomAnimation, SIGNAL(finished()),
41 this, SIGNAL(viewZoomFinished()));
43 setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing);
46 void MapView::centerToSceneCoordinates(QPoint sceneCoordinate)
48 qDebug() << __PRETTY_FUNCTION__ << "sceneCoordinate" << sceneCoordinate;
50 centerOn(sceneCoordinate);
53 void MapView::mouseMoveEvent(QMouseEvent *event)
55 m_scenePosition += m_mousePosition - mapToScene(event->pos());
57 qDebug() << __PRETTY_FUNCTION__ << "m_scenePosition:" << m_scenePosition;
59 emit viewScrolled(m_scenePosition.toPoint());
61 m_mousePosition = mapToScene(event->pos());
64 void MapView::mousePressEvent(QMouseEvent *event)
66 qDebug() << __PRETTY_FUNCTION__;
68 QGraphicsView::mousePressEvent(event);
70 m_mousePosition = mapToScene(event->pos());
71 m_scenePosition = mapToScene(width() / 2 - 1, height() / 2 - 1);
74 void MapView::mouseReleaseEvent(QMouseEvent *event)
76 QGraphicsView::mouseReleaseEvent(event);
79 void MapView::resizeEvent(QResizeEvent *event)
81 qDebug() << __PRETTY_FUNCTION__ << "Resize:" << event->size();
83 emit viewResized(event->size());
86 void MapView::setViewScale(qreal viewScale)
88 qDebug() << __PRETTY_FUNCTION__;
91 transform.scale(viewScale, viewScale);
92 setTransform(transform);
95 void MapView::setZoomLevel(int zoomLevel)
97 qDebug() << __PRETTY_FUNCTION__;
99 if (m_zoomAnimation) {
100 m_zoomAnimation->stop();
101 m_zoomAnimation->setDuration(ZOOM_TIME);
102 m_zoomAnimation->setStartValue(viewScale());
103 m_zoomAnimation->setEndValue(pow(2, zoomLevel - MAX_MAP_ZOOM_LEVEL));
105 m_zoomAnimation->start();
109 qreal MapView::viewScale()
111 qDebug() << __PRETTY_FUNCTION__;
113 return transform().m11();