floatingdockcontainer.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 <QDockWidget>
  38. #include <QRubberBand>
  39. #ifdef Q_OS_LINUX
  40. using FloatingWidgetBaseType = QDockWidget;
  41. #else
  42. using FloatingWidgetBaseType = QWidget;
  43. #endif
  44. namespace ADS {
  45. struct FloatingDockContainerPrivate;
  46. class DockManager;
  47. struct DockManagerPrivate;
  48. class DockAreaWidget;
  49. class DockContainerWidget;
  50. class DockWidget;
  51. class DockManager;
  52. class DockAreaTabBar;
  53. class DockWidgetTab;
  54. struct DockWidgetTabPrivate;
  55. class DockAreaTitleBar;
  56. struct DockAreaTitleBarPrivate;
  57. class FloatingWidgetTitleBar;
  58. class DockingStateReader;
  59. /**
  60. * Pure virtual interface for floating widgets.
  61. * This interface is used for opaque and non-opaque undocking. If opaque
  62. * undocking is used, the a real FloatingDockContainer widget will be created
  63. */
  64. class AbstractFloatingWidget
  65. {
  66. public:
  67. virtual ~AbstractFloatingWidget() = 0;
  68. /**
  69. * Starts floating.
  70. * This function should get called typically from a mouse press event
  71. * handler
  72. */
  73. virtual void startFloating(const QPoint &dragStartMousePos,
  74. const QSize &size,
  75. eDragState dragState,
  76. QWidget *mouseEventHandler)
  77. = 0;
  78. /**
  79. * Moves the widget to a new position relative to the position given when
  80. * startFloating() was called.
  81. * This function should be called from a mouse mouve event handler to
  82. * move the floating widget on mouse move events.
  83. */
  84. virtual void moveFloating() = 0;
  85. /**
  86. * Tells the widget that to finish dragging if the mouse is released.
  87. * This function should be called from a mouse release event handler
  88. * to finish the dragging
  89. */
  90. virtual void finishDragging() = 0;
  91. };
  92. /**
  93. * This implements a floating widget that is a dock container that accepts
  94. * docking of dock widgets like the main window and that can be docked into
  95. * another dock container.
  96. * Every floating window of the docking system is a FloatingDockContainer.
  97. */
  98. class ADS_EXPORT FloatingDockContainer : public FloatingWidgetBaseType,
  99. public AbstractFloatingWidget
  100. {
  101. Q_OBJECT
  102. private:
  103. FloatingDockContainerPrivate *d; ///< private data (pimpl)
  104. friend struct FloatingDockContainerPrivate;
  105. friend class DockManager;
  106. friend struct DockManagerPrivate;
  107. friend class DockAreaTabBar;
  108. friend struct DockWidgetTabPrivate;
  109. friend class DockWidgetTab;
  110. friend class DockAreaTitleBar;
  111. friend struct DockAreaTitleBarPrivate;
  112. friend class DockWidget;
  113. friend class DockAreaWidget;
  114. friend class FloatingWidgetTitleBar;
  115. void onDockAreasAddedOrRemoved();
  116. void onDockAreaCurrentChanged(int Index);
  117. protected:
  118. /**
  119. * Starts floating at the given global position.
  120. * Use moveToGlobalPos() to move the widget to a new position
  121. * depending on the start position given in Pos parameter
  122. */
  123. virtual void startFloating(const QPoint &dragStartMousePos,
  124. const QSize &size,
  125. eDragState dragState,
  126. QWidget *mouseEventHandler) override;
  127. /**
  128. * Call this function to start dragging the floating widget
  129. */
  130. void startDragging(const QPoint &dragStartMousePos,
  131. const QSize &size,
  132. QWidget *mouseEventHandler)
  133. {
  134. startFloating(dragStartMousePos, size, DraggingFloatingWidget, mouseEventHandler);
  135. }
  136. /**
  137. * Call this function if you explicitly want to signal that dragging has
  138. * finished
  139. */
  140. virtual void finishDragging() override;
  141. /**
  142. * Call this function if you just want to initialize the position
  143. * and size of the floating widget
  144. */
  145. void initFloatingGeometry(const QPoint &dragStartMousePos, const QSize &size)
  146. {
  147. startFloating(dragStartMousePos, size, DraggingInactive, nullptr);
  148. }
  149. /**
  150. * Moves the widget to a new position relative to the position given when
  151. * startFloating() was called
  152. */
  153. void moveFloating() override;
  154. /**
  155. * Restores the state from given stream.
  156. * If Testing is true, the function only parses the data from the given
  157. * stream but does not restore anything. You can use this check for
  158. * faulty files before you start restoring the state
  159. */
  160. bool restoreState(DockingStateReader &stream, bool testing);
  161. /**
  162. * Call this function to update the window title
  163. */
  164. void updateWindowTitle();
  165. protected: // reimplements QWidget
  166. virtual void changeEvent(QEvent *event) override;
  167. virtual void moveEvent(QMoveEvent *event) override;
  168. virtual bool event(QEvent *event) override;
  169. virtual void closeEvent(QCloseEvent *event) override;
  170. virtual void hideEvent(QHideEvent *event) override;
  171. virtual void showEvent(QShowEvent *event) override;
  172. public:
  173. using Super = QWidget;
  174. /**
  175. * Create empty floating widget - required for restore state
  176. */
  177. FloatingDockContainer(DockManager *dockManager);
  178. /**
  179. * Create floating widget with the given dock area
  180. */
  181. FloatingDockContainer(DockAreaWidget *dockArea);
  182. /**
  183. * Create floating widget with the given dock widget
  184. */
  185. FloatingDockContainer(DockWidget *dockWidget);
  186. /**
  187. * Virtual Destructor
  188. */
  189. virtual ~FloatingDockContainer() override;
  190. /**
  191. * Access function for the internal dock container
  192. */
  193. DockContainerWidget *dockContainer() const;
  194. /**
  195. * This function returns true, if it can be closed.
  196. * It can be closed, if all dock widgets in all dock areas can be closed
  197. */
  198. bool isClosable() const;
  199. /**
  200. * This function returns true, if this floating widget has only one single
  201. * visible dock widget in a single visible dock area.
  202. * The single dock widget is a real top level floating widget because no
  203. * other widgets are docked.
  204. */
  205. bool hasTopLevelDockWidget() const;
  206. /**
  207. * This function returns the first dock widget in the first dock area.
  208. * If the function hasSingleDockWidget() returns true, then this function
  209. * returns this single dock widget.
  210. */
  211. DockWidget *topLevelDockWidget() const;
  212. /**
  213. * This function returns a list of all dock widget in this floating widget.
  214. * This is a simple convenience function that simply calls the dockWidgets()
  215. * function of the internal container widget.
  216. */
  217. QList<DockWidget *> dockWidgets() const;
  218. }; // class FloatingDockContainer
  219. } // namespace ADS