-rw-r--r-- | noncore/settings/sysinfo/otabwidget.cpp | 78 | ||||
-rw-r--r-- | noncore/settings/sysinfo/otabwidget.h | 13 |
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 | |||
@@ -23,7 +23,6 @@ | |||
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 | ||
@@ -83,6 +82,8 @@ OTabWidget::OTabWidget( QWidget *parent, const char *name = 0x0, | |||
83 | { | 82 | { |
84 | tabBar->setShape( QTabBar::RoundedBelow ); | 83 | tabBar->setShape( QTabBar::RoundedBelow ); |
85 | } | 84 | } |
85 | |||
86 | currentTab= 0x0; | ||
86 | } | 87 | } |
87 | 88 | ||
88 | OTabWidget::~OTabWidget() | 89 | OTabWidget::~OTabWidget() |
@@ -108,10 +109,8 @@ void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &lab | |||
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 ); |
@@ -120,16 +119,43 @@ void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &lab | |||
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 ); | 135 | void 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 | |||
148 | void 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 | ||
135 | OTabWidget::TabStyle OTabWidget::tabStyle() const | 161 | OTabWidget::TabStyle OTabWidget::tabStyle() const |
@@ -154,11 +180,12 @@ void OTabWidget::setTabPosition( TabPosition p ) | |||
154 | 180 | ||
155 | void OTabWidget::slotTabBarSelected( int id ) | 181 | void 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 | } |
@@ -166,8 +193,8 @@ void OTabWidget::slotTabBarSelected( int id ) | |||
166 | 193 | ||
167 | void OTabWidget::slotTabListSelected( int index ) | 194 | void 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 | } |
@@ -181,27 +208,28 @@ QPixmap OTabWidget::loadSmooth( const QString &name ) | |||
181 | return pixmap; | 208 | return pixmap; |
182 | } | 209 | } |
183 | 210 | ||
184 | void OTabWidget::selectTab( TabInfoList::Iterator tab ) | 211 | void 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 | ||
203 | void OTabWidget::setUpLayout( bool onlyCheck ) | 230 | void 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() ); |
@@ -217,8 +245,8 @@ void OTabWidget::setUpLayout( bool onlyCheck ) | |||
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 | } |
@@ -232,5 +260,5 @@ QSize OTabWidget::sizeHint() const | |||
232 | 260 | ||
233 | void OTabWidget::resizeEvent( QResizeEvent * ) | 261 | void 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 | |||
@@ -21,6 +21,7 @@ | |||
21 | #define OTABWIDGET_H | 21 | #define OTABWIDGET_H |
22 | 22 | ||
23 | #include <qwidget.h> | 23 | #include <qwidget.h> |
24 | #include <qlist.h> | ||
24 | 25 | ||
25 | class QComboBox; | 26 | class QComboBox; |
26 | class QPixmap; | 27 | class QPixmap; |
@@ -45,7 +46,7 @@ private: | |||
45 | QString l; | 46 | QString l; |
46 | }; | 47 | }; |
47 | 48 | ||
48 | typedef QValueList<TabInfo> TabInfoList; | 49 | typedef QList<TabInfo> TabInfoList; |
49 | 50 | ||
50 | class OTabWidget : public QWidget | 51 | class OTabWidget : public QWidget |
51 | { | 52 | { |
@@ -63,6 +64,8 @@ public: | |||
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 | ||
@@ -70,8 +73,8 @@ protected: | |||
70 | void resizeEvent( QResizeEvent * ); | 73 | void resizeEvent( QResizeEvent * ); |
71 | 74 | ||
72 | private: | 75 | private: |
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; |
@@ -83,8 +86,8 @@ private: | |||
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 | ||
89 | private slots: | 92 | private slots: |
90 | void slotTabBarSelected( int ); | 93 | void slotTabBarSelected( int ); |