• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kmdi
 

kmdi

kmdichildarea.cpp
00001 //----------------------------------------------------------------------------
00002 //    filename             : kmdichildarea.cpp
00003 //----------------------------------------------------------------------------
00004 //    Project              : KDE MDI extension
00005 //
00006 //    begin                : 07/1999       by Szymon Stefanek as part of kvirc
00007 //                                         (an IRC application)
00008 //    changes              : 09/1999       by Falk Brettschneider to create an
00009 //                           - 06/2000     stand-alone Qt extension set of
00010 //                                         classes and a Qt-based library
00011 //                           2000-2003     maintained by the KDevelop project
00012 //
00013 //    copyright            : (C) 1999-2003 by Szymon Stefanek (stefanek@tin.it)
00014 //                                         and
00015 //                                         Falk Brettschneider
00016 //    email                :  falkbr@kdevelop.org (Falk Brettschneider)
00017 //----------------------------------------------------------------------------
00018 //
00019 //----------------------------------------------------------------------------
00020 //
00021 //    This program is free software; you can redistribute it and/or modify
00022 //    it under the terms of the GNU Library General Public License as
00023 //    published by the Free Software Foundation; either version 2 of the
00024 //    License, or (at your option) any later version.
00025 //
00026 //----------------------------------------------------------------------------
00027 
00028 #include "kmdichildarea.h"
00029 #include "kmdichildarea.moc"
00030 
00031 #include "kmdidefines.h"
00032 
00033 #include <kconfig.h>
00034 #include <kdebug.h>
00035 #include <kglobal.h>
00036 #include <kglobalsettings.h>
00037 
00038 #include <math.h>
00039 #include <tqpopupmenu.h>
00040 
00041 
00043 // KMdiChildArea
00045 
00046 //============ KMdiChildArea ============//
00047 
00048 KMdiChildArea::KMdiChildArea( TQWidget *parent )
00049         : TQFrame( parent, "kmdi_childarea" )
00050 {
00051     setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
00052     m_captionFont = TQFont();
00053     TQFontMetrics fm( m_captionFont );
00054     m_captionFontLineSpacing = fm.lineSpacing();
00055     m_captionActiveBackColor = KGlobalSettings::activeTitleColor();
00056     m_captionActiveForeColor = KGlobalSettings::activeTextColor();
00057     m_captionInactiveBackColor = KGlobalSettings::inactiveTitleColor();
00058     m_captionInactiveForeColor = KGlobalSettings::inactiveTextColor();
00059     m_pZ = new TQPtrList<KMdiChildFrm>;
00060     m_pZ->setAutoDelete( true );
00061     setFocusPolicy( TQ_ClickFocus );
00062     m_defaultChildFrmSize = TQSize( 400, 300 );
00063 }
00064 
00065 
00066 KMdiChildArea::~KMdiChildArea()
00067 {
00068     delete m_pZ; //This will destroy all the widgets inside.
00069 }
00070 
00071 
00072 void KMdiChildArea::manageChild( KMdiChildFrm* child, bool show, bool cascade )
00073 {
00074     kdDebug( 760 ) << k_funcinfo << "Adding child " << child << " to be managed" << endl;
00075     KMdiChildFrm* top = topChild();
00076     
00077     //remove old references. There can be more than one so we remove them all
00078     if ( m_pZ->findRef( child ) != -1 )
00079     {
00080         //TQPtrList::find* moves current() to the found item
00081         m_pZ->take(); 
00082         while ( m_pZ->findNextRef( child ) != -1 )
00083             m_pZ->take();
00084     }
00085 
00086     if ( show )
00087         m_pZ->append( child ); //visible -> first in the Z order
00088     else
00089         m_pZ->insert( 0, child ); //hidden -> last in the Z order
00090 
00091     if ( cascade )
00092         child->move( getCascadePoint( m_pZ->count() - 1 ) );
00093     
00094     if ( show )
00095     {
00096         if ( top && top->state() == KMdiChildFrm::Maximized )
00097         {
00098             kdDebug( 760 ) << k_funcinfo << "Maximizing the new child" << endl;
00099             emit sysButtonConnectionsMustChange( top, child );
00100             top->setState( KMdiChildFrm::Normal, false /*animate*/ );
00101             child->setState( KMdiChildFrm::Maximized, false /*animate*/ );
00102         }
00103         child->show();
00104         focusTopChild();
00105     }
00106 }
00107 
00108 
00109 void KMdiChildArea::destroyChild( KMdiChildFrm *child, bool focusTop )
00110 {
00111     kdDebug( 760 ) << k_funcinfo << "Removing child " << child->caption() << endl;
00112     bool wasMaximized = ( child->state() == KMdiChildFrm::Maximized );
00113 
00114     // destroy the old one
00115     disconnect( child );
00116     child->blockSignals( true );
00117     m_pZ->setAutoDelete( false );
00118     m_pZ->removeRef( child );
00119 
00120     // focus the next new childframe
00121     KMdiChildFrm* newTopChild = topChild();
00122     if ( wasMaximized )
00123     {
00124         if ( newTopChild )
00125         {
00126             newTopChild->setState( KMdiChildFrm::Maximized, false );
00127             emit sysButtonConnectionsMustChange( child, newTopChild );
00128         }
00129         else
00130             emit noMaximizedChildFrmLeft( child ); // last childframe removed
00131     }
00132     
00133     delete child;
00134     m_pZ->setAutoDelete( true );
00135 
00136     if ( focusTop )
00137         focusTopChild();
00138 }
00139 
00140 
00141 void KMdiChildArea::destroyChildButNotItsView( KMdiChildFrm* child, bool focusTop )
00142 {
00143     kdDebug( 760 ) << k_funcinfo << "Removing child " << child->caption() << endl;
00144     bool wasMaximized = ( child->state() == KMdiChildFrm::Maximized );
00145 
00146     // destroy the old one
00147     disconnect( child );
00148     child->unsetClient();
00149     m_pZ->setAutoDelete( false );
00150     m_pZ->removeRef( child );
00151 
00152     // focus the next new childframe
00153     KMdiChildFrm* newTopChild = topChild();
00154     if ( wasMaximized )
00155     {
00156         if ( newTopChild )
00157         {
00158             newTopChild->setState( KMdiChildFrm::Maximized, false );
00159             emit sysButtonConnectionsMustChange( child, newTopChild );
00160         }
00161         else
00162             emit noMaximizedChildFrmLeft( child ); // last childframe removed
00163     }
00164     delete child;
00165     m_pZ->setAutoDelete( true );
00166 
00167     if ( focusTop )
00168         focusTopChild();
00169 }
00170 
00171 void KMdiChildArea::setTopChild( KMdiChildFrm* child, bool /* bSetFocus */ )
00172 {
00173     if ( !child )
00174         return;
00175     
00176     if ( topChild() != child )
00177     {
00178         kdDebug( 760 ) << k_funcinfo << "Setting " << child->caption() << " as the new top child" << endl;
00179         m_pZ->setAutoDelete( false );
00180         if ( child )
00181             m_pZ->removeRef( child );
00182         m_pZ->setAutoDelete( true );
00183         
00184         //disable the labels of all the other children
00185         TQPtrListIterator<KMdiChildFrm> it( *m_pZ );
00186         for ( ; ( *it ); ++it )
00187             ( *it )->m_pCaption->setActive( false );
00188         
00189         KMdiChildFrm* maximizedChild = topChild();
00190         bool topChildMaximized = false;
00191         if ( maximizedChild && maximizedChild->state() == KMdiChildFrm::Maximized )
00192             topChildMaximized = true;
00193         
00194         m_pZ->append( child );
00195         
00196         int nChildAreaMinW = 0, nChildAreaMinH = 0;
00197         int nChildAreaMaxW = QWIDGETSIZE_MAX, nChildAreaMaxH = QWIDGETSIZE_MAX;
00198         if ( topChildMaximized && child->m_pClient )
00199         {
00200             //the former top child is maximized, so maximize the new one
00201             nChildAreaMinW = child->m_pClient->minimumWidth();
00202             nChildAreaMinH = child->m_pClient->minimumHeight();
00204             // nChildAreaMaxW = child->m_pClient->maximumWidth();
00205             // nChildAreaMaxH = child->m_pClient->maximumHeight();
00206         }
00207         
00208         //set the min and max sizes of this child area to the new top child
00209         setMinimumSize( nChildAreaMinW, nChildAreaMinH );
00210         setMaximumSize( nChildAreaMaxW, nChildAreaMaxH );
00211         
00212         if ( topChildMaximized )
00213         {   //maximize the new view and restore the old
00214             child->setState( KMdiChildFrm::Maximized, false /*animate*/);
00215             maximizedChild->setState( KMdiChildFrm::Normal, false /*animate*/ );
00216             emit sysButtonConnectionsMustChange( maximizedChild, child );
00217         }
00218         else
00219             child->raise();
00220         
00221 #ifdef USE_QT4
00222         child->m_pClient->setFocus();
00223 #else // USE_QT4
00224         TQFocusEvent::setReason( TQFocusEvent::Other );
00225         child->m_pClient->setFocus();
00226 #endif // USE_QT4
00227     }
00228 }
00229 
00230 
00231 void KMdiChildArea::resizeEvent( TQResizeEvent* e )
00232 {
00233     //If we have a maximized children at the top , adjust its size
00234     KMdiChildFrm* child = topChild();
00235     if ( child && child->state() == KMdiChildFrm::Maximized  )
00236     {
00237         int clientw = 0, clienth = 0;
00238         if ( child->m_pClient != 0L )
00239         {
00240             clientw = child->m_pClient->width();
00241             clienth = child->m_pClient->height();
00242         }
00243         child->resize( width() + KMDI_CHILDFRM_DOUBLE_BORDER,
00244                        height() + child->m_pCaption->heightHint() + KMDI_CHILDFRM_SEPARATOR + KMDI_CHILDFRM_DOUBLE_BORDER );
00245 
00246     }
00247     layoutMinimizedChildren();
00248     TQWidget::resizeEvent( e );
00249 }
00250 
00251 //=============== mousePressEvent =============//
00252 
00253 void KMdiChildArea::mousePressEvent( TQMouseEvent *e )
00254 {
00255     //Popup the window menu
00256     if ( e->button() & Qt::RightButton )
00257         emit popupWindowMenu( mapToGlobal( e->pos() ) );
00258 }
00259 
00260 //=============== getCascadePoint ============//
00261 
00262 TQPoint KMdiChildArea::getCascadePoint( int indexOfWindow )
00263 {
00264     if ( indexOfWindow < 0 )
00265     {
00266         indexOfWindow = m_pZ->count(); //use the window count
00267         kdDebug( 760 ) << k_funcinfo << "indexOfWindow was less than zero, using "
00268             << indexOfWindow << " as new index" << endl;
00269     }
00270 
00271     TQPoint pnt( 0, 0 );
00272     if ( indexOfWindow == 0 )
00273     {
00274         kdDebug( 760 ) << k_funcinfo << "No windows. Returning TQPoint( 0, 0 ) as the cascade point" << endl;
00275         return pnt;
00276     }
00277 
00278     bool topLevelMode = false;
00279     if ( height() == 1 )    // hacky?!
00280         topLevelMode = true;
00281 
00282     kdDebug( 760 ) << k_funcinfo << "Getting the cascade point for window index " << indexOfWindow << endl;
00283     kdDebug( 760 ) << k_funcinfo << "Do we think we're in top level mode? " << topLevelMode << endl;
00284     
00285     KMdiChildFrm* child = m_pZ->first();
00286     
00287     //default values
00288     int step = 20;
00289     int h = ( topLevelMode ? TQApplication::desktop()->height() : height() );
00290     int w = ( topLevelMode ? TQApplication::desktop()->width() : width() );
00291     
00292     int availableHeight = h - m_defaultChildFrmSize.height();
00293     int availableWidth = w - m_defaultChildFrmSize.width();
00294     int ax = 0;
00295     int ay = 0;
00296     
00297     if ( child )
00298     {
00299         kdDebug( 760 ) << k_funcinfo << "child frame exists. resetting height and width values" << endl;
00300         step = child->m_pCaption->heightHint() + KMDI_CHILDFRM_BORDER;
00301         availableHeight = h - child->minimumHeight();
00302         availableWidth = w - child->minimumWidth();
00303     }
00304     
00305     for ( int i = 0; i < indexOfWindow; i++ )
00306     {
00307         ax += step;
00308         ay += step;
00309         
00310         //do some bounds checking, because to not do it would be bad.
00311         if ( ax > availableWidth )
00312             ax = 0;
00313 
00314         if ( ay > availableHeight )
00315             ay = 0;
00316     }
00317     pnt.setX( ax );
00318     pnt.setY( ay );
00319     return pnt;
00320 }
00321 
00322 
00323 void KMdiChildArea::childMinimized( KMdiChildFrm *minimizedChild, bool wasMaximized )
00324 {
00325     //can't find the child in our list, so we don't care.
00326     if ( m_pZ->findRef( minimizedChild ) == -1 )
00327     {
00328         kdDebug( 760 ) << k_funcinfo << "child was minimized but wasn't in our list!" << endl;
00329         return;
00330     }
00331     
00332     kdDebug( 760 ) << k_funcinfo << endl;
00333     if ( m_pZ->count() > 1 )
00334     {
00335         //move the minimized child to the bottom
00336         m_pZ->setAutoDelete( false );
00337         m_pZ->removeRef( minimizedChild );
00338         m_pZ->setAutoDelete( true );
00339         m_pZ->insert( 0, minimizedChild );
00340         
00341         if ( wasMaximized )
00342         { // Need to maximize the new top child
00343             kdDebug( 760 ) << k_funcinfo << "child just minimized from maximized state. maximize new top child" << endl;
00344             minimizedChild = topChild();
00345             if ( !minimizedChild )
00346                 return; //??
00347             
00348             if ( minimizedChild->state() == KMdiChildFrm::Maximized )
00349                 return; //it's already maximized
00350             
00351             minimizedChild->setState( KMdiChildFrm::Maximized, false ); //do not animate the change
00352         }
00353         focusTopChild();
00354     }
00355     else
00356         setFocus(); //Remove focus from the child. We only have one window
00357 }
00358 
00359 void KMdiChildArea::focusTopChild()
00360 {
00361     KMdiChildFrm* lastChild = topChild();
00362     if ( !lastChild )
00363     {
00364         kdDebug( 760 ) << k_funcinfo << "No more child windows left" << endl;
00365         emit lastChildFrmClosed();
00366         return;
00367     }
00368 
00369     if ( !lastChild->m_pClient->hasFocus() )
00370     {
00371         //disable the labels of all the other children
00372         TQPtrListIterator<KMdiChildFrm> it ( *m_pZ );
00373         for ( ; ( *it ); ++it )
00374         {
00375             if ( ( *it ) != lastChild )
00376                 ( *it )->m_pCaption->setActive( false );
00377         }
00378 
00379         kdDebug( 760 ) << k_funcinfo << "Giving focus to " << lastChild->caption() << endl;
00380         lastChild->raise();
00381         lastChild->m_pClient->activate();
00382     }
00383 
00384 }
00385 
00386 void KMdiChildArea::cascadeWindows()
00387 {
00388     kdDebug( 760 ) << k_funcinfo << "cascading windows but not changing their size" << endl;
00389     int idx = 0;
00390     TQPtrList<KMdiChildFrm> list( *m_pZ );
00391     list.setAutoDelete( false );
00392     while ( !list.isEmpty() )
00393     {
00394         KMdiChildFrm* childFrm = list.first();
00395         if ( childFrm->state() != KMdiChildFrm::Minimized )
00396         {
00397             if ( childFrm->state() == KMdiChildFrm::Maximized )
00398                 childFrm->restorePressed();
00399             
00400             childFrm->move( getCascadePoint( idx ) );
00401             idx++;
00402         }
00403         list.removeFirst();
00404     }
00405     focusTopChild();
00406 }
00407 
00408 void KMdiChildArea::cascadeMaximized()
00409 {
00410     kdDebug( 760 ) << k_funcinfo << "cascading windows. will make sure they are minimum sized" << endl;
00411     int idx = 0;
00412     TQPtrList<KMdiChildFrm> list( *m_pZ );
00413 
00414     list.setAutoDelete( false );
00415     while ( !list.isEmpty() )
00416     {
00417         KMdiChildFrm* childFrm = list.first();
00418         if (childFrm->state() != KMdiChildFrm::Minimized )
00419         {
00420             if (childFrm->state() == KMdiChildFrm::Maximized )
00421                 childFrm->restorePressed();
00422             
00423             TQPoint pnt( getCascadePoint( idx ) );
00424             childFrm->move( pnt );
00425             TQSize curSize( width() - pnt.x(), height() - pnt.y() );
00426             
00427             if ( ( childFrm->minimumSize().width() > curSize.width() ) ||
00428                  ( childFrm->minimumSize().height() > curSize.height() ) )
00429             {
00430                 childFrm->resize( childFrm->minimumSize() );
00431             }
00432             else
00433                 childFrm->resize( curSize );
00434             
00435             idx++;
00436         }
00437         list.removeFirst();
00438     }
00439     focusTopChild();
00440 }
00441 
00442 void KMdiChildArea::expandVertical()
00443 {
00444     kdDebug( 760 ) << k_funcinfo << "expanding all child frames vertically" << endl;
00445     int idx = 0;
00446     TQPtrList<KMdiChildFrm> list( *m_pZ );
00447     list.setAutoDelete( false );
00448     while ( !list.isEmpty() )
00449     {
00450         KMdiChildFrm* childFrm = list.first();
00451         if ( childFrm->state() != KMdiChildFrm::Minimized )
00452         {
00453             if ( childFrm->state() == KMdiChildFrm::Maximized )
00454                 childFrm->restorePressed();
00455             
00456             childFrm->setGeometry( childFrm->x(), 0, childFrm->width(), height() );
00457             idx++;
00458         }
00459         list.removeFirst();
00460     }
00461     focusTopChild();
00462 }
00463 
00464 void KMdiChildArea::expandHorizontal()
00465 {
00466     kdDebug( 760 ) << k_funcinfo << "expanding all child frames horizontally" << endl;
00467     int idx = 0;
00468     TQPtrList<KMdiChildFrm> list( *m_pZ );
00469     list.setAutoDelete( false );
00470     while ( !list.isEmpty() )
00471     {
00472         KMdiChildFrm* childFrm = list.first();
00473         if ( childFrm->state() != KMdiChildFrm::Minimized )
00474         {
00475             if ( childFrm->state() == KMdiChildFrm::Maximized )
00476                 childFrm->restorePressed();
00477             
00478             childFrm->setGeometry( 0, childFrm->y(), width(), childFrm->height() );
00479             idx++;
00480         }
00481         list.removeFirst();
00482     }
00483     focusTopChild();
00484 }
00485 
00486 int KMdiChildArea::getVisibleChildCount() const
00487 {
00488     int visibleChildCount = 0;
00489     TQPtrListIterator<KMdiChildFrm> it( *m_pZ );
00490     for ( ; ( *it ); ++it )
00491     {
00492         if ( ( *it )->state() != KMdiChildFrm::Minimized && ( *it )->isVisible() )
00493             visibleChildCount++;
00494     }
00495     return visibleChildCount;
00496 }
00497 
00498 void KMdiChildArea::tilePragma()
00499 {
00500     kdDebug( 760 ) << k_funcinfo << endl;
00501     tileAllInternal( 9 );
00502 }
00503 
00504 void KMdiChildArea::tileAllInternal( int maxWnds )
00505 {
00506     kdDebug( 760 ) << k_funcinfo << endl;
00507     //NUM WINDOWS =           1,2,3,4,5,6,7,8,9
00508     static int colstable[ 9 ] = { 1, 1, 1, 2, 2, 2, 3, 3, 3 }; //num columns
00509     static int rowstable[ 9 ] = { 1, 2, 3, 2, 3, 3, 3, 3, 3 }; //num rows
00510     static int lastwindw[ 9 ] = { 1, 1, 1, 1, 2, 1, 3, 2, 1 }; //last window multiplier
00511     static int colrecall[ 9 ] = { 0, 0, 0, 3, 3, 3, 6, 6, 6 }; //adjust self
00512     static int rowrecall[ 9 ] = { 0, 0, 0, 0, 4, 4, 4, 4, 4 }; //adjust self
00513 
00514     int numVisible = getVisibleChildCount();
00515     if ( numVisible < 1 )
00516     {
00517         kdDebug( 760 ) << k_funcinfo << "No visible child windows to tile" << endl;
00518         return;
00519     }
00520 
00521     KMdiChildFrm *tcw = topChild();
00522     int numToHandle = ( ( numVisible > maxWnds ) ? maxWnds : numVisible );
00523     
00524     int xQuantum = width() / colstable[ numToHandle - 1 ];
00525     int widthToCompare;
00526     
00527     if ( tcw->minimumWidth() > m_defaultChildFrmSize.width() )
00528         widthToCompare = tcw->minimumWidth();
00529     else
00530         widthToCompare = m_defaultChildFrmSize.width();
00531     
00532     if ( xQuantum < widthToCompare )
00533     {
00534         if ( colrecall[ numToHandle - 1 ] != 0 )
00535         {
00536             tileAllInternal( colrecall[ numToHandle - 1 ] );
00537             return ;
00538         }
00539     }
00540     
00541     int yQuantum = height() / rowstable[ numToHandle - 1 ];
00542     int heightToCompare;
00543     if ( tcw->minimumHeight() > m_defaultChildFrmSize.height() )
00544         heightToCompare = tcw->minimumHeight();
00545     else
00546         heightToCompare = m_defaultChildFrmSize.height();
00547         
00548     if ( yQuantum < heightToCompare )
00549     {
00550         if ( rowrecall[ numToHandle - 1 ] != 0 )
00551         {
00552             tileAllInternal( rowrecall[ numToHandle - 1 ] );
00553             return ;
00554         }
00555     }
00556     int curX = 0;
00557     int curY = 0;
00558     int curRow = 1;
00559     int curCol = 1;
00560     int curWin = 1;
00561     
00562     TQPtrListIterator<KMdiChildFrm> it( *m_pZ );
00563     for ( ; ( *it ); ++it )
00564     {
00565         KMdiChildFrm* child = ( *it );
00566         if ( child->state() != KMdiChildFrm::Minimized )
00567         {
00568             //restore the window
00569             if ( child->state() == KMdiChildFrm::Maximized )
00570                 child->restorePressed();
00571             
00572             if ( ( curWin % numToHandle ) == 0 )
00573                 child->setGeometry( curX, curY, xQuantum * lastwindw[ numToHandle - 1 ], yQuantum );
00574             else
00575                 child->setGeometry( curX, curY, xQuantum, yQuantum );
00576             
00577             //example : 12 windows : 3 cols 3 rows
00578             if ( curCol < colstable[ numToHandle - 1 ] )
00579             { //curCol<3
00580                 curX += xQuantum; //add a column in the same row
00581                 curCol++;         //increase current column
00582             }
00583             else
00584             {
00585                 curX = 0;         //new row
00586                 curCol = 1;       //column 1
00587                 if ( curRow < rowstable[ numToHandle - 1 ] )
00588                 { //curRow<3
00589                     curY += yQuantum; //add a row
00590                     curRow++;         //increase current row
00591                 }
00592                 else
00593                 {
00594                     curY = 0;         //restart from beginning
00595                     curRow = 1;       //reset current row
00596                 }
00597             }
00598             curWin++;
00599         }
00600     }
00601     
00602     if ( tcw )
00603         tcw->m_pClient->activate();
00604 }
00605 
00606 void KMdiChildArea::tileAnodine()
00607 {
00608     KMdiChildFrm * topChildWindow = topChild();
00609     int numVisible = getVisibleChildCount(); // count visible windows
00610     if ( numVisible < 1 )
00611         return ;
00612     
00613     int numCols = int( sqrt( ( double ) numVisible ) ); // set columns to square root of visible count
00614     // create an array to form grid layout
00615     int *numRows = new int[ numCols ];
00616     int numCurCol = 0;
00617     
00618     while ( numCurCol < numCols )
00619     {
00620         numRows[numCurCol] = numCols; // create primary grid values
00621         numCurCol++;
00622     }
00623     
00624     int numDiff = numVisible - ( numCols * numCols ); // count extra rows
00625     int numCurDiffCol = numCols; // set column limiting for grid updates
00626     
00627     while ( numDiff > 0 )
00628     {
00629         numCurDiffCol--;
00630         numRows[numCurDiffCol]++; // add extra rows to column grid
00631         
00632         if ( numCurDiffCol < 1 )
00633             numCurDiffCol = numCols; // rotate through the grid
00634         
00635         numDiff--;
00636     }
00637     
00638     numCurCol = 0;
00639     int numCurRow = 0;
00640     int curX = 0;
00641     int curY = 0;
00642     
00643     // the following code will size everything based on my grid above
00644     // there is no limit to the number of windows it will handle
00645     // it's great when a kick-ass theory works!!!                      // Pragma :)
00646     int xQuantum = width() / numCols;
00647     int yQuantum = height() / numRows[numCurCol];
00648     TQPtrListIterator<KMdiChildFrm> it( *m_pZ );
00649     for ( ; ( *it ); ++it )
00650     {
00651         KMdiChildFrm* child = ( *it );
00652         if ( child->state() != KMdiChildFrm::Minimized )
00653         {
00654             if ( child->state() == KMdiChildFrm::Maximized )
00655                 child->restorePressed();
00656             
00657             child->setGeometry( curX, curY, xQuantum, yQuantum );
00658             numCurRow++;
00659             curY += yQuantum;
00660             
00661             if ( numCurRow == numRows[numCurCol] )
00662             {
00663                 numCurRow = 0;
00664                 numCurCol++;
00665                 curY = 0;
00666                 curX += xQuantum;
00667                 if ( numCurCol != numCols )
00668                     yQuantum = height() / numRows[ numCurCol ];
00669             }
00670         }
00671     }
00672     
00673     delete[] numRows;
00674     
00675     if ( topChildWindow )
00676         topChildWindow->m_pClient->activate();
00677 }
00678 
00679 
00680 void KMdiChildArea::tileVertically()
00681 {
00682     KMdiChildFrm * topChildWindow = topChild();
00683     int numVisible = getVisibleChildCount(); // count visible windows
00684     if ( numVisible < 1 )
00685         return ;
00686 
00687     int w = width() / numVisible;
00688     int lastWidth = 0;
00689     
00690     if ( numVisible > 1 )
00691         lastWidth = width() - ( w * ( numVisible - 1 ) );
00692     else
00693         lastWidth = w;
00694     
00695     int h = height();
00696     int posX = 0;
00697     int countVisible = 0;
00698 
00699     TQPtrListIterator<KMdiChildFrm> it( *m_pZ );
00700     for ( ; ( *it ); ++it )
00701     {
00702         KMdiChildFrm* child = ( *it );
00703         if ( child->state() != KMdiChildFrm::Minimized )
00704         {
00705             if ( child->state() == KMdiChildFrm::Maximized )
00706                 child->restorePressed();
00707             
00708             countVisible++;
00709             
00710             if ( countVisible < numVisible )
00711             {
00712                 child->setGeometry( posX, 0, w, h );
00713                 posX += w;
00714             }
00715             else
00716             { // last visible childframe
00717                 child->setGeometry( posX, 0, lastWidth, h );
00718             }
00719         }
00720     }
00721     
00722     if ( topChildWindow )
00723         topChildWindow->m_pClient->activate();
00724 }
00725 
00726 
00727 void KMdiChildArea::layoutMinimizedChildren()
00728 {
00729     int posX = 0;
00730     int posY = height();
00731     TQPtrListIterator<KMdiChildFrm> it( *m_pZ );
00732     for ( ; ( *it ); ++it )
00733     {
00734         KMdiChildFrm* child = *( it );
00735         if ( child->state() == KMdiChildFrm::Minimized )
00736         {
00737             
00738             if ( ( posX > 0 ) && ( posX + child->width() > width() ) )
00739             {
00740                 posX = 0;
00741                 posY -= child->height();
00742             }
00743             
00744             child->move( posX, posY - child->height() );
00745             posX = child->geometry().right();
00746         }
00747     }
00748 }
00749 
00750 
00751 void KMdiChildArea::setMdiCaptionFont( const TQFont& fnt )
00752 {
00753     m_captionFont = fnt;
00754     TQFontMetrics fm( m_captionFont );
00755     m_captionFontLineSpacing = fm.lineSpacing();
00756 
00757     TQPtrListIterator<KMdiChildFrm> it( *m_pZ );
00758     for ( ; ( *it ); ++it )
00759         ( *it )->doResize();
00760 
00761 }
00762 
00763 void KMdiChildArea::setMdiCaptionActiveForeColor( const TQColor& clr )
00764 {
00765     m_captionActiveForeColor = clr;
00766 }
00767 
00768 void KMdiChildArea::setMdiCaptionActiveBackColor( const TQColor& clr )
00769 {
00770     m_captionActiveBackColor = clr;
00771 }
00772 
00773 void KMdiChildArea::setMdiCaptionInactiveForeColor( const TQColor& clr )
00774 {
00775     m_captionInactiveForeColor = clr;
00776 }
00777 
00778 void KMdiChildArea::setMdiCaptionInactiveBackColor( const TQColor& clr )
00779 {
00780     m_captionInactiveBackColor = clr;
00781 }
00782 
00783 //KDE4: remove
00784 void KMdiChildArea::getCaptionColors( const TQPalette& /*pal*/, TQColor& activeBG,
00785                                       TQColor& activeFG, TQColor& inactiveBG, TQColor& inactiveFG )
00786 {
00787     activeBG = KGlobalSettings::activeTitleColor();
00788     activeFG = KGlobalSettings::activeTextColor();
00789     inactiveBG = KGlobalSettings::inactiveTitleColor();
00790     inactiveFG = KGlobalSettings::inactiveTextColor();
00791 }
00792 
00793 // kate: space-indent off; replace-tabs off; tab-width 4; indent-mode csands;

kmdi

Skip menu "kmdi"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kmdi

Skip menu "kmdi"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kmdi by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |