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:
Rodrigo Oliva 2021-10-11 20:33:56 +02:00 committed by GitHub
parent dbca6d79cf
commit 87b0596ebc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 7 deletions

View File

@ -630,6 +630,9 @@ CMainWindow::CMainWindow(QWidget *parent) :
// uncomment if you would like to enable an equal distribution of the
// available size of a splitter to all contained dock widgets
// 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
d->DockManager = new CDockManager(this);

View File

@ -195,6 +195,7 @@ public:
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.
//! 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
| DockAreaHasUndockButton

View File

@ -392,16 +392,30 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev)
// End of tab moving, emit signal
if (d->DockArea)
{
ev->accept();
Q_EMIT moved(internal::globalPositionOf(ev));
}
break;
case DraggingFloatingWidget:
ev->accept();
d->FloatingWidget->finishDragging();
break;
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);
@ -628,14 +642,18 @@ QString CDockWidgetTab::text() const
//============================================================================
void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
{
// If this is the last dock area in a dock container it does not make
// 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))
if (event->button() == Qt::LeftButton)
{
d->saveDragStartMousePosition(internal::globalPositionOf(event));
d->startFloating(DraggingInactive);
// If this is the last dock area in a dock container it does not make
// 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);