mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 21:25:44 +08:00
Implemented showing and hiding of side bar when it does not contain any visible tab
This commit is contained in:
parent
c80174e7e5
commit
f6b77f5c3c
@ -107,6 +107,7 @@ struct AutoHideDockContainerPrivate
|
|||||||
QBoxLayout* Layout;
|
QBoxLayout* Layout;
|
||||||
CResizeHandle* ResizeHandle = nullptr;
|
CResizeHandle* ResizeHandle = nullptr;
|
||||||
QSize Size; // creates invalid size
|
QSize Size; // creates invalid size
|
||||||
|
CDockWidgetSideTab* SideTab = nullptr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private data constructor
|
* Private data constructor
|
||||||
|
@ -70,12 +70,14 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Create Auto Hide widget with a dock manager
|
* Create Auto Hide widget with a dock manager
|
||||||
*/
|
*/
|
||||||
CAutoHideDockContainer(CDockManager* DockManager, SideBarLocation area, CDockContainerWidget* parent);
|
CAutoHideDockContainer(CDockManager* DockManager, SideBarLocation area,
|
||||||
|
CDockContainerWidget* parent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create Auto Hide widget with the given dock widget
|
* Create Auto Hide widget with the given dock widget
|
||||||
*/
|
*/
|
||||||
CAutoHideDockContainer(CDockWidget* DockWidget, SideBarLocation area, CDockContainerWidget* parent);
|
CAutoHideDockContainer(CDockWidget* DockWidget, SideBarLocation area,
|
||||||
|
CDockContainerWidget* parent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Virtual Destructor
|
* Virtual Destructor
|
||||||
|
@ -79,7 +79,6 @@ struct DockWidgetPrivate
|
|||||||
QBoxLayout* Layout = nullptr;
|
QBoxLayout* Layout = nullptr;
|
||||||
QWidget* Widget = nullptr;
|
QWidget* Widget = nullptr;
|
||||||
CDockWidgetTab* TabWidget = nullptr;
|
CDockWidgetTab* TabWidget = nullptr;
|
||||||
CDockWidgetSideTab* SideTabWidget = nullptr;
|
|
||||||
CDockWidget::DockWidgetFeatures Features = CDockWidget::DefaultDockWidgetFeatures;
|
CDockWidget::DockWidgetFeatures Features = CDockWidget::DefaultDockWidgetFeatures;
|
||||||
CDockManager* DockManager = nullptr;
|
CDockManager* DockManager = nullptr;
|
||||||
CDockAreaWidget* DockArea = nullptr;
|
CDockAreaWidget* DockArea = nullptr;
|
||||||
@ -97,6 +96,7 @@ struct DockWidgetPrivate
|
|||||||
WidgetFactory* Factory = nullptr;
|
WidgetFactory* Factory = nullptr;
|
||||||
double DefaultAutoHideDockProportion = 0.25;
|
double DefaultAutoHideDockProportion = 0.25;
|
||||||
CDockWidget::eAutoHideInsertOrder AutoHideInsertOrder = CDockWidget::Last;
|
CDockWidget::eAutoHideInsertOrder AutoHideInsertOrder = CDockWidget::Last;
|
||||||
|
QPointer<CDockWidgetSideTab> SideTabWidget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private data constructor
|
* Private data constructor
|
||||||
@ -246,6 +246,8 @@ void DockWidgetPrivate::updateParentDockArea()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
void DockWidgetPrivate::closeAutoHideDockWidgetsIfNeeded()
|
void DockWidgetPrivate::closeAutoHideDockWidgetsIfNeeded()
|
||||||
{
|
{
|
||||||
if (_this->dockContainer() && _this->dockContainer()->openedDockWidgets().isEmpty() && !_this->dockManager()->isRestoringState())
|
if (_this->dockContainer() && _this->dockContainer()->openedDockWidgets().isEmpty() && !_this->dockManager()->isRestoringState())
|
||||||
|
@ -113,6 +113,7 @@ CSideTabBar::CSideTabBar(CDockContainerWidget* parent, SideBarLocation area) :
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
CSideTabBar::~CSideTabBar()
|
CSideTabBar::~CSideTabBar()
|
||||||
{
|
{
|
||||||
|
qDebug() << "~CSideTabBar() ";
|
||||||
// The SideTabeBar is not the owner of the tabs and to prevent deletion
|
// The SideTabeBar is not the owner of the tabs and to prevent deletion
|
||||||
// we set the parent here to nullptr to remove it from the children
|
// we set the parent here to nullptr to remove it from the children
|
||||||
auto Tabs = findChildren<CDockWidgetSideTab*>(QString(), Qt::FindDirectChildrenOnly);
|
auto Tabs = findChildren<CDockWidgetSideTab*>(QString(), Qt::FindDirectChildrenOnly);
|
||||||
@ -127,6 +128,7 @@ CSideTabBar::~CSideTabBar()
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
void CSideTabBar::insertSideTab(int Index, CDockWidgetSideTab* SideTab)
|
void CSideTabBar::insertSideTab(int Index, CDockWidgetSideTab* SideTab)
|
||||||
{
|
{
|
||||||
|
SideTab->installEventFilter(this);
|
||||||
d->TabsLayout->insertWidget(Index, SideTab);
|
d->TabsLayout->insertWidget(Index, SideTab);
|
||||||
SideTab->setSideTabBar(this);
|
SideTab->setSideTabBar(this);
|
||||||
show();
|
show();
|
||||||
@ -166,6 +168,7 @@ void CSideTabBar::removeDockWidget(CDockWidget* DockWidget)
|
|||||||
void CSideTabBar::removeSideTab(CDockWidgetSideTab* SideTab)
|
void CSideTabBar::removeSideTab(CDockWidgetSideTab* SideTab)
|
||||||
{
|
{
|
||||||
qDebug() << "CSideTabBar::removeSideTab " << SideTab->text();
|
qDebug() << "CSideTabBar::removeSideTab " << SideTab->text();
|
||||||
|
SideTab->removeEventFilter(this);
|
||||||
d->TabsLayout->removeWidget(SideTab);
|
d->TabsLayout->removeWidget(SideTab);
|
||||||
if (d->TabsLayout->isEmpty())
|
if (d->TabsLayout->isEmpty())
|
||||||
{
|
{
|
||||||
@ -174,6 +177,65 @@ void CSideTabBar::removeSideTab(CDockWidgetSideTab* SideTab)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
bool CSideTabBar::event(QEvent* e)
|
||||||
|
{
|
||||||
|
qDebug() << e;
|
||||||
|
switch (e->type())
|
||||||
|
{
|
||||||
|
case QEvent::ChildRemoved:
|
||||||
|
if (d->TabsLayout->isEmpty())
|
||||||
|
{
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case QEvent::Resize:
|
||||||
|
if (d->TabsLayout->count())
|
||||||
|
{
|
||||||
|
auto ev = static_cast<QResizeEvent*>(e);
|
||||||
|
auto Tab = tabAt(0);
|
||||||
|
int Size = d->isHorizontal() ? ev->size().height() : ev->size().width();
|
||||||
|
int TabSize = d->isHorizontal() ? Tab->size().height() : Tab->size().width();
|
||||||
|
// If the size of the side bar is less than the size of the first tab
|
||||||
|
// then there are no visible tabs in this side bar. This check will
|
||||||
|
// fail if someone will force a very big border via CSS!!
|
||||||
|
if (Size < TabSize)
|
||||||
|
{
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return Super::event(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
bool CSideTabBar::eventFilter(QObject *watched, QEvent *event)
|
||||||
|
{
|
||||||
|
if (event->type() != QEvent::ShowToParent)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// As soon as on tab is shhown, we need to show the side tab bar
|
||||||
|
auto Tab = qobject_cast<CDockWidgetSideTab*>(watched);
|
||||||
|
if (Tab)
|
||||||
|
{
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
void CSideTabBar::paintEvent(QPaintEvent* event)
|
void CSideTabBar::paintEvent(QPaintEvent* event)
|
||||||
{
|
{
|
||||||
@ -212,4 +274,5 @@ SideBarLocation CSideTabBar::sideTabBarArea() const
|
|||||||
{
|
{
|
||||||
return d->SideTabArea;
|
return d->SideTabArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,9 @@ private:
|
|||||||
friend class DockWidgetSideTab;
|
friend class DockWidgetSideTab;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent* event) override;
|
virtual void paintEvent(QPaintEvent* event) override;
|
||||||
|
virtual bool event(QEvent* e) override;
|
||||||
|
virtual bool eventFilter(QObject *watched, QEvent *event) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using Super = QFrame;
|
using Super = QFrame;
|
||||||
|
Loading…
Reference in New Issue
Block a user