Documentation
[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 #ifndef TABBEDPANEL_H
24 #define TABBEDPANEL_H
25
26 #include <QWidget>
27
28 #include "panelcommon.h"
29
30 class QPropertyAnimation;
31 class QSignalTransition;
32 class QState;
33 class QStateMachine;
34
35 class ListItemContextButtonBar;
36 class PanelBar;
37 class PanelContentStack;
38 class PanelContextButtonBar;
39 class PanelTabBar;
40
41 /**
42  * @brief Class for tabbed panels
43  *
44  * @author Kaj Wallin - kaj.wallin (at) ixonos.com
45  * @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
46  */
47 class TabbedPanel : public QWidget
48 {
49     Q_OBJECT
50
51 public:
52     /**
53      * @brief Constructor
54      *
55      * @param parent Parent
56      */
57     TabbedPanel(QWidget *parent = 0);
58
59 /*******************************************************************************
60  * MEMBER FUNCTIONS AND SLOTS
61  ******************************************************************************/
62 public:
63     /**
64      * @brief Adds a tab to the panel
65      *
66      * Adds a tab with the given widget and icon into the tabbed panel and returns the index of the
67      * inserted tab.
68      *
69      * @param widget Widget to be added into the tab
70      * @param icon Icon of the tab
71      */
72     int addTab(QWidget *widget, const QIcon& icon);
73
74     /**
75      * @brief Inserts a tab to the panel
76      *
77      * Inserts a tab with the given widget and icon into the tabbed panel at the specified index,
78      * and returns the index of the inserted tab.
79      *
80      * If index is out of range, the tab is simply appended. Otherwise it is inserted at the
81      * specified position.
82      *
83      * @param index Index of the tab
84      * @param widget Widget to be inserted into the tab
85      * @param icon Icon of the tab
86      */
87     int insertTab(int index, QWidget *widget, const QIcon& icon);
88
89     /**
90      * @brief Removes a tab from the panel
91      *
92      * Removes a tab and its widget from the panel at index position. The widget itself is not
93      * deleted.
94      *
95      * @param index Index of the tab
96      */
97     void removeTab(int index);
98
99     /**
100     * @brief Sets tabs enabled.
101     *
102     * If disabled tab is currently selected, panel will be closed also
103     * @param tabIndexes tab indexes to set
104     * @param enabled true if should be enabled, false otherwise
105     */
106     void setTabsEnabled(const QList<int> &tabIndexes, bool enabled);
107
108 public slots:
109     /**
110      * @brief Slot that closes the panel
111      */
112     void closePanel();
113
114     /**
115      * @brief Slot that opens the panel
116      *
117      * If widget pointer is provided the corresponding tab is also set active
118      *
119      * @param widget Widget
120      */
121     void openPanel(QWidget *widget = 0);
122
123     /**
124      * @brief Slot to redraw the panel after window resize event
125      *
126      * @param size Size of the new window
127      */
128     void resizePanel(const QSize &size);
129
130 private slots:
131     /**
132      * @brief Calculates mask for tabbed panel
133      *
134      * Mask is constructed from PanelTabBar, PanelContextButtonBar and panel content sizes
135      */
136     void calculateMask();
137
138     /**
139      * @brief Repositions context button bar
140      */
141     void repositionContextButtonBar();
142
143     /**
144      * @brief Sets the panel at current index active
145      *
146      * @param index Index of the panel
147      */
148     void setCurrentIndex(int index);
149
150     /**
151      * @brief Internal slot used to set the panel state
152      */
153     void stateChanged();
154
155 /*******************************************************************************
156  * SIGNALS
157  ******************************************************************************/
158 signals:
159     /**
160      * @brief This signal is emitted whenever the current tab page changes
161      *
162      * @param index Index of the new tab page
163      */
164     void currentChanged(int index);
165
166     /**
167      * @brief Emitted when there is a change in list item selection
168      *
169      * @param itemIsSelected True if any item is selected.
170      */
171     void listItemSelectionChanged(bool itemIsSelected);
172
173     /**
174      * @brief Signal that is sent when panel is closed
175      *
176      * @sa openPanel
177      * @sa closePanel
178      */
179     void panelClosed();
180
181     /**
182      * @brief Signal that is sent when panel is opened
183      *
184      * @sa openPanel
185      * @sa closePanel
186      */
187     void panelOpened();
188
189     /**
190      * @brief Signal that is sent when the panel state must be changed
191      *
192      * @sa openPanel
193      * @sa closePanel
194      */
195     void toggleState();
196
197 /*******************************************************************************
198  * DATA MEMBERS
199  ******************************************************************************/
200 private:
201     bool m_open;                ///< Current state of the panel
202     bool m_closeRequestPending; ///< Indicates wheater the panel is waiting to be closed
203
204     QState *m_stateClosed;      ///< State of the closed panel
205     QState *m_stateOpened;      ///< State of the opened panel
206
207     ListItemContextButtonBar *m_itemContextButtonBar;   ///< Widget for list item context button bar
208     PanelBar *m_panelBar;                               ///< Widget for panel bar
209     PanelContentStack *m_panelContentStack;             ///< Stack for panel widgets
210     PanelContextButtonBar * m_panelContextButtonBar;    ///< Widget for panel context button bar
211     PanelTabBar *m_panelTabBar;                         ///< Widget for panel tab bar
212 };
213
214 #endif // TABBEDPANEL_H