From 9d60570ca784000cb5ef78b13861eee58117595d Mon Sep 17 00:00:00 2001 From: Akseli Lahtinen Date: Sat, 12 Apr 2025 16:28:38 +0000 Subject: [PATCH] DolphinNavigator: Hide the KUrlNavigator background if DolphinNavigator is outside of toolbar When the DolphinNavigator is outside of the toolbar, it's better to hide the background for better looks. This change works only when Dolphin is built against KIO 6.14. --- src/dolphinmainwindow.cpp | 8 ++++++++ src/dolphinmainwindow.h | 6 ++++++ src/dolphinnavigatorswidgetaction.cpp | 14 ++++++++++++++ src/dolphinnavigatorswidgetaction.h | 7 +++++++ 4 files changed, 35 insertions(+) diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 12b8be955..efcd4190e 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -236,6 +236,7 @@ DolphinMainWindow::DolphinMainWindow() } updateAllowedToolbarAreas(); + updateNavigatorsBackground(); // enable middle-click on back/forward/up to open in a new tab auto *middleClickEventFilter = new MiddleClickActionEventFilter(this); @@ -2760,6 +2761,12 @@ void DolphinMainWindow::updateAllowedToolbarAreas() } } +void DolphinMainWindow::updateNavigatorsBackground() +{ + auto navigators = static_cast(actionCollection()->action(QStringLiteral("url_navigators"))); + navigators->setBackgroundEnabled(navigators->isInToolbar()); +} + bool DolphinMainWindow::isKompareInstalled() const { static bool initialized = false; @@ -2946,6 +2953,7 @@ void DolphinMainWindow::saveNewToolbarConfig() m_tabWidget->currentTabPage()->insertNavigatorsWidget(navigators); } updateAllowedToolbarAreas(); + updateNavigatorsBackground(); (static_cast(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu))))->hideActionsOf(toolBar()); } diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index ecc84b971..b6aa9c020 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -704,6 +704,12 @@ private: */ void updateAllowedToolbarAreas(); + /** + * Sets the background of the location bar(s) on if they are inside the toolbar, + * or off if they are outside the toolbar. + */ + void updateNavigatorsBackground(); + bool isKompareInstalled() const; /** diff --git a/src/dolphinnavigatorswidgetaction.cpp b/src/dolphinnavigatorswidgetaction.cpp index 0095869b1..1e4e5df9c 100644 --- a/src/dolphinnavigatorswidgetaction.cpp +++ b/src/dolphinnavigatorswidgetaction.cpp @@ -9,6 +9,7 @@ #include "trash/dolphintrash.h" +#include #include #include #include @@ -102,6 +103,7 @@ void DolphinNavigatorsWidgetAction::createSecondaryUrlNavigator() Q_ASSERT(m_splitter->count() == 1); m_splitter->addWidget(createNavigatorWidget(Secondary)); Q_ASSERT(m_splitter->count() == 2); + secondaryUrlNavigator()->setBackgroundEnabled(primaryUrlNavigator()->isBackgroundEnabled()); updateText(); } @@ -148,6 +150,18 @@ void DolphinNavigatorsWidgetAction::setSecondaryNavigatorVisible(bool visible) updateText(); } +void DolphinNavigatorsWidgetAction::setBackgroundEnabled(bool enabled) +{ +#if KIO_VERSION >= QT_VERSION_CHECK(6, 14, 0) + m_splitter->setAutoFillBackground(!enabled); + m_splitter->setBackgroundRole(enabled ? QPalette::Window : QPalette::Base); + primaryUrlNavigator()->setBackgroundEnabled(enabled); + if (secondaryUrlNavigator()) { + secondaryUrlNavigator()->setBackgroundEnabled(enabled); + } +#endif +} + QWidget *DolphinNavigatorsWidgetAction::createWidget(QWidget *parent) { QWidget *oldParent = m_splitter->parentWidget(); diff --git a/src/dolphinnavigatorswidgetaction.h b/src/dolphinnavigatorswidgetaction.h index 6f068e27d..c9ce4ece2 100644 --- a/src/dolphinnavigatorswidgetaction.h +++ b/src/dolphinnavigatorswidgetaction.h @@ -85,6 +85,13 @@ public: */ void setSecondaryNavigatorVisible(bool visible); + /** + * Sets the background cosmetic of the location bar(s) visible or hidden. + * In frameless designs it's better to hide the background. + * @param enabled True for showing background cosmetic, false for hiding it. + */ + void setBackgroundEnabled(bool enabled); + protected: /** * There should always ever be one navigatorsWidget for this action so -- 2.47.3