Added signals
[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 <QWidget>
27 #include <QToolButton>
28 #include <QTimer>
29 #include <QMouseEvent>
30 #include <QPaintEvent>
31 #include "../user/user.h"
32
33 /**
34 * @brief Indicator button class
35 *
36 * @class IndicatorButton indicatorbutton.h "ui/indicatorbutton.h"
37 */
38 class IndicatorButton : public  QToolButton
39 {
40    Q_OBJECT
41
42 public:
43    /**
44     * @brief Constructor
45     *
46     * @param parent Parent widget
47     */
48    IndicatorButton(QWidget *parent = 0);
49
50 /*******************************************************************************
51 * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
52 ******************************************************************************/
53 protected:
54
55    /**
56     * @brief Move event for the distance indicator button
57     *
58     * @param event Event
59     */
60    void mouseMoveEvent(QMouseEvent *event);
61
62    /**
63     * @brief Press event for the distance indicator button
64     *
65     * @param event Event
66     */
67    void mousePressEvent(QMouseEvent *event);
68
69    /**
70     * @brief Event handler for mouse release events
71     *
72     * @param event Mouse event
73     */
74    void mouseReleaseEvent(QMouseEvent *event);
75
76 //   void paintEvent(QPaintEvent *event);
77
78
79 /*******************************************************************************
80 * MEMBER FUNCTIONS AND SLOTS
81 ******************************************************************************/
82
83 public slots:
84
85     /**
86     * @brief Relative position of the event inside the widget
87     */
88     const QPoint& eventPosition();
89
90     /**
91      * @brief Toggle distance indicator button draggability
92      */
93     void setDraggable(bool mode, QPoint eventPosition = QPoint(0,0));
94
95 private slots:
96     /**
97      * @brief Safeguard slot to release mouse grab if something goes horribly wrong
98      */
99     void forceMouseRelease();
100
101     /**
102      * @brief Slot that handles drag initialization once timer has timed out
103      */
104     void timerExpired();
105
106 /*******************************************************************************
107  * SIGNALS
108  ******************************************************************************/
109 signals:
110     /**
111     * @brief Automatic centering setting changed by user
112     *
113     * @param enabled True if automatic centering is enabled, otherwise false
114     */
115     void autoCenteringTriggered(bool enabled);
116
117 /*******************************************************************************
118 * DATA MEMBERS
119 ******************************************************************************/
120 private:
121    bool m_isDraggable;             ///< Boolean for tracking the draggability state
122
123    QPoint m_dragPosition;          ///< Location from where the widget is grabbed
124    QPoint m_eventPosition;         ///< Position of mousePressEvent
125
126    QSize m_screenSize;             ///< Store for the screen size
127
128    QTimer *m_dragStartTimer;       ///< Timer to init draggability of the distance indicator button
129    QTimer *m_forceReleaseTimer;    ///< Timer to run forceMouseRelease;
130
131 };
132
133 #endif // INDICATORBUTTON_H