formeditorplugin.cpp 5.15 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
**
hjk's avatar
hjk committed
7
** Contact: Nokia Corporation (info@qt.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
Tobias Hunger's avatar
Tobias Hunger committed
29
** Nokia at info@qt.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/id.h>
Lasse Holmstedt's avatar
Lasse Holmstedt committed
51
#include <extensionsystem/pluginmanager.h>
52

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

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

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

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

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

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

    Core::ICore *core = Core::ICore::instance();
    if (!core->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
con's avatar
con committed
95
    const QString locale = Core::ICore::instance()->userInterfaceLanguage();
96 97 98 99 100 101 102 103 104
    if (!locale.isEmpty()) {
        QTranslator *qtr = new QTranslator(this);
        const QString &creatorTrPath =
                Core::ICore::instance()->resourcePath() + QLatin1String("/translations");
        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()
{
Lasse Holmstedt's avatar
Lasse Holmstedt committed
111
    // 4) test and make sure everything works (undo, saving, editors, opening/closing multiple files, dirtiness etc)
con's avatar
con committed
112 113 114 115 116 117 118 119
}

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

120
void FormEditorPlugin::initializeTemplates()
con's avatar
con committed
121 122
{
    FormWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
Friedemann Kleint's avatar
Friedemann Kleint committed
123
    wizardParameters.setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT));
124
    wizardParameters.setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
con's avatar
con committed
125
    const QString formFileType = QLatin1String(Constants::FORM_FILE_TYPE);
126
    wizardParameters.setDisplayName(tr("Qt Designer Form"));
Friedemann Kleint's avatar
Friedemann Kleint committed
127
    wizardParameters.setId(QLatin1String("D.Form"));
Leena Miettinen's avatar
Leena Miettinen committed
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));
con's avatar
con committed
131 132 133

#ifdef CPP_ENABLED
    wizardParameters.setKind(Core::IWizard::ClassWizard);
134
    wizardParameters.setDisplayName(tr("Qt Designer Form Class"));
Friedemann Kleint's avatar
Friedemann Kleint committed
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) "
Leena Miettinen's avatar
Leena Miettinen committed
137
                                       "for implementation purposes. You can add the form and class to an existing Qt Widget Project."));
138 139
    addAutoReleasedObject(new FormClassWizard(wizardParameters, this));
    addAutoReleasedObject(new CppSettingsPage);
con's avatar
con committed
140 141 142 143
#endif
}

Q_EXPORT_PLUGIN(FormEditorPlugin)