2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@zohomail.eu>
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
8 #ifndef BOTTOMBARCONTENTSCONTAINER_H
9 #define BOTTOMBARCONTENTSCONTAINER_H
11 #include "actionwithwidget.h"
12 #include "bottombar.h"
15 #include <QPushButton>
18 class DolphinContextMenu
;
19 class KActionCollection
;
20 class KFileItemActions
;
26 namespace SelectionMode
30 * @brief An internal widget of BottomBar that controls the visible contents/widgets on it.
32 * This class should only be interacted with from the BottomBar class.
35 class BottomBarContentsContainer
: public QWidget
41 * @param actionCollection the collection where the actions for the contents are retrieved from
42 * @param parent the parent widget. Typically a ScrollView within the BottomBar
44 explicit BottomBarContentsContainer(KActionCollection
*actionCollection
, QWidget
*parent
);
47 * @param contents The kind of contents that should be contained instead.
49 void resetContents(BottomBar::Contents contents
);
50 inline BottomBar::Contents
contents() const
55 inline bool hasSomethingToShow() {
56 return contents() != BottomBar::GeneralContents
|| m_internalContextMenu
;
60 * Is called when the BottomBar resizes to let this ContentsContainer know that it should adapt its contents to the new width.
61 * Adapting is done by showing or hiding labels or buttons.
63 void adaptToNewBarWidth(int newBarWidth
);
66 /** Adapts the contents based on the selection in the related view. */
67 void slotSelectionChanged(const KFileItemList
&selection
, const QUrl
&baseUrl
);
71 * Forwards the errors from the KFileItemAction::error() used for contextual actions.
73 void error(const QString
&errorMessage
);
76 * When it does not make sense to show any specific contents, this signal is emitted and the receiver hides the bar.
77 * Later it might sense to show it again e.g. because the user selected items. Then this signal is used to request showing of the bar.
79 void barVisibilityChangeRequested(bool visible
);
81 void selectionModeLeavingRequested();
84 void addCopyContents();
85 void addCopyLocationContents();
86 void addCopyToOtherViewContents();
87 void addCutContents();
88 void addDeleteContents();
89 void addDuplicateContents();
91 * Adds the actions of m_generalBarActions as buttons to the bar. An overflow menu button is
92 * created to make sure any amount of actions can be accessed.
94 void addGeneralContents();
95 void addMoveToOtherViewContents();
96 void addMoveToTrashContents();
97 void addPasteContents();
98 void addRenameContents();
101 * Deletes every child layout and child widget of this container.
103 void emptyBarContents();
106 * @returns A vector containing contextual actions for the given \a selectedItems in the \a baseUrl.
107 * Cut, Copy, Rename and MoveToTrash are always added. Any further contextual actions depend on
108 * \a selectedItems and \a baseUrl.
109 * If there are no \a selectedItems, an empty vector is returned and m_internalContextMenu is deleted.
110 * @param selectedItems The selected items for which contextual actions should be displayed.
111 * @param baseUrl Base URL of the viewport the contextual actions apply to.
113 std::vector
<QAction
*> contextActionsFor(const KFileItemList
&selectedItems
, const QUrl
&baseUrl
);
116 * @returns the amount of pixels that can be spared to add more widgets. A negative value might
117 * be returned which signifies that some widgets should be hidden or removed from this bar to
118 * make sure that this BottomBarContentsContainer can fully fit on the BottomBar.
120 int unusedSpace() const;
123 * The label isn't that important. This method hides it if there isn't enough room on the bar or
124 * shows it if there is.
126 void updateExplanatoryLabelVisibility();
129 * Changes the text and enabled state of the main action button based on the amount of currently
130 * selected items and the state of the current m_mainAction.
131 * The current main action depends on the current barContents.
132 * @param selectedItems the currently selected fileItems.
134 void updateMainActionButton(const KFileItemList
&selectedItems
);
137 /// All the actions that should be available from this bar when in general mode.
138 std::vector
<ActionWithWidget
> m_generalBarActions
;
139 /// The context menu used to retrieve all the actions that are relevant for the current selection.
140 std::unique_ptr
<DolphinContextMenu
> m_internalContextMenu
;
141 /// An object that is necessary to keep around for m_internalContextMenu.
142 KFileItemActions
*m_fileItemActions
= nullptr;
144 /// @see updateMainActionButtonText
145 ActionWithWidget m_mainAction
= ActionWithWidget(nullptr);
146 /// The button containing all the actions that don't currently fit into the bar.
147 QPointer
<QPushButton
> m_overflowButton
;
148 /// The actionCollection from which the actions for this bar are retrieved.
149 KActionCollection
*m_actionCollection
;
150 /// Describes the current contents of the bar.
151 BottomBar::Contents m_contents
;
152 /// The main layout of this ContentsContainer that all the buttons and labels are added to.
153 QHBoxLayout
*m_layout
;
155 /// Caches the totalBarWidth as set in adaptToNewWidth(newBarWidth). */
157 /// The info label used for some of the Contents. Is hidden for narrow widths.
158 QPointer
<QLabel
> m_explanatoryLabel
;
163 #endif // BOTTOMBARCONTENTSCONTAINER_H