summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/otabwidget.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/libopie2/opieui/otabwidget.cpp b/libopie2/opieui/otabwidget.cpp
index d617a9c..7103884 100644
--- a/libopie2/opieui/otabwidget.cpp
+++ b/libopie2/opieui/otabwidget.cpp
@@ -76,183 +76,192 @@ OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPositi
76 setTabStyle( s ); 76 setTabStyle( s );
77 setTabPosition( p ); 77 setTabPosition( p );
78} 78}
79 79
80OTabWidget::~OTabWidget() 80OTabWidget::~OTabWidget()
81{ 81{
82 m_tabs.setAutoDelete( true ); 82 m_tabs.setAutoDelete( true );
83 m_tabs.clear(); 83 m_tabs.clear();
84} 84}
85 85
86void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) 86void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
87{ 87{
88 int tabid = -1; 88 int tabid = -1;
89 89
90 if ( m_usingTabs ) 90 if ( m_usingTabs )
91 { 91 {
92 // Create new tab in tab bar 92 // Create new tab in tab bar
93 QTab *tab = new QTab(); 93 QTab *tab = new QTab();
94 94
95 // Set label (and icon if necessary) 95 // Set label (and icon if necessary)
96 if ( m_tabBarStyle == IconTab ) 96 if ( m_tabBarStyle == IconTab )
97 { 97 {
98 tab->label = QString::null; 98 tab->label = QString::null;
99 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 ) );
100 } 100 }
101 else 101 else
102 tab->label = label; 102 tab->label = label;
103 103
104 tabid = m_tabBar->addTab( tab ); 104 tabid = m_tabBar->addTab( tab );
105 } 105 }
106 else 106 else
107 { 107 {
108 // Insert entry (with icon if necessary) into drop down list 108 // Insert entry (with icon if necessary) into drop down list
109 if ( m_tabBarStyle == IconList ) 109 if ( m_tabBarStyle == IconList )
110 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 );
111 else 111 else
112 m_tabList->insertItem( label ); 112 m_tabList->insertItem( label );
113 } 113 }
114 114
115 // Add widget to stack 115 // Add widget to stack
116 m_widgetStack->addWidget( child, tabid ); 116 m_widgetStack->addWidget( child, tabid );
117 m_widgetStack->raiseWidget( child ); 117 m_widgetStack->raiseWidget( child );
118 m_widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); 118 m_widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
119 119
120 // Keep track of tab information 120 // Keep track of tab information
121 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); 121 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label );
122 m_tabs.append( tabinfo ); 122 m_tabs.append( tabinfo );
123 123
124 // Force resizing of child controls
125 resizeEvent( 0x0 );
126
124 // Make newly added tab the current one displayed 127 // Make newly added tab the current one displayed
125 selectTab( tabinfo ); 128 selectTab( tabinfo );
126} 129}
127 130
128void OTabWidget::removePage( QWidget *childwidget ) 131void OTabWidget::removePage( QWidget *childwidget )
129{ 132{
130 if ( childwidget ) 133 if ( childwidget )
131 { 134 {
132 // Find tab information for desired widget 135 // Find tab information for desired widget
133 OTabInfo *tab = m_tabs.first(); 136 OTabInfo *tab = m_tabs.first();
134 while ( tab && tab->control() != childwidget ) 137 while ( tab && tab->control() != childwidget )
135 tab = m_tabs.next(); 138 tab = m_tabs.next();
136 139
137 if ( tab && tab->control() == childwidget ) 140 if ( tab && tab->control() == childwidget )
138 { 141 {
139 if ( m_usingTabs ) 142 if ( m_usingTabs )
140 { 143 {
141 // Remove tab from tab bar 144 // Remove tab from tab bar
142 m_tabBar->setTabEnabled( tab->id(), false ); 145 m_tabBar->setTabEnabled( tab->id(), false );
143 m_tabBar->removeTab( m_tabBar->tab( tab->id() ) ); 146 m_tabBar->removeTab( m_tabBar->tab( tab->id() ) );
144 } 147 }
145 else 148 else
146 { 149 {
147 // Remove entry from drop down list 150 // Remove entry from drop down list
148 int i = 0; 151 int i = 0;
149 while ( i < m_tabList->count() && m_tabList->text( i ) != tab->label() ) 152 while ( i < m_tabList->count() && m_tabList->text( i ) != tab->label() )
150 i++; 153 i++;
151 if ( m_tabList->text( i ) == tab->label() ) 154 if ( m_tabList->text( i ) == tab->label() )
152 m_tabList->removeItem( i ); 155 m_tabList->removeItem( i );
153 } 156 }
154 157
155 // Remove widget from stack 158 // Remove widget from stack
156 m_widgetStack->removeWidget( childwidget ); 159 m_widgetStack->removeWidget( childwidget );
157 160
158 // Get rid of tab information 161 // Get rid of tab information
159 m_tabs.remove( tab ); 162 m_tabs.remove( tab );
160 delete tab; 163 delete tab;
161 164
162 // Reset current tab 165 // Reset current tab
163 m_currTab = m_tabs.current(); 166 m_currTab = m_tabs.current();
164 if ( !m_currTab ) 167 if ( !m_currTab )
165 m_widgetStack->setFrameStyle( QFrame::NoFrame ); 168 m_widgetStack->setFrameStyle( QFrame::NoFrame );
166 169
167 // Redraw widget 170 // Redraw widget
168 setUpLayout(); 171 setUpLayout();
169 } 172 }
173
174 // Force resizing of child controls
175 resizeEvent( 0x0 );
170 } 176 }
171} 177}
172 178
173void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) 179void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label)
174{ 180{
175 // Find tab information for desired widget 181 // Find tab information for desired widget
176 OTabInfo *currtab = m_tabs.first(); 182 OTabInfo *currtab = m_tabs.first();
177 while ( currtab && currtab->control() != widget ) 183 while ( currtab && currtab->control() != widget )
178 currtab = m_tabs.next(); 184 currtab = m_tabs.next();
179 185
180 if ( currtab && currtab->control() == widget ) 186 if ( currtab && currtab->control() == widget )
181 { 187 {
182 QPixmap icon( Opie::Core::OResource::loadPixmap( iconset, Opie::Core::OResource::SmallIcon ) ); 188 QPixmap icon( Opie::Core::OResource::loadPixmap( iconset, Opie::Core::OResource::SmallIcon ) );
183 189
184 if ( m_usingTabs ) 190 if ( m_usingTabs )
185 { 191 {
186 // Update tab label and icon (if necessary) 192 // Update tab label and icon (if necessary)
187 QTab *tab = m_tabBar->tab( currtab->id() ); 193 QTab *tab = m_tabBar->tab( currtab->id() );
188 tab->setText( label ); 194 tab->setText( label );
189 if ( m_tabBarStyle == IconTab ) 195 if ( m_tabBarStyle == IconTab )
190 tab->setIconSet( icon ); 196 tab->setIconSet( icon );
191 } 197 }
192 else 198 else
193 { 199 {
194 // Update entry label and icon (if necessary) 200 // Update entry label and icon (if necessary)
195 int i = 0; 201 int i = 0;
196 while ( i < m_tabList->count() && m_tabList->text( i ) != currtab->label() ) 202 while ( i < m_tabList->count() && m_tabList->text( i ) != currtab->label() )
197 i++; 203 i++;
198 if ( i < m_tabList->count() && m_tabList->text( i ) == currtab->label() ) 204 if ( i < m_tabList->count() && m_tabList->text( i ) == currtab->label() )
199 { 205 {
200 if ( m_tabBarStyle == IconList ) 206 if ( m_tabBarStyle == IconList )
201 m_tabList->changeItem( icon, label, i ); 207 m_tabList->changeItem( icon, label, i );
202 else 208 else
203 m_tabList->changeItem( label, i ); 209 m_tabList->changeItem( label, i );
204 } 210 }
205 } 211 }
206 212
207 // Update tab information 213 // Update tab information
208 currtab->setLabel( label ); 214 currtab->setLabel( label );
209 currtab->setIcon( iconset ); 215 currtab->setIcon( iconset );
210 216
217 // Force resizing of child controls
218 resizeEvent( 0x0 );
219
211 // Redraw widget 220 // Redraw widget
212 setUpLayout(); 221 setUpLayout();
213 } 222 }
214} 223}
215 224
216void OTabWidget::setCurrentTab( QWidget *childwidget ) 225void OTabWidget::setCurrentTab( QWidget *childwidget )
217{ 226{
218 OTabInfo *currtab = m_tabs.first(); 227 OTabInfo *currtab = m_tabs.first();
219 while ( currtab && currtab->control() != childwidget ) 228 while ( currtab && currtab->control() != childwidget )
220 { 229 {
221 currtab = m_tabs.next(); 230 currtab = m_tabs.next();
222 } 231 }
223 if ( currtab && currtab->control() == childwidget ) 232 if ( currtab && currtab->control() == childwidget )
224 { 233 {
225 selectTab( currtab ); 234 selectTab( currtab );
226 } 235 }
227} 236}
228 237
229void OTabWidget::setCurrentTab( const QString &tabname ) 238void OTabWidget::setCurrentTab( const QString &tabname )
230{ 239{
231 OTabInfo *newtab = m_tabs.first(); 240 OTabInfo *newtab = m_tabs.first();
232 while ( newtab && newtab->label() != tabname ) 241 while ( newtab && newtab->label() != tabname )
233 { 242 {
234 newtab = m_tabs.next(); 243 newtab = m_tabs.next();
235 } 244 }
236 if ( newtab && newtab->label() == tabname ) 245 if ( newtab && newtab->label() == tabname )
237 { 246 {
238 selectTab( newtab ); 247 selectTab( newtab );
239 } 248 }
240} 249}
241 250
242void OTabWidget::setCurrentTab(int tabindex) 251void OTabWidget::setCurrentTab(int tabindex)
243{ 252{
244 OTabInfo *newtab = m_tabs.first(); 253 OTabInfo *newtab = m_tabs.first();
245 while ( newtab && newtab->id() != tabindex ) 254 while ( newtab && newtab->id() != tabindex )
246 { 255 {
247 newtab = m_tabs.next(); 256 newtab = m_tabs.next();
248 } 257 }
249 if ( newtab && newtab->id() == tabindex ) 258 if ( newtab && newtab->id() == tabindex )
250 { 259 {
251 selectTab( newtab ); 260 selectTab( newtab );
252 } 261 }
253} 262}
254 263
255 264
256OTabWidget::TabStyle OTabWidget::tabStyle() const 265OTabWidget::TabStyle OTabWidget::tabStyle() const
257{ 266{
258 return m_tabBarStyle; 267 return m_tabBarStyle;