1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef QDESIGNER_WORKBENCH_H |
5 | #define QDESIGNER_WORKBENCH_H |
6 | |
7 | #include "designer_enums.h" |
8 | |
9 | #include <QtCore/qhash.h> |
10 | #include <QtCore/qlist.h> |
11 | #include <QtCore/qobject.h> |
12 | #include <QtCore/qpointer.h> |
13 | #include <QtCore/qrect.h> |
14 | #include <QtCore/qset.h> |
15 | |
16 | QT_BEGIN_NAMESPACE |
17 | |
18 | class QDesignerActions; |
19 | class QDesignerToolWindow; |
20 | class QDesignerFormWindow; |
21 | class DockedMainWindow; |
22 | class QDesignerSettings; |
23 | |
24 | class QAction; |
25 | class QActionGroup; |
26 | class QDockWidget; |
27 | class ; |
28 | class ; |
29 | class QToolBar; |
30 | class QMdiSubWindow; |
31 | class QCloseEvent; |
32 | class ToolBarManager; |
33 | |
34 | class QDesignerFormEditorInterface; |
35 | class QDesignerFormWindowInterface; |
36 | class QDesignerFormWindowManagerInterface; |
37 | class QDesignerIntegration; |
38 | |
39 | class QDesignerWorkbench: public QObject |
40 | { |
41 | Q_OBJECT |
42 | |
43 | public: |
44 | QDesignerWorkbench(); |
45 | ~QDesignerWorkbench() override; |
46 | |
47 | UIMode mode() const; |
48 | |
49 | QDesignerFormEditorInterface *core() const; |
50 | QDesignerFormWindow *findFormWindow(QWidget *widget) const; |
51 | |
52 | QDesignerFormWindow *openForm(const QString &fileName, QString *errorMessage); |
53 | QDesignerFormWindow *openTemplate(const QString &templateFileName, |
54 | const QString &editorFileName, |
55 | QString *errorMessage); |
56 | |
57 | int toolWindowCount() const; |
58 | QDesignerToolWindow *toolWindow(int index) const; |
59 | |
60 | int formWindowCount() const; |
61 | QDesignerFormWindow *formWindow(int index) const; |
62 | |
63 | QDesignerActions *actionManager() const; |
64 | |
65 | QActionGroup *modeActionGroup() const; |
66 | |
67 | QRect availableGeometry() const; |
68 | QRect desktopGeometry() const; |
69 | |
70 | int marginHint() const; |
71 | |
72 | bool readInForm(const QString &fileName) const; |
73 | bool writeOutForm(QDesignerFormWindowInterface *formWindow, const QString &fileName) const; |
74 | bool saveForm(QDesignerFormWindowInterface *fw); |
75 | bool handleClose(); |
76 | bool readInBackup(); |
77 | void updateBackup(QDesignerFormWindowInterface* fwi); |
78 | void applyUiSettings(); |
79 | |
80 | signals: |
81 | void modeChanged(UIMode mode); |
82 | void initialized(); |
83 | |
84 | public slots: |
85 | void addFormWindow(QDesignerFormWindow *formWindow); |
86 | void removeFormWindow(QDesignerFormWindow *formWindow); |
87 | void bringAllToFront(); |
88 | void toggleFormMinimizationState(); |
89 | |
90 | private slots: |
91 | void switchToNeutralMode(); |
92 | void switchToDockedMode(); |
93 | void switchToTopLevelMode(); |
94 | void initializeCorePlugins(); |
95 | void handleCloseEvent(QCloseEvent *); |
96 | void slotFormWindowActivated(QDesignerFormWindow* fw); |
97 | void (QDesignerFormWindowInterface *fw); |
98 | void formWindowActionTriggered(QAction *a); |
99 | void adjustMDIFormPositions(); |
100 | void minimizationStateChanged(QDesignerFormWindowInterface *formWindow, bool minimized); |
101 | |
102 | void restoreUISettings(); |
103 | void notifyUISettingsChanged(); |
104 | void slotFileDropped(const QString &f); |
105 | |
106 | private: |
107 | QWidget *magicalParent(const QWidget *w) const; |
108 | Qt::WindowFlags magicalWindowFlags(const QWidget *widgetForFlags) const; |
109 | QDesignerFormWindowManagerInterface *formWindowManager() const; |
110 | void closeAllToolWindows(); |
111 | QDesignerToolWindow *widgetBoxToolWindow() const; |
112 | QDesignerFormWindow *loadForm(const QString &fileName, bool detectLineTermiantorMode, QString *errorMessage); |
113 | void resizeForm(QDesignerFormWindow *fw, const QWidget *mainContainer) const; |
114 | void saveGeometriesForModeChange(); |
115 | void saveGeometries(QDesignerSettings &settings) const; |
116 | |
117 | bool isFormWindowMinimized(const QDesignerFormWindow *fw); |
118 | void setFormWindowMinimized(QDesignerFormWindow *fw, bool minimized); |
119 | void saveSettings() const; |
120 | |
121 | QDesignerFormEditorInterface *m_core; |
122 | QDesignerIntegration *m_integration; |
123 | |
124 | QDesignerActions *m_actionManager; |
125 | QActionGroup *m_windowActions; |
126 | |
127 | QMenu *; |
128 | |
129 | QPointer<QMenuBar> ; |
130 | |
131 | struct TopLevelData { |
132 | ToolBarManager *toolbarManager; |
133 | QList<QToolBar *> toolbars; |
134 | }; |
135 | TopLevelData m_topLevelData; |
136 | |
137 | UIMode m_mode = NeutralMode; |
138 | QPointer<DockedMainWindow> m_dockedMainWindow; |
139 | |
140 | QList<QDesignerToolWindow *> m_toolWindows; |
141 | QList<QDesignerFormWindow *> m_formWindows; |
142 | |
143 | QMenu *; |
144 | |
145 | // Helper class to remember the position of a window while switching user |
146 | // interface modes. |
147 | class Position { |
148 | public: |
149 | Position(const QDockWidget *dockWidget); |
150 | Position(const QMdiSubWindow *mdiSubWindow, const QPoint &mdiAreaOffset); |
151 | Position(const QWidget *topLevelWindow, const QPoint &desktopTopLeft); |
152 | |
153 | void applyTo(QMdiSubWindow *mdiSubWindow, const QPoint &mdiAreaOffset) const; |
154 | void applyTo(QWidget *topLevelWindow, const QPoint &desktopTopLeft) const; |
155 | void applyTo(QDockWidget *dockWidget) const; |
156 | |
157 | QPoint position() const { return m_position; } |
158 | private: |
159 | bool m_minimized; |
160 | // Position referring to top-left corner (desktop in top-level mode or |
161 | // main window in MDI mode) |
162 | QPoint m_position; |
163 | }; |
164 | using PositionMap = QHash<QWidget*, Position>; |
165 | PositionMap m_Positions; |
166 | |
167 | enum State { StateInitializing, StateUp, StateClosing }; |
168 | State m_state = StateInitializing; |
169 | bool m_uiSettingsChanged = false; // UI mode changed in preference dialog, trigger delayed slot. |
170 | }; |
171 | |
172 | QT_END_NAMESPACE |
173 | |
174 | #endif // QDESIGNER_WORKBENCH_H |
175 | |