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 #include "coordinates/scenecoordinate.h"
31 class QPropertyAnimation;
32 class QParallelAnimationGroup;
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 * Does also shift the center point horizontally, if required.
137 * @param coordinate Scene coordinates of the new center point
138 * @param isUserDragAction True if caused by user dragging action. Does not shift the center
141 void centerToSceneCoordinates(const SceneCoordinate &coordinate, bool isUserDragAction = false);
144 * @brief Set zoom level of the view
146 * @param zoomLevel Zoom level
148 void setZoomLevel(int zoomLevel);
152 * @brief Disables shifting of the center point
154 void disableCenterShift();
157 * @brief Double tap zoom finished.
159 * Disables double tap zoom flag and emits zoomIn signal.
161 void doubleTapZoomFinished();
164 * @brief Enables shifting of the center point
166 void enableCenterShift();
170 * @brief Set new view scale
172 * @param viewScale New scaling factor
174 void setViewScale(qreal viewScale);
177 * @brief Toggles the shifting of the center point
179 * @param enabled True if shifting is enabled
181 void toggleCenterShift(bool enabled);
184 * @brief Update center shifting value
186 void updateCenterShift();
189 * @brief Get current view scale
191 * @return Current view scaling factor
195 /*******************************************************************************
197 ******************************************************************************/
200 * @brief Signal for view resize events.
202 * Signal is emitted when view has been resized.
203 * @param size view size
205 void viewResized(const QSize &size);
208 * @brief Signal for view scroll events
210 * Signal is emitted when view is scrolled.
211 * @param coordinate Scene coordinates of the new center point of the view
212 * @param isUserDragAction True if caused by user dragging action
214 void viewScrolled(const SceneCoordinate &coordinate, bool isUserDragAction);
217 * @brief Signal for informing that zooming animation is finished
219 void viewZoomFinished();
222 * @brief Signal for informing that double click zoom is finished
226 /*******************************************************************************
228 ******************************************************************************/
230 bool m_centerShiftEnabled; ///< Is the center point shifting enabled?
231 bool m_doubleTapZoomRunning; ///< Double tap zoom running flag
233 int m_dragTime[VALUES]; ///< Table of mouse event durations
234 int m_index; ///< Index of mouse event values tables
235 int m_zoomLevel; ///< Current zoom level
237 qreal m_kineticMaxViewDistance; ///< Maximum kinetic scroll distance in view pixels
239 QPoint m_dragMovement[VALUES]; ///< Table of mouse event distances
240 QPoint m_internalScenePosition; ///< New center position
241 QPoint m_lastMouseEventScenePosition; ///< Previous mouse event position in the scene
242 QPoint m_lastMouseEventViewPosition; ///< Previous mouse event position in the view
244 QPointF m_centerHorizontalShift; ///< Current amount of center point shifting
246 QParallelAnimationGroup *m_scrollAndZoomAnimation; ///< Double click zoom animation
247 QPropertyAnimation *m_zoomAnimation; ///< Zoom animation
249 QTime m_time; ///< Elapsed times in mouse events
251 MapScroller *m_scroller; ///< Kinetic scroller
252 SceneCoordinate m_lastSetScenePosition; ///< Last center point coordinate set by MapEngine