a4b4ac021eec5d7d6d2615fb1d0bdf6c050499af
[situare] / src / ui / tabbedpanel.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         Pekka Nissinen - pekka.nissinen@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
24 #ifndef TABBEDPANEL_H
25 #define TABBEDPANEL_H
26
27 #include <QWidget>
28
29 #include "panelcommon.h"
30
31 class QButtonGroup;
32 class QMouseEvent;
33 class QPaintEvent;
34 class QPixmap;
35 class QPropertyAnimation;
36 class QRect;
37 class QSignalTransition;
38 class QStackedWidget;
39 class QState;
40 class QStateMachine;
41
42 class PanelBar;
43 class PanelContent;
44
45
46 /**
47  * @brief Class for tabbed panels
48  *
49  * @author Kaj Wallin - kaj.wallin (at) ixonos.com
50  * @author Pekka Nissinen - pekka.nissinen@ixonos.com
51  *
52  * @class TabbedPanel tabbedpanel.h "ui/tabbedpanel.h"
53  */
54 class TabbedPanel : public QWidget
55 {
56     Q_OBJECT
57
58 public:
59     /**
60      * @brief Constructor
61      *
62      * @param parent Parent
63      */
64     TabbedPanel(QWidget *parent = 0);
65
66 /*******************************************************************************
67  * MEMBER FUNCTIONS AND SLOTS
68  ******************************************************************************/
69 public:
70     /**
71      * @brief Adds a tab to the panel
72      *
73      * Adds a tab with the given widget and icon into the tabbed panel and returns the index of the
74      * inserted tab.
75      *
76      * @param widget Widget to be added into the tab
77      * @param icon Icon of the tab
78      */
79     int addTab(QWidget *widget, const QIcon& icon);
80
81     /**
82      * @brief Inserts a tab to the panel
83      *
84      * Inserts a tab with the given widget and icon into the tabbed panel at the specified index,
85      * and returns the index of the inserted tab.
86      *
87      * If index is out of range, the tab is simply appended. Otherwise it is inserted at the
88      * specified position.
89      *
90      * @param index Index of the tab
91      * @param widget Widget to be inserted into the tab
92      * @param icon Icon of the tab
93      */
94     int insertTab(int index, QWidget *widget, const QIcon& icon);
95
96     /**
97      * @brief Removes a tab from the panel
98      *
99      * Removes a tab and its widget from the panel at index position. The widget itself is not
100      * deleted.
101      *
102      * @todo: Fix tab drawing order
103      *
104      * @param index Index of the tab
105      */
106     void removeTab(int index);
107
108 public slots:
109     /**
110      * @brief Public slot that will close the panel unless already closed
111      */
112     void closePanel();
113
114     /**
115      * @brief Public slot that will open the panel unless already open
116      */
117     void openPanel();
118
119     /**
120      * @brief Slot to redraw the panel after window resize event
121      *
122      * @param size Size of the new window
123      */
124     void resizePanel(const QSize &size);
125
126 private slots:
127     /**
128      * @brief Sets the tab at given index active
129      *
130      * @param index Index of the tab
131      */
132     void setActiveTab(int index);
133
134     /**
135      * @brief Internal slot used to track statemachine state
136      */
137     void stateChanged();
138
139 /*******************************************************************************
140  * SIGNALS
141  ******************************************************************************/
142 signals:
143     /**
144      * @brief Signal that is sent when panel is closed
145      *
146      * @sa openPanel
147      * @sa closePanel
148      */
149     void panelClosed();
150
151     /**
152      * @brief Signal that is sent when panel is opened
153      *
154      * @sa openPanel
155      * @sa closePanel
156      */
157     void panelOpened();
158
159     /**
160      * @brief Signal that is sent when user has clicked another tab active
161      */
162     void tabChanged();
163
164     /**
165      * @brief Signal that is sent to state machine when state must be changed
166      *
167      * @sa openPanel
168      * @sa closePanel
169      */
170     void toggleState();
171
172 /*******************************************************************************
173  * DATA MEMBERS
174  ******************************************************************************/
175 private:
176     bool m_isOpen;      ///< Boolean used to track the current state of the statemachine
177
178     int m_activeTab;    ///< Index of a active tab
179
180     QButtonGroup *m_tabButtonGroup; ///< Button groub for tab buttons
181
182     QPropertyAnimation *m_panelAnimation;       ///< Animation for panel state changes
183
184     QSignalTransition *m_panelTransitionClose;  ///< Transition signal for closing the panel
185     QSignalTransition *m_panelTransitionOpen;   ///< Transition signal for opening the panel
186
187     QStackedWidget *m_panelWidgetStack;         ///< Stack for panel widgets
188
189     QState *m_panelStateClosed;                 ///< State of the closed panel
190     QState *m_panelStateOpened;                 ///< State of the opened panel
191
192     QStateMachine *m_panelStateMachine;         ///< State machine for sliding the panel
193
194     PanelBar *m_panelBar;                       ///< Widget for panel bar
195     PanelContent *m_panelContent;               ///< Widget for panel content
196 };
197
198 #endif // TABBEDPANEL_H