From 91dbaa1f5bbff9a50b67b2c165f30f5b4a7f437a Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Mon, 26 Oct 2020 23:43:47 +0100 Subject: [PATCH] Set focus to the next current tab when closing the current tab And by that it means giving the focus to the pageview which is most of the fimes what we want. One could argue that if i had the focus on the searchbar we should restore the focus there, but that makes not much sense to me, since each tab is it's own world, at most one could say, let's remember where the focus was in that tab the last time it was focused and restore it there, but it seems a bit convoluted. To be able of setting the focus to the pageview from the shell we need to set up some focus proxies, so that part->widget (which is the sidebar) ends up giving the focus to the pageview, which is what makes sense if someone says "you part, set yourself the focus" BUGS: 428257 --- part.cpp | 1 + shell/shell.cpp | 12 ++++++++++++ ui/sidebar.cpp | 1 + 3 files changed, 14 insertions(+) diff --git a/part.cpp b/part.cpp index 7323da83a..a84d1b0e1 100644 --- a/part.cpp +++ b/part.cpp @@ -506,6 +506,7 @@ Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &args) m_signatureMessage->setWordWrap(true); rightLayout->addWidget(m_signatureMessage); m_pageView = new PageView(rightContainer, m_document); + rightContainer->setFocusProxy(m_pageView); QMetaObject::invokeMethod(m_pageView, "setFocus", Qt::QueuedConnection); // usability setting // m_splitter->setFocusProxy(m_pageView); connect(m_pageView.data(), &PageView::rightClick, this, &Part::slotShowMenu); diff --git a/shell/shell.cpp b/shell/shell.cpp index 0478d33bf..84f4a775d 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -290,6 +290,18 @@ void Shell::openUrl(const QUrl &url, const QString &serializedOptions) void Shell::closeUrl() { closeTab(m_tabWidget->currentIndex()); + + // When closing the current tab two things can happen: + // * the focus was on the tab + // * the focus was somewhere in the toolbar + // we don't have other places that accept focus + // * If it was on the tab, logic says it should go back to the next current tab + // * If it was on the toolbar, we could leave it there, but since we redo the menus/toobars for the new tab, it gets kind of lost + // so it's easier to set it to the next current tab which also makes sense as consistency + if (m_tabWidget->count() >= 0) { + KParts::ReadWritePart *const newPart = m_tabs[m_tabWidget->currentIndex()].part; + newPart->widget()->setFocus(); + } } void Shell::readSettings() diff --git a/ui/sidebar.cpp b/ui/sidebar.cpp index 8c2ef148a..bf43ae145 100644 --- a/ui/sidebar.cpp +++ b/ui/sidebar.cpp @@ -110,6 +110,7 @@ void Sidebar::setMainWidget(QWidget *widget) // setting the splitter as parent for the widget automatically plugs it // into the splitter, neat! d->sideWidget->setParent(d->splitter); + setFocusProxy(widget); if (!d->splitterSizesSet) { QList splitterSizes = Okular::Settings::splitterSizes();