]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphintabbar.cpp
Fix mouse back/forward buttons
[dolphin.git] / src / dolphintabbar.cpp
index e909c36aee923eeaba182d3184eb1eb97fe2fb8c..8598650223e9a0bf6941ae7d8d6aca858cc93f44 100644 (file)
@@ -1,35 +1,22 @@
-/***************************************************************************
- * Copyright (C) 2014 by Emmanuel Pescosta <emmanuelpescosta099@gmail.com> *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2014 Emmanuel Pescosta <emmanuelpescosta099@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #include "dolphintabbar.h"
 
-#include <QTimer>
-#include <QDragEnterEvent>
 #include <KLocalizedString>
+
+#include <QDragEnterEvent>
 #include <QMenu>
-#include <QIcon>
-#include <QUrl>
 #include <QMimeData>
+#include <QTimer>
 
 DolphinTabBar::DolphinTabBar(QWidget* parent) :
     QTabBar(parent),
-    m_autoActivationIndex(-1)
+    m_autoActivationIndex(-1),
+    m_tabToBeClosedOnMiddleMouseButtonRelease(-1)
 {
     setAcceptDrops(true);
     setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab);
@@ -95,12 +82,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)