┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/dolphinnavigatorswidgetaction.h
diff options
context:
space:
mode:
authorFelix Ernst <[email protected]>2020-09-20 18:53:59 +0200
committerElvis Angelaccio <[email protected]>2020-11-09 23:49:07 +0100
commit37327c9b0aae112c5890703cba1f0157043007e0 (patch)
tree5cda9876f310a258b95226bc0d9681acc665f98e /src/dolphinnavigatorswidgetaction.h
parent6151a7aec0516570926cb1d15da48936e38e6765 (diff)
Make UrlNavigators in the toolbar the only option
The UrlNavigators will be automatically added to the toolbar. The Sort By action is removed from the default toolbar to make space. Remove all options to have UrlNavigators outside the toolbar and remove those code paths. Make it so the new NavigatorsWidgetAction contains two UrlNavigators when in split view mode. Spacing was also added to align these UrlNavigators with the ViewContainers when enough space is available. Force the toolbar to be either at the top or bottom of the window. Set a sane sizeHint for DolphinUrlNavigator. It would be better to do this in KUrlNavigator in the future. This commit also contains a changes which should be moved to a separate merge requests before this gets merged: - Add an expansion animation when split view is enabled by the user
Diffstat (limited to 'src/dolphinnavigatorswidgetaction.h')
-rw-r--r--src/dolphinnavigatorswidgetaction.h149
1 files changed, 149 insertions, 0 deletions
diff --git a/src/dolphinnavigatorswidgetaction.h b/src/dolphinnavigatorswidgetaction.h
new file mode 100644
index 000000000..c1808d68e
--- /dev/null
+++ b/src/dolphinnavigatorswidgetaction.h
@@ -0,0 +1,149 @@
+/*
+ This file is part of the KDE project
+ SPDX-FileCopyrightText: 2020 Felix Ernst <[email protected]>
+
+ SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
+*/
+
+#ifndef DOLPHINNAVIGATORSWIDGETACTION_H
+#define DOLPHINNAVIGATORSWIDGETACTION_H
+
+#include "dolphinurlnavigator.h"
+
+#include <QSplitter>
+#include <QTimer>
+#include <QWidgetAction>
+
+#include <memory>
+
+class KXmlGuiWindow;
+class QPushButton;
+
+/**
+ * @brief QWidgetAction that allows to use DolphinUrlNavigators in a toolbar.
+ *
+ * This class is mainly a container that manages up to two DolphinUrlNavigator objects so they
+ * can be added to a toolbar. It also deals with alignment.
+ *
+ * The structure of the defaultWidget() of this QWidgetAction is as follows:
+ * - A QSplitter manages up to two sides which each correspond to one DolphinViewContainer.
+ * The secondary side only exists for split view and is created by
+ * createSecondaryUrlNavigator() when necessary.
+ * - Each side is a QWidget which I call NavigatorWidget with a QHBoxLayout.
+ * - Each NavigatorWidget consists an UrlNavigator, an emptyTrashButton and spacing.
+ * - Only the primary navigatorWidget has leading spacing. Both have trailing spacing.
+ * The spacing is there to align the UrlNavigator with its DolphinViewContainer.
+ */
+class DolphinNavigatorsWidgetAction : public QWidgetAction
+{
+ Q_OBJECT
+
+ /**
+ * In Left-to-right languages the Primary side will be the left one.
+ */
+ enum Side {
+ Primary,
+ Secondary
+ };
+
+public:
+ DolphinNavigatorsWidgetAction(QWidget *parent = nullptr);
+
+ /**
+ * Adds this action to the mainWindow's toolbar and saves the change
+ * in the users ui configuration file.
+ * @return true if successful. Otherwise false.
+ */
+ bool addToToolbarAndSave(KXmlGuiWindow *mainWindow);
+
+ /**
+ * Different to the primary UrlNavigator, the secondary UrlNavigator is only created on-demand.
+ */
+ 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);
+
+ /**
+ * @return the primary UrlNavigator.
+ */
+ DolphinUrlNavigator *primaryUrlNavigator() const;
+ /**
+ * @return the secondary UrlNavigator and nullptr if it doesn't exist.
+ */
+ DolphinUrlNavigator *secondaryUrlNavigator() const;
+
+ /**
+ * Change the visibility of the secondary UrlNavigator including spacing.
+ * @param visible Setting this to false will completely hide the secondary side of this
+ * WidgetAction's QSplitter making the QSplitter effectively disappear.
+ */
+ void setSecondaryNavigatorVisible(bool visible);
+
+protected:
+ /**
+ * 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();
+
+ /**
+ * Used to create the navigatorWidgets for both sides of the QSplitter.
+ */
+ QWidget *createNavigatorWidget(Side side) const;
+
+ /**
+ * Used to retrieve the emptyTrashButtons for the navigatorWidgets on both sides.
+ */
+ QPushButton *emptyTrashButton(Side side);
+
+ /**
+ * Creates a new empty trash button.
+ * @param urlNavigator Only when this UrlNavigator shows the trash directory
+ * will the 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;
+
+ 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.
+ */
+ QWidget *spacing(Side side, Position position) const;
+
+ /**
+ * The defaultWidget() of this QWidgetAction.
+ */
+ std::unique_ptr<QSplitter> m_splitter;
+
+ /**
+ * adjustSpacing() has to be called slightly later than when urlChanged is emitted.
+ * This timer bridges that time.
+ */
+ std::unique_ptr<QTimer> m_adjustSpacingTimer;
+
+ // cached values
+ int m_globalXOfSplitter;
+ int m_globalXOfPrimary;
+ int m_widthOfPrimary;
+ int m_globalXOfSecondary;
+ int m_widthOfSecondary;
+};
+
+#endif // DOLPHINNAVIGATORSWIDGETACTION_H