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