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-10-13 15:41:15 +08:00
|
|
|
/// \file AutoHideDockContainer.h
|
2022-09-05 17:29:42 +08:00
|
|
|
/// \author Syarif Fakhri
|
|
|
|
/// \date 05.09.2022
|
2022-10-13 14:26:54 +08:00
|
|
|
/// \brief Implementation of CAutoHideDockContainer class
|
2022-09-05 17:29:42 +08:00
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// INCLUDES
|
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
#include <AutoHideDockContainer.h>
|
2022-09-05 17:29:42 +08:00
|
|
|
#include "DockManager.h"
|
|
|
|
#include "DockWidgetSideTab.h"
|
|
|
|
#include "DockWidgetTab.h"
|
|
|
|
#include "SideTabBar.h"
|
|
|
|
#include "DockAreaWidget.h"
|
|
|
|
#include "DockingStateReader.h"
|
2022-10-24 22:21:26 +08:00
|
|
|
#include "ResizeHandle.h"
|
2022-09-05 17:29:42 +08:00
|
|
|
|
|
|
|
#include <QXmlStreamWriter>
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QSplitter>
|
2022-09-07 16:56:17 +08:00
|
|
|
#include <QPointer>
|
2022-10-12 17:17:54 +08:00
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
#include <iostream>
|
2022-09-05 17:29:42 +08:00
|
|
|
|
|
|
|
namespace ads
|
|
|
|
{
|
2022-10-23 22:42:14 +08:00
|
|
|
static const int ResizeMargin = 4;
|
|
|
|
|
2022-10-24 22:21:26 +08:00
|
|
|
//============================================================================
|
|
|
|
bool static isHorizontalArea(CDockWidgetSideTab::SideTabBarArea Area)
|
|
|
|
{
|
|
|
|
switch (Area)
|
|
|
|
{
|
|
|
|
case CDockWidgetSideTab::Top:
|
|
|
|
case CDockWidgetSideTab::Bottom: return true;
|
|
|
|
case CDockWidgetSideTab::Left:
|
|
|
|
case CDockWidgetSideTab::Right: return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
Qt::Edge static edgeFromSideTabBarArea(CDockWidgetSideTab::SideTabBarArea Area)
|
|
|
|
{
|
|
|
|
switch (Area)
|
|
|
|
{
|
|
|
|
case CDockWidgetSideTab::Top: return Qt::BottomEdge;
|
|
|
|
case CDockWidgetSideTab::Bottom: return Qt::TopEdge;
|
|
|
|
case CDockWidgetSideTab::Left: return Qt::RightEdge;
|
|
|
|
case CDockWidgetSideTab::Right: return Qt::LeftEdge;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Qt::LeftEdge;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
int resizeHandleLayoutPosition(CDockWidgetSideTab::SideTabBarArea Area)
|
|
|
|
{
|
|
|
|
switch (Area)
|
|
|
|
{
|
|
|
|
case CDockWidgetSideTab::Bottom:
|
|
|
|
case CDockWidgetSideTab::Right: return 0;
|
|
|
|
|
|
|
|
case CDockWidgetSideTab::Top:
|
|
|
|
case CDockWidgetSideTab::Left: return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-12 17:17:54 +08:00
|
|
|
struct AutoHideDockContainerPrivate
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-10-12 17:17:54 +08:00
|
|
|
CAutoHideDockContainer* _this;
|
2022-09-05 17:29:42 +08:00
|
|
|
CDockAreaWidget* DockArea{nullptr};
|
|
|
|
CDockWidget* DockWidget{nullptr};
|
|
|
|
QPointer<CDockManager> DockManager{nullptr};
|
2022-10-13 14:56:25 +08:00
|
|
|
CDockWidgetSideTab::SideTabBarArea SideTabBarArea;
|
2022-10-24 22:21:26 +08:00
|
|
|
QBoxLayout* Layout;
|
|
|
|
CResizeHandle* ResizeHandle = nullptr;
|
|
|
|
QSize Size;
|
2022-09-05 17:29:42 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data constructor
|
|
|
|
*/
|
2022-10-12 17:17:54 +08:00
|
|
|
AutoHideDockContainerPrivate(CAutoHideDockContainer *_public);
|
2022-09-13 10:42:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience function to get a dock widget area
|
|
|
|
*/
|
|
|
|
DockWidgetArea getArea(CDockWidgetSideTab::SideTabBarArea area)
|
|
|
|
{
|
|
|
|
switch (area)
|
|
|
|
{
|
2022-10-17 17:34:59 +08:00
|
|
|
case CDockWidgetSideTab::Left:
|
2022-09-13 10:42:58 +08:00
|
|
|
{
|
|
|
|
return LeftDockWidgetArea;
|
|
|
|
}
|
2022-10-17 17:34:59 +08:00
|
|
|
case CDockWidgetSideTab::Right:
|
2022-09-13 10:42:58 +08:00
|
|
|
{
|
|
|
|
return RightDockWidgetArea;
|
|
|
|
}
|
|
|
|
case CDockWidgetSideTab::Bottom:
|
|
|
|
{
|
|
|
|
return BottomDockWidgetArea;
|
|
|
|
}
|
2022-10-14 21:13:32 +08:00
|
|
|
case CDockWidgetSideTab::Top:
|
|
|
|
{
|
|
|
|
return TopDockWidgetArea;
|
|
|
|
}
|
2022-09-13 10:42:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return LeftDockWidgetArea;
|
|
|
|
}
|
2022-09-15 12:51:59 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Convenience function to get dock position
|
|
|
|
*/
|
|
|
|
QPoint getSimplifiedDockAreaPosition() const
|
|
|
|
{
|
2022-10-13 14:56:25 +08:00
|
|
|
switch (SideTabBarArea)
|
2022-09-15 12:51:59 +08:00
|
|
|
{
|
2022-10-17 17:34:59 +08:00
|
|
|
case CDockWidgetSideTab::Left:
|
2022-09-15 12:51:59 +08:00
|
|
|
{
|
|
|
|
return QPoint(1, _this->height() / 2);
|
|
|
|
}
|
2022-10-17 17:34:59 +08:00
|
|
|
case CDockWidgetSideTab::Right:
|
2022-09-15 12:51:59 +08:00
|
|
|
{
|
|
|
|
return QPoint(_this->width() - 1, _this->height() / 2);
|
|
|
|
}
|
|
|
|
case CDockWidgetSideTab::Bottom:
|
|
|
|
{
|
|
|
|
return QPoint(_this->width() / 2, _this->height() - 1);
|
|
|
|
}
|
2022-10-14 21:13:32 +08:00
|
|
|
case CDockWidgetSideTab::Top:
|
|
|
|
{
|
|
|
|
return QPoint(_this->width() / 2, 1);
|
|
|
|
}
|
2022-09-15 12:51:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return QPoint();
|
|
|
|
}
|
2022-10-13 14:56:25 +08:00
|
|
|
|
2022-10-24 22:21:26 +08:00
|
|
|
void updateResizeHandleSizeLimitMax()
|
2022-10-13 14:56:25 +08:00
|
|
|
{
|
2022-10-25 16:01:51 +08:00
|
|
|
auto Rect = _this->parentContainer()->contentRect();
|
2022-10-24 22:21:26 +08:00
|
|
|
ResizeHandle->setMaxResizeSize(ResizeHandle->orientation() == Qt::Horizontal
|
|
|
|
? Rect.width() : Rect.height());
|
2022-10-13 14:56:25 +08:00
|
|
|
}
|
2022-10-13 14:26:54 +08:00
|
|
|
}; // struct AutoHideDockContainerPrivate
|
2022-09-05 17:29:42 +08:00
|
|
|
|
2022-10-24 22:21:26 +08:00
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
AutoHideDockContainerPrivate::AutoHideDockContainerPrivate(
|
|
|
|
CAutoHideDockContainer *_public) :
|
2022-09-05 17:29:42 +08:00
|
|
|
_this(_public)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-24 22:21:26 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
CDockContainerWidget* CAutoHideDockContainer::parentContainer() const
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-09-19 10:49:07 +08:00
|
|
|
return internal::findParent<CDockContainerWidget*>(this);
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
|
|
|
|
2022-10-24 22:21:26 +08:00
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
CAutoHideDockContainer::CAutoHideDockContainer(CDockManager* DockManager, CDockWidgetSideTab::SideTabBarArea area, CDockContainerWidget* parent) :
|
2022-10-23 22:42:14 +08:00
|
|
|
Super(parent),
|
2022-10-12 17:17:54 +08:00
|
|
|
d(new AutoHideDockContainerPrivate(this))
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
|
|
|
d->DockManager = DockManager;
|
2022-10-13 14:56:25 +08:00
|
|
|
d->SideTabBarArea = area;
|
2022-09-05 17:29:42 +08:00
|
|
|
d->DockArea = new CDockAreaWidget(DockManager, parent);
|
2022-10-13 14:26:54 +08:00
|
|
|
d->DockArea->setObjectName("autoHideDockArea");
|
|
|
|
d->DockArea->setAutoHideDockContainer(this);
|
2022-09-09 14:43:59 +08:00
|
|
|
d->DockArea->updateAutoHideButtonCheckState();
|
|
|
|
d->DockArea->updateTitleBarButtonToolTip();
|
2022-09-05 17:29:42 +08:00
|
|
|
|
2022-10-23 22:42:14 +08:00
|
|
|
setObjectName("autoHideDockContainer");
|
2022-10-24 22:21:26 +08:00
|
|
|
|
|
|
|
d->Layout = new QBoxLayout(isHorizontalArea(area) ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
|
|
|
|
d->Layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
d->Layout->setSpacing(0);
|
|
|
|
setLayout(d->Layout);
|
|
|
|
d->Layout->addWidget(d->DockArea);
|
|
|
|
d->ResizeHandle = new CResizeHandle(edgeFromSideTabBarArea(area), this);
|
|
|
|
d->ResizeHandle->setMinResizeSize(64);
|
|
|
|
d->Layout->insertWidget(resizeHandleLayoutPosition(area), d->ResizeHandle);
|
|
|
|
d->Size = d->DockArea->size();
|
2022-09-05 17:29:42 +08:00
|
|
|
|
|
|
|
updateSize();
|
2022-10-13 14:26:54 +08:00
|
|
|
parent->registerAutoHideWidget(this);
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
|
|
|
|
2022-10-23 22:42:14 +08:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, CDockWidgetSideTab::SideTabBarArea area, CDockContainerWidget* parent) :
|
|
|
|
CAutoHideDockContainer(DockWidget->dockManager(), area, parent)
|
|
|
|
{
|
|
|
|
addDockWidget(DockWidget);
|
|
|
|
setDockSizeProportion(DockWidget->DefaultAutoHideDockProportion());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
void CAutoHideDockContainer::updateSize()
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-10-23 22:42:14 +08:00
|
|
|
qDebug() << "CAutoHideDockContainer::updateSize()";
|
2022-10-24 22:21:26 +08:00
|
|
|
auto dockContainerParent = parentContainer();
|
|
|
|
auto rect = dockContainerParent->contentRect();
|
2022-09-05 17:29:42 +08:00
|
|
|
|
2022-10-23 22:42:14 +08:00
|
|
|
switch (sideTabBarArea())
|
|
|
|
{
|
|
|
|
case CDockWidgetSideTab::Top:
|
|
|
|
move(rect.topLeft());
|
2022-10-24 22:21:26 +08:00
|
|
|
resize(rect.width(), qMin(rect.height(), d->Size.height()));
|
2022-10-23 22:42:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CDockWidgetSideTab::Left:
|
|
|
|
move(rect.topLeft());
|
2022-10-24 22:21:26 +08:00
|
|
|
resize(qMin(d->Size.width(), rect.width()), rect.height());
|
2022-10-23 22:42:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CDockWidgetSideTab::Right:
|
|
|
|
{
|
|
|
|
QPoint p = rect.topRight();
|
|
|
|
p.rx() -= (width() - 1);
|
|
|
|
move(p);
|
2022-10-24 22:21:26 +08:00
|
|
|
resize(qMin(d->Size.width(), rect.width()), rect.height());
|
2022-10-23 22:42:14 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CDockWidgetSideTab::Bottom:
|
|
|
|
{
|
|
|
|
QPoint p = rect.bottomLeft();
|
|
|
|
p.ry() -= (height() - 1);
|
|
|
|
move(p);
|
2022-10-24 22:21:26 +08:00
|
|
|
resize(rect.width(), qMin(rect.height(), d->Size.height()));
|
2022-10-23 22:42:14 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//resize(rect.width(), rect.height());
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
CAutoHideDockContainer::~CAutoHideDockContainer()
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-10-13 14:26:54 +08:00
|
|
|
ADS_PRINT("~CAutoHideDockContainer");
|
2022-09-05 17:29:42 +08:00
|
|
|
|
2022-09-14 13:10:06 +08:00
|
|
|
// Remove event filter in case there are any queued messages
|
2022-10-14 16:09:13 +08:00
|
|
|
qApp->removeEventFilter(this);
|
2022-09-14 13:10:06 +08:00
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
if (d->DockManager)
|
|
|
|
{
|
2022-10-13 14:26:54 +08:00
|
|
|
parentContainer()->removeAutoHideWidget(this);
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
CSideTabBar* CAutoHideDockContainer::sideTabBar() const
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-10-13 14:56:25 +08:00
|
|
|
return parentContainer()->sideTabBar(d->SideTabBarArea);
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
CDockWidget* CAutoHideDockContainer::dockWidget() const
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
|
|
|
return d->DockWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
void CAutoHideDockContainer::addDockWidget(CDockWidget* DockWidget)
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
|
|
|
if (d->DockWidget)
|
|
|
|
{
|
|
|
|
// Remove the old dock widget at this area
|
|
|
|
d->DockArea->removeDockWidget(d->DockWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->DockWidget = DockWidget;
|
|
|
|
CDockAreaWidget* OldDockArea = DockWidget->dockAreaWidget();
|
|
|
|
if (OldDockArea)
|
|
|
|
{
|
|
|
|
OldDockArea->removeDockWidget(DockWidget);
|
|
|
|
}
|
|
|
|
d->DockArea->addDockWidget(DockWidget);
|
2022-10-13 14:56:25 +08:00
|
|
|
d->DockWidget->sideTabWidget()->updateOrientationAndSpacing(d->SideTabBarArea);
|
2022-10-23 22:42:14 +08:00
|
|
|
qDebug() << "DockWidget->size(): " << DockWidget->size();
|
|
|
|
this->resize(OldDockArea ? OldDockArea->size() : d->DockWidget->size());
|
2022-09-13 11:20:46 +08:00
|
|
|
|
|
|
|
updateSize();
|
|
|
|
}
|
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
|
2022-09-13 11:20:46 +08:00
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
void CAutoHideDockContainer::setDockSizeProportion(float SplitterProportion)
|
2022-09-13 11:20:46 +08:00
|
|
|
{
|
2022-09-13 16:29:39 +08:00
|
|
|
if (SplitterProportion < 0 || SplitterProportion > 1)
|
|
|
|
{
|
|
|
|
ADS_PRINT("SplitterProportion must be set between 0 and 1.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-15 09:43:15 +08:00
|
|
|
const auto dockSize = static_cast<int>(static_cast<float>(INT_MAX) * SplitterProportion);
|
2022-09-13 16:29:39 +08:00
|
|
|
const auto remainingSize = INT_MAX - dockSize;
|
2022-10-23 22:42:14 +08:00
|
|
|
/* switch (d->SideTabBarArea)
|
2022-09-13 10:42:58 +08:00
|
|
|
{
|
2022-10-17 17:34:59 +08:00
|
|
|
case CDockWidgetSideTab::Left:
|
2022-09-13 10:42:58 +08:00
|
|
|
{
|
2022-09-19 10:49:07 +08:00
|
|
|
setSizes({ dockSize, remainingSize });
|
2022-09-13 10:42:58 +08:00
|
|
|
break;
|
|
|
|
}
|
2022-10-17 17:34:59 +08:00
|
|
|
case CDockWidgetSideTab::Right:
|
2022-09-13 10:42:58 +08:00
|
|
|
case CDockWidgetSideTab::Bottom:
|
|
|
|
{
|
2022-09-19 10:49:07 +08:00
|
|
|
setSizes({ remainingSize, dockSize });
|
2022-09-13 10:42:58 +08:00
|
|
|
break;
|
|
|
|
}
|
2022-10-23 22:42:14 +08:00
|
|
|
}*/
|
2022-09-09 15:24:33 +08:00
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
CDockWidgetSideTab::SideTabBarArea CAutoHideDockContainer::sideTabBarArea() const
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-10-13 14:56:25 +08:00
|
|
|
return d->SideTabBarArea;
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
CDockAreaWidget* CAutoHideDockContainer::dockAreaWidget() const
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
|
|
|
return d->DockArea;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
void CAutoHideDockContainer::moveContentsToParent()
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-10-12 16:58:47 +08:00
|
|
|
cleanupAndDelete();
|
2022-10-17 15:52:00 +08:00
|
|
|
// If we unpin the auto hide tock widget, then we insert it into the same
|
|
|
|
// location like it had as a auto hide widget. This brings the least surprise
|
|
|
|
// to the user and he does not have to search where the widget was inserted.
|
|
|
|
parentContainer()->addDockWidget(d->getArea(d->SideTabBarArea), d->DockWidget);
|
2022-10-12 16:58:47 +08:00
|
|
|
parentContainer()->removeDockArea(d->DockArea);
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
|
|
|
|
2022-09-08 16:30:07 +08:00
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
void CAutoHideDockContainer::cleanupAndDelete()
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
|
|
|
const auto dockWidget = d->DockWidget;
|
|
|
|
if (dockWidget)
|
|
|
|
{
|
|
|
|
dockWidget->sideTabWidget()->removeFromSideTabBar();
|
|
|
|
dockWidget->sideTabWidget()->setParent(dockWidget);
|
|
|
|
dockWidget->sideTabWidget()->hide();
|
|
|
|
}
|
2022-09-14 12:34:13 +08:00
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
hide();
|
|
|
|
deleteLater();
|
|
|
|
}
|
|
|
|
|
2022-09-08 16:30:07 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
void CAutoHideDockContainer::saveState(QXmlStreamWriter& s)
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-09-08 13:10:46 +08:00
|
|
|
s.writeAttribute("SideTabBarArea", QString::number(sideTabBarArea()));
|
2022-09-05 17:29:42 +08:00
|
|
|
QStringList Sizes;
|
2022-10-23 22:42:14 +08:00
|
|
|
// TODO implement auto hide dock container saving
|
|
|
|
/*for (auto Size : sizes())
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
|
|
|
Sizes << QString::number(Size);
|
2022-10-23 22:42:14 +08:00
|
|
|
}*/
|
2022-09-05 17:29:42 +08:00
|
|
|
|
|
|
|
s.writeAttribute("Sizes", Sizes.join(" "));
|
|
|
|
}
|
|
|
|
|
2022-09-08 16:30:07 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
bool CAutoHideDockContainer::restoreState(CDockingStateReader& s, bool Testing)
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
|
|
|
auto sSizes = s.attributes().value("Sizes").trimmed().toString();
|
|
|
|
ADS_PRINT("Sizes: " << sSizes);
|
|
|
|
QTextStream TextStream(&sSizes);
|
|
|
|
QList<int> Sizes;
|
|
|
|
while (!TextStream.atEnd())
|
|
|
|
{
|
|
|
|
int value;
|
|
|
|
TextStream >> value;
|
|
|
|
Sizes.append(value);
|
|
|
|
}
|
|
|
|
|
2022-10-23 22:42:14 +08:00
|
|
|
// TODO implement restore state
|
|
|
|
/*if (Sizes.count() != count())
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Testing)
|
|
|
|
{
|
2022-09-19 10:49:07 +08:00
|
|
|
setSizes(Sizes);
|
2022-10-23 22:42:14 +08:00
|
|
|
}*/
|
2022-09-05 17:29:42 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-10-12 17:32:55 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
void CAutoHideDockContainer::toggleView(bool Enable)
|
2022-09-09 12:18:41 +08:00
|
|
|
{
|
|
|
|
if (Enable)
|
|
|
|
{
|
|
|
|
const auto dockWidget = d->DockWidget;
|
|
|
|
if (dockWidget)
|
|
|
|
{
|
|
|
|
dockWidget->sideTabWidget()->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto dockWidget = d->DockWidget;
|
|
|
|
if (dockWidget)
|
|
|
|
{
|
|
|
|
dockWidget->sideTabWidget()->hide();
|
|
|
|
}
|
|
|
|
hide();
|
2022-10-12 17:17:54 +08:00
|
|
|
qApp->removeEventFilter(this);
|
2022-09-09 12:18:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-12 17:32:55 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
void CAutoHideDockContainer::collapseView(bool Enable)
|
2022-09-09 12:18:41 +08:00
|
|
|
{
|
|
|
|
if (Enable)
|
|
|
|
{
|
|
|
|
hide();
|
2022-09-14 12:32:32 +08:00
|
|
|
d->DockArea->hide();
|
|
|
|
d->DockWidget->hide();
|
2022-10-12 17:32:55 +08:00
|
|
|
qApp->removeEventFilter(this);
|
2022-09-09 12:18:41 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-24 22:21:26 +08:00
|
|
|
d->updateResizeHandleSizeLimitMax();
|
2022-09-15 11:51:56 +08:00
|
|
|
raise();
|
2022-09-09 12:18:41 +08:00
|
|
|
show();
|
2022-09-14 12:32:32 +08:00
|
|
|
d->DockArea->show();
|
|
|
|
d->DockWidget->show();
|
2022-10-14 16:09:13 +08:00
|
|
|
updateSize();
|
2022-10-14 17:47:41 +08:00
|
|
|
d->DockManager->setDockWidgetFocused(d->DockWidget);
|
2022-10-12 17:17:54 +08:00
|
|
|
qApp->installEventFilter(this);
|
2022-09-09 12:18:41 +08:00
|
|
|
}
|
2022-10-14 21:32:05 +08:00
|
|
|
|
|
|
|
d->DockWidget->sideTabWidget()->updateStyle();
|
2022-10-12 17:17:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CAutoHideDockContainer::toggleCollapseState()
|
|
|
|
{
|
|
|
|
collapseView(isVisible());
|
2022-09-09 12:18:41 +08:00
|
|
|
}
|
|
|
|
|
2022-09-08 16:30:07 +08:00
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
|
|
|
if (event->type() == QEvent::Resize)
|
|
|
|
{
|
2022-10-24 22:21:26 +08:00
|
|
|
if (!d->ResizeHandle->isResizing())
|
|
|
|
{
|
|
|
|
updateSize();
|
|
|
|
}
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
2022-10-12 17:17:54 +08:00
|
|
|
else if (event->type() == QEvent::MouseButtonPress)
|
|
|
|
{
|
|
|
|
// First we check, if the mouse button press is inside the dock manager
|
|
|
|
// widget. If it is not, i.e. if someone resizes the main window or
|
|
|
|
// clicks into the application menu or toolbar, then we ignore the
|
|
|
|
// event
|
|
|
|
auto widget = qobject_cast<QWidget*>(watched);
|
|
|
|
bool IsDockManager = false;
|
|
|
|
while (widget)
|
|
|
|
{
|
|
|
|
if (widget == d->DockManager)
|
|
|
|
{
|
|
|
|
IsDockManager = true;
|
|
|
|
}
|
|
|
|
widget = widget->parentWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsDockManager)
|
|
|
|
{
|
2022-10-23 22:42:14 +08:00
|
|
|
return Super::eventFilter(watched, event);
|
2022-10-12 17:17:54 +08:00
|
|
|
}
|
|
|
|
|
2022-10-12 17:47:54 +08:00
|
|
|
// Now we check, if the user clicked inside of this auto hide container.
|
|
|
|
// If the click is inside of this auto hide container, then we can also
|
2022-10-13 14:26:54 +08:00
|
|
|
// ignore the event, because the auto hide overlay should not get collapsed if
|
2022-10-12 17:47:54 +08:00
|
|
|
// user works in it
|
2022-10-12 17:17:54 +08:00
|
|
|
QMouseEvent* me = static_cast<QMouseEvent*>(event);
|
2022-10-13 14:56:25 +08:00
|
|
|
auto pos = mapFromGlobal(me->globalPos());
|
2022-10-24 22:21:26 +08:00
|
|
|
if (rect().contains(pos))
|
2022-10-12 17:17:54 +08:00
|
|
|
{
|
2022-10-23 22:42:14 +08:00
|
|
|
return Super::eventFilter(watched, event);
|
2022-10-12 17:17:54 +08:00
|
|
|
}
|
|
|
|
|
2022-10-12 17:32:55 +08:00
|
|
|
// Now check, if the user clicked into the side tab and ignore this event,
|
|
|
|
// because the side tab click handler will call collapseView(). If we
|
|
|
|
// do not ignore this here, then we will collapse the container and the side tab
|
|
|
|
// click handler will uncollapse it
|
|
|
|
auto SideTab = d->DockWidget->sideTabWidget();
|
|
|
|
pos = SideTab->mapFromGlobal(me->globalPos());
|
|
|
|
if (SideTab->rect().contains(pos))
|
|
|
|
{
|
2022-10-23 22:42:14 +08:00
|
|
|
return Super::eventFilter(watched, event);
|
2022-10-12 17:32:55 +08:00
|
|
|
}
|
|
|
|
|
2022-10-12 17:17:54 +08:00
|
|
|
// If the mouse button down event is in the dock manager but outside
|
2022-10-12 17:47:54 +08:00
|
|
|
// of the open auto hide container, then the auto hide dock widget
|
2022-10-12 17:17:54 +08:00
|
|
|
// should get collapsed
|
|
|
|
collapseView(true);
|
|
|
|
}
|
2022-10-12 16:58:47 +08:00
|
|
|
|
2022-10-23 22:42:14 +08:00
|
|
|
return Super::eventFilter(watched, event);
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
|
|
|
|
2022-09-08 16:30:07 +08:00
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
//============================================================================
|
2022-10-12 17:17:54 +08:00
|
|
|
void CAutoHideDockContainer::resizeEvent(QResizeEvent* event)
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-10-23 22:42:14 +08:00
|
|
|
std::cout << "ResizeEvent" << std::endl;
|
|
|
|
Super::resizeEvent(event);
|
2022-10-24 22:21:26 +08:00
|
|
|
if (d->ResizeHandle->isResizing())
|
2022-10-23 22:42:14 +08:00
|
|
|
{
|
2022-10-24 22:21:26 +08:00
|
|
|
d->Size = this->size();
|
|
|
|
qDebug() << "Size " << d->Size;
|
|
|
|
d->updateResizeHandleSizeLimitMax();
|
2022-10-23 22:42:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
|
|
|
|