1 | /* |
2 | SPDX-FileCopyrightText: 2001, 2002, 2003 Joseph Wenninger <jowenn@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef _KMultitabbar_h_ |
8 | #define _KMultitabbar_h_ |
9 | |
10 | #include <QPushButton> |
11 | #include <QString> |
12 | #include <memory> |
13 | |
14 | #include <kwidgetsaddons_export.h> |
15 | |
16 | class QPixmap; |
17 | class ; |
18 | class QStyleOptionToolButton; |
19 | |
20 | class KMultiTabBarInternal; |
21 | |
22 | /*! |
23 | * \class KMultiTabBar |
24 | * \inmodule KWidgetsAddons |
25 | * |
26 | * \brief A Widget for horizontal and vertical tabs. |
27 | * (Note that in Qt4, QTabBar can be vertical as well) |
28 | * |
29 | * It is possible to add normal buttons to the top/left |
30 | * The handling if only one tab at a time or multiple tabs |
31 | * should be raisable is left to the "user". |
32 | * |
33 | * \image kmultitabbar.png "KMultiTabBar Widget" |
34 | */ |
35 | class KWIDGETSADDONS_EXPORT KMultiTabBar : public QWidget |
36 | { |
37 | Q_OBJECT |
38 | |
39 | /*! |
40 | * \property KMultiTabBar::position |
41 | */ |
42 | Q_PROPERTY(KMultiTabBarPosition position READ position WRITE setPosition) |
43 | |
44 | /*! |
45 | * \property KMultiTabBar::style |
46 | */ |
47 | Q_PROPERTY(KMultiTabBarStyle tabStyle READ tabStyle WRITE setStyle) |
48 | public: |
49 | /*! |
50 | * \value Left |
51 | * \value Right |
52 | * \value Top |
53 | * \value Bottom |
54 | */ |
55 | enum KMultiTabBarPosition { |
56 | Left, |
57 | Right, |
58 | Top, |
59 | Bottom |
60 | }; |
61 | Q_ENUM(KMultiTabBarPosition) |
62 | |
63 | /*! |
64 | * The list of available styles for KMultiTabBar |
65 | * |
66 | * \value VSNET Visual Studio .Net like, always shows icon, only show the text of active tabs |
67 | * \value KDEV3ICON KDevelop 3 like, always shows the text and icons |
68 | * \omitvalue STYLELAST |
69 | */ |
70 | enum KMultiTabBarStyle { |
71 | VSNET = 0, |
72 | KDEV3ICON = 2, |
73 | STYLELAST = 0xffff, |
74 | }; |
75 | Q_ENUM(KMultiTabBarStyle) |
76 | |
77 | /*! |
78 | * Create a KMultiTabBar with Left as KMultiTabBar position. |
79 | * |
80 | * \a parent The parent of the widget. |
81 | * \since 5.24 |
82 | */ |
83 | explicit KMultiTabBar(QWidget *parent = nullptr); |
84 | |
85 | /*! |
86 | * |
87 | */ |
88 | explicit KMultiTabBar(KMultiTabBarPosition pos, QWidget *parent = nullptr); |
89 | ~KMultiTabBar() override; |
90 | |
91 | /*! |
92 | * append a new button to the button area. The button can later on be accessed with button(ID) |
93 | * eg for connecting signals to it |
94 | * |
95 | * \a icon a icon for the button |
96 | * |
97 | * \a id an arbitrary ID value. It will be emitted in the clicked signal for identifying the button |
98 | * if more than one button is connected to a signals. |
99 | * |
100 | * \a popup A popup menu which should be displayed if the button is clicked |
101 | * |
102 | * \a not_used_yet will be used for a popup text in the future |
103 | * |
104 | * \since 5.13 |
105 | */ |
106 | int (const QIcon &icon, int id = -1, QMenu * = nullptr, const QString ¬_used_yet = QString()); |
107 | |
108 | /*! |
109 | * remove a button with the given ID |
110 | */ |
111 | void removeButton(int id); |
112 | |
113 | /*! |
114 | * append a new tab to the tab area. It can be accessed lateron with tabb(id); |
115 | * |
116 | * \a icon a icon for the tab |
117 | * |
118 | * \a id an arbitrary ID which can be used later on to identify the tab |
119 | * |
120 | * \a text if a mode with text is used it will be the tab text, otherwise a mouse over hint |
121 | * |
122 | * \since 5.13 |
123 | */ |
124 | int appendTab(const QIcon &icon, int id = -1, const QString &text = QString()); |
125 | |
126 | /*! |
127 | * remove a tab with a given ID |
128 | */ |
129 | void removeTab(int id); |
130 | /*! |
131 | * set a tab to "raised" |
132 | * |
133 | * \a id The ID of the tab to manipulate |
134 | * |
135 | * \a state true == activated/raised, false == not active |
136 | */ |
137 | void setTab(int id, bool state); |
138 | /*! |
139 | * return the state of a tab, identified by its ID |
140 | */ |
141 | bool isTabRaised(int id) const; |
142 | /*! |
143 | * get a pointer to a button within the button area identified by its ID |
144 | */ |
145 | class KMultiTabBarButton *button(int id) const; |
146 | |
147 | /*! |
148 | * get a pointer to a tab within the tab area, identified by its ID |
149 | */ |
150 | class KMultiTabBarTab *tab(int id) const; |
151 | |
152 | /*! |
153 | * set the real position of the widget. |
154 | * |
155 | * \a pos if the mode is horizontal, only use top, bottom, if it is vertical use left or right |
156 | */ |
157 | void setPosition(KMultiTabBarPosition pos); |
158 | |
159 | /*! |
160 | * Returns the tabbar position. |
161 | */ |
162 | KMultiTabBarPosition position() const; |
163 | |
164 | /*! |
165 | * set the display style of the tabs |
166 | */ |
167 | void setStyle(KMultiTabBarStyle style); |
168 | |
169 | /*! |
170 | * Returns the display style of the tabs |
171 | */ |
172 | KMultiTabBarStyle tabStyle() const; |
173 | |
174 | protected: |
175 | friend class KMultiTabBarButton; |
176 | virtual void fontChange(const QFont &); |
177 | void paintEvent(class QPaintEvent *) override; |
178 | void updateSeparator(); |
179 | |
180 | private: |
181 | std::unique_ptr<class KMultiTabBarPrivate> const d; |
182 | }; |
183 | |
184 | /*! |
185 | * \class KMultiTabBarButton |
186 | * \inmodule KWidgetsAddons |
187 | * \inheaderfile KMultiTabBar |
188 | * |
189 | * \brief Use KMultiTabBar::appendButton to append a button, which creates a KMultiTabBarButton instance |
190 | */ |
191 | class KWIDGETSADDONS_EXPORT KMultiTabBarButton : public QPushButton |
192 | { |
193 | Q_OBJECT |
194 | public: |
195 | /*! |
196 | * |
197 | */ |
198 | int id() const; |
199 | ~KMultiTabBarButton() override; |
200 | |
201 | public Q_SLOTS: |
202 | /*! |
203 | * |
204 | */ |
205 | void setText(const QString &text); |
206 | |
207 | Q_SIGNALS: |
208 | /*! |
209 | * this is emitted if the button is clicked |
210 | * |
211 | * \a id the ID identifying the button |
212 | */ |
213 | void clicked(int id); |
214 | protected Q_SLOTS: |
215 | /*! |
216 | * |
217 | */ |
218 | virtual void slotClicked(); |
219 | |
220 | protected: |
221 | void hideEvent(class QHideEvent *) override; |
222 | void showEvent(class QShowEvent *) override; |
223 | void paintEvent(class QPaintEvent *) override; |
224 | |
225 | /*! |
226 | * Should not be created directly. Use KMultiTabBar::appendButton |
227 | */ |
228 | KMultiTabBarButton(const QIcon &icon, const QString &, int id, QWidget *parent); |
229 | |
230 | private: |
231 | friend class KMultiTabBar; |
232 | |
233 | int m_id; |
234 | std::unique_ptr<class KMultiTabBarButtonPrivate> const d; |
235 | }; |
236 | |
237 | /*! |
238 | * \class KMultiTabBarTab |
239 | * \inmodule KWidgetsAddons |
240 | * \inheaderfile KMultiTabBar |
241 | * |
242 | * \brief Use KMultiTabBar::appendTab to append a tab, which creates a KMultiTabBarTab instance. |
243 | */ |
244 | class KWIDGETSADDONS_EXPORT KMultiTabBarTab : public KMultiTabBarButton |
245 | { |
246 | Q_OBJECT |
247 | public: |
248 | ~KMultiTabBarTab() override; |
249 | QSize sizeHint() const override; |
250 | QSize minimumSizeHint() const override; |
251 | |
252 | public Q_SLOTS: |
253 | /*! |
254 | * this is used internally, but can be used by the user, if (s)he wants to |
255 | * It the according call of KMultiTabBar is invoked though this modifications will be overwritten |
256 | */ |
257 | void setPosition(KMultiTabBar::KMultiTabBarPosition); |
258 | |
259 | /*! |
260 | * this is used internally, but can be used by the user, if (s)he wants to |
261 | * It the according call of KMultiTabBar is invoked though this modifications will be overwritten |
262 | */ |
263 | void setStyle(KMultiTabBar::KMultiTabBarStyle); |
264 | |
265 | /*! |
266 | * set the active state of the tab |
267 | * |
268 | * \a state true==active false==not active |
269 | */ |
270 | void setState(bool state); |
271 | |
272 | public: |
273 | using KMultiTabBarButton::setIcon; |
274 | |
275 | protected: |
276 | void paintEvent(QPaintEvent *) override; |
277 | |
278 | private: |
279 | KMultiTabBar::KMultiTabBarPosition m_position; |
280 | KMultiTabBar::KMultiTabBarStyle m_style; |
281 | |
282 | KWIDGETSADDONS_NO_EXPORT void computeMargins(int *hMargin, int *vMargin) const; |
283 | KWIDGETSADDONS_NO_EXPORT QSize computeSizeHint(bool withText) const; |
284 | KWIDGETSADDONS_NO_EXPORT bool shouldDrawText() const; |
285 | KWIDGETSADDONS_NO_EXPORT bool isVertical() const; |
286 | |
287 | KWIDGETSADDONS_NO_EXPORT void initStyleOption(QStyleOptionToolButton *opt) const; |
288 | |
289 | friend class KMultiTabBarInternal; |
290 | /* |
291 | * This class should never be created except with the appendTab call of KMultiTabBar |
292 | */ |
293 | KWIDGETSADDONS_NO_EXPORT |
294 | KMultiTabBarTab(const QIcon &icon, const QString &, int id, QWidget *parent, KMultiTabBar::KMultiTabBarPosition pos, KMultiTabBar::KMultiTabBarStyle style); |
295 | |
296 | std::unique_ptr<class KMultiTabBarTabPrivate> const d; |
297 | }; |
298 | |
299 | #endif |
300 | |