Fixing defects found in the review
[situare] / src / ui / indicatorbuttonpanel.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Pekka Nissinen - pekka.nissinen@ixonos.com
6        Kaj Wallin - kaj.wallin@ixonos.com
7        Katri Kaikkonen - katri.kaikkonen@ixonos.com
8
9    Situare is free software; you can redistribute it and/or
10    modify it under the terms of the GNU General Public License
11    version 2 as published by the Free Software Foundation.
12
13    Situare is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with Situare; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
21    USA.
22 */
23
24 #ifndef INDICATORBUTTONPANEL_H
25 #define INDICATORBUTTONPANEL_H
26
27 #include <QGraphicsItem>
28 #include <QGridLayout>
29 #include <QLabel>
30 #include <QMouseEvent>
31 #include <QTimer>
32 #include <QWidget>
33
34 #include "indicatorbutton.h"
35
36 /**
37  * @brief Draggable panel for indicator button
38  *
39  * @author Katri Kaikkonen - katri.kaikkonen (at) ixonos.com
40  * @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
41  * @author Kaj Wallin - kaj.wallin (at) ixonos.com
42  */
43 class IndicatorButtonPanel : public QWidget
44 {
45     Q_OBJECT
46
47 public:
48     /**
49      * @brief Constructor
50      *
51      * @param parent Parent
52      */
53     IndicatorButtonPanel(QWidget *parent = 0);
54
55 /*******************************************************************************
56  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
57  ******************************************************************************/
58 protected:
59     /**
60      * @brief Move event for the indicator button panel
61      *
62      * @param event Event
63      */
64     void mouseMoveEvent(QMouseEvent *event);
65
66     /**
67      * @brief Press event for the indicator button panel
68      *
69      * @param event Event
70      */
71     void mousePressEvent(QMouseEvent *event);
72
73     /**
74      * @brief Event handler for mouse release events
75      *
76      * @param event Mouse event
77      */
78     void mouseReleaseEvent(QMouseEvent *event);
79
80     /**
81      * @brief Event handler for paint events
82      *
83      * Paints the panel
84      * @param event Paint event
85      */
86     void paintEvent(QPaintEvent *event);
87
88 /*******************************************************************************
89  * MEMBER FUNCTIONS AND SLOTS
90  ******************************************************************************/
91 public slots:
92     /**
93      * @brief Called when direction and distance from current map center point to current GPS
94      *        location is changed
95      *
96      * @param direction Direction in degrees
97      * @param distance Distance in meters
98      * @param draw Should the indicator triangle be drawn or not
99      */
100     void updateValues(qreal direction, qreal distance, bool draw);
101
102     /**
103      * @brief Set indicator button enabled.
104      *
105      * @param enabled true if enabled, false otherwise
106      */
107     void setIndicatorButtonEnabled(bool enabled);
108
109     /**
110      * @brief Toggle zoom panel draggability
111      *
112      * @param mode True if draggable, otherwise false
113      * @param distance Start value for dragging
114      */
115     void setDraggable(bool mode, QPoint eventPosition = QPoint(0,0));
116
117     /**
118      * @brief Slot to redraw the panel after window resize event
119      *
120      * @param size Size of the new screen
121      */
122     void screenResized(const QSize &size);
123
124 private slots:
125     /**
126      * @brief Safeguard slot to release mouse grab if something goes horribly wrong
127      */
128     void forceMouseRelease();
129
130     /**
131      * @brief Slot that handles drag initialization once timer has timed out
132      */
133     void timerExpired();
134
135 /*******************************************************************************
136  * SIGNALS
137  ******************************************************************************/
138 signals:
139     /**
140      * @brief Automatic centering setting changed by user
141      *
142      * @param enabled True if automatic centering is enabled, otherwise false
143      */
144     void autoCenteringTriggered(bool enabled);
145
146     /**
147      * @brief Signal when direction and distance from current map center point to current GPS
148      *        location is changed
149      *
150      * @param direction Direction in degrees
151      * @param distance Distance in meters
152      * @param draw Should the indicator triangle be drawn or not
153      */
154     void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
155
156     /**
157      * @brief Dragging mode triggered.
158      */
159     void draggingModeTriggered();
160
161 /*******************************************************************************
162  * DATA MEMBERS
163  ******************************************************************************/
164 private:
165     bool m_isDraggable;                     ///< Boolean for tracking the draggability state
166
167     qreal m_distance;                       ///< Distance to the GPS position
168
169     QColor *m_normalColor;                  ///< Normal background color
170
171     QLabel *m_distanceTextLabel;            ///< Pointer to distanceTextLabel
172
173     QPoint m_dragPosition;                  ///< Location from where the widget is grabbed
174
175     QSize m_screenSize;                     ///< Store for the screen size
176
177     QString m_distanceText;                 ///< Text description of the distance
178
179     QTimer *m_dragStartTimer;               ///< Timer to init draggability of the zoom panel
180     QTimer *m_forceReleaseTimer;            ///< Timer to run forceMouseRelease;
181
182     IndicatorButton *m_indicatorButton;     ///< Indicator button
183 };
184
185 #endif // INDICATORBUTTONPANEL_H