X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/f510339f033658eae27f8400bf042b78b36f82f2..aeb704851d3b33f88eb601d597c2b0743d4e08df:/src/dolphintabbar.cpp diff --git a/src/dolphintabbar.cpp b/src/dolphintabbar.cpp index c70089223..f6af9932d 100644 --- a/src/dolphintabbar.cpp +++ b/src/dolphintabbar.cpp @@ -13,6 +13,28 @@ #include #include +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(obj)->setFocusPolicy(Qt::NoFocus); + return false; + case QEvent::Show: + static_cast(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,15 +129,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); }