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
@@ -68,49 +68,65 @@ public:
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
@@ -77,49 +77,49 @@ OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPositi
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 )
@@ -137,58 +137,94 @@ void OTabWidget::removePage( QWidget *childwidget )
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 {
diff --git a/libopie/otabwidget.h b/libopie/otabwidget.h
index 74d683b..0aa9bb8 100644
--- a/libopie/otabwidget.h
+++ b/libopie/otabwidget.h
@@ -105,48 +105,58 @@ public:
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.