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