Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
03355c49
Commit
03355c49
authored
Nov 24, 2010
by
Rhys Weatherley
Browse files
Add GLSL file types to the File->New wizard
parent
4c7623a9
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/plugins/glsleditor/glsleditor.pro
View file @
03355c49
...
...
@@ -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
...
...
src/plugins/glsleditor/glsleditorconstants.h
View file @
03355c49
...
...
@@ -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
...
...
src/plugins/glsleditor/glsleditorplugin.cpp
View file @
03355c49
...
...
@@ -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
;
}
...
...
src/plugins/glsleditor/glslfilewizard.cpp
0 → 100644
View file @
03355c49
/**************************************************************************
**
** 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
&
parameters
,
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"
src/plugins/glsleditor/glslfilewizard.h
0 → 100644
View file @
03355c49
/**************************************************************************
**
** 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
&
parameters
,
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment