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/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2022-11-01 20:41:36 +08:00
|
|
|
/// \file AutoHideTab.cpp
|
2022-09-05 17:29:42 +08:00
|
|
|
/// \author Syarif Fakhri
|
|
|
|
/// \date 05.09.2022
|
2022-11-01 20:41:36 +08:00
|
|
|
/// \brief Implementation of CAutoHideTab class
|
2022-09-05 17:29:42 +08:00
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// INCLUDES
|
|
|
|
//============================================================================
|
2022-11-01 20:41:36 +08:00
|
|
|
#include "AutoHideTab.h"
|
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
#include <QBoxLayout>
|
|
|
|
|
2022-11-01 20:41:36 +08:00
|
|
|
#include "AutoHideDockContainer.h"
|
|
|
|
#include "AutoHideSideBar.h"
|
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 "DockWidget.h"
|
|
|
|
|
|
|
|
namespace ads
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Private data class of CDockWidgetTab class (pimpl)
|
|
|
|
*/
|
2022-11-01 19:06:59 +08:00
|
|
|
struct AutoHideTabPrivate
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-11-01 19:06:59 +08:00
|
|
|
CAutoHideTab* _this;
|
2022-10-28 22:28:23 +08:00
|
|
|
CDockWidget* DockWidget = nullptr;
|
2022-11-01 19:06:59 +08:00
|
|
|
CAutoHideSideBar* SideBar = nullptr;
|
2022-09-13 10:42:58 +08:00
|
|
|
Qt::Orientation Orientation{Qt::Vertical};
|
2022-09-05 17:29:42 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data constructor
|
|
|
|
*/
|
2022-11-01 19:06:59 +08:00
|
|
|
AutoHideTabPrivate(CAutoHideTab* _public);
|
2022-11-01 20:34:08 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the orientation, visibility and spacing based on the area of
|
|
|
|
* the side bar
|
|
|
|
*/
|
|
|
|
void updateOrientation();
|
2022-09-12 15:55:45 +08:00
|
|
|
}; // struct DockWidgetTabPrivate
|
2022-09-05 17:29:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2022-11-01 19:06:59 +08:00
|
|
|
AutoHideTabPrivate::AutoHideTabPrivate(CAutoHideTab* _public) :
|
2022-09-05 17:29:42 +08:00
|
|
|
_this(_public)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-01 20:34:08 +08:00
|
|
|
//============================================================================
|
|
|
|
void AutoHideTabPrivate::updateOrientation()
|
|
|
|
{
|
|
|
|
auto area = SideBar->sideBarLocation();
|
2022-11-03 22:28:01 +08:00
|
|
|
_this->setOrientation((area == SideBarBottom || area == SideBarTop) ? Qt::Horizontal : Qt::Vertical);
|
2022-11-01 20:34:08 +08:00
|
|
|
|
|
|
|
if (_this->icon().isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IconOnly = false;
|
|
|
|
switch (area)
|
|
|
|
{
|
2022-11-03 22:28:01 +08:00
|
|
|
case SideBarLocation::SideBarLeft:
|
2022-11-01 21:36:09 +08:00
|
|
|
IconOnly = CDockManager::testAutoHideConfigFlag(CDockManager::LeftSideBarIconOnly);
|
2022-11-01 20:34:08 +08:00
|
|
|
break;
|
|
|
|
|
2022-11-03 22:28:01 +08:00
|
|
|
case SideBarLocation::SideBarRight:
|
2022-11-01 21:36:09 +08:00
|
|
|
IconOnly = CDockManager::testAutoHideConfigFlag(CDockManager::RightSideBarIconOnly);
|
2022-11-01 20:34:08 +08:00
|
|
|
break;
|
|
|
|
|
2022-11-03 22:28:01 +08:00
|
|
|
case SideBarLocation::SideBarTop:
|
2022-11-01 21:36:09 +08:00
|
|
|
IconOnly = CDockManager::testAutoHideConfigFlag(CDockManager::BottomSideBarIconOnly);
|
2022-11-01 20:34:08 +08:00
|
|
|
break;
|
|
|
|
|
2022-11-03 22:28:01 +08:00
|
|
|
case SideBarLocation::SideBarBottom:
|
2022-11-01 21:36:09 +08:00
|
|
|
IconOnly = CDockManager::testAutoHideConfigFlag(CDockManager::TopSideBarIconOnly);
|
2022-11-01 20:34:08 +08:00
|
|
|
break;
|
2022-11-03 22:28:01 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2022-11-01 20:34:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IconOnly)
|
|
|
|
{
|
|
|
|
_this->setText("");
|
|
|
|
_this->setOrientation(Qt::Horizontal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
//============================================================================
|
2022-11-01 19:06:59 +08:00
|
|
|
void CAutoHideTab::setSideBar(CAutoHideSideBar* SideTabBar)
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-11-01 19:06:59 +08:00
|
|
|
d->SideBar = SideTabBar;
|
2022-11-01 20:34:08 +08:00
|
|
|
if (d->SideBar)
|
|
|
|
{
|
|
|
|
d->updateOrientation();
|
|
|
|
}
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2022-11-01 19:06:59 +08:00
|
|
|
void CAutoHideTab::removeFromSideBar()
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-11-01 19:06:59 +08:00
|
|
|
if (d->SideBar == nullptr)
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-11-01 20:34:08 +08:00
|
|
|
d->SideBar->removeTab(this);
|
2022-11-01 19:06:59 +08:00
|
|
|
setSideBar(nullptr);
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
2022-11-01 19:06:59 +08:00
|
|
|
CAutoHideTab::CAutoHideTab(QWidget* parent) :
|
2022-11-03 22:28:01 +08:00
|
|
|
CPushButton(parent),
|
2022-11-01 19:06:59 +08:00
|
|
|
d(new AutoHideTabPrivate(this))
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_NoMousePropagation);
|
|
|
|
setFocusPolicy(Qt::NoFocus);
|
|
|
|
}
|
|
|
|
|
2022-09-12 15:55:45 +08:00
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
//============================================================================
|
2022-11-01 19:06:59 +08:00
|
|
|
CAutoHideTab::~CAutoHideTab()
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-11-03 23:49:20 +08:00
|
|
|
ADS_PRINT("~CDockWidgetSideTab()");
|
2022-09-05 17:29:42 +08:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2022-09-12 15:55:45 +08:00
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
//============================================================================
|
2022-11-01 19:06:59 +08:00
|
|
|
void CAutoHideTab::updateStyle()
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-10-28 21:20:56 +08:00
|
|
|
internal::repolishStyle(this, internal::RepolishDirectChildren);
|
2022-10-25 21:51:38 +08:00
|
|
|
update();
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
2022-09-08 11:30:56 +08:00
|
|
|
|
2022-09-12 15:55:45 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2022-11-01 20:34:08 +08:00
|
|
|
SideBarLocation CAutoHideTab::sideBarLocation() const
|
2022-09-08 11:30:56 +08:00
|
|
|
{
|
2022-11-01 19:06:59 +08:00
|
|
|
if (d->SideBar)
|
2022-09-08 11:30:56 +08:00
|
|
|
{
|
2022-11-01 20:34:08 +08:00
|
|
|
return d->SideBar->sideBarLocation();
|
2022-09-08 11:30:56 +08:00
|
|
|
}
|
|
|
|
|
2022-11-03 22:28:01 +08:00
|
|
|
return SideBarLeft;
|
2022-09-08 11:30:56 +08:00
|
|
|
}
|
2022-09-12 15:55:45 +08:00
|
|
|
|
2022-10-26 15:51:37 +08:00
|
|
|
|
2022-09-12 15:55:45 +08:00
|
|
|
//============================================================================
|
2022-11-01 19:06:59 +08:00
|
|
|
void CAutoHideTab::setOrientation(Qt::Orientation Orientation)
|
2022-09-13 10:42:58 +08:00
|
|
|
{
|
|
|
|
d->Orientation = Orientation;
|
2022-11-03 18:34:04 +08:00
|
|
|
if (orientation() == Qt::Horizontal)
|
|
|
|
{
|
|
|
|
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
|
|
|
|
}
|
2022-10-26 15:51:37 +08:00
|
|
|
CPushButton::setButtonOrientation((Qt::Horizontal == Orientation)
|
2022-10-18 22:43:39 +08:00
|
|
|
? CPushButton::Horizontal : CPushButton::VerticalTopToBottom);
|
2022-09-13 14:21:01 +08:00
|
|
|
updateStyle();
|
2022-09-13 10:42:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-26 15:51:37 +08:00
|
|
|
//============================================================================
|
2022-11-01 19:06:59 +08:00
|
|
|
Qt::Orientation CAutoHideTab::orientation() const
|
2022-10-26 15:51:37 +08:00
|
|
|
{
|
|
|
|
return d->Orientation;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-14 21:32:05 +08:00
|
|
|
//============================================================================
|
2022-11-01 19:06:59 +08:00
|
|
|
bool CAutoHideTab::isActiveTab() const
|
2022-10-14 21:32:05 +08:00
|
|
|
{
|
2022-10-28 22:28:23 +08:00
|
|
|
if (d->DockWidget && d->DockWidget->autoHideDockContainer())
|
2022-10-14 21:32:05 +08:00
|
|
|
{
|
|
|
|
return d->DockWidget->autoHideDockContainer()->isVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-14 17:39:57 +08:00
|
|
|
//============================================================================
|
2022-11-01 19:06:59 +08:00
|
|
|
CDockWidget* CAutoHideTab::dockWidget() const
|
2022-09-14 17:39:57 +08:00
|
|
|
{
|
|
|
|
return d->DockWidget;
|
|
|
|
}
|
|
|
|
|
2022-10-28 22:28:23 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2022-11-01 19:06:59 +08:00
|
|
|
void CAutoHideTab::setDockWidget(CDockWidget* DockWidget)
|
2022-10-28 22:28:23 +08:00
|
|
|
{
|
|
|
|
if (!DockWidget)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d->DockWidget = DockWidget;
|
|
|
|
setText(DockWidget->windowTitle());
|
2022-10-31 02:44:33 +08:00
|
|
|
setIcon(d->DockWidget->icon());
|
2022-10-28 22:28:23 +08:00
|
|
|
}
|
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|