2022-09-05 17:29:42 +08:00
|
|
|
/*******************************************************************************
|
|
|
|
** Qt Advanced Docking System
|
|
|
|
** Copyright (C) 2017 Uwe Kindler
|
|
|
|
**
|
|
|
|
** This library is free software; you can redistribute it and/or
|
|
|
|
** modify it under the terms of the GNU Lesser General Public
|
|
|
|
** License as published by the Free Software Foundation; either
|
|
|
|
** version 2.1 of the License, or (at your option) any later version.
|
|
|
|
**
|
|
|
|
** This library is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
** Lesser General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU Lesser General Public
|
|
|
|
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
/// \file DockWidgetTab.h
|
|
|
|
/// \author Syarif Fakhri
|
|
|
|
/// \date 05.09.2022
|
|
|
|
/// \brief Implementation of CDockWidgetSideTab class
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// INCLUDES
|
|
|
|
//============================================================================
|
|
|
|
#include "DockWidgetSideTab.h"
|
|
|
|
#include "SideTabBar.h"
|
|
|
|
|
|
|
|
#include <QBoxLayout>
|
|
|
|
|
2022-09-08 11:30:56 +08:00
|
|
|
#include "DockAreaWidget.h"
|
2022-09-12 15:55:45 +08:00
|
|
|
#include "DockManager.h"
|
2022-09-05 17:29:42 +08:00
|
|
|
#include "ElidingLabel.h"
|
|
|
|
|
|
|
|
#include "DockWidget.h"
|
2022-09-08 11:30:56 +08:00
|
|
|
#include "OverlayDockContainer.h"
|
2022-09-05 17:29:42 +08:00
|
|
|
|
|
|
|
namespace ads
|
|
|
|
{
|
|
|
|
|
|
|
|
using tTabLabel = CVerticalElidingLabel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data class of CDockWidgetTab class (pimpl)
|
|
|
|
*/
|
|
|
|
struct DockWidgetSideTabPrivate
|
|
|
|
{
|
|
|
|
CDockWidgetSideTab* _this;
|
|
|
|
CDockWidget* DockWidget;
|
|
|
|
tTabLabel* TitleLabel;
|
|
|
|
QBoxLayout* Layout;
|
2022-09-12 15:55:45 +08:00
|
|
|
QBoxLayout* TitleLayout; // To have independent spacing from the icon
|
2022-09-05 17:29:42 +08:00
|
|
|
CSideTabBar* SideTabBar;
|
2022-09-12 15:55:45 +08:00
|
|
|
QSize IconSize;
|
|
|
|
SideTabIconLabel* IconLabel = nullptr;
|
|
|
|
QIcon Icon;
|
2022-09-05 17:29:42 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data constructor
|
|
|
|
*/
|
|
|
|
DockWidgetSideTabPrivate(CDockWidgetSideTab* _public);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the complete layout
|
|
|
|
*/
|
|
|
|
void createLayout();
|
2022-09-12 15:55:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}; // struct DockWidgetTabPrivate
|
2022-09-05 17:29:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
DockWidgetSideTabPrivate::DockWidgetSideTabPrivate(CDockWidgetSideTab* _public) :
|
|
|
|
_this(_public)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void DockWidgetSideTabPrivate::createLayout()
|
|
|
|
{
|
|
|
|
TitleLabel = new tTabLabel();
|
|
|
|
TitleLabel->setElideMode(Qt::ElideRight);
|
|
|
|
TitleLabel->setText(DockWidget->windowTitle());
|
|
|
|
TitleLabel->setObjectName("dockWidgetTabLabel");
|
2022-09-12 15:55:45 +08:00
|
|
|
//TitleLabel->setAlignment(Qt::AlignLeft);
|
2022-09-05 17:29:42 +08:00
|
|
|
_this->connect(TitleLabel, SIGNAL(elidedChanged(bool)), SIGNAL(elidedChanged(bool)));
|
|
|
|
|
|
|
|
QFontMetrics fm(TitleLabel->font());
|
|
|
|
int Spacing = qRound(fm.height() / 2.0);
|
|
|
|
|
|
|
|
// Fill the layout
|
2022-09-12 15:55:45 +08:00
|
|
|
// Purely for spacing on the text without messing up spacing on the icon
|
|
|
|
TitleLayout = new QBoxLayout(QBoxLayout::TopToBottom);
|
|
|
|
TitleLayout->setContentsMargins(Spacing,Spacing,0,Spacing);
|
|
|
|
TitleLayout->addWidget(TitleLabel);
|
|
|
|
TitleLayout->setSpacing(0);
|
|
|
|
|
|
|
|
Layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
|
|
|
Layout->setContentsMargins(0,0,0,0);
|
2022-09-05 17:29:42 +08:00
|
|
|
Layout->setSpacing(0);
|
|
|
|
_this->setLayout(Layout);
|
2022-09-12 15:55:45 +08:00
|
|
|
Layout->addLayout(TitleLayout, 1);
|
2022-09-05 17:29:42 +08:00
|
|
|
|
|
|
|
TitleLabel->setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidgetSideTab::mousePressEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
emit clicked();
|
|
|
|
}
|
|
|
|
|
|
|
|
QFrame::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidgetSideTab::setSideTabBar(CSideTabBar* SideTabBar)
|
|
|
|
{
|
|
|
|
d->SideTabBar = SideTabBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidgetSideTab::removeFromSideTabBar()
|
|
|
|
{
|
|
|
|
if (d->SideTabBar == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d->SideTabBar->removeSideTab(this);
|
|
|
|
setSideTabBar(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockWidgetSideTab::CDockWidgetSideTab(CDockWidget* DockWidget, QWidget* parent) :
|
|
|
|
QFrame(parent),
|
|
|
|
d(new DockWidgetSideTabPrivate(this))
|
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_NoMousePropagation);
|
|
|
|
d->DockWidget = DockWidget;
|
|
|
|
d->createLayout();
|
|
|
|
setFocusPolicy(Qt::NoFocus);
|
|
|
|
}
|
|
|
|
|
2022-09-12 15:55:45 +08:00
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
//============================================================================
|
|
|
|
CDockWidgetSideTab::~CDockWidgetSideTab()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2022-09-12 15:55:45 +08:00
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockWidgetSideTab::updateStyle()
|
|
|
|
{
|
|
|
|
internal::repolishStyle(this, internal::RepolishDirectChildren);
|
|
|
|
}
|
2022-09-08 11:30:56 +08:00
|
|
|
|
2022-09-12 15:55:45 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2022-09-08 11:30:56 +08:00
|
|
|
CDockWidgetSideTab::SideTabBarArea CDockWidgetSideTab::sideTabBarArea() const
|
|
|
|
{
|
|
|
|
auto dockAreaWidget = d->DockWidget->dockAreaWidget();
|
|
|
|
if (dockAreaWidget && dockAreaWidget->isOverlayed())
|
|
|
|
{
|
|
|
|
return dockAreaWidget->overlayDockContainer()->sideTabBarArea();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Left;
|
|
|
|
}
|
2022-09-12 15:55:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidgetSideTab::setIcon(const QIcon& Icon)
|
|
|
|
{
|
|
|
|
QBoxLayout* Layout = qobject_cast<QBoxLayout*>(layout());
|
|
|
|
if (!d->IconLabel && Icon.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d->IconLabel)
|
|
|
|
{
|
|
|
|
d->IconLabel = new SideTabIconLabel();
|
|
|
|
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::updateTitleAndIconVisibility(SideTabBarArea area)
|
|
|
|
{
|
|
|
|
if (d->Icon.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFontMetrics fm(d->TitleLabel->font());
|
|
|
|
int Spacing = qRound(fm.height() / 2.0);
|
|
|
|
|
|
|
|
if (CDockManager::testConfigFlag(CDockManager::LeftSideBarPrioritizeIconOnly) && area == Left
|
|
|
|
|| CDockManager::testConfigFlag(CDockManager::RightSideBarPrioritizeIconOnly) && area == Right)
|
|
|
|
{
|
|
|
|
d->TitleLabel->hide();
|
|
|
|
d->TitleLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
d->IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, Spacing / 2, Spacing / 2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->TitleLayout->setContentsMargins(Spacing, Spacing, 0, Spacing);
|
|
|
|
d->IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, Spacing / 2, 0);
|
|
|
|
|
|
|
|
d->TitleLabel->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data class of SideTabIcon class (pimpl)
|
|
|
|
*/
|
|
|
|
struct SideTabIconLabelPrivate
|
|
|
|
{
|
|
|
|
SideTabIconLabel* _this;
|
|
|
|
QLabel* IconLabel;
|
|
|
|
QBoxLayout* Layout;
|
|
|
|
|
|
|
|
SideTabIconLabelPrivate(SideTabIconLabel* _public);
|
|
|
|
}; // struct SideTabIconLabelPrivate
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
SideTabIconLabelPrivate::SideTabIconLabelPrivate(SideTabIconLabel* _public) :
|
|
|
|
_this(_public)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
SideTabIconLabel::SideTabIconLabel(QWidget* parent) : QWidget(parent),
|
|
|
|
d(new SideTabIconLabelPrivate(this))
|
|
|
|
{
|
|
|
|
d->Layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
|
|
|
d->Layout->addWidget(d->IconLabel = new QLabel());
|
|
|
|
d->IconLabel->setAlignment(Qt::AlignHCenter);
|
|
|
|
d->IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
|
|
|
setLayout(d->Layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
SideTabIconLabel::~SideTabIconLabel()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void SideTabIconLabel::setPixmap(const QPixmap& pixmap)
|
|
|
|
{
|
|
|
|
d->IconLabel->setPixmap(pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void SideTabIconLabel::setContentsMargins(int left, int top, int right, int bottom)
|
|
|
|
{
|
|
|
|
d->Layout->setContentsMargins(left, top, right, bottom);
|
|
|
|
}
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|