Finished implementing zoom button drag feature
[situare] / src / ui / zoombuttonpanel.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
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 ZOOMBUTTONPANEL_H
24 #define ZOOMBUTTONPANEL_H
25
26 #include <QWidget>
27 #include <QPaintEvent>
28 #include <QGridLayout>
29 #include <QGraphicsItem>
30
31 #include "imagebutton.h"
32
33 /**
34  * @brief Panel for zoom buttons
35  *
36  * @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
37  * @author Kaj Wallin - kaj.wallin (at) ixonos.com
38  */
39 class ZoomButtonPanel : public QWidget
40 {
41     Q_OBJECT
42
43 public:
44     /**
45      * @brief Constructor
46      *
47      * @param parent Parent
48      * @param x Panel x coordinate
49      * @param y Panel y coordinate
50      */
51     ZoomButtonPanel(QWidget *parent = 0, int x = 0, int y = 0);
52
53 /*******************************************************************************
54  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
55  ******************************************************************************/
56 protected:
57     /**
58      * @brief Move event for the zoom button panel
59      *
60      * @param event Event
61      */
62     void mouseMoveEvent(QMouseEvent *event);
63
64     /**
65      * @brief Press event for the zoom button panel
66      *
67      * @param event Event
68      */
69     void mousePressEvent(QMouseEvent *event);
70
71     /**
72      * @brief Event handler for mouse release events
73      *
74      * @param event Mouse event
75      */
76     void mouseReleaseEvent(QMouseEvent *event);
77
78 /*******************************************************************************
79  * MEMBER FUNCTIONS AND SLOTS
80  ******************************************************************************/
81 public slots:
82     /**
83      * @brief Disables the Zoom In button
84      */
85     void disableZoomInButton();
86
87     /**
88      * @brief Disables the Zoom Out button
89      */
90     void disableZoomOutButton();
91
92     /**
93      * @brief Reset Zoom button states to normal
94      */
95     void resetButtons();
96
97     /**
98      * @brief Toggle zoom panel draggability
99      */
100     void setDraggable(bool mode, QPoint eventPosition = QPoint(0,0));
101
102     void screenResized(const QSize &size);
103
104 private slots:
105     /**
106      * @brief Slot to emit signal to zoom button panel to start drag mode after timer timeout
107      */
108     void timerExpired();
109
110 /*******************************************************************************
111  * DATA MEMBERS
112  ******************************************************************************/
113 public:
114     ImageButton *m_zoomInButton;    ///< Button for zoom in
115     ImageButton *m_zoomOutButton;   ///< Button for zoom out
116
117 private:
118     bool m_isDraggable;             ///< Boolean for tracking the draggability state
119
120     int m_x;                        ///< Panel x coordinate
121     int m_y;                        ///< Panel y coordinate
122
123     QGridLayout m_panelLayout;      ///< Panel layout
124
125     QPoint m_dragPosition;          ///< Location from where the widget is grabbed
126
127     QIcon::Mode m_zoomInMode;       ///< Store for zoom in button mode before dragging
128     QIcon::Mode m_zoomOutMode;      ///< Store for zoom out button mode before dragging
129
130     QSize m_screenSize;             ///< Store for the screen size
131
132     QTimer *m_dragStartTimer;       ///< Timer to init draggability of the zoom panel
133
134     QWidget *m_eventBlocker;        ///< Overlaying widget that catches the mouse events
135 };
136
137 #endif // ZOOMBUTTONPANEL_H