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;
37 * @brief Map view widget
39 * @author Sami Rämö - sami.ramo (at) ixonos.com
40 * @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
42 class MapView : public QGraphicsView
51 Q_PROPERTY(qreal viewScale READ viewScale WRITE setViewScale)
57 * @param parent Parent
59 MapView(QWidget *parent = 0);
64 * Takes MapScroller animation from double click zoom animation group and
65 * deletes animation group.
69 /*******************************************************************************
70 * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
71 ******************************************************************************/
74 * @brief Called when view is resized.
76 * @param event resize event
78 void resizeEvent(QResizeEvent *event);
82 * @brief Event handler for mouse double click event
84 * Emits zoomIn signal.
85 * @param event QMouseEvent
87 void mouseDoubleClickEvent(QMouseEvent *event);
90 * @brief Event handler for mouse move events
92 * Does calculate mouse movement delta from last event position and new view center
93 * based on that delta. Saves current event position for next round. Emits viewScrolled
94 * signal and doesn't actually scroll the view.
96 * Saves mouse movement deltas and durations for last few move events to be used for
97 * calculating the kinetic scrolling speed.
99 * @param event Mouse event
101 void mouseMoveEvent(QMouseEvent *event);
104 * @brief Event handler for mouse press events
106 * Saves inial values for mouse and scene location for dragging the view. Does stop currently
107 * running kinetic scroll effect.
109 * @param event Mouse event
111 void mousePressEvent(QMouseEvent *event);
114 * @brief Event handler for mouse release events
116 * Set up and start kinetic scrolling effect if time elapsed from last mouseMoveEvent is below
117 * the limit and drag length is over the limit.
119 * Kinetic scroll distance is calculated based on mouse movement event values saved in
122 * @param event Mouse event
124 void mouseReleaseEvent(QMouseEvent *event);
126 /*******************************************************************************
127 * MEMBER FUNCTIONS AND SLOTS
128 ******************************************************************************/
131 * @brief Slot for centering view to new location
133 * @param sceneCoordinate Scene coordinates of the new center point
135 void centerToSceneCoordinates(QPoint sceneCoordinate);
138 * @brief Set zoom level of the view
140 * @param zoomLevel Zoom level
142 void setZoomLevel(int zoomLevel);
146 * @brief Double tap zoom finished.
148 * Disables double tap zoom flag and emits zoomIn signal.
150 void doubleTapZoomFinished();
154 * @brief Set new view scale
156 * @param viewScale New scaling factor
158 void setViewScale(qreal viewScale);
161 * @brief Get current view scale
163 * @return Current view scaling factor
167 /*******************************************************************************
169 ******************************************************************************/
172 * @brief Signal for view resize events.
174 * Signal is emitted when view has been resized.
175 * @param size view size
177 void viewResized(const QSize &size);
180 * @brief Signal for view scroll events
182 * Signal is emitted when view is scrolled.
183 * @param sceneCoordinate Scene coordinates of the new center point of the view
185 void viewScrolled(QPoint sceneCoordinate);
188 * @brief Signal for informing that zooming animation is finished
190 void viewZoomFinished();
193 * @brief Signal for informing that double click zoom is finished
197 /*******************************************************************************
199 ******************************************************************************/
201 bool m_doubleTapZoomRunning; ///< Double tap zoom running flag
203 int m_dragTime[VALUES]; ///< Table of mouse event durations
204 int m_index; ///< Index of mouse event values tables
205 int m_zoomLevel; ///< Current zoom level
207 QPoint m_dragMovement[VALUES]; ///< Table of mouse event distances
208 QPoint m_mouseLastScenePosition; ///< Previous mouse event position in the scene
209 QPoint m_mouseLastViewPosition; ///< Previous mouse event position in the view
210 QPoint m_scenePosition; ///< New center position
212 QParallelAnimationGroup *m_scrollAndZoomAnimation; ///< Double click zoom animation
213 QPropertyAnimation *m_zoomAnimation; ///< Zoom animation
215 QTime m_time; ///< Elapsed times in mouse events
217 MapScroller *m_scroller; ///< Kinetic scroller