formeditorplugin.cpp 5.1 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
** Alternatively, 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.
23
**
hjk's avatar
hjk committed
24
25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
33
34
35
#include "formeditorplugin.h"
#include "formeditorfactory.h"
#include "formeditorw.h"
#include "formwizard.h"

#ifdef CPP_ENABLED
36
37
#  include "cpp/formclasswizard.h"
#  include "cpp/cppsettingspage.h"
con's avatar
con committed
38
39
#endif

40
#include "settingspage.h"
41
#include "qtdesignerformclasscodegenerator.h"
con's avatar
con committed
42
43
44
45

#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/coreconstants.h>
46
#include <coreplugin/designmode.h>
47

48
49
50
51
#include <QDebug>
#include <QLibraryInfo>
#include <QTranslator>
#include <QtPlugin>
Lasse Holmstedt's avatar
Lasse Holmstedt committed
52

hjk's avatar
hjk committed
53
using namespace Core;
con's avatar
con committed
54
55
56
using namespace Designer::Internal;
using namespace Designer::Constants;

57
FormEditorPlugin::FormEditorPlugin()
con's avatar
con committed
58
59
60
61
62
63
64
65
66
67
68
69
70
{
}

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

////////////////////////////////////////////////////
//
// INHERITED FROM ExtensionSystem::Plugin
//
////////////////////////////////////////////////////
71
bool FormEditorPlugin::initialize(const QStringList &arguments, QString *error)
con's avatar
con committed
72
{
73
    Q_UNUSED(arguments)
74

hjk's avatar
hjk committed
75
    if (!MimeDatabase::addMimeTypes(QLatin1String(":/formeditor/Designer.mimetypes.xml"), error))
con's avatar
con committed
76
77
        return false;

78
    initializeTemplates();
con's avatar
con committed
79

80
    addAutoReleasedObject(new FormEditorFactory);
81
    addAutoReleasedObject(new SettingsPageProvider);
82
    addAutoReleasedObject(new QtDesignerFormClassCodeGenerator);
83
    // Ensure that loading designer translations is done before FormEditorW is instantiated
hjk's avatar
hjk committed
84
    const QString locale = ICore::userInterfaceLanguage();
85
86
87
    if (!locale.isEmpty()) {
        QTranslator *qtr = new QTranslator(this);
        const QString &creatorTrPath =
hjk's avatar
hjk committed
88
                ICore::resourcePath() + QLatin1String("/translations");
89
90
91
92
93
        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);
    }
94
    error->clear();
con's avatar
con committed
95
96
97
98
99
    return true;
}

void FormEditorPlugin::extensionsInitialized()
{
hjk's avatar
hjk committed
100
    DesignMode::instance()->setDesignModeIsRequired();
Lasse Holmstedt's avatar
Lasse Holmstedt committed
101
    // 4) test and make sure everything works (undo, saving, editors, opening/closing multiple files, dirtiness etc)
con's avatar
con committed
102
103
104
105
106
107
108
109
}

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

110
void FormEditorPlugin::initializeTemplates()
con's avatar
con committed
111
{
hjk's avatar
hjk committed
112
    FormWizard::BaseFileWizardParameters wizardParameters(IWizard::FileWizard);
Friedemann Kleint's avatar
Friedemann Kleint committed
113
    wizardParameters.setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT));
114
    wizardParameters.setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
con's avatar
con committed
115
    const QString formFileType = QLatin1String(Constants::FORM_FILE_TYPE);
116
    wizardParameters.setDisplayName(tr("Qt Designer Form"));
Friedemann Kleint's avatar
Friedemann Kleint committed
117
    wizardParameters.setId(QLatin1String("D.Form"));
Leena Miettinen's avatar
Leena Miettinen committed
118
    wizardParameters.setDescription(tr("Creates a Qt Designer form that you can add to a Qt Widget Project. "
119
                                       "This is useful if you already have an existing class for the UI business logic."));
120
    addAutoReleasedObject(new FormWizard(wizardParameters, this));
con's avatar
con committed
121
122

#ifdef CPP_ENABLED
hjk's avatar
hjk committed
123
    wizardParameters.setKind(IWizard::ClassWizard);
124
    wizardParameters.setDisplayName(tr("Qt Designer Form Class"));
Friedemann Kleint's avatar
Friedemann Kleint committed
125
    wizardParameters.setId(QLatin1String("C.FormClass"));
126
    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
127
                                       "for implementation purposes. You can add the form and class to an existing Qt Widget Project."));
128
129
    addAutoReleasedObject(new FormClassWizard(wizardParameters, this));
    addAutoReleasedObject(new CppSettingsPage);
con's avatar
con committed
130
131
132
133
#endif
}

Q_EXPORT_PLUGIN(FormEditorPlugin)