Self made kinetic scrolling first working version
[situare] / src / map / mapview.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Sami Rämö - sami.ramo@ixonos.com
6        Pekka Nissinen - pekka.nissinen@ixonos.com
7
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.
11
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.
16
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,
20    USA.
21 */
22
23 #ifndef MAPVIEW_H
24 #define MAPVIEW_H
25
26 #include <QGraphicsView>
27
28 class QPropertyAnimation;
29
30 class MapScroller;
31
32 /**
33 * @brief Map view widget
34 *
35 * @author Sami Rämö - sami.ramo (at) ixonos.com
36 * @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
37 */
38 class MapView : public QGraphicsView
39 {
40     Q_OBJECT
41
42     /**
43     * @brief View scaling
44     *
45     * @property viewScale
46     */
47     Q_PROPERTY(qreal viewScale READ viewScale WRITE setViewScale)
48
49 public:
50     /**
51     * @brief Constructor
52     *
53     * @param parent Parent
54     */
55     MapView(QWidget *parent = 0);
56
57 /*******************************************************************************
58  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
59  ******************************************************************************/
60 protected:
61     /**
62     * @brief Called when view is resized.
63     *
64     * @param event resize event
65     */
66     void resizeEvent(QResizeEvent *event);
67
68 private:
69     /**
70     * @brief Event handler for mouse move events
71     *
72     * Does calculate mouse movement delta from last event position and new view center
73     * based on that delta. Saves current event position for next round. Emits viewScrolled
74     * signal and doesn't actually scroll the view.
75     * @param event Mouse event
76     */
77     void mouseMoveEvent(QMouseEvent *event);
78
79     /**
80     * @brief Event handler for mouse press events
81     *
82     * Saves inial values for mouse and scene location for dragging view.
83     * @param event Mouse event
84     */
85     void mousePressEvent(QMouseEvent *event);
86
87     void mouseReleaseEvent(QMouseEvent *event);
88
89 /*******************************************************************************
90  * MEMBER FUNCTIONS AND SLOTS
91  ******************************************************************************/
92 public slots:
93     /**
94     * @brief Slot for centering view to new location
95     *
96     * @param sceneCoordinate Scene coordinates of the new center point
97     */
98     void centerToSceneCoordinates(QPoint sceneCoordinate);
99
100     /**
101     * @brief Set zoom level of the view
102     *
103     * @param zoomLevel Zoom level
104     */
105     void setZoomLevel(int zoomLevel);
106
107 private:
108     /**
109     * @brief Set new view scale
110     *
111     * @param viewScale New scaling factor
112     */
113     void setViewScale(qreal viewScale);
114
115     /**
116     * @brief Get current view scale
117     *
118     * @return Current view scaling factor
119     */
120     qreal viewScale();
121
122 /*******************************************************************************
123  * SIGNALS
124  ******************************************************************************/
125 signals:
126     /**
127     * @brief Signal for view resize events.
128     *
129     * Signal is emitted when view has been resized.
130     * @param size view size
131     */
132     void viewResized(const QSize &size);
133
134     /**
135     * @brief Signal for view scroll events
136     *
137     * Signal is emitted when view is scrolled.
138     * @param sceneCoordinate Scene coordinates of the new center point of the view
139     */
140     void viewScrolled(QPoint sceneCoordinate);
141
142     /**
143     * @brief Signal for informing that zooming animation is finished
144     */
145     void viewZoomFinished();
146
147 /*******************************************************************************
148  * DATA MEMBERS
149  ******************************************************************************/
150 private:
151     int m_zoomLevel;
152
153     QPoint m_dragViewSpeed;
154     QPoint m_mouseLastScenePosition;               ///< Previous mouse event position
155     QPoint m_mouseLastViewPosition;
156     QPoint m_scenePosition;               ///< New center position
157     QPropertyAnimation *m_zoomAnimation;  ///< Zoom animation
158
159     MapScroller *m_scroller;
160 };
161
162 #endif // MAPVIEW_H