X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/ed2d352c42a6d517d4f29b3582c0e00aa34fe647..67c045c768f961cfe072d31555463817cdfbae93:/src/dolphintabbar.cpp diff --git a/src/dolphintabbar.cpp b/src/dolphintabbar.cpp index a7799a669..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); @@ -32,7 +57,7 @@ DolphinTabBar::DolphinTabBar(QWidget *parent) void DolphinTabBar::dragEnterEvent(QDragEnterEvent *event) { const QMimeData *mimeData = event->mimeData(); - const int index = tabAt(event->pos()); + const int index = tabAt(event->position().toPoint()); if (mimeData->hasUrls()) { event->acceptProposedAction(); @@ -52,9 +77,10 @@ void DolphinTabBar::dragLeaveEvent(QDragLeaveEvent *event) void DolphinTabBar::dragMoveEvent(QDragMoveEvent *event) { const QMimeData *mimeData = event->mimeData(); - const int index = tabAt(event->pos()); + const int index = tabAt(event->position().toPoint()); if (mimeData->hasUrls()) { + Q_EMIT tabDragMoveEvent(index, event); updateAutoActivationTimer(index); } @@ -67,7 +93,7 @@ void DolphinTabBar::dropEvent(QDropEvent *event) updateAutoActivationTimer(-1); const QMimeData *mimeData = event->mimeData(); - const int index = tabAt(event->pos()); + const int index = tabAt(event->position().toPoint()); if (mimeData->hasUrls()) { Q_EMIT tabDropEvent(index, event); @@ -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); }