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