File indexing completed on 2025-02-16 13:11:38
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 2015 David Edmundson <davidedmundson@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KCOLLAPSIBLEGROUPBOX_H 0009 #define KCOLLAPSIBLEGROUPBOX_H 0010 0011 #include <QWidget> 0012 #include <kwidgetsaddons_export.h> 0013 #include <memory> 0014 0015 /** 0016 * @class KCollapsibleGroupBox kcollapsiblegroupbox.h KCollapsibleGroupBox 0017 * 0018 * A groupbox featuring a clickable header and arrow indicator that can be 0019 * expanded and collapsed to reveal the contents. 0020 * 0021 * When expanded, the widget will resize to fit the sizeHint of child items. 0022 * 0023 * @since 5.16 0024 */ 0025 class KWIDGETSADDONS_EXPORT KCollapsibleGroupBox : public QWidget 0026 { 0027 Q_OBJECT 0028 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) 0029 Q_PROPERTY(bool expanded READ isExpanded WRITE setExpanded NOTIFY expandedChanged) 0030 0031 public: 0032 explicit KCollapsibleGroupBox(QWidget *parent = nullptr); 0033 ~KCollapsibleGroupBox() override; 0034 0035 /** 0036 * Set the title that will be permanently shown at the top of the collapsing box 0037 * Mnemonics are supported 0038 */ 0039 void setTitle(const QString &title); 0040 0041 /** 0042 * The title 0043 */ 0044 QString title() const; 0045 0046 /** 0047 * Set whether contents are shown 0048 * 0049 * The default is false until the user clicks 0050 */ 0051 void setExpanded(bool expanded); 0052 0053 /** 0054 * Whether contents are shown 0055 * During animations, this will reflect the target state at the end of the animation 0056 */ 0057 bool isExpanded() const; 0058 0059 QSize sizeHint() const override; 0060 QSize minimumSizeHint() const override; 0061 0062 public Q_SLOTS: 0063 /** 0064 * Expands if collapsed and vice versa 0065 */ 0066 void toggle(); 0067 0068 /** 0069 * Equivalent to setExpanded(true) 0070 */ 0071 void expand(); 0072 0073 /** 0074 * Equivalent to setExpanded(false) 0075 */ 0076 void collapse(); 0077 0078 Q_SIGNALS: 0079 /** 0080 * Emitted when the title is changed 0081 */ 0082 void titleChanged(); 0083 0084 /** 0085 * Emitted when the widget expands or collapsed 0086 */ 0087 void expandedChanged(); 0088 0089 protected: 0090 void paintEvent(QPaintEvent *) override; 0091 0092 bool event(QEvent *) override; 0093 void mousePressEvent(QMouseEvent *) override; 0094 void mouseMoveEvent(QMouseEvent *) override; 0095 void leaveEvent(QEvent *) override; 0096 void keyPressEvent(QKeyEvent *) override; 0097 void resizeEvent(QResizeEvent *) override; 0098 0099 private Q_SLOTS: 0100 KWIDGETSADDONS_NO_EXPORT void overrideFocusPolicyOf(QWidget *widget); 0101 0102 private: 0103 std::unique_ptr<class KCollapsibleGroupBoxPrivate> const d; 0104 0105 Q_DISABLE_COPY(KCollapsibleGroupBox) 0106 }; 0107 0108 #endif