summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/otabinfo.h16
-rw-r--r--libopie/otabwidget.cpp48
-rw-r--r--libopie/otabwidget.h10
3 files changed, 68 insertions, 6 deletions
diff --git a/libopie/otabinfo.h b/libopie/otabinfo.h
index 8dbbcc2..6589638 100644
--- a/libopie/otabinfo.h
+++ b/libopie/otabinfo.h
@@ -1,116 +1,132 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org> 4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#ifndef OTABINFO_H 32#ifndef OTABINFO_H
33#define OTABINFO_H 33#define OTABINFO_H
34 34
35#include <qlist.h> 35#include <qlist.h>
36#include <qstring.h> 36#include <qstring.h>
37 37
38class QWidget; 38class QWidget;
39 39
40/** 40/**
41 * @class OTabInfo 41 * @class OTabInfo
42 * @brief The OTabInfo class is used internally by OTabWidget to keep track 42 * @brief The OTabInfo class is used internally by OTabWidget to keep track
43 * of widgets added to the control. 43 * of widgets added to the control.
44 * 44 *
45 * OTabInfo provides the following information about a widget added to an 45 * OTabInfo provides the following information about a widget added to an
46 * OTabWidget control: 46 * OTabWidget control:
47 * 47 *
48 * ID - integer tab bar ID 48 * ID - integer tab bar ID
49 * Control - QWidget pointer to child widget 49 * Control - QWidget pointer to child widget
50 * Label - QString text label for OTabWidget selection control 50 * Label - QString text label for OTabWidget selection control
51 * Icon - QString name of icon file 51 * Icon - QString name of icon file
52 */ 52 */
53class OTabInfo 53class OTabInfo
54{ 54{
55public: 55public:
56/** 56/**
57 * @fn OTabInfo() 57 * @fn OTabInfo()
58 * @brief Object constructor. 58 * @brief Object constructor.
59 * 59 *
60 * @param parent Pointer to parent of this control. 60 * @param parent Pointer to parent of this control.
61 * @param name Name of control. 61 * @param name Name of control.
62 * @param s Style of widget selection control. 62 * @param s Style of widget selection control.
63 * @param p Position of the widget selection control. 63 * @param p Position of the widget selection control.
64 */ 64 */
65 OTabInfo() : i( -1 ), c( 0 ), p( 0 ), l( QString::null ) {} 65 OTabInfo() : i( -1 ), c( 0 ), p( 0 ), l( QString::null ) {}
66 66
67/** 67/**
68 * @fn OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) 68 * @fn OTabInfo( int id, QWidget *control, const QString &icon, const QString &label )
69 * @brief Object constructor. 69 * @brief Object constructor.
70 * 70 *
71 * @param id TabBar identifier for widget. 71 * @param id TabBar identifier for widget.
72 * @param control QWidget pointer to widget. 72 * @param control QWidget pointer to widget.
73 * @param icon QString name of icon file. 73 * @param icon QString name of icon file.
74 * @param label QString text label for OTabWidget selection control. 74 * @param label QString text label for OTabWidget selection control.
75 */ 75 */
76 OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) 76 OTabInfo( int id, QWidget *control, const QString &icon, const QString &label )
77 : i( id ), c( control ), p( icon ), l( label ) {} 77 : i( id ), c( control ), p( icon ), l( label ) {}
78 78
79/** 79/**
80 * @fn id() 80 * @fn id()
81 * @brief Returns TabBar ID. 81 * @brief Returns TabBar ID.
82 */ 82 */
83 int id() const { return i; } 83 int id() const { return i; }
84 84
85/** 85/**
86 * @fn label() 86 * @fn label()
87 * @brief Returns text label for widget. 87 * @brief Returns text label for widget.
88 */ 88 */
89 const QString &label() const { return l; } 89 const QString &label() const { return l; }
90 90
91/** 91/**
92 * @fn setLabel( const QString &label )
93 * @brief Set label for tab.
94 *
95 * @param label QString text label for OTabWidget selection control.
96 */
97 void setLabel( const QString &label ) { l = label; }
98
99/**
92 * @fn control() 100 * @fn control()
93 * @brief Returns pointer to widget. 101 * @brief Returns pointer to widget.
94 */ 102 */
95 QWidget *control() const { return c; } 103 QWidget *control() const { return c; }
96 104
97/** 105/**
98 * @fn icon() 106 * @fn icon()
99 * @brief Returns name of icon file. 107 * @brief Returns name of icon file.
100 */ 108 */
101 const QString &icon() const { return p; } 109 const QString &icon() const { return p; }
102 110
111/**
112 * @fn setIcon( const QString &icon )
113 * @brief Set icon for tab.
114 *
115 * @param icon QString name of icon file.
116 */
117 void setIcon( const QString &icon ) { p = icon; }
118
103private: 119private:
104 int i; 120 int i;
105 QWidget *c; 121 QWidget *c;
106 QString p; 122 QString p;
107 QString l; 123 QString l;
108}; 124};
109 125
110/** 126/**
111 * @class OTabInfoList 127 * @class OTabInfoList
112 * @brief A list of OTabInfo objects used by OTabWidget. 128 * @brief A list of OTabInfo objects used by OTabWidget.
113 */ 129 */
114typedef QList<OTabInfo> OTabInfoList; 130typedef QList<OTabInfo> OTabInfoList;
115 131
116#endif 132#endif
diff --git a/libopie/otabwidget.cpp b/libopie/otabwidget.cpp
index bee3f35..99bf067 100644
--- a/libopie/otabwidget.cpp
+++ b/libopie/otabwidget.cpp
@@ -1,373 +1,409 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org> 4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#include "otabwidget.h" 32#include "otabwidget.h"
33 33
34#include <qpe/config.h> 34#include <qpe/config.h>
35#include <qpe/resource.h> 35#include <qpe/resource.h>
36#include <opie/otabbar.h> 36#include <opie/otabbar.h>
37 37
38#include <qcombobox.h> 38#include <qcombobox.h>
39#include <qwidgetstack.h> 39#include <qwidgetstack.h>
40 40
41OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p ) 41OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p )
42 : QWidget( parent, name ) 42 : QWidget( parent, name )
43{ 43{
44 if ( s == Global ) 44 if ( s == Global )
45 { 45 {
46 Config config( "qpe" ); 46 Config config( "qpe" );
47 config.setGroup( "Appearance" ); 47 config.setGroup( "Appearance" );
48 s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); 48 s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab );
49 if ( s <= Global || s > IconList) 49 if ( s <= Global || s > IconList)
50 { 50 {
51 s = IconTab; 51 s = IconTab;
52 } 52 }
53 QString pos = config.readEntry( "TabPosition", "Top"); 53 QString pos = config.readEntry( "TabPosition", "Top");
54 if ( pos == "Bottom" ) 54 if ( pos == "Bottom" )
55 { 55 {
56 p = Bottom; 56 p = Bottom;
57 } 57 }
58 else 58 else
59 { 59 {
60 p = Top; 60 p = Top;
61 } 61 }
62 } 62 }
63 63
64 widgetStack = new QWidgetStack( this, "widgetstack" ); 64 widgetStack = new QWidgetStack( this, "widgetstack" );
65 widgetStack->setFrameStyle( QFrame::NoFrame ); 65 widgetStack->setFrameStyle( QFrame::NoFrame );
66 widgetStack->setLineWidth( style().defaultFrameWidth() ); 66 widgetStack->setLineWidth( style().defaultFrameWidth() );
67 67
68 tabBarStack = new QWidgetStack( this, "tabbarstack" ); 68 tabBarStack = new QWidgetStack( this, "tabbarstack" );
69 69
70 tabBar = new OTabBar( tabBarStack, "tabbar" ); 70 tabBar = new OTabBar( tabBarStack, "tabbar" );
71 tabBarStack->addWidget( tabBar, 0 ); 71 tabBarStack->addWidget( tabBar, 0 );
72 connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) ); 72 connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) );
73 73
74 tabList = new QComboBox( false, tabBarStack, "tablist" ); 74 tabList = new QComboBox( false, tabBarStack, "tablist" );
75 tabBarStack->addWidget( tabList, 1 ); 75 tabBarStack->addWidget( tabList, 1 );
76 connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) ); 76 connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) );
77 77
78 setTabStyle( s ); 78 setTabStyle( s );
79 setTabPosition( p ); 79 setTabPosition( p );
80 80
81 currentTab= 0x0; 81 currentTab= 0x0;
82} 82}
83 83
84OTabWidget::~OTabWidget() 84OTabWidget::~OTabWidget()
85{ 85{
86} 86}
87 87
88void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) 88void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
89{ 89{
90 QPixmap iconset = loadSmooth( icon ); 90 QPixmap iconset = loadSmooth( icon );
91 91
92 QTab *tab = new QTab(); 92 QTab *tab = new QTab();
93 if ( tabBarStyle == IconTab ) 93 if ( tabBarStyle == IconTab )
94 { 94 {
95 tab->label = QString::null; 95 tab->label = QString::null;
96 } 96 }
97 else 97 else
98 { 98 {
99 tab->label = label; 99 tab->label = label;
100 } 100 }
101 if ( tabBarStyle == IconTab || tabBarStyle == IconList) 101 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
102 { 102 {
103 tab->iconset = new QIconSet( iconset ); 103 tab->iconset = new QIconSet( iconset );
104 } 104 }
105 int tabid = tabBar->addTab( tab ); 105 int tabid = tabBar->addTab( tab );
106 106
107 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 107 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
108 { 108 {
109 tabList->insertItem( iconset, label, -1 ); 109 tabList->insertItem( iconset, label, -1 );
110 } 110 }
111 else 111 else
112 { 112 {
113 tabList->insertItem( label ); 113 tabList->insertItem( label );
114 } 114 }
115 115
116 widgetStack->addWidget( child, tabid ); 116 widgetStack->addWidget( child, tabid );
117 widgetStack->raiseWidget( child ); 117 widgetStack->raiseWidget( child );
118 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); 118 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
119 119
120 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); 120 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label );
121 tabs.append( tabinfo ); 121 tabs.append( tabinfo );
122 selectTab( tabinfo ); 122 selectTab( tabinfo );
123} 123}
124 124
125void OTabWidget::removePage( QWidget *childwidget ) 125void OTabWidget::removePage( QWidget *childwidget )
126{ 126{
127 if ( childwidget ) 127 if ( childwidget )
128 { 128 {
129 OTabInfo *tab = tabs.first(); 129 OTabInfo *tab = tabs.first();
130 while ( tab && tab->control() != childwidget ) 130 while ( tab && tab->control() != childwidget )
131 { 131 {
132 tab = tabs.next(); 132 tab = tabs.next();
133 } 133 }
134 if ( tab && tab->control() == childwidget ) 134 if ( tab && tab->control() == childwidget )
135 { 135 {
136 tabBar->setTabEnabled( tab->id(), FALSE ); 136 tabBar->setTabEnabled( tab->id(), FALSE );
137 tabBar->removeTab( tabBar->tab( tab->id() ) ); 137 tabBar->removeTab( tabBar->tab( tab->id() ) );
138 int i = 0; 138 int i = 0;
139 while ( i < tabList->count() && tabList->text( i ) != tab->label() ) 139 while ( i < tabList->count() && tabList->text( i ) != tab->label() )
140 { 140 {
141 i++; 141 i++;
142 } 142 }
143 if ( tabList->text( i ) == tab->label() ) 143 if ( tabList->text( i ) == tab->label() )
144 { 144 {
145 tabList->removeItem( i ); 145 tabList->removeItem( i );
146 } 146 }
147 widgetStack->removeWidget( childwidget ); 147 widgetStack->removeWidget( childwidget );
148 tabs.remove( tab ); 148 tabs.remove( tab );
149 delete tab; 149 delete tab;
150 currentTab = tabs.current(); 150 currentTab = tabs.current();
151 if ( !currentTab ) 151 if ( !currentTab )
152 { 152 {
153 widgetStack->setFrameStyle( QFrame::NoFrame ); 153 widgetStack->setFrameStyle( QFrame::NoFrame );
154 } 154 }
155 155
156 setUpLayout(); 156 setUpLayout();
157 } 157 }
158 } 158 }
159} 159}
160 160
161void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label)
162{
163 OTabInfo *currtab = tabs.first();
164 while ( currtab && currtab->control() != widget )
165 {
166 currtab = tabs.next();
167 }
168 if ( currtab && currtab->control() == widget )
169 {
170 QTab *tab = tabBar->tab( currtab->id() );
171 QPixmap icon( loadSmooth( iconset ) );
172 tab->setText( label );
173 if ( tabBarStyle == IconTab )
174 tab->setIconSet( icon );
175 int i = 0;
176 while ( i < tabList->count() && tabList->text( i ) != currtab->label() )
177 {
178 i++;
179 }
180 if ( i < tabList->count() && tabList->text( i ) == currtab->label() )
181 {
182 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
183 {
184 tabList->changeItem( icon, label, i );
185 }
186 else
187 {
188 tabList->changeItem( label, i );
189 }
190 }
191 currtab->setLabel( label );
192 currtab->setIcon( iconset );
193 }
194 setUpLayout();
195}
196
161void OTabWidget::setCurrentTab( QWidget *childwidget ) 197void OTabWidget::setCurrentTab( QWidget *childwidget )
162{ 198{
163 OTabInfo *newtab = tabs.first(); 199 OTabInfo *currtab = tabs.first();
164 while ( newtab && newtab->control() != childwidget ) 200 while ( currtab && currtab->control() != childwidget )
165 { 201 {
166 newtab = tabs.next(); 202 currtab = tabs.next();
167 } 203 }
168 if ( newtab && newtab->control() == childwidget ) 204 if ( currtab && currtab->control() == childwidget )
169 { 205 {
170 selectTab( newtab ); 206 selectTab( currtab );
171 } 207 }
172} 208}
173 209
174void OTabWidget::setCurrentTab( const QString &tabname ) 210void OTabWidget::setCurrentTab( const QString &tabname )
175{ 211{
176 OTabInfo *newtab = tabs.first(); 212 OTabInfo *newtab = tabs.first();
177 while ( newtab && newtab->label() != tabname ) 213 while ( newtab && newtab->label() != tabname )
178 { 214 {
179 newtab = tabs.next(); 215 newtab = tabs.next();
180 } 216 }
181 if ( newtab && newtab->label() == tabname ) 217 if ( newtab && newtab->label() == tabname )
182 { 218 {
183 selectTab( newtab ); 219 selectTab( newtab );
184 } 220 }
185} 221}
186 222
187void OTabWidget::setCurrentTab(int tabindex) { 223void OTabWidget::setCurrentTab(int tabindex) {
188 OTabInfo *newtab = tabs.first(); 224 OTabInfo *newtab = tabs.first();
189 while ( newtab && newtab->id() != tabindex ) 225 while ( newtab && newtab->id() != tabindex )
190 { 226 {
191 newtab = tabs.next(); 227 newtab = tabs.next();
192 } 228 }
193 if ( newtab && newtab->id() == tabindex ) 229 if ( newtab && newtab->id() == tabindex )
194 { 230 {
195 selectTab( newtab ); 231 selectTab( newtab );
196 } 232 }
197} 233}
198 234
199 235
200OTabWidget::TabStyle OTabWidget::tabStyle() const 236OTabWidget::TabStyle OTabWidget::tabStyle() const
201{ 237{
202 return tabBarStyle; 238 return tabBarStyle;
203} 239}
204 240
205void OTabWidget::setTabStyle( TabStyle s ) 241void OTabWidget::setTabStyle( TabStyle s )
206{ 242{
207 tabBarStyle = s; 243 tabBarStyle = s;
208 if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) 244 if ( tabBarStyle == TextTab || tabBarStyle == IconTab )
209 { 245 {
210 QTab *currtab; 246 QTab *currtab;
211 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) 247 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
212 { 248 {
213 currtab = tabBar->tab( tabinfo->id() ); 249 currtab = tabBar->tab( tabinfo->id() );
214 if ( tabBarStyle == IconTab ) 250 if ( tabBarStyle == IconTab )
215 { 251 {
216 currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); 252 currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) );
217 if ( tabinfo == currentTab ) 253 if ( tabinfo == currentTab )
218 currtab->setText( tabinfo->label() ); 254 currtab->setText( tabinfo->label() );
219 else 255 else
220 currtab->setText( QString::null ); 256 currtab->setText( QString::null );
221 } 257 }
222 else 258 else
223 { 259 {
224 currtab->iconset = 0x0; 260 currtab->iconset = 0x0;
225 currtab->setText( tabinfo->label() ); 261 currtab->setText( tabinfo->label() );
226 } 262 }
227 } 263 }
228 tabBarStack->raiseWidget( tabBar ); 264 tabBarStack->raiseWidget( tabBar );
229 } 265 }
230 else if ( tabBarStyle == TextList || tabBarStyle == IconList ) 266 else if ( tabBarStyle == TextList || tabBarStyle == IconList )
231 { 267 {
232 tabList->clear(); 268 tabList->clear();
233 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) 269 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
234 { 270 {
235 if ( tabBarStyle == IconList ) 271 if ( tabBarStyle == IconList )
236 { 272 {
237 tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); 273 tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() );
238 } 274 }
239 else 275 else
240 { 276 {
241 tabList->insertItem( tabinfo->label() ); 277 tabList->insertItem( tabinfo->label() );
242 } 278 }
243 } 279 }
244 tabBarStack->raiseWidget( tabList ); 280 tabBarStack->raiseWidget( tabList );
245 } 281 }
246 setUpLayout(); 282 setUpLayout();
247} 283}
248 284
249OTabWidget::TabPosition OTabWidget::tabPosition() const 285OTabWidget::TabPosition OTabWidget::tabPosition() const
250{ 286{
251 return tabBarPosition; 287 return tabBarPosition;
252} 288}
253 289
254void OTabWidget::setTabPosition( TabPosition p ) 290void OTabWidget::setTabPosition( TabPosition p )
255{ 291{
256 tabBarPosition = p; 292 tabBarPosition = p;
257 if ( tabBarPosition == Top ) 293 if ( tabBarPosition == Top )
258 { 294 {
259 tabBar->setShape( QTabBar::RoundedAbove ); 295 tabBar->setShape( QTabBar::RoundedAbove );
260 } 296 }
261 else 297 else
262 { 298 {
263 tabBar->setShape( QTabBar::RoundedBelow ); 299 tabBar->setShape( QTabBar::RoundedBelow );
264 } 300 }
265 setUpLayout(); 301 setUpLayout();
266} 302}
267 303
268void OTabWidget::slotTabBarSelected( int id ) 304void OTabWidget::slotTabBarSelected( int id )
269{ 305{
270 OTabInfo *newtab = tabs.first(); 306 OTabInfo *newtab = tabs.first();
271 while ( newtab && newtab->id() != id ) 307 while ( newtab && newtab->id() != id )
272 { 308 {
273 newtab = tabs.next(); 309 newtab = tabs.next();
274 } 310 }
275 if ( newtab && newtab->id() == id ) 311 if ( newtab && newtab->id() == id )
276 { 312 {
277 selectTab( newtab ); 313 selectTab( newtab );
278 } 314 }
279} 315}
280 316
281void OTabWidget::slotTabListSelected( int index ) 317void OTabWidget::slotTabListSelected( int index )
282{ 318{
283 OTabInfo *newtab = tabs.at( index ); 319 OTabInfo *newtab = tabs.at( index );
284 if ( newtab ) 320 if ( newtab )
285 { 321 {
286 selectTab( newtab ); 322 selectTab( newtab );
287 } 323 }
288} 324}
289 325
290QPixmap OTabWidget::loadSmooth( const QString &name ) 326QPixmap OTabWidget::loadSmooth( const QString &name )
291{ 327{
292 QImage image = Resource::loadImage( name ); 328 QImage image = Resource::loadImage( name );
293 QPixmap pixmap; 329 QPixmap pixmap;
294 pixmap.convertFromImage( image.smoothScale( 16, 16 ) ); 330 pixmap.convertFromImage( image.smoothScale( 16, 16 ) );
295 return pixmap; 331 return pixmap;
296} 332}
297 333
298void OTabWidget::selectTab( OTabInfo *tab ) 334void OTabWidget::selectTab( OTabInfo *tab )
299{ 335{
300 if ( tabBarStyle == IconTab ) 336 if ( tabBarStyle == IconTab )
301 { 337 {
302 if ( currentTab ) 338 if ( currentTab )
303 { 339 {
304 tabBar->tab( currentTab->id() )->setText( QString::null ); 340 tabBar->tab( currentTab->id() )->setText( QString::null );
305 setUpLayout(); 341 setUpLayout();
306 } 342 }
307 tabBar->tab( tab->id() )->setText( tab->label() ); 343 tabBar->tab( tab->id() )->setText( tab->label() );
308 tabBar->setCurrentTab( tab->id() ); 344 tabBar->setCurrentTab( tab->id() );
309 setUpLayout(); 345 setUpLayout();
310 tabBar->update(); 346 tabBar->update();
311 } 347 }
312 else 348 else
313 { 349 {
314 tabBar->setCurrentTab( tab->id() ); 350 tabBar->setCurrentTab( tab->id() );
315 } 351 }
316 352
317 widgetStack->raiseWidget( tab->control() ); 353 widgetStack->raiseWidget( tab->control() );
318 354
319 emit currentChanged( tab->control() ); 355 emit currentChanged( tab->control() );
320 356
321 currentTab = tab; 357 currentTab = tab;
322} 358}
323 359
324void OTabWidget::setUpLayout() 360void OTabWidget::setUpLayout()
325{ 361{
326 tabBar->layoutTabs(); 362 tabBar->layoutTabs();
327 QSize t( tabBarStack->sizeHint() ); 363 QSize t( tabBarStack->sizeHint() );
328 if ( tabBarStyle == IconTab ) 364 if ( tabBarStyle == IconTab )
329 { 365 {
330 if ( t.width() > width() ) 366 if ( t.width() > width() )
331 t.setWidth( width() ); 367 t.setWidth( width() );
332 } 368 }
333 else 369 else
334 { 370 {
335 t.setWidth( width() ); 371 t.setWidth( width() );
336 } 372 }
337 int lw = widgetStack->lineWidth(); 373 int lw = widgetStack->lineWidth();
338 if ( tabBarPosition == Bottom ) 374 if ( tabBarPosition == Bottom )
339 { 375 {
340 tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); 376 tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() );
341 widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); 377 widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) );
342 } 378 }
343 else 379 else
344 { 380 {
345 tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); 381 tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() );
346 widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) ); 382 widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) );
347 } 383 }
348 384
349 if ( autoMask() ) 385 if ( autoMask() )
350 updateMask(); 386 updateMask();
351} 387}
352 388
353QSize OTabWidget::sizeHint() const 389QSize OTabWidget::sizeHint() const
354{ 390{
355 QSize s( widgetStack->sizeHint() ); 391 QSize s( widgetStack->sizeHint() );
356 QSize t( tabBarStack->sizeHint() ); 392 QSize t( tabBarStack->sizeHint() );
357 return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() ); 393 return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() );
358} 394}
359 395
360void OTabWidget::resizeEvent( QResizeEvent * ) 396void OTabWidget::resizeEvent( QResizeEvent * )
361{ 397{
362 setUpLayout(); 398 setUpLayout();
363} 399}
364 400
365int OTabWidget::getCurrentTab() 401int OTabWidget::getCurrentTab()
366{ 402{
367 if ( currentTab ) 403 if ( currentTab )
368 { 404 {
369 return currentTab->id(); 405 return currentTab->id();
370 } 406 }
371 return -1; 407 return -1;
372} 408}
373 409
diff --git a/libopie/otabwidget.h b/libopie/otabwidget.h
index 74d683b..0aa9bb8 100644
--- a/libopie/otabwidget.h
+++ b/libopie/otabwidget.h
@@ -1,265 +1,275 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org> 4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#ifndef OTABWIDGET_H 32#ifndef OTABWIDGET_H
33#define OTABWIDGET_H 33#define OTABWIDGET_H
34 34
35#include "otabinfo.h" 35#include "otabinfo.h"
36 36
37#include <qwidget.h> 37#include <qwidget.h>
38#include <qlist.h> 38#include <qlist.h>
39 39
40class OTabBar; 40class OTabBar;
41class QComboBox; 41class QComboBox;
42class QPixmap; 42class QPixmap;
43class QTabBar; 43class QTabBar;
44class QWidgetStack; 44class QWidgetStack;
45 45
46/** 46/**
47 * @class OTabWidget 47 * @class OTabWidget
48 * @brief The OTabWidget class provides a stack of widgets. 48 * @brief The OTabWidget class provides a stack of widgets.
49 * 49 *
50 * OTabWidget is a derivation of TrollTech's QTabWidget which provides 50 * OTabWidget is a derivation of TrollTech's QTabWidget which provides
51 * a stack of widgets. Widgets can be selected using either a tab bar or 51 * a stack of widgets. Widgets can be selected using either a tab bar or
52 * drop down list box. 52 * drop down list box.
53 * 53 *
54 * The normal way to use OTabWidget is to do the following in the 54 * The normal way to use OTabWidget is to do the following in the
55 * constructor: 55 * constructor:
56 * - Create a OTabWidget. 56 * - Create a OTabWidget.
57 * - Create a QWidget for each of the pages in the control, insert 57 * - Create a QWidget for each of the pages in the control, insert
58 * children into it, set up geometry management for it, and use addTab() 58 * children into it, set up geometry management for it, and use addTab()
59 * to add the widget. 59 * to add the widget.
60 */ 60 */
61class OTabWidget : public QWidget 61class OTabWidget : public QWidget
62{ 62{
63 Q_OBJECT 63 Q_OBJECT
64public: 64public:
65 65
66/** 66/**
67 * @enum TabStyle 67 * @enum TabStyle
68 * @brief Defines how the widget selection control is displayed. 68 * @brief Defines how the widget selection control is displayed.
69 * 69 *
70 * Valid values: 70 * Valid values:
71 * - Global: use globally selected options (qpe.conf - TabStyle & TabPosition) 71 * - Global: use globally selected options (qpe.conf - TabStyle & TabPosition)
72 * - TextTab: Tabbed widget selection with text labels 72 * - TextTab: Tabbed widget selection with text labels
73 * - IconTab: Tabbed widget selection with icon labels, text label for active widget 73 * - IconTab: Tabbed widget selection with icon labels, text label for active widget
74 * (similar to Opie launcher) 74 * (similar to Opie launcher)
75 * - TextList: Drop down list widget selection with text labels 75 * - TextList: Drop down list widget selection with text labels
76 * - IconList: Drop down list widget selection with icon & text labels 76 * - IconList: Drop down list widget selection with icon & text labels
77 */ 77 */
78 enum TabStyle { Global, TextTab, IconTab, TextList, IconList }; 78 enum TabStyle { Global, TextTab, IconTab, TextList, IconList };
79 79
80/** 80/**
81 * @enum TabPosition 81 * @enum TabPosition
82 * @brief Defines where the widget selection control is drawn. 82 * @brief Defines where the widget selection control is drawn.
83 * 83 *
84 * Valid values: 84 * Valid values:
85 * - Top: Widget selection control is drawn above widgets 85 * - Top: Widget selection control is drawn above widgets
86 * - Bottom: Widget selection control is drawn below widgets 86 * - Bottom: Widget selection control is drawn below widgets
87 */ 87 */
88 enum TabPosition { Top, Bottom }; 88 enum TabPosition { Top, Bottom };
89 89
90/** 90/**
91 * @fn OTabWidget( QWidget *parent = 0, const char *name = 0, TabStyle s = Global, TabPosition p = Top ) 91 * @fn OTabWidget( QWidget *parent = 0, const char *name = 0, TabStyle s = Global, TabPosition p = Top )
92 * @brief Object constructor. 92 * @brief Object constructor.
93 * 93 *
94 * @param parent Pointer to parent of this control. 94 * @param parent Pointer to parent of this control.
95 * @param name Name of control. 95 * @param name Name of control.
96 * @param s Style of widget selection control. 96 * @param s Style of widget selection control.
97 * @param p Position of the widget selection control. 97 * @param p Position of the widget selection control.
98 * 98 *
99 * Constructs a new OTabWidget control with parent and name. The style and position parameters 99 * Constructs a new OTabWidget control with parent and name. The style and position parameters
100 * determine how the widget selection control will be displayed. 100 * determine how the widget selection control will be displayed.
101 */ 101 */
102 OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top ); 102 OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top );
103 103
104/** 104/**
105 * @fn ~OTabWidget() 105 * @fn ~OTabWidget()
106 * @brief Object destructor. 106 * @brief Object destructor.
107 */ 107 */
108 ~OTabWidget(); 108 ~OTabWidget();
109 109
110/** 110/**
111 * @fn addTab( QWidget *child, const QString &icon, const QString &label ) 111 * @fn addTab( QWidget *child, const QString &icon, const QString &label )
112 * @brief Add new widget to control. 112 * @brief Add new widget to control.
113 * 113 *
114 * @param child Widget control. 114 * @param child Widget control.
115 * @param icon Path to icon. 115 * @param icon Path to icon.
116 * @param label Text label. 116 * @param label Text label.
117 */ 117 */
118 void addTab( QWidget *, const QString &, const QString & ); 118 void addTab( QWidget *, const QString &, const QString & );
119 119
120/** 120/**
121 * @fn removePage( QWidget *widget ) 121 * @fn removePage( QWidget *widget )
122 * @brief Remove widget from control. Does not delete widget. 122 * @brief Remove widget from control. Does not delete widget.
123 * 123 *
124 * @param widget Widget control to be removed. 124 * @param widget Widget control to be removed.
125 */ 125 */
126 void removePage( QWidget * ); 126 void removePage( QWidget * );
127 127
128/** 128/**
129 * @fn changeTab( QWidget *widget, const QIconSet &icon, const QString &label )
130 * @brief Change text and/or icon for existing tab
131 *
132 * @param child Widget control.
133 * @param icon Path to icon.
134 * @param label Text label.
135 */
136 void changeTab( QWidget *, const QString &, const QString & );
137
138/**
129 * @fn tabStyle() 139 * @fn tabStyle()
130 * @brief Returns current widget selection control style. 140 * @brief Returns current widget selection control style.
131 */ 141 */
132 TabStyle tabStyle() const; 142 TabStyle tabStyle() const;
133 143
134/** 144/**
135 * @fn setTabStyle( TabStyle s ) 145 * @fn setTabStyle( TabStyle s )
136 * @brief Set the current widget selection control style. 146 * @brief Set the current widget selection control style.
137 * 147 *
138 * @param s New style to be used. 148 * @param s New style to be used.
139 */ 149 */
140 void setTabStyle( TabStyle ); 150 void setTabStyle( TabStyle );
141 151
142/** 152/**
143 * @fn tabPosition() 153 * @fn tabPosition()
144 * @brief Returns current widget selection control position. 154 * @brief Returns current widget selection control position.
145 */ 155 */
146 TabPosition tabPosition() const; 156 TabPosition tabPosition() const;
147 157
148/** 158/**
149 * @fn setTabPosition( TabPosition p ) 159 * @fn setTabPosition( TabPosition p )
150 * @brief Set the current widget selection control position. 160 * @brief Set the current widget selection control position.
151 * 161 *
152 * @param p New position of widget selection control. 162 * @param p New position of widget selection control.
153 */ 163 */
154 void setTabPosition( TabPosition ); 164 void setTabPosition( TabPosition );
155 165
156/** 166/**
157 * @fn setCurrentTab( QWidget *childwidget ) 167 * @fn setCurrentTab( QWidget *childwidget )
158 * @brief Selects and brings to top the desired widget by using widget pointer. 168 * @brief Selects and brings to top the desired widget by using widget pointer.
159 * 169 *
160 * @param childwidget Widget to select. 170 * @param childwidget Widget to select.
161 */ 171 */
162 void setCurrentTab( QWidget * ); 172 void setCurrentTab( QWidget * );
163 173
164/** 174/**
165 * @fn setCurrentTab( const QString &tabname ) 175 * @fn setCurrentTab( const QString &tabname )
166 * @brief Selects and brings to top the desired widget, by using label. 176 * @brief Selects and brings to top the desired widget, by using label.
167 * 177 *
168 * @param tabname Text label for widget to select. 178 * @param tabname Text label for widget to select.
169 */ 179 */
170 void setCurrentTab( const QString & ); 180 void setCurrentTab( const QString & );
171 181
172/** 182/**
173 * @fn setCurrentTab( int ) 183 * @fn setCurrentTab( int )
174 * @brief Selects and brings to top the desired widget, by using id. 184 * @brief Selects and brings to top the desired widget, by using id.
175 * 185 *
176 * @param tab id for widget to select. 186 * @param tab id for widget to select.
177 */ 187 */
178 void setCurrentTab(int); 188 void setCurrentTab(int);
179 189
180/** 190/**
181 * @fn sizeHint() 191 * @fn sizeHint()
182 * @brief Reimplemented for internal purposes. 192 * @brief Reimplemented for internal purposes.
183 */ 193 */
184 QSize sizeHint() const; 194 QSize sizeHint() const;
185 195
186/** 196/**
187 * @fn getCurrentTab( ) 197 * @fn getCurrentTab( )
188 * @brief returns current tab id. 198 * @brief returns current tab id.
189 */ 199 */
190 int getCurrentTab(); 200 int getCurrentTab();
191 201
192 202
193protected: 203protected:
194 204
195/** 205/**
196 * @fn resizeEvent( QResizeEvent * ) 206 * @fn resizeEvent( QResizeEvent * )
197 * @brief Reimplemented for internal purposes. 207 * @brief Reimplemented for internal purposes.
198 */ 208 */
199 void resizeEvent( QResizeEvent * ); 209 void resizeEvent( QResizeEvent * );
200 210
201private: 211private:
202 OTabInfoList tabs; 212 OTabInfoList tabs;
203 OTabInfo *currentTab; 213 OTabInfo *currentTab;
204 214
205 TabStyle tabBarStyle; 215 TabStyle tabBarStyle;
206 TabPosition tabBarPosition; 216 TabPosition tabBarPosition;
207 217
208 QWidgetStack *tabBarStack; 218 QWidgetStack *tabBarStack;
209 OTabBar *tabBar; 219 OTabBar *tabBar;
210 QComboBox *tabList; 220 QComboBox *tabList;
211 221
212 QWidgetStack *widgetStack; 222 QWidgetStack *widgetStack;
213 223
214/** 224/**
215 * @fn loadSmooth( const QString &name ) 225 * @fn loadSmooth( const QString &name )
216 * @brief Loads icon for widget. 226 * @brief Loads icon for widget.
217 * 227 *
218 * @param name Name of icon image file. 228 * @param name Name of icon image file.
219 */ 229 */
220 QPixmap loadSmooth( const QString & ); 230 QPixmap loadSmooth( const QString & );
221 231
222/** 232/**
223 * @fn selectTab( OTabInfo *tab ) 233 * @fn selectTab( OTabInfo *tab )
224 * @brief Internal function to select desired widget. 234 * @brief Internal function to select desired widget.
225 * 235 *
226 * @param tab Pointer to data for widget. 236 * @param tab Pointer to data for widget.
227 */ 237 */
228 void selectTab( OTabInfo * ); 238 void selectTab( OTabInfo * );
229 239
230/** 240/**
231 * @fn setUpLayout() 241 * @fn setUpLayout()
232 * @brief Internal function to adjust layout. 242 * @brief Internal function to adjust layout.
233 */ 243 */
234 void setUpLayout(); 244 void setUpLayout();
235 245
236 246
237signals: 247signals:
238/** 248/**
239 * @fn currentChanegd( QWidget *widget ) 249 * @fn currentChanegd( QWidget *widget )
240 * @brief This signal is emitted whenever the widget has changed. 250 * @brief This signal is emitted whenever the widget has changed.
241 * 251 *
242 * @param widget Pointer to new current widget. 252 * @param widget Pointer to new current widget.
243 */ 253 */
244 void currentChanged( QWidget * ); 254 void currentChanged( QWidget * );
245 255
246private slots: 256private slots:
247 257
248/** 258/**
249 * @fn slotTabBarSelected( int id ) 259 * @fn slotTabBarSelected( int id )
250 * @brief Slot which is called when a tab is selected. 260 * @brief Slot which is called when a tab is selected.
251 * 261 *
252 * @param id ID of widget selected. 262 * @param id ID of widget selected.
253 */ 263 */
254 void slotTabBarSelected( int ); 264 void slotTabBarSelected( int );
255 265
256/** 266/**
257 * @fn slotTabListSelected( int index ) 267 * @fn slotTabListSelected( int index )
258 * @brief Slot which is called when a drop down selection is made. 268 * @brief Slot which is called when a drop down selection is made.
259 * 269 *
260 * @param id Index of widget selected. 270 * @param id Index of widget selected.
261 */ 271 */
262 void slotTabListSelected( int ); 272 void slotTabListSelected( int );
263}; 273};
264 274
265#endif 275#endif