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 | |
36 | QT_BEGIN_NAMESPACE |
37 | |
38 | class QDesignerActions; |
39 | class QDesignerWorkbench; |
40 | class QDesignerToolWindow; |
41 | class QDesignerFormWindow; |
42 | class QDesignerSettings; |
43 | |
44 | class QtToolBarManager; |
45 | class QToolBar; |
46 | class QMdiArea; |
47 | class ; |
48 | class QByteArray; |
49 | class 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 | |
56 | class MainWindowBase: public QMainWindow |
57 | { |
58 | Q_DISABLE_COPY_MOVE(MainWindowBase) |
59 | Q_OBJECT |
60 | protected: |
61 | explicit MainWindowBase(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::Window); |
62 | |
63 | public: |
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 | |
79 | signals: |
80 | void closeEventReceived(QCloseEvent *e); |
81 | |
82 | protected: |
83 | void closeEvent(QCloseEvent *e) override; |
84 | private: |
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. */ |
90 | class DockedMdiArea : public QMdiArea |
91 | { |
92 | Q_DISABLE_COPY_MOVE(DockedMdiArea) |
93 | Q_OBJECT |
94 | public: |
95 | explicit DockedMdiArea(const QString &extension, QWidget *parent = nullptr); |
96 | |
97 | signals: |
98 | void fileDropped(const QString &); |
99 | |
100 | protected: |
101 | bool event (QEvent *event); |
102 | |
103 | private: |
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. |
111 | class ToolBarManager : public QObject |
112 | { |
113 | Q_OBJECT |
114 | Q_DISABLE_COPY_MOVE(ToolBarManager) |
115 | public: |
116 | explicit ToolBarManager(QMainWindow *configureableMainWindow, |
117 | QWidget *parent, |
118 | QMenu *, |
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 | |
126 | private slots: |
127 | void configureToolBars(); |
128 | void (); |
129 | |
130 | private: |
131 | QMainWindow *m_configureableMainWindow; |
132 | QWidget *m_parent; |
133 | QMenu *; |
134 | QtToolBarManager *m_manager; |
135 | QAction *m_configureAction; |
136 | QVector<QToolBar *> m_toolbars; |
137 | }; |
138 | |
139 | /* Main window to be used for docked mode */ |
140 | class DockedMainWindow : public MainWindowBase { |
141 | Q_OBJECT |
142 | Q_DISABLE_COPY_MOVE(DockedMainWindow) |
143 | public: |
144 | using DesignerToolWindowList = QVector<QDesignerToolWindow *>; |
145 | using DockWidgetList = QVector<QDockWidget *>; |
146 | |
147 | explicit DockedMainWindow(QDesignerWorkbench *wb, |
148 | QMenu *, |
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 | |
161 | signals: |
162 | void fileDropped(const QString &); |
163 | void formWindowActivated(QDesignerFormWindow *); |
164 | |
165 | private slots: |
166 | void slotSubWindowActivated(QMdiSubWindow*); |
167 | |
168 | private: |
169 | ToolBarManager *m_toolBarManager; |
170 | }; |
171 | |
172 | QT_END_NAMESPACE |
173 | |
174 | #endif // MAINWINDOW_H |
175 | |