| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kdockwidget.cpp

    00001 /* This file is part of the KDE libraries
    00002    Copyright (C) 2000 Max Judin <novaprint@mtu-net.ru>
    00003
    00004    This library is free software; you can redistribute it and/or
    00005    modify it under the terms of the GNU Library General Public
    00006    License version 2 as published by the Free Software Foundation.
    00007
    00008    This library is distributed in the hope that it will be useful,
    00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00011    Library General Public License for more details.
    00012
    00013    You should have received a copy of the GNU Library General Public License
    00014    along with this library; see the file COPYING.LIB.  If not, write to
    00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00016    Boston, MA 02111-1307, USA.
    00017 */
    00018 #include "kdockwidget.h"
    00019 #include "kdockwidget_private.h"
    00020 #include "kdockwidget_p.h"
    00021
    00022 #include <qapplication.h>
    00023 #include <qlayout.h>
    00024 #include <qpainter.h>
    00025 #include <qobjectlist.h>
    00026 #include <qstrlist.h>
    00027 #include <qcursor.h>
    00028 #include <qwidgetlist.h>
    00029 #include <qtabwidget.h>
    00030 #include <qstyle.h>
    00031
    00032 #ifndef NO_KDE2
    00033 #include <kconfig.h>
    00034 #include <kglobal.h>
    00035 #include <klocale.h>
    00036 #include <ktoolbar.h>
    00037 #include <kpopupmenu.h>
    00038 #include <kwin.h>
    00039 #include <kdebug.h>
    00040 #ifdef Q_WS_X11
    00041 #include <X11/X.h>
    00042 #include <X11/Xlib.h>
    00043 #endif
    00044 #else
    00045 #include <qapplication.h>
    00046 #include <qtoolbar.h>
    00047 #include <qpopupmenu.h>
    00048 #endif
    00049
    00050 #include <stdlib.h>
    00051
    00052 #undef BORDERLESS_WINDOWS
    00053
    00054 #define DOCK_CONFIG_VERSION "0.0.5"
    00055
    00056 static const char* const dockback_xpm[]={
    00057 "6 6 2 1",
    00058 "# c black",
    00059 ". c None",
    00060 "......",
    00061 ".#....",
    00062 "..#..#",
    00063 "...#.#",
    00064 "....##",
    00065 "..####"};
    00066
    00067 static const char* const todesktop_xpm[]={
    00068 "5 5 2 1",
    00069 "# c black",
    00070 ". c None",
    00071 "####.",
    00072 "##...",
    00073 "#.#..",
    00074 "#..#.",
    00075 "....#"};
    00076
    00077 static const char* const not_close_xpm[]={
    00078 "5 5 2 1",
    00079 "# c black",
    00080 ". c None",
    00081 "#####",
    00082 "#...#",
    00083 "#...#",
    00084 "#...#",
    00085 "#####"};
    00086
    00096 KDockMainWindow::KDockMainWindow( QWidget* parent, const char *name, WFlags f)
    00097 :KMainWindow( parent, name, f )
    00098 {
    00099   QString new_name = QString(name) + QString("_DockManager");
    00100   dockManager = new KDockManager( this, new_name.latin1() );
    00101   mainDockWidget = 0L;
    00102 }
    00103
    00104 KDockMainWindow::~KDockMainWindow()
    00105 {
    00106         delete dockManager;
    00107 }
    00108
    00109 void KDockMainWindow::setMainDockWidget( KDockWidget* mdw )
    00110 {
    00111   if ( mainDockWidget == mdw ) return;
    00112   mainDockWidget = mdw;
    00113   dockManager->setMainDockWidget2(mdw);
    00114 }
    00115
    00116 void KDockMainWindow::setView( QWidget *view )
    00117 {
    00118   if ( view->isA("KDockWidget") ){
    00119     if ( view->parent() != this ) ((KDockWidget*)view)->applyToWidget( this );
    00120   }
    00121
    00122 #ifndef NO_KDE2
    00123   KMainWindow::setCentralWidget(view);
    00124 #else
    00125   QMainWindow::setCentralWidget(view);
    00126 #endif
    00127 }
    00128
    00129 KDockWidget* KDockMainWindow::createDockWidget( const QString& name, const QPixmap &pixmap, QWidget* parent, const QString& strCaption, const QString& strTabPageLabel)
    00130 {
    00131   return new KDockWidget( dockManager, name.latin1(), pixmap, parent, strCaption, strTabPageLabel );
    00132 }
    00133
    00134 void KDockMainWindow::makeDockVisible( KDockWidget* dock )
    00135 {
    00136   if ( dock != 0L)
    00137     dock->makeDockVisible();
    00138 }
    00139
    00140 void KDockMainWindow::makeDockInvisible( KDockWidget* dock )
    00141 {
    00142   if ( dock != 0L)
    00143     dock->undock();
    00144 }
    00145
    00146 void KDockMainWindow::makeWidgetDockVisible( QWidget* widget )
    00147 {
    00148   makeDockVisible( dockManager->findWidgetParentDock(widget) );
    00149 }
    00150
    00151 void KDockMainWindow::writeDockConfig(QDomElement &base)
    00152 {
    00153   dockManager->writeConfig(base);
    00154 }
    00155
    00156 void KDockMainWindow::readDockConfig(QDomElement &base)
    00157 {
    00158   dockManager->readConfig(base);
    00159 }
    00160
    00161 #ifndef NO_KDE2
    00162 void KDockMainWindow::writeDockConfig( KConfig* c, QString group )
    00163 {
    00164   dockManager->writeConfig( c, group );
    00165 }
    00166
    00167 void KDockMainWindow::readDockConfig( KConfig* c, QString group )
    00168 {
    00169   dockManager->readConfig( c, group );
    00170 }
    00171 #endif
    00172
    00173 void KDockMainWindow::slotDockWidgetUndocked()
    00174 {
    00175   QObject* pSender = (QObject*) sender();
    00176   if (!pSender->inherits("KDockWidget")) return;
    00177   KDockWidget* pDW = (KDockWidget*) pSender;
    00178   emit dockWidgetHasUndocked( pDW);
    00179 }
    00180
    00181 /*************************************************************************/
    00182 KDockWidgetAbstractHeaderDrag::KDockWidgetAbstractHeaderDrag( KDockWidgetAbstractHeader* parent, KDockWidget* dock, const char* name )
    00183 :QFrame( parent, name )
    00184 {
    00185   dw = dock;
    00186   installEventFilter( dock->dockManager() );
    00187 }
    00188 /*************************************************************************/
    00189 KDockWidgetHeaderDrag::KDockWidgetHeaderDrag( KDockWidgetAbstractHeader* parent, KDockWidget* dock, const char* name )
    00190 :KDockWidgetAbstractHeaderDrag( parent, dock, name )
    00191 {
    00192 }
    00193
    00194 void KDockWidgetHeaderDrag::paintEvent( QPaintEvent* )
    00195 {
    00196   QPainter paint;
    00197
    00198   paint.begin( this );
    00199
    00200   style().drawPrimitive (QStyle::PE_DockWindowHandle, &paint, QRect(0,0,width(), height()), colorGroup());
    00201
    00202   paint.end();
    00203 }
    00204 /*************************************************************************/
    00205 KDockWidgetAbstractHeader::KDockWidgetAbstractHeader( KDockWidget* parent, const char* name )
    00206 :QFrame( parent, name )
    00207 {
    00208 }
    00209 /*************************************************************************/
    00210 KDockWidgetHeader::KDockWidgetHeader( KDockWidget* parent, const char* name )
    00211 :KDockWidgetAbstractHeader( parent, name )
    00212 {
    00213 #ifdef BORDERLESS_WINDOWS
    00214   setCursor(QCursor(ArrowCursor));
    00215 #endif
    00216   d = new KDockWidgetHeaderPrivate( this );
    00217
    00218   layout = new QHBoxLayout( this );
    00219   layout->setResizeMode( QLayout::Minimum );
    00220
    00221   drag = new KDockWidgetHeaderDrag( this, parent );
    00222
    00223   closeButton = new KDockButton_Private( this, "DockCloseButton" );
    00224   closeButton->setPixmap( style().stylePixmap (QStyle::SP_TitleBarCloseButton , this));
    00225   closeButton->setFixedSize(closeButton->pixmap()->width(),closeButton->pixmap()->height());
    00226   connect( closeButton, SIGNAL(clicked()), parent, SIGNAL(headerCloseButtonClicked()));
    00227   connect( closeButton, SIGNAL(clicked()), parent, SLOT(undock()));
    00228
    00229   stayButton = new KDockButton_Private( this, "DockStayButton" );
    00230   stayButton->setToggleButton( true );
    00231   stayButton->setPixmap( const_cast< const char** >(not_close_xpm) );
    00232   stayButton->setFixedSize(closeButton->pixmap()->width(),closeButton->pixmap()->height());
    00233   connect( stayButton, SIGNAL(clicked()), this, SLOT(slotStayClicked()));
    00234
    00235   dockbackButton = new KDockButton_Private( this, "DockbackButton" );
    00236   dockbackButton->setPixmap( const_cast< const char** >(dockback_xpm));
    00237   dockbackButton->setFixedSize(closeButton->pixmap()->width(),closeButton->pixmap()->height());
    00238   connect( dockbackButton, SIGNAL(clicked()), parent, SIGNAL(headerDockbackButtonClicked()));
    00239   connect( dockbackButton, SIGNAL(clicked()), parent, SLOT(dockBack()));
    00240
    00241   d->toDesktopButton = new KDockButton_Private( this, "ToDesktopButton" );
    00242   d->toDesktopButton->setPixmap( const_cast< const char** >(todesktop_xpm));
    00243   d->toDesktopButton->setFixedSize(closeButton->pixmap()->width(),closeButton->pixmap()->height());
    00244   connect( d->toDesktopButton, SIGNAL(clicked()), parent, SLOT(toDesktop()));
    00245
    00246   stayButton->hide();
    00247
    00248   layout->addWidget( drag );
    00249   layout->addWidget( dockbackButton );
    00250   layout->addWidget( d->toDesktopButton );
    00251   layout->addWidget( stayButton );
    00252   layout->addWidget( closeButton );
    00253   layout->activate();
    00254   drag->setFixedHeight( layout->minimumSize().height() );
    00255 }
    00256
    00257 void KDockWidgetHeader::setTopLevel( bool isTopLevel )
    00258 {
    00259   d->topLevel = isTopLevel;
    00260   if ( isTopLevel ){
    00261     KDockWidget* par = (KDockWidget*)parent();
    00262     if( par) {
    00263       if( par->isDockBackPossible())
    00264         dockbackButton->show();
    00265       else
    00266         dockbackButton->hide();
    00267     }
    00268     stayButton->hide();
    00269     closeButton->hide();
    00270     d->toDesktopButton->hide();
    00271     drag->setEnabled( true );
    00272   } else {
    00273     dockbackButton->hide();
    00274     stayButton->hide();
    00275     closeButton->show();
    00276     if( d->showToDesktopButton )
    00277       d->toDesktopButton->show();
    00278   }
    00279   layout->activate();
    00280   updateGeometry();
    00281 }
    00282
    00283 void KDockWidgetHeader::setDragPanel( KDockWidgetHeaderDrag* nd )
    00284 {
    00285   if ( !nd ) return;
    00286
    00287   delete layout;
    00288   layout = new QHBoxLayout( this );
    00289   layout->setResizeMode( QLayout::Minimum );
    00290
    00291   delete drag;
    00292   drag = nd;
    00293
    00294   layout->addWidget( drag );
    00295   layout->addWidget( dockbackButton );
    00296   layout->addWidget( d->toDesktopButton );
    00297   layout->addWidget( stayButton );
    00298   layout->addWidget( closeButton );
    00299   layout->activate();
    00300   drag->setFixedHeight( layout->minimumSize().height() );
    00301 }
    00302
    00303 void KDockWidgetHeader::slotStayClicked()
    00304 {
    00305   setDragEnabled(!stayButton->isOn());
    00306 }
    00307
    00308 bool KDockWidgetHeader::dragEnabled() const
    00309 {
    00310   return drag->isEnabled();
    00311 }
    00312
    00313 void KDockWidgetHeader::showUndockButton(bool show)
    00314 {
    00315   if( d->showToDesktopButton == show )
    00316     return;
    00317
    00318   d->showToDesktopButton = show;
    00319   if( !show || d->topLevel )
    00320     d->toDesktopButton->hide( );
    00321   else
    00322     d->toDesktopButton->show( );
    00323 }
    00324
    00325 void KDockWidgetHeader::setDragEnabled(bool b)
    00326 {
    00327   stayButton->setOn(!b);
    00328   closeButton->setEnabled(b);
    00329   drag->setEnabled(b);
    00330 }
    00331
    00332 #ifndef NO_KDE2
    00333 void KDockWidgetHeader::saveConfig( KConfig* c )
    00334 {
    00335   c->writeEntry( QString("%1%2").arg(parent()->name()).arg(":stayButton"), stayButton->isOn() );
    00336 }
    00337
    00338 void KDockWidgetHeader::loadConfig( KConfig* c )
    00339 {
    00340   setDragEnabled( !c->readBoolEntry( QString("%1%2").arg(parent()->name()).arg(":stayButton"), false ) );
    00341 }
    00342 #endif
    00343
    00344 /*************************************************************************/
    00345
    00346 class KDockManager::KDockManagerPrivate
    00347 {
    00348 public:
    00352   QRect dragRect;
    00353
    00357   QRect oldDragRect;
    00358
    00362   bool readyToDrag;
    00363
    00367   QPoint dragOffset;
    00368
    00372   bool splitterOpaqueResize;
    00373   bool splitterKeepSize;
    00374   bool splitterHighResolution;
    00375
    00376   QGuardedPtr<KDockWidget> mainDockWidget;
    00377
    00378   QObjectList containerDocks;
    00379 };
    00380
    00381
    00382 /*************************************************************************/
    00383 KDockWidget::KDockWidget( KDockManager* dockManager, const char* name, const QPixmap &pixmap, QWidget* parent, const QString& strCaption, const QString& strTabPageLabel, WFlags f)
    00384 #ifdef BORDERLESS_WINDOWS
    00385 : QWidget( parent, name, f )//| WType_Dialog | WStyle_Customize | WStyle_NoBorder )
    00386 #else
    00387 : QWidget( parent, name, f )
    00388 #endif
    00389   ,formerBrotherDockWidget(0L)
    00390   ,currentDockPos(DockNone)
    00391   ,formerDockPos(DockNone)
    00392   ,widget(0L)
    00393   ,pix(new QPixmap(pixmap))
    00394   ,prevSideDockPosBeforeDrag(DockNone)
    00395 {
    00396   d = new KDockWidgetPrivate();  // create private data
    00397
    00398   d->_parent = parent;
    00399
    00400   layout = new QVBoxLayout( this );
    00401   layout->setResizeMode( QLayout::Minimum );
    00402
    00403   manager = dockManager;
    00404   manager->childDock->append( this );
    00405   installEventFilter( manager );
    00406
    00407   header = 0L;
    00408   setHeader( new KDockWidgetHeader( this, "AutoCreatedDockHeader" ) );
    00409
    00410   if( strCaption.isNull() )
    00411     setCaption( name );
    00412   else
    00413     setCaption( strCaption);
    00414
    00415   if( strTabPageLabel == " ")
    00416     setTabPageLabel( caption());
    00417   else
    00418     setTabPageLabel( strTabPageLabel);
    00419
    00420   eDocking = DockFullDocking;
    00421   sDocking = DockFullSite;
    00422
    00423   isGroup = false;
    00424   isTabGroup = false;
    00425   d->isContainer =false;
    00426   setIcon( pixmap);
    00427   widget = 0L;
    00428
    00429   QObject::connect(this, SIGNAL(hasUndocked()), manager->main, SLOT(slotDockWidgetUndocked()) );
    00430   applyToWidget( parent, QPoint(0,0) );
    00431 }
    00432
    00433 KDockWidget::~KDockWidget()
    00434 {
    00435   d->pendingDtor = true;
    00436   if ( !manager->undockProcess ){
    00437     d->blockHasUndockedSignal = true;
    00438     undock();
    00439     d->blockHasUndockedSignal = false;
    00440   }
    00441
    00442   if (latestKDockContainer()) static_cast<KDockContainer*>(latestKDockContainer()->qt_cast("KDockContainer"))->removeWidget(this);
    00443   emit iMBeingClosed();
    00444   if (manager->d) manager->d->containerDocks.remove(this);
    00445   manager->childDock->remove( this );
    00446   delete pix;
    00447   delete d; // destroy private data
    00448   d=0;
    00449 }
    00450
    00451 void KDockWidget::paintEvent(QPaintEvent* pe)
    00452 {
    00453         QWidget::paintEvent(pe);
    00454         QPainter paint;
    00455         paint.begin( this );
    00456         style().drawPrimitive (QStyle::PE_Panel, &paint, QRect(0,0,width(), height()), colorGroup());
    00457         paint.end();
    00458 }
    00459
    00460 void KDockWidget::leaveEvent(QEvent *e)
    00461 {
    00462         QWidget::leaveEvent(e);
    00463 #ifdef BORDERLESS_WINDOWS
    00464         if (parent()) return;
    00465 //      setCursor(QCursor(ArrowCursor));
    00466 #endif
    00467 }
    00468
    00469 void KDockWidget::mousePressEvent(QMouseEvent* mme)
    00470 {
    00471 #ifdef BORDERLESS_WINDOWS
    00472         if (!parent())
    00473         {
    00474                 kdDebug()<<"KDockWidget::mousePressEvent"<<endl;
    00475
    00476                 bool bbottom;
    00477                 bool bleft;
    00478                 bool bright;
    00479                 bool btop;
    00480                 int styleheight;
    00481                 QPoint mp;
    00482                 mp=mme->pos();
    00483                 styleheight=2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,this);
    00484                 bbottom=mp.y()>=height()-styleheight;
    00485                 btop=mp.y()<=styleheight;
    00486                 bleft=mp.x()<=styleheight;
    00487                 bright=mp.x()>=width()-styleheight;
    00488                 kdDebug()<<"mousemovevent"<<endl;
    00489                 d->resizing=true;
    00490                 if (bright)
    00491                 {
    00492                         if (btop)
    00493                         {
    00494                                 d->resizeMode=KDockWidgetPrivate::ResizeTopRight;
    00495                                 d->resizePos=QPoint(width(),0)-mme->pos();
    00496
    00497                         }
    00498                         else
    00499                         {
    00500                                 d->resizePos=QPoint(width(),height())-mme->pos();
    00501                                 if (bbottom) d->resizeMode=KDockWidgetPrivate::ResizeBottomRight;
    00502                                 else d->resizeMode=KDockWidgetPrivate::ResizeRight;
    00503                         }
    00504                 }
    00505                 else if (bleft)
    00506                 {
    00507                         if (btop) setCursor(QCursor(SizeFDiagCursor));
    00508                         else
    00509                         if (bbottom) setCursor(QCursor(SizeBDiagCursor));
    00510                         else setCursor(QCursor(SizeHorCursor));
    00511                 }
    00512                 else
    00513                 if (bbottom)
    00514                 {
    00515                         d->resizeMode=KDockWidgetPrivate::ResizeBottom;
    00516                         d->resizePos=QPoint(0,height())-mme->pos();
    00517                 }
    00518                 else
    00519                 if  (btop) setCursor(QCursor(SizeVerCursor));
    00520                 else d->resizing=false;
    00521
    00522                 if (d->resizing) grabMouse(cursor());
    00523
    00524         }
    00525 #endif
    00526         QWidget::mousePressEvent(mme);
    00527 }
    00528
    00529 void KDockWidget::mouseReleaseEvent(QMouseEvent* ev)
    00530 {
    00531 #ifdef BORDERLESS_WINDOWS
    00532         d->resizing=false;
    00533         releaseMouse();
    00534 #endif
    00535         QWidget::mouseReleaseEvent(ev);
    00536 }
    00537
    00538 void  KDockWidget::mouseMoveEvent(QMouseEvent* mme)
    00539 {
    00540         QWidget::mouseMoveEvent(mme);
    00541 #ifdef BORDERLESS_WINDOWS
    00542         if (parent()) return;
    00543
    00544         if (d->resizing)
    00545         {
    00546                 switch (d->resizeMode)
    00547                 {
    00548                         case KDockWidgetPrivate::ResizeRight:
    00549                                 resize(mme->pos().x()+d->resizePos.x(),height());
    00550                                 break;
    00551                         case KDockWidgetPrivate::ResizeBottomRight:
    00552                                 resize(mme->pos().x()+d->resizePos.x(),mme->pos().y()+d->resizePos.y());
    00553                                 break;
    00554                         case KDockWidgetPrivate::ResizeBottom:
    00555                                 resize(width(),mme->pos().y()+d->resizePos.y());
    00556                                 break;
    00557                         default:
    00558                                 break;
    00559                 }
    00560                 return;
    00561         }
    00562
    00563
    00564         bool bbottom;
    00565         bool bleft;
    00566         bool bright;
    00567         bool btop;
    00568         int styleheight;
    00569         QPoint mp;
    00570         mp=mme->pos();
    00571         styleheight=2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,this);
    00572         bbottom=mp.y()>=height()-styleheight;
    00573         btop=mp.y()<=styleheight;
    00574         bleft=mp.x()<=styleheight;
    00575         bright=mp.x()>=width()-styleheight;
    00576         kdDebug()<<"mousemovevent"<<endl;
    00577         if (bright)
    00578         {
    00579                 if (btop) setCursor(QCursor(SizeBDiagCursor));
    00580                 else
    00581                 if (bbottom) setCursor(QCursor(SizeFDiagCursor));
    00582                 else setCursor(QCursor(SizeHorCursor));
    00583         }
    00584         else if (bleft)
    00585         {
    00586                 if (btop) setCursor(QCursor(SizeFDiagCursor));
    00587                 else
    00588                 if (bbottom) setCursor(QCursor(SizeBDiagCursor));
    00589                 else setCursor(QCursor(SizeHorCursor));
    00590         }
    00591         else
    00592         if (bbottom ||  btop) setCursor(QCursor(SizeVerCursor));
    00593         else setCursor(QCursor(ArrowCursor));
    00594 #endif
    00595 }
    00596
    00597 void KDockWidget::setLatestKDockContainer(QWidget* container)
    00598 {
    00599         if (container)
    00600         {
    00601                 if (container->qt_cast("KDockContainer"))
    00602                 d->container=container;
    00603                 else
    00604                 d->container=0;
    00605         }
    00606 }
    00607
    00608 QWidget* KDockWidget::latestKDockContainer()
    00609 {
    00610         if (!(d->container)) return 0;
    00611         if (d->container->qt_cast("KDockContainer")) return d->container;
    00612         return 0;
    00613 }
    00614
    00615
    00616
    00617 void KDockWidget::setHeader( KDockWidgetAbstractHeader* h )
    00618 {
    00619   if ( !h ) return;
    00620
    00621   if ( header ){
    00622     delete header;
    00623     delete layout;
    00624     header = h;
    00625     layout = new QVBoxLayout( this );
    00626     layout->setResizeMode( QLayout::Minimum );
    00627     layout->addWidget( header );
    00628      setWidget( widget );
    00629   } else {
    00630     header = h;
    00631     layout->addWidget( header );
    00632   }
    00633 }
    00634
    00635 void KDockWidget::setEnableDocking( int pos )
    00636 {
    00637   eDocking = pos;
    00638   if( header && header->inherits( "KDockWidgetHeader" ) )
    00639      ( ( KDockWidgetHeader* ) header )->showUndockButton( pos & DockDesktop );
    00640   updateHeader();
    00641 }
    00642
    00643 void KDockWidget::updateHeader()
    00644 {
    00645   if ( parent() ){
    00646 #ifdef BORDERLESS_WINDOWS
    00647       layout->setMargin(0);
    00648       setMouseTracking(false);
    00649       setCursor(QCursor(ArrowCursor));
    00650 #endif
    00651
    00652     if ( (parent() == manager->main) || isGroup || (eDocking == KDockWidget::DockNone) ){
    00653       header->hide();
    00654     } else {
    00655       header->setTopLevel( false );
    00656       if (widget && (widget->qt_cast("KDockContainer"))) header->hide(); else
    00657       header->show();
    00658     }
    00659   } else {
    00660     header->setTopLevel( true );
    00661     header->show();
    00662 #ifdef BORDERLESS_WINDOWS
    00663       layout->setMargin(2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,this));
    00664       setMouseTracking(true);
    00665 #endif
    00666   }
    00667 }
    00668
    00669 void KDockWidget::applyToWidget( QWidget* s, const QPoint& p )
    00670 {
    00671   if ( parent() != s )
    00672   {
    00673     hide();
    00674     reparent(s, 0, QPoint(0,0), false);
    00675   }
    00676
    00677   if ( s && s->inherits("KDockMainWindow") ){
    00678     ((KDockMainWindow*)s)->setView( this );
    00679   }
    00680
    00681   if ( s == manager->main ){
    00682       setGeometry( QRect(QPoint(0,0), manager->main->geometry().size()) );
    00683   }
    00684
    00685   if ( !s )
    00686   {
    00687     move(p);
    00688
    00689 #ifndef NO_KDE2
    00690 #ifdef Q_WS_X11
    00691     if (d->transient && d->_parent)
    00692       XSetTransientForHint( qt_xdisplay(), winId(), d->_parent->winId() );
    00693
    00694 #ifdef BORDERLESS_WINDOWS
    00695     KWin::setType( winId(), NET::Override); //d->windowType );
    00696 //      setWFlags(WStyle_Customize | WStyle_NoBorder | WStyle_Tool);
    00697 #else
    00698     KWin::setType( winId(), d->windowType );
    00699 #endif
    00700 #endif
    00701 #endif
    00702
    00703   }
    00704   updateHeader();
    00705
    00706   setIcon(*pix);
    00707 }
    00708
    00709 void KDockWidget::show()
    00710 {
    00711   if ( parent() || manager->main->isVisible() )
    00712     if ( !parent() ){
    00713      emit manager->setDockDefaultPos( this );
    00714      emit setDockDefaultPos();
    00715      if ( parent() ){
    00716         makeDockVisible();
    00717       } else {
    00718         QWidget::show();
    00719       }
    00720     } else {
    00721      QWidget::show();
    00722     }
    00723 }
    00724
    00725 #ifndef NO_KDE2
    00726
    00727 void KDockWidget::setDockWindowType (NET::WindowType windowType)
    00728 {
    00729   d->windowType = windowType;
    00730   applyToWidget( parentWidget(), QPoint(0,0) );
    00731 }
    00732
    00733 #endif
    00734
    00735 void KDockWidget::setDockWindowTransient (QWidget *parent, bool transientEnabled)
    00736 {
    00737   d->_parent = parent;
    00738   d->transient = transientEnabled;
    00739   applyToWidget( parentWidget(), QPoint(0,0) );
    00740 }
    00741
    00742 bool KDockWidget::event( QEvent *event )
    00743 {
    00744   switch ( event->type() )
    00745   {
    00746     #undef FocusIn
    00747     case QEvent::FocusIn:
    00748       if (widget && !d->pendingFocusInEvent) {
    00749          d->pendingFocusInEvent = true;
    00750          widget->setFocus();
    00751       }
    00752       d->pendingFocusInEvent = false;
    00753       break;
    00754     case QEvent::ChildRemoved:
    00755       if ( widget == ((QChildEvent*)event)->child() ) widget = 0L;
    00756       break;
    00757     case QEvent::Show:
    00758       if ( widget ) widget->show();
    00759       emit manager->change();
    00760       break;
    00761     case QEvent::Hide:
    00762       if ( widget ) widget->hide();
    00763       emit manager->change();
    00764       break;
    00765     case QEvent::CaptionChange:
    00766       if ( parentWidget() ){
    00767         if ( parent()->inherits("KDockSplitter") ){
    00768           ((KDockSplitter*)(parent()))->updateName();
    00769         }
    00770         if ( parentDockTabGroup() ){
    00771           setDockTabName( parentDockTabGroup() );
    00772           parentDockTabGroup()->setTabLabel( this, tabPageLabel() );
    00773         }
    00774       }
    00775       break;
    00776     case QEvent::Close:
    00777       emit iMBeingClosed();
    00778       break;
    00779     default:
    00780       break;
    00781   }
    00782   return QWidget::event( event );
    00783 }
    00784
    00785 KDockWidget *KDockWidget::findNearestDockWidget(DockPosition pos)
    00786 {
    00787         if (!parent()) return 0;
    00788         if (!parent()->inherits("KDockSplitter")) return 0;
    00789         Orientation orientation=((pos==DockLeft) || (pos==DockRight)) ? Vertical:Horizontal;
    00790                 if (((KDockSplitter*)(parent()))->orientation()==orientation)
    00791                 {
    00792                         KDockWidget *neighbour=
    00793                                 ((pos==DockLeft)||(pos==DockTop))?
    00794                                 static_cast<KDockWidget*>(((KDockSplitter*)(parent()))->getFirst()):
    00795                                 static_cast<KDockWidget*>(((KDockSplitter*)(parent()))->getLast());
    00796
    00797                         if (neighbour==this)
    00798                         return (static_cast<KDockWidget*>(parent()->parent())->findNearestDockWidget(pos));
    00799                         else
    00800                         if (neighbour->getWidget() && (neighbour->getWidget()->qt_cast("KDockTabGroup")))
    00801                                 return (KDockWidget*)(((KDockTabGroup*)neighbour->getWidget())->page(0));
    00802                         else
    00803                         return neighbour;
    00804                 }
    00805                 else
    00806                 return (static_cast<KDockWidget*>(parent()->parent())->findNearestDockWidget(pos));
    00807
    00808         return 0;
    00809 }
    00810
    00811
    00812 KDockWidget* KDockWidget::manualDock( KDockWidget* target, DockPosition dockPos, int spliPos, QPoint pos, bool check, int tabIndex )
    00813 {
    00814   if (this == target)
    00815     return 0L;  // docking to itself not possible
    00816 //  kdDebug()<<"manualDock called "<<endl;
    00817   bool succes = true; // tested flag
    00818
    00819   // check allowed this dock submit this operations
    00820   if ( !(eDocking & (int)dockPos) ){
    00821     succes = false;
    00822 //  kdDebug()<<"KDockWidget::manualDock(): success = false (1)"<<endl;
    00823   }
    00824
    00825   // check allowed target submit this operations
    00826   if ( target && !(target->sDocking & (int)dockPos) ){
    00827     succes = false;
    00828 //  kdDebug()<<"KDockWidget::manualDock(): success = false (2)"<<endl;
    00829   }
    00830
    00831   if ( parent() && !parent()->inherits("KDockSplitter") && !parentDockTabGroup() &&
    00832         !(parent()->qt_cast("KDockContainer")) && !parentDockContainer()){
    00833 //  kdDebug()<<"KDockWidget::manualDock(): success = false (3)"<<endl;
    00834 //  kdDebug()<<parent()->name()<<endl;
    00835     succes = false;
    00836   }
    00837
    00838 //  kdDebug()<<"KDockWidget::manualDock(): success == false "<<endl;
    00839   if ( !succes ){
    00840     // try to make another manualDock
    00841     KDockWidget* dock_result = 0L;
    00842     if ( target && !check ){
    00843       KDockWidget::DockPosition another__dockPos = KDockWidget::DockNone;
    00844       switch ( dockPos ){
    00845         case KDockWidget::DockLeft  : another__dockPos = KDockWidget::DockRight ; break;
    00846         case KDockWidget::DockRight : another__dockPos = KDockWidget::DockLeft  ; break;
    00847         case KDockWidget::DockTop   : another__dockPos = KDockWidget::DockBottom; break;
    00848         case KDockWidget::DockBottom: another__dockPos = KDockWidget::DockTop   ; break;
    00849         default: break;
    00850       }
    00851       dock_result = target->manualDock( this, another__dockPos, spliPos, pos, true, tabIndex );
    00852     }
    00853     return dock_result;
    00854   }
    00855   // end check block
    00856
    00857   d->blockHasUndockedSignal = true;
    00858   undock();
    00859   d->blockHasUndockedSignal = false;
    00860
    00861   if ( !target ){
    00862     move( pos );
    00863     show();
    00864     emit manager->change();
    00865     return this;
    00866   }
    00867
    00868 //  kdDebug()<<"Looking for  KDockTabGroup"<<endl;
    00869   KDockTabGroup* parentTab = target->parentDockTabGroup();
    00870   if ( parentTab ){
    00871     // add to existing TabGroup
    00872     applyToWidget( parentTab );
    00873     parentTab->insertTab( this, icon() ? *icon() : QPixmap(),
    00874                           tabPageLabel(), tabIndex );
    00875     setDockTabName( parentTab );
    00876     if( !toolTipStr.isEmpty())
    00877       parentTab->setTabToolTip( this, toolTipStr);
    00878
    00879     currentDockPos = KDockWidget::DockCenter;
    00880     emit manager->change();
    00881     return (KDockWidget*)parentTab->parent();
    00882   }
    00883   else
    00884   {
    00885 //      kdDebug()<<"Looking for  KDockContainer"<<endl;
    00886         QWidget *contWid=target->parentDockContainer();
    00887           if (!contWid) contWid=target->widget;
    00888           if (contWid)
    00889           {
    00890                 KDockContainer *cont=(KDockContainer*)contWid->qt_cast("KDockContainer");
    00891                   if (cont)
    00892                   {
    00893                         if (latestKDockContainer() && (latestKDockContainer()!=contWid))
    00894                                 static_cast<KDockContainer*>(latestKDockContainer()->qt_cast("KDockContainer"))->removeWidget(this);
    00895 //                      kdDebug()<<"KDockContainerFound"<<endl;
    00896                         applyToWidget( contWid );
    00897                         cont->insertWidget( this, icon() ? *icon() : QPixmap(),
    00898                                                 tabPageLabel(), tabIndex );
    00899                         setLatestKDockContainer(contWid);
    00900 //                      setDockTabName( parentTab );
    00901                         if( !toolTipStr.isEmpty())
    00902                         cont->setToolTip( this, toolTipStr);
    00903
    00904                         currentDockPos = KDockWidget::DockCenter;
    00905                         emit manager->change();
    00906                         return (KDockWidget*)(cont->parentDockWidget());
    00907
    00908                   }
    00909           }
    00910   }
    00911
    00912   // create a new dockwidget that will contain the target and this
    00913   QWidget* parentDock = target->parentWidget();
    00914   KDockWidget* newDock = new KDockWidget( manager, "tempName", QPixmap(""), parentDock );
    00915   newDock->currentDockPos = target->currentDockPos;
    00916
    00917   if ( dockPos == KDockWidget::DockCenter ){
    00918     newDock->isTabGroup = true;
    00919   } else {
    00920     newDock->isGroup = true;
    00921   }
    00922   newDock->eDocking = (target->eDocking & eDocking) & (~(int)KDockWidget::DockCenter);
    00923
    00924   newDock->applyToWidget( parentDock );
    00925
    00926   if ( !parentDock ){
    00927     // dock to a toplevel dockwidget means newDock is toplevel now
    00928     newDock->move( target->frameGeometry().topLeft() );
    00929     newDock->resize( target->geometry().size() );
    00930     if ( target->isVisibleToTLW() ) newDock->show();
    00931   }
    00932
    00933   // redirect the dockback button to the new dockwidget
    00934   if( target->formerBrotherDockWidget != 0L) {
    00935     newDock->formerBrotherDockWidget = target->formerBrotherDockWidget;
    00936     if( formerBrotherDockWidget != 0L)
    00937       QObject::connect( newDock->formerBrotherDockWidget, SIGNAL(iMBeingClosed()),
    00938                         newDock, SLOT(loseFormerBrotherDockWidget()) );
    00939       target->loseFormerBrotherDockWidget();
    00940     }
    00941   newDock->formerDockPos = target->formerDockPos;
    00942
    00943
    00944  // HERE SOMETING CREATING CONTAINERS SHOULD BE ADDED !!!!!
    00945   if ( dockPos == KDockWidget::DockCenter )
    00946   {
    00947     KDockTabGroup* tab = new KDockTabGroup( newDock, "_dock_tab");
    00948     QObject::connect(tab, SIGNAL(currentChanged(QWidget*)), d, SLOT(slotFocusEmbeddedWidget(QWidget*)));
    00949     newDock->setWidget( tab );
    00950
    00951     target->applyToWidget( tab );
    00952     applyToWidget( tab );
    00953
    00954
    00955     tab->insertTab( target, target->icon() ? *(target->icon()) : QPixmap(),
    00956                     target->tabPageLabel() );
    00957     if( !target->toolTipString().isEmpty())
    00958       tab->setTabToolTip( target, target->toolTipString());
    00959
    00960     tab->insertTab( this, icon() ? *icon() : QPixmap(),
    00961                     tabPageLabel(), tabIndex );
    00962     if( !toolTipString().isEmpty())
    00963       tab->setTabToolTip( this, toolTipString());
    00964
    00965     setDockTabName( tab );
    00966     tab->show();
    00967
    00968     currentDockPos = DockCenter;
    00969     target->formerDockPos = target->currentDockPos;
    00970     target->currentDockPos = DockCenter;
    00971   }
    00972   else {
    00973     // if to dock not to the center of the target dockwidget,
    00974     // dock to newDock
    00975     KDockSplitter* panner = 0L;
    00976     if ( dockPos == KDockWidget::DockTop  || dockPos == KDockWidget::DockBottom ) panner = new KDockSplitter( newDock, "_dock_split_", Horizontal, spliPos, manager->splitterHighResolution() );
    00977     if ( dockPos == KDockWidget::DockLeft || dockPos == KDockWidget::DockRight  ) panner = new KDockSplitter( newDock, "_dock_split_", Vertical , spliPos, manager->splitterHighResolution() );
    00978     newDock->setWidget( panner );
    00979
    00980     panner->setOpaqueResize(manager->splitterOpaqueResize());
    00981     panner->setKeepSize(manager->splitterKeepSize());
    00982     panner->setFocusPolicy( NoFocus );
    00983     target->applyToWidget( panner );
    00984     applyToWidget( panner );
    00985     target->formerDockPos = target->currentDockPos;
    00986     if ( dockPos == KDockWidget::DockRight) {
    00987       panner->activate( target, this );
    00988       currentDockPos = KDockWidget::DockRight;
    00989       target->currentDockPos = KDockWidget::DockLeft;
    00990     }
    00991     else if( dockPos == KDockWidget::DockBottom) {
    00992       panner->activate( target, this );
    00993       currentDockPos = KDockWidget::DockBottom;
    00994       target->currentDockPos = KDockWidget::DockTop;
    00995     }
    00996     else if( dockPos == KDockWidget::DockTop) {
    00997       panner->activate( this, target );
    00998       currentDockPos = KDockWidget::DockTop;
    00999       target->currentDockPos = KDockWidget::DockBottom;
    01000     }
    01001     else if( dockPos == KDockWidget::DockLeft) {
    01002       panner->activate( this, target );
    01003       currentDockPos = KDockWidget::DockLeft;
    01004       target->currentDockPos = KDockWidget::DockRight;
    01005     }
    01006     target->show();
    01007     show();
    01008     panner->show();
    01009   }
    01010
    01011   if ( parentDock ){
    01012     if ( parentDock->inherits("KDockSplitter") ){
    01013       KDockSplitter* sp = (KDockSplitter*)parentDock;
    01014       sp->deactivate();
    01015       if ( sp->getFirst() == target )
    01016         sp->activate( newDock, 0L );
    01017       else
    01018         sp->activate( 0L, newDock );
    01019     }
    01020   }
    01021
    01022   newDock->show();
    01023   emit target->docking( this, dockPos );
    01024   emit manager->replaceDock( target, newDock );
    01025   emit manager->change();
    01026
    01027   return newDock;
    01028 }
    01029
    01030 KDockTabGroup* KDockWidget::parentDockTabGroup() const
    01031 {
    01032   if ( !parent() ) return 0L;
    01033   QWidget* candidate = parentWidget()->parentWidget();
    01034   if ( candidate && candidate->inherits("KDockTabGroup") ) return (KDockTabGroup*)candidate;
    01035   return 0L;
    01036 }
    01037
    01038 QWidget *KDockWidget::parentDockContainer() const
    01039 {
    01040   if (!parent()) return 0L;
    01041   QWidget* candidate = parentWidget()->parentWidget();
    01042   if (candidate && candidate->qt_cast("KDockContainer")) return candidate;
    01043   return 0L;
    01044 }
    01045
    01046
    01047 void KDockWidget::setForcedFixedWidth(int w)
    01048 {
    01049         d->forcedWidth=w;
    01050         setFixedWidth(w);
    01051         if (!parent()) return;
    01052         if (parent()->inherits("KDockSplitter"))
    01053                 static_cast<KDockSplitter*>(parent()->qt_cast("KDockSplitter"))->setForcedFixedWidth(this,w);
    01054 }
    01055
    01056 void KDockWidget::setForcedFixedHeight(int h)
    01057 {
    01058         d->forcedHeight=h;
    01059         setFixedHeight(h);
    01060         if (!parent()) return;
    01061         if (parent()->inherits("KDockSplitter"))
    01062                 static_cast<KDockSplitter*>(parent()->qt_cast("KDockSplitter"))->setForcedFixedHeight(this,h);
    01063 }
    01064
    01065 int KDockWidget::forcedFixedWidth()
    01066 {
    01067         return d->forcedWidth;
    01068 }
    01069
    01070 int KDockWidget::forcedFixedHeight()
    01071 {
    01072         return d->forcedHeight;
    01073 }
    01074
    01075 void KDockWidget::restoreFromForcedFixedSize()
    01076 {
    01077         d->forcedWidth=-1;
    01078         setMinimumWidth(0);
    01079         setMaximumWidth(32000);
    01080         setMinimumHeight(0);
    01081         setMaximumHeight(32000);
    01082         if (!parent()) return;
    01083         if (parent()->inherits("KDockSplitter"))
    01084                 static_cast<KDockSplitter*>(parent()->qt_cast("KDockSplitter"))->restoreFromForcedFixedSize(this);
    01085 }
    01086
    01087 void KDockWidget::toDesktop()
    01088 {
    01089    QPoint p = mapToGlobal( QPoint( -30, -30 ) );
    01090    if( p.x( ) < 0 )
    01091       p.setX( 0 );
    01092    if( p.y( ) < 0 )
    01093       p.setY( 0 );
    01094    manualDock( 0, DockDesktop, 50, p );
    01095 }
    01096
    01097 void KDockWidget::undock()
    01098 {
    01099 //  kdDebug()<<"KDockWidget::undock()"<<endl;
    01100
    01101   manager->d->dragRect = QRect ();
    01102   manager->drawDragRectangle ();
    01103
    01104   QWidget* parentW = parentWidget();
    01105   if ( !parentW ){
    01106     hide();
    01107     if (!d->blockHasUndockedSignal)
    01108       emit hasUndocked();
    01109     return;
    01110   }
    01111
    01112   formerDockPos = currentDockPos;
    01113   currentDockPos = KDockWidget::DockDesktop;
    01114
    01115   manager->blockSignals(true);
    01116   manager->undockProcess = true;
    01117
    01118   bool isV = parentW->isVisibleToTLW();
    01119
    01120   //UNDOCK HAS TO BE IMPLEMENTED CORRECTLY :)
    01121   KDockTabGroup* parentTab = parentDockTabGroup();
    01122   if ( parentTab ){
    01123     d->index = parentTab->indexOf( this); // memorize the page position in the tab widget
    01124     parentTab->removePage( this );
    01125     formerBrotherDockWidget = (KDockWidget*)parentTab->page(0);
    01126     QObject::connect( formerBrotherDockWidget, SIGNAL(iMBeingClosed()),
    01127                       this, SLOT(loseFormerBrotherDockWidget()) );
    01128     applyToWidget( 0L );
    01129     if ( parentTab->count() == 1 ){
    01130
    01131       // last subdock widget in the tab control
    01132       KDockWidget* lastTab = (KDockWidget*)parentTab->page(0);
    01133       parentTab->removePage( lastTab );
    01134       lastTab->applyToWidget( 0L );
    01135       lastTab->move( parentTab->mapToGlobal(parentTab->frameGeometry().topLeft()) );
    01136
    01137       // KDockTabGroup always have a parent that is a KDockWidget
    01138       KDockWidget* parentOfTab = (KDockWidget*)parentTab->parent();
    01139       delete parentTab; // KDockTabGroup
    01140
    01141       QWidget* parentOfDockWidget = parentOfTab->parentWidget();
    01142       if ( parentOfDockWidget == 0L ){
    01143           if ( isV ) lastTab->show();
    01144       } else {
    01145         if ( parentOfDockWidget->inherits("KDockSplitter") ){
    01146           KDockSplitter* split = (KDockSplitter*)parentOfDockWidget;
    01147           lastTab->applyToWidget( split );
    01148           split->deactivate();
    01149           if ( split->getFirst() == parentOfTab ){
    01150             split->activate( lastTab );
    01151             if ( ((KDockWidget*)split->parent())->splitterOrientation == Vertical )
    01152               emit ((KDockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, KDockWidget::DockLeft );
    01153             else
    01154               emit ((KDockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, KDockWidget::DockTop );
    01155           } else {
    01156             split->activate( 0L, lastTab );
    01157             if ( ((KDockWidget*)split->parent())->splitterOrientation == Vertical )
    01158               emit ((KDockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, KDockWidget::DockRight );
    01159             else
    01160               emit ((KDockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, KDockWidget::DockBottom );
    01161           }
    01162           split->show();
    01163         } else {
    01164           lastTab->applyToWidget( parentOfDockWidget );
    01165         }
    01166         lastTab->show();
    01167       }
    01168       manager->blockSignals(false);
    01169       emit manager->replaceDock( parentOfTab, lastTab );
    01170       lastTab->currentDockPos = parentOfTab->currentDockPos;
    01171       emit parentOfTab->iMBeingClosed();
    01172       manager->blockSignals(true);
    01173       delete parentOfTab;
    01174
    01175     } else {
    01176       setDockTabName( parentTab );
    01177     }
    01178   } else {
    01179  /*********************************************************************************************/
    01180   //QWidget* containerWidget = (QWidget*)parent();
    01181   bool undockedFromContainer=false;
    01182   if (d->container)
    01183   {
    01184 //                kdDebug()<<"undocked from dockcontainer"<<endl;
    01185                   undockedFromContainer=true;
    01186                   static_cast<KDockContainer*>(d->container->qt_cast("KDockContainer"))->undockWidget(this);
    01187                   formerBrotherDockWidget=static_cast<KDockContainer*>(d->container->qt_cast("KDockContainer"))->parentDockWidget();
    01188                   applyToWidget( 0L );
    01189   }
    01190    if (!undockedFromContainer) {
    01191 /*********************************************************************************************/
    01192     if ( parentW->inherits("KDockSplitter") ){
    01193       KDockSplitter* parentSplitterOfDockWidget = (KDockSplitter*)parentW;
    01194       d->splitPosInPercent = parentSplitterOfDockWidget->separatorPos();
    01195
    01196       KDockWidget* secondWidget = (KDockWidget*)parentSplitterOfDockWidget->getAnother( this );
    01197       KDockWidget* group        = (KDockWidget*)parentSplitterOfDockWidget->parentWidget();
    01198       formerBrotherDockWidget = secondWidget;
    01199       applyToWidget( 0L );
    01200       group->hide();
    01201
    01202       if( formerBrotherDockWidget != 0L)
    01203         QObject::connect( formerBrotherDockWidget, SIGNAL(iMBeingClosed()),
    01204                           this, SLOT(loseFormerBrotherDockWidget()) );
    01205
    01206       if ( !group->parentWidget() ){
    01207         secondWidget->applyToWidget( 0L, group->frameGeometry().topLeft() );
    01208         secondWidget->resize( group->width(), group->height() );
    01209       } else {
    01210         QWidget* obj = group->parentWidget();
    01211         secondWidget->applyToWidget( obj );
    01212         if ( obj->inherits("KDockSplitter") ){
    01213           KDockSplitter* parentOfGroup = (KDockSplitter*)obj;
    01214           parentOfGroup->deactivate();
    01215
    01216           if ( parentOfGroup->getFirst() == group )
    01217             parentOfGroup->activate( secondWidget );
    01218           else
    01219             parentOfGroup->activate( 0L, secondWidget );
    01220         }
    01221       }
    01222       secondWidget->currentDockPos = group->currentDockPos;
    01223       secondWidget->formerDockPos  = group->formerDockPos;
    01224       delete parentSplitterOfDockWidget;
    01225       manager->blockSignals(false);
    01226       emit manager->replaceDock( group, secondWidget );
    01227       emit group->iMBeingClosed();
    01228       manager->blockSignals(true);
    01229       delete group;
    01230
    01231       if ( isV ) secondWidget->show();
    01232     } else {
    01233       if (!d->pendingDtor) {
    01234         // don't reparent in the dtor of this
    01235         applyToWidget( 0L );
    01236       }
    01237     }
    01238 /*********************************************************************************************/
    01239   }
    01240   }
    01241   manager->blockSignals(false);
    01242   if (!d->blockHasUndockedSignal)
    01243     emit manager->change();
    01244   manager->undockProcess = false;
    01245
    01246   if (!d->blockHasUndockedSignal)
    01247     emit hasUndocked();
    01248 }
    01249
    01250 void KDockWidget::setWidget( QWidget* mw )
    01251 {
    01252   if ( !mw ) return;
    01253
    01254   if ( mw->parent() != this ){
    01255     mw->reparent(this, 0, QPoint(0,0), false);
    01256   }
    01257
    01258 #ifdef BORDERLESS_WINDOWS
    01259   if (!mw->ownCursor()) mw->setCursor(QCursor(ArrowCursor));
    01260 #endif
    01261   widget = mw;
    01262   delete layout;
    01263
    01264   layout = new QVBoxLayout( this );
    01265   layout->setResizeMode( QLayout::Minimum );
    01266
    01267   if (widget->qt_cast("KDockContainer"))
    01268   {
    01269     d->isContainer=true;
    01270     manager->d->containerDocks.append(this);
    01271   }
    01272   else
    01273   {
    01274         d->isContainer=false;
    01275   }
    01276
    01277   {
    01278      header->show();
    01279      layout->addWidget( header );
    01280      layout->addWidget( widget,1 );
    01281   }
    01282   updateHeader();
    01283 }
    01284
    01285 void KDockWidget::setDockTabName( KDockTabGroup* tab )
    01286 {
    01287   QString listOfName;
    01288   QString listOfCaption;
    01289   for ( int i = 0; i < tab->count(); ++i ) {
    01290     QWidget *w = tab->page( i );
    01291     listOfCaption.append( w->caption() ).append(",");
    01292     listOfName.append( w->name() ).append(",");
    01293   }
    01294   listOfCaption.remove( listOfCaption.length()-1, 1 );
    01295   listOfName.remove( listOfName.length()-1, 1 );
    01296
    01297   tab->parentWidget()->setName( listOfName.utf8() );
    01298   tab->parentWidget()->setCaption( listOfCaption );
    01299
    01300   tab->parentWidget()->repaint( false ); // KDockWidget->repaint
    01301   if ( tab->parentWidget()->parent() )
    01302     if ( tab->parentWidget()->parent()->inherits("KDockSplitter") )
    01303       ((KDockSplitter*)(tab->parentWidget()->parent()))->updateName();
    01304 }
    01305
    01306 bool KDockWidget::mayBeHide() const
    01307 {
    01308   bool f = (parent() != manager->main);
    01309   return ( !isGroup && !isTabGroup && f && isVisible() && ( eDocking != (int)KDockWidget::DockNone ) );
    01310 }
    01311
    01312 bool KDockWidget::mayBeShow() const
    01313 {
    01314   bool f = (parent() != manager->main);
    01315   return ( !isGroup && !isTabGroup && f && !isVisible() );
    01316 }
    01317
    01318 void KDockWidget::changeHideShowState()
    01319 {
    01320   if ( mayBeHide() ){
    01321     undock();
    01322     return;
    01323   }
    01324
    01325   if ( mayBeShow() ){
    01326     if ( manager->main->inherits("KDockMainWindow") ){
    01327       ((KDockMainWindow*)manager->main)->makeDockVisible(this);
    01328     } else {
    01329       makeDockVisible();
    01330     }
    01331   }
    01332 }
    01333
    01334 void KDockWidget::makeDockVisible()
    01335 {
    01336   if ( parentDockTabGroup() ){
    01337     parentDockTabGroup()->showPage( this );
    01338   }
    01339   if ( isVisible() ) return;
    01340
    01341   QWidget* p = parentWidget();
    01342   while ( p ){
    01343     if ( !p->isVisible() )
    01344       p->show();
    01345     p = p->parentWidget();
    01346   }
    01347   if( parent() == 0L) // is undocked
    01348     dockBack();
    01349   show();
    01350 }
    01351
    01352 void KDockWidget::loseFormerBrotherDockWidget()
    01353 {
    01354   if( formerBrotherDockWidget != 0L)
    01355     QObject::disconnect( formerBrotherDockWidget, SIGNAL(iMBeingClosed()),
    01356                          this, SLOT(loseFormerBrotherDockWidget()) );
    01357   formerBrotherDockWidget = 0L;
    01358   repaint();
    01359 }
    01360
    01361 void KDockWidget::dockBack()
    01362 {
    01363   if( formerBrotherDockWidget) {
    01364     // search all children if it tries to dock back to a child
    01365     bool found = false;
    01366     QObjectList* cl = queryList("KDockWidget");
    01367     QObjectListIt it( *cl );
    01368     QObject * obj;
    01369     while ( !found && (obj=it.current()) != 0 ) {
    01370       ++it;
    01371       QWidget* widg = (QWidget*)obj;
    01372       if( widg == formerBrotherDockWidget)
    01373         found = true;
    01374     }
    01375     delete cl;
    01376
    01377     if( !found) {
    01378       // can dock back to the former brother dockwidget
    01379       manualDock( formerBrotherDockWidget, formerDockPos, d->splitPosInPercent, QPoint(0,0), false, d->index);
    01380       formerBrotherDockWidget = 0L;
    01381       makeDockVisible();
    01382       return;
    01383     }
    01384   }
    01385
    01386   // else dockback to the dockmainwindow (default behaviour)
    01387   manualDock( ((KDockMainWindow*)manager->main)->getMainDockWidget(), formerDockPos, d->splitPosInPercent, QPoint(0,0), false, d->index);
    01388   formerBrotherDockWidget = 0L;
    01389   if (parent())
    01390     makeDockVisible();
    01391 }
    01392
    01393 bool KDockWidget::isDockBackPossible() const
    01394 {
    01395   if( (formerBrotherDockWidget == 0L) || !(formerBrotherDockWidget->dockSite() & formerDockPos))
    01396     return false;
    01397   else
    01398     return true;
    01399 }
    01400
    01401 /**************************************************************************************/
    01402
    01403
    01404 KDockManager::KDockManager( QWidget* mainWindow , const char* name )
    01405 :QObject( mainWindow, name )
    01406   ,main(mainWindow)
    01407   ,currentDragWidget(0L)
    01408   ,currentMoveWidget(0L)
    01409   ,childDockWidgetList(0L)
    01410   ,autoCreateDock(0L)
    01411   ,storeW(0)
    01412   ,storeH(0)
    01413   ,draging(false)
    01414   ,undockProcess(false)
    01415   ,dropCancel(true)
    01416 {
    01417   d = new KDockManagerPrivate;
    01418   d->mainDockWidget=0;
    01419   d->splitterOpaqueResize = false;
    01420   d->splitterKeepSize = false;
    01421   d->splitterHighResolution = false;
    01422
    01423   main->installEventFilter( this );
    01424
    01425   undockProcess = false;
    01426
    01427   menuData = new QPtrList<MenuDockData>;
    01428   menuData->setAutoDelete( true );
    01429   menuData->setAutoDelete( true );
    01430
    01431 #ifndef NO_KDE2
    01432   menu = new KPopupMenu();
    01433 #else
    01434   menu = new QPopupMenu();
    01435 #endif
    01436
    01437   connect( menu, SIGNAL(aboutToShow()), SLOT(slotMenuPopup()) );
    01438   connect( menu, SIGNAL(activated(int)), SLOT(slotMenuActivated(int)) );
    01439
    01440   childDock = new QObjectList();
    01441   childDock->setAutoDelete( false );
    01442 }
    01443
    01444
    01445 void KDockManager::setMainDockWidget2(KDockWidget *w)
    01446 {
    01447   d->mainDockWidget=w;
    01448 }
    01449
    01450 KDockManager::~KDockManager()
    01451 {
    01452   delete menuData;
    01453   delete menu;
    01454
    01455   QObjectListIt it( *childDock );
    01456   KDockWidget * obj;
    01457
    01458   while ( (obj=(KDockWidget*)it.current()) ) {
    01459     delete obj;
    01460   }
    01461   delete childDock;
    01462   delete d;
    01463   d=0;
    01464 }
    01465
    01466 void KDockManager::activate()
    01467 {
    01468   QObjectListIt it( *childDock );
    01469   KDockWidget * obj;
    01470
    01471   while ( (obj=(KDockWidget*)it.current()) ) {
    01472     ++it;
    01473     if ( obj->widget ) obj->widget->show();
    01474     if ( !obj->parentDockTabGroup() ){
    01475         obj->show();
    01476     }
    01477   }
    01478   if ( !main->inherits("QDialog") ) main->show();
    01479 }
    01480
    01481 bool KDockManager::eventFilter( QObject *obj, QEvent *event )
    01482 {
    01483
    01484   if ( obj->inherits("KDockWidgetAbstractHeaderDrag") ){
    01485     KDockWidget* pDockWdgAtCursor = 0L;
    01486     KDockWidget* curdw = ((KDockWidgetAbstractHeaderDrag*)obj)->dockWidget();
    01487     switch ( event->type() ){
    01488       case QEvent::MouseButtonDblClick:
    01489         if (curdw->currentDockPos == KDockWidget::DockDesktop)  curdw->dockBack();
    01490         else
    01491         {
    01492                 curdw->toDesktop();
    01493                 // curdw->manualDock (0, KDockWidget::DockDesktop);
    01494         }
    01495         break;
    01496
    01497       case QEvent::MouseButtonPress:
    01498         if ( ((QMouseEvent*)event)->button() == LeftButton ){
    01499           if ( curdw->eDocking != (int)KDockWidget::DockNone ){
    01500             dropCancel = true;
    01501             curdw->setFocus();
    01502             qApp->processOneEvent();
    01503
    01504             currentDragWidget = curdw;
    01505             currentMoveWidget = 0L;
    01506             childDockWidgetList = new QWidgetList();
    01507             childDockWidgetList->append( curdw );
    01508             findChildDockWidget( curdw, childDockWidgetList );
    01509
    01510             //d->oldDragRect = QRect(); should fix rectangle not erased problem
    01511             d->dragRect = QRect(curdw->geometry());
    01512             QPoint p = curdw->mapToGlobal(QPoint(0,0));
    01513             d->dragRect.moveTopLeft(p);
    01514             drawDragRectangle();
    01515             d->readyToDrag = true;
    01516
    01517             d->dragOffset = QCursor::pos()-currentDragWidget->mapToGlobal(QPoint(0,0));
    01518           }
    01519
    01520         }
    01521         break;
    01522       case QEvent::MouseButtonRelease:
    01523         if ( ((QMouseEvent*)event)->button() == LeftButton ){
    01524           if ( draging ){
    01525             if ( !dropCancel )
    01526               drop();
    01527             else
    01528               cancelDrop();
    01529           }
    01530           if (d->readyToDrag) {
    01531               d->readyToDrag = false;
    01532               //d->oldDragRect = QRect(); should fix rectangle not erased problem
    01533               d->dragRect = QRect(curdw->geometry());
    01534               QPoint p = curdw->mapToGlobal(QPoint(0,0));
    01535               d->dragRect.moveTopLeft(p);
    01536               drawDragRectangle();
    01537               currentDragWidget = 0L;
    01538               delete childDockWidgetList;
    01539               childDockWidgetList = 0L;
    01540           }
    01541           draging = false;
    01542           dropCancel = true;
    01543         }
    01544         break;
    01545       case QEvent::MouseMove:
    01546         if ( draging ) {
    01547
    01548 #ifdef BORDERLESS_WINDOWS
    01549 //BEGIN TEST
    01550           KDockWidget *oldMoveWidget;
    01551           if (curdw->parent()==0)
    01552           {
    01553                 curdw->move(QCursor::pos()-d->dragOffset);
    01554                 pDockWdgAtCursor = findDockWidgetAt( QCursor::pos()-QPoint(0,d->dragOffset.y()+3) );
    01555                 oldMoveWidget = currentMoveWidget;
    01556           }
    01557           else
    01558           {
    01559                 pDockWdgAtCursor = findDockWidgetAt( QCursor::pos() );
    01560                 oldMoveWidget = currentMoveWidget;
    01561           }
    01562 //END TEST
    01563 #else
    01564           pDockWdgAtCursor = findDockWidgetAt( QCursor::pos() );
    01565           KDockWidget* oldMoveWidget = currentMoveWidget;
    01566 #endif
    01567
    01568           if ( currentMoveWidget  && pDockWdgAtCursor == currentMoveWidget ) { //move
    01569             dragMove( currentMoveWidget, currentMoveWidget->mapFromGlobal( QCursor::pos() ) );
    01570             break;
    01571           } else {
    01572             if (dropCancel && curdw) {
    01573               d->dragRect = QRect(curdw->geometry());
    01574               QPoint p = curdw->mapToGlobal(QPoint(0,0));
    01575               d->dragRect.moveTopLeft(p);
    01576             }else
    01577               d->dragRect = QRect();
    01578
    01579             drawDragRectangle();
    01580           }
    01581
    01582           if ( !pDockWdgAtCursor && (curdw->eDocking & (int)KDockWidget::DockDesktop) == 0 ){
    01583               // just moving at the desktop
    01584               currentMoveWidget = pDockWdgAtCursor;
    01585               curPos = KDockWidget::DockDesktop;
    01586           } else {
    01587             if ( oldMoveWidget && pDockWdgAtCursor != currentMoveWidget ) { //leave
    01588               currentMoveWidget = pDockWdgAtCursor;
    01589               curPos = KDockWidget::DockDesktop;
    01590             }
    01591           }
    01592
    01593           if ( oldMoveWidget != pDockWdgAtCursor && pDockWdgAtCursor ) { //enter pDockWdgAtCursor
    01594             currentMoveWidget = pDockWdgAtCursor;
    01595             curPos = KDockWidget::DockDesktop;
    01596           }
    01597         } else {
    01598           if (d->readyToDrag) {
    01599             d->readyToDrag = false;
    01600           }
    01601           if ( (((QMouseEvent*)event)->state() == LeftButton) &&
    01602                (curdw->eDocking != (int)KDockWidget::DockNone) ) {
    01603             startDrag( curdw);
    01604           }
    01605         }
    01606         break;
    01607       default:
    01608         break;
    01609     }
    01610   }
    01611   return QObject::eventFilter( obj, event );
    01612 }
    01613
    01614 KDockWidget* KDockManager::findDockWidgetAt( const QPoint& pos )
    01615 {
    01616   dropCancel = true;
    01617
    01618   if (!currentDragWidget)
    01619     return 0L; // pointer access safety
    01620
    01621   if (currentDragWidget->eDocking == (int)KDockWidget::DockNone ) return 0L;
    01622
    01623   QWidget* p = QApplication::widgetAt( pos );
    01624   if ( !p ) {
    01625     dropCancel = false;
    01626     return 0L;
    01627   }
    01628 #if defined(_OS_WIN32_) || defined(Q_OS_WIN32)
    01629   p = p->topLevelWidget();
    01630 #endif
    01631   QWidget* w = 0L;
    01632   findChildDockWidget( w, p, p->mapFromGlobal(pos) );
    01633   if ( !w ){
    01634     if ( !p->inherits("KDockWidget") ) {
    01635       return 0L;
    01636     }
    01637     w = p;
    01638   }
    01639   if ( qt_find_obj_child( w, "KDockSplitter", "_dock_split_" ) ) return 0L;
    01640   if ( qt_find_obj_child( w, "KDockTabGroup", "_dock_tab" ) ) return 0L;
    01641   if (w->qt_cast("KDockContainer")) return 0L;
    01642
    01643   if (!childDockWidgetList) return 0L;
    01644   if ( childDockWidgetList->find(w) != -1 ) return 0L;
    01645   if ( currentDragWidget->isGroup && ((KDockWidget*)w)->parentDockTabGroup() ) return 0L;
    01646
    01647   KDockWidget* www = (KDockWidget*)w;
    01648   if ( www->sDocking == (int)KDockWidget::DockNone ) return 0L;
    01649
    01650   KDockWidget::DockPosition curPos = KDockWidget::DockDesktop;
    01651   QPoint cpos  = www->mapFromGlobal( pos );
    01652
    01653   int ww = www->widget->width() / 3;
    01654   int hh = www->widget->height() / 3;
    01655
    01656   if ( cpos.y() <= hh ){
    01657     curPos = KDockWidget::DockTop;
    01658   } else
    01659     if ( cpos.y() >= 2*hh ){
    01660       curPos = KDockWidget::DockBottom;
    01661     } else
    01662       if ( cpos.x() <= ww ){
    01663         curPos = KDockWidget::DockLeft;
    01664       } else
    01665         if ( cpos.x() >= 2*ww ){
    01666           curPos = KDockWidget::DockRight;
    01667         } else
    01668             curPos = KDockWidget::DockCenter;
    01669
    01670   if ( !(www->sDocking & (int)curPos) ) return 0L;
    01671   if ( !(currentDragWidget->eDocking & (int)curPos) ) return 0L;
    01672   if ( www->manager != this ) return 0L;
    01673
    01674   dropCancel = false;
    01675   return www;
    01676 }
    01677
    01678 void KDockManager::findChildDockWidget( QWidget*& ww, const QWidget* p, const QPoint& pos )
    01679 {
    01680   if ( p->children() ) {
    01681     QWidget *w;
    01682     QObjectListIt it( *p->children() );
    01683     it.toLast();
    01684     while ( it.current() ) {
    01685       if ( it.current()->isWidgetType() ) {
    01686         w = (QWidget*)it.current();
    01687         if ( w->isVisible() && w->geometry().contains(pos) ) {
    01688           if ( w->inherits("KDockWidget") ) ww = w;
    01689           findChildDockWidget( ww, w, w->mapFromParent(pos) );
    01690           return;
    01691         }
    01692       }
    01693       --it;
    01694     }
    01695   }
    01696   return;
    01697 }
    01698
    01699 void KDockManager::findChildDockWidget( const QWidget* p, QWidgetList*& list )
    01700 {
    01701   if ( p->children() ) {
    01702     QWidget *w;
    01703     QObjectListIt it( *p->children() );
    01704     it.toLast();
    01705     while ( it.current() ) {
    01706       if ( it.current()->isWidgetType() ) {
    01707         w = (QWidget*)it.current();
    01708         if ( w->isVisible() ) {
    01709           if ( w->inherits("KDockWidget") ) list->append( w );
    01710           findChildDockWidget( w, list );
    01711         }
    01712       }
    01713       --it;
    01714     }
    01715   }
    01716   return;
    01717 }
    01718
    01719 void KDockManager::startDrag( KDockWidget* w )
    01720 {
    01721   if(( w->currentDockPos == KDockWidget::DockLeft) || ( w->currentDockPos == KDockWidget::DockRight)
    01722    || ( w->currentDockPos == KDockWidget::DockTop) || ( w->currentDockPos == KDockWidget::DockBottom)) {
    01723     w->prevSideDockPosBeforeDrag = w->currentDockPos;
    01724
    01725     if ( w->parentWidget()->inherits("KDockSplitter") ){
    01726       KDockSplitter* parentSplitterOfDockWidget = (KDockSplitter*)(w->parentWidget());
    01727       w->d->splitPosInPercent = parentSplitterOfDockWidget->separatorPos();
    01728     }
    01729   }
    01730
    01731   curPos = KDockWidget::DockDesktop;
    01732   draging = true;
    01733
    01734   QApplication::setOverrideCursor(QCursor(sizeAllCursor));
    01735 }
    01736
    01737 void KDockManager::dragMove( KDockWidget* dw, QPoint pos )
    01738 {
    01739   QPoint p = dw->mapToGlobal( dw->widget->pos() );
    01740   KDockWidget::DockPosition oldPos = curPos;
    01741
    01742   QSize r = dw->widget->size();
    01743   if ( dw->parentDockTabGroup() ){
    01744     curPos = KDockWidget::DockCenter;
    01745     if ( oldPos != curPos ) {
    01746       d->dragRect.setRect( p.x()+2, p.y()+2, r.width()-4, r.height()-4 );
    01747     }
    01748     return;
    01749   }
    01750
    01751   int w = r.width() / 3;
    01752   int h = r.height() / 3;
    01753
    01754   if ( pos.y() <= h ){
    01755     curPos = KDockWidget::DockTop;
    01756     w = r.width();
    01757   } else
    01758     if ( pos.y() >= 2*h ){
    01759       curPos = KDockWidget::DockBottom;
    01760       p.setY( p.y() + 2*h );
    01761       w = r.width();
    01762     } else
    01763       if ( pos.x() <= w ){
    01764         curPos = KDockWidget::DockLeft;
    01765         h = r.height();
    01766       } else
    01767         if ( pos.x() >= 2*w ){
    01768           curPos = KDockWidget::DockRight;
    01769           p.setX( p.x() + 2*w );
    01770           h = r.height();
    01771         } else
    01772           {
    01773             curPos = KDockWidget::DockCenter;
    01774             p.setX( p.x() + w );
    01775             p.setY( p.y() + h );
    01776           }
    01777
    01778   if ( oldPos != curPos ) {
    01779     d->dragRect.setRect( p.x(), p.y(), w, h );
    01780     drawDragRectangle();
    01781   }
    01782 }
    01783
    01784
    01785 void KDockManager::cancelDrop()
    01786 {
    01787   QApplication::restoreOverrideCursor();
    01788
    01789   delete childDockWidgetList;
    01790   childDockWidgetList = 0L;
    01791
    01792   d->dragRect = QRect();  // cancel drawing
    01793   drawDragRectangle();    // only the old rect will be deleted
    01794 }
    01795
    01796
    01797 void KDockManager::drop()
    01798 {
    01799   d->dragRect = QRect();  // cancel drawing
    01800   drawDragRectangle();    // only the old rect will be deleted
    01801
    01802   QApplication::restoreOverrideCursor();
    01803
    01804   delete childDockWidgetList;
    01805   childDockWidgetList = 0L;
    01806
    01807   if ( dropCancel ) return;
    01808   if ( !currentMoveWidget && ((currentDragWidget->eDocking & (int)KDockWidget::DockDesktop) == 0) ) {
    01809     d->dragRect = QRect();  // cancel drawing
    01810     drawDragRectangle();    // only the old rect will be deleted
    01811     return;
    01812   }
    01813   if ( !currentMoveWidget && !currentDragWidget->parent() ) {
    01814     currentDragWidget->move( QCursor::pos() - d->dragOffset );
    01815   }
    01816   else {
    01817     int splitPos = currentDragWidget->d->splitPosInPercent;
    01818     // do we have to calculate 100%-splitPosInPercent?
    01819     if( (curPos != currentDragWidget->prevSideDockPosBeforeDrag) && (curPos != KDockWidget::DockCenter) && (curPos != KDockWidget::DockDesktop)) {
    01820       switch( currentDragWidget->prevSideDockPosBeforeDrag) {
    01821       case KDockWidget::DockLeft:   if(curPos != KDockWidget::DockTop)    splitPos = 100-splitPos; break;
    01822       case KDockWidget::DockRight:  if(curPos != KDockWidget::DockBottom) splitPos = 100-splitPos; break;
    01823       case KDockWidget::DockTop:    if(curPos != KDockWidget::DockLeft)   splitPos = 100-splitPos; break;
    01824       case KDockWidget::DockBottom: if(curPos != KDockWidget::DockRight)  splitPos = 100-splitPos; break;
    01825       default: break;
    01826       }
    01827     }
    01828     currentDragWidget->manualDock( currentMoveWidget, curPos , splitPos, QCursor::pos() - d->dragOffset );
    01829     currentDragWidget->makeDockVisible();
    01830   }
    01831 }
    01832
    01833
    01834 static QDomElement createStringEntry(QDomDocument &doc, const QString &tagName, const QString &str)
    01835 {
    01836     QDomElement el = doc.createElement(tagName);
    01837
    01838     el.appendChild(doc.createTextNode(str));
    01839     return el;
    01840 }
    01841
    01842
    01843 static QDomElement createBoolEntry(QDomDocument &doc, const QString &tagName, bool b)
    01844 {
    01845     return createStringEntry(doc, tagName, QString::fromLatin1(b? "true" : "false"));
    01846 }
    01847
    01848
    01849 static QDomElement createNumberEntry(QDomDocument &doc, const QString &tagName, int n)
    01850 {
    01851     return createStringEntry(doc, tagName, QString::number(n));
    01852 }
    01853
    01854
    01855 static QDomElement createRectEntry(QDomDocument &doc, const QString &tagName, const QRect &rect)
    01856 {
    01857     QDomElement el = doc.createElement(tagName);
    01858
    01859     QDomElement xel = doc.createElement("x");
    01860     xel.appendChild(doc.createTextNode(QString::number(rect.x())));
    01861     el.appendChild(xel);
    01862     QDomElement yel = doc.createElement("y");
    01863     yel.appendChild(doc.createTextNode(QString::number(rect.y())));
    01864     el.appendChild(yel);
    01865     QDomElement wel = doc.createElement("width");
    01866     wel.appendChild(doc.createTextNode(QString::number(rect.width())));
    01867     el.appendChild(wel);
    01868     QDomElement hel = doc.createElement("height");
    01869     hel.appendChild(doc.createTextNode(QString::number(rect.height())));
    01870     el.appendChild(hel);
    01871
    01872     return el;
    01873 }
    01874
    01875
    01876 static QDomElement createListEntry(QDomDocument &doc, const QString &tagName,
    01877                                    const QString &subTagName, const QStrList &list)
    01878 {
    01879     QDomElement el = doc.createElement(tagName);
    01880
    01881     QStrListIterator it(list);
    01882     for (; it.current(); ++it) {
    01883         QDomElement subel = doc.createElement(subTagName);
    01884         subel.appendChild(doc.createTextNode(QString::fromLatin1(it.current())));
    01885         el.appendChild(subel);
    01886     }
    01887
    01888     return el;
    01889 }
    01890
    01891
    01892 static QString stringEntry(QDomElement &base, const QString &tagName)
    01893 {
    01894     return base.namedItem(tagName).firstChild().toText().data();
    01895 }
    01896
    01897
    01898 static bool boolEntry(QDomElement &base, const QString &tagName)
    01899 {
    01900     return base.namedItem(tagName).firstChild().toText().data() == "true";
    01901 }
    01902
    01903
    01904 static int numberEntry(QDomElement &base, const QString &tagName)
    01905 {
    01906     return stringEntry(base, tagName).toInt();
    01907 }
    01908
    01909
    01910 static QRect rectEntry(QDomElement &base, const QString &tagName)
    01911 {
    01912     QDomElement el = base.namedItem(tagName).toElement();
    01913
    01914     int x = numberEntry(el, "x");
    01915     int y = numberEntry(el, "y");
    01916     int width = numberEntry(el, "width");
    01917     int height = numberEntry(el,  "height");
    01918
    01919     return QRect(x, y, width, height);
    01920 }
    01921
    01922
    01923 static QStrList listEntry(QDomElement &base, const QString &tagName, const QString &subTagName)
    01924 {
    01925     QStrList list;
    01926
    01927     QDomElement subel = base.namedItem(tagName).firstChild().toElement();
    01928     while (!subel.isNull()) {
    01929         if (subel.tagName() == subTagName)
    01930             list.append(subel.firstChild().toText().data().latin1());
    01931         subel = subel.nextSibling().toElement();
    01932     }
    01933
    01934     return list;
    01935 }
    01936
    01937
    01938 void KDockManager::writeConfig(QDomElement &base)
    01939 {
    01940     // First of all, clear the tree under base
    01941     while (!base.firstChild().isNull())
    01942         base.removeChild(base.firstChild());
    01943     QDomDocument doc = base.ownerDocument();
    01944
    01945     QStrList nameList;
    01946     QString mainWidgetStr;
    01947
    01948     // collect widget names
    01949     QStrList nList;
    01950     QObjectListIt it(*childDock);
    01951     KDockWidget *obj1;
    01952     while ( (obj1=(KDockWidget*)it.current()) ) {
    01953         if ( obj1->parent() == main )
    01954             mainWidgetStr = QString::fromLatin1(obj1->name());
    01955         nList.append(obj1->name());
    01956         ++it;
    01957     }
    01958
    01959     nList.first();
    01960     while ( nList.current() ) {
    01961         KDockWidget *obj = getDockWidgetFromName( nList.current() );
    01962         if (obj->isGroup && (nameList.find( obj->firstName.latin1() ) == -1
    01963                              || nameList.find(obj->lastName.latin1()) == -1)) {
    01964             // Skip until children are saved (why?)
    01965             nList.next();
    01966             if ( !nList.current() ) nList.first();
    01967             continue;
    01968         }
    01969
    01970         QDomElement groupEl;
    01971
    01972         if (obj->isGroup) {
    01974             groupEl = doc.createElement("splitGroup");
    01975
    01976             groupEl.appendChild(createStringEntry(doc, "firstName", obj->firstName));
    01977             groupEl.appendChild(createStringEntry(doc, "secondName", obj->lastName));
    01978             groupEl.appendChild(createNumberEntry(doc, "orientation", (int)obj->splitterOrientation));
    01979             groupEl.appendChild(createNumberEntry(doc, "separatorPos", ((KDockSplitter*)obj->widget)->separatorPos()));
    01980         } else if (obj->isTabGroup) {
    01982             groupEl = doc.createElement("tabGroup");
    01983
    01984             QStrList list;
    01985             for ( int i = 0; i < ((KDockTabGroup*)obj->widget)->count(); ++i )
    01986                 list.append( ((KDockTabGroup*)obj->widget)->page( i )->name() );
    01987             groupEl.appendChild(createListEntry(doc, "tabs", "tab", list));
    01988             groupEl.appendChild(createNumberEntry(doc, "currentTab", ((KDockTabGroup*)obj->widget)->currentPageIndex()));
    01989         } else {
    01991             groupEl = doc.createElement("dock");
    01992         }
    01993
    01994         groupEl.appendChild(createStringEntry(doc, "name", QString::fromLatin1(obj->name())));
    01995         groupEl.appendChild(createBoolEntry(doc, "hasParent", obj->parent()));
    01996         if ( !obj->parent() ) {
    01997             groupEl.appendChild(createRectEntry(doc, "geometry", QRect(main->frameGeometry().topLeft(), main->size())));
    01998             groupEl.appendChild(createBoolEntry(doc, "visible", obj->isVisible()));
    01999         }
    02000         if (obj->header && obj->header->inherits("KDockWidgetHeader")) {
    02001             KDockWidgetHeader *h = static_cast<KDockWidgetHeader*>(obj->header);
    02002             groupEl.appendChild(createBoolEntry(doc, "dragEnabled", h->dragEnabled()));
    02003         }
    02004
    02005         base.appendChild(groupEl);
    02006         nameList.append(obj->name());
    02007         nList.remove();
    02008         nList.first();
    02009     }
    02010
    02011     if (main->inherits("KDockMainWindow")) {
    02012         KDockMainWindow *dmain = (KDockMainWindow*)main;
    02013         QString centralWidgetStr = QString(dmain->centralWidget()? dmain->centralWidget()->name() : "");
    02014         base.appendChild(createStringEntry(doc, "centralWidget", centralWidgetStr));
    02015         QString mainDockWidgetStr = QString(dmain->getMainDockWidget()? dmain->getMainDockWidget()->name() : "");
    02016         base.appendChild(createStringEntry(doc, "mainDockWidget", mainDockWidgetStr));
    02017     } else {
    02018         base.appendChild(createStringEntry(doc, "mainWidget", mainWidgetStr));
    02019     }
    02020
    02021     base.appendChild(createRectEntry(doc, "geometry", QRect(main->frameGeometry().topLeft(), main->size())));
    02022 }
    02023
    02024
    02025 void KDockManager::readConfig(QDomElement &base)
    02026 {
    02027     if (base.namedItem("group").isNull()
    02028         && base.namedItem("tabgroup").isNull()
    02029         && base.namedItem("dock").isNull()) {
    02030         activate();
    02031         return;
    02032     }
    02033
    02034     autoCreateDock = new QObjectList();
    02035     autoCreateDock->setAutoDelete( true );
    02036
    02037     bool isMainVisible = main->isVisible();
    02038     main->hide();
    02039
    02040     QObjectListIt it(*childDock);
    02041     KDockWidget *obj1;
    02042     while ( (obj1=(KDockWidget*)it.current()) ) {
    02043         if ( !obj1->isGroup && !obj1->isTabGroup ) {
    02044             if ( obj1->parent() )
    02045                 obj1->undock();
    02046             else
    02047                 obj1->hide();
    02048         }
    02049         ++it;
    02050     }
    02051
    02052     QDomElement childEl = base.firstChild().toElement();
    02053     while (!childEl.isNull() ) {
    02054         KDockWidget *obj = 0;
    02055
    02056         if (childEl.tagName() == "splitGroup") {
    02057             // Read a group
    02058             QString name = stringEntry(childEl, "name");
    02059             QString firstName = stringEntry(childEl, "firstName");
    02060             QString secondName = stringEntry(childEl, "secondName");
    02061             int orientation = numberEntry(childEl, "orientation");
    02062             int separatorPos = numberEntry(childEl, "separatorPos");
    02063
    02064             KDockWidget *first = getDockWidgetFromName(firstName);
    02065             KDockWidget *second = getDockWidgetFromName(secondName);
    02066             if (first && second) {
    02067                 obj = first->manualDock(second,
    02068                                         (orientation == (int)Vertical)? KDockWidget::DockLeft : KDockWidget::DockTop,
    02069                                         separatorPos);
    02070                 if (obj)
    02071                     obj->setName(name.latin1());
    02072             }
    02073         } else if (childEl.tagName() == "tabGroup") {
    02074             // Read a tab group
    02075             QString name = stringEntry(childEl, "name");
    02076             QStrList list = listEntry(childEl, "tabs", "tab");
    02077
    02078             KDockWidget *d1 = getDockWidgetFromName( list.first() );
    02079             list.next();
    02080             KDockWidget *d2 = getDockWidgetFromName( list.current() );
    02081
    02082             KDockWidget *obj = d2->manualDock( d1, KDockWidget::DockCenter );
    02083             if (obj) {
    02084                 KDockTabGroup *tab = (KDockTabGroup*)obj->widget;
    02085                 list.next();
    02086                 while (list.current() && obj) {
    02087                     KDockWidget *tabDock = getDockWidgetFromName(list.current());
    02088                     obj = tabDock->manualDock(d1, KDockWidget::DockCenter);
    02089                     list.next();
    02090                 }
    02091                 if (obj) {
    02092                     obj->setName(name.latin1());
    02093                     tab->showPage(tab->page(numberEntry(childEl, "currentTab")));
    02094                 }
    02095             }
    02096         } else if (childEl.tagName() == "dock") {
    02097             // Read an ordinary dock widget
    02098             obj = getDockWidgetFromName(stringEntry(childEl, "name"));
    02099         }
    02100
    02101         if (!boolEntry(childEl, "hasParent")) {
    02102             QRect r = rectEntry(childEl, "geometry");
    02103             obj = getDockWidgetFromName(stringEntry(childEl, "name"));
    02104             obj->applyToWidget(0);
    02105             obj->setGeometry(r);
    02106             if (boolEntry(childEl, "visible"))
    02107                 obj->QWidget::show();
    02108         }
    02109
    02110         if (obj && obj->header && obj->header->inherits("KDockWidgetHeader")) {
    02111             KDockWidgetHeader *h = static_cast<KDockWidgetHeader*>(obj->header);
    02112             h->setDragEnabled(boolEntry(childEl, "dragEnabled"));
    02113         }
    02114
    02115         childEl = childEl.nextSibling().toElement();
    02116     }
    02117
    02118     if (main->inherits("KDockMainWindow")) {
    02119         KDockMainWindow *dmain = (KDockMainWindow*)main;
    02120
    02121         QString mv = stringEntry(base, "centralWidget");
    02122         if (!mv.isEmpty() && getDockWidgetFromName(mv) ) {
    02123             KDockWidget *mvd  = getDockWidgetFromName(mv);
    02124             mvd->applyToWidget(dmain);
    02125             mvd->show();
    02126             dmain->setCentralWidget(mvd);
    02127         }
    02128         QString md = stringEntry(base, "mainDockWidget");
    02129         if (!md.isEmpty() && getDockWidgetFromName(md)) {
    02130             KDockWidget *mvd  = getDockWidgetFromName(md);
    02131             dmain->setMainDockWidget(mvd);
    02132         }
    02133     } else {
    02134         QString mv = stringEntry(base, "mainWidget");
    02135         if (!mv.isEmpty() && getDockWidgetFromName(mv)) {
    02136             KDockWidget *mvd  = getDockWidgetFromName(mv);
    02137             mvd->applyToWidget(main);
    02138             mvd->show();
    02139         }
    02140     }
    02141
    02142     QRect mr = rectEntry(base, "geometry");
    02143     main->move(mr.topLeft());
    02144     main->resize(mr.size());
    02145     if (isMainVisible)
    02146         main->show();
    02147
    02148     delete autoCreateDock;
    02149     autoCreateDock = 0;
    02150 }
    02151
    02152
    02153 #ifndef NO_KDE2
    02154 void KDockManager::writeConfig( KConfig* c, QString group )
    02155 {
    02156   //debug("BEGIN Write Config");
    02157   if ( !c ) c = KGlobal::config();
    02158   if ( group.isEmpty() ) group = "dock_setting_default";
    02159
    02160   c->setGroup( group );
    02161   c->writeEntry( "Version", DOCK_CONFIG_VERSION );
    02162
    02163   QStringList nameList;
    02164   QStringList findList;
    02165   QObjectListIt it( *childDock );
    02166   KDockWidget * obj;
    02167
    02168   // collect KDockWidget's name
    02169   QStringList nList;
    02170   while ( (obj=(KDockWidget*)it.current()) ) {
    02171     ++it;
    02172     //debug("  +Add subdock %s", obj->name());
    02173     nList.append( obj->name() );
    02174     if ( obj->parent() == main )
    02175       c->writeEntry( "Main:view", obj->name() );
    02176   }
    02177
    02178 //  kdDebug()<<QString("list size: %1").arg(nList.count())<<endl;
    02179   for (QObjectListIt it(d->containerDocks);it.current();++it)
    02180   {
    02181         static_cast<KDockContainer*>(((KDockWidget*)it.current())->widget->qt_cast("KDockContainer"))->prepareSave(nList);
    02182   }
    02183 //  kdDebug()<<QString("new list size: %1").arg(nList.count())<<endl;
    02184
    02185   QStringList::Iterator nListIt=nList.begin();
    02186   while ( nListIt!=nList.end() ){
    02187     //debug("  -Try to save %s", nList.current());
    02188     obj = getDockWidgetFromName( *nListIt );
    02189     QString cname = obj->name();
    02190     if ( obj->header ){
    02191       obj->header->saveConfig( c );
    02192     }
    02193     if (obj->d->isContainer) static_cast<KDockContainer*>(obj->widget->qt_cast("KDockContainer"))->save(c);
    02194 /*************************************************************************************************/
    02195     if ( obj->isGroup ){
    02196       if ( (findList.find( obj->firstName ) != findList.end()) && (findList.find( obj->lastName ) != findList.end() )){
    02197
    02198         c->writeEntry( cname+":type", "GROUP");
    02199         if ( !obj->parent() ){
    02200           c->writeEntry( cname+":parent", "___null___");
    02201           c->writeEntry( cname+":geometry", QRect(obj->frameGeometry().topLeft(), obj->size()) );
    02202           c->writeEntry( cname+":visible", obj->isVisible());
    02203         } else {
    02204           c->writeEntry( cname+":parent", "yes");
    02205         }
    02206         c->writeEntry( cname+":first_name", obj->firstName );
    02207         c->writeEntry( cname+":last_name", obj->lastName );
    02208         c->writeEntry( cname+":orientation", (int)obj->splitterOrientation );
    02209         c->writeEntry( cname+":sepPos", ((KDockSplitter*)obj->widget)->separatorPos() );
    02210
    02211         nameList.append( obj->name() );
    02212         findList.append( obj->name() );
    02213         //debug("  Save %s", nList.current());
    02214         nList.remove(nListIt);
    02215         nListIt=nList.begin(); //nList.first();
    02216       } else {
    02217 /*************************************************************************************************/
    02218         //debug("  Skip %s", nList.current());
    02219         //if ( findList.find( obj->firstName ) == -1 )
    02220         //  debug("  ? Not found %s", obj->firstName);
    02221         //if ( findList.find( obj->lastName ) == -1 )
    02222         //  debug("  ? Not found %s", obj->lastName);
    02223         ++nListIt;
    02224         // if ( !nList.current() ) nList.first();
    02225         if (nListIt==nList.end()) nListIt=nList.begin();
    02226       }
    02227     } else {
    02228 /*************************************************************************************************/
    02229       if ( obj->isTabGroup){
    02230         c->writeEntry( cname+":type", "TAB_GROUP");
    02231         if ( !obj->parent() ){
    02232           c->writeEntry( cname+":parent", "___null___");
    02233           c->writeEntry( cname+":geometry", QRect(obj->frameGeometry().topLeft(), obj->size()) );
    02234           c->writeEntry( cname+":visible", obj->isVisible());
    02235         } else {
    02236           c->writeEntry( cname+":parent", "yes");
    02237         }
    02238         QStrList list;
    02239         for ( int i = 0; i < ((KDockTabGroup*)obj->widget)->count(); ++i )
    02240           list.append( ((KDockTabGroup*)obj->widget)->page( i )->name() );
    02241         c->writeEntry( cname+":tabNames", list );
    02242         c->writeEntry( cname+":curTab", ((KDockTabGroup*)obj->widget)->currentPageIndex() );
    02243
    02244         nameList.append( obj->name() );
    02245         findList.append( obj->name() ); // not realy need !!!
    02246         //debug("  Save %s", nList.current());
    02247         nList.remove(nListIt);
    02248         nListIt=nList.begin();
    02249       } else {
    02250 /*************************************************************************************************/
    02251         if ( !obj->parent() ){
    02252           c->writeEntry( cname+":type", "NULL_DOCK");
    02253           c->writeEntry( cname+":geometry", QRect(obj->frameGeometry().topLeft(), obj->size()) );
    02254           c->writeEntry( cname+":visible", obj->isVisible());
    02255         } else {
    02256           c->writeEntry( cname+":type", "DOCK");
    02257         }
    02258         nameList.append( cname.latin1() );
    02259         //debug("  Save %s", nList.current());
    02260         findList.append( obj->name() );
    02261         nList.remove(nListIt);
    02262         nListIt=nList.begin();
    02263       }
    02264     }
    02265   }
    02266   c->writeEntry( "NameList", nameList );
    02267
    02268   c->writeEntry( "Main:Geometry", QRect(main->frameGeometry().topLeft(), main->size()) );
    02269   c->writeEntry( "Main:visible", main->isVisible()); // curently nou use
    02270
    02271   if ( main->inherits("KDockMainWindow") ){
    02272     KDockMainWindow* dmain = (KDockMainWindow*)main;
    02273     // for KDockMainWindow->setView() in readConfig()
    02274     c->writeEntry( "Main:view", dmain->centralWidget() ? dmain->centralWidget()->name():"" );
    02275     c->writeEntry( "Main:dock", dmain->getMainDockWidget()     ? dmain->getMainDockWidget()->name()    :"" );
    02276   }
    02277
    02278   c->sync();
    02279   //debug("END Write Config");
    02280 }
    02281 #include <qmessagebox.h>
    02282 void KDockManager::readConfig( KConfig* c, QString group )
    02283 {
    02284   if ( !c ) c = KGlobal::config();
    02285   if ( group.isEmpty() ) group = "dock_setting_default";
    02286
    02287   c->setGroup( group );
    02288   QStrList nameList;
    02289   c->readListEntry( "NameList", nameList );
    02290   QString ver = c->readEntry( "Version", "0.0.1" );
    02291   nameList.first();
    02292   if ( !nameList.current() || ver != DOCK_CONFIG_VERSION ){
    02293     activate();
    02294     return;
    02295   }
    02296
    02297   autoCreateDock = new QObjectList();
    02298   autoCreateDock->setAutoDelete( true );
    02299
    02300   bool isMainVisible = main->isVisible();
    02301  // if (isMainVisible)  // CCC
    02302   //QMessageBox::information(0,"","hallo");
    02303 //COMMENTED4TESTING  main->hide();
    02304
    02305   QObjectListIt it( *childDock );
    02306   KDockWidget * obj;
    02307
    02308   while ( (obj=(KDockWidget*)it.current()) ){
    02309     ++it;
    02310     if ( !obj->isGroup && !obj->isTabGroup )
    02311     {
    02312       if ( obj->parent() ) obj->undock(); else obj->hide();
    02313     }
    02314   }
    02315
    02316   nameList.first();
    02317   while ( nameList.current() ){
    02318     QString oname = nameList.current();
    02319     c->setGroup( group );
    02320     QString type = c->readEntry( oname + ":type" );
    02321     obj = 0L;
    02322
    02323     if ( type == "GROUP" ){
    02324       KDockWidget* first = getDockWidgetFromName( c->readEntry( oname + ":first_name" ) );
    02325       KDockWidget* last  = getDockWidgetFromName( c->readEntry( oname + ":last_name"  ) );
    02326       int sepPos = c->readNumEntry( oname + ":sepPos" );
    02327
    02328       Orientation p = (Orientation)c->readNumEntry( oname + ":orientation" );
    02329       if ( first  && last ){
    02330         obj = first->manualDock( last, ( p == Vertical ) ? KDockWidget::DockLeft : KDockWidget::DockTop, sepPos );
    02331         if (obj){
    02332           obj->setName( oname.latin1() );
    02333         }
    02334       }
    02335     }
    02336
    02337     if ( type == "TAB_GROUP" ){
    02338       QStrList list;
    02339       KDockWidget* tabDockGroup = 0L;
    02340       c->readListEntry( oname+":tabNames", list );
    02341       KDockWidget* d1 = getDockWidgetFromName( list.first() );
    02342       list.next();
    02343       KDockWidget* d2 = getDockWidgetFromName( list.current() );
    02344       tabDockGroup = d2->manualDock( d1, KDockWidget::DockCenter );
    02345       if ( tabDockGroup ){
    02346         KDockTabGroup* tab = (KDockTabGroup*)tabDockGroup->widget;
    02347         list.next();
    02348         while ( list.current() && tabDockGroup ){
    02349           KDockWidget* tabDock = getDockWidgetFromName( list.current() );
    02350           tabDockGroup = tabDock->manualDock( d1, KDockWidget::DockCenter );
    02351           list.next();
    02352         }
    02353         if ( tabDockGroup ){
    02354           tabDockGroup->setName( oname.latin1() );
    02355           c->setGroup( group );
    02356           tab->showPage( tab->page( c->readNumEntry( oname+":curTab" ) ) );
    02357         }
    02358       }
    02359       obj = tabDockGroup;
    02360     }
    02361
    02362     if ( type == "NULL_DOCK" || c->readEntry( oname + ":parent") == "___null___" ){
    02363       QRect r = c->readRectEntry( oname + ":geometry" );
    02364       obj = getDockWidgetFromName( oname );
    02365       obj->applyToWidget( 0L );
    02366       obj->setGeometry(r);
    02367
    02368       c->setGroup( group );
    02369       if ( c->readBoolEntry( oname + ":visible" ) ){
    02370         obj->QWidget::show();
    02371       }
    02372     }
    02373
    02374     if ( type == "DOCK"  ){
    02375       obj = getDockWidgetFromName( oname );
    02376     }
    02377
    02378     if (obj && obj->d->isContainer)  static_cast<KDockContainer*>(obj->widget->qt_cast("KDockContainer"))->load(c);
    02379     if ( obj && obj->header){
    02380       obj->header->loadConfig( c );
    02381     }
    02382     nameList.next();
    02383   }
    02384
    02385   if ( main->inherits("KDockMainWindow") ){
    02386     KDockMainWindow* dmain = (KDockMainWindow*)main;
    02387
    02388     c->setGroup( group );
    02389     QString mv = c->readEntry( "Main:view" );
    02390     if ( !mv.isEmpty() && getDockWidgetFromName( mv ) ){
    02391       KDockWidget* mvd  = getDockWidgetFromName( mv );
    02392       mvd->applyToWidget( dmain );
    02393       mvd->show();
    02394       dmain->setView( mvd );
    02395     }
    02396     c->setGroup( group );
    02397     QString md = c->readEntry( "Main:dock" );
    02398     if ( !md.isEmpty() && getDockWidgetFromName( md ) ){
    02399       KDockWidget* mvd  = getDockWidgetFromName( md );
    02400       dmain->setMainDockWidget( mvd );
    02401     }
    02402   } else {
    02403     c->setGroup( group );
    02404     QString mv = c->readEntry( "Main:view" );
    02405     if ( !mv.isEmpty() && getDockWidgetFromName( mv ) ){
    02406       KDockWidget* mvd  = getDockWidgetFromName( mv );
    02407       mvd->applyToWidget( main );
    02408       mvd->show();
    02409     }
    02410
    02411   }
    02412   // delete all autocreate dock
    02413   delete autoCreateDock;
    02414   autoCreateDock = 0L;
    02415
    02416   c->setGroup( group );
    02417   QRect mr = c->readRectEntry("Main:Geometry");
    02418   main->move(mr.topLeft());
    02419   main->resize(mr.size());
    02420   if ( isMainVisible ) main->show();
    02421 }
    02422 #endif
    02423
    02424 KDockWidget* KDockManager::getDockWidgetFromName( const QString& dockName )
    02425 {
    02426   QObjectListIt it( *childDock );
    02427   KDockWidget * obj;
    02428   while ( (obj=(KDockWidget*)it.current()) ) {
    02429     ++it;
    02430     if ( QString(obj->name()) == dockName ) return obj;
    02431   }
    02432
    02433   KDockWidget* autoCreate = 0L;
    02434   if ( autoCreateDock ){
    02435     autoCreate = new KDockWidget( this, dockName.latin1(), QPixmap("") );
    02436     autoCreateDock->append( autoCreate );
    02437   }
    02438   return autoCreate;
    02439 }
    02440 void KDockManager::setSplitterOpaqueResize(bool b)
    02441 {
    02442   d->splitterOpaqueResize = b;
    02443 }
    02444
    02445 bool KDockManager::splitterOpaqueResize() const
    02446 {
    02447   return d->splitterOpaqueResize;
    02448 }
    02449
    02450 void KDockManager::setSplitterKeepSize(bool b)
    02451 {
    02452   d->splitterKeepSize = b;
    02453 }
    02454
    02455 bool KDockManager::splitterKeepSize() const
    02456 {
    02457   return d->splitterKeepSize;
    02458 }
    02459
    02460 void KDockManager::setSplitterHighResolution(bool b)
    02461 {
    02462   d->splitterHighResolution = b;
    02463 }
    02464
    02465 bool KDockManager::splitterHighResolution() const
    02466 {
    02467   return d->splitterHighResolution;
    02468 }
    02469
    02470 void KDockManager::slotMenuPopup()
    02471 {
    02472   menu->clear();
    02473   menuData->clear();
    02474
    02475   QObjectListIt it( *childDock );
    02476   KDockWidget * obj;
    02477   int numerator = 0;
    02478   while ( (obj=(KDockWidget*)it.current()) ) {
    02479     ++it;
    02480     if ( obj->mayBeHide() )
    02481     {
    02482       menu->insertItem( obj->icon() ? *(obj->icon()) : QPixmap(), i18n("Hide %1").arg(obj->caption()), numerator++ );
    02483       menuData->append( new MenuDockData( obj, true ) );
    02484     }
    02485
    02486     if ( obj->mayBeShow() )
    02487     {
    02488       menu->insertItem( obj->icon() ? *(obj->icon()) : QPixmap(), i18n("Show %1").arg(obj->caption()), numerator++ );
    02489       menuData->append( new MenuDockData( obj, false ) );
    02490     }
    02491   }
    02492 }
    02493
    02494 void KDockManager::slotMenuActivated( int id )
    02495 {
    02496   MenuDockData* data = menuData->at( id );
    02497   data->dock->changeHideShowState();
    02498 }
    02499
    02500 KDockWidget* KDockManager::findWidgetParentDock( QWidget* w ) const
    02501 {
    02502   QObjectListIt it( *childDock );
    02503   KDockWidget * dock;
    02504   KDockWidget * found = 0L;
    02505
    02506   while ( (dock=(KDockWidget*)it.current()) ) {
    02507     ++it;
    02508     if ( dock->widget == w ){ found  = dock; break; }
    02509   }
    02510   return found;
    02511 }
    02512
    02513 void KDockManager::drawDragRectangle()
    02514 {
    02515   if (d->oldDragRect == d->dragRect)
    02516     return;
    02517
    02518   int i;
    02519   QRect oldAndNewDragRect[2];
    02520   oldAndNewDragRect[0] = d->oldDragRect;
    02521   oldAndNewDragRect[1] = d->dragRect;
    02522
    02523   // 2 calls, one for the old and one for the new drag rectangle
    02524   for (i = 0; i <= 1; i++) {
    02525     if (oldAndNewDragRect[i].isEmpty())
    02526       continue;
    02527
    02528     KDockWidget* pDockWdgAtRect = (KDockWidget*) QApplication::widgetAt( oldAndNewDragRect[i].topLeft(), true );
    02529     if (!pDockWdgAtRect)
    02530       continue;
    02531
    02532     bool isOverMainWdg = false;
    02533     bool unclipped;
    02534     KDockMainWindow* pMain = 0L;
    02535     KDockWidget* pTLDockWdg = 0L;
    02536     QWidget* topWdg;
    02537     if (pDockWdgAtRect->topLevelWidget() == main) {
    02538       isOverMainWdg = true;
    02539       topWdg = pMain = (KDockMainWindow*) main;
    02540       unclipped = pMain->testWFlags( WPaintUnclipped );
    02541       pMain->setWFlags( WPaintUnclipped );
    02542     }
    02543     else {
    02544       topWdg = pTLDockWdg = (KDockWidget*) pDockWdgAtRect->topLevelWidget();
    02545       unclipped = pTLDockWdg->testWFlags( WPaintUnclipped );
    02546       pTLDockWdg->setWFlags( WPaintUnclipped );
    02547     }
    02548
    02549     // draw the rectangle unclipped over the main dock window
    02550     QPainter p;
    02551     p.begin( topWdg );
    02552       if ( !unclipped ) {
    02553         if (isOverMainWdg)
    02554           pMain->clearWFlags(WPaintUnclipped);
    02555         else
    02556           pTLDockWdg->clearWFlags(WPaintUnclipped);
    02557       }
    02558       // draw the rectangle
    02559       p.setRasterOp(Qt::NotXorROP);
    02560       QRect r = oldAndNewDragRect[i];
    02561       r.moveTopLeft( r.topLeft() - topWdg->mapToGlobal(QPoint(0,0)) );
    02562       p.drawRect(r.x(), r.y(), r.width(), r.height());
    02563     p.end();
    02564   }
    02565
    02566   // memorize the current rectangle for later removing
    02567   d->oldDragRect = d->dragRect;
    02568 }
    02569
    02570
    02571
    02572 KDockArea::KDockArea( QWidget* parent, const char *name)
    02573 :QWidget( parent, name)
    02574 {
    02575   QString new_name = QString(name) + QString("_DockManager");
    02576   dockManager = new KDockManager( this, new_name.latin1() );
    02577   mainDockWidget = 0L;
    02578 }
    02579
    02580 KDockArea::~KDockArea()
    02581 {
    02582         delete dockManager;
    02583 }
    02584
    02585 KDockWidget* KDockArea::createDockWidget( const QString& name, const QPixmap &pixmap, QWidget* parent, const QString& strCaption, const QString& strTabPageLabel)
    02586 {
    02587   return new KDockWidget( dockManager, name.latin1(), pixmap, parent, strCaption, strTabPageLabel );
    02588 }
    02589
    02590 void KDockArea::makeDockVisible( KDockWidget* dock )
    02591 {
    02592   if ( dock != 0L)
    02593     dock->makeDockVisible();
    02594 }
    02595
    02596 void KDockArea::makeDockInvisible( KDockWidget* dock )
    02597 {
    02598   if ( dock != 0L)
    02599     dock->undock();
    02600 }
    02601
    02602 void KDockArea::makeWidgetDockVisible( QWidget* widget )
    02603 {
    02604   makeDockVisible( dockManager->findWidgetParentDock(widget) );
    02605 }
    02606
    02607 void KDockArea::writeDockConfig(QDomElement &base)
    02608 {
    02609   dockManager->writeConfig(base);
    02610 }
    02611
    02612 void KDockArea::readDockConfig(QDomElement &base)
    02613 {
    02614   dockManager->readConfig(base);
    02615 }
    02616
    02617 void KDockArea::slotDockWidgetUndocked()
    02618 {
    02619   QObject* pSender = (QObject*) sender();
    02620   if (!pSender->inherits("KDockWidget")) return;
    02621   KDockWidget* pDW = (KDockWidget*) pSender;
    02622   emit dockWidgetHasUndocked( pDW);
    02623 }
    02624
    02625 void KDockArea::resizeEvent(QResizeEvent *rsize)
    02626 {
    02627   QWidget::resizeEvent(rsize);
    02628   if (children()){
    02629 #ifndef NO_KDE2
    02630 //    kdDebug()<<"KDockArea::resize"<<endl;
    02631 #endif
    02632     QObjectList *list=queryList("QWidget",0,false);
    02633
    02634     QObjectListIt it( *list ); // iterate over the buttons
    02635     QObject *obj;
    02636
    02637     while ( (obj = it.current()) != 0 ) {
    02638         // for each found object...
    02639         ((QWidget*)obj)->setGeometry(QRect(QPoint(0,0),size()));
    02640         break;
    02641     }
    02642     delete list;
    02643 #if 0
    02644     KDockSplitter *split;
    02645 //    for (unsigned int i=0;i<children()->count();i++)
    02646     {
    02647 //      QPtrList<QObject> list(children());
    02648 //       QObject *obj=((QPtrList<QObject*>)children())->at(i);
    02649         QObject *obj=children()->getFirst();
    02650        if (split=dynamic_cast<KDockSplitter*>(obj))
    02651        {
    02652           split->setGeometry( QRect(QPoint(0,0), size() ));
    02653 //        break;
    02654        }
    02655     }
    02656 #endif
    02657    }
    02658 }
    02659
    02660 #ifndef NO_KDE2
    02661 void KDockArea::writeDockConfig( KConfig* c, QString group )
    02662 {
    02663   dockManager->writeConfig( c, group );
    02664 }
    02665
    02666 void KDockArea::readDockConfig( KConfig* c, QString group )
    02667 {
    02668   dockManager->readConfig( c, group );
    02669 }
    02670
    02671 void KDockArea::setMainDockWidget( KDockWidget* mdw )
    02672 {
    02673   if ( mainDockWidget == mdw ) return;
    02674   mainDockWidget = mdw;
    02675   mdw->applyToWidget(this);
    02676 }
    02677 #endif
    02678
    02679
    02680
    02681 // KDOCKCONTAINER - AN ABSTRACTION OF THE KDOCKTABWIDGET
    02682 KDockContainer::KDockContainer(){m_childrenListBegin=0; m_childrenListEnd=0;}
    02683 KDockContainer::~KDockContainer(){
    02684
    02685         if (m_childrenListBegin!=0)
    02686         {
    02687                 struct ListItem *tmp=m_childrenListBegin;
    02688                 while (tmp)
    02689                 {
    02690                         struct ListItem *tmp2=tmp->next;
    02691                         delete tmp->data;
    02692                         delete tmp;
    02693                         tmp=tmp2;
    02694                 }
    02695                 m_childrenListBegin=0;
    02696                 m_childrenListEnd=0;
    02697         }
    02698
    02699 }
    02700
    02701 KDockWidget *KDockContainer::parentDockWidget(){return 0;}
    02702 void KDockContainer::insertWidget (KDockWidget *dw, QPixmap, const QString &, int &)
    02703         {
    02704                 struct ListItem *it=new struct ListItem;
    02705                 it->data=strdup(dw->name());
    02706                 it->next=0;
    02707
    02708                 if (m_childrenListEnd)
    02709                 {
    02710                         m_childrenListEnd->next=it;
    02711                         it->prev=m_childrenListEnd;
    02712                         m_childrenListEnd=it;
    02713                 }
    02714                 else
    02715                 {
    02716                         it->prev=0;
    02717                         m_childrenListEnd=it;
    02718                         m_childrenListBegin=it;
    02719                 }
    02720         }
    02721 void KDockContainer::removeWidget (KDockWidget *dw){
    02722         for (struct ListItem *tmp=m_childrenListBegin;tmp;tmp=tmp->next)
    02723         {
    02724                 if (!strcmp(tmp->data,dw->name()))
    02725                 {
    02726                         free(tmp->data);
    02727                         if (tmp->next) tmp->next->prev=tmp->prev;
    02728                         if (tmp->prev) tmp->prev->next=tmp->next;
    02729                         if (tmp==m_childrenListBegin) m_childrenListBegin=tmp->next;
    02730                         if (tmp==m_childrenListEnd) m_childrenListEnd=tmp->prev;
    02731                         delete tmp;
    02732                         break;
    02733                 }
    02734         }
    02735 }
    02736
    02737 //m_children.remove(dw->name());}
    02738 void KDockContainer::undockWidget (KDockWidget *){;}
    02739 void KDockContainer::setToolTip(KDockWidget *, QString &){;}
    02740 void KDockContainer::load (KConfig*){;}
    02741 void KDockContainer::save (KConfig*){;}
    02742 void KDockContainer::prepareSave(QStringList &names)
    02743 {
    02744
    02745         for (struct ListItem *tmp=m_childrenListBegin;tmp; tmp=tmp->next)
    02746                 names.remove(tmp->data);
    02747 //      for (uint i=0;i<m_children.count();i++)
    02748 //      {
    02749 //              names.remove(m_children.at(i));
    02750 //      }
    02751 }
    02752
    02753 void KDockWidgetAbstractHeader::virtual_hook( int, void* )
    02754 { /*BASE::virtual_hook( id, data );*/ }
    02755
    02756 void KDockWidgetAbstractHeaderDrag::virtual_hook( int, void* )
    02757 { /*BASE::virtual_hook( id, data );*/ }
    02758
    02759 void KDockWidgetHeaderDrag::virtual_hook( int id, void* data )
    02760 { KDockWidgetAbstractHeaderDrag::virtual_hook( id, data ); }
    02761
    02762 void KDockWidgetHeader::virtual_hook( int id, void* data )
    02763 { KDockWidgetAbstractHeader::virtual_hook( id, data ); }
    02764
    02765 void KDockTabGroup::virtual_hook( int, void* )
    02766 { /*BASE::virtual_hook( id, data );*/ }
    02767
    02768 void KDockWidget::virtual_hook( int, void* )
    02769 { /*BASE::virtual_hook( id, data );*/ }
    02770
    02771 void KDockManager::virtual_hook( int, void* )
    02772 { /*BASE::virtual_hook( id, data );*/ }
    02773
    02774 void KDockMainWindow::virtual_hook( int id, void* data )
    02775 { KMainWindow::virtual_hook( id, data ); }
    02776
    02777 void KDockArea::virtual_hook( int, void* )
    02778 { /*KMainWindow::virtual_hook( id, data );*/ }
    02779
    02780
    02781 #ifndef NO_INCLUDE_MOCFILES // for Qt-only projects, because tmake doesn't take this name
    02782 #include "kdockwidget.moc"
    02783 #endif

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:56:36 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001