dockareatabbar.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2020 Uwe Kindler
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of Qt Creator.
  7. **
  8. ** Commercial License Usage
  9. ** Licensees holding valid commercial Qt licenses may use this file in
  10. ** accordance with the commercial license agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and The Qt Company. For licensing terms
  13. ** and conditions see https://www.qt.io/terms-conditions. For further
  14. ** information use the contact form at https://www.qt.io/contact-us.
  15. **
  16. ** GNU Lesser General Public License Usage
  17. ** Alternatively, this file may be used under the terms of the GNU Lesser
  18. ** General Public License version 2.1 or (at your option) any later version.
  19. ** The licenses are as published by the Free Software Foundation
  20. ** and appearing in the file LICENSE.LGPLv21 included in the packaging
  21. ** of this file. Please review the following information to ensure
  22. ** the GNU Lesser General Public License version 2.1 requirements
  23. ** will be met: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.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 3 or (at your option) any later version
  28. ** approved by the KDE Free Qt Foundation. The licenses are as published by
  29. ** the Free Software Foundation and appearing in the file LICENSE.GPL3
  30. ** included in the packaging of this file. Please review the following
  31. ** information to ensure the GNU General Public License requirements will
  32. ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
  33. **
  34. ****************************************************************************/
  35. #pragma once
  36. #include "ads_globals.h"
  37. #include <QScrollArea>
  38. namespace ADS {
  39. class DockAreaWidget;
  40. class DockWidgetTab;
  41. struct DockAreaTabBarPrivate;
  42. class DockAreaTitleBar;
  43. class FloatingDockContainer;
  44. class AbstractFloatingWidget;
  45. /**
  46. * Custom tabbar implementation for tab area that is shown on top of a
  47. * dock area widget.
  48. * The tabbar displays the tab widgets of the contained dock widgets.
  49. * We cannot use QTabBar here because it does a lot of fancy animations
  50. * that will crash the application if a tab is removed while the animation
  51. * has not finished. And we need to remove a tab, if the user drags a
  52. * a dock widget out of a group of tabbed widgets
  53. */
  54. class ADS_EXPORT DockAreaTabBar : public QScrollArea
  55. {
  56. Q_OBJECT
  57. private:
  58. DockAreaTabBarPrivate *d; ///< private data (pimpl)
  59. friend struct DockAreaTabBarPrivate;
  60. friend class DockAreaTitleBar;
  61. void onTabClicked();
  62. void onTabCloseRequested();
  63. void onCloseOtherTabsRequested();
  64. void onTabWidgetMoved(const QPoint &globalPos);
  65. protected:
  66. virtual void wheelEvent(QWheelEvent *event) override;
  67. public:
  68. using Super = QScrollArea;
  69. /**
  70. * Default Constructor
  71. */
  72. DockAreaTabBar(DockAreaWidget *parent);
  73. /**
  74. * Virtual Destructor
  75. */
  76. virtual ~DockAreaTabBar() override;
  77. /**
  78. * Inserts the given dock widget tab at the given position.
  79. * Inserting a new tab at an index less than or equal to the current index
  80. * will increment the current index, but keep the current tab.
  81. */
  82. void insertTab(int Index, DockWidgetTab *tab);
  83. /**
  84. * Removes the given DockWidgetTab from the tabbar
  85. */
  86. void removeTab(DockWidgetTab *tab);
  87. /**
  88. * Returns the number of tabs in this tabbar
  89. */
  90. int count() const;
  91. /**
  92. * Returns the current index or -1 if no tab is selected
  93. */
  94. int currentIndex() const;
  95. /**
  96. * Returns the current tab or a nullptr if no tab is selected.
  97. */
  98. DockWidgetTab *currentTab() const;
  99. /**
  100. * Returns the tab with the given index
  101. */
  102. DockWidgetTab *tab(int index) const;
  103. /**
  104. * Filters the tab widget events
  105. */
  106. virtual bool eventFilter(QObject *watched, QEvent *event) override;
  107. /**
  108. * This function returns true if the tab is open, that means if it is
  109. * visible to the user. If the function returns false, the tab is
  110. * closed
  111. */
  112. bool isTabOpen(int index) const;
  113. /**
  114. * Overrides the minimumSizeHint() function of QScrollArea
  115. * The minimumSizeHint() is bigger than the sizeHint () for the scroll
  116. * area because even if the scrollbars are invisible, the required speace
  117. * is reserved in the minimumSizeHint(). This override simply returns
  118. * sizeHint();
  119. */
  120. virtual QSize minimumSizeHint() const override;
  121. /**
  122. * The function provides a sizeHint that matches the height of the
  123. * internal viewport.
  124. */
  125. virtual QSize sizeHint() const override;
  126. /**
  127. * This property sets the index of the tab bar's visible tab
  128. */
  129. void setCurrentIndex(int index);
  130. /**
  131. * This function will close the tab given in Index param.
  132. * Closing a tab means, the tab will be hidden, it will not be removed
  133. */
  134. void closeTab(int index);
  135. signals:
  136. /**
  137. * This signal is emitted when the tab bar's current tab is about to be changed. The new
  138. * current has the given index, or -1 if there isn't a new one.
  139. */
  140. void currentChanging(int index);
  141. /**
  142. * This signal is emitted when the tab bar's current tab changes. The new
  143. * current has the given index, or -1 if there isn't a new one
  144. */
  145. void currentChanged(int index);
  146. /**
  147. * This signal is emitted when user clicks on a tab
  148. */
  149. void tabBarClicked(int index);
  150. /**
  151. * This signal is emitted when the close button on a tab is clicked.
  152. * The index is the index that should be closed.
  153. */
  154. void tabCloseRequested(int index);
  155. /**
  156. * This signal is emitted if a tab has been closed
  157. */
  158. void tabClosed(int index);
  159. /**
  160. * This signal is emitted if a tab has been opened.
  161. * A tab is opened if it has been made visible
  162. */
  163. void tabOpened(int index);
  164. /**
  165. * This signal is emitted when the tab has moved the tab at index position
  166. * from to index position to.
  167. */
  168. void tabMoved(int from, int to);
  169. /**
  170. * This signal is emitted, just before the tab with the given index is
  171. * removed
  172. */
  173. void removingTab(int index);
  174. /**
  175. * This signal is emitted if a tab has been inserted
  176. */
  177. void tabInserted(int index);
  178. /**
  179. * This signal is emitted when a tab title elide state has been changed
  180. */
  181. void elidedChanged(bool elided);
  182. }; // class DockAreaTabBar
  183. } // namespace ADS