summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opieui/otabinfo.h50
-rw-r--r--libopie2/opieui/otabwidget.cpp424
-rw-r--r--libopie2/opieui/otabwidget.h69
3 files changed, 293 insertions, 250 deletions
diff --git a/libopie2/opieui/otabinfo.h b/libopie2/opieui/otabinfo.h
index d6d5abf..99ff10e 100644
--- a/libopie2/opieui/otabinfo.h
+++ b/libopie2/opieui/otabinfo.h
@@ -1,136 +1,144 @@
/*
-                This file is part of the Opie Project
+ This file is part of the Opie Project
-              Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
+ Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
=.
.=l.
-           .>+-=
- _;:,     .>    :=|. This program is free software; you can
-.> <`_,   >  .   <= redistribute it and/or modify it under
-:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
-.="- .-=="i,     .._ License as published by the Free Software
- - .   .-<_>     .<> Foundation; either version 2 of the License,
-     ._= =}       : or (at your option) any later version.
-    .%`+i>       _;_.
-    .i_,=:_.      -<s. This program is distributed in the hope that
-     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
-    : ..    .:,     . . . without even the implied warranty of
-    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
-  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
-..}^=.=       =       ; Library General Public License for more
-++=   -.     .`     .: details.
- :     =  ...= . :.=-
- -.   .:....=;==+<; You should have received a copy of the GNU
-  -_. . .   )=.  = Library General Public License along with
-    --        :-=` this library; see the file COPYING.LIB.
+ .>+-=
+_;:, .> :=|. This program is free software; you can
+.> <`_, > . <= redistribute it and/or modify it under
+:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
+.="- .-=="i, .._ License as published by the Free Software
+- . .-<_> .<> Foundation; either version 2 of the License,
+ ._= =} : or (at your option) any later version.
+ .%`+i> _;_.
+ .i_,=:_. -<s. This program is distributed in the hope that
+ + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
+ : .. .:, . . . without even the implied warranty of
+ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
+ _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.= = ; Library General Public License for more
+++= -. .` .: details.
+: = ...= . :.=-
+-. .:....=;==+<; You should have received a copy of the GNU
+ -_. . . )=. = Library General Public License along with
+ -- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OTABINFO_H
#define OTABINFO_H
/* QT */
#include <qlist.h>
#include <qstring.h>
class QWidget;
namespace Opie{
namespace Ui {
/**
* @class OTabInfo
* @brief The OTabInfo class is used internally by OTabWidget to keep track
* of widgets added to the control.
*
* OTabInfo provides the following information about a widget added to an
* OTabWidget control:
*
* ID - integer tab bar ID
* Control - QWidget pointer to child widget
* Label - QString text label for OTabWidget selection control
* Icon - QString name of icon file
*/
class OTabInfo
{
public:
/**
* @fn OTabInfo()
* @brief Object constructor.
*/
OTabInfo() : i( -1 ), c( 0 ), p( 0 ), l( QString::null ) {}
/**
* @fn OTabInfo( int id, QWidget *control, const QString &icon, const QString &label )
* @brief Object constructor.
*
* @param id TabBar identifier for widget.
* @param control QWidget pointer to widget.
* @param icon QString name of icon file.
* @param label QString text label for OTabWidget selection control.
*/
OTabInfo( int id, QWidget *control, const QString &icon, const QString &label )
: i( id ), c( control ), p( icon ), l( label ) {}
/**
* @fn id()const
* @brief Returns TabBar ID.
*/
int id() const { return i; }
/**
+ * @fn setId( int id )
+ * @brief Set Id for tab.
+ *
+ * @param id integer tab identifier.
+ */
+ void setId( int id ) { i = id; }
+
+ /**
* @fn label()const
* @brief Returns text label for widget.
*/
const QString &label() const { return l; }
/**
* @fn setLabel( const QString &label )
* @brief Set label for tab.
*
* @param label QString text label for OTabWidget selection control.
*/
void setLabel( const QString &label ) { l = label; }
/**
* @fn control()const
* @brief Returns pointer to widget.
*/
QWidget *control() const { return c; }
/**
* @fn icon()const
* @brief Returns name of icon file.
*/
const QString &icon() const { return p; }
/**
* @fn setIcon( const QString &icon )
* @brief Set icon for tab.
*
* @param icon QString name of icon file.
*/
void setIcon( const QString &icon ) { p = icon; }
private:
int i;
QWidget *c;
QString p;
QString l;
class Private;
Private *d;
};
/**
* @class OTabInfoList
* @brief A list of OTabInfo objects used by OTabWidget.
*/
typedef QList<OTabInfo> OTabInfoList;
}
}
#endif
diff --git a/libopie2/opieui/otabwidget.cpp b/libopie2/opieui/otabwidget.cpp
index d23b1c9..01747e1 100644
--- a/libopie2/opieui/otabwidget.cpp
+++ b/libopie2/opieui/otabwidget.cpp
@@ -1,426 +1,466 @@
/*
-                This file is part of the Opie Project
+ This file is part of the Opie Project
-              Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
+ Copyright (c) 2002, 2005 Dan Williams <drw@handhelds.org>
=.
.=l.
-           .>+-=
- _;:,     .>    :=|. This program is free software; you can
-.> <`_,   >  .   <= redistribute it and/or modify it under
-:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
-.="- .-=="i,     .._ License as published by the Free Software
- - .   .-<_>     .<> Foundation; either version 2 of the License,
-     ._= =}       : or (at your option) any later version.
-    .%`+i>       _;_.
-    .i_,=:_.      -<s. This program is distributed in the hope that
-     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
-    : ..    .:,     . . . without even the implied warranty of
-    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
-  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
-..}^=.=       =       ; Library General Public License for more
-++=   -.     .`     .: details.
- :     =  ...= . :.=-
- -.   .:....=;==+<; You should have received a copy of the GNU
-  -_. . .   )=.  = Library General Public License along with
-    --        :-=` this library; see the file COPYING.LIB.
+ .>+-=
+_;:, .> :=|. This program is free software; you can
+.> <`_, > . <= redistribute it and/or modify it under
+:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
+.="- .-=="i, .._ License as published by the Free Software
+- . .-<_> .<> Foundation; either version 2 of the License,
+ ._= =} : or (at your option) any later version.
+ .%`+i> _;_.
+ .i_,=:_. -<s. This program is distributed in the hope that
+ + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
+ : .. .:, . . . without even the implied warranty of
+ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
+ _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.= = ; Library General Public License for more
+++= -. .` .: details.
+: = ...= . :.=-
+-. .:....=;==+<; You should have received a copy of the GNU
+ -_. . . )=. = Library General Public License along with
+ -- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <opie2/otabwidget.h>
/* OPIE */
#include <qpe/applnk.h>
#include <qpe/config.h>
#include <qpe/resource.h>
#include <opie2/otabbar.h>
/* QT */
#include <qcombobox.h>
#include <qwidgetstack.h>
using namespace Opie::Ui;
OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p )
: QWidget( parent, name )
+ , m_currTab( 0l )
+ , m_usingTabs( true )
+ , m_tabBar( 0l )
+ , m_tabList( 0l )
{
if ( s == Global )
{
+ // Read Opie global settings for style and position
Config config( "qpe" );
config.setGroup( "Appearance" );
+
+ // Style
s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab );
if ( s <= Global || s > IconList)
- {
s = IconTab;
- }
- QString pos = config.readEntry( "TabPosition", "Top");
- if ( pos == "Bottom" )
- {
- p = Bottom;
- }
- else
- {
- p = Top;
- }
- }
-
- 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) ) );
+ // Position
+ ( config.readEntry( "TabPosition", "Top" ) == "Bottom" ) ? p = Bottom
+ : p = Top;
+ }
- tabList = new QComboBox( false, tabBarStack, "tablist" );
- tabBarStack->addWidget( tabList, 1 );
- connect( tabList, SIGNAL( activated(int) ), this, SLOT( slotTabListSelected(int) ) );
+ // Initialize widget stack for tab widgets
+ m_widgetStack = new QWidgetStack( this );
+ m_widgetStack->setFrameStyle( QFrame::NoFrame );
+ m_widgetStack->setLineWidth( style().defaultFrameWidth() );
- tabBarPosition = p;
+ // Set initial selector control style and position
setTabStyle( s );
setTabPosition( p );
-
- currTab= 0x0;
}
OTabWidget::~OTabWidget()
{
- tabs.setAutoDelete( true );
- tabs.clear();
+ m_tabs.setAutoDelete( true );
+ m_tabs.clear();
}
void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
{
- QPixmap iconset = loadSmooth( icon );
+ int tabid = -1;
+ if ( m_usingTabs )
+ {
+ // Create new tab in tab bar
QTab *tab = new QTab();
- if ( tabBarStyle == IconTab )
+
+ // Set label (and icon if necessary)
+ if ( m_tabBarStyle == IconTab )
{
tab->label = QString::null;
+ tab->iconset = new QIconSet( loadSmooth( icon ) );
}
else
- {
tab->label = label;
- }
- if ( tabBarStyle == IconTab || tabBarStyle == IconList )
- {
- tab->iconset = new QIconSet( iconset );
- }
- int tabid = tabBar->addTab( tab );
- if ( tabBarStyle == IconTab || tabBarStyle == IconList )
- {
- tabList->insertItem( iconset, label, -1 );
+ tabid = m_tabBar->addTab( tab );
}
else
{
- tabList->insertItem( label );
+ // Insert entry (with icon if necessary) into drop down list
+ if ( m_tabBarStyle == IconList )
+ m_tabList->insertItem( loadSmooth( icon ), label, -1 );
+ else
+ m_tabList->insertItem( label );
}
- widgetStack->addWidget( child, tabid );
- widgetStack->raiseWidget( child );
- widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
+ // Add widget to stack
+ m_widgetStack->addWidget( child, tabid );
+ m_widgetStack->raiseWidget( child );
+ m_widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
+ // Keep track of tab information
OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label );
- tabs.append( tabinfo );
+ m_tabs.append( tabinfo );
+
+ // Make newly added tab the current one displayed
selectTab( tabinfo );
}
void OTabWidget::removePage( QWidget *childwidget )
{
if ( childwidget )
{
- OTabInfo *tab = tabs.first();
+ // Find tab information for desired widget
+ OTabInfo *tab = m_tabs.first();
while ( tab && tab->control() != childwidget )
- {
- tab = tabs.next();
- }
+ tab = m_tabs.next();
+
if ( tab && tab->control() == childwidget )
{
- tabBar->setTabEnabled( tab->id(), FALSE );
- tabBar->removeTab( tabBar->tab( tab->id() ) );
- int i = 0;
- while ( i < tabList->count() && tabList->text( i ) != tab->label() )
+ if ( m_usingTabs )
{
- i++;
+ // Remove tab from tab bar
+ m_tabBar->setTabEnabled( tab->id(), false );
+ m_tabBar->removeTab( m_tabBar->tab( tab->id() ) );
}
- if ( tabList->text( i ) == tab->label() )
+ else
{
- tabList->removeItem( i );
+ // Remove entry from drop down list
+ int i = 0;
+ while ( i < m_tabList->count() && m_tabList->text( i ) != tab->label() )
+ i++;
+ if ( m_tabList->text( i ) == tab->label() )
+ m_tabList->removeItem( i );
}
- widgetStack->removeWidget( childwidget );
- tabs.remove( tab );
+
+ // Remove widget from stack
+ m_widgetStack->removeWidget( childwidget );
+
+ // Get rid of tab information
+ m_tabs.remove( tab );
delete tab;
- currTab = tabs.current();
- if ( !currTab )
- {
- widgetStack->setFrameStyle( QFrame::NoFrame );
- }
+ // Reset current tab
+ m_currTab = m_tabs.current();
+ if ( !m_currTab )
+ m_widgetStack->setFrameStyle( QFrame::NoFrame );
+
+ // Redraw widget
setUpLayout();
}
}
}
void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label)
{
- OTabInfo *currtab = tabs.first();
+ // Find tab information for desired widget
+ OTabInfo *currtab = m_tabs.first();
while ( currtab && currtab->control() != widget )
- {
- currtab = tabs.next();
- }
+ currtab = m_tabs.next();
+
if ( currtab && currtab->control() == widget )
{
- QTab *tab = tabBar->tab( currtab->id() );
QPixmap icon( loadSmooth( iconset ) );
+
+ if ( m_usingTabs )
+ {
+ // Update tab label and icon (if necessary)
+ QTab *tab = m_tabBar->tab( currtab->id() );
tab->setText( label );
- if ( tabBarStyle == IconTab )
+ if ( m_tabBarStyle == IconTab )
tab->setIconSet( icon );
- int i = 0;
- while ( i < tabList->count() && tabList->text( i ) != currtab->label() )
- {
- i++;
}
- if ( i < tabList->count() && tabList->text( i ) == currtab->label() )
+ else
{
- if ( tabBarStyle == IconTab || tabBarStyle == IconList )
+ // Update entry label and icon (if necessary)
+ int i = 0;
+ while ( i < m_tabList->count() && m_tabList->text( i ) != currtab->label() )
+ i++;
+ if ( i < m_tabList->count() && m_tabList->text( i ) == currtab->label() )
{
- tabList->changeItem( icon, label, i );
- }
+ if ( m_tabBarStyle == IconList )
+ m_tabList->changeItem( icon, label, i );
else
- {
- tabList->changeItem( label, i );
+ m_tabList->changeItem( label, i );
}
}
+
+ // Update tab information
currtab->setLabel( label );
currtab->setIcon( iconset );
- }
+
+ // Redraw widget
setUpLayout();
}
+}
void OTabWidget::setCurrentTab( QWidget *childwidget )
{
- OTabInfo *currtab = tabs.first();
+ OTabInfo *currtab = m_tabs.first();
while ( currtab && currtab->control() != childwidget )
{
- currtab = tabs.next();
+ currtab = m_tabs.next();
}
if ( currtab && currtab->control() == childwidget )
{
selectTab( currtab );
}
}
void OTabWidget::setCurrentTab( const QString &tabname )
{
- OTabInfo *newtab = tabs.first();
+ OTabInfo *newtab = m_tabs.first();
while ( newtab && newtab->label() != tabname )
{
- newtab = tabs.next();
+ newtab = m_tabs.next();
}
if ( newtab && newtab->label() == tabname )
{
selectTab( newtab );
}
}
void OTabWidget::setCurrentTab(int tabindex)
{
- OTabInfo *newtab = tabs.first();
+ OTabInfo *newtab = m_tabs.first();
while ( newtab && newtab->id() != tabindex )
{
- newtab = tabs.next();
+ newtab = m_tabs.next();
}
if ( newtab && newtab->id() == tabindex )
{
selectTab( newtab );
}
}
OTabWidget::TabStyle OTabWidget::tabStyle() const
{
- return tabBarStyle;
+ return m_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 )
+ // Get out if new and current styles are the same
+ if ( s == m_tabBarStyle )
+ return;
+
+ // Delete current selector control
+ if ( m_usingTabs )
{
- currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) );
- if ( tabinfo == currTab )
- currtab->setText( tabinfo->label() );
- else
- currtab->setText( QString::null );
+ delete m_tabBar;
+ m_tabBar = 0l;
}
else
{
- currtab->iconset = 0x0;
- currtab->setText( tabinfo->label() );
- }
+ delete m_tabList;
+ m_tabList = 0l;
}
- tabBarStack->raiseWidget( tabBar );
- }
- else if ( tabBarStyle == TextList || tabBarStyle == IconList )
+
+ // 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 )
{
- tabList->clear();
- for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
+ // 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() )
{
- if ( tabBarStyle == IconList )
+ // Create new tab in tab bar
+ QTab *tab = new QTab();
+
+ // Set label (and icon if necessary)
+ if ( m_tabBarStyle == IconTab )
{
- tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() );
+ tab->label = QString::null;
+ tab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) );
}
else
- {
- tabList->insertItem( tabinfo->label() );
+ tab->label = tabinfo->label();
+
+ // Add tab and save its Id
+ int tabid = m_tabBar->addTab( tab );
+ tabinfo->setId( tabid );
}
}
- tabBarStack->raiseWidget( tabList );
+ 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 tabBarPosition;
+ return m_tabBarPosition;
}
void OTabWidget::setTabPosition( TabPosition p )
{
- tabBarPosition = p;
- if ( tabBarPosition == Top )
- {
- tabBar->setShape( QTabBar::RoundedAbove );
- }
- else
+ m_tabBarPosition = p;
+
+ // If using the tab bar selector, set its shape
+ if ( m_usingTabs )
{
- tabBar->setShape( QTabBar::RoundedBelow );
+ ( m_tabBarPosition == Top ) ? m_tabBar->setShape( QTabBar::RoundedAbove )
+ : m_tabBar->setShape( QTabBar::RoundedBelow );
}
+
+ // Redraw widget
setUpLayout();
}
void OTabWidget::slotTabBarSelected( int id )
{
- OTabInfo *newtab = tabs.first();
+ OTabInfo *newtab = m_tabs.first();
while ( newtab && newtab->id() != id )
- {
- newtab = tabs.next();
- }
+ newtab = m_tabs.next();
+
if ( newtab && newtab->id() == id )
- {
selectTab( newtab );
}
-}
void OTabWidget::slotTabListSelected( int index )
{
- OTabInfo *newtab = tabs.at( 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 ( tabBarStyle == IconTab )
+ if ( m_tabBarStyle == IconTab )
{
- if ( currTab )
+ // Remove text label from currently selected tab
+ if ( m_currTab )
{
- tabBar->tab( currTab->id() )->setText( QString::null );
- setUpLayout();
+ m_tabBar->tab( m_currTab->id() )->setText( QString::null );
+ //setUpLayout();
}
- tabBar->tab( tab->id() )->setText( tab->label() );
- tabBar->setCurrentTab( tab->id() );
+
+ // Set text label for newly selected tab
+ m_tabBar->tab( tab->id() )->setText( tab->label() );
+ m_tabBar->setCurrentTab( tab->id() );
+
setUpLayout();
- tabBar->update();
}
- else
+ else if ( m_tabBarStyle == TextTab )
{
- tabBar->setCurrentTab( tab->id() );
+ m_tabBar->setCurrentTab( tab->id() );
}
- widgetStack->raiseWidget( tab->control() );
+ m_widgetStack->raiseWidget( tab->control() );
emit currentChanged( tab->control() );
- currTab = tab;
+ m_currTab = tab;
}
void OTabWidget::setUpLayout()
{
- tabBar->layoutTabs();
- QSize t( tabBarStack->sizeHint() );
- if ( tabBarStyle == IconTab )
+ if ( m_usingTabs )
{
- if ( t.width() > width() )
- t.setWidth( width() );
+ m_tabBar->update();
+ m_tabBar->layoutTabs();
}
- else
- {
- t.setWidth( width() );
}
- int lw = widgetStack->lineWidth();
- if ( tabBarPosition == Bottom )
+
+void OTabWidget::resizeEvent( QResizeEvent * )
{
- 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) );
+ QSize t;
+
+ if ( m_usingTabs )
+ {
+ m_tabBar->layoutTabs();
+ t = m_tabBar->sizeHint();
}
else
+ t = m_tabList->sizeHint();
+
+ t.setWidth( width() );
+
+ int lw = m_widgetStack->lineWidth();
+ if ( m_tabBarPosition == Bottom )
{
- 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 ( 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() );
- if ( autoMask() )
- updateMask();
+ m_widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) );
}
-
-QSize OTabWidget::sizeHint() const
+ else
{
- QSize s( widgetStack->sizeHint() );
- QSize t( tabBarStack->sizeHint() );
- return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() );
+ 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 ) );
}
-void OTabWidget::resizeEvent( QResizeEvent * )
-{
- setUpLayout();
+ if ( autoMask() )
+ updateMask();
}
int OTabWidget::currentTab()
{
- if ( currTab )
+ if ( m_currTab )
{
- return currTab->id();
+ return m_currTab->id();
}
return -1;
}
QWidget* OTabWidget::currentWidget()const
{
- if ( currTab )
+ if ( m_currTab )
{
- return currTab->control();
+ return m_currTab->control();
}
return 0;
}
diff --git a/libopie2/opieui/otabwidget.h b/libopie2/opieui/otabwidget.h
index b3423e8..e925592 100644
--- a/libopie2/opieui/otabwidget.h
+++ b/libopie2/opieui/otabwidget.h
@@ -1,292 +1,287 @@
/*
-                 This file is part of the Opie Project
-              Copyright (C) 2002 Dan Williams <williamsdr@acm.org>
+ This file is part of the Opie Project
+ Copyright (C) 2002, 2005 Dan Williams <drw@handhelds.org>
=.
.=l.
-           .>+-=
- _;:,     .>    :=|. This program is free software; you can
-.> <`_,   >  .   <= redistribute it and/or modify it under
-:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
-.="- .-=="i,     .._ License as published by the Free Software
- - .   .-<_>     .<> Foundation; either version 2 of the License,
-     ._= =}       : or (at your option) any later version.
-    .%`+i>       _;_.
-    .i_,=:_.      -<s. This program is distributed in the hope that
-     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
-    : ..    .:,     . . . without even the implied warranty of
-    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
-  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
-..}^=.=       =       ; Library General Public License for more
-++=   -.     .`     .: details.
- :     =  ...= . :.=-
- -.   .:....=;==+<; You should have received a copy of the GNU
-  -_. . .   )=.  = Library General Public License along with
-    --        :-=` this library; see the file COPYING.LIB.
+ .>+-=
+_;:, .> :=|. This program is free software; you can
+.> <`_, > . <= redistribute it and/or modify it under
+:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
+.="- .-=="i, .._ License as published by the Free Software
+- . .-<_> .<> Foundation; either version 2 of the License,
+ ._= =} : or (at your option) any later version.
+ .%`+i> _;_.
+ .i_,=:_. -<s. This program is distributed in the hope that
+ + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
+ : .. .:, . . . without even the implied warranty of
+ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
+ _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.= = ; Library General Public License for more
+++= -. .` .: details.
+: = ...= . :.=-
+-. .:....=;==+<; You should have received a copy of the GNU
+ -_. . . )=. = Library General Public License along with
+ -- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OTABWIDGET_H
#define OTABWIDGET_H
/* OPIE */
#include <opie2/otabinfo.h>
/* QT */
#include <qwidget.h>
#include <qlist.h>
class QComboBox;
class QPixmap;
class QTabBar;
class QWidgetStack;
namespace Opie {
namespace Ui {
class OTabBar;
/**
* @class OTabWidget
* @brief The OTabWidget class provides a stack of widgets.
*
* OTabWidget is a derivation of TrollTech's QTabWidget which provides
* a stack of widgets. Widgets can be selected using either a tab bar or
* drop down list box.
*
* The normal way to use OTabWidget is to do the following in the
* constructor:
* - Create a OTabWidget.
* - Create a QWidget for each of the pages in the control, insert
* children into it, set up geometry management for it, and use addTab()
* to add the widget.
*/
class OTabWidget : public QWidget
{
Q_OBJECT
public:
/**
* @enum TabStyle
* @brief Defines how the widget selection control is displayed.
*
* Valid values:
* - Global: use globally selected options (qpe.conf - TabStyle & TabPosition)
* - TextTab: Tabbed widget selection with text labels
* - IconTab: Tabbed widget selection with icon labels, text label for active widget
* (similar to Opie launcher)
* - TextList: Drop down list widget selection with text labels
* - IconList: Drop down list widget selection with icon & text labels
*/
enum TabStyle { Global, TextTab, IconTab, TextList, IconList };
/**
* @enum TabPosition
* @brief Defines where the widget selection control is drawn.
*
* Valid values:
* - Top: Widget selection control is drawn above widgets
* - Bottom: Widget selection control is drawn below widgets
*/
enum TabPosition { Top, Bottom };
/**
* @fn OTabWidget( QWidget *parent = 0, const char *name = 0, TabStyle s = Global, TabPosition p = Top )
* @brief Object constructor.
*
* @param parent Pointer to parent of this control.
* @param name Name of control.
* @param s Style of widget selection control.
* @param p Position of the widget selection control.
*
* Constructs a new OTabWidget control with parent and name. The style and position parameters
* determine how the widget selection control will be displayed.
*/
OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top );
/**
* @fn ~OTabWidget()
* @brief Object destructor.
*/
~OTabWidget();
/**
* @fn addTab( QWidget *child, const QString &icon, const QString &label )
* @brief Add new widget to control.
*
* @param child Widget control.
* @param icon Path to icon.
* @param label Text label.
*/
void addTab( QWidget *, const QString &, const QString & );
/**
* @fn removePage( QWidget *widget )
* @brief Remove widget from control. Does not delete widget.
*
* @param widget Widget control to be removed.
*/
void removePage( QWidget * );
/**
* @fn changeTab( QWidget *widget, const QString &icon, const QString &label )
* @brief Change text and/or icon for existing tab
*
* @param child Widget control.
* @param icon Path to icon.
* @param label Text label.
*/
void changeTab( QWidget *, const QString &, const QString & );
/**
* @fn tabStyle()const
* @brief Returns current widget selection control style.
*/
TabStyle tabStyle() const;
/**
* @fn setTabStyle( TabStyle s )
* @brief Set the current widget selection control style.
*
* @param s New style to be used.
*/
void setTabStyle( TabStyle );
/**
* @fn tabPosition()const
* @brief Returns current widget selection control position.
*/
TabPosition tabPosition() const;
/**
* @fn setTabPosition( TabPosition p )
* @brief Set the current widget selection control position.
*
* @param p New position of widget selection control.
*/
void setTabPosition( TabPosition );
/**
* @fn setCurrentTab( QWidget *childwidget )
* @brief Selects and brings to top the desired widget by using widget pointer.
*
* @param childwidget Widget to select.
*/
void setCurrentTab( QWidget * );
/**
* @fn setCurrentTab( const QString &tabname )
* @brief Selects and brings to top the desired widget, by using label.
*
* @param tabname Text label for widget to select.
*/
void setCurrentTab( const QString & );
/**
* @fn setCurrentTab( int )
* @brief Selects and brings to top the desired widget, by using id.
*
* @param tab id for widget to select.
*/
void setCurrentTab(int);
/**
- * @fn sizeHint()const
- * @brief Reimplemented for internal purposes.
- */
- QSize sizeHint() const;
-
-/**
* @fn currentTab( )
* @brief returns current tab id.
*/
// ### make const
int currentTab()/* const */;
/**
* @brief returns the current page of the active tab
*
* @since 1.2
*/
QWidget* currentWidget()const;
protected:
/**
* @fn resizeEvent( QResizeEvent * )
* @brief Reimplemented for internal purposes.
*/
void resizeEvent( QResizeEvent * );
private:
- OTabInfoList tabs;
- OTabInfo *currTab;
-
- TabStyle tabBarStyle;
- TabPosition tabBarPosition;
-
- QWidgetStack *tabBarStack;
- OTabBar *tabBar;
- QComboBox *tabList;
+ OTabInfoList m_tabs; // List of information for tabs
+ OTabInfo *m_currTab; // Current tab displayed
+ TabStyle m_tabBarStyle; // Current style of control
+ TabPosition m_tabBarPosition; // Position of selector control
+ bool m_usingTabs; // Indicates whether style is either TextTab or IconTab
+ // (saves from having to always check for these 2 values)
+
+ // UI components
+ OTabBar *m_tabBar;
+ QComboBox *m_tabList;
+ QWidgetStack *m_widgetStack;
- QWidgetStack *widgetStack;
class Private;
Private* d;
/**
* @fn loadSmooth( const QString &name )
* @brief Loads icon for widget.
*
* @param name Name of icon image file.
*/
QPixmap loadSmooth( const QString & );
/**
* @fn selectTab( OTabInfo *tab )
* @brief Internal function to select desired widget.
*
* @param tab Pointer to data for widget.
*/
void selectTab( OTabInfo * );
/**
* @fn setUpLayout()
* @brief Internal function to adjust layout.
*/
void setUpLayout();
signals:
/**
* @fn currentChanged( QWidget *widget )
* @brief This signal is emitted whenever the widget has changed.
*
* @param widget Pointer to new current widget.
*/
void currentChanged( QWidget * );
private slots:
/**
* @fn slotTabBarSelected( int id )
* @brief Slot which is called when a tab is selected.
*
* @param id ID of widget selected.
*/
void slotTabBarSelected( int );
/**
* @fn slotTabListSelected( int index )
* @brief Slot which is called when a drop down selection is made.
*
* @param id Index of widget selected.
*/
void slotTabListSelected( int );
};
}
}
#endif