-rw-r--r-- | libopie2/opieui/otabwidget.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libopie2/opieui/otabwidget.cpp b/libopie2/opieui/otabwidget.cpp index 80a4c9b..d23b1c9 100644 --- a/libopie2/opieui/otabwidget.cpp +++ b/libopie2/opieui/otabwidget.cpp | |||
@@ -1,426 +1,426 @@ | |||
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 | ||
44 | using namespace Opie::Ui; | 44 | using namespace Opie::Ui; |
45 | 45 | ||
46 | OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p ) | 46 | OTabWidget::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 | ||
90 | OTabWidget::~OTabWidget() | 90 | OTabWidget::~OTabWidget() |
91 | { | 91 | { |
92 | tabs.setAutoDelete( true ); | 92 | tabs.setAutoDelete( true ); |
93 | tabs.clear(); | 93 | tabs.clear(); |
94 | } | 94 | } |
95 | 95 | ||
96 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) | 96 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) |
97 | { | 97 | { |
98 | QPixmap iconset = loadSmooth( icon ); | 98 | QPixmap iconset = loadSmooth( icon ); |
99 | 99 | ||
100 | QTab *tab = new QTab(); | 100 | QTab *tab = new QTab(); |
101 | if ( tabBarStyle == IconTab ) | 101 | if ( tabBarStyle == IconTab ) |
102 | { | 102 | { |
103 | tab->label = QString::null; | 103 | tab->label = QString::null; |
104 | } | 104 | } |
105 | else | 105 | else |
106 | { | 106 | { |
107 | tab->label = label; | 107 | tab->label = label; |
108 | } | 108 | } |
109 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) | 109 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) |
110 | { | 110 | { |
111 | tab->iconset = new QIconSet( iconset ); | 111 | tab->iconset = new QIconSet( iconset ); |
112 | } | 112 | } |
113 | int tabid = tabBar->addTab( tab ); | 113 | int tabid = tabBar->addTab( tab ); |
114 | 114 | ||
115 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) | 115 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) |
116 | { | 116 | { |
117 | tabList->insertItem( iconset, label, -1 ); | 117 | tabList->insertItem( iconset, label, -1 ); |
118 | } | 118 | } |
119 | else | 119 | else |
120 | { | 120 | { |
121 | tabList->insertItem( label ); | 121 | tabList->insertItem( label ); |
122 | } | 122 | } |
123 | 123 | ||
124 | widgetStack->addWidget( child, tabid ); | 124 | widgetStack->addWidget( child, tabid ); |
125 | widgetStack->raiseWidget( child ); | 125 | widgetStack->raiseWidget( child ); |
126 | widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); | 126 | widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); |
127 | 127 | ||
128 | OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); | 128 | OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); |
129 | tabs.append( tabinfo ); | 129 | tabs.append( tabinfo ); |
130 | selectTab( tabinfo ); | 130 | selectTab( tabinfo ); |
131 | } | 131 | } |
132 | 132 | ||
133 | void OTabWidget::removePage( QWidget *childwidget ) | 133 | void OTabWidget::removePage( QWidget *childwidget ) |
134 | { | 134 | { |
135 | if ( childwidget ) | 135 | if ( childwidget ) |
136 | { | 136 | { |
137 | OTabInfo *tab = tabs.first(); | 137 | OTabInfo *tab = tabs.first(); |
138 | while ( tab && tab->control() != childwidget ) | 138 | while ( tab && tab->control() != childwidget ) |
139 | { | 139 | { |
140 | tab = tabs.next(); | 140 | tab = tabs.next(); |
141 | } | 141 | } |
142 | if ( tab && tab->control() == childwidget ) | 142 | if ( tab && tab->control() == childwidget ) |
143 | { | 143 | { |
144 | tabBar->setTabEnabled( tab->id(), FALSE ); | 144 | tabBar->setTabEnabled( tab->id(), FALSE ); |
145 | tabBar->removeTab( tabBar->tab( tab->id() ) ); | 145 | tabBar->removeTab( tabBar->tab( tab->id() ) ); |
146 | int i = 0; | 146 | int i = 0; |
147 | while ( i < tabList->count() && tabList->text( i ) != tab->label() ) | 147 | while ( i < tabList->count() && tabList->text( i ) != tab->label() ) |
148 | { | 148 | { |
149 | i++; | 149 | i++; |
150 | } | 150 | } |
151 | if ( tabList->text( i ) == tab->label() ) | 151 | if ( tabList->text( i ) == tab->label() ) |
152 | { | 152 | { |
153 | tabList->removeItem( i ); | 153 | tabList->removeItem( i ); |
154 | } | 154 | } |
155 | widgetStack->removeWidget( childwidget ); | 155 | widgetStack->removeWidget( childwidget ); |
156 | tabs.remove( tab ); | 156 | tabs.remove( tab ); |
157 | delete tab; | 157 | delete tab; |
158 | currTab = tabs.current(); | 158 | currTab = tabs.current(); |
159 | if ( !currTab ) | 159 | if ( !currTab ) |
160 | { | 160 | { |
161 | widgetStack->setFrameStyle( QFrame::NoFrame ); | 161 | widgetStack->setFrameStyle( QFrame::NoFrame ); |
162 | } | 162 | } |
163 | 163 | ||
164 | setUpLayout(); | 164 | setUpLayout(); |
165 | } | 165 | } |
166 | } | 166 | } |
167 | } | 167 | } |
168 | 168 | ||
169 | void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) | 169 | void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) |
170 | { | 170 | { |
171 | OTabInfo *currtab = tabs.first(); | 171 | OTabInfo *currtab = tabs.first(); |
172 | while ( currtab && currtab->control() != widget ) | 172 | while ( currtab && currtab->control() != widget ) |
173 | { | 173 | { |
174 | currtab = tabs.next(); | 174 | currtab = tabs.next(); |
175 | } | 175 | } |
176 | if ( currtab && currtab->control() == widget ) | 176 | if ( currtab && currtab->control() == widget ) |
177 | { | 177 | { |
178 | QTab *tab = tabBar->tab( currtab->id() ); | 178 | QTab *tab = tabBar->tab( currtab->id() ); |
179 | QPixmap icon( loadSmooth( iconset ) ); | 179 | QPixmap icon( loadSmooth( iconset ) ); |
180 | tab->setText( label ); | 180 | tab->setText( label ); |
181 | if ( tabBarStyle == IconTab ) | 181 | if ( tabBarStyle == IconTab ) |
182 | tab->setIconSet( icon ); | 182 | tab->setIconSet( icon ); |
183 | int i = 0; | 183 | int i = 0; |
184 | while ( i < tabList->count() && tabList->text( i ) != currtab->label() ) | 184 | while ( i < tabList->count() && tabList->text( i ) != currtab->label() ) |
185 | { | 185 | { |
186 | i++; | 186 | i++; |
187 | } | 187 | } |
188 | if ( i < tabList->count() && tabList->text( i ) == currtab->label() ) | 188 | if ( i < tabList->count() && tabList->text( i ) == currtab->label() ) |
189 | { | 189 | { |
190 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) | 190 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) |
191 | { | 191 | { |
192 | tabList->changeItem( icon, label, i ); | 192 | tabList->changeItem( icon, label, i ); |
193 | } | 193 | } |
194 | else | 194 | else |
195 | { | 195 | { |
196 | tabList->changeItem( label, i ); | 196 | tabList->changeItem( label, i ); |
197 | } | 197 | } |
198 | } | 198 | } |
199 | currtab->setLabel( label ); | 199 | currtab->setLabel( label ); |
200 | currtab->setIcon( iconset ); | 200 | currtab->setIcon( iconset ); |
201 | } | 201 | } |
202 | setUpLayout(); | 202 | setUpLayout(); |
203 | } | 203 | } |
204 | 204 | ||
205 | void OTabWidget::setCurrentTab( QWidget *childwidget ) | 205 | void OTabWidget::setCurrentTab( QWidget *childwidget ) |
206 | { | 206 | { |
207 | OTabInfo *currtab = tabs.first(); | 207 | OTabInfo *currtab = tabs.first(); |
208 | while ( currtab && currtab->control() != childwidget ) | 208 | while ( currtab && currtab->control() != childwidget ) |
209 | { | 209 | { |
210 | currtab = tabs.next(); | 210 | currtab = tabs.next(); |
211 | } | 211 | } |
212 | if ( currtab && currtab->control() == childwidget ) | 212 | if ( currtab && currtab->control() == childwidget ) |
213 | { | 213 | { |
214 | selectTab( currtab ); | 214 | selectTab( currtab ); |
215 | } | 215 | } |
216 | } | 216 | } |
217 | 217 | ||
218 | void OTabWidget::setCurrentTab( const QString &tabname ) | 218 | void OTabWidget::setCurrentTab( const QString &tabname ) |
219 | { | 219 | { |
220 | OTabInfo *newtab = tabs.first(); | 220 | OTabInfo *newtab = tabs.first(); |
221 | while ( newtab && newtab->label() != tabname ) | 221 | while ( newtab && newtab->label() != tabname ) |
222 | { | 222 | { |
223 | newtab = tabs.next(); | 223 | newtab = tabs.next(); |
224 | } | 224 | } |
225 | if ( newtab && newtab->label() == tabname ) | 225 | if ( newtab && newtab->label() == tabname ) |
226 | { | 226 | { |
227 | selectTab( newtab ); | 227 | selectTab( newtab ); |
228 | } | 228 | } |
229 | } | 229 | } |
230 | 230 | ||
231 | void OTabWidget::setCurrentTab(int tabindex) | 231 | void OTabWidget::setCurrentTab(int tabindex) |
232 | { | 232 | { |
233 | OTabInfo *newtab = tabs.first(); | 233 | OTabInfo *newtab = tabs.first(); |
234 | while ( newtab && newtab->id() != tabindex ) | 234 | while ( newtab && newtab->id() != tabindex ) |
235 | { | 235 | { |
236 | newtab = tabs.next(); | 236 | newtab = tabs.next(); |
237 | } | 237 | } |
238 | if ( newtab && newtab->id() == tabindex ) | 238 | if ( newtab && newtab->id() == tabindex ) |
239 | { | 239 | { |
240 | selectTab( newtab ); | 240 | selectTab( newtab ); |
241 | } | 241 | } |
242 | } | 242 | } |
243 | 243 | ||
244 | 244 | ||
245 | OTabWidget::TabStyle OTabWidget::tabStyle() const | 245 | OTabWidget::TabStyle OTabWidget::tabStyle() const |
246 | { | 246 | { |
247 | return tabBarStyle; | 247 | return tabBarStyle; |
248 | } | 248 | } |
249 | 249 | ||
250 | void OTabWidget::setTabStyle( TabStyle s ) | 250 | void OTabWidget::setTabStyle( TabStyle s ) |
251 | { | 251 | { |
252 | tabBarStyle = s; | 252 | tabBarStyle = s; |
253 | if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) | 253 | if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) |
254 | { | 254 | { |
255 | QTab *currtab; | 255 | QTab *currtab; |
256 | for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) | 256 | for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) |
257 | { | 257 | { |
258 | currtab = tabBar->tab( tabinfo->id() ); | 258 | currtab = tabBar->tab( tabinfo->id() ); |
259 | if ( tabBarStyle == IconTab ) | 259 | if ( tabBarStyle == IconTab ) |
260 | { | 260 | { |
261 | currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); | 261 | currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); |
262 | if ( tabinfo == currTab ) | 262 | if ( tabinfo == currTab ) |
263 | currtab->setText( tabinfo->label() ); | 263 | currtab->setText( tabinfo->label() ); |
264 | else | 264 | else |
265 | currtab->setText( QString::null ); | 265 | currtab->setText( QString::null ); |
266 | } | 266 | } |
267 | else | 267 | else |
268 | { | 268 | { |
269 | currtab->iconset = 0x0; | 269 | currtab->iconset = 0x0; |
270 | currtab->setText( tabinfo->label() ); | 270 | currtab->setText( tabinfo->label() ); |
271 | } | 271 | } |
272 | } | 272 | } |
273 | tabBarStack->raiseWidget( tabBar ); | 273 | tabBarStack->raiseWidget( tabBar ); |
274 | } | 274 | } |
275 | else if ( tabBarStyle == TextList || tabBarStyle == IconList ) | 275 | else if ( tabBarStyle == TextList || tabBarStyle == IconList ) |
276 | { | 276 | { |
277 | tabList->clear(); | 277 | tabList->clear(); |
278 | for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) | 278 | for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) |
279 | { | 279 | { |
280 | if ( tabBarStyle == IconList ) | 280 | if ( tabBarStyle == IconList ) |
281 | { | 281 | { |
282 | tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); | 282 | tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); |
283 | } | 283 | } |
284 | else | 284 | else |
285 | { | 285 | { |
286 | tabList->insertItem( tabinfo->label() ); | 286 | tabList->insertItem( tabinfo->label() ); |
287 | } | 287 | } |
288 | } | 288 | } |
289 | tabBarStack->raiseWidget( tabList ); | 289 | tabBarStack->raiseWidget( tabList ); |
290 | } | 290 | } |
291 | setUpLayout(); | 291 | setUpLayout(); |
292 | } | 292 | } |
293 | 293 | ||
294 | OTabWidget::TabPosition OTabWidget::tabPosition() const | 294 | OTabWidget::TabPosition OTabWidget::tabPosition() const |
295 | { | 295 | { |
296 | return tabBarPosition; | 296 | return tabBarPosition; |
297 | } | 297 | } |
298 | 298 | ||
299 | void OTabWidget::setTabPosition( TabPosition p ) | 299 | void OTabWidget::setTabPosition( TabPosition p ) |
300 | { | 300 | { |
301 | tabBarPosition = p; | 301 | tabBarPosition = p; |
302 | if ( tabBarPosition == Top ) | 302 | if ( tabBarPosition == Top ) |
303 | { | 303 | { |
304 | tabBar->setShape( QTabBar::RoundedAbove ); | 304 | tabBar->setShape( QTabBar::RoundedAbove ); |
305 | } | 305 | } |
306 | else | 306 | else |
307 | { | 307 | { |
308 | tabBar->setShape( QTabBar::RoundedBelow ); | 308 | tabBar->setShape( QTabBar::RoundedBelow ); |
309 | } | 309 | } |
310 | setUpLayout(); | 310 | setUpLayout(); |
311 | } | 311 | } |
312 | 312 | ||
313 | void OTabWidget::slotTabBarSelected( int id ) | 313 | void OTabWidget::slotTabBarSelected( int id ) |
314 | { | 314 | { |
315 | OTabInfo *newtab = tabs.first(); | 315 | OTabInfo *newtab = tabs.first(); |
316 | while ( newtab && newtab->id() != id ) | 316 | while ( newtab && newtab->id() != id ) |
317 | { | 317 | { |
318 | newtab = tabs.next(); | 318 | newtab = tabs.next(); |
319 | } | 319 | } |
320 | if ( newtab && newtab->id() == id ) | 320 | if ( newtab && newtab->id() == id ) |
321 | { | 321 | { |
322 | selectTab( newtab ); | 322 | selectTab( newtab ); |
323 | } | 323 | } |
324 | } | 324 | } |
325 | 325 | ||
326 | void OTabWidget::slotTabListSelected( int index ) | 326 | void OTabWidget::slotTabListSelected( int index ) |
327 | { | 327 | { |
328 | OTabInfo *newtab = tabs.at( index ); | 328 | OTabInfo *newtab = tabs.at( index ); |
329 | if ( newtab ) | 329 | if ( newtab ) |
330 | { | 330 | { |
331 | selectTab( newtab ); | 331 | selectTab( newtab ); |
332 | } | 332 | } |
333 | } | 333 | } |
334 | 334 | ||
335 | QPixmap OTabWidget::loadSmooth( const QString &name ) | 335 | QPixmap OTabWidget::loadSmooth( const QString &name ) |
336 | { | 336 | { |
337 | QPixmap p; | 337 | QPixmap p; |
338 | p.convertFromImage( Resource::loadImage( name ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); | 338 | p.convertFromImage( Resource::loadImage( name ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); |
339 | return p; | 339 | return p; |
340 | } | 340 | } |
341 | 341 | ||
342 | void OTabWidget::selectTab( OTabInfo *tab ) | 342 | void OTabWidget::selectTab( OTabInfo *tab ) |
343 | { | 343 | { |
344 | if ( tabBarStyle == IconTab ) | 344 | if ( tabBarStyle == IconTab ) |
345 | { | 345 | { |
346 | if ( currTab ) | 346 | if ( currTab ) |
347 | { | 347 | { |
348 | tabBar->tab( currTab->id() )->setText( QString::null ); | 348 | tabBar->tab( currTab->id() )->setText( QString::null ); |
349 | setUpLayout(); | 349 | setUpLayout(); |
350 | } | 350 | } |
351 | tabBar->tab( tab->id() )->setText( tab->label() ); | 351 | tabBar->tab( tab->id() )->setText( tab->label() ); |
352 | tabBar->setCurrentTab( tab->id() ); | 352 | tabBar->setCurrentTab( tab->id() ); |
353 | // setUpLayout(); | 353 | setUpLayout(); |
354 | tabBar->update(); | 354 | tabBar->update(); |
355 | } | 355 | } |
356 | else | 356 | else |
357 | { | 357 | { |
358 | tabBar->setCurrentTab( tab->id() ); | 358 | tabBar->setCurrentTab( tab->id() ); |
359 | } | 359 | } |
360 | 360 | ||
361 | widgetStack->raiseWidget( tab->control() ); | 361 | widgetStack->raiseWidget( tab->control() ); |
362 | 362 | ||
363 | emit currentChanged( tab->control() ); | 363 | emit currentChanged( tab->control() ); |
364 | 364 | ||
365 | currTab = tab; | 365 | currTab = tab; |
366 | } | 366 | } |
367 | 367 | ||
368 | void OTabWidget::setUpLayout() | 368 | void OTabWidget::setUpLayout() |
369 | { | 369 | { |
370 | tabBar->layoutTabs(); | 370 | tabBar->layoutTabs(); |
371 | QSize t( tabBarStack->sizeHint() ); | 371 | QSize t( tabBarStack->sizeHint() ); |
372 | if ( tabBarStyle == IconTab ) | 372 | if ( tabBarStyle == IconTab ) |
373 | { | 373 | { |
374 | if ( t.width() > width() ) | 374 | if ( t.width() > width() ) |
375 | t.setWidth( width() ); | 375 | t.setWidth( width() ); |
376 | } | 376 | } |
377 | else | 377 | else |
378 | { | 378 | { |
379 | t.setWidth( width() ); | 379 | t.setWidth( width() ); |
380 | } | 380 | } |
381 | int lw = widgetStack->lineWidth(); | 381 | int lw = widgetStack->lineWidth(); |
382 | if ( tabBarPosition == Bottom ) | 382 | if ( tabBarPosition == Bottom ) |
383 | { | 383 | { |
384 | tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); | 384 | tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); |
385 | widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); | 385 | widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); |
386 | } | 386 | } |
387 | else | 387 | else |
388 | { | 388 | { |
389 | tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); | 389 | tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); |
390 | widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) ); | 390 | widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) ); |
391 | } | 391 | } |
392 | 392 | ||
393 | if ( autoMask() ) | 393 | if ( autoMask() ) |
394 | updateMask(); | 394 | updateMask(); |
395 | } | 395 | } |
396 | 396 | ||
397 | QSize OTabWidget::sizeHint() const | 397 | QSize OTabWidget::sizeHint() const |
398 | { | 398 | { |
399 | QSize s( widgetStack->sizeHint() ); | 399 | QSize s( widgetStack->sizeHint() ); |
400 | QSize t( tabBarStack->sizeHint() ); | 400 | QSize t( tabBarStack->sizeHint() ); |
401 | return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() ); | 401 | return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() ); |
402 | } | 402 | } |
403 | 403 | ||
404 | void OTabWidget::resizeEvent( QResizeEvent * ) | 404 | void OTabWidget::resizeEvent( QResizeEvent * ) |
405 | { | 405 | { |
406 | setUpLayout(); | 406 | setUpLayout(); |
407 | } | 407 | } |
408 | 408 | ||
409 | int OTabWidget::currentTab() | 409 | int OTabWidget::currentTab() |
410 | { | 410 | { |
411 | if ( currTab ) | 411 | if ( currTab ) |
412 | { | 412 | { |
413 | return currTab->id(); | 413 | return currTab->id(); |
414 | } | 414 | } |
415 | return -1; | 415 | return -1; |
416 | } | 416 | } |
417 | 417 | ||
418 | QWidget* OTabWidget::currentWidget()const | 418 | QWidget* OTabWidget::currentWidget()const |
419 | { | 419 | { |
420 | if ( currTab ) | 420 | if ( currTab ) |
421 | { | 421 | { |
422 | return currTab->control(); | 422 | return currTab->control(); |
423 | } | 423 | } |
424 | 424 | ||
425 | return 0; | 425 | return 0; |
426 | } | 426 | } |