2017-02-27 21:15:20 +08:00
|
|
|
/*******************************************************************************
|
|
|
|
** QtAdcancedDockingSystem
|
|
|
|
** Copyright (C) 2017 Uwe Kindler
|
|
|
|
**
|
|
|
|
** This program is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
//============================================================================
|
|
|
|
/// \file DockContainerWidget.cpp
|
|
|
|
/// \author Uwe Kindler
|
|
|
|
/// \date 24.02.2017
|
|
|
|
/// \brief Implementation of CDockContainerWidget class
|
|
|
|
//============================================================================
|
|
|
|
|
2017-02-27 21:15:20 +08:00
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
//============================================================================
|
|
|
|
// INCLUDES
|
|
|
|
//============================================================================
|
|
|
|
#include "DockContainerWidget.h"
|
|
|
|
|
|
|
|
#include <QEvent>
|
|
|
|
#include <QList>
|
|
|
|
#include <QGridLayout>
|
2017-02-27 01:13:56 +08:00
|
|
|
#include <QSplitter>
|
2017-03-01 23:13:37 +08:00
|
|
|
#include <QPointer>
|
2017-02-25 05:44:02 +08:00
|
|
|
|
|
|
|
#include "DockManager.h"
|
|
|
|
#include "DockAreaWidget.h"
|
2017-03-01 21:09:56 +08:00
|
|
|
#include "DockWidget.h"
|
2017-03-02 18:43:48 +08:00
|
|
|
#include "FloatingDockContainer.h"
|
2017-03-02 22:49:53 +08:00
|
|
|
#include "DockOverlay.h"
|
2017-02-27 01:13:56 +08:00
|
|
|
#include "ads_globals.h"
|
2017-02-25 05:44:02 +08:00
|
|
|
|
2017-03-01 05:41:34 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
namespace ads
|
|
|
|
{
|
|
|
|
static unsigned int zOrderCounter = 0;
|
|
|
|
|
2017-02-27 01:13:56 +08:00
|
|
|
/**
|
|
|
|
* Helper function to ease insertion of dock area into splitter
|
|
|
|
*/
|
2017-03-02 22:49:53 +08:00
|
|
|
static void insertWidgetIntoSplitter(QSplitter* Splitter, QWidget* widget, bool Append)
|
2017-02-27 01:13:56 +08:00
|
|
|
{
|
|
|
|
if (Append)
|
|
|
|
{
|
|
|
|
Splitter->addWidget(widget);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Splitter->insertWidget(0, widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
/**
|
|
|
|
* Private data class of CDockContainerWidget class (pimpl)
|
|
|
|
*/
|
|
|
|
struct DockContainerWidgetPrivate
|
|
|
|
{
|
|
|
|
CDockContainerWidget* _this;
|
2017-03-01 23:13:37 +08:00
|
|
|
QPointer<CDockManager> DockManager;
|
2017-02-25 05:44:02 +08:00
|
|
|
unsigned int zOrderIndex = 0;
|
|
|
|
QList<CDockAreaWidget*> DockAreas;
|
|
|
|
QGridLayout* Layout = nullptr;
|
2017-03-02 18:43:48 +08:00
|
|
|
bool isFloating = false;
|
2017-02-25 05:44:02 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data constructor
|
|
|
|
*/
|
|
|
|
DockContainerWidgetPrivate(CDockContainerWidget* _public);
|
|
|
|
|
2017-02-27 01:13:56 +08:00
|
|
|
/**
|
2017-02-27 21:15:20 +08:00
|
|
|
* Adds dock widget to container and returns the dock area that contains
|
|
|
|
* the inserted dock widget
|
2017-02-27 01:13:56 +08:00
|
|
|
*/
|
2017-02-27 21:15:20 +08:00
|
|
|
CDockAreaWidget* dockWidgetIntoContainer(DockWidgetArea area, CDockWidget* Dockwidget);
|
2017-02-27 01:13:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds dock widget to a existing DockWidgetArea
|
|
|
|
*/
|
2017-02-27 21:15:20 +08:00
|
|
|
CDockAreaWidget* dockWidgetIntoDockArea(DockWidgetArea area, CDockWidget* Dockwidget,
|
2017-03-01 05:41:34 +08:00
|
|
|
CDockAreaWidget* TargetDockArea);
|
2017-03-01 21:09:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add dock area to this container
|
|
|
|
*/
|
|
|
|
void addDockArea(CDockAreaWidget* NewDockWidget, DockWidgetArea area = CenterDockWidgetArea);
|
2017-03-02 22:49:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Drop floating widget into container
|
|
|
|
*/
|
|
|
|
void dropIntoContainer(CFloatingDockContainer* FloatingWidget, DockWidgetArea area);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drop floating widget into dock area
|
|
|
|
*/
|
|
|
|
void dropIntoSection(CFloatingDockContainer* FloatingWidget,
|
2017-03-03 20:42:41 +08:00
|
|
|
CDockAreaWidget* TargetArea, DockWidgetArea area);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds new dock areas to the internal dock area list
|
|
|
|
*/
|
|
|
|
void addDockAreasToList(const QList<CDockAreaWidget*> NewDockAreas);
|
2017-02-25 05:44:02 +08:00
|
|
|
}; // struct DockContainerWidgetPrivate
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
DockContainerWidgetPrivate::DockContainerWidgetPrivate(CDockContainerWidget* _public) :
|
|
|
|
_this(_public)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-27 01:13:56 +08:00
|
|
|
|
2017-03-02 22:49:53 +08:00
|
|
|
//============================================================================
|
|
|
|
void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* FloatingWidget,
|
|
|
|
DockWidgetArea area)
|
|
|
|
{
|
|
|
|
auto InsertParam = internal::dockAreaInsertParameters(area);
|
|
|
|
auto NewDockAreas = FloatingWidget->dockContainer()->findChildren<CDockAreaWidget*>(
|
|
|
|
QString(), Qt::FindChildrenRecursively);
|
2017-03-03 20:42:41 +08:00
|
|
|
QSplitter* OldSplitter = nullptr;
|
2017-03-02 22:49:53 +08:00
|
|
|
|
2017-03-03 20:42:41 +08:00
|
|
|
// If the container already contains dock areas, then we need to ensure that
|
|
|
|
// we have a splitter with an orientation that matches the orientation of
|
|
|
|
// the current drop action
|
|
|
|
if (!DockAreas.isEmpty())
|
2017-03-02 22:49:53 +08:00
|
|
|
{
|
2017-03-03 20:42:41 +08:00
|
|
|
OldSplitter = _this->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
2017-03-02 22:49:53 +08:00
|
|
|
// First replace the dock widget with a splitter
|
|
|
|
if (DockAreas.count() == 1)
|
|
|
|
{
|
|
|
|
auto DockArea = dynamic_cast<CDockAreaWidget*>(Layout->itemAtPosition(0, 0)->widget());
|
|
|
|
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
|
|
|
Layout->replaceWidget(DockArea, NewSplitter);
|
|
|
|
NewSplitter->addWidget(DockArea);
|
|
|
|
OldSplitter = NewSplitter;
|
|
|
|
}
|
|
|
|
else if (OldSplitter->orientation() != InsertParam.orientation())
|
|
|
|
{
|
|
|
|
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
|
|
|
QLayoutItem* li = Layout->replaceWidget(OldSplitter, NewSplitter);
|
|
|
|
NewSplitter->addWidget(OldSplitter);
|
|
|
|
OldSplitter = NewSplitter;
|
|
|
|
}
|
2017-03-03 20:42:41 +08:00
|
|
|
}
|
2017-03-02 22:49:53 +08:00
|
|
|
|
2017-03-03 20:42:41 +08:00
|
|
|
// Now we can insert the floating widget content into this container
|
|
|
|
auto Widget = FloatingWidget->dockContainer()->findChild<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
|
|
|
|
auto FloatingSplitter = dynamic_cast<QSplitter*>(Widget);
|
|
|
|
if (DockAreas.isEmpty())
|
|
|
|
{
|
2017-03-02 22:49:53 +08:00
|
|
|
auto Widget = FloatingWidget->dockContainer()->findChild<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
|
2017-03-03 20:42:41 +08:00
|
|
|
Layout->addWidget(Widget, 0, 0);
|
|
|
|
}
|
|
|
|
else if (!FloatingSplitter)
|
|
|
|
{
|
|
|
|
insertWidgetIntoSplitter(OldSplitter, Widget, InsertParam.append());
|
|
|
|
}
|
|
|
|
else if (FloatingSplitter->orientation() == InsertParam.orientation())
|
|
|
|
{
|
|
|
|
while (FloatingSplitter->count())
|
|
|
|
{
|
|
|
|
insertWidgetIntoSplitter(OldSplitter, FloatingSplitter->widget(0), InsertParam.append());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
insertWidgetIntoSplitter(OldSplitter, FloatingSplitter, InsertParam.append());
|
|
|
|
}
|
|
|
|
|
|
|
|
addDockAreasToList(NewDockAreas);
|
|
|
|
FloatingWidget->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* FloatingWidget,
|
|
|
|
CDockAreaWidget* TargetArea, DockWidgetArea area)
|
|
|
|
{
|
|
|
|
CDockContainerWidget* FloatingContainer = FloatingWidget->dockContainer();
|
|
|
|
if (area == CenterDockWidgetArea)
|
|
|
|
{
|
|
|
|
auto NewDockWidgets = FloatingContainer->findChildren<CDockWidget*>(
|
|
|
|
QString(), Qt::FindChildrenRecursively);
|
|
|
|
for (auto DockWidget : NewDockWidgets)
|
|
|
|
{
|
|
|
|
TargetArea->insertDockWidget(0, DockWidget, false);
|
|
|
|
}
|
|
|
|
TargetArea->setCurrentIndex(0); // make the topmost widget active
|
|
|
|
FloatingWidget->deleteLater();
|
|
|
|
TargetArea->updateDockArea();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto InsertParam = internal::dockAreaInsertParameters(area);
|
|
|
|
auto NewDockAreas = FloatingWidget->dockContainer()->findChildren<CDockAreaWidget*>(
|
|
|
|
QString(), Qt::FindChildrenRecursively);
|
|
|
|
QSplitter* TargetAreaSplitter = internal::findParent<QSplitter*>(TargetArea);
|
|
|
|
|
|
|
|
if (!TargetAreaSplitter)
|
|
|
|
{
|
|
|
|
QSplitter* Splitter = internal::newSplitter(InsertParam.orientation());
|
|
|
|
Layout->replaceWidget(TargetArea, Splitter);
|
|
|
|
Splitter->addWidget(TargetArea);
|
|
|
|
TargetAreaSplitter = Splitter;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AreaIndex = TargetAreaSplitter->indexOf(TargetArea);
|
|
|
|
auto Widget = FloatingWidget->dockContainer()->findChild<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
|
|
|
|
auto FloatingSplitter = dynamic_cast<QSplitter*>(Widget);
|
2017-03-02 22:49:53 +08:00
|
|
|
|
2017-03-03 20:42:41 +08:00
|
|
|
if (TargetAreaSplitter->orientation() == InsertParam.orientation())
|
|
|
|
{
|
|
|
|
if (!FloatingSplitter || FloatingSplitter->orientation() != InsertParam.orientation())
|
2017-03-02 22:49:53 +08:00
|
|
|
{
|
2017-03-03 20:42:41 +08:00
|
|
|
TargetAreaSplitter->insertWidget(AreaIndex + InsertParam.insertOffset(), Widget);
|
2017-03-02 22:49:53 +08:00
|
|
|
}
|
2017-03-03 20:42:41 +08:00
|
|
|
else
|
2017-03-02 22:49:53 +08:00
|
|
|
{
|
2017-03-03 20:42:41 +08:00
|
|
|
int InsertIndex = AreaIndex + InsertParam.insertOffset();
|
2017-03-02 22:49:53 +08:00
|
|
|
while (FloatingSplitter->count())
|
|
|
|
{
|
2017-03-03 20:42:41 +08:00
|
|
|
TargetAreaSplitter->insertWidget(InsertIndex++, FloatingSplitter->widget(0));
|
2017-03-02 22:49:53 +08:00
|
|
|
}
|
|
|
|
}
|
2017-03-03 20:42:41 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
|
|
|
if (!FloatingSplitter || FloatingSplitter->orientation() != InsertParam.orientation())
|
|
|
|
{
|
|
|
|
NewSplitter->addWidget(Widget);
|
|
|
|
}
|
2017-03-02 22:49:53 +08:00
|
|
|
else
|
|
|
|
{
|
2017-03-03 20:42:41 +08:00
|
|
|
while (FloatingSplitter->count())
|
|
|
|
{
|
|
|
|
NewSplitter->addWidget(FloatingSplitter->widget(0));
|
|
|
|
}
|
2017-03-02 22:49:53 +08:00
|
|
|
}
|
2017-03-03 20:42:41 +08:00
|
|
|
|
|
|
|
insertWidgetIntoSplitter(NewSplitter, TargetArea, !InsertParam.append());
|
|
|
|
TargetAreaSplitter->insertWidget(AreaIndex, NewSplitter);
|
2017-03-02 22:49:53 +08:00
|
|
|
}
|
|
|
|
|
2017-03-03 20:42:41 +08:00
|
|
|
FloatingWidget->deleteLater();
|
|
|
|
addDockAreasToList(NewDockAreas);
|
|
|
|
}
|
|
|
|
|
2017-03-02 22:49:53 +08:00
|
|
|
|
2017-03-03 20:42:41 +08:00
|
|
|
//============================================================================
|
|
|
|
void DockContainerWidgetPrivate::addDockAreasToList(const QList<CDockAreaWidget*> NewDockAreas)
|
|
|
|
{
|
2017-03-02 22:49:53 +08:00
|
|
|
int CountBefore = DockAreas.count();
|
|
|
|
int NewAreaCount = NewDockAreas.count();
|
|
|
|
DockAreas.append(NewDockAreas);
|
2017-03-03 20:42:41 +08:00
|
|
|
|
|
|
|
// We need to ensure, that the dock area title bar is visible. The title bar
|
|
|
|
// is invisible, if the dock are is a single dock area in a floating widget.
|
2017-03-02 22:49:53 +08:00
|
|
|
if (1 == CountBefore)
|
|
|
|
{
|
|
|
|
DockAreas.at(0)->updateDockArea();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (1 == NewAreaCount)
|
|
|
|
{
|
|
|
|
DockAreas.last()->updateDockArea();
|
|
|
|
}
|
2017-03-13 22:34:40 +08:00
|
|
|
|
|
|
|
emit _this->dockAreasAdded();
|
2017-03-02 22:49:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-27 01:13:56 +08:00
|
|
|
//============================================================================
|
2017-02-27 21:15:20 +08:00
|
|
|
CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetArea area,
|
2017-02-27 01:13:56 +08:00
|
|
|
CDockWidget* Dockwidget)
|
|
|
|
{
|
|
|
|
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
|
|
|
|
NewDockArea->addDockWidget(Dockwidget);
|
2017-03-01 21:09:56 +08:00
|
|
|
addDockArea(NewDockArea, area);
|
|
|
|
return NewDockArea;
|
|
|
|
}
|
|
|
|
|
2017-02-27 01:13:56 +08:00
|
|
|
|
2017-03-01 21:09:56 +08:00
|
|
|
//============================================================================
|
|
|
|
void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockWidgetArea area)
|
|
|
|
{
|
|
|
|
auto InsertParam = internal::dockAreaInsertParameters(area);
|
2017-02-27 01:13:56 +08:00
|
|
|
if (DockAreas.isEmpty())
|
|
|
|
{
|
|
|
|
Layout->addWidget(NewDockArea, 0, 0);
|
|
|
|
}
|
|
|
|
else if (DockAreas.count() == 1)
|
|
|
|
{
|
2017-03-01 05:41:34 +08:00
|
|
|
QSplitter* Splitter = internal::newSplitter(InsertParam.orientation());
|
2017-02-27 01:13:56 +08:00
|
|
|
auto DockArea = dynamic_cast<CDockAreaWidget*>(Layout->itemAtPosition(0, 0)->widget());
|
|
|
|
Layout->replaceWidget(DockArea, Splitter);
|
|
|
|
Splitter->addWidget(DockArea);
|
2017-03-02 22:49:53 +08:00
|
|
|
insertWidgetIntoSplitter(Splitter, NewDockArea, InsertParam.append());
|
2017-02-27 01:13:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QSplitter* Splitter = _this->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
2017-03-01 05:41:34 +08:00
|
|
|
if (Splitter->orientation() == InsertParam.orientation())
|
2017-02-27 01:13:56 +08:00
|
|
|
{
|
2017-03-02 22:49:53 +08:00
|
|
|
insertWidgetIntoSplitter(Splitter, NewDockArea, InsertParam.append());
|
2017-02-27 01:13:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-01 05:41:34 +08:00
|
|
|
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
|
|
|
if (InsertParam.append())
|
2017-02-27 01:13:56 +08:00
|
|
|
{
|
|
|
|
QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter);
|
|
|
|
NewSplitter->addWidget(Splitter);
|
|
|
|
NewSplitter->addWidget(NewDockArea);
|
|
|
|
delete li;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NewSplitter->addWidget(NewDockArea);
|
|
|
|
QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter);
|
|
|
|
NewSplitter->addWidget(Splitter);
|
|
|
|
delete li;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DockAreas.append(NewDockArea);
|
2017-03-02 18:43:48 +08:00
|
|
|
NewDockArea->updateDockArea();
|
2017-03-13 22:34:40 +08:00
|
|
|
emit _this->dockAreasAdded();
|
2017-02-27 01:13:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2017-02-27 21:15:20 +08:00
|
|
|
CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetArea area,
|
2017-03-01 05:41:34 +08:00
|
|
|
CDockWidget* Dockwidget, CDockAreaWidget* TargetDockArea)
|
2017-02-27 01:13:56 +08:00
|
|
|
{
|
2017-02-27 21:15:20 +08:00
|
|
|
if (CenterDockWidgetArea == area)
|
|
|
|
{
|
2017-03-01 05:41:34 +08:00
|
|
|
TargetDockArea->addDockWidget(Dockwidget);
|
|
|
|
return TargetDockArea;
|
2017-02-27 21:15:20 +08:00
|
|
|
}
|
2017-02-27 01:13:56 +08:00
|
|
|
|
2017-03-01 05:41:34 +08:00
|
|
|
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
|
|
|
|
NewDockArea->addDockWidget(Dockwidget);
|
2017-02-27 21:15:20 +08:00
|
|
|
auto InsertParam = internal::dockAreaInsertParameters(area);
|
2017-03-03 20:42:41 +08:00
|
|
|
if (DockAreas.count() == 1)
|
2017-03-01 05:41:34 +08:00
|
|
|
{
|
2017-03-03 20:42:41 +08:00
|
|
|
QSplitter* Splitter = internal::newSplitter(InsertParam.orientation());
|
|
|
|
auto DockArea = dynamic_cast<CDockAreaWidget*>(Layout->itemAtPosition(0, 0)->widget());
|
|
|
|
Layout->replaceWidget(DockArea, Splitter);
|
|
|
|
Splitter->addWidget(DockArea);
|
|
|
|
insertWidgetIntoSplitter(Splitter, NewDockArea, InsertParam.append());
|
2017-03-01 05:41:34 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-03 20:42:41 +08:00
|
|
|
QSplitter* TargetAreaSplitter = internal::findParent<QSplitter*>(TargetDockArea);
|
|
|
|
int index = TargetAreaSplitter ->indexOf(TargetDockArea);
|
|
|
|
if (TargetAreaSplitter->orientation() == InsertParam.orientation())
|
|
|
|
{
|
|
|
|
std::cout << "TargetAreaSplitter->orientation() == InsertParam.orientation()" << std::endl;
|
|
|
|
TargetAreaSplitter->insertWidget(index + InsertParam.insertOffset(), NewDockArea);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << "TargetAreaSplitter->orientation() != InsertParam.orientation()" << std::endl;
|
|
|
|
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
|
|
|
NewSplitter->addWidget(TargetDockArea);
|
|
|
|
insertWidgetIntoSplitter(NewSplitter, NewDockArea, InsertParam.append());
|
|
|
|
TargetAreaSplitter->insertWidget(index, NewSplitter);
|
|
|
|
}
|
2017-03-01 05:41:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DockAreas.append(NewDockArea);
|
2017-03-13 22:34:40 +08:00
|
|
|
emit _this->dockAreasAdded();
|
2017-03-01 05:41:34 +08:00
|
|
|
return NewDockArea;
|
2017-02-27 01:13:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
//============================================================================
|
|
|
|
CDockContainerWidget::CDockContainerWidget(CDockManager* DockManager, QWidget *parent) :
|
|
|
|
QFrame(parent),
|
|
|
|
d(new DockContainerWidgetPrivate(this))
|
|
|
|
{
|
2017-03-02 18:43:48 +08:00
|
|
|
d->isFloating = dynamic_cast<CFloatingDockContainer*>(parent) != 0;
|
|
|
|
|
2017-02-27 21:15:20 +08:00
|
|
|
//setStyleSheet("background: green;");
|
2017-02-25 05:44:02 +08:00
|
|
|
d->DockManager = DockManager;
|
2017-03-01 23:13:37 +08:00
|
|
|
if (DockManager != this)
|
|
|
|
{
|
|
|
|
d->DockManager->registerDockContainer(this);
|
|
|
|
}
|
2017-02-25 05:44:02 +08:00
|
|
|
|
|
|
|
d->Layout = new QGridLayout();
|
2017-03-12 04:38:31 +08:00
|
|
|
d->Layout->setContentsMargins(0, 1, 0, 1);
|
2017-02-25 05:44:02 +08:00
|
|
|
d->Layout->setSpacing(0);
|
|
|
|
setLayout(d->Layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockContainerWidget::~CDockContainerWidget()
|
|
|
|
{
|
2017-03-01 23:13:37 +08:00
|
|
|
if (d->DockManager)
|
|
|
|
{
|
|
|
|
d->DockManager->removeDockContainer(this);
|
|
|
|
}
|
2017-02-25 05:44:02 +08:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2017-02-27 21:15:20 +08:00
|
|
|
CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget,
|
2017-02-25 05:44:02 +08:00
|
|
|
CDockAreaWidget* DockAreaWidget)
|
|
|
|
{
|
2017-03-01 21:09:56 +08:00
|
|
|
CDockAreaWidget* OldDockArea = Dockwidget->dockAreaWidget();
|
|
|
|
if (OldDockArea)
|
|
|
|
{
|
|
|
|
OldDockArea->removeDockWidget(Dockwidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
Dockwidget->setDockManager(d->DockManager);
|
2017-02-27 01:13:56 +08:00
|
|
|
if (DockAreaWidget)
|
2017-02-25 05:44:02 +08:00
|
|
|
{
|
2017-02-27 21:15:20 +08:00
|
|
|
return d->dockWidgetIntoDockArea(area, Dockwidget, DockAreaWidget);
|
2017-02-27 01:13:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-27 21:15:20 +08:00
|
|
|
return d->dockWidgetIntoContainer(area, Dockwidget);
|
2017-02-25 05:44:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
unsigned int CDockContainerWidget::zOrderIndex() const
|
|
|
|
{
|
|
|
|
return d->zOrderIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
bool CDockContainerWidget::isInFrontOf(CDockContainerWidget* Other) const
|
|
|
|
{
|
|
|
|
return this->zOrderIndex() > Other->zOrderIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
bool CDockContainerWidget::event(QEvent *e)
|
|
|
|
{
|
|
|
|
bool Result = QWidget::event(e);
|
|
|
|
if (e->type() == QEvent::WindowActivate)
|
|
|
|
{
|
|
|
|
d->zOrderIndex = ++zOrderCounter;
|
|
|
|
}
|
|
|
|
else if (e->type() == QEvent::Show && !d->zOrderIndex)
|
|
|
|
{
|
|
|
|
d->zOrderIndex = ++zOrderCounter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
2017-03-01 21:09:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockContainerWidget::addDockArea(CDockAreaWidget* DockAreaWidget,
|
|
|
|
DockWidgetArea area)
|
|
|
|
{
|
|
|
|
CDockContainerWidget* Container = DockAreaWidget->dockContainer();
|
|
|
|
if (Container && Container != this)
|
|
|
|
{
|
|
|
|
Container->removeDockArea(DockAreaWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->addDockArea(DockAreaWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
|
|
|
|
{
|
2017-03-02 18:43:48 +08:00
|
|
|
std::cout << "CDockContainerWidget::removeDockArea" << std::endl;
|
2017-03-01 21:09:56 +08:00
|
|
|
d->DockAreas.removeAll(area);
|
|
|
|
QSplitter* Splitter = internal::findParent<QSplitter*>(area);
|
|
|
|
area->setParent(0);
|
|
|
|
if (!(Splitter && Splitter->count() == 1))
|
|
|
|
{
|
2017-03-22 23:08:44 +08:00
|
|
|
emit dockAreasRemoved();
|
2017-03-01 21:09:56 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It the splitter contains only one single widget, then we do not need
|
|
|
|
// it anymore and can replace it with its content
|
|
|
|
std::cout << "Replacing splitter with content" << std::endl;
|
|
|
|
QWidget* widget = Splitter->widget(0);
|
|
|
|
widget->setParent(this);
|
|
|
|
QSplitter* ParentSplitter = internal::findParent<QSplitter*>(Splitter);
|
|
|
|
if (ParentSplitter)
|
|
|
|
{
|
|
|
|
internal::replaceSplitterWidget(ParentSplitter, Splitter, widget);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d->Layout->replaceWidget(Splitter, widget);
|
|
|
|
}
|
|
|
|
delete Splitter;
|
2017-03-13 22:34:40 +08:00
|
|
|
emit dockAreasRemoved();
|
2017-03-01 21:09:56 +08:00
|
|
|
}
|
2017-03-01 23:13:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockAreaWidget* CDockContainerWidget::dockAreaAt(const QPoint& GlobalPos) const
|
|
|
|
{
|
|
|
|
for (const auto& DockArea : d->DockAreas)
|
|
|
|
{
|
|
|
|
if (DockArea->rect().contains(DockArea->mapFromGlobal(GlobalPos)))
|
|
|
|
{
|
|
|
|
return DockArea;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2017-03-02 18:43:48 +08:00
|
|
|
|
|
|
|
|
2017-03-12 04:38:31 +08:00
|
|
|
//============================================================================
|
|
|
|
CDockAreaWidget* CDockContainerWidget::dockArea(int Index) const
|
|
|
|
{
|
|
|
|
return (Index < dockAreaCount()) ? d->DockAreas[Index] : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-02 18:43:48 +08:00
|
|
|
//============================================================================
|
|
|
|
bool CDockContainerWidget::isFloating() const
|
|
|
|
{
|
|
|
|
return d->isFloating;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
int CDockContainerWidget::dockAreaCount() const
|
|
|
|
{
|
|
|
|
return d->DockAreas.count();
|
|
|
|
}
|
2017-03-02 22:49:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWidget,
|
|
|
|
const QPoint& TargetPos)
|
|
|
|
{
|
|
|
|
std::cout << "CDockContainerWidget::dropFloatingWidget" << std::endl;
|
|
|
|
CDockAreaWidget* DockArea = dockAreaAt(TargetPos);
|
|
|
|
auto dropArea = InvalidDockWidgetArea;
|
|
|
|
if (DockArea)
|
|
|
|
{
|
|
|
|
auto dropOverlay = d->DockManager->dockAreaOverlay();
|
|
|
|
dropOverlay->setAllowedAreas(AllDockAreas);
|
|
|
|
dropArea = dropOverlay->showOverlay(DockArea);
|
|
|
|
if (dropArea != InvalidDockWidgetArea)
|
|
|
|
{
|
|
|
|
std::cout << "Dock Area Drop Content: " << dropArea << std::endl;
|
|
|
|
d->dropIntoSection(FloatingWidget, DockArea, dropArea);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// mouse is over container
|
|
|
|
if (InvalidDockWidgetArea == dropArea)
|
|
|
|
{
|
|
|
|
dropArea = d->DockManager->containerOverlay()->dropAreaUnderCursor();
|
|
|
|
std::cout << "Container Drop Content: " << dropArea << std::endl;
|
|
|
|
if (dropArea != InvalidDockWidgetArea)
|
|
|
|
{
|
|
|
|
d->dropIntoContainer(FloatingWidget, dropArea);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-22 23:08:44 +08:00
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
} // namespace ads
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// EOF DockContainerWidget.cpp
|