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