qtabwidget.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 QTABWIDGET_H
  40. #define QTABWIDGET_H
  41. #include <QtWidgets/qwidget.h>
  42. #include <QtGui/qicon.h>
  43. QT_BEGIN_NAMESPACE
  44. #ifndef QT_NO_TABWIDGET
  45. class QTabBar;
  46. class QTabWidgetPrivate;
  47. class QStyleOptionTabWidgetFrame;
  48. class Q_WIDGETS_EXPORT QTabWidget : public QWidget
  49. {
  50. Q_OBJECT
  51. Q_PROPERTY(TabPosition tabPosition READ tabPosition WRITE setTabPosition)
  52. Q_PROPERTY(TabShape tabShape READ tabShape WRITE setTabShape)
  53. Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
  54. Q_PROPERTY(int count READ count)
  55. Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
  56. Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode)
  57. Q_PROPERTY(bool usesScrollButtons READ usesScrollButtons WRITE setUsesScrollButtons)
  58. Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode)
  59. Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable)
  60. Q_PROPERTY(bool movable READ isMovable WRITE setMovable)
  61. Q_PROPERTY(bool tabBarAutoHide READ tabBarAutoHide WRITE setTabBarAutoHide)
  62. public:
  63. explicit QTabWidget(QWidget *parent = Q_NULLPTR);
  64. ~QTabWidget();
  65. int addTab(QWidget *widget, const QString &);
  66. int addTab(QWidget *widget, const QIcon& icon, const QString &label);
  67. int insertTab(int index, QWidget *widget, const QString &);
  68. int insertTab(int index, QWidget *widget, const QIcon& icon, const QString &label);
  69. void removeTab(int index);
  70. bool isTabEnabled(int index) const;
  71. void setTabEnabled(int index, bool);
  72. QString tabText(int index) const;
  73. void setTabText(int index, const QString &);
  74. QIcon tabIcon(int index) const;
  75. void setTabIcon(int index, const QIcon & icon);
  76. #ifndef QT_NO_TOOLTIP
  77. void setTabToolTip(int index, const QString & tip);
  78. QString tabToolTip(int index) const;
  79. #endif
  80. #ifndef QT_NO_WHATSTHIS
  81. void setTabWhatsThis(int index, const QString &text);
  82. QString tabWhatsThis(int index) const;
  83. #endif
  84. int currentIndex() const;
  85. QWidget *currentWidget() const;
  86. QWidget *widget(int index) const;
  87. int indexOf(QWidget *widget) const;
  88. int count() const;
  89. enum TabPosition { North, South, West, East };
  90. Q_ENUM(TabPosition)
  91. TabPosition tabPosition() const;
  92. void setTabPosition(TabPosition);
  93. bool tabsClosable() const;
  94. void setTabsClosable(bool closeable);
  95. bool isMovable() const;
  96. void setMovable(bool movable);
  97. enum TabShape { Rounded, Triangular };
  98. Q_ENUM(TabShape)
  99. TabShape tabShape() const;
  100. void setTabShape(TabShape s);
  101. QSize sizeHint() const Q_DECL_OVERRIDE;
  102. QSize minimumSizeHint() const Q_DECL_OVERRIDE;
  103. int heightForWidth(int width) const Q_DECL_OVERRIDE;
  104. bool hasHeightForWidth() const Q_DECL_OVERRIDE;
  105. void setCornerWidget(QWidget * w, Qt::Corner corner = Qt::TopRightCorner);
  106. QWidget * cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const;
  107. Qt::TextElideMode elideMode() const;
  108. void setElideMode(Qt::TextElideMode);
  109. QSize iconSize() const;
  110. void setIconSize(const QSize &size);
  111. bool usesScrollButtons() const;
  112. void setUsesScrollButtons(bool useButtons);
  113. bool documentMode() const;
  114. void setDocumentMode(bool set);
  115. bool tabBarAutoHide() const;
  116. void setTabBarAutoHide(bool enabled);
  117. void clear();
  118. QTabBar* tabBar() const;
  119. public Q_SLOTS:
  120. void setCurrentIndex(int index);
  121. void setCurrentWidget(QWidget *widget);
  122. Q_SIGNALS:
  123. void currentChanged(int index);
  124. void tabCloseRequested(int index);
  125. void tabBarClicked(int index);
  126. void tabBarDoubleClicked(int index);
  127. protected:
  128. virtual void tabInserted(int index);
  129. virtual void tabRemoved(int index);
  130. void showEvent(QShowEvent *) Q_DECL_OVERRIDE;
  131. void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
  132. void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE;
  133. void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
  134. void setTabBar(QTabBar *);
  135. void changeEvent(QEvent *) Q_DECL_OVERRIDE;
  136. bool event(QEvent *) Q_DECL_OVERRIDE;
  137. void initStyleOption(QStyleOptionTabWidgetFrame *option) const;
  138. private:
  139. Q_DECLARE_PRIVATE(QTabWidget)
  140. Q_DISABLE_COPY(QTabWidget)
  141. Q_PRIVATE_SLOT(d_func(), void _q_showTab(int))
  142. Q_PRIVATE_SLOT(d_func(), void _q_removeTab(int))
  143. Q_PRIVATE_SLOT(d_func(), void _q_tabMoved(int, int))
  144. void setUpLayout(bool = false);
  145. };
  146. #endif // QT_NO_TABWIDGET
  147. QT_END_NAMESPACE
  148. #endif // QTABWIDGET_H