author | drw <drw> | 2003-02-16 21:54:23 (UTC) |
---|---|---|
committer | drw <drw> | 2003-02-16 21:54:23 (UTC) |
commit | 8ecc375c803dc57b160bd0335891fcaf4f6de1df (patch) (unidiff) | |
tree | a89c1ccc6e3a469bb8fa435dfedce9386333cb72 /libopie/otabwidget.cpp | |
parent | e0eb3f016d7f8a1e1e5548ef8aa115fef8999697 (diff) | |
download | opie-8ecc375c803dc57b160bd0335891fcaf4f6de1df.zip opie-8ecc375c803dc57b160bd0335891fcaf4f6de1df.tar.gz opie-8ecc375c803dc57b160bd0335891fcaf4f6de1df.tar.bz2 |
Added changeTab() to OTabWidget to dynamically change tab name and/or icon (stumbled upon request for this in TinyKate todo)
-rw-r--r-- | libopie/otabwidget.cpp | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/libopie/otabwidget.cpp b/libopie/otabwidget.cpp index bee3f35..99bf067 100644 --- a/libopie/otabwidget.cpp +++ b/libopie/otabwidget.cpp | |||
@@ -158,16 +158,52 @@ void OTabWidget::removePage( QWidget *childwidget ) | |||
158 | } | 158 | } |
159 | } | 159 | } |
160 | 160 | ||
161 | void 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 | |||
161 | void OTabWidget::setCurrentTab( QWidget *childwidget ) | 197 | void 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 | ||