1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Designer of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef QDESIGNER_WORKBENCH_H
30#define QDESIGNER_WORKBENCH_H
31
32#include "designer_enums.h"
33
34#include <QtCore/qobject.h>
35#include <QtCore/qhash.h>
36#include <QtCore/qset.h>
37#include <QtCore/qrect.h>
38#include <QtCore/qvector.h>
39
40QT_BEGIN_NAMESPACE
41
42class QDesignerActions;
43class QDesignerToolWindow;
44class QDesignerFormWindow;
45class DockedMainWindow;
46class QDesignerSettings;
47
48class QAction;
49class QActionGroup;
50class QDockWidget;
51class QMenu;
52class QMenuBar;
53class QMainWindow;
54class QToolBar;
55class QMdiArea;
56class QMdiSubWindow;
57class QCloseEvent;
58class QFont;
59class QtToolBarManager;
60class ToolBarManager;
61
62class QDesignerFormEditorInterface;
63class QDesignerFormWindowInterface;
64class QDesignerFormWindowManagerInterface;
65class QDesignerIntegration;
66
67class QDesignerWorkbench: public QObject
68{
69 Q_OBJECT
70
71public:
72 QDesignerWorkbench();
73 ~QDesignerWorkbench() override;
74
75 UIMode mode() const;
76
77 QDesignerFormEditorInterface *core() const;
78 QDesignerFormWindow *findFormWindow(QWidget *widget) const;
79
80 QDesignerFormWindow *openForm(const QString &fileName, QString *errorMessage);
81 QDesignerFormWindow *openTemplate(const QString &templateFileName,
82 const QString &editorFileName,
83 QString *errorMessage);
84
85 int toolWindowCount() const;
86 QDesignerToolWindow *toolWindow(int index) const;
87
88 int formWindowCount() const;
89 QDesignerFormWindow *formWindow(int index) const;
90
91 QDesignerActions *actionManager() const;
92
93 QActionGroup *modeActionGroup() const;
94
95 QRect availableGeometry() const;
96 QRect desktopGeometry() const;
97
98 int marginHint() const;
99
100 bool readInForm(const QString &fileName) const;
101 bool writeOutForm(QDesignerFormWindowInterface *formWindow, const QString &fileName) const;
102 bool saveForm(QDesignerFormWindowInterface *fw);
103 bool handleClose();
104 bool readInBackup();
105 void updateBackup(QDesignerFormWindowInterface* fwi);
106 void applyUiSettings();
107
108signals:
109 void modeChanged(UIMode mode);
110 void initialized();
111
112public slots:
113 void addFormWindow(QDesignerFormWindow *formWindow);
114 void removeFormWindow(QDesignerFormWindow *formWindow);
115 void bringAllToFront();
116 void toggleFormMinimizationState();
117
118private slots:
119 void switchToNeutralMode();
120 void switchToDockedMode();
121 void switchToTopLevelMode();
122 void initializeCorePlugins();
123 void handleCloseEvent(QCloseEvent *);
124 void slotFormWindowActivated(QDesignerFormWindow* fw);
125 void updateWindowMenu(QDesignerFormWindowInterface *fw);
126 void formWindowActionTriggered(QAction *a);
127 void adjustMDIFormPositions();
128 void minimizationStateChanged(QDesignerFormWindowInterface *formWindow, bool minimized);
129
130 void restoreUISettings();
131 void notifyUISettingsChanged();
132 void slotFileDropped(const QString &f);
133
134private:
135 QWidget *magicalParent(const QWidget *w) const;
136 Qt::WindowFlags magicalWindowFlags(const QWidget *widgetForFlags) const;
137 QDesignerFormWindowManagerInterface *formWindowManager() const;
138 void closeAllToolWindows();
139 QDesignerToolWindow *widgetBoxToolWindow() const;
140 QDesignerFormWindow *loadForm(const QString &fileName, bool detectLineTermiantorMode, QString *errorMessage);
141 void resizeForm(QDesignerFormWindow *fw, const QWidget *mainContainer) const;
142 void saveGeometriesForModeChange();
143 void saveGeometries(QDesignerSettings &settings) const;
144
145 bool isFormWindowMinimized(const QDesignerFormWindow *fw);
146 void setFormWindowMinimized(QDesignerFormWindow *fw, bool minimized);
147 void saveSettings() const;
148
149 QDesignerFormEditorInterface *m_core;
150 QDesignerIntegration *m_integration;
151
152 QDesignerActions *m_actionManager;
153 QActionGroup *m_windowActions;
154
155 QMenu *m_windowMenu;
156
157 QMenuBar *m_globalMenuBar;
158
159 struct TopLevelData {
160 ToolBarManager *toolbarManager;
161 QVector<QToolBar *> toolbars;
162 };
163 TopLevelData m_topLevelData;
164
165 UIMode m_mode = NeutralMode;
166 DockedMainWindow *m_dockedMainWindow = nullptr;
167
168 QVector<QDesignerToolWindow *> m_toolWindows;
169 QVector<QDesignerFormWindow *> m_formWindows;
170
171 QMenu *m_toolbarMenu;
172
173 // Helper class to remember the position of a window while switching user
174 // interface modes.
175 class Position {
176 public:
177 Position(const QDockWidget *dockWidget);
178 Position(const QMdiSubWindow *mdiSubWindow, const QPoint &mdiAreaOffset);
179 Position(const QWidget *topLevelWindow, const QPoint &desktopTopLeft);
180
181 void applyTo(QMdiSubWindow *mdiSubWindow, const QPoint &mdiAreaOffset) const;
182 void applyTo(QWidget *topLevelWindow, const QPoint &desktopTopLeft) const;
183 void applyTo(QDockWidget *dockWidget) const;
184
185 QPoint position() const { return m_position; }
186 private:
187 bool m_minimized;
188 // Position referring to top-left corner (desktop in top-level mode or
189 // main window in MDI mode)
190 QPoint m_position;
191 };
192 using PositionMap = QHash<QWidget*, Position>;
193 PositionMap m_Positions;
194
195 enum State { StateInitializing, StateUp, StateClosing };
196 State m_state = StateInitializing;
197 bool m_uiSettingsChanged = false; // UI mode changed in preference dialog, trigger delayed slot.
198};
199
200QT_END_NAMESPACE
201
202#endif // QDESIGNER_WORKBENCH_H
203

source code of qttools/src/designer/src/designer/qdesigner_workbench.h