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 <QGraphicsView>
29 class QPropertyAnimation;
30 class QParallelAnimationGroup;
34 class SceneCoordinate;
39 * @brief Map view widget
41 * @author Sami Rämö - sami.ramo (at) ixonos.com
42 * @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
44 class MapView : public QGraphicsView
53 Q_PROPERTY(qreal viewScale READ viewScale WRITE setViewScale)
59 * @param parent Parent
61 MapView(QWidget *parent = 0);
66 * Takes MapScroller animation from double click zoom animation group and
67 * deletes animation group.
71 /*******************************************************************************
72 * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
73 ******************************************************************************/
76 * @brief Called when view is resized.
78 * @param event resize event
80 void resizeEvent(QResizeEvent *event);
84 * @brief Event handler for mouse double click event
86 * Emits zoomIn signal.
87 * @param event QMouseEvent
89 void mouseDoubleClickEvent(QMouseEvent *event);
92 * @brief Event handler for mouse move events
94 * Does calculate mouse movement delta from last event position and new view center
95 * based on that delta. Saves current event position for next round. Emits viewScrolled
96 * signal and doesn't actually scroll the view.
98 * Saves mouse movement deltas and durations for last few move events to be used for
99 * calculating the kinetic scrolling speed.
101 * @param event Mouse event
103 void mouseMoveEvent(QMouseEvent *event);
106 * @brief Event handler for mouse press events
108 * Saves inial values for mouse and scene location for dragging the view. Does stop currently
109 * running kinetic scroll effect.
111 * @param event Mouse event
113 void mousePressEvent(QMouseEvent *event);
116 * @brief Event handler for mouse release events
118 * Set up and start kinetic scrolling effect if time elapsed from last mouseMoveEvent is below
119 * the limit and drag length is over the limit.
121 * Kinetic scroll distance is calculated based on mouse movement event values saved in
122 * mouseMoveEvent(). The distance is also limited so that map doesn't run too far.
124 * @param event Mouse event
126 void mouseReleaseEvent(QMouseEvent *event);
128 /*******************************************************************************
129 * MEMBER FUNCTIONS AND SLOTS
130 ******************************************************************************/
133 * @brief Slot for centering view to new location
135 * @param sceneCoordinate Scene coordinates of the new center point
137 void centerToSceneCoordinates(const SceneCoordinate &sceneCoordinate);
140 * @brief Set zoom level of the view
142 * @param zoomLevel Zoom level
144 void setZoomLevel(int zoomLevel);
148 * @brief Double tap zoom finished.
150 * Disables double tap zoom flag and emits zoomIn signal.
152 void doubleTapZoomFinished();
156 * @brief Set new view scale
158 * @param viewScale New scaling factor
160 void setViewScale(qreal viewScale);
163 * @brief Get current view scale
165 * @return Current view scaling factor
169 /*******************************************************************************
171 ******************************************************************************/
174 * @brief Signal for view resize events.
176 * Signal is emitted when view has been resized.
177 * @param size view size
179 void viewResized(const QSize &size);
182 * @brief Signal for view scroll events
184 * Signal is emitted when view is scrolled.
185 * @param sceneCoordinate Scene coordinates of the new center point of the view
187 void viewScrolled(const SceneCoordinate &sceneCoordinate);
190 * @brief Signal for informing that zooming animation is finished
192 void viewZoomFinished();
195 * @brief Signal for informing that double click zoom is finished
199 /*******************************************************************************
201 ******************************************************************************/
203 bool m_doubleTapZoomRunning; ///< Double tap zoom running flag
205 int m_dragTime[VALUES]; ///< Table of mouse event durations
206 int m_index; ///< Index of mouse event values tables
207 int m_zoomLevel; ///< Current zoom level
209 qreal m_kineticMaxViewDistance; ///< Maximum kinetic scroll distance in view pixels
211 QPoint m_dragMovement[VALUES]; ///< Table of mouse event distances
212 QPoint m_mouseLastScenePosition; ///< Previous mouse event position in the scene
213 QPoint m_mouseLastViewPosition; ///< Previous mouse event position in the view
214 QPoint m_scenePosition; ///< New center position
216 QParallelAnimationGroup *m_scrollAndZoomAnimation; ///< Double click zoom animation
217 QPropertyAnimation *m_zoomAnimation; ///< Zoom animation
219 QTime m_time; ///< Elapsed times in mouse events
221 MapScroller *m_scroller; ///< Kinetic scroller