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 | |
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/otabinfo.h | 16 | ||||
-rw-r--r-- | libopie/otabwidget.cpp | 48 | ||||
-rw-r--r-- | libopie/otabwidget.h | 10 |
3 files changed, 68 insertions, 6 deletions
diff --git a/libopie/otabinfo.h b/libopie/otabinfo.h index 8dbbcc2..6589638 100644 --- a/libopie/otabinfo.h +++ b/libopie/otabinfo.h | |||
@@ -88,8 +88,16 @@ public: | |||
88 | */ | 88 | */ |
89 | const QString &label() const { return l; } | 89 | const QString &label() const { return l; } |
90 | 90 | ||
91 | /** | 91 | /** |
92 | * @fn setLabel( const QString &label ) | ||
93 | * @brief Set label for tab. | ||
94 | * | ||
95 | * @param label QString text label for OTabWidget selection control. | ||
96 | */ | ||
97 | void setLabel( const QString &label ) { l = label; } | ||
98 | |||
99 | /** | ||
92 | * @fn control() | 100 | * @fn control() |
93 | * @brief Returns pointer to widget. | 101 | * @brief Returns pointer to widget. |
94 | */ | 102 | */ |
95 | QWidget *control() const { return c; } | 103 | QWidget *control() const { return c; } |
@@ -99,8 +107,16 @@ public: | |||
99 | * @brief Returns name of icon file. | 107 | * @brief Returns name of icon file. |
100 | */ | 108 | */ |
101 | const QString &icon() const { return p; } | 109 | const QString &icon() const { return p; } |
102 | 110 | ||
111 | /** | ||
112 | * @fn setIcon( const QString &icon ) | ||
113 | * @brief Set icon for tab. | ||
114 | * | ||
115 | * @param icon QString name of icon file. | ||
116 | */ | ||
117 | void setIcon( const QString &icon ) { p = icon; } | ||
118 | |||
103 | private: | 119 | private: |
104 | int i; | 120 | int i; |
105 | QWidget *c; | 121 | QWidget *c; |
106 | QString p; | 122 | QString p; |
diff --git a/libopie/otabwidget.cpp b/libopie/otabwidget.cpp index bee3f35..99bf067 100644 --- a/libopie/otabwidget.cpp +++ b/libopie/otabwidget.cpp | |||
@@ -97,9 +97,9 @@ void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &lab | |||
97 | else | 97 | else |
98 | { | 98 | { |
99 | tab->label = label; | 99 | tab->label = label; |
100 | } | 100 | } |
101 | if ( tabBarStyle == IconTab || tabBarStyle == IconList) | 101 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) |
102 | { | 102 | { |
103 | tab->iconset = new QIconSet( iconset ); | 103 | tab->iconset = new QIconSet( iconset ); |
104 | } | 104 | } |
105 | int tabid = tabBar->addTab( tab ); | 105 | int tabid = tabBar->addTab( tab ); |
@@ -157,18 +157,54 @@ void OTabWidget::removePage( QWidget *childwidget ) | |||
157 | } | 157 | } |
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 | ||
174 | void OTabWidget::setCurrentTab( const QString &tabname ) | 210 | void OTabWidget::setCurrentTab( const QString &tabname ) |
diff --git a/libopie/otabwidget.h b/libopie/otabwidget.h index 74d683b..0aa9bb8 100644 --- a/libopie/otabwidget.h +++ b/libopie/otabwidget.h | |||
@@ -125,8 +125,18 @@ public: | |||
125 | */ | 125 | */ |
126 | void removePage( QWidget * ); | 126 | void removePage( QWidget * ); |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * @fn changeTab( QWidget *widget, const QIconSet &icon, const QString &label ) | ||
130 | * @brief Change text and/or icon for existing tab | ||
131 | * | ||
132 | * @param child Widget control. | ||
133 | * @param icon Path to icon. | ||
134 | * @param label Text label. | ||
135 | */ | ||
136 | void changeTab( QWidget *, const QString &, const QString & ); | ||
137 | |||
138 | /** | ||
129 | * @fn tabStyle() | 139 | * @fn tabStyle() |
130 | * @brief Returns current widget selection control style. | 140 | * @brief Returns current widget selection control style. |
131 | */ | 141 | */ |
132 | TabStyle tabStyle() const; | 142 | TabStyle tabStyle() const; |