OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / designer / formeditorplugin.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "formeditorplugin.h"
34 #include "formeditorfactory.h"
35 #include "formeditorw.h"
36 #include "formwizard.h"
37
38 #ifdef CPP_ENABLED
39 #  include "formclasswizard.h"
40 #  include "cppsettingspage.h"
41 #endif
42
43 #include "settingspage.h"
44 #include "designerconstants.h"
45 #include "qtdesignerformclasscodegenerator.h"
46
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>
52
53 #include <QtCore/QDebug>
54 #include <QtCore/QLibraryInfo>
55 #include <QtCore/QTranslator>
56 #include <QtCore/QtPlugin>
57
58 #ifdef CPP_ENABLED
59 #    include <QtGui/QWizard>
60 #    include <QtGui/QMainWindow>
61 #endif
62
63 using namespace Designer::Internal;
64 using namespace Designer::Constants;
65
66 FormEditorPlugin::FormEditorPlugin()
67 {
68 }
69
70 FormEditorPlugin::~FormEditorPlugin()
71 {
72     FormEditorW::deleteInstance();
73 }
74
75 ////////////////////////////////////////////////////
76 //
77 // INHERITED FROM ExtensionSystem::Plugin
78 //
79 ////////////////////////////////////////////////////
80 bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error)
81 {
82     Q_UNUSED(arguments)
83     Q_UNUSED(error)
84
85     Core::ICore *core = Core::ICore::instance();
86     if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/formeditor/Designer.mimetypes.xml"), error))
87         return false;
88
89     initializeTemplates();
90
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);
104     }
105     error->clear();
106     return true;
107 }
108
109 void FormEditorPlugin::extensionsInitialized()
110 {
111     // 4) test and make sure everything works (undo, saving, editors, opening/closing multiple files, dirtiness etc)
112 }
113
114 ////////////////////////////////////////////////////
115 //
116 // PRIVATE methods
117 //
118 ////////////////////////////////////////////////////
119
120 void FormEditorPlugin::initializeTemplates()
121 {
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));
131
132 #ifdef CPP_ENABLED
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);
140 #endif
141 }
142
143 Q_EXPORT_PLUGIN(FormEditorPlugin)