summaryrefslogtreecommitdiff
authordrw <drw>2002-12-05 23:28:33 (UTC)
committer drw <drw>2002-12-05 23:28:33 (UTC)
commit0e19980617d101f69d0540d62b89fe1894cfe0f2 (patch) (side-by-side diff)
treeb5ecf3cdc140a08e69a98202b60e84a17e3858bf
parent8a1c4b4b84d8a8de87bb6adb4df3f09961854633 (diff)
downloadopie-0e19980617d101f69d0540d62b89fe1894cfe0f2.zip
opie-0e19980617d101f69d0540d62b89fe1894cfe0f2.tar.gz
opie-0e19980617d101f69d0540d62b89fe1894cfe0f2.tar.bz2
Allow changing styles/position at run-time (i.e. make setTabStyle/setTabPosition work).
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/otabwidget.cpp90
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
@@ -36,74 +36,57 @@
#include <opie/otabbar.h>
#include <qcombobox.h>
#include <qwidgetstack.h>
OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p )
: QWidget( parent, name )
{
if ( s == Global )
{
Config config( "qpe" );
config.setGroup( "Appearance" );
- tabBarStyle = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab );
- if ( tabBarStyle <= Global || tabBarStyle > IconList)
+ s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab );
+ if ( s <= Global || s > IconList)
{
- tabBarStyle = IconTab;
+ s = IconTab;
}
QString pos = config.readEntry( "TabPosition", "Top");
if ( pos == "Bottom" )
{
- tabBarPosition = Bottom;
+ p = Bottom;
}
else
{
- tabBarPosition = Top;
+ p = Top;
}
}
- else
- {
- tabBarStyle = s;
- tabBarPosition = p;
- }
widgetStack = new QWidgetStack( this, "widgetstack" );
widgetStack->setFrameStyle( QFrame::NoFrame );
widgetStack->setLineWidth( style().defaultFrameWidth() );
tabBarStack = new QWidgetStack( this, "tabbarstack" );
tabBar = new OTabBar( 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 );
- }
+ setTabStyle( s );
+ setTabPosition( p );
- //tabs.setAutoDelete( TRUE );
currentTab= 0x0;
}
OTabWidget::~OTabWidget()
{
}
void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
{
QPixmap iconset = loadSmooth( icon );
QTab *tab = new QTab();
@@ -213,34 +196,82 @@ void OTabWidget::setCurrentTab(int tabindex) {
}
}
OTabWidget::TabStyle OTabWidget::tabStyle() const
{
return tabBarStyle;
}
void OTabWidget::setTabStyle( TabStyle s )
{
tabBarStyle = s;
+ if ( tabBarStyle == TextTab || tabBarStyle == IconTab )
+ {
+ QTab *currtab;
+ for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
+ {
+ currtab = tabBar->tab( tabinfo->id() );
+ if ( tabBarStyle == IconTab )
+ {
+ currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) );
+ if ( tabinfo == currentTab )
+ currtab->setText( tabinfo->label() );
+ else
+ currtab->setText( QString::null );
+ }
+ else
+ {
+ currtab->iconset = 0x0;
+ currtab->setText( tabinfo->label() );
+ }
+ }
+ tabBarStack->raiseWidget( tabBar );
+ }
+ else if ( tabBarStyle == TextList || tabBarStyle == IconList )
+ {
+ tabList->clear();
+ for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
+ {
+ if ( tabBarStyle == IconList )
+ {
+ tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() );
+ }
+ else
+ {
+ tabList->insertItem( tabinfo->label() );
+ }
+ }
+ tabBarStack->raiseWidget( tabList );
+ }
+ setUpLayout();
}
OTabWidget::TabPosition OTabWidget::tabPosition() const
{
return tabBarPosition;
}
void OTabWidget::setTabPosition( TabPosition p )
{
tabBarPosition = p;
+ if ( tabBarPosition == Top )
+ {
+ tabBar->setShape( QTabBar::RoundedAbove );
+ }
+ else
+ {
+ tabBar->setShape( QTabBar::RoundedBelow );
+ }
+ setUpLayout();
}
void OTabWidget::slotTabBarSelected( int id )
{
OTabInfo *newtab = tabs.first();
while ( newtab && newtab->id() != id )
{
newtab = tabs.next();
}
if ( newtab && newtab->id() == id )
{
selectTab( newtab );
@@ -261,25 +292,25 @@ QPixmap OTabWidget::loadSmooth( const QString &name )
QImage image = Resource::loadImage( name );
QPixmap pixmap;
pixmap.convertFromImage( image.smoothScale( 16, 16 ) );
return pixmap;
}
void OTabWidget::selectTab( OTabInfo *tab )
{
if ( tabBarStyle == IconTab )
{
if ( currentTab )
{
- tabBar->tab( currentTab->id() )->setText( "" );
+ tabBar->tab( currentTab->id() )->setText( QString::null );
setUpLayout();
}
tabBar->tab( tab->id() )->setText( tab->label() );
tabBar->setCurrentTab( tab->id() );
setUpLayout();
tabBar->update();
}
else
{
tabBar->setCurrentTab( tab->id() );
}
@@ -322,20 +353,21 @@ void OTabWidget::setUpLayout()
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();
}
-int OTabWidget::getCurrentTab() {
+int OTabWidget::getCurrentTab()
+{
if ( currentTab )
- {
- return currentTab->id();
- }
+ {
+ return currentTab->id();
+ }
return -1;
}