GlslEditor: Code cosmetics

Namespaces, CamelCase names.

Change-Id: I6ced0dccb073bda0fc82fed1831886fb9f62bf65
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
hjk
2014-08-21 08:29:55 +02:00
parent 2481e71d18
commit bb8575c60c
13 changed files with 167 additions and 158 deletions

View File

@@ -37,17 +37,18 @@
#include <QLatin1Char> #include <QLatin1Char>
#include <QTextCursor> #include <QTextCursor>
using namespace GLSLEditor;
using namespace Internal;
using namespace CPlusPlus; using namespace CPlusPlus;
GLSLCompleter::GLSLCompleter() namespace GLSLEditor {
namespace Internal {
GlslCompleter::GlslCompleter()
{} {}
GLSLCompleter::~GLSLCompleter() GlslCompleter::~GlslCompleter()
{} {}
bool GLSLCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor, bool GlslCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert) const const QString &textToInsert) const
{ {
QChar ch; QChar ch;
@@ -65,7 +66,7 @@ bool GLSLCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
return true; return true;
} }
bool GLSLCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) const bool GlslCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) const
{ {
const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(), const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(),
BackwardsScanner::previousBlockState(cursor.block())); BackwardsScanner::previousBlockState(cursor.block()));
@@ -94,7 +95,7 @@ bool GLSLCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) c
return true; return true;
} }
bool GLSLCompleter::isInComment(const QTextCursor &cursor) const bool GlslCompleter::isInComment(const QTextCursor &cursor) const
{ {
const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(), const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(),
BackwardsScanner::previousBlockState(cursor.block())); BackwardsScanner::previousBlockState(cursor.block()));
@@ -118,7 +119,7 @@ bool GLSLCompleter::isInComment(const QTextCursor &cursor) const
return false; return false;
} }
QString GLSLCompleter::insertMatchingBrace(const QTextCursor &cursor, QString GlslCompleter::insertMatchingBrace(const QTextCursor &cursor,
const QString &text, const QString &text,
QChar la, QChar la,
int *skippedChars) const int *skippedChars) const
@@ -127,8 +128,11 @@ QString GLSLCompleter::insertMatchingBrace(const QTextCursor &cursor,
return m.insertMatchingBrace(cursor, text, la, skippedChars); return m.insertMatchingBrace(cursor, text, la, skippedChars);
} }
QString GLSLCompleter::insertParagraphSeparator(const QTextCursor &cursor) const QString GlslCompleter::insertParagraphSeparator(const QTextCursor &cursor) const
{ {
MatchingText m; MatchingText m;
return m.insertParagraphSeparator(cursor); return m.insertParagraphSeparator(cursor);
} }
} // namespace Internal
} // namespace GLSLEditor

View File

@@ -35,11 +35,11 @@
namespace GLSLEditor { namespace GLSLEditor {
namespace Internal { namespace Internal {
class GLSLCompleter : public TextEditor::AutoCompleter class GlslCompleter : public TextEditor::AutoCompleter
{ {
public: public:
GLSLCompleter(); GlslCompleter();
virtual ~GLSLCompleter(); virtual ~GlslCompleter();
virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor, virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert = QString()) const; const QString &textToInsert = QString()) const;
@@ -52,7 +52,7 @@ public:
virtual QString insertParagraphSeparator(const QTextCursor &cursor) const; virtual QString insertParagraphSeparator(const QTextCursor &cursor) const;
}; };
} // Internal } // namespace Internal
} // GLSLEditor } // namespace GLSLEditor
#endif // GLSLAUTOCOMPLETER_H #endif // GLSLAUTOCOMPLETER_H

View File

@@ -59,28 +59,26 @@
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QDebug> #include <QDebug>
using namespace GLSLEditor;
using namespace Internal;
using namespace TextEditor; using namespace TextEditor;
namespace { namespace GLSLEditor {
namespace Internal {
enum CompletionOrder { enum CompletionOrder {
SpecialMemberOrder = -5 SpecialMemberOrder = -5
}; };
static bool isActivationChar(const QChar &ch)
bool isActivationChar(const QChar &ch)
{ {
return ch == QLatin1Char('(') || ch == QLatin1Char('.') || ch == QLatin1Char(','); return ch == QLatin1Char('(') || ch == QLatin1Char('.') || ch == QLatin1Char(',');
} }
bool isIdentifierChar(QChar ch) static bool isIdentifierChar(QChar ch)
{ {
return ch.isLetterOrNumber() || ch == QLatin1Char('_'); return ch.isLetterOrNumber() || ch == QLatin1Char('_');
} }
bool isDelimiter(QChar ch) static bool isDelimiter(QChar ch)
{ {
switch (ch.unicode()) { switch (ch.unicode()) {
case '{': case '{':
@@ -104,7 +102,7 @@ bool isDelimiter(QChar ch)
} }
} }
bool checkStartOfIdentifier(const QString &word) static bool checkStartOfIdentifier(const QString &word)
{ {
if (! word.isEmpty()) { if (! word.isEmpty()) {
const QChar ch = word.at(0); const QChar ch = word.at(0);
@@ -115,38 +113,36 @@ bool checkStartOfIdentifier(const QString &word)
return false; return false;
} }
} // Anonymous
// ---------------------------- // ----------------------------
// GLSLCompletionAssistProvider // GlslCompletionAssistProvider
// ---------------------------- // ----------------------------
bool GLSLCompletionAssistProvider::supportsEditor(Core::Id editorId) const bool GlslCompletionAssistProvider::supportsEditor(Core::Id editorId) const
{ {
return editorId == Constants::C_GLSLEDITOR_ID; return editorId == Constants::C_GLSLEDITOR_ID;
} }
IAssistProcessor *GLSLCompletionAssistProvider::createProcessor() const IAssistProcessor *GlslCompletionAssistProvider::createProcessor() const
{ {
return new GLSLCompletionAssistProcessor; return new GlslCompletionAssistProcessor;
} }
int GLSLCompletionAssistProvider::activationCharSequenceLength() const int GlslCompletionAssistProvider::activationCharSequenceLength() const
{ {
return 1; return 1;
} }
bool GLSLCompletionAssistProvider::isActivationCharSequence(const QString &sequence) const bool GlslCompletionAssistProvider::isActivationCharSequence(const QString &sequence) const
{ {
return isActivationChar(sequence.at(0)); return isActivationChar(sequence.at(0));
} }
// ----------------------------- // -----------------------------
// GLSLFunctionHintProposalModel // GlslFunctionHintProposalModel
// ----------------------------- // -----------------------------
class GLSLFunctionHintProposalModel : public TextEditor::IFunctionHintProposalModel class GlslFunctionHintProposalModel : public IFunctionHintProposalModel
{ {
public: public:
GLSLFunctionHintProposalModel(QVector<GLSL::Function *> functionSymbols) GlslFunctionHintProposalModel(QVector<GLSL::Function *> functionSymbols)
: m_items(functionSymbols) : m_items(functionSymbols)
, m_currentArg(-1) , m_currentArg(-1)
{} {}
@@ -161,12 +157,12 @@ private:
mutable int m_currentArg; mutable int m_currentArg;
}; };
QString GLSLFunctionHintProposalModel::text(int index) const QString GlslFunctionHintProposalModel::text(int index) const
{ {
return m_items.at(index)->prettyPrint(m_currentArg); return m_items.at(index)->prettyPrint(m_currentArg);
} }
int GLSLFunctionHintProposalModel::activeArgument(const QString &prefix) const int GlslFunctionHintProposalModel::activeArgument(const QString &prefix) const
{ {
const QByteArray &str = prefix.toLatin1(); const QByteArray &str = prefix.toLatin1();
int argnr = 0; int argnr = 0;
@@ -200,7 +196,7 @@ int GLSLFunctionHintProposalModel::activeArgument(const QString &prefix) const
// ----------------------------- // -----------------------------
// GLSLCompletionAssistProcessor // GLSLCompletionAssistProcessor
// ----------------------------- // -----------------------------
GLSLCompletionAssistProcessor::GLSLCompletionAssistProcessor() GlslCompletionAssistProcessor::GlslCompletionAssistProcessor()
: m_startPosition(0) : m_startPosition(0)
, m_keywordIcon(QLatin1String(":/glsleditor/images/keyword.png")) , m_keywordIcon(QLatin1String(":/glsleditor/images/keyword.png"))
, m_varIcon(QLatin1String(":/glsleditor/images/var.png")) , m_varIcon(QLatin1String(":/glsleditor/images/var.png"))
@@ -213,12 +209,12 @@ GLSLCompletionAssistProcessor::GLSLCompletionAssistProcessor()
, m_otherIcon(QLatin1String(":/glsleditor/images/other.png")) , m_otherIcon(QLatin1String(":/glsleditor/images/other.png"))
{} {}
GLSLCompletionAssistProcessor::~GLSLCompletionAssistProcessor() GlslCompletionAssistProcessor::~GlslCompletionAssistProcessor()
{} {}
IAssistProposal *GLSLCompletionAssistProcessor::perform(const IAssistInterface *interface) IAssistProposal *GlslCompletionAssistProcessor::perform(const IAssistInterface *interface)
{ {
m_interface.reset(static_cast<const GLSLCompletionAssistInterface *>(interface)); m_interface.reset(static_cast<const GlslCompletionAssistInterface *>(interface));
if (interface->reason() == IdleEditor && !acceptsIdleEditor()) if (interface->reason() == IdleEditor && !acceptsIdleEditor())
return 0; return 0;
@@ -404,22 +400,22 @@ IAssistProposal *GLSLCompletionAssistProcessor::perform(const IAssistInterface *
return createContentProposal(); return createContentProposal();
} }
IAssistProposal *GLSLCompletionAssistProcessor::createContentProposal() const IAssistProposal *GlslCompletionAssistProcessor::createContentProposal() const
{ {
IGenericProposalModel *model = new BasicProposalItemListModel(m_completions); IGenericProposalModel *model = new BasicProposalItemListModel(m_completions);
IAssistProposal *proposal = new GenericProposal(m_startPosition, model); IAssistProposal *proposal = new GenericProposal(m_startPosition, model);
return proposal; return proposal;
} }
IAssistProposal *GLSLCompletionAssistProcessor::createHintProposal( IAssistProposal *GlslCompletionAssistProcessor::createHintProposal(
const QVector<GLSL::Function *> &symbols) const QVector<GLSL::Function *> &symbols)
{ {
IFunctionHintProposalModel *model = new GLSLFunctionHintProposalModel(symbols); IFunctionHintProposalModel *model = new GlslFunctionHintProposalModel(symbols);
IAssistProposal *proposal = new FunctionHintProposal(m_startPosition, model); IAssistProposal *proposal = new FunctionHintProposal(m_startPosition, model);
return proposal; return proposal;
} }
bool GLSLCompletionAssistProcessor::acceptsIdleEditor() const bool GlslCompletionAssistProcessor::acceptsIdleEditor() const
{ {
const int cursorPosition = m_interface->position(); const int cursorPosition = m_interface->position();
const QChar ch = m_interface->characterAt(cursorPosition - 1); const QChar ch = m_interface->characterAt(cursorPosition - 1);
@@ -449,7 +445,7 @@ bool GLSLCompletionAssistProcessor::acceptsIdleEditor() const
return isActivationChar(ch); return isActivationChar(ch);
} }
void GLSLCompletionAssistProcessor::addCompletion(const QString &text, void GlslCompletionAssistProcessor::addCompletion(const QString &text,
const QIcon &icon, const QIcon &icon,
int order) int order)
{ {
@@ -461,12 +457,12 @@ void GLSLCompletionAssistProcessor::addCompletion(const QString &text,
} }
// ----------------------------- // -----------------------------
// GLSLCompletionAssistInterface // GlslCompletionAssistInterface
// ----------------------------- // -----------------------------
GLSLCompletionAssistInterface::GLSLCompletionAssistInterface(QTextDocument *textDocument, GlslCompletionAssistInterface::GlslCompletionAssistInterface(QTextDocument *textDocument,
int position, int position,
const QString &fileName, const QString &fileName,
TextEditor::AssistReason reason, AssistReason reason,
const QString &mimeType, const QString &mimeType,
const Document::Ptr &glslDoc) const Document::Ptr &glslDoc)
: DefaultAssistInterface(textDocument, position, fileName, reason) : DefaultAssistInterface(textDocument, position, fileName, reason)
@@ -474,3 +470,6 @@ GLSLCompletionAssistInterface::GLSLCompletionAssistInterface(QTextDocument *text
, m_glslDoc(glslDoc) , m_glslDoc(glslDoc)
{ {
} }
} // namespace Internal
} // namespace GLSLEditor

View File

@@ -49,9 +49,9 @@ namespace TextEditor { class BasicProposalItem; }
namespace GLSLEditor { namespace GLSLEditor {
namespace Internal { namespace Internal {
class GLSLCompletionAssistInterface; class GlslCompletionAssistInterface;
class GLSLCompletionAssistProvider : public TextEditor::CompletionAssistProvider class GlslCompletionAssistProvider : public TextEditor::CompletionAssistProvider
{ {
Q_OBJECT Q_OBJECT
@@ -63,11 +63,11 @@ public:
bool isActivationCharSequence(const QString &sequence) const QTC_OVERRIDE; bool isActivationCharSequence(const QString &sequence) const QTC_OVERRIDE;
}; };
class GLSLCompletionAssistProcessor : public TextEditor::IAssistProcessor class GlslCompletionAssistProcessor : public TextEditor::IAssistProcessor
{ {
public: public:
GLSLCompletionAssistProcessor(); GlslCompletionAssistProcessor();
~GLSLCompletionAssistProcessor(); ~GlslCompletionAssistProcessor();
TextEditor::IAssistProposal *perform(const TextEditor::IAssistInterface *interface) QTC_OVERRIDE; TextEditor::IAssistProposal *perform(const TextEditor::IAssistInterface *interface) QTC_OVERRIDE;
@@ -78,7 +78,7 @@ private:
void addCompletion(const QString &text, const QIcon &icon, int order = 0); void addCompletion(const QString &text, const QIcon &icon, int order = 0);
int m_startPosition; int m_startPosition;
QScopedPointer<const GLSLCompletionAssistInterface> m_interface; QScopedPointer<const GlslCompletionAssistInterface> m_interface;
QList<TextEditor::BasicProposalItem *> m_completions; QList<TextEditor::BasicProposalItem *> m_completions;
QIcon m_keywordIcon; QIcon m_keywordIcon;
@@ -92,10 +92,10 @@ private:
QIcon m_otherIcon; QIcon m_otherIcon;
}; };
class GLSLCompletionAssistInterface : public TextEditor::DefaultAssistInterface class GlslCompletionAssistInterface : public TextEditor::DefaultAssistInterface
{ {
public: public:
GLSLCompletionAssistInterface(QTextDocument *textDocument, GlslCompletionAssistInterface(QTextDocument *textDocument,
int position, const QString &fileName, int position, const QString &fileName,
TextEditor::AssistReason reason, TextEditor::AssistReason reason,
const QString &mimeType, const QString &mimeType,
@@ -109,7 +109,7 @@ private:
Document::Ptr m_glslDoc; Document::Ptr m_glslDoc;
}; };
} // Internal } // namespace Internal
} // GLSLEditor } // namespace GLSLEditor
#endif // GLSLCOMPLETIONASSIST_H #endif // GLSLCOMPLETIONASSIST_H

View File

@@ -141,7 +141,7 @@ void Document::addRange(const QTextCursor &cursor, GLSL::Scope *scope)
GlslEditorWidget::GlslEditorWidget() GlslEditorWidget::GlslEditorWidget()
{ {
setAutoCompleter(new GLSLCompleter); setAutoCompleter(new GlslCompleter);
m_outlineCombo = 0; m_outlineCombo = 0;
setParenthesesMatchingEnabled(true); setParenthesesMatchingEnabled(true);
setMarksVisible(true); setMarksVisible(true);
@@ -242,14 +242,14 @@ void GlslEditorWidget::updateDocumentNow()
Semantic sem; Semantic sem;
Scope *globalScope = engine->newNamespace(); Scope *globalScope = engine->newNamespace();
doc->_globalScope = globalScope; doc->_globalScope = globalScope;
const GLSLEditorPlugin::InitFile *file = GLSLEditorPlugin::shaderInit(variant); const GlslEditorPlugin::InitFile *file = GlslEditorPlugin::shaderInit(variant);
sem.translationUnit(file->ast, globalScope, file->engine); sem.translationUnit(file->ast, globalScope, file->engine);
if (variant & Lexer::Variant_VertexShader) { if (variant & Lexer::Variant_VertexShader) {
file = GLSLEditorPlugin::vertexShaderInit(variant); file = GlslEditorPlugin::vertexShaderInit(variant);
sem.translationUnit(file->ast, globalScope, file->engine); sem.translationUnit(file->ast, globalScope, file->engine);
} }
if (variant & Lexer::Variant_FragmentShader) { if (variant & Lexer::Variant_FragmentShader) {
file = GLSLEditorPlugin::fragmentShaderInit(variant); file = GlslEditorPlugin::fragmentShaderInit(variant);
sem.translationUnit(file->ast, globalScope, file->engine); sem.translationUnit(file->ast, globalScope, file->engine);
} }
sem.translationUnit(ast, globalScope, engine); sem.translationUnit(ast, globalScope, engine);
@@ -332,7 +332,7 @@ IAssistInterface *GlslEditorWidget::createAssistInterface(
AssistKind kind, AssistReason reason) const AssistKind kind, AssistReason reason) const
{ {
if (kind == Completion) if (kind == Completion)
return new GLSLCompletionAssistInterface(document(), return new GlslCompletionAssistInterface(document(),
position(), position(),
editor()->document()->filePath(), editor()->document()->filePath(),
reason, reason,
@@ -353,14 +353,14 @@ GlslEditor::GlslEditor()
addContext(C_GLSLEDITOR_ID); addContext(C_GLSLEDITOR_ID);
setDuplicateSupported(true); setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle); setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GLSLCompletionAssistProvider>()); setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GlslCompletionAssistProvider>());
setEditorCreator([]() { return new GlslEditor; }); setEditorCreator([]() { return new GlslEditor; });
setWidgetCreator([]() { return new GlslEditorWidget; }); setWidgetCreator([]() { return new GlslEditorWidget; });
setDocumentCreator([]() -> BaseTextDocument * { setDocumentCreator([]() -> BaseTextDocument * {
auto doc = new BaseTextDocument(C_GLSLEDITOR_ID); auto doc = new BaseTextDocument(C_GLSLEDITOR_ID);
doc->setIndenter(new GLSLIndenter); doc->setIndenter(new GlslIndenter);
new Highlighter(doc); new Highlighter(doc);
return doc; return doc;
}); });

View File

@@ -71,10 +71,10 @@ using namespace TextEditor;
namespace GLSLEditor { namespace GLSLEditor {
namespace Internal { namespace Internal {
class GLSLEditorPluginPrivate class GlslEditorPluginPrivate
{ {
public: public:
GLSLEditorPluginPrivate() : GlslEditorPluginPrivate() :
m_glsl_120_frag(0), m_glsl_120_frag(0),
m_glsl_120_vert(0), m_glsl_120_vert(0),
m_glsl_120_common(0), m_glsl_120_common(0),
@@ -83,7 +83,7 @@ public:
m_glsl_es_100_common(0) m_glsl_es_100_common(0)
{} {}
~GLSLEditorPluginPrivate() ~GlslEditorPluginPrivate()
{ {
delete m_glsl_120_frag; delete m_glsl_120_frag;
delete m_glsl_120_vert; delete m_glsl_120_vert;
@@ -93,44 +93,44 @@ public:
delete m_glsl_es_100_common; delete m_glsl_es_100_common;
} }
QPointer<TextEditor::BaseTextEditor> m_currentTextEditable; QPointer<BaseTextEditor> m_currentTextEditable;
GLSLEditorPlugin::InitFile *m_glsl_120_frag; GlslEditorPlugin::InitFile *m_glsl_120_frag;
GLSLEditorPlugin::InitFile *m_glsl_120_vert; GlslEditorPlugin::InitFile *m_glsl_120_vert;
GLSLEditorPlugin::InitFile *m_glsl_120_common; GlslEditorPlugin::InitFile *m_glsl_120_common;
GLSLEditorPlugin::InitFile *m_glsl_es_100_frag; GlslEditorPlugin::InitFile *m_glsl_es_100_frag;
GLSLEditorPlugin::InitFile *m_glsl_es_100_vert; GlslEditorPlugin::InitFile *m_glsl_es_100_vert;
GLSLEditorPlugin::InitFile *m_glsl_es_100_common; GlslEditorPlugin::InitFile *m_glsl_es_100_common;
}; };
static GLSLEditorPluginPrivate *dd = 0; static GlslEditorPluginPrivate *dd = 0;
static GLSLEditorPlugin *m_instance = 0; static GlslEditorPlugin *m_instance = 0;
GLSLEditorPlugin::InitFile::~InitFile() GlslEditorPlugin::InitFile::~InitFile()
{ {
delete engine; delete engine;
} }
GLSLEditorPlugin::GLSLEditorPlugin() GlslEditorPlugin::GlslEditorPlugin()
{ {
m_instance = this; m_instance = this;
dd = new GLSLEditorPluginPrivate; dd = new GlslEditorPluginPrivate;
} }
GLSLEditorPlugin::~GLSLEditorPlugin() GlslEditorPlugin::~GlslEditorPlugin()
{ {
delete dd; delete dd;
m_instance = 0; m_instance = 0;
} }
bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage) bool GlslEditorPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
{ {
if (!MimeDatabase::addMimeTypes(QLatin1String(":/glsleditor/GLSLEditor.mimetypes.xml"), errorMessage)) if (!MimeDatabase::addMimeTypes(QLatin1String(":/glsleditor/GLSLEditor.mimetypes.xml"), errorMessage))
return false; return false;
addAutoReleasedObject(new GLSLHoverHandler(this)); addAutoReleasedObject(new GlslHoverHandler(this));
addAutoReleasedObject(new GlslEditorFactory); addAutoReleasedObject(new GlslEditorFactory);
addAutoReleasedObject(new GLSLCompletionAssistProvider); addAutoReleasedObject(new GlslCompletionAssistProvider);
ActionContainer *contextMenu = ActionManager::createMenu(GLSLEditor::Constants::M_CONTEXT); ActionContainer *contextMenu = ActionManager::createMenu(GLSLEditor::Constants::M_CONTEXT);
ActionContainer *glslToolsMenu = ActionManager::createMenu(Id(Constants::M_TOOLS_GLSL)); ActionContainer *glslToolsMenu = ActionManager::createMenu(Id(Constants::M_TOOLS_GLSL));
@@ -159,7 +159,7 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE_VERT_ES); FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE_VERT_ES);
FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE_FRAG_ES); FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE_FRAG_ES);
IWizardFactory *wizard = new GLSLFileWizard(GLSLFileWizard::FragmentShaderES); IWizardFactory *wizard = new GlslFileWizard(GlslFileWizard::FragmentShaderES);
wizard->setWizardKind(IWizardFactory::FileWizard); wizard->setWizardKind(IWizardFactory::FileWizard);
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL)); wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL)); wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
@@ -172,7 +172,7 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
wizard->setId(QLatin1String("F.GLSL")); wizard->setId(QLatin1String("F.GLSL"));
addAutoReleasedObject(wizard); addAutoReleasedObject(wizard);
wizard = new GLSLFileWizard(GLSLFileWizard::VertexShaderES); wizard = new GlslFileWizard(GlslFileWizard::VertexShaderES);
wizard->setWizardKind(IWizardFactory::FileWizard); wizard->setWizardKind(IWizardFactory::FileWizard);
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL)); wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL)); wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
@@ -185,7 +185,7 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
wizard->setId(QLatin1String("G.GLSL")); wizard->setId(QLatin1String("G.GLSL"));
addAutoReleasedObject(wizard); addAutoReleasedObject(wizard);
wizard = new GLSLFileWizard(GLSLFileWizard::FragmentShaderDesktop); wizard = new GlslFileWizard(GlslFileWizard::FragmentShaderDesktop);
wizard->setWizardKind(IWizardFactory::FileWizard); wizard->setWizardKind(IWizardFactory::FileWizard);
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL)); wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL)); wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
@@ -198,7 +198,7 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
wizard->setId(QLatin1String("J.GLSL")); wizard->setId(QLatin1String("J.GLSL"));
addAutoReleasedObject(wizard); addAutoReleasedObject(wizard);
wizard = new GLSLFileWizard(GLSLFileWizard::VertexShaderDesktop); wizard = new GlslFileWizard(GlslFileWizard::VertexShaderDesktop);
wizard->setWizardKind(IWizardFactory::FileWizard); wizard->setWizardKind(IWizardFactory::FileWizard);
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL)); wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL)); wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
@@ -211,7 +211,7 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
wizard->setId(QLatin1String("K.GLSL")); wizard->setId(QLatin1String("K.GLSL"));
addAutoReleasedObject(wizard); addAutoReleasedObject(wizard);
auto hf = new TextEditor::HighlighterFactory; auto hf = new HighlighterFactory;
hf->setProductType<Highlighter>(); hf->setProductType<Highlighter>();
hf->setId(GLSLEditor::Constants::C_GLSLEDITOR_ID); hf->setId(GLSLEditor::Constants::C_GLSLEDITOR_ID);
hf->addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE); hf->addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE);
@@ -224,11 +224,11 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
return true; return true;
} }
void GLSLEditorPlugin::extensionsInitialized() void GlslEditorPlugin::extensionsInitialized()
{ {
} }
ExtensionSystem::IPlugin::ShutdownFlag GLSLEditorPlugin::aboutToShutdown() ExtensionSystem::IPlugin::ShutdownFlag GlslEditorPlugin::aboutToShutdown()
{ {
// delete GLSL::Icons::instance(); // delete object held by singleton // delete GLSL::Icons::instance(); // delete object held by singleton
return IPlugin::aboutToShutdown(); return IPlugin::aboutToShutdown();
@@ -242,7 +242,7 @@ static QByteArray glslFile(const QString &fileName)
return QByteArray(); return QByteArray();
} }
static void parseGlslFile(const QString &fileName, GLSLEditorPlugin::InitFile *initFile) static void parseGlslFile(const QString &fileName, GlslEditorPlugin::InitFile *initFile)
{ {
// Parse the builtins for any langugage variant so we can use all keywords. // Parse the builtins for any langugage variant so we can use all keywords.
const int variant = GLSL::Lexer::Variant_All; const int variant = GLSL::Lexer::Variant_All;
@@ -253,16 +253,16 @@ static void parseGlslFile(const QString &fileName, GLSLEditorPlugin::InitFile *i
initFile->ast = parser.parse(); initFile->ast = parser.parse();
} }
static GLSLEditorPlugin::InitFile *getInitFile(const char *fileName, GLSLEditorPlugin::InitFile **initFile) static GlslEditorPlugin::InitFile *getInitFile(const char *fileName, GlslEditorPlugin::InitFile **initFile)
{ {
if (*initFile) if (*initFile)
return *initFile; return *initFile;
*initFile = new GLSLEditorPlugin::InitFile; *initFile = new GlslEditorPlugin::InitFile;
parseGlslFile(QLatin1String(fileName), *initFile); parseGlslFile(QLatin1String(fileName), *initFile);
return *initFile; return *initFile;
} }
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::fragmentShaderInit(int variant) const GlslEditorPlugin::InitFile *GlslEditorPlugin::fragmentShaderInit(int variant)
{ {
if (variant & GLSL::Lexer::Variant_GLSL_120) if (variant & GLSL::Lexer::Variant_GLSL_120)
return getInitFile("glsl_120.frag", &dd->m_glsl_120_frag); return getInitFile("glsl_120.frag", &dd->m_glsl_120_frag);
@@ -270,7 +270,7 @@ const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::fragmentShaderInit(int varia
return getInitFile("glsl_es_100.frag", &dd->m_glsl_es_100_frag); return getInitFile("glsl_es_100.frag", &dd->m_glsl_es_100_frag);
} }
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::vertexShaderInit(int variant) const GlslEditorPlugin::InitFile *GlslEditorPlugin::vertexShaderInit(int variant)
{ {
if (variant & GLSL::Lexer::Variant_GLSL_120) if (variant & GLSL::Lexer::Variant_GLSL_120)
return getInitFile("glsl_120.vert", &dd->m_glsl_120_vert); return getInitFile("glsl_120.vert", &dd->m_glsl_120_vert);
@@ -278,7 +278,7 @@ const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::vertexShaderInit(int variant
return getInitFile("glsl_es_100.vert", &dd->m_glsl_es_100_vert); return getInitFile("glsl_es_100.vert", &dd->m_glsl_es_100_vert);
} }
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::shaderInit(int variant) const GlslEditorPlugin::InitFile *GlslEditorPlugin::shaderInit(int variant)
{ {
if (variant & GLSL::Lexer::Variant_GLSL_120) if (variant & GLSL::Lexer::Variant_GLSL_120)
return getInitFile("glsl_120_common.glsl", &dd->m_glsl_120_common); return getInitFile("glsl_120_common.glsl", &dd->m_glsl_120_common);

View File

@@ -38,14 +38,14 @@ namespace Internal {
class GlslEditorWidget; class GlslEditorWidget;
class GLSLEditorPlugin : public ExtensionSystem::IPlugin class GlslEditorPlugin : public ExtensionSystem::IPlugin
{ {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "GLSLEditor.json") Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "GLSLEditor.json")
public: public:
GLSLEditorPlugin(); GlslEditorPlugin();
~GLSLEditorPlugin(); ~GlslEditorPlugin();
// IPlugin // IPlugin
bool initialize(const QStringList &arguments, QString *errorMessage = 0); bool initialize(const QStringList &arguments, QString *errorMessage = 0);

View File

@@ -40,39 +40,41 @@
#include <QWizard> #include <QWizard>
#include <QPushButton> #include <QPushButton>
using namespace GLSLEditor; using namespace Core;
using namespace Utils;
GLSLFileWizard::GLSLFileWizard(ShaderType shaderType) namespace GLSLEditor {
GlslFileWizard::GlslFileWizard(ShaderType shaderType)
: m_shaderType(shaderType) : m_shaderType(shaderType)
{ {
setFlags(Core::IWizardFactory::PlatformIndependent); setFlags(IWizardFactory::PlatformIndependent);
} }
Core::GeneratedFiles GLSLFileWizard::generateFiles(const QWizard *w, GeneratedFiles GlslFileWizard::generateFiles(const QWizard *w, QString * /*errorMessage*/) const
QString * /*errorMessage*/) const
{ {
const Core::BaseFileWizard *wizard = qobject_cast<const Core::BaseFileWizard *>(w); const BaseFileWizard *wizard = qobject_cast<const BaseFileWizard *>(w);
Utils::FileWizardPage *page = wizard->find<Utils::FileWizardPage>(); const FileWizardPage *page = wizard->find<FileWizardPage>();
QTC_ASSERT(page, return Core::GeneratedFiles()); QTC_ASSERT(page, return GeneratedFiles());
const QString path = page->path(); const QString path = page->path();
const QString name = page->fileName(); const QString name = page->fileName();
const QString fileName = Core::BaseFileWizardFactory::buildFileName(path, name, preferredSuffix(m_shaderType)); const QString fileName = BaseFileWizardFactory::buildFileName(path, name, preferredSuffix(m_shaderType));
Core::GeneratedFile file(fileName); GeneratedFile file(fileName);
file.setContents(fileContents(fileName, m_shaderType)); file.setContents(fileContents(fileName, m_shaderType));
file.setAttributes(Core::GeneratedFile::OpenEditorAttribute); file.setAttributes(GeneratedFile::OpenEditorAttribute);
return Core::GeneratedFiles() << file; return GeneratedFiles() << file;
} }
QString GLSLFileWizard::fileContents(const QString &, ShaderType shaderType) const QString GlslFileWizard::fileContents(const QString &, ShaderType shaderType) const
{ {
QString contents; QString contents;
QTextStream str(&contents); QTextStream str(&contents);
switch (shaderType) { switch (shaderType) {
case GLSLFileWizard::VertexShaderES: case GlslFileWizard::VertexShaderES:
str << QLatin1String("attribute highp vec4 qt_Vertex;\n") str << QLatin1String("attribute highp vec4 qt_Vertex;\n")
<< QLatin1String("attribute highp vec4 qt_MultiTexCoord0;\n") << QLatin1String("attribute highp vec4 qt_MultiTexCoord0;\n")
<< QLatin1String("uniform highp mat4 qt_ModelViewProjectionMatrix;\n") << QLatin1String("uniform highp mat4 qt_ModelViewProjectionMatrix;\n")
@@ -84,7 +86,7 @@ QString GLSLFileWizard::fileContents(const QString &, ShaderType shaderType) con
<< QLatin1String(" qt_TexCoord0 = qt_MultiTexCoord0;\n") << QLatin1String(" qt_TexCoord0 = qt_MultiTexCoord0;\n")
<< QLatin1String("}\n"); << QLatin1String("}\n");
break; break;
case GLSLFileWizard::FragmentShaderES: case GlslFileWizard::FragmentShaderES:
str << QLatin1String("uniform sampler2D qt_Texture0;\n") str << QLatin1String("uniform sampler2D qt_Texture0;\n")
<< QLatin1String("varying highp vec4 qt_TexCoord0;\n") << QLatin1String("varying highp vec4 qt_TexCoord0;\n")
<< QLatin1String("\n") << QLatin1String("\n")
@@ -93,7 +95,7 @@ QString GLSLFileWizard::fileContents(const QString &, ShaderType shaderType) con
<< QLatin1String(" gl_FragColor = texture2D(qt_Texture0, qt_TexCoord0.st);\n") << QLatin1String(" gl_FragColor = texture2D(qt_Texture0, qt_TexCoord0.st);\n")
<< QLatin1String("}\n"); << QLatin1String("}\n");
break; break;
case GLSLFileWizard::VertexShaderDesktop: case GlslFileWizard::VertexShaderDesktop:
str << QLatin1String("attribute vec4 qt_Vertex;\n") str << QLatin1String("attribute vec4 qt_Vertex;\n")
<< QLatin1String("attribute vec4 qt_MultiTexCoord0;\n") << QLatin1String("attribute vec4 qt_MultiTexCoord0;\n")
<< QLatin1String("uniform mat4 qt_ModelViewProjectionMatrix;\n") << QLatin1String("uniform mat4 qt_ModelViewProjectionMatrix;\n")
@@ -105,7 +107,7 @@ QString GLSLFileWizard::fileContents(const QString &, ShaderType shaderType) con
<< QLatin1String(" qt_TexCoord0 = qt_MultiTexCoord0;\n") << QLatin1String(" qt_TexCoord0 = qt_MultiTexCoord0;\n")
<< QLatin1String("}\n"); << QLatin1String("}\n");
break; break;
case GLSLFileWizard::FragmentShaderDesktop: case GlslFileWizard::FragmentShaderDesktop:
str << QLatin1String("uniform sampler2D qt_Texture0;\n") str << QLatin1String("uniform sampler2D qt_Texture0;\n")
<< QLatin1String("varying vec4 qt_TexCoord0;\n") << QLatin1String("varying vec4 qt_TexCoord0;\n")
<< QLatin1String("\n") << QLatin1String("\n")
@@ -120,11 +122,11 @@ QString GLSLFileWizard::fileContents(const QString &, ShaderType shaderType) con
return contents; return contents;
} }
Core::BaseFileWizard *GLSLFileWizard::create(QWidget *parent, const Core::WizardDialogParameters &parameters) const BaseFileWizard *GlslFileWizard::create(QWidget *parent, const WizardDialogParameters &parameters) const
{ {
Core::BaseFileWizard *wizard = new Core::BaseFileWizard(parent); BaseFileWizard *wizard = new BaseFileWizard(parent);
wizard->setWindowTitle(tr("New %1").arg(displayName())); wizard->setWindowTitle(tr("New %1").arg(displayName()));
Utils::FileWizardPage *page = new Utils::FileWizardPage; FileWizardPage *page = new FileWizardPage;
page->setPath(parameters.defaultPath()); page->setPath(parameters.defaultPath());
wizard->addPage(page); wizard->addPage(page);
@@ -133,18 +135,20 @@ Core::BaseFileWizard *GLSLFileWizard::create(QWidget *parent, const Core::Wizard
return wizard; return wizard;
} }
QString GLSLFileWizard::preferredSuffix(ShaderType shaderType) const QString GlslFileWizard::preferredSuffix(ShaderType shaderType) const
{ {
switch (shaderType) { switch (shaderType) {
case GLSLFileWizard::VertexShaderES: case GlslFileWizard::VertexShaderES:
return QLatin1String("vsh"); return QLatin1String("vsh");
case GLSLFileWizard::FragmentShaderES: case GlslFileWizard::FragmentShaderES:
return QLatin1String("fsh"); return QLatin1String("fsh");
case GLSLFileWizard::VertexShaderDesktop: case GlslFileWizard::VertexShaderDesktop:
return QLatin1String("vert"); return QLatin1String("vert");
case GLSLFileWizard::FragmentShaderDesktop: case GlslFileWizard::FragmentShaderDesktop:
return QLatin1String("frag"); return QLatin1String("frag");
default: default:
return QLatin1String("glsl"); return QLatin1String("glsl");
} }
} }
} // namespace GlslEditor

View File

@@ -34,7 +34,7 @@
namespace GLSLEditor { namespace GLSLEditor {
class GLSLFileWizard: public Core::BaseFileWizardFactory class GlslFileWizard: public Core::BaseFileWizardFactory
{ {
Q_OBJECT Q_OBJECT
@@ -47,7 +47,7 @@ public:
FragmentShaderDesktop FragmentShaderDesktop
}; };
explicit GLSLFileWizard(ShaderType shaderType); explicit GlslFileWizard(ShaderType shaderType);
private: private:
QString fileContents(const QString &baseName, ShaderType shaderType) const; QString fileContents(const QString &baseName, ShaderType shaderType) const;

View File

@@ -38,24 +38,23 @@
#include <QTextCursor> #include <QTextCursor>
using namespace GLSLEditor;
using namespace GLSLEditor::Internal;
using namespace Core; using namespace Core;
GLSLHoverHandler::GLSLHoverHandler(QObject *parent) : BaseHoverHandler(parent) namespace GLSLEditor {
namespace Internal {
GlslHoverHandler::GlslHoverHandler(QObject *parent) : BaseHoverHandler(parent)
{} {}
GLSLHoverHandler::~GLSLHoverHandler() GlslHoverHandler::~GlslHoverHandler()
{} {}
bool GLSLHoverHandler::acceptEditor(IEditor *editor) bool GlslHoverHandler::acceptEditor(IEditor *editor)
{ {
if (qobject_cast<GlslEditor *>(editor) != 0) return qobject_cast<GlslEditor *>(editor) != 0;
return true;
return false;
} }
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 (GlslEditorWidget *glslEditor = qobject_cast<GlslEditorWidget *>(editor->widget())) {
if (! glslEditor->extraSelectionTooltip(pos).isEmpty()) if (! glslEditor->extraSelectionTooltip(pos).isEmpty())
@@ -63,8 +62,11 @@ void GLSLHoverHandler::identifyMatch(TextEditor::BaseTextEditor *editor, int pos
} }
} }
void GLSLHoverHandler::decorateToolTip() void GlslHoverHandler::decorateToolTip()
{ {
if (Qt::mightBeRichText(toolTip())) if (Qt::mightBeRichText(toolTip()))
setToolTip(Qt::escape(toolTip())); setToolTip(Qt::escape(toolTip()));
} }
} // namespace Internal
} // namespace GLSLEditor

View File

@@ -41,12 +41,12 @@ namespace TextEditor { class BaseTextEditor; }
namespace GLSLEditor { namespace GLSLEditor {
namespace Internal { namespace Internal {
class GLSLHoverHandler : public TextEditor::BaseHoverHandler class GlslHoverHandler : public TextEditor::BaseHoverHandler
{ {
Q_OBJECT Q_OBJECT
public: public:
GLSLHoverHandler(QObject *parent = 0); GlslHoverHandler(QObject *parent = 0);
virtual ~GLSLHoverHandler(); virtual ~GlslHoverHandler();
private: private:
virtual bool acceptEditor(Core::IEditor *editor); virtual bool acceptEditor(Core::IEditor *editor);

View File

@@ -39,27 +39,24 @@
#include <QTextBlock> #include <QTextBlock>
#include <QTextCursor> #include <QTextCursor>
using namespace GLSLEditor; namespace GLSLEditor {
using namespace Internal; namespace Internal {
GLSLIndenter::GLSLIndenter() GlslIndenter::GlslIndenter()
{} {}
GLSLIndenter::~GLSLIndenter() GlslIndenter::~GlslIndenter()
{} {}
bool GLSLIndenter::isElectricCharacter(const QChar &ch) const bool GlslIndenter::isElectricCharacter(const QChar &ch) const
{ {
if (ch == QLatin1Char('{') || return ch == QLatin1Char('{')
ch == QLatin1Char('}') || || ch == QLatin1Char('}')
ch == QLatin1Char(':') || || ch == QLatin1Char(':')
ch == QLatin1Char('#')) { || ch == QLatin1Char('#');
return true;
}
return false;
} }
void GLSLIndenter::indentBlock(QTextDocument *doc, void GlslIndenter::indentBlock(QTextDocument *doc,
const QTextBlock &block, const QTextBlock &block,
const QChar &typedChar, const QChar &typedChar,
const TextEditor::TabSettings &tabSettings) const TextEditor::TabSettings &tabSettings)
@@ -75,8 +72,8 @@ void GLSLIndenter::indentBlock(QTextDocument *doc,
int padding; int padding;
codeFormatter.indentFor(block, &indent, &padding); codeFormatter.indentFor(block, &indent, &padding);
// only reindent the current line when typing electric characters if the // Only reindent the current line when typing electric characters if the
// indent is the same it would be if the line were empty // indent is the same it would be if the line were empty.
if (isElectricCharacter(typedChar)) { if (isElectricCharacter(typedChar)) {
int newlineIndent; int newlineIndent;
int newlinePadding; int newlinePadding;
@@ -88,7 +85,7 @@ void GLSLIndenter::indentBlock(QTextDocument *doc,
tabSettings.indentLine(block, indent + padding, padding); tabSettings.indentLine(block, indent + padding, padding);
} }
void GLSLIndenter::indent(QTextDocument *doc, void GlslIndenter::indent(QTextDocument *doc,
const QTextCursor &cursor, const QTextCursor &cursor,
const QChar &typedChar, const QChar &typedChar,
const TextEditor::TabSettings &tabSettings) const TextEditor::TabSettings &tabSettings)
@@ -117,3 +114,6 @@ void GLSLIndenter::indent(QTextDocument *doc,
indentBlock(doc, cursor.block(), typedChar, tabSettings); indentBlock(doc, cursor.block(), typedChar, tabSettings);
} }
} }
} // namespace Internal
} // namespace GLSLEditor

View File

@@ -35,11 +35,11 @@
namespace GLSLEditor { namespace GLSLEditor {
namespace Internal { namespace Internal {
class GLSLIndenter : public TextEditor::Indenter class GlslIndenter : public TextEditor::Indenter
{ {
public: public:
GLSLIndenter(); GlslIndenter();
virtual ~GLSLIndenter(); virtual ~GlslIndenter();
virtual bool isElectricCharacter(const QChar &ch) const; virtual bool isElectricCharacter(const QChar &ch) const;
virtual void indentBlock(QTextDocument *doc, virtual void indentBlock(QTextDocument *doc,