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>
28 #include <QAbstractKineticScroller>
29 #endif // Q_WS_MAEMO_5
34 MapView::MapView(QWidget *parent) : QGraphicsView(parent)
36 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
37 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
42 qDebug() << __PRETTY_FUNCTION__ << "QAbstractKineticScroller built in";
44 QAbstractKineticScroller *scroller = this->property("kineticScroller")
45 .value<QAbstractKineticScroller *>();
48 scroller->setEnabled(true);
49 #endif // Q_WS_MAEMO_5
52 void MapView::setZoomLevel(int zoomLevel)
54 double scaleFactor = pow(2, zoomLevel - MAX_ZOOM_LEVEL);
56 transform.scale(scaleFactor, scaleFactor);
57 setTransform(transform);
60 void MapView::mouseMoveEvent(QMouseEvent *event)
62 // qDebug() << __PRETTY_FUNCTION__ << "scene coordinate:" << mapToScene(event->pos());
63 // if (event->buttons() & Qt::LeftButton)
65 // QPointF delta = mapToScene(event->pos()) - m_mouseClickLocation;
66 // qDebug() << __PRETTY_FUNCTION__ << "delta:" << delta;
68 // int x = size().width() / 2;
69 // int y = size().height() / 2;
70 // QPointF sceneCoordinate = mapToScene(QPoint(x, y)) + delta;
71 // centerToSceneCoordinates(sceneCoordinate);
73 m_scenePosition += m_mousePressPosition - event->pos();
74 centerToSceneCoordinates(m_scenePosition);
77 m_mouseSpeed = event->pos() - m_mousePressPosition;
79 m_mousePressPosition = event->pos();
82 void MapView::mousePressEvent(QMouseEvent *event)
84 // qDebug() << __PRETTY_FUNCTION__ << "scene coordinate:" << mapToScene(event->pos());
86 // if (event->button() == Qt::LeftButton)
87 // m_mouseClickLocation = mapToScene(event->pos());
88 m_mousePressPosition = event->pos();
90 m_mouseSpeed = QPointF(0, 0);
92 m_scenePosition = mapToScene(width() / 2 - 1, height() / 2 - 1);
95 void MapView::mouseReleaseEvent(QMouseEvent *) {
96 m_mouseIsDown = false;
99 void MapView::timerEvent(QTimerEvent *event) {
100 if (!m_mouseIsDown) {
101 m_mouseSpeed *= 0.97;
102 if (m_mouseSpeed.manhattanLength() < 0.1)
103 m_mouseSpeed = QPointF(0, 0);
105 // qDebug() << __PRETTY_FUNCTION__ << "m_mouseSpeed" << m_mouseSpeed;
107 m_scenePosition -= m_mouseSpeed;
108 centerToSceneCoordinates(m_scenePosition);
112 void MapView::centerToSceneCoordinates(QPointF sceneCoordinate)
114 centerOn(sceneCoordinate);
117 //bool MapView::event(QEvent *event)
119 // qDebug() << __PRETTY_FUNCTION__ << "event type:" << event->type();
121 // QObject::event(event);