Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osplitter.cpp

Go to the documentation of this file.
00001 /*
00002                =.            This file is part of the OPIE Project
00003              .=l.            Copyright (c)  2003 hOlgAr <zecke@handhelds.org>
00004            .>+-=
00005  _;:,     .>    :=|.         This library is free software; you can
00006 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00007 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00008 .="- .-=="i,     .._         License as published by the Free Software
00009  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00010      ._= =}       :          or (at your option) any later version.
00011     .%`+i>       _;_.
00012     .i_,=:_.      -<s.       This library is distributed in the hope that
00013      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00014     : ..    .:,     . . .    without even the implied warranty of
00015     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00016   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00017 ..}^=.=       =       ;      Library General Public License for more
00018 ++=   -.     .`     .:       details.
00019  :     =  ...= . :.=-
00020  -.   .:....=;==+<;          You should have received a copy of the GNU
00021   -_. . .   )=.  =           Library General Public License along with
00022     --        :-=`           this library; see the file COPYING.LIB.
00023                              If not, write to the Free Software Foundation,
00024                              Inc., 59 Temple Place - Suite 330,
00025                              Boston, MA 02111-1307, USA.
00026 
00027 */
00028 
00029 #include "osplitter.h"
00030 
00031 /* OPIE */
00032 #include <opie2/otabwidget.h>
00033 #include <opie2/odebug.h>
00034 
00035 /* QT */
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     /* start by default with the tab widget */
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      * set tab widget
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  * If in a tab it should be removed
00180  * and if in a hbox  the reparent kills it too
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     /* only tab needs to be removed.. box recognizes it */
00256     if ( !m_hbox )
00257         removeFromTab( w );
00258 
00259 
00260     /* Find reparent it and remove it from our list */
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     //    else
00279     //      m_hbox->setFocus( w );
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 /* wrong */
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  * Adds a container to a tab either the parent tab
00392  * or our own
00393  */
00394 void OSplitter::addToTab( const Opie::Ui::Internal::OSplitterContainer& con )
00395 {
00396     QWidget *wid = con.widget;
00397     // not needed widgetstack will reparent as well    wid.reparent(m_tabWidget, wid->getWFlags(), QPoint(0, 0) );
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  * adds a container to the box
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  * Removes a widget from the tab
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  * switches over to a OTabWidget layout
00428  * it is recursive
00429  */
00430 void OSplitter::changeTab()
00431 {
00432     /* if we're the owner of the tab widget */
00433     if (m_tabWidget )
00434     {
00435         raise();
00436         show();
00437         m_tabWidget->setGeometry( frameRect() );
00438         return;
00439     }
00440 
00441     /*
00442      * and add all widgets this will reparent them
00443      * delete m_hbox set it to 0
00444      *
00445      */
00446     OTabWidget *tab;
00447     if ( m_parentTab )
00448     {
00449         hide();
00450         tab = m_parentTab;
00451         /* expensive but needed cause we're called from setTabWidget and resizeEvent*/
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  * changes over to a box
00489  * this is recursive as well
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  * common box code
00519  * first remove and add children
00520  * the other splitters
00521  * it is recursive as well due the call to setTabWidget
00522  */
00523 void OSplitter::commonChangeBox()
00524 {
00525     for (ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it )
00526     {
00527         /* only if parent tab.. m_tabWidgets gets deleted and would do that as well */
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         /* tell them the world had changed */
00535         split->setTabWidget( 0 );
00536         OSplitterContainer con;
00537         con.widget = split;
00538         //        con.widget = split->m_tabWidget ? static_cast<QWidget*>(split->m_tabWidget)
00539         //                     : static_cast<QWidget*>(split->m_hbox);
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(); // also show this widget
00554     }
00555 }
00556 
00557 /*
00558  * sets the tabwidget, removes tabs, and relayouts the widget
00559  */
00560 void OSplitter::setTabWidget( OTabWidget* wid)
00561 {
00562     /* clean up cause m_parentTab will not be available for us */
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     /* the parent Splitter changed so either make us indepent or dep */
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     /* our own crap is added and children from change* */
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 }

Generated on Sat Nov 5 16:16:24 2005 for OPIE by  doxygen 1.4.2