dockareawidget.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 "dockwidget.h"
  38. #include <QFrame>
  39. class QXmlStreamWriter;
  40. class QAbstractButton;
  41. namespace ADS {
  42. struct DockAreaWidgetPrivate;
  43. class DockManager;
  44. class DockContainerWidget;
  45. class DockContainerWidgetPrivate;
  46. class DockAreaTitleBar;
  47. /**
  48. * DockAreaWidget manages multiple instances of DockWidgets.
  49. * It displays a title tab, which is clickable and will switch to
  50. * the contents associated to the title when clicked.
  51. */
  52. class ADS_EXPORT DockAreaWidget : public QFrame
  53. {
  54. Q_OBJECT
  55. private:
  56. DockAreaWidgetPrivate *d; ///< private data (pimpl)
  57. friend struct DockAreaWidgetPrivate;
  58. friend class DockContainerWidget;
  59. friend class DockContainerWidgetPrivate;
  60. friend class DockWidgetTab;
  61. friend struct DockWidgetPrivate;
  62. friend class DockWidget;
  63. friend struct DockManagerPrivate;
  64. friend class DockManager;
  65. void onTabCloseRequested(int index);
  66. /**
  67. * Reorder the index position of DockWidget at fromIndx to toIndex
  68. * if a tab in the tabbar is dragged from one index to another one
  69. */
  70. void reorderDockWidget(int fromIndex, int toIndex);
  71. protected:
  72. /**
  73. * Inserts a dock widget into dock area.
  74. * All dockwidgets in the dock area tabified in a stacked layout with tabs.
  75. * The index indicates the index of the new dockwidget in the tabbar and
  76. * in the stacked layout. If the Activate parameter is true, the new
  77. * DockWidget will be the active one in the stacked layout
  78. */
  79. void insertDockWidget(int index, DockWidget *dockWidget, bool activate = true);
  80. /**
  81. * Add a new dock widget to dock area.
  82. * All dockwidgets in the dock area tabified in a stacked layout with tabs
  83. */
  84. void addDockWidget(DockWidget *dockWidget);
  85. /**
  86. * Removes the given dock widget from the dock area
  87. */
  88. void removeDockWidget(DockWidget *dockWidget);
  89. /**
  90. * Called from dock widget if it is opened or closed
  91. */
  92. void toggleDockWidgetView(DockWidget *dockWidget, bool open);
  93. /**
  94. * This is a helper function to get the next open dock widget to activate
  95. * if the given DockWidget will be closed or removed.
  96. * The function returns the next widget that should be activated or
  97. * nullptr in case there are no more open widgets in this area.
  98. */
  99. DockWidget *nextOpenDockWidget(DockWidget *dockWidget) const;
  100. /**
  101. * Returns the index of the given DockWidget in the internal layout
  102. */
  103. int indexOf(DockWidget *dockWidget);
  104. /**
  105. * Call this function, if you already know, that the dock does not
  106. * contain any visible content (any open dock widgets).
  107. */
  108. void hideAreaWithNoVisibleContent();
  109. /**
  110. * Updates the dock area layout and components visibility
  111. */
  112. void updateTitleBarVisibility();
  113. /**
  114. * This is the internal private function for setting the current widget.
  115. * This function is called by the public setCurrentDockWidget() function
  116. * and by the dock manager when restoring the state
  117. */
  118. void internalSetCurrentDockWidget(DockWidget *dockWidget);
  119. /**
  120. * Marks tabs menu to update
  121. */
  122. void markTitleBarMenuOutdated();
  123. void toggleView(bool open);
  124. public:
  125. using Super = QFrame;
  126. /**
  127. * Default Constructor
  128. */
  129. DockAreaWidget(DockManager *dockManager, DockContainerWidget *parent);
  130. /**
  131. * Virtual Destructor
  132. */
  133. virtual ~DockAreaWidget() override;
  134. /**
  135. * Returns the dock manager object this dock area belongs to
  136. */
  137. DockManager *dockManager() const;
  138. /**
  139. * Returns the dock container widget this dock area widget belongs to or 0
  140. * if there is no
  141. */
  142. DockContainerWidget *dockContainer() const;
  143. /**
  144. * Returns the rectangle of the title area
  145. */
  146. QRect titleBarGeometry() const;
  147. /**
  148. * Returns the rectangle of the content
  149. */
  150. QRect contentAreaGeometry() const;
  151. /**
  152. * Returns the number of dock widgets in this area
  153. */
  154. int dockWidgetsCount() const;
  155. /**
  156. * Returns a list of all dock widgets in this dock area.
  157. * This list contains open and closed dock widgets.
  158. */
  159. QList<DockWidget *> dockWidgets() const;
  160. /**
  161. * Returns the number of open dock widgets in this area
  162. */
  163. int openDockWidgetsCount() const;
  164. /**
  165. * Returns a list of dock widgets that are not closed.
  166. */
  167. QList<DockWidget *> openedDockWidgets() const;
  168. /**
  169. * Returns a dock widget by its index
  170. */
  171. DockWidget *dockWidget(int indexOf) const;
  172. /**
  173. * Returns the index of the current active dock widget or -1 if there
  174. * are is no active dock widget (ie.e if all dock widgets are closed)
  175. */
  176. int currentIndex() const;
  177. /**
  178. * Returns the index of the first open dock widgets in the list of
  179. * dock widgets.
  180. * This function is here for performance reasons. Normally it would
  181. * be possible to take the first dock widget from the list returned by
  182. * openedDockWidgets() function. But that function enumerates all
  183. * dock widgets while this functions stops after the first open dock widget.
  184. * If there are no open dock widgets, the function returns -1.
  185. */
  186. int indexOfFirstOpenDockWidget() const;
  187. /**
  188. * Returns the current active dock widget or a nullptr if there is no
  189. * active dock widget (i.e. if all dock widgets are closed)
  190. */
  191. DockWidget *currentDockWidget() const;
  192. /**
  193. * Shows the tab with the given dock widget
  194. */
  195. void setCurrentDockWidget(DockWidget *dockWidget);
  196. /**
  197. * Saves the state into the given stream
  198. */
  199. void saveState(QXmlStreamWriter &stream) const;
  200. /**
  201. * This functions returns the dock widget features of all dock widget in
  202. * this area.
  203. * A bitwise and is used to combine the flags of all dock widgets. That
  204. * means, if only one single dock widget does not support a certain flag,
  205. * the whole dock are does not support the flag. I.e. if one single
  206. * dock widget in this area is not closable, the whole dock are is not
  207. * closable.
  208. */
  209. DockWidget::DockWidgetFeatures features(eBitwiseOperator mode = BitwiseAnd) const;
  210. /**
  211. * Returns the title bar button corresponding to the given title bar
  212. * button identifier
  213. */
  214. QAbstractButton *titleBarButton(eTitleBarButton which) const;
  215. /**
  216. * Update the close button if visibility changed
  217. */
  218. virtual void setVisible(bool visible) override;
  219. /**
  220. * Configures the areas of this particular dock area that are allowed for docking
  221. */
  222. void setAllowedAreas(DockWidgetAreas areas);
  223. /**
  224. * Returns flags with all allowed drop areas of this particular dock area
  225. */
  226. DockWidgetAreas allowedAreas() const;
  227. /**
  228. * Returns the title bar of this dock area
  229. */
  230. DockAreaTitleBar *titleBar() const;
  231. /**
  232. * This activates the tab for the given tab index.
  233. * If the dock widget for the given tab is not visible, the this function
  234. * call will make it visible.
  235. */
  236. void setCurrentIndex(int indexOf);
  237. /**
  238. * Closes the dock area and all dock widgets in this area
  239. */
  240. void closeArea();
  241. /**
  242. * This function closes all other areas except of this area
  243. */
  244. void closeOtherAreas();
  245. signals:
  246. /**
  247. * This signal is emitted when user clicks on a tab at an index.
  248. */
  249. void tabBarClicked(int indexOf);
  250. /**
  251. * This signal is emitted when the tab bar's current tab is about to be changed. The new
  252. * current has the given index, or -1 if there isn't a new one.
  253. * @param index
  254. */
  255. void currentChanging(int indexOf);
  256. /**
  257. * This signal is emitted when the tab bar's current tab changes. The new
  258. * current has the given index, or -1 if there isn't a new one
  259. * @param index
  260. */
  261. void currentChanged(int indexOf);
  262. /**
  263. * This signal is emitted if the visibility of this dock area is toggled
  264. * via toggle view function
  265. */
  266. void viewToggled(bool open);
  267. }; // class DockAreaWidget
  268. } // namespace ADS