author | drw <drw> | 2002-07-31 00:20:25 (UTC) |
---|---|---|
committer | drw <drw> | 2002-07-31 00:20:25 (UTC) |
commit | 012abe9b9c667d24052a9f078030bfa7874b404e (patch) (side-by-side diff) | |
tree | c781fc00f048010835d7f7a1346ac16c87c8479e | |
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
-rw-r--r-- | noncore/settings/sysinfo/otabwidget.cpp | 199 | ||||
-rw-r--r-- | noncore/settings/sysinfo/otabwidget.h | 54 | ||||
-rw-r--r-- | noncore/settings/sysinfo/sysinfo.cpp | 18 |
3 files changed, 239 insertions, 32 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 @@ #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 ) - : QTabWidget( parent, name ) +OTabWidget::OTabWidget( QWidget *parent, const char *name = 0x0, + TabStyle s = Global, TabPosition p = Top ) + : QWidget( parent, name ) { - connect( this, SIGNAL( currentChanged( QWidget * ) ), - this, SLOT( tabChangedSlot( QWidget * ) ) ); + if ( s == Global ) + { + Config config( "qpe" ); + config.setGroup( "Appearance" ); + tabBarStyle = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); + if ( tabBarStyle <= Global || tabBarStyle > IconList) + { + tabBarStyle = IconTab; + } + QString pos = config.readEntry( "TabPosition", "Top"); + if ( pos == "Top" ) + { + tabBarPosition = Top; + } + else + { + tabBarPosition = Bottom; + } + } + else + { + tabBarStyle = s; + tabBarPosition = p; + } + + widgetStack = new QWidgetStack( this, "widgetstack" ); + widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); + widgetStack->setLineWidth( style().defaultFrameWidth() ); + + tabBarStack = new QWidgetStack( this, "tabbarstack" ); + + tabBar = new QTabBar( tabBarStack, "tabbar" ); + tabBarStack->addWidget( tabBar, 0 ); + connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) ); + + tabList = new QComboBox( false, tabBarStack, "tablist" ); + tabBarStack->addWidget( tabList, 1 ); + connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) ); + + if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) + { + tabBarStack->raiseWidget( tabBar ); + } + else if ( tabBarStyle == TextList || tabBarStyle == IconList ) + { + tabBarStack->raiseWidget( tabList ); + } + + if ( tabBarPosition == Bottom ) + { + tabBar->setShape( QTabBar::RoundedBelow ); + } } OTabWidget::~OTabWidget() @@ -38,26 +91,85 @@ OTabWidget::~OTabWidget() void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) { - Tabs.append( TabInfo( child, icon, label ) ); - QTabWidget::addTab( child, loadSmooth( icon ), QString::null ); + QPixmap iconset = loadSmooth( icon ); + + // Add to tabBar + QTab * tab = new QTab(); + if ( tabBarStyle == IconTab ) + { + tab->label = QString::null; + } + else + { + tab->label = label; + } + 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 ) ); + + setUpLayout( FALSE ); +} + +OTabWidget::TabStyle OTabWidget::tabStyle() const +{ + return tabBarStyle; +} + +void OTabWidget::setTabStyle( TabStyle s ) +{ + tabBarStyle = s; } -void OTabWidget::tabChangedSlot( QWidget *child ) +OTabWidget::TabPosition OTabWidget::tabPosition() const { - TabInfoList::Iterator it; + return tabBarPosition; +} - if ( CurrentTab != 0x0 ) +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 ) { - changeTab( (*CurrentTab).control(), loadSmooth( (*CurrentTab).icon() ), QString::null ); + selectTab( newtab ); } +} - for ( it = Tabs.begin(); it != Tabs.end(); ++it ) +void OTabWidget::slotTabListSelected( int index ) +{ + TabInfoList::Iterator newtab = tabs.at( index ); + if ( newtab != tabs.end() ) { - if ( (*it).control() == child ) - { - CurrentTab = it; - changeTab( (*CurrentTab).control(), loadSmooth( (*CurrentTab).icon() ), (*CurrentTab).label() ); - } + selectTab( newtab ); } } @@ -69,3 +181,56 @@ QPixmap OTabWidget::loadSmooth( const QString &name ) return pixmap; } +void OTabWidget::selectTab( TabInfoList::Iterator tab ) +{ + if ( tabBarStyle == IconTab ) + { + if ( currentTab != 0x0 ) + { + tabBar->tab( (*currentTab).id() )->label = QString::null; + } + tabBar->tab( (*tab).id() )->label = (*tab).label(); + currentTab = tab; + } + tabBar->layoutTabs(); + tabBar->update(); + + widgetStack->raiseWidget( (*tab).control() ); + + setUpLayout( FALSE ); +} + +void OTabWidget::setUpLayout( bool onlyCheck ) +{ + QSize t( tabBarStack->sizeHint() ); + if ( t.width() > width() ) + t.setWidth( width() ); + int lw = widgetStack->lineWidth(); + if ( tabBarPosition == Bottom ) + { + tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); + widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); + } + 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 ( autoMask() ) + updateMask(); +} + +QSize OTabWidget::sizeHint() const +{ + QSize s( widgetStack->sizeHint() ); + QSize t( tabBarStack->sizeHint() ); + return QSize( QMAX( s.width(), t.width()), s.height() + t.height() ); +} + +void OTabWidget::resizeEvent( QResizeEvent * ) +{ + setUpLayout( FALSE ); +} diff --git a/noncore/settings/sysinfo/otabwidget.h b/noncore/settings/sysinfo/otabwidget.h index 4588cb9..38f4d20 100644 --- a/noncore/settings/sysinfo/otabwidget.h +++ b/noncore/settings/sysinfo/otabwidget.h @@ -20,43 +20,75 @@ #ifndef OTABWIDGET_H #define OTABWIDGET_H -#include <qtabwidget.h> +#include <qwidget.h> + +class QComboBox; +class QPixmap; +class QTabBar; +class QWidgetStack; class TabInfo { public: - TabInfo() : c( 0 ), i( 0 ), l( QString::null ) {} - TabInfo( QWidget *control, const QString &icon, const QString &label ) - : c( control ), i( icon ), l( label ) {} + TabInfo() : i( -1 ), c( 0 ), p( 0 ), l( QString::null ) {} + TabInfo( int id, QWidget *control, const QString &icon, const QString &label ) + : i( id ), c( control ), p( icon ), l( label ) {} + int id() const { return i; } QString label() const { return l; } QWidget *control() const { return c; } - QString icon() const { return i; } + QString icon() const { return p; } private: + int i; QWidget *c; - QString i; + QString p; QString l; }; typedef QValueList<TabInfo> TabInfoList; -class OTabWidget : public QTabWidget +class OTabWidget : public QWidget { Q_OBJECT public: - OTabWidget( QWidget *, const char * ); + enum TabStyle { Global, TextTab, IconTab, TextList, IconList }; + TabStyle tabStyle() const; + void setTabStyle( TabStyle ); + + enum TabPosition { Top, Bottom }; + TabPosition tabPosition() const; + void setTabPosition( TabPosition ); + + OTabWidget( QWidget *, const char *, TabStyle, TabPosition ); ~OTabWidget(); void addTab( QWidget *, const QString &, const QString & ); + QSize sizeHint() const; + + +protected: + void resizeEvent( QResizeEvent * ); private: - TabInfoList Tabs; - TabInfoList::Iterator CurrentTab; + TabInfoList tabs; + TabInfoList::Iterator currentTab; + + TabStyle tabBarStyle; + TabPosition tabBarPosition; + + QWidgetStack *tabBarStack; + QTabBar *tabBar; + QComboBox *tabList; + + QWidgetStack *widgetStack; QPixmap loadSmooth( const QString & ); + void selectTab( TabInfoList::Iterator ); + void setUpLayout( bool ); private slots: - void tabChangedSlot( QWidget * ); + void slotTabBarSelected( int ); + void slotTabListSelected( int ); }; #endif diff --git a/noncore/settings/sysinfo/sysinfo.cpp b/noncore/settings/sysinfo/sysinfo.cpp index 56ac488..ca08ae2 100644 --- a/noncore/settings/sysinfo/sysinfo.cpp +++ b/noncore/settings/sysinfo/sysinfo.cpp @@ -28,6 +28,7 @@ #include "otabwidget.h" +#include <qpe/config.h> #include <qpe/resource.h> #include <qlayout.h> @@ -37,19 +38,28 @@ SystemInfo::SystemInfo( QWidget *parent, const char *name, WFlags f ) { setIcon( Resource::loadPixmap( "system_icon" ) ); setCaption( tr("System Info") ); + + resize( 220, 180 ); + + Config config( "qpe" ); + config.setGroup( "Appearance" ); + bool advanced = config.readBoolEntry( "Advanced", TRUE ); + QVBoxLayout *lay = new QVBoxLayout( this ); - OTabWidget *tab = new OTabWidget( this, "tabwidget" ); + OTabWidget *tab = new OTabWidget( this, "tabwidget", OTabWidget::Global, OTabWidget::Bottom ); lay->addWidget( tab ); tab->addTab( new MemoryInfo( tab ), "sysinfo/memorytabicon.png", tr("Memory") ); #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) tab->addTab( new StorageInfo( tab ), "sysinfo/storagetabicon.png", tr("Storage") ); #endif tab->addTab( new LoadInfo( tab ), "sysinfo/cputabicon.png", tr("CPU") ); - tab->addTab( new ProcessInfo( tab ), "sysinfo/processtabicon.png", tr("Process") ); - tab->addTab( new ModulesInfo( tab ), "sysinfo/moduletabicon.png", tr("Modules") ); + if ( advanced ) + { + tab->addTab( new ProcessInfo( tab ), "sysinfo/processtabicon.png", tr("Process") ); + tab->addTab( new ModulesInfo( tab ), "sysinfo/moduletabicon.png", tr("Modules") ); + } tab->addTab( new VersionInfo( tab ), "sysinfo/versiontabicon.png", tr("Version") ); - resize( 220, 180 ); } |