formeditorplugin.cpp 5.31 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
36
#include "formeditorplugin.h"
#include "formeditorfactory.h"
#include "formeditorw.h"
#include "formwizard.h"

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

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

#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/coreconstants.h>
47
#include <coreplugin/designmode.h>
48
#include <coreplugin/id.h>
Lasse Holmstedt's avatar
Lasse Holmstedt committed
49
#include <extensionsystem/pluginmanager.h>
50

51
52
53
54
#include <QDebug>
#include <QLibraryInfo>
#include <QTranslator>
#include <QtPlugin>
Lasse Holmstedt's avatar
Lasse Holmstedt committed
55

con's avatar
con committed
56
#ifdef CPP_ENABLED
57
58
#    include <QWizard>
#    include <QMainWindow>
con's avatar
con committed
59
60
61
62
63
#endif

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

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

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

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

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

86
    initializeTemplates();
con's avatar
con committed
87

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

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

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

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

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

Q_EXPORT_PLUGIN(FormEditorPlugin)