summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opieui/otabwidget.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/libopie2/opieui/otabwidget.cpp b/libopie2/opieui/otabwidget.cpp
index ae396b9..8d7806c 100644
--- a/libopie2/opieui/otabwidget.cpp
+++ b/libopie2/opieui/otabwidget.cpp
@@ -263,206 +263,220 @@ void OTabWidget::setTabStyle( TabStyle s )
{
// Get out if new and current styles are the same
if ( s == m_tabBarStyle )
return;
// Delete current selector control
if ( m_usingTabs )
{
delete m_tabBar;
m_tabBar = 0l;
}
else
{
delete m_tabList;
m_tabList = 0l;
}
// Set new style information
m_tabBarStyle = s;
m_usingTabs = ( m_tabBarStyle == TextTab || m_tabBarStyle == IconTab );
// Create new selector control and populate with tab information
if ( m_usingTabs )
{
// Create new tab bar selector
m_tabBar = new OTabBar( this );
connect( m_tabBar, SIGNAL(selected(int)), this, SLOT(slotTabBarSelected(int)) );
// Add all current tabs to tab bar
for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() )
{
// Create new tab in tab bar
QTab *tab = new QTab();
// Set label (and icon if necessary)
if ( m_tabBarStyle == IconTab )
{
tab->label = QString::null;
tab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) );
}
else
tab->label = tabinfo->label();
// Add tab and save its Id
int tabid = m_tabBar->addTab( tab );
tabinfo->setId( tabid );
}
}
else
{
// Create new drop down list selector
m_tabList = new QComboBox( false, this );
connect( m_tabList, SIGNAL(activated(int)), this, SLOT(slotTabListSelected(int)) );
// Add all current tabs to drop down list
for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() )
{
if ( m_tabBarStyle == IconList )
m_tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() );
else
m_tabList->insertItem( tabinfo->label() );
}
}
// Redraw widget
setUpLayout();
}
OTabWidget::TabPosition OTabWidget::tabPosition() const
{
return m_tabBarPosition;
}
void OTabWidget::setTabPosition( TabPosition p )
{
m_tabBarPosition = p;
// If using the tab bar selector, set its shape
if ( m_usingTabs )
{
( m_tabBarPosition == Top ) ? m_tabBar->setShape( QTabBar::RoundedAbove )
: m_tabBar->setShape( QTabBar::RoundedBelow );
}
// Redraw widget
setUpLayout();
}
void OTabWidget::slotTabBarSelected( int id )
{
OTabInfo *newtab = m_tabs.first();
while ( newtab && newtab->id() != id )
newtab = m_tabs.next();
if ( newtab && newtab->id() == id )
selectTab( newtab );
}
void OTabWidget::slotTabListSelected( int index )
{
OTabInfo *newtab = m_tabs.at( index );
if ( newtab )
selectTab( newtab );
}
QPixmap OTabWidget::loadSmooth( const QString &name )
{
QPixmap p;
p.convertFromImage( Resource::loadImage( name ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) );
return p;
}
void OTabWidget::selectTab( OTabInfo *tab )
{
if ( m_tabBarStyle == IconTab )
{
// Remove text label from currently selected tab
if ( m_currTab )
{
m_tabBar->tab( m_currTab->id() )->setText( QString::null );
//setUpLayout();
}
// Set text label for newly selected tab
m_tabBar->tab( tab->id() )->setText( tab->label() );
m_tabBar->setCurrentTab( tab->id() );
setUpLayout();
+
+ QSize t;
+
+ t = m_tabBar->sizeHint();
+ if ( t.width() > width() )
+ t.setWidth( width() );
+ int lw = m_widgetStack->lineWidth();
+ if ( m_tabBarPosition == Bottom )
+ m_tabBar->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() );
+ else
+ m_tabBar->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() );
}
else if ( m_tabBarStyle == TextTab )
{
m_tabBar->setCurrentTab( tab->id() );
}
m_widgetStack->raiseWidget( tab->control() );
emit currentChanged( tab->control() );
m_currTab = tab;
}
void OTabWidget::setUpLayout()
{
if ( m_usingTabs )
{
m_tabBar->update();
m_tabBar->layoutTabs();
}
}
void OTabWidget::resizeEvent( QResizeEvent * )
{
QSize t;
if ( m_usingTabs )
{
m_tabBar->layoutTabs();
t = m_tabBar->sizeHint();
+ if ( t.width() > width() )
+ t.setWidth( width() );
}
else
+ {
t = m_tabList->sizeHint();
-
t.setWidth( width() );
+ }
int lw = m_widgetStack->lineWidth();
if ( m_tabBarPosition == Bottom )
{
if ( m_usingTabs )
m_tabBar->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() );
else
m_tabList->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() );
m_widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) );
}
else
{
if ( m_usingTabs )
m_tabBar->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() );
else
m_tabList->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() );
m_widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) );
}
if ( autoMask() )
updateMask();
}
int OTabWidget::currentTab()
{
if ( m_currTab )
{
return m_currTab->id();
}
return -1;
}
QWidget* OTabWidget::currentWidget()const
{
if ( m_currTab )
{
return m_currTab->control();
}
return 0;
}