]> cloud.milkyroute.net Git - dolphin.git/blob - src/selectionmode/bottombar.h
ab29a85a5bf232e4d0628c9adf813176df3d482f
[dolphin.git] / src / selectionmode / bottombar.h
1 /*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@zohomail.eu>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7
8 #ifndef BOTTOMBAR_H
9 #define BOTTOMBAR_H
10
11 #include "global.h"
12
13 #include <QAction>
14 #include <QPointer>
15 #include <QPropertyAnimation>
16 #include <QWidget>
17
18 class KActionCollection;
19 class KFileItemList;
20 class QAction;
21 class QPushButton;
22 class QResizeEvent;
23 class QScrollArea;
24 class QUrl;
25
26 namespace SelectionMode
27 {
28 class BottomBarContentsContainer;
29
30 /**
31 * @brief A bar used in selection mode that serves various purposes depending on what the user is currently trying to do.
32 *
33 * The Contents enum below gives a rough idea about the different states this bar might have.
34 * The bar is notified of various changes that make changing or updating the content worthwhile.
35 *
36 * The visible contents of the bar are managed in BottomBarContentsContainer. This class serves as a wrapper around it.
37 */
38 class BottomBar : public QWidget
39 {
40 Q_OBJECT
41
42 public:
43 /** The different contents this bar can have. */
44 enum Contents {
45 CopyContents,
46 CopyLocationContents,
47 CopyToOtherViewContents,
48 CutContents,
49 DeleteContents,
50 DuplicateContents,
51 GeneralContents,
52 MoveToOtherViewContents,
53 MoveToTrashContents,
54 PasteContents,
55 RenameContents
56 };
57
58 /**
59 * @param actionCollection the collection this bar retrieves its actions from
60 * @param parent the parent widget. Typically a DolphinViewContainer
61 */
62 explicit BottomBar(KActionCollection *actionCollection, QWidget *parent);
63
64 /**
65 * Plays a show or hide animation while changing visibility.
66 * Therefore, if this method is used to hide this widget, the actual hiding will be postponed until the animation finished.
67 *
68 * This bar might also not show itself when setVisible(true), when context menu actions are supposed to be shown
69 * for the selected items but no items have been selected yet. In that case it will only show itself once items were selected.
70 *
71 * This bar might also ignore a setVisible(false) call, if it has PasteContents because that bar is supposed to stay visible
72 * even outside of selection mode.
73 *
74 * @param visible Whether this bar is supposed to be visible long term
75 * @param animated Whether this should be animated. The animation is skipped if the users' settings are configured that way.
76 *
77 * @see QWidget::setVisible()
78 */
79 void setVisible(bool visible, Animated animated);
80
81 /**
82 * Changes the contents of the bar to @p contents.
83 */
84 void resetContents(Contents contents);
85 Contents contents() const;
86
87 /** @returns a width of 1 to make sure that this bar never causes side panels to shrink. */
88 QSize sizeHint() const override;
89
90 public Q_SLOTS:
91 /** Adapts the contents based on the selection in the related view. */
92 void slotSelectionChanged(const KFileItemList &selection, const QUrl &baseUrl);
93
94 /** Used to notify the m_selectionModeBottomBar that there is no other ViewContainer in the tab. */
95 void slotSplitTabDisabled();
96
97 Q_SIGNALS:
98 /**
99 * Forwards the errors from the KFileItemAction::error() used for contextual actions.
100 */
101 void error(const QString &errorMessage);
102
103 void leaveSelectionModeRequested();
104
105 protected:
106 /** Is installed on an internal widget to make sure that the height of the bar is adjusted to its contents. */
107 bool eventFilter(QObject *watched, QEvent *event) override;
108
109 /** Adapts the way the contents of this bar are displayed based on the available width. */
110 void resizeEvent(QResizeEvent *resizeEvent) override;
111
112 private:
113 using QWidget::setVisible; // Makes sure that the setVisible() declaration above doesn't hide the one from QWidget so we can still use it privately.
114
115 /**
116 * Identical to SelectionModeBottomBar::setVisible() but doesn't change m_allowedToBeVisible.
117 * @see SelectionModeBottomBar::setVisible()
118 * @see m_allowedToBeVisible
119 */
120 void setVisibleInternal(bool visible, Animated animated);
121
122 private:
123 /** The only direct child widget of this bar. */
124 QScrollArea *m_scrollArea;
125 /** The only direct grandchild of this bar. */
126 BottomBarContentsContainer *m_contentsContainer;
127
128 /** Remembers if this bar was setVisible(true) or setVisible(false) the last time.
129 * 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.
130 * @see SelectionModeBottomBar::setVisible() */
131 bool m_allowedToBeVisible = false;
132 /** @see SelectionModeBottomBar::setVisible() */
133 QPointer<QPropertyAnimation> m_heightAnimation;
134 };
135
136 }
137
138 #endif // BOTTOMBAR_H