author | drw <drw> | 2005-02-25 21:43:00 (UTC) |
---|---|---|
committer | drw <drw> | 2005-02-25 21:43:00 (UTC) |
commit | f2f2b0bc7f8fbb0ecbfd7548b7a29618cc5a9139 (patch) (unidiff) | |
tree | 8dfef7af3cd038b3a27570e64234388c8c563884 /libopie2 | |
parent | 8cddb795296ddc1f9bd3203a9441c555a565f476 (diff) | |
download | opie-f2f2b0bc7f8fbb0ecbfd7548b7a29618cc5a9139.zip opie-f2f2b0bc7f8fbb0ecbfd7548b7a29618cc5a9139.tar.gz opie-f2f2b0bc7f8fbb0ecbfd7548b7a29618cc5a9139.tar.bz2 |
Reworked OTabWidget - optimized (now uses less runtime resources), fix display issue where tabbar appears to float a few pixels above where it should
-rw-r--r-- | libopie2/opieui/otabinfo.h | 50 | ||||
-rw-r--r-- | libopie2/opieui/otabwidget.cpp | 440 | ||||
-rw-r--r-- | libopie2/opieui/otabwidget.h | 69 |
3 files changed, 301 insertions, 258 deletions
diff --git a/libopie2/opieui/otabinfo.h b/libopie2/opieui/otabinfo.h index d6d5abf..99ff10e 100644 --- a/libopie2/opieui/otabinfo.h +++ b/libopie2/opieui/otabinfo.h | |||
@@ -1,27 +1,27 @@ | |||
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, |
@@ -83,4 +83,12 @@ public: | |||
83 | 83 | ||
84 | /** | 84 | /** |
85 | * @fn setId( int id ) | ||
86 | * @brief Set Id for tab. | ||
87 | * | ||
88 | * @param id integer tab identifier. | ||
89 | */ | ||
90 | void setId( int id ) { i = id; } | ||
91 | |||
92 | /** | ||
85 | * @fn label()const | 93 | * @fn label()const |
86 | * @brief Returns text label for widget. | 94 | * @brief Returns text label for widget. |
diff --git a/libopie2/opieui/otabwidget.cpp b/libopie2/opieui/otabwidget.cpp index d23b1c9..01747e1 100644 --- a/libopie2/opieui/otabwidget.cpp +++ b/libopie2/opieui/otabwidget.cpp | |||
@@ -1,27 +1,27 @@ | |||
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, 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, |
@@ -46,86 +46,80 @@ using namespace Opie::Ui; | |||
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 ) | ||
49 | , m_usingTabs( true ) | ||
50 | , m_tabBar( 0l ) | ||
51 | , m_tabList( 0l ) | ||
48 | { | 52 | { |
49 | if ( s == Global ) | 53 | if ( s == Global ) |
50 | { | 54 | { |
55 | // Read Opie global settings for style and position | ||
51 | Config config( "qpe" ); | 56 | Config config( "qpe" ); |
52 | config.setGroup( "Appearance" ); | 57 | config.setGroup( "Appearance" ); |
58 | |||
59 | // Style | ||
53 | s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); | 60 | s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); |
54 | if ( s <= Global || s > IconList) | 61 | if ( s <= Global || s > IconList) |
55 | { | ||
56 | s = IconTab; | 62 | s = IconTab; |
57 | } | ||
58 | QString pos = config.readEntry( "TabPosition", "Top"); | ||
59 | if ( pos == "Bottom" ) | ||
60 | { | ||
61 | p = Bottom; | ||
62 | } | ||
63 | else | ||
64 | { | ||
65 | p = Top; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | widgetStack = new QWidgetStack( this, "widgetstack" ); | ||
70 | widgetStack->setFrameStyle( QFrame::NoFrame ); | ||
71 | widgetStack->setLineWidth( style().defaultFrameWidth() ); | ||
72 | |||
73 | tabBarStack = new QWidgetStack( this, "tabbarstack" ); | ||
74 | 63 | ||
75 | tabBar = new OTabBar( tabBarStack, "tabbar" ); | 64 | // Position |
76 | tabBarStack->addWidget( tabBar, 0 ); | 65 | ( config.readEntry( "TabPosition", "Top" ) == "Bottom" ) ? p = Bottom |
77 | connect( tabBar, SIGNAL( selected(int) ), this, SLOT( slotTabBarSelected(int) ) ); | 66 | : p = Top; |
67 | } | ||
78 | 68 | ||
79 | tabList = new QComboBox( false, tabBarStack, "tablist" ); | 69 | // Initialize widget stack for tab widgets |
80 | tabBarStack->addWidget( tabList, 1 ); | 70 | m_widgetStack = new QWidgetStack( this ); |
81 | connect( tabList, SIGNAL( activated(int) ), this, SLOT( slotTabListSelected(int) ) ); | 71 | m_widgetStack->setFrameStyle( QFrame::NoFrame ); |
72 | m_widgetStack->setLineWidth( style().defaultFrameWidth() ); | ||
82 | 73 | ||
83 | tabBarPosition = p; | 74 | // Set initial selector control style and position |
84 | setTabStyle( s ); | 75 | setTabStyle( s ); |
85 | setTabPosition( p ); | 76 | setTabPosition( p ); |
86 | |||
87 | currTab= 0x0; | ||
88 | } | 77 | } |
89 | 78 | ||
90 | OTabWidget::~OTabWidget() | 79 | OTabWidget::~OTabWidget() |
91 | { | 80 | { |
92 | tabs.setAutoDelete( true ); | 81 | m_tabs.setAutoDelete( true ); |
93 | tabs.clear(); | 82 | m_tabs.clear(); |
94 | } | 83 | } |
95 | 84 | ||
96 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) | 85 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) |
97 | { | 86 | { |
98 | QPixmap iconset = loadSmooth( icon ); | 87 | int tabid = -1; |
99 | 88 | ||
100 | QTab *tab = new QTab(); | 89 | if ( m_usingTabs ) |
101 | if ( tabBarStyle == IconTab ) | ||
102 | { | ||
103 | tab->label = QString::null; | ||
104 | } | ||
105 | else | ||
106 | { | ||
107 | tab->label = label; | ||
108 | } | ||
109 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) | ||
110 | { | 90 | { |
111 | tab->iconset = new QIconSet( iconset ); | 91 | // Create new tab in tab bar |
112 | } | 92 | QTab *tab = new QTab(); |
113 | int tabid = tabBar->addTab( tab ); | ||
114 | 93 | ||
115 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) | 94 | // Set label (and icon if necessary) |
116 | { | 95 | if ( m_tabBarStyle == IconTab ) |
117 | tabList->insertItem( iconset, label, -1 ); | 96 | { |
97 | tab->label = QString::null; | ||
98 | tab->iconset = new QIconSet( loadSmooth( icon ) ); | ||
99 | } | ||
100 | else | ||
101 | tab->label = label; | ||
102 | |||
103 | tabid = m_tabBar->addTab( tab ); | ||
118 | } | 104 | } |
119 | else | 105 | else |
120 | { | 106 | { |
121 | tabList->insertItem( label ); | 107 | // Insert entry (with icon if necessary) into drop down list |
108 | if ( m_tabBarStyle == IconList ) | ||
109 | m_tabList->insertItem( loadSmooth( icon ), label, -1 ); | ||
110 | else | ||
111 | m_tabList->insertItem( label ); | ||
122 | } | 112 | } |
123 | 113 | ||
124 | widgetStack->addWidget( child, tabid ); | 114 | // Add widget to stack |
125 | widgetStack->raiseWidget( child ); | 115 | m_widgetStack->addWidget( child, tabid ); |
126 | widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); | 116 | m_widgetStack->raiseWidget( child ); |
117 | m_widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); | ||
127 | 118 | ||
119 | // Keep track of tab information | ||
128 | OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); | 120 | OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); |
129 | tabs.append( tabinfo ); | 121 | m_tabs.append( tabinfo ); |
122 | |||
123 | // Make newly added tab the current one displayed | ||
130 | selectTab( tabinfo ); | 124 | selectTab( tabinfo ); |
131 | } | 125 | } |
@@ -135,31 +129,40 @@ void OTabWidget::removePage( QWidget *childwidget ) | |||
135 | if ( childwidget ) | 129 | if ( childwidget ) |
136 | { | 130 | { |
137 | OTabInfo *tab = tabs.first(); | 131 | // Find tab information for desired widget |
132 | OTabInfo *tab = m_tabs.first(); | ||
138 | while ( tab && tab->control() != childwidget ) | 133 | while ( tab && tab->control() != childwidget ) |
139 | { | 134 | tab = m_tabs.next(); |
140 | tab = tabs.next(); | 135 | |
141 | } | ||
142 | if ( tab && tab->control() == childwidget ) | 136 | if ( tab && tab->control() == childwidget ) |
143 | { | 137 | { |
144 | tabBar->setTabEnabled( tab->id(), FALSE ); | 138 | if ( m_usingTabs ) |
145 | tabBar->removeTab( tabBar->tab( tab->id() ) ); | ||
146 | int i = 0; | ||
147 | while ( i < tabList->count() && tabList->text( i ) != tab->label() ) | ||
148 | { | 139 | { |
149 | i++; | 140 | // Remove tab from tab bar |
141 | m_tabBar->setTabEnabled( tab->id(), false ); | ||
142 | m_tabBar->removeTab( m_tabBar->tab( tab->id() ) ); | ||
150 | } | 143 | } |
151 | if ( tabList->text( i ) == tab->label() ) | 144 | else |
152 | { | 145 | { |
153 | tabList->removeItem( i ); | 146 | // Remove entry from drop down list |
147 | int i = 0; | ||
148 | while ( i < m_tabList->count() && m_tabList->text( i ) != tab->label() ) | ||
149 | i++; | ||
150 | if ( m_tabList->text( i ) == tab->label() ) | ||
151 | m_tabList->removeItem( i ); | ||
154 | } | 152 | } |
155 | widgetStack->removeWidget( childwidget ); | 153 | |
156 | tabs.remove( tab ); | 154 | // Remove widget from stack |
155 | m_widgetStack->removeWidget( childwidget ); | ||
156 | |||
157 | // Get rid of tab information | ||
158 | m_tabs.remove( tab ); | ||
157 | delete tab; | 159 | delete tab; |
158 | currTab = tabs.current(); | ||
159 | if ( !currTab ) | ||
160 | { | ||
161 | widgetStack->setFrameStyle( QFrame::NoFrame ); | ||
162 | } | ||
163 | 160 | ||
161 | // Reset current tab | ||
162 | m_currTab = m_tabs.current(); | ||
163 | if ( !m_currTab ) | ||
164 | m_widgetStack->setFrameStyle( QFrame::NoFrame ); | ||
165 | |||
166 | // Redraw widget | ||
164 | setUpLayout(); | 167 | setUpLayout(); |
165 | } | 168 | } |
@@ -169,44 +172,51 @@ void OTabWidget::removePage( QWidget *childwidget ) | |||
169 | void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) | 172 | void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) |
170 | { | 173 | { |
171 | OTabInfo *currtab = tabs.first(); | 174 | // Find tab information for desired widget |
175 | OTabInfo *currtab = m_tabs.first(); | ||
172 | while ( currtab && currtab->control() != widget ) | 176 | while ( currtab && currtab->control() != widget ) |
173 | { | 177 | currtab = m_tabs.next(); |
174 | currtab = tabs.next(); | 178 | |
175 | } | ||
176 | if ( currtab && currtab->control() == widget ) | 179 | if ( currtab && currtab->control() == widget ) |
177 | { | 180 | { |
178 | QTab *tab = tabBar->tab( currtab->id() ); | ||
179 | QPixmap icon( loadSmooth( iconset ) ); | 181 | QPixmap icon( loadSmooth( iconset ) ); |
180 | tab->setText( label ); | 182 | |
181 | if ( tabBarStyle == IconTab ) | 183 | if ( m_usingTabs ) |
182 | tab->setIconSet( icon ); | ||
183 | int i = 0; | ||
184 | while ( i < tabList->count() && tabList->text( i ) != currtab->label() ) | ||
185 | { | 184 | { |
186 | i++; | 185 | // Update tab label and icon (if necessary) |
186 | QTab *tab = m_tabBar->tab( currtab->id() ); | ||
187 | tab->setText( label ); | ||
188 | if ( m_tabBarStyle == IconTab ) | ||
189 | tab->setIconSet( icon ); | ||
187 | } | 190 | } |
188 | if ( i < tabList->count() && tabList->text( i ) == currtab->label() ) | 191 | else |
189 | { | 192 | { |
190 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) | 193 | // Update entry label and icon (if necessary) |
191 | { | 194 | int i = 0; |
192 | tabList->changeItem( icon, label, i ); | 195 | while ( i < m_tabList->count() && m_tabList->text( i ) != currtab->label() ) |
193 | } | 196 | i++; |
194 | else | 197 | if ( i < m_tabList->count() && m_tabList->text( i ) == currtab->label() ) |
195 | { | 198 | { |
196 | tabList->changeItem( label, i ); | 199 | if ( m_tabBarStyle == IconList ) |
200 | m_tabList->changeItem( icon, label, i ); | ||
201 | else | ||
202 | m_tabList->changeItem( label, i ); | ||
197 | } | 203 | } |
198 | } | 204 | } |
205 | |||
206 | // Update tab information | ||
199 | currtab->setLabel( label ); | 207 | currtab->setLabel( label ); |
200 | currtab->setIcon( iconset ); | 208 | currtab->setIcon( iconset ); |
209 | |||
210 | // Redraw widget | ||
211 | setUpLayout(); | ||
201 | } | 212 | } |
202 | setUpLayout(); | ||
203 | } | 213 | } |
204 | 214 | ||
205 | void OTabWidget::setCurrentTab( QWidget *childwidget ) | 215 | void OTabWidget::setCurrentTab( QWidget *childwidget ) |
206 | { | 216 | { |
207 | OTabInfo *currtab = tabs.first(); | 217 | OTabInfo *currtab = m_tabs.first(); |
208 | while ( currtab && currtab->control() != childwidget ) | 218 | while ( currtab && currtab->control() != childwidget ) |
209 | { | 219 | { |
210 | currtab = tabs.next(); | 220 | currtab = m_tabs.next(); |
211 | } | 221 | } |
212 | if ( currtab && currtab->control() == childwidget ) | 222 | if ( currtab && currtab->control() == childwidget ) |
@@ -218,8 +228,8 @@ void OTabWidget::setCurrentTab( QWidget *childwidget ) | |||
218 | void OTabWidget::setCurrentTab( const QString &tabname ) | 228 | void OTabWidget::setCurrentTab( const QString &tabname ) |
219 | { | 229 | { |
220 | OTabInfo *newtab = tabs.first(); | 230 | OTabInfo *newtab = m_tabs.first(); |
221 | while ( newtab && newtab->label() != tabname ) | 231 | while ( newtab && newtab->label() != tabname ) |
222 | { | 232 | { |
223 | newtab = tabs.next(); | 233 | newtab = m_tabs.next(); |
224 | } | 234 | } |
225 | if ( newtab && newtab->label() == tabname ) | 235 | if ( newtab && newtab->label() == tabname ) |
@@ -231,8 +241,8 @@ void OTabWidget::setCurrentTab( const QString &tabname ) | |||
231 | void OTabWidget::setCurrentTab(int tabindex) | 241 | void OTabWidget::setCurrentTab(int tabindex) |
232 | { | 242 | { |
233 | OTabInfo *newtab = tabs.first(); | 243 | OTabInfo *newtab = m_tabs.first(); |
234 | while ( newtab && newtab->id() != tabindex ) | 244 | while ( newtab && newtab->id() != tabindex ) |
235 | { | 245 | { |
236 | newtab = tabs.next(); | 246 | newtab = m_tabs.next(); |
237 | } | 247 | } |
238 | if ( newtab && newtab->id() == tabindex ) | 248 | if ( newtab && newtab->id() == tabindex ) |
@@ -245,48 +255,73 @@ void OTabWidget::setCurrentTab(int tabindex) | |||
245 | OTabWidget::TabStyle OTabWidget::tabStyle() const | 255 | OTabWidget::TabStyle OTabWidget::tabStyle() const |
246 | { | 256 | { |
247 | return tabBarStyle; | 257 | return m_tabBarStyle; |
248 | } | 258 | } |
249 | 259 | ||
250 | void OTabWidget::setTabStyle( TabStyle s ) | 260 | void OTabWidget::setTabStyle( TabStyle s ) |
251 | { | 261 | { |
252 | tabBarStyle = s; | 262 | // Get out if new and current styles are the same |
253 | if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) | 263 | if ( s == m_tabBarStyle ) |
264 | return; | ||
265 | |||
266 | // Delete current selector control | ||
267 | if ( m_usingTabs ) | ||
268 | { | ||
269 | delete m_tabBar; | ||
270 | m_tabBar = 0l; | ||
271 | } | ||
272 | else | ||
254 | { | 273 | { |
255 | QTab *currtab; | 274 | delete m_tabList; |
256 | for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) | 275 | m_tabList = 0l; |
276 | } | ||
277 | |||
278 | // Set new style information | ||
279 | m_tabBarStyle = s; | ||
280 | m_usingTabs = ( m_tabBarStyle == TextTab || m_tabBarStyle == IconTab ); | ||
281 | |||
282 | // Create new selector control and populate with tab information | ||
283 | if ( m_usingTabs ) | ||
284 | { | ||
285 | // Create new tab bar selector | ||
286 | m_tabBar = new OTabBar( this ); | ||
287 | connect( m_tabBar, SIGNAL(selected(int)), this, SLOT(slotTabBarSelected(int)) ); | ||
288 | |||
289 | // Add all current tabs to tab bar | ||
290 | for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() ) | ||
257 | { | 291 | { |
258 | currtab = tabBar->tab( tabinfo->id() ); | 292 | // Create new tab in tab bar |
259 | if ( tabBarStyle == IconTab ) | 293 | QTab *tab = new QTab(); |
294 | |||
295 | // Set label (and icon if necessary) | ||
296 | if ( m_tabBarStyle == IconTab ) | ||
260 | { | 297 | { |
261 | currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); | 298 | tab->label = QString::null; |
262 | if ( tabinfo == currTab ) | 299 | tab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); |
263 | currtab->setText( tabinfo->label() ); | ||
264 | else | ||
265 | currtab->setText( QString::null ); | ||
266 | } | 300 | } |
267 | else | 301 | else |
268 | { | 302 | tab->label = tabinfo->label(); |
269 | currtab->iconset = 0x0; | 303 | |
270 | currtab->setText( tabinfo->label() ); | 304 | // Add tab and save its Id |
271 | } | 305 | int tabid = m_tabBar->addTab( tab ); |
306 | tabinfo->setId( tabid ); | ||
272 | } | 307 | } |
273 | tabBarStack->raiseWidget( tabBar ); | ||
274 | } | 308 | } |
275 | else if ( tabBarStyle == TextList || tabBarStyle == IconList ) | 309 | else |
276 | { | 310 | { |
277 | tabList->clear(); | 311 | // Create new drop down list selector |
278 | for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) | 312 | m_tabList = new QComboBox( false, this ); |
313 | connect( m_tabList, SIGNAL(activated(int)), this, SLOT(slotTabListSelected(int)) ); | ||
314 | |||
315 | // Add all current tabs to drop down list | ||
316 | for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() ) | ||
279 | { | 317 | { |
280 | if ( tabBarStyle == IconList ) | 318 | if ( m_tabBarStyle == IconList ) |
281 | { | 319 | m_tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); |
282 | tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); | ||
283 | } | ||
284 | else | 320 | else |
285 | { | 321 | m_tabList->insertItem( tabinfo->label() ); |
286 | tabList->insertItem( tabinfo->label() ); | ||
287 | } | ||
288 | } | 322 | } |
289 | tabBarStack->raiseWidget( tabList ); | ||
290 | } | 323 | } |
324 | |||
325 | // Redraw widget | ||
291 | setUpLayout(); | 326 | setUpLayout(); |
292 | } | 327 | } |
@@ -294,18 +329,19 @@ void OTabWidget::setTabStyle( TabStyle s ) | |||
294 | OTabWidget::TabPosition OTabWidget::tabPosition() const | 329 | OTabWidget::TabPosition OTabWidget::tabPosition() const |
295 | { | 330 | { |
296 | return tabBarPosition; | 331 | return m_tabBarPosition; |
297 | } | 332 | } |
298 | 333 | ||
299 | void OTabWidget::setTabPosition( TabPosition p ) | 334 | void OTabWidget::setTabPosition( TabPosition p ) |
300 | { | 335 | { |
301 | tabBarPosition = p; | 336 | m_tabBarPosition = p; |
302 | if ( tabBarPosition == Top ) | 337 | |
303 | { | 338 | // If using the tab bar selector, set its shape |
304 | tabBar->setShape( QTabBar::RoundedAbove ); | 339 | if ( m_usingTabs ) |
305 | } | ||
306 | else | ||
307 | { | 340 | { |
308 | tabBar->setShape( QTabBar::RoundedBelow ); | 341 | ( m_tabBarPosition == Top ) ? m_tabBar->setShape( QTabBar::RoundedAbove ) |
342 | : m_tabBar->setShape( QTabBar::RoundedBelow ); | ||
309 | } | 343 | } |
344 | |||
345 | // Redraw widget | ||
310 | setUpLayout(); | 346 | setUpLayout(); |
311 | } | 347 | } |
@@ -313,22 +349,17 @@ void OTabWidget::setTabPosition( TabPosition p ) | |||
313 | void OTabWidget::slotTabBarSelected( int id ) | 349 | void OTabWidget::slotTabBarSelected( int id ) |
314 | { | 350 | { |
315 | OTabInfo *newtab = tabs.first(); | 351 | OTabInfo *newtab = m_tabs.first(); |
316 | while ( newtab && newtab->id() != id ) | 352 | while ( newtab && newtab->id() != id ) |
317 | { | 353 | newtab = m_tabs.next(); |
318 | newtab = tabs.next(); | 354 | |
319 | } | ||
320 | if ( newtab && newtab->id() == id ) | 355 | if ( newtab && newtab->id() == id ) |
321 | { | ||
322 | selectTab( newtab ); | 356 | selectTab( newtab ); |
323 | } | ||
324 | } | 357 | } |
325 | 358 | ||
326 | void OTabWidget::slotTabListSelected( int index ) | 359 | void OTabWidget::slotTabListSelected( int index ) |
327 | { | 360 | { |
328 | OTabInfo *newtab = tabs.at( index ); | 361 | OTabInfo *newtab = m_tabs.at( index ); |
329 | if ( newtab ) | 362 | if ( newtab ) |
330 | { | ||
331 | selectTab( newtab ); | 363 | selectTab( newtab ); |
332 | } | ||
333 | } | 364 | } |
334 | 365 | ||
@@ -342,51 +373,72 @@ QPixmap OTabWidget::loadSmooth( const QString &name ) | |||
342 | void OTabWidget::selectTab( OTabInfo *tab ) | 373 | void OTabWidget::selectTab( OTabInfo *tab ) |
343 | { | 374 | { |
344 | if ( tabBarStyle == IconTab ) | 375 | if ( m_tabBarStyle == IconTab ) |
345 | { | 376 | { |
346 | if ( currTab ) | 377 | // Remove text label from currently selected tab |
378 | if ( m_currTab ) | ||
347 | { | 379 | { |
348 | tabBar->tab( currTab->id() )->setText( QString::null ); | 380 | m_tabBar->tab( m_currTab->id() )->setText( QString::null ); |
349 | setUpLayout(); | 381 | //setUpLayout(); |
350 | } | 382 | } |
351 | tabBar->tab( tab->id() )->setText( tab->label() ); | 383 | |
352 | tabBar->setCurrentTab( tab->id() ); | 384 | // Set text label for newly selected tab |
385 | m_tabBar->tab( tab->id() )->setText( tab->label() ); | ||
386 | m_tabBar->setCurrentTab( tab->id() ); | ||
387 | |||
353 | setUpLayout(); | 388 | setUpLayout(); |
354 | tabBar->update(); | ||
355 | } | 389 | } |
356 | else | 390 | else if ( m_tabBarStyle == TextTab ) |
357 | { | 391 | { |
358 | tabBar->setCurrentTab( tab->id() ); | 392 | m_tabBar->setCurrentTab( tab->id() ); |
359 | } | 393 | } |
360 | 394 | ||
361 | widgetStack->raiseWidget( tab->control() ); | 395 | m_widgetStack->raiseWidget( tab->control() ); |
362 | 396 | ||
363 | emit currentChanged( tab->control() ); | 397 | emit currentChanged( tab->control() ); |
364 | 398 | ||
365 | currTab = tab; | 399 | m_currTab = tab; |
366 | } | 400 | } |
367 | 401 | ||
368 | void OTabWidget::setUpLayout() | 402 | void OTabWidget::setUpLayout() |
369 | { | 403 | { |
370 | tabBar->layoutTabs(); | 404 | if ( m_usingTabs ) |
371 | QSize t( tabBarStack->sizeHint() ); | ||
372 | if ( tabBarStyle == IconTab ) | ||
373 | { | 405 | { |
374 | if ( t.width() > width() ) | 406 | m_tabBar->update(); |
375 | t.setWidth( width() ); | 407 | m_tabBar->layoutTabs(); |
376 | } | 408 | } |
377 | else | 409 | } |
410 | |||
411 | void OTabWidget::resizeEvent( QResizeEvent * ) | ||
412 | { | ||
413 | QSize t; | ||
414 | |||
415 | if ( m_usingTabs ) | ||
378 | { | 416 | { |
379 | t.setWidth( width() ); | 417 | m_tabBar->layoutTabs(); |
418 | t = m_tabBar->sizeHint(); | ||
380 | } | 419 | } |
381 | int lw = widgetStack->lineWidth(); | 420 | else |
382 | if ( tabBarPosition == Bottom ) | 421 | t = m_tabList->sizeHint(); |
422 | |||
423 | t.setWidth( width() ); | ||
424 | |||
425 | int lw = m_widgetStack->lineWidth(); | ||
426 | if ( m_tabBarPosition == Bottom ) | ||
383 | { | 427 | { |
384 | tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); | 428 | if ( m_usingTabs ) |
385 | widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); | 429 | m_tabBar->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); |
430 | else | ||
431 | m_tabList->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); | ||
432 | |||
433 | m_widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); | ||
386 | } | 434 | } |
387 | else | 435 | else |
388 | { | 436 | { |
389 | tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); | 437 | if ( m_usingTabs ) |
390 | widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) ); | 438 | m_tabBar->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); |
439 | else | ||
440 | m_tabList->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); | ||
441 | |||
442 | m_widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) ); | ||
391 | } | 443 | } |
392 | 444 | ||
@@ -395,21 +447,9 @@ void OTabWidget::setUpLayout() | |||
395 | } | 447 | } |
396 | 448 | ||
397 | QSize OTabWidget::sizeHint() const | ||
398 | { | ||
399 | QSize s( widgetStack->sizeHint() ); | ||
400 | QSize t( tabBarStack->sizeHint() ); | ||
401 | return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() ); | ||
402 | } | ||
403 | |||
404 | void OTabWidget::resizeEvent( QResizeEvent * ) | ||
405 | { | ||
406 | setUpLayout(); | ||
407 | } | ||
408 | |||
409 | int OTabWidget::currentTab() | 449 | int OTabWidget::currentTab() |
410 | { | 450 | { |
411 | if ( currTab ) | 451 | if ( m_currTab ) |
412 | { | 452 | { |
413 | return currTab->id(); | 453 | return m_currTab->id(); |
414 | } | 454 | } |
415 | return -1; | 455 | return -1; |
@@ -418,7 +458,7 @@ int OTabWidget::currentTab() | |||
418 | QWidget* OTabWidget::currentWidget()const | 458 | QWidget* OTabWidget::currentWidget()const |
419 | { | 459 | { |
420 | if ( currTab ) | 460 | if ( m_currTab ) |
421 | { | 461 | { |
422 | return currTab->control(); | 462 | return m_currTab->control(); |
423 | } | 463 | } |
424 | 464 | ||
diff --git a/libopie2/opieui/otabwidget.h b/libopie2/opieui/otabwidget.h index b3423e8..e925592 100644 --- a/libopie2/opieui/otabwidget.h +++ b/libopie2/opieui/otabwidget.h | |||
@@ -1,26 +1,26 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2002 Dan Williams <williamsdr@acm.org> | 3 | Copyright (C) 2002, 2005 Dan Williams <drw@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
@@ -195,10 +195,4 @@ class OTabWidget : public QWidget | |||
195 | 195 | ||
196 | /** | 196 | /** |
197 | * @fn sizeHint()const | ||
198 | * @brief Reimplemented for internal purposes. | ||
199 | */ | ||
200 | QSize sizeHint() const; | ||
201 | |||
202 | /** | ||
203 | * @fn currentTab( ) | 197 | * @fn currentTab( ) |
204 | * @brief returns current tab id. | 198 | * @brief returns current tab id. |
@@ -222,15 +216,16 @@ protected: | |||
222 | 216 | ||
223 | private: | 217 | private: |
224 | OTabInfoList tabs; | 218 | OTabInfoList m_tabs; // List of information for tabs |
225 | OTabInfo *currTab; | 219 | OTabInfo *m_currTab; // Current tab displayed |
226 | 220 | TabStyle m_tabBarStyle; // Current style of control | |
227 | TabStyle tabBarStyle; | 221 | TabPosition m_tabBarPosition; // Position of selector control |
228 | TabPosition tabBarPosition; | 222 | bool m_usingTabs; // Indicates whether style is either TextTab or IconTab |
229 | 223 | // (saves from having to always check for these 2 values) | |
230 | QWidgetStack *tabBarStack; | 224 | |
231 | OTabBar *tabBar; | 225 | // UI components |
232 | QComboBox *tabList; | 226 | OTabBar *m_tabBar; |
227 | QComboBox *m_tabList; | ||
228 | QWidgetStack *m_widgetStack; | ||
233 | 229 | ||
234 | QWidgetStack *widgetStack; | ||
235 | class Private; | 230 | class Private; |
236 | Private* d; | 231 | Private* d; |