Debian Codegraph @

src/Gui/DockWindowManager.h

raw
1 /***************************************************************************
2 * Copyright (c) 2007 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23 #ifndef GUI_DOCKWINDOWMANAGER_H
24 #define GUI_DOCKWINDOWMANAGER_H
25
26 #include <QObject>
27 #include <Base/Bitmask.h>
28 #include <FCGlobal.h>
29
30 class QDockWidget;
31 class QWidget;
32
33 namespace Gui
34 {
35
36 enum class DockWindowOption
37 {
38 // clang-format off
39 Hidden = 0,
40 Visible = 1,
41 HiddenTabbed = 2,
42 VisibleTabbed = 3
43 // clang-format on
44 };
45
46 using DockWindowOptions = Base::Flags<DockWindowOption>;
47
48 struct DockWindowItem
49 {
50 QString name;
51 Qt::DockWidgetArea pos;
52 bool visibility;
53 bool tabbed;
54 };
55
56 class GuiExport DockWindowItems
57 {
58 public:
59 DockWindowItems();
60 ~DockWindowItems();
61
62 void addDockWidget(const char* name, Qt::DockWidgetArea pos, DockWindowOptions option);
63 void setDockingArea(const char* name, Qt::DockWidgetArea pos);
64 void setVisibility(const char* name, bool v);
65 void setVisibility(bool v);
66 const QList<DockWindowItem>& dockWidgets() const;
67
68 private:
69 QList<DockWindowItem> _items;
70 };
71
72 /**
73 * Class that manages the widgets inside a QDockWidget.
74 * \author Werner Mayer
75 */
76 class GuiExport DockWindowManager: public QObject
77 {
78 Q_OBJECT
79
80 public:
81 /** Creates the only instance of the DockWindowManager. */
82 static DockWindowManager* instance();
83 static void destruct();
84
85 bool registerDockWindow(const char* name, QWidget* widget);
86 QWidget* unregisterDockWindow(const char* name);
87 QWidget* findRegisteredDockWindow(const char* name);
88 void setup(DockWindowItems*);
89
90 /// Adds a QDockWidget to the main window and sets \a widget as its widget
91 QDockWidget* addDockWindow(
92 const char* name,
93 QWidget* widget,
94 Qt::DockWidgetArea pos = Qt::AllDockWidgetAreas
95 );
96 /// Removes and destroys the QDockWidget and returns the widget
97 /// with name \a name added with @ref addDockWindow.
98 QWidget* removeDockWindow(const char* name);
99 /// Removes and destroys the QDockWidget that contains \a dock. \a dock
100 /// does not get destroyed.
101 void removeDockWindow(QWidget* dock);
102 /// Returns the widget with name \a name added with @ref addDockWindow.
103 /// @note The returned widget is not the QDockWidget instance
104 /// returned from @ref addDockWindow. If you want to access the QDockWidget
105 /// you get it with parentWidget() of the returned widget.
106 QWidget* getDockWindow(const char* name) const;
107 /// Returns the QDockWidget container
108 QDockWidget* getDockContainer(const char* name) const;
109 /// Returns a list of all widgets which set to a QDockWidget.
110 QList<QWidget*> getDockWindows() const;
111 /// If the corresponding dock widget isn't visible then activate it
112 void activate(QWidget* widget);
113
114 void saveState();
115 void loadState();
116 void retranslate();
117
118 bool isOverlayActivated() const;
119
120 private Q_SLOTS:
121 /**
122 * \internal
123 */
124 void onDockWidgetDestroyed(QObject*);
125 /**
126 * \internal
127 */
128 void onWidgetDestroyed(QObject*);
129
130 private:
131 QDockWidget* findDockWidget(const QList<QDockWidget*>&, const QString&) const;
132 void tabifyDockWidgets(DockWindowItems*);
133 void setupOverlayManagement();
134
135 DockWindowManager();
136 ~DockWindowManager() override;
137 static DockWindowManager* _instance;
138 struct DockWindowManagerP* d;
139 };
140
141 } // namespace Gui
142
143 ENABLE_BITMASK_OPERATORS(Gui::DockWindowOption)
144
145 #endif // GUI_DOCKWINDOWMANAGER_H