mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 23:31:32 +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;
|
||||
QBoxLayout* TabsLayout;
|
||||
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
|
||||
|
||||
//============================================================================
|
||||
@ -64,12 +73,14 @@ SideTabBarPrivate::SideTabBarPrivate(CSideTabBar* _public) :
|
||||
|
||||
|
||||
//============================================================================
|
||||
CSideTabBar::CSideTabBar(CDockContainerWidget* parent, Qt::Orientation orientation) :
|
||||
QWidget(parent),
|
||||
CSideTabBar::CSideTabBar(CDockContainerWidget* parent, CDockWidgetSideTab::SideTabBarArea area) :
|
||||
Super(parent),
|
||||
d(new SideTabBarPrivate(this))
|
||||
{
|
||||
d->SideTabArea = area;
|
||||
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);
|
||||
|
||||
@ -80,9 +91,19 @@ CSideTabBar::CSideTabBar(CDockContainerWidget* parent, Qt::Orientation orientati
|
||||
mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||
mainLayout->setSpacing(0);
|
||||
mainLayout->addStretch(1);
|
||||
|
||||
setLayout(mainLayout);
|
||||
|
||||
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);
|
||||
SideTab->setSideTabBar(this);
|
||||
show();
|
||||
}
|
||||
|
||||
|
||||
@ -105,6 +127,10 @@ void CSideTabBar::insertSideTab(int Index, CDockWidgetSideTab* SideTab)
|
||||
void CSideTabBar::removeSideTab(CDockWidgetSideTab* SideTab)
|
||||
{
|
||||
d->TabsLayout->removeWidget(SideTab);
|
||||
if (d->TabsLayout->isEmpty())
|
||||
{
|
||||
hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -139,4 +165,11 @@ int CSideTabBar::tabCount() const
|
||||
{
|
||||
return d->TabsLayout->count();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockWidgetSideTab::SideTabBarArea CSideTabBar::sideTabBarArea() const
|
||||
{
|
||||
return d->SideTabArea;
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,8 @@
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <QWidget>
|
||||
#include <QFrame>
|
||||
#include "DockWidgetSideTab.h"
|
||||
#include "ads_globals.h"
|
||||
|
||||
namespace ads
|
||||
@ -37,15 +38,14 @@ namespace ads
|
||||
struct SideTabBarPrivate;
|
||||
class CDockContainerWidget;
|
||||
class CDockWidgetSideTab;
|
||||
class CDockWidgetTab;
|
||||
|
||||
/**
|
||||
* 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_PROPERTY(int sideTabBarArea READ sideTabBarArea)
|
||||
Q_PROPERTY(Qt::Orientation orientation READ orientation)
|
||||
|
||||
private:
|
||||
@ -57,12 +57,12 @@ protected:
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
|
||||
public:
|
||||
using Super = QWidget;
|
||||
using Super = QFrame;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
CSideTabBar(CDockContainerWidget* parent, Qt::Orientation orientation);
|
||||
CSideTabBar(CDockContainerWidget* parent, CDockWidgetSideTab::SideTabBarArea area);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
@ -94,8 +94,13 @@ public:
|
||||
*/
|
||||
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