summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/otabinfo.h50
-rw-r--r--libopie2/opieui/otabwidget.cpp440
-rw-r--r--libopie2/opieui/otabwidget.h69
3 files changed, 301 insertions, 258 deletions
diff --git a/libopie2/opieui/otabinfo.h b/libopie2/opieui/otabinfo.h
index d6d5abf..99ff10e 100644
--- a/libopie2/opieui/otabinfo.h
+++ b/libopie2/opieui/otabinfo.h
@@ -1,28 +1,28 @@
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.
@@ -82,6 +82,14 @@ public:
82 int id() const { return i; } 82 int id() const { return i; }
83 83
84 /** 84 /**
85 * @fn setId( int id )
86 * @brief Set Id for tab.
87 *
88 * @param id integer tab identifier.
89 */
90 void setId( int id ) { i = id; }
91
92 /**
85 * @fn label()const 93 * @fn label()const
86 * @brief Returns text label for widget. 94 * @brief Returns text label for widget.
87 */ 95 */
diff --git a/libopie2/opieui/otabwidget.cpp b/libopie2/opieui/otabwidget.cpp
index d23b1c9..01747e1 100644
--- a/libopie2/opieui/otabwidget.cpp
+++ b/libopie2/opieui/otabwidget.cpp
@@ -1,28 +1,28 @@
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, 2005 Dan Williams <drw@handhelds.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.
@@ -45,88 +45,82 @@ using namespace Opie::Ui;
45 45
46OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p ) 46OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p )
47 : QWidget( parent, name ) 47 : QWidget( parent, name )
48 , m_currTab( 0l )
49 , m_usingTabs( true )
50 , m_tabBar( 0l )
51 , m_tabList( 0l )
48{ 52{
49 if ( s == Global ) 53 if ( s == Global )
50 { 54 {
55 // Read Opie global settings for style and position
51 Config config( "qpe" ); 56 Config config( "qpe" );
52 config.setGroup( "Appearance" ); 57 config.setGroup( "Appearance" );
58
59 // Style
53 s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); 60 s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab );
54 if ( s <= Global || s > IconList) 61 if ( s <= Global || s > IconList)
55 {
56 s = IconTab; 62 s = IconTab;
57 }
58 QString pos = config.readEntry( "TabPosition", "Top");
59 if ( pos == "Bottom" )
60 {
61 p = Bottom;
62 }
63 else
64 {
65 p = Top;
66 }
67 }
68
69 widgetStack = new QWidgetStack( this, "widgetstack" );
70 widgetStack->setFrameStyle( QFrame::NoFrame );
71 widgetStack->setLineWidth( style().defaultFrameWidth() );
72
73 tabBarStack = new QWidgetStack( this, "tabbarstack" );
74 63
75 tabBar = new OTabBar( tabBarStack, "tabbar" ); 64 // Position
76 tabBarStack->addWidget( tabBar, 0 ); 65 ( config.readEntry( "TabPosition", "Top" ) == "Bottom" ) ? p = Bottom
77 connect( tabBar, SIGNAL( selected(int) ), this, SLOT( slotTabBarSelected(int) ) ); 66 : p = Top;
67 }
78 68
79 tabList = new QComboBox( false, tabBarStack, "tablist" ); 69 // Initialize widget stack for tab widgets
80 tabBarStack->addWidget( tabList, 1 ); 70 m_widgetStack = new QWidgetStack( this );
81 connect( tabList, SIGNAL( activated(int) ), this, SLOT( slotTabListSelected(int) ) ); 71 m_widgetStack->setFrameStyle( QFrame::NoFrame );
72 m_widgetStack->setLineWidth( style().defaultFrameWidth() );
82 73
83 tabBarPosition = p; 74 // Set initial selector control style and position
84 setTabStyle( s ); 75 setTabStyle( s );
85 setTabPosition( p ); 76 setTabPosition( p );
86
87 currTab= 0x0;
88} 77}
89 78
90OTabWidget::~OTabWidget() 79OTabWidget::~OTabWidget()
91{ 80{
92 tabs.setAutoDelete( true ); 81 m_tabs.setAutoDelete( true );
93 tabs.clear(); 82 m_tabs.clear();
94} 83}
95 84
96void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) 85void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
97{ 86{
98 QPixmap iconset = loadSmooth( icon ); 87 int tabid = -1;
99 88
100 QTab *tab = new QTab(); 89 if ( m_usingTabs )
101 if ( tabBarStyle == IconTab )
102 {
103 tab->label = QString::null;
104 }
105 else
106 {
107 tab->label = label;
108 }
109 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
110 { 90 {
111 tab->iconset = new QIconSet( iconset ); 91 // Create new tab in tab bar
112 } 92 QTab *tab = new QTab();
113 int tabid = tabBar->addTab( tab );
114 93
115 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 94 // Set label (and icon if necessary)
116 { 95 if ( m_tabBarStyle == IconTab )
117 tabList->insertItem( iconset, label, -1 ); 96 {
97 tab->label = QString::null;
98 tab->iconset = new QIconSet( loadSmooth( icon ) );
99 }
100 else
101 tab->label = label;
102
103 tabid = m_tabBar->addTab( tab );
118 } 104 }
119 else 105 else
120 { 106 {
121 tabList->insertItem( label ); 107 // Insert entry (with icon if necessary) into drop down list
108 if ( m_tabBarStyle == IconList )
109 m_tabList->insertItem( loadSmooth( icon ), label, -1 );
110 else
111 m_tabList->insertItem( label );
122 } 112 }
123 113
124 widgetStack->addWidget( child, tabid ); 114 // Add widget to stack
125 widgetStack->raiseWidget( child ); 115 m_widgetStack->addWidget( child, tabid );
126 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); 116 m_widgetStack->raiseWidget( child );
117 m_widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
127 118
119 // Keep track of tab information
128 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); 120 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label );
129 tabs.append( tabinfo ); 121 m_tabs.append( tabinfo );
122
123 // Make newly added tab the current one displayed
130 selectTab( tabinfo ); 124 selectTab( tabinfo );
131} 125}
132 126
@@ -134,33 +128,42 @@ void OTabWidget::removePage( QWidget *childwidget )
134{ 128{
135 if ( childwidget ) 129 if ( childwidget )
136 { 130 {
137 OTabInfo *tab = tabs.first(); 131 // Find tab information for desired widget
132 OTabInfo *tab = m_tabs.first();
138 while ( tab && tab->control() != childwidget ) 133 while ( tab && tab->control() != childwidget )
139 { 134 tab = m_tabs.next();
140 tab = tabs.next(); 135
141 }
142 if ( tab && tab->control() == childwidget ) 136 if ( tab && tab->control() == childwidget )
143 { 137 {
144 tabBar->setTabEnabled( tab->id(), FALSE ); 138 if ( m_usingTabs )
145 tabBar->removeTab( tabBar->tab( tab->id() ) );
146 int i = 0;
147 while ( i < tabList->count() && tabList->text( i ) != tab->label() )
148 { 139 {
149 i++; 140 // Remove tab from tab bar
141 m_tabBar->setTabEnabled( tab->id(), false );
142 m_tabBar->removeTab( m_tabBar->tab( tab->id() ) );
150 } 143 }
151 if ( tabList->text( i ) == tab->label() ) 144 else
152 { 145 {
153 tabList->removeItem( i ); 146 // Remove entry from drop down list
147 int i = 0;
148 while ( i < m_tabList->count() && m_tabList->text( i ) != tab->label() )
149 i++;
150 if ( m_tabList->text( i ) == tab->label() )
151 m_tabList->removeItem( i );
154 } 152 }
155 widgetStack->removeWidget( childwidget ); 153
156 tabs.remove( tab ); 154 // Remove widget from stack
155 m_widgetStack->removeWidget( childwidget );
156
157 // Get rid of tab information
158 m_tabs.remove( tab );
157 delete tab; 159 delete tab;
158 currTab = tabs.current();
159 if ( !currTab )
160 {
161 widgetStack->setFrameStyle( QFrame::NoFrame );
162 }
163 160
161 // Reset current tab
162 m_currTab = m_tabs.current();
163 if ( !m_currTab )
164 m_widgetStack->setFrameStyle( QFrame::NoFrame );
165
166 // Redraw widget
164 setUpLayout(); 167 setUpLayout();
165 } 168 }
166 } 169 }
@@ -168,46 +171,53 @@ void OTabWidget::removePage( QWidget *childwidget )
168 171
169void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) 172void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label)
170{ 173{
171 OTabInfo *currtab = tabs.first(); 174 // Find tab information for desired widget
175 OTabInfo *currtab = m_tabs.first();
172 while ( currtab && currtab->control() != widget ) 176 while ( currtab && currtab->control() != widget )
173 { 177 currtab = m_tabs.next();
174 currtab = tabs.next(); 178
175 }
176 if ( currtab && currtab->control() == widget ) 179 if ( currtab && currtab->control() == widget )
177 { 180 {
178 QTab *tab = tabBar->tab( currtab->id() );
179 QPixmap icon( loadSmooth( iconset ) ); 181 QPixmap icon( loadSmooth( iconset ) );
180 tab->setText( label ); 182
181 if ( tabBarStyle == IconTab ) 183 if ( m_usingTabs )
182 tab->setIconSet( icon );
183 int i = 0;
184 while ( i < tabList->count() && tabList->text( i ) != currtab->label() )
185 { 184 {
186 i++; 185 // Update tab label and icon (if necessary)
186 QTab *tab = m_tabBar->tab( currtab->id() );
187 tab->setText( label );
188 if ( m_tabBarStyle == IconTab )
189 tab->setIconSet( icon );
187 } 190 }
188 if ( i < tabList->count() && tabList->text( i ) == currtab->label() ) 191 else
189 { 192 {
190 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 193 // Update entry label and icon (if necessary)
191 { 194 int i = 0;
192 tabList->changeItem( icon, label, i ); 195 while ( i < m_tabList->count() && m_tabList->text( i ) != currtab->label() )
193 } 196 i++;
194 else 197 if ( i < m_tabList->count() && m_tabList->text( i ) == currtab->label() )
195 { 198 {
196 tabList->changeItem( label, i ); 199 if ( m_tabBarStyle == IconList )
200 m_tabList->changeItem( icon, label, i );
201 else
202 m_tabList->changeItem( label, i );
197 } 203 }
198 } 204 }
205
206 // Update tab information
199 currtab->setLabel( label ); 207 currtab->setLabel( label );
200 currtab->setIcon( iconset ); 208 currtab->setIcon( iconset );
209
210 // Redraw widget
211 setUpLayout();
201 } 212 }
202 setUpLayout();
203} 213}
204 214
205void OTabWidget::setCurrentTab( QWidget *childwidget ) 215void OTabWidget::setCurrentTab( QWidget *childwidget )
206{ 216{
207 OTabInfo *currtab = tabs.first(); 217 OTabInfo *currtab = m_tabs.first();
208 while ( currtab && currtab->control() != childwidget ) 218 while ( currtab && currtab->control() != childwidget )
209 { 219 {
210 currtab = tabs.next(); 220 currtab = m_tabs.next();
211 } 221 }
212 if ( currtab && currtab->control() == childwidget ) 222 if ( currtab && currtab->control() == childwidget )
213 { 223 {
@@ -217,10 +227,10 @@ void OTabWidget::setCurrentTab( QWidget *childwidget )
217 227
218void OTabWidget::setCurrentTab( const QString &tabname ) 228void OTabWidget::setCurrentTab( const QString &tabname )
219{ 229{
220 OTabInfo *newtab = tabs.first(); 230 OTabInfo *newtab = m_tabs.first();
221 while ( newtab && newtab->label() != tabname ) 231 while ( newtab && newtab->label() != tabname )
222 { 232 {
223 newtab = tabs.next(); 233 newtab = m_tabs.next();
224 } 234 }
225 if ( newtab && newtab->label() == tabname ) 235 if ( newtab && newtab->label() == tabname )
226 { 236 {
@@ -230,10 +240,10 @@ void OTabWidget::setCurrentTab( const QString &tabname )
230 240
231void OTabWidget::setCurrentTab(int tabindex) 241void OTabWidget::setCurrentTab(int tabindex)
232{ 242{
233 OTabInfo *newtab = tabs.first(); 243 OTabInfo *newtab = m_tabs.first();
234 while ( newtab && newtab->id() != tabindex ) 244 while ( newtab && newtab->id() != tabindex )
235 { 245 {
236 newtab = tabs.next(); 246 newtab = m_tabs.next();
237 } 247 }
238 if ( newtab && newtab->id() == tabindex ) 248 if ( newtab && newtab->id() == tabindex )
239 { 249 {
@@ -244,92 +254,113 @@ void OTabWidget::setCurrentTab(int tabindex)
244 254
245OTabWidget::TabStyle OTabWidget::tabStyle() const 255OTabWidget::TabStyle OTabWidget::tabStyle() const
246{ 256{
247 return tabBarStyle; 257 return m_tabBarStyle;
248} 258}
249 259
250void OTabWidget::setTabStyle( TabStyle s ) 260void OTabWidget::setTabStyle( TabStyle s )
251{ 261{
252 tabBarStyle = s; 262 // Get out if new and current styles are the same
253 if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) 263 if ( s == m_tabBarStyle )
264 return;
265
266 // Delete current selector control
267 if ( m_usingTabs )
268 {
269 delete m_tabBar;
270 m_tabBar = 0l;
271 }
272 else
254 { 273 {
255 QTab *currtab; 274 delete m_tabList;
256 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) 275 m_tabList = 0l;
276 }
277
278 // Set new style information
279 m_tabBarStyle = s;
280 m_usingTabs = ( m_tabBarStyle == TextTab || m_tabBarStyle == IconTab );
281
282 // Create new selector control and populate with tab information
283 if ( m_usingTabs )
284 {
285 // Create new tab bar selector
286 m_tabBar = new OTabBar( this );
287 connect( m_tabBar, SIGNAL(selected(int)), this, SLOT(slotTabBarSelected(int)) );
288
289 // Add all current tabs to tab bar
290 for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() )
257 { 291 {
258 currtab = tabBar->tab( tabinfo->id() ); 292 // Create new tab in tab bar
259 if ( tabBarStyle == IconTab ) 293 QTab *tab = new QTab();
294
295 // Set label (and icon if necessary)
296 if ( m_tabBarStyle == IconTab )
260 { 297 {
261 currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); 298 tab->label = QString::null;
262 if ( tabinfo == currTab ) 299 tab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) );
263 currtab->setText( tabinfo->label() );
264 else
265 currtab->setText( QString::null );
266 } 300 }
267 else 301 else
268 { 302 tab->label = tabinfo->label();
269 currtab->iconset = 0x0; 303
270 currtab->setText( tabinfo->label() ); 304 // Add tab and save its Id
271 } 305 int tabid = m_tabBar->addTab( tab );
306 tabinfo->setId( tabid );
272 } 307 }
273 tabBarStack->raiseWidget( tabBar );
274 } 308 }
275 else if ( tabBarStyle == TextList || tabBarStyle == IconList ) 309 else
276 { 310 {
277 tabList->clear(); 311 // Create new drop down list selector
278 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) 312 m_tabList = new QComboBox( false, this );
313 connect( m_tabList, SIGNAL(activated(int)), this, SLOT(slotTabListSelected(int)) );
314
315 // Add all current tabs to drop down list
316 for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() )
279 { 317 {
280 if ( tabBarStyle == IconList ) 318 if ( m_tabBarStyle == IconList )
281 { 319 m_tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() );
282 tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() );
283 }
284 else 320 else
285 { 321 m_tabList->insertItem( tabinfo->label() );
286 tabList->insertItem( tabinfo->label() );
287 }
288 } 322 }
289 tabBarStack->raiseWidget( tabList );
290 } 323 }
324
325 // Redraw widget
291 setUpLayout(); 326 setUpLayout();
292} 327}
293 328
294OTabWidget::TabPosition OTabWidget::tabPosition() const 329OTabWidget::TabPosition OTabWidget::tabPosition() const
295{ 330{
296 return tabBarPosition; 331 return m_tabBarPosition;
297} 332}
298 333
299void OTabWidget::setTabPosition( TabPosition p ) 334void OTabWidget::setTabPosition( TabPosition p )
300{ 335{
301 tabBarPosition = p; 336 m_tabBarPosition = p;
302 if ( tabBarPosition == Top ) 337
303 { 338 // If using the tab bar selector, set its shape
304 tabBar->setShape( QTabBar::RoundedAbove ); 339 if ( m_usingTabs )
305 }
306 else
307 { 340 {
308 tabBar->setShape( QTabBar::RoundedBelow ); 341 ( m_tabBarPosition == Top ) ? m_tabBar->setShape( QTabBar::RoundedAbove )
342 : m_tabBar->setShape( QTabBar::RoundedBelow );
309 } 343 }
344
345 // Redraw widget
310 setUpLayout(); 346 setUpLayout();
311} 347}
312 348
313void OTabWidget::slotTabBarSelected( int id ) 349void OTabWidget::slotTabBarSelected( int id )
314{ 350{
315 OTabInfo *newtab = tabs.first(); 351 OTabInfo *newtab = m_tabs.first();
316 while ( newtab && newtab->id() != id ) 352 while ( newtab && newtab->id() != id )
317 { 353 newtab = m_tabs.next();
318 newtab = tabs.next(); 354
319 }
320 if ( newtab && newtab->id() == id ) 355 if ( newtab && newtab->id() == id )
321 {
322 selectTab( newtab ); 356 selectTab( newtab );
323 }
324} 357}
325 358
326void OTabWidget::slotTabListSelected( int index ) 359void OTabWidget::slotTabListSelected( int index )
327{ 360{
328 OTabInfo *newtab = tabs.at( index ); 361 OTabInfo *newtab = m_tabs.at( index );
329 if ( newtab ) 362 if ( newtab )
330 {
331 selectTab( newtab ); 363 selectTab( newtab );
332 }
333} 364}
334 365
335QPixmap OTabWidget::loadSmooth( const QString &name ) 366QPixmap OTabWidget::loadSmooth( const QString &name )
@@ -341,85 +372,94 @@ QPixmap OTabWidget::loadSmooth( const QString &name )
341 372
342void OTabWidget::selectTab( OTabInfo *tab ) 373void OTabWidget::selectTab( OTabInfo *tab )
343{ 374{
344 if ( tabBarStyle == IconTab ) 375 if ( m_tabBarStyle == IconTab )
345 { 376 {
346 if ( currTab ) 377 // Remove text label from currently selected tab
378 if ( m_currTab )
347 { 379 {
348 tabBar->tab( currTab->id() )->setText( QString::null ); 380 m_tabBar->tab( m_currTab->id() )->setText( QString::null );
349 setUpLayout(); 381 //setUpLayout();
350 } 382 }
351 tabBar->tab( tab->id() )->setText( tab->label() ); 383
352 tabBar->setCurrentTab( tab->id() ); 384 // Set text label for newly selected tab
385 m_tabBar->tab( tab->id() )->setText( tab->label() );
386 m_tabBar->setCurrentTab( tab->id() );
387
353 setUpLayout(); 388 setUpLayout();
354 tabBar->update();
355 } 389 }
356 else 390 else if ( m_tabBarStyle == TextTab )
357 { 391 {
358 tabBar->setCurrentTab( tab->id() ); 392 m_tabBar->setCurrentTab( tab->id() );
359 } 393 }
360 394
361 widgetStack->raiseWidget( tab->control() ); 395 m_widgetStack->raiseWidget( tab->control() );
362 396
363 emit currentChanged( tab->control() ); 397 emit currentChanged( tab->control() );
364 398
365 currTab = tab; 399 m_currTab = tab;
366} 400}
367 401
368void OTabWidget::setUpLayout() 402void OTabWidget::setUpLayout()
369{ 403{
370 tabBar->layoutTabs(); 404 if ( m_usingTabs )
371 QSize t( tabBarStack->sizeHint() );
372 if ( tabBarStyle == IconTab )
373 { 405 {
374 if ( t.width() > width() ) 406 m_tabBar->update();
375 t.setWidth( width() ); 407 m_tabBar->layoutTabs();
376 } 408 }
377 else 409}
410
411void OTabWidget::resizeEvent( QResizeEvent * )
412{
413 QSize t;
414
415 if ( m_usingTabs )
378 { 416 {
379 t.setWidth( width() ); 417 m_tabBar->layoutTabs();
418 t = m_tabBar->sizeHint();
380 } 419 }
381 int lw = widgetStack->lineWidth(); 420 else
382 if ( tabBarPosition == Bottom ) 421 t = m_tabList->sizeHint();
422
423 t.setWidth( width() );
424
425 int lw = m_widgetStack->lineWidth();
426 if ( m_tabBarPosition == Bottom )
383 { 427 {
384 tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); 428 if ( m_usingTabs )
385 widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); 429 m_tabBar->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() );
430 else
431 m_tabList->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() );
432
433 m_widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) );
386 } 434 }
387 else 435 else
388 { 436 {
389 tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); 437 if ( m_usingTabs )
390 widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) ); 438 m_tabBar->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() );
439 else
440 m_tabList->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() );
441
442 m_widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) );
391 } 443 }
392 444
393 if ( autoMask() ) 445 if ( autoMask() )
394 updateMask(); 446 updateMask();
395} 447}
396 448
397QSize OTabWidget::sizeHint() const
398{
399 QSize s( widgetStack->sizeHint() );
400 QSize t( tabBarStack->sizeHint() );
401 return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() );
402}
403
404void OTabWidget::resizeEvent( QResizeEvent * )
405{
406 setUpLayout();
407}
408
409int OTabWidget::currentTab() 449int OTabWidget::currentTab()
410{ 450{
411 if ( currTab ) 451 if ( m_currTab )
412 { 452 {
413 return currTab->id(); 453 return m_currTab->id();
414 } 454 }
415 return -1; 455 return -1;
416} 456}
417 457
418QWidget* OTabWidget::currentWidget()const 458QWidget* OTabWidget::currentWidget()const
419{ 459{
420 if ( currTab ) 460 if ( m_currTab )
421 { 461 {
422 return currTab->control(); 462 return m_currTab->control();
423 } 463 }
424 464
425 return 0; 465 return 0;
diff --git a/libopie2/opieui/otabwidget.h b/libopie2/opieui/otabwidget.h
index b3423e8..e925592 100644
--- a/libopie2/opieui/otabwidget.h
+++ b/libopie2/opieui/otabwidget.h
@@ -1,27 +1,27 @@
1/* 1/*
2                 This file is part of the Opie Project 2 This file is part of the Opie Project
3              Copyright (C) 2002 Dan Williams <williamsdr@acm.org> 3 Copyright (C) 2002, 2005 Dan Williams <drw@handhelds.org>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6 .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7_;:, .> :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11- . .-<_> .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13    .%`+i>       _;_. 13 .%`+i> _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++=   -.     .`     .: details. 20++= -. .` .: details.
21 :     =  ...= . :.=- 21: = ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22-. .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
@@ -194,12 +194,6 @@ class OTabWidget : public QWidget
194 void setCurrentTab(int); 194 void setCurrentTab(int);
195 195
196/** 196/**
197 * @fn sizeHint()const
198 * @brief Reimplemented for internal purposes.
199 */
200 QSize sizeHint() const;
201
202/**
203 * @fn currentTab( ) 197 * @fn currentTab( )
204 * @brief returns current tab id. 198 * @brief returns current tab id.
205 */ 199 */
@@ -221,17 +215,18 @@ protected:
221 void resizeEvent( QResizeEvent * ); 215 void resizeEvent( QResizeEvent * );
222 216
223private: 217private:
224 OTabInfoList tabs; 218 OTabInfoList m_tabs; // List of information for tabs
225 OTabInfo *currTab; 219 OTabInfo *m_currTab; // Current tab displayed
226 220 TabStyle m_tabBarStyle; // Current style of control
227 TabStyle tabBarStyle; 221 TabPosition m_tabBarPosition; // Position of selector control
228 TabPosition tabBarPosition; 222 bool m_usingTabs; // Indicates whether style is either TextTab or IconTab
229 223 // (saves from having to always check for these 2 values)
230 QWidgetStack *tabBarStack; 224
231 OTabBar *tabBar; 225 // UI components
232 QComboBox *tabList; 226 OTabBar *m_tabBar;
227 QComboBox *m_tabList;
228 QWidgetStack *m_widgetStack;
233 229
234 QWidgetStack *widgetStack;
235 class Private; 230 class Private;
236 Private* d; 231 Private* d;
237 232