Merge branch 'crosshair2'
[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 #include <QPropertyAnimation>
28
29 /**
30 * @brief Map view widget
31 *
32 * @author Sami Rämö - sami.ramo (at) ixonos.com
33 * @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
34 */
35 class MapView : public QGraphicsView
36 {
37     Q_OBJECT
38
39     /**
40     * @brief View scaling
41     *
42     * @property viewScale
43     */
44     Q_PROPERTY(qreal viewScale READ viewScale WRITE setViewScale)
45
46 public:
47     /**
48     * @brief Constructor
49     *
50     * @param parent Parent
51     */
52     MapView(QWidget *parent = 0);
53
54 /*******************************************************************************
55  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
56  ******************************************************************************/
57 protected:
58     /**
59     * @brief Called when view is resized.
60     *
61     * @param event resize event
62     */
63     void resizeEvent(QResizeEvent *event);
64
65 private:
66     /**
67     * @brief Event handler for mouse move events
68     *
69     * Does calculate mouse movement delta from last event position and new view center
70     * based on that delta. Saves current event position for next round. Emits viewScrolled
71     * signal and doesn't actually scroll the view.
72     * @param event Mouse event
73     */
74     void mouseMoveEvent(QMouseEvent *event);
75
76     /**
77     * @brief Event handler for mouse press events
78     *
79     * Saves inial values for mouse and scene location for dragging view.
80     * @param event Mouse event
81     */
82     void mousePressEvent(QMouseEvent *event);
83
84 /*******************************************************************************
85  * MEMBER FUNCTIONS AND SLOTS
86  ******************************************************************************/
87 public slots:
88     /**
89     * @brief Slot for centering view to new location
90     *
91     * @param sceneCoordinate Scene coordinates of the new center point
92     */
93     void centerToSceneCoordinates(QPoint sceneCoordinate);
94
95     /**
96     * @brief Set zoom level of the view
97     *
98     * @param zoomLevel Zoom level
99     */
100     void setZoomLevel(int zoomLevel);
101
102     /**
103     * @brief updates view ports content
104     */
105     void updateViewPortContent();
106
107     /**
108     * @brief Slot for catching request to get view port contents.
109     * implementation of this slot sends signal that includes visble area of view port.
110     */
111     QRect viewportContent();
112
113 private:
114     /**
115     * @brief Set new view scale
116     *
117     * @param viewScale New scaling factor
118     */
119     void setViewScale(qreal viewScale);
120
121     /**
122     * @brief Get current view scale
123     *
124     * @return Current view scaling factor
125     */
126     qreal viewScale();
127
128 /*******************************************************************************
129  * SIGNALS
130  ******************************************************************************/
131 signals:
132     /**
133     * @brief Signal for view resize events.
134     *
135     * Signal is emitted when view has been resized.
136     * @param size view size
137     */
138     void viewResized(const QSize &size);
139
140     /**
141     * @brief Signal for view scroll events
142     *
143     * Signal is emitted when view is scrolled.
144     * @param sceneCoordinate Scene coordinates of the new center point of the view
145     */
146     void viewScrolled(QPoint sceneCoordinate);
147
148     /**
149     * @brief Signal for informing that zooming animation is finished
150     */
151     void viewZoomFinished();
152
153     /**
154     * @brief Signal for updating view content
155     *
156     * Signal is emitted when view content needs an update.
157     * @param viewTopLeft Scene coordinate of the viewport top left corner
158     */
159     void viewContentChanged(QPoint viewTopLeft);
160
161     /**
162     * @brief Signal that sends visible area of map scene
163     *
164     * @param viewArea visible area of map scene
165     */
166     void updateViewContent(QRect viewArea);
167
168     /**
169     * @brief Signal for drawing OSM license
170     *
171     * Signal is emitted when view is resized.
172     * @param width Viewport width
173     * @param height Viewport height
174     */
175     void viewResizedNewSize(int width, int height);
176
177 /*******************************************************************************
178  * DATA MEMBERS
179  ******************************************************************************/
180 private:
181     QPoint m_mousePosition; ///< Previous mouse event position
182     QPoint m_scenePosition; ///< New center position
183     QPropertyAnimation *m_zoomAnimation; ///< Zoom animation
184 };
185
186 #endif // MAPVIEW_H