author | drw <drw> | 2002-12-05 23:28:33 (UTC) |
---|---|---|
committer | drw <drw> | 2002-12-05 23:28:33 (UTC) |
commit | 0e19980617d101f69d0540d62b89fe1894cfe0f2 (patch) (unidiff) | |
tree | b5ecf3cdc140a08e69a98202b60e84a17e3858bf | |
parent | 8a1c4b4b84d8a8de87bb6adb4df3f09961854633 (diff) | |
download | opie-0e19980617d101f69d0540d62b89fe1894cfe0f2.zip opie-0e19980617d101f69d0540d62b89fe1894cfe0f2.tar.gz opie-0e19980617d101f69d0540d62b89fe1894cfe0f2.tar.bz2 |
Allow changing styles/position at run-time (i.e. make setTabStyle/setTabPosition work).
-rw-r--r-- | libopie/otabwidget.cpp | 90 |
1 files changed, 61 insertions, 29 deletions
diff --git a/libopie/otabwidget.cpp b/libopie/otabwidget.cpp index 1fee919..bee3f35 100644 --- a/libopie/otabwidget.cpp +++ b/libopie/otabwidget.cpp | |||
@@ -40,66 +40,49 @@ | |||
40 | 40 | ||
41 | OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p ) | 41 | OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p ) |
42 | : QWidget( parent, name ) | 42 | : QWidget( parent, name ) |
43 | { | 43 | { |
44 | if ( s == Global ) | 44 | if ( s == Global ) |
45 | { | 45 | { |
46 | Config config( "qpe" ); | 46 | Config config( "qpe" ); |
47 | config.setGroup( "Appearance" ); | 47 | config.setGroup( "Appearance" ); |
48 | tabBarStyle = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); | 48 | s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); |
49 | if ( tabBarStyle <= Global || tabBarStyle > IconList) | 49 | if ( s <= Global || s > IconList) |
50 | { | 50 | { |
51 | tabBarStyle = IconTab; | 51 | s = IconTab; |
52 | } | 52 | } |
53 | QString pos = config.readEntry( "TabPosition", "Top"); | 53 | QString pos = config.readEntry( "TabPosition", "Top"); |
54 | if ( pos == "Bottom" ) | 54 | if ( pos == "Bottom" ) |
55 | { | 55 | { |
56 | tabBarPosition = Bottom; | 56 | p = Bottom; |
57 | } | 57 | } |
58 | else | 58 | else |
59 | { | 59 | { |
60 | tabBarPosition = Top; | 60 | p = Top; |
61 | } | 61 | } |
62 | } | 62 | } |
63 | else | ||
64 | { | ||
65 | tabBarStyle = s; | ||
66 | tabBarPosition = p; | ||
67 | } | ||
68 | 63 | ||
69 | widgetStack = new QWidgetStack( this, "widgetstack" ); | 64 | widgetStack = new QWidgetStack( this, "widgetstack" ); |
70 | widgetStack->setFrameStyle( QFrame::NoFrame ); | 65 | widgetStack->setFrameStyle( QFrame::NoFrame ); |
71 | widgetStack->setLineWidth( style().defaultFrameWidth() ); | 66 | widgetStack->setLineWidth( style().defaultFrameWidth() ); |
72 | 67 | ||
73 | tabBarStack = new QWidgetStack( this, "tabbarstack" ); | 68 | tabBarStack = new QWidgetStack( this, "tabbarstack" ); |
74 | 69 | ||
75 | tabBar = new OTabBar( tabBarStack, "tabbar" ); | 70 | tabBar = new OTabBar( tabBarStack, "tabbar" ); |
76 | tabBarStack->addWidget( tabBar, 0 ); | 71 | tabBarStack->addWidget( tabBar, 0 ); |
77 | connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) ); | 72 | connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) ); |
78 | 73 | ||
79 | tabList = new QComboBox( false, tabBarStack, "tablist" ); | 74 | tabList = new QComboBox( false, tabBarStack, "tablist" ); |
80 | tabBarStack->addWidget( tabList, 1 ); | 75 | tabBarStack->addWidget( tabList, 1 ); |
81 | connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) ); | 76 | connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) ); |
82 | 77 | ||
83 | if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) | 78 | setTabStyle( s ); |
84 | { | 79 | setTabPosition( p ); |
85 | tabBarStack->raiseWidget( tabBar ); | ||
86 | } | ||
87 | else if ( tabBarStyle == TextList || tabBarStyle == IconList ) | ||
88 | { | ||
89 | tabBarStack->raiseWidget( tabList ); | ||
90 | } | ||
91 | |||
92 | if ( tabBarPosition == Bottom ) | ||
93 | { | ||
94 | tabBar->setShape( QTabBar::RoundedBelow ); | ||
95 | } | ||
96 | 80 | ||
97 | //tabs.setAutoDelete( TRUE ); | ||
98 | currentTab= 0x0; | 81 | currentTab= 0x0; |
99 | } | 82 | } |
100 | 83 | ||
101 | OTabWidget::~OTabWidget() | 84 | OTabWidget::~OTabWidget() |
102 | { | 85 | { |
103 | } | 86 | } |
104 | 87 | ||
105 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) | 88 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) |
@@ -217,26 +200,74 @@ void OTabWidget::setCurrentTab(int tabindex) { | |||
217 | OTabWidget::TabStyle OTabWidget::tabStyle() const | 200 | OTabWidget::TabStyle OTabWidget::tabStyle() const |
218 | { | 201 | { |
219 | return tabBarStyle; | 202 | return tabBarStyle; |
220 | } | 203 | } |
221 | 204 | ||
222 | void OTabWidget::setTabStyle( TabStyle s ) | 205 | void OTabWidget::setTabStyle( TabStyle s ) |
223 | { | 206 | { |
224 | tabBarStyle = s; | 207 | tabBarStyle = s; |
208 | if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) | ||
209 | { | ||
210 | QTab *currtab; | ||
211 | for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) | ||
212 | { | ||
213 | currtab = tabBar->tab( tabinfo->id() ); | ||
214 | if ( tabBarStyle == IconTab ) | ||
215 | { | ||
216 | currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); | ||
217 | if ( tabinfo == currentTab ) | ||
218 | currtab->setText( tabinfo->label() ); | ||
219 | else | ||
220 | currtab->setText( QString::null ); | ||
221 | } | ||
222 | else | ||
223 | { | ||
224 | currtab->iconset = 0x0; | ||
225 | currtab->setText( tabinfo->label() ); | ||
226 | } | ||
227 | } | ||
228 | tabBarStack->raiseWidget( tabBar ); | ||
229 | } | ||
230 | else if ( tabBarStyle == TextList || tabBarStyle == IconList ) | ||
231 | { | ||
232 | tabList->clear(); | ||
233 | for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) | ||
234 | { | ||
235 | if ( tabBarStyle == IconList ) | ||
236 | { | ||
237 | tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); | ||
238 | } | ||
239 | else | ||
240 | { | ||
241 | tabList->insertItem( tabinfo->label() ); | ||
242 | } | ||
243 | } | ||
244 | tabBarStack->raiseWidget( tabList ); | ||
245 | } | ||
246 | setUpLayout(); | ||
225 | } | 247 | } |
226 | 248 | ||
227 | OTabWidget::TabPosition OTabWidget::tabPosition() const | 249 | OTabWidget::TabPosition OTabWidget::tabPosition() const |
228 | { | 250 | { |
229 | return tabBarPosition; | 251 | return tabBarPosition; |
230 | } | 252 | } |
231 | 253 | ||
232 | void OTabWidget::setTabPosition( TabPosition p ) | 254 | void OTabWidget::setTabPosition( TabPosition p ) |
233 | { | 255 | { |
234 | tabBarPosition = p; | 256 | tabBarPosition = p; |
257 | if ( tabBarPosition == Top ) | ||
258 | { | ||
259 | tabBar->setShape( QTabBar::RoundedAbove ); | ||
260 | } | ||
261 | else | ||
262 | { | ||
263 | tabBar->setShape( QTabBar::RoundedBelow ); | ||
264 | } | ||
265 | setUpLayout(); | ||
235 | } | 266 | } |
236 | 267 | ||
237 | void OTabWidget::slotTabBarSelected( int id ) | 268 | void OTabWidget::slotTabBarSelected( int id ) |
238 | { | 269 | { |
239 | OTabInfo *newtab = tabs.first(); | 270 | OTabInfo *newtab = tabs.first(); |
240 | while ( newtab && newtab->id() != id ) | 271 | while ( newtab && newtab->id() != id ) |
241 | { | 272 | { |
242 | newtab = tabs.next(); | 273 | newtab = tabs.next(); |
@@ -265,17 +296,17 @@ QPixmap OTabWidget::loadSmooth( const QString &name ) | |||
265 | } | 296 | } |
266 | 297 | ||
267 | void OTabWidget::selectTab( OTabInfo *tab ) | 298 | void OTabWidget::selectTab( OTabInfo *tab ) |
268 | { | 299 | { |
269 | if ( tabBarStyle == IconTab ) | 300 | if ( tabBarStyle == IconTab ) |
270 | { | 301 | { |
271 | if ( currentTab ) | 302 | if ( currentTab ) |
272 | { | 303 | { |
273 | tabBar->tab( currentTab->id() )->setText( "" ); | 304 | tabBar->tab( currentTab->id() )->setText( QString::null ); |
274 | setUpLayout(); | 305 | setUpLayout(); |
275 | } | 306 | } |
276 | tabBar->tab( tab->id() )->setText( tab->label() ); | 307 | tabBar->tab( tab->id() )->setText( tab->label() ); |
277 | tabBar->setCurrentTab( tab->id() ); | 308 | tabBar->setCurrentTab( tab->id() ); |
278 | setUpLayout(); | 309 | setUpLayout(); |
279 | tabBar->update(); | 310 | tabBar->update(); |
280 | } | 311 | } |
281 | else | 312 | else |
@@ -326,16 +357,17 @@ QSize OTabWidget::sizeHint() const | |||
326 | return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() ); | 357 | return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() ); |
327 | } | 358 | } |
328 | 359 | ||
329 | void OTabWidget::resizeEvent( QResizeEvent * ) | 360 | void OTabWidget::resizeEvent( QResizeEvent * ) |
330 | { | 361 | { |
331 | setUpLayout(); | 362 | setUpLayout(); |
332 | } | 363 | } |
333 | 364 | ||
334 | int OTabWidget::getCurrentTab() { | 365 | int OTabWidget::getCurrentTab() |
366 | { | ||
335 | if ( currentTab ) | 367 | if ( currentTab ) |
336 | { | 368 | { |
337 | return currentTab->id(); | 369 | return currentTab->id(); |
338 | } | 370 | } |
339 | return -1; | 371 | return -1; |
340 | } | 372 | } |
341 | 373 | ||