author | drw <drw> | 2002-07-31 00:20:25 (UTC) |
---|---|---|
committer | drw <drw> | 2002-07-31 00:20:25 (UTC) |
commit | 012abe9b9c667d24052a9f078030bfa7874b404e (patch) (unidiff) | |
tree | c781fc00f048010835d7f7a1346ac16c87c8479e /noncore/settings/sysinfo/otabwidget.cpp | |
parent | aedd5172ae67346f491dcd58e89e8e3f50247f2b (diff) | |
download | opie-012abe9b9c667d24052a9f078030bfa7874b404e.zip opie-012abe9b9c667d24052a9f078030bfa7874b404e.tar.gz opie-012abe9b9c667d24052a9f078030bfa7874b404e.tar.bz2 |
Added advanced config option to determine tabs to display, and otabwidget updates
Diffstat (limited to 'noncore/settings/sysinfo/otabwidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/sysinfo/otabwidget.cpp | 193 |
1 files changed, 179 insertions, 14 deletions
diff --git a/noncore/settings/sysinfo/otabwidget.cpp b/noncore/settings/sysinfo/otabwidget.cpp index 5d5b3e6..5154196 100644 --- a/noncore/settings/sysinfo/otabwidget.cpp +++ b/noncore/settings/sysinfo/otabwidget.cpp | |||
@@ -19,17 +19,70 @@ | |||
19 | 19 | ||
20 | #include "otabwidget.h" | 20 | #include "otabwidget.h" |
21 | 21 | ||
22 | #include <qpe/config.h> | ||
22 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
23 | 24 | ||
25 | #include <qcombobox.h> | ||
24 | #include <qlist.h> | 26 | #include <qlist.h> |
25 | #include <qtabbar.h> | 27 | #include <qtabbar.h> |
28 | #include <qwidgetstack.h> | ||
26 | 29 | ||
30 | OTabWidget::OTabWidget( QWidget *parent, const char *name = 0x0, | ||
31 | TabStyle s = Global, TabPosition p = Top ) | ||
32 | : QWidget( parent, name ) | ||
33 | { | ||
34 | if ( s == Global ) | ||
35 | { | ||
36 | Config config( "qpe" ); | ||
37 | config.setGroup( "Appearance" ); | ||
38 | tabBarStyle = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); | ||
39 | if ( tabBarStyle <= Global || tabBarStyle > IconList) | ||
40 | { | ||
41 | tabBarStyle = IconTab; | ||
42 | } | ||
43 | QString pos = config.readEntry( "TabPosition", "Top"); | ||
44 | if ( pos == "Top" ) | ||
45 | { | ||
46 | tabBarPosition = Top; | ||
47 | } | ||
48 | else | ||
49 | { | ||
50 | tabBarPosition = Bottom; | ||
51 | } | ||
52 | } | ||
53 | else | ||
54 | { | ||
55 | tabBarStyle = s; | ||
56 | tabBarPosition = p; | ||
57 | } | ||
58 | |||
59 | widgetStack = new QWidgetStack( this, "widgetstack" ); | ||
60 | widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); | ||
61 | widgetStack->setLineWidth( style().defaultFrameWidth() ); | ||
62 | |||
63 | tabBarStack = new QWidgetStack( this, "tabbarstack" ); | ||
64 | |||
65 | tabBar = new QTabBar( tabBarStack, "tabbar" ); | ||
66 | tabBarStack->addWidget( tabBar, 0 ); | ||
67 | connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) ); | ||
27 | 68 | ||
28 | OTabWidget::OTabWidget( QWidget *parent, const char *name ) | 69 | tabList = new QComboBox( false, tabBarStack, "tablist" ); |
29 | : QTabWidget( parent, name ) | 70 | tabBarStack->addWidget( tabList, 1 ); |
71 | connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) ); | ||
72 | |||
73 | if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) | ||
74 | { | ||
75 | tabBarStack->raiseWidget( tabBar ); | ||
76 | } | ||
77 | else if ( tabBarStyle == TextList || tabBarStyle == IconList ) | ||
30 | { | 78 | { |
31 | connect( this, SIGNAL( currentChanged( QWidget * ) ), | 79 | tabBarStack->raiseWidget( tabList ); |
32 | this, SLOT( tabChangedSlot( QWidget * ) ) ); | 80 | } |
81 | |||
82 | if ( tabBarPosition == Bottom ) | ||
83 | { | ||
84 | tabBar->setShape( QTabBar::RoundedBelow ); | ||
85 | } | ||
33 | } | 86 | } |
34 | 87 | ||
35 | OTabWidget::~OTabWidget() | 88 | OTabWidget::~OTabWidget() |
@@ -38,26 +91,85 @@ OTabWidget::~OTabWidget() | |||
38 | 91 | ||
39 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) | 92 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) |
40 | { | 93 | { |
41 | Tabs.append( TabInfo( child, icon, label ) ); | 94 | QPixmap iconset = loadSmooth( icon ); |
42 | QTabWidget::addTab( child, loadSmooth( icon ), QString::null ); | 95 | |
96 | // Add to tabBar | ||
97 | QTab * tab = new QTab(); | ||
98 | if ( tabBarStyle == IconTab ) | ||
99 | { | ||
100 | tab->label = QString::null; | ||
101 | } | ||
102 | else | ||
103 | { | ||
104 | tab->label = label; | ||
105 | } | ||
106 | if ( tabBarStyle == IconTab || tabBarStyle == IconList) | ||
107 | { | ||
108 | tab->iconset = new QIconSet( iconset ); | ||
109 | } | ||
110 | int tabid = tabBar->addTab( tab ); | ||
111 | tabBar->setCurrentTab( tab ); | ||
112 | |||
113 | // Add to tabList | ||
114 | |||
115 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) | ||
116 | { | ||
117 | tabList->insertItem( iconset, label, -1 ); | ||
118 | } | ||
119 | else | ||
120 | { | ||
121 | tabList->insertItem( label ); | ||
122 | } | ||
123 | tabList->setCurrentItem( tabList->count()-1 ); | ||
124 | |||
125 | // Add child to widget list | ||
126 | widgetStack->addWidget( child, tabid ); | ||
127 | widgetStack->raiseWidget( child ); | ||
128 | |||
129 | // Save tab information | ||
130 | tabs.append( TabInfo( tabid, child, icon, label ) ); | ||
131 | |||
132 | setUpLayout( FALSE ); | ||
133 | } | ||
134 | |||
135 | OTabWidget::TabStyle OTabWidget::tabStyle() const | ||
136 | { | ||
137 | return tabBarStyle; | ||
43 | } | 138 | } |
44 | 139 | ||
45 | void OTabWidget::tabChangedSlot( QWidget *child ) | 140 | void OTabWidget::setTabStyle( TabStyle s ) |
46 | { | 141 | { |
47 | TabInfoList::Iterator it; | 142 | tabBarStyle = s; |
143 | } | ||
144 | |||
145 | OTabWidget::TabPosition OTabWidget::tabPosition() const | ||
146 | { | ||
147 | return tabBarPosition; | ||
148 | } | ||
48 | 149 | ||
49 | if ( CurrentTab != 0x0 ) | 150 | void OTabWidget::setTabPosition( TabPosition p ) |
50 | { | 151 | { |
51 | changeTab( (*CurrentTab).control(), loadSmooth( (*CurrentTab).icon() ), QString::null ); | 152 | tabBarPosition = p; |
52 | } | 153 | } |
53 | 154 | ||
54 | for ( it = Tabs.begin(); it != Tabs.end(); ++it ) | 155 | void OTabWidget::slotTabBarSelected( int id ) |
55 | { | 156 | { |
56 | if ( (*it).control() == child ) | 157 | |
158 | TabInfoList::Iterator newtab = tabs.begin(); | ||
159 | while ( newtab != tabs.end() && (*newtab).id() != id ) | ||
160 | newtab++; | ||
161 | if ( (*newtab).id() == id ) | ||
57 | { | 162 | { |
58 | CurrentTab = it; | 163 | selectTab( newtab ); |
59 | changeTab( (*CurrentTab).control(), loadSmooth( (*CurrentTab).icon() ), (*CurrentTab).label() ); | 164 | } |
60 | } | 165 | } |
166 | |||
167 | void OTabWidget::slotTabListSelected( int index ) | ||
168 | { | ||
169 | TabInfoList::Iterator newtab = tabs.at( index ); | ||
170 | if ( newtab != tabs.end() ) | ||
171 | { | ||
172 | selectTab( newtab ); | ||
61 | } | 173 | } |
62 | } | 174 | } |
63 | 175 | ||
@@ -69,3 +181,56 @@ QPixmap OTabWidget::loadSmooth( const QString &name ) | |||
69 | return pixmap; | 181 | return pixmap; |
70 | } | 182 | } |
71 | 183 | ||
184 | void OTabWidget::selectTab( TabInfoList::Iterator tab ) | ||
185 | { | ||
186 | if ( tabBarStyle == IconTab ) | ||
187 | { | ||
188 | if ( currentTab != 0x0 ) | ||
189 | { | ||
190 | tabBar->tab( (*currentTab).id() )->label = QString::null; | ||
191 | } | ||
192 | tabBar->tab( (*tab).id() )->label = (*tab).label(); | ||
193 | currentTab = tab; | ||
194 | } | ||
195 | tabBar->layoutTabs(); | ||
196 | tabBar->update(); | ||
197 | |||
198 | widgetStack->raiseWidget( (*tab).control() ); | ||
199 | |||
200 | setUpLayout( FALSE ); | ||
201 | } | ||
202 | |||
203 | void OTabWidget::setUpLayout( bool onlyCheck ) | ||
204 | { | ||
205 | QSize t( tabBarStack->sizeHint() ); | ||
206 | if ( t.width() > width() ) | ||
207 | t.setWidth( width() ); | ||
208 | int lw = widgetStack->lineWidth(); | ||
209 | if ( tabBarPosition == Bottom ) | ||
210 | { | ||
211 | 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) ); | ||
213 | } | ||
214 | else | ||
215 | { // Top | ||
216 | 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)); | ||
218 | } | ||
219 | |||
220 | if ( !onlyCheck ) | ||
221 | update(); | ||
222 | if ( autoMask() ) | ||
223 | updateMask(); | ||
224 | } | ||
225 | |||
226 | QSize OTabWidget::sizeHint() const | ||
227 | { | ||
228 | QSize s( widgetStack->sizeHint() ); | ||
229 | QSize t( tabBarStack->sizeHint() ); | ||
230 | return QSize( QMAX( s.width(), t.width()), s.height() + t.height() ); | ||
231 | } | ||
232 | |||
233 | void OTabWidget::resizeEvent( QResizeEvent * ) | ||
234 | { | ||
235 | setUpLayout( FALSE ); | ||
236 | } | ||