2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2020 Felix Ernst <fe.a.ernst@gmail.com>
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
8 #ifndef DOLPHINNAVIGATORSWIDGETACTION_H
9 #define DOLPHINNAVIGATORSWIDGETACTION_H
11 #include "dolphinurlnavigator.h"
15 #include <QWidgetAction>
23 * @brief QWidgetAction that allows to use DolphinUrlNavigators in a toolbar.
25 * This class is mainly a container that manages up to two DolphinUrlNavigator objects so they
26 * can be added to a toolbar. It also deals with alignment.
28 * The structure of the defaultWidget() of this QWidgetAction is as follows:
29 * - A QSplitter manages up to two sides which each correspond to one DolphinViewContainer.
30 * The secondary side only exists for split view and is created by
31 * createSecondaryUrlNavigator() when necessary.
32 * - Each side is a QWidget which I call NavigatorWidget with a QHBoxLayout.
33 * - Each NavigatorWidget consists an UrlNavigator, an emptyTrashButton and spacing.
34 * - Only the primary navigatorWidget has leading spacing. Both have trailing spacing.
35 * The spacing is there to align the UrlNavigator with its DolphinViewContainer.
37 class DolphinNavigatorsWidgetAction
: public QWidgetAction
42 DolphinNavigatorsWidgetAction(QWidget
*parent
= nullptr);
45 * Adds this action to the mainWindow's toolbar and saves the change
46 * in the users ui configuration file.
47 * @return true if successful. Otherwise false.
49 bool addToToolbarAndSave(KXmlGuiWindow
*mainWindow
);
52 * The secondary UrlNavigator is only created on-demand. Such an action is not necessary
53 * for the primary UrlNavigator which is created preemptively.
55 * This method should preferably only be called when:
56 * - Split view is activated in the active tab
58 * - A switch to a tab that is already in split view mode is occuring
60 void createSecondaryUrlNavigator();
63 * Notify the primary UrlNavigator of changes in geometry of the ViewContainer it tries to be
64 * aligned with. Only call this method if there is no secondary UrlNavigator.
66 void followViewContainerGeometry(int globalXOfPrimary
, int widthOfPrimary
);
68 * Notify this widget of changes in geometry of the ViewContainers it tries to be
71 void followViewContainersGeometry(int globalXOfPrimary
, int widthOfPrimary
,
72 int globalXOfSecondary
, int widthOfSecondary
);
75 * @return the primary UrlNavigator.
77 DolphinUrlNavigator
*primaryUrlNavigator() const;
79 * @return the secondary UrlNavigator and nullptr if it doesn't exist.
81 DolphinUrlNavigator
*secondaryUrlNavigator() const;
84 * Change the visibility of the secondary UrlNavigator including spacing.
85 * @param visible Setting this to false will completely hide the secondary side of this
86 * WidgetAction's QSplitter making the QSplitter effectively disappear.
88 void setSecondaryNavigatorVisible(bool visible
);
92 * Adjusts the width of the spacings used to align the UrlNavigators with ViewContainers.
93 * This can only work nicely if up-to-date geometry of ViewContainers is cached so
94 * followViewContainersGeometry() has to have been called at least once before.
99 * In Left-to-right languages the Primary side will be the left one.
106 * Used to create the navigatorWidgets for both sides of the QSplitter.
108 QWidget
*createNavigatorWidget(Side side
) const;
111 * Used to retrieve the emptyTrashButtons for the navigatorWidgets on both sides.
113 QPushButton
*emptyTrashButton(Side side
);
116 * Creates a new empty trash button.
117 * @param urlNavigator Only when this UrlNavigator shows the trash directory
118 * will the the button be visible.
119 * @param parent Aside from the usual QObject deletion mechanisms,
120 * this parameter influences the positioning of dialog windows
121 * pertaining to this trash button.
123 QPushButton
*newEmptyTrashButton(const DolphinUrlNavigator
*urlNavigator
, QWidget
*parent
) const;
130 * Used to retrieve both the leading and trailing spacing for the navigatorWidgets
131 * on both sides. A secondary leading spacing does not exist.
133 QWidget
*spacing(Side side
, Position position
) const;
136 * Sets this action's text depending on the amount of visible UrlNavigators.
141 * The defaultWidget() of this QWidgetAction.
143 std::unique_ptr
<QSplitter
> m_splitter
;
146 * adjustSpacing() has to be called slightly later than when urlChanged is emitted.
147 * This timer bridges that time.
149 std::unique_ptr
<QTimer
> m_adjustSpacingTimer
;
152 int m_globalXOfSplitter
;
153 int m_globalXOfPrimary
;
154 int m_widthOfPrimary
;
155 int m_globalXOfSecondary
;
156 int m_widthOfSecondary
;
159 #endif // DOLPHINNAVIGATORSWIDGETACTION_H