1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "formeditorplugin.h"
34 #include "formeditorfactory.h"
35 #include "formeditorw.h"
36 #include "formwizard.h"
39 # include "formclasswizard.h"
40 # include "cppsettingspage.h"
43 #include "settingspage.h"
44 #include "designerconstants.h"
45 #include "qtdesignerformclasscodegenerator.h"
47 #include <coreplugin/icore.h>
48 #include <coreplugin/mimedatabase.h>
49 #include <coreplugin/coreconstants.h>
50 #include <coreplugin/uniqueidmanager.h>
51 #include <extensionsystem/pluginmanager.h>
53 #include <QtCore/QDebug>
54 #include <QtCore/QLibraryInfo>
55 #include <QtCore/QTranslator>
56 #include <QtCore/QtPlugin>
59 # include <QtGui/QWizard>
60 # include <QtGui/QMainWindow>
63 using namespace Designer::Internal;
64 using namespace Designer::Constants;
66 FormEditorPlugin::FormEditorPlugin()
70 FormEditorPlugin::~FormEditorPlugin()
72 FormEditorW::deleteInstance();
75 ////////////////////////////////////////////////////
77 // INHERITED FROM ExtensionSystem::Plugin
79 ////////////////////////////////////////////////////
80 bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error)
85 Core::ICore *core = Core::ICore::instance();
86 if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/formeditor/Designer.mimetypes.xml"), error))
89 initializeTemplates();
91 addAutoReleasedObject(new FormEditorFactory);
92 addAutoReleasedObject(new SettingsPageProvider);
93 addAutoReleasedObject(new QtDesignerFormClassCodeGenerator);
94 // Ensure that loading designer translations is done before FormEditorW is instantiated
95 const QString locale = Core::ICore::instance()->userInterfaceLanguage();
96 if (!locale.isEmpty()) {
97 QTranslator *qtr = new QTranslator(this);
98 const QString &creatorTrPath =
99 Core::ICore::instance()->resourcePath() + QLatin1String("/translations");
100 const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
101 const QString &trFile = QLatin1String("designer_") + locale;
102 if (qtr->load(trFile, qtTrPath) || qtr->load(trFile, creatorTrPath))
103 qApp->installTranslator(qtr);
109 void FormEditorPlugin::extensionsInitialized()
111 // 4) test and make sure everything works (undo, saving, editors, opening/closing multiple files, dirtiness etc)
114 ////////////////////////////////////////////////////
118 ////////////////////////////////////////////////////
120 void FormEditorPlugin::initializeTemplates()
122 FormWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
123 wizardParameters.setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT));
124 wizardParameters.setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
125 const QString formFileType = QLatin1String(Constants::FORM_FILE_TYPE);
126 wizardParameters.setDisplayName(tr("Qt Designer Form"));
127 wizardParameters.setId(QLatin1String("D.Form"));
128 wizardParameters.setDescription(tr("Creates a Qt Designer form that you can add to a Qt Widget Project. "
129 "This is useful if you already have an existing class for the UI business logic."));
130 addAutoReleasedObject(new FormWizard(wizardParameters, this));
133 wizardParameters.setKind(Core::IWizard::ClassWizard);
134 wizardParameters.setDisplayName(tr("Qt Designer Form Class"));
135 wizardParameters.setId(QLatin1String("C.FormClass"));
136 wizardParameters.setDescription(tr("Creates a Qt Designer form along with a matching class (C++ header and source file) "
137 "for implementation purposes. You can add the form and class to an existing Qt Widget Project."));
138 addAutoReleasedObject(new FormClassWizard(wizardParameters, this));
139 addAutoReleasedObject(new CppSettingsPage);
143 Q_EXPORT_PLUGIN(FormEditorPlugin)