Debian Codegraph @

src/Gui/QSint/actionpanel/actionbox.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 ACTIONBOX_H
10 #define ACTIONBOX_H
11
12 #include "actionlabel.h"
13
14 #include <QLabel>
15 #include <QVBoxLayout>
16
17
18 namespace QSint
19 {
20 /**
21 * @brief A panel of actions, similar to Windows Vista/7 control panel items.
22 *
23 * An ActionBox displays an icon, a clickable header, and a list of actions.
24 * Actions can have icons, tooltips, status tips, and support click/check functionality
25 * (similar to ActionLabel). Customizable via CSS.
26 */
27 class QSINT_EXPORT ActionBox : public QFrame
28 {
29 Q_OBJECT
30
31 Q_PROPERTY(QPixmap icon READ icon WRITE setIcon) // clazy:exclude=qproperty-without-notify
32 Q_PROPERTY(ActionLabel header READ header) // clazy:exclude=qproperty-without-notify
33
34 public:
35 /**
36 * @brief Constructs an ActionBox.
37 * @param parent The parent widget.
38 */
39 explicit ActionBox(QWidget *parent = nullptr);
40
41 /**
42 * @brief Constructs an ActionBox with a header text.
43 * @param headerText The header text.
44 * @param parent The parent widget.
45 */
46 ActionBox(const QString & headerText, QWidget *parent = nullptr);
47
48 /**
49 * @brief Constructs an ActionBox with an icon and header text.
50 * @param icon The icon.
51 * @param headerText The header text.
52 * @param parent The parent widget.
53 */
54 explicit ActionBox(const QPixmap & icon, const QString & headerText, QWidget *parent = nullptr);
55
56 /**
57 * @brief Sets the ActionBox icon.
58 * @param icon The icon.
59 */
60 void setIcon(const QPixmap & icon);
61
62 /**
63 * @brief Returns the ActionBox icon.
64 * @return The icon.
65 */
66 QPixmap icon() const;
67
68 /**
69 * @brief Returns the header label.
70 * @return The header label.
71 */
72 inline ActionLabel* header() const { return headerLabel; }
73
74 /**
75 * @brief Creates and adds an action from a QAction.
76 * @param action The QAction.
77 * @param l Optional layout to add the action to. Defaults to the
78 * ActionBox's default vertical layout.
79 * @return The created ActionLabel.
80 */
81 ActionLabel* createItem(QAction * action, QLayout * l = nullptr);
82
83 /**
84 * @brief Creates and adds multiple actions from a list of QActions.
85 * @param actions The list of QActions.
86 * @return The list of created ActionLabels.
87 */
88 QList<ActionLabel*> createItems(const QList<QAction*> actions);
89
90 /**
91 * @brief Creates and adds an action with text.
92 * @param text The action text.
93 * @param l Optional layout to add the action to.
94 * @return The created ActionLabel.
95 */
96 ActionLabel* createItem(const QString & text = QString(), QLayout * l = nullptr);
97
98 /**
99 * @brief Creates and adds an action with an icon and text.
100 * @param icon The action icon.
101 * @param text The action text.
102 * @param l Optional layout to add the action to.
103 * @return The created ActionLabel.
104 */
105 ActionLabel* createItem(const QPixmap & icon, const QString & text, QLayout * l = nullptr);
106
107 /**
108 * @brief Creates and adds a spacer.
109 * @param l Optional layout to add the spacer to. Defaults to the
110 * ActionBox's default vertical layout.
111 * @return The created spacer item.
112 */
113 QSpacerItem* createSpacer(QLayout * l = nullptr);
114
115 /**
116 * @brief Creates a horizontal layout.
117 * @return The created layout.
118 */
119 QLayout* createHBoxLayout();
120
121 /**
122 * @brief Returns the default layout used for actions.
123 * @return The default layout.
124 */
125 inline QLayout* itemLayout() const { return dataLayout; }
126
127 /**
128 * @brief Adds a layout.
129 * @param l The layout to add.
130 */
131 void addLayout(QLayout * l);
132
133 /**
134 * @brief Adds a widget.
135 * @param w The widget to add.
136 * @param l Optional layout to add the widget to. Defaults to the
137 * ActionBox's default vertical layout.
138 */
139 void addWidget(QWidget * w, QLayout * l = nullptr);
140
141 /**
142 * @brief Returns the recommended minimum size.
143 * @return The minimum size hint.
144 */
145 QSize minimumSizeHint() const override;
146
147 protected:
148 /**
149 * @brief Initializes the ActionBox.
150 * @param headerText The initial header text.
151 */
152 void init(const QString &headerText = QString());
153
154 QVBoxLayout *dataLayout; ///< Default layout for actions/widgets.
155 QLabel *iconLabel; ///< Label for the ActionBox icon.
156 ActionLabel *headerLabel; ///< Label for the header.
157 };
158 } // namespace
159
160 #endif // ACTIONBOX_H