forked from qt-creator/qt-creator
GlslEditor: Some editor creation related cleanup
Use a BaseEditorFactory derived class, move some code around. Change-Id: Id560a215102016cdbe21809f97be8fc190ed5cf5 Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -30,7 +30,6 @@
|
|||||||
#include "glslcompletionassist.h"
|
#include "glslcompletionassist.h"
|
||||||
#include "glsleditorconstants.h"
|
#include "glsleditorconstants.h"
|
||||||
#include "glsleditorplugin.h"
|
#include "glsleditorplugin.h"
|
||||||
#include "reuse.h"
|
|
||||||
|
|
||||||
#include <glsl/glslengine.h>
|
#include <glsl/glslengine.h>
|
||||||
#include <glsl/glsllexer.h>
|
#include <glsl/glsllexer.h>
|
||||||
@@ -64,6 +63,37 @@ using namespace TextEditor;
|
|||||||
namespace GlslEditor {
|
namespace GlslEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
Document::Document()
|
||||||
|
: _engine(0)
|
||||||
|
, _ast(0)
|
||||||
|
, _globalScope(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Document::~Document()
|
||||||
|
{
|
||||||
|
delete _globalScope;
|
||||||
|
delete _engine;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLSL::Scope *Document::scopeAt(int position) const
|
||||||
|
{
|
||||||
|
foreach (const Range &c, _cursors) {
|
||||||
|
if (position >= c.cursor.selectionStart() && position <= c.cursor.selectionEnd())
|
||||||
|
return c.scope;
|
||||||
|
}
|
||||||
|
return _globalScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Document::addRange(const QTextCursor &cursor, GLSL::Scope *scope)
|
||||||
|
{
|
||||||
|
Range c;
|
||||||
|
c.cursor = cursor;
|
||||||
|
c.scope = scope;
|
||||||
|
_cursors.append(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
enum CompletionOrder {
|
enum CompletionOrder {
|
||||||
SpecialMemberOrder = -5
|
SpecialMemberOrder = -5
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,16 +39,51 @@
|
|||||||
|
|
||||||
#include <utils/qtcoverride.h>
|
#include <utils/qtcoverride.h>
|
||||||
|
|
||||||
#include <QScopedPointer>
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QScopedPointer>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
namespace GLSL { class Function; }
|
namespace GLSL {
|
||||||
|
class Engine;
|
||||||
|
class Function;
|
||||||
|
class TranslationUnitAST;
|
||||||
|
class Scope;
|
||||||
|
} // namespace GLSL
|
||||||
|
|
||||||
namespace TextEditor { class BasicProposalItem; }
|
namespace TextEditor { class BasicProposalItem; }
|
||||||
|
|
||||||
namespace GlslEditor {
|
namespace GlslEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
class Document
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef QSharedPointer<Document> Ptr;
|
||||||
|
|
||||||
|
Document();
|
||||||
|
~Document();
|
||||||
|
|
||||||
|
GLSL::Engine *engine() const { return _engine; }
|
||||||
|
GLSL::TranslationUnitAST *ast() const { return _ast; }
|
||||||
|
GLSL::Scope *globalScope() const { return _globalScope; }
|
||||||
|
|
||||||
|
GLSL::Scope *scopeAt(int position) const;
|
||||||
|
void addRange(const QTextCursor &cursor, GLSL::Scope *scope);
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Range {
|
||||||
|
QTextCursor cursor;
|
||||||
|
GLSL::Scope *scope;
|
||||||
|
};
|
||||||
|
|
||||||
|
GLSL::Engine *_engine;
|
||||||
|
GLSL::TranslationUnitAST *_ast;
|
||||||
|
GLSL::Scope *_globalScope;
|
||||||
|
QList<Range> _cursors;
|
||||||
|
|
||||||
|
friend class GlslEditorWidget;
|
||||||
|
};
|
||||||
|
|
||||||
class GlslCompletionAssistInterface;
|
class GlslCompletionAssistInterface;
|
||||||
|
|
||||||
class GlslCompletionAssistProvider : public TextEditor::CompletionAssistProvider
|
class GlslCompletionAssistProvider : public TextEditor::CompletionAssistProvider
|
||||||
|
|||||||
@@ -75,7 +75,6 @@
|
|||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
using namespace GLSL;
|
using namespace GLSL;
|
||||||
using namespace GlslEditor::Constants;
|
|
||||||
|
|
||||||
namespace GlslEditor {
|
namespace GlslEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -109,35 +108,33 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Document::Document()
|
//
|
||||||
: _engine(0)
|
// GlslEditorWidget
|
||||||
, _ast(0)
|
//
|
||||||
, _globalScope(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Document::~Document()
|
class GlslEditorWidget : public BaseTextEditorWidget
|
||||||
{
|
{
|
||||||
delete _globalScope;
|
public:
|
||||||
delete _engine;
|
GlslEditorWidget();
|
||||||
}
|
|
||||||
|
|
||||||
GLSL::Scope *Document::scopeAt(int position) const
|
int editorRevision() const;
|
||||||
{
|
bool isOutdated() const;
|
||||||
foreach (const Range &c, _cursors) {
|
|
||||||
if (position >= c.cursor.selectionStart() && position <= c.cursor.selectionEnd())
|
|
||||||
return c.scope;
|
|
||||||
}
|
|
||||||
return _globalScope;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Document::addRange(const QTextCursor &cursor, GLSL::Scope *scope)
|
QSet<QString> identifiers() const;
|
||||||
{
|
|
||||||
Range c;
|
IAssistInterface *createAssistInterface(AssistKind assistKind, AssistReason reason) const;
|
||||||
c.cursor = cursor;
|
|
||||||
c.scope = scope;
|
private:
|
||||||
_cursors.append(c);
|
BaseTextEditor *createEditor();
|
||||||
}
|
|
||||||
|
void updateDocumentNow();
|
||||||
|
void setSelectedElements();
|
||||||
|
QString wordUnderCursor() const;
|
||||||
|
|
||||||
|
QTimer m_updateDocumentTimer;
|
||||||
|
QComboBox *m_outlineCombo;
|
||||||
|
Document::Ptr m_glslDocument;
|
||||||
|
};
|
||||||
|
|
||||||
GlslEditorWidget::GlslEditorWidget()
|
GlslEditorWidget::GlslEditorWidget()
|
||||||
{
|
{
|
||||||
@@ -200,13 +197,6 @@ bool GlslEditorWidget::isOutdated() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GlslEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
|
||||||
{
|
|
||||||
textDocument()->setMimeType(Core::MimeDatabase::findByFile(QFileInfo(fileName)).type());
|
|
||||||
bool b = BaseTextEditor::open(errorString, fileName, realFileName);
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString GlslEditorWidget::wordUnderCursor() const
|
QString GlslEditorWidget::wordUnderCursor() const
|
||||||
{
|
{
|
||||||
QTextCursor tc = textCursor();
|
QTextCursor tc = textCursor();
|
||||||
@@ -291,7 +281,7 @@ void GlslEditorWidget::updateDocumentNow()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int GlslEditorWidget::languageVariant(const QString &type)
|
int languageVariant(const QString &type)
|
||||||
{
|
{
|
||||||
int variant = 0;
|
int variant = 0;
|
||||||
bool isVertex = false;
|
bool isVertex = false;
|
||||||
@@ -342,56 +332,55 @@ IAssistInterface *GlslEditorWidget::createAssistInterface(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
//
|
//
|
||||||
// GlslEditor
|
// GlslEditor
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
GlslEditor::GlslEditor()
|
class GlslEditor : public TextEditor::BaseTextEditor
|
||||||
{
|
{
|
||||||
addContext(C_GLSLEDITOR_ID);
|
public:
|
||||||
setDuplicateSupported(true);
|
GlslEditor()
|
||||||
setCommentStyle(Utils::CommentDefinition::CppStyle);
|
{
|
||||||
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GlslCompletionAssistProvider>());
|
addContext(Constants::C_GLSLEDITOR_ID);
|
||||||
|
setDuplicateSupported(true);
|
||||||
|
setCommentStyle(Utils::CommentDefinition::CppStyle);
|
||||||
|
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GlslCompletionAssistProvider>());
|
||||||
|
}
|
||||||
|
|
||||||
setEditorCreator([]() { return new GlslEditor; });
|
bool open(QString *errorString, const QString &fileName, const QString &realFileName)
|
||||||
setWidgetCreator([]() { return new GlslEditorWidget; });
|
{
|
||||||
|
textDocument()->setMimeType(Core::MimeDatabase::findByFile(QFileInfo(fileName)).type());
|
||||||
setDocumentCreator([]() -> BaseTextDocument * {
|
bool b = BaseTextEditor::open(errorString, fileName, realFileName);
|
||||||
auto doc = new BaseTextDocument(C_GLSLEDITOR_ID);
|
return b;
|
||||||
doc->setIndenter(new GlslIndenter);
|
}
|
||||||
new Highlighter(doc);
|
};
|
||||||
return doc;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
//
|
//
|
||||||
// GlslEditorFactory
|
// GlslEditorFactory
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
GlslEditorFactory::GlslEditorFactory()
|
GlslEditorFactory::GlslEditorFactory()
|
||||||
{
|
{
|
||||||
setId(C_GLSLEDITOR_ID);
|
setId(Constants::C_GLSLEDITOR_ID);
|
||||||
setDisplayName(qApp->translate("OpenWith::Editors", C_GLSLEDITOR_DISPLAY_NAME));
|
setDisplayName(qApp->translate("OpenWith::Editors", Constants::C_GLSLEDITOR_DISPLAY_NAME));
|
||||||
addMimeType(GLSL_MIMETYPE);
|
addMimeType(Constants::GLSL_MIMETYPE);
|
||||||
addMimeType(GLSL_MIMETYPE_VERT);
|
addMimeType(Constants::GLSL_MIMETYPE_VERT);
|
||||||
addMimeType(GLSL_MIMETYPE_FRAG);
|
addMimeType(Constants::GLSL_MIMETYPE_FRAG);
|
||||||
addMimeType(GLSL_MIMETYPE_VERT_ES);
|
addMimeType(Constants::GLSL_MIMETYPE_VERT_ES);
|
||||||
addMimeType(GLSL_MIMETYPE_FRAG_ES);
|
addMimeType(Constants::GLSL_MIMETYPE_FRAG_ES);
|
||||||
new TextEditorActionHandler(this, C_GLSLEDITOR_ID,
|
|
||||||
TextEditorActionHandler::Format
|
|
||||||
| TextEditorActionHandler::UnCommentSelection
|
|
||||||
| TextEditorActionHandler::UnCollapseAll);
|
|
||||||
|
|
||||||
}
|
setDocumentCreator([]() { return new BaseTextDocument(Constants::C_GLSLEDITOR_ID); });
|
||||||
|
setEditorWidgetCreator([]() { return new GlslEditorWidget; });
|
||||||
|
setEditorCreator([]() { return new GlslEditor; });
|
||||||
|
setIndenterCreator([]() { return new GlslIndenter; });
|
||||||
|
setSyntaxHighlighterCreator([]() { return new Highlighter; });
|
||||||
|
|
||||||
|
setEditorActionHandlers(Constants::C_GLSLEDITOR_ID,
|
||||||
|
TextEditorActionHandler::Format
|
||||||
|
| TextEditorActionHandler::UnCommentSelection
|
||||||
|
| TextEditorActionHandler::UnCollapseAll);
|
||||||
|
|
||||||
Core::IEditor *GlslEditorFactory::createEditor()
|
|
||||||
{
|
|
||||||
return new GlslEditor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -31,104 +31,18 @@
|
|||||||
#define GLSLEDITOR_H
|
#define GLSLEDITOR_H
|
||||||
|
|
||||||
#include <texteditor/basetexteditor.h>
|
#include <texteditor/basetexteditor.h>
|
||||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
|
||||||
|
|
||||||
#include <QSharedPointer>
|
|
||||||
#include <QSet>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QComboBox;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace GLSL {
|
|
||||||
class Engine;
|
|
||||||
class TranslationUnitAST;
|
|
||||||
class Scope;
|
|
||||||
} // namespace GLSL
|
|
||||||
|
|
||||||
namespace GlslEditor {
|
namespace GlslEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class GlslEditor;
|
int languageVariant(const QString &mimeType);
|
||||||
class GlslEditorWidget;
|
|
||||||
|
|
||||||
class Document
|
class GlslEditorFactory : public TextEditor::BaseTextEditorFactory
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef QSharedPointer<Document> Ptr;
|
|
||||||
|
|
||||||
Document();
|
|
||||||
~Document();
|
|
||||||
|
|
||||||
GLSL::Engine *engine() const { return _engine; }
|
|
||||||
GLSL::TranslationUnitAST *ast() const { return _ast; }
|
|
||||||
GLSL::Scope *globalScope() const { return _globalScope; }
|
|
||||||
|
|
||||||
GLSL::Scope *scopeAt(int position) const;
|
|
||||||
void addRange(const QTextCursor &cursor, GLSL::Scope *scope);
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct Range {
|
|
||||||
QTextCursor cursor;
|
|
||||||
GLSL::Scope *scope;
|
|
||||||
};
|
|
||||||
|
|
||||||
GLSL::Engine *_engine;
|
|
||||||
GLSL::TranslationUnitAST *_ast;
|
|
||||||
GLSL::Scope *_globalScope;
|
|
||||||
QList<Range> _cursors;
|
|
||||||
|
|
||||||
friend class GlslEditorWidget;
|
|
||||||
};
|
|
||||||
|
|
||||||
class GlslEditorWidget : public TextEditor::BaseTextEditorWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
GlslEditorWidget();
|
|
||||||
|
|
||||||
int editorRevision() const;
|
|
||||||
bool isOutdated() const;
|
|
||||||
|
|
||||||
QSet<QString> identifiers() const;
|
|
||||||
|
|
||||||
static int languageVariant(const QString &mimeType);
|
|
||||||
|
|
||||||
TextEditor::IAssistInterface *createAssistInterface(TextEditor::AssistKind assistKind,
|
|
||||||
TextEditor::AssistReason reason) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
TextEditor::BaseTextEditor *createEditor();
|
|
||||||
|
|
||||||
void updateDocumentNow();
|
|
||||||
void setSelectedElements();
|
|
||||||
QString wordUnderCursor() const;
|
|
||||||
|
|
||||||
QTimer m_updateDocumentTimer;
|
|
||||||
QComboBox *m_outlineCombo;
|
|
||||||
Document::Ptr m_glslDocument;
|
|
||||||
};
|
|
||||||
|
|
||||||
class GlslEditor : public TextEditor::BaseTextEditor
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
GlslEditor();
|
|
||||||
|
|
||||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
|
||||||
};
|
|
||||||
|
|
||||||
class GlslEditorFactory : public Core::IEditorFactory
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GlslEditorFactory();
|
GlslEditorFactory();
|
||||||
|
|
||||||
Core::IEditor *createEditor();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ glslhighlighter.h \
|
|||||||
glslautocompleter.h \
|
glslautocompleter.h \
|
||||||
glslindenter.h \
|
glslindenter.h \
|
||||||
glslhoverhandler.h \
|
glslhoverhandler.h \
|
||||||
glslcompletionassist.h \
|
glslcompletionassist.h
|
||||||
reuse.h
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
glsleditor.cpp \
|
glsleditor.cpp \
|
||||||
@@ -23,7 +22,6 @@ glslhighlighter.cpp \
|
|||||||
glslautocompleter.cpp \
|
glslautocompleter.cpp \
|
||||||
glslindenter.cpp \
|
glslindenter.cpp \
|
||||||
glslhoverhandler.cpp \
|
glslhoverhandler.cpp \
|
||||||
glslcompletionassist.cpp \
|
glslcompletionassist.cpp
|
||||||
reuse.cpp
|
|
||||||
|
|
||||||
RESOURCES += glsleditor.qrc
|
RESOURCES += glsleditor.qrc
|
||||||
|
|||||||
@@ -34,7 +34,5 @@ QtcPlugin {
|
|||||||
"glslhoverhandler.h",
|
"glslhoverhandler.h",
|
||||||
"glslindenter.cpp",
|
"glslindenter.cpp",
|
||||||
"glslindenter.h",
|
"glslindenter.h",
|
||||||
"reuse.cpp",
|
|
||||||
"reuse.h",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ void Highlighter::highlightBlock(const QString &text)
|
|||||||
lex.setState(state);
|
lex.setState(state);
|
||||||
lex.setScanKeywords(false);
|
lex.setScanKeywords(false);
|
||||||
lex.setScanComments(true);
|
lex.setScanComments(true);
|
||||||
const int variant = GlslEditorWidget::languageVariant(parent()
|
const int variant = languageVariant(parent()
|
||||||
? static_cast<BaseTextDocument*>(parent())->mimeType()
|
? static_cast<BaseTextDocument*>(parent())->mimeType()
|
||||||
: QString());
|
: QString());
|
||||||
lex.setVariant(variant);
|
lex.setVariant(variant);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include "glslhoverhandler.h"
|
#include "glslhoverhandler.h"
|
||||||
#include "glsleditor.h"
|
#include "glsleditor.h"
|
||||||
|
#include "glsleditorconstants.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
@@ -36,8 +37,6 @@
|
|||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <texteditor/basetexteditor.h>
|
#include <texteditor/basetexteditor.h>
|
||||||
|
|
||||||
#include <QTextCursor>
|
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
|
||||||
namespace GlslEditor {
|
namespace GlslEditor {
|
||||||
@@ -51,15 +50,13 @@ GlslHoverHandler::~GlslHoverHandler()
|
|||||||
|
|
||||||
bool GlslHoverHandler::acceptEditor(IEditor *editor)
|
bool GlslHoverHandler::acceptEditor(IEditor *editor)
|
||||||
{
|
{
|
||||||
return qobject_cast<GlslEditor *>(editor) != 0;
|
return editor->context().contains(Constants::C_GLSLEDITOR_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlslHoverHandler::identifyMatch(TextEditor::BaseTextEditor *editor, int pos)
|
void GlslHoverHandler::identifyMatch(TextEditor::BaseTextEditor *editor, int pos)
|
||||||
{
|
{
|
||||||
if (GlslEditorWidget *glslEditor = qobject_cast<GlslEditorWidget *>(editor->widget())) {
|
if (!editor->editorWidget()->extraSelectionTooltip(pos).isEmpty())
|
||||||
if (! glslEditor->extraSelectionTooltip(pos).isEmpty())
|
setToolTip(editor->editorWidget()->extraSelectionTooltip(pos));
|
||||||
setToolTip(glslEditor->extraSelectionTooltip(pos));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlslHoverHandler::decorateToolTip()
|
void GlslHoverHandler::decorateToolTip()
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
|
||||||
** Contact: http://www.qt-project.org/legal
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and Digia. For licensing terms and
|
|
||||||
** conditions see http://qt.digia.com/licensing. For further information
|
|
||||||
** use the contact form at http://qt.digia.com/contact-us.
|
|
||||||
**
|
|
||||||
** 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.
|
|
||||||
**
|
|
||||||
** In addition, as a special exception, Digia gives you certain additional
|
|
||||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "reuse.h"
|
|
||||||
|
|
||||||
#include <QLatin1String>
|
|
||||||
|
|
||||||
#include <glsl/glsllexer.h>
|
|
||||||
|
|
||||||
using namespace GLSL;
|
|
||||||
|
|
||||||
namespace GlslEditor {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
int languageVariant(const QString &mimeType)
|
|
||||||
{
|
|
||||||
int variant = 0;
|
|
||||||
bool isVertex = false;
|
|
||||||
bool isFragment = false;
|
|
||||||
bool isDesktop = false;
|
|
||||||
if (mimeType.isEmpty()) {
|
|
||||||
// ### Before file has been opened, so don't know the mime type.
|
|
||||||
isVertex = true;
|
|
||||||
isFragment = true;
|
|
||||||
} else if (mimeType == QLatin1String("text/x-glsl") ||
|
|
||||||
mimeType == QLatin1String("application/x-glsl")) {
|
|
||||||
isVertex = true;
|
|
||||||
isFragment = true;
|
|
||||||
isDesktop = true;
|
|
||||||
} else if (mimeType == QLatin1String("text/x-glsl-vert")) {
|
|
||||||
isVertex = true;
|
|
||||||
isDesktop = true;
|
|
||||||
} else if (mimeType == QLatin1String("text/x-glsl-frag")) {
|
|
||||||
isFragment = true;
|
|
||||||
isDesktop = true;
|
|
||||||
} else if (mimeType == QLatin1String("text/x-glsl-es-vert")) {
|
|
||||||
isVertex = true;
|
|
||||||
} else if (mimeType == QLatin1String("text/x-glsl-es-frag")) {
|
|
||||||
isFragment = true;
|
|
||||||
}
|
|
||||||
if (isDesktop)
|
|
||||||
variant |= Lexer::Variant_GLSL_120;
|
|
||||||
else
|
|
||||||
variant |= Lexer::Variant_GLSL_ES_100;
|
|
||||||
if (isVertex)
|
|
||||||
variant |= Lexer::Variant_VertexShader;
|
|
||||||
if (isFragment)
|
|
||||||
variant |= Lexer::Variant_FragmentShader;
|
|
||||||
return variant;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace GlslEditor
|
|
||||||
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
|
||||||
** Contact: http://www.qt-project.org/legal
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and Digia. For licensing terms and
|
|
||||||
** conditions see http://qt.digia.com/licensing. For further information
|
|
||||||
** use the contact form at http://qt.digia.com/contact-us.
|
|
||||||
**
|
|
||||||
** 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.
|
|
||||||
**
|
|
||||||
** In addition, as a special exception, Digia gives you certain additional
|
|
||||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef REUSE_H
|
|
||||||
#define REUSE_H
|
|
||||||
|
|
||||||
#include <QtGlobal>
|
|
||||||
|
|
||||||
namespace GlslEditor {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
int languageVariant(const QString &mimeType);
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace GlslEditor
|
|
||||||
|
|
||||||
#endif // REUSE_H
|
|
||||||
Reference in New Issue
Block a user