mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-04-19 03:44:45 +08:00
Fix formatting#2 (#663)
This commit is contained in:
parent
2878559ee6
commit
8cfa5c8e0e
@ -16,6 +16,7 @@
|
||||
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
//============================================================================
|
||||
/// \file AutoHideDockContainer.cpp
|
||||
/// \author Syarif Fakhri
|
||||
@ -28,23 +29,23 @@
|
||||
//============================================================================
|
||||
#include "AutoHideDockContainer.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QBoxLayout>
|
||||
#include <QCursor>
|
||||
#include <QPainter>
|
||||
#include <QPointer>
|
||||
#include <QSplitter>
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QSplitter>
|
||||
#include <QPointer>
|
||||
#include <QApplication>
|
||||
#include <QCursor>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "DockManager.h"
|
||||
#include "DockAreaWidget.h"
|
||||
#include "ResizeHandle.h"
|
||||
#include "DockComponentsFactory.h"
|
||||
#include "AutoHideSideBar.h"
|
||||
#include "AutoHideTab.h"
|
||||
#include "DockAreaWidget.h"
|
||||
#include "DockComponentsFactory.h"
|
||||
#include "DockManager.h"
|
||||
#include "ResizeHandle.h"
|
||||
#include "ads_globals.h"
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
@ -59,12 +60,14 @@ bool static isHorizontalArea(SideBarLocation Area)
|
||||
case SideBarLocation::SideBarBottom: return true;
|
||||
case SideBarLocation::SideBarLeft:
|
||||
case SideBarLocation::SideBarRight: return false;
|
||||
default: return true;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
Qt::Edge static edgeFromSideTabBarArea(SideBarLocation Area)
|
||||
{
|
||||
@ -74,12 +77,14 @@ Qt::Edge static edgeFromSideTabBarArea(SideBarLocation Area)
|
||||
case SideBarLocation::SideBarBottom: return Qt::TopEdge;
|
||||
case SideBarLocation::SideBarLeft: return Qt::RightEdge;
|
||||
case SideBarLocation::SideBarRight: return Qt::LeftEdge;
|
||||
default: return Qt::LeftEdge;
|
||||
default:
|
||||
return Qt::LeftEdge;
|
||||
}
|
||||
|
||||
return Qt::LeftEdge;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
int resizeHandleLayoutPosition(SideBarLocation Area)
|
||||
{
|
||||
@ -91,12 +96,14 @@ int resizeHandleLayoutPosition(SideBarLocation Area)
|
||||
case SideBarLocation::SideBarTop:
|
||||
case SideBarLocation::SideBarLeft: return 1;
|
||||
|
||||
default: return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Private data of CAutoHideDockContainer - pimpl
|
||||
*/
|
||||
@ -128,7 +135,8 @@ struct AutoHideDockContainerPrivate
|
||||
case SideBarLocation::SideBarRight: return RightDockWidgetArea;
|
||||
case SideBarLocation::SideBarBottom: return BottomDockWidgetArea;
|
||||
case SideBarLocation::SideBarTop: return TopDockWidgetArea;
|
||||
default: return LeftDockWidgetArea;
|
||||
default:
|
||||
return LeftDockWidgetArea;
|
||||
}
|
||||
|
||||
return LeftDockWidgetArea;
|
||||
@ -140,16 +148,18 @@ struct AutoHideDockContainerPrivate
|
||||
void updateResizeHandleSizeLimitMax()
|
||||
{
|
||||
auto Rect = _this->dockContainer()->contentRect();
|
||||
const auto maxResizeHandleSize =
|
||||
ResizeHandle->orientation() == Qt::Horizontal ? Rect.width() :
|
||||
Rect.height();
|
||||
const auto maxResizeHandleSize = ResizeHandle->orientation() == Qt::Horizontal
|
||||
? Rect.width() : Rect.height();
|
||||
ResizeHandle->setMaxResizeSize(maxResizeHandleSize - ResizeMargin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to check, if this is an horizontal area
|
||||
*/
|
||||
bool isHorizontal() const { return isHorizontalArea(SideTabBarArea); }
|
||||
bool isHorizontal() const
|
||||
{
|
||||
return isHorizontalArea(SideTabBarArea);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forward this event to the dock container
|
||||
@ -165,11 +175,15 @@ struct AutoHideDockContainerPrivate
|
||||
|
||||
}; // struct AutoHideDockContainerPrivate
|
||||
|
||||
|
||||
//============================================================================
|
||||
AutoHideDockContainerPrivate::AutoHideDockContainerPrivate(
|
||||
CAutoHideDockContainer* _public)
|
||||
: _this(_public)
|
||||
{}
|
||||
CAutoHideDockContainer *_public) :
|
||||
_this(_public)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockContainerWidget* CAutoHideDockContainer::dockContainer() const
|
||||
@ -177,32 +191,29 @@ CDockContainerWidget* CAutoHideDockContainer::dockContainer() const
|
||||
return internal::findParent<CDockContainerWidget*>(this);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget,
|
||||
SideBarLocation area,
|
||||
CDockContainerWidget* parent)
|
||||
: Super(parent), d(new AutoHideDockContainerPrivate(this))
|
||||
CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarLocation area, CDockContainerWidget* parent) :
|
||||
Super(parent),
|
||||
d(new AutoHideDockContainerPrivate(this))
|
||||
{
|
||||
hide(); // auto hide dock container is initially always hidden
|
||||
d->SideTabBarArea = area;
|
||||
d->SideTab = componentsFactory()->createDockWidgetSideTab(nullptr);
|
||||
connect(d->SideTab, &CAutoHideTab::pressed, this,
|
||||
&CAutoHideDockContainer::toggleCollapseState);
|
||||
connect(d->SideTab, &CAutoHideTab::pressed, this, &CAutoHideDockContainer::toggleCollapseState);
|
||||
d->DockArea = new CDockAreaWidget(DockWidget->dockManager(), parent);
|
||||
d->DockArea->setObjectName("autoHideDockArea");
|
||||
d->DockArea->setAutoHideDockContainer(this);
|
||||
|
||||
setObjectName("autoHideDockContainer");
|
||||
|
||||
d->Layout = new QBoxLayout(isHorizontalArea(area) ? QBoxLayout::TopToBottom :
|
||||
QBoxLayout::LeftToRight);
|
||||
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->ResizeHandle = new CResizeHandle(edgeFromSideTabBarArea(area), this);
|
||||
d->ResizeHandle->setMinResizeSize(64);
|
||||
bool OpaqueResize =
|
||||
CDockManager::testConfigFlag(CDockManager::OpaqueSplitterResize);
|
||||
bool OpaqueResize = CDockManager::testConfigFlag(CDockManager::OpaqueSplitterResize);
|
||||
d->ResizeHandle->setOpaqueResize(OpaqueResize);
|
||||
d->Size = d->DockArea->size();
|
||||
d->SizeCache = DockWidget->size();
|
||||
@ -212,12 +223,12 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget,
|
||||
// The dock area should not be added to the layout before it contains the
|
||||
// dock widget. If you add it to the layout before it contains the dock widget
|
||||
// then you will likely see this warning for OpenGL widgets or QAxWidgets:
|
||||
// setGeometry: Unable to set geometry XxY+Width+Height on
|
||||
// QWidgetWindow/'WidgetClassWindow
|
||||
// setGeometry: Unable to set geometry XxY+Width+Height on QWidgetWindow/'WidgetClassWindow
|
||||
d->Layout->addWidget(d->DockArea);
|
||||
d->Layout->insertWidget(resizeHandleLayoutPosition(area), d->ResizeHandle);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CAutoHideDockContainer::updateSize()
|
||||
{
|
||||
@ -231,8 +242,7 @@ void CAutoHideDockContainer::updateSize()
|
||||
switch (sideBarLocation())
|
||||
{
|
||||
case SideBarLocation::SideBarTop:
|
||||
resize(rect.width(),
|
||||
qMin(rect.height() - ResizeMargin, d->Size.height()));
|
||||
resize(rect.width(), qMin(rect.height() - ResizeMargin, d->Size.height()));
|
||||
move(rect.topLeft());
|
||||
break;
|
||||
|
||||
@ -252,15 +262,15 @@ void CAutoHideDockContainer::updateSize()
|
||||
|
||||
case SideBarLocation::SideBarBottom:
|
||||
{
|
||||
resize(rect.width(),
|
||||
qMin(rect.height() - ResizeMargin, d->Size.height()));
|
||||
resize(rect.width(), qMin(rect.height() - ResizeMargin, d->Size.height()));
|
||||
QPoint p = rect.bottomLeft();
|
||||
p.ry() -= (height() - 1);
|
||||
move(p);
|
||||
}
|
||||
break;
|
||||
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (orientation() == Qt::Horizontal)
|
||||
@ -303,17 +313,18 @@ CAutoHideSideBar* CAutoHideDockContainer::autoHideSideBar() const
|
||||
else
|
||||
{
|
||||
auto DockContainer = dockContainer();
|
||||
return DockContainer ? DockContainer->autoHideSideBar(d->SideTabBarArea) :
|
||||
nullptr;
|
||||
return DockContainer ? DockContainer->autoHideSideBar(d->SideTabBarArea) : nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CAutoHideTab* CAutoHideDockContainer::autoHideTab() const
|
||||
{
|
||||
return d->SideTab;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockWidget* CAutoHideDockContainer::dockWidget() const
|
||||
{
|
||||
@ -349,12 +360,14 @@ void CAutoHideDockContainer::addDockWidget(CDockWidget* DockWidget)
|
||||
d->DockArea->resize(size());
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
SideBarLocation CAutoHideDockContainer::sideBarLocation() const
|
||||
{
|
||||
return d->SideTabBarArea;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CAutoHideDockContainer::setSideBarLocation(SideBarLocation SideBarLocation)
|
||||
{
|
||||
@ -365,15 +378,13 @@ void CAutoHideDockContainer::setSideBarLocation(SideBarLocation SideBarLocation)
|
||||
|
||||
d->SideTabBarArea = SideBarLocation;
|
||||
d->Layout->removeWidget(d->ResizeHandle);
|
||||
d->Layout->setDirection(isHorizontalArea(SideBarLocation) ?
|
||||
QBoxLayout::TopToBottom :
|
||||
QBoxLayout::LeftToRight);
|
||||
d->Layout->insertWidget(resizeHandleLayoutPosition(SideBarLocation),
|
||||
d->ResizeHandle);
|
||||
d->Layout->setDirection(isHorizontalArea(SideBarLocation) ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
|
||||
d->Layout->insertWidget(resizeHandleLayoutPosition(SideBarLocation), d->ResizeHandle);
|
||||
d->ResizeHandle->setHandlePosition(edgeFromSideTabBarArea(SideBarLocation));
|
||||
internal::repolishStyle(this, internal::RepolishDirectChildren);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockAreaWidget* CAutoHideDockContainer::dockAreaWidget() const
|
||||
{
|
||||
@ -389,16 +400,17 @@ void CAutoHideDockContainer::moveContentsToParent()
|
||||
// to the user and he does not have to search where the widget was inserted.
|
||||
d->DockWidget->setDockArea(nullptr);
|
||||
auto DockContainer = dockContainer();
|
||||
DockContainer->addDockWidget(d->getDockWidgetArea(d->SideTabBarArea),
|
||||
d->DockWidget);
|
||||
DockContainer->addDockWidget(d->getDockWidgetArea(d->SideTabBarArea), d->DockWidget);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CAutoHideDockContainer::cleanupAndDelete()
|
||||
{
|
||||
const auto dockWidget = d->DockWidget;
|
||||
if (dockWidget)
|
||||
{
|
||||
|
||||
auto SideTab = d->SideTab;
|
||||
SideTab->removeFromSideBar();
|
||||
SideTab->setParent(nullptr);
|
||||
@ -409,19 +421,18 @@ void CAutoHideDockContainer::cleanupAndDelete()
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CAutoHideDockContainer::saveState(QXmlStreamWriter& s)
|
||||
{
|
||||
s.writeStartElement("Widget");
|
||||
s.writeAttribute("Name", d->DockWidget->objectName());
|
||||
s.writeAttribute("Closed",
|
||||
QString::number(d->DockWidget->isClosed() ? 1 : 0));
|
||||
s.writeAttribute(
|
||||
"Size",
|
||||
QString::number(d->isHorizontal() ? d->Size.height() : d->Size.width()));
|
||||
s.writeAttribute("Closed", QString::number(d->DockWidget->isClosed() ? 1 : 0));
|
||||
s.writeAttribute("Size", QString::number(d->isHorizontal() ? d->Size.height() : d->Size.width()));
|
||||
s.writeEndElement();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CAutoHideDockContainer::toggleView(bool Enable)
|
||||
{
|
||||
@ -443,6 +454,7 @@ void CAutoHideDockContainer::toggleView(bool Enable)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CAutoHideDockContainer::collapseView(bool Enable)
|
||||
{
|
||||
@ -465,12 +477,14 @@ void CAutoHideDockContainer::collapseView(bool Enable)
|
||||
d->SideTab->updateStyle();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CAutoHideDockContainer::toggleCollapseState()
|
||||
{
|
||||
collapseView(isVisible());
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CAutoHideDockContainer::setSize(int Size)
|
||||
{
|
||||
@ -486,6 +500,7 @@ void CAutoHideDockContainer::setSize(int Size)
|
||||
updateSize();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
/**
|
||||
* Returns true if the object given in ancestor is an ancestor of the object
|
||||
@ -508,6 +523,7 @@ static bool objectIsAncestorOf(const QObject* descendant, const QObject* ancesto
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
/**
|
||||
* Returns true if the object given in ancestor is the object given in descendant
|
||||
@ -525,6 +541,7 @@ static bool isObjectOrAncestor(const QObject* descendant, const QObject* ancesto
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
|
||||
{
|
||||
@ -548,8 +565,8 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
|
||||
|
||||
// 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
|
||||
// do not ignore this here, then we will collapse the container and the side tab
|
||||
// click handler will uncollapse it
|
||||
if (widget == d->SideTab.data())
|
||||
{
|
||||
return Super::eventFilter(watched, event);
|
||||
@ -557,8 +574,8 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
|
||||
|
||||
// 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
|
||||
// ignore the event, because the auto hide overlay should not get
|
||||
// collapsed if user works in it
|
||||
// ignore the event, because the auto hide overlay should not get collapsed if
|
||||
// user works in it
|
||||
if (isObjectOrAncestor(widget, this))
|
||||
{
|
||||
return Super::eventFilter(watched, event);
|
||||
@ -591,6 +608,7 @@ bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
|
||||
return Super::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CAutoHideDockContainer::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
@ -602,6 +620,7 @@ void CAutoHideDockContainer::resizeEvent(QResizeEvent* event)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CAutoHideDockContainer::leaveEvent(QEvent *event)
|
||||
{
|
||||
@ -616,17 +635,23 @@ void CAutoHideDockContainer::leaveEvent(QEvent* event)
|
||||
Super::leaveEvent(event);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool CAutoHideDockContainer::event(QEvent* event)
|
||||
{
|
||||
switch (event->type())
|
||||
{
|
||||
case QEvent::Enter:
|
||||
case QEvent::Hide: d->forwardEventToDockContainer(event); break;
|
||||
case QEvent::Hide:
|
||||
d->forwardEventToDockContainer(event);
|
||||
break;
|
||||
|
||||
case QEvent::MouseButtonPress: return true; break;
|
||||
case QEvent::MouseButtonPress:
|
||||
return true;
|
||||
break;
|
||||
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return Super::event(event);
|
||||
@ -645,11 +670,11 @@ void CAutoHideDockContainer::dragLeaveEvent(QDragLeaveEvent*)
|
||||
//============================================================================
|
||||
Qt::Orientation CAutoHideDockContainer::orientation() const
|
||||
{
|
||||
return ads::internal::isHorizontalSideBarLocation(d->SideTabBarArea) ?
|
||||
Qt::Horizontal :
|
||||
Qt::Vertical;
|
||||
return ads::internal::isHorizontalSideBarLocation(d->SideTabBarArea)
|
||||
? Qt::Horizontal : Qt::Vertical;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CAutoHideDockContainer::resetToInitialDockWidgetSize()
|
||||
{
|
||||
@ -663,9 +688,10 @@ void CAutoHideDockContainer::resetToInitialDockWidgetSize()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CAutoHideDockContainer::moveToNewSideBarLocation(
|
||||
SideBarLocation NewSideBarLocation, int TabIndex)
|
||||
void CAutoHideDockContainer::moveToNewSideBarLocation(SideBarLocation NewSideBarLocation,
|
||||
int TabIndex)
|
||||
{
|
||||
if (NewSideBarLocation == sideBarLocation() && TabIndex == this->tabIndex())
|
||||
{
|
||||
@ -684,10 +710,11 @@ void CAutoHideDockContainer::moveToNewSideBarLocation(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
int CAutoHideDockContainer::tabIndex() const
|
||||
{
|
||||
return d->SideTab->tabIndex();
|
||||
}
|
||||
|
||||
} // namespace ads
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user