mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-04-01 02:42:39 +08:00
Add feature to close tabs with the middle mouse button. (#360)
Co-authored-by: Rodrigo Oliva <Rodrigo.Oliva@king.com>
This commit is contained in:
parent
dbca6d79cf
commit
87b0596ebc
@ -630,6 +630,9 @@ CMainWindow::CMainWindow(QWidget *parent) :
|
|||||||
// uncomment if you would like to enable an equal distribution of the
|
// uncomment if you would like to enable an equal distribution of the
|
||||||
// available size of a splitter to all contained dock widgets
|
// available size of a splitter to all contained dock widgets
|
||||||
// CDockManager::setConfigFlag(CDockManager::EqualSplitOnInsertion, true);
|
// CDockManager::setConfigFlag(CDockManager::EqualSplitOnInsertion, true);
|
||||||
|
|
||||||
|
// uncomment if you would like to close tabs with the middle mouse button, web browser style
|
||||||
|
// CDockManager::setConfigFlag(CDockManager::MiddleMouseButtonClosesTab, true);
|
||||||
|
|
||||||
// Now create the dock manager and its content
|
// Now create the dock manager and its content
|
||||||
d->DockManager = new CDockManager(this);
|
d->DockManager = new CDockManager(this);
|
||||||
|
@ -195,6 +195,7 @@ public:
|
|||||||
FloatingContainerForceQWidgetTitleBar = 0x1000000,//!< Linux only ! Forces all FloatingContainer to use a QWidget based title bar.
|
FloatingContainerForceQWidgetTitleBar = 0x1000000,//!< Linux only ! Forces all FloatingContainer to use a QWidget based title bar.
|
||||||
//!< If neither this nor FloatingContainerForceNativeTitleBar is set (the default) native titlebars are used except on known bad systems.
|
//!< If neither this nor FloatingContainerForceNativeTitleBar is set (the default) native titlebars are used except on known bad systems.
|
||||||
//! Users can overwrite this by setting the environment variable ADS_UseNativeTitle to "1" or "0".
|
//! Users can overwrite this by setting the environment variable ADS_UseNativeTitle to "1" or "0".
|
||||||
|
MiddleMouseButtonClosesTab = 0x2000000, //! If the flag is set, the user can use the mouse middle button to close the tab under the mouse
|
||||||
|
|
||||||
DefaultDockAreaButtons = DockAreaHasCloseButton
|
DefaultDockAreaButtons = DockAreaHasCloseButton
|
||||||
| DockAreaHasUndockButton
|
| DockAreaHasUndockButton
|
||||||
|
@ -392,16 +392,30 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev)
|
|||||||
// End of tab moving, emit signal
|
// End of tab moving, emit signal
|
||||||
if (d->DockArea)
|
if (d->DockArea)
|
||||||
{
|
{
|
||||||
|
ev->accept();
|
||||||
Q_EMIT moved(internal::globalPositionOf(ev));
|
Q_EMIT moved(internal::globalPositionOf(ev));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DraggingFloatingWidget:
|
case DraggingFloatingWidget:
|
||||||
|
ev->accept();
|
||||||
d->FloatingWidget->finishDragging();
|
d->FloatingWidget->finishDragging();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:; // do nothing
|
default:; // do nothing
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (ev->button() == Qt::MiddleButton)
|
||||||
|
{
|
||||||
|
if (CDockManager::testConfigFlag(CDockManager::MiddleMouseButtonClosesTab))
|
||||||
|
{
|
||||||
|
// Only attempt to close if the mouse is still
|
||||||
|
// on top of the widget, to allow the user to cancel.
|
||||||
|
if (rect().contains(mapFromGlobal(QCursor::pos()))) {
|
||||||
|
ev->accept();
|
||||||
|
Q_EMIT closeRequested();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Super::mouseReleaseEvent(ev);
|
Super::mouseReleaseEvent(ev);
|
||||||
@ -628,14 +642,18 @@ QString CDockWidgetTab::text() const
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
|
void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
// If this is the last dock area in a dock container it does not make
|
if (event->button() == Qt::LeftButton)
|
||||||
// sense to move it to a new floating widget and leave this one
|
|
||||||
// empty
|
|
||||||
if ((!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
|
|
||||||
&& d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
|
|
||||||
{
|
{
|
||||||
d->saveDragStartMousePosition(internal::globalPositionOf(event));
|
// If this is the last dock area in a dock container it does not make
|
||||||
d->startFloating(DraggingInactive);
|
// sense to move it to a new floating widget and leave this one
|
||||||
|
// empty
|
||||||
|
if ((!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
|
||||||
|
&& d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
|
||||||
|
{
|
||||||
|
event->accept();
|
||||||
|
d->saveDragStartMousePosition(internal::globalPositionOf(event));
|
||||||
|
d->startFloating(DraggingInactive);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Super::mouseDoubleClickEvent(event);
|
Super::mouseDoubleClickEvent(event);
|
||||||
|
Loading…
Reference in New Issue
Block a user