]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphintabbar.cpp
Merge remote-tracking branch 'upstream/master' into work/zakharafoniam/useful-groups
[dolphin.git] / src / dolphintabbar.cpp
index aa74e17ae6dea5949d4ce0d5edf678301e3cbd2d..f6af9932da2f4df3a15da0884a84a3484748a3e2 100644 (file)
 #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 +45,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 +80,7 @@ void DolphinTabBar::dragMoveEvent(QDragMoveEvent *event)
     const int index = tabAt(event->position().toPoint());
 
     if (mimeData->hasUrls()) {
+        Q_EMIT tabDragMoveEvent(index, event);
         updateAutoActivationTimer(index);
     }
 
@@ -103,13 +129,16 @@ void DolphinTabBar::mouseReleaseEvent(QMouseEvent *event)
 
 void DolphinTabBar::mouseDoubleClickEvent(QMouseEvent *event)
 {
-    const int index = tabAt(event->pos());
+    if (event->buttons() & Qt::LeftButton) {
+        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.
-        Q_EMIT openNewActivatedTab(currentIndex());
-        return;
+        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);
     }
 
     QTabBar::mouseDoubleClickEvent(event);
@@ -171,3 +200,5 @@ void DolphinTabBar::updateAutoActivationTimer(const int index)
         }
     }
 }
+
+#include "moc_dolphintabbar.cpp"