]> cloud.milkyroute.net Git - dolphin.git/blob - src/selectionmode/topbar.h
Improve code quality
[dolphin.git] / src / selectionmode / topbar.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 SELECTIONMODETOPBAR_H
9 #define SELECTIONMODETOPBAR_H
10
11 #include "global.h"
12
13 #include <QPointer>
14 #include <QPropertyAnimation>
15 #include <QStyle>
16 #include <QWidget>
17
18 class QHideEvent;
19 class QLabel;
20 class QPushButton;
21 class QResizeEvent;
22 class QShowEvent;
23
24 namespace SelectionMode
25 {
26
27 /**
28 * @brief A bar appearing at the top of the view when in selection mode to make users aware of the selection mode state of the application.
29 */
30 class TopBar : public QWidget
31 {
32 Q_OBJECT
33
34 public:
35 TopBar(QWidget *parent);
36
37 /**
38 * Plays a show or hide animation while changing visibility.
39 * Therefore, if this method is used to hide this widget, the actual hiding will be postponed until the animation finished.
40 * @see QWidget::setVisible()
41 */
42 void setVisible(bool visible, Animated animated);
43
44 Q_SIGNALS:
45 void leaveSelectionModeRequested();
46
47 protected:
48 /** Calls updateLabelString() */
49 void resizeEvent(QResizeEvent *resizeEvent) override;
50
51 private:
52 using QWidget::setVisible; // Makes sure that the setVisible() declaration above doesn't hide the one from QWidget so we can still use it privately.
53
54 /** Decides whether the m_fullLabelString or m_shortLabelString should be used based on available width. */
55 void updateLabelString();
56
57 private:
58 QLabel *m_label;
59 QPushButton *m_closeButton;
60
61 /** @see updateLabelString() */
62 QString m_fullLabelString;
63 /** @see updateLabelString() */
64 QString m_shortLabelString;
65
66 int m_preferredHeight;
67
68 QPointer<QPropertyAnimation> m_heightAnimation;
69 };
70
71 }
72
73 #endif // SELECTIONMODETOPBAR_H