mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 23:31:32 +08:00
Properly handle dragging of dock widget into DockWidgetTabBar and AutoHideSideBar
This commit is contained in:
parent
f5cfe9e05a
commit
7140e5e32a
@ -196,6 +196,7 @@ void CAutoHideSideBar::insertTab(int Index, CAutoHideTab* SideTab)
|
||||
{
|
||||
SideTab->setSideBar(this);
|
||||
SideTab->installEventFilter(this);
|
||||
// Default insertion is append
|
||||
if (Index < 0)
|
||||
{
|
||||
d->TabsLayout->insertWidget(d->TabsLayout->count() - 1, SideTab);
|
||||
@ -451,7 +452,7 @@ int CAutoHideSideBar::tabAt(const QPoint& Pos) const
|
||||
{
|
||||
if (!isVisible())
|
||||
{
|
||||
return InvalidTabIndex;
|
||||
return TabInvalidIndex;
|
||||
}
|
||||
|
||||
if (orientation() == Qt::Horizontal)
|
||||
@ -486,9 +487,9 @@ int CAutoHideSideBar::tabAt(const QPoint& Pos) const
|
||||
int CAutoHideSideBar::tabInsertIndexAt(const QPoint& Pos) const
|
||||
{
|
||||
int Index = tabAt(Pos);
|
||||
if (Index == InvalidTabIndex)
|
||||
if (Index == TabInvalidIndex)
|
||||
{
|
||||
return Append;
|
||||
return TabDefaultInsertIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -84,8 +84,6 @@ protected:
|
||||
|
||||
public:
|
||||
using Super = QScrollArea;
|
||||
static constexpr int Append = -1;
|
||||
static constexpr int InvalidTabIndex = -2;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
@ -119,7 +117,7 @@ public:
|
||||
* If the AutoHideWidget is in another sidebar, then it will be removed
|
||||
* from this sidebar.
|
||||
*/
|
||||
void addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget, int Index = Append);
|
||||
void addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget, int Index = TabDefaultInsertIndex);
|
||||
|
||||
/**
|
||||
* Returns orientation of side tab.
|
||||
|
@ -510,7 +510,7 @@ int CDockAreaTabBar::tabAt(const QPoint& Pos) const
|
||||
{
|
||||
if (!isVisible())
|
||||
{
|
||||
return -2;
|
||||
return TabInvalidIndex;
|
||||
}
|
||||
|
||||
if (Pos.x() < tab(0)->geometry().x())
|
||||
@ -529,6 +529,21 @@ int CDockAreaTabBar::tabAt(const QPoint& Pos) const
|
||||
return count();
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
int CDockAreaTabBar::tabInsertIndexAt(const QPoint& Pos) const
|
||||
{
|
||||
int Index = tabAt(Pos);
|
||||
if (Index == TabInvalidIndex)
|
||||
{
|
||||
return TabDefaultInsertIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (Index < 0) ? 0 : Index;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ads
|
||||
|
||||
|
||||
|
@ -121,6 +121,11 @@ public:
|
||||
*/
|
||||
int tabAt(const QPoint& Pos) const;
|
||||
|
||||
/**
|
||||
* Returns the tab insertion index for the given mouse cursor position
|
||||
*/
|
||||
int tabInsertIndexAt(const QPoint& Pos) const;
|
||||
|
||||
/**
|
||||
* Filters the tab widget events
|
||||
*/
|
||||
|
@ -190,20 +190,20 @@ public:
|
||||
* Creates a new tab for a widget dropped into the center of a section
|
||||
*/
|
||||
void dropIntoCenterOfSection(CFloatingDockContainer* FloatingWidget,
|
||||
CDockAreaWidget* TargetArea, int TabIndex = -2);
|
||||
CDockAreaWidget* TargetArea, int TabIndex = 0);
|
||||
|
||||
/**
|
||||
* Drop floating widget into dock area
|
||||
*/
|
||||
void dropIntoSection(CFloatingDockContainer* FloatingWidget,
|
||||
CDockAreaWidget* TargetArea, DockWidgetArea area, int TabIndex = -2);
|
||||
CDockAreaWidget* TargetArea, DockWidgetArea area, int TabIndex = 0);
|
||||
|
||||
/**
|
||||
* Moves the dock widget or dock area given in Widget parameter to a
|
||||
* new dock widget area
|
||||
*/
|
||||
void moveToNewSection(QWidget* Widget, CDockAreaWidget* TargetArea, DockWidgetArea area,
|
||||
int TabIndex = -2);
|
||||
int TabIndex = 0);
|
||||
|
||||
/**
|
||||
* Moves the dock widget or dock area given in Widget parameter to a
|
||||
@ -214,13 +214,13 @@ public:
|
||||
/**
|
||||
* Creates a new tab for a widget dropped into the center of a section
|
||||
*/
|
||||
void moveIntoCenterOfSection(QWidget* Widget, CDockAreaWidget* TargetArea, int TabIndex = -2);
|
||||
void moveIntoCenterOfSection(QWidget* Widget, CDockAreaWidget* TargetArea, int TabIndex = 0);
|
||||
|
||||
/**
|
||||
* Moves the dock widget or dock area given in Widget parameter to
|
||||
* a auto hide sidebar area
|
||||
*/
|
||||
void moveToAutoHideSideBar(QWidget* Widget, DockWidgetArea area, int TabIndex = -2);
|
||||
void moveToAutoHideSideBar(QWidget* Widget, DockWidgetArea area, int TabIndex = TabDefaultInsertIndex);
|
||||
|
||||
|
||||
/**
|
||||
@ -543,7 +543,7 @@ void DockContainerWidgetPrivate::dropIntoCenterOfSection(
|
||||
auto NewDockWidgets = FloatingContainer->dockWidgets();
|
||||
auto TopLevelDockArea = FloatingContainer->topLevelDockArea();
|
||||
int NewCurrentIndex = -1;
|
||||
TabIndex = (TabIndex < 0) ? 0 : TabIndex;
|
||||
TabIndex = qMax(0, TabIndex);
|
||||
|
||||
// If the floating widget contains only one single dock are, then the
|
||||
// current dock widget of the dock area will also be the future current
|
||||
@ -675,7 +675,7 @@ void DockContainerWidgetPrivate::moveIntoCenterOfSection(QWidget* Widget, CDockA
|
||||
auto DroppedDockWidget = qobject_cast<CDockWidget*>(Widget);
|
||||
auto DroppedArea = qobject_cast<CDockAreaWidget*>(Widget);
|
||||
|
||||
TabIndex = (TabIndex < 0) ? 0 : TabIndex;
|
||||
TabIndex = qMax(0, TabIndex);
|
||||
if (DroppedDockWidget)
|
||||
{
|
||||
CDockAreaWidget* OldDockArea = DroppedDockWidget->dockAreaWidget();
|
||||
@ -1493,7 +1493,6 @@ CAutoHideDockContainer* CDockContainerWidget::createAndSetupAutoHideContainer(
|
||||
DockWidget->setDockManager(d->DockManager); // Auto hide Dock Container needs a valid dock manager
|
||||
}
|
||||
|
||||
qDebug() << "CDockContainerWidget::createAndSetupAutoHideContainer TabIndex: " << TabIndex;
|
||||
return autoHideSideBar(area)->insertDockWidget(TabIndex, DockWidget);
|
||||
}
|
||||
|
||||
|
@ -520,7 +520,7 @@ DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
|
||||
&& DockArea->titleBarGeometry().contains(DockArea->mapFromGlobal(CursorPos)))
|
||||
{
|
||||
auto TabBar = DockArea->titleBar()->tabBar();
|
||||
d->TabIndex = TabBar->tabAt(TabBar->mapFromGlobal(CursorPos));
|
||||
d->TabIndex = TabBar->tabInsertIndexAt(TabBar->mapFromGlobal(CursorPos));
|
||||
return CenterDockWidgetArea;
|
||||
}
|
||||
|
||||
|
@ -95,6 +95,13 @@ enum DockWidgetArea
|
||||
Q_DECLARE_FLAGS(DockWidgetAreas, DockWidgetArea)
|
||||
|
||||
|
||||
enum eTabIndex
|
||||
{
|
||||
TabDefaultInsertIndex = -1,
|
||||
TabInvalidIndex = -2
|
||||
};
|
||||
|
||||
|
||||
enum TitleBarButton
|
||||
{
|
||||
TitleBarButtonTabsMenu,
|
||||
|
Loading…
Reference in New Issue
Block a user