mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 07:21:32 +08:00
Merged pull request #201 but made it configurable via config flag
This commit is contained in:
parent
38d8e6aa25
commit
ffed6a9c5f
@ -578,6 +578,10 @@ CMainWindow::CMainWindow(QWidget *parent) :
|
||||
// widget that has the focus
|
||||
// CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true);
|
||||
|
||||
// uncomment if you would like to enable an equal distribution of the
|
||||
// available size of a splitter to all contained dock widgets
|
||||
// CDockManager::setConfigFlag(CDockManager::EqualSplitOnInsertion, true);
|
||||
|
||||
// Now create the dock manager and its content
|
||||
d->DockManager = new CDockManager(this);
|
||||
|
||||
@ -586,7 +590,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
|
||||
|
||||
d->createContent();
|
||||
// Default window geometry - center on screen
|
||||
resize(1200, 1000);
|
||||
resize(1280, 720);
|
||||
setGeometry(QStyle::alignedRect(
|
||||
Qt::LeftToRight, Qt::AlignCenter, frameSize(),
|
||||
QGuiApplication::primaryScreen()->availableGeometry()
|
||||
|
@ -147,12 +147,12 @@ public:
|
||||
* Adds dock widget to container and returns the dock area that contains
|
||||
* the inserted dock widget
|
||||
*/
|
||||
CDockAreaWidget* dockWidgetIntoContainer(DockWidgetArea area, CDockWidget* Dockwidget);
|
||||
CDockAreaWidget* addDockWidgetToContainer(DockWidgetArea area, CDockWidget* Dockwidget);
|
||||
|
||||
/**
|
||||
* Adds dock widget to a existing DockWidgetArea
|
||||
*/
|
||||
CDockAreaWidget* dockWidgetIntoDockArea(DockWidgetArea area, CDockWidget* Dockwidget,
|
||||
CDockAreaWidget* addDockWidgetToDockArea(DockWidgetArea area, CDockWidget* Dockwidget,
|
||||
CDockAreaWidget* TargetDockArea);
|
||||
|
||||
/**
|
||||
@ -304,6 +304,24 @@ public:
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures equal distribution of the sizes of a splitter if an dock widget
|
||||
* is inserted from code
|
||||
*/
|
||||
void adjustSplitterSizesOnInsertion(QSplitter* Splitter, qreal LastRatio = 1.0)
|
||||
{
|
||||
int AreaSize = (Splitter->orientation() == Qt::Horizontal) ? Splitter->width() : Splitter->height();
|
||||
auto SplitterSizes = Splitter->sizes();
|
||||
|
||||
qreal TotRatio = SplitterSizes.size() - 1.0 + LastRatio;
|
||||
for(int i = 0; i < SplitterSizes.size() -1; i++)
|
||||
{
|
||||
SplitterSizes[i] = AreaSize / TotRatio;
|
||||
}
|
||||
SplitterSizes.back() = AreaSize * LastRatio / TotRatio;
|
||||
Splitter->setSizes(SplitterSizes);
|
||||
}
|
||||
|
||||
|
||||
// private slots: ------------------------------------------------------------
|
||||
void onDockAreaViewToggled(bool Visible)
|
||||
@ -313,21 +331,6 @@ public:
|
||||
onVisibleDockAreaCountChanged();
|
||||
emit _this->dockAreaViewToggled(DockArea, Visible);
|
||||
}
|
||||
|
||||
void onAdjustSplitterSizes(QSplitter* Splitter, qreal LastRatio = 1.0)
|
||||
{
|
||||
int AreaSize = (Splitter->orientation() == Qt::Horizontal) ? Splitter->width() : Splitter->height();
|
||||
auto SplitterSizes = Splitter->sizes();
|
||||
|
||||
qreal TotRatio = SplitterSizes.size() - 1.0 + LastRatio;
|
||||
for( int i=0; i<SplitterSizes.size()-1; i++)
|
||||
{
|
||||
SplitterSizes[i] = AreaSize / TotRatio;
|
||||
}
|
||||
SplitterSizes.back() = AreaSize * LastRatio / TotRatio;
|
||||
Splitter->setSizes(SplitterSizes);
|
||||
}
|
||||
|
||||
}; // struct DockContainerWidgetPrivate
|
||||
|
||||
|
||||
@ -1028,7 +1031,7 @@ bool DockContainerWidgetPrivate::restoreChildNodes(CDockingStateReader& s,
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetArea area,
|
||||
CDockAreaWidget* DockContainerWidgetPrivate::addDockWidgetToContainer(DockWidgetArea area,
|
||||
CDockWidget* Dockwidget)
|
||||
{
|
||||
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
|
||||
@ -1141,7 +1144,7 @@ void DockContainerWidgetPrivate::dumpRecursive(int level, QWidget* widget)
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetArea area,
|
||||
CDockAreaWidget* DockContainerWidgetPrivate::addDockWidgetToDockArea(DockWidgetArea area,
|
||||
CDockWidget* Dockwidget, CDockAreaWidget* TargetDockArea)
|
||||
{
|
||||
if (CenterDockWidgetArea == area)
|
||||
@ -1161,7 +1164,12 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetAr
|
||||
{
|
||||
ADS_PRINT("TargetAreaSplitter->orientation() == InsertParam.orientation()");
|
||||
TargetAreaSplitter->insertWidget(index + InsertParam.insertOffset(), NewDockArea);
|
||||
onAdjustSplitterSizes(TargetAreaSplitter);
|
||||
// do nothing, if flag is not enabled
|
||||
if (CDockManager::testConfigFlag(CDockManager::EqualSplitOnInsertion))
|
||||
{
|
||||
adjustSplitterSizesOnInsertion(TargetAreaSplitter);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1172,8 +1180,11 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetAr
|
||||
|
||||
insertWidgetIntoSplitter(NewSplitter, NewDockArea, InsertParam.append());
|
||||
TargetAreaSplitter->insertWidget(index, NewSplitter);
|
||||
TargetAreaSplitter->setSizes(TargetAreaSizes);
|
||||
onAdjustSplitterSizes(NewSplitter);
|
||||
if (CDockManager::testConfigFlag(CDockManager::EqualSplitOnInsertion))
|
||||
{
|
||||
TargetAreaSplitter->setSizes(TargetAreaSizes);
|
||||
adjustSplitterSizesOnInsertion(NewSplitter);
|
||||
}
|
||||
}
|
||||
|
||||
appendDockAreas({NewDockArea});
|
||||
@ -1231,11 +1242,11 @@ CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockW
|
||||
Dockwidget->setDockManager(d->DockManager);
|
||||
if (DockAreaWidget)
|
||||
{
|
||||
return d->dockWidgetIntoDockArea(area, Dockwidget, DockAreaWidget);
|
||||
return d->addDockWidgetToDockArea(area, Dockwidget, DockAreaWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
return d->dockWidgetIntoContainer(area, Dockwidget);
|
||||
return d->addDockWidgetToContainer(area, Dockwidget);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,6 +179,7 @@ public:
|
||||
HideSingleCentralWidgetTitleBar = 0x100000, //!< If there is only one single visible dock widget in the main dock container (the dock manager) and if this flag is set, then the titlebar of this dock widget will be hidden
|
||||
//!< this only makes sense for non draggable and non floatable widgets and enables the creation of some kind of "central" widget
|
||||
FocusHighlighting = 0x200000, //!< enables styling of focused dock widget tabs or floating widget titlebar
|
||||
EqualSplitOnInsertion = 0x400000, ///!< if enabled, the space is equally distributed to all widgets in a splitter
|
||||
|
||||
DefaultDockAreaButtons = DockAreaHasCloseButton
|
||||
| DockAreaHasUndockButton
|
||||
|
Loading…
Reference in New Issue
Block a user