• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDE3Support

k3dockwidget.cpp

Go to the documentation of this file.
00001 
00002 /* This file is part of the KDE libraries
00003    Copyright (C) 2000 Max Judin <novaprint@mtu-net.ru>
00004    Copyright (C) 2002,2003 Joseph Wenninger <jowenn@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 #include "k3dockwidget.h"
00021 #include "k3dockwidget_p.h"
00022 #include "k3dockwidget_private.h"
00023 
00024 #include <QtGui/QApplication>
00025 #include <QtGui/QLayout>
00026 #include <QtGui/QPainter>
00027 #include <Qt3Support/Q3StrIList>
00028 #include <QtGui/QCursor>
00029 #include <QtGui/QWidget>
00030 #include <QtGui/QTabWidget>
00031 
00032 #include <QtGui/QStyle>
00033 #include <QMouseEvent>
00034 #include <QObject>
00035 #include <QStylePainter>
00036 #include <QStyleOption>
00037 
00038 #ifndef NO_KDE2
00039 #include <kconfiggroup.h>
00040 #include <kglobal.h>
00041 #include <klocale.h>
00042 #include <ktoolbar.h>
00043 #include <k3popupmenu.h>
00044 #include <kwindowsystem.h>
00045 #include <kdebug.h>
00046 #include <kglobalsettings.h>
00047 
00048 #include <config.h>
00049 #ifdef Q_WS_X11
00050 #include <X11/X.h>
00051 #include <X11/Xlib.h>
00052 #include <qx11info_x11.h>
00053 #endif
00054 #else
00055 #include <q3toolbar.h>
00056 #include <q3popupmenu.h>
00057 #endif
00058 
00059 #include <stdlib.h>
00060 
00061 #undef BORDERLESS_WINDOWS
00062 
00063 #define DOCK_CONFIG_VERSION "0.0.5"
00064 
00065 static const char* const dockback_xpm[]={
00066 "6 6 2 1",
00067 "# c black",
00068 ". c None",
00069 "......",
00070 ".#....",
00071 "..#..#",
00072 "...#.#",
00073 "....##",
00074 "..####"};
00075 
00076 static const char* const todesktop_xpm[]={
00077 "5 5 2 1",
00078 "# c black",
00079 ". c None",
00080 "####.",
00081 "##...",
00082 "#.#..",
00083 "#..#.",
00084 "....#"};
00085 
00086 static const char* const not_close_xpm[]={
00087 "5 5 2 1",
00088 "# c black",
00089 ". c None",
00090 "#####",
00091 "#...#",
00092 "#...#",
00093 "#...#",
00094 "#####"};
00095 
00105 K3DockMainWindow::K3DockMainWindow( QWidget* parent, const char *name, Qt::WFlags f)
00106     : KXmlGuiWindow( parent, f )
00107 {
00108     setObjectName( name );
00109     QString new_name = QString(name) + QString("_DockManager");
00110     dockManager = new K3DockManager( this, new_name.toLatin1().constData() );
00111     mainDockWidget = 0L;
00112     setAttribute( Qt::WA_DeleteOnClose );
00113 }
00114 
00115 K3DockMainWindow::~K3DockMainWindow()
00116 {
00117     delete dockManager;
00118 }
00119 
00120 K3DockManager* K3DockMainWindow::manager() const
00121 {
00122     return dockManager;
00123 }
00124 
00125 void K3DockMainWindow::setMainDockWidget( K3DockWidget* mdw )
00126 {
00127   if ( mainDockWidget == mdw ) return;
00128   mainDockWidget = mdw;
00129   dockManager->setMainDockWidget2(mdw);
00130 }
00131 
00132 K3DockWidget* K3DockMainWindow::getMainDockWidget() const
00133 {
00134     return mainDockWidget;
00135 }
00136 
00137 void K3DockMainWindow::setView( QWidget *view )
00138 {
00139   if ( view->isA("K3DockWidget") ){
00140     if ( view->parent() != this ) ((K3DockWidget*)view)->applyToWidget( this );
00141   }
00142 
00143 #ifndef NO_KDE2
00144   KXmlGuiWindow::setCentralWidget(view);
00145 #else
00146   Q3MainWindow::setCentralWidget(view);
00147 #endif
00148 }
00149 
00150 K3DockWidget* K3DockMainWindow::createDockWidget( const QString& name, const QPixmap &pixmap, QWidget* parent, const QString& strCaption, const QString& strTabPageLabel)
00151 {
00152   return new K3DockWidget( dockManager, name.toLatin1().constData(), pixmap, parent, strCaption, strTabPageLabel );
00153 }
00154 
00155 void K3DockMainWindow::activateDock()
00156 {
00157     dockManager->activate();
00158 }
00159 
00160 Q3PopupMenu* K3DockMainWindow::dockHideShowMenu() const
00161 {
00162     return dockManager->dockHideShowMenu();
00163 }
00164 
00165 void K3DockMainWindow::makeDockVisible( K3DockWidget* dock )
00166 {
00167   if ( dock )
00168     dock->makeDockVisible();
00169 }
00170 
00171 void K3DockMainWindow::makeDockInvisible( K3DockWidget* dock )
00172 {
00173   if ( dock )
00174     dock->undock();
00175 }
00176 
00177 void K3DockMainWindow::makeWidgetDockVisible( QWidget* widget )
00178 {
00179   makeDockVisible( dockManager->findWidgetParentDock(widget) );
00180 }
00181 
00182 void K3DockMainWindow::writeDockConfig(QDomElement &base)
00183 {
00184   dockManager->writeConfig(base);
00185 }
00186 
00187 void K3DockMainWindow::readDockConfig(QDomElement &base)
00188 {
00189   dockManager->readConfig(base);
00190 }
00191 
00192 #ifndef NO_KDE2
00193 void K3DockMainWindow::writeDockConfig( KConfig* c, const QString &group )
00194 {
00195   dockManager->writeConfig( c, group );
00196 }
00197 
00198 void K3DockMainWindow::readDockConfig( KConfig* c, const QString &group )
00199 {
00200   dockManager->readConfig( c, group );
00201 }
00202 #endif
00203 
00204 void K3DockMainWindow::slotDockWidgetUndocked()
00205 {
00206   QObject* pSender = (QObject*) sender();
00207   if (!pSender->inherits("K3DockWidget")) return;
00208   K3DockWidget* pDW = (K3DockWidget*) pSender;
00209   emit dockWidgetHasUndocked( pDW);
00210 }
00211 
00212 /*************************************************************************/
00213 K3DockWidgetAbstractHeaderDrag::K3DockWidgetAbstractHeaderDrag( K3DockWidgetAbstractHeader* parent, K3DockWidget* dock, const char* name )
00214 :QFrame( parent, name )
00215 {
00216   dw = dock;
00217   installEventFilter( dock->dockManager() );
00218 }
00219 
00220 K3DockWidgetAbstractHeaderDrag::~K3DockWidgetAbstractHeaderDrag()
00221 {
00222 }
00223 
00224 K3DockWidget* K3DockWidgetAbstractHeaderDrag::dockWidget() const
00225 {
00226     return dw;
00227 }
00228 /*************************************************************************/
00229 K3DockWidgetHeaderDrag::K3DockWidgetHeaderDrag( K3DockWidgetAbstractHeader* parent, K3DockWidget* dock, const char* name )
00230 :K3DockWidgetAbstractHeaderDrag( parent, dock, name )
00231 {
00232 }
00233 
00234 K3DockWidgetHeaderDrag::~K3DockWidgetHeaderDrag()
00235 {
00236 }
00237 
00238 void K3DockWidgetHeaderDrag::paintEvent( QPaintEvent* )
00239 {
00240   QStylePainter paint;
00241 
00242   paint.begin( this );
00243   QStyleOption qso;
00244   qso.initFrom( this );
00245   paint.drawPrimitive( QStyle::PE_IndicatorToolBarHandle, qso );
00246 
00247   paint.end();
00248 }
00249 /*************************************************************************/
00250 K3DockWidgetAbstractHeader::K3DockWidgetAbstractHeader( K3DockWidget* parent, const char* name )
00251 :QFrame( parent, name )
00252 {
00253 }
00254 /*************************************************************************/
00255 K3DockWidgetHeader::K3DockWidgetHeader( K3DockWidget* parent, const char* name )
00256 :K3DockWidgetAbstractHeader( parent, name )
00257 {
00258 #ifdef BORDERLESS_WINDOWS
00259   setCursor(QCursor(Qt::ArrowCursor));
00260 #endif
00261   d = new K3DockWidgetHeaderPrivate( this );
00262 
00263   layout = new QHBoxLayout( this );
00264   layout->setSizeConstraint( QLayout::Minimum );
00265 
00266   drag = new K3DockWidgetHeaderDrag( this, parent );
00267 
00268   // Auxillary pixmap (to create the dock buttons)
00269   QPixmap auxPix;
00270 
00271   closeButton = new K3DockButton_Private( this, "DockCloseButton" );
00272   closeButton->setToolTip(  i18n("Close") );
00273   auxPix = style()->standardPixmap( QStyle::SP_DockWidgetCloseButton );
00274   closeButton->setIcon( QIcon( auxPix ) );
00275   closeButton->setFixedSize( auxPix.size() );
00276   connect( closeButton, SIGNAL(clicked()), parent, SIGNAL(headerCloseButtonClicked()));
00277   connect( closeButton, SIGNAL(clicked()), parent, SLOT(undock()));
00278 
00279   stayButton = new K3DockButton_Private( this, "DockStayButton" );
00280   stayButton->setToolTip( i18nc("Freeze the window geometry", "Freeze") );
00281   stayButton->setCheckable( true );
00282   auxPix = QPixmap( not_close_xpm );
00283   stayButton->setIcon( QIcon( auxPix ) );
00284   stayButton->setFixedSize( auxPix.size() );
00285   connect( stayButton, SIGNAL(clicked()), this, SLOT(slotStayClicked()));
00286 
00287   dockbackButton = new K3DockButton_Private( this, "DockbackButton" );
00288   dockbackButton->setToolTip( i18nc("Dock this window", "Dock") );
00289   auxPix = QPixmap( dockback_xpm );
00290   dockbackButton->setIcon( QIcon( auxPix ) );
00291   dockbackButton->setFixedSize( auxPix.size() );
00292   connect( dockbackButton, SIGNAL(clicked()), parent, SIGNAL(headerDockbackButtonClicked()));
00293   connect( dockbackButton, SIGNAL(clicked()), parent, SLOT(dockBack()));
00294 
00295   d->toDesktopButton = new K3DockButton_Private( this, "ToDesktopButton" );
00296   d->toDesktopButton->setToolTip( i18n("Detach") );
00297   auxPix = QPixmap( todesktop_xpm );
00298   d->toDesktopButton->setIcon( QIcon( auxPix ) );
00299   d->toDesktopButton->setFixedSize( auxPix.size() );
00300   connect( d->toDesktopButton, SIGNAL(clicked()), parent, SLOT(toDesktop()));
00301   stayButton->hide();
00302 
00303   d->dummy = new QWidget( this );
00304   d->dummy->setFixedSize( 1, closeButton->height() );
00305 
00306 
00307   layout->addWidget( drag );
00308   layout->addWidget( dockbackButton );
00309   layout->addWidget( d->toDesktopButton );
00310   layout->addWidget( d->dummy);
00311   layout->addWidget( stayButton );
00312   layout->addWidget( closeButton );
00313   layout->activate();
00314   d->dummy->hide();
00315 #if 1
00316   drag->setFixedHeight( closeButton->height() );
00317 #else
00318   drag->setFixedHeight( layout->minimumSize().height() );
00319 #endif
00320 }
00321 
00322 K3DockWidgetHeader::~K3DockWidgetHeader()
00323 {
00324 }
00325 
00326 void K3DockWidgetHeader::setTopLevel( bool isTopLevel )
00327 {
00328   d->topLevel = isTopLevel;
00329   if ( isTopLevel ){
00330     K3DockWidget* par = (K3DockWidget*)parent();
00331     if( par && par->isDockBackPossible() )
00332         dockbackButton->show();
00333     else
00334         dockbackButton->hide();
00335 
00336     stayButton->hide();
00337     closeButton->hide();
00338     d->toDesktopButton->hide();
00339     drag->setEnabled( true );
00340   } else {
00341     dockbackButton->hide();
00342     stayButton->hide();
00343     if (!d->forceCloseButtonHidden) closeButton->show();
00344     if( d->showToDesktopButton )
00345       d->toDesktopButton->show();
00346   }
00347   layout->activate();
00348 
00349    bool dontShowDummy=drag->isVisibleTo(this) || dockbackButton->isVisibleTo(this) ||
00350         d->toDesktopButton->isVisibleTo(this) || stayButton->isVisibleTo(this) ||
00351         closeButton->isVisibleTo(this);
00352    for (Q3PtrListIterator<K3DockButton_Private> it( d->btns );it.current();++it) {
00353         dontShowDummy=dontShowDummy || (it.current()->isVisibleTo(this));
00354    }
00355    if (dontShowDummy) d->dummy->hide(); else d->dummy->show();
00356 
00357   updateGeometry();
00358 }
00359 
00360 void K3DockWidgetHeader::forceCloseButtonHidden(bool hidden) {
00361   d->forceCloseButtonHidden=hidden;
00362   if (hidden) closeButton->hide();
00363   else closeButton->show();
00364 }
00365 
00366 K3DockWidgetHeaderDrag *K3DockWidgetHeader::dragPanel() {
00367     return drag;
00368 }
00369 
00370 void K3DockWidgetHeader::setDragPanel( K3DockWidgetHeaderDrag* nd )
00371 {
00372   if ( !nd ) return;
00373 
00374   delete layout;
00375   layout = new QHBoxLayout( this );
00376   layout->setSizeConstraint( QLayout::Minimum );
00377 
00378   delete drag;
00379   drag = nd;
00380   if (drag->parentWidget()!=this) {
00381     drag->setParent(this);
00382         drag->move(0,0);
00383   }
00384 
00385 
00386   layout->addWidget( drag );
00387   layout->addWidget( dockbackButton );
00388   layout->addWidget( d->dummy );
00389   layout->addWidget( d->toDesktopButton );
00390   layout->addWidget( stayButton );
00391   bool dontShowDummy=drag->isVisibleTo(this) || dockbackButton->isVisibleTo(this) ||
00392     d->toDesktopButton->isVisibleTo(this) || stayButton->isVisibleTo(this) ||
00393     closeButton->isVisibleTo(this);
00394   for (Q3PtrListIterator<K3DockButton_Private> it( d->btns );it.current();++it) {
00395       layout->addWidget(it.current());
00396     dontShowDummy=dontShowDummy || (it.current()->isVisibleTo(this));
00397   }
00398   if (dontShowDummy) d->dummy->hide(); else d->dummy->show();
00399   layout->addWidget( closeButton );
00400   layout->activate();
00401   kDebug(282)<<"KdockWidgetHeader::setDragPanel:minimum height="<<layout->minimumSize().height();
00402   //FIXME somebody left this here, but we don't know what the hell it's for.
00403   drag->setFixedHeight( closeButton->height()); // /*layout->minimumS*/sizeHint().height() );
00404 }
00405 
00406 void K3DockWidgetHeader::addButton(K3DockButton_Private* btn) {
00407     if (!btn) return;
00408 
00409     if (btn->parentWidget()!=this) {
00410         btn->setParent(this);
00411     }
00412     btn->setFixedSize( closeButton->size() );
00413     if (!d->btns.containsRef(btn)) d->btns.append(btn);
00414 
00415     btn->show();
00416 
00417     delete layout;
00418     layout = new QHBoxLayout( this );
00419     layout->setSizeConstraint( QLayout::Minimum );
00420 
00421     layout->addWidget( drag );
00422     layout->addWidget( dockbackButton );
00423     layout->addWidget( d->toDesktopButton );
00424     layout->addWidget( d->dummy);
00425     layout->addWidget( stayButton );
00426      bool dontShowDummy=drag->isVisibleTo(this) || dockbackButton->isVisibleTo(this) ||
00427             d->toDesktopButton->isVisibleTo(this) || stayButton->isVisibleTo(this) ||
00428             closeButton->isVisibleTo(this);
00429      for (Q3PtrListIterator<K3DockButton_Private> it( d->btns );it.current();++it) {
00430             layout->addWidget(it.current());
00431         dontShowDummy=dontShowDummy || (it.current()->isVisibleTo(this));
00432     }
00433     if (dontShowDummy) d->dummy->hide(); else d->dummy->show();
00434     layout->addWidget( closeButton );
00435     layout->activate();
00436     drag->setFixedHeight( layout->minimumSize().height() );
00437 }
00438 
00439 void K3DockWidgetHeader::removeButton(K3DockButton_Private* btn) {
00440     if (btn->parentWidget()==this) {
00441         if (d->btns.containsRef(btn)) d->btns.removeRef(btn);
00442         delete btn;
00443     }
00444 }
00445 
00446 
00447 void K3DockWidgetHeader::slotStayClicked()
00448 {
00449   setDragEnabled(!stayButton->isChecked());
00450 }
00451 
00452 bool K3DockWidgetHeader::dragEnabled() const
00453 {
00454   return drag->isEnabled();
00455 }
00456 
00457 void K3DockWidgetHeader::showUndockButton(bool show)
00458 {
00459   kDebug(282)<<"K3DockWidgetHeader::showUndockButton("<<show<<")";
00460   if( d->showToDesktopButton == show )
00461     return;
00462 
00463   d->showToDesktopButton = show;
00464   if( !show || d->topLevel )
00465     d->toDesktopButton->hide( );
00466   else
00467     d->toDesktopButton->show( );
00468 }
00469 
00470 void K3DockWidgetHeader::setDragEnabled(bool b)
00471 {
00472   stayButton->setChecked(!b);
00473   closeButton->setEnabled(b);
00474   drag->setEnabled(b);
00475 }
00476 
00477 #ifndef NO_KDE2
00478 void K3DockWidgetHeader::saveConfig( KConfigGroup* cg )
00479 {
00480   cg->writeEntry( QString("%1:stayButton").arg(parent()->name()), stayButton->isChecked() );
00481 }
00482 
00483 void K3DockWidgetHeader::loadConfig( KConfigGroup* cg )
00484 {
00485   setDragEnabled( !cg->readEntry( QString("%1:stayButton").arg(parent()->name()), false ) );
00486 }
00487 #endif
00488 
00489 /*************************************************************************/
00490 
00491 class K3DockManager::K3DockManagerPrivate
00492 {
00493 public:
00497   QRect dragRect;
00498 
00502   QRect oldDragRect;
00503 
00507   bool readyToDrag;
00508 
00512   QPoint dragOffset;
00513 
00517   bool splitterOpaqueResize;
00518   bool splitterKeepSize;
00519   bool splitterHighResolution;
00520 
00521   QPointer<K3DockWidget> mainDockWidget;
00522 
00523   QList<QObject*> containerDocks;
00524 
00525   QPointer<K3DockWidget> leftContainer;
00526   QPointer<K3DockWidget> topContainer;
00527   QPointer<K3DockWidget> rightContainer;
00528   QPointer<K3DockWidget> bottomContainer;
00529   int m_readDockConfigMode;
00530 };
00531 
00532 
00533 /*************************************************************************/
00534 K3DockWidget::K3DockWidget( K3DockManager* dockManager, const char* name, const QPixmap &pixmap, QWidget* parent, const QString& strCaption, const QString& strTabPageLabel, Qt::WFlags f)
00535 #ifdef BORDERLESS_WINDOWS
00536 : QWidget( parent, name, f )//| WType_Dialog | WStyle_Customize | WStyle_NoBorder )
00537 #else
00538 : QWidget( parent, name, f )
00539 #endif
00540   ,formerBrotherDockWidget(0L)
00541   ,currentDockPos(DockNone)
00542   ,formerDockPos(DockNone)
00543   ,widget(0L)
00544   ,pix(new QPixmap(pixmap))
00545   ,prevSideDockPosBeforeDrag(DockNone)
00546   ,isGroup(false)
00547 {
00548   d = new K3DockWidgetPrivate();  // create private data
00549 
00550   d->_parent = parent;
00551 
00552   layout = new QVBoxLayout( this );
00553   layout->setSizeConstraint( QLayout::Minimum );
00554 
00555   manager = dockManager;
00556   manager->childDock->append( this );
00557   installEventFilter( manager );
00558 
00559   eDocking = DockFullDocking;
00560   sDocking = DockFullSite;
00561 
00562   header = 0L;
00563   setHeader( new K3DockWidgetHeader( this, "AutoCreatedDockHeader" ) );
00564 
00565   if( strCaption.isNull() )
00566     setWindowTitle( name );
00567   else
00568     setWindowTitle( strCaption);
00569 
00570   if( strTabPageLabel == " ")
00571     setTabPageLabel( windowTitle());
00572   else
00573     setTabPageLabel( strTabPageLabel);
00574 
00575   isTabGroup = false;
00576   d->isContainer =false;
00577   setIcon( pixmap);
00578   widget = 0L;
00579 
00580   QObject::connect(this, SIGNAL(hasUndocked()), manager->main, SLOT(slotDockWidgetUndocked()) );
00581   applyToWidget( parent, QPoint(0,0) );
00582 }
00583 
00584 void K3DockWidget::setPixmap(const QPixmap& pixmap) {
00585     delete pix;
00586     pix=new QPixmap(pixmap);
00587     setIcon(*pix);
00588     K3DockTabGroup *dtg=parentDockTabGroup();
00589     if (dtg)
00590         dtg->changeTab(this,pixmap,dtg->tabLabel(this));
00591      QWidget *contWid=parentDockContainer();
00592          if (contWid) {
00593             K3DockContainer *x = dynamic_cast<K3DockContainer*>(contWid);
00594                 if (x) {
00595                         x->setPixmap(this,pixmap);
00596                 }
00597          }
00598 }
00599 
00600 const QPixmap& K3DockWidget::pixmap() const {
00601     return *pix;
00602 }
00603 
00604 K3DockWidget::~K3DockWidget()
00605 {
00606   d->pendingDtor = true;
00607   if ( !manager->undockProcess ){
00608     d->blockHasUndockedSignal = true;
00609     undock();
00610     d->blockHasUndockedSignal = false;
00611   }
00612 
00613   if (latestK3DockContainer()) {
00614     K3DockContainer *x = dynamic_cast<K3DockContainer*>(latestK3DockContainer());
00615     if (x) {
00616       x->removeWidget(this);
00617     }
00618   }
00619   emit iMBeingClosed();
00620   if (manager->d) manager->d->containerDocks.removeAll(this);
00621   manager->childDock->removeAll( this );
00622   delete pix;
00623   delete d; // destroy private data
00624   d=0;
00625 }
00626 
00627 void K3DockWidget::paintEvent(QPaintEvent* pe)
00628 {
00629   QWidget::paintEvent(pe);
00630   QPainter paint;
00631   paint.begin( this );
00632   QStyleOption option;
00633   option.init(this);
00634   option.rect = QRect( 0, 0, width(), height() );
00635   style()->drawPrimitive (QStyle::PE_FrameDockWidget, &option, &paint, this);
00636   paint.end();
00637 }
00638 
00639 void K3DockWidget::leaveEvent(QEvent *e)
00640 {
00641     QWidget::leaveEvent(e);
00642 #ifdef BORDERLESS_WINDOWS
00643     if (parent()) return;
00644 //  setCursor(QCursor(ArrowCursor));
00645 #endif
00646 }
00647 
00648 void K3DockWidget::mousePressEvent(QMouseEvent* mme)
00649 {
00650 #ifdef BORDERLESS_WINDOWS
00651     if (!parent())
00652     {
00653         kDebug(282)<<"K3DockWidget::mousePressEvent";
00654 
00655         bool bbottom;
00656         bool bleft;
00657         bool bright;
00658         bool btop;
00659         int styleheight;
00660         QPoint mp;
00661         mp=mme->pos();
00662             styleheight=2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,this);
00663         bbottom=mp.y()>=height()-styleheight;
00664         btop=mp.y()<=styleheight;
00665         bleft=mp.x()<=styleheight;
00666         bright=mp.x()>=width()-styleheight;
00667         kDebug(282)<<"mousemovevent";
00668         d->resizing=true;
00669         if (bright)
00670         {
00671             if (btop)
00672             {
00673                 d->resizeMode=K3DockWidgetPrivate::ResizeTopRight;
00674                 d->resizePos=QPoint(width(),0)-mme->pos();
00675 
00676             }
00677             else
00678             {
00679                 d->resizePos=QPoint(width(),height())-mme->pos();
00680                 if (bbottom) d->resizeMode=K3DockWidgetPrivate::ResizeBottomRight;
00681                 else d->resizeMode=K3DockWidgetPrivate::ResizeRight;
00682             }
00683         }
00684         else if (bleft)
00685         {
00686             if (btop) setCursor(QCursor(Qt::SizeFDiagCursor));
00687             else
00688             if (bbottom) setCursor(QCursor(Qt::SizeBDiagCursor));
00689             else setCursor(QCursor(Qt::SizeHorCursor));
00690         }
00691         else
00692         if (bbottom)
00693         {
00694             d->resizeMode=K3DockWidgetPrivate::ResizeBottom;
00695             d->resizePos=QPoint(0,height())-mme->pos();
00696         }
00697         else
00698         if  (btop) setCursor(QCursor(Qt::SizeVerCursor));
00699         else d->resizing=false;
00700 
00701         if (d->resizing) grabMouse(cursor());
00702 
00703     }
00704 #endif
00705     QWidget::mousePressEvent(mme);
00706 }
00707 
00708 void K3DockWidget::mouseReleaseEvent(QMouseEvent* ev)
00709 {
00710 #ifdef BORDERLESS_WINDOWS
00711     d->resizing=false;
00712     releaseMouse();
00713 #endif
00714     QWidget::mouseReleaseEvent(ev);
00715 }
00716 
00717 void  K3DockWidget::mouseMoveEvent(QMouseEvent* mme)
00718 {
00719     QWidget::mouseMoveEvent(mme);
00720 #ifdef BORDERLESS_WINDOWS
00721     if (parent()) return;
00722 
00723     if (d->resizing)
00724     {
00725         switch (d->resizeMode)
00726         {
00727             case K3DockWidgetPrivate::ResizeRight:
00728                 resize(mme->pos().x()+d->resizePos.x(),height());
00729                 break;
00730             case K3DockWidgetPrivate::ResizeBottomRight:
00731                 resize(mme->pos().x()+d->resizePos.x(),mme->pos().y()+d->resizePos.y());
00732                 break;
00733             case K3DockWidgetPrivate::ResizeBottom:
00734                 resize(width(),mme->pos().y()+d->resizePos.y());
00735                 break;
00736             default:
00737                 break;
00738         }
00739         return;
00740     }
00741 
00742 
00743     bool bbottom;
00744     bool bleft;
00745     bool bright;
00746     bool btop;
00747     int styleheight;
00748     QPoint mp;
00749     mp=mme->pos();
00750         styleheight=2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,this);
00751     bbottom=mp.y()>=height()-styleheight;
00752     btop=mp.y()<=styleheight;
00753     bleft=mp.x()<=styleheight;
00754     bright=mp.x()>=width()-styleheight;
00755     kDebug(282)<<"mousemovevent";
00756     if (bright)
00757     {
00758         if (btop) setCursor(QCursor(Qt::SizeBDiagCursor));
00759         else
00760         if (bbottom) setCursor(QCursor(Qt::SizeFDiagCursor));
00761         else setCursor(QCursor(Qt::SizeHorCursor));
00762     }
00763     else if (bleft)
00764     {
00765         if (btop) setCursor(QCursor(Qt::SizeFDiagCursor));
00766         else
00767         if (bbottom) setCursor(QCursor(Qt::SizeBDiagCursor));
00768         else setCursor(QCursor(Qt::SizeHorCursor));
00769     }
00770     else
00771     if (bbottom ||  btop) setCursor(QCursor(Qt::SizeVerCursor));
00772     else setCursor(QCursor(Qt::ArrowCursor));
00773 #endif
00774 }
00775 
00776 void K3DockWidget::setLatestK3DockContainer(QWidget* container)
00777 {
00778     if (container)
00779     {
00780         if (dynamic_cast<K3DockContainer*>(container))
00781             d->container=container;
00782         else
00783             d->container=0;
00784     }
00785 }
00786 
00787 QWidget* K3DockWidget::latestK3DockContainer()
00788 {
00789     if (!(d->container)) return 0;
00790     if (dynamic_cast<K3DockContainer*>(d->container.operator->())) return d->container;
00791     return 0;
00792 }
00793 
00794 
00795 
00796 K3DockWidgetAbstractHeader *K3DockWidget::getHeader() {
00797     return header;
00798 }
00799 
00800 void K3DockWidget::setHeader( K3DockWidgetAbstractHeader* h )
00801 {
00802   if ( !h ) return;
00803 
00804   if ( header ){
00805     delete header;
00806     delete layout;
00807     header = h;
00808     layout = new QVBoxLayout( this );
00809     layout->setSizeConstraint( QLayout::Minimum );
00810     layout->addWidget( header );
00811      setWidget( widget );
00812   } else {
00813     header = h;
00814     layout->addWidget( header );
00815   }
00816 //  kDebug(282)<<windowTitle()<<": K3DockWidget::setHeader";
00817   setEnableDocking(eDocking);
00818 }
00819 
00820 void K3DockWidget::setEnableDocking( int pos )
00821 {
00822   eDocking = pos;
00823   if( header ) {
00824      if ( header->inherits( "K3DockWidgetHeader" ) )
00825        ( ( K3DockWidgetHeader* ) header )->showUndockButton( pos & DockDesktop );
00826     updateHeader();
00827   }
00828 }
00829 
00830 int K3DockWidget::enableDocking() const
00831 {
00832     return eDocking;
00833 }
00834 
00835 void K3DockWidget::setDockSite( int pos )
00836 {
00837     sDocking = pos;
00838 }
00839 
00840 int K3DockWidget::dockSite() const
00841 {
00842     return sDocking;
00843 }
00844 
00845 void K3DockWidget::updateHeader()
00846 {
00847   if ( parent() ){
00848 #ifdef BORDERLESS_WINDOWS
00849       layout->setMargin(0);
00850       setMouseTracking(false);
00851       setCursor(QCursor(Qt::ArrowCursor));
00852 #endif
00853 
00854     if ( (parent() == manager->main) || isGroup || (eDocking == K3DockWidget::DockNone) ){
00855       header->hide();
00856     } else {
00857       header->setTopLevel( false );
00858       if (widget && dynamic_cast<K3DockContainer*>(widget))
00859         header->hide();
00860       else
00861         header->show();
00862     }
00863   } else {
00864     header->setTopLevel( true );
00865     header->show();
00866 #ifdef BORDERLESS_WINDOWS
00867       layout->setMargin(2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,this));
00868       setMouseTracking(true);
00869 #endif
00870   }
00871 }
00872 
00873 void K3DockWidget::applyToWidget( QWidget* s, const QPoint& p )
00874 {
00875   if ( parent() != s )
00876   {
00877     hide();
00878     setParent(s);
00879     move(0,0);
00880   }
00881 
00882   if ( s && s->inherits("K3DockMainWindow") ){
00883     ((K3DockMainWindow*)s)->setView( this );
00884   }
00885 
00886   if ( manager && s == manager->main ){
00887       setGeometry( QRect(QPoint(0,0), manager->main->geometry().size()) );
00888   }
00889 
00890   if ( !s )
00891   {
00892     move(p);
00893 
00894 #ifndef NO_KDE2
00895 #ifdef Q_WS_X11
00896     if (d->transient && d->_parent)
00897       XSetTransientForHint( QX11Info::display(), winId(), d->_parent->winId() );
00898 
00899 #ifdef BORDERLESS_WINDOWS
00900     KWindowSystem::setType( winId(), NET::Override); //d->windowType );
00901 //      setWFlags(WStyle_Customize | WStyle_NoBorder | WStyle_Tool);
00902 #else
00903     KWindowSystem::setType( winId(), d->windowType );
00904 #endif // BORDERLESS_WINDOW
00905 #endif // Q_WS_X11
00906 #endif
00907 
00908   }
00909   updateHeader();
00910 
00911   setIcon(*pix);
00912 }
00913 
00914 void K3DockWidget::show()
00915 {
00916   if ( parent() || manager->main->isVisible() ) {
00917     if ( !parent() ){
00918      emit manager->setDockDefaultPos( this );
00919      emit setDockDefaultPos();
00920      if ( parent() ){
00921         makeDockVisible();
00922       } else {
00923         QWidget::show();
00924       }
00925     } else {
00926      QWidget::show();
00927     }
00928   }
00929 }
00930 
00931 #ifndef NO_KDE2
00932 
00933 void K3DockWidget::setDockWindowType (NET::WindowType windowType)
00934 {
00935   d->windowType = windowType;
00936   applyToWidget( parentWidget(), QPoint(0,0) );
00937 }
00938 
00939 #endif
00940 
00941 void K3DockWidget::setDockWindowTransient (QWidget *parent, bool transientEnabled)
00942 {
00943   d->_parent = parent;
00944   d->transient = transientEnabled;
00945   applyToWidget( parentWidget(), QPoint(0,0) );
00946 }
00947 
00948 QWidget *K3DockWidget::transientTo() {
00949     if (d->transient && d->_parent) return d->_parent; else return 0;
00950 }
00951 
00952 bool K3DockWidget::event( QEvent *event )
00953 {
00954   switch ( event->type() )
00955   {
00956     #undef FocusIn
00957     case QEvent::FocusIn:
00958       if (widget && !d->pendingFocusInEvent) {
00959          d->pendingFocusInEvent = true;
00960          widget->setFocus();
00961       }
00962       d->pendingFocusInEvent = false;
00963       break;
00964     case QEvent::ChildRemoved:
00965       if ( widget == ((QChildEvent*)event)->child() ) widget = 0L;
00966       break;
00967     case QEvent::Show:
00968       if ( widget ) widget->show();
00969       emit manager->change();
00970       break;
00971     case QEvent::Hide:
00972       if ( widget ) widget->hide();
00973       emit manager->change();
00974       break;
00975     case QEvent::WindowTitleChange:
00976       if ( parentWidget() ){
00977         if ( parent()->inherits("K3DockSplitter") ){
00978           ((K3DockSplitter*)(parent()))->updateName();
00979         }
00980         if ( parentDockTabGroup() ){
00981           setDockTabName( parentDockTabGroup() );
00982           parentDockTabGroup()->setTabLabel( this, tabPageLabel() );
00983         }
00984       }
00985       break;
00986     case QEvent::Close:
00987       emit iMBeingClosed();
00988       break;
00989     default:
00990       break;
00991   }
00992   return QWidget::event( event );
00993 }
00994 
00995 K3DockWidget *K3DockWidget::findNearestDockWidget(DockPosition pos)
00996 {
00997     if (!parent()) return 0;
00998     if (!parent()->inherits("K3DockSplitter")) return 0;
00999     Qt::Orientation orientation= ( ( pos == K3DockWidget::DockLeft) ||
01000                                    ( pos == K3DockWidget::DockRight ) ) ? Qt::Vertical : Qt::Horizontal;
01001         if (((K3DockSplitter*)(parent()))->orientation() == orientation)
01002         {
01003             K3DockWidget *neighbor=
01004                 ( ( pos == K3DockWidget::DockLeft ) || ( pos == K3DockWidget::DockTop ) ) ?
01005                 static_cast<K3DockWidget*>( ( ( K3DockSplitter* )( parent() ) )->getFirst() ) :
01006                 static_cast<K3DockWidget*>( ( ( K3DockSplitter* )( parent() ) )->getLast() );
01007 
01008             if (neighbor==this)
01009             return (static_cast<K3DockWidget*>(parent()->parent())->findNearestDockWidget(pos));
01010             else
01011             if (neighbor->getWidget() && qobject_cast<K3DockTabGroup*>(neighbor->getWidget()))
01012                 return (K3DockWidget*)(((K3DockTabGroup*)neighbor->getWidget())->page(0));
01013             else
01014             return neighbor;
01015         }
01016         else
01017         return (static_cast<K3DockWidget*>(parent()->parent())->findNearestDockWidget(pos));
01018 
01019     return 0;
01020 }
01021 
01022 
01023 K3DockWidget* K3DockWidget::manualDock( K3DockWidget* target, DockPosition dockPos, int spliPos, QPoint pos, bool check, int tabIndex )
01024 {
01025   if (this == target)
01026     return 0L;  // docking to itself not possible
01027 
01028 //  kDebug(282)<<"manualDock called ";
01029   bool success = true; // tested flag
01030 
01031   // Check to make sure that we can dock in to the position wee
01032   // were told to dock in to
01033   if ( !(eDocking & (int)dockPos) ){
01034     success = false;
01035 //  kDebug(282)<<"K3DockWidget::manualDock(): success = false (1)";
01036   }
01037 
01038   // fix for apps which use a value > 100%. The splitter position must be between 0..100
01039   // The old behavior on high resolution was 0..10000. So likely the value is >100.
01040   if (spliPos > 100) {
01041       spliPos = spliPos / 100;
01042       kDebug(282) << "K3DockWidget::manualDock(): fix splitter position: " << spliPos;
01043   }
01044 
01045   K3DockWidget *tmpTarget = 0;
01046   switch (dockPos) {
01047     case K3DockWidget::DockLeft:
01048         tmpTarget=dockManager()->d->leftContainer;
01049         break;
01050     case K3DockWidget::DockRight:
01051         tmpTarget=dockManager()->d->rightContainer;
01052         break;
01053     case K3DockWidget::DockBottom:
01054         tmpTarget=dockManager()->d->bottomContainer;
01055         break;
01056     case K3DockWidget::DockTop:
01057         tmpTarget=dockManager()->d->topContainer;
01058         break;
01059     default:
01060         tmpTarget = 0;
01061   }
01062 
01063   //If we're not the target, and the target is our dock manager's main window
01064   //dock into the temp target as chosen above
01065   if ( tmpTarget && target && this != tmpTarget && target == dockManager()->d->mainDockWidget )
01066     return manualDock(tmpTarget,DockCenter,spliPos,pos,check,tabIndex);
01067 
01068   // check if the target allows us to oock into the requested position
01069   if ( target && !(target->sDocking & (int)dockPos) ){
01070     success = false;
01071 //  kDebug(282)<<"K3DockWidget::manualDock(): success = false (2)";
01072   }
01073 
01074   /* if we have a parent, and it's not a K3DockSplitter, and we don't have a parent
01075    * dock tab group, and our parent isn't a K3DockContainer, and we have no explicit
01076    * parent dock container...we can't do much yet */
01077   if ( parent() && !parent()->inherits("K3DockSplitter") && !parentDockTabGroup() &&
01078     !(dynamic_cast<K3DockContainer*>(parent())) && !parentDockContainer()){
01079 //  kDebug(282)<<"K3DockWidget::manualDock(): success = false (3)";
01080 //  kDebug(282)<<parent()->name();
01081     success = false;
01082   }
01083 
01084   /* If all of our attempts to dock back so far have failed and we have a target
01085    * and we're not being called recursively (i guess that's what check is for)
01086    * then attempt to dock back to ourselves. */
01087   if ( !success ){
01088     // try to make another manualDock
01089     K3DockWidget* dock_result = 0L;
01090     if ( target && !check ){
01091       K3DockWidget::DockPosition another__dockPos = K3DockWidget::DockNone;
01092       switch ( dockPos ){
01093         case K3DockWidget::DockLeft  : another__dockPos = K3DockWidget::DockRight ; break;
01094         case K3DockWidget::DockRight : another__dockPos = K3DockWidget::DockLeft  ; break;
01095         case K3DockWidget::DockTop   : another__dockPos = K3DockWidget::DockBottom; break;
01096         case K3DockWidget::DockBottom: another__dockPos = K3DockWidget::DockTop   ; break;
01097         default: break;
01098       }
01099       dock_result = target->manualDock( this, another__dockPos, spliPos, pos, true, tabIndex );
01100     }
01101     return dock_result;
01102   }
01103   // end check block
01104 
01105   d->blockHasUndockedSignal = true;
01106   undock();
01107   d->blockHasUndockedSignal = false;
01108 
01109   //we have no docking target, so we're undocking
01110   if ( !target ){
01111     move( pos );
01112     show();
01113     emit manager->change();
01114     return this;
01115   }
01116 
01117 //  kDebug(282)<<"Looking for  K3DockTabGroup";
01118   K3DockTabGroup* parentTab = target->parentDockTabGroup();
01119   if ( parentTab ){
01120     // add to existing TabGroup
01121     applyToWidget( parentTab );
01122     parentTab->insertTab( this, icon() ? *icon() : QPixmap(),
01123                           tabPageLabel(), tabIndex );
01124 
01125     QWidget *wantTransient=parentTab->transientTo();
01126     target->setDockWindowTransient(wantTransient,wantTransient);
01127 
01128     setDockTabName( parentTab );
01129     if( !toolTipStr.isEmpty())
01130       parentTab->setTabToolTip( this, toolTipStr);
01131 
01132     currentDockPos = K3DockWidget::DockCenter;
01133     emit manager->change();
01134     return (K3DockWidget*)parentTab->parent();
01135   }
01136   else
01137   {
01138 //      kDebug(282)<<"Looking for  K3DockContainer";
01139     QWidget *contWid=target->parentDockContainer();
01140       if (!contWid) contWid=target->widget;
01141       if (contWid)
01142       {
01143         K3DockContainer *cont=dynamic_cast<K3DockContainer*>(contWid);
01144           if (cont)
01145           {
01146             if (latestK3DockContainer() && (latestK3DockContainer()!=contWid)) {
01147                 K3DockContainer* dc = dynamic_cast<K3DockContainer*>(latestK3DockContainer());
01148                 if (dc) {
01149                     dc->removeWidget(this);
01150                 }
01151             }
01152 //          kDebug(282)<<"K3DockContainerFound";
01153             applyToWidget( contWid );
01154             cont->insertWidget( this, icon() ? *icon() : QPixmap(),
01155                         tabPageLabel(), tabIndex );
01156             setLatestK3DockContainer(contWid);
01157 //          setDockTabName( parentTab );
01158             if( !toolTipStr.isEmpty())
01159             cont->setToolTip( this, toolTipStr);
01160 
01161             currentDockPos = K3DockWidget::DockCenter;
01162             emit manager->change();
01163             return (K3DockWidget*)(cont->parentDockWidget());
01164 
01165           }
01166       }
01167   }
01168 
01169   // create a new dockwidget that will contain the target and this
01170   QWidget* parentDock = target->parentWidget();
01171   K3DockWidget* newDock = new K3DockWidget( manager, "tempName", QPixmap(""), parentDock );
01172   newDock->currentDockPos = target->currentDockPos;
01173 
01174   if ( dockPos == K3DockWidget::DockCenter ){
01175     newDock->isTabGroup = true;
01176   } else {
01177     newDock->isGroup = true;
01178   }
01179   newDock->eDocking = (target->eDocking & eDocking) & (~(int)K3DockWidget::DockCenter);
01180 
01181   newDock->applyToWidget( parentDock );
01182 
01183   if ( !parentDock ){
01184     // dock to a toplevel dockwidget means newDock is toplevel now
01185     newDock->move( target->frameGeometry().topLeft() );
01186     newDock->resize( target->geometry().size() );
01187     if ( target->isVisibleToTLW() ) newDock->show();
01188   }
01189 
01190   // redirect the dockback button to the new dockwidget
01191   if( target->formerBrotherDockWidget ) {
01192     newDock->setFormerBrotherDockWidget(target->formerBrotherDockWidget);
01193     if( formerBrotherDockWidget )
01194       target->loseFormerBrotherDockWidget();
01195     }
01196   newDock->formerDockPos = target->formerDockPos;
01197 
01198 
01199  // HERE SOMETING CREATING CONTAINERS SHOULD BE ADDED !!!!!
01200   if ( dockPos == K3DockWidget::DockCenter )
01201   {
01202     K3DockTabGroup* tab = new K3DockTabGroup( newDock );
01203     tab->setObjectName( QLatin1String( "_dock_tab" ) );
01204     QObject::connect(tab, SIGNAL(currentChanged(QWidget*)), d, SLOT(slotFocusEmbeddedWidget(QWidget*)));
01205     newDock->setWidget( tab );
01206 
01207     target->applyToWidget( tab );
01208     applyToWidget( tab );
01209 
01210 
01211     tab->insertTab( target, target->icon() ? *(target->icon()) : QPixmap(),
01212                     target->tabPageLabel() );
01213 
01214 
01215 
01216     if( !target->toolTipString().isEmpty())
01217      tab->setTabToolTip( target, target->toolTipString());
01218 
01219     tab->insertTab( this, icon() ? *icon() : QPixmap(),
01220                     tabPageLabel(), tabIndex );
01221 
01222     QRect geom=newDock->geometry();
01223     QWidget *wantTransient=tab->transientTo();
01224     newDock->setDockWindowTransient(wantTransient,wantTransient);
01225     newDock->setGeometry(geom);
01226 
01227     if( !toolTipString().isEmpty())
01228       tab->setTabToolTip( this, toolTipString());
01229 
01230     setDockTabName( tab );
01231     tab->show();
01232 
01233     currentDockPos = DockCenter;
01234     target->formerDockPos = target->currentDockPos;
01235     target->currentDockPos = DockCenter;
01236   }
01237   else {
01238     // if to dock not to the center of the target dockwidget,
01239     // dock to newDock
01240     K3DockSplitter* panner = 0L;
01241     if ( dockPos == K3DockWidget::DockTop  || dockPos == K3DockWidget::DockBottom ) panner = new K3DockSplitter( newDock, "_dock_split_", Qt::Horizontal, spliPos );
01242     if ( dockPos == K3DockWidget::DockLeft || dockPos == K3DockWidget::DockRight  ) panner = new K3DockSplitter( newDock, "_dock_split_", Qt::Vertical , spliPos );
01243     newDock->setWidget( panner );
01244 
01245     panner->setOpaqueResize(manager->splitterOpaqueResize());
01246     panner->setKeepSize(manager->splitterKeepSize());
01247     panner->setFocusPolicy( Qt::NoFocus );
01248     target->applyToWidget( panner );
01249     applyToWidget( panner );
01250     target->formerDockPos = target->currentDockPos;
01251     if ( dockPos == K3DockWidget::DockRight) {
01252       panner->activate( target, this );
01253       currentDockPos = K3DockWidget::DockRight;
01254       target->currentDockPos = K3DockWidget::DockLeft;
01255     }
01256     else if( dockPos == K3DockWidget::DockBottom) {
01257       panner->activate( target, this );
01258       currentDockPos = K3DockWidget::DockBottom;
01259       target->currentDockPos = K3DockWidget::DockTop;
01260     }
01261     else if( dockPos == K3DockWidget::DockTop) {
01262       panner->activate( this, target );
01263       currentDockPos = K3DockWidget::DockTop;
01264       target->currentDockPos = K3DockWidget::DockBottom;
01265     }
01266     else if( dockPos == K3DockWidget::DockLeft) {
01267       panner->activate( this, target );
01268       currentDockPos = K3DockWidget::DockLeft;
01269       target->currentDockPos = K3DockWidget::DockRight;
01270     }
01271     target->show();
01272     show();
01273     panner->show();
01274   }
01275 
01276   if ( parentDock ){
01277     if ( parentDock->inherits("K3DockSplitter") ){
01278       K3DockSplitter* sp = (K3DockSplitter*)parentDock;
01279       sp->deactivate();
01280       if ( sp->getFirst() == target )
01281         sp->activate( newDock, 0L );
01282       else
01283         sp->activate( 0L, newDock );
01284     }
01285   }
01286 
01287   newDock->show();
01288   emit target->docking( this, dockPos );
01289   emit manager->replaceDock( target, newDock );
01290   emit manager->change();
01291 
01292   return newDock;
01293 }
01294 
01295 K3DockTabGroup* K3DockWidget::parentDockTabGroup() const
01296 {
01297   if ( !parent() ) return 0L;
01298   QWidget* candidate = parentWidget()->parentWidget();
01299   if ( candidate && candidate->inherits("K3DockTabGroup") ) return (K3DockTabGroup*)candidate;
01300   return 0L;
01301 }
01302 
01303 QWidget *K3DockWidget::parentDockContainer() const
01304 {
01305   if (!parent()) return 0L;
01306   QWidget* candidate = parentWidget()->parentWidget();
01307   if (candidate && dynamic_cast<K3DockContainer*>(candidate)) return candidate;
01308   return 0L;
01309 }
01310 
01311 
01312 void K3DockWidget::setForcedFixedWidth(int w)
01313 {
01314     d->forcedWidth=w;
01315     setFixedWidth(w);
01316     if (!parent()) return;
01317     if (parent()->inherits("K3DockSplitter"))
01318         qobject_cast<K3DockSplitter*>(parent())->setForcedFixedWidth(this,w);
01319 }
01320 
01321 void K3DockWidget::setForcedFixedHeight(int h)
01322 {
01323     d->forcedHeight=h;
01324     setFixedHeight(h);
01325     if (!parent()) return;
01326     if (parent()->inherits("K3DockSplitter"))
01327         qobject_cast<K3DockSplitter*>(parent())->setForcedFixedHeight(this,h);
01328 }
01329 
01330 int K3DockWidget::forcedFixedWidth()
01331 {
01332     return d->forcedWidth;
01333 }
01334 
01335 int K3DockWidget::forcedFixedHeight()
01336 {
01337     return d->forcedHeight;
01338 }
01339 
01340 void K3DockWidget::restoreFromForcedFixedSize()
01341 {
01342     d->forcedWidth=-1;
01343     d->forcedHeight=-1;
01344     setMinimumWidth(0);
01345     setMaximumWidth(32000);
01346     setMinimumHeight(0);
01347     setMaximumHeight(32000);
01348     if (!parent()) return;
01349     if (parent()->inherits("K3DockSplitter"))
01350         qobject_cast<K3DockSplitter*>(parent())->restoreFromForcedFixedSize(this);
01351 }
01352 
01353 void K3DockWidget::toDesktop()
01354 {
01355    QPoint p = mapToGlobal( QPoint( -30, -30 ) );
01356    if( p.x( ) < 0 )
01357       p.setX( 0 );
01358    if( p.y( ) < 0 )
01359       p.setY( 0 );
01360    manualDock( 0, DockDesktop, 50, p );
01361 }
01362 
01363 K3DockWidget::DockPosition K3DockWidget::currentDockPosition() const
01364 {
01365     return currentDockPos;
01366 }
01367 
01368 void K3DockWidget::undock()
01369 {
01370   //  kDebug(282) << "K3DockWidget::undock : undocking " << name();
01371 
01372   manager->d->dragRect = QRect ();
01373   manager->drawDragRectangle ();
01374 
01375   QWidget* parentW = parentWidget();
01376   if ( !parentW ){
01377     hide();
01378     if (!d->blockHasUndockedSignal)
01379       emit hasUndocked();
01380     return;
01381   }
01382 
01383   formerDockPos = currentDockPos;
01384   currentDockPos = K3DockWidget::DockDesktop;
01385 
01386   manager->blockSignals(true);
01387   manager->undockProcess = true;
01388 
01389   bool isV = parentW->isVisibleToTLW();
01390 
01391   //UNDOCK HAS TO BE IMPLEMENTED CORRECTLY :)
01392   K3DockTabGroup* parentTab = parentDockTabGroup();
01393   if ( parentTab ){
01394     d->index = parentTab->indexOf( this); // memorize the page position in the tab widget
01395     parentTab->removePage( this );
01396 /*
01397     QWidget *wantTransient=parentTab->transientTo();
01398     target->setDockWindowTransient(wantTransient,wantTransient);
01399  */
01400     setFormerBrotherDockWidget((K3DockWidget*)parentTab->page(0));
01401     applyToWidget( 0L );
01402     if ( parentTab->count() == 1 ){
01403 
01404       // last subdock widget in the tab control
01405       K3DockWidget* lastTab = (K3DockWidget*)parentTab->page(0);
01406       parentTab->removePage( lastTab );
01407 /*      QWidget *wantTransient=parentTab->transientTo();
01408       target->setDockWindowTransient(wantTransient,wantTransient);*/
01409 
01410       lastTab->applyToWidget( 0L );
01411       lastTab->move( parentTab->mapToGlobal(parentTab->frameGeometry().topLeft()) );
01412 
01413       // K3DockTabGroup always have a parent that is a K3DockWidget
01414       K3DockWidget* parentOfTab = (K3DockWidget*)parentTab->parent();
01415       delete parentTab; // K3DockTabGroup
01416 
01417       QWidget* parentOfDockWidget = parentOfTab->parentWidget();
01418       if ( !parentOfDockWidget ){
01419           if ( isV ) lastTab->show();
01420       } else {
01421         if ( parentOfDockWidget->inherits("K3DockSplitter") ){
01422           K3DockSplitter* split = (K3DockSplitter*)parentOfDockWidget;
01423           lastTab->applyToWidget( split );
01424           split->deactivate();
01425           if ( split->getFirst() == parentOfTab ){
01426             split->activate( lastTab );
01427             if ( ((K3DockWidget*)split->parent())->splitterOrientation == Qt::Vertical )
01428               emit ((K3DockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, K3DockWidget::DockLeft );
01429             else
01430               emit ((K3DockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, K3DockWidget::DockTop );
01431           } else {
01432             split->activate( 0L, lastTab );
01433             if ( ((K3DockWidget*)split->parent())->splitterOrientation == Qt::Vertical )
01434               emit ((K3DockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, K3DockWidget::DockRight );
01435             else
01436               emit ((K3DockWidget*)split->getAnother(parentOfTab))->docking( parentOfTab, K3DockWidget::DockBottom );
01437           }
01438           split->show();
01439         } else {
01440           lastTab->applyToWidget( parentOfDockWidget );
01441         }
01442         lastTab->show();
01443       }
01444       manager->blockSignals(false);
01445       emit manager->replaceDock( parentOfTab, lastTab );
01446       lastTab->currentDockPos = parentOfTab->currentDockPos;
01447       emit parentOfTab->iMBeingClosed();
01448       manager->blockSignals(true);
01449       delete parentOfTab;
01450 
01451     } else {
01452       setDockTabName( parentTab );
01453     }
01454   } else {
01455  /*********************************************************************************************/
01456   //QWidget* containerWidget = (QWidget*)parent();
01457   bool undockedFromContainer=false;
01458   if (d->container)
01459   {
01460 //    kDebug(282)<<"undocked from dockcontainer";
01461       undockedFromContainer=true;
01462       K3DockContainer* dc = dynamic_cast<K3DockContainer*>(d->container.operator->());
01463       if (dc) {
01464           dc->undockWidget(this);
01465           setFormerBrotherDockWidget(dc->parentDockWidget());
01466       }
01467       applyToWidget( 0L );
01468   }
01469    if (!undockedFromContainer) {
01470 /*********************************************************************************************/
01471     if ( parentW->inherits("K3DockSplitter") ){
01472       K3DockSplitter* parentSplitterOfDockWidget = (K3DockSplitter*)parentW;
01473       d->splitPosInPercent = parentSplitterOfDockWidget->separatorPosInPercent();
01474 
01475       K3DockWidget* secondWidget = (K3DockWidget*)parentSplitterOfDockWidget->getAnother( this );
01476       K3DockWidget* group        = (K3DockWidget*)parentSplitterOfDockWidget->parentWidget();
01477       setFormerBrotherDockWidget(secondWidget);
01478       applyToWidget( 0L );
01479       group->hide();
01480 
01481       if ( !group->parentWidget() ){
01482         secondWidget->applyToWidget( 0L, group->frameGeometry().topLeft() );
01483         secondWidget->resize( group->width(), group->height() );
01484       } else {
01485         QWidget* obj = group->parentWidget();
01486         secondWidget->applyToWidget( obj );
01487         if ( obj->inherits("K3DockSplitter") ){
01488           K3DockSplitter* parentOfGroup = (K3DockSplitter*)obj;
01489           parentOfGroup->deactivate();
01490 
01491           if ( parentOfGroup->getFirst() == group )
01492             parentOfGroup->activate( secondWidget );
01493           else
01494             parentOfGroup->activate( 0L, secondWidget );
01495         }
01496       }
01497       secondWidget->currentDockPos = group->currentDockPos;
01498       secondWidget->formerDockPos  = group->formerDockPos;
01499       delete parentSplitterOfDockWidget;
01500       manager->blockSignals(false);
01501       emit manager->replaceDock( group, secondWidget );
01502       emit group->iMBeingClosed();
01503       manager->blockSignals(true);
01504       delete group;
01505 
01506       if ( isV ) secondWidget->show();
01507     } else {
01508       if (!d->pendingDtor) {
01509         // don't reparent in the dtor of this
01510         applyToWidget( 0L );
01511       }
01512     }
01513 /*********************************************************************************************/
01514   }
01515   }
01516   manager->blockSignals(false);
01517   if (!d->blockHasUndockedSignal)
01518     emit manager->change();
01519   manager->undockProcess = false;
01520 
01521   if (!d->blockHasUndockedSignal)
01522     emit hasUndocked();
01523 }
01524 
01525 void K3DockWidget::setWidget( QWidget* mw )
01526 {
01527   if ( !mw ) return;
01528 
01529   if ( mw->parent() != this ){
01530     mw->setParent(this);
01531     mw->move(0,0);
01532   }
01533 
01534 #ifdef BORDERLESS_WINDOWS
01535   if (!mw->ownCursor()) mw->setCursor(QCursor(Qt::ArrowCursor));
01536 #endif
01537   widget = mw;
01538   delete layout;
01539 
01540   /*
01541    * Qt 4.1 does not fill the background if not asked so explicitly.
01542    * However code from Qt3/KDE3 could except that the background is filled.
01543    */
01544   widget->setAutoFillBackground( true );
01545 
01546   layout = new QVBoxLayout( this );
01547   layout->setSizeConstraint( QLayout::Minimum );
01548 
01549   K3DockContainer* dc = dynamic_cast<K3DockContainer*>(widget);
01550   if (dc)
01551   {
01552     d->isContainer=true;
01553     manager->d->containerDocks.append(this);
01554   }
01555   else
01556   {
01557     d->isContainer=false;
01558   }
01559 
01560   {
01561      header->show();
01562      layout->addWidget( header );
01563      layout->addWidget( widget,1 );
01564   }
01565   updateHeader();
01566   emit widgetSet(mw);
01567 }
01568 
01569 QWidget* K3DockWidget::getWidget() const
01570 {
01571     return widget;
01572 }
01573 
01574 void K3DockWidget::setDockTabName( K3DockTabGroup* tab )
01575 {
01576   QString listOfName;
01577   QString listOfCaption;
01578   for ( int i = 0; i < tab->count(); ++i ) {
01579     QWidget *w = tab->page( i );
01580     listOfCaption.append( w->windowTitle() ).append(",");
01581     listOfName.append( w->name() ).append(",");
01582   }
01583   listOfCaption.remove( listOfCaption.length()-1, 1 );
01584   listOfName.remove( listOfName.length()-1, 1 );
01585 
01586   tab->parentWidget()->setName( listOfName.toUtf8() );
01587   tab->parentWidget()->setWindowTitle( listOfCaption );
01588 
01589   tab->parentWidget()->repaint(); // K3DockWidget->repaint
01590   if ( tab->parentWidget()->parent() )
01591     if ( tab->parentWidget()->parent()->inherits("K3DockSplitter") )
01592       ((K3DockSplitter*)(tab->parentWidget()->parent()))->updateName();
01593 }
01594 
01595 bool K3DockWidget::mayBeHide() const
01596 {
01597   bool f = (parent() != manager->main);
01598   return ( !isGroup && !isTabGroup && f && isVisible() && ( eDocking != (int)K3DockWidget::DockNone ) );
01599 }
01600 
01601 bool K3DockWidget::mayBeShow() const
01602 {
01603   bool f = (parent() != manager->main);
01604   return ( !isGroup && !isTabGroup && f && !isVisible() );
01605 }
01606 
01607 K3DockManager* K3DockWidget::dockManager() const
01608 {
01609     return manager;
01610 }
01611 
01612 void K3DockWidget::setToolTipString(const QString& ttStr)
01613 {
01614     toolTipStr = ttStr;
01615 }
01616 
01617 const QString& K3DockWidget::toolTipString() const
01618 {
01619     return toolTipStr;
01620 }
01621 
01622 void K3DockWidget::changeHideShowState()
01623 {
01624   if ( mayBeHide() ){
01625     undock();
01626     return;
01627   }
01628 
01629   if ( mayBeShow() ){
01630     if ( manager->main->inherits("K3DockMainWindow") ){
01631       ((K3DockMainWindow*)manager->main)->makeDockVisible(this);
01632     } else {
01633       makeDockVisible();
01634     }
01635   }
01636 }
01637 
01638 void K3DockWidget::makeDockVisible()
01639 {
01640   if ( parentDockTabGroup() ){
01641     parentDockTabGroup()->showPage( this );
01642   }
01643   if (parentDockContainer()) {
01644     QWidget *contWid=parentDockContainer();
01645     K3DockContainer *x = dynamic_cast<K3DockContainer*>(contWid);
01646     if (x) {
01647       x->showWidget(this);
01648     }
01649   }
01650   if ( isVisible() ) return;
01651 
01652   QWidget* p = parentWidget();
01653   while ( p ){
01654     if ( !p->isVisible() )
01655       p->show();
01656     p = p->parentWidget();
01657   }
01658   if( !parent() ) // is undocked
01659     dockBack();
01660   show();
01661 }
01662 
01663 void K3DockWidget::setFormerBrotherDockWidget(K3DockWidget *dockWidget)
01664 {
01665   formerBrotherDockWidget = dockWidget;
01666   if( formerBrotherDockWidget )
01667     QObject::connect( formerBrotherDockWidget, SIGNAL(iMBeingClosed()),
01668                       this, SLOT(loseFormerBrotherDockWidget()) );
01669 }
01670 
01671 void K3DockWidget::loseFormerBrotherDockWidget()
01672 {
01673   if( formerBrotherDockWidget )
01674     QObject::disconnect( formerBrotherDockWidget, SIGNAL(iMBeingClosed()),
01675                          this, SLOT(loseFormerBrotherDockWidget()) );
01676   formerBrotherDockWidget = 0L;
01677   repaint();
01678 }
01679 
01680 void K3DockWidget::dockBack()
01681 {
01682   if( formerBrotherDockWidget) {
01683     // search all children if it tries to dock back to a child
01684     bool found = false;
01685     QList<K3DockWidget *> cl = findChildren<K3DockWidget *>();
01686     foreach ( K3DockWidget *obj, cl ) {
01687         while ( !found && obj!= 0 ) {
01688         QWidget* widg = qobject_cast<QWidget*>(obj);
01689             if( widg == formerBrotherDockWidget)
01690                 found = true;
01691         }
01692     }
01693 
01694     if( !found) {
01695       // can dock back to the former brother dockwidget
01696       manualDock( formerBrotherDockWidget, formerDockPos, d->splitPosInPercent, QPoint(0,0), false, d->index);
01697       formerBrotherDockWidget = 0L;
01698       makeDockVisible();
01699       return;
01700     }
01701   }
01702 
01703   // else dockback to the dockmainwindow (default behavior)
01704   manualDock( ((K3DockMainWindow*)manager->main)->getMainDockWidget(), formerDockPos, d->splitPosInPercent, QPoint(0,0), false, d->index);
01705   formerBrotherDockWidget = 0L;
01706   if (parent())
01707     makeDockVisible();
01708 }
01709 
01710 bool K3DockWidget::isDockBackPossible() const
01711 {
01712   if( !(formerBrotherDockWidget) || !(formerBrotherDockWidget->dockSite() & formerDockPos))
01713     return false;
01714   else
01715     return true;
01716 }
01717 
01718 void K3DockWidget::setTabPageLabel( const QString& label)
01719 {
01720     tabPageTitle = label;
01721 }
01722 
01723 const QString& K3DockWidget::tabPageLabel() const
01724 {
01725     return tabPageTitle;
01726 }
01727 
01728 /**************************************************************************************/
01729 
01730 
01731 K3DockManager::K3DockManager( QWidget* mainWindow , const char* name )
01732 :QObject( mainWindow, name )
01733   ,main(mainWindow)
01734   ,currentDragWidget(0L)
01735   ,currentMoveWidget(0L)
01736   ,childDockWidgetList(0L)
01737   ,autoCreateDock(0L)
01738   ,storeW(0)
01739   ,storeH(0)
01740   ,dragging(false)
01741   ,undockProcess(false)
01742   ,dropCancel(true)
01743 {
01744   d = new K3DockManagerPrivate;
01745 
01746   d->readyToDrag = false;
01747   d->mainDockWidget=0;
01748 
01749 #ifndef NO_KDE2
01750   d->splitterOpaqueResize = KGlobalSettings::opaqueResize();
01751 #else
01752   d->splitterOpaqueResize = false;
01753 #endif
01754 
01755   d->splitterKeepSize = false;
01756   d->splitterHighResolution = false;
01757   d->m_readDockConfigMode = WrapExistingWidgetsOnly; // default as before
01758 
01759   main->installEventFilter( this );
01760 
01761   undockProcess = false;
01762 
01763   menuData = new Q3PtrList<MenuDockData>;
01764   menuData->setAutoDelete( true );
01765   menuData->setAutoDelete( true );
01766 
01767 #ifndef NO_KDE2
01768   menu = new K3PopupMenu();
01769 #else
01770   menu = new Q3PopupMenu();
01771 #endif
01772 
01773   connect( menu, SIGNAL(aboutToShow()), SLOT(slotMenuPopup()) );
01774   connect( menu, SIGNAL(activated(int)), SLOT(slotMenuActivated(int)) );
01775 
01776   childDock = new QList<QObject*>();
01777 }
01778 
01779 
01780 void K3DockManager::setMainDockWidget2(K3DockWidget *w)
01781 {
01782   d->mainDockWidget=w;
01783 }
01784 
01785 K3DockManager::~K3DockManager()
01786 {
01787   delete menuData;
01788   delete menu;
01789 
01790   // ### FIXME: this seems to crash but why? (KDE4)
01791   K3DockWidget * obj;
01792   Q_FOREACH ( QObject *o, *childDock ) {
01793     obj = (K3DockWidget*) ( o );
01794     delete obj;
01795   }
01796 
01797   delete childDock;
01798   delete d;
01799   d=0;
01800 }
01801 
01802 void K3DockManager::activate()
01803 {
01804   K3DockWidget * obj;
01805   foreach ( QObject *o, *childDock ) {
01806     obj=(K3DockWidget*)o;
01807     if ( obj->widget ) obj->widget->show();
01808     if ( !obj->parentDockTabGroup() ){
01809         obj->show();
01810     }
01811   }
01812   if ( !main->inherits("QDialog") ) main->show();
01813 }
01814 
01815 bool K3DockManager::eventFilter( QObject *obj, QEvent *event )
01816 {
01817 
01818   if ( obj->inherits("K3DockWidgetAbstractHeaderDrag") ){
01819     K3DockWidget* pDockWdgAtCursor = 0L;
01820     K3DockWidget* curdw = ((K3DockWidgetAbstractHeaderDrag*)obj)->dockWidget();
01821     switch ( event->type() ){
01822       case QEvent::MouseButtonDblClick:
01823         if (curdw->currentDockPos == K3DockWidget::DockDesktop)  curdw->dockBack();
01824         else
01825     {
01826         curdw->toDesktop();
01827         // curdw->manualDock (0, K3DockWidget::DockDesktop);
01828     }
01829         break;
01830 
01831       case QEvent::MouseButtonPress:
01832         if ( ((QMouseEvent*)event)->button() == Qt::LeftButton ){
01833           if ( curdw->eDocking != (int)K3DockWidget::DockNone ){
01834             dropCancel = true;
01835             curdw->setFocus();
01836             qApp->processOneEvent();
01837 
01838             currentDragWidget = curdw;
01839             currentMoveWidget = 0L;
01840             childDockWidgetList = new QWidgetList();
01841             childDockWidgetList->append( curdw );
01842             findChildDockWidget( curdw, childDockWidgetList );
01843 
01844             //d->oldDragRect = QRect(); should fix rectangle not erased problem
01845             d->dragRect = QRect(curdw->geometry());
01846             QPoint p = curdw->mapToGlobal(QPoint(0,0));
01847             d->dragRect.moveTopLeft(p);
01848             drawDragRectangle();
01849             d->readyToDrag = true;
01850 
01851             d->dragOffset = QCursor::pos()-currentDragWidget->mapToGlobal(QPoint(0,0));
01852           }
01853 
01854         }
01855         break;
01856       case QEvent::MouseButtonRelease:
01857         if ( ((QMouseEvent*)event)->button() == Qt::LeftButton ){
01858           if ( dragging ){
01859             if ( !dropCancel )
01860               drop();
01861             else
01862               cancelDrop();
01863           }
01864           if (d->readyToDrag) {
01865               d->readyToDrag = false;
01866               //d->oldDragRect = QRect(); should fix rectangle not erased problem
01867               d->dragRect = QRect(curdw->geometry());
01868               QPoint p = curdw->mapToGlobal(QPoint(0,0));
01869               d->dragRect.moveTopLeft(p);
01870               drawDragRectangle();
01871               currentDragWidget = 0L;
01872               delete childDockWidgetList;
01873               childDockWidgetList = 0L;
01874           }
01875           dragging = false;
01876           dropCancel = true;
01877         }
01878         break;
01879       case QEvent::MouseMove:
01880         if ( dragging ) {
01881 
01882 #ifdef BORDERLESS_WINDOWS
01883 //BEGIN TEST
01884       K3DockWidget *oldMoveWidget;
01885       if (!curdw->parent())
01886       {
01887         curdw->move(QCursor::pos()-d->dragOffset);
01888             pDockWdgAtCursor = findDockWidgetAt( QCursor::pos()-QPoint(0,d->dragOffset.y()+3) );
01889                 oldMoveWidget = currentMoveWidget;
01890       }
01891       else
01892       {
01893             pDockWdgAtCursor = findDockWidgetAt( QCursor::pos() );
01894                 oldMoveWidget = currentMoveWidget;
01895       }
01896 //END TEST
01897 #else
01898       pDockWdgAtCursor = findDockWidgetAt( QCursor::pos() );
01899           K3DockWidget* oldMoveWidget = currentMoveWidget;
01900 #endif
01901 
01902       if ( currentMoveWidget  && pDockWdgAtCursor == currentMoveWidget ) { //move
01903             dragMove( currentMoveWidget, currentMoveWidget->mapFromGlobal( QCursor::pos() ) );
01904             break;
01905           } else {
01906             if (dropCancel && curdw) {
01907               d->dragRect = QRect(curdw->geometry());
01908               QPoint p = curdw->mapToGlobal(QPoint(0,0));
01909               d->dragRect.moveTopLeft(p);
01910             }else
01911               d->dragRect = QRect();
01912 
01913             drawDragRectangle();
01914           }
01915 
01916           if ( !pDockWdgAtCursor && !(curdw->eDocking & (int)K3DockWidget::DockDesktop) ){
01917               // just moving at the desktop
01918               currentMoveWidget = pDockWdgAtCursor;
01919               curPos = K3DockWidget::DockDesktop;
01920           } else {
01921             if ( oldMoveWidget && pDockWdgAtCursor != currentMoveWidget ) { //leave
01922               currentMoveWidget = pDockWdgAtCursor;
01923               curPos = K3DockWidget::DockDesktop;
01924             }
01925           }
01926 
01927           if ( oldMoveWidget != pDockWdgAtCursor && pDockWdgAtCursor ) { //enter pDockWdgAtCursor
01928             currentMoveWidget = pDockWdgAtCursor;
01929             curPos = K3DockWidget::DockDesktop;
01930           }
01931         } else {
01932           if (d->readyToDrag) {
01933             d->readyToDrag = false;
01934           }
01935           if ( (((QMouseEvent*)event)->state() == Qt::LeftButton) &&
01936                (curdw->eDocking != (int)K3DockWidget::DockNone) ) {
01937             startDrag( curdw);
01938           }
01939         }
01940     break;
01941       default:
01942         break;
01943     }
01944   }
01945   return QObject::eventFilter( obj, event );
01946 }
01947 
01948 K3DockWidget* K3DockManager::findDockWidgetAt( const QPoint& pos )
01949 {
01950   dropCancel = true;
01951 
01952   if (!currentDragWidget)
01953     return 0L; // pointer access safety
01954 
01955   if (currentDragWidget->eDocking == (int)K3DockWidget::DockNone ) return 0L;
01956 
01957   QWidget* p = QApplication::topLevelAt( pos );
01958   if ( !p ) {
01959     dropCancel = false;
01960     return 0L;
01961   }
01962 #if defined(_OS_WIN32_) || defined(Q_OS_WIN32)
01963   p = p->topLevelWidget();
01964 #endif
01965   QWidget* w = 0L;
01966   findChildDockWidget( w, p, p->mapFromGlobal(pos) );
01967   if ( !w ){
01968     if ( !p->inherits("K3DockWidget") ) {
01969       return 0L;
01970     }
01971     w = p;
01972   }
01973   if ( findChild<K3DockSplitter*>("_dock_split_")) return 0L;
01974   if ( findChild<K3DockTabGroup*>( "_dock_tab" )) return 0L;
01975   if (dynamic_cast<K3DockContainer*>(w)) return 0L;
01976 
01977   if (!childDockWidgetList) return 0L;
01978   if ( childDockWidgetList->indexOf(w) != -1 ) return 0L;
01979   if ( currentDragWidget->isGroup && ((K3DockWidget*)w)->parentDockTabGroup() ) return 0L;
01980 
01981   K3DockWidget* www = (K3DockWidget*)w;
01982   if ( www->sDocking == (int)K3DockWidget::DockNone ) return 0L;
01983   if( !www->widget )
01984     return 0L;
01985 
01986   K3DockWidget::DockPosition curPos = K3DockWidget::DockDesktop;
01987   QPoint cpos  = www->mapFromGlobal( pos );
01988 
01989   int ww = www->widget->width() / 3;
01990   int hh = www->widget->height() / 3;
01991 
01992   if ( cpos.y() <= hh ){
01993     curPos = K3DockWidget::DockTop;
01994   } else
01995     if ( cpos.y() >= 2*hh ){
01996       curPos = K3DockWidget::DockBottom;
01997     } else
01998       if ( cpos.x() <= ww ){
01999         curPos = K3DockWidget::DockLeft;
02000       } else
02001         if ( cpos.x() >= 2*ww ){
02002           curPos = K3DockWidget::DockRight;
02003         } else
02004             curPos = K3DockWidget::DockCenter;
02005 
02006   if ( !(www->sDocking & (int)curPos) ) return 0L;
02007   if ( !(currentDragWidget->eDocking & (int)curPos) ) return 0L;
02008   if ( www->manager != this ) return 0L;
02009 
02010   dropCancel = false;
02011   return www;
02012 }
02013 
02014 void K3DockManager::findChildDockWidget( QWidget*& ww, const QWidget* p, const QPoint& pos )
02015 {
02016   if ( !p->children().isEmpty() ) {
02017     QWidget *w;
02018     foreach( QObject* o, p->children() )
02019     {
02020       if ( o->isWidgetType() ) {
02021         w = (QWidget*)o;
02022         if ( w->isVisible() && w->geometry().contains(pos) ) {
02023           if ( w->inherits("K3DockWidget") ) ww = w;
02024           findChildDockWidget( ww, w, w->mapFromParent(pos) );
02025           return;
02026         }
02027       }
02028     }
02029   }
02030   return;
02031 }
02032 
02033 void K3DockManager::findChildDockWidget( const QWidget* p, QWidgetList*& list )
02034 {
02035   if ( !p->children().isEmpty() ) {
02036     QWidget *w;
02037     foreach( QObject* o, p->children() )
02038     {
02039       if ( o->isWidgetType() ) {
02040         w = (QWidget*)o;
02041         if ( w->isVisible() ) {
02042           if ( w->inherits("K3DockWidget") ) list->append( w );
02043           findChildDockWidget( w, list );
02044         }
02045       }
02046     }
02047   }
02048   return;
02049 }
02050 
02051 void K3DockManager::startDrag( K3DockWidget* w )
02052 {
02053   if(( w->currentDockPos == K3DockWidget::DockLeft) || ( w->currentDockPos == K3DockWidget::DockRight)
02054    || ( w->currentDockPos == K3DockWidget::DockTop) || ( w->currentDockPos == K3DockWidget::DockBottom)) {
02055     w->prevSideDockPosBeforeDrag = w->currentDockPos;
02056 
02057     if ( w->parentWidget()->inherits("K3DockSplitter") ){
02058       K3DockSplitter* parentSplitterOfDockWidget = (K3DockSplitter*)(w->parentWidget());
02059       w->d->splitPosInPercent = parentSplitterOfDockWidget->separatorPosInPercent();
02060     }
02061   }
02062 
02063   curPos = K3DockWidget::DockDesktop;
02064   dragging = true;
02065 
02066   QApplication::setOverrideCursor(QCursor(Qt::SizeAllCursor));
02067 }
02068 
02069 void K3DockManager::dragMove( K3DockWidget* dw, QPoint pos )
02070 {
02071   QPoint p = dw->mapToGlobal( dw->widget->pos() );
02072   K3DockWidget::DockPosition oldPos = curPos;
02073 
02074   QSize r = dw->widget->size();
02075   if ( dw->parentDockTabGroup() ){
02076     curPos = K3DockWidget::DockCenter;
02077     if ( oldPos != curPos ) {
02078       d->dragRect.setRect( p.x()+2, p.y()+2, r.width()-4, r.height()-4 );
02079     }
02080     return;
02081   }
02082 
02083   int w = r.width() / 3;
02084   int h = r.height() / 3;
02085 
02086   if ( pos.y() <= h ){
02087     curPos = K3DockWidget::DockTop;
02088     w = r.width();
02089   } else
02090     if ( pos.y() >= 2*h ){
02091       curPos = K3DockWidget::DockBottom;
02092       p.setY( p.y() + 2*h );
02093       w = r.width();
02094     } else
02095       if ( pos.x() <= w ){
02096         curPos = K3DockWidget::DockLeft;
02097         h = r.height();
02098       } else
02099         if ( pos.x() >= 2*w ){
02100           curPos = K3DockWidget::DockRight;
02101           p.setX( p.x() + 2*w );
02102           h = r.height();
02103         } else
02104           {
02105             curPos = K3DockWidget::DockCenter;
02106             p.setX( p.x() + w );
02107             p.setY( p.y() + h );
02108           }
02109 
02110   if ( oldPos != curPos ) {
02111     d->dragRect.setRect( p.x(), p.y(), w, h );
02112     drawDragRectangle();
02113   }
02114 }
02115 
02116 
02117 void K3DockManager::cancelDrop()
02118 {
02119   QApplication::restoreOverrideCursor();
02120 
02121   delete childDockWidgetList;
02122   childDockWidgetList = 0L;
02123 
02124   d->dragRect = QRect();  // cancel drawing
02125   drawDragRectangle();    // only the old rect will be deleted
02126 }
02127 
02128 
02129 void K3DockManager::drop()
02130 {
02131   d->dragRect = QRect();  // cancel drawing
02132   drawDragRectangle();    // only the old rect will be deleted
02133 
02134   QApplication::restoreOverrideCursor();
02135 
02136   delete childDockWidgetList;
02137   childDockWidgetList = 0L;
02138 
02139   if ( dropCancel ) return;
02140   if ( !currentMoveWidget && (!(currentDragWidget->eDocking & (int)K3DockWidget::DockDesktop)) ) {
02141     d->dragRect = QRect();  // cancel drawing
02142     drawDragRectangle();    // only the old rect will be deleted
02143     return;
02144   }
02145   if ( !currentMoveWidget && !currentDragWidget->parent() ) {
02146     currentDragWidget->move( QCursor::pos() - d->dragOffset );
02147   }
02148   else {
02149     // curPos is the current target DockPosition.
02150     // currentDragWidget->prevSideDockPosBeforeDrag is where the dockwidget comes from.
02151     // currentDragWidget->formerDockPos is the position *before* the dockwidget was in
02152     // position currentDragWidget->prevSideDockPosBeforeDrag.
02153     int splitPos = currentDragWidget->d->splitPosInPercent;
02154     K3DockWidget::DockPosition previousPosition = currentDragWidget->prevSideDockPosBeforeDrag;
02155 
02156 //    kDebug() << splitPos;
02157 //    kDebug() << "curPos: " << curPos;
02158 //    kDebug() << "formerDockPos: " << currentDragWidget->formerDockPos;
02159 //    kDebug() << "prevSideDockPosBeforeDrag: " << currentDragWidget->prevSideDockPosBeforeDrag;
02160 
02161     // Now we *need* to "invert" the procentual value, if the dockwidget moves from top/left
02162     // to bottom/right or vice versa. This keeps the dockwidget's size on its new position.
02163     // A special case is, when the dock position was DockNone, then we have to look for the
02164     // formerDockPos to get things right.
02165     if( (curPos != previousPosition)
02166        && (curPos != K3DockWidget::DockCenter) && (curPos != K3DockWidget::DockDesktop)) {
02167 
02168       if (previousPosition == K3DockWidget::DockNone)
02169         previousPosition = currentDragWidget->formerDockPos;
02170 
02171       switch( previousPosition ) {
02172       case K3DockWidget::DockLeft:
02173         if(curPos != K3DockWidget::DockTop && curPos != K3DockWidget::DockLeft)
02174           splitPos = 100 - splitPos;
02175         break;
02176 
02177       case K3DockWidget::DockRight:
02178         if(curPos != K3DockWidget::DockBottom && curPos != K3DockWidget::DockRight)
02179           splitPos = 100 - splitPos;
02180         break;
02181 
02182       case K3DockWidget::DockTop:
02183         if(curPos != K3DockWidget::DockLeft && curPos != K3DockWidget::DockTop )
02184           splitPos = 100 - splitPos;
02185         break;
02186 
02187       case K3DockWidget::DockBottom:
02188         if(curPos != K3DockWidget::DockRight && curPos != K3DockWidget::DockBottom )
02189           splitPos = 100 - splitPos;
02190         break;
02191 
02192       default: break;
02193       }
02194     }
02195     // set new prevSideDockPosBeforeDrag
02196     currentDragWidget->prevSideDockPosBeforeDrag = curPos;
02197     currentDragWidget->manualDock( currentMoveWidget, curPos , splitPos, QCursor::pos() - d->dragOffset );
02198     currentDragWidget->makeDockVisible();
02199   }
02200 }
02201 
02202 
02203 static QDomElement createStringEntry(QDomDocument &doc, const QString &tagName, const QString &str)
02204 {
02205     QDomElement el = doc.createElement(tagName);
02206 
02207     el.appendChild(doc.createTextNode(str));
02208     return el;
02209 }
02210 
02211 
02212 static QDomElement createBoolEntry(QDomDocument &doc, const QString &tagName, bool b)
02213 {
02214     return createStringEntry(doc, tagName, QLatin1String(b? "true" : "false"));
02215 }
02216 
02217 
02218 static QDomElement createNumberEntry(QDomDocument &doc, const QString &tagName, int n)
02219 {
02220     return createStringEntry(doc, tagName, QString::number(n));
02221 }
02222 
02223 
02224 static QDomElement createRectEntry(QDomDocument &doc, const QString &tagName, const QRect &rect)
02225 {
02226     QDomElement el = doc.createElement(tagName);
02227 
02228     QDomElement xel = doc.createElement("x");
02229     xel.appendChild(doc.createTextNode(QString::number(rect.x())));
02230     el.appendChild(xel);
02231     QDomElement yel = doc.createElement("y");
02232     yel.appendChild(doc.createTextNode(QString::number(rect.y())));
02233     el.appendChild(yel);
02234     QDomElement wel = doc.createElement("width");
02235     wel.appendChild(doc.createTextNode(QString::number(rect.width())));
02236     el.appendChild(wel);
02237     QDomElement hel = doc.createElement("height");
02238     hel.appendChild(doc.createTextNode(QString::number(rect.height())));
02239     el.appendChild(hel);
02240 
02241     return el;
02242 }
02243 
02244 
02245 static QDomElement createListEntry(QDomDocument &doc, const QString &tagName,
02246                                    const QString &subTagName, const QStringList &list)
02247 {
02248   QDomElement el = doc.createElement(tagName);
02249 
02250   foreach( const QString &s, list )
02251   {
02252     QDomElement subel = doc.createElement(subTagName);
02253     subel.appendChild(doc.createTextNode(s));
02254     el.appendChild(subel);
02255   }
02256 
02257   return el;
02258 }
02259 
02260 
02261 static QString stringEntry(QDomElement &base, const QString &tagName)
02262 {
02263     return base.namedItem(tagName).firstChild().toText().data();
02264 }
02265 
02266 
02267 static bool boolEntry(QDomElement &base, const QString &tagName)
02268 {
02269     return base.namedItem(tagName).firstChild().toText().data() == "true";
02270 }
02271 
02272 
02273 static int numberEntry(QDomElement &base, const QString &tagName)
02274 {
02275     return stringEntry(base, tagName).toInt();
02276 }
02277 
02278 
02279 static QRect rectEntry(QDomElement &base, const QString &tagName)
02280 {
02281     QDomElement el = base.namedItem(tagName).toElement();
02282 
02283     int x = numberEntry(el, "x");
02284     int y = numberEntry(el, "y");
02285     int width = numberEntry(el, "width");
02286     int height = numberEntry(el,  "height");
02287 
02288     return QRect(x, y, width, height);
02289 }
02290 
02291 
02292 static Q3StrList listEntry(QDomElement &base, const QString &tagName, const QString &subTagName)
02293 {
02294     Q3StrList list;
02295 
02296     for( QDomNode n = base.namedItem(tagName).firstChild(); !n.isNull(); n = n.nextSibling() )
02297     {
02298         QDomElement subel = n.toElement();
02299         if (subel.tagName() == subTagName)
02300             list.append(subel.firstChild().toText().data().toLatin1().constData());
02301     }
02302 
02303     return list;
02304 }
02305 
02306 
02307 void K3DockManager::writeConfig(QDomElement &base)
02308 {
02309     // First of all, clear the tree under base
02310     while (!base.firstChild().isNull())
02311         base.removeChild(base.firstChild());
02312     QDomDocument doc = base.ownerDocument();
02313 
02314     QStringList nameList;
02315     QString mainWidgetStr;
02316 
02317     // collect widget names
02318     QStringList nList;
02319     Q_FOREACH( QObject *o, *childDock )
02320     {
02321 #ifdef __GNUC__ // ### KDE4
02322 # warning "Can dw be 0 and what should we do in the case that it is?"
02323 #endif
02324         K3DockWidget* dw = qobject_cast<K3DockWidget*> ( o );
02325         if ( !dw )
02326             continue;
02327         if ( dw->parent() == main )
02328             mainWidgetStr = dw->objectName();
02329         nList.append( dw->objectName() );
02330     }
02331 
02332     for (QObjectList::iterator it = d->containerDocks.begin();it != d->containerDocks.end();++it)
02333     {
02334         K3DockContainer* dc = dynamic_cast<K3DockContainer*>(((K3DockWidget*)(*it))->widget);
02335         if (dc) {
02336                 dc->prepareSave(nList);
02337         }
02338     }
02339 
02340     QStringList::Iterator nListIt=nList.begin();
02341     while ( nListIt!=nList.end() ) {
02342         K3DockWidget *obj = getDockWidgetFromName( *nListIt);
02343         if ((obj->isGroup && (!obj->d->isContainer)) && (nameList.indexOf( obj->firstName) == -1
02344                              || nameList.indexOf(obj->lastName) == -1)) {
02345             // Skip until children are saved (why?)
02346             ++nListIt;
02347 //            nList.next();
02348 //falk?            if ( !nList.current() ) nList.first();
02349             continue;
02350         }
02351 
02352         QDomElement groupEl;
02353     if (obj->d->isContainer) {
02354             K3DockContainer* x = dynamic_cast<K3DockContainer*>(obj->widget);
02355             if (x) {
02356             groupEl=doc.createElement("dockContainer");
02357                 x->save(groupEl);
02358             }
02359         } else
02360         if (obj->isGroup) {
02362             groupEl = doc.createElement("splitGroup");
02363 
02364             groupEl.appendChild(createStringEntry(doc, "firstName", obj->firstName));
02365             groupEl.appendChild(createStringEntry(doc, "secondName", obj->lastName));
02366             groupEl.appendChild(createNumberEntry(doc, "orientation", (int)obj->splitterOrientation));
02367             groupEl.appendChild(createNumberEntry(doc, "separatorPos", ((K3DockSplitter*)obj->widget)->separatorPosInPercent()));
02368         } else if (obj->isTabGroup) {
02370             groupEl = doc.createElement("tabGroup");
02371 
02372             QStringList list;
02373             for ( int i = 0; i < ((K3DockTabGroup*)obj->widget)->count(); ++i )
02374                 list.append( ((K3DockTabGroup*)obj->widget)->page( i )->name() );
02375             groupEl.appendChild(createListEntry(doc, "tabs", "tab", list));
02376             groupEl.appendChild(createNumberEntry(doc, "currentTab", ((K3DockTabGroup*)obj->widget)->currentPageIndex()));
02377             if (!obj->parent()) {
02378                 groupEl.appendChild(createStringEntry(doc, "dockBackTo", obj->formerBrotherDockWidget ? obj->formerBrotherDockWidget->name() : ""));
02379                 groupEl.appendChild(createNumberEntry(doc, "dockBackToPos", obj->formerDockPos));
02380             }
02381         } else {
02383             groupEl = doc.createElement("dock");
02384             groupEl.appendChild(createStringEntry(doc, "tabCaption", obj->tabPageLabel()));
02385             groupEl.appendChild(createStringEntry(doc, "tabToolTip", obj->toolTipString()));
02386             if (!obj->parent()) {
02387                 groupEl.appendChild(createStringEntry(doc, "dockBackTo", obj->formerBrotherDockWidget ? obj->formerBrotherDockWidget->name() : ""));
02388                 groupEl.appendChild(createNumberEntry(doc, "dockBackToPos", obj->formerDockPos));
02389             }
02390         }
02391 
02392         groupEl.appendChild(createStringEntry(doc, "name", QLatin1String(obj->name())));
02393         groupEl.appendChild(createBoolEntry(doc, "hasParent", obj->parent()));
02394         if ( !obj->parent() ) {
02395             groupEl.appendChild(createRectEntry(doc, "geometry", QRect(main->frameGeometry().topLeft(), main->size())));
02396             groupEl.appendChild(createBoolEntry(doc, "visible", obj->isVisible()));
02397         }
02398         if (obj->header && obj->header->inherits("K3DockWidgetHeader")) {
02399             K3DockWidgetHeader *h = static_cast<K3DockWidgetHeader*>(obj->header);
02400             groupEl.appendChild(createBoolEntry(doc, "dragEnabled", h->dragEnabled()));
02401         }
02402 
02403         base.appendChild(groupEl);
02404         nameList.append(obj->name());
02405         nList.erase(nListIt);
02406         nListIt=nList.begin();
02407     }
02408 
02409     if (main->inherits("K3DockMainWindow")) {
02410         K3DockMainWindow *dmain = (K3DockMainWindow*)main;
02411         QString centralWidgetStr = QString(dmain->centralWidget()? dmain->centralWidget()->name() : "");
02412         base.appendChild(createStringEntry(doc, "centralWidget", centralWidgetStr));
02413         QString mainDockWidgetStr = QString(dmain->getMainDockWidget()? dmain->getMainDockWidget()->name() : "");
02414         base.appendChild(createStringEntry(doc, "mainDockWidget", mainDockWidgetStr));
02415     } else {
02416         base.appendChild(createStringEntry(doc, "mainWidget", mainWidgetStr));
02417     }
02418 
02419     base.appendChild(createRectEntry(doc, "geometry", QRect(main->frameGeometry().topLeft(), main->size())));
02420 }
02421 
02422 
02423 void K3DockManager::readConfig(QDomElement &base)
02424 {
02425     if (base.namedItem("group").isNull()
02426         && base.namedItem("tabgroup").isNull()
02427         && base.namedItem("dock").isNull()
02428     && base.namedItem("dockContainer").isNull()) {
02429         activate();
02430         return;
02431     }
02432 
02433     autoCreateDock = new QObjectList;
02434 
02435     bool isMainVisible = main->isVisible();
02436     main->hide();
02437 
02438     QObjectList::iterator it = childDock->begin();
02439     K3DockWidget *obj1;
02440     while ( it != childDock->end() ) {
02441     obj1=(K3DockWidget*)(*it);
02442         if ( !obj1->isGroup && !obj1->isTabGroup ) {
02443             if ( obj1->parent() )
02444                 obj1->undock();
02445             else
02446                 obj1->hide();
02447         }
02448         ++it;
02449     }
02450 
02451     // firstly, recreate all common dockwidgets
02452     for( QDomNode n = base.firstChild(); !n.isNull(); n = n.nextSibling() )
02453     {
02454         QDomElement childEl = n.toElement();
02455         if (childEl.tagName() != "dock") continue;
02456 
02457         // Read an ordinary dock widget
02458         K3DockWidget *obj = getDockWidgetFromName(stringEntry(childEl, "name"));
02459         obj->setTabPageLabel(stringEntry(childEl, "tabCaption"));
02460         obj->setToolTipString(stringEntry(childEl, "tabToolTip"));
02461 
02462         if (!boolEntry(childEl, "hasParent")) {
02463             QRect r = rectEntry(childEl, "geometry");
02464             obj = getDockWidgetFromName(stringEntry(childEl, "name"));
02465             obj->applyToWidget(0);
02466             obj->setGeometry(r);
02467             if (boolEntry(childEl, "visible"))
02468                 obj->QWidget::show();
02469         }
02470 
02471         if (obj && obj->header && obj->header->inherits("K3DockWidgetHeader")) {
02472             K3DockWidgetHeader *h = static_cast<K3DockWidgetHeader*>(obj->header);
02473             h->setDragEnabled(boolEntry(childEl, "dragEnabled"));
02474         }
02475     }
02476 
02477     // secondly, now iterate again and create the groups and tabwidgets, apply the dockwidgets to them
02478     for( QDomNode n = base.firstChild(); !n.isNull(); n = n.nextSibling() )
02479     {
02480         QDomElement childEl = n.toElement();
02481         if (childEl.isNull()) continue;
02482 
02483         K3DockWidget *obj = 0;
02484 
02485     if (childEl.tagName() == "dockContainer") {
02486 
02487         K3DockWidget *cont=getDockWidgetFromName(stringEntry(childEl, "name"));
02488         kDebug(282)<<"dockContainer: "<<stringEntry(childEl,"name");
02489         if (!(cont->d->isContainer)) {
02490             kDebug(282)<<"restoration of dockContainer is only supported for already existing dock containers";
02491         } else {
02492             K3DockContainer *dc=dynamic_cast<K3DockContainer*>(cont->getWidget());
02493             if (!dc) kDebug(282)<<"Error while trying to handle dockcontainer configuration restoration";
02494                 else {
02495                     dc->load(childEl);
02496                     removeFromAutoCreateList(cont);
02497                 }
02498 
02499         }
02500     }
02501     else
02502         if (childEl.tagName() == "splitGroup") {
02503             // Read a group
02504             QString name = stringEntry(childEl, "name");
02505             QString firstName = stringEntry(childEl, "firstName");
02506             QString secondName = stringEntry(childEl, "secondName");
02507             int orientation = numberEntry(childEl, "orientation");
02508             int separatorPos = numberEntry(childEl, "separatorPos");
02509 
02510             K3DockWidget *first = getDockWidgetFromName(firstName);
02511             K3DockWidget *second = getDockWidgetFromName(secondName);
02512             if (first && second) {
02513                 obj = first->manualDock(second,
02514                                         (orientation == (int)Qt::Vertical)? K3DockWidget::DockLeft : K3DockWidget::DockTop,
02515                                         separatorPos);
02516                 if (obj)
02517                     obj->setName(name.toLatin1().constData());
02518             }
02519         } else if (childEl.tagName() == "tabGroup") {
02520             // Read a tab group
02521             QString name = stringEntry(childEl, "name");
02522             Q3StrList list = listEntry(childEl, "tabs", "tab");
02523 
02524             K3DockWidget *d1 = getDockWidgetFromName( list.first() );
02525             list.next();
02526             K3DockWidget *d2 = getDockWidgetFromName( list.current() );
02527 
02528             K3DockWidget *obj = d2->manualDock( d1, K3DockWidget::DockCenter );
02529             if (obj) {
02530                 K3DockTabGroup *tab = (K3DockTabGroup*)obj->widget;
02531                 list.next();
02532                 while (list.current() && obj) {
02533                     K3DockWidget *tabDock = getDockWidgetFromName(list.current());
02534                     obj = tabDock->manualDock(d1, K3DockWidget::DockCenter);
02535                     list.next();
02536                 }
02537                 if (obj) {
02538                     obj->setName(name.toLatin1().constData());
02539                     tab->showPage(tab->page(numberEntry(childEl, "currentTab")));
02540                 }
02541             }
02542         } else {
02543             continue;
02544         }
02545 
02546         if (!boolEntry(childEl, "hasParent")) {
02547             QRect r = rectEntry(childEl, "geometry");
02548             obj = getDockWidgetFromName(stringEntry(childEl, "name"));
02549             obj->applyToWidget(0);
02550             obj->setGeometry(r);
02551             if (boolEntry(childEl, "visible"))
02552                 obj->QWidget::show();
02553         }
02554 
02555         if (obj && obj->header && obj->header->inherits("K3DockWidgetHeader")) {
02556             K3DockWidgetHeader *h = static_cast<K3DockWidgetHeader*>(obj->header);
02557             h->setDragEnabled(boolEntry(childEl, "dragEnabled"));
02558         }
02559     }
02560 
02561     // thirdly, now that all ordinary dockwidgets are created,
02562     // iterate them again and link them with their corresponding dockwidget for the dockback action
02563     for( QDomNode n = base.firstChild(); !n.isNull(); n = n.nextSibling() )
02564     {
02565         QDomElement childEl = n.toElement();
02566 
02567         if (childEl.tagName() != "dock" && childEl.tagName() != "tabGroup")
02568             continue;
02569 
02570         K3DockWidget *obj = 0;
02571 
02572         if (!boolEntry(childEl, "hasParent")) {
02573             // Read a common toplevel dock widget
02574             obj = getDockWidgetFromName(stringEntry(childEl, "name"));
02575             QString name = stringEntry(childEl, "dockBackTo");
02576             if (!name.isEmpty()) {
02577                 obj->setFormerBrotherDockWidget(getDockWidgetFromName(name));
02578             }
02579             obj->formerDockPos = K3DockWidget::DockPosition(numberEntry(childEl, "dockBackToPos"));
02580             obj->updateHeader();
02581         }
02582     }
02583 
02584     if (main->inherits("K3DockMainWindow")) {
02585         K3DockMainWindow *dmain = (K3DockMainWindow*)main;
02586 
02587         QString mv = stringEntry(base, "centralWidget");
02588         if (!mv.isEmpty() && getDockWidgetFromName(mv) ) {
02589             K3DockWidget *mvd  = getDockWidgetFromName(mv);
02590             mvd->applyToWidget(dmain);
02591             mvd->show();
02592             dmain->setCentralWidget(mvd);
02593         }
02594         QString md = stringEntry(base, "mainDockWidget");
02595         if (!md.isEmpty() && getDockWidgetFromName(md)) {
02596             K3DockWidget *mvd  = getDockWidgetFromName(md);
02597             dmain->setMainDockWidget(mvd);
02598         }
02599     } else {
02600         QString mv = stringEntry(base, "mainWidget");
02601         if (!mv.isEmpty() && getDockWidgetFromName(mv)) {
02602             K3DockWidget *mvd  = getDockWidgetFromName(mv);
02603             mvd->applyToWidget(main);
02604             mvd->show();
02605         }
02606 
02607         // only resize + move non-mainwindows
02608         QRect mr = rectEntry(base, "geometry");
02609         main->move(mr.topLeft());
02610         main->resize(mr.size());
02611     }
02612 
02613     if (isMainVisible)
02614         main->show();
02615 
02616     if (d->m_readDockConfigMode == WrapExistingWidgetsOnly) {
02617         finishReadDockConfig(); // remove empty dockwidgets
02618     }
02619 }
02620 
02621 void K3DockManager::removeFromAutoCreateList(K3DockWidget* pDockWidget)
02622 {
02623     if (!autoCreateDock) return;
02624     autoCreateDock->removeAt(autoCreateDock->indexOf(pDockWidget));
02625 }
02626 
02627 void K3DockManager::finishReadDockConfig()
02628 {
02629     delete autoCreateDock;
02630     autoCreateDock = 0;
02631 }
02632 
02633 void K3DockManager::setReadDockConfigMode(int mode)
02634 {
02635     d->m_readDockConfigMode = mode;
02636 }
02637 
02638 #ifndef NO_KDE2
02639 void K3DockManager::writeConfig( KConfig* c, const QString &_group )
02640 {
02641   //debug("BEGIN Write Config");
02642   if (!c) {
02643       c = KGlobal::config().data();
02644   }
02645   QString group = _group.isEmpty() ? "dock_setting_default" : _group;
02646 
02647   KConfigGroup cg(c, group);
02648   cg.writeEntry( "Version", DOCK_CONFIG_VERSION );
02649 
02650   QStringList nameList;
02651   QStringList findList;
02652   K3DockWidget* obj;
02653 
02654   // collect K3DockWidget's name
02655   QStringList nList;
02656   Q_FOREACH( QObject* o, *childDock )
02657   {
02658 #ifdef __GNUC__ // ### KDE4
02659 # warning "Can obj be 0 and what should we do in the case that it is?"
02660 #endif
02661     obj = qobject_cast<K3DockWidget*> ( o );
02662     if ( !obj )
02663       continue;
02664     //debug("  +Add subdock %s", obj->objectName());
02665     nList.append( obj->objectName() );
02666     if ( obj->parent() == main )
02667       cg.writeEntry( "Main:view", obj->objectName() );
02668   }
02669 
02670 //  kDebug(282)<<QString("list size: %1").arg(nList.count());
02671   for (QObjectList::iterator it = d->containerDocks.begin() ;it != d->containerDocks.end(); ++it)
02672   {
02673         K3DockContainer* dc = dynamic_cast<K3DockContainer*>(((K3DockWidget*)(*it))->widget);
02674     if (dc) {
02675         dc->prepareSave(nList);
02676     }
02677   }
02678 //  kDebug(282)<<QString("new list size: %1").arg(nList.count());
02679 
02680   QStringList::Iterator nListIt=nList.begin();
02681   while ( nListIt!=nList.end() ){
02682     //debug("  -Try to save %s", nList.current());
02683     obj = getDockWidgetFromName( *nListIt );
02684     QString cname = obj->name();
02685     if ( obj->header ){
02686       obj->header->saveConfig( &cg );
02687     }
02688     if (obj->d->isContainer) {
02689        K3DockContainer* x = dynamic_cast<K3DockContainer*>(obj->widget);
02690        if (x) {
02691           x->save(c,group);
02692        }
02693     }
02694 /*************************************************************************************************/
02695     if ( obj->isGroup ){
02696       if ( (findList.indexOf( obj->firstName ) != -1) && (findList.indexOf( obj->lastName ) != -1 )){
02697 
02698         cg.writeEntry( cname+":type", "GROUP");
02699         if ( !obj->parent() ){
02700           cg.writeEntry( cname+":parent", "___null___");
02701           cg.writeEntry( cname+":geometry", QRect(obj->frameGeometry().topLeft(), obj->size()) );
02702           cg.writeEntry( cname+":visible", QVariant(obj->isVisible()) );
02703         } else {
02704           cg.writeEntry( cname+":parent", "yes");
02705         }
02706         cg.writeEntry( cname+":first_name", obj->firstName );
02707         cg.writeEntry( cname+":last_name", obj->lastName );
02708         cg.writeEntry( cname+":orientation", QVariant(obj->splitterOrientation) );
02709         cg.writeEntry( cname+":sepPos", QVariant(((K3DockSplitter*)obj->widget)->separatorPosInPercent()) );
02710 
02711         nameList.append( obj->name() );
02712         findList.append( obj->name() );
02713         //debug("  Save %s", nList.current());
02714         nList.erase(nListIt);
02715         nListIt=nList.begin(); //nList.first();
02716       } else {
02717 /*************************************************************************************************/
02718         //debug("  Skip %s", nList.current());
02719         //if ( findList.find( obj->firstName ) == -1 )
02720         //  debug("  ? Not found %s", obj->firstName);
02721         //if ( findList.find( obj->lastName ) == -1 )
02722         //  debug("  ? Not found %s", obj->lastName);
02723         ++nListIt;
02724         // if ( !nList.current() ) nList.first();
02725     if (nListIt==nList.end()) nListIt=nList.begin();
02726       }
02727     } else {
02728 /*************************************************************************************************/
02729       if ( obj->isTabGroup){
02730         cg.writeEntry( cname+":type", "TAB_GROUP");
02731         if ( !obj->parent() ){
02732           cg.writeEntry( cname+":parent", "___null___");
02733           cg.writeEntry( cname+":geometry", QRect(obj->frameGeometry().topLeft(), obj->size()) );
02734           cg.writeEntry( cname+":visible", QVariant(obj->isVisible()) );
02735           cg.writeEntry( cname+":dockBackTo", obj->formerBrotherDockWidget ? obj->formerBrotherDockWidget->name() : "");
02736           cg.writeEntry( cname+":dockBackToPos", QVariant(obj->formerDockPos) );
02737         } else {
02738           cg.writeEntry( cname+":parent", "yes");
02739         }
02740         QStringList list;
02741         for ( int i = 0; i < ((K3DockTabGroup*)obj->widget)->count(); ++i )
02742           list.append( ((K3DockTabGroup*)obj->widget)->page( i )->name() );
02743         cg.writeEntry( cname+":tabNames", list );
02744         cg.writeEntry( cname+":curTab", QVariant(((K3DockTabGroup*)obj->widget)->currentPageIndex()) );
02745 
02746         nameList.append( obj->name() );
02747         findList.append( obj->name() ); // not really need !!!
02748         //debug("  Save %s", nList.current());
02749         nList.erase(nListIt);
02750         nListIt=nList.begin();
02751       } else {
02752 /*************************************************************************************************/
02753         cg.writeEntry( cname+":tabCaption", obj->tabPageLabel());
02754         cg.writeEntry( cname+":tabToolTip", obj->toolTipString());
02755         if ( !obj->parent() ){
02756           cg.writeEntry( cname+":type", "NULL_DOCK");
02757           cg.writeEntry( cname+":geometry", QRect(obj->frameGeometry().topLeft(), obj->size()) );
02758           cg.writeEntry( cname+":visible", QVariant(obj->isVisible()) );
02759           cg.writeEntry( cname+":dockBackTo", obj->formerBrotherDockWidget ? obj->formerBrotherDockWidget->name() : "");
02760           cg.writeEntry( cname+":dockBackToPos", QVariant(obj->formerDockPos) );
02761         } else {
02762           cg.writeEntry( cname+":type", "DOCK");
02763         }
02764         nameList.append( cname.toLatin1().constData() );
02765         //debug("  Save %s", nList.current());
02766         findList.append( obj->name() );
02767         nList.erase(nListIt);
02768         nListIt=nList.begin();
02769       }
02770     }
02771   }
02772   cg.writeEntry( "NameList", nameList );
02773 
02774   cg.writeEntry( "Main:Geometry", QRect(main->frameGeometry().topLeft(), main->size()) );
02775   cg.writeEntry( "Main:visible", QVariant(main->isVisible()) ); // curently nou use
02776 
02777   if ( main->inherits("K3DockMainWindow") ){
02778     K3DockMainWindow* dmain = (K3DockMainWindow*)main;
02779     // for K3DockMainWindow->setView() in readConfig()
02780     cg.writeEntry( "Main:view", dmain->centralWidget() ? dmain->centralWidget()->name():"" );
02781     cg.writeEntry( "Main:dock", dmain->getMainDockWidget()     ? dmain->getMainDockWidget()->name()    :"" );
02782   }
02783 
02784   c->sync();
02785   //debug("END Write Config");
02786 }
02787 #include <qmessagebox.h>
02788 void K3DockManager::readConfig( KConfig* c, const QString &_group )
02789 {
02790   if (!c) {
02791       c = KGlobal::config().data();
02792   }
02793   QString group = _group.isEmpty() ? "dock_setting_default" : _group;
02794 
02795   KConfigGroup cg(c, group );
02796   QStringList nameList;
02797   nameList = cg.readEntry( "NameList", QStringList() );
02798   QString ver = cg.readEntry( "Version", "0.0.1" );
02799   if ( nameList.isEmpty() || ver != DOCK_CONFIG_VERSION ){
02800     activate();
02801     return;
02802   }
02803 
02804   autoCreateDock = new QObjectList();
02805 
02806   bool isMainVisible = main->isVisible();
02807  // if (isMainVisible)  // CCC
02808   //QMessageBox::information(0,"","hallo");
02809 //COMMENTED4TESTING  main->hide();
02810 
02811   QObjectList::iterator it = childDock->begin();
02812   K3DockWidget * obj;
02813 
02814   while ( it != childDock->end() ){
02815     obj = (K3DockWidget*)(*it);
02816     ++it;
02817     if ( !obj->isGroup && !obj->isTabGroup ) {
02818       if ( obj->parent() ) obj->undock(); else obj->hide();
02819     }
02820   }
02821 
02822   // firstly, only the common dockwidgets,
02823   // they must be restored before e.g. tabgroups are restored
02824   foreach( const QString &oname, nameList )
02825   {
02826     cg = KConfigGroup( c, group );
02827     QString type = cg.readEntry( oname + ":type", QString() );
02828     obj = 0L;
02829 
02830     if ( type == "NULL_DOCK" || cg.readEntry( oname + ":parent", QString() ) == "___null___" ){
02831       QRect r = cg.readEntry( oname + ":geometry",QRect() );
02832       obj = getDockWidgetFromName( oname );
02833       obj->applyToWidget( 0L );
02834       obj->setGeometry(r);
02835 
02836       cg = KConfigGroup( c, group );
02837       obj->setTabPageLabel(cg.readEntry( oname + ":tabCaption", QString() ));
02838       obj->setToolTipString(cg.readEntry( oname + ":tabToolTip", QString() ));
02839       if ( cg.readEntry( oname + ":visible",QVariant(false) ).toBool() ){
02840         obj->QWidget::show();
02841       }
02842     }
02843 
02844     if ( type == "DOCK"  ){
02845       obj = getDockWidgetFromName( oname );
02846       obj->setTabPageLabel(cg.readEntry( oname + ":tabCaption", QString() ));
02847       obj->setToolTipString(cg.readEntry( oname + ":tabToolTip", QString() ));
02848     }
02849 
02850     if (obj && obj->d->isContainer) {
02851         dynamic_cast<K3DockContainer*>(obj->widget)->load(c,group);
02852         removeFromAutoCreateList(obj);
02853     }
02854     if ( obj && obj->header){
02855       obj->header->loadConfig( &cg );
02856     }
02857   }
02858 
02859   // secondly, after the common dockwidgets, restore the groups and tabgroups
02860   foreach( const QString &oname, nameList )
02861   {
02862     cg = KConfigGroup( c, group );
02863     QString type = cg.readEntry( oname + ":type", QString() );
02864     obj = 0L;
02865 
02866     if ( type == "GROUP" ){
02867       K3DockWidget* first = getDockWidgetFromName( cg.readEntry( oname + ":first_name", QString() ) );
02868       K3DockWidget* last  = getDockWidgetFromName( cg.readEntry( oname + ":last_name",  QString() ) );
02869       int sepPos = cg.readEntry( oname + ":sepPos",0 );
02870 
02871       Qt::Orientation p = (Qt::Orientation)cg.readEntry( oname + ":orientation",0 );
02872       if ( first  && last ){
02873         obj = first->manualDock( last, ( p == Qt::Vertical ) ? K3DockWidget::DockLeft : K3DockWidget::DockTop, sepPos );
02874         if (obj){
02875           obj->setName( oname.toLatin1().constData() );
02876         }
02877       }
02878     }
02879 
02880     if ( type == "TAB_GROUP" ){
02881       K3DockWidget* tabDockGroup = 0L;
02882       const QStringList list = cg.readEntry( oname+":tabNames",QStringList() );
02883       QStringList::const_iterator listit = list.begin();
02884       K3DockWidget* d1 = getDockWidgetFromName( *listit++ );
02885       K3DockWidget* d2 = getDockWidgetFromName( *listit++ );
02886       tabDockGroup = d2->manualDock( d1, K3DockWidget::DockCenter );
02887       if ( tabDockGroup ){
02888         K3DockTabGroup* tab = dynamic_cast<K3DockTabGroup*>(tabDockGroup->widget);
02889         while ( listit != list.end() && tabDockGroup ){
02890           K3DockWidget* tabDock = getDockWidgetFromName( *listit++ );
02891           tabDockGroup = tabDock->manualDock( d1, K3DockWidget::DockCenter );
02892         }
02893         if ( tabDockGroup ){
02894           tabDockGroup->setName( oname.toLatin1().constData() );
02895           cg = KConfigGroup( c, group );
02896           if (tab)
02897             tab->showPage( tab->page( cg.readEntry( oname+":curTab",0 ) ) );
02898         }
02899       }
02900       obj = tabDockGroup;
02901     }
02902 
02903     if (obj && obj->d->isContainer)  dynamic_cast<K3DockContainer*>(obj->widget)->load(c,group);
02904     if ( obj && obj->header){
02905       obj->header->loadConfig( &cg );
02906     }
02907   }
02908 
02909   // thirdly, now that all ordinary dockwidgets are created,
02910   // iterate them again and link the toplevel ones of them with their corresponding dockwidget for the dockback action
02911   foreach( const QString &oname, nameList )
02912   {
02913     cg = KConfigGroup( c, group );
02914     QString type = cg.readEntry( oname + ":type", QString() );
02915     obj = 0L;
02916 
02917     if ( type == "NULL_DOCK" || cg.readEntry( oname + ":parent", QString() ) == "___null___" ){
02918       obj = getDockWidgetFromName( oname );
02919       cg = KConfigGroup( c, group );
02920       QString name = cg.readEntry( oname + ":dockBackTo", QString() );
02921       if (!name.isEmpty()) {
02922           obj->setFormerBrotherDockWidget(getDockWidgetFromName( name ));
02923       }
02924       obj->formerDockPos = K3DockWidget::DockPosition(cg.readEntry( oname + ":dockBackToPos",0 ));
02925     }
02926   }
02927 
02928   if ( main->inherits("K3DockMainWindow") ){
02929     K3DockMainWindow* dmain = (K3DockMainWindow*)main;
02930 
02931     cg = KConfigGroup( c, group );
02932     QString mv = cg.readEntry( "Main:view" );
02933     if ( !mv.isEmpty() && getDockWidgetFromName( mv ) ){
02934       K3DockWidget* mvd  = getDockWidgetFromName( mv );
02935       mvd->applyToWidget( dmain );
02936       mvd->show();
02937       dmain->setView( mvd );
02938     }
02939     cg = KConfigGroup( c, group );
02940     QString md = cg.readEntry( "Main:dock" );
02941     if ( !md.isEmpty() && getDockWidgetFromName( md ) ){
02942       K3DockWidget* mvd  = getDockWidgetFromName( md );
02943       dmain->setMainDockWidget( mvd );
02944     }
02945   } else {
02946     cg = KConfigGroup( c, group );
02947     QString mv = cg.readEntry( "Main:view" );
02948     if ( !mv.isEmpty() && getDockWidgetFromName( mv ) ){
02949       K3DockWidget* mvd  = getDockWidgetFromName( mv );
02950       mvd->applyToWidget( main );
02951       mvd->show();
02952     }
02953 
02954   }
02955 
02956   // delete all autocreate dock
02957   if (d->m_readDockConfigMode == WrapExistingWidgetsOnly) {
02958     finishReadDockConfig(); // remove empty dockwidgets
02959   }
02960 
02961   cg = KConfigGroup( c, group );
02962 
02963   QRect mr = cg.readEntry("Main:Geometry", QRect());
02964 
02965   if (!main->inherits("K3DockMainWindow"))
02966     main->move(mr.topLeft());
02967 
02968   main->resize(mr.size());
02969 
02970   if ( isMainVisible ) main->show();
02971 }
02972 #endif
02973 
02974 
02975 void K3DockManager::dumpDockWidgets() {
02976   QObjectList::iterator it = childDock->begin();
02977   K3DockWidget * obj;
02978   while ( it != childDock->end() ) {
02979     obj = (K3DockWidget*)(*it);
02980     ++it;
02981     kDebug(282) << "K3DockManager::dumpDockWidgets:" << obj->name();
02982   }
02983 
02984 }
02985 
02986 K3DockWidget* K3DockManager::getDockWidgetFromName( const QString& dockName )
02987 {
02988   QObjectList::iterator it = childDock->begin();
02989   K3DockWidget * obj;
02990   while ( it != childDock->end() ) {
02991     obj=(K3DockWidget*)(*it);
02992     ++it;
02993     if ( obj->objectName() == dockName ) return obj;
02994   }
02995 
02996   K3DockWidget* autoCreate = 0L;
02997   if ( autoCreateDock ){
02998     kDebug(282)<<"Autocreating dock: "<<dockName;
02999     autoCreate = new K3DockWidget( this, dockName.toLatin1().constData(), QPixmap("") );
03000     autoCreateDock->append( autoCreate );
03001   }
03002   return autoCreate;
03003 }
03004 void K3DockManager::setSplitterOpaqueResize(bool b)
03005 {
03006   d->splitterOpaqueResize = b;
03007 }
03008 
03009 bool K3DockManager::splitterOpaqueResize() const
03010 {
03011   return d->splitterOpaqueResize;
03012 }
03013 
03014 void K3DockManager::setSplitterKeepSize(bool b)
03015 {
03016   d->splitterKeepSize = b;
03017 }
03018 
03019 bool K3DockManager::splitterKeepSize() const
03020 {
03021   return d->splitterKeepSize;
03022 }
03023 
03024 void K3DockManager::setSplitterHighResolution(bool b)
03025 {
03026   d->splitterHighResolution = b;
03027 }
03028 
03029 bool K3DockManager::splitterHighResolution() const
03030 {
03031   return d->splitterHighResolution;
03032 }
03033 
03034 void K3DockManager::slotMenuPopup()
03035 {
03036   menu->clear();
03037   menuData->clear();
03038 
03039   QObjectList::iterator it = childDock->begin();
03040   K3DockWidget * obj;
03041   while ( it != childDock->end() ) {
03042     obj=(K3DockWidget*)(*it);
03043     ++it;
03044     if ( obj->mayBeHide() ) {
03045       menu->insertItem( i18n("Hide %1", obj->windowTitle()));
03046       menuData->append( new MenuDockData( obj, true ) );
03047     }
03048 
03049     if ( obj->mayBeShow() ) {
03050       menu->insertItem( i18n("Show %1", obj->windowTitle()));
03051       menuData->append( new MenuDockData( obj, false ) );
03052     }
03053   }
03054 }
03055 
03056 void K3DockManager::slotMenuActivated( int id )
03057 {
03058   MenuDockData* data = menuData->at( id );
03059   data->dock->changeHideShowState();
03060 }
03061 
03062 K3DockWidget* K3DockManager::findWidgetParentDock( QWidget* w ) const
03063 {
03064   QObjectList::iterator it = childDock->begin();
03065   K3DockWidget * dock;
03066   K3DockWidget * found = 0L;
03067 
03068   while (it != childDock->end()  ) {
03069     dock=(K3DockWidget*)(*it);
03070     ++it;
03071     if ( dock->widget == w ){ found  = dock; break; }
03072   }
03073   return found;
03074 }
03075 
03076 void K3DockManager::makeWidgetDockVisible( QWidget* w )
03077 {
03078     findWidgetParentDock(w)->makeDockVisible();
03079 }
03080 
03081 Q3PopupMenu* K3DockManager::dockHideShowMenu() const
03082 {
03083     return menu;
03084 }
03085 
03086 void K3DockManager::drawDragRectangle()
03087 {
03088 #ifdef BORDERLESS_WINDOWS
03089     return
03090 #endif
03091   if (d->oldDragRect == d->dragRect)
03092     return;
03093 
03094   int i;
03095   QRect oldAndNewDragRect[2];
03096   oldAndNewDragRect[0] = d->oldDragRect;
03097   oldAndNewDragRect[1] = d->dragRect;
03098 
03099   // 2 calls, one for the old and one for the new drag rectangle
03100   for (i = 0; i <= 1; i++) {
03101     if (oldAndNewDragRect[i].isEmpty())
03102       continue;
03103 
03104     K3DockWidget* pDockWdgAtRect = (K3DockWidget*) QApplication::widgetAt( oldAndNewDragRect[i].topLeft() );
03105     if (!pDockWdgAtRect)
03106       continue;
03107 
03108     bool isOverMainWdg = false;
03109     //bool unclipped;
03110     K3DockMainWindow* pMain = 0L;
03111     K3DockWidget* pTLDockWdg = 0L;
03112     QWidget* topWdg;
03113     if (pDockWdgAtRect->topLevelWidget() == main) {
03114       isOverMainWdg = true;
03115       topWdg = pMain = (K3DockMainWindow*) main;
03116       //unclipped = pMain->testWFlags( WPaintUnclipped );
03117       //pMain->setWFlags( WPaintUnclipped );
03118     }
03119     else {
03120       topWdg = pTLDockWdg = (K3DockWidget*) pDockWdgAtRect->topLevelWidget();
03121       //unclipped = pTLDockWdg->testWFlags( WPaintUnclipped );
03122       //pTLDockWdg->setWFlags( WPaintUnclipped );
03123     }
03124 
03125     // draw the rectangle unclipped over the main dock window
03126     QPainter p;
03127     p.begin( topWdg );
03128     /*
03129     if ( !unclipped ) {
03130       if (isOverMainWdg)
03131         pMain->clearWFlags(WPaintUnclipped);
03132       else
03133         pTLDockWdg->clearWFlags(WPaintUnclipped);
03134     }
03135     */
03136     // draw the rectangle
03137     //p.setRasterOp(Qt::NotXorROP);
03138     QRect r = oldAndNewDragRect[i];
03139     r.moveTopLeft( r.topLeft() - topWdg->mapToGlobal(QPoint(0,0)) );
03140     p.drawRect(r.x(), r.y(), r.width(), r.height());
03141     p.end();
03142   }
03143 
03144   // memorize the current rectangle for later removing
03145   d->oldDragRect = d->dragRect;
03146 }
03147 
03148 void K3DockManager::setSpecialLeftDockContainer(K3DockWidget* container) {
03149     d->leftContainer=container;
03150 }
03151 
03152 void K3DockManager::setSpecialTopDockContainer(K3DockWidget* container) {
03153     d->topContainer=container;
03154 }
03155 
03156 void K3DockManager::setSpecialRightDockContainer(K3DockWidget* container) {
03157     d->rightContainer=container;
03158 
03159 }
03160 
03161 void K3DockManager::setSpecialBottomDockContainer(K3DockWidget* container) {
03162     d->bottomContainer=container;
03163 }
03164 
03165 
03166 K3DockArea::K3DockArea( QWidget* parent, const char *name)
03167 :QWidget( parent, name)
03168 {
03169   QString new_name = QString(name) + QString("_DockManager");
03170   dockManager = new K3DockManager( this, new_name.toLatin1().constData() );
03171   mainDockWidget = 0L;
03172 }
03173 
03174 K3DockArea::~K3DockArea()
03175 {
03176     delete dockManager;
03177 }
03178 
03179 K3DockManager* K3DockArea::manager()
03180 {
03181     return dockManager;
03182 }
03183 
03184 K3DockWidget* K3DockArea::createDockWidget( const QString& name, const QPixmap &pixmap, QWidget* parent, const QString& strCaption, const QString& strTabPageLabel)
03185 {
03186   return new K3DockWidget( dockManager, name.toLatin1().constData(), pixmap, parent, strCaption, strTabPageLabel );
03187 }
03188 
03189 void K3DockArea::activateDock()
03190 {
03191     dockManager->activate();
03192 }
03193 
03194 Q3PopupMenu* K3DockArea::dockHideShowMenu()
03195 {
03196     return dockManager->dockHideShowMenu();
03197 }
03198 
03199 void K3DockArea::makeDockVisible( K3DockWidget* dock )
03200 {
03201   if ( dock )
03202     dock->makeDockVisible();
03203 }
03204 
03205 void K3DockArea::makeDockInvisible( K3DockWidget* dock )
03206 {
03207   if ( dock )
03208     dock->undock();
03209 }
03210 
03211 void K3DockArea::makeWidgetDockVisible( QWidget* widget )
03212 {
03213   makeDockVisible( dockManager->findWidgetParentDock(widget) );
03214 }
03215 
03216 void K3DockArea::writeDockConfig(QDomElement &base)
03217 {
03218   dockManager->writeConfig(base);
03219 }
03220 
03221 void K3DockArea::readDockConfig(QDomElement &base)
03222 {
03223   dockManager->readConfig(base);
03224 }
03225 
03226 void K3DockArea::slotDockWidgetUndocked()
03227 {
03228   QObject* pSender = (QObject*) sender();
03229   if (!pSender->inherits("K3DockWidget")) return;
03230   K3DockWidget* pDW = (K3DockWidget*) pSender;
03231   emit dockWidgetHasUndocked( pDW);
03232 }
03233 
03234 void K3DockArea::resizeEvent(QResizeEvent *rsize)
03235 {
03236   QWidget::resizeEvent(rsize);
03237   if (!children().isEmpty()){
03238 #ifndef NO_KDE2
03239 //    kDebug(282)<<"K3DockArea::resize";
03240 #endif
03241     QList<QWidget *> list = findChildren<QWidget*>();
03242 
03243     foreach( QWidget *w, list )
03244     {
03245       w->setGeometry(QRect(QPoint(0,0),size()));
03246     }
03247 #if 0
03248     K3DockSplitter *split;
03249 //    for (unsigned int i=0;i<children()->count();i++)
03250     {
03251 //      QPtrList<QObject> list(children());
03252 //       QObject *obj=((QPtrList<QObject*>)children())->at(i);
03253     QObject *obj=children()->getFirst();
03254        if (split = dynamic_cast<K3DockSplitter*>(obj))
03255        {
03256           split->setGeometry( QRect(QPoint(0,0), size() ));
03257 //    break;
03258        }
03259     }
03260 #endif
03261    }
03262 }
03263 
03264 #ifndef NO_KDE2
03265 void K3DockArea::writeDockConfig( KConfig* c, const QString &group )
03266 {
03267   dockManager->writeConfig( c, group );
03268 }
03269 
03270 void K3DockArea::readDockConfig( KConfig* c, const QString &group )
03271 {
03272   dockManager->readConfig( c, group );
03273 }
03274 #endif
03275 
03276 void K3DockArea::setMainDockWidget( K3DockWidget* mdw )
03277 {
03278   if ( mainDockWidget == mdw ) return;
03279   mainDockWidget = mdw;
03280   mdw->applyToWidget(this);
03281 }
03282 
03283 K3DockWidget* K3DockArea::getMainDockWidget()
03284 {
03285     return mainDockWidget;
03286 }
03287 
03288 
03289 
03290 // KDOCKCONTAINER - AN ABSTRACTION OF THE KDOCKTABWIDGET
03291 K3DockContainer::K3DockContainer(){m_overlapMode=false; m_childrenListBegin=0; m_childrenListEnd=0;}
03292 K3DockContainer::~K3DockContainer(){
03293 
03294     if (m_childrenListBegin)
03295     {
03296         struct ListItem *tmp=m_childrenListBegin;
03297         while (tmp)
03298         {
03299             struct ListItem *tmp2=tmp->next;
03300             free(tmp->data);
03301             delete tmp;
03302             tmp=tmp2;
03303         }
03304         m_childrenListBegin=0;
03305         m_childrenListEnd=0;
03306     }
03307 
03308 }
03309 
03310 void K3DockContainer::activateOverlapMode(int nonOverlapSize) {
03311     m_nonOverlapSize=nonOverlapSize;
03312     m_overlapMode=true;
03313     if (parentDockWidget() && parentDockWidget()->parent()) {
03314         kDebug(282)<<"K3DockContainer::activateOverlapMode: recalculating sizes";
03315         K3DockSplitter *sp= qobject_cast<K3DockSplitter*>(parentDockWidget()->parent());
03316         if (sp)
03317             sp->resizeEvent(0);
03318     }
03319 }
03320 
03321 void K3DockContainer::deactivateOverlapMode() {
03322     if (!m_overlapMode) return;
03323     m_overlapMode=false;
03324     if (parentDockWidget() && parentDockWidget()->parent()) {
03325         kDebug(282)<<"K3DockContainer::deactivateOverlapMode: recalculating sizes";
03326         K3DockSplitter *sp= qobject_cast<K3DockSplitter*>(parentDockWidget()->parent());
03327         if (sp)
03328             sp->resizeEvent(0);
03329         }
03330 }
03331 
03332 bool K3DockContainer::isOverlapMode() {
03333     return m_overlapMode;
03334 }
03335 
03336 
03337 bool K3DockContainer::dockDragEnter(K3DockWidget*, QMouseEvent *) { return false;}
03338 bool K3DockContainer::dockDragMove(K3DockWidget*, QMouseEvent *) { return false;}
03339 bool K3DockContainer::dockDragLeave(K3DockWidget*, QMouseEvent *) { return false;}
03340 
03341 
03342 K3DockWidget *K3DockContainer::parentDockWidget(){return 0;}
03343 
03344 QStringList K3DockContainer::containedWidgets() const {
03345     QStringList tmp;
03346     for (struct ListItem *it=m_childrenListBegin;it;it=it->next) {
03347         tmp<<QString(it->data);
03348     }
03349 
03350     return tmp;
03351 }
03352 
03353 void K3DockContainer::showWidget(K3DockWidget *) {
03354 }
03355 
03356 void K3DockContainer::insertWidget (K3DockWidget *dw, const QPixmap &, const QString &, int &)
03357     {
03358         struct ListItem *it=new struct ListItem;
03359         it->data=strdup(dw->name());
03360         it->next=0;
03361 
03362         if (m_childrenListEnd)
03363         {
03364             m_childrenListEnd->next=it;
03365             it->prev=m_childrenListEnd;
03366             m_childrenListEnd=it;
03367         }
03368         else
03369         {
03370             it->prev=0;
03371             m_childrenListEnd=it;
03372             m_childrenListBegin=it;
03373         }
03374     }
03375 void K3DockContainer::removeWidget (K3DockWidget *dw){
03376     for (struct ListItem *tmp=m_childrenListBegin;tmp;tmp=tmp->next)
03377     {
03378         if (!strcmp(tmp->data,dw->name()))
03379         {
03380             free(tmp->data);
03381             if (tmp->next) tmp->next->prev=tmp->prev;
03382             if (tmp->prev) tmp->prev->next=tmp->next;
03383             if (tmp==m_childrenListBegin) m_childrenListBegin=tmp->next;
03384             if (tmp==m_childrenListEnd) m_childrenListEnd=tmp->prev;
03385             delete tmp;
03386             break;
03387         }
03388     }
03389 }
03390 
03391 //m_children.remove(dw->name());}
03392 void K3DockContainer::undockWidget (K3DockWidget *){;}
03393 void K3DockContainer::setToolTip(K3DockWidget *, QString &){;}
03394 void K3DockContainer::setPixmap(K3DockWidget*,const QPixmap&){;}
03395 void K3DockContainer::load (KConfig*, const QString&){;}
03396 void K3DockContainer::save (KConfig*, const QString&){;}
03397 void K3DockContainer::load (QDomElement&){;}
03398 void K3DockContainer::save (QDomElement&){;}
03399 void K3DockContainer::prepareSave(QStringList &names)
03400 {
03401 
03402     for (struct ListItem *tmp=m_childrenListBegin;tmp; tmp=tmp->next)
03403         names.removeAll(tmp->data);
03404 //  for (uint i=0;i<m_children.count();i++)
03405 //  {
03406 //      names.remove(m_children.at(i));
03407 //  }
03408 }
03409 
03410 
03411 K3DockTabGroup::K3DockTabGroup( QWidget *parent, const char *name )
03412   :QTabWidget( parent )
03413 {
03414     setObjectName( QLatin1String(name) );
03415 }
03416 
03417 K3DockTabGroup::~K3DockTabGroup()
03418 {
03419 }
03420 
03421 QWidget *K3DockTabGroup::transientTo() {
03422     QWidget *tT=0;
03423     for (int i=0;i<count();i++) {
03424         K3DockWidget *dw=qobject_cast<K3DockWidget*>(page(i));
03425         QWidget *tmp;
03426         if ((tmp=dw->transientTo())) {
03427             if (!tT) tT=tmp;
03428             else {
03429                 if (tT!=tmp) {
03430                     kDebug(282)<<"K3DockTabGroup::transientTo: widget mismatch";
03431                     return 0;
03432                 }
03433             }
03434         }
03435     }
03436 
03437     kDebug(282)<<"K3DockTabGroup::transientTo: "<<(tT?"YES":"NO");
03438 
03439     return tT;
03440 }
03441 
03442 void K3DockWidgetAbstractHeader::virtual_hook( int, void* )
03443 { /*BASE::virtual_hook( id, data );*/ }
03444 
03445 void K3DockWidgetAbstractHeaderDrag::virtual_hook( int, void* )
03446 { /*BASE::virtual_hook( id, data );*/ }
03447 
03448 void K3DockWidgetHeaderDrag::virtual_hook( int id, void* data )
03449 { K3DockWidgetAbstractHeaderDrag::virtual_hook( id, data ); }
03450 
03451 void K3DockWidgetHeader::virtual_hook( int id, void* data )
03452 { K3DockWidgetAbstractHeader::virtual_hook( id, data ); }
03453 
03454 void K3DockTabGroup::virtual_hook( int, void* )
03455 { /*BASE::virtual_hook( id, data );*/ }
03456 
03457 void K3DockWidget::virtual_hook( int, void* )
03458 { /*BASE::virtual_hook( id, data );*/ }
03459 
03460 void K3DockManager::virtual_hook( int, void* )
03461 { /*BASE::virtual_hook( id, data );*/ }
03462 
03463 void K3DockMainWindow::virtual_hook( int, void* )
03464 { /* KMainWindow::virtual_hook( id, data ); */ }
03465 
03466 void K3DockArea::virtual_hook( int, void* )
03467 { /*KMainWindow::virtual_hook( id, data );*/ }
03468 
03469 
03470 #ifndef NO_INCLUDE_MOCFILES // for Qt-only projects, because tmake doesn't take this name
03471 #include "k3dockwidget.moc"
03472 #endif
03473 
03474 //kate: indent-mode csands; space-indent on; indent-width 2;

KDE3Support

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal