mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-25 07:31:33 +08:00
Added context menu for dock area title bar to enable closing of area and other areas via context menu and to enable detaching of dock area via context menu
This commit is contained in:
parent
c9a97534a8
commit
e37e4fdf57
@ -233,11 +233,11 @@ void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
|
||||
|
||||
//============================================================================
|
||||
CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Pos)
|
||||
CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Offset)
|
||||
{
|
||||
QSize Size = d->DockArea->size();
|
||||
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(d->DockArea);
|
||||
FloatingWidget->startFloating(Pos, Size);
|
||||
FloatingWidget->startFloating(Offset, Size);
|
||||
auto TopLevelDockWidget = FloatingWidget->topLevelDockWidget();
|
||||
if (TopLevelDockWidget)
|
||||
{
|
||||
@ -249,9 +249,9 @@ CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Pos)
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTabBar::startFloating(const QPoint& Pos)
|
||||
void CDockAreaTabBar::startFloating(const QPoint& Offset)
|
||||
{
|
||||
d->FloatingWidget = makeAreaFloating(Pos);
|
||||
d->FloatingWidget = makeAreaFloating(Offset);
|
||||
}
|
||||
|
||||
|
||||
|
@ -84,12 +84,12 @@ protected:
|
||||
/**
|
||||
* Starts floating
|
||||
*/
|
||||
void startFloating(const QPoint& Pos);
|
||||
void startFloating(const QPoint& Offset);
|
||||
|
||||
/**
|
||||
* Makes the dock area loating
|
||||
* Makes the dock area floating
|
||||
*/
|
||||
CFloatingDockContainer* makeAreaFloating(const QPoint& Pos);
|
||||
CFloatingDockContainer* makeAreaFloating(const QPoint& Offset);
|
||||
|
||||
|
||||
public:
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "DockWidgetTab.h"
|
||||
#include "DockAreaTabBar.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
@ -173,6 +174,10 @@ void DockAreaTitleBarPrivate::createTabBar()
|
||||
_this->connect(TabBar, SIGNAL(tabMoved(int, int)), SLOT(markTabsMenuOutdated()));
|
||||
_this->connect(TabBar, SIGNAL(currentChanged(int)), SLOT(onCurrentTabChanged(int)));
|
||||
_this->connect(TabBar, SIGNAL(tabBarClicked(int)), SIGNAL(tabBarClicked(int)));
|
||||
|
||||
TabBar->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
_this->connect(TabBar, SIGNAL(customContextMenuRequested(const QPoint&)),
|
||||
SLOT(showContextMenu(const QPoint&)));
|
||||
}
|
||||
|
||||
|
||||
@ -310,6 +315,19 @@ void CDockAreaTitleBar::setVisible(bool Visible)
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::showContextMenu(const QPoint& pos)
|
||||
{
|
||||
QMenu Menu(this);
|
||||
Menu.addAction(tr("Detach Area"), this, SLOT(onUndockButtonClicked()));
|
||||
Menu.addSeparator();
|
||||
auto Action = Menu.addAction(tr("Close Area"), this, SLOT(onCloseButtonClicked()));
|
||||
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable));
|
||||
Menu.addAction(tr("Close Other Areas"), d->DockArea, SLOT(closeOtherAreas()));
|
||||
Menu.exec(mapToGlobal(pos));
|
||||
}
|
||||
|
||||
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -59,6 +59,7 @@ private slots:
|
||||
void onUndockButtonClicked();
|
||||
void onTabsMenuActionTriggered(QAction* Action);
|
||||
void onCurrentTabChanged(int Index);
|
||||
void showContextMenu(const QPoint& pos);
|
||||
|
||||
public:
|
||||
using Super = QFrame;
|
||||
|
@ -779,6 +779,13 @@ void CDockAreaWidget::closeArea()
|
||||
DockWidget->toggleView(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::closeOtherAreas()
|
||||
{
|
||||
dockContainer()->closeOtherAreas(this);
|
||||
}
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -259,6 +259,11 @@ public slots:
|
||||
*/
|
||||
void closeArea();
|
||||
|
||||
/**
|
||||
* This function closes all other areas except of this area
|
||||
*/
|
||||
void closeOtherAreas();
|
||||
|
||||
signals:
|
||||
/**
|
||||
* This signal is emitted when user clicks on a tab at an index.
|
||||
|
@ -1378,6 +1378,19 @@ CFloatingDockContainer* CDockContainerWidget::floatingWidget() const
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockContainerWidget::closeOtherAreas(CDockAreaWidget* KeepOpenArea)
|
||||
{
|
||||
for (const auto DockArea : d->DockAreas)
|
||||
{
|
||||
if (DockArea != KeepOpenArea && DockArea->features().testFlag(CDockWidget::DockWidgetClosable))
|
||||
{
|
||||
DockArea->closeArea();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace ads
|
||||
|
||||
#include "moc_DockContainerWidget.cpp"
|
||||
|
@ -233,6 +233,11 @@ public:
|
||||
*/
|
||||
CFloatingDockContainer* floatingWidget() const;
|
||||
|
||||
/**
|
||||
* Call this function to close all dock areas except the KeepOpenArea
|
||||
*/
|
||||
void closeOtherAreas(CDockAreaWidget* KeepOpenArea);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* This signal is emitted if one or multiple dock areas has been added to
|
||||
|
@ -759,6 +759,7 @@ void CDockManager::setConfigFlags(const ConfigFlags Flags)
|
||||
d->ConfigFlags = Flags;
|
||||
}
|
||||
|
||||
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -123,7 +123,7 @@ struct DockWidgetTabPrivate
|
||||
* Returns true, if floating has been started and false if floating
|
||||
* is not possible for any reason
|
||||
*/
|
||||
bool startFloating();
|
||||
bool startFloating(eDragState DraggingState = DraggingFloatingWidget);
|
||||
|
||||
/**
|
||||
* Returns true if the given config flag is set
|
||||
@ -197,7 +197,7 @@ void DockWidgetTabPrivate::moveTab(QMouseEvent* ev)
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool DockWidgetTabPrivate::startFloating()
|
||||
bool DockWidgetTabPrivate::startFloating(eDragState DraggingState)
|
||||
{
|
||||
auto dockContainer = DockWidget->dockContainer();
|
||||
qDebug() << "isFloating " << dockContainer->isFloating();
|
||||
@ -214,7 +214,7 @@ bool DockWidgetTabPrivate::startFloating()
|
||||
}
|
||||
|
||||
qDebug() << "startFloating";
|
||||
DragState = DraggingFloatingWidget;
|
||||
DragState = DraggingState;
|
||||
QSize Size = DockArea->size();
|
||||
CFloatingDockContainer* FloatingWidget = nullptr;
|
||||
if (DockArea->dockWidgetsCount() > 1)
|
||||
@ -230,10 +230,13 @@ bool DockWidgetTabPrivate::startFloating()
|
||||
}
|
||||
|
||||
FloatingWidget->startFloating(DragStartMousePosition, Size);
|
||||
auto Overlay = DockWidget->dockManager()->containerOverlay();
|
||||
Overlay->setAllowedAreas(OuterDockAreas);
|
||||
this->FloatingWidget = FloatingWidget;
|
||||
DockWidget->emitTopLevelChanged(true);
|
||||
if (DraggingFloatingWidget == DraggingState)
|
||||
{
|
||||
auto Overlay = DockWidget->dockManager()->containerOverlay();
|
||||
Overlay->setAllowedAreas(OuterDockAreas);
|
||||
this->FloatingWidget = FloatingWidget;
|
||||
}
|
||||
DockWidget->emitTopLevelChanged(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -471,7 +474,7 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
if (!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
|
||||
{
|
||||
d->DragStartMousePosition = event->pos();
|
||||
d->startFloating();
|
||||
d->startFloating(DraggingInactive);
|
||||
}
|
||||
|
||||
Super::mouseDoubleClickEvent(event);
|
||||
@ -497,7 +500,7 @@ bool CDockWidgetTab::isClosable() const
|
||||
void CDockWidgetTab::onDetachActionTriggered()
|
||||
{
|
||||
d->DragStartMousePosition = mapFromGlobal(QCursor::pos());
|
||||
d->startFloating();
|
||||
d->startFloating(DraggingInactive);
|
||||
}
|
||||
|
||||
} // namespace ads
|
||||
|
@ -435,14 +435,14 @@ bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event)
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CFloatingDockContainer::startFloating(const QPoint& Pos, const QSize& Size)
|
||||
void CFloatingDockContainer::startFloating(const QPoint& DragStartMousePos, const QSize& Size)
|
||||
{
|
||||
resize(Size);
|
||||
d->setState(StateDraggingActive);
|
||||
QPoint TargetPos = QCursor::pos() - Pos;
|
||||
move(TargetPos);
|
||||
d->DragStartMousePosition = DragStartMousePos;
|
||||
moveFloating();
|
||||
show();
|
||||
d->DragStartMousePosition = Pos;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -81,7 +81,7 @@ protected:
|
||||
* Use moveToGlobalPos() to move the widget to a new position
|
||||
* depending on the start position given in Pos parameter
|
||||
*/
|
||||
void startFloating(const QPoint& Pos, const QSize& Size = QSize());
|
||||
void startFloating(const QPoint& DragStartMousePos, const QSize& Size = QSize());
|
||||
|
||||
/**
|
||||
* Moves the widget to a new position relative to the position given when
|
||||
|
Loading…
Reference in New Issue
Block a user