X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/acc5e739ce540768c611940af936602693513f18..a4240f6c2285c87de5763b4924fbc1c954b4408c:/src/dolphintabbar.cpp diff --git a/src/dolphintabbar.cpp b/src/dolphintabbar.cpp index 55b5e5edf..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); } @@ -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;