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 Event handler for mouse double click event
68 * Emits zoomIn signal.
69 * @param event QMouseEvent
71 void mouseDoubleClickEvent(QMouseEvent *event);
74 * @brief Called when view is resized.
76 * @param event resize event
78 void resizeEvent(QResizeEvent *event);
81 void mouseDoubleClickEvent(QMouseEvent *event);
84 * @brief Event handler for mouse move events
86 * Does calculate mouse movement delta from last event position and new view center
87 * based on that delta. Saves current event position for next round. Emits viewScrolled
88 * signal and doesn't actually scroll the view.
90 * Saves mouse movement deltas and durations for last few move events to be used for
91 * calculating the kinetic scrolling speed.
93 * @param event Mouse event
95 void mouseMoveEvent(QMouseEvent *event);
98 * @brief Event handler for mouse press events
100 * Saves inial values for mouse and scene location for dragging the view. Does stop currently
101 * running kinetic scroll effect.
103 * @param event Mouse event
105 void mousePressEvent(QMouseEvent *event);
108 * @brief Event handler for mouse release events
110 * Set up and start kinetic scrolling effect if time elapsed from last mouseMoveEvent is below
111 * the limit and drag length is over the limit.
113 * Kinetic scroll distance is calculated based on mouse movement event values saved in
116 * @param event Mouse event
118 void mouseReleaseEvent(QMouseEvent *event);
120 /*******************************************************************************
121 * MEMBER FUNCTIONS AND SLOTS
122 ******************************************************************************/
125 * @brief Slot for centering view to new location
127 * @param sceneCoordinate Scene coordinates of the new center point
129 void centerToSceneCoordinates(QPoint sceneCoordinate);
132 * @brief Set zoom level of the view
134 * @param zoomLevel Zoom level
136 void setZoomLevel(int zoomLevel);
140 * @brief Set new view scale
142 * @param viewScale New scaling factor
144 void setViewScale(qreal viewScale);
147 * @brief Get current view scale
149 * @return Current view scaling factor
153 /*******************************************************************************
155 ******************************************************************************/
158 * @brief Signal for view resize events.
160 * Signal is emitted when view has been resized.
161 * @param size view size
163 void viewResized(const QSize &size);
166 * @brief Signal for view scroll events
168 * Signal is emitted when view is scrolled.
169 * @param sceneCoordinate Scene coordinates of the new center point of the view
171 void viewScrolled(QPoint sceneCoordinate);
174 * @brief Signal for informing that zooming animation is finished
176 void viewZoomFinished();
180 /*******************************************************************************
182 ******************************************************************************/
184 int m_dragTime[VALUES]; ///< Table of mouse event durations
185 int m_index; ///< Index of mouse event values tables
186 int m_zoomLevel; ///< Current zoom level
188 QPoint m_dragMovement[VALUES]; ///< Table of mouse event distances
189 QPoint m_mouseLastScenePosition; ///< Previous mouse event position in the scene
190 QPoint m_mouseLastViewPosition; ///< Previous mouse event position in the view
191 QPoint m_scenePosition; ///< New center position
193 QPropertyAnimation *m_zoomAnimation; ///< Zoom animation
194 QParallelAnimationGroup *m_groupAnimation;
196 QTime m_time; ///< Elapsed times in mouse events
198 MapScroller *m_scroller; ///< Kinetic scroller
200 QParallelAnimationGroup *m_group;