dockcontainerwidget.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. namespace ADS {
  41. class DockContainerWidgetPrivate;
  42. class DockAreaWidget;
  43. class DockWidget;
  44. class DockManager;
  45. struct DockManagerPrivate;
  46. class FloatingDockContainer;
  47. struct FloatingDockContainerPrivate;
  48. class FloatingDragPreview;
  49. struct FloatingDragPreviewPrivate;
  50. class DockingStateReader;
  51. /**
  52. * Container that manages a number of dock areas with single dock widgets
  53. * or tabyfied dock widgets in each area.
  54. * Each window that support docking has a DockContainerWidget. That means
  55. * the main application window and all floating windows contain
  56. * a DockContainerWidget.
  57. */
  58. class ADS_EXPORT DockContainerWidget : public QFrame
  59. {
  60. Q_OBJECT
  61. private:
  62. DockContainerWidgetPrivate *d; ///< private data (pimpl)
  63. friend class DockContainerWidgetPrivate;
  64. friend class DockManager;
  65. friend struct DockManagerPrivate;
  66. friend class DockAreaWidget;
  67. friend struct DockAreaWidgetPrivate;
  68. friend class FloatingDockContainer;
  69. friend struct FloatingDockContainerPrivate;
  70. friend class DockWidget;
  71. friend class FloatingDragPreview;
  72. friend struct FloatingDragPreviewPrivate;
  73. protected:
  74. /**
  75. * Handles activation events to update zOrderIndex
  76. */
  77. virtual bool event(QEvent *event) override;
  78. public: // TODO temporary
  79. /**
  80. * Access function for the internal root splitter
  81. */
  82. QSplitter *rootSplitter() const;
  83. protected:
  84. /**
  85. * Helper function for creation of the root splitter
  86. */
  87. void createRootSplitter();
  88. /**
  89. * Drop floating widget into the container
  90. */
  91. void dropFloatingWidget(FloatingDockContainer *floatingWidget, const QPoint &targetPos);
  92. /**
  93. * Drop a dock area or a dock widget given in widget parameter
  94. */
  95. void dropWidget(QWidget *widget, const QPoint &targetPos);
  96. /**
  97. * Adds the given dock area to this container widget
  98. */
  99. void addDockArea(DockAreaWidget *dockAreaWidget, DockWidgetArea area = CenterDockWidgetArea);
  100. /**
  101. * Removes the given dock area from this container
  102. */
  103. void removeDockArea(DockAreaWidget *area);
  104. /**
  105. * This function replaces the goto construct. Still need to write a good description.
  106. */
  107. void emitAndExit() const; // TODO rename
  108. /**
  109. * Saves the state into the given stream
  110. */
  111. void saveState(QXmlStreamWriter &stream) const;
  112. /**
  113. * Restores the state from given stream.
  114. * If Testing is true, the function only parses the data from the given
  115. * stream but does not restore anything. You can use this check for
  116. * faulty files before you start restoring the state
  117. */
  118. bool restoreState(DockingStateReader &stream, bool testing);
  119. /**
  120. * This function returns the last added dock area widget for the given
  121. * area identifier or 0 if no dock area widget has been added for the given
  122. * area
  123. */
  124. DockAreaWidget *lastAddedDockAreaWidget(DockWidgetArea area) const;
  125. /**
  126. * If hasSingleVisibleDockWidget() returns true, this function returns the
  127. * one and only visible dock widget. Otherwise it returns a nullptr.
  128. */
  129. DockWidget *topLevelDockWidget() const;
  130. /**
  131. * Returns the top level dock area.
  132. */
  133. DockAreaWidget *topLevelDockArea() const;
  134. /**
  135. * This function returns a list of all dock widgets in this floating widget.
  136. * It may be possible, depending on the implementation, that dock widgets,
  137. * that are not visible to the user have no parent widget. Therefore simply
  138. * calling findChildren() would not work here. Therefore this function
  139. * iterates over all dock areas and creates a list that contains all
  140. * dock widgets returned from all dock areas.
  141. */
  142. QList<DockWidget *> dockWidgets() const;
  143. public:
  144. /**
  145. * Default Constructor
  146. */
  147. DockContainerWidget(DockManager *dockManager, QWidget *parent = nullptr);
  148. /**
  149. * Virtual Destructor
  150. */
  151. virtual ~DockContainerWidget() override;
  152. /**
  153. * Adds dockwidget into the given area.
  154. * If DockAreaWidget is not null, then the area parameter indicates the area
  155. * into the DockAreaWidget. If DockAreaWidget is null, the Dockwidget will
  156. * be dropped into the container.
  157. * \return Returns the dock area widget that contains the new DockWidget
  158. */
  159. DockAreaWidget *addDockWidget(DockWidgetArea area,
  160. DockWidget *dockWidget,
  161. DockAreaWidget *dockAreaWidget = nullptr);
  162. /**
  163. * Removes dockwidget
  164. */
  165. void removeDockWidget(DockWidget *dockWidget);
  166. /**
  167. * Returns the current zOrderIndex
  168. */
  169. virtual unsigned int zOrderIndex() const;
  170. /**
  171. * This function returns true if this container widgets z order index is
  172. * higher than the index of the container widget given in Other parameter
  173. */
  174. bool isInFrontOf(DockContainerWidget *other) const;
  175. /**
  176. * Returns the dock area at the given global position or 0 if there is no
  177. * dock area at this position
  178. */
  179. DockAreaWidget *dockAreaAt(const QPoint &globalPos) const;
  180. /**
  181. * Returns the dock area at the given Index or 0 if the index is out of
  182. * range
  183. */
  184. DockAreaWidget *dockArea(int index) const;
  185. /**
  186. * Returns the list of dock areas that are not closed
  187. * If all dock widgets in a dock area are closed, the dock area will be closed
  188. */
  189. QList<DockAreaWidget *> openedDockAreas() const;
  190. /**
  191. * This function returns true if this dock area has only one single
  192. * visible dock widget.
  193. * A top level widget is a real floating widget. Only the isFloating()
  194. * function of top level widgets may returns true.
  195. */
  196. bool hasTopLevelDockWidget() const;
  197. /**
  198. * Returns the number of dock areas in this container
  199. */
  200. int dockAreaCount() const;
  201. /**
  202. * Returns the number of visible dock areas
  203. */
  204. int visibleDockAreaCount() const;
  205. /**
  206. * This function returns true, if this container is in a floating widget
  207. */
  208. bool isFloating() const;
  209. /**
  210. * Dumps the layout for debugging purposes
  211. */
  212. void dumpLayout() const;
  213. /**
  214. * This functions returns the dock widget features of all dock widget in
  215. * this container.
  216. * A bitwise and is used to combine the flags of all dock widgets. That
  217. * means, if only dock widget does not support a certain flag, the whole
  218. * dock are does not support the flag.
  219. */
  220. DockWidget::DockWidgetFeatures features() const;
  221. /**
  222. * If this dock container is in a floating widget, this function returns
  223. * the floating widget.
  224. * Else, it returns a nullptr.
  225. */
  226. FloatingDockContainer *floatingWidget() const;
  227. /**
  228. * Call this function to close all dock areas except the KeepOpenArea
  229. */
  230. void closeOtherAreas(DockAreaWidget *keepOpenArea);
  231. signals:
  232. /**
  233. * This signal is emitted if one or multiple dock areas has been added to
  234. * the internal list of dock areas.
  235. * If multiple dock areas are inserted, this signal is emitted only once
  236. */
  237. void dockAreasAdded();
  238. /**
  239. * This signal is emitted if one or multiple dock areas has been removed
  240. */
  241. void dockAreasRemoved();
  242. /**
  243. * This signal is emitted if a dock area is opened or closed via
  244. * toggleView() function
  245. */
  246. void dockAreaViewToggled(DockAreaWidget *dockArea, bool open);
  247. }; // class DockContainerWidget
  248. } // namespace ADS