summaryrefslogtreecommitdiff
authordrw <drw>2003-02-16 21:54:23 (UTC)
committer drw <drw>2003-02-16 21:54:23 (UTC)
commit8ecc375c803dc57b160bd0335891fcaf4f6de1df (patch) (unidiff)
treea89c1ccc6e3a469bb8fa435dfedce9386333cb72
parente0eb3f016d7f8a1e1e5548ef8aa115fef8999697 (diff)
downloadopie-8ecc375c803dc57b160bd0335891fcaf4f6de1df.zip
opie-8ecc375c803dc57b160bd0335891fcaf4f6de1df.tar.gz
opie-8ecc375c803dc57b160bd0335891fcaf4f6de1df.tar.bz2
Added changeTab() to OTabWidget to dynamically change tab name and/or icon (stumbled upon request for this in TinyKate todo)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/otabinfo.h16
-rw-r--r--libopie/otabwidget.cpp48
-rw-r--r--libopie/otabwidget.h10
3 files changed, 68 insertions, 6 deletions
diff --git a/libopie/otabinfo.h b/libopie/otabinfo.h
index 8dbbcc2..6589638 100644
--- a/libopie/otabinfo.h
+++ b/libopie/otabinfo.h
@@ -44,73 +44,89 @@ class QWidget;
44 * 44 *
45 * OTabInfo provides the following information about a widget added to an 45 * OTabInfo provides the following information about a widget added to an
46 * OTabWidget control: 46 * OTabWidget control:
47 * 47 *
48 * ID - integer tab bar ID 48 * ID - integer tab bar ID
49 * Control - QWidget pointer to child widget 49 * Control - QWidget pointer to child widget
50 * Label - QString text label for OTabWidget selection control 50 * Label - QString text label for OTabWidget selection control
51 * Icon - QString name of icon file 51 * Icon - QString name of icon file
52 */ 52 */
53class OTabInfo 53class OTabInfo
54{ 54{
55public: 55public:
56/** 56/**
57 * @fn OTabInfo() 57 * @fn OTabInfo()
58 * @brief Object constructor. 58 * @brief Object constructor.
59 * 59 *
60 * @param parent Pointer to parent of this control. 60 * @param parent Pointer to parent of this control.
61 * @param name Name of control. 61 * @param name Name of control.
62 * @param s Style of widget selection control. 62 * @param s Style of widget selection control.
63 * @param p Position of the widget selection control. 63 * @param p Position of the widget selection control.
64 */ 64 */
65 OTabInfo() : i( -1 ), c( 0 ), p( 0 ), l( QString::null ) {} 65 OTabInfo() : i( -1 ), c( 0 ), p( 0 ), l( QString::null ) {}
66 66
67/** 67/**
68 * @fn OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) 68 * @fn OTabInfo( int id, QWidget *control, const QString &icon, const QString &label )
69 * @brief Object constructor. 69 * @brief Object constructor.
70 * 70 *
71 * @param id TabBar identifier for widget. 71 * @param id TabBar identifier for widget.
72 * @param control QWidget pointer to widget. 72 * @param control QWidget pointer to widget.
73 * @param icon QString name of icon file. 73 * @param icon QString name of icon file.
74 * @param label QString text label for OTabWidget selection control. 74 * @param label QString text label for OTabWidget selection control.
75 */ 75 */
76 OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) 76 OTabInfo( int id, QWidget *control, const QString &icon, const QString &label )
77 : i( id ), c( control ), p( icon ), l( label ) {} 77 : i( id ), c( control ), p( icon ), l( label ) {}
78 78
79/** 79/**
80 * @fn id() 80 * @fn id()
81 * @brief Returns TabBar ID. 81 * @brief Returns TabBar ID.
82 */ 82 */
83 int id() const { return i; } 83 int id() const { return i; }
84 84
85/** 85/**
86 * @fn label() 86 * @fn label()
87 * @brief Returns text label for widget. 87 * @brief Returns text label for widget.
88 */ 88 */
89 const QString &label() const { return l; } 89 const QString &label() const { return l; }
90 90
91/** 91/**
92 * @fn setLabel( const QString &label )
93 * @brief Set label for tab.
94 *
95 * @param label QString text label for OTabWidget selection control.
96 */
97 void setLabel( const QString &label ) { l = label; }
98
99/**
92 * @fn control() 100 * @fn control()
93 * @brief Returns pointer to widget. 101 * @brief Returns pointer to widget.
94 */ 102 */
95 QWidget *control() const { return c; } 103 QWidget *control() const { return c; }
96 104
97/** 105/**
98 * @fn icon() 106 * @fn icon()
99 * @brief Returns name of icon file. 107 * @brief Returns name of icon file.
100 */ 108 */
101 const QString &icon() const { return p; } 109 const QString &icon() const { return p; }
102 110
111/**
112 * @fn setIcon( const QString &icon )
113 * @brief Set icon for tab.
114 *
115 * @param icon QString name of icon file.
116 */
117 void setIcon( const QString &icon ) { p = icon; }
118
103private: 119private:
104 int i; 120 int i;
105 QWidget *c; 121 QWidget *c;
106 QString p; 122 QString p;
107 QString l; 123 QString l;
108}; 124};
109 125
110/** 126/**
111 * @class OTabInfoList 127 * @class OTabInfoList
112 * @brief A list of OTabInfo objects used by OTabWidget. 128 * @brief A list of OTabInfo objects used by OTabWidget.
113 */ 129 */
114typedef QList<OTabInfo> OTabInfoList; 130typedef QList<OTabInfo> OTabInfoList;
115 131
116#endif 132#endif
diff --git a/libopie/otabwidget.cpp b/libopie/otabwidget.cpp
index bee3f35..99bf067 100644
--- a/libopie/otabwidget.cpp
+++ b/libopie/otabwidget.cpp
@@ -53,166 +53,202 @@ OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPositi
53 QString pos = config.readEntry( "TabPosition", "Top"); 53 QString pos = config.readEntry( "TabPosition", "Top");
54 if ( pos == "Bottom" ) 54 if ( pos == "Bottom" )
55 { 55 {
56 p = Bottom; 56 p = Bottom;
57 } 57 }
58 else 58 else
59 { 59 {
60 p = Top; 60 p = Top;
61 } 61 }
62 } 62 }
63 63
64 widgetStack = new QWidgetStack( this, "widgetstack" ); 64 widgetStack = new QWidgetStack( this, "widgetstack" );
65 widgetStack->setFrameStyle( QFrame::NoFrame ); 65 widgetStack->setFrameStyle( QFrame::NoFrame );
66 widgetStack->setLineWidth( style().defaultFrameWidth() ); 66 widgetStack->setLineWidth( style().defaultFrameWidth() );
67 67
68 tabBarStack = new QWidgetStack( this, "tabbarstack" ); 68 tabBarStack = new QWidgetStack( this, "tabbarstack" );
69 69
70 tabBar = new OTabBar( tabBarStack, "tabbar" ); 70 tabBar = new OTabBar( tabBarStack, "tabbar" );
71 tabBarStack->addWidget( tabBar, 0 ); 71 tabBarStack->addWidget( tabBar, 0 );
72 connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) ); 72 connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) );
73 73
74 tabList = new QComboBox( false, tabBarStack, "tablist" ); 74 tabList = new QComboBox( false, tabBarStack, "tablist" );
75 tabBarStack->addWidget( tabList, 1 ); 75 tabBarStack->addWidget( tabList, 1 );
76 connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) ); 76 connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) );
77 77
78 setTabStyle( s ); 78 setTabStyle( s );
79 setTabPosition( p ); 79 setTabPosition( p );
80 80
81 currentTab= 0x0; 81 currentTab= 0x0;
82} 82}
83 83
84OTabWidget::~OTabWidget() 84OTabWidget::~OTabWidget()
85{ 85{
86} 86}
87 87
88void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) 88void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
89{ 89{
90 QPixmap iconset = loadSmooth( icon ); 90 QPixmap iconset = loadSmooth( icon );
91 91
92 QTab *tab = new QTab(); 92 QTab *tab = new QTab();
93 if ( tabBarStyle == IconTab ) 93 if ( tabBarStyle == IconTab )
94 { 94 {
95 tab->label = QString::null; 95 tab->label = QString::null;
96 } 96 }
97 else 97 else
98 { 98 {
99 tab->label = label; 99 tab->label = label;
100 } 100 }
101 if ( tabBarStyle == IconTab || tabBarStyle == IconList) 101 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
102 { 102 {
103 tab->iconset = new QIconSet( iconset ); 103 tab->iconset = new QIconSet( iconset );
104 } 104 }
105 int tabid = tabBar->addTab( tab ); 105 int tabid = tabBar->addTab( tab );
106 106
107 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 107 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
108 { 108 {
109 tabList->insertItem( iconset, label, -1 ); 109 tabList->insertItem( iconset, label, -1 );
110 } 110 }
111 else 111 else
112 { 112 {
113 tabList->insertItem( label ); 113 tabList->insertItem( label );
114 } 114 }
115 115
116 widgetStack->addWidget( child, tabid ); 116 widgetStack->addWidget( child, tabid );
117 widgetStack->raiseWidget( child ); 117 widgetStack->raiseWidget( child );
118 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); 118 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
119 119
120 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); 120 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label );
121 tabs.append( tabinfo ); 121 tabs.append( tabinfo );
122 selectTab( tabinfo ); 122 selectTab( tabinfo );
123} 123}
124 124
125void OTabWidget::removePage( QWidget *childwidget ) 125void OTabWidget::removePage( QWidget *childwidget )
126{ 126{
127 if ( childwidget ) 127 if ( childwidget )
128 { 128 {
129 OTabInfo *tab = tabs.first(); 129 OTabInfo *tab = tabs.first();
130 while ( tab && tab->control() != childwidget ) 130 while ( tab && tab->control() != childwidget )
131 { 131 {
132 tab = tabs.next(); 132 tab = tabs.next();
133 } 133 }
134 if ( tab && tab->control() == childwidget ) 134 if ( tab && tab->control() == childwidget )
135 { 135 {
136 tabBar->setTabEnabled( tab->id(), FALSE ); 136 tabBar->setTabEnabled( tab->id(), FALSE );
137 tabBar->removeTab( tabBar->tab( tab->id() ) ); 137 tabBar->removeTab( tabBar->tab( tab->id() ) );
138 int i = 0; 138 int i = 0;
139 while ( i < tabList->count() && tabList->text( i ) != tab->label() ) 139 while ( i < tabList->count() && tabList->text( i ) != tab->label() )
140 { 140 {
141 i++; 141 i++;
142 } 142 }
143 if ( tabList->text( i ) == tab->label() ) 143 if ( tabList->text( i ) == tab->label() )
144 { 144 {
145 tabList->removeItem( i ); 145 tabList->removeItem( i );
146 } 146 }
147 widgetStack->removeWidget( childwidget ); 147 widgetStack->removeWidget( childwidget );
148 tabs.remove( tab ); 148 tabs.remove( tab );
149 delete tab; 149 delete tab;
150 currentTab = tabs.current(); 150 currentTab = tabs.current();
151 if ( !currentTab ) 151 if ( !currentTab )
152 { 152 {
153 widgetStack->setFrameStyle( QFrame::NoFrame ); 153 widgetStack->setFrameStyle( QFrame::NoFrame );
154 } 154 }
155 155
156 setUpLayout(); 156 setUpLayout();
157 } 157 }
158 } 158 }
159} 159}
160 160
161void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label)
162{
163 OTabInfo *currtab = tabs.first();
164 while ( currtab && currtab->control() != widget )
165 {
166 currtab = tabs.next();
167 }
168 if ( currtab && currtab->control() == widget )
169 {
170 QTab *tab = tabBar->tab( currtab->id() );
171 QPixmap icon( loadSmooth( iconset ) );
172 tab->setText( label );
173 if ( tabBarStyle == IconTab )
174 tab->setIconSet( icon );
175 int i = 0;
176 while ( i < tabList->count() && tabList->text( i ) != currtab->label() )
177 {
178 i++;
179 }
180 if ( i < tabList->count() && tabList->text( i ) == currtab->label() )
181 {
182 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
183 {
184 tabList->changeItem( icon, label, i );
185 }
186 else
187 {
188 tabList->changeItem( label, i );
189 }
190 }
191 currtab->setLabel( label );
192 currtab->setIcon( iconset );
193 }
194 setUpLayout();
195}
196
161void OTabWidget::setCurrentTab( QWidget *childwidget ) 197void OTabWidget::setCurrentTab( QWidget *childwidget )
162{ 198{
163 OTabInfo *newtab = tabs.first(); 199 OTabInfo *currtab = tabs.first();
164 while ( newtab && newtab->control() != childwidget ) 200 while ( currtab && currtab->control() != childwidget )
165 { 201 {
166 newtab = tabs.next(); 202 currtab = tabs.next();
167 } 203 }
168 if ( newtab && newtab->control() == childwidget ) 204 if ( currtab && currtab->control() == childwidget )
169 { 205 {
170 selectTab( newtab ); 206 selectTab( currtab );
171 } 207 }
172} 208}
173 209
174void OTabWidget::setCurrentTab( const QString &tabname ) 210void OTabWidget::setCurrentTab( const QString &tabname )
175{ 211{
176 OTabInfo *newtab = tabs.first(); 212 OTabInfo *newtab = tabs.first();
177 while ( newtab && newtab->label() != tabname ) 213 while ( newtab && newtab->label() != tabname )
178 { 214 {
179 newtab = tabs.next(); 215 newtab = tabs.next();
180 } 216 }
181 if ( newtab && newtab->label() == tabname ) 217 if ( newtab && newtab->label() == tabname )
182 { 218 {
183 selectTab( newtab ); 219 selectTab( newtab );
184 } 220 }
185} 221}
186 222
187void OTabWidget::setCurrentTab(int tabindex) { 223void OTabWidget::setCurrentTab(int tabindex) {
188 OTabInfo *newtab = tabs.first(); 224 OTabInfo *newtab = tabs.first();
189 while ( newtab && newtab->id() != tabindex ) 225 while ( newtab && newtab->id() != tabindex )
190 { 226 {
191 newtab = tabs.next(); 227 newtab = tabs.next();
192 } 228 }
193 if ( newtab && newtab->id() == tabindex ) 229 if ( newtab && newtab->id() == tabindex )
194 { 230 {
195 selectTab( newtab ); 231 selectTab( newtab );
196 } 232 }
197} 233}
198 234
199 235
200OTabWidget::TabStyle OTabWidget::tabStyle() const 236OTabWidget::TabStyle OTabWidget::tabStyle() const
201{ 237{
202 return tabBarStyle; 238 return tabBarStyle;
203} 239}
204 240
205void OTabWidget::setTabStyle( TabStyle s ) 241void OTabWidget::setTabStyle( TabStyle s )
206{ 242{
207 tabBarStyle = s; 243 tabBarStyle = s;
208 if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) 244 if ( tabBarStyle == TextTab || tabBarStyle == IconTab )
209 { 245 {
210 QTab *currtab; 246 QTab *currtab;
211 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) 247 for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
212 { 248 {
213 currtab = tabBar->tab( tabinfo->id() ); 249 currtab = tabBar->tab( tabinfo->id() );
214 if ( tabBarStyle == IconTab ) 250 if ( tabBarStyle == IconTab )
215 { 251 {
216 currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); 252 currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) );
217 if ( tabinfo == currentTab ) 253 if ( tabinfo == currentTab )
218 currtab->setText( tabinfo->label() ); 254 currtab->setText( tabinfo->label() );
diff --git a/libopie/otabwidget.h b/libopie/otabwidget.h
index 74d683b..0aa9bb8 100644
--- a/libopie/otabwidget.h
+++ b/libopie/otabwidget.h
@@ -81,96 +81,106 @@ public:
81 * @enum TabPosition 81 * @enum TabPosition
82 * @brief Defines where the widget selection control is drawn. 82 * @brief Defines where the widget selection control is drawn.
83 * 83 *
84 * Valid values: 84 * Valid values:
85 * - Top: Widget selection control is drawn above widgets 85 * - Top: Widget selection control is drawn above widgets
86 * - Bottom: Widget selection control is drawn below widgets 86 * - Bottom: Widget selection control is drawn below widgets
87 */ 87 */
88 enum TabPosition { Top, Bottom }; 88 enum TabPosition { Top, Bottom };
89 89
90/** 90/**
91 * @fn OTabWidget( QWidget *parent = 0, const char *name = 0, TabStyle s = Global, TabPosition p = Top ) 91 * @fn OTabWidget( QWidget *parent = 0, const char *name = 0, TabStyle s = Global, TabPosition p = Top )
92 * @brief Object constructor. 92 * @brief Object constructor.
93 * 93 *
94 * @param parent Pointer to parent of this control. 94 * @param parent Pointer to parent of this control.
95 * @param name Name of control. 95 * @param name Name of control.
96 * @param s Style of widget selection control. 96 * @param s Style of widget selection control.
97 * @param p Position of the widget selection control. 97 * @param p Position of the widget selection control.
98 * 98 *
99 * Constructs a new OTabWidget control with parent and name. The style and position parameters 99 * Constructs a new OTabWidget control with parent and name. The style and position parameters
100 * determine how the widget selection control will be displayed. 100 * determine how the widget selection control will be displayed.
101 */ 101 */
102 OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top ); 102 OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top );
103 103
104/** 104/**
105 * @fn ~OTabWidget() 105 * @fn ~OTabWidget()
106 * @brief Object destructor. 106 * @brief Object destructor.
107 */ 107 */
108 ~OTabWidget(); 108 ~OTabWidget();
109 109
110/** 110/**
111 * @fn addTab( QWidget *child, const QString &icon, const QString &label ) 111 * @fn addTab( QWidget *child, const QString &icon, const QString &label )
112 * @brief Add new widget to control. 112 * @brief Add new widget to control.
113 * 113 *
114 * @param child Widget control. 114 * @param child Widget control.
115 * @param icon Path to icon. 115 * @param icon Path to icon.
116 * @param label Text label. 116 * @param label Text label.
117 */ 117 */
118 void addTab( QWidget *, const QString &, const QString & ); 118 void addTab( QWidget *, const QString &, const QString & );
119 119
120/** 120/**
121 * @fn removePage( QWidget *widget ) 121 * @fn removePage( QWidget *widget )
122 * @brief Remove widget from control. Does not delete widget. 122 * @brief Remove widget from control. Does not delete widget.
123 * 123 *
124 * @param widget Widget control to be removed. 124 * @param widget Widget control to be removed.
125 */ 125 */
126 void removePage( QWidget * ); 126 void removePage( QWidget * );
127 127
128/** 128/**
129 * @fn changeTab( QWidget *widget, const QIconSet &icon, const QString &label )
130 * @brief Change text and/or icon for existing tab
131 *
132 * @param child Widget control.
133 * @param icon Path to icon.
134 * @param label Text label.
135 */
136 void changeTab( QWidget *, const QString &, const QString & );
137
138/**
129 * @fn tabStyle() 139 * @fn tabStyle()
130 * @brief Returns current widget selection control style. 140 * @brief Returns current widget selection control style.
131 */ 141 */
132 TabStyle tabStyle() const; 142 TabStyle tabStyle() const;
133 143
134/** 144/**
135 * @fn setTabStyle( TabStyle s ) 145 * @fn setTabStyle( TabStyle s )
136 * @brief Set the current widget selection control style. 146 * @brief Set the current widget selection control style.
137 * 147 *
138 * @param s New style to be used. 148 * @param s New style to be used.
139 */ 149 */
140 void setTabStyle( TabStyle ); 150 void setTabStyle( TabStyle );
141 151
142/** 152/**
143 * @fn tabPosition() 153 * @fn tabPosition()
144 * @brief Returns current widget selection control position. 154 * @brief Returns current widget selection control position.
145 */ 155 */
146 TabPosition tabPosition() const; 156 TabPosition tabPosition() const;
147 157
148/** 158/**
149 * @fn setTabPosition( TabPosition p ) 159 * @fn setTabPosition( TabPosition p )
150 * @brief Set the current widget selection control position. 160 * @brief Set the current widget selection control position.
151 * 161 *
152 * @param p New position of widget selection control. 162 * @param p New position of widget selection control.
153 */ 163 */
154 void setTabPosition( TabPosition ); 164 void setTabPosition( TabPosition );
155 165
156/** 166/**
157 * @fn setCurrentTab( QWidget *childwidget ) 167 * @fn setCurrentTab( QWidget *childwidget )
158 * @brief Selects and brings to top the desired widget by using widget pointer. 168 * @brief Selects and brings to top the desired widget by using widget pointer.
159 * 169 *
160 * @param childwidget Widget to select. 170 * @param childwidget Widget to select.
161 */ 171 */
162 void setCurrentTab( QWidget * ); 172 void setCurrentTab( QWidget * );
163 173
164/** 174/**
165 * @fn setCurrentTab( const QString &tabname ) 175 * @fn setCurrentTab( const QString &tabname )
166 * @brief Selects and brings to top the desired widget, by using label. 176 * @brief Selects and brings to top the desired widget, by using label.
167 * 177 *
168 * @param tabname Text label for widget to select. 178 * @param tabname Text label for widget to select.
169 */ 179 */
170 void setCurrentTab( const QString & ); 180 void setCurrentTab( const QString & );
171 181
172/** 182/**
173 * @fn setCurrentTab( int ) 183 * @fn setCurrentTab( int )
174 * @brief Selects and brings to top the desired widget, by using id. 184 * @brief Selects and brings to top the desired widget, by using id.
175 * 185 *
176 * @param tab id for widget to select. 186 * @param tab id for widget to select.