dockwidgettab.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. namespace ADS {
  39. class DockWidget;
  40. class DockAreaWidget;
  41. struct DockWidgetTabPrivate;
  42. /**
  43. * A dock widget tab that shows a title and an icon.
  44. * The dock widget tab is shown in the dock area title bar to switch between
  45. * tabbed dock widgets
  46. */
  47. class ADS_EXPORT DockWidgetTab : public QFrame
  48. {
  49. Q_OBJECT
  50. Q_PROPERTY(bool activeTab READ isActiveTab WRITE setActiveTab NOTIFY activeTabChanged)
  51. private:
  52. DockWidgetTabPrivate *d; ///< private data (pimpl)
  53. friend struct DockWidgetTabPrivate;
  54. friend class DockWidget;
  55. void onDockWidgetFeaturesChanged();
  56. void detachDockWidget();
  57. protected:
  58. virtual void mousePressEvent(QMouseEvent *event) override;
  59. virtual void mouseReleaseEvent(QMouseEvent *event) override;
  60. virtual void mouseMoveEvent(QMouseEvent *event) override;
  61. virtual void contextMenuEvent(QContextMenuEvent *event) override;
  62. /**
  63. * Double clicking the tab widget makes the assigned dock widget floating
  64. */
  65. virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
  66. public:
  67. using Super = QFrame;
  68. /**
  69. * Default Constructor
  70. * param[in] DockWidget The dock widget this title bar belongs to
  71. * param[in] parent The parent widget of this title bar
  72. */
  73. DockWidgetTab(DockWidget *DockWidget, QWidget *parent = nullptr);
  74. /**
  75. * Virtual Destructor
  76. */
  77. virtual ~DockWidgetTab() override;
  78. /**
  79. * Returns true, if this is the active tab
  80. */
  81. bool isActiveTab() const;
  82. /**
  83. * Set this true to make this tab the active tab
  84. */
  85. void setActiveTab(bool active);
  86. /**
  87. * Returns the dock widget this title widget belongs to
  88. */
  89. DockWidget *dockWidget() const;
  90. /**
  91. * Sets the dock area widget the dockWidget returned by dockWidget()
  92. * function belongs to.
  93. */
  94. void setDockAreaWidget(DockAreaWidget *dockArea);
  95. /**
  96. * Returns the dock area widget this title bar belongs to.
  97. * \return This function returns 0 if the dock widget that owns this title
  98. * bar widget has not been added to any dock area yet.
  99. */
  100. DockAreaWidget *dockAreaWidget() const;
  101. /**
  102. * Sets the icon to show in title bar
  103. */
  104. void setIcon(const QIcon &icon);
  105. /**
  106. * Returns the icon
  107. */
  108. const QIcon &icon() const;
  109. /**
  110. * Returns the tab text
  111. */
  112. QString text() const;
  113. /**
  114. * Sets the tab text
  115. */
  116. void setText(const QString &title);
  117. /**
  118. * Returns true if text is elided on the tab's title
  119. */
  120. bool isTitleElided() const;
  121. /**
  122. * This function returns true if the assigned dock widget is closable
  123. */
  124. bool isClosable() const;
  125. /**
  126. * Track event ToolTipChange and set child ToolTip
  127. */
  128. virtual bool event(QEvent *event) override;
  129. virtual void setVisible(bool visible) override;
  130. signals:
  131. void activeTabChanged();
  132. void clicked();
  133. void closeRequested();
  134. void closeOtherTabsRequested();
  135. void moved(const QPoint &globalPosition);
  136. void elidedChanged(bool elided);
  137. }; // class DockWidgetTab
  138. } // namespace ADS