Few minor cosmetic changes here and there
[situare] / src / ui / indicatorbutton.h
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Kaj Wallin - kaj.wallin@ixonos.com
6         Katri Kaikkonen - katri.kaikkonen@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 INDICATORBUTTON_H
24 #define INDICATORBUTTON_H
25
26 #include <QMouseEvent>
27 #include <QTimer>
28 #include <QToolButton>
29 #include <QWidget>
30
31 #include "../user/user.h"
32
33 /**
34  * @brief Indicator button class
35  *
36  * @class IndicatorButton indicatorbutton.h "ui/indicatorbutton.h"
37  * @author Katri Kaikkonen - katri.kaikkonen (at) ixonos.com
38  */
39 class IndicatorButton : public  QToolButton
40 {
41    Q_OBJECT
42
43 public:
44    /**
45     * @brief Constructor
46     *
47     * @param parent Parent widget
48     */
49    IndicatorButton(QWidget *parent = 0);
50
51    /**
52     * @brief Desctructor
53     */
54    ~IndicatorButton();
55
56 /*******************************************************************************
57  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
58  ******************************************************************************/
59 protected:
60    /**
61     * @brief Move event for the distance indicator button
62     *
63     * @param event Mouse event
64     */
65    void mouseMoveEvent(QMouseEvent *event);
66
67    /**
68     * @brief Press event for the distance indicator button
69     *
70     * @param event Mouse event
71     */
72    void mousePressEvent(QMouseEvent *event);
73
74    /**
75     * @brief Event handler for mouse release events
76     *
77     * @param event Mouse event
78     */
79    void mouseReleaseEvent(QMouseEvent *event);
80
81     /**
82      * @brief Event handler for paint events
83      *
84      * Paints the button and its icon
85      * @param event Paint event
86      */
87     void paintEvent(QPaintEvent *event);
88
89 /*******************************************************************************
90  * MEMBER FUNCTIONS AND SLOTS
91  ******************************************************************************/
92 public slots:
93     /**
94      * @brief Relative position of the event inside the widget
95      */
96     const QPoint& eventPosition();
97
98     /**
99      * @brief Slot to redraw the panel after window resize event
100      *
101      * @param size Size of the new screen
102      */
103     void screenResized(const QSize &size);
104
105     /**
106      * @brief Toggle distance indicator button draggability
107      */
108     void setDraggable(bool mode, QPoint eventPosition = QPoint(0,0));
109
110 private slots:
111     /**
112      * @brief Safeguard slot to release mouse grab if something goes horribly wrong
113      */
114     void forceMouseRelease();
115
116     /**
117      * @brief Slot that handles drag initialization once timer has timed out
118      */
119     void timerExpired();
120
121 /*******************************************************************************
122  * SIGNALS
123  ******************************************************************************/
124 signals:
125     /**
126      * @brief Automatic centering setting changed by user
127      *
128      * @param enabled True if automatic centering is enabled, otherwise false
129      */
130     void autoCenteringTriggered(bool enabled);
131
132 /*******************************************************************************
133  * DATA MEMBERS
134  ******************************************************************************/
135 private:
136
137     bool m_isDraggable;             ///< Boolean for tracking the draggability state
138
139     QColor *m_normalColor;                  ///< Normal background color
140
141     QLinearGradient *m_selectedGradient;    ///< Selected background
142
143     QPainterPath m_backgroundPath;          ///< Item shape path
144
145     QPixmap m_indicatorLeds[2];             ///< Placeholder for images
146
147     QPoint m_dragPosition;          ///< Location from where the widget is grabbed
148     QPoint m_eventPosition;         ///< Position of mousePressEvent
149
150     QSize m_screenSize;             ///< Store for the screen size
151
152     QTimer *m_dragStartTimer;       ///< Timer to init draggability of the distance indicator button
153     QTimer *m_forceReleaseTimer;    ///< Timer to run forceMouseRelease
154 };
155
156 #endif // INDICATORBUTTON_H