formeditorplugin.cpp 5.18 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
**
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12
13
14
15
16
17
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21
22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23
24
25
26
27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
con's avatar
con committed
30
**
31
**************************************************************************/
hjk's avatar
hjk committed
32

con's avatar
con committed
33
34
35
36
37
38
39
#include "formeditorplugin.h"
#include "formeditorfactory.h"
#include "formeditorw.h"
#include "formwizard.h"

#ifdef CPP_ENABLED
#  include "formclasswizard.h"
40
#  include "cppsettingspage.h"
con's avatar
con committed
41
42
#endif

43
#include "settingspage.h"
con's avatar
con committed
44
#include "designerconstants.h"
45
#include "qtdesignerformclasscodegenerator.h"
con's avatar
con committed
46
47
48
49

#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/coreconstants.h>
50
#include <coreplugin/designmode.h>
51
#include <coreplugin/id.h>
Lasse Holmstedt's avatar
Lasse Holmstedt committed
52
#include <extensionsystem/pluginmanager.h>
53

con's avatar
con committed
54
#include <QtCore/QDebug>
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
55
56
#include <QtCore/QLibraryInfo>
#include <QtCore/QTranslator>
57
#include <QtCore/QtPlugin>
Lasse Holmstedt's avatar
Lasse Holmstedt committed
58

con's avatar
con committed
59
60
61
62
63
64
65
66
#ifdef CPP_ENABLED
#    include <QtGui/QWizard>
#    include <QtGui/QMainWindow>
#endif

using namespace Designer::Internal;
using namespace Designer::Constants;

67
FormEditorPlugin::FormEditorPlugin()
con's avatar
con committed
68
69
70
71
72
73
74
75
76
77
78
79
80
{
}

FormEditorPlugin::~FormEditorPlugin()
{
    FormEditorW::deleteInstance();
}

////////////////////////////////////////////////////
//
// INHERITED FROM ExtensionSystem::Plugin
//
////////////////////////////////////////////////////
81
bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error)
con's avatar
con committed
82
{
83
84
    Q_UNUSED(arguments)
    Q_UNUSED(error)
85

hjk's avatar
hjk committed
86
    if (!Core::ICore::mimeDatabase()->addMimeTypes(QLatin1String(":/formeditor/Designer.mimetypes.xml"), error))
con's avatar
con committed
87
88
        return false;

89
    initializeTemplates();
con's avatar
con committed
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
hjk's avatar
hjk committed
95
    const QString locale = Core::ICore::userInterfaceLanguage();
96
97
98
    if (!locale.isEmpty()) {
        QTranslator *qtr = new QTranslator(this);
        const QString &creatorTrPath =
hjk's avatar
hjk committed
99
                Core::ICore::resourcePath() + QLatin1String("/translations");
100
101
102
103
104
        const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
        const QString &trFile = QLatin1String("designer_") + locale;
        if (qtr->load(trFile, qtTrPath) || qtr->load(trFile, creatorTrPath))
            qApp->installTranslator(qtr);
    }
105
    error->clear();
con's avatar
con committed
106
107
108
109
110
    return true;
}

void FormEditorPlugin::extensionsInitialized()
{
111
    Core::DesignMode::instance()->setDesignModeIsRequired();
Lasse Holmstedt's avatar
Lasse Holmstedt committed
112
    // 4) test and make sure everything works (undo, saving, editors, opening/closing multiple files, dirtiness etc)
con's avatar
con committed
113
114
115
116
117
118
119
120
}

////////////////////////////////////////////////////
//
// PRIVATE methods
//
////////////////////////////////////////////////////

121
void FormEditorPlugin::initializeTemplates()
con's avatar
con committed
122
123
{
    FormWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
Friedemann Kleint's avatar
Friedemann Kleint committed
124
    wizardParameters.setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT));
125
    wizardParameters.setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
con's avatar
con committed
126
    const QString formFileType = QLatin1String(Constants::FORM_FILE_TYPE);
127
    wizardParameters.setDisplayName(tr("Qt Designer Form"));
Friedemann Kleint's avatar
Friedemann Kleint committed
128
    wizardParameters.setId(QLatin1String("D.Form"));
Leena Miettinen's avatar
Leena Miettinen committed
129
    wizardParameters.setDescription(tr("Creates a Qt Designer form that you can add to a Qt Widget Project. "
130
                                       "This is useful if you already have an existing class for the UI business logic."));
131
    addAutoReleasedObject(new FormWizard(wizardParameters, this));
con's avatar
con committed
132
133
134

#ifdef CPP_ENABLED
    wizardParameters.setKind(Core::IWizard::ClassWizard);
135
    wizardParameters.setDisplayName(tr("Qt Designer Form Class"));
Friedemann Kleint's avatar
Friedemann Kleint committed
136
    wizardParameters.setId(QLatin1String("C.FormClass"));
137
    wizardParameters.setDescription(tr("Creates a Qt Designer form along with a matching class (C++ header and source file) "
Leena Miettinen's avatar
Leena Miettinen committed
138
                                       "for implementation purposes. You can add the form and class to an existing Qt Widget Project."));
139
140
    addAutoReleasedObject(new FormClassWizard(wizardParameters, this));
    addAutoReleasedObject(new CppSettingsPage);
con's avatar
con committed
141
142
143
144
#endif
}

Q_EXPORT_PLUGIN(FormEditorPlugin)