File indexing completed on 2024-03-24 15:27:46
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 2003 Stephan Binner <binner@kde.org> 0003 Copyright (C) 2003 Zack Rusin <zack@kde.org> 0004 Copyright (C) 2009 Urs Wolfer <uwolfer @ kde.org> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Library General Public 0008 License as published by the Free Software Foundation; either 0009 version 2 of the License, or (at your option) any later version. 0010 0011 This library is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 Library General Public License for more details. 0015 0016 You should have received a copy of the GNU Library General Public License 0017 along with this library; see the file COPYING.LIB. If not, write to 0018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #ifndef KTABBAR_H 0023 #define KTABBAR_H 0024 0025 #include <kdelibs4support_export.h> 0026 0027 #include <QTabBar> 0028 0029 /** 0030 * A QTabBar with extended features. 0031 * 0032 * \image html ktabbar.png "KDE Tab Bar" 0033 */ 0034 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KTabBar: public QTabBar //krazy:exclude=qclasses 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 /** 0040 * Creates a new tab bar. 0041 * 0042 * @param parent The parent widget. 0043 */ 0044 KDELIBS4SUPPORT_DEPRECATED explicit KTabBar(QWidget *parent = nullptr); 0045 0046 /** 0047 * Destroys the tab bar. 0048 */ 0049 ~KTabBar() override; 0050 0051 /** 0052 * Sets the tab reordering enabled or disabled. If enabled, 0053 * the user can reorder the tabs by drag and drop the tab 0054 * headers with the middle mouse button. 0055 * 0056 * @deprecated Use QTabBar::setMovable() instead. 0057 * 0058 * Note, however, that QTabBar::setMovable(true) disables 0059 * dragging tabs out of the KTabBar (e.g., dragging the tab 0060 * URL from Konqueror to another application)! 0061 */ 0062 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0063 KDELIBS4SUPPORT_DEPRECATED void setTabReorderingEnabled(bool enable); 0064 #endif 0065 0066 /** 0067 * Returns whether tab reordering is enabled. 0068 * 0069 * @deprecated Use QTabBar::isMovable() instead. 0070 */ 0071 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0072 KDELIBS4SUPPORT_DEPRECATED bool isTabReorderingEnabled() const; 0073 #endif 0074 0075 /** 0076 * If enabled, a close button is shown above the tab icon. 0077 * The signal KTabBar::closeRequest() is emitted, if the 0078 * close button has been clicked. Note that the tab must have 0079 * an icon to use this feature. 0080 * 0081 * @deprecated Use QTabBar::setTabsClosable() instead. 0082 */ 0083 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0084 KDELIBS4SUPPORT_DEPRECATED void setHoverCloseButton(bool); 0085 #endif 0086 0087 /** @deprecated Use QTabBar::tabsClosable() instead. */ 0088 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0089 KDELIBS4SUPPORT_DEPRECATED bool hoverCloseButton() const; 0090 #endif 0091 0092 /** 0093 * If enabled, the close button cannot get clicked until a 0094 * minor delay has been passed. This prevents that user 0095 * accidentally closes a tab. 0096 * 0097 * @deprecated Use QTabBar::setTabsClosable() instead. 0098 */ 0099 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0100 KDELIBS4SUPPORT_DEPRECATED void setHoverCloseButtonDelayed(bool); 0101 #endif 0102 0103 /** @deprecated Use QTabBar::tabsClosable() instead. */ 0104 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0105 KDELIBS4SUPPORT_DEPRECATED bool hoverCloseButtonDelayed() const; 0106 #endif 0107 0108 /** 0109 * If enabled, a close button is available for each tab. The 0110 * signal KTabBar::closeRequest() is emitted, if the close button 0111 * has been clicked. 0112 * 0113 * @since 4.1 0114 * 0115 * @deprecated Use QTabBar::setTabsClosable() instead. 0116 */ 0117 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0118 KDELIBS4SUPPORT_DEPRECATED void setCloseButtonEnabled(bool); 0119 #endif 0120 0121 /** 0122 * Returns true if the close button is shown on tabs. 0123 * 0124 * @since 4.1 0125 * 0126 * @deprecated Use QTabBar::tabsClosable() instead. 0127 */ 0128 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0129 KDELIBS4SUPPORT_DEPRECATED bool isCloseButtonEnabled() const; 0130 #endif 0131 0132 /** 0133 * Sets the 'activate previous tab on close' feature enabled 0134 * or disabled. If enabled, as soon as you close a tab, the 0135 * previously selected tab is activated again. 0136 * 0137 * @deprecated Use QTabBar::setSelectionBehaviorOnRemove() instead. 0138 */ 0139 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0140 KDELIBS4SUPPORT_DEPRECATED void setTabCloseActivatePrevious(bool); 0141 #endif 0142 0143 /** 0144 * Returns whether the 'activate previous tab on close' feature 0145 * is enabled. 0146 * 0147 * @deprecated Use QTabBar::selectionBehaviorOnRemove() instead. 0148 */ 0149 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0150 KDELIBS4SUPPORT_DEPRECATED bool tabCloseActivatePrevious() const; 0151 #endif 0152 0153 /** 0154 * Selects the tab which has a tab header at 0155 * given @param position. 0156 * 0157 * @param position the coordinates of the tab 0158 */ 0159 int selectTab(const QPoint &position) const; 0160 0161 Q_SIGNALS: 0162 /** 0163 * A right mouse button click was performed over the tab with the @param index. 0164 * The signal is emitted on the press of the mouse button. 0165 */ 0166 void contextMenu(int index, const QPoint &globalPos); 0167 /** 0168 * A right mouse button click was performed over the empty area on the tab bar. 0169 * The signal is emitted on the press of the mouse button. 0170 */ 0171 void emptyAreaContextMenu(const QPoint &globalPos); 0172 /** @deprecated use tabDoubleClicked(int) and newTabRequest() instead. */ 0173 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0174 QT_MOC_COMPAT void mouseDoubleClick(int); 0175 #endif 0176 /** 0177 * A double left mouse button click was performed over the tab with the @param index. 0178 * The signal is emitted on the second press of the mouse button, before the release. 0179 */ 0180 void tabDoubleClicked(int index); 0181 /** 0182 * A double left mouse button click was performed over the empty area on the tab bar. 0183 * The signal is emitted on the second press of the mouse button, before the release. 0184 */ 0185 void newTabRequest(); 0186 /** 0187 * A double middle mouse button click was performed over the tab with the @param index. 0188 * The signal is emitted on the release of the mouse button. 0189 */ 0190 void mouseMiddleClick(int index); 0191 void initiateDrag(int); 0192 void testCanDecode(const QDragMoveEvent *, bool &); 0193 void receivedDropEvent(int, QDropEvent *); 0194 /** 0195 * Used internally by KTabBar's/KTabWidget's middle-click tab moving mechanism. 0196 * Tells the KTabWidget which owns the KTabBar to move a tab. 0197 */ 0198 void moveTab(int, int); 0199 /** @deprecated Use QTabBar::tabCloseRequested(int) instead. */ 0200 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0201 QT_MOC_COMPAT void closeRequest(int); 0202 #endif 0203 #ifndef QT_NO_WHEELEVENT 0204 void wheelDelta(int); 0205 #endif 0206 0207 protected: 0208 void mouseDoubleClickEvent(QMouseEvent *event) override; 0209 void mousePressEvent(QMouseEvent *event) override; 0210 void mouseMoveEvent(QMouseEvent *event) override; 0211 void mouseReleaseEvent(QMouseEvent *event) override; 0212 #ifndef QT_NO_WHEELEVENT 0213 void wheelEvent(QWheelEvent *event) override; 0214 #endif 0215 0216 void dragEnterEvent(QDragEnterEvent *event) override; 0217 void dragMoveEvent(QDragMoveEvent *event) override; 0218 void dropEvent(QDropEvent *event) override; 0219 0220 void paintEvent(QPaintEvent *event) override; 0221 void leaveEvent(QEvent *event) override; 0222 QSize tabSizeHint(int index) const override; 0223 0224 protected Q_SLOTS: 0225 /** @deprecated */ 0226 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0227 QT_MOC_COMPAT void closeButtonClicked(); 0228 #endif 0229 /** @deprecated */ 0230 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED 0231 QT_MOC_COMPAT void enableCloseButton(); 0232 #endif 0233 virtual void activateDragSwitchTab(); 0234 0235 protected: 0236 void tabLayoutChange() override; 0237 0238 private: 0239 QPoint closeButtonPos(int tabIndex) const; 0240 QRect closeButtonRect(int tabIndex) const; 0241 0242 private: 0243 class Private; 0244 Private *const d; 0245 }; 0246 0247 #endif