]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphintabbar.cpp
Port to Qt6
[dolphin.git] / src / dolphintabbar.cpp
index 78bd5edcb98f376628edd1a4a34ade2eb6c5aa71..aa74e17ae6dea5949d4ce0d5edf678301e3cbd2d 100644 (file)
@@ -1,34 +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 <KMenu>
-#include <KIcon>
-#include <KUrl>
 
-DolphinTabBar::DolphinTabBar(QWidget* parent) :
-    QTabBar(parent),
-    m_autoActivationIndex(-1)
+#include <QDragEnterEvent>
+#include <QMenu>
+#include <QMimeData>
+#include <QTimer>
+
+DolphinTabBar::DolphinTabBar(QWidget *parent)
+    : QTabBar(parent)
+    , m_autoActivationIndex(-1)
+    , m_tabToBeClosedOnMiddleMouseButtonRelease(-1)
 {
     setAcceptDrops(true);
     setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab);
@@ -38,16 +26,15 @@ 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(QDragEnterEventevent)
+void DolphinTabBar::dragEnterEvent(QDragEnterEvent *event)
 {
-    const QMimeDatamimeData = event->mimeData();
-    const int index = tabAt(event->pos());
+    const QMimeData *mimeData = event->mimeData();
+    const int index = tabAt(event->position().toPoint());
 
-    if (KUrl::List::canDecode(mimeData)) {
+    if (mimeData->hasUrls()) {
         event->acceptProposedAction();
         updateAutoActivationTimer(index);
     }
@@ -55,95 +42,107 @@ void DolphinTabBar::dragEnterEvent(QDragEnterEvent* event)
     QTabBar::dragEnterEvent(event);
 }
 
-void DolphinTabBar::dragLeaveEvent(QDragLeaveEventevent)
+void DolphinTabBar::dragLeaveEvent(QDragLeaveEvent *event)
 {
     updateAutoActivationTimer(-1);
 
     QTabBar::dragLeaveEvent(event);
 }
 
-void DolphinTabBar::dragMoveEvent(QDragMoveEventevent)
+void DolphinTabBar::dragMoveEvent(QDragMoveEvent *event)
 {
-    const QMimeDatamimeData = event->mimeData();
-    const int index = tabAt(event->pos());
+    const QMimeData *mimeData = event->mimeData();
+    const int index = tabAt(event->position().toPoint());
 
-    if (KUrl::List::canDecode(mimeData)) {
+    if (mimeData->hasUrls()) {
         updateAutoActivationTimer(index);
     }
 
     QTabBar::dragMoveEvent(event);
 }
 
-void DolphinTabBar::dropEvent(QDropEventevent)
+void DolphinTabBar::dropEvent(QDropEvent *event)
 {
     // Disable the auto activation timer
     updateAutoActivationTimer(-1);
 
-    const QMimeDatamimeData = event->mimeData();
-    const int index = tabAt(event->pos());
+    const QMimeData *mimeData = event->mimeData();
+    const int index = tabAt(event->position().toPoint());
 
-    if (index >= 0 && KUrl::List::canDecode(mimeData)) {
-        emit tabDropEvent(index, event);
+    if (mimeData->hasUrls()) {
+        Q_EMIT tabDropEvent(index, event);
     }
 
     QTabBar::dropEvent(event);
 }
 
-void DolphinTabBar::mousePressEvent(QMouseEventevent)
+void DolphinTabBar::mousePressEvent(QMouseEvent *event)
 {
     const int index = tabAt(event->pos());
 
     if (index >= 0 && event->button() == Qt::MiddleButton) {
-        // Mouse middle click on a tab closes this tab.
-        emit tabCloseRequested(index);
+        m_tabToBeClosedOnMiddleMouseButtonRelease = index;
         return;
     }
 
     QTabBar::mousePressEvent(event);
 }
 
-void DolphinTabBar::mouseDoubleClickEvent(QMouseEvent* 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.
+        Q_EMIT tabCloseRequested(index);
+        return;
+    }
+
+    QTabBar::mouseReleaseEvent(event);
+}
+
+void DolphinTabBar::mouseDoubleClickEvent(QMouseEvent *event)
 {
     const int index = tabAt(event->pos());
 
     if (index < 0) {
         // Double click on the empty tabbar area opens a new activated tab
         // with the url from the current tab.
-        emit openNewActivatedTab(currentIndex());
+        Q_EMIT openNewActivatedTab(currentIndex());
         return;
     }
 
     QTabBar::mouseDoubleClickEvent(event);
 }
 
-void DolphinTabBar::contextMenuEvent(QContextMenuEventevent)
+void DolphinTabBar::contextMenuEvent(QContextMenuEvent *event)
 {
     const int index = tabAt(event->pos());
 
     if (index >= 0) {
         // Tab context menu
-        KMenu menu(this);
+        QMenu menu(this);
 
-        QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
-        QAction* detachTabAction = menu.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
-        QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
-        QAction* closeTabAction = menu.addAction(KIcon("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"));
 
-        QActionselectedAction = menu.exec(event->globalPos());
+        QAction *selectedAction = menu.exec(event->globalPos());
         if (selectedAction == newTabAction) {
-            emit openNewActivatedTab(index);
+            Q_EMIT openNewActivatedTab(index);
         } else if (selectedAction == detachTabAction) {
-            emit tabDetachRequested(index);
+            Q_EMIT tabDetachRequested(index);
         } else if (selectedAction == closeOtherTabsAction) {
             const int tabCount = count();
             for (int i = 0; i < index; i++) {
-                emit tabCloseRequested(0);
+                Q_EMIT tabCloseRequested(0);
             }
             for (int i = index + 1; i < tabCount; i++) {
-                emit tabCloseRequested(1);
+                Q_EMIT tabCloseRequested(1);
             }
         } else if (selectedAction == closeTabAction) {
-            emit tabCloseRequested(index);
+            Q_EMIT tabCloseRequested(index);
         }
 
         return;