mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-01-24 05:22:06 +08:00
Implemented support for dropping into a dock are
This commit is contained in:
parent
f9f064dd71
commit
a8ccbfa407
@ -52,6 +52,7 @@ namespace ads
|
|||||||
{
|
{
|
||||||
static const char* const INDEX_PROPERTY = "index";
|
static const char* const INDEX_PROPERTY = "index";
|
||||||
static const char* const ACTION_PROPERTY = "action";
|
static const char* const ACTION_PROPERTY = "action";
|
||||||
|
static const int APPEND = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom scroll bar implementation for dock area tab bar
|
* Custom scroll bar implementation for dock area tab bar
|
||||||
@ -62,12 +63,13 @@ class CTabsScrollArea : public QScrollArea
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
QPoint m_DragStartMousePos;
|
QPoint m_DragStartMousePos;
|
||||||
CDockAreaWidget* DockArea;
|
CDockAreaWidget* m_DockArea;
|
||||||
|
CFloatingDockContainer* m_FloatingWidget = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CTabsScrollArea(CDockAreaWidget* parent)
|
CTabsScrollArea(CDockAreaWidget* parent)
|
||||||
: QScrollArea(parent),
|
: QScrollArea(parent),
|
||||||
DockArea(parent)
|
m_DockArea(parent)
|
||||||
{
|
{
|
||||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
||||||
setFrameStyle(QFrame::NoFrame);
|
setFrameStyle(QFrame::NoFrame);
|
||||||
@ -79,6 +81,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void wheelEvent(QWheelEvent* Event) override
|
virtual void wheelEvent(QWheelEvent* Event) override
|
||||||
{
|
{
|
||||||
|
std::cout << "CTabsScrollArea::wheelEvent" << std::endl;
|
||||||
Event->accept();
|
Event->accept();
|
||||||
const int direction = Event->angleDelta().y();
|
const int direction = Event->angleDelta().y();
|
||||||
if (direction < 0)
|
if (direction < 0)
|
||||||
@ -105,6 +108,22 @@ protected:
|
|||||||
QScrollArea::mousePressEvent(ev);
|
QScrollArea::mousePressEvent(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores mouse position to detect dragging
|
||||||
|
*/
|
||||||
|
virtual void mouseReleaseEvent(QMouseEvent* ev) override
|
||||||
|
{
|
||||||
|
if (ev->button() == Qt::LeftButton)
|
||||||
|
{
|
||||||
|
std::cout << "CTabsScrollArea::mouseReleaseEvent" << std::endl;
|
||||||
|
ev->accept();
|
||||||
|
m_FloatingWidget = nullptr;
|
||||||
|
m_DragStartMousePos = QPoint();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QScrollArea::mouseReleaseEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts floating the complete docking area including all dock widgets,
|
* Starts floating the complete docking area including all dock widgets,
|
||||||
* if it is not the last dock area in a floating widget
|
* if it is not the last dock area in a floating widget
|
||||||
@ -117,10 +136,16 @@ protected:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_FloatingWidget)
|
||||||
|
{
|
||||||
|
m_FloatingWidget->moveFloating();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If this is the last dock area in a dock container it does not make
|
// If this is the last dock area in a dock container it does not make
|
||||||
// sense to move it to a new floating widget and leave this one
|
// sense to move it to a new floating widget and leave this one
|
||||||
// empty
|
// empty
|
||||||
if (DockArea->dockContainer()->isFloating() && DockArea->dockContainer()->dockAreaCount() == 1)
|
if (m_DockArea->dockContainer()->isFloating() && m_DockArea->dockContainer()->dockAreaCount() == 1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -128,11 +153,8 @@ protected:
|
|||||||
if (!this->geometry().contains(ev->pos()))
|
if (!this->geometry().contains(ev->pos()))
|
||||||
{
|
{
|
||||||
std::cout << "CTabsScrollArea::startFloating" << std::endl;
|
std::cout << "CTabsScrollArea::startFloating" << std::endl;
|
||||||
QSize Size = DockArea->size();
|
startFloating(m_DragStartMousePos);
|
||||||
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(DockArea);
|
auto Overlay = m_DockArea->dockManager()->containerOverlay();
|
||||||
FloatingWidget->startFloating(m_DragStartMousePos, Size);
|
|
||||||
|
|
||||||
auto Overlay = DockArea->dockManager()->containerOverlay();
|
|
||||||
Overlay->setAllowedAreas(OuterDockAreas);
|
Overlay->setAllowedAreas(OuterDockAreas);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,9 +166,18 @@ protected:
|
|||||||
*/
|
*/
|
||||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override
|
virtual void mouseDoubleClickEvent(QMouseEvent *event) override
|
||||||
{
|
{
|
||||||
QSize Size = DockArea->size();
|
startFloating(event->pos());
|
||||||
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(DockArea);
|
}
|
||||||
FloatingWidget->startFloating(event->pos(), Size);
|
|
||||||
|
/**
|
||||||
|
* Starts floating
|
||||||
|
*/
|
||||||
|
void startFloating(const QPoint& Pos)
|
||||||
|
{
|
||||||
|
QSize Size = m_DockArea->size();
|
||||||
|
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(m_DockArea);
|
||||||
|
FloatingWidget->startFloating(Pos, Size);
|
||||||
|
m_FloatingWidget = FloatingWidget;
|
||||||
}
|
}
|
||||||
}; // class CTabsScrollArea
|
}; // class CTabsScrollArea
|
||||||
|
|
||||||
@ -201,7 +232,7 @@ struct DockAreaWidgetPrivate
|
|||||||
* member. If menu is a valid menu pointer, the entry will be added to
|
* member. If menu is a valid menu pointer, the entry will be added to
|
||||||
* the given menu
|
* the given menu
|
||||||
*/
|
*/
|
||||||
void addTabsMenuEntry(CDockWidget* DockWidget, QMenu* menu = 0);
|
void addTabsMenuEntry(CDockWidget* DockWidget, int Index = -1, QMenu* menu = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the tab action of the given dock widget
|
* Returns the tab action of the given dock widget
|
||||||
@ -310,10 +341,19 @@ void DockAreaWidgetPrivate::updateTabBar()
|
|||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
void DockAreaWidgetPrivate::addTabsMenuEntry(CDockWidget* DockWidget,
|
void DockAreaWidgetPrivate::addTabsMenuEntry(CDockWidget* DockWidget,
|
||||||
QMenu* menu)
|
int Index, QMenu* menu)
|
||||||
{
|
{
|
||||||
menu = menu ? menu : TabsMenuButton->menu();
|
menu = menu ? menu : TabsMenuButton->menu();
|
||||||
auto Action = menu->addAction(DockWidget->windowTitle());
|
QAction* Action;
|
||||||
|
if (Index >= 0 && Index < menu->actions().count())
|
||||||
|
{
|
||||||
|
Action = new QAction(DockWidget->windowTitle());
|
||||||
|
menu->insertAction(menu->actions().at(Index), Action);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Action = menu->addAction(DockWidget->windowTitle());
|
||||||
|
}
|
||||||
QVariant vAction = QVariant::fromValue(Action);
|
QVariant vAction = QVariant::fromValue(Action);
|
||||||
DockWidget->setProperty(ACTION_PROPERTY, vAction);
|
DockWidget->setProperty(ACTION_PROPERTY, vAction);
|
||||||
}
|
}
|
||||||
@ -327,7 +367,7 @@ void DockAreaWidgetPrivate::updateTabsMenu()
|
|||||||
for (int i = 0; i < ContentsLayout->count(); ++i)
|
for (int i = 0; i < ContentsLayout->count(); ++i)
|
||||||
{
|
{
|
||||||
CDockWidget* DockWidget = dockWidgetAt(i);
|
CDockWidget* DockWidget = dockWidgetAt(i);
|
||||||
addTabsMenuEntry(dockWidgetAt(i), menu);
|
addTabsMenuEntry(dockWidgetAt(i), APPEND, menu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,20 +428,26 @@ CDockContainerWidget* CDockAreaWidget::dockContainer() const
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
void CDockAreaWidget::addDockWidget(CDockWidget* DockWidget)
|
void CDockAreaWidget::addDockWidget(CDockWidget* DockWidget)
|
||||||
{
|
{
|
||||||
d->ContentsLayout->addWidget(DockWidget);
|
insertDockWidget(d->ContentsLayout->count(), DockWidget);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
|
||||||
|
bool Activate)
|
||||||
|
{
|
||||||
|
d->ContentsLayout->insertWidget(index, DockWidget);
|
||||||
DockWidget->titleBar()->setDockAreaWidget(this);
|
DockWidget->titleBar()->setDockAreaWidget(this);
|
||||||
auto TitleBar = DockWidget->titleBar();
|
auto TitleBar = DockWidget->titleBar();
|
||||||
d->TabsLayout->insertWidget(d->TabsLayout->count() - d->TabsLayoutInitCount,
|
d->TabsLayout->insertWidget(index, TitleBar);
|
||||||
TitleBar);
|
|
||||||
connect(TitleBar, SIGNAL(clicked()), this, SLOT(onDockWidgetTitleClicked()));
|
connect(TitleBar, SIGNAL(clicked()), this, SLOT(onDockWidgetTitleClicked()));
|
||||||
// if this is the first tab, then activate it
|
DockWidget->setProperty(INDEX_PROPERTY, index);
|
||||||
if (d->ContentsLayout->count() == 1)
|
if (Activate)
|
||||||
{
|
{
|
||||||
setCurrentIndex(0);
|
setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
|
d->addTabsMenuEntry(DockWidget, index);
|
||||||
DockWidget->setProperty(INDEX_PROPERTY, d->ContentsLayout->count() - 1);
|
|
||||||
d->addTabsMenuEntry(DockWidget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -413,6 +459,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
|
|||||||
auto TitleBar = DockWidget->titleBar();
|
auto TitleBar = DockWidget->titleBar();
|
||||||
d->TabsLayout->removeWidget(TitleBar);
|
d->TabsLayout->removeWidget(TitleBar);
|
||||||
disconnect(TitleBar, SIGNAL(clicked()), this, SLOT(onDockWidgetTitleClicked()));
|
disconnect(TitleBar, SIGNAL(clicked()), this, SLOT(onDockWidgetTitleClicked()));
|
||||||
|
setCurrentIndex(d->ContentsLayout->currentIndex());
|
||||||
d->updateTabsMenu();
|
d->updateTabsMenu();
|
||||||
|
|
||||||
if (d->ContentsLayout->isEmpty())
|
if (d->ContentsLayout->isEmpty())
|
||||||
@ -481,6 +528,13 @@ void CDockAreaWidget::setCurrentIndex(int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
int CDockAreaWidget::currentIndex() const
|
||||||
|
{
|
||||||
|
return d->ContentsLayout->currentIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
QRect CDockAreaWidget::titleAreaGeometry() const
|
QRect CDockAreaWidget::titleAreaGeometry() const
|
||||||
{
|
{
|
||||||
|
@ -77,6 +77,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
CDockContainerWidget* dockContainer() const;
|
CDockContainerWidget* dockContainer() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts a dock widget into dock area.
|
||||||
|
* All dockwidgets in the dock area tabified in a stacked layout with tabs.
|
||||||
|
* The index indicates the index of the new dockwidget in the tabbar and
|
||||||
|
* in the stacked layout. If the Activate parameter is true, the new
|
||||||
|
* DockWidget will be the active one in the stacked layout
|
||||||
|
*/
|
||||||
|
void insertDockWidget(int index, CDockWidget* DockWidget, bool Activate = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new dock widget to dock area.
|
* Add a new dock widget to dock area.
|
||||||
* All dockwidgets in the dock area tabified in a stacked layout with tabs
|
* All dockwidgets in the dock area tabified in a stacked layout with tabs
|
||||||
@ -129,6 +138,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void reorderDockWidget(int fromIndex, int toIndex);
|
void reorderDockWidget(int fromIndex, int toIndex);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the index of the current active dock widget
|
||||||
|
*/
|
||||||
|
int currentIndex() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/**
|
||||||
* This sets the index position of the current tab page.
|
* This sets the index position of the current tab page.
|
||||||
|
@ -117,7 +117,12 @@ struct DockContainerWidgetPrivate
|
|||||||
* Drop floating widget into dock area
|
* Drop floating widget into dock area
|
||||||
*/
|
*/
|
||||||
void dropIntoSection(CFloatingDockContainer* FloatingWidget,
|
void dropIntoSection(CFloatingDockContainer* FloatingWidget,
|
||||||
CDockAreaWidget* targetSection, DockWidgetArea area);
|
CDockAreaWidget* TargetArea, DockWidgetArea area);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds new dock areas to the internal dock area list
|
||||||
|
*/
|
||||||
|
void addDockAreasToList(const QList<CDockAreaWidget*> NewDockAreas);
|
||||||
}; // struct DockContainerWidgetPrivate
|
}; // struct DockContainerWidgetPrivate
|
||||||
|
|
||||||
|
|
||||||
@ -133,19 +138,17 @@ DockContainerWidgetPrivate::DockContainerWidgetPrivate(CDockContainerWidget* _pu
|
|||||||
void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* FloatingWidget,
|
void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* FloatingWidget,
|
||||||
DockWidgetArea area)
|
DockWidgetArea area)
|
||||||
{
|
{
|
||||||
QSplitter* OldSplitter = _this->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
|
||||||
auto InsertParam = internal::dockAreaInsertParameters(area);
|
auto InsertParam = internal::dockAreaInsertParameters(area);
|
||||||
auto NewDockAreas = FloatingWidget->dockContainer()->findChildren<CDockAreaWidget*>(
|
auto NewDockAreas = FloatingWidget->dockContainer()->findChildren<CDockAreaWidget*>(
|
||||||
QString(), Qt::FindChildrenRecursively);
|
QString(), Qt::FindChildrenRecursively);
|
||||||
|
QSplitter* OldSplitter = nullptr;
|
||||||
|
|
||||||
if (DockAreas.isEmpty())
|
// 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())
|
||||||
{
|
{
|
||||||
auto Widget = FloatingWidget->dockContainer()->findChild<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
|
OldSplitter = _this->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
||||||
Layout->addWidget(Widget, 0, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QSplitter* OldSplitter = _this->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
|
||||||
// First replace the dock widget with a splitter
|
// First replace the dock widget with a splitter
|
||||||
if (DockAreas.count() == 1)
|
if (DockAreas.count() == 1)
|
||||||
{
|
{
|
||||||
@ -162,11 +165,17 @@ void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* Float
|
|||||||
NewSplitter->addWidget(OldSplitter);
|
NewSplitter->addWidget(OldSplitter);
|
||||||
OldSplitter = NewSplitter;
|
OldSplitter = NewSplitter;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now we can insert the floating widget content into this container
|
||||||
auto Widget = FloatingWidget->dockContainer()->findChild<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
|
auto Widget = FloatingWidget->dockContainer()->findChild<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
|
||||||
auto FloatingSplitter = dynamic_cast<QSplitter*>(Widget);
|
auto FloatingSplitter = dynamic_cast<QSplitter*>(Widget);
|
||||||
|
if (DockAreas.isEmpty())
|
||||||
if (!FloatingSplitter)
|
{
|
||||||
|
auto Widget = FloatingWidget->dockContainer()->findChild<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
|
||||||
|
Layout->addWidget(Widget, 0, 0);
|
||||||
|
}
|
||||||
|
else if (!FloatingSplitter)
|
||||||
{
|
{
|
||||||
insertWidgetIntoSplitter(OldSplitter, Widget, InsertParam.append());
|
insertWidgetIntoSplitter(OldSplitter, Widget, InsertParam.append());
|
||||||
}
|
}
|
||||||
@ -181,13 +190,96 @@ void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* Float
|
|||||||
{
|
{
|
||||||
insertWidgetIntoSplitter(OldSplitter, FloatingSplitter, InsertParam.append());
|
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);
|
||||||
|
|
||||||
std::cout << "Adding " << NewDockAreas.count() << " dock areas" << std::endl;
|
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);
|
||||||
|
|
||||||
|
if (TargetAreaSplitter->orientation() == InsertParam.orientation())
|
||||||
|
{
|
||||||
|
if (!FloatingSplitter || FloatingSplitter->orientation() != InsertParam.orientation())
|
||||||
|
{
|
||||||
|
TargetAreaSplitter->insertWidget(AreaIndex + InsertParam.insertOffset(), Widget);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int InsertIndex = AreaIndex + InsertParam.insertOffset();
|
||||||
|
while (FloatingSplitter->count())
|
||||||
|
{
|
||||||
|
TargetAreaSplitter->insertWidget(InsertIndex++, FloatingSplitter->widget(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
||||||
|
if (!FloatingSplitter || FloatingSplitter->orientation() != InsertParam.orientation())
|
||||||
|
{
|
||||||
|
NewSplitter->addWidget(Widget);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (FloatingSplitter->count())
|
||||||
|
{
|
||||||
|
NewSplitter->addWidget(FloatingSplitter->widget(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
insertWidgetIntoSplitter(NewSplitter, TargetArea, !InsertParam.append());
|
||||||
|
TargetAreaSplitter->insertWidget(AreaIndex, NewSplitter);
|
||||||
|
}
|
||||||
|
|
||||||
|
FloatingWidget->deleteLater();
|
||||||
|
addDockAreasToList(NewDockAreas);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void DockContainerWidgetPrivate::addDockAreasToList(const QList<CDockAreaWidget*> NewDockAreas)
|
||||||
|
{
|
||||||
int CountBefore = DockAreas.count();
|
int CountBefore = DockAreas.count();
|
||||||
int NewAreaCount = NewDockAreas.count();
|
int NewAreaCount = NewDockAreas.count();
|
||||||
DockAreas.append(NewDockAreas);
|
DockAreas.append(NewDockAreas);
|
||||||
|
|
||||||
|
// 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.
|
||||||
if (1 == CountBefore)
|
if (1 == CountBefore)
|
||||||
{
|
{
|
||||||
DockAreas.at(0)->updateDockArea();
|
DockAreas.at(0)->updateDockArea();
|
||||||
@ -197,15 +289,6 @@ void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* Float
|
|||||||
{
|
{
|
||||||
DockAreas.last()->updateDockArea();
|
DockAreas.last()->updateDockArea();
|
||||||
}
|
}
|
||||||
FloatingWidget->deleteLater();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* FloatingWidget,
|
|
||||||
CDockAreaWidget* targetSection, DockWidgetArea area)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -281,6 +364,16 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetAr
|
|||||||
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
|
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
|
||||||
NewDockArea->addDockWidget(Dockwidget);
|
NewDockArea->addDockWidget(Dockwidget);
|
||||||
auto InsertParam = internal::dockAreaInsertParameters(area);
|
auto InsertParam = internal::dockAreaInsertParameters(area);
|
||||||
|
if (DockAreas.count() == 1)
|
||||||
|
{
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
QSplitter* TargetAreaSplitter = internal::findParent<QSplitter*>(TargetDockArea);
|
QSplitter* TargetAreaSplitter = internal::findParent<QSplitter*>(TargetDockArea);
|
||||||
int index = TargetAreaSplitter ->indexOf(TargetDockArea);
|
int index = TargetAreaSplitter ->indexOf(TargetDockArea);
|
||||||
if (TargetAreaSplitter->orientation() == InsertParam.orientation())
|
if (TargetAreaSplitter->orientation() == InsertParam.orientation())
|
||||||
@ -296,6 +389,7 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetAr
|
|||||||
insertWidgetIntoSplitter(NewSplitter, NewDockArea, InsertParam.append());
|
insertWidgetIntoSplitter(NewSplitter, NewDockArea, InsertParam.append());
|
||||||
TargetAreaSplitter->insertWidget(index, NewSplitter);
|
TargetAreaSplitter->insertWidget(index, NewSplitter);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DockAreas.append(NewDockArea);
|
DockAreas.append(NewDockArea);
|
||||||
return NewDockArea;
|
return NewDockArea;
|
||||||
|
@ -73,6 +73,7 @@ struct DockWidgetTitleBarPrivate
|
|||||||
bool IsActiveTab = false;
|
bool IsActiveTab = false;
|
||||||
CDockAreaWidget* DockArea = nullptr;
|
CDockAreaWidget* DockArea = nullptr;
|
||||||
eDragState DragState = DraggingInactive;
|
eDragState DragState = DraggingInactive;
|
||||||
|
CFloatingDockContainer* FloatingWidget = nullptr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private data constructor
|
* Private data constructor
|
||||||
@ -193,6 +194,7 @@ bool DockWidgetTitleBarPrivate::startFloating(const QPoint& GlobalPos)
|
|||||||
FloatingWidget->startFloating(DragStartMousePosition, Size);
|
FloatingWidget->startFloating(DragStartMousePosition, Size);
|
||||||
auto Overlay = DockWidget->dockManager()->containerOverlay();
|
auto Overlay = DockWidget->dockManager()->containerOverlay();
|
||||||
Overlay->setAllowedAreas(OuterDockAreas);
|
Overlay->setAllowedAreas(OuterDockAreas);
|
||||||
|
this->FloatingWidget = FloatingWidget;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,6 +235,7 @@ void CDockWidgetTitleBar::mousePressEvent(QMouseEvent* ev)
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
void CDockWidgetTitleBar::mouseReleaseEvent(QMouseEvent* ev)
|
void CDockWidgetTitleBar::mouseReleaseEvent(QMouseEvent* ev)
|
||||||
{
|
{
|
||||||
|
std::cout << "CDockWidgetTitleBar::mouseReleaseEvent" << std::endl;
|
||||||
// End of tab moving, change order now
|
// End of tab moving, change order now
|
||||||
if (d->isDraggingState(DraggingTab) && d->DockArea)
|
if (d->isDraggingState(DraggingTab) && d->DockArea)
|
||||||
{
|
{
|
||||||
@ -255,8 +258,6 @@ void CDockWidgetTitleBar::mouseReleaseEvent(QMouseEvent* ev)
|
|||||||
|
|
||||||
d->DragStartMousePosition = QPoint();
|
d->DragStartMousePosition = QPoint();
|
||||||
d->DragState = DraggingInactive;
|
d->DragState = DraggingInactive;
|
||||||
//mcw->m_SectionDropOverlay->hideDropOverlay();
|
|
||||||
//mcw->hideContainerOverlay();
|
|
||||||
QFrame::mouseReleaseEvent(ev);
|
QFrame::mouseReleaseEvent(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,6 +276,8 @@ void CDockWidgetTitleBar::mouseMoveEvent(QMouseEvent* ev)
|
|||||||
|
|
||||||
if (d->isDraggingState(DraggingFloatingWidget))
|
if (d->isDraggingState(DraggingFloatingWidget))
|
||||||
{
|
{
|
||||||
|
std::cout << "DraggingFloatingWidget" << std::endl;
|
||||||
|
d->FloatingWidget->moveFloating();
|
||||||
QFrame::mouseMoveEvent(ev);
|
QFrame::mouseMoveEvent(ev);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -189,6 +189,9 @@ CFloatingDockContainer::CFloatingDockContainer(CDockManager* DockManager) :
|
|||||||
l->addWidget(d->DockContainer);
|
l->addWidget(d->DockContainer);
|
||||||
DockManager->registerFloatingWidget(this);
|
DockManager->registerFloatingWidget(this);
|
||||||
|
|
||||||
|
// We install an event filter to detect mouse release events because we
|
||||||
|
// do not receive mouse release event if the floating widget is behind
|
||||||
|
// the drop overlay cross
|
||||||
qApp->installEventFilter(this);
|
qApp->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,14 +303,7 @@ bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event)
|
|||||||
std::cout << "FloatingWidget::eventFilter QEvent::MouseButtonRelease" << std::endl;
|
std::cout << "FloatingWidget::eventFilter QEvent::MouseButtonRelease" << std::endl;
|
||||||
d->titleMouseReleaseEvent();
|
d->titleMouseReleaseEvent();
|
||||||
}
|
}
|
||||||
else if ((event->type() == QEvent::MouseMove) && d->DraggingActive)
|
|
||||||
{
|
|
||||||
QMouseEvent* MouseEvent = dynamic_cast<QMouseEvent*>(event);
|
|
||||||
int BorderSize = (frameSize().width() - size().width()) / 2;
|
|
||||||
const QPoint moveToPos = QCursor::pos() - d->DragStartMousePosition - QPoint(BorderSize, 0);
|
|
||||||
move(moveToPos);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,6 +318,15 @@ void CFloatingDockContainer::startFloating(const QPoint& Pos, const QSize& Size)
|
|||||||
show();
|
show();
|
||||||
d->DragStartMousePosition = Pos;
|
d->DragStartMousePosition = Pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void CFloatingDockContainer::moveFloating()
|
||||||
|
{
|
||||||
|
int BorderSize = (frameSize().width() - size().width()) / 2;
|
||||||
|
const QPoint moveToPos = QCursor::pos() - d->DragStartMousePosition - QPoint(BorderSize, 0);
|
||||||
|
move(moveToPos);
|
||||||
|
}
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -85,9 +85,17 @@ public:
|
|||||||
CDockContainerWidget* dockContainer() const;
|
CDockContainerWidget* dockContainer() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts floating at the given global position
|
* Starts floating at the given global position.
|
||||||
|
* Use moveToGlobalPos() to move the widget to a new position
|
||||||
|
* depending on the start position given in Pos parameter
|
||||||
*/
|
*/
|
||||||
void startFloating(const QPoint& Pos, const QSize& Size = QSize());
|
void startFloating(const QPoint& Pos, const QSize& Size = QSize());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the widget to a new position relative to the position given when
|
||||||
|
* startFloating() was called
|
||||||
|
*/
|
||||||
|
void moveFloating();
|
||||||
}; // class FloatingDockContainer
|
}; // class FloatingDockContainer
|
||||||
}
|
}
|
||||||
// namespace ads
|
// namespace ads
|
||||||
|
Loading…
Reference in New Issue
Block a user