summaryrefslogtreecommitdiff
path: root/libopie/otabwidget.cpp
authorharlekin <harlekin>2002-10-05 22:15:43 (UTC)
committer harlekin <harlekin>2002-10-05 22:15:43 (UTC)
commit94180a2019a945e6a492405dc6a30420c760529f (patch) (unidiff)
treed50e2c308b94a563f82db8bd9086cfc46da09c0f /libopie/otabwidget.cpp
parent4e27d072b90cf1d877f0f31b44da10639ff3803f (diff)
downloadopie-94180a2019a945e6a492405dc6a30420c760529f.zip
opie-94180a2019a945e6a492405dc6a30420c760529f.tar.gz
opie-94180a2019a945e6a492405dc6a30420c760529f.tar.bz2
making otabwidget more simular to qtabwidget - drw
Diffstat (limited to 'libopie/otabwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/otabwidget.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/libopie/otabwidget.cpp b/libopie/otabwidget.cpp
index d5b963b..1f3fbb0 100644
--- a/libopie/otabwidget.cpp
+++ b/libopie/otabwidget.cpp
@@ -65,107 +65,137 @@ OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPositi
65 tabBarStyle = s; 65 tabBarStyle = s;
66 tabBarPosition = p; 66 tabBarPosition = p;
67 } 67 }
68 68
69 widgetStack = new QWidgetStack( this, "widgetstack" ); 69 widgetStack = new QWidgetStack( this, "widgetstack" );
70 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); 70 widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
71 widgetStack->setLineWidth( style().defaultFrameWidth() ); 71 widgetStack->setLineWidth( style().defaultFrameWidth() );
72 72
73 tabBarStack = new QWidgetStack( this, "tabbarstack" ); 73 tabBarStack = new QWidgetStack( this, "tabbarstack" );
74 74
75 tabBar = new OTabBar( tabBarStack, "tabbar" ); 75 tabBar = new OTabBar( tabBarStack, "tabbar" );
76 tabBarStack->addWidget( tabBar, 0 ); 76 tabBarStack->addWidget( tabBar, 0 );
77 connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) ); 77 connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) );
78 78
79 tabList = new QComboBox( false, tabBarStack, "tablist" ); 79 tabList = new QComboBox( false, tabBarStack, "tablist" );
80 tabBarStack->addWidget( tabList, 1 ); 80 tabBarStack->addWidget( tabList, 1 );
81 connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) ); 81 connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) );
82 82
83 if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) 83 if ( tabBarStyle == TextTab || tabBarStyle == IconTab )
84 { 84 {
85 tabBarStack->raiseWidget( tabBar ); 85 tabBarStack->raiseWidget( tabBar );
86 } 86 }
87 else if ( tabBarStyle == TextList || tabBarStyle == IconList ) 87 else if ( tabBarStyle == TextList || tabBarStyle == IconList )
88 { 88 {
89 tabBarStack->raiseWidget( tabList ); 89 tabBarStack->raiseWidget( tabList );
90 } 90 }
91 91
92 if ( tabBarPosition == Bottom ) 92 if ( tabBarPosition == Bottom )
93 { 93 {
94 tabBar->setShape( QTabBar::RoundedBelow ); 94 tabBar->setShape( QTabBar::RoundedBelow );
95 } 95 }
96 96
97 tabs.setAutoDelete( TRUE );
97 currentTab= 0x0; 98 currentTab= 0x0;
98} 99}
99 100
100OTabWidget::~OTabWidget() 101OTabWidget::~OTabWidget()
101{ 102{
102} 103}
103 104
104void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) 105void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
105{ 106{
106 QPixmap iconset = loadSmooth( icon ); 107 QPixmap iconset = loadSmooth( icon );
107 108
108 QTab * tab = new QTab(); 109 QTab * tab = new QTab();
109 if ( tabBarStyle == IconTab ) 110 if ( tabBarStyle == IconTab )
110 { 111 {
111 tab->label = QString::null; 112 tab->label = QString::null;
112 } 113 }
113 else 114 else
114 { 115 {
115 tab->label = label; 116 tab->label = label;
116 } 117 }
117 if ( tabBarStyle == IconTab || tabBarStyle == IconList) 118 if ( tabBarStyle == IconTab || tabBarStyle == IconList)
118 { 119 {
119 tab->iconset = new QIconSet( iconset ); 120 tab->iconset = new QIconSet( iconset );
120 } 121 }
121 int tabid = tabBar->addTab( tab ); 122 int tabid = tabBar->addTab( tab );
122 123
123 if ( tabBarStyle == IconTab || tabBarStyle == IconList ) 124 if ( tabBarStyle == IconTab || tabBarStyle == IconList )
124 { 125 {
125 tabList->insertItem( iconset, label, -1 ); 126 tabList->insertItem( iconset, label, -1 );
126 } 127 }
127 else 128 else
128 { 129 {
129 tabList->insertItem( label ); 130 tabList->insertItem( label );
130 } 131 }
131 132
132 widgetStack->addWidget( child, tabid ); 133 widgetStack->addWidget( child, tabid );
133 widgetStack->raiseWidget( child ); 134 widgetStack->raiseWidget( child );
134 135
135 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); 136 OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label );
136 tabs.append( tabinfo ); 137 tabs.append( tabinfo );
137 selectTab( tabinfo ); 138 selectTab( tabinfo );
138} 139}
139 140
141void OTabWidget::removePage( QWidget *childwidget )
142{
143 if ( childwidget )
144 {
145 OTabInfo *tab = tabs.first();
146 while ( tab && tab->control() != childwidget )
147 {
148 tab = tabs.next();
149 }
150 if ( tab && tab->control() == childwidget )
151 {
152 tabBar->setTabEnabled( tab->id(), FALSE );
153 tabBar->removeTab( tabBar->tab( tab->id() ) );
154 int i = 0;
155 while ( i < tabList->count() && tabList->text( i ) != tab->label() )
156 {
157 i++;
158 }
159 if ( tabList->text( i ) == tab->label() )
160 {
161 tabList->removeItem( i );
162 }
163 widgetStack->removeWidget( childwidget );
164 tabs.remove( tab );
165 setUpLayout();
166 }
167 }
168}
169
140void OTabWidget::setCurrentTab( QWidget *childwidget ) 170void OTabWidget::setCurrentTab( QWidget *childwidget )
141{ 171{
142 OTabInfo *newtab = tabs.first(); 172 OTabInfo *newtab = tabs.first();
143 while ( newtab && newtab->control() != childwidget ) 173 while ( newtab && newtab->control() != childwidget )
144 { 174 {
145 newtab = tabs.next(); 175 newtab = tabs.next();
146 } 176 }
147 if ( newtab && newtab->control() == childwidget ) 177 if ( newtab && newtab->control() == childwidget )
148 { 178 {
149 selectTab( newtab ); 179 selectTab( newtab );
150 } 180 }
151} 181}
152 182
153void OTabWidget::setCurrentTab( const QString &tabname ) 183void OTabWidget::setCurrentTab( const QString &tabname )
154{ 184{
155 OTabInfo *newtab = tabs.first(); 185 OTabInfo *newtab = tabs.first();
156 while ( newtab && newtab->label() != tabname ) 186 while ( newtab && newtab->label() != tabname )
157 { 187 {
158 newtab = tabs.next(); 188 newtab = tabs.next();
159 } 189 }
160 if ( newtab && newtab->label() == tabname ) 190 if ( newtab && newtab->label() == tabname )
161 { 191 {
162 selectTab( newtab ); 192 selectTab( newtab );
163 } 193 }
164} 194}
165 195
166OTabWidget::TabStyle OTabWidget::tabStyle() const 196OTabWidget::TabStyle OTabWidget::tabStyle() const
167{ 197{
168 return tabBarStyle; 198 return tabBarStyle;
169} 199}
170 200
171void OTabWidget::setTabStyle( TabStyle s ) 201void OTabWidget::setTabStyle( TabStyle s )
@@ -201,64 +231,66 @@ void OTabWidget::slotTabListSelected( int index )
201 OTabInfo *newtab = tabs.at( index ); 231 OTabInfo *newtab = tabs.at( index );
202 if ( newtab ) 232 if ( newtab )
203 { 233 {
204 selectTab( newtab ); 234 selectTab( newtab );
205 } 235 }
206} 236}
207 237
208QPixmap OTabWidget::loadSmooth( const QString &name ) 238QPixmap OTabWidget::loadSmooth( const QString &name )
209{ 239{
210 QImage image = Resource::loadImage( name ); 240 QImage image = Resource::loadImage( name );
211 QPixmap pixmap; 241 QPixmap pixmap;
212 pixmap.convertFromImage( image.smoothScale( 16, 16 ) ); 242 pixmap.convertFromImage( image.smoothScale( 16, 16 ) );
213 return pixmap; 243 return pixmap;
214} 244}
215 245
216void OTabWidget::selectTab( OTabInfo *tab ) 246void OTabWidget::selectTab( OTabInfo *tab )
217{ 247{
218 if ( tabBarStyle == IconTab ) 248 if ( tabBarStyle == IconTab )
219 { 249 {
220 if ( currentTab ) 250 if ( currentTab )
221 { 251 {
222 tabBar->tab( currentTab->id() )->setText( QString::null ); 252 tabBar->tab( currentTab->id() )->setText( QString::null );
223 setUpLayout(); 253 setUpLayout();
224 } 254 }
225 tabBar->tab( tab->id() )->setText( tab->label() ); 255 tabBar->tab( tab->id() )->setText( tab->label() );
226 currentTab = tab; 256 currentTab = tab;
227 } 257 }
228 tabBar->setCurrentTab( tab->id() ); 258 tabBar->setCurrentTab( tab->id() );
229 setUpLayout(); 259 setUpLayout();
230 tabBar->update(); 260 tabBar->update();
231 261
232 widgetStack->raiseWidget( tab->control() ); 262 widgetStack->raiseWidget( tab->control() );
263
264 emit currentChanged( tab->control() );
233} 265}
234 266
235void OTabWidget::setUpLayout() 267void OTabWidget::setUpLayout()
236{ 268{
237 tabBar->layoutTabs(); 269 tabBar->layoutTabs();
238 QSize t( tabBarStack->sizeHint() ); 270 QSize t( tabBarStack->sizeHint() );
239 if ( t.width() > width() ) 271 if ( t.width() > width() )
240 t.setWidth( width() ); 272 t.setWidth( width() );
241 int lw = widgetStack->lineWidth(); 273 int lw = widgetStack->lineWidth();
242 if ( tabBarPosition == Bottom ) 274 if ( tabBarPosition == Bottom )
243 { 275 {
244 tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); 276 tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() );
245 widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); 277 widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) );
246 } 278 }
247 else 279 else
248 { 280 {
249 tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); 281 tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() );
250 widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX(0, lw-2)); 282 widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX(0, lw-2));
251 } 283 }
252 284
253 if ( autoMask() ) 285 if ( autoMask() )
254 updateMask(); 286 updateMask();
255} 287}
256 288
257QSize OTabWidget::sizeHint() const 289QSize OTabWidget::sizeHint() const
258{ 290{
259 QSize s( widgetStack->sizeHint() ); 291 QSize s( widgetStack->sizeHint() );
260 QSize t( tabBarStack->sizeHint() ); 292 QSize t( tabBarStack->sizeHint() );
261 return QSize( QMAX( s.width(), t.width()), s.height() + t.height() ); 293 return QSize( QMAX( s.width(), t.width()), s.height() + t.height() );
262} 294}
263 295
264void OTabWidget::resizeEvent( QResizeEvent * ) 296void OTabWidget::resizeEvent( QResizeEvent * )