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()), this, SIGNAL(viewZoomFinished()));
43 void MapView::setZoomLevel(int zoomLevel)
45 qDebug() << __PRETTY_FUNCTION__;
47 if (m_zoomAnimation) {
48 m_zoomAnimation->stop();
49 m_zoomAnimation->setDuration(ZOOM_TIME);
50 m_zoomAnimation->setStartValue(viewScale());
51 m_zoomAnimation->setEndValue(pow(2, zoomLevel - MAX_MAP_ZOOM_LEVEL));
53 m_zoomAnimation->start();
57 qreal MapView::viewScale()
59 qDebug() << __PRETTY_FUNCTION__;
61 return transform().m11();
64 void MapView::setViewScale(qreal viewScale)
66 qDebug() << __PRETTY_FUNCTION__;
69 transform.scale(viewScale, viewScale);
70 setTransform(transform);
71 emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
74 void MapView::mouseMoveEvent(QMouseEvent *event)
76 m_scenePosition += m_mousePosition - mapToScene(event->pos()).toPoint();
78 qDebug() << __PRETTY_FUNCTION__ << "m_scenePosition:" << m_scenePosition;
80 emit viewScrolled(m_scenePosition);
82 m_mousePosition = mapToScene(event->pos()).toPoint();
83 emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
86 void MapView::mousePressEvent(QMouseEvent *event)
88 qDebug() << __PRETTY_FUNCTION__;
90 QGraphicsView::mousePressEvent(event); // Temporary solution
92 m_mousePosition = mapToScene(event->pos()).toPoint();
93 m_scenePosition = mapToScene(width() / 2 - 1, height() / 2 - 1).toPoint();
96 void MapView::centerToSceneCoordinates(QPoint sceneCoordinate)
98 qDebug() << __PRETTY_FUNCTION__ << "sceneCoordinate" << sceneCoordinate;
100 centerOn(sceneCoordinate);
103 void MapView::resizeEvent(QResizeEvent *event)
105 qDebug() << __PRETTY_FUNCTION__ << "Resize:" << event->size();
107 emit viewResized(event->size());
108 emit viewResizedNewSize(viewport()->width(), viewport()->height());
109 //emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
112 void MapView::showEvent(QShowEvent *event)
114 qDebug() << __PRETTY_FUNCTION__;
116 QGraphicsView::showEvent(event);
117 //emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
120 void MapView::updateViewPortContent()
122 qDebug() << __PRETTY_FUNCTION__;
124 QPoint topLeft = mapToScene(viewport()->contentsRect().topLeft()).toPoint();
125 QPoint bottomRight = mapToScene(viewport()->contentsRect().bottomRight()).toPoint();
126 //emit viewContentChanged(QRect(topLeft, bottomRight));
129 QRect MapView::viewportContent()
131 QPoint topLeft = mapToScene(viewport()->contentsRect().topLeft()).toPoint();
132 QPoint bottomRight = mapToScene(viewport()->contentsRect().bottomRight()).toPoint();
133 emit updateViewContent(QRect(topLeft, bottomRight));
135 return QRect(topLeft, bottomRight);