summaryrefslogtreecommitdiff
path: root/libopie/otabwidget.cpp
authormickeyl <mickeyl>2004-11-16 19:14:18 (UTC)
committer mickeyl <mickeyl>2004-11-16 19:14:18 (UTC)
commitea3945a9bd8f9830f70b1efa133f9df13b19362f (patch) (unidiff)
treef2ea22cc50e9aa8aa73ee7dea148f41c563c9666 /libopie/otabwidget.cpp
parent1c6f490e8541626f68422e0a3a7c7281d7f5b7d3 (diff)
downloadopie-ea3945a9bd8f9830f70b1efa133f9df13b19362f.zip
opie-ea3945a9bd8f9830f70b1efa133f9df13b19362f.tar.gz
opie-ea3945a9bd8f9830f70b1efa133f9df13b19362f.tar.bz2
libopie1 goes into unsupported
Diffstat (limited to 'libopie/otabwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/otabwidget.cpp419
1 files changed, 0 insertions, 419 deletions
diff --git a/libopie/otabwidget.cpp b/libopie/otabwidget.cpp
deleted file mode 100644
index 52190b2..0000000
--- a/libopie/otabwidget.cpp
+++ b/dev/null
@@ -1,419 +0,0 @@
1/*
2                This file is part of the Opie Project
3
4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5 =.
6 .=l.
7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details.
22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA.
29
30*/
31
32#include "otabwidget.h"
33
34#include <qpe/applnk.h>
35#include <qpe/config.h>
36#include <qpe/resource.h>
37#include <opie/otabbar.h>
38
39#include <qcombobox.h>
40#include <qwidgetstack.h>
41
42OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p )
43 : QWidget( parent, name )
44{
45 if ( s == Global )
46 {
47 Config config( "qpe" );
48 config.setGroup( "Appearance" );
49 s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab );
50 if ( s <= Global || s > IconList)
51 {
52 s = IconTab;
53 }
54 QString pos = config.readEntry( "TabPosition", "Top");
55 if ( pos == "Bottom" )
56 {
57 p = Bottom;
58 }
59 else
60 {
61 p = Top;
62 }
63 }
64
65 widgetStack = new QWidgetStack( this, "widgetstack" );
66 widgetStack->setFrameStyle( QFrame::NoFrame );
67 widgetStack->setLineWidth( style().defaultFrameWidth() );
68
69 tabBarStack = new QWidgetStack( this, "tabbarstack" );
70
71 tabBar = new OTabBar( tabBarStack, "tabbar" );
72 tabBarStack->addWidget( tabBar, 0 );
73 connect( tabBar, SIGNAL( selected(int) ), this, SLOT( slotTabBarSelected(int) ) );
74
75 tabList = new QComboBox( false, tabBarStack, "tablist" );
76 tabBarStack->addWidget( tabList, 1 );
77 connect( tabList, SIGNAL( activated(int) ), this, SLOT( slotTabListSelected(int) ) );
78
79 tabBarPosition = p;
80 setTabStyle( s );
81 setTabPosition( p );
82
83 currTab= 0x0;
84}
85
86OTabWidget::~OTabWidget()
87{
88}
89
90void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
91{
92 QPixmap iconset = loadSmooth( icon );
93
94 QTab *tab = new QTab();
95 if ( tabBarStyle == IconTab )
96 {
97 tab->label = QString::null;
98 }
99 else
100 {
101 tab->label = label;
102 }
103 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
104 {
105 tab->iconset = new QIconSet( iconset );
106 }
107 int tabid = tabBar->addTab( tab );
108
109 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
110 {
111 tabList->insertItem( iconset, label, -1 );
112 }
113 else
114 {
115 tabList->insertItem( label );
116 }
117
118 widgetStack->addWidget( child, tabid );
119 widgetStack->raiseWidget( child );
120 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
121
122 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label );
123 tabs.append( tabinfo );
124 selectTab( tabinfo );
125}
126
127void OTabWidget::removePage( QWidget *childwidget )
128{
129 if ( childwidget )
130 {
131 OTabInfo *tab = tabs.first();
132 while ( tab && tab->control() != childwidget )
133 {
134 tab = tabs.next();
135 }
136 if ( tab && tab->control() == childwidget )
137 {
138 tabBar->setTabEnabled( tab->id(), FALSE );
139 tabBar->removeTab( tabBar->tab( tab->id() ) );
140 int i = 0;
141 while ( i < tabList->count() && tabList->text( i ) != tab->label() )
142 {
143 i++;
144 }
145 if ( tabList->text( i ) == tab->label() )
146 {
147 tabList->removeItem( i );
148 }
149 widgetStack->removeWidget( childwidget );
150 tabs.remove( tab );
151 delete tab;
152 currTab = tabs.current();
153 if ( !currTab )
154 {
155 widgetStack->setFrameStyle( QFrame::NoFrame );
156 }
157
158 setUpLayout();
159 }
160 }
161}
162
163void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label)
164{
165 OTabInfo *currtab = tabs.first();
166 while ( currtab && currtab->control() != widget )
167 {
168 currtab = tabs.next();
169 }
170 if ( currtab && currtab->control() == widget )
171 {
172 QTab *tab = tabBar->tab( currtab->id() );
173 QPixmap icon( loadSmooth( iconset ) );
174 tab->setText( label );
175 if ( tabBarStyle == IconTab )
176 tab->setIconSet( icon );
177 int i = 0;
178 while ( i < tabList->count() && tabList->text( i ) != currtab->label() )
179 {
180 i++;
181 }
182 if ( i < tabList->count() && tabList->text( i ) == currtab->label() )
183 {
184 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
185 {
186 tabList->changeItem( icon, label, i );
187 }
188 else
189 {
190 tabList->changeItem( label, i );
191 }
192 }
193 currtab->setLabel( label );
194 currtab->setIcon( iconset );
195 }
196 setUpLayout();
197}
198
199void OTabWidget::setCurrentTab( QWidget *childwidget )
200{
201 OTabInfo *currtab = tabs.first();
202 while ( currtab && currtab->control() != childwidget )
203 {
204 currtab = tabs.next();
205 }
206 if ( currtab && currtab->control() == childwidget )
207 {
208 selectTab( currtab );
209 }
210}
211
212void OTabWidget::setCurrentTab( const QString &tabname )
213{
214 OTabInfo *newtab = tabs.first();
215 while ( newtab && newtab->label() != tabname )
216 {
217 newtab = tabs.next();
218 }
219 if ( newtab && newtab->label() == tabname )
220 {
221 selectTab( newtab );
222 }
223}
224
225void OTabWidget::setCurrentTab(int tabindex) {
226 OTabInfo *newtab = tabs.first();
227 while ( newtab && newtab->id() != tabindex )
228 {
229 newtab = tabs.next();
230 }
231 if ( newtab && newtab->id() == tabindex )
232 {
233 selectTab( newtab );
234 }
235}
236
237
238OTabWidget::TabStyle OTabWidget::tabStyle() const
239{
240 return tabBarStyle;
241}
242
243void OTabWidget::setTabStyle( TabStyle s )
244{
245 tabBarStyle = s;
246 if ( tabBarStyle == TextTab || tabBarStyle == IconTab )
247 {
248 QTab *currtab;
249 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
250 {
251 currtab = tabBar->tab( tabinfo->id() );
252 if ( tabBarStyle == IconTab )
253 {
254 currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) );
255 if ( tabinfo == currTab )
256 currtab->setText( tabinfo->label() );
257 else
258 currtab->setText( QString::null );
259 }
260 else
261 {
262 currtab->iconset = 0x0;
263 currtab->setText( tabinfo->label() );
264 }
265 }
266 tabBarStack->raiseWidget( tabBar );
267 }
268 else if ( tabBarStyle == TextList || tabBarStyle == IconList )
269 {
270 tabList->clear();
271 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
272 {
273 if ( tabBarStyle == IconList )
274 {
275 tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() );
276 }
277 else
278 {
279 tabList->insertItem( tabinfo->label() );
280 }
281 }
282 tabBarStack->raiseWidget( tabList );
283 }
284 setUpLayout();
285}
286
287OTabWidget::TabPosition OTabWidget::tabPosition() const
288{
289 return tabBarPosition;
290}
291
292void OTabWidget::setTabPosition( TabPosition p )
293{
294 tabBarPosition = p;
295 if ( tabBarPosition == Top )
296 {
297 tabBar->setShape( QTabBar::RoundedAbove );
298 }
299 else
300 {
301 tabBar->setShape( QTabBar::RoundedBelow );
302 }
303 setUpLayout();
304}
305
306void OTabWidget::slotTabBarSelected( int id )
307{
308 OTabInfo *newtab = tabs.first();
309 while ( newtab && newtab->id() != id )
310 {
311 newtab = tabs.next();
312 }
313 if ( newtab && newtab->id() == id )
314 {
315 selectTab( newtab );
316 }
317}
318
319void OTabWidget::slotTabListSelected( int index )
320{
321 OTabInfo *newtab = tabs.at( index );
322 if ( newtab )
323 {
324 selectTab( newtab );
325 }
326}
327
328QPixmap OTabWidget::loadSmooth( const QString &name )
329{
330 QPixmap p;
331 p.convertFromImage( Resource::loadImage( name ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) );
332 return p;
333}
334
335void OTabWidget::selectTab( OTabInfo *tab )
336{
337 if ( tabBarStyle == IconTab )
338 {
339 if ( currTab )
340 {
341 tabBar->tab( currTab->id() )->setText( QString::null );
342 setUpLayout();
343 }
344 tabBar->tab( tab->id() )->setText( tab->label() );
345 tabBar->setCurrentTab( tab->id() );
346 setUpLayout();
347 tabBar->update();
348 }
349 else
350 {
351 tabBar->setCurrentTab( tab->id() );
352 }
353
354 widgetStack->raiseWidget( tab->control() );
355
356 emit currentChanged( tab->control() );
357
358 currTab = tab;
359}
360
361void OTabWidget::setUpLayout()
362{
363 tabBar->layoutTabs();
364 QSize t( tabBarStack->sizeHint() );
365 if ( tabBarStyle == IconTab )
366 {
367 if ( t.width() > width() )
368 t.setWidth( width() );
369 }
370 else
371 {
372 t.setWidth( width() );
373 }
374 int lw = widgetStack->lineWidth();
375 if ( tabBarPosition == Bottom )
376 {
377 tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() );
378 widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) );
379 }
380 else
381 {
382 tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() );
383 widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) );
384 }
385
386 if ( autoMask() )
387 updateMask();
388}
389
390QSize OTabWidget::sizeHint() const
391{
392 QSize s( widgetStack->sizeHint() );
393 QSize t( tabBarStack->sizeHint() );
394 return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() );
395}
396
397void OTabWidget::resizeEvent( QResizeEvent * )
398{
399 setUpLayout();
400}
401
402int OTabWidget::currentTab()
403{
404 if ( currTab )
405 {
406 return currTab->id();
407 }
408 return -1;
409}
410
411QWidget* OTabWidget::currentWidget()const
412{
413 if ( currTab )
414 {
415 return currTab->control();
416 }
417
418 return 0;
419}