00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "osplitter.h"
00030
00031
00032 #include <opie2/otabwidget.h>
00033 #include <opie2/odebug.h>
00034
00035
00036 #include <qvaluelist.h>
00037 #include <qvbox.h>
00038
00039 using namespace Opie::Ui;
00040 using namespace Opie::Ui::Internal;
00041
00061 OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFlags fl )
00062 : QFrame( parent, name, fl )
00063 {
00064 m_orient = orient;
00065 m_hbox = 0;
00066 m_size_policy = 330;
00067 setFontPropagation( AllChildren );
00068 setPalettePropagation( AllChildren );
00069
00070
00071 m_tabWidget = 0;
00072 m_parentTab = 0;
00073 changeTab();
00074
00075 }
00076
00077
00083 OSplitter::~OSplitter()
00084 {
00085 m_splitter.setAutoDelete( true );
00086 m_splitter.clear();
00087
00088 delete m_hbox;
00089 delete m_tabWidget;
00090 }
00091
00092
00101 void OSplitter::setLabel( const QString& name )
00102 {
00103 m_name = name;
00104 }
00105
00111 void OSplitter::setIconName( const QString& name )
00112 {
00113 m_icon = name;
00114 }
00115
00116
00121 QString OSplitter::iconName()const
00122 {
00123 return m_icon;
00124 }
00125
00130 QString OSplitter::label()const
00131 {
00132 return m_name;
00133 }
00134
00148 void OSplitter::setSizeChange( int width_height )
00149 {
00150 m_size_policy = width_height;
00151 QSize sz(width(), height() );
00152 QResizeEvent ev(sz, sz );
00153 resizeEvent(&ev);
00154 }
00155
00161 void OSplitter::addWidget( OSplitter* split )
00162 {
00163 m_splitter.append( split );
00164
00165
00166
00167
00168 if (m_tabWidget )
00169 setTabWidget( m_parentTab );
00170 else
00171 {
00172 OSplitterContainer con;
00173 con.widget =split;
00174 addToBox( con );
00175 }
00176 }
00177
00178
00179
00180
00181
00189 void OSplitter::removeWidget( OSplitter* split)
00190 {
00191 split->setTabWidget( 0 );
00192 split->reparent( 0, 0, QPoint(0, 0) );
00193 }
00194
00208 void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& label )
00209 {
00210 #ifdef DEBUG
00211 if (!wid )
00212 return;
00213 #endif
00214 OSplitterContainer cont;
00215 cont.widget = wid;
00216 cont.icon =icon;
00217 cont.name = label;
00218
00219 m_container.append( cont );
00220
00221
00222
00223
00224 if (!m_splitter.isEmpty() && (m_tabWidget || m_parentTab ) )
00225 setTabWidget( m_parentTab );
00226 else
00227 {
00228 if (m_hbox )
00229 addToBox( cont );
00230 else
00231 addToTab( cont );
00232 }
00233 }
00234
00235
00244 void OSplitter::removeWidget( QWidget* w)
00245 {
00246 ContainerList::Iterator it;
00247 for ( it = m_container.begin(); it != m_container.end(); ++it )
00248 if ( (*it).widget == w )
00249 break;
00250
00251 if (it == m_container.end() )
00252 return;
00253
00254
00255
00256 if ( !m_hbox )
00257 removeFromTab( w );
00258
00259
00260
00261
00262 w->reparent( 0, 0, QPoint(0, 0));
00263 it = m_container.remove( it );
00264
00265 }
00266
00267
00274 void OSplitter::setCurrentWidget( QWidget* w)
00275 {
00276 if (m_tabWidget )
00277 m_tabWidget->setCurrentTab( w );
00278
00279
00280
00281 }
00282
00290 void OSplitter::setCurrentWidget( const QString& label )
00291 {
00292 ContainerList::Iterator it;
00293 for (it = m_container.begin(); it != m_container.end(); ++it )
00294 {
00295 if ( (*it).name == label )
00296 {
00297 setCurrentWidget( (*it).widget );
00298 break;
00299 }
00300 }
00301 }
00302
00310 void OSplitter::setCurrentWidget( int tab )
00311 {
00312 if (m_tabWidget )
00313 m_tabWidget->setCurrentTab( tab );
00314 }
00315
00320 QWidget* OSplitter::currentWidget() const
00321 {
00322 if (m_tabWidget)
00323 return m_tabWidget->currentWidget();
00324 else if (m_parentTab )
00325 return m_parentTab->currentWidget();
00326
00327 return 0l;
00328 }
00329
00330 #if 0
00331
00335 QSize OSplitter::sizeHint()const
00336 {
00337 if (m_parentTab )
00338 return QFrame::sizeHint();
00339
00340 if (m_hbox )
00341 return m_hbox->sizeHint();
00342 else
00343 return m_tabWidget->sizeHint();
00344 }
00345
00346 QSize OSplitter::minimumSizeHint()const
00347 {
00348 if (m_parentTab )
00349 return QFrame::minimumSizeHint();
00350 if (m_hbox)
00351 return m_hbox->sizeHint();
00352 else
00353 return m_tabWidget->sizeHint();
00354 }
00355 #endif
00356
00360 void OSplitter::resizeEvent( QResizeEvent* res )
00361 {
00362 QFrame::resizeEvent( res );
00363
00364
00365
00366 bool mode = true;
00367 if ( res->size().width() > m_size_policy &&
00368 m_orient == Horizontal )
00369 {
00370 changeHBox();
00371 mode = false;
00372 }
00373 else if ( (res->size().width() <= m_size_policy &&
00374 m_orient == Horizontal ) ||
00375 (res->size().height() <= m_size_policy &&
00376 m_orient == Vertical ) )
00377 {
00378 changeTab();
00379 }
00380 else if ( res->size().height() > m_size_policy &&
00381 m_orient == Vertical )
00382 {
00383 changeVBox();
00384 mode = false;
00385 }
00386
00387 emit sizeChanged(mode, m_orient );
00388 }
00389
00390
00391
00392
00393
00394 void OSplitter::addToTab( const Opie::Ui::Internal::OSplitterContainer& con )
00395 {
00396 QWidget *wid = con.widget;
00397
00398 if (m_parentTab )
00399 m_parentTab->addTab( wid, con.icon, con.name );
00400 else
00401 m_tabWidget->addTab( wid, con.icon, con.name );
00402 }
00403
00404
00405
00406
00407
00408 void OSplitter::addToBox( const Opie::Ui::Internal::OSplitterContainer& con )
00409 {
00410 QWidget* wid = con.widget;
00411 wid->reparent(m_hbox, 0, QPoint(0, 0) );
00412 }
00413
00414
00415
00416
00417
00418 void OSplitter::removeFromTab( QWidget* wid )
00419 {
00420 if (m_parentTab )
00421 m_parentTab->removePage( wid );
00422 else
00423 m_tabWidget->removePage( wid );
00424 }
00425
00426
00427
00428
00429
00430 void OSplitter::changeTab()
00431 {
00432
00433 if (m_tabWidget )
00434 {
00435 raise();
00436 show();
00437 m_tabWidget->setGeometry( frameRect() );
00438 return;
00439 }
00440
00441
00442
00443
00444
00445
00446 OTabWidget *tab;
00447 if ( m_parentTab )
00448 {
00449 hide();
00450 tab = m_parentTab;
00451
00452 if (!m_container.isEmpty() )
00453 {
00454 ContainerList::Iterator it = m_container.begin();
00455 for (; it != m_container.end(); ++it )
00456 m_parentTab->removePage( (*it).widget );
00457 }
00458 }
00459 else
00460 tab = m_tabWidget = new OTabWidget( this );
00461
00462 connect(tab, SIGNAL(currentChanged(QWidget*) ),
00463 this, SIGNAL(currentChanged(QWidget*) ) );
00464
00465 for ( ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it )
00466 {
00467 addToTab( (*it) );
00468 }
00469
00470 for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() )
00471 {
00472 split->reparent(this, 0, QPoint(0, 0) );
00473 split->setTabWidget( tab );
00474 }
00475
00476
00477 delete m_hbox;
00478 m_hbox = 0;
00479 if (!m_tabWidget )
00480 return;
00481
00482 m_tabWidget->setGeometry( frameRect() );
00483 m_tabWidget->show();
00484
00485 }
00486
00487
00488
00489
00490
00491 void OSplitter::changeHBox()
00492 {
00493 if (m_hbox )
00494 {
00495 m_hbox->setGeometry( frameRect() );
00496 return;
00497 }
00498
00499 m_hbox = new QHBox( this );
00500 commonChangeBox();
00501 }
00502
00503 void OSplitter::changeVBox()
00504 {
00505 if (m_hbox )
00506 {
00507 m_hbox->setGeometry( frameRect() );
00508 return;
00509 }
00510
00511 m_hbox = new QVBox( this );
00512
00513 commonChangeBox();
00514
00515 }
00516
00517
00518
00519
00520
00521
00522
00523 void OSplitter::commonChangeBox()
00524 {
00525 for (ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it )
00526 {
00527
00528 if (m_parentTab )
00529 removeFromTab( (*it).widget );
00530 addToBox( (*it) );
00531 }
00532 for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() )
00533 {
00534
00535 split->setTabWidget( 0 );
00536 OSplitterContainer con;
00537 con.widget = split;
00538
00539
00540 addToBox( con );
00541 }
00542
00543
00544
00545 if (m_parentTab )
00546 m_parentTab->addTab(m_hbox, iconName(), label() );
00547 else
00548 {
00549 m_hbox->setGeometry( frameRect() );
00550 m_hbox->show();
00551 delete m_tabWidget;
00552 m_tabWidget = 0;
00553 show();
00554 }
00555 }
00556
00557
00558
00559
00560 void OSplitter::setTabWidget( OTabWidget* wid)
00561 {
00562
00563 if ( m_parentTab )
00564 {
00565 if (m_hbox )
00566 m_parentTab->removePage( m_hbox );
00567 else if (!m_container.isEmpty() )
00568 {
00569 ContainerList::Iterator it = m_container.begin();
00570 for ( ; it != m_container.end(); ++it )
00571 m_parentTab->removePage( (*it).widget );
00572 }
00573 }
00574
00575
00576 m_parentTab = wid;
00577
00578 QWidget *tab = m_tabWidget;
00579 QWidget *box = m_hbox;
00580 m_hbox = 0; m_tabWidget = 0;
00581
00582 if ( layoutMode() )
00583 changeTab();
00584 else if (m_orient == Horizontal )
00585 changeHBox();
00586 else
00587 changeVBox();
00588
00589
00590 delete tab;
00591 delete box;
00592 }
00593
00594 #if 0
00595 void OSplitter::reparentAll()
00596 {
00597 if (m_container.isEmpty() )
00598 return;
00599
00600 ContainerList::Iterator it = m_container.begin();
00601 for ( ; it != m_container.end(); ++it )
00602 (*it).wid->reparent(0, 0, QPoint(0, 0) );
00603
00604
00605 }
00606 #endif
00607
00611 bool OSplitter::layoutMode()const
00612 {
00613 if ( size().width() > m_size_policy &&
00614 m_orient == Horizontal )
00615 {
00616 return false;
00617 }
00618 else if ( size().height() > m_size_policy &&
00619 m_orient == Vertical )
00620 {
00621 return false;
00622 }
00623
00624 return true;
00625 }