Fixed FacebookLoginBrowser::destroyed() signal handling
[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      * @brief Desctructor
57      * Destroys m_normalColor
58      */
59     ~IndicatorButtonPanel();
60
61 /*******************************************************************************
62  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
63  ******************************************************************************/
64 protected:
65     /**
66      * @brief Move event for the indicator button panel
67      *
68      * @param event Event
69      */
70     void mouseMoveEvent(QMouseEvent *event);
71
72     /**
73      * @brief Press event for the indicator button panel
74      *
75      * @param event Event
76      */
77     void mousePressEvent(QMouseEvent *event);
78
79     /**
80      * @brief Event handler for mouse release events
81      *
82      * @param event Mouse event
83      */
84     void mouseReleaseEvent(QMouseEvent *event);
85
86     /**
87      * @brief Event handler for paint events
88      *
89      * Paints the panel
90      * @param event Paint event
91      */
92     void paintEvent(QPaintEvent *event);
93
94 /*******************************************************************************
95  * MEMBER FUNCTIONS AND SLOTS
96  ******************************************************************************/
97 public slots:
98     /**
99      * @brief Called when direction and distance from current map center point to current GPS
100      *        location is changed
101      *
102      * @param direction Direction in degrees
103      * @param distance Distance in meters
104      * @param draw Should the indicator triangle be drawn or not
105      */
106     void updateValues(qreal direction, qreal distance, bool draw);
107
108     /**
109      * @brief Set indicator button enabled.
110      *
111      * @param enabled true if enabled, false otherwise
112      */
113     void setIndicatorButtonEnabled(bool enabled);
114
115     /**
116      * @brief Toggle indicator button panel draggability
117      *
118      * @param mode True if draggable, otherwise false
119      * @param eventPosition Start position of the dragging
120      */
121     void setDraggable(bool mode, QPoint eventPosition = QPoint(0,0));
122
123     /**
124      * @brief Slot to redraw the panel after window resize event
125      *
126      * @param size Size of the new screen
127      */
128     void screenResized(const QSize &size);
129
130 private slots:
131     /**
132      * @brief Safeguard slot to release mouse grab if something goes horribly wrong
133      */
134     void forceMouseRelease();
135
136     /**
137      * @brief Slot that handles drag initialization once timer has timed out
138      */
139     void timerExpired();
140
141 /*******************************************************************************
142  * SIGNALS
143  ******************************************************************************/
144 signals:
145     /**
146      * @brief Automatic centering setting changed by user
147      *
148      * @param enabled True if automatic centering is enabled, otherwise false
149      */
150     void autoCenteringTriggered(bool enabled);
151
152     /**
153      * @brief Signal when direction and distance from current map center point to current GPS
154      *        location is changed
155      *
156      * @param direction Direction in degrees
157      * @param distance Distance in meters
158      * @param draw Should the indicator triangle be drawn or not
159      */
160     void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
161
162     /**
163      * @brief Dragging mode triggered.
164      */
165     void draggingModeTriggered();
166
167 /*******************************************************************************
168  * DATA MEMBERS
169  ******************************************************************************/
170 private:
171     bool m_isDraggable;                     ///< Boolean for tracking the draggability state
172
173     qreal m_distance;                       ///< Distance to the GPS position
174
175     QColor *m_normalColor;                  ///< Normal background color
176
177     QLabel *m_distanceTextLabel;            ///< Pointer to distanceTextLabel
178
179     QPoint m_dragPosition;                  ///< Location from where the widget is grabbed
180
181     QSize m_screenSize;                     ///< Store for the screen size
182
183     QString m_distanceText;                 ///< Text description of the distance
184
185     QTimer *m_dragStartTimer;               ///< Timer to init draggability of the zoom panel
186     QTimer *m_forceReleaseTimer;            ///< Timer to run forceMouseRelease;
187
188     IndicatorButton *m_indicatorButton;     ///< Indicator button
189 };
190
191 #endif // INDICATORBUTTONPANEL_H