mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-26 08:01:32 +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();
|
QSize Size = d->DockArea->size();
|
||||||
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(d->DockArea);
|
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(d->DockArea);
|
||||||
FloatingWidget->startFloating(Pos, Size);
|
FloatingWidget->startFloating(Offset, Size);
|
||||||
auto TopLevelDockWidget = FloatingWidget->topLevelDockWidget();
|
auto TopLevelDockWidget = FloatingWidget->topLevelDockWidget();
|
||||||
if (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
|
* 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:
|
public:
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#include "DockWidgetTab.h"
|
#include "DockWidgetTab.h"
|
||||||
#include "DockAreaTabBar.h"
|
#include "DockAreaTabBar.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace ads
|
namespace ads
|
||||||
{
|
{
|
||||||
@ -173,6 +174,10 @@ void DockAreaTitleBarPrivate::createTabBar()
|
|||||||
_this->connect(TabBar, SIGNAL(tabMoved(int, int)), SLOT(markTabsMenuOutdated()));
|
_this->connect(TabBar, SIGNAL(tabMoved(int, int)), SLOT(markTabsMenuOutdated()));
|
||||||
_this->connect(TabBar, SIGNAL(currentChanged(int)), SLOT(onCurrentTabChanged(int)));
|
_this->connect(TabBar, SIGNAL(currentChanged(int)), SLOT(onCurrentTabChanged(int)));
|
||||||
_this->connect(TabBar, SIGNAL(tabBarClicked(int)), SIGNAL(tabBarClicked(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
|
} // namespace ads
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -59,6 +59,7 @@ private slots:
|
|||||||
void onUndockButtonClicked();
|
void onUndockButtonClicked();
|
||||||
void onTabsMenuActionTriggered(QAction* Action);
|
void onTabsMenuActionTriggered(QAction* Action);
|
||||||
void onCurrentTabChanged(int Index);
|
void onCurrentTabChanged(int Index);
|
||||||
|
void showContextMenu(const QPoint& pos);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using Super = QFrame;
|
using Super = QFrame;
|
||||||
|
@ -779,6 +779,13 @@ void CDockAreaWidget::closeArea()
|
|||||||
DockWidget->toggleView(false);
|
DockWidget->toggleView(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void CDockAreaWidget::closeOtherAreas()
|
||||||
|
{
|
||||||
|
dockContainer()->closeOtherAreas(this);
|
||||||
|
}
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -259,6 +259,11 @@ public slots:
|
|||||||
*/
|
*/
|
||||||
void closeArea();
|
void closeArea();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function closes all other areas except of this area
|
||||||
|
*/
|
||||||
|
void closeOtherAreas();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
* This signal is emitted when user clicks on a tab at an index.
|
* 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
|
} // namespace ads
|
||||||
|
|
||||||
#include "moc_DockContainerWidget.cpp"
|
#include "moc_DockContainerWidget.cpp"
|
||||||
|
@ -233,6 +233,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
CFloatingDockContainer* floatingWidget() const;
|
CFloatingDockContainer* floatingWidget() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call this function to close all dock areas except the KeepOpenArea
|
||||||
|
*/
|
||||||
|
void closeOtherAreas(CDockAreaWidget* KeepOpenArea);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
* This signal is emitted if one or multiple dock areas has been added to
|
* 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;
|
d->ConfigFlags = Flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -123,7 +123,7 @@ struct DockWidgetTabPrivate
|
|||||||
* Returns true, if floating has been started and false if floating
|
* Returns true, if floating has been started and false if floating
|
||||||
* is not possible for any reason
|
* is not possible for any reason
|
||||||
*/
|
*/
|
||||||
bool startFloating();
|
bool startFloating(eDragState DraggingState = DraggingFloatingWidget);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the given config flag is set
|
* 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();
|
auto dockContainer = DockWidget->dockContainer();
|
||||||
qDebug() << "isFloating " << dockContainer->isFloating();
|
qDebug() << "isFloating " << dockContainer->isFloating();
|
||||||
@ -214,7 +214,7 @@ bool DockWidgetTabPrivate::startFloating()
|
|||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "startFloating";
|
qDebug() << "startFloating";
|
||||||
DragState = DraggingFloatingWidget;
|
DragState = DraggingState;
|
||||||
QSize Size = DockArea->size();
|
QSize Size = DockArea->size();
|
||||||
CFloatingDockContainer* FloatingWidget = nullptr;
|
CFloatingDockContainer* FloatingWidget = nullptr;
|
||||||
if (DockArea->dockWidgetsCount() > 1)
|
if (DockArea->dockWidgetsCount() > 1)
|
||||||
@ -230,9 +230,12 @@ bool DockWidgetTabPrivate::startFloating()
|
|||||||
}
|
}
|
||||||
|
|
||||||
FloatingWidget->startFloating(DragStartMousePosition, Size);
|
FloatingWidget->startFloating(DragStartMousePosition, Size);
|
||||||
|
if (DraggingFloatingWidget == DraggingState)
|
||||||
|
{
|
||||||
auto Overlay = DockWidget->dockManager()->containerOverlay();
|
auto Overlay = DockWidget->dockManager()->containerOverlay();
|
||||||
Overlay->setAllowedAreas(OuterDockAreas);
|
Overlay->setAllowedAreas(OuterDockAreas);
|
||||||
this->FloatingWidget = FloatingWidget;
|
this->FloatingWidget = FloatingWidget;
|
||||||
|
}
|
||||||
DockWidget->emitTopLevelChanged(true);
|
DockWidget->emitTopLevelChanged(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -471,7 +474,7 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
|
|||||||
if (!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
|
if (!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
|
||||||
{
|
{
|
||||||
d->DragStartMousePosition = event->pos();
|
d->DragStartMousePosition = event->pos();
|
||||||
d->startFloating();
|
d->startFloating(DraggingInactive);
|
||||||
}
|
}
|
||||||
|
|
||||||
Super::mouseDoubleClickEvent(event);
|
Super::mouseDoubleClickEvent(event);
|
||||||
@ -497,7 +500,7 @@ bool CDockWidgetTab::isClosable() const
|
|||||||
void CDockWidgetTab::onDetachActionTriggered()
|
void CDockWidgetTab::onDetachActionTriggered()
|
||||||
{
|
{
|
||||||
d->DragStartMousePosition = mapFromGlobal(QCursor::pos());
|
d->DragStartMousePosition = mapFromGlobal(QCursor::pos());
|
||||||
d->startFloating();
|
d->startFloating(DraggingInactive);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ads
|
} // 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);
|
resize(Size);
|
||||||
d->setState(StateDraggingActive);
|
d->setState(StateDraggingActive);
|
||||||
QPoint TargetPos = QCursor::pos() - Pos;
|
d->DragStartMousePosition = DragStartMousePos;
|
||||||
move(TargetPos);
|
moveFloating();
|
||||||
show();
|
show();
|
||||||
d->DragStartMousePosition = Pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ protected:
|
|||||||
* Use moveToGlobalPos() to move the widget to a new position
|
* Use moveToGlobalPos() to move the widget to a new position
|
||||||
* depending on the start position given in Pos parameter
|
* 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
|
* Moves the widget to a new position relative to the position given when
|
||||||
|
Loading…
Reference in New Issue
Block a user