summaryrefslogtreecommitdiff
path: root/noncore/settings/sysinfo/otabwidget.cpp
Unidiff
Diffstat (limited to 'noncore/settings/sysinfo/otabwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/sysinfo/otabwidget.cpp264
1 files changed, 0 insertions, 264 deletions
diff --git a/noncore/settings/sysinfo/otabwidget.cpp b/noncore/settings/sysinfo/otabwidget.cpp
deleted file mode 100644
index 9fe6c4b..0000000
--- a/noncore/settings/sysinfo/otabwidget.cpp
+++ b/dev/null
@@ -1,264 +0,0 @@
1/**********************************************************************
2** OTabWidget
3**
4** Modified tab widget control
5**
6** Copyright (C) 2002, Dan Williams
7** williamsdr@acm.org
8** http://draknor.net
9**
10** This file may be distributed and/or modified under the terms of the
11** GNU General Public License version 2 as published by the Free Software
12** Foundation and appearing in the file LICENSE.GPL included in the
13** packaging of this file.
14**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17**
18**********************************************************************/
19
20#include "otabwidget.h"
21
22#include <qpe/config.h>
23#include <qpe/resource.h>
24
25#include <qcombobox.h>
26#include <qtabbar.h>
27#include <qwidgetstack.h>
28
29OTabWidget::OTabWidget( QWidget *parent, const char *name = 0x0,
30 TabStyle s = Global, TabPosition p = Top )
31 : QWidget( parent, name )
32{
33 if ( s == Global )
34 {
35 Config config( "qpe" );
36 config.setGroup( "Appearance" );
37 tabBarStyle = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab );
38 if ( tabBarStyle <= Global || tabBarStyle > IconList)
39 {
40 tabBarStyle = IconTab;
41 }
42 QString pos = config.readEntry( "TabPosition", "Top");
43 if ( pos == "Top" )
44 {
45 tabBarPosition = Top;
46 }
47 else
48 {
49 tabBarPosition = Bottom;
50 }
51 }
52 else
53 {
54 tabBarStyle = s;
55 tabBarPosition = p;
56 }
57
58 widgetStack = new QWidgetStack( this, "widgetstack" );
59 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
60 widgetStack->setLineWidth( style().defaultFrameWidth() );
61
62 tabBarStack = new QWidgetStack( this, "tabbarstack" );
63
64 tabBar = new QTabBar( tabBarStack, "tabbar" );
65 tabBarStack->addWidget( tabBar, 0 );
66 connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) );
67
68 tabList = new QComboBox( false, tabBarStack, "tablist" );
69 tabBarStack->addWidget( tabList, 1 );
70 connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) );
71
72 if ( tabBarStyle == TextTab || tabBarStyle == IconTab )
73 {
74 tabBarStack->raiseWidget( tabBar );
75 }
76 else if ( tabBarStyle == TextList || tabBarStyle == IconList )
77 {
78 tabBarStack->raiseWidget( tabList );
79 }
80
81 if ( tabBarPosition == Bottom )
82 {
83 tabBar->setShape( QTabBar::RoundedBelow );
84 }
85
86 currentTab= 0x0;
87}
88
89OTabWidget::~OTabWidget()
90{
91}
92
93void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
94{
95 QPixmap iconset = loadSmooth( icon );
96
97 // Add to tabBar
98 QTab * tab = new QTab();
99 if ( tabBarStyle == IconTab )
100 {
101 tab->label = QString::null;
102 }
103 else
104 {
105 tab->label = label;
106 }
107 if ( tabBarStyle == IconTab || tabBarStyle == IconList)
108 {
109 tab->iconset = new QIconSet( iconset );
110 }
111 int tabid = tabBar->addTab( tab );
112
113 // Add to tabList
114 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
115 {
116 tabList->insertItem( iconset, label, -1 );
117 }
118 else
119 {
120 tabList->insertItem( label );
121 }
122
123 // Add child to widget list
124 widgetStack->addWidget( child, tabid );
125 widgetStack->raiseWidget( child );
126
127 // Save tab information
128 TabInfo *tabinfo = new TabInfo( tabid, child, icon, label );
129 tabs.append( tabinfo );
130 selectTab( tabinfo );
131
132// setUpLayout();
133}
134
135void OTabWidget::setCurrentTab( QWidget *childwidget )
136{
137 TabInfo *newtab = tabs.first();
138 while ( newtab && newtab->control() != childwidget )
139 {
140 newtab = tabs.next();
141 }
142 if ( newtab && newtab->control() == childwidget )
143 {
144 selectTab( newtab );
145 }
146}
147
148void OTabWidget::setCurrentTab( QString tabname )
149{
150 TabInfo *newtab = tabs.first();
151 while ( newtab && newtab->label() != tabname )
152 {
153 newtab = tabs.next();
154 }
155 if ( newtab && newtab->label() == tabname )
156 {
157 selectTab( newtab );
158 }
159}
160
161OTabWidget::TabStyle OTabWidget::tabStyle() const
162{
163 return tabBarStyle;
164}
165
166void OTabWidget::setTabStyle( TabStyle s )
167{
168 tabBarStyle = s;
169}
170
171OTabWidget::TabPosition OTabWidget::tabPosition() const
172{
173 return tabBarPosition;
174}
175
176void OTabWidget::setTabPosition( TabPosition p )
177{
178 tabBarPosition = p;
179}
180
181void OTabWidget::slotTabBarSelected( int id )
182{
183 TabInfo *newtab = tabs.first();
184 while ( newtab && newtab->id() != id )
185 {
186 newtab = tabs.next();
187 }
188 if ( newtab && newtab->id() == id )
189 {
190 selectTab( newtab );
191 }
192}
193
194void OTabWidget::slotTabListSelected( int index )
195{
196 TabInfo *newtab = tabs.at( index );
197 if ( newtab )
198 {
199 selectTab( newtab );
200 }
201}
202
203QPixmap OTabWidget::loadSmooth( const QString &name )
204{
205 QImage image = Resource::loadImage( name );
206 QPixmap pixmap;
207 pixmap.convertFromImage( image.smoothScale( 16, 16 ) );
208 return pixmap;
209}
210
211void OTabWidget::selectTab( TabInfo *tab )
212{
213 if ( tabBarStyle == IconTab )
214 {
215 if ( currentTab )
216 {
217 tabBar->tab( currentTab->id() )->setText( QString::null );
218 setUpLayout();
219 }
220 tabBar->tab( tab->id() )->setText( tab->label() );
221 currentTab = tab;
222 }
223 tabBar->setCurrentTab( tab->id() );
224 setUpLayout();
225 tabBar->update();
226
227 widgetStack->raiseWidget( tab->control() );
228}
229
230void OTabWidget::setUpLayout()
231{
232 tabBar->layoutTabs();
233 QSize t( tabBarStack->sizeHint() );
234 if ( t.width() > width() )
235 t.setWidth( width() );
236 int lw = widgetStack->lineWidth();
237 if ( tabBarPosition == Bottom )
238 {
239 tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() );
240 widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) );
241 }
242 else
243 { // Top
244 tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() );
245 widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX(0, lw-2));
246 }
247
248// if ( !onlyCheck )
249// update();
250 if ( autoMask() )
251 updateMask();
252}
253
254QSize OTabWidget::sizeHint() const
255{
256 QSize s( widgetStack->sizeHint() );
257 QSize t( tabBarStack->sizeHint() );
258 return QSize( QMAX( s.width(), t.width()), s.height() + t.height() );
259}
260
261void OTabWidget::resizeEvent( QResizeEvent * )
262{
263 setUpLayout();
264}