author | drw <drw> | 2002-08-11 22:12:54 (UTC) |
---|---|---|
committer | drw <drw> | 2002-08-11 22:12:54 (UTC) |
commit | 496ba37b34ef5847865e0e387443d7481b1487f0 (patch) (side-by-side diff) | |
tree | 60ec019d7d4539818743b6babd71300e22b1cbeb | |
parent | e7af03e8257119824b53a63f581366b6e25f4ae5 (diff) | |
download | opie-496ba37b34ef5847865e0e387443d7481b1487f0.zip opie-496ba37b34ef5847865e0e387443d7481b1487f0.tar.gz opie-496ba37b34ef5847865e0e387443d7481b1487f0.tar.bz2 |
OTabWidget updates
-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 @@ #include "otabwidget.h" #include <qpe/config.h> #include <qpe/resource.h> #include <qcombobox.h> -#include <qlist.h> #include <qtabbar.h> #include <qwidgetstack.h> OTabWidget::OTabWidget( QWidget *parent, const char *name = 0x0, TabStyle s = Global, TabPosition p = Top ) : QWidget( parent, name ) @@ -80,12 +79,14 @@ OTabWidget::OTabWidget( QWidget *parent, const char *name = 0x0, } if ( tabBarPosition == Bottom ) { tabBar->setShape( QTabBar::RoundedBelow ); } + + currentTab= 0x0; } OTabWidget::~OTabWidget() { } @@ -105,34 +106,59 @@ void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &lab } if ( tabBarStyle == IconTab || tabBarStyle == IconList) { tab->iconset = new QIconSet( iconset ); } int tabid = tabBar->addTab( tab ); - tabBar->setCurrentTab( tab ); // Add to tabList - if ( tabBarStyle == IconTab || tabBarStyle == IconList ) { tabList->insertItem( iconset, label, -1 ); } else { tabList->insertItem( label ); } - tabList->setCurrentItem( tabList->count()-1 ); // Add child to widget list widgetStack->addWidget( child, tabid ); widgetStack->raiseWidget( child ); // Save tab information - tabs.append( TabInfo( tabid, child, icon, label ) ); + TabInfo *tabinfo = new TabInfo( tabid, child, icon, label ); + tabs.append( tabinfo ); + selectTab( tabinfo ); + +// setUpLayout(); +} - setUpLayout( FALSE ); +void OTabWidget::setCurrentTab( QWidget *childwidget ) +{ + TabInfo *newtab = tabs.first(); + while ( newtab && newtab->control() != childwidget ) + { + newtab = tabs.next(); + } + if ( newtab && newtab->control() == childwidget ) + { + selectTab( newtab ); + } +} + +void OTabWidget::setCurrentTab( QString tabname ) +{ + TabInfo *newtab = tabs.first(); + while ( newtab && newtab->label() != tabname ) + { + newtab = tabs.next(); + } + if ( newtab && newtab->label() == tabname ) + { + selectTab( newtab ); + } } OTabWidget::TabStyle OTabWidget::tabStyle() const { return tabBarStyle; } @@ -151,26 +177,27 @@ void OTabWidget::setTabPosition( TabPosition p ) { tabBarPosition = p; } void OTabWidget::slotTabBarSelected( int id ) { - - TabInfoList::Iterator newtab = tabs.begin(); - while ( newtab != tabs.end() && (*newtab).id() != id ) - newtab++; - if ( (*newtab).id() == id ) + TabInfo *newtab = tabs.first(); + while ( newtab && newtab->id() != id ) + { + newtab = tabs.next(); + } + if ( newtab && newtab->id() == id ) { selectTab( newtab ); } } void OTabWidget::slotTabListSelected( int index ) { - TabInfoList::Iterator newtab = tabs.at( index ); - if ( newtab != tabs.end() ) + TabInfo *newtab = tabs.at( index ); + if ( newtab ) { selectTab( newtab ); } } QPixmap OTabWidget::loadSmooth( const QString &name ) @@ -178,33 +205,34 @@ QPixmap OTabWidget::loadSmooth( const QString &name ) QImage image = Resource::loadImage( name ); QPixmap pixmap; pixmap.convertFromImage( image.smoothScale( 16, 16 ) ); return pixmap; } -void OTabWidget::selectTab( TabInfoList::Iterator tab ) +void OTabWidget::selectTab( TabInfo *tab ) { if ( tabBarStyle == IconTab ) { - if ( currentTab != 0x0 ) + if ( currentTab ) { - tabBar->tab( (*currentTab).id() )->label = QString::null; + tabBar->tab( currentTab->id() )->setText( QString::null ); + setUpLayout(); } - tabBar->tab( (*tab).id() )->label = (*tab).label(); + tabBar->tab( tab->id() )->setText( tab->label() ); currentTab = tab; } - tabBar->layoutTabs(); + tabBar->setCurrentTab( tab->id() ); + setUpLayout(); tabBar->update(); - widgetStack->raiseWidget( (*tab).control() ); - - setUpLayout( FALSE ); + widgetStack->raiseWidget( tab->control() ); } -void OTabWidget::setUpLayout( bool onlyCheck ) +void OTabWidget::setUpLayout() { + tabBar->layoutTabs(); QSize t( tabBarStack->sizeHint() ); if ( t.width() > width() ) t.setWidth( width() ); int lw = widgetStack->lineWidth(); if ( tabBarPosition == Bottom ) { @@ -214,14 +242,14 @@ void OTabWidget::setUpLayout( bool onlyCheck ) else { // Top tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX(0, lw-2)); } - if ( !onlyCheck ) - update(); +// if ( !onlyCheck ) +// update(); if ( autoMask() ) updateMask(); } QSize OTabWidget::sizeHint() const { @@ -229,8 +257,8 @@ QSize OTabWidget::sizeHint() const QSize t( tabBarStack->sizeHint() ); return QSize( QMAX( s.width(), t.width()), s.height() + t.height() ); } void OTabWidget::resizeEvent( QResizeEvent * ) { - setUpLayout( FALSE ); + setUpLayout(); } 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 @@ **********************************************************************/ #ifndef OTABWIDGET_H #define OTABWIDGET_H #include <qwidget.h> +#include <qlist.h> class QComboBox; class QPixmap; class QTabBar; class QWidgetStack; @@ -42,13 +43,13 @@ private: int i; QWidget *c; QString p; QString l; }; -typedef QValueList<TabInfo> TabInfoList; +typedef QList<TabInfo> TabInfoList; class OTabWidget : public QWidget { Q_OBJECT public: enum TabStyle { Global, TextTab, IconTab, TextList, IconList }; @@ -60,34 +61,36 @@ public: void setTabPosition( TabPosition ); OTabWidget( QWidget *, const char *, TabStyle, TabPosition ); ~OTabWidget(); void addTab( QWidget *, const QString &, const QString & ); + void setCurrentTab( QWidget * ); + void setCurrentTab( QString ); QSize sizeHint() const; protected: void resizeEvent( QResizeEvent * ); private: - TabInfoList tabs; - TabInfoList::Iterator currentTab; + TabInfoList tabs; + TabInfo *currentTab; TabStyle tabBarStyle; TabPosition tabBarPosition; QWidgetStack *tabBarStack; QTabBar *tabBar; QComboBox *tabList; QWidgetStack *widgetStack; QPixmap loadSmooth( const QString & ); - void selectTab( TabInfoList::Iterator ); - void setUpLayout( bool ); + void selectTab( TabInfo * ); + void setUpLayout(); private slots: void slotTabBarSelected( int ); void slotTabListSelected( int ); }; |