File indexing completed on 2024-04-21 04:58:24
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 2003 Stephan Binner <binner@kde.org> 0003 SPDX-FileCopyrightText: 2003 Zack Rusin <zack@kde.org> 0004 SPDX-FileCopyrightText: 2009 Urs Wolfer <uwolfer @ kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef KTABWIDGET_H 0010 #define KTABWIDGET_H 0011 0012 #include <QTabWidget> 0013 #include <konqprivate_export.h> 0014 0015 class QTab; 0016 0017 /** 0018 * \brief A widget containing multiple tabs 0019 * 0020 * It extends the Qt QTabWidget, providing extra features such as automatic resizing of tabs, and moving tabs. 0021 * 0022 * See also the QTabWidget documentation. 0023 */ 0024 class KONQ_TESTS_EXPORT KTabWidget : public QTabWidget 0025 { 0026 Q_OBJECT 0027 Q_PROPERTY(bool automaticResizeTabs READ automaticResizeTabs WRITE setAutomaticResizeTabs) 0028 0029 public: 0030 0031 /** 0032 * Creates a new tab widget. 0033 * 0034 * @param parent The parent widgets. 0035 * @param flags The Qt window flags @see QWidget. 0036 */ 0037 explicit KTabWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = {}); 0038 0039 /** 0040 * Destroys the tab widget. 0041 */ 0042 ~KTabWidget() override; 0043 0044 /** 0045 * Returns true if calling setTitle() will resize tabs 0046 * to the width of the tab bar. 0047 */ 0048 bool automaticResizeTabs() const; 0049 0050 /** 0051 * Reimplemented for internal reasons. 0052 */ 0053 QString tabText(int) const; // but it's not virtual... 0054 0055 /** 0056 * Reimplemented for internal reasons. 0057 */ 0058 void setTabText(int, const QString &); 0059 0060 public Q_SLOTS: 0061 /** 0062 * Removes the widget, reimplemented for 0063 * internal reasons (keeping labels in sync). 0064 */ 0065 virtual void removeTab(int index); // but it's not virtual in QTabWidget... 0066 0067 /** 0068 * If \a enable is true, tabs will be resized to the width of the tab bar. 0069 * 0070 * Does not work reliably with "QTabWidget* foo=new KTabWidget()" and if 0071 * you change tabs via the tabbar or by accessing tabs directly. 0072 */ 0073 void setAutomaticResizeTabs(bool enable); 0074 0075 Q_SIGNALS: 0076 /** 0077 * Connect to this and set accept to true if you can and want to decode the event. 0078 */ 0079 void testCanDecode(const QDragMoveEvent *e, bool &accept /* result */); 0080 0081 /** 0082 * Received an event in the empty space beside tabbar. Usually creates a new tab. 0083 * This signal is only possible after testCanDecode and positive accept result. 0084 */ 0085 void receivedDropEvent(QDropEvent *); 0086 0087 /** 0088 * Received an drop event on given widget's tab. 0089 * This signal is only possible after testCanDecode and positive accept result. 0090 */ 0091 void receivedDropEvent(QWidget *, QDropEvent *); 0092 0093 /** 0094 * Request to start a drag operation on the given tab. 0095 */ 0096 void initiateDrag(QWidget *); 0097 0098 /** 0099 * The right mouse button was pressed over empty space besides tabbar. 0100 */ 0101 void contextMenu(const QPoint &); 0102 0103 /** 0104 * The right mouse button was pressed over a widget. 0105 */ 0106 void contextMenu(QWidget *, const QPoint &); 0107 0108 /** 0109 * A double left mouse button click was performed over empty space besides tabbar. 0110 * The signal is emitted on the second press of the mouse button, before the release. 0111 */ 0112 void mouseDoubleClick(); 0113 0114 /** 0115 * A double left mouse button click was performed over the widget. 0116 * The signal is emitted on the second press of the mouse button, before the release. 0117 */ 0118 void mouseDoubleClick(QWidget *); 0119 0120 /** 0121 * A middle mouse button click was performed over empty space besides tabbar. 0122 * The signal is emitted on the release of the mouse button. 0123 */ 0124 void mouseMiddleClick(); 0125 0126 /** 0127 * A middle mouse button click was performed over the widget. 0128 * The signal is emitted on the release of the mouse button. 0129 */ 0130 void mouseMiddleClick(QWidget *); 0131 0132 protected: 0133 void mouseDoubleClickEvent(QMouseEvent *) override; 0134 void mousePressEvent(QMouseEvent *) override; 0135 void mouseReleaseEvent(QMouseEvent *) override; 0136 void dragEnterEvent(QDragEnterEvent *) override; 0137 void dragMoveEvent(QDragMoveEvent *) override; 0138 void dropEvent(QDropEvent *) override; 0139 int tabBarWidthForMaxChars(int); 0140 #ifndef QT_NO_WHEELEVENT 0141 void wheelEvent(QWheelEvent *) override; 0142 #endif 0143 void resizeEvent(QResizeEvent *) override; 0144 void tabInserted(int) override; 0145 0146 protected Q_SLOTS: 0147 virtual void receivedDropEvent(int, QDropEvent *); 0148 virtual void initiateDrag(int); 0149 virtual void contextMenu(int, const QPoint &); 0150 virtual void mouseDoubleClick(int); 0151 virtual void mouseMiddleClick(int); 0152 #ifndef QT_NO_WHEELEVENT 0153 virtual void wheelDelta(int); 0154 #endif 0155 0156 private: 0157 class Private; 0158 Private *const d; 0159 0160 Q_PRIVATE_SLOT(d, void slotTabMoved(int, int)) 0161 }; 0162 0163 #endif