OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmlprojectmanager / qmlprojectapplicationwizard.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 "qmlprojectapplicationwizard.h"
34
35 #include "qmlprojectconstants.h"
36
37 #include <coreplugin/coreconstants.h>
38 #include <projectexplorer/customwizard/customwizard.h>
39 #include <qt4projectmanager/qt4projectmanagerconstants.h>
40
41 #include <QtGui/QIcon>
42
43 #include <QtGui/QPainter>
44 #include <QtGui/QPixmap>
45
46 #include <QtCore/QDir>
47 #include <QtCore/QTextStream>
48 #include <QtCore/QCoreApplication>
49
50 namespace QmlProjectManager {
51 namespace Internal {
52
53 QmlProjectApplicationWizardDialog::QmlProjectApplicationWizardDialog(QWidget *parent) :
54     ProjectExplorer::BaseProjectWizardDialog(parent)
55 {
56     setWindowTitle(tr("New Qt Quick UI Project"));
57     setIntroDescription(tr("This wizard generates a Qt Quick UI project."));
58 }
59
60 QmlProjectApplicationWizard::QmlProjectApplicationWizard()
61     : Core::BaseFileWizard(parameters())
62 { }
63
64 QmlProjectApplicationWizard::~QmlProjectApplicationWizard()
65 { }
66
67 Core::BaseFileWizardParameters QmlProjectApplicationWizard::parameters()
68 {
69     Core::BaseFileWizardParameters parameters(ProjectWizard);
70     parameters.setIcon(QIcon(QLatin1String(Qt4ProjectManager::Constants::QML_WIZARD_ICON)));
71     parameters.setDisplayName(tr("Qt Quick UI"));
72     parameters.setId(QLatin1String("QB.QML Application"));
73
74     parameters.setDescription(tr("Creates a  Qt Quick UI project with a single "
75         "QML file that contains the main view.\n\n"
76         "You can review Qt Quick UI projects in the QML Viewer and you need not build them. "
77         "You do not need to have the development environment installed "
78         "on your computer to create and run this type of projects."));
79     parameters.setCategory(QLatin1String(Qt4ProjectManager::Constants::QML_WIZARD_CATEGORY));
80     parameters.setDisplayCategory(QCoreApplication::translate(Qt4ProjectManager::Constants::QML_WIZARD_TR_SCOPE,
81                                                               Qt4ProjectManager::Constants::QML_WIZARD_TR_CATEGORY));
82     return parameters;
83 }
84
85 QWizard *QmlProjectApplicationWizard::createWizardDialog(QWidget *parent,
86                                                   const QString &defaultPath,
87                                                   const WizardPageList &extensionPages) const
88 {
89     QmlProjectApplicationWizardDialog *wizard = new QmlProjectApplicationWizardDialog(parent);
90
91     wizard->setPath(defaultPath);
92     wizard->setProjectName(QmlProjectApplicationWizardDialog::uniqueProjectName(defaultPath));
93
94     foreach (QWizardPage *p, extensionPages)
95         BaseFileWizard::applyExtensionPageShortTitle(wizard, wizard->addPage(p));
96
97     return wizard;
98 }
99
100 Core::GeneratedFiles QmlProjectApplicationWizard::generateFiles(const QWizard *w,
101                                                      QString *errorMessage) const
102 {
103     Q_UNUSED(errorMessage)
104
105     const QmlProjectApplicationWizardDialog *wizard = qobject_cast<const QmlProjectApplicationWizardDialog *>(w);
106     const QString projectName = wizard->projectName();
107     const QString projectPath = wizard->path() + QLatin1Char('/') + projectName;
108
109     const QString creatorFileName = Core::BaseFileWizard::buildFileName(projectPath,
110                                                                         projectName,
111                                                                         QLatin1String("qmlproject"));
112
113     const QString mainFileName = Core::BaseFileWizard::buildFileName(projectPath,
114                                                                      projectName,
115                                                                      QLatin1String("qml"));
116
117     QString contents;
118     {
119         QTextStream out(&contents);
120
121         out
122             << "import QtQuick 1.0" << endl
123             << endl
124             << "Rectangle {" << endl
125             << "    width: 360" << endl
126             << "    height: 360" << endl
127             << "    Text {" << endl
128             << "        anchors.centerIn: parent" << endl
129             << "        text: \"Hello World\"" << endl
130             << "    }" << endl
131             << "    MouseArea {" << endl
132             << "        anchors.fill: parent" << endl
133             << "        onClicked: {" << endl
134             << "            Qt.quit();" << endl
135             << "        }" << endl
136             << "    }" << endl
137             << "}" << endl;
138     }
139     Core::GeneratedFile generatedMainFile(mainFileName);
140     generatedMainFile.setContents(contents);
141     generatedMainFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
142
143     QString projectContents;
144     {
145         QTextStream out(&projectContents);
146
147         out << "/* File generated by Qt Creator, version " << Core::Constants::IDE_VERSION_LONG << " */" << endl
148             << endl
149             << "import QmlProject 1.1" << endl
150             << endl
151             << "Project {" << endl
152             << "    mainFile: \"" << QDir(projectPath).relativeFilePath(mainFileName) << '"' << endl
153             << endl
154             << "    /* Include .qml, .js, and image files from current directory and subdirectories */" << endl
155             << "    QmlFiles {" << endl
156             << "        directory: \".\"" << endl
157             << "    }" << endl
158             << "    JavaScriptFiles {" << endl
159             << "        directory: \".\"" << endl
160             << "    }" << endl
161             << "    ImageFiles {" << endl
162             << "        directory: \".\"" << endl
163             << "    }" << endl
164             << "    /* List of plugin directories passed to QML runtime */" << endl
165             << "    // importPaths: [ \"../exampleplugin\" ]" << endl
166             << "}" << endl;
167     }
168     Core::GeneratedFile generatedCreatorFile(creatorFileName);
169     generatedCreatorFile.setContents(projectContents);
170     generatedCreatorFile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
171
172     Core::GeneratedFiles files;
173     files.append(generatedMainFile);
174     files.append(generatedCreatorFile);
175
176     return files;
177 }
178
179 bool QmlProjectApplicationWizard::postGenerateFiles(const QWizard *, const Core::GeneratedFiles &l, QString *errorMessage)
180 {
181     return ProjectExplorer::CustomProjectWizard::postGenerateOpen(l, errorMessage);
182
183 }
184
185 } // namespace Internal
186 } // namespace QmlProjectManager
187