X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/76e3eab6ea3545339da2fd30b838acbc8c0ff607..a4240f6c2285c87de5763b4924fbc1c954b4408c:/src/dolphintabbar.cpp diff --git a/src/dolphintabbar.cpp b/src/dolphintabbar.cpp index aa74e17ae..4df25263f 100644 --- a/src/dolphintabbar.cpp +++ b/src/dolphintabbar.cpp @@ -9,10 +9,33 @@ #include #include +#include #include #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 +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,13 +130,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); @@ -128,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); @@ -143,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; @@ -171,3 +210,5 @@ void DolphinTabBar::updateAutoActivationTimer(const int index) } } } + +#include "moc_dolphintabbar.cpp"