1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2015 David Edmundson <davidedmundson@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KCOLLAPSIBLEGROUPBOX_H
9#define KCOLLAPSIBLEGROUPBOX_H
10
11#include <QWidget>
12#include <kwidgetsaddons_export.h>
13#include <memory>
14
15/**
16 * @class KCollapsibleGroupBox kcollapsiblegroupbox.h KCollapsibleGroupBox
17 *
18 * A groupbox featuring a clickable header and arrow indicator that can be
19 * expanded and collapsed to reveal the contents.
20 *
21 * When expanded, the widget will resize to fit the sizeHint of child items.
22 *
23 * @since 5.16
24 */
25class KWIDGETSADDONS_EXPORT KCollapsibleGroupBox : public QWidget
26{
27 Q_OBJECT
28 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
29 Q_PROPERTY(bool expanded READ isExpanded WRITE setExpanded NOTIFY expandedChanged)
30
31public:
32 explicit KCollapsibleGroupBox(QWidget *parent = nullptr);
33 ~KCollapsibleGroupBox() override;
34
35 /**
36 * Set the title that will be permanently shown at the top of the collapsing box
37 * Mnemonics are supported
38 */
39 void setTitle(const QString &title);
40
41 /**
42 * The title
43 */
44 QString title() const;
45
46 /**
47 * Set whether contents are shown
48 *
49 * The default is false until the user clicks
50 */
51 void setExpanded(bool expanded);
52
53 /**
54 * Whether contents are shown
55 * During animations, this will reflect the target state at the end of the animation
56 */
57 bool isExpanded() const;
58
59 QSize sizeHint() const override;
60 QSize minimumSizeHint() const override;
61
62public Q_SLOTS:
63 /**
64 * Expands if collapsed and vice versa
65 */
66 void toggle();
67
68 /**
69 * Equivalent to setExpanded(true)
70 */
71 void expand();
72
73 /**
74 * Equivalent to setExpanded(false)
75 */
76 void collapse();
77
78Q_SIGNALS:
79 /**
80 * Emitted when the title is changed
81 */
82 void titleChanged();
83
84 /**
85 * Emitted when the widget expands or collapsed
86 */
87 void expandedChanged();
88
89protected:
90 void paintEvent(QPaintEvent *) override;
91
92 bool event(QEvent *) override;
93 void mousePressEvent(QMouseEvent *) override;
94 void mouseMoveEvent(QMouseEvent *) override;
95 void leaveEvent(QEvent *) override;
96 void keyPressEvent(QKeyEvent *) override;
97 void resizeEvent(QResizeEvent *) override;
98
99private Q_SLOTS:
100 KWIDGETSADDONS_NO_EXPORT void overrideFocusPolicyOf(QWidget *widget);
101
102private:
103 std::unique_ptr<class KCollapsibleGroupBoxPrivate> const d;
104
105 Q_DISABLE_COPY(KCollapsibleGroupBox)
106};
107
108#endif
109

source code of kwidgetsaddons/src/kcollapsiblegroupbox.h