summaryrefslogtreecommitdiff
path: root/libopie
authordrw <drw>2003-06-03 22:11:32 (UTC)
committer drw <drw>2003-06-03 22:11:32 (UTC)
commit41ffd8ca271b6803558389d0c10ecb289517c896 (patch) (unidiff)
tree3d858b42989219ca7f38db0d01e7d88a0bff01c0 /libopie
parent94223c1a074b98d636b546b5a6b237ba91ee1f51 (diff)
downloadopie-41ffd8ca271b6803558389d0c10ecb289517c896.zip
opie-41ffd8ca271b6803558389d0c10ecb289517c896.tar.gz
opie-41ffd8ca271b6803558389d0c10ecb289517c896.tar.bz2
Make sure tabPosition is initialized properly, thanks zecke for finding
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/otabwidget.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/libopie/otabwidget.cpp b/libopie/otabwidget.cpp
index 05aafd4..fe2c60f 100644
--- a/libopie/otabwidget.cpp
+++ b/libopie/otabwidget.cpp
@@ -1,269 +1,270 @@
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 tabBarPosition = p;
78 setTabStyle( s ); 79 setTabStyle( s );
79 setTabPosition( p ); 80 setTabPosition( p );
80 81
81 currTab= 0x0; 82 currTab= 0x0;
82} 83}
83 84
84OTabWidget::~OTabWidget() 85OTabWidget::~OTabWidget()
85{ 86{
86} 87}
87 88
88void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) 89void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
89{ 90{
90 QPixmap iconset = loadSmooth( icon ); 91 QPixmap iconset = loadSmooth( icon );
91 92
92 QTab *tab = new QTab(); 93 QTab *tab = new QTab();
93 if ( tabBarStyle == IconTab ) 94 if ( tabBarStyle == IconTab )
94 { 95 {
95 tab->label = QString::null; 96 tab->label = QString::null;
96 } 97 }
97 else 98 else
98 { 99 {
99 tab->label = label; 100 tab->label = label;
100 } 101 }
101 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 102 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
102 { 103 {
103 tab->iconset = new QIconSet( iconset ); 104 tab->iconset = new QIconSet( iconset );
104 } 105 }
105 int tabid = tabBar->addTab( tab ); 106 int tabid = tabBar->addTab( tab );
106 107
107 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 108 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
108 { 109 {
109 tabList->insertItem( iconset, label, -1 ); 110 tabList->insertItem( iconset, label, -1 );
110 } 111 }
111 else 112 else
112 { 113 {
113 tabList->insertItem( label ); 114 tabList->insertItem( label );
114 } 115 }
115 116
116 widgetStack->addWidget( child, tabid ); 117 widgetStack->addWidget( child, tabid );
117 widgetStack->raiseWidget( child ); 118 widgetStack->raiseWidget( child );
118 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); 119 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
119 120
120 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); 121 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label );
121 tabs.append( tabinfo ); 122 tabs.append( tabinfo );
122 selectTab( tabinfo ); 123 selectTab( tabinfo );
123} 124}
124 125
125void OTabWidget::removePage( QWidget *childwidget ) 126void OTabWidget::removePage( QWidget *childwidget )
126{ 127{
127 if ( childwidget ) 128 if ( childwidget )
128 { 129 {
129 OTabInfo *tab = tabs.first(); 130 OTabInfo *tab = tabs.first();
130 while ( tab && tab->control() != childwidget ) 131 while ( tab && tab->control() != childwidget )
131 { 132 {
132 tab = tabs.next(); 133 tab = tabs.next();
133 } 134 }
134 if ( tab && tab->control() == childwidget ) 135 if ( tab && tab->control() == childwidget )
135 { 136 {
136 tabBar->setTabEnabled( tab->id(), FALSE ); 137 tabBar->setTabEnabled( tab->id(), FALSE );
137 tabBar->removeTab( tabBar->tab( tab->id() ) ); 138 tabBar->removeTab( tabBar->tab( tab->id() ) );
138 int i = 0; 139 int i = 0;
139 while ( i < tabList->count() && tabList->text( i ) != tab->label() ) 140 while ( i < tabList->count() && tabList->text( i ) != tab->label() )
140 { 141 {
141 i++; 142 i++;
142 } 143 }
143 if ( tabList->text( i ) == tab->label() ) 144 if ( tabList->text( i ) == tab->label() )
144 { 145 {
145 tabList->removeItem( i ); 146 tabList->removeItem( i );
146 } 147 }
147 widgetStack->removeWidget( childwidget ); 148 widgetStack->removeWidget( childwidget );
148 tabs.remove( tab ); 149 tabs.remove( tab );
149 delete tab; 150 delete tab;
150 currTab = tabs.current(); 151 currTab = tabs.current();
151 if ( !currTab ) 152 if ( !currTab )
152 { 153 {
153 widgetStack->setFrameStyle( QFrame::NoFrame ); 154 widgetStack->setFrameStyle( QFrame::NoFrame );
154 } 155 }
155 156
156 setUpLayout(); 157 setUpLayout();
157 } 158 }
158 } 159 }
159} 160}
160 161
161void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) 162void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label)
162{ 163{
163 OTabInfo *currtab = tabs.first(); 164 OTabInfo *currtab = tabs.first();
164 while ( currtab && currtab->control() != widget ) 165 while ( currtab && currtab->control() != widget )
165 { 166 {
166 currtab = tabs.next(); 167 currtab = tabs.next();
167 } 168 }
168 if ( currtab && currtab->control() == widget ) 169 if ( currtab && currtab->control() == widget )
169 { 170 {
170 QTab *tab = tabBar->tab( currtab->id() ); 171 QTab *tab = tabBar->tab( currtab->id() );
171 QPixmap icon( loadSmooth( iconset ) ); 172 QPixmap icon( loadSmooth( iconset ) );
172 tab->setText( label ); 173 tab->setText( label );
173 if ( tabBarStyle == IconTab ) 174 if ( tabBarStyle == IconTab )
174 tab->setIconSet( icon ); 175 tab->setIconSet( icon );
175 int i = 0; 176 int i = 0;
176 while ( i < tabList->count() && tabList->text( i ) != currtab->label() ) 177 while ( i < tabList->count() && tabList->text( i ) != currtab->label() )
177 { 178 {
178 i++; 179 i++;
179 } 180 }
180 if ( i < tabList->count() && tabList->text( i ) == currtab->label() ) 181 if ( i < tabList->count() && tabList->text( i ) == currtab->label() )
181 { 182 {
182 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 183 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
183 { 184 {
184 tabList->changeItem( icon, label, i ); 185 tabList->changeItem( icon, label, i );
185 } 186 }
186 else 187 else
187 { 188 {
188 tabList->changeItem( label, i ); 189 tabList->changeItem( label, i );
189 } 190 }
190 } 191 }
191 currtab->setLabel( label ); 192 currtab->setLabel( label );
192 currtab->setIcon( iconset ); 193 currtab->setIcon( iconset );
193 } 194 }
194 setUpLayout(); 195 setUpLayout();
195} 196}
196 197
197void OTabWidget::setCurrentTab( QWidget *childwidget ) 198void OTabWidget::setCurrentTab( QWidget *childwidget )
198{ 199{
199 OTabInfo *currtab = tabs.first(); 200 OTabInfo *currtab = tabs.first();
200 while ( currtab && currtab->control() != childwidget ) 201 while ( currtab && currtab->control() != childwidget )
201 { 202 {
202 currtab = tabs.next(); 203 currtab = tabs.next();
203 } 204 }
204 if ( currtab && currtab->control() == childwidget ) 205 if ( currtab && currtab->control() == childwidget )
205 { 206 {
206 selectTab( currtab ); 207 selectTab( currtab );
207 } 208 }
208} 209}
209 210
210void OTabWidget::setCurrentTab( const QString &tabname ) 211void OTabWidget::setCurrentTab( const QString &tabname )
211{ 212{
212 OTabInfo *newtab = tabs.first(); 213 OTabInfo *newtab = tabs.first();
213 while ( newtab && newtab->label() != tabname ) 214 while ( newtab && newtab->label() != tabname )
214 { 215 {
215 newtab = tabs.next(); 216 newtab = tabs.next();
216 } 217 }
217 if ( newtab && newtab->label() == tabname ) 218 if ( newtab && newtab->label() == tabname )
218 { 219 {
219 selectTab( newtab ); 220 selectTab( newtab );
220 } 221 }
221} 222}
222 223
223void OTabWidget::setCurrentTab(int tabindex) { 224void OTabWidget::setCurrentTab(int tabindex) {
224 OTabInfo *newtab = tabs.first(); 225 OTabInfo *newtab = tabs.first();
225 while ( newtab && newtab->id() != tabindex ) 226 while ( newtab && newtab->id() != tabindex )
226 { 227 {
227 newtab = tabs.next(); 228 newtab = tabs.next();
228 } 229 }
229 if ( newtab && newtab->id() == tabindex ) 230 if ( newtab && newtab->id() == tabindex )
230 { 231 {
231 selectTab( newtab ); 232 selectTab( newtab );
232 } 233 }
233} 234}
234 235
235 236
236OTabWidget::TabStyle OTabWidget::tabStyle() const 237OTabWidget::TabStyle OTabWidget::tabStyle() const
237{ 238{
238 return tabBarStyle; 239 return tabBarStyle;
239} 240}
240 241
241void OTabWidget::setTabStyle( TabStyle s ) 242void OTabWidget::setTabStyle( TabStyle s )
242{ 243{
243 tabBarStyle = s; 244 tabBarStyle = s;
244 if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) 245 if ( tabBarStyle == TextTab || tabBarStyle == IconTab )
245 { 246 {
246 QTab *currtab; 247 QTab *currtab;
247 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) 248 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
248 { 249 {
249 currtab = tabBar->tab( tabinfo->id() ); 250 currtab = tabBar->tab( tabinfo->id() );
250 if ( tabBarStyle == IconTab ) 251 if ( tabBarStyle == IconTab )
251 { 252 {
252 currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); 253 currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) );
253 if ( tabinfo == currTab ) 254 if ( tabinfo == currTab )
254 currtab->setText( tabinfo->label() ); 255 currtab->setText( tabinfo->label() );
255 else 256 else
256 currtab->setText( QString::null ); 257 currtab->setText( QString::null );
257 } 258 }
258 else 259 else
259 { 260 {
260 currtab->iconset = 0x0; 261 currtab->iconset = 0x0;
261 currtab->setText( tabinfo->label() ); 262 currtab->setText( tabinfo->label() );
262 } 263 }
263 } 264 }
264 tabBarStack->raiseWidget( tabBar ); 265 tabBarStack->raiseWidget( tabBar );
265 } 266 }
266 else if ( tabBarStyle == TextList || tabBarStyle == IconList ) 267 else if ( tabBarStyle == TextList || tabBarStyle == IconList )
267 { 268 {
268 tabList->clear(); 269 tabList->clear();
269 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) 270 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )