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 QParallelAnimationGroup;
32 class QPropertyAnimation;
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)
56 * @brief View shifting
60 Q_PROPERTY(qreal viewShift READ viewShift WRITE setViewShift)
66 * @param parent Parent
68 MapView(QWidget *parent = 0);
73 * Takes MapScroller animation from double click zoom animation group and
74 * deletes animation group.
78 /*******************************************************************************
79 * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
80 ******************************************************************************/
83 * @brief Called when view is resized.
85 * @param event resize event
87 void resizeEvent(QResizeEvent *event);
91 * @brief Event handler for mouse double click event
93 * Emits zoomIn signal.
94 * @param event QMouseEvent
96 void mouseDoubleClickEvent(QMouseEvent *event);
99 * @brief Event handler for mouse move events
101 * Does calculate mouse movement delta from last event position and new view center
102 * based on that delta. Saves current event position for next round. Emits viewScrolled
103 * signal and doesn't actually scroll the view.
105 * Saves mouse movement deltas and durations for last few move events to be used for
106 * calculating the kinetic scrolling speed.
108 * @param event Mouse event
110 void mouseMoveEvent(QMouseEvent *event);
113 * @brief Event handler for mouse press events
115 * Saves inial values for mouse and scene location for dragging the view. Does stop currently
116 * running kinetic scroll effect.
118 * @param event Mouse event
120 void mousePressEvent(QMouseEvent *event);
123 * @brief Event handler for mouse release events
125 * Set up and start kinetic scrolling effect if time elapsed from last mouseMoveEvent is below
126 * the limit and drag length is over the limit.
128 * Kinetic scroll distance is calculated based on mouse movement event values saved in
129 * mouseMoveEvent(). The distance is also limited so that map doesn't run too far.
131 * @param event Mouse event
133 void mouseReleaseEvent(QMouseEvent *event);
135 /*******************************************************************************
136 * MEMBER FUNCTIONS AND SLOTS
137 ******************************************************************************/
140 * @brief Slot for centering view to new location
142 * Does also shift the center point horizontally, if required.
144 * @param coordinate Scene coordinates of the new center point
145 * @param isUserDragAction True if caused by user dragging action. Does not shift the center
148 void centerToSceneCoordinates(const SceneCoordinate &coordinate, bool isUserDragAction = false);
151 * @brief Set zoom level of the view
153 * @param zoomLevel Zoom level
155 void setZoomLevel(int zoomLevel);
159 * @brief Disables shifting of the center point
161 void disableCenterShift();
164 * @brief Double tap zoom finished.
166 * Disables double tap zoom flag and emits zoomIn signal.
168 void doubleTapZoomFinished();
171 * @brief Enables shifting of the center point
173 void enableCenterShift();
177 * @brief Set new view scale
179 * @param viewScale New scaling factor
181 void setViewScale(qreal viewScale);
184 * @brief Set new view shifting
186 * @param viewShift New shifting amount
188 void setViewShift(qreal viewShift);
191 * @brief Update center shifting value
193 void updateCenterShift();
196 * @brief Get current view scale
198 * @return Current view scaling factor
200 qreal viewScale() const;
203 * @brief Get current view shifting
205 * @return Current view shifting amount
207 qreal viewShift() const;
209 /*******************************************************************************
211 ******************************************************************************/
214 * @brief Emitted when map center point shiftin is changed
216 * @param shifting New shifting value
218 void horizontalShiftingChanged(int shifting);
221 * @brief Signal for view resize events.
223 * Signal is emitted when view has been resized.
224 * @param size view size
226 void viewResized(const QSize &size);
229 * @brief Signal for view scroll events
231 * Signal is emitted when view is scrolled.
232 * @param coordinate Scene coordinates of the new center point of the view
233 * @param isUserDragAction True if caused by user dragging action
235 void viewScrolled(const SceneCoordinate &coordinate, bool isUserDragAction);
238 * @brief Signal for informing that zooming animation is finished
240 void viewZoomFinished();
243 * @brief Signal for informing that double click zoom is finished
247 /*******************************************************************************
249 ******************************************************************************/
251 bool m_doubleTapZoomRunning; ///< Double tap zoom running flag
253 int m_dragTime[VALUES]; ///< Table of mouse event durations
254 int m_index; ///< Current index of mouse event values table
255 int m_zoomLevel; ///< Current zoom level
257 qreal m_centerHorizontalShiftViewPixels; ///< Center point horizontal shift in the view
258 qreal m_kineticMaxViewDistance; ///< Maximum kinetic scroll distance in view pixels
260 QParallelAnimationGroup *m_scrollAndZoomAnimation; ///< Double click zoom animation
262 QPoint m_dragMovement[VALUES]; ///< Table of mouse event distances
263 QPoint m_internalScenePosition; ///< New center position (used for dragging)
264 QPoint m_lastMouseEventScenePosition; ///< Previous mouse event position in the scene
265 QPoint m_lastMouseEventViewPosition; ///< Previous mouse event position in the view
267 QPointF m_centerHorizontalShiftPoint; ///< Current amount of center point shifting
269 QPropertyAnimation *m_zoomAnimation; ///< Zoom animation
271 QTime m_time; ///< Elapsed time between mouse events
273 QPropertyAnimation *m_centerShiftAnimation; ///< Animation for shifting the center point
275 MapScroller *m_scroller; ///< Kinetic scroller
276 SceneCoordinate m_lastSetScenePosition; ///< Last center point coordinate set by MapEngine