aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/advanceddockingsystem/autohidetab.h
blob: d97aeb17fe400191eedb63e64dd3c49d0094a7df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (C) 2020 Uwe Kindler
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-2.1-or-later OR GPL-3.0-or-later

#pragma once

#include "pushbutton.h"

#include "ads_globals.h"

namespace ADS {

struct AutoHideTabPrivate;
class DockWidget;
class AutoHideSideBar;
class DockWidgetTab;
class DockContainerWidgetPrivate;

/**
 * A dock widget Side tab that shows a title or an icon.
 * The dock widget tab is shown in the side tab bar to switch between pinned dock widgets.
 */
class ADS_EXPORT AutoHideTab : public PushButton
{
    Q_OBJECT

    Q_PROPERTY(int sideBarLocation READ sideBarLocation CONSTANT)
    Q_PROPERTY(Qt::Orientation orientation READ orientation CONSTANT)
    Q_PROPERTY(bool activeTab READ isActiveTab CONSTANT)
    Q_PROPERTY(bool iconOnly READ iconOnly CONSTANT)

private:
    AutoHideTabPrivate *d; ///< private data (pimpl)
    friend struct AutoHideTabPrivate;
    friend class DockWidget;
    friend class AutoHideDockContainer;
    friend class AutoHideSideBar;
    friend class DockAreaWidget;
    friend class DockContainerWidget;
    friend DockContainerWidgetPrivate;

protected:
    void setSideBar(AutoHideSideBar *sideTabBar);
    void removeFromSideBar();
    virtual bool event(QEvent *event) override;
    virtual void contextMenuEvent(QContextMenuEvent *event) override;
    virtual void mousePressEvent(QMouseEvent *event) override;
    virtual void mouseReleaseEvent(QMouseEvent *event) override;
    virtual void mouseMoveEvent(QMouseEvent *event) override;

public:
    using Super = PushButton;

    /**
     * Default Constructor
     * param[in] parent The parent widget of this title bar
     */
    AutoHideTab(QWidget *parent = nullptr);

    /**
     * Virtual Destructor
     */
    virtual ~AutoHideTab();

    /**
     * Update stylesheet style if a property changes.
     */
    void updateStyle();

    /**
     * Getter for side tab bar area property.
     */
    SideBarLocation sideBarLocation() const;

    /**
     * Set orientation vertical or horizontal.
     */
    void setOrientation(Qt::Orientation value);

    /**
     * Returns the current orientation.
     */
    Qt::Orientation orientation() const;

    /**
     * Returns true, if this is the active tab. The tab is active if the auto hide widget is visible.
     */
    bool isActiveTab() const;

    /**
     * Returns the dock widget this belongs to.
     */
    DockWidget *dockWidget() const;

    /**
     * Sets the dock widget that is controlled by this tab.
     */
    void setDockWidget(DockWidget *dockWidget);

    /**
     * Returns true if the auto hide config flag AutoHideSideBarsIconOnly is set and if
     * the tab has an icon - that means the icon is not null.
     */
    bool iconOnly() const;

    /**
     * Returns the side bar that contains this tab or a nullptr if the tab is not in a side bar.
     */
    AutoHideSideBar *sideBar() const;

    /**
     * Returns the index of this tab in the sideBar.
     */
    int tabIndex() const;

    /**
     * Set the dock widget floating, if it is floatable
     */
    void setDockWidgetFloating();

    /**
     * Unpin and dock the auto hide widget.
     */
    void unpinDockWidget();

    /**
     * Calls the requestCloseDockWidget() function for the assigned dock widget.
     */
    void requestCloseDockWidget();
}; // class AutoHideTab

} // namespace ADS