KWidgetsAddons

kmultitabbar.h
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
16class QPixmap;
17class QMenu;
19
20class KMultiTabBarInternal;
21
22/**
23 * @class KMultiTabBar kmultitabbar.h KMultiTabBar
24 *
25 * A Widget for horizontal and vertical tabs.
26 * (Note that in Qt4, QTabBar can be vertical as well)
27 *
28 * It is possible to add normal buttons to the top/left
29 * The handling if only one tab at a time or multiple tabs
30 * should be raisable is left to the "user".
31 *
32 * \image html kmultitabbar.png "KMultiTabBar Widget"
33 *
34 * @author Joseph Wenninger
35 */
36class KWIDGETSADDONS_EXPORT KMultiTabBar : public QWidget
37{
39 Q_PROPERTY(KMultiTabBarPosition position READ position WRITE setPosition)
40 Q_PROPERTY(KMultiTabBarStyle tabStyle READ tabStyle WRITE setStyle)
41public:
42 enum KMultiTabBarPosition {
43 Left,
44 Right,
45 Top,
46 Bottom
47 };
48 Q_ENUM(KMultiTabBarPosition)
49
50 /**
51 * The list of available styles for KMultiTabBar
52 */
54 VSNET = 0, ///< Visual Studio .Net like, always shows icon, only show the text of active tabs
55 KDEV3ICON = 2, ///< KDevelop 3 like, always shows the text and icons
56 STYLELAST = 0xffff,
57 };
58 Q_ENUM(KMultiTabBarStyle)
59
60 /**
61 * Create a KMultiTabBar with Left as KMultiTabBar position.
62 * @param parent The parent of the widget.
63 * @since 5.24
64 */
65 explicit KMultiTabBar(QWidget *parent = nullptr);
66
67 explicit KMultiTabBar(KMultiTabBarPosition pos, QWidget *parent = nullptr);
68 ~KMultiTabBar() override;
69
70 /**
71 * append a new button to the button area. The button can later on be accessed with button(ID)
72 * eg for connecting signals to it
73 * @param icon a icon for the button
74 * @param id an arbitrary ID value. It will be emitted in the clicked signal for identifying the button
75 * if more than one button is connected to a signals.
76 * @param popup A popup menu which should be displayed if the button is clicked
77 * @param not_used_yet will be used for a popup text in the future
78 * @since 5.13
79 */
80 int appendButton(const QIcon &icon, int id = -1, QMenu *popup = nullptr, const QString &not_used_yet = QString());
81
82 /**
83 * remove a button with the given ID
84 */
85 void removeButton(int id);
86
87 /**
88 * append a new tab to the tab area. It can be accessed lateron with tabb(id);
89 * @param icon a icon for the tab
90 * @param id an arbitrary ID which can be used later on to identify the tab
91 * @param text if a mode with text is used it will be the tab text, otherwise a mouse over hint
92 * @since 5.13
93 */
94 int appendTab(const QIcon &icon, int id = -1, const QString &text = QString());
95
96 /**
97 * remove a tab with a given ID
98 */
99 void removeTab(int id);
100 /**
101 * set a tab to "raised"
102 * @param id The ID of the tab to manipulate
103 * @param state true == activated/raised, false == not active
104 */
105 void setTab(int id, bool state);
106 /**
107 * return the state of a tab, identified by its ID
108 */
109 bool isTabRaised(int id) const;
110 /**
111 * get a pointer to a button within the button area identified by its ID
112 */
113 class KMultiTabBarButton *button(int id) const;
114
115 /**
116 * get a pointer to a tab within the tab area, identified by its ID
117 */
118 class KMultiTabBarTab *tab(int id) const;
119
120 /**
121 * set the real position of the widget.
122 * @param pos if the mode is horizontal, only use top, bottom, if it is vertical use left or right
123 */
124 void setPosition(KMultiTabBarPosition pos);
125
126 /**
127 * get the tabbar position.
128 * @return position
129 */
130 KMultiTabBarPosition position() const;
131
132 /**
133 * set the display style of the tabs
134 */
135 void setStyle(KMultiTabBarStyle style);
136
137 /**
138 * get the display style of the tabs
139 * @return display style
140 */
141 KMultiTabBarStyle tabStyle() const;
142
143protected:
144 friend class KMultiTabBarButton;
145 virtual void fontChange(const QFont &);
146 void paintEvent(class QPaintEvent *) override;
147 void updateSeparator();
148
149private:
150 std::unique_ptr<class KMultiTabBarPrivate> const d;
151};
152
153/**
154 * @class KMultiTabBarButton kmultitabbar.h KMultiTabBarButton
155 *
156 * Use KMultiTabBar::appendButton to append a button, which creates a KMultiTabBarButton instance
157 */
158class KWIDGETSADDONS_EXPORT KMultiTabBarButton : public QPushButton
159{
161public:
162 int id() const;
163 ~KMultiTabBarButton() override;
164
165public Q_SLOTS:
166 void setText(const QString &text);
167
169 /**
170 * this is emitted if the button is clicked
171 * @param id the ID identifying the button
172 */
173 void clicked(int id);
174protected Q_SLOTS:
175 virtual void slotClicked();
176
177protected:
178 void hideEvent(class QHideEvent *) override;
179 void showEvent(class QShowEvent *) override;
180 void paintEvent(class QPaintEvent *) override;
181
182 /**
183 * Should not be created directly. Use KMultiTabBar::appendButton
184 */
185 KMultiTabBarButton(const QIcon &icon, const QString &, int id, QWidget *parent);
186
187private:
188 friend class KMultiTabBar;
189
190 int m_id;
191 std::unique_ptr<class KMultiTabBarButtonPrivate> const d;
192};
193
194/**
195 * @class KMultiTabBarTab kmultitabbar.h KMultiTabBarTab
196 *
197 * Use KMultiTabBar::appendTab to append a tab, which creates a KMultiTabBarTab instance
198 */
199class KWIDGETSADDONS_EXPORT KMultiTabBarTab : public KMultiTabBarButton
200{
202public:
203 ~KMultiTabBarTab() override;
204 QSize sizeHint() const override;
205 QSize minimumSizeHint() const override;
206
207public Q_SLOTS:
208 /**
209 * this is used internally, but can be used by the user, if (s)he wants to
210 * It the according call of KMultiTabBar is invoked though this modifications will be overwritten
211 */
212 void setPosition(KMultiTabBar::KMultiTabBarPosition);
213
214 /**
215 * this is used internally, but can be used by the user, if (s)he wants to
216 * It the according call of KMultiTabBar is invoked though this modifications will be overwritten
217 */
219
220 /**
221 * set the active state of the tab
222 * @param state true==active false==not active
223 */
224 void setState(bool state);
225
226public:
228
229protected:
230 void paintEvent(QPaintEvent *) override;
231
232private:
233 KMultiTabBar::KMultiTabBarPosition m_position;
235
236 KWIDGETSADDONS_NO_EXPORT void computeMargins(int *hMargin, int *vMargin) const;
237 KWIDGETSADDONS_NO_EXPORT QSize computeSizeHint(bool withText) const;
238 KWIDGETSADDONS_NO_EXPORT bool shouldDrawText() const;
239 KWIDGETSADDONS_NO_EXPORT bool isVertical() const;
240
241 KWIDGETSADDONS_NO_EXPORT void initStyleOption(QStyleOptionToolButton *opt) const;
242
243 friend class KMultiTabBarInternal;
244 /**
245 * This class should never be created except with the appendTab call of KMultiTabBar
246 */
247 KWIDGETSADDONS_NO_EXPORT
248 KMultiTabBarTab(const QIcon &icon, const QString &, int id, QWidget *parent, KMultiTabBar::KMultiTabBarPosition pos, KMultiTabBar::KMultiTabBarStyle style);
249
250 std::unique_ptr<class KMultiTabBarTabPrivate> const d;
251};
252
253#endif
Use KMultiTabBar::appendButton to append a button, which creates a KMultiTabBarButton instance.
void clicked(int id)
this is emitted if the button is clicked
KMultiTabBarButton(const QIcon &icon, const QString &, int id, QWidget *parent)
Should not be created directly.
Use KMultiTabBar::appendTab to append a tab, which creates a KMultiTabBarTab instance.
void setState(bool state)
set the active state of the tab
void setPosition(KMultiTabBar::KMultiTabBarPosition)
this is used internally, but can be used by the user, if (s)he wants to It the according call of KMul...
A Widget for horizontal and vertical tabs.
void setStyle(KMultiTabBarStyle style)
set the display style of the tabs
KMultiTabBarStyle
The list of available styles for KMultiTabBar.
@ KDEV3ICON
KDevelop 3 like, always shows the text and icons.
@ VSNET
Visual Studio .Net like, always shows icon, only show the text of active tabs.
KMultiTabBar(QWidget *parent=nullptr)
Create a KMultiTabBar with Left as KMultiTabBar position.
void setPosition(KMultiTabBarPosition pos)
set the real position of the widget.
Q_ENUM(...)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
QPushButton(QWidget *parent)
QWidget(QWidget *parent, Qt::WindowFlags f)
virtual void hideEvent(QHideEvent *event)
virtual void paintEvent(QPaintEvent *event)
void setStyle(QStyle *style)
virtual void showEvent(QShowEvent *event)
QStyle * style() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 12:02:04 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.