summaryrefslogtreecommitdiff
authorzecke <zecke>2004-09-12 23:02:35 (UTC)
committer zecke <zecke>2004-09-12 23:02:35 (UTC)
commit8123b75c55cb5140ae5b0c5aeddb4644a0a8ffbb (patch) (unidiff)
tree2ada329a539b5143bd732be361b9bcb5e7784ec4
parent0f705db7c338e9642294823333e5f4410aa0573f (diff)
downloadopie-8123b75c55cb5140ae5b0c5aeddb4644a0a8ffbb.zip
opie-8123b75c55cb5140ae5b0c5aeddb4644a0a8ffbb.tar.gz
opie-8123b75c55cb5140ae5b0c5aeddb4644a0a8ffbb.tar.bz2
Remove memory leak
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/otabwidget.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/libopie2/opieui/otabwidget.cpp b/libopie2/opieui/otabwidget.cpp
index a9f7da9..d23b1c9 100644
--- a/libopie2/opieui/otabwidget.cpp
+++ b/libopie2/opieui/otabwidget.cpp
@@ -1,283 +1,286 @@
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 <opie2/otabwidget.h> 32#include <opie2/otabwidget.h>
33 33
34/* OPIE */ 34/* OPIE */
35#include <qpe/applnk.h> 35#include <qpe/applnk.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37#include <qpe/resource.h> 37#include <qpe/resource.h>
38#include <opie2/otabbar.h> 38#include <opie2/otabbar.h>
39 39
40/* QT */ 40/* QT */
41#include <qcombobox.h> 41#include <qcombobox.h>
42#include <qwidgetstack.h> 42#include <qwidgetstack.h>
43 43
44using namespace Opie::Ui; 44using 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{ 48{
49 if ( s == Global ) 49 if ( s == Global )
50 { 50 {
51 Config config( "qpe" ); 51 Config config( "qpe" );
52 config.setGroup( "Appearance" ); 52 config.setGroup( "Appearance" );
53 s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); 53 s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab );
54 if ( s <= Global || s > IconList) 54 if ( s <= Global || s > IconList)
55 { 55 {
56 s = IconTab; 56 s = IconTab;
57 } 57 }
58 QString pos = config.readEntry( "TabPosition", "Top"); 58 QString pos = config.readEntry( "TabPosition", "Top");
59 if ( pos == "Bottom" ) 59 if ( pos == "Bottom" )
60 { 60 {
61 p = Bottom; 61 p = Bottom;
62 } 62 }
63 else 63 else
64 { 64 {
65 p = Top; 65 p = Top;
66 } 66 }
67 } 67 }
68 68
69 widgetStack = new QWidgetStack( this, "widgetstack" ); 69 widgetStack = new QWidgetStack( this, "widgetstack" );
70 widgetStack->setFrameStyle( QFrame::NoFrame ); 70 widgetStack->setFrameStyle( QFrame::NoFrame );
71 widgetStack->setLineWidth( style().defaultFrameWidth() ); 71 widgetStack->setLineWidth( style().defaultFrameWidth() );
72 72
73 tabBarStack = new QWidgetStack( this, "tabbarstack" ); 73 tabBarStack = new QWidgetStack( this, "tabbarstack" );
74 74
75 tabBar = new OTabBar( tabBarStack, "tabbar" ); 75 tabBar = new OTabBar( tabBarStack, "tabbar" );
76 tabBarStack->addWidget( tabBar, 0 ); 76 tabBarStack->addWidget( tabBar, 0 );
77 connect( tabBar, SIGNAL( selected(int) ), this, SLOT( slotTabBarSelected(int) ) ); 77 connect( tabBar, SIGNAL( selected(int) ), this, SLOT( slotTabBarSelected(int) ) );
78 78
79 tabList = new QComboBox( false, tabBarStack, "tablist" ); 79 tabList = new QComboBox( false, tabBarStack, "tablist" );
80 tabBarStack->addWidget( tabList, 1 ); 80 tabBarStack->addWidget( tabList, 1 );
81 connect( tabList, SIGNAL( activated(int) ), this, SLOT( slotTabListSelected(int) ) ); 81 connect( tabList, SIGNAL( activated(int) ), this, SLOT( slotTabListSelected(int) ) );
82 82
83 tabBarPosition = p; 83 tabBarPosition = p;
84 setTabStyle( s ); 84 setTabStyle( s );
85 setTabPosition( p ); 85 setTabPosition( p );
86 86
87 currTab= 0x0; 87 currTab= 0x0;
88} 88}
89 89
90OTabWidget::~OTabWidget() 90OTabWidget::~OTabWidget()
91{} 91{
92 tabs.setAutoDelete( true );
93 tabs.clear();
94}
92 95
93void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) 96void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
94{ 97{
95 QPixmap iconset = loadSmooth( icon ); 98 QPixmap iconset = loadSmooth( icon );
96 99
97 QTab *tab = new QTab(); 100 QTab *tab = new QTab();
98 if ( tabBarStyle == IconTab ) 101 if ( tabBarStyle == IconTab )
99 { 102 {
100 tab->label = QString::null; 103 tab->label = QString::null;
101 } 104 }
102 else 105 else
103 { 106 {
104 tab->label = label; 107 tab->label = label;
105 } 108 }
106 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 109 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
107 { 110 {
108 tab->iconset = new QIconSet( iconset ); 111 tab->iconset = new QIconSet( iconset );
109 } 112 }
110 int tabid = tabBar->addTab( tab ); 113 int tabid = tabBar->addTab( tab );
111 114
112 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 115 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
113 { 116 {
114 tabList->insertItem( iconset, label, -1 ); 117 tabList->insertItem( iconset, label, -1 );
115 } 118 }
116 else 119 else
117 { 120 {
118 tabList->insertItem( label ); 121 tabList->insertItem( label );
119 } 122 }
120 123
121 widgetStack->addWidget( child, tabid ); 124 widgetStack->addWidget( child, tabid );
122 widgetStack->raiseWidget( child ); 125 widgetStack->raiseWidget( child );
123 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); 126 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
124 127
125 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); 128 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label );
126 tabs.append( tabinfo ); 129 tabs.append( tabinfo );
127 selectTab( tabinfo ); 130 selectTab( tabinfo );
128} 131}
129 132
130void OTabWidget::removePage( QWidget *childwidget ) 133void OTabWidget::removePage( QWidget *childwidget )
131{ 134{
132 if ( childwidget ) 135 if ( childwidget )
133 { 136 {
134 OTabInfo *tab = tabs.first(); 137 OTabInfo *tab = tabs.first();
135 while ( tab && tab->control() != childwidget ) 138 while ( tab && tab->control() != childwidget )
136 { 139 {
137 tab = tabs.next(); 140 tab = tabs.next();
138 } 141 }
139 if ( tab && tab->control() == childwidget ) 142 if ( tab && tab->control() == childwidget )
140 { 143 {
141 tabBar->setTabEnabled( tab->id(), FALSE ); 144 tabBar->setTabEnabled( tab->id(), FALSE );
142 tabBar->removeTab( tabBar->tab( tab->id() ) ); 145 tabBar->removeTab( tabBar->tab( tab->id() ) );
143 int i = 0; 146 int i = 0;
144 while ( i < tabList->count() && tabList->text( i ) != tab->label() ) 147 while ( i < tabList->count() && tabList->text( i ) != tab->label() )
145 { 148 {
146 i++; 149 i++;
147 } 150 }
148 if ( tabList->text( i ) == tab->label() ) 151 if ( tabList->text( i ) == tab->label() )
149 { 152 {
150 tabList->removeItem( i ); 153 tabList->removeItem( i );
151 } 154 }
152 widgetStack->removeWidget( childwidget ); 155 widgetStack->removeWidget( childwidget );
153 tabs.remove( tab ); 156 tabs.remove( tab );
154 delete tab; 157 delete tab;
155 currTab = tabs.current(); 158 currTab = tabs.current();
156 if ( !currTab ) 159 if ( !currTab )
157 { 160 {
158 widgetStack->setFrameStyle( QFrame::NoFrame ); 161 widgetStack->setFrameStyle( QFrame::NoFrame );
159 } 162 }
160 163
161 setUpLayout(); 164 setUpLayout();
162 } 165 }
163 } 166 }
164} 167}
165 168
166void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) 169void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label)
167{ 170{
168 OTabInfo *currtab = tabs.first(); 171 OTabInfo *currtab = tabs.first();
169 while ( currtab && currtab->control() != widget ) 172 while ( currtab && currtab->control() != widget )
170 { 173 {
171 currtab = tabs.next(); 174 currtab = tabs.next();
172 } 175 }
173 if ( currtab && currtab->control() == widget ) 176 if ( currtab && currtab->control() == widget )
174 { 177 {
175 QTab *tab = tabBar->tab( currtab->id() ); 178 QTab *tab = tabBar->tab( currtab->id() );
176 QPixmap icon( loadSmooth( iconset ) ); 179 QPixmap icon( loadSmooth( iconset ) );
177 tab->setText( label ); 180 tab->setText( label );
178 if ( tabBarStyle == IconTab ) 181 if ( tabBarStyle == IconTab )
179 tab->setIconSet( icon ); 182 tab->setIconSet( icon );
180 int i = 0; 183 int i = 0;
181 while ( i < tabList->count() && tabList->text( i ) != currtab->label() ) 184 while ( i < tabList->count() && tabList->text( i ) != currtab->label() )
182 { 185 {
183 i++; 186 i++;
184 } 187 }
185 if ( i < tabList->count() && tabList->text( i ) == currtab->label() ) 188 if ( i < tabList->count() && tabList->text( i ) == currtab->label() )
186 { 189 {
187 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 190 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
188 { 191 {
189 tabList->changeItem( icon, label, i ); 192 tabList->changeItem( icon, label, i );
190 } 193 }
191 else 194 else
192 { 195 {
193 tabList->changeItem( label, i ); 196 tabList->changeItem( label, i );
194 } 197 }
195 } 198 }
196 currtab->setLabel( label ); 199 currtab->setLabel( label );
197 currtab->setIcon( iconset ); 200 currtab->setIcon( iconset );
198 } 201 }
199 setUpLayout(); 202 setUpLayout();
200} 203}
201 204
202void OTabWidget::setCurrentTab( QWidget *childwidget ) 205void OTabWidget::setCurrentTab( QWidget *childwidget )
203{ 206{
204 OTabInfo *currtab = tabs.first(); 207 OTabInfo *currtab = tabs.first();
205 while ( currtab && currtab->control() != childwidget ) 208 while ( currtab && currtab->control() != childwidget )
206 { 209 {
207 currtab = tabs.next(); 210 currtab = tabs.next();
208 } 211 }
209 if ( currtab && currtab->control() == childwidget ) 212 if ( currtab && currtab->control() == childwidget )
210 { 213 {
211 selectTab( currtab ); 214 selectTab( currtab );
212 } 215 }
213} 216}
214 217
215void OTabWidget::setCurrentTab( const QString &tabname ) 218void OTabWidget::setCurrentTab( const QString &tabname )
216{ 219{
217 OTabInfo *newtab = tabs.first(); 220 OTabInfo *newtab = tabs.first();
218 while ( newtab && newtab->label() != tabname ) 221 while ( newtab && newtab->label() != tabname )
219 { 222 {
220 newtab = tabs.next(); 223 newtab = tabs.next();
221 } 224 }
222 if ( newtab && newtab->label() == tabname ) 225 if ( newtab && newtab->label() == tabname )
223 { 226 {
224 selectTab( newtab ); 227 selectTab( newtab );
225 } 228 }
226} 229}
227 230
228void OTabWidget::setCurrentTab(int tabindex) 231void OTabWidget::setCurrentTab(int tabindex)
229{ 232{
230 OTabInfo *newtab = tabs.first(); 233 OTabInfo *newtab = tabs.first();
231 while ( newtab && newtab->id() != tabindex ) 234 while ( newtab && newtab->id() != tabindex )
232 { 235 {
233 newtab = tabs.next(); 236 newtab = tabs.next();
234 } 237 }
235 if ( newtab && newtab->id() == tabindex ) 238 if ( newtab && newtab->id() == tabindex )
236 { 239 {
237 selectTab( newtab ); 240 selectTab( newtab );
238 } 241 }
239} 242}
240 243
241 244
242OTabWidget::TabStyle OTabWidget::tabStyle() const 245OTabWidget::TabStyle OTabWidget::tabStyle() const
243{ 246{
244 return tabBarStyle; 247 return tabBarStyle;
245} 248}
246 249
247void OTabWidget::setTabStyle( TabStyle s ) 250void OTabWidget::setTabStyle( TabStyle s )
248{ 251{
249 tabBarStyle = s; 252 tabBarStyle = s;
250 if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) 253 if ( tabBarStyle == TextTab || tabBarStyle == IconTab )
251 { 254 {
252 QTab *currtab; 255 QTab *currtab;
253 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) 256 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
254 { 257 {
255 currtab = tabBar->tab( tabinfo->id() ); 258 currtab = tabBar->tab( tabinfo->id() );
256 if ( tabBarStyle == IconTab ) 259 if ( tabBarStyle == IconTab )
257 { 260 {
258 currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); 261 currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) );
259 if ( tabinfo == currTab ) 262 if ( tabinfo == currTab )
260 currtab->setText( tabinfo->label() ); 263 currtab->setText( tabinfo->label() );
261 else 264 else
262 currtab->setText( QString::null ); 265 currtab->setText( QString::null );
263 } 266 }
264 else 267 else
265 { 268 {
266 currtab->iconset = 0x0; 269 currtab->iconset = 0x0;
267 currtab->setText( tabinfo->label() ); 270 currtab->setText( tabinfo->label() );
268 } 271 }
269 } 272 }
270 tabBarStack->raiseWidget( tabBar ); 273 tabBarStack->raiseWidget( tabBar );
271 } 274 }
272 else if ( tabBarStyle == TextList || tabBarStyle == IconList ) 275 else if ( tabBarStyle == TextList || tabBarStyle == IconList )
273 { 276 {
274 tabList->clear(); 277 tabList->clear();
275 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) 278 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
276 { 279 {
277 if ( tabBarStyle == IconList ) 280 if ( tabBarStyle == IconList )
278 { 281 {
279 tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); 282 tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() );
280 } 283 }
281 else 284 else
282 { 285 {
283 tabList->insertItem( tabinfo->label() ); 286 tabList->insertItem( tabinfo->label() );