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