]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphintabbar.cpp
Check if the item supports sequencing before looking for sequence pixmaps
[dolphin.git] / src / dolphintabbar.cpp
index ac9f1f734a097d75552d403f7e50bd87db3b31aa..4df25263f3f52deb07a5555e60feba2453336a2b 100644 (file)
@@ -9,10 +9,33 @@
 #include <KLocalizedString>
 
 #include <QDragEnterEvent>
+#include <QInputDialog>
 #include <QMenu>
 #include <QMimeData>
 #include <QTimer>
 
+class PreventFocusWhileHidden : public QObject
+{
+public:
+    PreventFocusWhileHidden(QObject *parent)
+        : QObject(parent){};
+
+protected:
+    bool eventFilter(QObject *obj, QEvent *ev) override
+    {
+        switch (ev->type()) {
+        case QEvent::Hide:
+            static_cast<QWidget *>(obj)->setFocusPolicy(Qt::NoFocus);
+            return false;
+        case QEvent::Show:
+            static_cast<QWidget *>(obj)->setFocusPolicy(Qt::TabFocus);
+            return false;
+        default:
+            return false;
+        }
+    };
+};
+
 DolphinTabBar::DolphinTabBar(QWidget *parent)
     : QTabBar(parent)
     , m_autoActivationIndex(-1)
@@ -23,6 +46,9 @@ DolphinTabBar::DolphinTabBar(QWidget *parent)
     setMovable(true);
     setTabsClosable(true);
 
+    setFocusPolicy(Qt::NoFocus);
+    installEventFilter(new PreventFocusWhileHidden(this));
+
     m_autoActivationTimer = new QTimer(this);
     m_autoActivationTimer->setSingleShot(true);
     m_autoActivationTimer->setInterval(800);
@@ -55,6 +81,7 @@ void DolphinTabBar::dragMoveEvent(QDragMoveEvent *event)
     const int index = tabAt(event->position().toPoint());
 
     if (mimeData->hasUrls()) {
+        Q_EMIT tabDragMoveEvent(index, event);
         updateAutoActivationTimer(index);
     }
 
@@ -103,15 +130,17 @@ void DolphinTabBar::mouseReleaseEvent(QMouseEvent *event)
 
 void DolphinTabBar::mouseDoubleClickEvent(QMouseEvent *event)
 {
-    int index = tabAt(event->pos());
+    if (event->buttons() & Qt::LeftButton) {
+        int index = tabAt(event->pos());
 
-    if (index < 0) {
-        // empty tabbar area case
-        index = currentIndex();
+        if (index < 0) {
+            // empty tabbar area case
+            index = currentIndex();
+        }
+        // Double left click on the tabbar opens a new activated tab
+        // with the url from the doubleclicked tab or currentTab otherwise.
+        Q_EMIT openNewActivatedTab(index);
     }
-    // Double click on the tabbar opens a new activated tab
-    // with the url from the doubleclicked tab or currentTab otherwise.
-    Q_EMIT openNewActivatedTab(index);
 
     QTabBar::mouseDoubleClickEvent(event);
 }
@@ -129,6 +158,8 @@ void DolphinTabBar::contextMenuEvent(QContextMenuEvent *event)
         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 *renameTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-rename")), i18nc("@action:inmenu", "Rename Tab"));
+
         QAction *selectedAction = menu.exec(event->globalPos());
         if (selectedAction == newTabAction) {
             Q_EMIT openNewActivatedTab(index);
@@ -144,6 +175,13 @@ void DolphinTabBar::contextMenuEvent(QContextMenuEvent *event)
             }
         } else if (selectedAction == closeTabAction) {
             Q_EMIT tabCloseRequested(index);
+        } else if (selectedAction == renameTabAction) {
+            bool renamed = false;
+            const QString tabNewName = QInputDialog::getText(this, i18nc("@title:window for text input", "Rename Tab"), i18n("New tab name:"), QLineEdit::Normal, tabText(index), &renamed);
+
+            if (renamed) {
+                Q_EMIT tabRenamed(index, tabNewName);
+            }
         }
 
         return;
@@ -172,3 +210,5 @@ void DolphinTabBar::updateAutoActivationTimer(const int index)
         }
     }
 }
+
+#include "moc_dolphintabbar.cpp"