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