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 #include "formeditor.h"
30 #include "formeditor_optionspage.h"
31 #include "embeddedoptionspage.h"
32 #include "templateoptionspage.h"
33 #include "metadatabase_p.h"
34 #include "widgetdatabase_p.h"
35 #include "widgetfactory_p.h"
36 #include "formwindowmanager.h"
37 #include "qmainwindow_container.h"
38 #include "qmdiarea_container.h"
39 #include "qwizard_container.h"
40 #include "default_container.h"
41 #include "default_layoutdecoration.h"
42 #include "default_actionprovider.h"
43 #include "qlayoutwidget_propertysheet.h"
44 #include "spacer_propertysheet.h"
45 #include "line_propertysheet.h"
46 #include "layout_propertysheet.h"
47 #include "qdesigner_dockwidget_p.h"
48 #include "qdesigner_stackedbox_p.h"
49 #include "qdesigner_toolbox_p.h"
50 #include "qdesigner_tabwidget_p.h"
51 #include "qtresourcemodel_p.h"
52 #include "itemview_propertysheet.h"
53
54 // sdk
55 #include <QtDesigner/qextensionmanager.h>
56 #include <QtDesigner/abstractintegration.h>
57 // shared
58 #include <pluginmanager_p.h>
59 #include <qdesigner_taskmenu_p.h>
60 #include <qdesigner_membersheet_p.h>
61 #include <qdesigner_promotion_p.h>
62 #include <dialoggui_p.h>
63 #include <qdesigner_introspection_p.h>
64 #include <qdesigner_qsettings_p.h>
65
66 QT_BEGIN_NAMESPACE
67
68 namespace qdesigner_internal {
69
FormEditor(QObject * parent)70 FormEditor::FormEditor(QObject *parent)
71 : QDesignerFormEditorInterface(parent)
72 {
73 setIntrospection(new QDesignerIntrospection);
74 setDialogGui(new DialogGui);
75 QDesignerPluginManager *pluginManager = new QDesignerPluginManager(this);
76 setPluginManager(pluginManager);
77
78 WidgetDataBase *widgetDatabase = new WidgetDataBase(this, this);
79 setWidgetDataBase(widgetDatabase);
80
81 MetaDataBase *metaDataBase = new MetaDataBase(this, this);
82 setMetaDataBase(metaDataBase);
83
84 WidgetFactory *widgetFactory = new WidgetFactory(this, this);
85 setWidgetFactory(widgetFactory);
86
87 FormWindowManager *formWindowManager = new FormWindowManager(this, this);
88 setFormManager(formWindowManager);
89 connect(formWindowManager, &QDesignerFormWindowManagerInterface::formWindowAdded,
90 widgetFactory, &WidgetFactory::formWindowAdded);
91 connect(formWindowManager, &QDesignerFormWindowManagerInterface::activeFormWindowChanged,
92 widgetFactory, &WidgetFactory::activeFormWindowChanged);
93
94 QExtensionManager *mgr = new QExtensionManager(this);
95 const QString containerExtensionId = Q_TYPEID(QDesignerContainerExtension);
96
97 QDesignerStackedWidgetContainerFactory::registerExtension(mgr, containerExtensionId);
98 QDesignerTabWidgetContainerFactory::registerExtension(mgr, containerExtensionId);
99 QDesignerToolBoxContainerFactory::registerExtension(mgr, containerExtensionId);
100 QMainWindowContainerFactory::registerExtension(mgr, containerExtensionId);
101 QDockWidgetContainerFactory::registerExtension(mgr, containerExtensionId);
102 QScrollAreaContainerFactory::registerExtension(mgr, containerExtensionId);
103 QMdiAreaContainerFactory::registerExtension(mgr, containerExtensionId);
104 QWizardContainerFactory::registerExtension(mgr, containerExtensionId);
105
106 mgr->registerExtensions(new QDesignerLayoutDecorationFactory(mgr),
107 Q_TYPEID(QDesignerLayoutDecorationExtension));
108
109 const QString actionProviderExtensionId = Q_TYPEID(QDesignerActionProviderExtension);
110 QToolBarActionProviderFactory::registerExtension(mgr, actionProviderExtensionId);
111 QMenuBarActionProviderFactory::registerExtension(mgr, actionProviderExtensionId);
112 QMenuActionProviderFactory::registerExtension(mgr, actionProviderExtensionId);
113
114 QDesignerDefaultPropertySheetFactory::registerExtension(mgr);
115 QDockWidgetPropertySheetFactory::registerExtension(mgr);
116 QLayoutWidgetPropertySheetFactory::registerExtension(mgr);
117 SpacerPropertySheetFactory::registerExtension(mgr);
118 LinePropertySheetFactory::registerExtension(mgr);
119 LayoutPropertySheetFactory::registerExtension(mgr);
120 QStackedWidgetPropertySheetFactory::registerExtension(mgr);
121 QToolBoxWidgetPropertySheetFactory::registerExtension(mgr);
122 QTabWidgetPropertySheetFactory::registerExtension(mgr);
123 QMdiAreaPropertySheetFactory::registerExtension(mgr);
124 QWizardPagePropertySheetFactory::registerExtension(mgr);
125 QWizardPropertySheetFactory::registerExtension(mgr);
126
127 QTreeViewPropertySheetFactory::registerExtension(mgr);
128 QTableViewPropertySheetFactory::registerExtension(mgr);
129
130 const QString internalTaskMenuId = QStringLiteral("QDesignerInternalTaskMenuExtension");
131 QDesignerTaskMenuFactory::registerExtension(mgr, internalTaskMenuId);
132
133 mgr->registerExtensions(new QDesignerMemberSheetFactory(mgr),
134 Q_TYPEID(QDesignerMemberSheetExtension));
135
136 setExtensionManager(mgr);
137
138 setPromotion(new QDesignerPromotion(this));
139
140 QtResourceModel *resourceModel = new QtResourceModel(this);
141 setResourceModel(resourceModel);
142 connect(resourceModel, &QtResourceModel::qrcFileModifiedExternally,
143 this, &FormEditor::slotQrcFileChangedExternally);
144
145 QList<QDesignerOptionsPageInterface*> optionsPages;
146 optionsPages << new TemplateOptionsPage(this) << new FormEditorOptionsPage(this) << new EmbeddedOptionsPage(this);
147 setOptionsPages(optionsPages);
148
149 setSettingsManager(new QDesignerQSettings());
150 }
151
152 FormEditor::~FormEditor() = default;
153
slotQrcFileChangedExternally(const QString & path)154 void FormEditor::slotQrcFileChangedExternally(const QString &path)
155 {
156 if (!integration())
157 return;
158
159 QDesignerIntegration::ResourceFileWatcherBehaviour behaviour = integration()->resourceFileWatcherBehaviour();
160 if (behaviour == QDesignerIntegration::NoResourceFileWatcher)
161 return;
162 if (behaviour == QDesignerIntegration::PromptToReloadResourceFile) {
163 QMessageBox::StandardButton button = dialogGui()->message(topLevel(), QDesignerDialogGuiInterface::FileChangedMessage, QMessageBox::Warning,
164 tr("Resource File Changed"),
165 tr("The file \"%1\" has changed outside Designer. Do you want to reload it?").arg(path),
166 QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
167
168 if (button != QMessageBox::Yes)
169 return;
170 }
171
172 resourceModel()->reload(path);
173 }
174
175 }
176
177 QT_END_NAMESPACE
178