| 1 |
/* |
| 2 |
* libkysdk-qtwidgets's Library |
| 3 |
* |
| 4 |
* Copyright (C) 2023, KylinSoft Co., Ltd. |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 3 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* Authors: Zhenyu Wang <[email protected]> |
| 20 |
* |
| 21 |
*/ |
| 22 |
#ifndef KCUSTOMBAR_H |
| 23 |
#define KCUSTOMBAR_H |
| 24 |
|
| 25 |
#include <QIcon> |
| 26 |
#include <QLayoutItem> |
| 27 |
#include <QStyleOptionTab> |
| 28 |
#include <QTabBar> |
| 29 |
#include <QtWidgets/qtwidgetsglobal.h> |
| 30 |
#include <QtWidgets/qwidget.h> |
| 31 |
|
| 32 |
class KCustomTabBarPrivate; |
| 33 |
|
| 34 |
/** |
| 35 |
* @defgroup KCustomTabBar |
| 36 |
* @since 2.5.2.0 |
| 37 |
*/ |
| 38 |
|
| 39 |
class KCustomTabBar : public QWidget |
| 40 |
{ |
| 41 |
Q_OBJECT |
| 42 |
|
| 43 |
Q_PROPERTY(Shape shape READ shape WRITE setShape) |
| 44 |
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged) |
| 45 |
Q_PROPERTY(int count READ count) |
| 46 |
Q_PROPERTY(bool drawBase READ drawBase WRITE setDrawBase) |
| 47 |
Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) |
| 48 |
Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode) |
| 49 |
Q_PROPERTY(bool usesScrollButtons READ usesScrollButtons WRITE setUsesScrollButtons) |
| 50 |
Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable) |
| 51 |
Q_PROPERTY(SelectionBehavior selectionBehaviorOnRemove READ selectionBehaviorOnRemove WRITE setSelectionBehaviorOnRemove) |
| 52 |
Q_PROPERTY(bool expanding READ expanding WRITE setExpanding) |
| 53 |
Q_PROPERTY(bool movable READ isMovable WRITE setMovable) |
| 54 |
Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode) |
| 55 |
Q_PROPERTY(bool autoHide READ autoHide WRITE setAutoHide) |
| 56 |
Q_PROPERTY(bool changeCurrentOnDrag READ changeCurrentOnDrag WRITE setChangeCurrentOnDrag) |
| 57 |
|
| 58 |
public: |
| 59 |
explicit KCustomTabBar(QWidget *parent = nullptr); |
| 60 |
~KCustomTabBar(); |
| 61 |
|
| 62 |
enum Shape { RoundedNorth, |
| 63 |
RoundedSouth, |
| 64 |
RoundedWest, |
| 65 |
RoundedEast, |
| 66 |
TriangularNorth, |
| 67 |
TriangularSouth, |
| 68 |
TriangularWest, |
| 69 |
TriangularEast |
| 70 |
}; |
| 71 |
Q_ENUM(Shape) |
| 72 |
|
| 73 |
enum ButtonPosition { |
| 74 |
LeftSide, |
| 75 |
RightSide |
| 76 |
}; |
| 77 |
|
| 78 |
enum SelectionBehavior { |
| 79 |
SelectLeftTab, |
| 80 |
SelectRightTab, |
| 81 |
SelectPreviousTab |
| 82 |
}; |
| 83 |
|
| 84 |
Shape shape() const; |
| 85 |
void setShape(Shape shape); |
| 86 |
|
| 87 |
int addTab(const QString &text); |
| 88 |
int addTab(const QIcon &icon, const QString &text); |
| 89 |
|
| 90 |
int insertTab(int index, const QString &text); |
| 91 |
int insertTab(int index, const QIcon &icon, const QString &text); |
| 92 |
|
| 93 |
void removeTab(int index); |
| 94 |
void moveTab(int from, int to); |
| 95 |
|
| 96 |
bool isTabEnabled(int index) const; |
| 97 |
void setTabEnabled(int index, bool); |
| 98 |
|
| 99 |
QString tabText(int index) const; |
| 100 |
void setTabText(int index, const QString &text); |
| 101 |
|
| 102 |
void setTabContent(int index, const QString &text); |
| 103 |
|
| 104 |
QColor tabTextColor(int index) const; |
| 105 |
void setTabTextColor(int index, const QColor &color); |
| 106 |
|
| 107 |
QIcon tabIcon(int index) const; |
| 108 |
void setTabIcon(int index, const QIcon &icon); |
| 109 |
|
| 110 |
Qt::TextElideMode elideMode() const; |
| 111 |
void setElideMode(Qt::TextElideMode); |
| 112 |
|
| 113 |
// #ifndef QT_NO_TOOLTIP |
| 114 |
void setTabToolTip(int index, const QString &tip); |
| 115 |
QString tabToolTip(int index) const; |
| 116 |
// #endif |
| 117 |
|
| 118 |
// #if QT_CONFIG(whatsthis) |
| 119 |
void setTabWhatsThis(int index, const QString &text); |
| 120 |
QString tabWhatsThis(int index) const; |
| 121 |
// #endif |
| 122 |
|
| 123 |
void setTabData(int index, const QVariant &data); |
| 124 |
QVariant tabData(int index) const; |
| 125 |
|
| 126 |
QRect tabRect(int index) const; |
| 127 |
int tabAt(const QPoint &pos) const; |
| 128 |
|
| 129 |
int currentIndex() const; |
| 130 |
int count() const; |
| 131 |
|
| 132 |
QSize sizeHint() const override; |
| 133 |
QSize minimumSizeHint() const override; |
| 134 |
|
| 135 |
void setDrawBase(bool drawTheBase); |
| 136 |
bool drawBase() const; |
| 137 |
|
| 138 |
QSize iconSize() const; |
| 139 |
void setIconSize(const QSize &size); |
| 140 |
|
| 141 |
bool usesScrollButtons() const; |
| 142 |
void setUsesScrollButtons(bool useButtons); |
| 143 |
|
| 144 |
bool tabsClosable() const; |
| 145 |
void setTabsClosable(bool closable); |
| 146 |
|
| 147 |
void setTabButton(int index, ButtonPosition position, QWidget *widget); |
| 148 |
QWidget *tabButton(int index, ButtonPosition position) const; |
| 149 |
|
| 150 |
SelectionBehavior selectionBehaviorOnRemove() const; |
| 151 |
void setSelectionBehaviorOnRemove(SelectionBehavior behavior); |
| 152 |
|
| 153 |
bool expanding() const; |
| 154 |
void setExpanding(bool enabled); |
| 155 |
|
| 156 |
bool isMovable() const; |
| 157 |
void setMovable(bool movable); |
| 158 |
|
| 159 |
bool documentMode() const; |
| 160 |
void setDocumentMode(bool set); |
| 161 |
|
| 162 |
bool autoHide() const; |
| 163 |
void setAutoHide(bool hide); |
| 164 |
|
| 165 |
bool changeCurrentOnDrag() const; |
| 166 |
void setChangeCurrentOnDrag(bool change); |
| 167 |
|
| 168 |
// #ifndef QT_NO_ACCESSIBILITY |
| 169 |
QString accessibleTabName(int index) const; |
| 170 |
void setAccessibleTabName(int index, const QString &name); |
| 171 |
// #endif |
| 172 |
|
| 173 |
public Q_SLOTS: |
| 174 |
void setCurrentIndex(int index); |
| 175 |
// void scrollTabs(); |
| 176 |
void leftScrollTabs(); |
| 177 |
void rightScrollTabs(); |
| 178 |
void closeTab(); |
| 179 |
|
| 180 |
Q_SIGNALS: |
| 181 |
void currentChanged(int index); |
| 182 |
void tabCloseRequested(int index); |
| 183 |
void tabMoved(int from, int to); |
| 184 |
void tabBarClicked(int index); |
| 185 |
void tabBarDoubleClicked(int index); |
| 186 |
void leftBStatus(bool flag); |
| 187 |
void rightBStatus(bool flag); |
| 188 |
|
| 189 |
protected: |
| 190 |
virtual QSize tabSizeHint(int index) const; |
| 191 |
virtual QSize minimumTabSizeHint(int index) const; |
| 192 |
virtual void tabInserted(int index); |
| 193 |
virtual void tabRemoved(int index); |
| 194 |
virtual void tabLayoutChange(); |
| 195 |
|
| 196 |
bool event(QEvent *) override; |
| 197 |
void resizeEvent(QResizeEvent *) override; |
| 198 |
void showEvent(QShowEvent *) override; |
| 199 |
void hideEvent(QHideEvent *) override; |
| 200 |
void paintEvent(QPaintEvent *) override; |
| 201 |
void mousePressEvent(QMouseEvent *) override; |
| 202 |
void mouseMoveEvent(QMouseEvent *) override; |
| 203 |
void mouseReleaseEvent(QMouseEvent *) override; |
| 204 |
void wheelEvent(QWheelEvent *event) override; |
| 205 |
void keyPressEvent(QKeyEvent *) override; |
| 206 |
void changeEvent(QEvent *) override; |
| 207 |
void timerEvent(QTimerEvent *event) override; |
| 208 |
void initStyleOption(QStyleOptionTab *option, int tabIndex) const; |
| 209 |
|
| 210 |
// #ifndef QT_NO_ACCESSIBILITY |
| 211 |
// friend class QAccessibleTabBar; |
| 212 |
// #endif |
| 213 |
private: |
| 214 |
Q_DISABLE_COPY(KCustomTabBar) |
| 215 |
Q_DECLARE_PRIVATE(KCustomTabBar) |
| 216 |
KCustomTabBarPrivate *const d_ptr; |
| 217 |
}; |
| 218 |
|
| 219 |
#endif // QTABBAR_H |