KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
accordionwidget.h
1#ifndef ACCORDIONWIDGET_H
2#define ACCORDIONWIDGET_H
3
4#include <QPushButton>
5#include <QWidget>
6#include <Kanoop/gui/libkanoopgui.h>
7
8class AccordionItem;
9
10/**
11 * @brief Vertically stacked collapsible-panel (accordion) widget.
12 *
13 * AccordionWidget manages a list of AccordionItem panels, each with a title
14 * button and a content widget. Items can be added, removed, expanded, and
15 * collapsed individually or all at once.
16 */
17class LIBKANOOPGUI_EXPORT AccordionWidget : public QWidget
18{
19 Q_OBJECT
20public:
21 /**
22 * @brief Construct with an optional parent widget.
23 * @param parent Optional QWidget parent
24 */
25 explicit AccordionWidget(QWidget *parent = nullptr);
26
27 /**
28 * @brief Append a new panel at the end.
29 * @param title Title shown on the panel's header button
30 * @param content Widget displayed when the panel is expanded
31 */
32 void addItem(const QString& title, QWidget* content);
33
34 /**
35 * @brief Insert a new panel at a specific position.
36 * @param index Zero-based position to insert at
37 * @param title Title shown on the panel's header button
38 * @param content Widget displayed when the panel is expanded
39 */
40 void insertItem(int index, const QString& title, QWidget* content);
41
42 /**
43 * @brief Remove the panel at the given index.
44 * @param index Zero-based index of the panel to remove
45 */
46 void removeItem(int index);
47
48 /**
49 * @brief Show or hide the panel at the given index.
50 * @param index Zero-based index of the panel
51 * @param visible true to show, false to hide
52 */
53 void setItemVisible(int index, bool visible);
54
55 /** @brief Remove all panels from the widget. */
56 void clear();
57
58 /** @brief Expand all panels. */
59 void expandAll();
60
61 /** @brief Collapse all panels. */
63
64 /**
65 * @brief Expand or collapse the panel containing the given content widget.
66 * @param widget Content widget identifying the panel
67 * @param expanded true to expand, false to collapse
68 */
69 void setExpanded(QWidget* widget, bool expanded);
70
71 /**
72 * @brief Return whether the panel containing the given content widget is expanded.
73 * @param widget Content widget identifying the panel
74 * @return true if the panel is expanded
75 */
76 bool isExpanded(QWidget* widget) const;
77
78 /**
79 * @brief Return whether all panels are currently expanded.
80 * @return true if every panel is expanded
81 */
82 bool areAllExpanded() const;
83
84 /**
85 * @brief Return whether all panels are currently collapsed.
86 * @return true if every panel is collapsed
87 */
88 bool areAllCollapsed() const;
89
90 /**
91 * @brief Change the title of the panel containing the given content widget.
92 * @param widget Content widget identifying the panel
93 * @param title New title text
94 */
95 void setTitle(QWidget* widget, const QString& title);
96
97 /**
98 * @brief Return the index of the panel containing the given content widget.
99 * @param widget Content widget to look up
100 * @return Zero-based index, or -1 if not found
101 */
102 int indexOf(QWidget* widget) const;
103
104 /**
105 * @brief Return the number of panels.
106 * @return Panel count
107 */
108 int count() const;
109
110signals:
111 /** @brief Emitted when a panel is added or removed. */
113
114private:
115 AccordionItem* findItemForWidget(QWidget* widget) const;
116
117public slots:
118 /** @brief Called when application preferences change; reapplies styling. */
119 virtual void onPreferencesChanged();
120};
121
122#endif // ACCORDIONWIDGET_H
Vertically stacked collapsible-panel (accordion) widget.
bool areAllCollapsed() const
Return whether all panels are currently collapsed.
void addItem(const QString &title, QWidget *content)
Append a new panel at the end.
bool isExpanded(QWidget *widget) const
Return whether the panel containing the given content widget is expanded.
void removeItem(int index)
Remove the panel at the given index.
void collapseAll()
Collapse all panels.
void setExpanded(QWidget *widget, bool expanded)
Expand or collapse the panel containing the given content widget.
int count() const
Return the number of panels.
void setItemVisible(int index, bool visible)
Show or hide the panel at the given index.
void itemCountModified()
Emitted when a panel is added or removed.
void expandAll()
Expand all panels.
int indexOf(QWidget *widget) const
Return the index of the panel containing the given content widget.
virtual void onPreferencesChanged()
Called when application preferences change; reapplies styling.
void clear()
Remove all panels from the widget.
void setTitle(QWidget *widget, const QString &title)
Change the title of the panel containing the given content widget.
bool areAllExpanded() const
Return whether all panels are currently expanded.
void insertItem(int index, const QString &title, QWidget *content)
Insert a new panel at a specific position.
AccordionWidget(QWidget *parent=nullptr)
Construct with an optional parent widget.