Implemented Pin To functionality for Auto Hide Tabs

This commit is contained in:
Uwe Kindler 2023-07-07 13:35:55 +02:00
parent 1c6d86e70f
commit 4bdc04e9d8
9 changed files with 125 additions and 33 deletions

View File

@ -117,6 +117,7 @@ struct AutoHideDockContainerPrivate
CResizeHandle* ResizeHandle = nullptr;
QSize Size; // creates invalid size
QPointer<CAutoHideTab> SideTab;
QSize OriginalDockWidgetSize;
/**
* Private data constructor
@ -214,7 +215,9 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarL
d->ResizeHandle->setMinResizeSize(64);
bool OpaqueResize = CDockManager::testConfigFlag(CDockManager::OpaqueSplitterResize);
d->ResizeHandle->setOpaqueResize(OpaqueResize);
std::cout << "d->DockArea->size(); " << d->DockArea->size().width() << std::endl;
d->Size = d->DockArea->size();
d->OriginalDockWidgetSize = DockWidget->size();
addDockWidget(DockWidget);
parent->registerAutoHideWidget(this);
@ -303,7 +306,7 @@ CAutoHideDockContainer::~CAutoHideDockContainer()
}
//============================================================================
CAutoHideSideBar* CAutoHideDockContainer::sideBar() const
CAutoHideSideBar* CAutoHideDockContainer::autoHideSideBar() const
{
if (d->SideTab)
{
@ -312,7 +315,7 @@ CAutoHideSideBar* CAutoHideDockContainer::sideBar() const
else
{
auto DockContainer = dockContainer();
return DockContainer ? DockContainer->sideTabBar(d->SideTabBarArea) : nullptr;
return DockContainer ? DockContainer->autoHideSideBar(d->SideTabBarArea) : nullptr;
}
}
@ -657,5 +660,19 @@ bool CAutoHideDockContainer::event(QEvent* event)
return Super::event(event);
}
//============================================================================
QSize CAutoHideDockContainer::originalDockWidgetSize() const
{
return d->OriginalDockWidgetSize;
}
//============================================================================
Qt::Orientation CAutoHideDockContainer::orientation() const
{
return autoHideSideBar()->orientation();
}
}

View File

@ -93,7 +93,7 @@ public:
/**
* Get's the side tab bar
*/
CAutoHideSideBar* sideBar() const;
CAutoHideSideBar* autoHideSideBar() const;
/**
* Returns the side tab
@ -166,6 +166,21 @@ public:
* of this auto hide container.
*/
void setSize(int Size);
/**
* Returns the original size of the dock widget at the time it has been
* added to this auto hide widget
*/
QSize originalDockWidgetSize() const;
/**
* Returns orientation of this container.
* Left and right containers have a Qt::Vertical orientation and top / bottom
* containers have a Qt::Horizontal orientation.
* The function returns the orientation of the corresponding auto hide
* side bar.
*/
Qt::Orientation orientation() const;
};
} // namespace ads

View File

@ -42,6 +42,8 @@
namespace ads
{
static const char* const LocationProperty = "Location";
/**
* Private data class of CDockWidgetTab class (pimpl)
*/
@ -83,6 +85,20 @@ struct AutoHideTabPrivate
DockContainer->handleAutoHideWidgetEvent(event, _this);
}
}
/**
* Helper function to create and initialize the menu entries for
* the "Auto Hide Group To..." menu
*/
QAction* createAutoHideToAction(const QString& Title, SideBarLocation Location,
QMenu* Menu)
{
auto Action = Menu->addAction(Title);
Action->setProperty("Location", Location);
QObject::connect(Action, &QAction::triggered, _this, &CAutoHideTab::onAutoHideToActionClicked);
Action->setEnabled(Location != _this->sideBarLocation());
return Action;
}
}; // struct DockWidgetTabPrivate
@ -299,10 +315,10 @@ void CAutoHideTab::contextMenuEvent(QContextMenuEvent* ev)
auto menu = Menu.addMenu(tr("Pin To..."));
menu->setEnabled(IsPinnable);
//d->createAutoHideToAction(tr("Top"), SideBarTop, menu);
//d->createAutoHideToAction(tr("Left"), SideBarLeft, menu);
//d->createAutoHideToAction(tr("Right"), SideBarRight, menu);
//d->createAutoHideToAction(tr("Bottom"), SideBarBottom, menu);
d->createAutoHideToAction(tr("Top"), SideBarTop, menu);
d->createAutoHideToAction(tr("Left"), SideBarLeft, menu);
d->createAutoHideToAction(tr("Right"), SideBarRight, menu);
d->createAutoHideToAction(tr("Bottom"), SideBarBottom, menu);
/*Menu.addSeparator();
Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested()));
@ -315,23 +331,33 @@ void CAutoHideTab::contextMenuEvent(QContextMenuEvent* ev)
}
//============================================================================
void CAutoHideTab::mouseDoubleClickEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
setDockWidgetFloating();
}
Super::mouseDoubleClickEvent(event);
}
//============================================================================
void CAutoHideTab::setDockWidgetFloating()
{
/*auto DockArea = dockWidget()->dockAreaWidget();
auto AutoHideContainer = dockWidget()->autoHideDockContainer();
auto OriginalSize = AutoHideContainer->originalDockWidgetSize();
auto DockAreaSize = DockArea->size();
if (ads::internal::isHorizontalSideBarLocation(sideBarLocation()))
{
DockAreaSize.setHeight(OriginalSize.height());
}
else
{
DockAreaSize.setWidth(OriginalSize.width());
}
DockArea->resize(DockAreaSize);*/
dockWidget()->setFloating();
}
//===========================================================================
void CAutoHideTab::onAutoHideToActionClicked()
{
int Location = sender()->property(LocationProperty).toInt();
std::cout << "CAutoHideTab::onAutoHideToActionClicked " << Location << std::endl;
d->DockWidget->setAutoHide(true, (SideBarLocation)Location);
}
}

View File

@ -65,12 +65,14 @@ private:
friend class CDockContainerWidget;
friend DockContainerWidgetPrivate;
private Q_SLOTS:
void onAutoHideToActionClicked();
protected:
void setSideBar(CAutoHideSideBar *SideTabBar);
void removeFromSideBar();
virtual bool event(QEvent* event) override;
virtual void contextMenuEvent(QContextMenuEvent* ev) override;
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
public:
using Super = CPushButton;

View File

@ -1156,12 +1156,12 @@ bool DockContainerWidgetPrivate::restoreSideBar(CDockingStateReader& s,
continue;
}
auto SideBar = _this->sideTabBar(Area);
auto SideBar = _this->autoHideSideBar(Area);
CAutoHideDockContainer* AutoHideContainer;
if (DockWidget->isAutoHide())
{
AutoHideContainer = DockWidget->autoHideDockContainer();
if (AutoHideContainer->sideBar() != SideBar)
if (AutoHideContainer->autoHideSideBar() != SideBar)
{
SideBar->addAutoHideWidget(AutoHideContainer);
}
@ -1472,7 +1472,7 @@ CAutoHideDockContainer* CDockContainerWidget::createAndSetupAutoHideContainer(
DockWidget->setDockManager(d->DockManager); // Auto hide Dock Container needs a valid dock manager
}
return sideTabBar(area)->insertDockWidget(-1, DockWidget);
return autoHideSideBar(area)->insertDockWidget(-1, DockWidget);
}
@ -1731,7 +1731,7 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
// them into this widget
for (auto AutohideWidget : FloatingWidget->dockContainer()->autoHideWidgets())
{
auto SideBar = sideTabBar(AutohideWidget->sideBarLocation());
auto SideBar = autoHideSideBar(AutohideWidget->sideBarLocation());
SideBar->addAutoHideWidget(AutohideWidget);
}
@ -2118,7 +2118,7 @@ void CDockContainerWidget::closeOtherAreas(CDockAreaWidget* KeepOpenArea)
}
//============================================================================
CAutoHideSideBar* CDockContainerWidget::sideTabBar(SideBarLocation area) const
CAutoHideSideBar* CDockContainerWidget::autoHideSideBar(SideBarLocation area) const
{
return d->SideTabBarWidgets[area];
}
@ -2140,10 +2140,10 @@ QRect CDockContainerWidget::contentRect() const
{
auto ContentRect = this->rect();
ContentRect.adjust(
sideTabBar(SideBarLeft)->sizeHint().width(),
sideTabBar(SideBarTop)->sizeHint().height(),
-sideTabBar(SideBarRight)->sizeHint().width(),
-sideTabBar(SideBarBottom)->sizeHint().height());
autoHideSideBar(SideBarLeft)->sizeHint().width(),
autoHideSideBar(SideBarTop)->sizeHint().height(),
-autoHideSideBar(SideBarRight)->sizeHint().width(),
-autoHideSideBar(SideBarBottom)->sizeHint().height());
return ContentRect;
}

View File

@ -329,7 +329,7 @@ public:
/**
* Returns the side tab widget for the given area
*/
CAutoHideSideBar* sideTabBar(SideBarLocation area) const;
CAutoHideSideBar* autoHideSideBar(SideBarLocation area) const;
/**

View File

@ -370,7 +370,7 @@ struct DockOverlayCrossPrivate
int DockOverlayPrivate::sideBarOverlaySize(SideBarLocation sideBarLocation)
{
auto Container = qobject_cast<CDockContainerWidget*>(TargetWidget.data());
auto SideBar = Container->sideTabBar(sideBarLocation);
auto SideBar = Container->autoHideSideBar(sideBarLocation);
if (!SideBar || !SideBar->isVisibleTo(Container))
{
return AutoHideAreaWidth;
@ -386,7 +386,7 @@ int DockOverlayPrivate::sideBarOverlaySize(SideBarLocation sideBarLocation)
int DockOverlayPrivate::sideBarMouseZone(SideBarLocation sideBarLocation)
{
auto Container = qobject_cast<CDockContainerWidget*>(TargetWidget.data());
auto SideBar = Container->sideTabBar(sideBarLocation);
auto SideBar = Container->autoHideSideBar(sideBarLocation);
if (!SideBar || !SideBar->isVisibleTo(Container))
{
return AutoHideAreaMouseZone;

View File

@ -555,6 +555,13 @@ bool CDockWidget::isAutoHide() const
}
//============================================================================
SideBarLocation CDockWidget::autoHideLocation() const
{
return isAutoHide() ? autoHideDockContainer()->sideBarLocation() : SideBarNone;
}
//============================================================================
bool CDockWidget::isFloating() const
{
@ -1206,7 +1213,7 @@ void CDockWidget::setAutoHide(bool Enable, SideBarLocation Location)
}
// Do nothing if nothing changes
if (Enable == isAutoHide())
if (Enable == isAutoHide() && Location == autoHideLocation())
{
return;
}
@ -1216,6 +1223,25 @@ void CDockWidget::setAutoHide(bool Enable, SideBarLocation Location)
{
DockArea->setAutoHide(false);
}
else if (isAutoHide())
{
auto AutoHideContainer = autoHideDockContainer();
auto OldOrientation = AutoHideContainer->orientation();
auto SideBar = dockContainer()->autoHideSideBar(Location);
SideBar->addAutoHideWidget(AutoHideContainer);
if (SideBar->orientation() != OldOrientation)
{
auto OriginalSize = AutoHideContainer->originalDockWidgetSize();
if (SideBar->orientation() == Qt::Horizontal)
{
AutoHideContainer->setSize(OriginalSize.height());
}
else
{
AutoHideContainer->setSize(OriginalSize.width());
}
}
}
else
{
auto area = (SideBarNone == Location) ? DockArea->calculateSideTabBarArea() : Location;

View File

@ -377,6 +377,12 @@ public:
*/
CAutoHideDockContainer* autoHideDockContainer() const;
/**
* Returns the auto hide side bar location or SideBarNone if, this is not
* an autohide dock widget
*/
SideBarLocation autoHideLocation() const;
/**
* This property holds whether the dock widget is floating.
* A dock widget is only floating, if it is the one and only widget inside