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 * @param coordinate Scene coordinates of the new center point
137 void centerToSceneCoordinates(const SceneCoordinate &coordinate, bool isUserDragAction = false);
140 * @brief Set zoom level of the view
142 * @param zoomLevel Zoom level
144 void setZoomLevel(int zoomLevel);
147 void disableCenterShift();
150 * @brief Double tap zoom finished.
152 * Disables double tap zoom flag and emits zoomIn signal.
154 void doubleTapZoomFinished();
156 void enableCenterShift();
160 * @brief Set new view scale
162 * @param viewScale New scaling factor
164 void setViewScale(qreal viewScale);
166 void toggleCenterShift(bool enabled);
168 void updateCenterShift();
171 * @brief Get current view scale
173 * @return Current view scaling factor
177 /*******************************************************************************
179 ******************************************************************************/
182 * @brief Signal for view resize events.
184 * Signal is emitted when view has been resized.
185 * @param size view size
187 void viewResized(const QSize &size);
190 * @brief Signal for view scroll events
192 * Signal is emitted when view is scrolled.
193 * @param coordinate Scene coordinates of the new center point of the view
195 void viewScrolled(const SceneCoordinate &coordinate, bool isUserDragAction);
198 * @brief Signal for informing that zooming animation is finished
200 void viewZoomFinished();
203 * @brief Signal for informing that double click zoom is finished
207 /*******************************************************************************
209 ******************************************************************************/
211 bool m_centerShiftEnabled;
212 bool m_doubleTapZoomRunning; ///< Double tap zoom running flag
214 int m_dragTime[VALUES]; ///< Table of mouse event durations
215 int m_index; ///< Index of mouse event values tables
216 int m_zoomLevel; ///< Current zoom level
218 qreal m_kineticMaxViewDistance; ///< Maximum kinetic scroll distance in view pixels
220 QPoint m_dragMovement[VALUES]; ///< Table of mouse event distances
221 QPoint m_internalScenePosition; ///< New center position
222 QPoint m_lastMouseEventScenePosition; ///< Previous mouse event position in the scene
223 QPoint m_lastMouseEventViewPosition; ///< Previous mouse event position in the view
225 QPointF m_centerHorizontalShift;
227 QParallelAnimationGroup *m_scrollAndZoomAnimation; ///< Double click zoom animation
228 QPropertyAnimation *m_zoomAnimation; ///< Zoom animation
230 QTime m_time; ///< Elapsed times in mouse events
232 MapScroller *m_scroller; ///< Kinetic scroller
233 SceneCoordinate m_lastSetScenePosition;