mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-03-31 18:32:38 +08:00
Ensure the SideTab is hidden if empty
This commit is contained in:
parent
cd58e6e9b5
commit
875a358600
BIN
doc/taiwan_ukraine.jpg
Normal file
BIN
doc/taiwan_ukraine.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 140 KiB |
@ -54,6 +54,15 @@ struct SideTabBarPrivate
|
|||||||
CDockContainerWidget* ContainerWidget;
|
CDockContainerWidget* ContainerWidget;
|
||||||
QBoxLayout* TabsLayout;
|
QBoxLayout* TabsLayout;
|
||||||
Qt::Orientation Orientation;
|
Qt::Orientation Orientation;
|
||||||
|
CDockWidgetSideTab::SideTabBarArea SideTabArea = CDockWidgetSideTab::Left;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience function to check if this is a horizontal side bar
|
||||||
|
*/
|
||||||
|
bool isHorizontal() const
|
||||||
|
{
|
||||||
|
return Qt::Horizontal == Orientation;
|
||||||
|
}
|
||||||
}; // struct SideTabBarPrivate
|
}; // struct SideTabBarPrivate
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
@ -64,12 +73,14 @@ SideTabBarPrivate::SideTabBarPrivate(CSideTabBar* _public) :
|
|||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
CSideTabBar::CSideTabBar(CDockContainerWidget* parent, Qt::Orientation orientation) :
|
CSideTabBar::CSideTabBar(CDockContainerWidget* parent, CDockWidgetSideTab::SideTabBarArea area) :
|
||||||
QWidget(parent),
|
Super(parent),
|
||||||
d(new SideTabBarPrivate(this))
|
d(new SideTabBarPrivate(this))
|
||||||
{
|
{
|
||||||
|
d->SideTabArea = area;
|
||||||
d->ContainerWidget = parent;
|
d->ContainerWidget = parent;
|
||||||
d->Orientation = orientation;
|
d->Orientation = (area == CDockWidgetSideTab::Bottom || area == CDockWidgetSideTab::Top)
|
||||||
|
? Qt::Horizontal : Qt::Vertical;
|
||||||
|
|
||||||
auto mainLayout = new QBoxLayout(d->Orientation == Qt::Vertical ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
|
auto mainLayout = new QBoxLayout(d->Orientation == Qt::Vertical ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
|
||||||
|
|
||||||
@ -80,9 +91,19 @@ CSideTabBar::CSideTabBar(CDockContainerWidget* parent, Qt::Orientation orientati
|
|||||||
mainLayout->setContentsMargins(0, 0, 0, 0);
|
mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
mainLayout->setSpacing(0);
|
mainLayout->setSpacing(0);
|
||||||
mainLayout->addStretch(1);
|
mainLayout->addStretch(1);
|
||||||
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
||||||
setFocusPolicy(Qt::NoFocus);
|
setFocusPolicy(Qt::NoFocus);
|
||||||
|
if (d->isHorizontal())
|
||||||
|
{
|
||||||
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||||
|
}
|
||||||
|
|
||||||
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -98,6 +119,7 @@ void CSideTabBar::insertSideTab(int Index, CDockWidgetSideTab* SideTab)
|
|||||||
{
|
{
|
||||||
d->TabsLayout->insertWidget(Index, SideTab);
|
d->TabsLayout->insertWidget(Index, SideTab);
|
||||||
SideTab->setSideTabBar(this);
|
SideTab->setSideTabBar(this);
|
||||||
|
show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -105,6 +127,10 @@ void CSideTabBar::insertSideTab(int Index, CDockWidgetSideTab* SideTab)
|
|||||||
void CSideTabBar::removeSideTab(CDockWidgetSideTab* SideTab)
|
void CSideTabBar::removeSideTab(CDockWidgetSideTab* SideTab)
|
||||||
{
|
{
|
||||||
d->TabsLayout->removeWidget(SideTab);
|
d->TabsLayout->removeWidget(SideTab);
|
||||||
|
if (d->TabsLayout->isEmpty())
|
||||||
|
{
|
||||||
|
hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -139,4 +165,11 @@ int CSideTabBar::tabCount() const
|
|||||||
{
|
{
|
||||||
return d->TabsLayout->count();
|
return d->TabsLayout->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
CDockWidgetSideTab::SideTabBarArea CSideTabBar::sideTabBarArea() const
|
||||||
|
{
|
||||||
|
return d->SideTabArea;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,8 @@
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
// INCLUDES
|
// INCLUDES
|
||||||
//============================================================================
|
//============================================================================
|
||||||
#include <QWidget>
|
#include <QFrame>
|
||||||
|
#include "DockWidgetSideTab.h"
|
||||||
#include "ads_globals.h"
|
#include "ads_globals.h"
|
||||||
|
|
||||||
namespace ads
|
namespace ads
|
||||||
@ -37,15 +38,14 @@ namespace ads
|
|||||||
struct SideTabBarPrivate;
|
struct SideTabBarPrivate;
|
||||||
class CDockContainerWidget;
|
class CDockContainerWidget;
|
||||||
class CDockWidgetSideTab;
|
class CDockWidgetSideTab;
|
||||||
class CDockWidgetTab;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Side tab widget that is shown at the edges of a dock container.
|
* Side tab widget that is shown at the edges of a dock container.
|
||||||
*/
|
*/
|
||||||
class ADS_EXPORT CSideTabBar : public QWidget
|
class ADS_EXPORT CSideTabBar : public QFrame
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int sideTabBarArea READ sideTabBarArea)
|
||||||
Q_PROPERTY(Qt::Orientation orientation READ orientation)
|
Q_PROPERTY(Qt::Orientation orientation READ orientation)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -57,12 +57,12 @@ protected:
|
|||||||
void paintEvent(QPaintEvent* event) override;
|
void paintEvent(QPaintEvent* event) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using Super = QWidget;
|
using Super = QFrame;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
*/
|
*/
|
||||||
CSideTabBar(CDockContainerWidget* parent, Qt::Orientation orientation);
|
CSideTabBar(CDockContainerWidget* parent, CDockWidgetSideTab::SideTabBarArea area);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Virtual Destructor
|
* Virtual Destructor
|
||||||
@ -94,8 +94,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
int tabCount() const;
|
int tabCount() const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
/**
|
||||||
void sideTabAutoHideToggleRequested();
|
* Getter for side tab bar area property
|
||||||
|
*/
|
||||||
|
CDockWidgetSideTab::SideTabBarArea sideTabBarArea() const;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void sideTabAutoHideToggleRequested();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user