Debian Codegraph @

src/Gui/QSint/actionpanel/actiongroup.h

raw
1 // SPDX-License-Identifier: LGPL-3.0-only
2 /***************************************************************************
3 * *
4 * Copyright: https://code.google.com/p/qsint/ *
5 * License: LGPL *
6 * *
7 ***************************************************************************/
8
9 #ifndef ACTIONGROUP_H
10 #define ACTIONGROUP_H
11
12 #include <QWidget>
13 #include <QBoxLayout>
14 #include <QTimer>
15 #include "qsint_global.h"
16
17
18 namespace QSint
19 {
20 class ActionLabel;
21 class ActionPanelScheme;
22 class TaskHeader;
23 class TaskGroup;
24
25 /**
26 * @brief A collapsible group widget for organizing actions.
27 *
28 * An ActionGroup can have a header and contains actions (ActionLabels) or other widgets.
29 */
30 class QSINT_EXPORT ActionGroup : public QWidget
31 {
32 Q_OBJECT
33
34 Q_PROPERTY(bool expandable READ isExpandable WRITE setExpandable NOTIFY expandableChanged)
35 Q_PROPERTY(bool header READ hasHeader WRITE setHeader NOTIFY headerChanged)
36 Q_PROPERTY(QString headerText READ headerText WRITE setHeaderText NOTIFY headerTextChanged)
37
38 Q_SIGNALS:
39 void expandableChanged();
40 void headerChanged();
41 void headerTextChanged();
42
43
44 public:
45 /**
46 * @brief Constructs an ActionGroup.
47 * @param parent The parent widget.
48 */
49 explicit ActionGroup(QWidget *parent = nullptr);
50
51 /**
52 * @brief Constructs an ActionGroup with a title.
53 * @param title The title of the group's header.
54 * @param expandable If `true` (default), the group can be expanded/collapsed.
55 * @param parent The parent widget.
56 */
57 explicit ActionGroup(const QString& title, bool expandable = true, QWidget *parent = nullptr);
58
59 /**
60 * @brief Constructs an ActionGroup with an icon and title.
61 * @param icon The icon for the group's header.
62 * @param title The title of the group's header.
63 * @param expandable If `true` (default), the group can be expanded/collapsed.
64 * @param parent The parent widget.
65 */
66 explicit ActionGroup(const QPixmap& icon, const QString& title, bool expandable = true, QWidget *parent = nullptr);
67
68 /**
69 * @brief Destroys the ActionGroup.
70 */
71 ~ActionGroup() override;
72
73 /**
74 * @brief Creates and adds an action.
75 * @param action The QAction to add.
76 * @param addToLayout If `true` (default), adds the action to the group's layout.
77 * @param addStretch If `true` (default), aligns the ActionLabel to the left.
78 * @return The newly created ActionLabel.
79 */
80 ActionLabel* addAction(QAction *action, bool addToLayout = true, bool addStretch = true);
81
82 /**
83 * @brief Adds an existing ActionLabel.
84 * @param label The ActionLabel to add.
85 * @param addToLayout If `true` (default), adds the label to the group's layout.
86 * @param addStretch If `true` (default), aligns the ActionLabel to the left.
87 * @return The added ActionLabel.
88 */
89 ActionLabel* addActionLabel(ActionLabel *label, bool addToLayout = true, bool addStretch = true);
90
91 /**
92 * @brief Adds a widget to the group.
93 * @param widget The widget to add.
94 * @param addToLayout If `true` (default), adds the widget to the group's layout.
95 * @param addStretch If `true` (default), aligns the widget to the left.
96 * @return `true` if added successfully.
97 */
98 bool addWidget(QWidget *widget, bool addToLayout = true, bool addStretch = true);
99
100 /**
101 * @brief Returns the group's layout.
102 * @return The group's layout (QVBoxLayout by default).
103 */
104 QBoxLayout* groupLayout();
105
106 /**
107 * @brief Set the style of the widgets
108 */
109 void setScheme(ActionPanelScheme *scheme);
110
111 /**
112 * @brief Checks if the group is expandable.
113 * @return `true` if the group is expandable, `false` otherwise.
114 */
115 bool isExpandable() const;
116
117 /**
118 * @brief Sets whether the group is expandable.
119 * @param expandable If `true`, the group can be expanded/collapsed.
120 */
121 void setExpandable(bool expandable);
122
123 /**
124 * @brief Checks if the group has a header.
125 * @return `true` if the group has a header, `false` otherwise.
126 */
127 bool hasHeader() const;
128
129 /**
130 * @brief Sets whether the group has a header.
131 * @param enable If `true`, the group will have a header.
132 */
133 void setHeader(bool enable);
134
135 /**
136 * @brief Returns the header text.
137 * @return The header text.
138 */
139 QString headerText() const;
140
141 /**
142 * @brief Sets the header text.
143 * @param text The header text.
144 */
145 void setHeaderText(const QString &text);
146
147 /**
148 * @brief Sets the header icon.
149 * @param icon The header icon.
150 */
151 void setHeaderIcon(const QPixmap &icon);
152
153 /**
154 * @brief Returns the recommended minimum size for the group.
155 * @return The minimum size hint.
156 */
157 QSize minimumSizeHint() const override;
158
159 public Q_SLOTS:
160 /**
161 * @brief Shows or hides the group's contents.
162 */
163 void showHide();
164
165 protected Q_SLOTS:
166 /**
167 * @brief Handles hiding the group's contents.
168 */
169 void processHide();
170
171 /**
172 * @brief Handles showing the group's contents.
173 */
174 void processShow();
175
176 protected:
177 /**
178 * @brief Paints the group.
179 * @param event The paint event.
180 */
181 void paintEvent(QPaintEvent *event) override;
182
183 /**
184 * @brief Initializes the group.
185 * @param hasHeader Whether the group has a header.
186 */
187 void init(bool hasHeader);
188
189 double m_foldStep = 0; ///< Current folding animation step.
190 double m_foldDelta = 0; ///< Change in height per animation step.
191 double m_fullHeight = 0; ///< Full (expanded) height of the group.
192 double m_tempHeight = 0; ///< Temporary height during animation.
193 int m_foldDirection = 0; ///< Direction of folding animation.
194
195 QPixmap m_foldPixmap; ///< Pixmap for the fold/unfold icon.
196
197 TaskHeader *myHeader = nullptr; ///< The group's header.
198 TaskGroup *myGroup = nullptr; ///< The container for actions/widgets.
199 QWidget *myDummy = nullptr; ///< Dummy widget for animation.
200 ActionPanelScheme *myScheme = nullptr; ///< The color scheme.
201
202 private:
203 const int separatorHeight = 1;
204 };
205 } // namespace QSint
206
207 #endif // ACTIONGROUP_H