24 #include <QtGui/QApplication>
25 #include <QtGui/QLayout>
26 #include <QtGui/QPainter>
27 #include <Qt3Support/Q3StrIList>
28 #include <QtGui/QCursor>
29 #include <QtGui/QWidget>
30 #include <QtGui/QTabWidget>
32 #include <QtGui/QStyle>
33 #include <QMouseEvent>
35 #include <QStylePainter>
36 #include <QStyleOption>
52 #include <qx11info_x11.h>
55 #include <q3toolbar.h>
56 #include <q3popupmenu.h>
61 #undef BORDERLESS_WINDOWS
63 #define DOCK_CONFIG_VERSION "0.0.5"
108 setObjectName( name );
112 setAttribute( Qt::WA_DeleteOnClose );
139 if ( view->isA(
"K3DockWidget") ){
140 if ( view->parent() != this ) ((
K3DockWidget*)view)->applyToWidget(
this );
144 KXmlGuiWindow::setCentralWidget(view);
146 Q3MainWindow::setCentralWidget(view);
152 return new K3DockWidget(
dockManager, name.toLatin1().constData(), pixmap, parent, strCaption, strTabPageLabel );
207 if (!pSender->inherits(
"K3DockWidget"))
return;
244 qso.initFrom(
this );
245 paint.drawPrimitive( QStyle::PE_IndicatorToolBarHandle, qso );
258 #ifdef BORDERLESS_WINDOWS
259 setCursor(
QCursor(Qt::ArrowCursor));
263 layout =
new QHBoxLayout(
this );
264 layout->setSizeConstraint( QLayout::Minimum );
273 auxPix = style()->standardPixmap( QStyle::SP_DockWidgetCloseButton );
276 connect(
closeButton, SIGNAL(clicked()), parent, SIGNAL(headerCloseButtonClicked()));
277 connect(
closeButton, SIGNAL(clicked()), parent, SLOT(undock()));
280 stayButton->setToolTip(
i18nc(
"Freeze the window geometry",
"Freeze") );
292 connect(
dockbackButton, SIGNAL(clicked()), parent, SIGNAL(headerDockbackButtonClicked()));
293 connect(
dockbackButton, SIGNAL(clicked()), parent, SLOT(dockBack()));
300 connect( d->
toDesktopButton, SIGNAL(clicked()), parent, SLOT(toDesktop()));
318 drag->setFixedHeight(
layout->minimumSize().height() );
339 drag->setEnabled(
true );
352 for (Q3PtrListIterator<K3DockButton_Private> it( d->
btns );it.current();++it) {
353 dontShowDummy=dontShowDummy || (it.current()->isVisibleTo(
this));
355 if (dontShowDummy) d->
dummy->hide();
else d->
dummy->show();
375 layout =
new QHBoxLayout(
this );
376 layout->setSizeConstraint( QLayout::Minimum );
380 if (
drag->parentWidget()!=
this) {
381 drag->setParent(
this);
394 for (Q3PtrListIterator<K3DockButton_Private> it( d->
btns );it.current();++it) {
395 layout->addWidget(it.current());
396 dontShowDummy=dontShowDummy || (it.current()->isVisibleTo(
this));
398 if (dontShowDummy) d->
dummy->hide();
else d->
dummy->show();
401 kDebug(282)<<
"KdockWidgetHeader::setDragPanel:minimum height="<<
layout->minimumSize().height();
409 if (btn->parentWidget()!=
this) {
410 btn->setParent(
this);
413 if (!d->
btns.containsRef(btn)) d->
btns.append(btn);
418 layout =
new QHBoxLayout(
this );
419 layout->setSizeConstraint( QLayout::Minimum );
429 for (Q3PtrListIterator<K3DockButton_Private> it( d->
btns );it.current();++it) {
430 layout->addWidget(it.current());
431 dontShowDummy=dontShowDummy || (it.current()->isVisibleTo(
this));
433 if (dontShowDummy) d->
dummy->hide();
else d->
dummy->show();
436 drag->setFixedHeight(
layout->minimumSize().height() );
440 if (btn->parentWidget()==
this) {
441 if (d->
btns.containsRef(btn)) d->
btns.removeRef(btn);
454 return drag->isEnabled();
459 kDebug(282)<<
"K3DockWidgetHeader::showUndockButton("<<show<<
")";
491 class K3DockManager::K3DockManagerPrivate
521 QPointer<K3DockWidget> mainDockWidget;
525 QPointer<K3DockWidget> leftContainer;
526 QPointer<K3DockWidget> topContainer;
527 QPointer<K3DockWidget> rightContainer;
528 QPointer<K3DockWidget> bottomContainer;
529 int m_readDockConfigMode;
535 #ifdef BORDERLESS_WINDOWS
540 ,formerBrotherDockWidget(0L)
541 ,currentDockPos(DockNone)
542 ,formerDockPos(DockNone)
544 ,pix(
new QPixmap(pixmap))
545 ,prevSideDockPosBeforeDrag(DockNone)
552 layout =
new QVBoxLayout(
this );
553 layout->setSizeConstraint( QLayout::Minimum );
555 manager = dockManager;
556 manager->childDock->append(
this );
559 eDocking = DockFullDocking;
560 sDocking = DockFullSite;
565 if( strCaption.isNull() )
566 setWindowTitle( name );
568 setWindowTitle( strCaption);
570 if( strTabPageLabel ==
" ")
571 setTabPageLabel( windowTitle());
573 setTabPageLabel( strTabPageLabel);
576 d->isContainer =
false;
580 QObject::connect(
this, SIGNAL(hasUndocked()), manager->main, SLOT(slotDockWidgetUndocked()) );
581 applyToWidget( parent,
QPoint(0,0) );
586 pix=
new QPixmap(pixmap);
590 dtg->changeTab(
this,pixmap,dtg->tabLabel(
this));
607 if ( !manager->undockProcess ){
620 if (manager->d) manager->d->containerDocks.removeAll(
this);
621 manager->childDock->removeAll(
this );
629 QWidget::paintEvent(pe);
634 option.rect =
QRect( 0, 0, width(), height() );
635 style()->drawPrimitive (QStyle::PE_FrameDockWidget, &option, &paint,
this);
641 QWidget::leaveEvent(e);
642 #ifdef BORDERLESS_WINDOWS
643 if (parent())
return;
650 #ifdef BORDERLESS_WINDOWS
653 kDebug(282)<<
"K3DockWidget::mousePressEvent";
662 styleheight=2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,
this);
663 bbottom=mp.y()>=height()-styleheight;
664 btop=mp.y()<=styleheight;
665 bleft=mp.x()<=styleheight;
666 bright=mp.x()>=width()-styleheight;
667 kDebug(282)<<
"mousemovevent";
686 if (btop) setCursor(
QCursor(Qt::SizeFDiagCursor));
688 if (bbottom) setCursor(
QCursor(Qt::SizeBDiagCursor));
689 else setCursor(
QCursor(Qt::SizeHorCursor));
698 if (btop) setCursor(
QCursor(Qt::SizeVerCursor));
701 if (d->
resizing) grabMouse(cursor());
705 QWidget::mousePressEvent(mme);
710 #ifdef BORDERLESS_WINDOWS
714 QWidget::mouseReleaseEvent(ev);
719 QWidget::mouseMoveEvent(mme);
720 #ifdef BORDERLESS_WINDOWS
721 if (parent())
return;
728 resize(mme->pos().x()+d->
resizePos.x(),height());
734 resize(width(),mme->pos().y()+d->
resizePos.y());
750 styleheight=2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,
this);
751 bbottom=mp.y()>=height()-styleheight;
752 btop=mp.y()<=styleheight;
753 bleft=mp.x()<=styleheight;
754 bright=mp.x()>=width()-styleheight;
755 kDebug(282)<<
"mousemovevent";
758 if (btop) setCursor(
QCursor(Qt::SizeBDiagCursor));
760 if (bbottom) setCursor(
QCursor(Qt::SizeFDiagCursor));
761 else setCursor(
QCursor(Qt::SizeHorCursor));
765 if (btop) setCursor(
QCursor(Qt::SizeFDiagCursor));
767 if (bbottom) setCursor(
QCursor(Qt::SizeBDiagCursor));
768 else setCursor(
QCursor(Qt::SizeHorCursor));
771 if (bbottom || btop) setCursor(
QCursor(Qt::SizeVerCursor));
772 else setCursor(
QCursor(Qt::ArrowCursor));
780 if (dynamic_cast<K3DockContainer*>(container))
808 layout =
new QVBoxLayout(
this );
809 layout->setSizeConstraint( QLayout::Minimum );
810 layout->addWidget( header );
814 layout->addWidget( header );
824 if ( header->inherits(
"K3DockWidgetHeader" ) )
848 #ifdef BORDERLESS_WINDOWS
849 layout->setMargin(0);
850 setMouseTracking(
false);
851 setCursor(
QCursor(Qt::ArrowCursor));
858 if (widget && dynamic_cast<K3DockContainer*>(widget))
866 #ifdef BORDERLESS_WINDOWS
867 layout->setMargin(2*style().pixelMetric(QStyle::PM_DefaultFrameWidth,
this));
868 setMouseTracking(
true);
873 void K3DockWidget::applyToWidget(
QWidget* s,
const QPoint& p )
882 if ( s && s->inherits(
"K3DockMainWindow") ){
886 if ( manager && s == manager->main ){
887 setGeometry(
QRect(
QPoint(0,0), manager->main->geometry().size()) );
897 XSetTransientForHint( QX11Info::display(), winId(), d->
_parent->winId() );
899 #ifdef BORDERLESS_WINDOWS
904 #endif // BORDERLESS_WINDOW
916 if ( parent() || manager->main->isVisible() ) {
936 applyToWidget( parentWidget(),
QPoint(0,0) );
945 applyToWidget( parentWidget(),
QPoint(0,0) );
954 switch ( event->type() )
957 case QEvent::FocusIn:
964 case QEvent::ChildRemoved:
965 if ( widget == ((QChildEvent*)event)->child() ) widget = 0L;
968 if ( widget ) widget->show();
972 if ( widget ) widget->hide();
975 case QEvent::WindowTitleChange:
976 if ( parentWidget() ){
977 if ( parent()->inherits(
"K3DockSplitter") ){
992 return QWidget::event( event );
997 if (!parent())
return 0;
998 if (!parent()->inherits(
"K3DockSplitter"))
return 0;
1005 static_cast<K3DockWidget*>( ( (
K3DockSplitter* )( parent() ) )->getFirst() ) :
1006 static_cast<K3DockWidget*>( ( (
K3DockSplitter* )( parent() ) )->getLast() );
1009 return (static_cast<K3DockWidget*>(parent()->parent())->findNearestDockWidget(pos));
1029 bool success =
true;
1033 if ( !(eDocking & (
int)dockPos) ){
1040 if (spliPos > 100) {
1041 spliPos = spliPos / 100;
1042 kDebug(282) <<
"K3DockWidget::manualDock(): fix splitter position: " << spliPos;
1065 if ( tmpTarget && target &&
this != tmpTarget && target ==
dockManager()->d->mainDockWidget )
1069 if ( target && !(target->sDocking & (
int)dockPos) ){
1090 if ( target && !check ){
1099 dock_result = target->
manualDock(
this, another__dockPos, spliPos, pos,
true, tabIndex );
1121 applyToWidget( parentTab );
1122 parentTab->insertTab(
this, icon() ? *icon() : QPixmap(),
1128 setDockTabName( parentTab );
1140 if (!contWid) contWid=target->widget;
1153 applyToWidget( contWid );
1154 cont->
insertWidget(
this, icon() ? *icon() : QPixmap(),
1170 QWidget* parentDock = target->parentWidget();
1175 newDock->isTabGroup =
true;
1177 newDock->isGroup =
true;
1181 newDock->applyToWidget( parentDock );
1185 newDock->move( target->frameGeometry().topLeft() );
1186 newDock->resize( target->geometry().size() );
1187 if ( target->isVisibleToTLW() ) newDock->
show();
1203 tab->setObjectName( QLatin1String(
"_dock_tab" ) );
1204 QObject::connect(tab, SIGNAL(currentChanged(
QWidget*)), d, SLOT(slotFocusEmbeddedWidget(
QWidget*)));
1207 target->applyToWidget( tab );
1208 applyToWidget( tab );
1211 tab->insertTab( target, target->icon() ? *(target->icon()) : QPixmap(),
1219 tab->insertTab(
this, icon() ? *icon() : QPixmap(),
1222 QRect geom=newDock->geometry();
1225 newDock->setGeometry(geom);
1230 setDockTabName( tab );
1247 panner->setFocusPolicy( Qt::NoFocus );
1248 target->applyToWidget( panner );
1249 applyToWidget( panner );
1277 if ( parentDock->inherits(
"K3DockSplitter") ){
1288 emit target->
docking(
this, dockPos );
1297 if ( !parent() )
return 0L;
1298 QWidget* candidate = parentWidget()->parentWidget();
1299 if ( candidate && candidate->inherits(
"K3DockTabGroup") )
return (
K3DockTabGroup*)candidate;
1305 if (!parent())
return 0L;
1306 QWidget* candidate = parentWidget()->parentWidget();
1307 if (candidate && dynamic_cast<K3DockContainer*>(candidate))
return candidate;
1316 if (!parent())
return;
1317 if (parent()->inherits(
"K3DockSplitter"))
1325 if (!parent())
return;
1326 if (parent()->inherits(
"K3DockSplitter"))
1345 setMaximumWidth(32000);
1346 setMinimumHeight(0);
1347 setMaximumHeight(32000);
1348 if (!parent())
return;
1349 if (parent()->inherits(
"K3DockSplitter"))
1372 manager->d->dragRect =
QRect ();
1373 manager->drawDragRectangle ();
1375 QWidget* parentW = parentWidget();
1386 manager->blockSignals(
true);
1387 manager->undockProcess =
true;
1389 bool isV = parentW->isVisibleToTLW();
1394 d->
index = parentTab->indexOf(
this);
1395 parentTab->removePage(
this );
1401 applyToWidget( 0L );
1402 if ( parentTab->count() == 1 ){
1406 parentTab->removePage( lastTab );
1410 lastTab->applyToWidget( 0L );
1411 lastTab->move( parentTab->mapToGlobal(parentTab->frameGeometry().topLeft()) );
1417 QWidget* parentOfDockWidget = parentOfTab->parentWidget();
1418 if ( !parentOfDockWidget ){
1419 if ( isV ) lastTab->
show();
1421 if ( parentOfDockWidget->inherits(
"K3DockSplitter") ){
1423 lastTab->applyToWidget( split );
1425 if ( split->
getFirst() == parentOfTab ){
1427 if ( ((
K3DockWidget*)split->parent())->splitterOrientation == Qt::Vertical )
1433 if ( ((
K3DockWidget*)split->parent())->splitterOrientation == Qt::Vertical )
1440 lastTab->applyToWidget( parentOfDockWidget );
1444 manager->blockSignals(
false);
1445 emit manager->
replaceDock( parentOfTab, lastTab );
1448 manager->blockSignals(
true);
1452 setDockTabName( parentTab );
1457 bool undockedFromContainer=
false;
1461 undockedFromContainer=
true;
1467 applyToWidget( 0L );
1469 if (!undockedFromContainer) {
1471 if ( parentW->inherits(
"K3DockSplitter") ){
1478 applyToWidget( 0L );
1481 if ( !group->parentWidget() ){
1482 secondWidget->applyToWidget( 0L, group->frameGeometry().topLeft() );
1483 secondWidget->resize( group->width(), group->height() );
1485 QWidget* obj = group->parentWidget();
1486 secondWidget->applyToWidget( obj );
1487 if ( obj->inherits(
"K3DockSplitter") ){
1491 if ( parentOfGroup->
getFirst() == group )
1492 parentOfGroup->
activate( secondWidget );
1494 parentOfGroup->
activate( 0L, secondWidget );
1499 delete parentSplitterOfDockWidget;
1500 manager->blockSignals(
false);
1503 manager->blockSignals(
true);
1506 if ( isV ) secondWidget->
show();
1510 applyToWidget( 0L );
1516 manager->blockSignals(
false);
1519 manager->undockProcess =
false;
1529 if ( mw->parent() != this ){
1530 mw->setParent(
this);
1534 #ifdef BORDERLESS_WINDOWS
1535 if (!mw->ownCursor()) mw->setCursor(
QCursor(Qt::ArrowCursor));
1544 widget->setAutoFillBackground(
true );
1546 layout =
new QVBoxLayout(
this );
1547 layout->setSizeConstraint( QLayout::Minimum );
1553 manager->d->containerDocks.append(
this);
1562 layout->addWidget( header );
1563 layout->addWidget( widget,1 );
1578 for (
int i = 0; i < tab->count(); ++i ) {
1580 listOfCaption.append( w->windowTitle() ).append(
",");
1581 listOfName.append( w->name() ).append(
",");
1583 listOfCaption.remove( listOfCaption.length()-1, 1 );
1584 listOfName.remove( listOfName.length()-1, 1 );
1586 tab->parentWidget()->setName( listOfName.toUtf8() );
1587 tab->parentWidget()->setWindowTitle( listOfCaption );
1589 tab->parentWidget()->repaint();
1590 if ( tab->parentWidget()->parent() )
1591 if ( tab->parentWidget()->parent()->inherits(
"K3DockSplitter") )
1592 ((
K3DockSplitter*)(tab->parentWidget()->parent()))->updateName();
1597 bool f = (parent() != manager->main);
1603 bool f = (parent() != manager->main);
1604 return ( !isGroup && !isTabGroup && f && !isVisible() );
1630 if ( manager->main->inherits(
"K3DockMainWindow") ){
1650 if ( isVisible() )
return;
1654 if ( !p->isVisible() )
1656 p = p->parentWidget();
1687 while ( !found && obj!= 0 ) {
1734 ,currentDragWidget(0L)
1735 ,currentMoveWidget(0L)
1736 ,childDockWidgetList(0L)
1741 ,undockProcess(false)
1744 d =
new K3DockManagerPrivate;
1746 d->readyToDrag =
false;
1747 d->mainDockWidget=0;
1752 d->splitterOpaqueResize =
false;
1755 d->splitterKeepSize =
false;
1756 d->splitterHighResolution =
false;
1759 main->installEventFilter(
this );
1761 undockProcess =
false;
1764 menuData->setAutoDelete(
true );
1765 menuData->setAutoDelete(
true );
1773 connect( menu, SIGNAL(aboutToShow()), SLOT(slotMenuPopup()) );
1774 connect( menu, SIGNAL(activated(
int)), SLOT(slotMenuActivated(
int)) );
1782 d->mainDockWidget=w;
1792 Q_FOREACH (
QObject *o, *childDock ) {
1805 foreach (
QObject *o, *childDock ) {
1807 if ( obj->widget ) obj->widget->show();
1812 if ( !main->inherits(
"QDialog") ) main->show();
1818 if ( obj->inherits(
"K3DockWidgetAbstractHeaderDrag") ){
1821 switch ( event->type() ){
1822 case QEvent::MouseButtonDblClick:
1831 case QEvent::MouseButtonPress:
1832 if ( ((QMouseEvent*)event)->button() == Qt::LeftButton ){
1836 qApp->processOneEvent();
1838 currentDragWidget = curdw;
1839 currentMoveWidget = 0L;
1840 childDockWidgetList =
new QWidgetList();
1841 childDockWidgetList->append( curdw );
1842 findChildDockWidget( curdw, childDockWidgetList );
1845 d->dragRect =
QRect(curdw->geometry());
1847 d->dragRect.moveTopLeft(p);
1848 drawDragRectangle();
1849 d->readyToDrag =
true;
1851 d->dragOffset = QCursor::pos()-currentDragWidget->mapToGlobal(
QPoint(0,0));
1856 case QEvent::MouseButtonRelease:
1857 if ( ((QMouseEvent*)event)->button() == Qt::LeftButton ){
1864 if (d->readyToDrag) {
1865 d->readyToDrag =
false;
1867 d->dragRect =
QRect(curdw->geometry());
1869 d->dragRect.moveTopLeft(p);
1870 drawDragRectangle();
1871 currentDragWidget = 0L;
1872 delete childDockWidgetList;
1873 childDockWidgetList = 0L;
1879 case QEvent::MouseMove:
1882 #ifdef BORDERLESS_WINDOWS
1885 if (!curdw->parent())
1887 curdw->move(QCursor::pos()-d->dragOffset);
1888 pDockWdgAtCursor = findDockWidgetAt( QCursor::pos()-
QPoint(0,d->dragOffset.y()+3) );
1889 oldMoveWidget = currentMoveWidget;
1893 pDockWdgAtCursor = findDockWidgetAt( QCursor::pos() );
1894 oldMoveWidget = currentMoveWidget;
1898 pDockWdgAtCursor = findDockWidgetAt( QCursor::pos() );
1902 if ( currentMoveWidget && pDockWdgAtCursor == currentMoveWidget ) {
1903 dragMove( currentMoveWidget, currentMoveWidget->mapFromGlobal( QCursor::pos() ) );
1906 if (dropCancel && curdw) {
1907 d->dragRect =
QRect(curdw->geometry());
1909 d->dragRect.moveTopLeft(p);
1911 d->dragRect =
QRect();
1913 drawDragRectangle();
1918 currentMoveWidget = pDockWdgAtCursor;
1921 if ( oldMoveWidget && pDockWdgAtCursor != currentMoveWidget ) {
1922 currentMoveWidget = pDockWdgAtCursor;
1927 if ( oldMoveWidget != pDockWdgAtCursor && pDockWdgAtCursor ) {
1928 currentMoveWidget = pDockWdgAtCursor;
1932 if (d->readyToDrag) {
1933 d->readyToDrag =
false;
1935 if ( (((QMouseEvent*)event)->state() == Qt::LeftButton) &&
1945 return QObject::eventFilter( obj, event );
1952 if (!currentDragWidget)
1957 QWidget* p = QApplication::topLevelAt( pos );
1962 #if defined(_OS_WIN32_) || defined(Q_OS_WIN32)
1963 p = p->topLevelWidget();
1966 findChildDockWidget( w, p, p->mapFromGlobal(pos) );
1968 if ( !p->inherits(
"K3DockWidget") ) {
1973 if ( findChild<K3DockSplitter*>(
"_dock_split_"))
return 0L;
1974 if ( findChild<K3DockTabGroup*>(
"_dock_tab" ))
return 0L;
1975 if (dynamic_cast<K3DockContainer*>(w))
return 0L;
1977 if (!childDockWidgetList)
return 0L;
1978 if ( childDockWidgetList->indexOf(w) != -1 )
return 0L;
1979 if ( currentDragWidget->isGroup && ((
K3DockWidget*)w)->parentDockTabGroup() )
return 0L;
1987 QPoint cpos = www->mapFromGlobal( pos );
1989 int ww = www->widget->width() / 3;
1990 int hh = www->widget->height() / 3;
1992 if ( cpos.y() <= hh ){
1995 if ( cpos.y() >= 2*hh ){
1998 if ( cpos.x() <= ww ){
2001 if ( cpos.x() >= 2*ww ){
2006 if ( !(www->sDocking & (
int)curPos) )
return 0L;
2007 if ( !(currentDragWidget->eDocking & (
int)curPos) )
return 0L;
2008 if ( www->manager !=
this )
return 0L;
2016 if ( !p->children().isEmpty() ) {
2018 foreach(
QObject* o, p->children() )
2020 if ( o->isWidgetType() ) {
2022 if ( w->isVisible() && w->geometry().contains(pos) ) {
2023 if ( w->inherits(
"K3DockWidget") ) ww = w;
2024 findChildDockWidget( ww, w, w->mapFromParent(pos) );
2033 void K3DockManager::findChildDockWidget(
const QWidget* p, QWidgetList*& list )
2035 if ( !p->children().isEmpty() ) {
2037 foreach(
QObject* o, p->children() )
2039 if ( o->isWidgetType() ) {
2041 if ( w->isVisible() ) {
2042 if ( w->inherits(
"K3DockWidget") ) list->append( w );
2043 findChildDockWidget( w, list );
2057 if ( w->parentWidget()->inherits(
"K3DockSplitter") ){
2066 QApplication::setOverrideCursor(
QCursor(Qt::SizeAllCursor));
2071 QPoint p = dw->mapToGlobal( dw->widget->pos() );
2074 QSize r = dw->widget->size();
2077 if ( oldPos != curPos ) {
2078 d->dragRect.setRect( p.x()+2, p.y()+2, r.width()-4, r.height()-4 );
2083 int w = r.width() / 3;
2084 int h = r.height() / 3;
2086 if ( pos.y() <= h ){
2090 if ( pos.y() >= 2*h ){
2092 p.setY( p.y() + 2*h );
2095 if ( pos.x() <= w ){
2099 if ( pos.x() >= 2*w ){
2101 p.setX( p.x() + 2*w );
2106 p.setX( p.x() + w );
2107 p.setY( p.y() + h );
2110 if ( oldPos != curPos ) {
2111 d->dragRect.setRect( p.x(), p.y(), w, h );
2112 drawDragRectangle();
2117 void K3DockManager::cancelDrop()
2119 QApplication::restoreOverrideCursor();
2121 delete childDockWidgetList;
2122 childDockWidgetList = 0L;
2124 d->dragRect =
QRect();
2125 drawDragRectangle();
2129 void K3DockManager::drop()
2131 d->dragRect =
QRect();
2132 drawDragRectangle();
2134 QApplication::restoreOverrideCursor();
2136 delete childDockWidgetList;
2137 childDockWidgetList = 0L;
2139 if ( dropCancel )
return;
2141 d->dragRect =
QRect();
2142 drawDragRectangle();
2145 if ( !currentMoveWidget && !currentDragWidget->parent() ) {
2146 currentDragWidget->move( QCursor::pos() - d->dragOffset );
2165 if( (curPos != previousPosition)
2168 if (previousPosition == K3DockWidget::DockNone)
2171 switch( previousPosition ) {
2174 splitPos = 100 - splitPos;
2179 splitPos = 100 - splitPos;
2184 splitPos = 100 - splitPos;
2189 splitPos = 100 - splitPos;
2196 currentDragWidget->prevSideDockPosBeforeDrag = curPos;
2197 currentDragWidget->
manualDock( currentMoveWidget, curPos , splitPos, QCursor::pos() - d->dragOffset );
2205 QDomElement el = doc.createElement(tagName);
2207 el.appendChild(doc.createTextNode(str));
2226 QDomElement el = doc.createElement(tagName);
2228 QDomElement xel = doc.createElement(
"x");
2229 xel.appendChild(doc.createTextNode(QString::number(rect.x())));
2230 el.appendChild(xel);
2231 QDomElement yel = doc.createElement(
"y");
2232 yel.appendChild(doc.createTextNode(QString::number(rect.y())));
2233 el.appendChild(yel);
2234 QDomElement wel = doc.createElement(
"width");
2235 wel.appendChild(doc.createTextNode(QString::number(rect.width())));
2236 el.appendChild(wel);
2237 QDomElement hel = doc.createElement(
"height");
2238 hel.appendChild(doc.createTextNode(QString::number(rect.height())));
2239 el.appendChild(hel);
2248 QDomElement el = doc.createElement(tagName);
2250 foreach(
const QString &s, list )
2252 QDomElement subel = doc.createElement(subTagName);
2253 subel.appendChild(doc.createTextNode(s));
2254 el.appendChild(subel);
2263 return base.namedItem(tagName).firstChild().toText().data();
2269 return base.namedItem(tagName).firstChild().toText().data() ==
"true";
2281 QDomElement el = base.namedItem(tagName).toElement();
2288 return QRect(x, y, width, height);
2296 for( QDomNode n = base.namedItem(tagName).firstChild(); !n.isNull(); n = n.nextSibling() )
2298 QDomElement subel = n.toElement();
2299 if (subel.tagName() == subTagName)
2300 list.append(subel.firstChild().toText().data().toLatin1().constData());
2310 while (!base.firstChild().isNull())
2311 base.removeChild(base.firstChild());
2312 QDomDocument doc = base.ownerDocument();
2319 Q_FOREACH(
QObject *o, *childDock )
2321 #ifdef __GNUC__ // ### KDE4
2322 # warning "Can dw be 0 and what should we do in the case that it is?"
2327 if ( dw->parent() == main )
2328 mainWidgetStr = dw->objectName();
2329 nList.append( dw->objectName() );
2332 for (QObjectList::iterator it = d->containerDocks.begin();it != d->containerDocks.end();++it)
2340 QStringList::Iterator nListIt=nList.begin();
2341 while ( nListIt!=nList.end() ) {
2343 if ((obj->isGroup && (!obj->d->
isContainer)) && (nameList.indexOf( obj->firstName) == -1
2344 || nameList.indexOf(obj->lastName) == -1)) {
2352 QDomElement groupEl;
2356 groupEl=doc.createElement(
"dockContainer");
2362 groupEl = doc.createElement(
"splitGroup");
2366 groupEl.appendChild(
createNumberEntry(doc,
"orientation", (
int)obj->splitterOrientation));
2368 }
else if (obj->isTabGroup) {
2370 groupEl = doc.createElement(
"tabGroup");
2373 for (
int i = 0; i < ((
K3DockTabGroup*)obj->widget)->count(); ++i )
2374 list.append( ((
K3DockTabGroup*)obj->widget)->page( i )->name() );
2377 if (!obj->parent()) {
2383 groupEl = doc.createElement(
"dock");
2386 if (!obj->parent()) {
2392 groupEl.appendChild(
createStringEntry(doc,
"name", QLatin1String(obj->name())));
2393 groupEl.appendChild(
createBoolEntry(doc,
"hasParent", obj->parent()));
2394 if ( !obj->parent() ) {
2395 groupEl.appendChild(
createRectEntry(doc,
"geometry",
QRect(main->frameGeometry().topLeft(), main->size())));
2396 groupEl.appendChild(
createBoolEntry(doc,
"visible", obj->isVisible()));
2398 if (obj->header && obj->header->inherits(
"K3DockWidgetHeader")) {
2403 base.appendChild(groupEl);
2404 nameList.append(obj->name());
2405 nList.erase(nListIt);
2406 nListIt=nList.begin();
2409 if (main->inherits(
"K3DockMainWindow")) {
2411 QString centralWidgetStr =
QString(dmain->centralWidget()? dmain->centralWidget()->name() :
"");
2419 base.appendChild(
createRectEntry(doc,
"geometry",
QRect(main->frameGeometry().topLeft(), main->size())));
2425 if (base.namedItem(
"group").isNull()
2426 && base.namedItem(
"tabgroup").isNull()
2427 && base.namedItem(
"dock").isNull()
2428 && base.namedItem(
"dockContainer").isNull()) {
2433 autoCreateDock =
new QObjectList;
2435 bool isMainVisible = main->isVisible();
2438 QObjectList::iterator it = childDock->begin();
2440 while ( it != childDock->end() ) {
2442 if ( !obj1->isGroup && !obj1->isTabGroup ) {
2443 if ( obj1->parent() )
2452 for( QDomNode n = base.firstChild(); !n.isNull(); n = n.nextSibling() )
2454 QDomElement childEl = n.toElement();
2455 if (childEl.tagName() !=
"dock")
continue;
2465 obj->applyToWidget(0);
2466 obj->setGeometry(r);
2468 obj->QWidget::show();
2471 if (obj && obj->header && obj->header->inherits(
"K3DockWidgetHeader")) {
2478 for( QDomNode n = base.firstChild(); !n.isNull(); n = n.nextSibling() )
2480 QDomElement childEl = n.toElement();
2481 if (childEl.isNull())
continue;
2485 if (childEl.tagName() ==
"dockContainer") {
2490 kDebug(282)<<
"restoration of dockContainer is only supported for already existing dock containers";
2493 if (!dc)
kDebug(282)<<
"Error while trying to handle dockcontainer configuration restoration";
2502 if (childEl.tagName() ==
"splitGroup") {
2507 int orientation =
numberEntry(childEl,
"orientation");
2508 int separatorPos =
numberEntry(childEl,
"separatorPos");
2512 if (first && second) {
2517 obj->setName(name.toLatin1().constData());
2519 }
else if (childEl.tagName() ==
"tabGroup") {
2522 Q3StrList list =
listEntry(childEl,
"tabs",
"tab");
2532 while (list.current() && obj) {
2538 obj->setName(name.toLatin1().constData());
2539 tab->showPage(tab->page(
numberEntry(childEl,
"currentTab")));
2549 obj->applyToWidget(0);
2550 obj->setGeometry(r);
2552 obj->QWidget::show();
2555 if (obj && obj->header && obj->header->inherits(
"K3DockWidgetHeader")) {
2563 for( QDomNode n = base.firstChild(); !n.isNull(); n = n.nextSibling() )
2565 QDomElement childEl = n.toElement();
2567 if (childEl.tagName() !=
"dock" && childEl.tagName() !=
"tabGroup")
2576 if (!name.isEmpty()) {
2584 if (main->inherits(
"K3DockMainWindow")) {
2590 mvd->applyToWidget(dmain);
2592 dmain->setCentralWidget(mvd);
2603 mvd->applyToWidget(main);
2609 main->move(mr.topLeft());
2610 main->resize(mr.size());
2623 if (!autoCreateDock)
return;
2624 autoCreateDock->removeAt(autoCreateDock->indexOf(pDockWidget));
2629 delete autoCreateDock;
2635 d->m_readDockConfigMode = mode;
2643 c = KGlobal::config().data();
2645 QString group = _group.isEmpty() ?
"dock_setting_default" : _group;
2656 Q_FOREACH(
QObject* o, *childDock )
2658 #ifdef __GNUC__ // ### KDE4
2659 # warning "Can obj be 0 and what should we do in the case that it is?"
2665 nList.append( obj->objectName() );
2666 if ( obj->parent() == main )
2667 cg.
writeEntry(
"Main:view", obj->objectName() );
2671 for (QObjectList::iterator it = d->containerDocks.begin() ;it != d->containerDocks.end(); ++it)
2680 QStringList::Iterator nListIt=nList.begin();
2681 while ( nListIt!=nList.end() ){
2695 if ( obj->isGroup ){
2696 if ( (findList.indexOf( obj->firstName ) != -1) && (findList.indexOf( obj->lastName ) != -1 )){
2699 if ( !obj->parent() ){
2700 cg.
writeEntry( cname+
":parent",
"___null___");
2701 cg.
writeEntry( cname+
":geometry",
QRect(obj->frameGeometry().topLeft(), obj->size()) );
2706 cg.
writeEntry( cname+
":first_name", obj->firstName );
2707 cg.
writeEntry( cname+
":last_name", obj->lastName );
2711 nameList.append( obj->name() );
2712 findList.append( obj->name() );
2714 nList.erase(nListIt);
2715 nListIt=nList.begin();
2725 if (nListIt==nList.end()) nListIt=nList.begin();
2729 if ( obj->isTabGroup){
2731 if ( !obj->parent() ){
2732 cg.
writeEntry( cname+
":parent",
"___null___");
2733 cg.
writeEntry( cname+
":geometry",
QRect(obj->frameGeometry().topLeft(), obj->size()) );
2741 for (
int i = 0; i < ((
K3DockTabGroup*)obj->widget)->count(); ++i )
2742 list.append( ((
K3DockTabGroup*)obj->widget)->page( i )->name() );
2746 nameList.append( obj->name() );
2747 findList.append( obj->name() );
2749 nList.erase(nListIt);
2750 nListIt=nList.begin();
2755 if ( !obj->parent() ){
2757 cg.
writeEntry( cname+
":geometry",
QRect(obj->frameGeometry().topLeft(), obj->size()) );
2764 nameList.append( cname.toLatin1().constData() );
2766 findList.append( obj->name() );
2767 nList.erase(nListIt);
2768 nListIt=nList.begin();
2774 cg.
writeEntry(
"Main:Geometry",
QRect(main->frameGeometry().topLeft(), main->size()) );
2777 if ( main->inherits(
"K3DockMainWindow") ){
2780 cg.
writeEntry(
"Main:view", dmain->centralWidget() ? dmain->centralWidget()->name():
"" );
2787 #include <qmessagebox.h>
2791 c = KGlobal::config().data();
2793 QString group = _group.isEmpty() ?
"dock_setting_default" : _group;
2804 autoCreateDock =
new QObjectList();
2806 bool isMainVisible = main->isVisible();
2811 QObjectList::iterator it = childDock->begin();
2814 while ( it != childDock->end() ){
2817 if ( !obj->isGroup && !obj->isTabGroup ) {
2818 if ( obj->parent() ) obj->
undock();
else obj->hide();
2824 foreach(
const QString &oname, nameList )
2830 if ( type ==
"NULL_DOCK" || cg.
readEntry( oname +
":parent",
QString() ) ==
"___null___" ){
2833 obj->applyToWidget( 0L );
2834 obj->setGeometry(r);
2840 obj->QWidget::show();
2844 if ( type ==
"DOCK" ){
2854 if ( obj && obj->header){
2860 foreach(
const QString &oname, nameList )
2866 if ( type ==
"GROUP" ){
2869 int sepPos = cg.
readEntry( oname +
":sepPos",0 );
2871 Qt::Orientation p = (Qt::Orientation)cg.
readEntry( oname +
":orientation",0 );
2872 if ( first && last ){
2875 obj->setName( oname.toLatin1().constData() );
2880 if ( type ==
"TAB_GROUP" ){
2883 QStringList::const_iterator listit = list.begin();
2887 if ( tabDockGroup ){
2889 while ( listit != list.end() && tabDockGroup ){
2893 if ( tabDockGroup ){
2894 tabDockGroup->setName( oname.toLatin1().constData() );
2897 tab->showPage( tab->page( cg.
readEntry( oname+
":curTab",0 ) ) );
2904 if ( obj && obj->header){
2911 foreach(
const QString &oname, nameList )
2917 if ( type ==
"NULL_DOCK" || cg.
readEntry( oname +
":parent",
QString() ) ==
"___null___" ){
2921 if (!name.isEmpty()) {
2928 if ( main->inherits(
"K3DockMainWindow") ){
2935 mvd->applyToWidget( dmain );
2950 mvd->applyToWidget( main );
2965 if (!main->inherits(
"K3DockMainWindow"))
2966 main->move(mr.topLeft());
2968 main->resize(mr.size());
2970 if ( isMainVisible ) main->show();
2976 QObjectList::iterator it = childDock->begin();
2978 while ( it != childDock->end() ) {
2981 kDebug(282) <<
"K3DockManager::dumpDockWidgets:" << obj->name();
2988 QObjectList::iterator it = childDock->begin();
2990 while ( it != childDock->end() ) {
2993 if ( obj->objectName() == dockName )
return obj;
2997 if ( autoCreateDock ){
2998 kDebug(282)<<
"Autocreating dock: "<<dockName;
2999 autoCreate =
new K3DockWidget(
this, dockName.toLatin1().constData(), QPixmap(
"") );
3000 autoCreateDock->append( autoCreate );
3006 d->splitterOpaqueResize = b;
3011 return d->splitterOpaqueResize;
3016 d->splitterKeepSize = b;
3021 return d->splitterKeepSize;
3026 d->splitterHighResolution = b;
3031 return d->splitterHighResolution;
3034 void K3DockManager::slotMenuPopup()
3039 QObjectList::iterator it = childDock->begin();
3041 while ( it != childDock->end() ) {
3045 menu->insertItem(
i18n(
"Hide %1", obj->windowTitle()));
3046 menuData->append(
new MenuDockData( obj,
true ) );
3050 menu->insertItem(
i18n(
"Show %1", obj->windowTitle()));
3051 menuData->append(
new MenuDockData( obj,
false ) );
3056 void K3DockManager::slotMenuActivated(
int id )
3058 MenuDockData* data = menuData->at(
id );
3059 data->dock->changeHideShowState();
3064 QObjectList::iterator it = childDock->begin();
3068 while (it != childDock->end() ) {
3071 if ( dock->widget == w ){ found = dock;
break; }
3086 void K3DockManager::drawDragRectangle()
3088 #ifdef BORDERLESS_WINDOWS
3091 if (d->oldDragRect == d->dragRect)
3095 QRect oldAndNewDragRect[2];
3096 oldAndNewDragRect[0] = d->oldDragRect;
3097 oldAndNewDragRect[1] = d->dragRect;
3100 for (i = 0; i <= 1; i++) {
3101 if (oldAndNewDragRect[i].isEmpty())
3105 if (!pDockWdgAtRect)
3108 bool isOverMainWdg =
false;
3113 if (pDockWdgAtRect->topLevelWidget() == main) {
3114 isOverMainWdg =
true;
3120 topWdg = pTLDockWdg = (
K3DockWidget*) pDockWdgAtRect->topLevelWidget();
3138 QRect r = oldAndNewDragRect[i];
3139 r.moveTopLeft( r.topLeft() - topWdg->mapToGlobal(
QPoint(0,0)) );
3140 p.drawRect(r.x(), r.y(), r.width(), r.height());
3145 d->oldDragRect = d->dragRect;
3149 d->leftContainer=container;
3153 d->topContainer=container;
3157 d->rightContainer=container;
3162 d->bottomContainer=container;
3170 dockManager =
new K3DockManager(
this, new_name.toLatin1().constData() );
3186 return new K3DockWidget( dockManager, name.toLatin1().constData(), pixmap, parent, strCaption, strTabPageLabel );
3229 if (!pSender->inherits(
"K3DockWidget"))
return;
3236 QWidget::resizeEvent(rsize);
3237 if (!children().isEmpty()){
3253 QObject *obj=children()->getFirst();
3254 if (split = dynamic_cast<K3DockSplitter*>(obj))
3280 mdw->applyToWidget(
this);
3294 if (m_childrenListBegin)
3296 struct ListItem *tmp=m_childrenListBegin;
3299 struct ListItem *tmp2=tmp->next;
3304 m_childrenListBegin=0;
3305 m_childrenListEnd=0;
3311 m_nonOverlapSize=nonOverlapSize;
3314 kDebug(282)<<
"K3DockContainer::activateOverlapMode: recalculating sizes";
3322 if (!m_overlapMode)
return;
3323 m_overlapMode=
false;
3325 kDebug(282)<<
"K3DockContainer::deactivateOverlapMode: recalculating sizes";
3333 return m_overlapMode;
3346 for (
struct ListItem *it=m_childrenListBegin;it;it=it->next) {
3358 struct ListItem *it=
new struct ListItem;
3359 it->data=strdup(dw->name());
3362 if (m_childrenListEnd)
3364 m_childrenListEnd->next=it;
3365 it->prev=m_childrenListEnd;
3366 m_childrenListEnd=it;
3371 m_childrenListEnd=it;
3372 m_childrenListBegin=it;
3376 for (
struct ListItem *tmp=m_childrenListBegin;tmp;tmp=tmp->next)
3378 if (!strcmp(tmp->data,dw->name()))
3381 if (tmp->next) tmp->next->prev=tmp->prev;
3382 if (tmp->prev) tmp->prev->next=tmp->next;
3383 if (tmp==m_childrenListBegin) m_childrenListBegin=tmp->next;
3384 if (tmp==m_childrenListEnd) m_childrenListEnd=tmp->prev;
3402 for (
struct ListItem *tmp=m_childrenListBegin;tmp; tmp=tmp->next)
3403 names.removeAll(tmp->data);
3414 setObjectName( QLatin1String(name) );
3423 for (
int i=0;i<count();i++) {
3430 kDebug(282)<<
"K3DockTabGroup::transientTo: widget mismatch";
3437 kDebug(282)<<
"K3DockTabGroup::transientTo: "<<(tT?
"YES":
"NO");
3470 #ifndef NO_INCLUDE_MOCFILES // for Qt-only projects, because tmake doesn't take this name
3471 #include "k3dockwidget.moc"