author | zecke <zecke> | 2002-10-11 22:32:31 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-11 22:32:31 (UTC) |
commit | ffa7f45a2100b7c438a437fce2d3a47608bd36e3 (patch) (unidiff) | |
tree | ccfa8b0c7490d2a271ff7f5edc19ae8e14e277f1 | |
parent | c8c961b4106f49f544195733cef17af5f15f6bb8 (diff) | |
download | opie-ffa7f45a2100b7c438a437fce2d3a47608bd36e3.zip opie-ffa7f45a2100b7c438a437fce2d3a47608bd36e3.tar.gz opie-ffa7f45a2100b7c438a437fce2d3a47608bd36e3.tar.bz2 |
Fix from drw for his widget. This sounds a bit paradox
Remove Page and Inserting one again crashed...
This patch fixes this problem
-rw-r--r-- | libopie/otabwidget.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/libopie/otabwidget.cpp b/libopie/otabwidget.cpp index 1f3fbb0..6ef4034 100644 --- a/libopie/otabwidget.cpp +++ b/libopie/otabwidget.cpp | |||
@@ -49,251 +49,253 @@ OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPositi | |||
49 | if ( tabBarStyle <= Global || tabBarStyle > IconList) | 49 | if ( tabBarStyle <= Global || tabBarStyle > IconList) |
50 | { | 50 | { |
51 | tabBarStyle = IconTab; | 51 | tabBarStyle = 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 | tabBarPosition = Bottom; | 56 | tabBarPosition = Bottom; |
57 | } | 57 | } |
58 | else | 58 | else |
59 | { | 59 | { |
60 | tabBarPosition = Top; | 60 | tabBarPosition = Top; |
61 | } | 61 | } |
62 | } | 62 | } |
63 | else | 63 | else |
64 | { | 64 | { |
65 | tabBarStyle = s; | 65 | tabBarStyle = s; |
66 | tabBarPosition = p; | 66 | tabBarPosition = p; |
67 | } | 67 | } |
68 | 68 | ||
69 | widgetStack = new QWidgetStack( this, "widgetstack" ); | 69 | widgetStack = new QWidgetStack( this, "widgetstack" ); |
70 | widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); | 70 | widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); |
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 | if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) | 83 | if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) |
84 | { | 84 | { |
85 | tabBarStack->raiseWidget( tabBar ); | 85 | tabBarStack->raiseWidget( tabBar ); |
86 | } | 86 | } |
87 | else if ( tabBarStyle == TextList || tabBarStyle == IconList ) | 87 | else if ( tabBarStyle == TextList || tabBarStyle == IconList ) |
88 | { | 88 | { |
89 | tabBarStack->raiseWidget( tabList ); | 89 | tabBarStack->raiseWidget( tabList ); |
90 | } | 90 | } |
91 | 91 | ||
92 | if ( tabBarPosition == Bottom ) | 92 | if ( tabBarPosition == Bottom ) |
93 | { | 93 | { |
94 | tabBar->setShape( QTabBar::RoundedBelow ); | 94 | tabBar->setShape( QTabBar::RoundedBelow ); |
95 | } | 95 | } |
96 | 96 | ||
97 | tabs.setAutoDelete( TRUE ); | 97 | //tabs.setAutoDelete( TRUE ); |
98 | currentTab= 0x0; | 98 | currentTab= 0x0; |
99 | } | 99 | } |
100 | 100 | ||
101 | OTabWidget::~OTabWidget() | 101 | OTabWidget::~OTabWidget() |
102 | { | 102 | { |
103 | } | 103 | } |
104 | 104 | ||
105 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) | 105 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) |
106 | { | 106 | { |
107 | QPixmap iconset = loadSmooth( icon ); | 107 | QPixmap iconset = loadSmooth( icon ); |
108 | 108 | ||
109 | QTab * tab = new QTab(); | 109 | QTab * tab = new QTab(); |
110 | if ( tabBarStyle == IconTab ) | 110 | if ( tabBarStyle == IconTab ) |
111 | { | 111 | { |
112 | tab->label = QString::null; | 112 | tab->label = QString::null; |
113 | } | 113 | } |
114 | else | 114 | else |
115 | { | 115 | { |
116 | tab->label = label; | 116 | tab->label = label; |
117 | } | 117 | } |
118 | if ( tabBarStyle == IconTab || tabBarStyle == IconList) | 118 | if ( tabBarStyle == IconTab || tabBarStyle == IconList) |
119 | { | 119 | { |
120 | tab->iconset = new QIconSet( iconset ); | 120 | tab->iconset = new QIconSet( iconset ); |
121 | } | 121 | } |
122 | int tabid = tabBar->addTab( tab ); | 122 | int tabid = tabBar->addTab( tab ); |
123 | 123 | ||
124 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) | 124 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) |
125 | { | 125 | { |
126 | tabList->insertItem( iconset, label, -1 ); | 126 | tabList->insertItem( iconset, label, -1 ); |
127 | } | 127 | } |
128 | else | 128 | else |
129 | { | 129 | { |
130 | tabList->insertItem( label ); | 130 | tabList->insertItem( label ); |
131 | } | 131 | } |
132 | 132 | ||
133 | widgetStack->addWidget( child, tabid ); | 133 | widgetStack->addWidget( child, tabid ); |
134 | widgetStack->raiseWidget( child ); | 134 | widgetStack->raiseWidget( child ); |
135 | 135 | ||
136 | OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); | 136 | OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); |
137 | tabs.append( tabinfo ); | 137 | tabs.append( tabinfo ); |
138 | selectTab( tabinfo ); | 138 | selectTab( tabinfo ); |
139 | } | 139 | } |
140 | 140 | ||
141 | void OTabWidget::removePage( QWidget *childwidget ) | 141 | void OTabWidget::removePage( QWidget *childwidget ) |
142 | { | 142 | { |
143 | if ( childwidget ) | 143 | if ( childwidget ) |
144 | { | 144 | { |
145 | OTabInfo *tab = tabs.first(); | 145 | OTabInfo *tab = tabs.first(); |
146 | while ( tab && tab->control() != childwidget ) | 146 | while ( tab && tab->control() != childwidget ) |
147 | { | 147 | { |
148 | tab = tabs.next(); | 148 | tab = tabs.next(); |
149 | } | 149 | } |
150 | if ( tab && tab->control() == childwidget ) | 150 | if ( tab && tab->control() == childwidget ) |
151 | { | 151 | { |
152 | tabBar->setTabEnabled( tab->id(), FALSE ); | 152 | tabBar->setTabEnabled( tab->id(), FALSE ); |
153 | tabBar->removeTab( tabBar->tab( tab->id() ) ); | 153 | tabBar->removeTab( tabBar->tab( tab->id() ) ); |
154 | int i = 0; | 154 | int i = 0; |
155 | while ( i < tabList->count() && tabList->text( i ) != tab->label() ) | 155 | while ( i < tabList->count() && tabList->text( i ) != tab->label() ) |
156 | { | 156 | { |
157 | i++; | 157 | i++; |
158 | } | 158 | } |
159 | if ( tabList->text( i ) == tab->label() ) | 159 | if ( tabList->text( i ) == tab->label() ) |
160 | { | 160 | { |
161 | tabList->removeItem( i ); | 161 | tabList->removeItem( i ); |
162 | } | 162 | } |
163 | widgetStack->removeWidget( childwidget ); | 163 | widgetStack->removeWidget( childwidget ); |
164 | tabs.remove( tab ); | 164 | tabs.remove( tab ); |
165 | delete tab; | ||
166 | currentTab = tabs.current(); | ||
165 | setUpLayout(); | 167 | setUpLayout(); |
166 | } | 168 | } |
167 | } | 169 | } |
168 | } | 170 | } |
169 | 171 | ||
170 | void OTabWidget::setCurrentTab( QWidget *childwidget ) | 172 | void OTabWidget::setCurrentTab( QWidget *childwidget ) |
171 | { | 173 | { |
172 | OTabInfo *newtab = tabs.first(); | 174 | OTabInfo *newtab = tabs.first(); |
173 | while ( newtab && newtab->control() != childwidget ) | 175 | while ( newtab && newtab->control() != childwidget ) |
174 | { | 176 | { |
175 | newtab = tabs.next(); | 177 | newtab = tabs.next(); |
176 | } | 178 | } |
177 | if ( newtab && newtab->control() == childwidget ) | 179 | if ( newtab && newtab->control() == childwidget ) |
178 | { | 180 | { |
179 | selectTab( newtab ); | 181 | selectTab( newtab ); |
180 | } | 182 | } |
181 | } | 183 | } |
182 | 184 | ||
183 | void OTabWidget::setCurrentTab( const QString &tabname ) | 185 | void OTabWidget::setCurrentTab( const QString &tabname ) |
184 | { | 186 | { |
185 | OTabInfo *newtab = tabs.first(); | 187 | OTabInfo *newtab = tabs.first(); |
186 | while ( newtab && newtab->label() != tabname ) | 188 | while ( newtab && newtab->label() != tabname ) |
187 | { | 189 | { |
188 | newtab = tabs.next(); | 190 | newtab = tabs.next(); |
189 | } | 191 | } |
190 | if ( newtab && newtab->label() == tabname ) | 192 | if ( newtab && newtab->label() == tabname ) |
191 | { | 193 | { |
192 | selectTab( newtab ); | 194 | selectTab( newtab ); |
193 | } | 195 | } |
194 | } | 196 | } |
195 | 197 | ||
196 | OTabWidget::TabStyle OTabWidget::tabStyle() const | 198 | OTabWidget::TabStyle OTabWidget::tabStyle() const |
197 | { | 199 | { |
198 | return tabBarStyle; | 200 | return tabBarStyle; |
199 | } | 201 | } |
200 | 202 | ||
201 | void OTabWidget::setTabStyle( TabStyle s ) | 203 | void OTabWidget::setTabStyle( TabStyle s ) |
202 | { | 204 | { |
203 | tabBarStyle = s; | 205 | tabBarStyle = s; |
204 | } | 206 | } |
205 | 207 | ||
206 | OTabWidget::TabPosition OTabWidget::tabPosition() const | 208 | OTabWidget::TabPosition OTabWidget::tabPosition() const |
207 | { | 209 | { |
208 | return tabBarPosition; | 210 | return tabBarPosition; |
209 | } | 211 | } |
210 | 212 | ||
211 | void OTabWidget::setTabPosition( TabPosition p ) | 213 | void OTabWidget::setTabPosition( TabPosition p ) |
212 | { | 214 | { |
213 | tabBarPosition = p; | 215 | tabBarPosition = p; |
214 | } | 216 | } |
215 | 217 | ||
216 | void OTabWidget::slotTabBarSelected( int id ) | 218 | void OTabWidget::slotTabBarSelected( int id ) |
217 | { | 219 | { |
218 | OTabInfo *newtab = tabs.first(); | 220 | OTabInfo *newtab = tabs.first(); |
219 | while ( newtab && newtab->id() != id ) | 221 | while ( newtab && newtab->id() != id ) |
220 | { | 222 | { |
221 | newtab = tabs.next(); | 223 | newtab = tabs.next(); |
222 | } | 224 | } |
223 | if ( newtab && newtab->id() == id ) | 225 | if ( newtab && newtab->id() == id ) |
224 | { | 226 | { |
225 | selectTab( newtab ); | 227 | selectTab( newtab ); |
226 | } | 228 | } |
227 | } | 229 | } |
228 | 230 | ||
229 | void OTabWidget::slotTabListSelected( int index ) | 231 | void OTabWidget::slotTabListSelected( int index ) |
230 | { | 232 | { |
231 | OTabInfo *newtab = tabs.at( index ); | 233 | OTabInfo *newtab = tabs.at( index ); |
232 | if ( newtab ) | 234 | if ( newtab ) |
233 | { | 235 | { |
234 | selectTab( newtab ); | 236 | selectTab( newtab ); |
235 | } | 237 | } |
236 | } | 238 | } |
237 | 239 | ||
238 | QPixmap OTabWidget::loadSmooth( const QString &name ) | 240 | QPixmap OTabWidget::loadSmooth( const QString &name ) |
239 | { | 241 | { |
240 | QImage image = Resource::loadImage( name ); | 242 | QImage image = Resource::loadImage( name ); |
241 | QPixmap pixmap; | 243 | QPixmap pixmap; |
242 | pixmap.convertFromImage( image.smoothScale( 16, 16 ) ); | 244 | pixmap.convertFromImage( image.smoothScale( 16, 16 ) ); |
243 | return pixmap; | 245 | return pixmap; |
244 | } | 246 | } |
245 | 247 | ||
246 | void OTabWidget::selectTab( OTabInfo *tab ) | 248 | void OTabWidget::selectTab( OTabInfo *tab ) |
247 | { | 249 | { |
248 | if ( tabBarStyle == IconTab ) | 250 | if ( tabBarStyle == IconTab ) |
249 | { | 251 | { |
250 | if ( currentTab ) | 252 | if ( currentTab ) |
251 | { | 253 | { |
252 | tabBar->tab( currentTab->id() )->setText( QString::null ); | 254 | tabBar->tab( currentTab->id() )->setText( "" ); |
253 | setUpLayout(); | 255 | setUpLayout(); |
254 | } | 256 | } |
255 | tabBar->tab( tab->id() )->setText( tab->label() ); | 257 | tabBar->tab( tab->id() )->setText( tab->label() ); |
256 | currentTab = tab; | 258 | currentTab = tab; |
257 | } | 259 | } |
258 | tabBar->setCurrentTab( tab->id() ); | 260 | tabBar->setCurrentTab( tab->id() ); |
259 | setUpLayout(); | 261 | setUpLayout(); |
260 | tabBar->update(); | 262 | tabBar->update(); |
261 | 263 | ||
262 | widgetStack->raiseWidget( tab->control() ); | 264 | widgetStack->raiseWidget( tab->control() ); |
263 | 265 | ||
264 | emit currentChanged( tab->control() ); | 266 | emit currentChanged( tab->control() ); |
265 | } | 267 | } |
266 | 268 | ||
267 | void OTabWidget::setUpLayout() | 269 | void OTabWidget::setUpLayout() |
268 | { | 270 | { |
269 | tabBar->layoutTabs(); | 271 | tabBar->layoutTabs(); |
270 | QSize t( tabBarStack->sizeHint() ); | 272 | QSize t( tabBarStack->sizeHint() ); |
271 | if ( t.width() > width() ) | 273 | if ( t.width() > width() ) |
272 | t.setWidth( width() ); | 274 | t.setWidth( width() ); |
273 | int lw = widgetStack->lineWidth(); | 275 | int lw = widgetStack->lineWidth(); |
274 | if ( tabBarPosition == Bottom ) | 276 | if ( tabBarPosition == Bottom ) |
275 | { | 277 | { |
276 | tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); | 278 | tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); |
277 | widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); | 279 | widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); |
278 | } | 280 | } |
279 | else | 281 | else |
280 | { | 282 | { |
281 | tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); | 283 | tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); |
282 | widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX(0, lw-2)); | 284 | widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX(0, lw-2)); |
283 | } | 285 | } |
284 | 286 | ||
285 | if ( autoMask() ) | 287 | if ( autoMask() ) |
286 | updateMask(); | 288 | updateMask(); |
287 | } | 289 | } |
288 | 290 | ||
289 | QSize OTabWidget::sizeHint() const | 291 | QSize OTabWidget::sizeHint() const |
290 | { | 292 | { |
291 | QSize s( widgetStack->sizeHint() ); | 293 | QSize s( widgetStack->sizeHint() ); |
292 | QSize t( tabBarStack->sizeHint() ); | 294 | QSize t( tabBarStack->sizeHint() ); |
293 | return QSize( QMAX( s.width(), t.width()), s.height() + t.height() ); | 295 | return QSize( QMAX( s.width(), t.width()), s.height() + t.height() ); |
294 | } | 296 | } |
295 | 297 | ||
296 | void OTabWidget::resizeEvent( QResizeEvent * ) | 298 | void OTabWidget::resizeEvent( QResizeEvent * ) |
297 | { | 299 | { |
298 | setUpLayout(); | 300 | setUpLayout(); |
299 | } | 301 | } |