summaryrefslogtreecommitdiff
path: root/noncore/unsupported/libopie/otabwidget.h
blob: 047eaa1ef87b45213bae5f9ef11b8e9d6958cbb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/*
                            This file is part of the Opie Project

                             Copyright (c)  2002 Dan Williams <williamsdr@acm.org>
              =.
            .=l.
           .>+-=
 _;:,     .>    :=|.         This program is free software; you can
.> <`_,   >  .   <=          redistribute it and/or  modify it under
:`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
.="- .-=="i,     .._         License as published by the Free Software
 - .   .-<_>     .<>         Foundation; either version 2 of the License,
     ._= =}       :          or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s.       This program is distributed in the hope that
     +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
    : ..    .:,     . . .    without even the implied warranty of
    =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ;      Library General Public License for more
++=   -.     .`     .:       details.
 :     =  ...= . :.=-
 -.   .:....=;==+<;          You should have received a copy of the GNU
  -_. . .   )=.  =           Library General Public License along with
    --        :-=`           this library; see the file COPYING.LIB.
                             If not, write to the Free Software Foundation,
                             Inc., 59 Temple Place - Suite 330,
                             Boston, MA 02111-1307, USA.

*/

#ifndef OTABWIDGET_H
#define OTABWIDGET_H

#include "otabinfo.h"

#include <qwidget.h>
#include <qlist.h>

class OTabBar;
class QComboBox;
class QPixmap;
class QTabBar;
class QWidgetStack;

/**
 * @class OTabWidget
 * @brief The OTabWidget class provides a stack of widgets.
 *
 * OTabWidget is a derivation of TrollTech's QTabWidget which provides
 * a stack of widgets.  Widgets can be selected using either a tab bar or
 * drop down list box.
 *
 * The normal way to use OTabWidget is to do the following in the
 * constructor:
 * - Create a OTabWidget.
 * - Create a QWidget for each of the pages in the control, insert
 *   children into it, set up geometry management for it, and use addTab()
 *   to add the widget.
 */
class OTabWidget : public QWidget
{
    Q_OBJECT
public:

/**
 * @enum TabStyle
 * @brief Defines how the widget selection control is displayed.
 *
 * Valid values:
 * - Global: use globally selected options (qpe.conf - TabStyle & TabPosition)
 * - TextTab: Tabbed widget selection with text labels
 * - IconTab: Tabbed widget selection with icon labels, text label for active widget
 *            (similar to Opie launcher)
 * - TextList: Drop down list widget selection with text labels
 * - IconList: Drop down list widget selection with icon & text labels
 */
    enum TabStyle { Global, TextTab, IconTab, TextList, IconList };

/**
 * @enum TabPosition
 * @brief Defines where the widget selection control is drawn.
 *
 * Valid values:
 * - Top: Widget selection control is drawn above widgets
 * - Bottom: Widget selection control is drawn below widgets
 */
    enum TabPosition { Top, Bottom };

/**
 * @fn OTabWidget( QWidget *parent = 0, const char *name = 0, TabStyle s = Global, TabPosition p = Top )
 * @brief Object constructor.
 *
 * @param parent Pointer to parent of this control.
 * @param name Name of control.
 * @param s Style of widget selection control.
 * @param p Position of the widget selection control.
 *
 * Constructs a new OTabWidget control with parent and name.  The style and position parameters
 * determine how the widget selection control will be displayed.
 */
 // FIXME WFlags? -zecke
    OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top );

/**
 * @fn ~OTabWidget()
 * @brief Object destructor.
 */
    ~OTabWidget();

/**
 * @fn addTab( QWidget *child, const QString &icon, const QString &label )
 * @brief Add new widget to control.
 *
 * @param child Widget control.
 * @param icon Path to icon.
 * @param label Text label.
 */
    void addTab( QWidget *, const QString &, const QString & );

/**
 * @fn removePage( QWidget *widget )
 * @brief Remove widget from control.  Does not delete widget.
 *
 * @param widget Widget control to be removed.
 */
    /* ### Page vs. Tab.. yes the widget is a Page but then is addTab wrong -zecke */
    void removePage( QWidget * );

/**
 * @fn changeTab( QWidget *widget, const QString &icon, const QString &label )
 * @brief Change text and/or icon for existing tab
 *
 * @param child Widget control.
 * @param icon Path to icon.
 * @param label Text label.
 */
    void changeTab( QWidget *, const QString &, const QString & );

/**
 * @fn tabStyle()const
 * @brief Returns current widget selection control style.
 */
    TabStyle tabStyle() const;

/**
 * @fn setTabStyle( TabStyle s )
 * @brief Set the current widget selection control style.
 *
 * @param s New style to be used.
 */
    void setTabStyle( TabStyle );

/**
 * @fn tabPosition()const
 * @brief Returns current widget selection control position.
 */
    TabPosition tabPosition() const;

/**
 * @fn setTabPosition( TabPosition p )
 * @brief Set the current widget selection control position.
 *
 * @param p New position of widget selection control.
 */
    void setTabPosition( TabPosition );

/**
 * @fn setCurrentTab( QWidget *childwidget )
 * @brief Selects and brings to top the desired widget by using widget pointer.
 *
 * @param childwidget Widget to select.
 */
    void setCurrentTab( QWidget * );

/**
 * @fn setCurrentTab( const QString &tabname )
 * @brief Selects and brings to top the desired widget, by using label.
 *
 * @param tabname Text label for widget to select.
 */
    void setCurrentTab( const QString & );

/**
 * @fn setCurrentTab( int )
 * @brief Selects and brings to top the desired widget, by using id.
 *
 * @param tab id for widget to select.
 */
    void setCurrentTab(int);

/**
 * @fn sizeHint()const
 * @brief Reimplemented for internal purposes.
 */
    QSize sizeHint() const;

/**
 * @fn currentTab( )
 * @brief returns current tab id.
 */
    // ### make const
    int currentTab()/* const */;
/**
 * @brief returns the current page of the active tab
 *
 * @since 1.2
 */
    QWidget* currentWidget()const;

protected:

/**
 * @fn resizeEvent( QResizeEvent * )
 * @brief Reimplemented for internal purposes.
 */
    void resizeEvent( QResizeEvent * );

private:
    OTabInfoList  tabs;
    OTabInfo     *currTab;

    TabStyle    tabBarStyle;
    TabPosition tabBarPosition;

    QWidgetStack *tabBarStack;
    OTabBar      *tabBar;
    QComboBox    *tabList;

    QWidgetStack *widgetStack;
    class Private;
    Private* d;

/**
 * @fn loadSmooth( const QString &name )
 * @brief Loads icon for widget.
 *
 * @param name Name of icon image file.
 */
    QPixmap loadSmooth( const QString & );

/**
 * @fn selectTab( OTabInfo *tab )
 * @brief Internal function to select desired widget.
 *
 * @param tab Pointer to data for widget.
 */
    void    selectTab( OTabInfo * );

/**
 * @fn setUpLayout()
 * @brief Internal function to adjust layout.
 */
    void    setUpLayout();


signals:
/**
 * @fn currentChanged( QWidget *widget )
 * @brief This signal is emitted whenever the widget has changed.
 *
 * @param widget Pointer to new current widget.
 */
    void currentChanged( QWidget * );

private slots:

/**
 * @fn slotTabBarSelected( int id )
 * @brief Slot which is called when a tab is selected.
 *
 * @param id ID of widget selected.
 */
    void slotTabBarSelected( int );

/**
 * @fn slotTabListSelected( int index )
 * @brief Slot which is called when a drop down selection is made.
 *
 * @param id Index of widget selected.
 */
    void slotTabListSelected( int );
};

#endif