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
|
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
#include <AutoHideDockContainer.h>
|
2022-09-05 17:29:42 +08:00
|
|
|
#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"
|
|
|
|
|
|
|
|
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;
|
2022-09-13 10:42:58 +08:00
|
|
|
Qt::Orientation Orientation{Qt::Vertical};
|
2022-10-18 21:29:31 +08:00
|
|
|
CSideTabIconLabel* IconLabel = nullptr;
|
2022-09-12 15:55:45 +08:00
|
|
|
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);
|
|
|
|
}
|
2022-09-13 10:42:58 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2022-10-14 21:13:32 +08:00
|
|
|
TitleLayout->setContentsMargins(Spacing / 2, Spacing, Spacing, Spacing);
|
2022-09-13 10:42:58 +08:00
|
|
|
if (IconLabel)
|
|
|
|
{
|
2022-09-13 16:51:15 +08:00
|
|
|
IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, 0, Spacing / 2);
|
2022-09-13 10:42:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-12 15:55:45 +08:00
|
|
|
}; // 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());
|
2022-10-18 21:29:31 +08:00
|
|
|
TitleLabel->setObjectName("sideTabLabel");
|
2022-09-05 17:29:42 +08:00
|
|
|
_this->connect(TitleLabel, SIGNAL(elidedChanged(bool)), SIGNAL(elidedChanged(bool)));
|
|
|
|
|
|
|
|
// 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);
|
2022-09-13 14:57:24 +08:00
|
|
|
TitleLayout->setAlignment(Qt::AlignCenter);
|
2022-09-12 15:55:45 +08:00
|
|
|
TitleLayout->addWidget(TitleLabel);
|
|
|
|
TitleLayout->setSpacing(0);
|
|
|
|
|
|
|
|
Layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
2022-09-13 14:57:24 +08:00
|
|
|
Layout->setAlignment(Qt::AlignCenter);
|
2022-09-12 15:55:45 +08:00
|
|
|
Layout->setContentsMargins(0,0,0,0);
|
2022-09-05 17:29:42 +08:00
|
|
|
Layout->setSpacing(0);
|
|
|
|
_this->setLayout(Layout);
|
2022-09-13 14:57:24 +08:00
|
|
|
Layout->addLayout(TitleLayout);
|
2022-09-05 17:29:42 +08:00
|
|
|
|
2022-09-13 10:42:58 +08:00
|
|
|
updateContentsMargins();
|
|
|
|
|
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();
|
2022-10-13 14:26:54 +08:00
|
|
|
if (dockAreaWidget && dockAreaWidget->isAutoHide())
|
2022-09-08 11:30:56 +08:00
|
|
|
{
|
2022-10-13 14:26:54 +08:00
|
|
|
return dockAreaWidget->autoHideDockContainer()->sideTabBarArea();
|
2022-09-08 11:30:56 +08:00
|
|
|
}
|
|
|
|
|
2022-10-17 17:34:59 +08:00
|
|
|
return Left;
|
2022-09-08 11:30:56 +08:00
|
|
|
}
|
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)
|
|
|
|
{
|
2022-10-18 21:29:31 +08:00
|
|
|
d->IconLabel = new CSideTabIconLabel();
|
2022-09-12 15:55:45 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2022-09-13 10:42:58 +08:00
|
|
|
void CDockWidgetSideTab::setOrientation(Qt::Orientation Orientation)
|
|
|
|
{
|
|
|
|
d->Orientation = Orientation;
|
|
|
|
d->Layout->setDirection(Orientation == Qt::Vertical ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
|
|
|
|
d->TitleLabel->setOrientation(Orientation);
|
2022-09-13 14:21:01 +08:00
|
|
|
updateStyle();
|
2022-09-13 10:42:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidgetSideTab::updateOrientationAndSpacing(SideTabBarArea area)
|
2022-09-12 15:55:45 +08:00
|
|
|
{
|
2022-10-14 21:13:32 +08:00
|
|
|
setOrientation((area == Bottom || area == Top) ? Qt::Horizontal : Qt::Vertical);
|
2022-09-13 10:42:58 +08:00
|
|
|
|
|
|
|
d->updateContentsMargins();
|
|
|
|
|
|
|
|
// Handle Icon changes
|
2022-09-12 15:55:45 +08:00
|
|
|
if (d->Icon.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFontMetrics fm(d->TitleLabel->font());
|
|
|
|
int Spacing = qRound(fm.height() / 2.0);
|
|
|
|
|
2022-10-17 17:34:59 +08:00
|
|
|
if (CDockManager::testConfigFlag(CDockManager::LeftSideBarPrioritizeIconOnly) && area == Left)
|
2022-09-12 15:55:45 +08:00
|
|
|
{
|
|
|
|
d->TitleLabel->hide();
|
|
|
|
d->TitleLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
d->IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, Spacing / 2, Spacing / 2);
|
|
|
|
return;
|
|
|
|
}
|
2022-10-17 17:34:59 +08:00
|
|
|
if (CDockManager::testConfigFlag(CDockManager::RightSideBarPrioritizeIconOnly) && area == Right)
|
2022-09-13 10:42:58 +08:00
|
|
|
{
|
|
|
|
d->TitleLabel->hide();
|
|
|
|
d->TitleLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
d->IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, Spacing, Spacing / 2);
|
|
|
|
return;
|
|
|
|
}
|
2022-09-13 14:16:12 +08:00
|
|
|
if (CDockManager::testConfigFlag(CDockManager::BottomSideBarPrioritizeIconOnly) && area == Bottom)
|
2022-10-14 21:13:32 +08:00
|
|
|
{
|
|
|
|
d->TitleLabel->hide();
|
|
|
|
d->TitleLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
d->IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, Spacing / 2, Spacing);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (CDockManager::testConfigFlag(CDockManager::TopSideBarPrioritizeIconOnly) && area == Top)
|
2022-09-13 14:16:12 +08:00
|
|
|
{
|
|
|
|
d->TitleLabel->hide();
|
|
|
|
d->TitleLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
d->IconLabel->setContentsMargins(Spacing / 2, Spacing / 2, Spacing / 2, Spacing / 2);
|
|
|
|
return;
|
|
|
|
}
|
2022-09-12 15:55:45 +08:00
|
|
|
|
|
|
|
d->TitleLabel->show();
|
|
|
|
}
|
|
|
|
|
2022-09-14 17:39:57 +08:00
|
|
|
|
2022-10-14 21:32:05 +08:00
|
|
|
//============================================================================
|
|
|
|
bool CDockWidgetSideTab::isActiveTab() const
|
|
|
|
{
|
|
|
|
if (d->DockWidget->autoHideDockContainer())
|
|
|
|
{
|
|
|
|
return d->DockWidget->autoHideDockContainer()->isVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-14 17:39:57 +08:00
|
|
|
//============================================================================
|
|
|
|
CDockWidget* CDockWidgetSideTab::dockWidget() const
|
|
|
|
{
|
|
|
|
return d->DockWidget;
|
|
|
|
}
|
|
|
|
|
2022-09-12 15:55:45 +08:00
|
|
|
/**
|
|
|
|
* Private data class of SideTabIcon class (pimpl)
|
|
|
|
*/
|
|
|
|
struct SideTabIconLabelPrivate
|
|
|
|
{
|
2022-10-18 21:29:31 +08:00
|
|
|
CSideTabIconLabel* _this;
|
2022-09-12 15:55:45 +08:00
|
|
|
QLabel* IconLabel;
|
|
|
|
QBoxLayout* Layout;
|
|
|
|
|
2022-10-18 21:29:31 +08:00
|
|
|
SideTabIconLabelPrivate(CSideTabIconLabel* _public);
|
2022-09-12 15:55:45 +08:00
|
|
|
}; // struct SideTabIconLabelPrivate
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2022-10-18 21:29:31 +08:00
|
|
|
SideTabIconLabelPrivate::SideTabIconLabelPrivate(CSideTabIconLabel* _public) :
|
2022-09-12 15:55:45 +08:00
|
|
|
_this(_public)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2022-10-18 21:29:31 +08:00
|
|
|
CSideTabIconLabel::CSideTabIconLabel(QWidget* parent) : QFrame(parent),
|
2022-09-12 15:55:45 +08:00
|
|
|
d(new SideTabIconLabelPrivate(this))
|
|
|
|
{
|
|
|
|
d->Layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
|
|
|
d->Layout->addWidget(d->IconLabel = new QLabel());
|
2022-10-18 21:29:31 +08:00
|
|
|
d->IconLabel->setObjectName("sideTabIconLabel");
|
2022-09-13 14:57:24 +08:00
|
|
|
d->Layout->setAlignment(Qt::AlignCenter);
|
2022-09-12 15:55:45 +08:00
|
|
|
d->IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
|
|
|
setLayout(d->Layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2022-10-18 21:29:31 +08:00
|
|
|
CSideTabIconLabel::~CSideTabIconLabel()
|
2022-09-12 15:55:45 +08:00
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2022-10-18 21:29:31 +08:00
|
|
|
void CSideTabIconLabel::setPixmap(const QPixmap& pixmap)
|
2022-09-12 15:55:45 +08:00
|
|
|
{
|
|
|
|
d->IconLabel->setPixmap(pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2022-10-18 21:29:31 +08:00
|
|
|
void CSideTabIconLabel::setContentsMargins(int left, int top, int right, int bottom)
|
2022-09-12 15:55:45 +08:00
|
|
|
{
|
|
|
|
d->Layout->setContentsMargins(left, top, right, bottom);
|
|
|
|
}
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|