1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "qmlprojectapplicationwizard.h"
35 #include "qmlprojectconstants.h"
37 #include <coreplugin/coreconstants.h>
38 #include <projectexplorer/customwizard/customwizard.h>
39 #include <qt4projectmanager/qt4projectmanagerconstants.h>
41 #include <QtGui/QIcon>
43 #include <QtGui/QPainter>
44 #include <QtGui/QPixmap>
46 #include <QtCore/QDir>
47 #include <QtCore/QTextStream>
48 #include <QtCore/QCoreApplication>
50 namespace QmlProjectManager {
53 QmlProjectApplicationWizardDialog::QmlProjectApplicationWizardDialog(QWidget *parent) :
54 ProjectExplorer::BaseProjectWizardDialog(parent)
56 setWindowTitle(tr("New Qt Quick UI Project"));
57 setIntroDescription(tr("This wizard generates a Qt Quick UI project."));
60 QmlProjectApplicationWizard::QmlProjectApplicationWizard()
61 : Core::BaseFileWizard(parameters())
64 QmlProjectApplicationWizard::~QmlProjectApplicationWizard()
67 Core::BaseFileWizardParameters QmlProjectApplicationWizard::parameters()
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"));
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));
85 QWizard *QmlProjectApplicationWizard::createWizardDialog(QWidget *parent,
86 const QString &defaultPath,
87 const WizardPageList &extensionPages) const
89 QmlProjectApplicationWizardDialog *wizard = new QmlProjectApplicationWizardDialog(parent);
91 wizard->setPath(defaultPath);
92 wizard->setProjectName(QmlProjectApplicationWizardDialog::uniqueProjectName(defaultPath));
94 foreach (QWizardPage *p, extensionPages)
95 BaseFileWizard::applyExtensionPageShortTitle(wizard, wizard->addPage(p));
100 Core::GeneratedFiles QmlProjectApplicationWizard::generateFiles(const QWizard *w,
101 QString *errorMessage) const
103 Q_UNUSED(errorMessage)
105 const QmlProjectApplicationWizardDialog *wizard = qobject_cast<const QmlProjectApplicationWizardDialog *>(w);
106 const QString projectName = wizard->projectName();
107 const QString projectPath = wizard->path() + QLatin1Char('/') + projectName;
109 const QString creatorFileName = Core::BaseFileWizard::buildFileName(projectPath,
111 QLatin1String("qmlproject"));
113 const QString mainFileName = Core::BaseFileWizard::buildFileName(projectPath,
115 QLatin1String("qml"));
119 QTextStream out(&contents);
122 << "import QtQuick 1.0" << endl
124 << "Rectangle {" << endl
125 << " width: 360" << endl
126 << " height: 360" << endl
128 << " anchors.centerIn: parent" << endl
129 << " text: \"Hello World\"" << endl
131 << " MouseArea {" << endl
132 << " anchors.fill: parent" << endl
133 << " onClicked: {" << endl
134 << " Qt.quit();" << endl
139 Core::GeneratedFile generatedMainFile(mainFileName);
140 generatedMainFile.setContents(contents);
141 generatedMainFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
143 QString projectContents;
145 QTextStream out(&projectContents);
147 out << "/* File generated by Qt Creator, version " << Core::Constants::IDE_VERSION_LONG << " */" << endl
149 << "import QmlProject 1.1" << endl
151 << "Project {" << endl
152 << " mainFile: \"" << QDir(projectPath).relativeFilePath(mainFileName) << '"' << endl
154 << " /* Include .qml, .js, and image files from current directory and subdirectories */" << endl
155 << " QmlFiles {" << endl
156 << " directory: \".\"" << endl
158 << " JavaScriptFiles {" << endl
159 << " directory: \".\"" << endl
161 << " ImageFiles {" << endl
162 << " directory: \".\"" << endl
164 << " /* List of plugin directories passed to QML runtime */" << endl
165 << " // importPaths: [ \"../exampleplugin\" ]" << endl
168 Core::GeneratedFile generatedCreatorFile(creatorFileName);
169 generatedCreatorFile.setContents(projectContents);
170 generatedCreatorFile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
172 Core::GeneratedFiles files;
173 files.append(generatedMainFile);
174 files.append(generatedCreatorFile);
179 bool QmlProjectApplicationWizard::postGenerateFiles(const QWizard *, const Core::GeneratedFiles &l, QString *errorMessage)
181 return ProjectExplorer::CustomProjectWizard::postGenerateOpen(l, errorMessage);
185 } // namespace Internal
186 } // namespace QmlProjectManager