File indexing completed on 2024-06-02 03:47:32

0001 #ifndef DockWidgetTabH
0002 #define DockWidgetTabH
0003 /*******************************************************************************
0004 ** Qt Advanced Docking System
0005 ** Copyright (C) 2017 Uwe Kindler
0006 **
0007 ** This library is free software; you can redistribute it and/or
0008 ** modify it under the terms of the GNU Lesser General Public
0009 ** License as published by the Free Software Foundation; either
0010 ** version 2.1 of the License, or (at your option) any later version.
0011 **
0012 ** This library is distributed in the hope that it will be useful,
0013 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015 ** Lesser General Public License for more details.
0016 **
0017 ** You should have received a copy of the GNU Lesser General Public
0018 ** License along with this library; If not, see <http://www.gnu.org/licenses/>.
0019 ******************************************************************************/
0020 
0021 
0022 //============================================================================
0023 /// \file   DockWidgetTab.h
0024 /// \author Uwe Kindler
0025 /// \date   27.02.2017
0026 /// \brief  Declaration of CDockWidgetTab class
0027 //============================================================================
0028 
0029 
0030 //============================================================================
0031 //                                   INCLUDES
0032 //============================================================================
0033 #include <QFrame>
0034 #include <QSize>
0035 
0036 #include "ads_globals.h"
0037 
0038 namespace ads
0039 {
0040 class CDockWidget;
0041 class CDockAreaWidget;
0042 struct DockWidgetTabPrivate;
0043 class CDockManager;
0044 
0045 /**
0046  * A dock widget tab that shows a title and an icon.
0047  * The dock widget tab is shown in the dock area title bar to switch between
0048  * tabbed dock widgets
0049  */
0050 class ADS_EXPORT CDockWidgetTab : public QFrame
0051 {
0052     Q_OBJECT
0053     Q_PROPERTY(bool activeTab READ isActiveTab WRITE setActiveTab NOTIFY activeTabChanged)
0054     Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
0055 
0056 private:
0057     DockWidgetTabPrivate* d; ///< private data (pimpl)
0058     friend struct DockWidgetTabPrivate;
0059     friend class CDockWidget;
0060     friend class CDockManager;
0061     friend class CAutoHideDockContainer;
0062     void onDockWidgetFeaturesChanged();
0063 
0064 private Q_SLOTS:
0065     void detachDockWidget();
0066     void autoHideDockWidget();
0067     void onAutoHideToActionClicked();
0068 
0069 protected:
0070     virtual void mousePressEvent(QMouseEvent* ev) override;
0071     virtual void mouseReleaseEvent(QMouseEvent* ev) override;
0072     virtual void mouseMoveEvent(QMouseEvent* ev) override;
0073     virtual void contextMenuEvent(QContextMenuEvent* ev) override;
0074 
0075     /**
0076      * Double clicking the tab widget makes the assigned dock widget floating
0077      */
0078     virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
0079 
0080 public:
0081     using Super = QFrame;
0082     /**
0083      * Default Constructor
0084      * param[in] DockWidget The dock widget this title bar belongs to
0085      * param[in] parent The parent widget of this title bar
0086      */
0087     CDockWidgetTab(CDockWidget* DockWidget, QWidget* parent = nullptr);
0088 
0089     /**
0090      * Virtual Destructor
0091      */
0092     virtual ~CDockWidgetTab();
0093 
0094     /**
0095      * Returns true, if this is the active tab
0096      */
0097     bool isActiveTab() const;
0098 
0099     /**
0100      * Set this true to make this tab the active tab
0101      */
0102     void setActiveTab(bool active);
0103 
0104     /**
0105      * Sets the dock area widget the dockWidget returned by dockWidget()
0106      * function belongs to.
0107      */
0108     void setDockAreaWidget(CDockAreaWidget* DockArea);
0109 
0110     /**
0111      * Returns the dock area widget this title bar belongs to.
0112      * \return This function returns 0 if the dock widget that owns this title
0113      * bar widget has not been added to any dock area yet.
0114      */
0115     CDockAreaWidget* dockAreaWidget() const;
0116 
0117     /**
0118      * Returns the dock widget this title widget belongs to
0119      */
0120     CDockWidget* dockWidget() const;
0121 
0122     /**
0123      * Sets the icon to show in title bar
0124      */
0125     void setIcon(const QIcon& Icon);
0126 
0127     /**
0128      * Returns the icon
0129      */
0130     const QIcon& icon() const;
0131 
0132     /**
0133      * Returns the tab text
0134      */
0135     QString text() const;
0136 
0137     /**
0138      * Sets the tab text
0139      */
0140     void setText(const QString& title);
0141 
0142     /**
0143      * Returns true if text is elided on the tab's title
0144      */
0145     bool isTitleElided() const;
0146 
0147     /**
0148      * This function returns true if the assigned dock widget is closable
0149      */
0150     bool isClosable() const;
0151 
0152     /**
0153     * Track event ToolTipChange and set child ToolTip 
0154     */
0155     virtual bool event(QEvent *e) override;
0156 
0157     /**
0158      * Sets the text elide mode
0159      */
0160     void setElideMode(Qt::TextElideMode mode);
0161 
0162     /**
0163      * Update stylesheet style if a property changes
0164      */
0165     void updateStyle();
0166 
0167     /**
0168      * Returns the icon size.
0169      * If no explicit icon size has been set, the function returns an invalid
0170      * QSize
0171      */
0172     QSize iconSize() const;
0173 
0174     /**
0175      * Set an explicit icon size.
0176      * If no icon size has been set explicitly, than the tab sets the icon size
0177      * depending on the style
0178      */
0179     void setIconSize(const QSize& Size);
0180 
0181 public Q_SLOTS:
0182     virtual void setVisible(bool visible) override;
0183 
0184 Q_SIGNALS:
0185     void activeTabChanged();
0186     void clicked();
0187     void closeRequested();
0188     void closeOtherTabsRequested();
0189     void moved(const QPoint& GlobalPos);
0190     void elidedChanged(bool elided);
0191 }; // class DockWidgetTab
0192 }
0193  // namespace ads
0194 //-----------------------------------------------------------------------------
0195 #endif // DockWidgetTabH