File indexing completed on 2024-04-21 16:29:59

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef BOTTOMBAR_H
0009 #define BOTTOMBAR_H
0010 
0011 #include "global.h"
0012 
0013 #include <QAction>
0014 #include <QPointer>
0015 #include <QPropertyAnimation>
0016 #include <QWidget>
0017 
0018 class KActionCollection;
0019 class KFileItemList;
0020 class QPushButton;
0021 class QResizeEvent;
0022 class QScrollArea;
0023 class QUrl;
0024 
0025 namespace SelectionMode
0026 {
0027 class BottomBarContentsContainer;
0028 
0029 /**
0030  * @brief A bar used in selection mode that serves various purposes depending on what the user is currently trying to do.
0031  *
0032  * The Contents enum below gives a rough idea about the different states this bar might have.
0033  * The bar is notified of various changes that make changing or updating the content worthwhile.
0034  *
0035  * The visible contents of the bar are managed in BottomBarContentsContainer. This class serves as a wrapper around it.
0036  */
0037 class BottomBar : public QWidget
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     /** The different contents this bar can have. */
0043     enum Contents {
0044         CopyContents,
0045         CopyLocationContents,
0046         CopyToOtherViewContents,
0047         CutContents,
0048         DeleteContents,
0049         DuplicateContents,
0050         GeneralContents,
0051         MoveToOtherViewContents,
0052         MoveToTrashContents,
0053         PasteContents,
0054         RenameContents
0055     };
0056 
0057     /**
0058      * @param actionCollection the collection this bar retrieves its actions from
0059      * @param parent           the parent widget. Typically a DolphinViewContainer
0060      */
0061     explicit BottomBar(KActionCollection *actionCollection, QWidget *parent);
0062 
0063     /**
0064      * Plays a show or hide animation while changing visibility.
0065      * Therefore, if this method is used to hide this widget, the actual hiding will be postponed until the animation finished.
0066      *
0067      * This bar might also not show itself when setVisible(true), when context menu actions are supposed to be shown
0068      * for the selected items but no items have been selected yet. In that case it will only show itself once items were selected.
0069      *
0070      * This bar might also ignore a setVisible(false) call, if it has PasteContents because that bar is supposed to stay visible
0071      * even outside of selection mode.
0072      *
0073      * @param visible   Whether this bar is supposed to be visible long term
0074      * @param animated  Whether this should be animated. The animation is skipped if the users' settings are configured that way.
0075      *
0076      * @see QWidget::setVisible()
0077      */
0078     void setVisible(bool visible, Animated animated);
0079 
0080     /**
0081      * Changes the contents of the bar to @p contents.
0082      */
0083     void resetContents(Contents contents);
0084     Contents contents() const;
0085 
0086     /** @returns a width of 1 to make sure that this bar never causes side panels to shrink. */
0087     QSize sizeHint() const override;
0088 
0089 public Q_SLOTS:
0090     /** Adapts the contents based on the selection in the related view. */
0091     void slotSelectionChanged(const KFileItemList &selection, const QUrl &baseUrl);
0092 
0093     /** Used to notify the m_selectionModeBottomBar that there is no other ViewContainer in the tab. */
0094     void slotSplitTabDisabled();
0095 
0096 Q_SIGNALS:
0097     /**
0098      * Forwards the errors from the KFileItemAction::error() used for contextual actions.
0099      */
0100     void error(const QString &errorMessage);
0101 
0102     void selectionModeLeavingRequested();
0103 
0104 protected:
0105     /** Is installed on an internal widget to make sure that the height of the bar is adjusted to its contents. */
0106     bool eventFilter(QObject *watched, QEvent *event) override;
0107 
0108     /** Adapts the way the contents of this bar are displayed based on the available width. */
0109     void resizeEvent(QResizeEvent *resizeEvent) override;
0110 
0111 private:
0112     using QWidget::setVisible; // Makes sure that the setVisible() declaration above doesn't hide the one from QWidget so we can still use it privately.
0113 
0114     /**
0115      * Identical to SelectionModeBottomBar::setVisible() but doesn't change m_allowedToBeVisible.
0116      * @see SelectionModeBottomBar::setVisible()
0117      * @see m_allowedToBeVisible
0118      */
0119     void setVisibleInternal(bool visible, Animated animated);
0120 
0121 private:
0122     /** The only direct child widget of this bar. */
0123     QScrollArea *m_scrollArea;
0124     /** The only direct grandchild of this bar. */
0125     BottomBarContentsContainer *m_contentsContainer;
0126 
0127     /** Remembers if this bar was setVisible(true) or setVisible(false) the last time.
0128      * This is necessary because this bar might have been setVisible(true) but there is no reason to show the bar currently so it was kept hidden.
0129      * @see SelectionModeBottomBar::setVisible() */
0130     bool m_allowedToBeVisible = false;
0131     /** @see SelectionModeBottomBar::setVisible() */
0132     QPointer<QPropertyAnimation> m_heightAnimation;
0133 };
0134 
0135 }
0136 
0137 #endif // BOTTOMBAR_H