X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/1b4572dac9fb529d31b786f93e4f02c6f8aeeb21..a2052105089309b87b3b94eba820c76d02d5a187:/src/dolphintabbar.cpp diff --git a/src/dolphintabbar.cpp b/src/dolphintabbar.cpp index dbd324db5..fc52afff6 100644 --- a/src/dolphintabbar.cpp +++ b/src/dolphintabbar.cpp @@ -19,17 +19,17 @@ #include "dolphintabbar.h" -#include -#include #include + +#include #include -#include -#include #include +#include DolphinTabBar::DolphinTabBar(QWidget* parent) : QTabBar(parent), - m_autoActivationIndex(-1) + m_autoActivationIndex(-1), + m_tabToBeClosedOnMiddleMouseButtonRelease(-1) { setAcceptDrops(true); setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab); @@ -39,8 +39,8 @@ DolphinTabBar::DolphinTabBar(QWidget* parent) : m_autoActivationTimer = new QTimer(this); m_autoActivationTimer->setSingleShot(true); m_autoActivationTimer->setInterval(800); - connect(m_autoActivationTimer, SIGNAL(timeout()), - this, SLOT(slotAutoActivationTimeout())); + connect(m_autoActivationTimer, &QTimer::timeout, + this, &DolphinTabBar::slotAutoActivationTimeout); } void DolphinTabBar::dragEnterEvent(QDragEnterEvent* event) @@ -95,12 +95,25 @@ void DolphinTabBar::mousePressEvent(QMouseEvent* event) const int index = tabAt(event->pos()); if (index >= 0 && event->button() == Qt::MiddleButton) { + m_tabToBeClosedOnMiddleMouseButtonRelease = index; + return; + } + + QTabBar::mousePressEvent(event); +} + +void DolphinTabBar::mouseReleaseEvent(QMouseEvent *event) +{ + const int index = tabAt(event->pos()); + + if (index >= 0 && index == m_tabToBeClosedOnMiddleMouseButtonRelease + && event->button() == Qt::MiddleButton) { // Mouse middle click on a tab closes this tab. emit tabCloseRequested(index); return; } - QTabBar::mousePressEvent(event); + QTabBar::mouseReleaseEvent(event); } void DolphinTabBar::mouseDoubleClickEvent(QMouseEvent* event) @@ -125,10 +138,10 @@ void DolphinTabBar::contextMenuEvent(QContextMenuEvent* event) // Tab context menu QMenu menu(this); - QAction* newTabAction = menu.addAction(QIcon::fromTheme("tab-new"), i18nc("@action:inmenu", "New Tab")); - QAction* detachTabAction = menu.addAction(QIcon::fromTheme("tab-detach"), i18nc("@action:inmenu", "Detach Tab")); - QAction* closeOtherTabsAction = menu.addAction(QIcon::fromTheme("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs")); - QAction* closeTabAction = menu.addAction(QIcon::fromTheme("tab-close"), i18nc("@action:inmenu", "Close Tab")); + QAction* newTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-new")), i18nc("@action:inmenu", "New Tab")); + QAction* detachTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-detach")), i18nc("@action:inmenu", "Detach Tab")); + QAction* closeOtherTabsAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-close-other")), i18nc("@action:inmenu", "Close Other Tabs")); + QAction* closeTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-close")), i18nc("@action:inmenu", "Close Tab")); QAction* selectedAction = menu.exec(event->globalPos()); if (selectedAction == newTabAction) {