dockareatitlebar.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 <QFrame>
  38. #include <QToolButton>
  39. class QAbstractButton;
  40. namespace ADS {
  41. class DockAreaTabBar;
  42. class DockAreaWidget;
  43. struct DockAreaTitleBarPrivate;
  44. using TitleBarButtonType = QToolButton;
  45. /**
  46. * Title bar button of a dock area that customizes TitleBarButtonType appearance/behavior
  47. * according to various config flags such as:
  48. * DockManager::DockAreaHas_xxx_Button - if set to 'false' keeps the button always invisible
  49. * DockManager::DockAreaHideDisabledButtons - if set to 'true' hides button when it is disabled
  50. */
  51. class TitleBarButton : public TitleBarButtonType
  52. {
  53. Q_OBJECT
  54. bool m_visible = true;
  55. bool m_hideWhenDisabled = false;
  56. public:
  57. using Super = TitleBarButtonType;
  58. TitleBarButton(bool visible = true, QWidget *parent = nullptr);
  59. /**
  60. * Adjust this visibility change request with our internal settings:
  61. */
  62. virtual void setVisible(bool visible) override;
  63. protected:
  64. /**
  65. * Handle EnabledChanged signal to set button invisible if the configured
  66. */
  67. bool event(QEvent *event) override;
  68. };
  69. /**
  70. * This spacer widget is here because of the following problem.
  71. * The dock area title bar handles mouse dragging and moving the floating widget.
  72. * The problem is, that if the title bar becomes invisible, i.e. if the dock
  73. * area contains only one single dock widget and the dock area is moved
  74. * into a floating widget, then mouse events are not handled anymore and dragging
  75. * of the floating widget stops.
  76. */
  77. class SpacerWidget : public QWidget
  78. {
  79. Q_OBJECT
  80. public:
  81. SpacerWidget(QWidget *parent = nullptr);
  82. virtual QSize sizeHint() const override {return QSize(0, 0);}
  83. virtual QSize minimumSizeHint() const override {return QSize(0, 0);}
  84. };
  85. /**
  86. * Title bar of a dock area.
  87. * The title bar contains a tabbar with all tabs for a dock widget group and
  88. * with a tabs menu button, a undock button and a close button.
  89. */
  90. class ADS_EXPORT DockAreaTitleBar : public QFrame
  91. {
  92. Q_OBJECT
  93. private:
  94. DockAreaTitleBarPrivate *d; ///< private data (pimpl)
  95. friend struct DockAreaTitleBarPrivate;
  96. void onTabsMenuAboutToShow();
  97. void onCloseButtonClicked();
  98. void onUndockButtonClicked();
  99. void onTabsMenuActionTriggered(QAction *action);
  100. void onCurrentTabChanged(int index);
  101. protected:
  102. /**
  103. * Stores mouse position to detect dragging
  104. */
  105. virtual void mousePressEvent(QMouseEvent *event) override;
  106. /**
  107. * Stores mouse position to detect dragging
  108. */
  109. virtual void mouseReleaseEvent(QMouseEvent *event) override;
  110. /**
  111. * Starts floating the complete docking area including all dock widgets,
  112. * if it is not the last dock area in a floating widget
  113. */
  114. virtual void mouseMoveEvent(QMouseEvent *event) override;
  115. /**
  116. * Double clicking the title bar also starts floating of the complete area
  117. */
  118. virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
  119. /**
  120. * Show context menu
  121. */
  122. virtual void contextMenuEvent(QContextMenuEvent *event) override;
  123. public:
  124. /**
  125. * Call this slot to tell the title bar that it should update the tabs menu
  126. * the next time it is shown.
  127. */
  128. void markTabsMenuOutdated();
  129. using Super = QFrame;
  130. /**
  131. * Default Constructor
  132. */
  133. DockAreaTitleBar(DockAreaWidget *parent);
  134. /**
  135. * Virtual Destructor
  136. */
  137. virtual ~DockAreaTitleBar() override;
  138. /**
  139. * Returns the pointer to the tabBar()
  140. */
  141. DockAreaTabBar *tabBar() const;
  142. /**
  143. * Returns the button corresponding to the given title bar button identifier
  144. */
  145. QAbstractButton *button(eTitleBarButton which) const;
  146. /**
  147. * Updates the visibility of the dock widget actions in the title bar
  148. */
  149. void updateDockWidgetActionsButtons();
  150. /**
  151. * Marks the tabs menu outdated before it calls its base class
  152. * implementation
  153. */
  154. virtual void setVisible(bool visible) override;
  155. /**
  156. * Inserts a custom widget at position index into this title bar.
  157. * If index is negative, the widget is added at the end.
  158. * You can use this function to insert custom widgets into the title bar.
  159. */
  160. void insertWidget(int index, QWidget *widget);
  161. /**
  162. * Searches for widget widget in this title bar.
  163. * You can use this function, to get the position of the default
  164. * widget in the tile bar.
  165. * \code
  166. * int tabBarIndex = TitleBar->indexOf(TitleBar->tabBar());
  167. * int closeButtonIndex = TitleBar->indexOf(TitleBar->button(TitleBarButtonClose));
  168. * \endcode
  169. */
  170. int indexOf(QWidget *widget) const;
  171. signals:
  172. /**
  173. * This signal is emitted if a tab in the tab bar is clicked by the user
  174. * or if the user clicks on a tab item in the title bar tab menu.
  175. */
  176. void tabBarClicked(int index);
  177. }; // class DockAreaTitleBar
  178. } // namespace ADS