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