mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 23:31:32 +08:00
Fixed tab insertion when dragging side tab
This commit is contained in:
parent
be727c5890
commit
f5cfe9e05a
@ -232,7 +232,6 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarL
|
||||
//============================================================================
|
||||
void CAutoHideDockContainer::updateSize()
|
||||
{
|
||||
qDebug() << "CAutoHideDockContainer::updateSize()";
|
||||
auto dockContainerParent = dockContainer();
|
||||
if (!dockContainerParent)
|
||||
{
|
||||
@ -692,7 +691,9 @@ void CAutoHideDockContainer::resetToInitialDockWidgetSize()
|
||||
void CAutoHideDockContainer::moveToNewSideBarLocation(SideBarLocation NewSideBarLocation,
|
||||
int TabIndex)
|
||||
{
|
||||
if (NewSideBarLocation == sideBarLocation())
|
||||
qDebug() << "CAutoHideDockContainer::moveToNewSideBarLocation TabIndex " <<
|
||||
TabIndex << " this->tabIndex: " << this->tabIndex();
|
||||
if (NewSideBarLocation == sideBarLocation() && TabIndex == this->tabIndex())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -709,5 +710,12 @@ void CAutoHideDockContainer::moveToNewSideBarLocation(SideBarLocation NewSideBar
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
int CAutoHideDockContainer::tabIndex() const
|
||||
{
|
||||
return d->SideTab->tabIndex();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -105,6 +105,11 @@ public:
|
||||
*/
|
||||
CDockWidget* dockWidget() const;
|
||||
|
||||
/**
|
||||
* Returns the index of this container in the sidebar
|
||||
*/
|
||||
int tabIndex() const;
|
||||
|
||||
/**
|
||||
* Adds a dock widget and removes the previous dock widget
|
||||
*/
|
||||
|
@ -234,12 +234,24 @@ void CAutoHideSideBar::removeAutoHideWidget(CAutoHideDockContainer* AutoHideWidg
|
||||
|
||||
//============================================================================
|
||||
void CAutoHideSideBar::addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget,
|
||||
int Index)
|
||||
int TabIndex)
|
||||
{
|
||||
auto SideBar = AutoHideWidget->autoHideTab()->sideBar();
|
||||
if (SideBar == this)
|
||||
{
|
||||
return;
|
||||
// If we move to the same tab index or if we insert before the next
|
||||
// tab index, then we will end at the same tab position and can leave
|
||||
if (AutoHideWidget->tabIndex() == TabIndex || (AutoHideWidget->tabIndex() + 1) == TabIndex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// We remove this auto hide widget from the sidebar in the code below
|
||||
// and therefore need to correct the TabIndex here
|
||||
if (AutoHideWidget->tabIndex() < TabIndex)
|
||||
{
|
||||
--TabIndex;
|
||||
}
|
||||
}
|
||||
|
||||
if (SideBar)
|
||||
@ -249,7 +261,7 @@ void CAutoHideSideBar::addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget,
|
||||
AutoHideWidget->setParent(d->ContainerWidget);
|
||||
AutoHideWidget->setSideBarLocation(d->SideTabArea);
|
||||
d->ContainerWidget->registerAutoHideWidget(AutoHideWidget);
|
||||
insertTab(Index, AutoHideWidget->autoHideTab());
|
||||
insertTab(TabIndex, AutoHideWidget->autoHideTab());
|
||||
}
|
||||
|
||||
|
||||
@ -349,6 +361,21 @@ bool CAutoHideSideBar::hasVisibleTabs() const
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
int CAutoHideSideBar::indexOfTab(const CAutoHideTab& Tab) const
|
||||
{
|
||||
for (auto i = 0; i < count(); i++)
|
||||
{
|
||||
if (tab(i) == &Tab)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
SideBarLocation CAutoHideSideBar::sideBarLocation() const
|
||||
{
|
||||
@ -424,13 +451,24 @@ int CAutoHideSideBar::tabAt(const QPoint& Pos) const
|
||||
{
|
||||
if (!isVisible())
|
||||
{
|
||||
return -2;
|
||||
return InvalidTabIndex;
|
||||
}
|
||||
|
||||
if (Pos.x() < tab(0)->geometry().x())
|
||||
if (orientation() == Qt::Horizontal)
|
||||
{
|
||||
return -1;
|
||||
if (Pos.x() < tab(0)->geometry().x())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Pos.y() < tab(0)->geometry().y())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < count(); ++i)
|
||||
{
|
||||
@ -448,7 +486,14 @@ int CAutoHideSideBar::tabAt(const QPoint& Pos) const
|
||||
int CAutoHideSideBar::tabInsertIndexAt(const QPoint& Pos) const
|
||||
{
|
||||
int Index = tabAt(Pos);
|
||||
return (Index < 0) ? -1 : Index;
|
||||
if (Index == InvalidTabIndex)
|
||||
{
|
||||
return Append;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (Index < 0) ? 0 : Index;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ads
|
||||
|
@ -84,6 +84,8 @@ protected:
|
||||
|
||||
public:
|
||||
using Super = QScrollArea;
|
||||
static constexpr int Append = -1;
|
||||
static constexpr int InvalidTabIndex = -2;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
@ -117,7 +119,7 @@ public:
|
||||
* If the AutoHideWidget is in another sidebar, then it will be removed
|
||||
* from this sidebar.
|
||||
*/
|
||||
void addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget, int Index = -1);
|
||||
void addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget, int Index = Append);
|
||||
|
||||
/**
|
||||
* Returns orientation of side tab.
|
||||
@ -125,15 +127,15 @@ public:
|
||||
Qt::Orientation orientation() const;
|
||||
|
||||
/*
|
||||
* get the side tab widget at position, returns nullptr if it's out of bounds
|
||||
* Get the side tab widget at position, returns nullptr if it's out of bounds
|
||||
*/
|
||||
CAutoHideTab* tab(int index) const;
|
||||
|
||||
/**
|
||||
* Returns the tab at the given position.
|
||||
* Returns -1 if the position is left of the first tab and count() if the
|
||||
* position is right of the last tab. Returns -2 to indicate an invalid
|
||||
* value.
|
||||
* position is right of the last tab. Returns InvalidTabIndex (-2) to
|
||||
* indicate an invalid value.
|
||||
*/
|
||||
int tabAt(const QPoint& Pos) const;
|
||||
|
||||
@ -142,6 +144,11 @@ public:
|
||||
*/
|
||||
int tabInsertIndexAt(const QPoint& Pos) const;
|
||||
|
||||
/**
|
||||
* Returns the index of the given tab
|
||||
*/
|
||||
int indexOfTab(const CAutoHideTab& Tab) const;
|
||||
|
||||
/*
|
||||
* Gets the count of the tab widgets
|
||||
*/
|
||||
|
@ -546,4 +546,16 @@ void CAutoHideTab::requestCloseDockWidget()
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
int CAutoHideTab::tabIndex() const
|
||||
{
|
||||
if (!d->SideBar)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return d->SideBar->indexOfTab(*this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -140,6 +140,11 @@ public:
|
||||
*/
|
||||
CAutoHideSideBar* sideBar() const;
|
||||
|
||||
/**
|
||||
* Returns the index of this tab in the sideBar
|
||||
*/
|
||||
int tabIndex() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
* Set the dock widget floating, if it is floatable
|
||||
|
@ -260,7 +260,6 @@ void DockAreaTitleBarPrivate::createTabBar()
|
||||
//============================================================================
|
||||
IFloatingWidget* DockAreaTitleBarPrivate::makeAreaFloating(const QPoint& Offset, eDragState DragState)
|
||||
{
|
||||
qDebug() << "DockAreaTitleBarPrivate::makeAreaFloating " << DockArea->size();
|
||||
QSize Size = DockArea->size();
|
||||
this->DragState = DragState;
|
||||
bool CreateFloatingDockContainer = (DraggingFloatingWidget != DragState);
|
||||
|
@ -523,12 +523,13 @@ void DockContainerWidgetPrivate::dropIntoAutoHideSideBar(CFloatingDockContainer*
|
||||
auto SideBarLocation = internal::toSideBarLocation(area);
|
||||
auto NewDockAreas = FloatingWidget->findChildren<CDockAreaWidget*>(
|
||||
QString(), Qt::FindChildrenRecursively);
|
||||
int TabIndex = DockManager->containerOverlay()->tabIndexUnderCursor();
|
||||
for (auto DockArea : NewDockAreas)
|
||||
{
|
||||
auto DockWidgets = DockArea->dockWidgets();
|
||||
for (auto DockWidget : DockWidgets)
|
||||
{
|
||||
_this->createAndSetupAutoHideContainer(SideBarLocation, DockWidget);
|
||||
_this->createAndSetupAutoHideContainer(SideBarLocation, DockWidget, TabIndex++);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -574,7 +575,6 @@ void DockContainerWidgetPrivate::dropIntoCenterOfSection(
|
||||
void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* FloatingWidget,
|
||||
CDockAreaWidget* TargetArea, DockWidgetArea area, int TabIndex)
|
||||
{
|
||||
qDebug() << "DockContainerWidgetPrivate::dropIntoSection TabIndex: " << TabIndex;
|
||||
// Dropping into center means all dock widgets in the dropped floating
|
||||
// widget will become tabs of the drop area
|
||||
if (CenterDockWidgetArea == area)
|
||||
@ -672,8 +672,6 @@ void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* Floatin
|
||||
void DockContainerWidgetPrivate::moveIntoCenterOfSection(QWidget* Widget, CDockAreaWidget* TargetArea,
|
||||
int TabIndex)
|
||||
{
|
||||
qDebug() << "DockContainerWidgetPrivate::moveIntoCenterOfSection TabIndex: "
|
||||
<< TabIndex;
|
||||
auto DroppedDockWidget = qobject_cast<CDockWidget*>(Widget);
|
||||
auto DroppedArea = qobject_cast<CDockAreaWidget*>(Widget);
|
||||
|
||||
@ -715,8 +713,6 @@ void DockContainerWidgetPrivate::moveIntoCenterOfSection(QWidget* Widget, CDockA
|
||||
void DockContainerWidgetPrivate::moveToNewSection(QWidget* Widget, CDockAreaWidget* TargetArea, DockWidgetArea area,
|
||||
int TabIndex)
|
||||
{
|
||||
qDebug() << "DockContainerWidgetPrivate::moveToNewSection TabIndex: "
|
||||
<< TabIndex;
|
||||
// Dropping into center means all dock widgets in the dropped floating
|
||||
// widget will become tabs of the drop area
|
||||
if (CenterDockWidgetArea == area)
|
||||
@ -1707,7 +1703,6 @@ int CDockContainerWidget::visibleDockAreaCount() const
|
||||
void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWidget,
|
||||
const QPoint& TargetPos)
|
||||
{
|
||||
//dockContainer()->createAndSetupAutoHideContainer(area, this);
|
||||
ADS_PRINT("CDockContainerWidget::dropFloatingWidget");
|
||||
CDockWidget* SingleDroppedDockWidget = FloatingWidget->topLevelDockWidget();
|
||||
CDockWidget* SingleDockWidget = topLevelDockWidget();
|
||||
@ -1716,6 +1711,7 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
|
||||
bool Dropped = false;
|
||||
|
||||
CDockAreaWidget* DockArea = dockAreaAt(TargetPos);
|
||||
// mouse is over dock area
|
||||
if (DockArea)
|
||||
{
|
||||
auto dropOverlay = d->DockManager->dockAreaOverlay();
|
||||
@ -1736,7 +1732,7 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
|
||||
}
|
||||
}
|
||||
|
||||
// mouse is over container
|
||||
// mouse is over container or auto hide side bar
|
||||
if (InvalidDockWidgetArea == dropArea && InvalidDockWidgetArea != ContainerDropArea)
|
||||
{
|
||||
if (internal::isSideBarArea(ContainerDropArea))
|
||||
|
@ -506,7 +506,6 @@ DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
|
||||
if (SideBar->isVisible())
|
||||
{
|
||||
d->TabIndex = SideBar->tabInsertIndexAt(SideBar->mapFromGlobal(CursorPos));
|
||||
qDebug() << "TabIndex " << d->TabIndex;
|
||||
}
|
||||
}
|
||||
return Result;
|
||||
@ -522,7 +521,6 @@ DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
|
||||
{
|
||||
auto TabBar = DockArea->titleBar()->tabBar();
|
||||
d->TabIndex = TabBar->tabAt(TabBar->mapFromGlobal(CursorPos));
|
||||
qDebug() << "TabIndex " << d->TabIndex;
|
||||
return CenterDockWidgetArea;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user