1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "glsleditorconstants.h"
35 #include "glslfilewizard.h"
37 #include <utils/filewizarddialog.h>
38 #include <utils/qtcassert.h>
39 #include <utils/filewizarddialog.h>
41 #include <QtCore/QFileInfo>
42 #include <QtCore/QTextStream>
43 #include <QtGui/QWizard>
44 #include <QtGui/QPushButton>
47 class GLSLFileWizardDialog : public Utils::FileWizardDialog
51 GLSLFileWizardDialog(QWidget *parent = 0)
52 : Utils::FileWizardDialog(parent)
56 } // anonymous namespace
58 using namespace GLSLEditor;
60 GLSLFileWizard::GLSLFileWizard(const BaseFileWizardParameters ¶meters,
61 ShaderType shaderType, QObject *parent):
62 Core::BaseFileWizard(parameters, parent),
63 m_shaderType(shaderType)
67 Core::GeneratedFiles GLSLFileWizard::generateFiles(const QWizard *w,
68 QString * /*errorMessage*/) const
70 const GLSLFileWizardDialog *wizardDialog = qobject_cast<const GLSLFileWizardDialog *>(w);
71 const QString path = wizardDialog->path();
72 const QString name = wizardDialog->fileName();
74 const QString fileName = Core::BaseFileWizard::buildFileName(path, name, preferredSuffix(m_shaderType));
76 Core::GeneratedFile file(fileName);
77 file.setContents(fileContents(fileName, m_shaderType));
78 file.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
79 return Core::GeneratedFiles() << file;
82 QString GLSLFileWizard::fileContents(const QString &, ShaderType shaderType) const
85 QTextStream str(&contents);
88 case GLSLFileWizard::VertexShaderES:
89 str << QLatin1String("attribute highp vec4 qt_Vertex;\n")
90 << QLatin1String("attribute highp vec4 qt_MultiTexCoord0;\n")
91 << QLatin1String("uniform highp mat4 qt_ModelViewProjectionMatrix;\n")
92 << QLatin1String("varying highp vec4 qt_TexCoord0;\n")
93 << QLatin1String("\n")
94 << QLatin1String("void main(void)\n")
95 << QLatin1String("{\n")
96 << QLatin1String(" gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;\n")
97 << QLatin1String(" qt_TexCoord0 = qt_MultiTexCoord0;\n")
98 << QLatin1String("}\n");
100 case GLSLFileWizard::FragmentShaderES:
101 str << QLatin1String("uniform sampler2D qt_Texture0;\n")
102 << QLatin1String("varying highp vec4 qt_TexCoord0;\n")
103 << QLatin1String("\n")
104 << QLatin1String("void main(void)\n")
105 << QLatin1String("{\n")
106 << QLatin1String(" gl_FragColor = texture2D(qt_Texture0, qt_TexCoord0.st);\n")
107 << QLatin1String("}\n");
109 case GLSLFileWizard::VertexShaderDesktop:
110 str << QLatin1String("attribute vec4 qt_Vertex;\n")
111 << QLatin1String("attribute vec4 qt_MultiTexCoord0;\n")
112 << QLatin1String("uniform mat4 qt_ModelViewProjectionMatrix;\n")
113 << QLatin1String("varying vec4 qt_TexCoord0;\n")
114 << QLatin1String("\n")
115 << QLatin1String("void main(void)\n")
116 << QLatin1String("{\n")
117 << QLatin1String(" gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;\n")
118 << QLatin1String(" qt_TexCoord0 = qt_MultiTexCoord0;\n")
119 << QLatin1String("}\n");
121 case GLSLFileWizard::FragmentShaderDesktop:
122 str << QLatin1String("uniform sampler2D qt_Texture0;\n")
123 << QLatin1String("varying vec4 qt_TexCoord0;\n")
124 << QLatin1String("\n")
125 << QLatin1String("void main(void)\n")
126 << QLatin1String("{\n")
127 << QLatin1String(" gl_FragColor = texture2D(qt_Texture0, qt_TexCoord0.st);\n")
128 << QLatin1String("}\n");
136 QWizard *GLSLFileWizard::createWizardDialog(QWidget *parent, const QString &defaultPath,
137 const WizardPageList &extensionPages) const
139 GLSLFileWizardDialog *wizardDialog = new GLSLFileWizardDialog(parent);
140 wizardDialog->setWindowTitle(tr("New %1").arg(displayName()));
141 setupWizard(wizardDialog);
142 wizardDialog->setPath(defaultPath);
143 foreach (QWizardPage *p, extensionPages)
144 BaseFileWizard::applyExtensionPageShortTitle(wizardDialog, wizardDialog->addPage(p));
148 QString GLSLFileWizard::preferredSuffix(ShaderType shaderType) const
150 switch (shaderType) {
151 case GLSLFileWizard::VertexShaderES:
152 return QLatin1String("vsh");
153 case GLSLFileWizard::FragmentShaderES:
154 return QLatin1String("fsh");
155 case GLSLFileWizard::VertexShaderDesktop:
156 return QLatin1String("vert");
157 case GLSLFileWizard::FragmentShaderDesktop:
158 return QLatin1String("frag");
160 return QLatin1String("glsl");
164 #include "glslfilewizard.moc"