Added new signals for min/max zoom levels and methods for disabling zoom in/out buttons
[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     /**
66     * @brief Called when view is displayed.
67     *
68     * @param event show event
69     */
70     void showEvent(QShowEvent *event);
71
72 private:
73     /**
74     * @brief Event handler for mouse move events
75     *
76     * Does calculate mouse movement delta from last event position and new view center
77     * based on that delta. Saves current event position for next round. Emits viewScrolled
78     * signal and doesn't actually scroll the view.
79     * @param event Mouse event
80     */
81     void mouseMoveEvent(QMouseEvent *event);
82
83     /**
84     * @brief Event handler for mouse press events
85     *
86     * Saves inial values for mouse and scene location for dragging view.
87     * @param event Mouse event
88     */
89     void mousePressEvent(QMouseEvent *event);
90
91 /*******************************************************************************
92  * MEMBER FUNCTIONS AND SLOTS
93  ******************************************************************************/
94 public slots:
95     /**
96     * @brief Slot for centering view to new location
97     *
98     * @param sceneCoordinate Scene coordinates of the new center point
99     */
100     void centerToSceneCoordinates(QPoint sceneCoordinate);
101
102     /**
103     * @brief Set zoom level of the view
104     *
105     * @param zoomLevel Zoom level
106     */
107     void setZoomLevel(int zoomLevel);
108
109 private:
110     /**
111     * @brief Set new view scale
112     *
113     * @param viewScale New scaling factor
114     */
115     void setViewScale(qreal viewScale);
116
117     /**
118     * @brief Get current view scale
119     *
120     * @return Current view scaling factor
121     */
122     qreal viewScale();
123
124 /*******************************************************************************
125  * SIGNALS
126  ******************************************************************************/
127 signals:
128     /**
129     * @brief Signal for view resize events.
130     *
131     * Signal is emitted when view has been resized.
132     * @param size view size
133     */
134     void viewResized(const QSize &size);
135
136     /**
137     * @brief Signal for view scroll events
138     *
139     * Signal is emitted when view is scrolled.
140     * @param sceneCoordinate Scene coordinates of the new center point of the view
141     */
142     void viewScrolled(QPoint sceneCoordinate);
143
144     /**
145     * @brief Signal for informing that zooming animation is finished
146     */
147     void viewZoomFinished();
148
149     /**
150     * @brief Signal for updating view content
151     *
152     * Signal is emitted when view content needs an update.
153     * @param viewTopLeft Scene coordinate of the viewport top left corner
154     */
155     void viewContentChanged(QPoint viewTopLeft);
156
157     /**
158     * @brief Signal for drawing OSM license
159     *
160     * Signal is emitted when view is resized.
161     * @param width Viewport width
162     * @param height Viewport height
163     */
164     void viewResizedNewSize(int width, int height);
165
166 /*******************************************************************************
167  * DATA MEMBERS
168  ******************************************************************************/
169 private:
170     QPoint m_mousePosition; ///< Previous mouse event position
171     QPoint m_scenePosition; ///< New center position
172     QPropertyAnimation *m_zoomAnimation; ///< Zoom animation
173 };
174
175 #endif // MAPVIEW_H