Warning, file /frameworks/kwidgetsaddons/src/kmultitabbar.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2001, 2002, 2003 Joseph Wenninger <jowenn@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef _KMultitabbar_h_ 0008 #define _KMultitabbar_h_ 0009 0010 #include <QPushButton> 0011 #include <QString> 0012 #include <memory> 0013 0014 #include <kwidgetsaddons_export.h> 0015 0016 class QPixmap; 0017 class QMenu; 0018 class QStyleOptionToolButton; 0019 0020 class KMultiTabBarInternal; 0021 0022 /** 0023 * @class KMultiTabBar kmultitabbar.h KMultiTabBar 0024 * 0025 * A Widget for horizontal and vertical tabs. 0026 * (Note that in Qt4, QTabBar can be vertical as well) 0027 * 0028 * It is possible to add normal buttons to the top/left 0029 * The handling if only one tab at a time or multiple tabs 0030 * should be raisable is left to the "user". 0031 * 0032 * \image html kmultitabbar.png "KMultiTabBar Widget" 0033 * 0034 * @author Joseph Wenninger 0035 */ 0036 class KWIDGETSADDONS_EXPORT KMultiTabBar : public QWidget 0037 { 0038 Q_OBJECT 0039 Q_PROPERTY(KMultiTabBarPosition position READ position WRITE setPosition) 0040 Q_PROPERTY(KMultiTabBarStyle tabStyle READ tabStyle WRITE setStyle) 0041 public: 0042 enum KMultiTabBarPosition { Left, Right, Top, Bottom }; 0043 Q_ENUM(KMultiTabBarPosition) 0044 0045 /** 0046 * The list of available styles for KMultiTabBar 0047 */ 0048 enum KMultiTabBarStyle { 0049 VSNET = 0, ///< Visual Studio .Net like, always shows icon, only show the text of active tabs 0050 KDEV3ICON = 2, ///< KDevelop 3 like, always shows the text and icons 0051 STYLELAST = 0xffff, 0052 }; 0053 Q_ENUM(KMultiTabBarStyle) 0054 0055 /** 0056 * Create a KMultiTabBar with Left as KMultiTabBar position. 0057 * @param parent The parent of the widget. 0058 * @since 5.24 0059 */ 0060 explicit KMultiTabBar(QWidget *parent = nullptr); 0061 0062 explicit KMultiTabBar(KMultiTabBarPosition pos, QWidget *parent = nullptr); 0063 ~KMultiTabBar() override; 0064 0065 /** 0066 * append a new button to the button area. The button can later on be accessed with button(ID) 0067 * eg for connecting signals to it 0068 * @param icon a icon for the button 0069 * @param id an arbitrary ID value. It will be emitted in the clicked signal for identifying the button 0070 * if more than one button is connected to a signals. 0071 * @param popup A popup menu which should be displayed if the button is clicked 0072 * @param not_used_yet will be used for a popup text in the future 0073 * @since 5.13 0074 */ 0075 int appendButton(const QIcon &icon, int id = -1, QMenu *popup = nullptr, const QString ¬_used_yet = QString()); 0076 0077 #if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(5, 13) 0078 /** 0079 * append a new button to the button area. The button can later on be accessed with button(ID) 0080 * eg for connecting signals to it 0081 * 0082 * @param pic a pixmap for the button 0083 * @param id an arbitrary ID value. It will be emitted in the clicked signal for identifying the button 0084 * if more than one button is connected to a signals. 0085 * @param popup A popup menu which should be displayed if the button is clicked 0086 * @param not_used_yet will be used for a popup text in the future 0087 * 0088 * @deprecated Since 5.13, use appendButton(const QIcon &, int, QMenu *, const QString &) 0089 */ 0090 KWIDGETSADDONS_DEPRECATED_VERSION(5, 13, "Use KMultiTabBar::appendButton(const QIcon&, ...)") 0091 int appendButton(const QPixmap &pic, int id = -1, QMenu *popup = nullptr, const QString ¬_used_yet = QString()); 0092 #endif 0093 0094 /** 0095 * remove a button with the given ID 0096 */ 0097 void removeButton(int id); 0098 0099 /** 0100 * append a new tab to the tab area. It can be accessed lateron with tabb(id); 0101 * @param icon a icon for the tab 0102 * @param id an arbitrary ID which can be used later on to identify the tab 0103 * @param text if a mode with text is used it will be the tab text, otherwise a mouse over hint 0104 * @since 5.13 0105 */ 0106 int appendTab(const QIcon &icon, int id = -1, const QString &text = QString()); 0107 0108 #if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(5, 13) 0109 /** 0110 * append a new tab to the tab area. It can be accessed lateron with tabb(id); 0111 * 0112 * @param pic a bitmap for the tab 0113 * @param id an arbitrary ID which can be used later on to identify the tab 0114 * @param text if a mode with text is used it will be the tab text, otherwise a mouse over hint 0115 * 0116 * @deprecated Since 5.13, use appendTab(const QIcon &, int, const QString &) 0117 */ 0118 KWIDGETSADDONS_DEPRECATED_VERSION(5, 13, "Use KMultiTabBar::appendTab(const QIcon&, ...)") 0119 int appendTab(const QPixmap &pic, int id = -1, const QString &text = QString()); 0120 #endif 0121 0122 /** 0123 * remove a tab with a given ID 0124 */ 0125 void removeTab(int id); 0126 /** 0127 * set a tab to "raised" 0128 * @param id The ID of the tab to manipulate 0129 * @param state true == activated/raised, false == not active 0130 */ 0131 void setTab(int id, bool state); 0132 /** 0133 * return the state of a tab, identified by its ID 0134 */ 0135 bool isTabRaised(int id) const; 0136 /** 0137 * get a pointer to a button within the button area identified by its ID 0138 */ 0139 class KMultiTabBarButton *button(int id) const; 0140 0141 /** 0142 * get a pointer to a tab within the tab area, identified by its ID 0143 */ 0144 class KMultiTabBarTab *tab(int id) const; 0145 0146 /** 0147 * set the real position of the widget. 0148 * @param pos if the mode is horizontal, only use top, bottom, if it is vertical use left or right 0149 */ 0150 void setPosition(KMultiTabBarPosition pos); 0151 0152 /** 0153 * get the tabbar position. 0154 * @return position 0155 */ 0156 KMultiTabBarPosition position() const; 0157 0158 /** 0159 * set the display style of the tabs 0160 */ 0161 void setStyle(KMultiTabBarStyle style); 0162 0163 /** 0164 * get the display style of the tabs 0165 * @return display style 0166 */ 0167 KMultiTabBarStyle tabStyle() const; 0168 0169 protected: 0170 friend class KMultiTabBarButton; 0171 virtual void fontChange(const QFont &); 0172 void updateSeparator(); 0173 0174 private: 0175 std::unique_ptr<class KMultiTabBarPrivate> const d; 0176 }; 0177 0178 /** 0179 * @class KMultiTabBarButton kmultitabbar.h KMultiTabBarButton 0180 * 0181 * Use KMultiTabBar::appendButton to append a button, which creates a KMultiTabBarButton instance 0182 */ 0183 class KWIDGETSADDONS_EXPORT KMultiTabBarButton : public QPushButton 0184 { 0185 Q_OBJECT 0186 public: 0187 int id() const; 0188 ~KMultiTabBarButton() override; 0189 0190 public Q_SLOTS: 0191 void setText(const QString &text); 0192 0193 Q_SIGNALS: 0194 /** 0195 * this is emitted if the button is clicked 0196 * @param id the ID identifying the button 0197 */ 0198 void clicked(int id); 0199 protected Q_SLOTS: 0200 virtual void slotClicked(); 0201 0202 protected: 0203 void hideEvent(class QHideEvent *) override; 0204 void showEvent(class QShowEvent *) override; 0205 void paintEvent(class QPaintEvent *) override; 0206 0207 /** 0208 * Should not be created directly. Use KMultiTabBar::appendButton 0209 */ 0210 KMultiTabBarButton(const QIcon &icon, const QString &, int id, QWidget *parent); 0211 0212 #if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(5, 72) 0213 /** 0214 * Should not be created directly. Use KMultiTabBar::appendButton 0215 */ 0216 KWIDGETSADDONS_DEPRECATED_VERSION(5, 72, "Use overload with QIcon") 0217 KMultiTabBarButton(const QPixmap &pic, const QString &, int id, QWidget *parent); 0218 #endif 0219 private: 0220 friend class KMultiTabBar; 0221 0222 int m_id; 0223 std::unique_ptr<class KMultiTabBarButtonPrivate> const d; 0224 }; 0225 0226 /** 0227 * @class KMultiTabBarTab kmultitabbar.h KMultiTabBarTab 0228 * 0229 * Use KMultiTabBar::appendTab to append a tab, which creates a KMultiTabBarTab instance 0230 */ 0231 class KWIDGETSADDONS_EXPORT KMultiTabBarTab : public KMultiTabBarButton 0232 { 0233 Q_OBJECT 0234 public: 0235 ~KMultiTabBarTab() override; 0236 QSize sizeHint() const override; 0237 QSize minimumSizeHint() const override; 0238 0239 public Q_SLOTS: 0240 /** 0241 * this is used internally, but can be used by the user, if (s)he wants to 0242 * It the according call of KMultiTabBar is invoked though this modifications will be overwritten 0243 */ 0244 void setPosition(KMultiTabBar::KMultiTabBarPosition); 0245 0246 /** 0247 * this is used internally, but can be used by the user, if (s)he wants to 0248 * It the according call of KMultiTabBar is invoked though this modifications will be overwritten 0249 */ 0250 void setStyle(KMultiTabBar::KMultiTabBarStyle); 0251 0252 /** 0253 * set the active state of the tab 0254 * @param state true==active false==not active 0255 */ 0256 void setState(bool state); 0257 0258 #if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(5, 72) 0259 KWIDGETSADDONS_DEPRECATED_VERSION(5, 72, "Use KMultiTabBar::setIcon(const QIcon&)") 0260 void setIcon(const QString &); 0261 #endif 0262 #if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(5, 72) 0263 KWIDGETSADDONS_DEPRECATED_VERSION(5, 72, "Use KMultiTabBar::setIcon(const QIcon&)") 0264 void setIcon(const QPixmap &); 0265 #endif 0266 public: 0267 using KMultiTabBarButton::setIcon; 0268 0269 protected: 0270 void paintEvent(QPaintEvent *) override; 0271 0272 private: 0273 KMultiTabBar::KMultiTabBarPosition m_position; 0274 KMultiTabBar::KMultiTabBarStyle m_style; 0275 0276 KWIDGETSADDONS_NO_EXPORT void computeMargins(int *hMargin, int *vMargin) const; 0277 KWIDGETSADDONS_NO_EXPORT QSize computeSizeHint(bool withText) const; 0278 KWIDGETSADDONS_NO_EXPORT bool shouldDrawText() const; 0279 KWIDGETSADDONS_NO_EXPORT bool isVertical() const; 0280 #if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(5, 72) 0281 KWIDGETSADDONS_NO_EXPORT QPixmap iconPixmap() const; 0282 #endif 0283 0284 KWIDGETSADDONS_NO_EXPORT void initStyleOption(QStyleOptionToolButton *opt) const; 0285 0286 friend class KMultiTabBarInternal; 0287 /** 0288 * This class should never be created except with the appendTab call of KMultiTabBar 0289 */ 0290 KWIDGETSADDONS_NO_EXPORT 0291 KMultiTabBarTab(const QIcon &icon, const QString &, int id, QWidget *parent, KMultiTabBar::KMultiTabBarPosition pos, KMultiTabBar::KMultiTabBarStyle style); 0292 #if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(5, 72) 0293 /** 0294 * This class should never be created except with the appendTab call of KMultiTabBar 0295 */ 0296 KWIDGETSADDONS_NO_EXPORT 0297 KWIDGETSADDONS_DEPRECATED_VERSION(5, 72, "Use overload with QIcon") 0298 KMultiTabBarTab(const QPixmap &pic, 0299 const QString &, 0300 int id, 0301 QWidget *parent, 0302 KMultiTabBar::KMultiTabBarPosition pos, 0303 KMultiTabBar::KMultiTabBarStyle style); 0304 #endif 0305 std::unique_ptr<class KMultiTabBarTabPrivate> const d; 0306 }; 0307 0308 #endif