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