d92a4d2b0b8e93908bf28aef83a6cd38ef8f64fe
[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
7    Situare is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License
9    version 2 as published by the Free Software Foundation.
10
11    Situare is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with Situare; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19    USA.
20 */
21
22 #ifndef MAPVIEW_H
23 #define MAPVIEW_H
24
25 #include <QGraphicsView>
26
27 /**
28 * @brief Map view widget
29 *
30 * QAbstractKineticScroller is enabled when built for Maemo5.
31 * @author Sami Rämö - sami.ramo (at) ixonos.com
32 */
33 class MapView : public QGraphicsView
34 {
35     Q_OBJECT
36 public:
37     /**
38     * @brief Constructor
39     *
40     * @param parent Parent
41     */
42     MapView(QWidget *parent = 0);
43
44 protected:
45     void scrollContentsBy(int dx, int dy);
46
47 private:
48     //
49     /**
50     * @brief get current horizontal scale (vertical should be same)
51     *
52     * @return qreal Current horizontal scale value
53     */
54     qreal currentScale();
55
56 signals:
57     /**
58     * @brief Signal for view scroll events
59     *
60     * Signal is emitted when view scroll is requested with mouse (or finger).
61     * @param sceneCoordinate Scene coordinates of the new requested center point of the view
62     */
63     void viewScrolled(QPointF sceneCoordinate);
64
65     void viewResized(const QSize &size);
66
67 public slots:
68     /**
69     * @brief Slot for centering view to new location
70     *
71     * @param sceneCoordinate Scene coordinates of the new center point
72     */
73     void centerToSceneCoordinates(QPointF sceneCoordinate);
74
75     /**
76     * @brief Set zoom level of the view
77     *
78     * @param zoomLevel Zoom level
79     */
80     void setZoomLevel(int zoomLevel);
81
82 protected:
83     void resizeEvent(QResizeEvent *event);
84
85 private slots:
86     /**
87     * @brief Slot for mouse move events
88     *
89     * Does calculate mouse movement delta from last event position and new view center
90     * based on that delta. Saves current event position for next round. Emits viewScrolled
91     * signal and doesn't actually scroll the view.
92     * @param event Mouse event
93     */
94 //    void mouseMoveEvent(QMouseEvent *event);
95
96     /**
97     * @brief Slot for mouse press events
98     *
99     * Saves inial values for mouse and scene location for dragging view.
100     * @param event Mouse event
101     */
102 //    void mousePressEvent(QMouseEvent *event);
103
104     /**
105     * @brief Timer events for smooth zoom effect
106     *
107     * @param event
108     */
109     void timerEvent(QTimerEvent *event);
110
111 private:
112     QPointF m_mousePosition; ///< Previous mouse event position
113     QPointF m_scenePosition; ///< New center position
114     qreal m_zoomTargetScale; ///< Scaling factor of the target zoom level
115     qreal m_zoomScaleDelta; ///< Scaling factor delta for smooth zoom transition effect
116 };
117
118 #endif // MAPVIEW_H