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 * The secondary UrlNavigator is only created on-demand. Such an action is not necessary
46 * for the primary UrlNavigator which is created preemptively.
48 * This method should preferably only be called when:
49 * - Split view is activated in the active tab
51 * - A switch to a tab that is already in split view mode is occuring
53 void createSecondaryUrlNavigator();
56 * Notify the primary UrlNavigator of changes in geometry of the ViewContainer it tries to be
57 * aligned with. Only call this method if there is no secondary UrlNavigator.
59 void followViewContainerGeometry(int globalXOfPrimary
, int widthOfPrimary
);
61 * Notify this widget of changes in geometry of the ViewContainers it tries to be
64 void followViewContainersGeometry(int globalXOfPrimary
, int widthOfPrimary
,
65 int globalXOfSecondary
, int widthOfSecondary
);
67 bool isInToolbar() const;
70 * @return the primary UrlNavigator.
72 DolphinUrlNavigator
*primaryUrlNavigator() const;
74 * @return the secondary UrlNavigator and nullptr if it doesn't exist.
76 DolphinUrlNavigator
*secondaryUrlNavigator() const;
79 * Change the visibility of the secondary UrlNavigator including spacing.
80 * @param visible Setting this to false will completely hide the secondary side of this
81 * WidgetAction's QSplitter making the QSplitter effectively disappear.
83 void setSecondaryNavigatorVisible(bool visible
);
87 * There should always ever be one navigatorsWidget for this action so
88 * this method always returns the same widget and reparents it.
89 * You normally don't have to use this method directly because
90 * QWidgetAction::requestWidget() is used to obtain the navigatorsWidget
91 * and to steal it from whereever it was prior.
92 * @param parent the new parent of the navigatorsWidget.
94 QWidget
*createWidget(QWidget
*parent
) override
;
96 /** @see QWidgetAction::deleteWidget() */
97 void deleteWidget(QWidget
*widget
) override
;
101 * Adjusts the width of the spacings used to align the UrlNavigators with ViewContainers.
102 * This can only work nicely if up-to-date geometry of ViewContainers is cached so
103 * followViewContainersGeometry() has to have been called at least once before.
105 void adjustSpacing();
108 * In Left-to-right languages the Primary side will be the left one.
115 * Used to create the navigatorWidgets for both sides of the QSplitter.
117 QWidget
*createNavigatorWidget(Side side
) const;
120 * Used to retrieve the emptyTrashButtons for the navigatorWidgets on both sides.
122 QPushButton
*emptyTrashButton(Side side
);
125 * Creates a new empty trash button.
126 * @param urlNavigator Only when this UrlNavigator shows the trash directory
127 * will the the button be visible.
128 * @param parent Aside from the usual QObject deletion mechanisms,
129 * this parameter influences the positioning of dialog windows
130 * pertaining to this trash button.
132 QPushButton
*newEmptyTrashButton(const DolphinUrlNavigator
*urlNavigator
, QWidget
*parent
) const;
139 * Used to retrieve both the leading and trailing spacing for the navigatorWidgets
140 * on both sides. A secondary leading spacing does not exist.
142 QWidget
*spacing(Side side
, Position position
) const;
145 * Sets this action's text depending on the amount of visible UrlNavigators.
150 * The defaultWidget() of this QWidgetAction.
152 std::unique_ptr
<QSplitter
> m_splitter
;
155 * adjustSpacing() has to be called slightly later than when urlChanged is emitted.
156 * This timer bridges that time.
158 std::unique_ptr
<QTimer
> m_adjustSpacingTimer
;
161 int m_globalXOfSplitter
;
162 int m_globalXOfPrimary
;
163 int m_widthOfPrimary
;
164 int m_globalXOfSecondary
;
165 int m_widthOfSecondary
;
168 #endif // DOLPHINNAVIGATORSWIDGETACTION_H