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