-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 | |||
@@ -20,13 +20,12 @@ | |||
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 | ||
30 | OTabWidget::OTabWidget( QWidget *parent, const char *name = 0x0, | 29 | OTabWidget::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 ) |
@@ -80,12 +79,14 @@ OTabWidget::OTabWidget( QWidget *parent, const char *name = 0x0, | |||
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 | ||
88 | OTabWidget::~OTabWidget() | 89 | OTabWidget::~OTabWidget() |
89 | { | 90 | { |
90 | } | 91 | } |
91 | 92 | ||
@@ -105,34 +106,59 @@ void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &lab | |||
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 ); | 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 |
136 | { | 162 | { |
137 | return tabBarStyle; | 163 | return tabBarStyle; |
138 | } | 164 | } |
@@ -151,26 +177,27 @@ void OTabWidget::setTabPosition( TabPosition p ) | |||
151 | { | 177 | { |
152 | tabBarPosition = p; | 178 | tabBarPosition = p; |
153 | } | 179 | } |
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 | } |
165 | } | 192 | } |
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 | } |
174 | } | 201 | } |
175 | 202 | ||
176 | QPixmap OTabWidget::loadSmooth( const QString &name ) | 203 | QPixmap OTabWidget::loadSmooth( const QString &name ) |
@@ -178,33 +205,34 @@ QPixmap OTabWidget::loadSmooth( const QString &name ) | |||
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 | ||
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() ); |
208 | int lw = widgetStack->lineWidth(); | 236 | int lw = widgetStack->lineWidth(); |
209 | if ( tabBarPosition == Bottom ) | 237 | if ( tabBarPosition == Bottom ) |
210 | { | 238 | { |
@@ -214,14 +242,14 @@ void OTabWidget::setUpLayout( bool onlyCheck ) | |||
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 | ||
226 | QSize OTabWidget::sizeHint() const | 254 | QSize OTabWidget::sizeHint() const |
227 | { | 255 | { |
@@ -229,8 +257,8 @@ QSize OTabWidget::sizeHint() const | |||
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 | ||
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 | |||
@@ -18,12 +18,13 @@ | |||
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 | ||
25 | class QComboBox; | 26 | class QComboBox; |
26 | class QPixmap; | 27 | class QPixmap; |
27 | class QTabBar; | 28 | class QTabBar; |
28 | class QWidgetStack; | 29 | class QWidgetStack; |
29 | 30 | ||
@@ -42,13 +43,13 @@ private: | |||
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 | ||
48 | typedef QValueList<TabInfo> TabInfoList; | 49 | typedef QList<TabInfo> TabInfoList; |
49 | 50 | ||
50 | class OTabWidget : public QWidget | 51 | class OTabWidget : public QWidget |
51 | { | 52 | { |
52 | Q_OBJECT | 53 | Q_OBJECT |
53 | public: | 54 | public: |
54 | enum TabStyle { Global, TextTab, IconTab, TextList, IconList }; | 55 | enum TabStyle { Global, TextTab, IconTab, TextList, IconList }; |
@@ -60,34 +61,36 @@ public: | |||
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 | ||
69 | protected: | 72 | 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; |
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 | ||
89 | private slots: | 92 | private slots: |
90 | void slotTabBarSelected( int ); | 93 | void slotTabBarSelected( int ); |
91 | void slotTabListSelected( int ); | 94 | void slotTabListSelected( int ); |
92 | }; | 95 | }; |
93 | 96 | ||