Reviewed new files
[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 : public QWidget
52 {
53     Q_OBJECT
54
55 public:
56     /**
57      * @brief Constructor
58      *
59      * @param parent Parent
60      */
61     TabbedPanel(QWidget *parent = 0);
62
63 /*******************************************************************************
64  * MEMBER FUNCTIONS AND SLOTS
65  ******************************************************************************/
66 public:
67     /**
68      * @brief Adds a tab to the panel
69      *
70      * Adds a tab with the given widget and icon into the tabbed panel and returns the index of the
71      * inserted tab.
72      *
73      * @param widget Widget to be added into the tab
74      * @param icon Icon of the tab
75      */
76     int addTab(QWidget *widget, const QIcon& icon);
77
78     ///< @todo define "out of range"
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 Slot to redraw the panel after window resize event
119      *
120      * @param size Size of the new window
121      */
122     void resizePanel(const QSize &size);
123
124 private slots:
125     /**
126      * @brief Sets the tab at given index active
127      *
128      * @param index Index of the tab
129      */
130     void setActiveTab(int index);
131
132     /**
133      * @brief Internal slot used to track statemachine state
134      */
135     void stateChanged();
136
137 /*******************************************************************************
138  * SIGNALS
139  ******************************************************************************/
140 signals:
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 when user has clicked another tab active
159      */
160     void tabChanged();
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     QPropertyAnimation *m_panelAnimation;       ///< Animation for panel state changes
181
182     QSignalTransition *m_panelTransitionClose;  ///< Transition signal for closing the panel
183     QSignalTransition *m_panelTransitionOpen;   ///< Transition signal for opening the panel
184
185     QStackedWidget *m_panelWidgetStack;         ///< Stack for panel widgets
186
187     QState *m_panelStateClosed;                 ///< State of the closed panel
188     QState *m_panelStateOpened;                 ///< State of the opened panel
189
190     QStateMachine *m_panelStateMachine;         ///< State machine for sliding the panel
191
192     PanelBar *m_panelBar;                       ///< Widget for panel bar
193     PanelContent *m_panelContent;               ///< Widget for panel content
194 };
195
196 #endif // TABBEDPANEL_H