qtabbar.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtWidgets module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QTABBAR_H
  40. #define QTABBAR_H
  41. #include <QtWidgets/qwidget.h>
  42. QT_BEGIN_NAMESPACE
  43. #ifndef QT_NO_TABBAR
  44. class QIcon;
  45. class QTabBarPrivate;
  46. class QStyleOptionTab;
  47. class Q_WIDGETS_EXPORT QTabBar: public QWidget
  48. {
  49. Q_OBJECT
  50. Q_PROPERTY(Shape shape READ shape WRITE setShape)
  51. Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
  52. Q_PROPERTY(int count READ count)
  53. Q_PROPERTY(bool drawBase READ drawBase WRITE setDrawBase)
  54. Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
  55. Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode)
  56. Q_PROPERTY(bool usesScrollButtons READ usesScrollButtons WRITE setUsesScrollButtons)
  57. Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable)
  58. Q_PROPERTY(SelectionBehavior selectionBehaviorOnRemove READ selectionBehaviorOnRemove WRITE setSelectionBehaviorOnRemove)
  59. Q_PROPERTY(bool expanding READ expanding WRITE setExpanding)
  60. Q_PROPERTY(bool movable READ isMovable WRITE setMovable)
  61. Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode)
  62. Q_PROPERTY(bool autoHide READ autoHide WRITE setAutoHide)
  63. Q_PROPERTY(bool changeCurrentOnDrag READ changeCurrentOnDrag WRITE setChangeCurrentOnDrag)
  64. public:
  65. explicit QTabBar(QWidget *parent = Q_NULLPTR);
  66. ~QTabBar();
  67. enum Shape { RoundedNorth, RoundedSouth, RoundedWest, RoundedEast,
  68. TriangularNorth, TriangularSouth, TriangularWest, TriangularEast
  69. };
  70. Q_ENUM(Shape)
  71. enum ButtonPosition {
  72. LeftSide,
  73. RightSide
  74. };
  75. enum SelectionBehavior {
  76. SelectLeftTab,
  77. SelectRightTab,
  78. SelectPreviousTab
  79. };
  80. Shape shape() const;
  81. void setShape(Shape shape);
  82. int addTab(const QString &text);
  83. int addTab(const QIcon &icon, const QString &text);
  84. int insertTab(int index, const QString &text);
  85. int insertTab(int index, const QIcon&icon, const QString &text);
  86. void removeTab(int index);
  87. void moveTab(int from, int to);
  88. bool isTabEnabled(int index) const;
  89. void setTabEnabled(int index, bool);
  90. QString tabText(int index) const;
  91. void setTabText(int index, const QString &text);
  92. QColor tabTextColor(int index) const;
  93. void setTabTextColor(int index, const QColor &color);
  94. QIcon tabIcon(int index) const;
  95. void setTabIcon(int index, const QIcon &icon);
  96. Qt::TextElideMode elideMode() const;
  97. void setElideMode(Qt::TextElideMode);
  98. #ifndef QT_NO_TOOLTIP
  99. void setTabToolTip(int index, const QString &tip);
  100. QString tabToolTip(int index) const;
  101. #endif
  102. #ifndef QT_NO_WHATSTHIS
  103. void setTabWhatsThis(int index, const QString &text);
  104. QString tabWhatsThis(int index) const;
  105. #endif
  106. void setTabData(int index, const QVariant &data);
  107. QVariant tabData(int index) const;
  108. QRect tabRect(int index) const;
  109. int tabAt(const QPoint &pos) const;
  110. int currentIndex() const;
  111. int count() const;
  112. QSize sizeHint() const Q_DECL_OVERRIDE;
  113. QSize minimumSizeHint() const Q_DECL_OVERRIDE;
  114. void setDrawBase(bool drawTheBase);
  115. bool drawBase() const;
  116. QSize iconSize() const;
  117. void setIconSize(const QSize &size);
  118. bool usesScrollButtons() const;
  119. void setUsesScrollButtons(bool useButtons);
  120. bool tabsClosable() const;
  121. void setTabsClosable(bool closable);
  122. void setTabButton(int index, ButtonPosition position, QWidget *widget);
  123. QWidget *tabButton(int index, ButtonPosition position) const;
  124. SelectionBehavior selectionBehaviorOnRemove() const;
  125. void setSelectionBehaviorOnRemove(SelectionBehavior behavior);
  126. bool expanding() const;
  127. void setExpanding(bool enabled);
  128. bool isMovable() const;
  129. void setMovable(bool movable);
  130. bool documentMode() const;
  131. void setDocumentMode(bool set);
  132. bool autoHide() const;
  133. void setAutoHide(bool hide);
  134. bool changeCurrentOnDrag() const;
  135. void setChangeCurrentOnDrag(bool change);
  136. public Q_SLOTS:
  137. void setCurrentIndex(int index);
  138. Q_SIGNALS:
  139. void currentChanged(int index);
  140. void tabCloseRequested(int index);
  141. void tabMoved(int from, int to);
  142. void tabBarClicked(int index);
  143. void tabBarDoubleClicked(int index);
  144. protected:
  145. virtual QSize tabSizeHint(int index) const;
  146. virtual QSize minimumTabSizeHint(int index) const;
  147. virtual void tabInserted(int index);
  148. virtual void tabRemoved(int index);
  149. virtual void tabLayoutChange();
  150. bool event(QEvent *) Q_DECL_OVERRIDE;
  151. void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
  152. void showEvent(QShowEvent *) Q_DECL_OVERRIDE;
  153. void hideEvent(QHideEvent *) Q_DECL_OVERRIDE;
  154. void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
  155. void mousePressEvent (QMouseEvent *) Q_DECL_OVERRIDE;
  156. void mouseMoveEvent (QMouseEvent *) Q_DECL_OVERRIDE;
  157. void mouseReleaseEvent (QMouseEvent *) Q_DECL_OVERRIDE;
  158. #ifndef QT_NO_WHEELEVENT
  159. void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
  160. #endif
  161. void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE;
  162. void changeEvent(QEvent *) Q_DECL_OVERRIDE;
  163. void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
  164. void initStyleOption(QStyleOptionTab *option, int tabIndex) const;
  165. #ifndef QT_NO_ACCESSIBILITY
  166. friend class QAccessibleTabBar;
  167. #endif
  168. private:
  169. Q_DISABLE_COPY(QTabBar)
  170. Q_DECLARE_PRIVATE(QTabBar)
  171. Q_PRIVATE_SLOT(d_func(), void _q_scrollTabs())
  172. Q_PRIVATE_SLOT(d_func(), void _q_closeTab())
  173. };
  174. #endif // QT_NO_TABBAR
  175. QT_END_NAMESPACE
  176. #endif // QTABBAR_H