summaryrefslogtreecommitdiff
path: root/libopie
authorllornkcor <llornkcor>2002-08-21 11:06:40 (UTC)
committer llornkcor <llornkcor>2002-08-21 11:06:40 (UTC)
commit646e6491e62c73903d330881ca6781bfc2c234f1 (patch) (side-by-side diff)
treefb4b41c2cd3dd63f4c81fe725f6cec0c402290f3 /libopie
parentc198ae0217f761418f7170d08a94da3864e47583 (diff)
downloadopie-646e6491e62c73903d330881ca6781bfc2c234f1.zip
opie-646e6491e62c73903d330881ca6781bfc2c234f1.tar.gz
opie-646e6491e62c73903d330881ca6781bfc2c234f1.tar.bz2
patch from drw, adds otabwidget
Diffstat (limited to 'libopie') (more/less context) (show whitespace changes)
-rw-r--r--libopie/libopie.pro4
-rw-r--r--libopie/otabwidget.cpp267
-rw-r--r--libopie/otabwidget.h232
3 files changed, 501 insertions, 2 deletions
diff --git a/libopie/libopie.pro b/libopie/libopie.pro
index 463fce2..d5b4836 100644
--- a/libopie/libopie.pro
+++ b/libopie/libopie.pro
@@ -1,25 +1,25 @@
TEMPLATE = lib
CONFIG += qte warn_on release
-HEADERS = ofontmenu.h ofileselector.h ofiledialog.h ofileview.h tododb.h todoevent.h todoresource.h todovcalresource.h xmltree.h colordialog.h colorpopupmenu.h oclickablelabel.h oprocctrl.h oprocess.h odevice.h otimepicker.h
-SOURCES = ofontmenu.cc ofileselector.cc ofiledialog.cc xmltree.cc tododb.cpp todoevent.cpp todovcalresource.cpp colordialog.cpp colorpopupmenu.cpp oclickablelabel.cpp oprocctrl.cpp oprocess.cpp odevice.cpp otimepicker.cpp
+HEADERS = ofontmenu.h ofileselector.h ofiledialog.h ofileview.h tododb.h todoevent.h todoresource.h todovcalresource.h xmltree.h colordialog.h colorpopupmenu.h oclickablelabel.h oprocctrl.h oprocess.h odevice.h otimepicker.h otabwidget.h otabinfo.h
+SOURCES = ofontmenu.cc ofileselector.cc ofiledialog.cc xmltree.cc tododb.cpp todoevent.cpp todovcalresource.cpp colordialog.cpp colorpopupmenu.cpp oclickablelabel.cpp oprocctrl.cpp oprocess.cpp odevice.cpp otimepicker.cpp otabwidget.cpp
TARGET = opie
INCLUDEPATH += $(OPIEDIR)/include
DESTDIR = $(QTDIR)/lib$(PROJMAK)
#VERSION = 1.0.0
INTERFACES = otimepickerbase.ui
TRANSLATIONS = ../i18n/de/libopie.ts \
../i18n/en/libopie.ts \
../i18n/es/libopie.ts \
../i18n/fr/libopie.ts \
../i18n/hu/libopie.ts \
../i18n/ja/libopie.ts \
../i18n/ko/libopie.ts \
../i18n/no/libopie.ts \
../i18n/pl/libopie.ts \
../i18n/pt/libopie.ts \
../i18n/pt_BR/libopie.ts \
../i18n/sl/libopie.ts \
../i18n/zh_CN/libopie.ts \
../i18n/zh_TW/libopie.ts
diff --git a/libopie/otabwidget.cpp b/libopie/otabwidget.cpp
new file mode 100644
index 0000000..6e10be9
--- a/dev/null
+++ b/libopie/otabwidget.cpp
@@ -0,0 +1,267 @@
+/*
+                This file is part of the Opie Project
+
+              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 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 "otabwidget.h"
+
+#include <qpe/config.h>
+#include <qpe/resource.h>
+
+#include <qcombobox.h>
+#include <qtabbar.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)
+ {
+ tabBarStyle = IconTab;
+ }
+ QString pos = config.readEntry( "TabPosition", "Top");
+ if ( pos == "Bottom" )
+ {
+ tabBarPosition = Bottom;
+ }
+ else
+ {
+ tabBarPosition = Top;
+ }
+ }
+ 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 );
+ }
+
+ currentTab= 0x0;
+}
+
+OTabWidget::~OTabWidget()
+{
+}
+
+void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
+{
+ QPixmap iconset = loadSmooth( icon );
+
+ 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 );
+
+ if ( tabBarStyle == IconTab || tabBarStyle == IconList )
+ {
+ tabList->insertItem( iconset, label, -1 );
+ }
+ else
+ {
+ tabList->insertItem( label );
+ }
+
+ widgetStack->addWidget( child, tabid );
+ widgetStack->raiseWidget( child );
+
+ OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label );
+ tabs.append( tabinfo );
+ selectTab( tabinfo );
+}
+
+void OTabWidget::setCurrentTab( QWidget *childwidget )
+{
+ OTabInfo *newtab = tabs.first();
+ while ( newtab && newtab->control() != childwidget )
+ {
+ newtab = tabs.next();
+ }
+ if ( newtab && newtab->control() == childwidget )
+ {
+ selectTab( newtab );
+ }
+}
+
+void OTabWidget::setCurrentTab( const QString &tabname )
+{
+ OTabInfo *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;
+}
+
+void OTabWidget::setTabStyle( TabStyle s )
+{
+ tabBarStyle = s;
+}
+
+OTabWidget::TabPosition OTabWidget::tabPosition() const
+{
+ return tabBarPosition;
+}
+
+void OTabWidget::setTabPosition( TabPosition p )
+{
+ tabBarPosition = p;
+}
+
+void OTabWidget::slotTabBarSelected( int id )
+{
+ OTabInfo *newtab = tabs.first();
+ while ( newtab && newtab->id() != id )
+ {
+ newtab = tabs.next();
+ }
+ if ( newtab && newtab->id() == id )
+ {
+ selectTab( newtab );
+ }
+}
+
+void OTabWidget::slotTabListSelected( int index )
+{
+ OTabInfo *newtab = tabs.at( index );
+ if ( newtab )
+ {
+ selectTab( newtab );
+ }
+}
+
+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( QString::null );
+ setUpLayout();
+ }
+ tabBar->tab( tab->id() )->setText( tab->label() );
+ currentTab = tab;
+ }
+ tabBar->setCurrentTab( tab->id() );
+ setUpLayout();
+ tabBar->update();
+
+ widgetStack->raiseWidget( tab->control() );
+}
+
+void OTabWidget::setUpLayout()
+{
+ tabBar->layoutTabs();
+ 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
+ {
+ 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 ( 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();
+}
diff --git a/libopie/otabwidget.h b/libopie/otabwidget.h
new file mode 100644
index 0000000..9f16f14
--- a/dev/null
+++ b/libopie/otabwidget.h
@@ -0,0 +1,232 @@
+/*
+                This file is part of the Opie Project
+
+              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 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
+
+#include "otabinfo.h"
+
+#include <qwidget.h>
+#include <qlist.h>
+
+class QComboBox;
+class QPixmap;
+class QTabBar;
+class QWidgetStack;
+
+/**
+ * @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 tabStyle()
+ * @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()
+ * @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 sizeHint()
+ * @brief Reimplemented for internal purposes.
+ */
+ QSize sizeHint() const;
+
+
+protected:
+
+/**
+ * @fn resizeEvent( QResizeEvent * )
+ * @brief Reimplemented for internal purposes.
+ */
+ void resizeEvent( QResizeEvent * );
+
+private:
+ OTabInfoList tabs;
+ OTabInfo *currentTab;
+
+ TabStyle tabBarStyle;
+ TabPosition tabBarPosition;
+
+ QWidgetStack *tabBarStack;
+ QTabBar *tabBar;
+ QComboBox *tabList;
+
+ QWidgetStack *widgetStack;
+
+/**
+ * @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();
+
+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