-rw-r--r-- | libopie2/opieui/otabinfo.h | 50 | ||||
-rw-r--r-- | libopie2/opieui/otabwidget.cpp | 440 | ||||
-rw-r--r-- | libopie2/opieui/otabwidget.h | 69 |
3 files changed, 301 insertions, 258 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 @@ | |||
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 OTABINFO_H | 32 | #ifndef OTABINFO_H |
33 | #define OTABINFO_H | 33 | #define OTABINFO_H |
34 | 34 | ||
35 | /* QT */ | 35 | /* QT */ |
36 | #include <qlist.h> | 36 | #include <qlist.h> |
37 | #include <qstring.h> | 37 | #include <qstring.h> |
38 | 38 | ||
39 | class QWidget; | 39 | class QWidget; |
40 | 40 | ||
41 | namespace Opie{ | 41 | namespace Opie{ |
42 | namespace Ui { | 42 | namespace Ui { |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * @class OTabInfo | 45 | * @class OTabInfo |
46 | * @brief The OTabInfo class is used internally by OTabWidget to keep track | 46 | * @brief The OTabInfo class is used internally by OTabWidget to keep track |
47 | * of widgets added to the control. | 47 | * of widgets added to the control. |
48 | * | 48 | * |
49 | * OTabInfo provides the following information about a widget added to an | 49 | * OTabInfo provides the following information about a widget added to an |
50 | * OTabWidget control: | 50 | * OTabWidget control: |
51 | * | 51 | * |
52 | * ID - integer tab bar ID | 52 | * ID - integer tab bar ID |
53 | * Control - QWidget pointer to child widget | 53 | * Control - QWidget pointer to child widget |
54 | * Label - QString text label for OTabWidget selection control | 54 | * Label - QString text label for OTabWidget selection control |
55 | * Icon - QString name of icon file | 55 | * Icon - QString name of icon file |
56 | */ | 56 | */ |
57 | class OTabInfo | 57 | class OTabInfo |
58 | { | 58 | { |
59 | public: | 59 | public: |
60 | /** | 60 | /** |
61 | * @fn OTabInfo() | 61 | * @fn OTabInfo() |
62 | * @brief Object constructor. | 62 | * @brief Object constructor. |
63 | */ | 63 | */ |
64 | OTabInfo() : i( -1 ), c( 0 ), p( 0 ), l( QString::null ) {} | 64 | OTabInfo() : i( -1 ), c( 0 ), p( 0 ), l( QString::null ) {} |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * @fn OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) | 67 | * @fn OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) |
68 | * @brief Object constructor. | 68 | * @brief Object constructor. |
69 | * | 69 | * |
70 | * @param id TabBar identifier for widget. | 70 | * @param id TabBar identifier for widget. |
71 | * @param control QWidget pointer to widget. | 71 | * @param control QWidget pointer to widget. |
72 | * @param icon QString name of icon file. | 72 | * @param icon QString name of icon file. |
73 | * @param label QString text label for OTabWidget selection control. | 73 | * @param label QString text label for OTabWidget selection control. |
74 | */ | 74 | */ |
75 | OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) | 75 | OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) |
76 | : i( id ), c( control ), p( icon ), l( label ) {} | 76 | : i( id ), c( control ), p( icon ), l( label ) {} |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * @fn id()const | 79 | * @fn id()const |
80 | * @brief Returns TabBar ID. | 80 | * @brief Returns TabBar ID. |
81 | */ | 81 | */ |
82 | int id() const { return i; } | 82 | int id() const { return i; } |
83 | 83 | ||
84 | /** | 84 | /** |
85 | * @fn setId( int id ) | ||
86 | * @brief Set Id for tab. | ||
87 | * | ||
88 | * @param id integer tab identifier. | ||
89 | */ | ||
90 | void setId( int id ) { i = id; } | ||
91 | |||
92 | /** | ||
85 | * @fn label()const | 93 | * @fn label()const |
86 | * @brief Returns text label for widget. | 94 | * @brief Returns text label for widget. |
87 | */ | 95 | */ |
88 | const QString &label() const { return l; } | 96 | const QString &label() const { return l; } |
89 | 97 | ||
90 | /** | 98 | /** |
91 | * @fn setLabel( const QString &label ) | 99 | * @fn setLabel( const QString &label ) |
92 | * @brief Set label for tab. | 100 | * @brief Set label for tab. |
93 | * | 101 | * |
94 | * @param label QString text label for OTabWidget selection control. | 102 | * @param label QString text label for OTabWidget selection control. |
95 | */ | 103 | */ |
96 | void setLabel( const QString &label ) { l = label; } | 104 | void setLabel( const QString &label ) { l = label; } |
97 | 105 | ||
98 | /** | 106 | /** |
99 | * @fn control()const | 107 | * @fn control()const |
100 | * @brief Returns pointer to widget. | 108 | * @brief Returns pointer to widget. |
101 | */ | 109 | */ |
102 | QWidget *control() const { return c; } | 110 | QWidget *control() const { return c; } |
103 | 111 | ||
104 | /** | 112 | /** |
105 | * @fn icon()const | 113 | * @fn icon()const |
106 | * @brief Returns name of icon file. | 114 | * @brief Returns name of icon file. |
107 | */ | 115 | */ |
108 | const QString &icon() const { return p; } | 116 | const QString &icon() const { return p; } |
109 | 117 | ||
110 | /** | 118 | /** |
111 | * @fn setIcon( const QString &icon ) | 119 | * @fn setIcon( const QString &icon ) |
112 | * @brief Set icon for tab. | 120 | * @brief Set icon for tab. |
113 | * | 121 | * |
114 | * @param icon QString name of icon file. | 122 | * @param icon QString name of icon file. |
115 | */ | 123 | */ |
116 | void setIcon( const QString &icon ) { p = icon; } | 124 | void setIcon( const QString &icon ) { p = icon; } |
117 | 125 | ||
118 | private: | 126 | private: |
119 | int i; | 127 | int i; |
120 | QWidget *c; | 128 | QWidget *c; |
121 | QString p; | 129 | QString p; |
122 | QString l; | 130 | QString l; |
123 | class Private; | 131 | class Private; |
124 | Private *d; | 132 | Private *d; |
125 | }; | 133 | }; |
126 | 134 | ||
127 | /** | 135 | /** |
128 | * @class OTabInfoList | 136 | * @class OTabInfoList |
129 | * @brief A list of OTabInfo objects used by OTabWidget. | 137 | * @brief A list of OTabInfo objects used by OTabWidget. |
130 | */ | 138 | */ |
131 | typedef QList<OTabInfo> OTabInfoList; | 139 | typedef QList<OTabInfo> OTabInfoList; |
132 | 140 | ||
133 | } | 141 | } |
134 | } | 142 | } |
135 | 143 | ||
136 | #endif | 144 | #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 @@ | |||
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, 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 | 31 | ||
32 | #include <opie2/otabwidget.h> | 32 | #include <opie2/otabwidget.h> |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | #include <qpe/applnk.h> | 35 | #include <qpe/applnk.h> |
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | #include <qpe/resource.h> | 37 | #include <qpe/resource.h> |
38 | #include <opie2/otabbar.h> | 38 | #include <opie2/otabbar.h> |
39 | 39 | ||
40 | /* QT */ | 40 | /* QT */ |
41 | #include <qcombobox.h> | 41 | #include <qcombobox.h> |
42 | #include <qwidgetstack.h> | 42 | #include <qwidgetstack.h> |
43 | 43 | ||
44 | using namespace Opie::Ui; | 44 | using namespace Opie::Ui; |
45 | 45 | ||
46 | OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p ) | 46 | OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p ) |
47 | : QWidget( parent, name ) | 47 | : QWidget( parent, name ) |
48 | , m_currTab( 0l ) | ||
49 | , m_usingTabs( true ) | ||
50 | , m_tabBar( 0l ) | ||
51 | , m_tabList( 0l ) | ||
48 | { | 52 | { |
49 | if ( s == Global ) | 53 | if ( s == Global ) |
50 | { | 54 | { |
55 | // Read Opie global settings for style and position | ||
51 | Config config( "qpe" ); | 56 | Config config( "qpe" ); |
52 | config.setGroup( "Appearance" ); | 57 | config.setGroup( "Appearance" ); |
58 | |||
59 | // Style | ||
53 | s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); | 60 | s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); |
54 | if ( s <= Global || s > IconList) | 61 | if ( s <= Global || s > IconList) |
55 | { | ||
56 | s = IconTab; | 62 | s = IconTab; |
57 | } | ||
58 | QString pos = config.readEntry( "TabPosition", "Top"); | ||
59 | if ( pos == "Bottom" ) | ||
60 | { | ||
61 | p = Bottom; | ||
62 | } | ||
63 | else | ||
64 | { | ||
65 | p = Top; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | widgetStack = new QWidgetStack( this, "widgetstack" ); | ||
70 | widgetStack->setFrameStyle( QFrame::NoFrame ); | ||
71 | widgetStack->setLineWidth( style().defaultFrameWidth() ); | ||
72 | |||
73 | tabBarStack = new QWidgetStack( this, "tabbarstack" ); | ||
74 | 63 | ||
75 | tabBar = new OTabBar( tabBarStack, "tabbar" ); | 64 | // Position |
76 | tabBarStack->addWidget( tabBar, 0 ); | 65 | ( config.readEntry( "TabPosition", "Top" ) == "Bottom" ) ? p = Bottom |
77 | connect( tabBar, SIGNAL( selected(int) ), this, SLOT( slotTabBarSelected(int) ) ); | 66 | : p = Top; |
67 | } | ||
78 | 68 | ||
79 | tabList = new QComboBox( false, tabBarStack, "tablist" ); | 69 | // Initialize widget stack for tab widgets |
80 | tabBarStack->addWidget( tabList, 1 ); | 70 | m_widgetStack = new QWidgetStack( this ); |
81 | connect( tabList, SIGNAL( activated(int) ), this, SLOT( slotTabListSelected(int) ) ); | 71 | m_widgetStack->setFrameStyle( QFrame::NoFrame ); |
72 | m_widgetStack->setLineWidth( style().defaultFrameWidth() ); | ||
82 | 73 | ||
83 | tabBarPosition = p; | 74 | // Set initial selector control style and position |
84 | setTabStyle( s ); | 75 | setTabStyle( s ); |
85 | setTabPosition( p ); | 76 | setTabPosition( p ); |
86 | |||
87 | currTab= 0x0; | ||
88 | } | 77 | } |
89 | 78 | ||
90 | OTabWidget::~OTabWidget() | 79 | OTabWidget::~OTabWidget() |
91 | { | 80 | { |
92 | tabs.setAutoDelete( true ); | 81 | m_tabs.setAutoDelete( true ); |
93 | tabs.clear(); | 82 | m_tabs.clear(); |
94 | } | 83 | } |
95 | 84 | ||
96 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) | 85 | void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) |
97 | { | 86 | { |
98 | QPixmap iconset = loadSmooth( icon ); | 87 | int tabid = -1; |
99 | 88 | ||
100 | QTab *tab = new QTab(); | 89 | if ( m_usingTabs ) |
101 | if ( tabBarStyle == IconTab ) | ||
102 | { | ||
103 | tab->label = QString::null; | ||
104 | } | ||
105 | else | ||
106 | { | ||
107 | tab->label = label; | ||
108 | } | ||
109 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) | ||
110 | { | 90 | { |
111 | tab->iconset = new QIconSet( iconset ); | 91 | // Create new tab in tab bar |
112 | } | 92 | QTab *tab = new QTab(); |
113 | int tabid = tabBar->addTab( tab ); | ||
114 | 93 | ||
115 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) | 94 | // Set label (and icon if necessary) |
116 | { | 95 | if ( m_tabBarStyle == IconTab ) |
117 | tabList->insertItem( iconset, label, -1 ); | 96 | { |
97 | tab->label = QString::null; | ||
98 | tab->iconset = new QIconSet( loadSmooth( icon ) ); | ||
99 | } | ||
100 | else | ||
101 | tab->label = label; | ||
102 | |||
103 | tabid = m_tabBar->addTab( tab ); | ||
118 | } | 104 | } |
119 | else | 105 | else |
120 | { | 106 | { |
121 | tabList->insertItem( label ); | 107 | // Insert entry (with icon if necessary) into drop down list |
108 | if ( m_tabBarStyle == IconList ) | ||
109 | m_tabList->insertItem( loadSmooth( icon ), label, -1 ); | ||
110 | else | ||
111 | m_tabList->insertItem( label ); | ||
122 | } | 112 | } |
123 | 113 | ||
124 | widgetStack->addWidget( child, tabid ); | 114 | // Add widget to stack |
125 | widgetStack->raiseWidget( child ); | 115 | m_widgetStack->addWidget( child, tabid ); |
126 | widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); | 116 | m_widgetStack->raiseWidget( child ); |
117 | m_widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); | ||
127 | 118 | ||
119 | // Keep track of tab information | ||
128 | OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); | 120 | OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); |
129 | tabs.append( tabinfo ); | 121 | m_tabs.append( tabinfo ); |
122 | |||
123 | // Make newly added tab the current one displayed | ||
130 | selectTab( tabinfo ); | 124 | selectTab( tabinfo ); |
131 | } | 125 | } |
132 | 126 | ||
133 | void OTabWidget::removePage( QWidget *childwidget ) | 127 | void OTabWidget::removePage( QWidget *childwidget ) |
134 | { | 128 | { |
135 | if ( childwidget ) | 129 | if ( childwidget ) |
136 | { | 130 | { |
137 | OTabInfo *tab = tabs.first(); | 131 | // Find tab information for desired widget |
132 | OTabInfo *tab = m_tabs.first(); | ||
138 | while ( tab && tab->control() != childwidget ) | 133 | while ( tab && tab->control() != childwidget ) |
139 | { | 134 | tab = m_tabs.next(); |
140 | tab = tabs.next(); | 135 | |
141 | } | ||
142 | if ( tab && tab->control() == childwidget ) | 136 | if ( tab && tab->control() == childwidget ) |
143 | { | 137 | { |
144 | tabBar->setTabEnabled( tab->id(), FALSE ); | 138 | if ( m_usingTabs ) |
145 | tabBar->removeTab( tabBar->tab( tab->id() ) ); | ||
146 | int i = 0; | ||
147 | while ( i < tabList->count() && tabList->text( i ) != tab->label() ) | ||
148 | { | 139 | { |
149 | i++; | 140 | // Remove tab from tab bar |
141 | m_tabBar->setTabEnabled( tab->id(), false ); | ||
142 | m_tabBar->removeTab( m_tabBar->tab( tab->id() ) ); | ||
150 | } | 143 | } |
151 | if ( tabList->text( i ) == tab->label() ) | 144 | else |
152 | { | 145 | { |
153 | tabList->removeItem( i ); | 146 | // Remove entry from drop down list |
147 | int i = 0; | ||
148 | while ( i < m_tabList->count() && m_tabList->text( i ) != tab->label() ) | ||
149 | i++; | ||
150 | if ( m_tabList->text( i ) == tab->label() ) | ||
151 | m_tabList->removeItem( i ); | ||
154 | } | 152 | } |
155 | widgetStack->removeWidget( childwidget ); | 153 | |
156 | tabs.remove( tab ); | 154 | // Remove widget from stack |
155 | m_widgetStack->removeWidget( childwidget ); | ||
156 | |||
157 | // Get rid of tab information | ||
158 | m_tabs.remove( tab ); | ||
157 | delete tab; | 159 | delete tab; |
158 | currTab = tabs.current(); | ||
159 | if ( !currTab ) | ||
160 | { | ||
161 | widgetStack->setFrameStyle( QFrame::NoFrame ); | ||
162 | } | ||
163 | 160 | ||
161 | // Reset current tab | ||
162 | m_currTab = m_tabs.current(); | ||
163 | if ( !m_currTab ) | ||
164 | m_widgetStack->setFrameStyle( QFrame::NoFrame ); | ||
165 | |||
166 | // Redraw widget | ||
164 | setUpLayout(); | 167 | setUpLayout(); |
165 | } | 168 | } |
166 | } | 169 | } |
167 | } | 170 | } |
168 | 171 | ||
169 | void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) | 172 | void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) |
170 | { | 173 | { |
171 | OTabInfo *currtab = tabs.first(); | 174 | // Find tab information for desired widget |
175 | OTabInfo *currtab = m_tabs.first(); | ||
172 | while ( currtab && currtab->control() != widget ) | 176 | while ( currtab && currtab->control() != widget ) |
173 | { | 177 | currtab = m_tabs.next(); |
174 | currtab = tabs.next(); | 178 | |
175 | } | ||
176 | if ( currtab && currtab->control() == widget ) | 179 | if ( currtab && currtab->control() == widget ) |
177 | { | 180 | { |
178 | QTab *tab = tabBar->tab( currtab->id() ); | ||
179 | QPixmap icon( loadSmooth( iconset ) ); | 181 | QPixmap icon( loadSmooth( iconset ) ); |
180 | tab->setText( label ); | 182 | |
181 | if ( tabBarStyle == IconTab ) | 183 | if ( m_usingTabs ) |
182 | tab->setIconSet( icon ); | ||
183 | int i = 0; | ||
184 | while ( i < tabList->count() && tabList->text( i ) != currtab->label() ) | ||
185 | { | 184 | { |
186 | i++; | 185 | // Update tab label and icon (if necessary) |
186 | QTab *tab = m_tabBar->tab( currtab->id() ); | ||
187 | tab->setText( label ); | ||
188 | if ( m_tabBarStyle == IconTab ) | ||
189 | tab->setIconSet( icon ); | ||
187 | } | 190 | } |
188 | if ( i < tabList->count() && tabList->text( i ) == currtab->label() ) | 191 | else |
189 | { | 192 | { |
190 | if ( tabBarStyle == IconTab || tabBarStyle == IconList ) | 193 | // Update entry label and icon (if necessary) |
191 | { | 194 | int i = 0; |
192 | tabList->changeItem( icon, label, i ); | 195 | while ( i < m_tabList->count() && m_tabList->text( i ) != currtab->label() ) |
193 | } | 196 | i++; |
194 | else | 197 | if ( i < m_tabList->count() && m_tabList->text( i ) == currtab->label() ) |
195 | { | 198 | { |
196 | tabList->changeItem( label, i ); | 199 | if ( m_tabBarStyle == IconList ) |
200 | m_tabList->changeItem( icon, label, i ); | ||
201 | else | ||
202 | m_tabList->changeItem( label, i ); | ||
197 | } | 203 | } |
198 | } | 204 | } |
205 | |||
206 | // Update tab information | ||
199 | currtab->setLabel( label ); | 207 | currtab->setLabel( label ); |
200 | currtab->setIcon( iconset ); | 208 | currtab->setIcon( iconset ); |
209 | |||
210 | // Redraw widget | ||
211 | setUpLayout(); | ||
201 | } | 212 | } |
202 | setUpLayout(); | ||
203 | } | 213 | } |
204 | 214 | ||
205 | void OTabWidget::setCurrentTab( QWidget *childwidget ) | 215 | void OTabWidget::setCurrentTab( QWidget *childwidget ) |
206 | { | 216 | { |
207 | OTabInfo *currtab = tabs.first(); | 217 | OTabInfo *currtab = m_tabs.first(); |
208 | while ( currtab && currtab->control() != childwidget ) | 218 | while ( currtab && currtab->control() != childwidget ) |
209 | { | 219 | { |
210 | currtab = tabs.next(); | 220 | currtab = m_tabs.next(); |
211 | } | 221 | } |
212 | if ( currtab && currtab->control() == childwidget ) | 222 | if ( currtab && currtab->control() == childwidget ) |
213 | { | 223 | { |
214 | selectTab( currtab ); | 224 | selectTab( currtab ); |
215 | } | 225 | } |
216 | } | 226 | } |
217 | 227 | ||
218 | void OTabWidget::setCurrentTab( const QString &tabname ) | 228 | void OTabWidget::setCurrentTab( const QString &tabname ) |
219 | { | 229 | { |
220 | OTabInfo *newtab = tabs.first(); | 230 | OTabInfo *newtab = m_tabs.first(); |
221 | while ( newtab && newtab->label() != tabname ) | 231 | while ( newtab && newtab->label() != tabname ) |
222 | { | 232 | { |
223 | newtab = tabs.next(); | 233 | newtab = m_tabs.next(); |
224 | } | 234 | } |
225 | if ( newtab && newtab->label() == tabname ) | 235 | if ( newtab && newtab->label() == tabname ) |
226 | { | 236 | { |
227 | selectTab( newtab ); | 237 | selectTab( newtab ); |
228 | } | 238 | } |
229 | } | 239 | } |
230 | 240 | ||
231 | void OTabWidget::setCurrentTab(int tabindex) | 241 | void OTabWidget::setCurrentTab(int tabindex) |
232 | { | 242 | { |
233 | OTabInfo *newtab = tabs.first(); | 243 | OTabInfo *newtab = m_tabs.first(); |
234 | while ( newtab && newtab->id() != tabindex ) | 244 | while ( newtab && newtab->id() != tabindex ) |
235 | { | 245 | { |
236 | newtab = tabs.next(); | 246 | newtab = m_tabs.next(); |
237 | } | 247 | } |
238 | if ( newtab && newtab->id() == tabindex ) | 248 | if ( newtab && newtab->id() == tabindex ) |
239 | { | 249 | { |
240 | selectTab( newtab ); | 250 | selectTab( newtab ); |
241 | } | 251 | } |
242 | } | 252 | } |
243 | 253 | ||
244 | 254 | ||
245 | OTabWidget::TabStyle OTabWidget::tabStyle() const | 255 | OTabWidget::TabStyle OTabWidget::tabStyle() const |
246 | { | 256 | { |
247 | return tabBarStyle; | 257 | return m_tabBarStyle; |
248 | } | 258 | } |
249 | 259 | ||
250 | void OTabWidget::setTabStyle( TabStyle s ) | 260 | void OTabWidget::setTabStyle( TabStyle s ) |
251 | { | 261 | { |
252 | tabBarStyle = s; | 262 | // Get out if new and current styles are the same |
253 | if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) | 263 | if ( s == m_tabBarStyle ) |
264 | return; | ||
265 | |||
266 | // Delete current selector control | ||
267 | if ( m_usingTabs ) | ||
268 | { | ||
269 | delete m_tabBar; | ||
270 | m_tabBar = 0l; | ||
271 | } | ||
272 | else | ||
254 | { | 273 | { |
255 | QTab *currtab; | 274 | delete m_tabList; |
256 | for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) | 275 | m_tabList = 0l; |
276 | } | ||
277 | |||
278 | // Set new style information | ||
279 | m_tabBarStyle = s; | ||
280 | m_usingTabs = ( m_tabBarStyle == TextTab || m_tabBarStyle == IconTab ); | ||
281 | |||
282 | // Create new selector control and populate with tab information | ||
283 | if ( m_usingTabs ) | ||
284 | { | ||
285 | // Create new tab bar selector | ||
286 | m_tabBar = new OTabBar( this ); | ||
287 | connect( m_tabBar, SIGNAL(selected(int)), this, SLOT(slotTabBarSelected(int)) ); | ||
288 | |||
289 | // Add all current tabs to tab bar | ||
290 | for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() ) | ||
257 | { | 291 | { |
258 | currtab = tabBar->tab( tabinfo->id() ); | 292 | // Create new tab in tab bar |
259 | if ( tabBarStyle == IconTab ) | 293 | QTab *tab = new QTab(); |
294 | |||
295 | // Set label (and icon if necessary) | ||
296 | if ( m_tabBarStyle == IconTab ) | ||
260 | { | 297 | { |
261 | currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); | 298 | tab->label = QString::null; |
262 | if ( tabinfo == currTab ) | 299 | tab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); |
263 | currtab->setText( tabinfo->label() ); | ||
264 | else | ||
265 | currtab->setText( QString::null ); | ||
266 | } | 300 | } |
267 | else | 301 | else |
268 | { | 302 | tab->label = tabinfo->label(); |
269 | currtab->iconset = 0x0; | 303 | |
270 | currtab->setText( tabinfo->label() ); | 304 | // Add tab and save its Id |
271 | } | 305 | int tabid = m_tabBar->addTab( tab ); |
306 | tabinfo->setId( tabid ); | ||
272 | } | 307 | } |
273 | tabBarStack->raiseWidget( tabBar ); | ||
274 | } | 308 | } |
275 | else if ( tabBarStyle == TextList || tabBarStyle == IconList ) | 309 | else |
276 | { | 310 | { |
277 | tabList->clear(); | 311 | // Create new drop down list selector |
278 | for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) | 312 | m_tabList = new QComboBox( false, this ); |
313 | connect( m_tabList, SIGNAL(activated(int)), this, SLOT(slotTabListSelected(int)) ); | ||
314 | |||
315 | // Add all current tabs to drop down list | ||
316 | for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() ) | ||
279 | { | 317 | { |
280 | if ( tabBarStyle == IconList ) | 318 | if ( m_tabBarStyle == IconList ) |
281 | { | 319 | m_tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); |
282 | tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); | ||
283 | } | ||
284 | else | 320 | else |
285 | { | 321 | m_tabList->insertItem( tabinfo->label() ); |
286 | tabList->insertItem( tabinfo->label() ); | ||
287 | } | ||
288 | } | 322 | } |
289 | tabBarStack->raiseWidget( tabList ); | ||
290 | } | 323 | } |
324 | |||
325 | // Redraw widget | ||
291 | setUpLayout(); | 326 | setUpLayout(); |
292 | } | 327 | } |
293 | 328 | ||
294 | OTabWidget::TabPosition OTabWidget::tabPosition() const | 329 | OTabWidget::TabPosition OTabWidget::tabPosition() const |
295 | { | 330 | { |
296 | return tabBarPosition; | 331 | return m_tabBarPosition; |
297 | } | 332 | } |
298 | 333 | ||
299 | void OTabWidget::setTabPosition( TabPosition p ) | 334 | void OTabWidget::setTabPosition( TabPosition p ) |
300 | { | 335 | { |
301 | tabBarPosition = p; | 336 | m_tabBarPosition = p; |
302 | if ( tabBarPosition == Top ) | 337 | |
303 | { | 338 | // If using the tab bar selector, set its shape |
304 | tabBar->setShape( QTabBar::RoundedAbove ); | 339 | if ( m_usingTabs ) |
305 | } | ||
306 | else | ||
307 | { | 340 | { |
308 | tabBar->setShape( QTabBar::RoundedBelow ); | 341 | ( m_tabBarPosition == Top ) ? m_tabBar->setShape( QTabBar::RoundedAbove ) |
342 | : m_tabBar->setShape( QTabBar::RoundedBelow ); | ||
309 | } | 343 | } |
344 | |||
345 | // Redraw widget | ||
310 | setUpLayout(); | 346 | setUpLayout(); |
311 | } | 347 | } |
312 | 348 | ||
313 | void OTabWidget::slotTabBarSelected( int id ) | 349 | void OTabWidget::slotTabBarSelected( int id ) |
314 | { | 350 | { |
315 | OTabInfo *newtab = tabs.first(); | 351 | OTabInfo *newtab = m_tabs.first(); |
316 | while ( newtab && newtab->id() != id ) | 352 | while ( newtab && newtab->id() != id ) |
317 | { | 353 | newtab = m_tabs.next(); |
318 | newtab = tabs.next(); | 354 | |
319 | } | ||
320 | if ( newtab && newtab->id() == id ) | 355 | if ( newtab && newtab->id() == id ) |
321 | { | ||
322 | selectTab( newtab ); | 356 | selectTab( newtab ); |
323 | } | ||
324 | } | 357 | } |
325 | 358 | ||
326 | void OTabWidget::slotTabListSelected( int index ) | 359 | void OTabWidget::slotTabListSelected( int index ) |
327 | { | 360 | { |
328 | OTabInfo *newtab = tabs.at( index ); | 361 | OTabInfo *newtab = m_tabs.at( index ); |
329 | if ( newtab ) | 362 | if ( newtab ) |
330 | { | ||
331 | selectTab( newtab ); | 363 | selectTab( newtab ); |
332 | } | ||
333 | } | 364 | } |
334 | 365 | ||
335 | QPixmap OTabWidget::loadSmooth( const QString &name ) | 366 | QPixmap OTabWidget::loadSmooth( const QString &name ) |
336 | { | 367 | { |
337 | QPixmap p; | 368 | QPixmap p; |
338 | p.convertFromImage( Resource::loadImage( name ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); | 369 | p.convertFromImage( Resource::loadImage( name ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); |
339 | return p; | 370 | return p; |
340 | } | 371 | } |
341 | 372 | ||
342 | void OTabWidget::selectTab( OTabInfo *tab ) | 373 | void OTabWidget::selectTab( OTabInfo *tab ) |
343 | { | 374 | { |
344 | if ( tabBarStyle == IconTab ) | 375 | if ( m_tabBarStyle == IconTab ) |
345 | { | 376 | { |
346 | if ( currTab ) | 377 | // Remove text label from currently selected tab |
378 | if ( m_currTab ) | ||
347 | { | 379 | { |
348 | tabBar->tab( currTab->id() )->setText( QString::null ); | 380 | m_tabBar->tab( m_currTab->id() )->setText( QString::null ); |
349 | setUpLayout(); | 381 | //setUpLayout(); |
350 | } | 382 | } |
351 | tabBar->tab( tab->id() )->setText( tab->label() ); | 383 | |
352 | tabBar->setCurrentTab( tab->id() ); | 384 | // Set text label for newly selected tab |
385 | m_tabBar->tab( tab->id() )->setText( tab->label() ); | ||
386 | m_tabBar->setCurrentTab( tab->id() ); | ||
387 | |||
353 | setUpLayout(); | 388 | setUpLayout(); |
354 | tabBar->update(); | ||
355 | } | 389 | } |
356 | else | 390 | else if ( m_tabBarStyle == TextTab ) |
357 | { | 391 | { |
358 | tabBar->setCurrentTab( tab->id() ); | 392 | m_tabBar->setCurrentTab( tab->id() ); |
359 | } | 393 | } |
360 | 394 | ||
361 | widgetStack->raiseWidget( tab->control() ); | 395 | m_widgetStack->raiseWidget( tab->control() ); |
362 | 396 | ||
363 | emit currentChanged( tab->control() ); | 397 | emit currentChanged( tab->control() ); |
364 | 398 | ||
365 | currTab = tab; | 399 | m_currTab = tab; |
366 | } | 400 | } |
367 | 401 | ||
368 | void OTabWidget::setUpLayout() | 402 | void OTabWidget::setUpLayout() |
369 | { | 403 | { |
370 | tabBar->layoutTabs(); | 404 | if ( m_usingTabs ) |
371 | QSize t( tabBarStack->sizeHint() ); | ||
372 | if ( tabBarStyle == IconTab ) | ||
373 | { | 405 | { |
374 | if ( t.width() > width() ) | 406 | m_tabBar->update(); |
375 | t.setWidth( width() ); | 407 | m_tabBar->layoutTabs(); |
376 | } | 408 | } |
377 | else | 409 | } |
410 | |||
411 | void OTabWidget::resizeEvent( QResizeEvent * ) | ||
412 | { | ||
413 | QSize t; | ||
414 | |||
415 | if ( m_usingTabs ) | ||
378 | { | 416 | { |
379 | t.setWidth( width() ); | 417 | m_tabBar->layoutTabs(); |
418 | t = m_tabBar->sizeHint(); | ||
380 | } | 419 | } |
381 | int lw = widgetStack->lineWidth(); | 420 | else |
382 | if ( tabBarPosition == Bottom ) | 421 | t = m_tabList->sizeHint(); |
422 | |||
423 | t.setWidth( width() ); | ||
424 | |||
425 | int lw = m_widgetStack->lineWidth(); | ||
426 | if ( m_tabBarPosition == Bottom ) | ||
383 | { | 427 | { |
384 | tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); | 428 | if ( m_usingTabs ) |
385 | widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); | 429 | m_tabBar->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); |
430 | else | ||
431 | m_tabList->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); | ||
432 | |||
433 | m_widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); | ||
386 | } | 434 | } |
387 | else | 435 | else |
388 | { | 436 | { |
389 | tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); | 437 | if ( m_usingTabs ) |
390 | widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) ); | 438 | m_tabBar->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); |
439 | else | ||
440 | m_tabList->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); | ||
441 | |||
442 | m_widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) ); | ||
391 | } | 443 | } |
392 | 444 | ||
393 | if ( autoMask() ) | 445 | if ( autoMask() ) |
394 | updateMask(); | 446 | updateMask(); |
395 | } | 447 | } |
396 | 448 | ||
397 | QSize OTabWidget::sizeHint() const | ||
398 | { | ||
399 | QSize s( widgetStack->sizeHint() ); | ||
400 | QSize t( tabBarStack->sizeHint() ); | ||
401 | return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() ); | ||
402 | } | ||
403 | |||
404 | void OTabWidget::resizeEvent( QResizeEvent * ) | ||
405 | { | ||
406 | setUpLayout(); | ||
407 | } | ||
408 | |||
409 | int OTabWidget::currentTab() | 449 | int OTabWidget::currentTab() |
410 | { | 450 | { |
411 | if ( currTab ) | 451 | if ( m_currTab ) |
412 | { | 452 | { |
413 | return currTab->id(); | 453 | return m_currTab->id(); |
414 | } | 454 | } |
415 | return -1; | 455 | return -1; |
416 | } | 456 | } |
417 | 457 | ||
418 | QWidget* OTabWidget::currentWidget()const | 458 | QWidget* OTabWidget::currentWidget()const |
419 | { | 459 | { |
420 | if ( currTab ) | 460 | if ( m_currTab ) |
421 | { | 461 | { |
422 | return currTab->control(); | 462 | return m_currTab->control(); |
423 | } | 463 | } |
424 | 464 | ||
425 | return 0; | 465 | return 0; |
426 | } | 466 | } |
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 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2002 Dan Williams <williamsdr@acm.org> | 3 | Copyright (C) 2002, 2005 Dan Williams <drw@handhelds.org> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #ifndef OTABWIDGET_H | 31 | #ifndef OTABWIDGET_H |
32 | #define OTABWIDGET_H | 32 | #define OTABWIDGET_H |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | #include <opie2/otabinfo.h> | 35 | #include <opie2/otabinfo.h> |
36 | 36 | ||
37 | /* QT */ | 37 | /* QT */ |
38 | #include <qwidget.h> | 38 | #include <qwidget.h> |
39 | #include <qlist.h> | 39 | #include <qlist.h> |
40 | 40 | ||
41 | 41 | ||
42 | class QComboBox; | 42 | class QComboBox; |
43 | class QPixmap; | 43 | class QPixmap; |
44 | class QTabBar; | 44 | class QTabBar; |
45 | class QWidgetStack; | 45 | class QWidgetStack; |
46 | 46 | ||
47 | namespace Opie { | 47 | namespace Opie { |
48 | namespace Ui { | 48 | namespace Ui { |
49 | 49 | ||
50 | class OTabBar; | 50 | class OTabBar; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * @class OTabWidget | 53 | * @class OTabWidget |
54 | * @brief The OTabWidget class provides a stack of widgets. | 54 | * @brief The OTabWidget class provides a stack of widgets. |
55 | * | 55 | * |
56 | * OTabWidget is a derivation of TrollTech's QTabWidget which provides | 56 | * OTabWidget is a derivation of TrollTech's QTabWidget which provides |
57 | * a stack of widgets. Widgets can be selected using either a tab bar or | 57 | * a stack of widgets. Widgets can be selected using either a tab bar or |
58 | * drop down list box. | 58 | * drop down list box. |
59 | * | 59 | * |
60 | * The normal way to use OTabWidget is to do the following in the | 60 | * The normal way to use OTabWidget is to do the following in the |
61 | * constructor: | 61 | * constructor: |
62 | * - Create a OTabWidget. | 62 | * - Create a OTabWidget. |
63 | * - Create a QWidget for each of the pages in the control, insert | 63 | * - Create a QWidget for each of the pages in the control, insert |
64 | * children into it, set up geometry management for it, and use addTab() | 64 | * children into it, set up geometry management for it, and use addTab() |
65 | * to add the widget. | 65 | * to add the widget. |
66 | */ | 66 | */ |
67 | class OTabWidget : public QWidget | 67 | class OTabWidget : public QWidget |
68 | { | 68 | { |
69 | Q_OBJECT | 69 | Q_OBJECT |
70 | 70 | ||
71 | public: | 71 | public: |
72 | /** | 72 | /** |
73 | * @enum TabStyle | 73 | * @enum TabStyle |
74 | * @brief Defines how the widget selection control is displayed. | 74 | * @brief Defines how the widget selection control is displayed. |
75 | * | 75 | * |
76 | * Valid values: | 76 | * Valid values: |
77 | * - Global: use globally selected options (qpe.conf - TabStyle & TabPosition) | 77 | * - Global: use globally selected options (qpe.conf - TabStyle & TabPosition) |
78 | * - TextTab: Tabbed widget selection with text labels | 78 | * - TextTab: Tabbed widget selection with text labels |
79 | * - IconTab: Tabbed widget selection with icon labels, text label for active widget | 79 | * - IconTab: Tabbed widget selection with icon labels, text label for active widget |
80 | * (similar to Opie launcher) | 80 | * (similar to Opie launcher) |
81 | * - TextList: Drop down list widget selection with text labels | 81 | * - TextList: Drop down list widget selection with text labels |
82 | * - IconList: Drop down list widget selection with icon & text labels | 82 | * - IconList: Drop down list widget selection with icon & text labels |
83 | */ | 83 | */ |
84 | enum TabStyle { Global, TextTab, IconTab, TextList, IconList }; | 84 | enum TabStyle { Global, TextTab, IconTab, TextList, IconList }; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | * @enum TabPosition | 87 | * @enum TabPosition |
88 | * @brief Defines where the widget selection control is drawn. | 88 | * @brief Defines where the widget selection control is drawn. |
89 | * | 89 | * |
90 | * Valid values: | 90 | * Valid values: |
91 | * - Top: Widget selection control is drawn above widgets | 91 | * - Top: Widget selection control is drawn above widgets |
92 | * - Bottom: Widget selection control is drawn below widgets | 92 | * - Bottom: Widget selection control is drawn below widgets |
93 | */ | 93 | */ |
94 | enum TabPosition { Top, Bottom }; | 94 | enum TabPosition { Top, Bottom }; |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * @fn OTabWidget( QWidget *parent = 0, const char *name = 0, TabStyle s = Global, TabPosition p = Top ) | 97 | * @fn OTabWidget( QWidget *parent = 0, const char *name = 0, TabStyle s = Global, TabPosition p = Top ) |
98 | * @brief Object constructor. | 98 | * @brief Object constructor. |
99 | * | 99 | * |
100 | * @param parent Pointer to parent of this control. | 100 | * @param parent Pointer to parent of this control. |
101 | * @param name Name of control. | 101 | * @param name Name of control. |
102 | * @param s Style of widget selection control. | 102 | * @param s Style of widget selection control. |
103 | * @param p Position of the widget selection control. | 103 | * @param p Position of the widget selection control. |
104 | * | 104 | * |
105 | * Constructs a new OTabWidget control with parent and name. The style and position parameters | 105 | * Constructs a new OTabWidget control with parent and name. The style and position parameters |
106 | * determine how the widget selection control will be displayed. | 106 | * determine how the widget selection control will be displayed. |
107 | */ | 107 | */ |
108 | OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top ); | 108 | OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top ); |
109 | 109 | ||
110 | /** | 110 | /** |
111 | * @fn ~OTabWidget() | 111 | * @fn ~OTabWidget() |
112 | * @brief Object destructor. | 112 | * @brief Object destructor. |
113 | */ | 113 | */ |
114 | ~OTabWidget(); | 114 | ~OTabWidget(); |
115 | 115 | ||
116 | /** | 116 | /** |
117 | * @fn addTab( QWidget *child, const QString &icon, const QString &label ) | 117 | * @fn addTab( QWidget *child, const QString &icon, const QString &label ) |
118 | * @brief Add new widget to control. | 118 | * @brief Add new widget to control. |
119 | * | 119 | * |
120 | * @param child Widget control. | 120 | * @param child Widget control. |
121 | * @param icon Path to icon. | 121 | * @param icon Path to icon. |
122 | * @param label Text label. | 122 | * @param label Text label. |
123 | */ | 123 | */ |
124 | void addTab( QWidget *, const QString &, const QString & ); | 124 | void addTab( QWidget *, const QString &, const QString & ); |
125 | 125 | ||
126 | /** | 126 | /** |
127 | * @fn removePage( QWidget *widget ) | 127 | * @fn removePage( QWidget *widget ) |
128 | * @brief Remove widget from control. Does not delete widget. | 128 | * @brief Remove widget from control. Does not delete widget. |
129 | * | 129 | * |
130 | * @param widget Widget control to be removed. | 130 | * @param widget Widget control to be removed. |
131 | */ | 131 | */ |
132 | void removePage( QWidget * ); | 132 | void removePage( QWidget * ); |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * @fn changeTab( QWidget *widget, const QString &icon, const QString &label ) | 135 | * @fn changeTab( QWidget *widget, const QString &icon, const QString &label ) |
136 | * @brief Change text and/or icon for existing tab | 136 | * @brief Change text and/or icon for existing tab |
137 | * | 137 | * |
138 | * @param child Widget control. | 138 | * @param child Widget control. |
139 | * @param icon Path to icon. | 139 | * @param icon Path to icon. |
140 | * @param label Text label. | 140 | * @param label Text label. |
141 | */ | 141 | */ |
142 | void changeTab( QWidget *, const QString &, const QString & ); | 142 | void changeTab( QWidget *, const QString &, const QString & ); |
143 | 143 | ||
144 | /** | 144 | /** |
145 | * @fn tabStyle()const | 145 | * @fn tabStyle()const |
146 | * @brief Returns current widget selection control style. | 146 | * @brief Returns current widget selection control style. |
147 | */ | 147 | */ |
148 | TabStyle tabStyle() const; | 148 | TabStyle tabStyle() const; |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * @fn setTabStyle( TabStyle s ) | 151 | * @fn setTabStyle( TabStyle s ) |
152 | * @brief Set the current widget selection control style. | 152 | * @brief Set the current widget selection control style. |
153 | * | 153 | * |
154 | * @param s New style to be used. | 154 | * @param s New style to be used. |
155 | */ | 155 | */ |
156 | void setTabStyle( TabStyle ); | 156 | void setTabStyle( TabStyle ); |
157 | 157 | ||
158 | /** | 158 | /** |
159 | * @fn tabPosition()const | 159 | * @fn tabPosition()const |
160 | * @brief Returns current widget selection control position. | 160 | * @brief Returns current widget selection control position. |
161 | */ | 161 | */ |
162 | TabPosition tabPosition() const; | 162 | TabPosition tabPosition() const; |
163 | 163 | ||
164 | /** | 164 | /** |
165 | * @fn setTabPosition( TabPosition p ) | 165 | * @fn setTabPosition( TabPosition p ) |
166 | * @brief Set the current widget selection control position. | 166 | * @brief Set the current widget selection control position. |
167 | * | 167 | * |
168 | * @param p New position of widget selection control. | 168 | * @param p New position of widget selection control. |
169 | */ | 169 | */ |
170 | void setTabPosition( TabPosition ); | 170 | void setTabPosition( TabPosition ); |
171 | 171 | ||
172 | /** | 172 | /** |
173 | * @fn setCurrentTab( QWidget *childwidget ) | 173 | * @fn setCurrentTab( QWidget *childwidget ) |
174 | * @brief Selects and brings to top the desired widget by using widget pointer. | 174 | * @brief Selects and brings to top the desired widget by using widget pointer. |
175 | * | 175 | * |
176 | * @param childwidget Widget to select. | 176 | * @param childwidget Widget to select. |
177 | */ | 177 | */ |
178 | void setCurrentTab( QWidget * ); | 178 | void setCurrentTab( QWidget * ); |
179 | 179 | ||
180 | /** | 180 | /** |
181 | * @fn setCurrentTab( const QString &tabname ) | 181 | * @fn setCurrentTab( const QString &tabname ) |
182 | * @brief Selects and brings to top the desired widget, by using label. | 182 | * @brief Selects and brings to top the desired widget, by using label. |
183 | * | 183 | * |
184 | * @param tabname Text label for widget to select. | 184 | * @param tabname Text label for widget to select. |
185 | */ | 185 | */ |
186 | void setCurrentTab( const QString & ); | 186 | void setCurrentTab( const QString & ); |
187 | 187 | ||
188 | /** | 188 | /** |
189 | * @fn setCurrentTab( int ) | 189 | * @fn setCurrentTab( int ) |
190 | * @brief Selects and brings to top the desired widget, by using id. | 190 | * @brief Selects and brings to top the desired widget, by using id. |
191 | * | 191 | * |
192 | * @param tab id for widget to select. | 192 | * @param tab id for widget to select. |
193 | */ | 193 | */ |
194 | void setCurrentTab(int); | 194 | void setCurrentTab(int); |
195 | 195 | ||
196 | /** | 196 | /** |
197 | * @fn sizeHint()const | ||
198 | * @brief Reimplemented for internal purposes. | ||
199 | */ | ||
200 | QSize sizeHint() const; | ||
201 | |||
202 | /** | ||
203 | * @fn currentTab( ) | 197 | * @fn currentTab( ) |
204 | * @brief returns current tab id. | 198 | * @brief returns current tab id. |
205 | */ | 199 | */ |
206 | // ### make const | 200 | // ### make const |
207 | int currentTab()/* const */; | 201 | int currentTab()/* const */; |
208 | /** | 202 | /** |
209 | * @brief returns the current page of the active tab | 203 | * @brief returns the current page of the active tab |
210 | * | 204 | * |
211 | * @since 1.2 | 205 | * @since 1.2 |
212 | */ | 206 | */ |
213 | QWidget* currentWidget()const; | 207 | QWidget* currentWidget()const; |
214 | 208 | ||
215 | protected: | 209 | protected: |
216 | 210 | ||
217 | /** | 211 | /** |
218 | * @fn resizeEvent( QResizeEvent * ) | 212 | * @fn resizeEvent( QResizeEvent * ) |
219 | * @brief Reimplemented for internal purposes. | 213 | * @brief Reimplemented for internal purposes. |
220 | */ | 214 | */ |
221 | void resizeEvent( QResizeEvent * ); | 215 | void resizeEvent( QResizeEvent * ); |
222 | 216 | ||
223 | private: | 217 | private: |
224 | OTabInfoList tabs; | 218 | OTabInfoList m_tabs; // List of information for tabs |
225 | OTabInfo *currTab; | 219 | OTabInfo *m_currTab; // Current tab displayed |
226 | 220 | TabStyle m_tabBarStyle; // Current style of control | |
227 | TabStyle tabBarStyle; | 221 | TabPosition m_tabBarPosition; // Position of selector control |
228 | TabPosition tabBarPosition; | 222 | bool m_usingTabs; // Indicates whether style is either TextTab or IconTab |
229 | 223 | // (saves from having to always check for these 2 values) | |
230 | QWidgetStack *tabBarStack; | 224 | |
231 | OTabBar *tabBar; | 225 | // UI components |
232 | QComboBox *tabList; | 226 | OTabBar *m_tabBar; |
227 | QComboBox *m_tabList; | ||
228 | QWidgetStack *m_widgetStack; | ||
233 | 229 | ||
234 | QWidgetStack *widgetStack; | ||
235 | class Private; | 230 | class Private; |
236 | Private* d; | 231 | Private* d; |
237 | 232 | ||
238 | /** | 233 | /** |
239 | * @fn loadSmooth( const QString &name ) | 234 | * @fn loadSmooth( const QString &name ) |
240 | * @brief Loads icon for widget. | 235 | * @brief Loads icon for widget. |
241 | * | 236 | * |
242 | * @param name Name of icon image file. | 237 | * @param name Name of icon image file. |
243 | */ | 238 | */ |
244 | QPixmap loadSmooth( const QString & ); | 239 | QPixmap loadSmooth( const QString & ); |
245 | 240 | ||
246 | /** | 241 | /** |
247 | * @fn selectTab( OTabInfo *tab ) | 242 | * @fn selectTab( OTabInfo *tab ) |
248 | * @brief Internal function to select desired widget. | 243 | * @brief Internal function to select desired widget. |
249 | * | 244 | * |
250 | * @param tab Pointer to data for widget. | 245 | * @param tab Pointer to data for widget. |
251 | */ | 246 | */ |
252 | void selectTab( OTabInfo * ); | 247 | void selectTab( OTabInfo * ); |
253 | 248 | ||
254 | /** | 249 | /** |
255 | * @fn setUpLayout() | 250 | * @fn setUpLayout() |
256 | * @brief Internal function to adjust layout. | 251 | * @brief Internal function to adjust layout. |
257 | */ | 252 | */ |
258 | void setUpLayout(); | 253 | void setUpLayout(); |
259 | 254 | ||
260 | 255 | ||
261 | signals: | 256 | signals: |
262 | /** | 257 | /** |
263 | * @fn currentChanged( QWidget *widget ) | 258 | * @fn currentChanged( QWidget *widget ) |
264 | * @brief This signal is emitted whenever the widget has changed. | 259 | * @brief This signal is emitted whenever the widget has changed. |
265 | * | 260 | * |
266 | * @param widget Pointer to new current widget. | 261 | * @param widget Pointer to new current widget. |
267 | */ | 262 | */ |
268 | void currentChanged( QWidget * ); | 263 | void currentChanged( QWidget * ); |
269 | 264 | ||
270 | private slots: | 265 | private slots: |
271 | 266 | ||
272 | /** | 267 | /** |
273 | * @fn slotTabBarSelected( int id ) | 268 | * @fn slotTabBarSelected( int id ) |
274 | * @brief Slot which is called when a tab is selected. | 269 | * @brief Slot which is called when a tab is selected. |
275 | * | 270 | * |
276 | * @param id ID of widget selected. | 271 | * @param id ID of widget selected. |
277 | */ | 272 | */ |
278 | void slotTabBarSelected( int ); | 273 | void slotTabBarSelected( int ); |
279 | 274 | ||
280 | /** | 275 | /** |
281 | * @fn slotTabListSelected( int index ) | 276 | * @fn slotTabListSelected( int index ) |
282 | * @brief Slot which is called when a drop down selection is made. | 277 | * @brief Slot which is called when a drop down selection is made. |
283 | * | 278 | * |
284 | * @param id Index of widget selected. | 279 | * @param id Index of widget selected. |
285 | */ | 280 | */ |
286 | void slotTabListSelected( int ); | 281 | void slotTabListSelected( int ); |
287 | }; | 282 | }; |
288 | 283 | ||
289 | } | 284 | } |
290 | } | 285 | } |
291 | 286 | ||
292 | #endif | 287 | #endif |