mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-04-01 02:42:39 +08:00
Implemented Pin To functionality for Auto Hide Tabs
This commit is contained in:
parent
1c6d86e70f
commit
4bdc04e9d8
@ -117,6 +117,7 @@ struct AutoHideDockContainerPrivate
|
|||||||
CResizeHandle* ResizeHandle = nullptr;
|
CResizeHandle* ResizeHandle = nullptr;
|
||||||
QSize Size; // creates invalid size
|
QSize Size; // creates invalid size
|
||||||
QPointer<CAutoHideTab> SideTab;
|
QPointer<CAutoHideTab> SideTab;
|
||||||
|
QSize OriginalDockWidgetSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private data constructor
|
* Private data constructor
|
||||||
@ -214,7 +215,9 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarL
|
|||||||
d->ResizeHandle->setMinResizeSize(64);
|
d->ResizeHandle->setMinResizeSize(64);
|
||||||
bool OpaqueResize = CDockManager::testConfigFlag(CDockManager::OpaqueSplitterResize);
|
bool OpaqueResize = CDockManager::testConfigFlag(CDockManager::OpaqueSplitterResize);
|
||||||
d->ResizeHandle->setOpaqueResize(OpaqueResize);
|
d->ResizeHandle->setOpaqueResize(OpaqueResize);
|
||||||
|
std::cout << "d->DockArea->size(); " << d->DockArea->size().width() << std::endl;
|
||||||
d->Size = d->DockArea->size();
|
d->Size = d->DockArea->size();
|
||||||
|
d->OriginalDockWidgetSize = DockWidget->size();
|
||||||
|
|
||||||
addDockWidget(DockWidget);
|
addDockWidget(DockWidget);
|
||||||
parent->registerAutoHideWidget(this);
|
parent->registerAutoHideWidget(this);
|
||||||
@ -303,7 +306,7 @@ CAutoHideDockContainer::~CAutoHideDockContainer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
CAutoHideSideBar* CAutoHideDockContainer::sideBar() const
|
CAutoHideSideBar* CAutoHideDockContainer::autoHideSideBar() const
|
||||||
{
|
{
|
||||||
if (d->SideTab)
|
if (d->SideTab)
|
||||||
{
|
{
|
||||||
@ -312,7 +315,7 @@ CAutoHideSideBar* CAutoHideDockContainer::sideBar() const
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto DockContainer = dockContainer();
|
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);
|
return Super::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
QSize CAutoHideDockContainer::originalDockWidgetSize() const
|
||||||
|
{
|
||||||
|
return d->OriginalDockWidgetSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
Qt::Orientation CAutoHideDockContainer::orientation() const
|
||||||
|
{
|
||||||
|
return autoHideSideBar()->orientation();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Get's the side tab bar
|
* Get's the side tab bar
|
||||||
*/
|
*/
|
||||||
CAutoHideSideBar* sideBar() const;
|
CAutoHideSideBar* autoHideSideBar() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the side tab
|
* Returns the side tab
|
||||||
@ -166,6 +166,21 @@ public:
|
|||||||
* of this auto hide container.
|
* of this auto hide container.
|
||||||
*/
|
*/
|
||||||
void setSize(int Size);
|
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
|
} // namespace ads
|
||||||
|
|
||||||
|
@ -42,6 +42,8 @@
|
|||||||
|
|
||||||
namespace ads
|
namespace ads
|
||||||
{
|
{
|
||||||
|
static const char* const LocationProperty = "Location";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private data class of CDockWidgetTab class (pimpl)
|
* Private data class of CDockWidgetTab class (pimpl)
|
||||||
*/
|
*/
|
||||||
@ -83,6 +85,20 @@ struct AutoHideTabPrivate
|
|||||||
DockContainer->handleAutoHideWidgetEvent(event, _this);
|
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
|
}; // struct DockWidgetTabPrivate
|
||||||
|
|
||||||
|
|
||||||
@ -299,10 +315,10 @@ void CAutoHideTab::contextMenuEvent(QContextMenuEvent* ev)
|
|||||||
|
|
||||||
auto menu = Menu.addMenu(tr("Pin To..."));
|
auto menu = Menu.addMenu(tr("Pin To..."));
|
||||||
menu->setEnabled(IsPinnable);
|
menu->setEnabled(IsPinnable);
|
||||||
//d->createAutoHideToAction(tr("Top"), SideBarTop, menu);
|
d->createAutoHideToAction(tr("Top"), SideBarTop, menu);
|
||||||
//d->createAutoHideToAction(tr("Left"), SideBarLeft, menu);
|
d->createAutoHideToAction(tr("Left"), SideBarLeft, menu);
|
||||||
//d->createAutoHideToAction(tr("Right"), SideBarRight, menu);
|
d->createAutoHideToAction(tr("Right"), SideBarRight, menu);
|
||||||
//d->createAutoHideToAction(tr("Bottom"), SideBarBottom, menu);
|
d->createAutoHideToAction(tr("Bottom"), SideBarBottom, menu);
|
||||||
|
|
||||||
/*Menu.addSeparator();
|
/*Menu.addSeparator();
|
||||||
Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested()));
|
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()
|
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();
|
dockWidget()->setFloating();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
void CAutoHideTab::onAutoHideToActionClicked()
|
||||||
|
{
|
||||||
|
int Location = sender()->property(LocationProperty).toInt();
|
||||||
|
std::cout << "CAutoHideTab::onAutoHideToActionClicked " << Location << std::endl;
|
||||||
|
d->DockWidget->setAutoHide(true, (SideBarLocation)Location);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -65,12 +65,14 @@ private:
|
|||||||
friend class CDockContainerWidget;
|
friend class CDockContainerWidget;
|
||||||
friend DockContainerWidgetPrivate;
|
friend DockContainerWidgetPrivate;
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onAutoHideToActionClicked();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setSideBar(CAutoHideSideBar *SideTabBar);
|
void setSideBar(CAutoHideSideBar *SideTabBar);
|
||||||
void removeFromSideBar();
|
void removeFromSideBar();
|
||||||
virtual bool event(QEvent* event) override;
|
virtual bool event(QEvent* event) override;
|
||||||
virtual void contextMenuEvent(QContextMenuEvent* ev) override;
|
virtual void contextMenuEvent(QContextMenuEvent* ev) override;
|
||||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using Super = CPushButton;
|
using Super = CPushButton;
|
||||||
|
@ -1156,12 +1156,12 @@ bool DockContainerWidgetPrivate::restoreSideBar(CDockingStateReader& s,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto SideBar = _this->sideTabBar(Area);
|
auto SideBar = _this->autoHideSideBar(Area);
|
||||||
CAutoHideDockContainer* AutoHideContainer;
|
CAutoHideDockContainer* AutoHideContainer;
|
||||||
if (DockWidget->isAutoHide())
|
if (DockWidget->isAutoHide())
|
||||||
{
|
{
|
||||||
AutoHideContainer = DockWidget->autoHideDockContainer();
|
AutoHideContainer = DockWidget->autoHideDockContainer();
|
||||||
if (AutoHideContainer->sideBar() != SideBar)
|
if (AutoHideContainer->autoHideSideBar() != SideBar)
|
||||||
{
|
{
|
||||||
SideBar->addAutoHideWidget(AutoHideContainer);
|
SideBar->addAutoHideWidget(AutoHideContainer);
|
||||||
}
|
}
|
||||||
@ -1472,7 +1472,7 @@ CAutoHideDockContainer* CDockContainerWidget::createAndSetupAutoHideContainer(
|
|||||||
DockWidget->setDockManager(d->DockManager); // Auto hide Dock Container needs a valid dock manager
|
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
|
// them into this widget
|
||||||
for (auto AutohideWidget : FloatingWidget->dockContainer()->autoHideWidgets())
|
for (auto AutohideWidget : FloatingWidget->dockContainer()->autoHideWidgets())
|
||||||
{
|
{
|
||||||
auto SideBar = sideTabBar(AutohideWidget->sideBarLocation());
|
auto SideBar = autoHideSideBar(AutohideWidget->sideBarLocation());
|
||||||
SideBar->addAutoHideWidget(AutohideWidget);
|
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];
|
return d->SideTabBarWidgets[area];
|
||||||
}
|
}
|
||||||
@ -2140,10 +2140,10 @@ QRect CDockContainerWidget::contentRect() const
|
|||||||
{
|
{
|
||||||
auto ContentRect = this->rect();
|
auto ContentRect = this->rect();
|
||||||
ContentRect.adjust(
|
ContentRect.adjust(
|
||||||
sideTabBar(SideBarLeft)->sizeHint().width(),
|
autoHideSideBar(SideBarLeft)->sizeHint().width(),
|
||||||
sideTabBar(SideBarTop)->sizeHint().height(),
|
autoHideSideBar(SideBarTop)->sizeHint().height(),
|
||||||
-sideTabBar(SideBarRight)->sizeHint().width(),
|
-autoHideSideBar(SideBarRight)->sizeHint().width(),
|
||||||
-sideTabBar(SideBarBottom)->sizeHint().height());
|
-autoHideSideBar(SideBarBottom)->sizeHint().height());
|
||||||
|
|
||||||
return ContentRect;
|
return ContentRect;
|
||||||
}
|
}
|
||||||
|
@ -329,7 +329,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Returns the side tab widget for the given area
|
* Returns the side tab widget for the given area
|
||||||
*/
|
*/
|
||||||
CAutoHideSideBar* sideTabBar(SideBarLocation area) const;
|
CAutoHideSideBar* autoHideSideBar(SideBarLocation area) const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -370,7 +370,7 @@ struct DockOverlayCrossPrivate
|
|||||||
int DockOverlayPrivate::sideBarOverlaySize(SideBarLocation sideBarLocation)
|
int DockOverlayPrivate::sideBarOverlaySize(SideBarLocation sideBarLocation)
|
||||||
{
|
{
|
||||||
auto Container = qobject_cast<CDockContainerWidget*>(TargetWidget.data());
|
auto Container = qobject_cast<CDockContainerWidget*>(TargetWidget.data());
|
||||||
auto SideBar = Container->sideTabBar(sideBarLocation);
|
auto SideBar = Container->autoHideSideBar(sideBarLocation);
|
||||||
if (!SideBar || !SideBar->isVisibleTo(Container))
|
if (!SideBar || !SideBar->isVisibleTo(Container))
|
||||||
{
|
{
|
||||||
return AutoHideAreaWidth;
|
return AutoHideAreaWidth;
|
||||||
@ -386,7 +386,7 @@ int DockOverlayPrivate::sideBarOverlaySize(SideBarLocation sideBarLocation)
|
|||||||
int DockOverlayPrivate::sideBarMouseZone(SideBarLocation sideBarLocation)
|
int DockOverlayPrivate::sideBarMouseZone(SideBarLocation sideBarLocation)
|
||||||
{
|
{
|
||||||
auto Container = qobject_cast<CDockContainerWidget*>(TargetWidget.data());
|
auto Container = qobject_cast<CDockContainerWidget*>(TargetWidget.data());
|
||||||
auto SideBar = Container->sideTabBar(sideBarLocation);
|
auto SideBar = Container->autoHideSideBar(sideBarLocation);
|
||||||
if (!SideBar || !SideBar->isVisibleTo(Container))
|
if (!SideBar || !SideBar->isVisibleTo(Container))
|
||||||
{
|
{
|
||||||
return AutoHideAreaMouseZone;
|
return AutoHideAreaMouseZone;
|
||||||
|
@ -555,6 +555,13 @@ bool CDockWidget::isAutoHide() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
SideBarLocation CDockWidget::autoHideLocation() const
|
||||||
|
{
|
||||||
|
return isAutoHide() ? autoHideDockContainer()->sideBarLocation() : SideBarNone;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
bool CDockWidget::isFloating() const
|
bool CDockWidget::isFloating() const
|
||||||
{
|
{
|
||||||
@ -1206,7 +1213,7 @@ void CDockWidget::setAutoHide(bool Enable, SideBarLocation Location)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do nothing if nothing changes
|
// Do nothing if nothing changes
|
||||||
if (Enable == isAutoHide())
|
if (Enable == isAutoHide() && Location == autoHideLocation())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1216,6 +1223,25 @@ void CDockWidget::setAutoHide(bool Enable, SideBarLocation Location)
|
|||||||
{
|
{
|
||||||
DockArea->setAutoHide(false);
|
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
|
else
|
||||||
{
|
{
|
||||||
auto area = (SideBarNone == Location) ? DockArea->calculateSideTabBarArea() : Location;
|
auto area = (SideBarNone == Location) ? DockArea->calculateSideTabBarArea() : Location;
|
||||||
|
@ -377,6 +377,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
CAutoHideDockContainer* autoHideDockContainer() const;
|
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.
|
* This property holds whether the dock widget is floating.
|
||||||
* A dock widget is only floating, if it is the one and only widget inside
|
* A dock widget is only floating, if it is the one and only widget inside
|
||||||
|
Loading…
Reference in New Issue
Block a user