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