mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-26 08:01:32 +08:00
Reimplemented DockWidgetSideTab based on QPushButton
This commit is contained in:
parent
cbc43e5e0e
commit
866ccb2c4e
@ -326,7 +326,7 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
|
||||
d->TabWidget = componentsFactory()->createDockWidgetTab(this);
|
||||
d->SideTabWidget = componentsFactory()->createDockWidgetSideTab(this);
|
||||
|
||||
connect(d->SideTabWidget, &CDockWidgetSideTab::clicked, this, &CDockWidget::onDockWidgetSideTabClicked);
|
||||
connect(d->SideTabWidget, &CDockWidgetSideTab::pressed, this, &CDockWidget::onDockWidgetSideTabClicked);
|
||||
|
||||
d->ToggleViewAction = new QAction(title, this);
|
||||
d->ToggleViewAction->setCheckable(true);
|
||||
|
@ -51,68 +51,13 @@ struct DockWidgetSideTabPrivate
|
||||
{
|
||||
CDockWidgetSideTab* _this;
|
||||
CDockWidget* DockWidget;
|
||||
tTabLabel* TitleLabel;
|
||||
QBoxLayout* Layout;
|
||||
QBoxLayout* TitleLayout; // To have independent spacing from the icon
|
||||
CSideTabBar* SideTabBar;
|
||||
QSize IconSize;
|
||||
Qt::Orientation Orientation{Qt::Vertical};
|
||||
CSideTabIconLabel* IconLabel = nullptr;
|
||||
QIcon Icon;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
*/
|
||||
DockWidgetSideTabPrivate(CDockWidgetSideTab* _public);
|
||||
|
||||
/**
|
||||
* Creates the complete layout
|
||||
*/
|
||||
void createLayout();
|
||||
|
||||
/**
|
||||
* Update the icon in case the icon size changed
|
||||
*/
|
||||
void updateIcon()
|
||||
{
|
||||
if (!IconLabel || Icon.isNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IconSize.isValid())
|
||||
{
|
||||
IconLabel->setPixmap(Icon.pixmap(IconSize));
|
||||
}
|
||||
else
|
||||
{
|
||||
IconLabel->setPixmap(Icon.pixmap(_this->style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, _this)));
|
||||
}
|
||||
IconLabel->setVisible(true);
|
||||
}
|
||||
|
||||
void updateContentsMargins()
|
||||
{
|
||||
QFontMetrics fm(TitleLabel->font());
|
||||
int Spacing = qRound(fm.height() / 2.0);
|
||||
|
||||
if (Orientation == Qt::Vertical)
|
||||
{
|
||||
TitleLayout->setContentsMargins(Spacing, Spacing, 0, Spacing);
|
||||
if (IconLabel)
|
||||
{
|
||||
IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, Spacing / 2, 0);
|
||||
}
|
||||
}
|
||||
else if (Orientation == Qt::Horizontal)
|
||||
{
|
||||
TitleLayout->setContentsMargins(Spacing / 2, Spacing, Spacing, Spacing);
|
||||
if (IconLabel)
|
||||
{
|
||||
IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, 0, Spacing / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}; // struct DockWidgetTabPrivate
|
||||
|
||||
|
||||
@ -123,45 +68,6 @@ DockWidgetSideTabPrivate::DockWidgetSideTabPrivate(CDockWidgetSideTab* _public)
|
||||
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void DockWidgetSideTabPrivate::createLayout()
|
||||
{
|
||||
TitleLabel = new tTabLabel();
|
||||
TitleLabel->setElideMode(Qt::ElideRight);
|
||||
TitleLabel->setText(DockWidget->windowTitle());
|
||||
TitleLabel->setObjectName("sideTabLabel");
|
||||
_this->connect(TitleLabel, SIGNAL(elidedChanged(bool)), SIGNAL(elidedChanged(bool)));
|
||||
|
||||
// Fill the layout
|
||||
// Purely for spacing on the text without messing up spacing on the icon
|
||||
TitleLayout = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
TitleLayout->setAlignment(Qt::AlignCenter);
|
||||
TitleLayout->addWidget(TitleLabel);
|
||||
TitleLayout->setSpacing(0);
|
||||
|
||||
Layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
Layout->setAlignment(Qt::AlignCenter);
|
||||
Layout->setContentsMargins(0,0,0,0);
|
||||
Layout->setSpacing(0);
|
||||
_this->setLayout(Layout);
|
||||
Layout->addLayout(TitleLayout);
|
||||
|
||||
updateContentsMargins();
|
||||
|
||||
TitleLabel->setVisible(true);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void CDockWidgetSideTab::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
QFrame::mousePressEvent(event);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidgetSideTab::setSideTabBar(CSideTabBar* SideTabBar)
|
||||
@ -183,13 +89,14 @@ void CDockWidgetSideTab::removeFromSideTabBar()
|
||||
|
||||
//============================================================================
|
||||
CDockWidgetSideTab::CDockWidgetSideTab(CDockWidget* DockWidget, QWidget* parent) :
|
||||
QFrame(parent),
|
||||
Super(parent),
|
||||
d(new DockWidgetSideTabPrivate(this))
|
||||
{
|
||||
setAttribute(Qt::WA_NoMousePropagation);
|
||||
d->DockWidget = DockWidget;
|
||||
d->createLayout();
|
||||
setText(DockWidget->windowTitle());
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
setFlat(true);
|
||||
}
|
||||
|
||||
|
||||
@ -219,56 +126,12 @@ CDockWidgetSideTab::SideTabBarArea CDockWidgetSideTab::sideTabBarArea() const
|
||||
return Left;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidgetSideTab::setIcon(const QIcon& Icon)
|
||||
{
|
||||
QBoxLayout* Layout = qobject_cast<QBoxLayout*>(layout());
|
||||
if (!d->IconLabel && Icon.isNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!d->IconLabel)
|
||||
{
|
||||
d->IconLabel = new CSideTabIconLabel();
|
||||
internal::setToolTip(d->IconLabel, d->TitleLabel->toolTip());
|
||||
Layout->insertWidget(0, d->IconLabel, Qt::AlignHCenter);
|
||||
}
|
||||
else if (Icon.isNull())
|
||||
{
|
||||
// Remove icon label
|
||||
Layout->removeWidget(d->IconLabel);
|
||||
delete d->IconLabel;
|
||||
d->IconLabel = nullptr;
|
||||
}
|
||||
|
||||
d->Icon = Icon;
|
||||
d->updateIcon();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QSize CDockWidgetSideTab::iconSize() const
|
||||
{
|
||||
return d->IconSize;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidgetSideTab::setIconSize(const QSize& Size)
|
||||
{
|
||||
d->IconSize = Size;
|
||||
d->updateIcon();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidgetSideTab::setOrientation(Qt::Orientation Orientation)
|
||||
{
|
||||
d->Orientation = Orientation;
|
||||
d->Layout->setDirection(Orientation == Qt::Vertical ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
|
||||
d->TitleLabel->setOrientation(Orientation);
|
||||
CPushButton::setOrientation((Qt::Horizontal == Orientation)
|
||||
? CPushButton::Horizontal : CPushButton::VerticalTopToBottom);
|
||||
updateStyle();
|
||||
}
|
||||
|
||||
@ -278,18 +141,7 @@ void CDockWidgetSideTab::updateOrientationAndSpacing(SideTabBarArea area)
|
||||
{
|
||||
setOrientation((area == Bottom || area == Top) ? Qt::Horizontal : Qt::Vertical);
|
||||
|
||||
d->updateContentsMargins();
|
||||
|
||||
// Handle Icon changes
|
||||
if (d->Icon.isNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QFontMetrics fm(d->TitleLabel->font());
|
||||
int Spacing = qRound(fm.height() / 2.0);
|
||||
|
||||
if (CDockManager::testConfigFlag(CDockManager::LeftSideBarPrioritizeIconOnly) && area == Left)
|
||||
/*if (CDockManager::testConfigFlag(CDockManager::LeftSideBarPrioritizeIconOnly) && area == Left)
|
||||
{
|
||||
d->TitleLabel->hide();
|
||||
d->TitleLayout->setContentsMargins(0, 0, 0, 0);
|
||||
@ -316,9 +168,7 @@ void CDockWidgetSideTab::updateOrientationAndSpacing(SideTabBarArea area)
|
||||
d->TitleLayout->setContentsMargins(0, 0, 0, 0);
|
||||
d->IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, Spacing / 2, Spacing / 2);
|
||||
return;
|
||||
}
|
||||
|
||||
d->TitleLabel->show();
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
@ -340,56 +190,4 @@ CDockWidget* CDockWidgetSideTab::dockWidget() const
|
||||
return d->DockWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private data class of SideTabIcon class (pimpl)
|
||||
*/
|
||||
struct SideTabIconLabelPrivate
|
||||
{
|
||||
CSideTabIconLabel* _this;
|
||||
QLabel* IconLabel;
|
||||
QBoxLayout* Layout;
|
||||
|
||||
SideTabIconLabelPrivate(CSideTabIconLabel* _public);
|
||||
}; // struct SideTabIconLabelPrivate
|
||||
|
||||
|
||||
//============================================================================
|
||||
SideTabIconLabelPrivate::SideTabIconLabelPrivate(CSideTabIconLabel* _public) :
|
||||
_this(_public)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CSideTabIconLabel::CSideTabIconLabel(QWidget* parent) : QFrame(parent),
|
||||
d(new SideTabIconLabelPrivate(this))
|
||||
{
|
||||
d->Layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
d->Layout->addWidget(d->IconLabel = new QLabel());
|
||||
d->IconLabel->setObjectName("sideTabIconLabel");
|
||||
d->Layout->setAlignment(Qt::AlignCenter);
|
||||
d->IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
setLayout(d->Layout);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CSideTabIconLabel::~CSideTabIconLabel()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CSideTabIconLabel::setPixmap(const QPixmap& pixmap)
|
||||
{
|
||||
d->IconLabel->setPixmap(pixmap);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CSideTabIconLabel::setContentsMargins(int left, int top, int right, int bottom)
|
||||
{
|
||||
d->Layout->setContentsMargins(left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <QFrame>
|
||||
#include "PushButton.h"
|
||||
|
||||
#include "ads_globals.h"
|
||||
|
||||
@ -46,12 +46,11 @@ struct SideTabIconLabelPrivate;
|
||||
* The dock widget tab is shown in the side tab bar to switch between
|
||||
* pinned dock widgets
|
||||
*/
|
||||
class ADS_EXPORT CDockWidgetSideTab : public QFrame
|
||||
class ADS_EXPORT CDockWidgetSideTab : public CPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(SideTabBarArea sideTabBarArea READ sideTabBarArea)
|
||||
Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
|
||||
Q_PROPERTY(bool activeTab READ isActiveTab)
|
||||
|
||||
private:
|
||||
@ -65,13 +64,11 @@ protected:
|
||||
friend class CDockAreaWidget;
|
||||
friend class CDockContainerWidget;
|
||||
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
|
||||
void setSideTabBar(CSideTabBar *SideTabBar);
|
||||
void removeFromSideTabBar();
|
||||
|
||||
public:
|
||||
using Super = QFrame;
|
||||
using Super = CPushButton;
|
||||
|
||||
/**
|
||||
* Dock widget side tab bar locations
|
||||
@ -108,25 +105,6 @@ public:
|
||||
*/
|
||||
SideTabBarArea sideTabBarArea() const;
|
||||
|
||||
/**
|
||||
* Sets the icon to show in title bar
|
||||
*/
|
||||
void setIcon(const QIcon& Icon);
|
||||
|
||||
/**
|
||||
* Returns the icon size.
|
||||
* If no explicit icon size has been set, the function returns an invalid
|
||||
* QSize
|
||||
*/
|
||||
QSize iconSize() const;
|
||||
|
||||
/**
|
||||
* Set an explicit icon size.
|
||||
* If no icon size has been set explicitly, than the tab sets the icon size
|
||||
* depending on the style
|
||||
*/
|
||||
void setIconSize(const QSize& Size);
|
||||
|
||||
/**
|
||||
* Set orientation vertical or horizontal
|
||||
*/
|
||||
@ -149,22 +127,7 @@ public:
|
||||
|
||||
Q_SIGNALS:
|
||||
void elidedChanged(bool elided);
|
||||
void clicked();
|
||||
}; // class DockWidgetSideTab
|
||||
|
||||
class CSideTabIconLabel : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
SideTabIconLabelPrivate *d; ///< private data (pimpl)
|
||||
|
||||
public:
|
||||
CSideTabIconLabel(QWidget* parent = nullptr);
|
||||
virtual ~CSideTabIconLabel();
|
||||
|
||||
void setPixmap(const QPixmap &pixmap);
|
||||
void setContentsMargins(int left, int top, int right, int bottom);
|
||||
}; // class SideTabIconLabel
|
||||
}
|
||||
// namespace ads
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -59,7 +59,7 @@ CPushButton::Orientation CPushButton::orientation() const
|
||||
return m_Orientation;
|
||||
}
|
||||
|
||||
void CPushButton::setOrientation(Orientation &orientation)
|
||||
void CPushButton::setOrientation(Orientation orientation)
|
||||
{
|
||||
m_Orientation = orientation;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
virtual QSize sizeHint() const override;
|
||||
|
||||
Orientation orientation() const;
|
||||
void setOrientation(Orientation &orientation);
|
||||
void setOrientation(Orientation orientation);
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent *event) override;
|
||||
|
@ -110,30 +110,17 @@ QScrollArea#dockWidgetScrollArea {
|
||||
*----------------------------------------------------------------------------
|
||||
*/
|
||||
ads--CDockWidgetSideTab {
|
||||
background: palette(window);
|
||||
/*background: palette(window);*/
|
||||
qproperty-iconSize: 16px 16px;/* this is optional in case you would like to change icon size*/
|
||||
}
|
||||
|
||||
ads--CDockWidgetSideTab[sideTabBarArea="0"] {
|
||||
border-right: 1px solid white;
|
||||
background: red;
|
||||
/*border-right: 1px solid white;*/
|
||||
}
|
||||
|
||||
#sideTabLabel {
|
||||
background: green;
|
||||
}
|
||||
|
||||
#sideTabIconLabel {
|
||||
background: blue;
|
||||
}
|
||||
|
||||
ads--CSideTabIconLabel {
|
||||
border: 1px solid yellow
|
||||
}
|
||||
|
||||
ads--CDockWidgetSideTab[sideTabBarArea="1"] {
|
||||
border-bottom: 1px solid white;
|
||||
background: red;
|
||||
/*border-bottom: 1px solid white;*/
|
||||
}
|
||||
|
||||
ads--CDockWidgetSideTab[sideTabBarArea="2"] {
|
||||
|
Loading…
Reference in New Issue
Block a user