#include "glsleditorconstants.h"
#include "glsleditorfactory.h"
#include "glslcodecompletion.h"
+#include "glslfilewizard.h"
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
iconProvider->registerIconOverlayForSuffix(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")), "glsl");
+ Core::BaseFileWizardParameters fragWizardParameters(Core::IWizard::FileWizard);
+ fragWizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
+ fragWizardParameters.setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
+ fragWizardParameters.setDescription
+ (tr("Creates a fragment shader in the OpenGL/ES 2.0 Shading "
+ "Language (GLSL/ES). Fragment shaders generate the final "
+ "pixel colors for triangles, points, and lines rendered "
+ "with OpenGL."));
+ fragWizardParameters.setDisplayName(tr("Fragment shader"));
+ fragWizardParameters.setId(QLatin1String("F.GLSL"));
+ addAutoReleasedObject(new GLSLFileWizard(fragWizardParameters, GLSLFileWizard::FragmentShader, core));
+
+ Core::BaseFileWizardParameters vertWizardParameters(Core::IWizard::FileWizard);
+ vertWizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
+ vertWizardParameters.setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
+ vertWizardParameters.setDescription
+ (tr("Creates a vertex shader in the OpenGL/ES 2.0 Shading "
+ "Language (GLSL/ES). Vertex shaders transform the "
+ "positions, normals, and texture co-ordinates of "
+ "triangles, points, and lines rendered with OpenGL."));
+ vertWizardParameters.setDisplayName(tr("Vertex shader"));
+ vertWizardParameters.setId(QLatin1String("V.GLSL"));
+ addAutoReleasedObject(new GLSLFileWizard(vertWizardParameters, GLSLFileWizard::VertexShader, core));
+
return true;
}
--- /dev/null
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#include "glsleditorconstants.h"
+#include "glslfilewizard.h"
+
+#include <utils/filewizarddialog.h>
+#include <utils/qtcassert.h>
+#include <utils/filewizarddialog.h>
+
+#include <QtCore/QFileInfo>
+#include <QtCore/QTextStream>
+#include <QtGui/QWizard>
+#include <QtGui/QPushButton>
+
+namespace {
+class GLSLFileWizardDialog : public Utils::FileWizardDialog
+{
+ Q_OBJECT
+public:
+ GLSLFileWizardDialog(QWidget *parent = 0)
+ : Utils::FileWizardDialog(parent)
+ {
+ }
+};
+} // anonymous namespace
+
+using namespace GLSLEditor;
+
+GLSLFileWizard::GLSLFileWizard(const BaseFileWizardParameters ¶meters,
+ ShaderType shaderType, QObject *parent):
+ Core::BaseFileWizard(parameters, parent),
+ m_shaderType(shaderType)
+{
+}
+
+Core::GeneratedFiles GLSLFileWizard::generateFiles(const QWizard *w,
+ QString * /*errorMessage*/) const
+{
+ const GLSLFileWizardDialog *wizardDialog = qobject_cast<const GLSLFileWizardDialog *>(w);
+ const QString path = wizardDialog->path();
+ const QString name = wizardDialog->fileName();
+
+ const QString mimeType = QLatin1String(Constants::GLSL_MIMETYPE);
+ const QString fileName = Core::BaseFileWizard::buildFileName(path, name, preferredSuffix(m_shaderType));
+
+ Core::GeneratedFile file(fileName);
+ file.setContents(fileContents(fileName, m_shaderType));
+ file.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
+ return Core::GeneratedFiles() << file;
+}
+
+QString GLSLFileWizard::fileContents(const QString &, ShaderType shaderType) const
+{
+ QString contents;
+ QTextStream str(&contents);
+
+ switch (shaderType) {
+ case GLSLFileWizard::VertexShader:
+ str << QLatin1String("attribute highp vec4 qgl_Vertex;\n")
+ << QLatin1String("attribute highp vec4 qgl_TexCoord0;\n")
+ << QLatin1String("uniform highp mat4 qgl_ModelViewProjectionMatrix;\n")
+ << QLatin1String("varying highp vec4 qTexCoord0;\n")
+ << QLatin1String("\n")
+ << QLatin1String("void main(void)\n")
+ << QLatin1String("{\n")
+ << QLatin1String(" gl_Position = qgl_ModelViewProjectionMatrix * qgl_Vertex;\n")
+ << QLatin1String(" qTexCoord0 = qgl_TexCoord0;\n")
+ << QLatin1String("}\n");
+ break;
+ case GLSLFileWizard::FragmentShader:
+ str << QLatin1String("uniform sampler2D qgl_Texture0;\n")
+ << QLatin1String("varying highp vec4 qTexCoord0;\n")
+ << QLatin1String("\n")
+ << QLatin1String("void main(void)\n")
+ << QLatin1String("{\n")
+ << QLatin1String(" gl_FragColor = texture2D(qgl_Texture0, qTexCoord0.st);\n")
+ << QLatin1String("}\n");
+ break;
+ default: break;
+ }
+
+ return contents;
+}
+
+QWizard *GLSLFileWizard::createWizardDialog(QWidget *parent, const QString &defaultPath,
+ const WizardPageList &extensionPages) const
+{
+ GLSLFileWizardDialog *wizardDialog = new GLSLFileWizardDialog(parent);
+ wizardDialog->setWindowTitle(tr("New %1").arg(displayName()));
+ setupWizard(wizardDialog);
+ wizardDialog->setPath(defaultPath);
+ foreach (QWizardPage *p, extensionPages)
+ BaseFileWizard::applyExtensionPageShortTitle(wizardDialog, wizardDialog->addPage(p));
+ return wizardDialog;
+}
+
+QString GLSLFileWizard::preferredSuffix(ShaderType shaderType) const
+{
+ switch (shaderType) {
+ case GLSLFileWizard::VertexShader:
+ return QLatin1String("vert");
+ case GLSLFileWizard::FragmentShader:
+ return QLatin1String("frag");
+ default:
+ return QLatin1String("glsl");
+ }
+}
+
+#include "glslfilewizard.moc"
--- /dev/null
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#ifndef GLSLFILEWIZARD_H
+#define GLSLFILEWIZARD_H
+
+#include <coreplugin/basefilewizard.h>
+
+namespace GLSLEditor {
+
+class GLSLFileWizard: public Core::BaseFileWizard
+{
+ Q_OBJECT
+
+public:
+ typedef Core::BaseFileWizardParameters BaseFileWizardParameters;
+
+ enum ShaderType
+ {
+ VertexShader,
+ FragmentShader
+ };
+
+ explicit GLSLFileWizard(const BaseFileWizardParameters ¶meters,
+ ShaderType shaderType, QObject *parent = 0);
+
+protected:
+ QString fileContents(const QString &baseName, ShaderType shaderType) const;
+
+ virtual QWizard *createWizardDialog(QWidget *parent,
+ const QString &defaultPath,
+ const WizardPageList &extensionPages) const;
+
+ virtual Core::GeneratedFiles generateFiles(const QWizard *w,
+ QString *errorMessage) const;
+
+ virtual QString preferredSuffix(ShaderType shaderType) const;
+
+private:
+ ShaderType m_shaderType;
+};
+
+} // namespace GLSLEditor
+
+#endif // GLSLFILEWIZARD_H