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

KDE's Doxygen guidelines are available online.