diff --git a/src/DetachableTabBar.h b/src/DetachableTabBar.h --- a/src/DetachableTabBar.h +++ b/src/DetachableTabBar.h @@ -34,7 +34,10 @@ Q_SIGNALS: void detachTab(int index); void moveTabToWindow(int tabIndex, QWidget *otherWindow); + void closeTab(int index); + void newTabRequest(); protected: + void middleMouseButtonClickAt(const QPoint& pos); void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent*event) override; void mouseReleaseEvent(QMouseEvent *event) override; @@ -44,6 +47,7 @@ DragType dragType; QCursor _originalCursor; QList _containers; + int tabId; }; } diff --git a/src/DetachableTabBar.cpp b/src/DetachableTabBar.cpp --- a/src/DetachableTabBar.cpp +++ b/src/DetachableTabBar.cpp @@ -18,6 +18,7 @@ */ #include "DetachableTabBar.h" +#include "KonsoleSettings.h" #include "ViewContainer.h" #include @@ -28,7 +29,8 @@ DetachableTabBar::DetachableTabBar(QWidget *parent) : QTabBar(parent), dragType(DragType::NONE), - _originalCursor(cursor()) + _originalCursor(cursor()), + tabId(-1) {} bool DetachableTabBar::droppedContainerIsNotThis(const QPoint& currentPos) const @@ -43,6 +45,15 @@ return false; } +void DetachableTabBar::middleMouseButtonClickAt(const QPoint& pos) +{ + tabId = tabAt(pos); + + if (tabId != -1) { + emit closeTab(tabId); + } +} + void DetachableTabBar::mousePressEvent(QMouseEvent *event) { QTabBar::mousePressEvent(event); @@ -87,6 +98,21 @@ void DetachableTabBar::mouseReleaseEvent(QMouseEvent *event) { QTabBar::mouseReleaseEvent(event); + + switch(event->button()) { + case Qt::MiddleButton : if (KonsoleSettings::closeTabOnMiddleMouseButton()) { + middleMouseButtonClickAt(event->pos()); + } + + tabId = tabAt(event->pos()); + if (tabId == -1) { + emit newTabRequest(); + } + break; + case Qt::LeftButton: _containers = window()->findChildren(); break; + default: break; + } + setCursor(_originalCursor); if (contentsRect().adjusted(-30,-30,30,30).contains(event->pos())) { diff --git a/src/ViewContainer.cpp b/src/ViewContainer.cpp --- a/src/ViewContainer.cpp +++ b/src/ViewContainer.cpp @@ -89,6 +89,10 @@ connect(tabBarWidget, &DetachableTabBar::detachTab, this, [this](int idx) { emit detachTab(this, terminalAt(idx)); }); + connect(tabBarWidget, &DetachableTabBar::closeTab, + this, &TabbedViewContainer::closeTerminalTab); + connect(tabBarWidget, &DetachableTabBar::newTabRequest, + this, [this]{ emit newViewRequest(this); }); connect(this, &TabbedViewContainer::currentChanged, this, &TabbedViewContainer::currentTabChanged); // The context menu of tab bar diff --git a/src/settings/TabBarSettings.ui b/src/settings/TabBarSettings.ui --- a/src/settings/TabBarSettings.ui +++ b/src/settings/TabBarSettings.ui @@ -151,6 +151,13 @@ + + + + Close tab on middle-click + + + diff --git a/src/settings/konsole.kcfg b/src/settings/konsole.kcfg --- a/src/settings/konsole.kcfg +++ b/src/settings/konsole.kcfg @@ -91,6 +91,10 @@ + + + false + false