X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/33270dd4423eea329b8f20db17f8d70ab7b108da..2eb009455bec2fcdbd394a276ce40b3ff5efc35f:/src/dolphinnavigatorswidgetaction.h diff --git a/src/dolphinnavigatorswidgetaction.h b/src/dolphinnavigatorswidgetaction.h index ce199b3f0..c9ce4ece2 100644 --- a/src/dolphinnavigatorswidgetaction.h +++ b/src/dolphinnavigatorswidgetaction.h @@ -1,6 +1,6 @@ /* This file is part of the KDE project - SPDX-FileCopyrightText: 2020 Felix Ernst + SPDX-FileCopyrightText: 2020 Felix Ernst SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ @@ -10,7 +10,7 @@ #include "dolphinurlnavigator.h" -#include +#include #include #include #include @@ -32,7 +32,7 @@ class QPushButton; * createSecondaryUrlNavigator() when necessary. * - Each side is a QWidget which I call NavigatorWidget with a QHBoxLayout. * - Each NavigatorWidget consists an UrlNavigator, an emptyTrashButton, a - * networkFolderButton (for frameworks >= 5.78), and spacing. + * networkFolderButton, and spacing. * - Only the primary navigatorWidget has leading spacing. Both have trailing spacing. * The spacing is there to align the UrlNavigator with its DolphinViewContainer. */ @@ -43,6 +43,13 @@ class DolphinNavigatorsWidgetAction : public QWidgetAction public: DolphinNavigatorsWidgetAction(QWidget *parent = nullptr); + /** + * Adjusts the width of the spacings used to align the UrlNavigators with ViewContainers. + * This can only work nicely if up-to-date geometry of ViewContainers is cached so + * followViewContainersGeometry() has to have been called at least once before. + */ + void adjustSpacing(); + /** * The secondary UrlNavigator is only created on-demand. Such an action is not necessary * for the primary UrlNavigator which is created preemptively. @@ -50,21 +57,15 @@ public: * This method should preferably only be called when: * - Split view is activated in the active tab * OR - * - A switch to a tab that is already in split view mode is occuring + * - A switch to a tab that is already in split view mode is occurring */ void createSecondaryUrlNavigator(); - /** - * Notify the primary UrlNavigator of changes in geometry of the ViewContainer it tries to be - * aligned with. Only call this method if there is no secondary UrlNavigator. - */ - void followViewContainerGeometry(int globalXOfPrimary, int widthOfPrimary); /** * Notify this widget of changes in geometry of the ViewContainers it tries to be * aligned with. */ - void followViewContainersGeometry(int globalXOfPrimary, int widthOfPrimary, - int globalXOfSecondary, int widthOfSecondary); + void followViewContainersGeometry(QWidget *primaryViewContainer, QWidget *secondaryViewContainer = nullptr); bool isInToolbar() const; @@ -84,13 +85,20 @@ 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 * this method always returns the same widget and reparents it. * You normally don't have to use this method directly because * QWidgetAction::requestWidget() is used to obtain the navigatorsWidget - * and to steal it from whereever it was prior. + * and to steal it from wherever it was prior. * @param parent the new parent of the navigatorsWidget. */ QWidget *createWidget(QWidget *parent) override; @@ -99,20 +107,10 @@ protected: void deleteWidget(QWidget *widget) override; private: - /** - * Adjusts the width of the spacings used to align the UrlNavigators with ViewContainers. - * This can only work nicely if up-to-date geometry of ViewContainers is cached so - * followViewContainersGeometry() has to have been called at least once before. - */ - void adjustSpacing(); - /** * In Left-to-right languages the Primary side will be the left one. */ - enum Side { - Primary, - Secondary - }; + enum Side { Primary, Secondary }; /** * Used to create the navigatorWidgets for both sides of the QSplitter. */ @@ -126,14 +124,13 @@ private: /** * Creates a new empty trash button. * @param urlNavigator Only when this UrlNavigator shows the trash directory - * will the the button be visible. + * will the button be visible. * @param parent Aside from the usual QObject deletion mechanisms, * this parameter influences the positioning of dialog windows * pertaining to this trash button. */ QPushButton *newEmptyTrashButton(const DolphinUrlNavigator *urlNavigator, QWidget *parent) const; -#if !(KIO_VERSION < QT_VERSION_CHECK(5, 78, 0)) /** * Used to retrieve the networkFolderButtons for the navigatorWidgets on * both sides. @@ -147,12 +144,8 @@ private: * @param parent The object that should be the button's parent. */ QPushButton *newNetworkFolderButton(const DolphinUrlNavigator *urlNavigator, QWidget *parent) const; -#endif - enum Position { - Leading, - Trailing - }; + enum Position { Leading, Trailing }; /** * Used to retrieve both the leading and trailing spacing for the navigatorWidgets * on both sides. A secondary leading spacing does not exist. @@ -175,12 +168,59 @@ private: */ std::unique_ptr m_adjustSpacingTimer; - // cached values - int m_globalXOfSplitter; - int m_globalXOfPrimary; - int m_widthOfPrimary; - int m_globalXOfSecondary; - int m_widthOfSecondary; + /** + * Extracts the geometry information needed by adjustSpacing() from + * ViewContainers. They are also monitored for size changes which + * will lead to adjustSpacing() calls. + */ + class ViewGeometriesHelper : public QObject + { + public: + /** + * @param navigatorsWidget The QWidget of the navigatorsWidgetAction. + * @param navigatorsWidgetAction is only used to call adjustSpacing() whenever that is + * deemed necessary. + */ + ViewGeometriesHelper(QWidget *navigatorsWidget, DolphinNavigatorsWidgetAction *navigatorsWidgetAction); + + /** + * Calls m_navigatorsWidgetAction::adjustSpacing() when a watched object is resized. + */ + bool eventFilter(QObject *watched, QEvent *event) override; + + /** + * Sets the ViewContainers whose geometry is obtained when viewGeometries() is called. + */ + void setViewContainers(QWidget *primaryViewContainer, QWidget *secondaryViewContainer = nullptr); + + struct Geometries { + int globalXOfNavigatorsWidget; + int globalXOfPrimary; + int widthOfPrimary; + int globalXOfSecondary; + int widthOfSecondary; + }; + /** + * @return a Geometries struct that contains values adjustSpacing() requires. + */ + Geometries viewGeometries(); + + private: + QWidget *m_navigatorsWidget; + /** Is only used to call adjustSpacing() whenever that is deemed necessary. */ + DolphinNavigatorsWidgetAction *m_navigatorsWidgetAction; + + QPointer m_primaryViewContainer; + QPointer m_secondaryViewContainer; + }; + + ViewGeometriesHelper m_viewGeometriesHelper; + + /** + * Used to check if the window has been resized. + * @see ViewGeometriesHelper::eventFilter() for why this is needed. + */ + int m_previousWindowWidth = -1; }; #endif // DOLPHINNAVIGATORSWIDGETACTION_H