File indexing completed on 2024-04-21 16:30:00
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 SELECTIONMODETOPBAR_H 0009 #define SELECTIONMODETOPBAR_H 0010 0011 #include "global.h" 0012 0013 #include <QPointer> 0014 #include <QPropertyAnimation> 0015 #include <QWidget> 0016 0017 class QHideEvent; 0018 class QLabel; 0019 class QPushButton; 0020 class QResizeEvent; 0021 class QShowEvent; 0022 0023 namespace SelectionMode 0024 { 0025 0026 /** 0027 * @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. 0028 */ 0029 class TopBar : public QWidget 0030 { 0031 Q_OBJECT 0032 0033 public: 0034 TopBar(QWidget *parent); 0035 0036 /** 0037 * Plays a show or hide animation while changing visibility. 0038 * Therefore, if this method is used to hide this widget, the actual hiding will be postponed until the animation finished. 0039 * @see QWidget::setVisible() 0040 */ 0041 void setVisible(bool visible, Animated animated); 0042 0043 Q_SIGNALS: 0044 void selectionModeLeavingRequested(); 0045 0046 protected: 0047 /** Calls updateLabelString() */ 0048 void resizeEvent(QResizeEvent *resizeEvent) override; 0049 0050 private: 0051 using QWidget::setVisible; // Makes sure that the setVisible() declaration above doesn't hide the one from QWidget so we can still use it privately. 0052 0053 /** Decides whether the m_fullLabelString or m_shortLabelString should be used based on available width. */ 0054 void updateLabelString(); 0055 0056 private: 0057 QLabel *m_label; 0058 QPushButton *m_closeButton; 0059 0060 /** @see updateLabelString() */ 0061 QString m_fullLabelString; 0062 /** @see updateLabelString() */ 0063 QString m_shortLabelString; 0064 0065 int m_preferredHeight; 0066 0067 QPointer<QPropertyAnimation> m_heightAnimation; 0068 }; 0069 0070 } 0071 0072 #endif // SELECTIONMODETOPBAR_H