summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/otabwidget.cpp90
1 files changed, 61 insertions, 29 deletions
diff --git a/libopie/otabwidget.cpp b/libopie/otabwidget.cpp
index 1fee919..bee3f35 100644
--- a/libopie/otabwidget.cpp
+++ b/libopie/otabwidget.cpp
@@ -16,114 +16,97 @@
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 "otabwidget.h" 32#include "otabwidget.h"
33 33
34#include <qpe/config.h> 34#include <qpe/config.h>
35#include <qpe/resource.h> 35#include <qpe/resource.h>
36#include <opie/otabbar.h> 36#include <opie/otabbar.h>
37 37
38#include <qcombobox.h> 38#include <qcombobox.h>
39#include <qwidgetstack.h> 39#include <qwidgetstack.h>
40 40
41OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p ) 41OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p )
42 : QWidget( parent, name ) 42 : QWidget( parent, name )
43{ 43{
44 if ( s == Global ) 44 if ( s == Global )
45 { 45 {
46 Config config( "qpe" ); 46 Config config( "qpe" );
47 config.setGroup( "Appearance" ); 47 config.setGroup( "Appearance" );
48 tabBarStyle = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); 48 s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab );
49 if ( tabBarStyle <= Global || tabBarStyle > IconList) 49 if ( s <= Global || s > IconList)
50 { 50 {
51 tabBarStyle = IconTab; 51 s = IconTab;
52 } 52 }
53 QString pos = config.readEntry( "TabPosition", "Top"); 53 QString pos = config.readEntry( "TabPosition", "Top");
54 if ( pos == "Bottom" ) 54 if ( pos == "Bottom" )
55 { 55 {
56 tabBarPosition = Bottom; 56 p = Bottom;
57 } 57 }
58 else 58 else
59 { 59 {
60 tabBarPosition = Top; 60 p = Top;
61 } 61 }
62 } 62 }
63 else
64 {
65 tabBarStyle = s;
66 tabBarPosition = p;
67 }
68 63
69 widgetStack = new QWidgetStack( this, "widgetstack" ); 64 widgetStack = new QWidgetStack( this, "widgetstack" );
70 widgetStack->setFrameStyle( QFrame::NoFrame ); 65 widgetStack->setFrameStyle( QFrame::NoFrame );
71 widgetStack->setLineWidth( style().defaultFrameWidth() ); 66 widgetStack->setLineWidth( style().defaultFrameWidth() );
72 67
73 tabBarStack = new QWidgetStack( this, "tabbarstack" ); 68 tabBarStack = new QWidgetStack( this, "tabbarstack" );
74 69
75 tabBar = new OTabBar( tabBarStack, "tabbar" ); 70 tabBar = new OTabBar( tabBarStack, "tabbar" );
76 tabBarStack->addWidget( tabBar, 0 ); 71 tabBarStack->addWidget( tabBar, 0 );
77 connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) ); 72 connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) );
78 73
79 tabList = new QComboBox( false, tabBarStack, "tablist" ); 74 tabList = new QComboBox( false, tabBarStack, "tablist" );
80 tabBarStack->addWidget( tabList, 1 ); 75 tabBarStack->addWidget( tabList, 1 );
81 connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) ); 76 connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) );
82 77
83 if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) 78 setTabStyle( s );
84 { 79 setTabPosition( p );
85 tabBarStack->raiseWidget( tabBar );
86 }
87 else if ( tabBarStyle == TextList || tabBarStyle == IconList )
88 {
89 tabBarStack->raiseWidget( tabList );
90 }
91
92 if ( tabBarPosition == Bottom )
93 {
94 tabBar->setShape( QTabBar::RoundedBelow );
95 }
96 80
97 //tabs.setAutoDelete( TRUE );
98 currentTab= 0x0; 81 currentTab= 0x0;
99} 82}
100 83
101OTabWidget::~OTabWidget() 84OTabWidget::~OTabWidget()
102{ 85{
103} 86}
104 87
105void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) 88void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
106{ 89{
107 QPixmap iconset = loadSmooth( icon ); 90 QPixmap iconset = loadSmooth( icon );
108 91
109 QTab *tab = new QTab(); 92 QTab *tab = new QTab();
110 if ( tabBarStyle == IconTab ) 93 if ( tabBarStyle == IconTab )
111 { 94 {
112 tab->label = QString::null; 95 tab->label = QString::null;
113 } 96 }
114 else 97 else
115 { 98 {
116 tab->label = label; 99 tab->label = label;
117 } 100 }
118 if ( tabBarStyle == IconTab || tabBarStyle == IconList) 101 if ( tabBarStyle == IconTab || tabBarStyle == IconList)
119 { 102 {
120 tab->iconset = new QIconSet( iconset ); 103 tab->iconset = new QIconSet( iconset );
121 } 104 }
122 int tabid = tabBar->addTab( tab ); 105 int tabid = tabBar->addTab( tab );
123 106
124 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 107 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
125 { 108 {
126 tabList->insertItem( iconset, label, -1 ); 109 tabList->insertItem( iconset, label, -1 );
127 } 110 }
128 else 111 else
129 { 112 {
@@ -193,149 +176,198 @@ void OTabWidget::setCurrentTab( const QString &tabname )
193 OTabInfo *newtab = tabs.first(); 176 OTabInfo *newtab = tabs.first();
194 while ( newtab && newtab->label() != tabname ) 177 while ( newtab && newtab->label() != tabname )
195 { 178 {
196 newtab = tabs.next(); 179 newtab = tabs.next();
197 } 180 }
198 if ( newtab && newtab->label() == tabname ) 181 if ( newtab && newtab->label() == tabname )
199 { 182 {
200 selectTab( newtab ); 183 selectTab( newtab );
201 } 184 }
202} 185}
203 186
204void OTabWidget::setCurrentTab(int tabindex) { 187void OTabWidget::setCurrentTab(int tabindex) {
205 OTabInfo *newtab = tabs.first(); 188 OTabInfo *newtab = tabs.first();
206 while ( newtab && newtab->id() != tabindex ) 189 while ( newtab && newtab->id() != tabindex )
207 { 190 {
208 newtab = tabs.next(); 191 newtab = tabs.next();
209 } 192 }
210 if ( newtab && newtab->id() == tabindex ) 193 if ( newtab && newtab->id() == tabindex )
211 { 194 {
212 selectTab( newtab ); 195 selectTab( newtab );
213 } 196 }
214} 197}
215 198
216 199
217OTabWidget::TabStyle OTabWidget::tabStyle() const 200OTabWidget::TabStyle OTabWidget::tabStyle() const
218{ 201{
219 return tabBarStyle; 202 return tabBarStyle;
220} 203}
221 204
222void OTabWidget::setTabStyle( TabStyle s ) 205void OTabWidget::setTabStyle( TabStyle s )
223{ 206{
224 tabBarStyle = s; 207 tabBarStyle = s;
208 if ( tabBarStyle == TextTab || tabBarStyle == IconTab )
209 {
210 QTab *currtab;
211 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
212 {
213 currtab = tabBar->tab( tabinfo->id() );
214 if ( tabBarStyle == IconTab )
215 {
216 currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) );
217 if ( tabinfo == currentTab )
218 currtab->setText( tabinfo->label() );
219 else
220 currtab->setText( QString::null );
221 }
222 else
223 {
224 currtab->iconset = 0x0;
225 currtab->setText( tabinfo->label() );
226 }
227 }
228 tabBarStack->raiseWidget( tabBar );
229 }
230 else if ( tabBarStyle == TextList || tabBarStyle == IconList )
231 {
232 tabList->clear();
233 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
234 {
235 if ( tabBarStyle == IconList )
236 {
237 tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() );
238 }
239 else
240 {
241 tabList->insertItem( tabinfo->label() );
242 }
243 }
244 tabBarStack->raiseWidget( tabList );
245 }
246 setUpLayout();
225} 247}
226 248
227OTabWidget::TabPosition OTabWidget::tabPosition() const 249OTabWidget::TabPosition OTabWidget::tabPosition() const
228{ 250{
229 return tabBarPosition; 251 return tabBarPosition;
230} 252}
231 253
232void OTabWidget::setTabPosition( TabPosition p ) 254void OTabWidget::setTabPosition( TabPosition p )
233{ 255{
234 tabBarPosition = p; 256 tabBarPosition = p;
257 if ( tabBarPosition == Top )
258 {
259 tabBar->setShape( QTabBar::RoundedAbove );
260 }
261 else
262 {
263 tabBar->setShape( QTabBar::RoundedBelow );
264 }
265 setUpLayout();
235} 266}
236 267
237void OTabWidget::slotTabBarSelected( int id ) 268void OTabWidget::slotTabBarSelected( int id )
238{ 269{
239 OTabInfo *newtab = tabs.first(); 270 OTabInfo *newtab = tabs.first();
240 while ( newtab && newtab->id() != id ) 271 while ( newtab && newtab->id() != id )
241 { 272 {
242 newtab = tabs.next(); 273 newtab = tabs.next();
243 } 274 }
244 if ( newtab && newtab->id() == id ) 275 if ( newtab && newtab->id() == id )
245 { 276 {
246 selectTab( newtab ); 277 selectTab( newtab );
247 } 278 }
248} 279}
249 280
250void OTabWidget::slotTabListSelected( int index ) 281void OTabWidget::slotTabListSelected( int index )
251{ 282{
252 OTabInfo *newtab = tabs.at( index ); 283 OTabInfo *newtab = tabs.at( index );
253 if ( newtab ) 284 if ( newtab )
254 { 285 {
255 selectTab( newtab ); 286 selectTab( newtab );
256 } 287 }
257} 288}
258 289
259QPixmap OTabWidget::loadSmooth( const QString &name ) 290QPixmap OTabWidget::loadSmooth( const QString &name )
260{ 291{
261 QImage image = Resource::loadImage( name ); 292 QImage image = Resource::loadImage( name );
262 QPixmap pixmap; 293 QPixmap pixmap;
263 pixmap.convertFromImage( image.smoothScale( 16, 16 ) ); 294 pixmap.convertFromImage( image.smoothScale( 16, 16 ) );
264 return pixmap; 295 return pixmap;
265} 296}
266 297
267void OTabWidget::selectTab( OTabInfo *tab ) 298void OTabWidget::selectTab( OTabInfo *tab )
268{ 299{
269 if ( tabBarStyle == IconTab ) 300 if ( tabBarStyle == IconTab )
270 { 301 {
271 if ( currentTab ) 302 if ( currentTab )
272 { 303 {
273 tabBar->tab( currentTab->id() )->setText( "" ); 304 tabBar->tab( currentTab->id() )->setText( QString::null );
274 setUpLayout(); 305 setUpLayout();
275 } 306 }
276 tabBar->tab( tab->id() )->setText( tab->label() ); 307 tabBar->tab( tab->id() )->setText( tab->label() );
277 tabBar->setCurrentTab( tab->id() ); 308 tabBar->setCurrentTab( tab->id() );
278 setUpLayout(); 309 setUpLayout();
279 tabBar->update(); 310 tabBar->update();
280 } 311 }
281 else 312 else
282 { 313 {
283 tabBar->setCurrentTab( tab->id() ); 314 tabBar->setCurrentTab( tab->id() );
284 } 315 }
285 316
286 widgetStack->raiseWidget( tab->control() ); 317 widgetStack->raiseWidget( tab->control() );
287 318
288 emit currentChanged( tab->control() ); 319 emit currentChanged( tab->control() );
289 320
290 currentTab = tab; 321 currentTab = tab;
291} 322}
292 323
293void OTabWidget::setUpLayout() 324void OTabWidget::setUpLayout()
294{ 325{
295 tabBar->layoutTabs(); 326 tabBar->layoutTabs();
296 QSize t( tabBarStack->sizeHint() ); 327 QSize t( tabBarStack->sizeHint() );
297 if ( tabBarStyle == IconTab ) 328 if ( tabBarStyle == IconTab )
298 { 329 {
299 if ( t.width() > width() ) 330 if ( t.width() > width() )
300 t.setWidth( width() ); 331 t.setWidth( width() );
301 } 332 }
302 else 333 else
303 { 334 {
304 t.setWidth( width() ); 335 t.setWidth( width() );
305 } 336 }
306 int lw = widgetStack->lineWidth(); 337 int lw = widgetStack->lineWidth();
307 if ( tabBarPosition == Bottom ) 338 if ( tabBarPosition == Bottom )
308 { 339 {
309 tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); 340 tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() );
310 widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); 341 widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) );
311 } 342 }
312 else 343 else
313 { 344 {
314 tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); 345 tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() );
315 widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) ); 346 widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) );
316 } 347 }
317 348
318 if ( autoMask() ) 349 if ( autoMask() )
319 updateMask(); 350 updateMask();
320} 351}
321 352
322QSize OTabWidget::sizeHint() const 353QSize OTabWidget::sizeHint() const
323{ 354{
324 QSize s( widgetStack->sizeHint() ); 355 QSize s( widgetStack->sizeHint() );
325 QSize t( tabBarStack->sizeHint() ); 356 QSize t( tabBarStack->sizeHint() );
326 return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() ); 357 return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() );
327} 358}
328 359
329void OTabWidget::resizeEvent( QResizeEvent * ) 360void OTabWidget::resizeEvent( QResizeEvent * )
330{ 361{
331 setUpLayout(); 362 setUpLayout();
332} 363}
333 364
334int OTabWidget::getCurrentTab() { 365int OTabWidget::getCurrentTab()
366{
335 if ( currentTab ) 367 if ( currentTab )
336 { 368 {
337 return currentTab->id(); 369 return currentTab->id();
338 } 370 }
339 return -1; 371 return -1;
340} 372}
341 373