]> 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 55b5e5edfd03c703dbdc05647db7973d6afba5e2..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);
     }
 
@@ -131,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);
@@ -146,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;