Merge branch 'new_panels' of https://vcs.maemo.org/git/situare into new_panels
[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 QStackedWidget;
33 class QState;
34 class QStateMachine;
35
36 class PanelBar;
37 class PanelContent;
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@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     ///< @todo define "out of range"
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 public slots:
100     /**
101      * @brief Slot that closes the panel
102      */
103     void closePanel();
104
105     /**
106      * @brief Slot that shows the tab (and opens it if closed) with the desired widget
107      *
108      * @param widget Widget
109      */
110     void showPanel(QWidget *widget);
111
112     /**
113      * @brief Slot to redraw the panel after window resize event
114      *
115      * @param size Size of the new window
116      */
117     void resizePanel(const QSize &size);
118
119 private slots:
120     /**
121      * @brief Sets the panel at current index active
122      *
123      * @param index Index of the panel
124      */
125     void setCurrentIndex(int index);
126
127     /**
128      * @brief Internal slot used to track statemachine state
129      */
130     void stateChanged();
131
132 /*******************************************************************************
133  * SIGNALS
134  ******************************************************************************/
135 signals:
136     /**
137      * @brief This signal is emitted whenever the current page index changes
138      */
139     void currentChanged(int index);
140
141     /**
142      * @brief Signal that is sent when panel is closed
143      *
144      * @sa openPanel
145      * @sa closePanel
146      */
147     void panelClosed();
148
149     /**
150      * @brief Signal that is sent when panel is opened
151      *
152      * @sa openPanel
153      * @sa closePanel
154      */
155     void panelOpened();
156
157     /**
158      * @brief Signal that is sent to state machine when panel state must be changed
159      *
160      * @sa openPanel
161      * @sa closePanel
162      */
163     void toggleState();
164
165 /*******************************************************************************
166  * DATA MEMBERS
167  ******************************************************************************/
168 private:
169     bool m_isOpen;      ///< Boolean used to track the current state of the statemachine
170
171     QPropertyAnimation *m_panelAnimation;       ///< Animation for panel state changes
172
173     QSignalTransition *m_panelTransitionClose;  ///< Transition signal for closing the panel
174     QSignalTransition *m_panelTransitionOpen;   ///< Transition signal for opening the panel
175
176     QStackedWidget *m_panelWidgetStack;         ///< Stack for panel widgets
177
178     QState *m_panelStateClosed;                 ///< State of the closed panel
179     QState *m_panelStateOpened;                 ///< State of the opened panel
180
181     QStateMachine *m_panelStateMachine;         ///< State machine for sliding the panel
182
183     PanelBar *m_panelBar;                       ///< Widget for panel bar
184     PanelContent *m_panelContent;               ///< Widget for panel content
185     PanelTabBar *m_panelTabBar;                 ///< Widget for panel tab bar
186 };
187
188 #endif // TABBEDPANEL_H