summaryrefslogtreecommitdiff
path: root/libopie2/opieui
Unidiff
Diffstat (limited to 'libopie2/opieui') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/otabbar.cpp50
-rw-r--r--libopie2/opieui/otabbar.h46
-rw-r--r--libopie2/opieui/otabwidget.cpp1
3 files changed, 50 insertions, 47 deletions
diff --git a/libopie2/opieui/otabbar.cpp b/libopie2/opieui/otabbar.cpp
index a62e18b..dc5df42 100644
--- a/libopie2/opieui/otabbar.cpp
+++ b/libopie2/opieui/otabbar.cpp
@@ -1,83 +1,87 @@
1/* 1/*
2                This file is part of the Opie Project 2 This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org> 4 Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7 .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8_;:, .> :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_, > . <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i, .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12- . .-<_> .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13 ._= =} : or (at your option) any later version.
14    .%`+i>       _;_. 14 .%`+i> _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15 .i_,=:_. -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17 : .. .:, . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.= = ; Library General Public License for more
21++=   -.     .`     .: details. 21++= -. .` .: details.
22 :     =  ...= . :.=- 22: = ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23-. .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24 -_. . . )=. = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25 -- :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#include <opie2/otabbar.h> 32#include <opie2/otabbar.h>
33 33
34#include <qpe/applnk.h>
35
36#include <stdio.h>
37
34using namespace Opie::Ui; 38using namespace Opie::Ui;
35 39
36OTabBar::OTabBar( QWidget *parent , const char *name ) 40OTabBar::OTabBar( QWidget *parent , const char *name )
37 :QTabBar( parent, name ) 41 :QTabBar( parent, name )
38{} 42{}
39 43
40void OTabBar::paintLabel( QPainter* p, const QRect& br, QTab* t, bool has_focus ) const 44void OTabBar::paintLabel( QPainter* p, const QRect& br, QTab* t, bool has_focus ) const
41{ 45{
42 46
43 QRect r = br; 47 QRect r = br;
44 if ( t->iconset) 48 if ( t->iconset)
45 { 49 {
46 QIconSet::Mode mode = (t->enabled && isEnabled()) ? QIconSet::Normal : QIconSet::Disabled; 50 QIconSet::Mode mode = (t->enabled && isEnabled()) ? QIconSet::Normal : QIconSet::Disabled;
47 if ( mode == QIconSet::Normal && has_focus ) 51 if ( mode == QIconSet::Normal && has_focus )
48 { 52 {
49 mode = QIconSet::Active; 53 mode = QIconSet::Active;
50 } 54 }
51 QPixmap pixmap = t->iconset->pixmap( QIconSet::Small, mode ); 55 QPixmap pixmap = t->iconset->pixmap();
52 int pixw = pixmap.width(); 56 int pixw = pixmap.width();
53 int pixh = pixmap.height(); 57 int pixh = pixmap.height();
54 r.setLeft( r.left() + pixw + 2 ); 58 r.setLeft( r.left() + pixw + 2 );
55 p->drawPixmap( br.left()+2, br.center().y()-pixh/2, pixmap ); 59 p->drawPixmap( br.left()+2, br.center().y()-pixh/2, pixmap );
56 } 60 }
57 61
58 QRect tr = r; 62 QRect tr = r;
59 if ( t->id == currentTab() ) 63 if ( t->id == currentTab() )
60 { 64 {
61 tr.setBottom( tr.bottom() - style().defaultFrameWidth() ); 65 tr.setBottom( tr.bottom() - style().defaultFrameWidth() );
62 } 66 }
63 67
64 if ( t->enabled && isEnabled() ) 68 if ( t->enabled && isEnabled() )
65 { 69 {
66 p->setPen( colorGroup().foreground() ); 70 p->setPen( colorGroup().foreground() );
67 p->drawText( tr, AlignCenter | ShowPrefix, t->label ); 71 p->drawText( tr, AlignCenter | ShowPrefix, t->label );
68 } 72 }
69 else if ( style() == MotifStyle ) 73 else if ( style() == MotifStyle )
70 { 74 {
71 p->setPen( palette().disabled().foreground() ); 75 p->setPen( palette().disabled().foreground() );
72 p->drawText( tr, AlignCenter | ShowPrefix, t->label ); 76 p->drawText( tr, AlignCenter | ShowPrefix, t->label );
73 } 77 }
74 else 78 else
75 { 79 {
76 p->setPen( colorGroup().light() ); 80 p->setPen( colorGroup().light() );
77 QRect wr = tr; 81 QRect wr = tr;
78 wr.moveBy( 1, 1 ); 82 wr.moveBy( 1, 1 );
79 p->drawText( wr, AlignCenter | ShowPrefix, t->label ); 83 p->drawText( wr, AlignCenter | ShowPrefix, t->label );
80 p->setPen( palette().disabled().foreground() ); 84 p->setPen( palette().disabled().foreground() );
81 p->drawText( tr, AlignCenter | ShowPrefix, t->label ); 85 p->drawText( tr, AlignCenter | ShowPrefix, t->label );
82 } 86 }
83} 87}
diff --git a/libopie2/opieui/otabbar.h b/libopie2/opieui/otabbar.h
index 925ae96..1044bdd 100644
--- a/libopie2/opieui/otabbar.h
+++ b/libopie2/opieui/otabbar.h
@@ -1,86 +1,86 @@
1/* 1/*
2                This file is part of the Opie Project 2 This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Dan Williams <williamsdr@acm.org> 4 Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7 .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8_;:, .> :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_, > . <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i, .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12- . .-<_> .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13 ._= =} : or (at your option) any later version.
14    .%`+i>       _;_. 14 .%`+i> _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15 .i_,=:_. -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17 : .. .:, . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.= = ; Library General Public License for more
21++=   -.     .`     .: details. 21++= -. .` .: details.
22 :     =  ...= . :.=- 22: = ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23-. .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24 -_. . . )=. = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25 -- :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#ifndef OTABBAR_H 32#ifndef OTABBAR_H
33#define OTABBAR_H 33#define OTABBAR_H
34 34
35/* QT */ 35/* QT */
36#include <qtabbar.h> 36#include <qtabbar.h>
37 37
38namespace Opie { 38namespace Opie {
39namespace Ui { 39namespace Ui {
40 40
41/** 41/**
42 * @class OTabBar 42 * @class OTabBar
43 * @brief The OTabBar class is a derivative of QTabBar. 43 * @brief The OTabBar class is a derivative of QTabBar.
44 * 44 *
45 * OTabBar is a derivation of TrollTech's QTabBar which provides 45 * OTabBar is a derivation of TrollTech's QTabBar which provides
46 * a row of tabs for selection. The only difference between this 46 * a row of tabs for selection. The only difference between this
47 * class and QTabBar is that there is no dotted line box around 47 * class and QTabBar is that there is no dotted line box around
48 * the label of the tab with the current focus. 48 * the label of the tab with the current focus.
49 */ 49 */
50class OTabBar : public QTabBar 50class OTabBar : public QTabBar
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54public: 54public:
55 /** 55 /**
56 * @fn OTabBar( QWidget *parent = 0, const char *name = 0 ) 56 * @fn OTabBar( QWidget *parent = 0, const char *name = 0 )
57 * @brief Object constructor. 57 * @brief Object constructor.
58 * 58 *
59 * @param parent Pointer to parent of this control. 59 * @param parent Pointer to parent of this control.
60 * @param name Name of control. 60 * @param name Name of control.
61 * 61 *
62 * Constructs a new OTabBar control with parent and name. 62 * Constructs a new OTabBar control with parent and name.
63 */ 63 */
64 OTabBar( QWidget * = 0, const char * = 0 ); 64 OTabBar( QWidget * = 0, const char * = 0 );
65 65
66protected: 66protected:
67 /** 67 /**
68 * @fn paintLabel( QPainter* p, const QRect& br , QTab* t, bool has_focus)const 68 * @fn paintLabel( QPainter* p, const QRect& br , QTab* t, bool has_focus)const
69 * @brief Internal function to draw a tab's label. 69 * @brief Internal function to draw a tab's label.
70 * 70 *
71 * @param p Pointer to QPainter used for drawing. 71 * @param p Pointer to QPainter used for drawing.
72 * @param br QRect providing region to draw label in. 72 * @param br QRect providing region to draw label in.
73 * @param t Tab to draw label for. 73 * @param t Tab to draw label for.
74 * @param has_focus Boolean value not used, retained for compatibility reasons. 74 * @param has_focus Boolean value not used, retained for compatibility reasons.
75 */ 75 */
76 void paintLabel( QPainter *, const QRect &, QTab *, bool ) const; 76 void paintLabel( QPainter *, const QRect &, QTab *, bool ) const;
77 77
78private: 78private:
79 class Private; 79 class Private;
80 Private *d; 80 Private *d;
81}; 81};
82 82
83} 83}
84} 84}
85 85
86#endif 86#endif
diff --git a/libopie2/opieui/otabwidget.cpp b/libopie2/opieui/otabwidget.cpp
index 7333f5e..d617a9c 100644
--- a/libopie2/opieui/otabwidget.cpp
+++ b/libopie2/opieui/otabwidget.cpp
@@ -1,421 +1,420 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4 Copyright (C) 2002, 2005 Dan Williams <drw@handhelds.org> 4 Copyright (C) 2002, 2005 Dan Williams <drw@handhelds.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17 : ..    .:,     . . . without even the implied warranty of 17 : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <opie2/otabwidget.h> 31#include <opie2/otabwidget.h>
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/oresource.h> 34#include <opie2/oresource.h>
35#include <opie2/otabbar.h> 35#include <opie2/otabbar.h>
36 36
37#include <qpe/applnk.h>
38#include <qpe/config.h> 37#include <qpe/config.h>
39 38
40/* QT */ 39/* QT */
41#include <qcombobox.h> 40#include <qcombobox.h>
42#include <qwidgetstack.h> 41#include <qwidgetstack.h>
43 42
44using namespace Opie::Ui; 43using namespace Opie::Ui;
45 44
46OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p ) 45OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p )
47 : QWidget( parent, name ) 46 : QWidget( parent, name )
48 , m_currTab( 0l ) 47 , m_currTab( 0l )
49 , m_tabBarStyle( Global ) 48 , m_tabBarStyle( Global )
50 , m_tabBarPosition( Top ) 49 , m_tabBarPosition( Top )
51 , m_usingTabs( true ) 50 , m_usingTabs( true )
52 , m_tabBar( 0l ) 51 , m_tabBar( 0l )
53 , m_tabList( 0l ) 52 , m_tabList( 0l )
54{ 53{
55 if ( s == Global ) 54 if ( s == Global )
56 { 55 {
57 // Read Opie global settings for style and position 56 // Read Opie global settings for style and position
58 Config config( "qpe" ); 57 Config config( "qpe" );
59 config.setGroup( "Appearance" ); 58 config.setGroup( "Appearance" );
60 59
61 // Style 60 // Style
62 s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); 61 s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab );
63 if ( s <= Global || s > IconList) 62 if ( s <= Global || s > IconList)
64 s = IconTab; 63 s = IconTab;
65 64
66 // Position 65 // Position
67 ( config.readEntry( "TabPosition", "Top" ) == "Bottom" ) ? p = Bottom 66 ( config.readEntry( "TabPosition", "Top" ) == "Bottom" ) ? p = Bottom
68 : p = Top; 67 : p = Top;
69 } 68 }
70 69
71 // Initialize widget stack for tab widgets 70 // Initialize widget stack for tab widgets
72 m_widgetStack = new QWidgetStack( this ); 71 m_widgetStack = new QWidgetStack( this );
73 m_widgetStack->setFrameStyle( QFrame::NoFrame ); 72 m_widgetStack->setFrameStyle( QFrame::NoFrame );
74 m_widgetStack->setLineWidth( style().defaultFrameWidth() ); 73 m_widgetStack->setLineWidth( style().defaultFrameWidth() );
75 74
76 // Set initial selector control style and position 75 // Set initial selector control style and position
77 setTabStyle( s ); 76 setTabStyle( s );
78 setTabPosition( p ); 77 setTabPosition( p );
79} 78}
80 79
81OTabWidget::~OTabWidget() 80OTabWidget::~OTabWidget()
82{ 81{
83 m_tabs.setAutoDelete( true ); 82 m_tabs.setAutoDelete( true );
84 m_tabs.clear(); 83 m_tabs.clear();
85} 84}
86 85
87void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) 86void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
88{ 87{
89 int tabid = -1; 88 int tabid = -1;
90 89
91 if ( m_usingTabs ) 90 if ( m_usingTabs )
92 { 91 {
93 // Create new tab in tab bar 92 // Create new tab in tab bar
94 QTab *tab = new QTab(); 93 QTab *tab = new QTab();
95 94
96 // Set label (and icon if necessary) 95 // Set label (and icon if necessary)
97 if ( m_tabBarStyle == IconTab ) 96 if ( m_tabBarStyle == IconTab )
98 { 97 {
99 tab->label = QString::null; 98 tab->label = QString::null;
100 tab->iconset = new QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ); 99 tab->iconset = new QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) );
101 } 100 }
102 else 101 else
103 tab->label = label; 102 tab->label = label;
104 103
105 tabid = m_tabBar->addTab( tab ); 104 tabid = m_tabBar->addTab( tab );
106 } 105 }
107 else 106 else
108 { 107 {
109 // Insert entry (with icon if necessary) into drop down list 108 // Insert entry (with icon if necessary) into drop down list
110 if ( m_tabBarStyle == IconList ) 109 if ( m_tabBarStyle == IconList )
111 m_tabList->insertItem( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ), label, -1 ); 110 m_tabList->insertItem( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ), label, -1 );
112 else 111 else
113 m_tabList->insertItem( label ); 112 m_tabList->insertItem( label );
114 } 113 }
115 114
116 // Add widget to stack 115 // Add widget to stack
117 m_widgetStack->addWidget( child, tabid ); 116 m_widgetStack->addWidget( child, tabid );
118 m_widgetStack->raiseWidget( child ); 117 m_widgetStack->raiseWidget( child );
119 m_widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); 118 m_widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
120 119
121 // Keep track of tab information 120 // Keep track of tab information
122 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); 121 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label );
123 m_tabs.append( tabinfo ); 122 m_tabs.append( tabinfo );
124 123
125 // Make newly added tab the current one displayed 124 // Make newly added tab the current one displayed
126 selectTab( tabinfo ); 125 selectTab( tabinfo );
127} 126}
128 127
129void OTabWidget::removePage( QWidget *childwidget ) 128void OTabWidget::removePage( QWidget *childwidget )
130{ 129{
131 if ( childwidget ) 130 if ( childwidget )
132 { 131 {
133 // Find tab information for desired widget 132 // Find tab information for desired widget
134 OTabInfo *tab = m_tabs.first(); 133 OTabInfo *tab = m_tabs.first();
135 while ( tab && tab->control() != childwidget ) 134 while ( tab && tab->control() != childwidget )
136 tab = m_tabs.next(); 135 tab = m_tabs.next();
137 136
138 if ( tab && tab->control() == childwidget ) 137 if ( tab && tab->control() == childwidget )
139 { 138 {
140 if ( m_usingTabs ) 139 if ( m_usingTabs )
141 { 140 {
142 // Remove tab from tab bar 141 // Remove tab from tab bar
143 m_tabBar->setTabEnabled( tab->id(), false ); 142 m_tabBar->setTabEnabled( tab->id(), false );
144 m_tabBar->removeTab( m_tabBar->tab( tab->id() ) ); 143 m_tabBar->removeTab( m_tabBar->tab( tab->id() ) );
145 } 144 }
146 else 145 else
147 { 146 {
148 // Remove entry from drop down list 147 // Remove entry from drop down list
149 int i = 0; 148 int i = 0;
150 while ( i < m_tabList->count() && m_tabList->text( i ) != tab->label() ) 149 while ( i < m_tabList->count() && m_tabList->text( i ) != tab->label() )
151 i++; 150 i++;
152 if ( m_tabList->text( i ) == tab->label() ) 151 if ( m_tabList->text( i ) == tab->label() )
153 m_tabList->removeItem( i ); 152 m_tabList->removeItem( i );
154 } 153 }
155 154
156 // Remove widget from stack 155 // Remove widget from stack
157 m_widgetStack->removeWidget( childwidget ); 156 m_widgetStack->removeWidget( childwidget );
158 157
159 // Get rid of tab information 158 // Get rid of tab information
160 m_tabs.remove( tab ); 159 m_tabs.remove( tab );
161 delete tab; 160 delete tab;
162 161
163 // Reset current tab 162 // Reset current tab
164 m_currTab = m_tabs.current(); 163 m_currTab = m_tabs.current();
165 if ( !m_currTab ) 164 if ( !m_currTab )
166 m_widgetStack->setFrameStyle( QFrame::NoFrame ); 165 m_widgetStack->setFrameStyle( QFrame::NoFrame );
167 166
168 // Redraw widget 167 // Redraw widget
169 setUpLayout(); 168 setUpLayout();
170 } 169 }
171 } 170 }
172} 171}
173 172
174void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) 173void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label)
175{ 174{
176 // Find tab information for desired widget 175 // Find tab information for desired widget
177 OTabInfo *currtab = m_tabs.first(); 176 OTabInfo *currtab = m_tabs.first();
178 while ( currtab && currtab->control() != widget ) 177 while ( currtab && currtab->control() != widget )
179 currtab = m_tabs.next(); 178 currtab = m_tabs.next();
180 179
181 if ( currtab && currtab->control() == widget ) 180 if ( currtab && currtab->control() == widget )
182 { 181 {
183 QPixmap icon( Opie::Core::OResource::loadPixmap( iconset, Opie::Core::OResource::SmallIcon ) ); 182 QPixmap icon( Opie::Core::OResource::loadPixmap( iconset, Opie::Core::OResource::SmallIcon ) );
184 183
185 if ( m_usingTabs ) 184 if ( m_usingTabs )
186 { 185 {
187 // Update tab label and icon (if necessary) 186 // Update tab label and icon (if necessary)
188 QTab *tab = m_tabBar->tab( currtab->id() ); 187 QTab *tab = m_tabBar->tab( currtab->id() );
189 tab->setText( label ); 188 tab->setText( label );
190 if ( m_tabBarStyle == IconTab ) 189 if ( m_tabBarStyle == IconTab )
191 tab->setIconSet( icon ); 190 tab->setIconSet( icon );
192 } 191 }
193 else 192 else
194 { 193 {
195 // Update entry label and icon (if necessary) 194 // Update entry label and icon (if necessary)
196 int i = 0; 195 int i = 0;
197 while ( i < m_tabList->count() && m_tabList->text( i ) != currtab->label() ) 196 while ( i < m_tabList->count() && m_tabList->text( i ) != currtab->label() )
198 i++; 197 i++;
199 if ( i < m_tabList->count() && m_tabList->text( i ) == currtab->label() ) 198 if ( i < m_tabList->count() && m_tabList->text( i ) == currtab->label() )
200 { 199 {
201 if ( m_tabBarStyle == IconList ) 200 if ( m_tabBarStyle == IconList )
202 m_tabList->changeItem( icon, label, i ); 201 m_tabList->changeItem( icon, label, i );
203 else 202 else
204 m_tabList->changeItem( label, i ); 203 m_tabList->changeItem( label, i );
205 } 204 }
206 } 205 }
207 206
208 // Update tab information 207 // Update tab information
209 currtab->setLabel( label ); 208 currtab->setLabel( label );
210 currtab->setIcon( iconset ); 209 currtab->setIcon( iconset );
211 210
212 // Redraw widget 211 // Redraw widget
213 setUpLayout(); 212 setUpLayout();
214 } 213 }
215} 214}
216 215
217void OTabWidget::setCurrentTab( QWidget *childwidget ) 216void OTabWidget::setCurrentTab( QWidget *childwidget )
218{ 217{
219 OTabInfo *currtab = m_tabs.first(); 218 OTabInfo *currtab = m_tabs.first();
220 while ( currtab && currtab->control() != childwidget ) 219 while ( currtab && currtab->control() != childwidget )
221 { 220 {
222 currtab = m_tabs.next(); 221 currtab = m_tabs.next();
223 } 222 }
224 if ( currtab && currtab->control() == childwidget ) 223 if ( currtab && currtab->control() == childwidget )
225 { 224 {
226 selectTab( currtab ); 225 selectTab( currtab );
227 } 226 }
228} 227}
229 228
230void OTabWidget::setCurrentTab( const QString &tabname ) 229void OTabWidget::setCurrentTab( const QString &tabname )
231{ 230{
232 OTabInfo *newtab = m_tabs.first(); 231 OTabInfo *newtab = m_tabs.first();
233 while ( newtab && newtab->label() != tabname ) 232 while ( newtab && newtab->label() != tabname )
234 { 233 {
235 newtab = m_tabs.next(); 234 newtab = m_tabs.next();
236 } 235 }
237 if ( newtab && newtab->label() == tabname ) 236 if ( newtab && newtab->label() == tabname )
238 { 237 {
239 selectTab( newtab ); 238 selectTab( newtab );
240 } 239 }
241} 240}
242 241
243void OTabWidget::setCurrentTab(int tabindex) 242void OTabWidget::setCurrentTab(int tabindex)
244{ 243{
245 OTabInfo *newtab = m_tabs.first(); 244 OTabInfo *newtab = m_tabs.first();
246 while ( newtab && newtab->id() != tabindex ) 245 while ( newtab && newtab->id() != tabindex )
247 { 246 {
248 newtab = m_tabs.next(); 247 newtab = m_tabs.next();
249 } 248 }
250 if ( newtab && newtab->id() == tabindex ) 249 if ( newtab && newtab->id() == tabindex )
251 { 250 {
252 selectTab( newtab ); 251 selectTab( newtab );
253 } 252 }
254} 253}
255 254
256 255
257OTabWidget::TabStyle OTabWidget::tabStyle() const 256OTabWidget::TabStyle OTabWidget::tabStyle() const
258{ 257{
259 return m_tabBarStyle; 258 return m_tabBarStyle;
260} 259}
261 260
262void OTabWidget::setTabStyle( TabStyle s ) 261void OTabWidget::setTabStyle( TabStyle s )
263{ 262{
264 // Get out if new and current styles are the same 263 // Get out if new and current styles are the same
265 if ( s == m_tabBarStyle ) 264 if ( s == m_tabBarStyle )
266 return; 265 return;
267 266
268 // Delete current selector control 267 // Delete current selector control
269 if ( m_usingTabs ) 268 if ( m_usingTabs )
270 { 269 {
271 delete m_tabBar; 270 delete m_tabBar;
272 m_tabBar = 0l; 271 m_tabBar = 0l;
273 } 272 }
274 else 273 else
275 { 274 {
276 delete m_tabList; 275 delete m_tabList;
277 m_tabList = 0l; 276 m_tabList = 0l;
278 } 277 }
279 278
280 // Set new style information 279 // Set new style information
281 m_tabBarStyle = s; 280 m_tabBarStyle = s;
282 m_usingTabs = ( m_tabBarStyle == TextTab || m_tabBarStyle == IconTab ); 281 m_usingTabs = ( m_tabBarStyle == TextTab || m_tabBarStyle == IconTab );
283 282
284 // Create new selector control and populate with tab information 283 // Create new selector control and populate with tab information
285 if ( m_usingTabs ) 284 if ( m_usingTabs )
286 { 285 {
287 // Create new tab bar selector 286 // Create new tab bar selector
288 m_tabBar = new OTabBar( this ); 287 m_tabBar = new OTabBar( this );
289 connect( m_tabBar, SIGNAL(selected(int)), this, SLOT(slotTabBarSelected(int)) ); 288 connect( m_tabBar, SIGNAL(selected(int)), this, SLOT(slotTabBarSelected(int)) );
290 289
291 // Add all current tabs to tab bar 290 // Add all current tabs to tab bar
292 for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() ) 291 for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() )
293 { 292 {
294 // Create new tab in tab bar 293 // Create new tab in tab bar
295 QTab *tab = new QTab(); 294 QTab *tab = new QTab();
296 295
297 // Set label (and icon if necessary) 296 // Set label (and icon if necessary)
298 if ( m_tabBarStyle == IconTab ) 297 if ( m_tabBarStyle == IconTab )
299 { 298 {
300 tab->label = QString::null; 299 tab->label = QString::null;
301 tab->iconset = new QIconSet( Opie::Core::OResource::loadPixmap( tabinfo->icon(), Opie::Core::OResource::SmallIcon ) ); 300 tab->iconset = new QIconSet( Opie::Core::OResource::loadPixmap( tabinfo->icon(), Opie::Core::OResource::SmallIcon ) );
302 } 301 }
303 else 302 else
304 tab->label = tabinfo->label(); 303 tab->label = tabinfo->label();
305 304
306 // Add tab and save its Id 305 // Add tab and save its Id
307 int tabid = m_tabBar->addTab( tab ); 306 int tabid = m_tabBar->addTab( tab );
308 tabinfo->setId( tabid ); 307 tabinfo->setId( tabid );
309 } 308 }
310 } 309 }
311 else 310 else
312 { 311 {
313 // Create new drop down list selector 312 // Create new drop down list selector
314 m_tabList = new QComboBox( false, this ); 313 m_tabList = new QComboBox( false, this );
315 connect( m_tabList, SIGNAL(activated(int)), this, SLOT(slotTabListSelected(int)) ); 314 connect( m_tabList, SIGNAL(activated(int)), this, SLOT(slotTabListSelected(int)) );
316 315
317 // Add all current tabs to drop down list 316 // Add all current tabs to drop down list
318 for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() ) 317 for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() )
319 { 318 {
320 if ( m_tabBarStyle == IconList ) 319 if ( m_tabBarStyle == IconList )
321 m_tabList->insertItem( Opie::Core::OResource::loadPixmap( tabinfo->icon(), Opie::Core::OResource::SmallIcon ), 320 m_tabList->insertItem( Opie::Core::OResource::loadPixmap( tabinfo->icon(), Opie::Core::OResource::SmallIcon ),
322 tabinfo->label() ); 321 tabinfo->label() );
323 else 322 else
324 m_tabList->insertItem( tabinfo->label() ); 323 m_tabList->insertItem( tabinfo->label() );
325 } 324 }
326 } 325 }
327 326
328 // Redraw widget 327 // Redraw widget
329 setUpLayout(); 328 setUpLayout();
330} 329}
331 330
332OTabWidget::TabPosition OTabWidget::tabPosition() const 331OTabWidget::TabPosition OTabWidget::tabPosition() const
333{ 332{
334 return m_tabBarPosition; 333 return m_tabBarPosition;
335} 334}
336 335
337void OTabWidget::setTabPosition( TabPosition p ) 336void OTabWidget::setTabPosition( TabPosition p )
338{ 337{
339 m_tabBarPosition = p; 338 m_tabBarPosition = p;
340 339
341 // If using the tab bar selector, set its shape 340 // If using the tab bar selector, set its shape
342 if ( m_usingTabs ) 341 if ( m_usingTabs )
343 { 342 {
344 ( m_tabBarPosition == Top ) ? m_tabBar->setShape( QTabBar::RoundedAbove ) 343 ( m_tabBarPosition == Top ) ? m_tabBar->setShape( QTabBar::RoundedAbove )
345 : m_tabBar->setShape( QTabBar::RoundedBelow ); 344 : m_tabBar->setShape( QTabBar::RoundedBelow );
346 } 345 }
347 346
348 // Redraw widget 347 // Redraw widget
349 setUpLayout(); 348 setUpLayout();
350} 349}
351 350
352void OTabWidget::slotTabBarSelected( int id ) 351void OTabWidget::slotTabBarSelected( int id )
353{ 352{
354 OTabInfo *newtab = m_tabs.first(); 353 OTabInfo *newtab = m_tabs.first();
355 while ( newtab && newtab->id() != id ) 354 while ( newtab && newtab->id() != id )
356 newtab = m_tabs.next(); 355 newtab = m_tabs.next();
357 356
358 if ( newtab && newtab->id() == id ) 357 if ( newtab && newtab->id() == id )
359 selectTab( newtab ); 358 selectTab( newtab );
360} 359}
361 360
362void OTabWidget::slotTabListSelected( int index ) 361void OTabWidget::slotTabListSelected( int index )
363{ 362{
364 OTabInfo *newtab = m_tabs.at( index ); 363 OTabInfo *newtab = m_tabs.at( index );
365 if ( newtab ) 364 if ( newtab )
366 selectTab( newtab ); 365 selectTab( newtab );
367} 366}
368 367
369void OTabWidget::selectTab( OTabInfo *tab ) 368void OTabWidget::selectTab( OTabInfo *tab )
370{ 369{
371 if ( m_tabBarStyle == IconTab ) 370 if ( m_tabBarStyle == IconTab )
372 { 371 {
373 // Remove text label from currently selected tab 372 // Remove text label from currently selected tab
374 if ( m_currTab ) 373 if ( m_currTab )
375 { 374 {
376 m_tabBar->tab( m_currTab->id() )->setText( QString::null ); 375 m_tabBar->tab( m_currTab->id() )->setText( QString::null );
377 //setUpLayout(); 376 //setUpLayout();
378 } 377 }
379 378
380 // Set text label for newly selected tab 379 // Set text label for newly selected tab
381 m_tabBar->tab( tab->id() )->setText( tab->label() ); 380 m_tabBar->tab( tab->id() )->setText( tab->label() );
382 m_tabBar->setCurrentTab( tab->id() ); 381 m_tabBar->setCurrentTab( tab->id() );
383 382
384 setUpLayout(); 383 setUpLayout();
385 384
386 QSize t; 385 QSize t;
387 386
388 t = m_tabBar->sizeHint(); 387 t = m_tabBar->sizeHint();
389 if ( t.width() > width() ) 388 if ( t.width() > width() )
390 t.setWidth( width() ); 389 t.setWidth( width() );
391 int lw = m_widgetStack->lineWidth(); 390 int lw = m_widgetStack->lineWidth();
392 if ( m_tabBarPosition == Bottom ) 391 if ( m_tabBarPosition == Bottom )
393 m_tabBar->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); 392 m_tabBar->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() );
394 else 393 else
395 m_tabBar->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); 394 m_tabBar->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() );
396 } 395 }
397 else if ( m_tabBarStyle == TextTab ) 396 else if ( m_tabBarStyle == TextTab )
398 { 397 {
399 m_tabBar->setCurrentTab( tab->id() ); 398 m_tabBar->setCurrentTab( tab->id() );
400 } 399 }
401 400
402 m_widgetStack->raiseWidget( tab->control() ); 401 m_widgetStack->raiseWidget( tab->control() );
403 402
404 emit currentChanged( tab->control() ); 403 emit currentChanged( tab->control() );
405 404
406 m_currTab = tab; 405 m_currTab = tab;
407} 406}
408 407
409void OTabWidget::setUpLayout() 408void OTabWidget::setUpLayout()
410{ 409{
411 if ( m_usingTabs ) 410 if ( m_usingTabs )
412 { 411 {
413 m_tabBar->update(); 412 m_tabBar->update();
414 m_tabBar->layoutTabs(); 413 m_tabBar->layoutTabs();
415 } 414 }
416} 415}
417 416
418void OTabWidget::resizeEvent( QResizeEvent * ) 417void OTabWidget::resizeEvent( QResizeEvent * )
419{ 418{
420 QSize t; 419 QSize t;
421 420