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 MAINWINDOW_H
30#define MAINWINDOW_H
31
32#include <QtWidgets/qmainwindow.h>
33#include <QtCore/qvector.h>
34#include <QtWidgets/qmdiarea.h>
35
36QT_BEGIN_NAMESPACE
37
38class QDesignerActions;
39class QDesignerWorkbench;
40class QDesignerToolWindow;
41class QDesignerFormWindow;
42class QDesignerSettings;
43
44class QtToolBarManager;
45class QToolBar;
46class QMdiArea;
47class QMenu;
48class QByteArray;
49class QMimeData;
50
51/* A main window that has a configureable policy on handling close events. If
52 * enabled, it can forward the close event to external handlers.
53 * Base class for windows that can switch roles between tool windows
54 * and main windows. */
55
56class MainWindowBase: public QMainWindow
57{
58 Q_DISABLE_COPY_MOVE(MainWindowBase)
59 Q_OBJECT
60protected:
61 explicit MainWindowBase(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::Window);
62
63public:
64 enum CloseEventPolicy {
65 /* Always accept close events */
66 AcceptCloseEvents,
67 /* Emit a signal with the event, have it handled elsewhere */
68 EmitCloseEventSignal };
69
70 CloseEventPolicy closeEventPolicy() const { return m_policy; }
71 void setCloseEventPolicy(CloseEventPolicy pol) { m_policy = pol; }
72
73 static QVector<QToolBar *> createToolBars(const QDesignerActions *actions, bool singleToolBar);
74 static QString mainWindowTitle();
75
76 // Use the minor Qt version as settings versions to avoid conflicts
77 static int settingsVersion();
78
79signals:
80 void closeEventReceived(QCloseEvent *e);
81
82protected:
83 void closeEvent(QCloseEvent *e) override;
84private:
85 CloseEventPolicy m_policy = AcceptCloseEvents;
86};
87
88/* An MdiArea that listens for desktop file manager file drop events and emits
89 * a signal to open a dropped file. */
90class DockedMdiArea : public QMdiArea
91{
92 Q_DISABLE_COPY_MOVE(DockedMdiArea)
93 Q_OBJECT
94public:
95 explicit DockedMdiArea(const QString &extension, QWidget *parent = nullptr);
96
97signals:
98 void fileDropped(const QString &);
99
100protected:
101 bool event (QEvent *event);
102
103private:
104 QStringList uiFiles(const QMimeData *d) const;
105
106 const QString m_extension;
107};
108
109// Convenience class that manages a QtToolBarManager and an action to trigger
110// it on a mainwindow.
111class ToolBarManager : public QObject
112{
113 Q_OBJECT
114 Q_DISABLE_COPY_MOVE(ToolBarManager)
115public:
116 explicit ToolBarManager(QMainWindow *configureableMainWindow,
117 QWidget *parent,
118 QMenu *toolBarMenu,
119 const QDesignerActions *actions,
120 const QVector<QToolBar *> &toolbars,
121 const QVector<QDesignerToolWindow *> &toolWindows);
122
123 QByteArray saveState(int version = 0) const;
124 bool restoreState(const QByteArray &state, int version = 0);
125
126private slots:
127 void configureToolBars();
128 void updateToolBarMenu();
129
130private:
131 QMainWindow *m_configureableMainWindow;
132 QWidget *m_parent;
133 QMenu *m_toolBarMenu;
134 QtToolBarManager *m_manager;
135 QAction *m_configureAction;
136 QVector<QToolBar *> m_toolbars;
137};
138
139/* Main window to be used for docked mode */
140class DockedMainWindow : public MainWindowBase {
141 Q_OBJECT
142 Q_DISABLE_COPY_MOVE(DockedMainWindow)
143public:
144 using DesignerToolWindowList = QVector<QDesignerToolWindow *>;
145 using DockWidgetList = QVector<QDockWidget *>;
146
147 explicit DockedMainWindow(QDesignerWorkbench *wb,
148 QMenu *toolBarMenu,
149 const DesignerToolWindowList &toolWindows);
150
151 // Create a MDI subwindow for the form.
152 QMdiSubWindow *createMdiSubWindow(QWidget *fw, Qt::WindowFlags f, const QKeySequence &designerCloseActionShortCut);
153
154 QMdiArea *mdiArea() const;
155
156 DockWidgetList addToolWindows(const DesignerToolWindowList &toolWindows);
157
158 void restoreSettings(const QDesignerSettings &s, const DockWidgetList &dws, const QRect &desktopArea);
159 void saveSettings(QDesignerSettings &) const;
160
161signals:
162 void fileDropped(const QString &);
163 void formWindowActivated(QDesignerFormWindow *);
164
165private slots:
166 void slotSubWindowActivated(QMdiSubWindow*);
167
168private:
169 ToolBarManager *m_toolBarManager;
170};
171
172QT_END_NAMESPACE
173
174#endif // MAINWINDOW_H
175

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