Qt-Advanced-Docking-System/src/DockWidgetSideTab.cpp

201 lines
5.3 KiB
C++
Raw Normal View History

/*******************************************************************************
** 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 <AutoHideDockContainer.h>
#include "DockWidgetSideTab.h"
#include "SideTabBar.h"
#include <QBoxLayout>
#include "DockAreaWidget.h"
#include "DockManager.h"
#include "DockWidget.h"
namespace ads
{
/**
* Private data class of CDockWidgetTab class (pimpl)
*/
struct DockWidgetSideTabPrivate
{
CDockWidgetSideTab* _this;
CDockWidget* DockWidget;
CSideTabBar* SideTabBar = nullptr;
2022-09-13 10:42:58 +08:00
Qt::Orientation Orientation{Qt::Vertical};
/**
* Private data constructor
*/
DockWidgetSideTabPrivate(CDockWidgetSideTab* _public);
}; // struct DockWidgetTabPrivate
//============================================================================
DockWidgetSideTabPrivate::DockWidgetSideTabPrivate(CDockWidgetSideTab* _public) :
_this(_public)
{
}
//============================================================================
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) :
Super(parent),
d(new DockWidgetSideTabPrivate(this))
{
setAttribute(Qt::WA_NoMousePropagation);
d->DockWidget = DockWidget;
setText(DockWidget->windowTitle());
setFocusPolicy(Qt::NoFocus);
}
//============================================================================
CDockWidgetSideTab::~CDockWidgetSideTab()
{
qDebug() << "~CDockWidgetSideTab()";
delete d;
}
//============================================================================
void CDockWidgetSideTab::updateStyle()
{
internal::repolishStyle(this, internal::RepolishDirectChildren);
2022-10-25 21:51:38 +08:00
update();
}
//============================================================================
SideBarLocation CDockWidgetSideTab::sideTabBarArea() const
{
if (d->SideTabBar)
{
qDebug() << "CDockWidgetSideTab::sideTabBarArea() " << d->SideTabBar->sideTabBarArea();
return d->SideTabBar->sideTabBarArea();
}
return Left;
}
//============================================================================
2022-09-13 10:42:58 +08:00
void CDockWidgetSideTab::setOrientation(Qt::Orientation Orientation)
{
d->Orientation = Orientation;
CPushButton::setButtonOrientation((Qt::Horizontal == Orientation)
? CPushButton::Horizontal : CPushButton::VerticalTopToBottom);
updateStyle();
2022-09-13 10:42:58 +08:00
}
//============================================================================
Qt::Orientation CDockWidgetSideTab::orientation() const
{
return d->Orientation;
}
2022-09-13 10:42:58 +08:00
//============================================================================
void CDockWidgetSideTab::updateOrientationForArea(SideBarLocation area)
{
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
2022-10-19 17:35:36 +08:00
if (icon().isNull())
{
2022-10-19 17:35:36 +08:00
return;
}
bool IconOnly = false;
switch (area)
2022-10-19 17:35:36 +08:00
{
case SideBarLocation::Left:
IconOnly = CDockManager::testConfigFlag(CDockManager::LeftSideBarIconOnly);
break;
case SideBarLocation::Right:
IconOnly = CDockManager::testConfigFlag(CDockManager::RightSideBarIconOnly);
break;
case SideBarLocation::Top:
IconOnly = CDockManager::testConfigFlag(CDockManager::BottomSideBarIconOnly);
break;
case SideBarLocation::Bottom:
IconOnly = CDockManager::testConfigFlag(CDockManager::TopSideBarIconOnly);
break;
2022-10-14 21:13:32 +08:00
}
if (IconOnly)
2022-09-13 14:16:12 +08:00
{
2022-10-19 17:35:36 +08:00
setText("");
setOrientation(Qt::Horizontal);
}
}
2022-10-14 21:32:05 +08:00
//============================================================================
bool CDockWidgetSideTab::isActiveTab() const
{
if (d->DockWidget->autoHideDockContainer())
{
return d->DockWidget->autoHideDockContainer()->isVisible();
}
return false;
}
//============================================================================
CDockWidget* CDockWidgetSideTab::dockWidget() const
{
return d->DockWidget;
}
}