From 2a72145eb09276a4576762b74cb976fcd4550e87 Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Fri, 15 May 2026 17:29:46 +0200 Subject: dolphinview: Unselect navigator when click on background --- src/dolphinmainwindow.cpp | 12 ++++++++++++ src/dolphinmainwindow.h | 5 +++++ src/kitemviews/kitemlistcontroller.cpp | 4 ++++ src/kitemviews/kitemlistcontroller.h | 6 ++++++ src/views/dolphinview.cpp | 1 + src/views/dolphinview.h | 6 ++++++ 6 files changed, 34 insertions(+) (limited to 'src') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index ebd811efa..439db8293 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -768,6 +768,17 @@ void DolphinMainWindow::slotSaveSession() } } +void DolphinMainWindow::slotClickViewBackground() +{ + auto navigators = static_cast(actionCollection()->action(QStringLiteral("url_navigators"))); + KUrlNavigator *navigator = + m_tabWidget->currentTabPage()->primaryViewActive() ? navigators->primaryUrlNavigator() : navigators->secondaryUrlNavigator(); + + if (navigator->isUrlEditable() && !GeneralSettings::editableUrl()) { + navigator->setUrlEditable(false); + } +} + void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable) { if (enable) { @@ -2791,6 +2802,7 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer *container) connect(view, &DolphinView::urlActivated, this, &DolphinMainWindow::handleUrl); connect(view, &DolphinView::goUpRequested, this, &DolphinMainWindow::goUp); connect(view, &DolphinView::doubleClickViewBackground, this, &DolphinMainWindow::slotDoubleClickViewBackground); + connect(view, &DolphinView::clickViewBackground, this, &DolphinMainWindow::slotClickViewBackground); connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged, this, &DolphinMainWindow::changeUrl); connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged, this, &DolphinMainWindow::updateHistory); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 4b2b0c87b..884b9f7bd 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -685,6 +685,11 @@ private Q_SLOTS: */ void slotSaveSession(); + /** + * Is called when the user clicks the active view's background. + */ + void slotClickViewBackground(); + private: /** * Sets up the various menus and actions and connects them. diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 3250e570a..b1927fc71 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -604,6 +604,10 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent *event, const const Qt::MouseButtons buttons = event->buttons(); + if (!m_pressedIndex.has_value()) { + Q_EMIT clickViewBackground(event->button()); + } + if (!onPress(event->pos(), event->modifiers(), buttons)) { startRubberBand(); return false; diff --git a/src/kitemviews/kitemlistcontroller.h b/src/kitemviews/kitemlistcontroller.h index 6379acbd8..38a4b6038 100644 --- a/src/kitemviews/kitemlistcontroller.h +++ b/src/kitemviews/kitemlistcontroller.h @@ -222,6 +222,12 @@ Q_SIGNALS: void decreaseZoom(); void swipeUp(); + /** + * Emitted when the view's background is clicked. + * Used to trigger a user configured action. + */ + void clickViewBackground(Qt::MouseButton button); + /** * Emitted when the view's background is double-clicked. * Used to trigger an user configured action. diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 74c5ecd23..97c1e926c 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -129,6 +129,7 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) KItemListController *controller = new KItemListController(m_model, m_view, this); controller->setAutoActivationEnabled(GeneralSettings::autoExpandFolders()); + connect(controller, &KItemListController::clickViewBackground, this, &DolphinView::clickViewBackground); connect(controller, &KItemListController::doubleClickViewBackground, this, &DolphinView::doubleClickViewBackground); connect(controller, &KItemListController::typeAheadUsed, this, [this](const QString &typedString, std::optional foundIndex) { if (foundIndex.has_value()) { diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index 9b068f92e..35276f9ac 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -729,6 +729,12 @@ Q_SIGNALS: */ void currentDirectoryRemoved(); + /** + * Emitted when the view's background is clicked. + * Used to trigger a user configured action. + */ + void clickViewBackground(Qt::MouseButton button); + /** * Emitted when the view's background is double-clicked. * Used to trigger an user configured action. -- cgit v1.3.1