mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 13:15:43 +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;
|
||||
CResizeHandle* ResizeHandle = nullptr;
|
||||
QSize Size; // creates invalid size
|
||||
CDockWidgetSideTab* SideTab = nullptr;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
|
@ -70,12 +70,14 @@ public:
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
CAutoHideDockContainer(CDockWidget* DockWidget, SideBarLocation area, CDockContainerWidget* parent);
|
||||
CAutoHideDockContainer(CDockWidget* DockWidget, SideBarLocation area,
|
||||
CDockContainerWidget* parent);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
|
@ -79,7 +79,6 @@ struct DockWidgetPrivate
|
||||
QBoxLayout* Layout = nullptr;
|
||||
QWidget* Widget = nullptr;
|
||||
CDockWidgetTab* TabWidget = nullptr;
|
||||
CDockWidgetSideTab* SideTabWidget = nullptr;
|
||||
CDockWidget::DockWidgetFeatures Features = CDockWidget::DefaultDockWidgetFeatures;
|
||||
CDockManager* DockManager = nullptr;
|
||||
CDockAreaWidget* DockArea = nullptr;
|
||||
@ -97,6 +96,7 @@ struct DockWidgetPrivate
|
||||
WidgetFactory* Factory = nullptr;
|
||||
double DefaultAutoHideDockProportion = 0.25;
|
||||
CDockWidget::eAutoHideInsertOrder AutoHideInsertOrder = CDockWidget::Last;
|
||||
QPointer<CDockWidgetSideTab> SideTabWidget;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -246,6 +246,8 @@ void DockWidgetPrivate::updateParentDockArea()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockWidgetPrivate::closeAutoHideDockWidgetsIfNeeded()
|
||||
{
|
||||
if (_this->dockContainer() && _this->dockContainer()->openedDockWidgets().isEmpty() && !_this->dockManager()->isRestoringState())
|
||||
|
@ -113,6 +113,7 @@ CSideTabBar::CSideTabBar(CDockContainerWidget* parent, SideBarLocation area) :
|
||||
//============================================================================
|
||||
CSideTabBar::~CSideTabBar()
|
||||
{
|
||||
qDebug() << "~CSideTabBar() ";
|
||||
// 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
|
||||
auto Tabs = findChildren<CDockWidgetSideTab*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
@ -127,6 +128,7 @@ CSideTabBar::~CSideTabBar()
|
||||
//============================================================================
|
||||
void CSideTabBar::insertSideTab(int Index, CDockWidgetSideTab* SideTab)
|
||||
{
|
||||
SideTab->installEventFilter(this);
|
||||
d->TabsLayout->insertWidget(Index, SideTab);
|
||||
SideTab->setSideTabBar(this);
|
||||
show();
|
||||
@ -166,6 +168,7 @@ void CSideTabBar::removeDockWidget(CDockWidget* DockWidget)
|
||||
void CSideTabBar::removeSideTab(CDockWidgetSideTab* SideTab)
|
||||
{
|
||||
qDebug() << "CSideTabBar::removeSideTab " << SideTab->text();
|
||||
SideTab->removeEventFilter(this);
|
||||
d->TabsLayout->removeWidget(SideTab);
|
||||
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)
|
||||
{
|
||||
@ -212,4 +274,5 @@ SideBarLocation CSideTabBar::sideTabBarArea() const
|
||||
{
|
||||
return d->SideTabArea;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,7 +55,9 @@ private:
|
||||
friend class DockWidgetSideTab;
|
||||
|
||||
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:
|
||||
using Super = QFrame;
|
||||
|
Loading…
Reference in New Issue
Block a user