ads_globals.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 <QDebug>
  37. #include <QPair>
  38. #include <QPixmap>
  39. #include <QStyle>
  40. #include <QWidget>
  41. #include <QtCore/QtGlobal>
  42. class QAbstractButton;
  43. #ifndef ADS_STATIC
  44. #ifdef ADVANCEDDOCKINGSYSTEM_LIBRARY
  45. #define ADS_EXPORT Q_DECL_EXPORT
  46. #else
  47. #define ADS_EXPORT Q_DECL_IMPORT
  48. #endif
  49. #else
  50. #define ADS_EXPORT
  51. #endif
  52. //#define ADS_DEBUG_PRINT
  53. // Define ADS_DEBUG_PRINT to enable a lot of debug output
  54. #ifdef ADS_DEBUG_PRINT
  55. #define ADS_PRINT(s) qDebug() << s
  56. #else
  57. #define ADS_PRINT(s)
  58. #endif
  59. // Set ADS_DEBUG_LEVEL to enable additional debug output and to enable layout
  60. // dumps to qDebug and std::cout after layout changes
  61. #define ADS_DEBUG_LEVEL 0
  62. class QSplitter;
  63. namespace ADS {
  64. enum eStateFileVersion { InitialVerison = 0, Version1 = 1, CurrentVersion = Version1 };
  65. class DockSplitter;
  66. enum DockWidgetArea {
  67. NoDockWidgetArea = 0x00,
  68. LeftDockWidgetArea = 0x01,
  69. RightDockWidgetArea = 0x02,
  70. TopDockWidgetArea = 0x04,
  71. BottomDockWidgetArea = 0x08,
  72. CenterDockWidgetArea = 0x10,
  73. InvalidDockWidgetArea = NoDockWidgetArea,
  74. OuterDockAreas = TopDockWidgetArea | LeftDockWidgetArea | RightDockWidgetArea
  75. | BottomDockWidgetArea,
  76. AllDockAreas = OuterDockAreas | CenterDockWidgetArea
  77. };
  78. Q_DECLARE_FLAGS(DockWidgetAreas, DockWidgetArea)
  79. enum eTitleBarButton { TitleBarButtonTabsMenu, TitleBarButtonUndock, TitleBarButtonClose };
  80. /**
  81. * The different dragging states
  82. */
  83. enum eDragState {
  84. DraggingInactive, //!< DraggingInactive
  85. DraggingMousePressed, //!< DraggingMousePressed
  86. DraggingTab, //!< DraggingTab
  87. DraggingFloatingWidget //!< DraggingFloatingWidget
  88. };
  89. /**
  90. * The different icons used in the UI
  91. */
  92. enum eIcon {
  93. TabCloseIcon, //!< TabCloseIcon
  94. DockAreaMenuIcon, //!< DockAreaMenuIcon
  95. DockAreaUndockIcon, //!< DockAreaUndockIcon
  96. DockAreaCloseIcon, //!< DockAreaCloseIcon
  97. IconCount, //!< just a delimiter for range checks
  98. };
  99. /**
  100. * For bitwise combination of dock wdget features
  101. */
  102. enum eBitwiseOperator
  103. {
  104. BitwiseAnd,
  105. BitwiseOr
  106. };
  107. namespace internal {
  108. const bool restoreTesting = true;
  109. const bool restore = false;
  110. const char *const closedProperty = "close";
  111. const char *const dirtyProperty = "dirty";
  112. /**
  113. * Replace the from widget in the given splitter with the To widget
  114. */
  115. void replaceSplitterWidget(QSplitter *splitter, QWidget *from, QWidget *to);
  116. /**
  117. * This function walks the splitter tree upwards to hides all splitters
  118. * that do not have visible content
  119. */
  120. void hideEmptyParentSplitters(DockSplitter *firstParentSplitter);
  121. /**
  122. * Convenience class for QPair to provide better naming than first and
  123. * second
  124. */
  125. class DockInsertParam : public QPair<Qt::Orientation, bool>
  126. {
  127. public:
  128. using QPair::QPair;
  129. Qt::Orientation orientation() const { return this->first; }
  130. bool append() const { return this->second; }
  131. int insertOffset() const { return append() ? 1 : 0; }
  132. };
  133. /**
  134. * Returns the insertion parameters for the given dock area
  135. */
  136. DockInsertParam dockAreaInsertParameters(DockWidgetArea area);
  137. /**
  138. * Searches for the parent widget of the given type.
  139. * Returns the parent widget of the given widget or 0 if the widget is not
  140. * child of any widget of type T
  141. *
  142. * It is not safe to use this function in in DockWidget because only
  143. * the current dock widget has a parent. All dock widgets that are not the
  144. * current dock widget in a dock area have no parent.
  145. */
  146. template<class T>
  147. T findParent(const QWidget *widget)
  148. {
  149. QWidget *parentWidget = widget->parentWidget();
  150. while (parentWidget) {
  151. T parentImpl = qobject_cast<T>(parentWidget);
  152. if (parentImpl) {
  153. return parentImpl;
  154. }
  155. parentWidget = parentWidget->parentWidget();
  156. }
  157. return 0;
  158. }
  159. /**
  160. * Creates a semi transparent pixmap from the given pixmap Source.
  161. * The Opacity parameter defines the opacity from completely transparent (0.0)
  162. * to completely opaque (1.0)
  163. */
  164. QPixmap createTransparentPixmap(const QPixmap &source, qreal opacity);
  165. /**
  166. * Helper function for settings flags in a QFlags instance.
  167. */
  168. template<class T>
  169. void setFlag(T &flags, typename T::enum_type flag, bool on = true)
  170. {
  171. flags.setFlag(flag, on);
  172. }
  173. /**
  174. * Helper function for settings tooltips without cluttering the code with
  175. * tests for preprocessor macros
  176. */
  177. template <class QObjectPtr>
  178. void setToolTip(QObjectPtr obj, const QString &tip)
  179. {
  180. #ifndef QT_NO_TOOLTIP
  181. obj->setToolTip(tip);
  182. #else
  183. Q_UNUSED(obj);
  184. Q_UNUSED(tip);
  185. #endif
  186. }
  187. /**
  188. * Helper function to set the icon of a certain button.
  189. * Use this function to set the icons for the dock area and dock widget buttons.
  190. * The function first uses the CustomIconId to get an icon from the
  191. * IconProvider. You can register your custom icons with the icon provider, if
  192. * you do not want to use the default buttons and if you do not want to use
  193. * stylesheets.
  194. * If the IconProvider does not return a valid icon (icon is null), the function
  195. * fetches the given standard pixmap from the QStyle.
  196. * param[in] Button The button whose icons are to be set
  197. * param[in] StandardPixmap The standard pixmap to be used for the button
  198. * param[in] CustomIconId The identifier for the custom icon.
  199. */
  200. void setButtonIcon(QAbstractButton *button, QStyle::StandardPixmap standarPixmap,
  201. ADS::eIcon CustomIconId);
  202. } // namespace internal
  203. } // namespace ADS