diff --git a/src/plugins/glsleditor/glsleditor.pro b/src/plugins/glsleditor/glsleditor.pro index 1eb24f3c76ad77abe485d30900ccd86def72c47f..ea3650c9f39d2b04c99ab526c6c153b5f8ada5dd 100644 --- a/src/plugins/glsleditor/glsleditor.pro +++ b/src/plugins/glsleditor/glsleditor.pro @@ -15,6 +15,7 @@ glsleditorconstants.h \ glsleditoreditable.h \ glsleditorfactory.h \ glsleditorplugin.h \ +glslfilewizard.h \ glslhighlighter.h \ glslcodecompletion.h @@ -24,6 +25,7 @@ glsleditoractionhandler.cpp \ glsleditoreditable.cpp \ glsleditorfactory.cpp \ glsleditorplugin.cpp \ +glslfilewizard.cpp \ glslhighlighter.cpp \ glslcodecompletion.cpp diff --git a/src/plugins/glsleditor/glsleditorconstants.h b/src/plugins/glsleditor/glsleditorconstants.h index 4c4d28b701995323eb495673138d6bee9f602774..05748725c229b8a33b0c04a65896a69739eb0157 100644 --- a/src/plugins/glsleditor/glsleditorconstants.h +++ b/src/plugins/glsleditor/glsleditorconstants.h @@ -51,6 +51,8 @@ const char * const TASK_SEARCH = "GLSLEditor.TaskSearch"; const char * const GLSL_MIMETYPE = "application/x-glsl"; +const char * const WIZARD_CATEGORY_GLSL = "U.GLSL"; +const char * const WIZARD_TR_CATEGORY_GLSL = QT_TRANSLATE_NOOP("GLSLEditor", "GLSL"); } // namespace Constants } // namespace GLSLEditor diff --git a/src/plugins/glsleditor/glsleditorplugin.cpp b/src/plugins/glsleditor/glsleditorplugin.cpp index 7608ab3b428c074fdb7fad91b0e5429019b841b0..fd0dc319cb3921135addab4e4b6d49a7f5306240 100644 --- a/src/plugins/glsleditor/glsleditorplugin.cpp +++ b/src/plugins/glsleditor/glsleditorplugin.cpp @@ -32,6 +32,7 @@ #include "glsleditorconstants.h" #include "glsleditorfactory.h" #include "glslcodecompletion.h" +#include "glslfilewizard.h" #include <coreplugin/icore.h> #include <coreplugin/coreconstants.h> @@ -151,6 +152,30 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er 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; } diff --git a/src/plugins/glsleditor/glslfilewizard.cpp b/src/plugins/glsleditor/glslfilewizard.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5dc020a67e2eaebe92575de2d7cd9dfe94c8657e --- /dev/null +++ b/src/plugins/glsleditor/glslfilewizard.cpp @@ -0,0 +1,136 @@ +/************************************************************************** +** +** 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" diff --git a/src/plugins/glsleditor/glslfilewizard.h b/src/plugins/glsleditor/glslfilewizard.h new file mode 100644 index 0000000000000000000000000000000000000000..9823dcca6b4fd58a163b81502bdb8f2a47b89ce7 --- /dev/null +++ b/src/plugins/glsleditor/glslfilewizard.h @@ -0,0 +1,71 @@ +/************************************************************************** +** +** 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