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);
61 /*******************************************************************************
62 * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
63 ******************************************************************************/
66 * @brief Called when view is resized.
68 * @param event resize event
70 void resizeEvent(QResizeEvent *event);
74 * @brief Event handler for mouse double click event
76 * Emits zoomIn signal.
77 * @param event QMouseEvent
79 void mouseDoubleClickEvent(QMouseEvent *event);
82 * @brief Event handler for mouse move events
84 * Does calculate mouse movement delta from last event position and new view center
85 * based on that delta. Saves current event position for next round. Emits viewScrolled
86 * signal and doesn't actually scroll the view.
88 * Saves mouse movement deltas and durations for last few move events to be used for
89 * calculating the kinetic scrolling speed.
91 * @param event Mouse event
93 void mouseMoveEvent(QMouseEvent *event);
96 * @brief Event handler for mouse press events
98 * Saves inial values for mouse and scene location for dragging the view. Does stop currently
99 * running kinetic scroll effect.
101 * @param event Mouse event
103 void mousePressEvent(QMouseEvent *event);
106 * @brief Event handler for mouse release events
108 * Set up and start kinetic scrolling effect if time elapsed from last mouseMoveEvent is below
109 * the limit and drag length is over the limit.
111 * Kinetic scroll distance is calculated based on mouse movement event values saved in
114 * @param event Mouse event
116 void mouseReleaseEvent(QMouseEvent *event);
118 /*******************************************************************************
119 * MEMBER FUNCTIONS AND SLOTS
120 ******************************************************************************/
123 * @brief Slot for centering view to new location
125 * @param sceneCoordinate Scene coordinates of the new center point
127 void centerToSceneCoordinates(QPoint sceneCoordinate);
130 * @brief Set zoom level of the view
132 * @param zoomLevel Zoom level
134 void setZoomLevel(int zoomLevel);
138 * @brief Set new view scale
140 * @param viewScale New scaling factor
142 void setViewScale(qreal viewScale);
145 * @brief Get current view scale
147 * @return Current view scaling factor
151 /*******************************************************************************
153 ******************************************************************************/
156 * @brief Signal for view resize events.
158 * Signal is emitted when view has been resized.
159 * @param size view size
161 void viewResized(const QSize &size);
164 * @brief Signal for view scroll events
166 * Signal is emitted when view is scrolled.
167 * @param sceneCoordinate Scene coordinates of the new center point of the view
169 void viewScrolled(QPoint sceneCoordinate);
172 * @brief Signal for informing that zooming animation is finished
174 void viewZoomFinished();
178 /*******************************************************************************
180 ******************************************************************************/
182 int m_dragTime[VALUES]; ///< Table of mouse event durations
183 int m_index; ///< Index of mouse event values tables
184 int m_zoomLevel; ///< Current zoom level
186 QPoint m_dragMovement[VALUES]; ///< Table of mouse event distances
187 QPoint m_mouseLastScenePosition; ///< Previous mouse event position in the scene
188 QPoint m_mouseLastViewPosition; ///< Previous mouse event position in the view
189 QPoint m_scenePosition; ///< New center position
191 QPropertyAnimation *m_zoomAnimation; ///< Zoom animation
192 QParallelAnimationGroup *m_groupAnimation;
194 QTime m_time; ///< Elapsed times in mouse events
196 MapScroller *m_scroller; ///< Kinetic scroller
198 QParallelAnimationGroup *m_group;