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