-rw-r--r-- | libopie2/opieui/otabwidget.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/libopie2/opieui/otabwidget.cpp b/libopie2/opieui/otabwidget.cpp index 01747e1..ae396b9 100644 --- a/libopie2/opieui/otabwidget.cpp +++ b/libopie2/opieui/otabwidget.cpp | |||
@@ -1,466 +1,468 @@ | |||
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, 2005 Dan Williams <drw@handhelds.org> | 4 | Copyright (c) 2002, 2005 Dan Williams <drw@handhelds.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 | , m_currTab( 0l ) | 48 | , m_currTab( 0l ) |
49 | , m_tabBarStyle( Global ) | ||
50 | , m_tabBarPosition( Top ) | ||
49 | , m_usingTabs( true ) | 51 | , m_usingTabs( true ) |
50 | , m_tabBar( 0l ) | 52 | , m_tabBar( 0l ) |
51 | , m_tabList( 0l ) | 53 | , m_tabList( 0l ) |
52 | { | 54 | { |
53 | if ( s == Global ) | 55 | if ( s == Global ) |
54 | { | 56 | { |
55 | // Read Opie global settings for style and position | 57 | // Read Opie global settings for style and position |
56 | Config config( "qpe" ); | 58 | Config config( "qpe" ); |
57 | config.setGroup( "Appearance" ); | 59 | config.setGroup( "Appearance" ); |
58 | 60 | ||
59 | // Style | 61 | // Style |
60 | s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); | 62 | s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); |
61 | if ( s <= Global || s > IconList) | 63 | if ( s <= Global || s > IconList) |
62 | s = IconTab; | 64 | s = IconTab; |
63 | 65 | ||
64 | // Position | 66 | // Position |
65 | ( config.readEntry( "TabPosition", "Top" ) == "Bottom" ) ? p = Bottom | 67 | ( config.readEntry( "TabPosition", "Top" ) == "Bottom" ) ? p = Bottom |
66 | : p = Top; | 68 | : p = Top; |
67 | } | 69 | } |
68 | 70 | ||
69 | // Initialize widget stack for tab widgets | 71 | // Initialize widget stack for tab widgets |
70 | m_widgetStack = new QWidgetStack( this ); | 72 | m_widgetStack = new QWidgetStack( this ); |
71 | m_widgetStack->setFrameStyle( QFrame::NoFrame ); | 73 | m_widgetStack->setFrameStyle( QFrame::NoFrame ); |
72 | m_widgetStack->setLineWidth( style().defaultFrameWidth() ); | 74 | m_widgetStack->setLineWidth( style().defaultFrameWidth() ); |
73 | 75 | ||
74 | // Set initial selector control style and position | 76 | // Set initial selector control style and position |
75 | setTabStyle( s ); | 77 | setTabStyle( s ); |
76 | setTabPosition( p ); | 78 | setTabPosition( p ); |
77 | } | 79 | } |
78 | 80 | ||
79 | OTabWidget::~OTabWidget() | 81 | OTabWidget::~OTabWidget() |
80 | { | 82 | { |
81 | m_tabs.setAutoDelete( true ); | 83 | m_tabs.setAutoDelete( true ); |
82 | m_tabs.clear(); | 84 | m_tabs.clear(); |
83 | } | 85 | } |
84 | 86 | ||
85 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) | 87 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) |
86 | { | 88 | { |
87 | int tabid = -1; | 89 | int tabid = -1; |
88 | 90 | ||
89 | if ( m_usingTabs ) | 91 | if ( m_usingTabs ) |
90 | { | 92 | { |
91 | // Create new tab in tab bar | 93 | // Create new tab in tab bar |
92 | QTab *tab = new QTab(); | 94 | QTab *tab = new QTab(); |
93 | 95 | ||
94 | // Set label (and icon if necessary) | 96 | // Set label (and icon if necessary) |
95 | if ( m_tabBarStyle == IconTab ) | 97 | if ( m_tabBarStyle == IconTab ) |
96 | { | 98 | { |
97 | tab->label = QString::null; | 99 | tab->label = QString::null; |
98 | tab->iconset = new QIconSet( loadSmooth( icon ) ); | 100 | tab->iconset = new QIconSet( loadSmooth( icon ) ); |
99 | } | 101 | } |
100 | else | 102 | else |
101 | tab->label = label; | 103 | tab->label = label; |
102 | 104 | ||
103 | tabid = m_tabBar->addTab( tab ); | 105 | tabid = m_tabBar->addTab( tab ); |
104 | } | 106 | } |
105 | else | 107 | else |
106 | { | 108 | { |
107 | // Insert entry (with icon if necessary) into drop down list | 109 | // Insert entry (with icon if necessary) into drop down list |
108 | if ( m_tabBarStyle == IconList ) | 110 | if ( m_tabBarStyle == IconList ) |
109 | m_tabList->insertItem( loadSmooth( icon ), label, -1 ); | 111 | m_tabList->insertItem( loadSmooth( icon ), label, -1 ); |
110 | else | 112 | else |
111 | m_tabList->insertItem( label ); | 113 | m_tabList->insertItem( label ); |
112 | } | 114 | } |
113 | 115 | ||
114 | // Add widget to stack | 116 | // Add widget to stack |
115 | m_widgetStack->addWidget( child, tabid ); | 117 | m_widgetStack->addWidget( child, tabid ); |
116 | m_widgetStack->raiseWidget( child ); | 118 | m_widgetStack->raiseWidget( child ); |
117 | m_widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); | 119 | m_widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); |
118 | 120 | ||
119 | // Keep track of tab information | 121 | // Keep track of tab information |
120 | OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); | 122 | OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); |
121 | m_tabs.append( tabinfo ); | 123 | m_tabs.append( tabinfo ); |
122 | 124 | ||
123 | // Make newly added tab the current one displayed | 125 | // Make newly added tab the current one displayed |
124 | selectTab( tabinfo ); | 126 | selectTab( tabinfo ); |
125 | } | 127 | } |
126 | 128 | ||
127 | void OTabWidget::removePage( QWidget *childwidget ) | 129 | void OTabWidget::removePage( QWidget *childwidget ) |
128 | { | 130 | { |
129 | if ( childwidget ) | 131 | if ( childwidget ) |
130 | { | 132 | { |
131 | // Find tab information for desired widget | 133 | // Find tab information for desired widget |
132 | OTabInfo *tab = m_tabs.first(); | 134 | OTabInfo *tab = m_tabs.first(); |
133 | while ( tab && tab->control() != childwidget ) | 135 | while ( tab && tab->control() != childwidget ) |
134 | tab = m_tabs.next(); | 136 | tab = m_tabs.next(); |
135 | 137 | ||
136 | if ( tab && tab->control() == childwidget ) | 138 | if ( tab && tab->control() == childwidget ) |
137 | { | 139 | { |
138 | if ( m_usingTabs ) | 140 | if ( m_usingTabs ) |
139 | { | 141 | { |
140 | // Remove tab from tab bar | 142 | // Remove tab from tab bar |
141 | m_tabBar->setTabEnabled( tab->id(), false ); | 143 | m_tabBar->setTabEnabled( tab->id(), false ); |
142 | m_tabBar->removeTab( m_tabBar->tab( tab->id() ) ); | 144 | m_tabBar->removeTab( m_tabBar->tab( tab->id() ) ); |
143 | } | 145 | } |
144 | else | 146 | else |
145 | { | 147 | { |
146 | // Remove entry from drop down list | 148 | // Remove entry from drop down list |
147 | int i = 0; | 149 | int i = 0; |
148 | while ( i < m_tabList->count() && m_tabList->text( i ) != tab->label() ) | 150 | while ( i < m_tabList->count() && m_tabList->text( i ) != tab->label() ) |
149 | i++; | 151 | i++; |
150 | if ( m_tabList->text( i ) == tab->label() ) | 152 | if ( m_tabList->text( i ) == tab->label() ) |
151 | m_tabList->removeItem( i ); | 153 | m_tabList->removeItem( i ); |
152 | } | 154 | } |
153 | 155 | ||
154 | // Remove widget from stack | 156 | // Remove widget from stack |
155 | m_widgetStack->removeWidget( childwidget ); | 157 | m_widgetStack->removeWidget( childwidget ); |
156 | 158 | ||
157 | // Get rid of tab information | 159 | // Get rid of tab information |
158 | m_tabs.remove( tab ); | 160 | m_tabs.remove( tab ); |
159 | delete tab; | 161 | delete tab; |
160 | 162 | ||
161 | // Reset current tab | 163 | // Reset current tab |
162 | m_currTab = m_tabs.current(); | 164 | m_currTab = m_tabs.current(); |
163 | if ( !m_currTab ) | 165 | if ( !m_currTab ) |
164 | m_widgetStack->setFrameStyle( QFrame::NoFrame ); | 166 | m_widgetStack->setFrameStyle( QFrame::NoFrame ); |
165 | 167 | ||
166 | // Redraw widget | 168 | // Redraw widget |
167 | setUpLayout(); | 169 | setUpLayout(); |
168 | } | 170 | } |
169 | } | 171 | } |
170 | } | 172 | } |
171 | 173 | ||
172 | void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) | 174 | void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) |
173 | { | 175 | { |
174 | // Find tab information for desired widget | 176 | // Find tab information for desired widget |
175 | OTabInfo *currtab = m_tabs.first(); | 177 | OTabInfo *currtab = m_tabs.first(); |
176 | while ( currtab && currtab->control() != widget ) | 178 | while ( currtab && currtab->control() != widget ) |
177 | currtab = m_tabs.next(); | 179 | currtab = m_tabs.next(); |
178 | 180 | ||
179 | if ( currtab && currtab->control() == widget ) | 181 | if ( currtab && currtab->control() == widget ) |
180 | { | 182 | { |
181 | QPixmap icon( loadSmooth( iconset ) ); | 183 | QPixmap icon( loadSmooth( iconset ) ); |
182 | 184 | ||
183 | if ( m_usingTabs ) | 185 | if ( m_usingTabs ) |
184 | { | 186 | { |
185 | // Update tab label and icon (if necessary) | 187 | // Update tab label and icon (if necessary) |
186 | QTab *tab = m_tabBar->tab( currtab->id() ); | 188 | QTab *tab = m_tabBar->tab( currtab->id() ); |
187 | tab->setText( label ); | 189 | tab->setText( label ); |
188 | if ( m_tabBarStyle == IconTab ) | 190 | if ( m_tabBarStyle == IconTab ) |
189 | tab->setIconSet( icon ); | 191 | tab->setIconSet( icon ); |
190 | } | 192 | } |
191 | else | 193 | else |
192 | { | 194 | { |
193 | // Update entry label and icon (if necessary) | 195 | // Update entry label and icon (if necessary) |
194 | int i = 0; | 196 | int i = 0; |
195 | while ( i < m_tabList->count() && m_tabList->text( i ) != currtab->label() ) | 197 | while ( i < m_tabList->count() && m_tabList->text( i ) != currtab->label() ) |
196 | i++; | 198 | i++; |
197 | if ( i < m_tabList->count() && m_tabList->text( i ) == currtab->label() ) | 199 | if ( i < m_tabList->count() && m_tabList->text( i ) == currtab->label() ) |
198 | { | 200 | { |
199 | if ( m_tabBarStyle == IconList ) | 201 | if ( m_tabBarStyle == IconList ) |
200 | m_tabList->changeItem( icon, label, i ); | 202 | m_tabList->changeItem( icon, label, i ); |
201 | else | 203 | else |
202 | m_tabList->changeItem( label, i ); | 204 | m_tabList->changeItem( label, i ); |
203 | } | 205 | } |
204 | } | 206 | } |
205 | 207 | ||
206 | // Update tab information | 208 | // Update tab information |
207 | currtab->setLabel( label ); | 209 | currtab->setLabel( label ); |
208 | currtab->setIcon( iconset ); | 210 | currtab->setIcon( iconset ); |
209 | 211 | ||
210 | // Redraw widget | 212 | // Redraw widget |
211 | setUpLayout(); | 213 | setUpLayout(); |
212 | } | 214 | } |
213 | } | 215 | } |
214 | 216 | ||
215 | void OTabWidget::setCurrentTab( QWidget *childwidget ) | 217 | void OTabWidget::setCurrentTab( QWidget *childwidget ) |
216 | { | 218 | { |
217 | OTabInfo *currtab = m_tabs.first(); | 219 | OTabInfo *currtab = m_tabs.first(); |
218 | while ( currtab && currtab->control() != childwidget ) | 220 | while ( currtab && currtab->control() != childwidget ) |
219 | { | 221 | { |
220 | currtab = m_tabs.next(); | 222 | currtab = m_tabs.next(); |
221 | } | 223 | } |
222 | if ( currtab && currtab->control() == childwidget ) | 224 | if ( currtab && currtab->control() == childwidget ) |
223 | { | 225 | { |
224 | selectTab( currtab ); | 226 | selectTab( currtab ); |
225 | } | 227 | } |
226 | } | 228 | } |
227 | 229 | ||
228 | void OTabWidget::setCurrentTab( const QString &tabname ) | 230 | void OTabWidget::setCurrentTab( const QString &tabname ) |
229 | { | 231 | { |
230 | OTabInfo *newtab = m_tabs.first(); | 232 | OTabInfo *newtab = m_tabs.first(); |
231 | while ( newtab && newtab->label() != tabname ) | 233 | while ( newtab && newtab->label() != tabname ) |
232 | { | 234 | { |
233 | newtab = m_tabs.next(); | 235 | newtab = m_tabs.next(); |
234 | } | 236 | } |
235 | if ( newtab && newtab->label() == tabname ) | 237 | if ( newtab && newtab->label() == tabname ) |
236 | { | 238 | { |
237 | selectTab( newtab ); | 239 | selectTab( newtab ); |
238 | } | 240 | } |
239 | } | 241 | } |
240 | 242 | ||
241 | void OTabWidget::setCurrentTab(int tabindex) | 243 | void OTabWidget::setCurrentTab(int tabindex) |
242 | { | 244 | { |
243 | OTabInfo *newtab = m_tabs.first(); | 245 | OTabInfo *newtab = m_tabs.first(); |
244 | while ( newtab && newtab->id() != tabindex ) | 246 | while ( newtab && newtab->id() != tabindex ) |
245 | { | 247 | { |
246 | newtab = m_tabs.next(); | 248 | newtab = m_tabs.next(); |
247 | } | 249 | } |
248 | if ( newtab && newtab->id() == tabindex ) | 250 | if ( newtab && newtab->id() == tabindex ) |
249 | { | 251 | { |
250 | selectTab( newtab ); | 252 | selectTab( newtab ); |
251 | } | 253 | } |
252 | } | 254 | } |
253 | 255 | ||
254 | 256 | ||
255 | OTabWidget::TabStyle OTabWidget::tabStyle() const | 257 | OTabWidget::TabStyle OTabWidget::tabStyle() const |
256 | { | 258 | { |
257 | return m_tabBarStyle; | 259 | return m_tabBarStyle; |
258 | } | 260 | } |
259 | 261 | ||
260 | void OTabWidget::setTabStyle( TabStyle s ) | 262 | void OTabWidget::setTabStyle( TabStyle s ) |
261 | { | 263 | { |
262 | // Get out if new and current styles are the same | 264 | // Get out if new and current styles are the same |
263 | if ( s == m_tabBarStyle ) | 265 | if ( s == m_tabBarStyle ) |
264 | return; | 266 | return; |
265 | 267 | ||
266 | // Delete current selector control | 268 | // Delete current selector control |
267 | if ( m_usingTabs ) | 269 | if ( m_usingTabs ) |
268 | { | 270 | { |
269 | delete m_tabBar; | 271 | delete m_tabBar; |
270 | m_tabBar = 0l; | 272 | m_tabBar = 0l; |
271 | } | 273 | } |
272 | else | 274 | else |
273 | { | 275 | { |
274 | delete m_tabList; | 276 | delete m_tabList; |
275 | m_tabList = 0l; | 277 | m_tabList = 0l; |
276 | } | 278 | } |
277 | 279 | ||
278 | // Set new style information | 280 | // Set new style information |
279 | m_tabBarStyle = s; | 281 | m_tabBarStyle = s; |
280 | m_usingTabs = ( m_tabBarStyle == TextTab || m_tabBarStyle == IconTab ); | 282 | m_usingTabs = ( m_tabBarStyle == TextTab || m_tabBarStyle == IconTab ); |
281 | 283 | ||
282 | // Create new selector control and populate with tab information | 284 | // Create new selector control and populate with tab information |
283 | if ( m_usingTabs ) | 285 | if ( m_usingTabs ) |
284 | { | 286 | { |
285 | // Create new tab bar selector | 287 | // Create new tab bar selector |
286 | m_tabBar = new OTabBar( this ); | 288 | m_tabBar = new OTabBar( this ); |
287 | connect( m_tabBar, SIGNAL(selected(int)), this, SLOT(slotTabBarSelected(int)) ); | 289 | connect( m_tabBar, SIGNAL(selected(int)), this, SLOT(slotTabBarSelected(int)) ); |
288 | 290 | ||
289 | // Add all current tabs to tab bar | 291 | // Add all current tabs to tab bar |
290 | for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() ) | 292 | for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() ) |
291 | { | 293 | { |
292 | // Create new tab in tab bar | 294 | // Create new tab in tab bar |
293 | QTab *tab = new QTab(); | 295 | QTab *tab = new QTab(); |
294 | 296 | ||
295 | // Set label (and icon if necessary) | 297 | // Set label (and icon if necessary) |
296 | if ( m_tabBarStyle == IconTab ) | 298 | if ( m_tabBarStyle == IconTab ) |
297 | { | 299 | { |
298 | tab->label = QString::null; | 300 | tab->label = QString::null; |
299 | tab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); | 301 | tab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); |
300 | } | 302 | } |
301 | else | 303 | else |
302 | tab->label = tabinfo->label(); | 304 | tab->label = tabinfo->label(); |
303 | 305 | ||
304 | // Add tab and save its Id | 306 | // Add tab and save its Id |
305 | int tabid = m_tabBar->addTab( tab ); | 307 | int tabid = m_tabBar->addTab( tab ); |
306 | tabinfo->setId( tabid ); | 308 | tabinfo->setId( tabid ); |
307 | } | 309 | } |
308 | } | 310 | } |
309 | else | 311 | else |
310 | { | 312 | { |
311 | // Create new drop down list selector | 313 | // Create new drop down list selector |
312 | m_tabList = new QComboBox( false, this ); | 314 | m_tabList = new QComboBox( false, this ); |
313 | connect( m_tabList, SIGNAL(activated(int)), this, SLOT(slotTabListSelected(int)) ); | 315 | connect( m_tabList, SIGNAL(activated(int)), this, SLOT(slotTabListSelected(int)) ); |
314 | 316 | ||
315 | // Add all current tabs to drop down list | 317 | // Add all current tabs to drop down list |
316 | for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() ) | 318 | for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() ) |
317 | { | 319 | { |
318 | if ( m_tabBarStyle == IconList ) | 320 | if ( m_tabBarStyle == IconList ) |
319 | m_tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); | 321 | m_tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); |
320 | else | 322 | else |
321 | m_tabList->insertItem( tabinfo->label() ); | 323 | m_tabList->insertItem( tabinfo->label() ); |
322 | } | 324 | } |
323 | } | 325 | } |
324 | 326 | ||
325 | // Redraw widget | 327 | // Redraw widget |
326 | setUpLayout(); | 328 | setUpLayout(); |
327 | } | 329 | } |
328 | 330 | ||
329 | OTabWidget::TabPosition OTabWidget::tabPosition() const | 331 | OTabWidget::TabPosition OTabWidget::tabPosition() const |
330 | { | 332 | { |
331 | return m_tabBarPosition; | 333 | return m_tabBarPosition; |
332 | } | 334 | } |
333 | 335 | ||
334 | void OTabWidget::setTabPosition( TabPosition p ) | 336 | void OTabWidget::setTabPosition( TabPosition p ) |
335 | { | 337 | { |
336 | m_tabBarPosition = p; | 338 | m_tabBarPosition = p; |
337 | 339 | ||
338 | // If using the tab bar selector, set its shape | 340 | // If using the tab bar selector, set its shape |
339 | if ( m_usingTabs ) | 341 | if ( m_usingTabs ) |
340 | { | 342 | { |
341 | ( m_tabBarPosition == Top ) ? m_tabBar->setShape( QTabBar::RoundedAbove ) | 343 | ( m_tabBarPosition == Top ) ? m_tabBar->setShape( QTabBar::RoundedAbove ) |
342 | : m_tabBar->setShape( QTabBar::RoundedBelow ); | 344 | : m_tabBar->setShape( QTabBar::RoundedBelow ); |
343 | } | 345 | } |
344 | 346 | ||
345 | // Redraw widget | 347 | // Redraw widget |
346 | setUpLayout(); | 348 | setUpLayout(); |
347 | } | 349 | } |
348 | 350 | ||
349 | void OTabWidget::slotTabBarSelected( int id ) | 351 | void OTabWidget::slotTabBarSelected( int id ) |
350 | { | 352 | { |
351 | OTabInfo *newtab = m_tabs.first(); | 353 | OTabInfo *newtab = m_tabs.first(); |
352 | while ( newtab && newtab->id() != id ) | 354 | while ( newtab && newtab->id() != id ) |
353 | newtab = m_tabs.next(); | 355 | newtab = m_tabs.next(); |
354 | 356 | ||
355 | if ( newtab && newtab->id() == id ) | 357 | if ( newtab && newtab->id() == id ) |
356 | selectTab( newtab ); | 358 | selectTab( newtab ); |
357 | } | 359 | } |
358 | 360 | ||
359 | void OTabWidget::slotTabListSelected( int index ) | 361 | void OTabWidget::slotTabListSelected( int index ) |
360 | { | 362 | { |
361 | OTabInfo *newtab = m_tabs.at( index ); | 363 | OTabInfo *newtab = m_tabs.at( index ); |
362 | if ( newtab ) | 364 | if ( newtab ) |
363 | selectTab( newtab ); | 365 | selectTab( newtab ); |
364 | } | 366 | } |
365 | 367 | ||
366 | QPixmap OTabWidget::loadSmooth( const QString &name ) | 368 | QPixmap OTabWidget::loadSmooth( const QString &name ) |
367 | { | 369 | { |
368 | QPixmap p; | 370 | QPixmap p; |
369 | p.convertFromImage( Resource::loadImage( name ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); | 371 | p.convertFromImage( Resource::loadImage( name ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); |
370 | return p; | 372 | return p; |
371 | } | 373 | } |
372 | 374 | ||
373 | void OTabWidget::selectTab( OTabInfo *tab ) | 375 | void OTabWidget::selectTab( OTabInfo *tab ) |
374 | { | 376 | { |
375 | if ( m_tabBarStyle == IconTab ) | 377 | if ( m_tabBarStyle == IconTab ) |
376 | { | 378 | { |
377 | // Remove text label from currently selected tab | 379 | // Remove text label from currently selected tab |
378 | if ( m_currTab ) | 380 | if ( m_currTab ) |
379 | { | 381 | { |
380 | m_tabBar->tab( m_currTab->id() )->setText( QString::null ); | 382 | m_tabBar->tab( m_currTab->id() )->setText( QString::null ); |
381 | //setUpLayout(); | 383 | //setUpLayout(); |
382 | } | 384 | } |
383 | 385 | ||
384 | // Set text label for newly selected tab | 386 | // Set text label for newly selected tab |
385 | m_tabBar->tab( tab->id() )->setText( tab->label() ); | 387 | m_tabBar->tab( tab->id() )->setText( tab->label() ); |
386 | m_tabBar->setCurrentTab( tab->id() ); | 388 | m_tabBar->setCurrentTab( tab->id() ); |
387 | 389 | ||
388 | setUpLayout(); | 390 | setUpLayout(); |
389 | } | 391 | } |
390 | else if ( m_tabBarStyle == TextTab ) | 392 | else if ( m_tabBarStyle == TextTab ) |
391 | { | 393 | { |
392 | m_tabBar->setCurrentTab( tab->id() ); | 394 | m_tabBar->setCurrentTab( tab->id() ); |
393 | } | 395 | } |
394 | 396 | ||
395 | m_widgetStack->raiseWidget( tab->control() ); | 397 | m_widgetStack->raiseWidget( tab->control() ); |
396 | 398 | ||
397 | emit currentChanged( tab->control() ); | 399 | emit currentChanged( tab->control() ); |
398 | 400 | ||
399 | m_currTab = tab; | 401 | m_currTab = tab; |
400 | } | 402 | } |
401 | 403 | ||
402 | void OTabWidget::setUpLayout() | 404 | void OTabWidget::setUpLayout() |
403 | { | 405 | { |
404 | if ( m_usingTabs ) | 406 | if ( m_usingTabs ) |
405 | { | 407 | { |
406 | m_tabBar->update(); | 408 | m_tabBar->update(); |
407 | m_tabBar->layoutTabs(); | 409 | m_tabBar->layoutTabs(); |
408 | } | 410 | } |
409 | } | 411 | } |
410 | 412 | ||
411 | void OTabWidget::resizeEvent( QResizeEvent * ) | 413 | void OTabWidget::resizeEvent( QResizeEvent * ) |
412 | { | 414 | { |
413 | QSize t; | 415 | QSize t; |
414 | 416 | ||
415 | if ( m_usingTabs ) | 417 | if ( m_usingTabs ) |
416 | { | 418 | { |
417 | m_tabBar->layoutTabs(); | 419 | m_tabBar->layoutTabs(); |
418 | t = m_tabBar->sizeHint(); | 420 | t = m_tabBar->sizeHint(); |
419 | } | 421 | } |
420 | else | 422 | else |
421 | t = m_tabList->sizeHint(); | 423 | t = m_tabList->sizeHint(); |
422 | 424 | ||
423 | t.setWidth( width() ); | 425 | t.setWidth( width() ); |
424 | 426 | ||
425 | int lw = m_widgetStack->lineWidth(); | 427 | int lw = m_widgetStack->lineWidth(); |
426 | if ( m_tabBarPosition == Bottom ) | 428 | if ( m_tabBarPosition == Bottom ) |
427 | { | 429 | { |
428 | if ( m_usingTabs ) | 430 | if ( m_usingTabs ) |
429 | m_tabBar->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); | 431 | m_tabBar->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); |
430 | else | 432 | else |
431 | m_tabList->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); | 433 | m_tabList->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); |
432 | 434 | ||
433 | m_widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); | 435 | m_widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); |
434 | } | 436 | } |
435 | else | 437 | else |
436 | { | 438 | { |
437 | if ( m_usingTabs ) | 439 | if ( m_usingTabs ) |
438 | m_tabBar->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); | 440 | m_tabBar->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); |
439 | else | 441 | else |
440 | m_tabList->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); | 442 | m_tabList->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); |
441 | 443 | ||
442 | m_widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) ); | 444 | m_widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) ); |
443 | } | 445 | } |
444 | 446 | ||
445 | if ( autoMask() ) | 447 | if ( autoMask() ) |
446 | updateMask(); | 448 | updateMask(); |
447 | } | 449 | } |
448 | 450 | ||
449 | int OTabWidget::currentTab() | 451 | int OTabWidget::currentTab() |
450 | { | 452 | { |
451 | if ( m_currTab ) | 453 | if ( m_currTab ) |
452 | { | 454 | { |
453 | return m_currTab->id(); | 455 | return m_currTab->id(); |
454 | } | 456 | } |
455 | return -1; | 457 | return -1; |
456 | } | 458 | } |
457 | 459 | ||
458 | QWidget* OTabWidget::currentWidget()const | 460 | QWidget* OTabWidget::currentWidget()const |
459 | { | 461 | { |
460 | if ( m_currTab ) | 462 | if ( m_currTab ) |
461 | { | 463 | { |
462 | return m_currTab->control(); | 464 | return m_currTab->control(); |
463 | } | 465 | } |
464 | 466 | ||
465 | return 0; | 467 | return 0; |
466 | } | 468 | } |