X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/8e55f2c2409fd6ca9ebc66a6568f4d3bcbef7576..697d58e9727e229abb81956d27a05d1f02d8c775:/src/selectionmode/bottombarcontentscontainer.h diff --git a/src/selectionmode/bottombarcontentscontainer.h b/src/selectionmode/bottombarcontentscontainer.h index 6255ff987..10e7ba5fd 100644 --- a/src/selectionmode/bottombarcontentscontainer.h +++ b/src/selectionmode/bottombarcontentscontainer.h @@ -1,6 +1,6 @@ /* This file is part of the KDE project - SPDX-FileCopyrightText: 2022 Felix Ernst + SPDX-FileCopyrightText: 2022 Felix Ernst SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ @@ -12,7 +12,7 @@ #include "bottombar.h" #include -#include +#include #include class DolphinContextMenu; @@ -43,19 +43,28 @@ public: */ explicit BottomBarContentsContainer(KActionCollection *actionCollection, QWidget *parent); + /** + * @param contents The kind of contents that should be contained instead. + */ void resetContents(BottomBar::Contents contents); inline BottomBar::Contents contents() const { return m_contents; }; - inline bool hasSomethingToShow() { + inline bool hasSomethingToShow() + { return contents() != BottomBar::GeneralContents || m_internalContextMenu; } - void updateForNewWidth(); + /** + * Is called when the BottomBar resizes to let this ContentsContainer know that it should adapt its contents to the new width. + * Adapting is done by showing or hiding labels or buttons. + */ + void adaptToNewBarWidth(int newBarWidth); public Q_SLOTS: + /** Adapts the contents based on the selection in the related view. */ void slotSelectionChanged(const KFileItemList &selection, const QUrl &baseUrl); Q_SIGNALS: @@ -65,12 +74,12 @@ Q_SIGNALS: void error(const QString &errorMessage); /** - * Sometimes the contents see no reason to be visible and request the bar to be hidden instead which emits this signal. - * This can later change e.g. because the user selected items. Then this signal is used to request showing of the bar. + * When it does not make sense to show any specific contents, this signal is emitted and the receiver hides the bar. + * Later it might make sense to show it again e.g. because the user selected items. Then this signal is used to request showing of the bar. */ void barVisibilityChangeRequested(bool visible); - void leaveSelectionModeRequested(); + void selectionModeLeavingRequested(); private: void addCopyContents(); @@ -90,15 +99,15 @@ private: void addRenameContents(); /** - * Deletes all visible widgets and layouts from the bar. + * Deletes every child layout and child widget of this container. */ void emptyBarContents(); /** - * @returns A vector containing contextual actions for the given \a selection in the \a baseUrl. + * @returns A vector containing contextual actions for the given \a selectedItems in the \a baseUrl. * Cut, Copy, Rename and MoveToTrash are always added. Any further contextual actions depend on - * \a selection and \a baseUrl. \a selection and \a baseUrl can be empty/default constructed if - * no item- or view-specific actions should be added aside from Cut, Copy, Rename, MoveToTrash. + * \a selectedItems and \a baseUrl. + * If there are no \a selectedItems, an empty vector is returned and m_internalContextMenu is deleted. * @param selectedItems The selected items for which contextual actions should be displayed. * @param baseUrl Base URL of the viewport the contextual actions apply to. */ @@ -107,7 +116,7 @@ private: /** * @returns the amount of pixels that can be spared to add more widgets. A negative value might * be returned which signifies that some widgets should be hidden or removed from this bar to - * make sure that this SelectionModeBottomBar won't stretch the width of its parent. + * make sure that this BottomBarContentsContainer can fully fit on the BottomBar. */ int unusedSpace() const; @@ -118,12 +127,12 @@ private: void updateExplanatoryLabelVisibility(); /** - * Changes the text and enabled state of the main action button - * based on the amount of currently selected items and the state of the current m_mainAction. + * Changes the text and enabled state of the main action button based on the amount of currently + * selected items and the state of the current m_mainAction. * The current main action depends on the current barContents. - * @param selection the currently selected fileItems. + * @param selectedItems the currently selected fileItems. */ - void updateMainActionButton(const KFileItemList &selection); + void updateMainActionButton(const KFileItemList &selectedItems); private: /// All the actions that should be available from this bar when in general mode. @@ -136,16 +145,17 @@ private: /// @see updateMainActionButtonText ActionWithWidget m_mainAction = ActionWithWidget(nullptr); /// The button containing all the actions that don't currently fit into the bar. - QPointer m_overflowButton; + QPointer m_overflowButton; /// The actionCollection from which the actions for this bar are retrieved. KActionCollection *m_actionCollection; /// Describes the current contents of the bar. BottomBar::Contents m_contents; - /** The layout all the buttons and labels are added to. - * Do not confuse this with layout() because we do have a QScrollView in between this widget and m_layout. */ + /// The main layout of this ContentsContainer that all the buttons and labels are added to. QHBoxLayout *m_layout; - /// The info label used for some of the BarContents. Is hidden for narrow widths. + /// Caches the totalBarWidth as set in adaptToNewWidth(newBarWidth). */ + int m_barWidth = 0; + /// The info label used for some of the Contents. Is hidden for narrow widths. QPointer m_explanatoryLabel; };