forked from qt-creator/qt-creator
GlslEditor: Code cosmetics
Namespaces, CamelCase names. Change-Id: I6ced0dccb073bda0fc82fed1831886fb9f62bf65 Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -37,17 +37,18 @@
|
||||
#include <QLatin1Char>
|
||||
#include <QTextCursor>
|
||||
|
||||
using namespace GLSLEditor;
|
||||
using namespace Internal;
|
||||
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
|
||||
{
|
||||
QChar ch;
|
||||
@@ -65,7 +66,7 @@ bool GLSLCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
|
||||
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(),
|
||||
BackwardsScanner::previousBlockState(cursor.block()));
|
||||
@@ -94,7 +95,7 @@ bool GLSLCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) c
|
||||
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(),
|
||||
BackwardsScanner::previousBlockState(cursor.block()));
|
||||
@@ -118,7 +119,7 @@ bool GLSLCompleter::isInComment(const QTextCursor &cursor) const
|
||||
return false;
|
||||
}
|
||||
|
||||
QString GLSLCompleter::insertMatchingBrace(const QTextCursor &cursor,
|
||||
QString GlslCompleter::insertMatchingBrace(const QTextCursor &cursor,
|
||||
const QString &text,
|
||||
QChar la,
|
||||
int *skippedChars) const
|
||||
@@ -127,8 +128,11 @@ QString GLSLCompleter::insertMatchingBrace(const QTextCursor &cursor,
|
||||
return m.insertMatchingBrace(cursor, text, la, skippedChars);
|
||||
}
|
||||
|
||||
QString GLSLCompleter::insertParagraphSeparator(const QTextCursor &cursor) const
|
||||
QString GlslCompleter::insertParagraphSeparator(const QTextCursor &cursor) const
|
||||
{
|
||||
MatchingText m;
|
||||
return m.insertParagraphSeparator(cursor);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace GLSLEditor
|
||||
|
||||
@@ -35,11 +35,11 @@
|
||||
namespace GLSLEditor {
|
||||
namespace Internal {
|
||||
|
||||
class GLSLCompleter : public TextEditor::AutoCompleter
|
||||
class GlslCompleter : public TextEditor::AutoCompleter
|
||||
{
|
||||
public:
|
||||
GLSLCompleter();
|
||||
virtual ~GLSLCompleter();
|
||||
GlslCompleter();
|
||||
virtual ~GlslCompleter();
|
||||
|
||||
virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor,
|
||||
const QString &textToInsert = QString()) const;
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
virtual QString insertParagraphSeparator(const QTextCursor &cursor) const;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
} // GLSLEditor
|
||||
} // namespace Internal
|
||||
} // namespace GLSLEditor
|
||||
|
||||
#endif // GLSLAUTOCOMPLETER_H
|
||||
|
||||
@@ -59,28 +59,26 @@
|
||||
#include <QDesktopWidget>
|
||||
#include <QDebug>
|
||||
|
||||
using namespace GLSLEditor;
|
||||
using namespace Internal;
|
||||
using namespace TextEditor;
|
||||
|
||||
namespace {
|
||||
namespace GLSLEditor {
|
||||
namespace Internal {
|
||||
|
||||
enum CompletionOrder {
|
||||
SpecialMemberOrder = -5
|
||||
};
|
||||
|
||||
|
||||
bool isActivationChar(const QChar &ch)
|
||||
static bool isActivationChar(const QChar &ch)
|
||||
{
|
||||
return ch == QLatin1Char('(') || ch == QLatin1Char('.') || ch == QLatin1Char(',');
|
||||
}
|
||||
|
||||
bool isIdentifierChar(QChar ch)
|
||||
static bool isIdentifierChar(QChar ch)
|
||||
{
|
||||
return ch.isLetterOrNumber() || ch == QLatin1Char('_');
|
||||
}
|
||||
|
||||
bool isDelimiter(QChar ch)
|
||||
static bool isDelimiter(QChar ch)
|
||||
{
|
||||
switch (ch.unicode()) {
|
||||
case '{':
|
||||
@@ -104,7 +102,7 @@ bool isDelimiter(QChar ch)
|
||||
}
|
||||
}
|
||||
|
||||
bool checkStartOfIdentifier(const QString &word)
|
||||
static bool checkStartOfIdentifier(const QString &word)
|
||||
{
|
||||
if (! word.isEmpty()) {
|
||||
const QChar ch = word.at(0);
|
||||
@@ -115,38 +113,36 @@ bool checkStartOfIdentifier(const QString &word)
|
||||
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;
|
||||
}
|
||||
|
||||
IAssistProcessor *GLSLCompletionAssistProvider::createProcessor() const
|
||||
IAssistProcessor *GlslCompletionAssistProvider::createProcessor() const
|
||||
{
|
||||
return new GLSLCompletionAssistProcessor;
|
||||
return new GlslCompletionAssistProcessor;
|
||||
}
|
||||
|
||||
int GLSLCompletionAssistProvider::activationCharSequenceLength() const
|
||||
int GlslCompletionAssistProvider::activationCharSequenceLength() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool GLSLCompletionAssistProvider::isActivationCharSequence(const QString &sequence) const
|
||||
bool GlslCompletionAssistProvider::isActivationCharSequence(const QString &sequence) const
|
||||
{
|
||||
return isActivationChar(sequence.at(0));
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// GLSLFunctionHintProposalModel
|
||||
// GlslFunctionHintProposalModel
|
||||
// -----------------------------
|
||||
class GLSLFunctionHintProposalModel : public TextEditor::IFunctionHintProposalModel
|
||||
class GlslFunctionHintProposalModel : public IFunctionHintProposalModel
|
||||
{
|
||||
public:
|
||||
GLSLFunctionHintProposalModel(QVector<GLSL::Function *> functionSymbols)
|
||||
GlslFunctionHintProposalModel(QVector<GLSL::Function *> functionSymbols)
|
||||
: m_items(functionSymbols)
|
||||
, m_currentArg(-1)
|
||||
{}
|
||||
@@ -161,12 +157,12 @@ private:
|
||||
mutable int m_currentArg;
|
||||
};
|
||||
|
||||
QString GLSLFunctionHintProposalModel::text(int index) const
|
||||
QString GlslFunctionHintProposalModel::text(int index) const
|
||||
{
|
||||
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();
|
||||
int argnr = 0;
|
||||
@@ -200,7 +196,7 @@ int GLSLFunctionHintProposalModel::activeArgument(const QString &prefix) const
|
||||
// -----------------------------
|
||||
// GLSLCompletionAssistProcessor
|
||||
// -----------------------------
|
||||
GLSLCompletionAssistProcessor::GLSLCompletionAssistProcessor()
|
||||
GlslCompletionAssistProcessor::GlslCompletionAssistProcessor()
|
||||
: m_startPosition(0)
|
||||
, m_keywordIcon(QLatin1String(":/glsleditor/images/keyword.png"))
|
||||
, m_varIcon(QLatin1String(":/glsleditor/images/var.png"))
|
||||
@@ -213,12 +209,12 @@ GLSLCompletionAssistProcessor::GLSLCompletionAssistProcessor()
|
||||
, 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())
|
||||
return 0;
|
||||
@@ -404,22 +400,22 @@ IAssistProposal *GLSLCompletionAssistProcessor::perform(const IAssistInterface *
|
||||
return createContentProposal();
|
||||
}
|
||||
|
||||
IAssistProposal *GLSLCompletionAssistProcessor::createContentProposal() const
|
||||
IAssistProposal *GlslCompletionAssistProcessor::createContentProposal() const
|
||||
{
|
||||
IGenericProposalModel *model = new BasicProposalItemListModel(m_completions);
|
||||
IAssistProposal *proposal = new GenericProposal(m_startPosition, model);
|
||||
return proposal;
|
||||
}
|
||||
|
||||
IAssistProposal *GLSLCompletionAssistProcessor::createHintProposal(
|
||||
IAssistProposal *GlslCompletionAssistProcessor::createHintProposal(
|
||||
const QVector<GLSL::Function *> &symbols)
|
||||
{
|
||||
IFunctionHintProposalModel *model = new GLSLFunctionHintProposalModel(symbols);
|
||||
IFunctionHintProposalModel *model = new GlslFunctionHintProposalModel(symbols);
|
||||
IAssistProposal *proposal = new FunctionHintProposal(m_startPosition, model);
|
||||
return proposal;
|
||||
}
|
||||
|
||||
bool GLSLCompletionAssistProcessor::acceptsIdleEditor() const
|
||||
bool GlslCompletionAssistProcessor::acceptsIdleEditor() const
|
||||
{
|
||||
const int cursorPosition = m_interface->position();
|
||||
const QChar ch = m_interface->characterAt(cursorPosition - 1);
|
||||
@@ -449,7 +445,7 @@ bool GLSLCompletionAssistProcessor::acceptsIdleEditor() const
|
||||
return isActivationChar(ch);
|
||||
}
|
||||
|
||||
void GLSLCompletionAssistProcessor::addCompletion(const QString &text,
|
||||
void GlslCompletionAssistProcessor::addCompletion(const QString &text,
|
||||
const QIcon &icon,
|
||||
int order)
|
||||
{
|
||||
@@ -461,12 +457,12 @@ void GLSLCompletionAssistProcessor::addCompletion(const QString &text,
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// GLSLCompletionAssistInterface
|
||||
// GlslCompletionAssistInterface
|
||||
// -----------------------------
|
||||
GLSLCompletionAssistInterface::GLSLCompletionAssistInterface(QTextDocument *textDocument,
|
||||
GlslCompletionAssistInterface::GlslCompletionAssistInterface(QTextDocument *textDocument,
|
||||
int position,
|
||||
const QString &fileName,
|
||||
TextEditor::AssistReason reason,
|
||||
AssistReason reason,
|
||||
const QString &mimeType,
|
||||
const Document::Ptr &glslDoc)
|
||||
: DefaultAssistInterface(textDocument, position, fileName, reason)
|
||||
@@ -474,3 +470,6 @@ GLSLCompletionAssistInterface::GLSLCompletionAssistInterface(QTextDocument *text
|
||||
, m_glslDoc(glslDoc)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace GLSLEditor
|
||||
|
||||
@@ -49,9 +49,9 @@ namespace TextEditor { class BasicProposalItem; }
|
||||
namespace GLSLEditor {
|
||||
namespace Internal {
|
||||
|
||||
class GLSLCompletionAssistInterface;
|
||||
class GlslCompletionAssistInterface;
|
||||
|
||||
class GLSLCompletionAssistProvider : public TextEditor::CompletionAssistProvider
|
||||
class GlslCompletionAssistProvider : public TextEditor::CompletionAssistProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -63,11 +63,11 @@ public:
|
||||
bool isActivationCharSequence(const QString &sequence) const QTC_OVERRIDE;
|
||||
};
|
||||
|
||||
class GLSLCompletionAssistProcessor : public TextEditor::IAssistProcessor
|
||||
class GlslCompletionAssistProcessor : public TextEditor::IAssistProcessor
|
||||
{
|
||||
public:
|
||||
GLSLCompletionAssistProcessor();
|
||||
~GLSLCompletionAssistProcessor();
|
||||
GlslCompletionAssistProcessor();
|
||||
~GlslCompletionAssistProcessor();
|
||||
|
||||
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);
|
||||
|
||||
int m_startPosition;
|
||||
QScopedPointer<const GLSLCompletionAssistInterface> m_interface;
|
||||
QScopedPointer<const GlslCompletionAssistInterface> m_interface;
|
||||
QList<TextEditor::BasicProposalItem *> m_completions;
|
||||
|
||||
QIcon m_keywordIcon;
|
||||
@@ -92,10 +92,10 @@ private:
|
||||
QIcon m_otherIcon;
|
||||
};
|
||||
|
||||
class GLSLCompletionAssistInterface : public TextEditor::DefaultAssistInterface
|
||||
class GlslCompletionAssistInterface : public TextEditor::DefaultAssistInterface
|
||||
{
|
||||
public:
|
||||
GLSLCompletionAssistInterface(QTextDocument *textDocument,
|
||||
GlslCompletionAssistInterface(QTextDocument *textDocument,
|
||||
int position, const QString &fileName,
|
||||
TextEditor::AssistReason reason,
|
||||
const QString &mimeType,
|
||||
@@ -109,7 +109,7 @@ private:
|
||||
Document::Ptr m_glslDoc;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
} // GLSLEditor
|
||||
} // namespace Internal
|
||||
} // namespace GLSLEditor
|
||||
|
||||
#endif // GLSLCOMPLETIONASSIST_H
|
||||
|
||||
@@ -141,7 +141,7 @@ void Document::addRange(const QTextCursor &cursor, GLSL::Scope *scope)
|
||||
|
||||
GlslEditorWidget::GlslEditorWidget()
|
||||
{
|
||||
setAutoCompleter(new GLSLCompleter);
|
||||
setAutoCompleter(new GlslCompleter);
|
||||
m_outlineCombo = 0;
|
||||
setParenthesesMatchingEnabled(true);
|
||||
setMarksVisible(true);
|
||||
@@ -242,14 +242,14 @@ void GlslEditorWidget::updateDocumentNow()
|
||||
Semantic sem;
|
||||
Scope *globalScope = engine->newNamespace();
|
||||
doc->_globalScope = globalScope;
|
||||
const GLSLEditorPlugin::InitFile *file = GLSLEditorPlugin::shaderInit(variant);
|
||||
const GlslEditorPlugin::InitFile *file = GlslEditorPlugin::shaderInit(variant);
|
||||
sem.translationUnit(file->ast, globalScope, file->engine);
|
||||
if (variant & Lexer::Variant_VertexShader) {
|
||||
file = GLSLEditorPlugin::vertexShaderInit(variant);
|
||||
file = GlslEditorPlugin::vertexShaderInit(variant);
|
||||
sem.translationUnit(file->ast, globalScope, file->engine);
|
||||
}
|
||||
if (variant & Lexer::Variant_FragmentShader) {
|
||||
file = GLSLEditorPlugin::fragmentShaderInit(variant);
|
||||
file = GlslEditorPlugin::fragmentShaderInit(variant);
|
||||
sem.translationUnit(file->ast, globalScope, file->engine);
|
||||
}
|
||||
sem.translationUnit(ast, globalScope, engine);
|
||||
@@ -332,7 +332,7 @@ IAssistInterface *GlslEditorWidget::createAssistInterface(
|
||||
AssistKind kind, AssistReason reason) const
|
||||
{
|
||||
if (kind == Completion)
|
||||
return new GLSLCompletionAssistInterface(document(),
|
||||
return new GlslCompletionAssistInterface(document(),
|
||||
position(),
|
||||
editor()->document()->filePath(),
|
||||
reason,
|
||||
@@ -353,14 +353,14 @@ GlslEditor::GlslEditor()
|
||||
addContext(C_GLSLEDITOR_ID);
|
||||
setDuplicateSupported(true);
|
||||
setCommentStyle(Utils::CommentDefinition::CppStyle);
|
||||
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GLSLCompletionAssistProvider>());
|
||||
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GlslCompletionAssistProvider>());
|
||||
|
||||
setEditorCreator([]() { return new GlslEditor; });
|
||||
setWidgetCreator([]() { return new GlslEditorWidget; });
|
||||
|
||||
setDocumentCreator([]() -> BaseTextDocument * {
|
||||
auto doc = new BaseTextDocument(C_GLSLEDITOR_ID);
|
||||
doc->setIndenter(new GLSLIndenter);
|
||||
doc->setIndenter(new GlslIndenter);
|
||||
new Highlighter(doc);
|
||||
return doc;
|
||||
});
|
||||
|
||||
@@ -71,10 +71,10 @@ using namespace TextEditor;
|
||||
namespace GLSLEditor {
|
||||
namespace Internal {
|
||||
|
||||
class GLSLEditorPluginPrivate
|
||||
class GlslEditorPluginPrivate
|
||||
{
|
||||
public:
|
||||
GLSLEditorPluginPrivate() :
|
||||
GlslEditorPluginPrivate() :
|
||||
m_glsl_120_frag(0),
|
||||
m_glsl_120_vert(0),
|
||||
m_glsl_120_common(0),
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
m_glsl_es_100_common(0)
|
||||
{}
|
||||
|
||||
~GLSLEditorPluginPrivate()
|
||||
~GlslEditorPluginPrivate()
|
||||
{
|
||||
delete m_glsl_120_frag;
|
||||
delete m_glsl_120_vert;
|
||||
@@ -93,44 +93,44 @@ public:
|
||||
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_vert;
|
||||
GLSLEditorPlugin::InitFile *m_glsl_120_common;
|
||||
GLSLEditorPlugin::InitFile *m_glsl_es_100_frag;
|
||||
GLSLEditorPlugin::InitFile *m_glsl_es_100_vert;
|
||||
GLSLEditorPlugin::InitFile *m_glsl_es_100_common;
|
||||
GlslEditorPlugin::InitFile *m_glsl_120_frag;
|
||||
GlslEditorPlugin::InitFile *m_glsl_120_vert;
|
||||
GlslEditorPlugin::InitFile *m_glsl_120_common;
|
||||
GlslEditorPlugin::InitFile *m_glsl_es_100_frag;
|
||||
GlslEditorPlugin::InitFile *m_glsl_es_100_vert;
|
||||
GlslEditorPlugin::InitFile *m_glsl_es_100_common;
|
||||
};
|
||||
|
||||
static GLSLEditorPluginPrivate *dd = 0;
|
||||
static GLSLEditorPlugin *m_instance = 0;
|
||||
static GlslEditorPluginPrivate *dd = 0;
|
||||
static GlslEditorPlugin *m_instance = 0;
|
||||
|
||||
GLSLEditorPlugin::InitFile::~InitFile()
|
||||
GlslEditorPlugin::InitFile::~InitFile()
|
||||
{
|
||||
delete engine;
|
||||
}
|
||||
|
||||
GLSLEditorPlugin::GLSLEditorPlugin()
|
||||
GlslEditorPlugin::GlslEditorPlugin()
|
||||
{
|
||||
m_instance = this;
|
||||
dd = new GLSLEditorPluginPrivate;
|
||||
dd = new GlslEditorPluginPrivate;
|
||||
}
|
||||
|
||||
GLSLEditorPlugin::~GLSLEditorPlugin()
|
||||
GlslEditorPlugin::~GlslEditorPlugin()
|
||||
{
|
||||
delete dd;
|
||||
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))
|
||||
return false;
|
||||
|
||||
addAutoReleasedObject(new GLSLHoverHandler(this));
|
||||
addAutoReleasedObject(new GlslHoverHandler(this));
|
||||
addAutoReleasedObject(new GlslEditorFactory);
|
||||
addAutoReleasedObject(new GLSLCompletionAssistProvider);
|
||||
addAutoReleasedObject(new GlslCompletionAssistProvider);
|
||||
|
||||
ActionContainer *contextMenu = ActionManager::createMenu(GLSLEditor::Constants::M_CONTEXT);
|
||||
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_FRAG_ES);
|
||||
|
||||
IWizardFactory *wizard = new GLSLFileWizard(GLSLFileWizard::FragmentShaderES);
|
||||
IWizardFactory *wizard = new GlslFileWizard(GlslFileWizard::FragmentShaderES);
|
||||
wizard->setWizardKind(IWizardFactory::FileWizard);
|
||||
wizard->setCategory(QLatin1String(Constants::WIZARD_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"));
|
||||
addAutoReleasedObject(wizard);
|
||||
|
||||
wizard = new GLSLFileWizard(GLSLFileWizard::VertexShaderES);
|
||||
wizard = new GlslFileWizard(GlslFileWizard::VertexShaderES);
|
||||
wizard->setWizardKind(IWizardFactory::FileWizard);
|
||||
wizard->setCategory(QLatin1String(Constants::WIZARD_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"));
|
||||
addAutoReleasedObject(wizard);
|
||||
|
||||
wizard = new GLSLFileWizard(GLSLFileWizard::FragmentShaderDesktop);
|
||||
wizard = new GlslFileWizard(GlslFileWizard::FragmentShaderDesktop);
|
||||
wizard->setWizardKind(IWizardFactory::FileWizard);
|
||||
wizard->setCategory(QLatin1String(Constants::WIZARD_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"));
|
||||
addAutoReleasedObject(wizard);
|
||||
|
||||
wizard = new GLSLFileWizard(GLSLFileWizard::VertexShaderDesktop);
|
||||
wizard = new GlslFileWizard(GlslFileWizard::VertexShaderDesktop);
|
||||
wizard->setWizardKind(IWizardFactory::FileWizard);
|
||||
wizard->setCategory(QLatin1String(Constants::WIZARD_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"));
|
||||
addAutoReleasedObject(wizard);
|
||||
|
||||
auto hf = new TextEditor::HighlighterFactory;
|
||||
auto hf = new HighlighterFactory;
|
||||
hf->setProductType<Highlighter>();
|
||||
hf->setId(GLSLEditor::Constants::C_GLSLEDITOR_ID);
|
||||
hf->addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE);
|
||||
@@ -224,11 +224,11 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
|
||||
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
|
||||
return IPlugin::aboutToShutdown();
|
||||
@@ -242,7 +242,7 @@ static QByteArray glslFile(const QString &fileName)
|
||||
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.
|
||||
const int variant = GLSL::Lexer::Variant_All;
|
||||
@@ -253,16 +253,16 @@ static void parseGlslFile(const QString &fileName, GLSLEditorPlugin::InitFile *i
|
||||
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)
|
||||
return *initFile;
|
||||
*initFile = new GLSLEditorPlugin::InitFile;
|
||||
*initFile = new GlslEditorPlugin::InitFile;
|
||||
parseGlslFile(QLatin1String(fileName), *initFile);
|
||||
return *initFile;
|
||||
}
|
||||
|
||||
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::fragmentShaderInit(int variant)
|
||||
const GlslEditorPlugin::InitFile *GlslEditorPlugin::fragmentShaderInit(int variant)
|
||||
{
|
||||
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
||||
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);
|
||||
}
|
||||
|
||||
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::vertexShaderInit(int variant)
|
||||
const GlslEditorPlugin::InitFile *GlslEditorPlugin::vertexShaderInit(int variant)
|
||||
{
|
||||
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
||||
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);
|
||||
}
|
||||
|
||||
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::shaderInit(int variant)
|
||||
const GlslEditorPlugin::InitFile *GlslEditorPlugin::shaderInit(int variant)
|
||||
{
|
||||
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
||||
return getInitFile("glsl_120_common.glsl", &dd->m_glsl_120_common);
|
||||
|
||||
@@ -38,14 +38,14 @@ namespace Internal {
|
||||
|
||||
class GlslEditorWidget;
|
||||
|
||||
class GLSLEditorPlugin : public ExtensionSystem::IPlugin
|
||||
class GlslEditorPlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "GLSLEditor.json")
|
||||
|
||||
public:
|
||||
GLSLEditorPlugin();
|
||||
~GLSLEditorPlugin();
|
||||
GlslEditorPlugin();
|
||||
~GlslEditorPlugin();
|
||||
|
||||
// IPlugin
|
||||
bool initialize(const QStringList &arguments, QString *errorMessage = 0);
|
||||
|
||||
@@ -40,39 +40,41 @@
|
||||
#include <QWizard>
|
||||
#include <QPushButton>
|
||||
|
||||
using namespace GLSLEditor;
|
||||
using namespace Core;
|
||||
using namespace Utils;
|
||||
|
||||
GLSLFileWizard::GLSLFileWizard(ShaderType shaderType)
|
||||
namespace GLSLEditor {
|
||||
|
||||
GlslFileWizard::GlslFileWizard(ShaderType shaderType)
|
||||
: m_shaderType(shaderType)
|
||||
{
|
||||
setFlags(Core::IWizardFactory::PlatformIndependent);
|
||||
setFlags(IWizardFactory::PlatformIndependent);
|
||||
}
|
||||
|
||||
Core::GeneratedFiles GLSLFileWizard::generateFiles(const QWizard *w,
|
||||
QString * /*errorMessage*/) const
|
||||
GeneratedFiles GlslFileWizard::generateFiles(const QWizard *w, QString * /*errorMessage*/) const
|
||||
{
|
||||
const Core::BaseFileWizard *wizard = qobject_cast<const Core::BaseFileWizard *>(w);
|
||||
Utils::FileWizardPage *page = wizard->find<Utils::FileWizardPage>();
|
||||
QTC_ASSERT(page, return Core::GeneratedFiles());
|
||||
const BaseFileWizard *wizard = qobject_cast<const BaseFileWizard *>(w);
|
||||
const FileWizardPage *page = wizard->find<FileWizardPage>();
|
||||
QTC_ASSERT(page, return GeneratedFiles());
|
||||
|
||||
const QString path = page->path();
|
||||
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.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
|
||||
return Core::GeneratedFiles() << file;
|
||||
file.setAttributes(GeneratedFile::OpenEditorAttribute);
|
||||
return GeneratedFiles() << file;
|
||||
}
|
||||
|
||||
QString GLSLFileWizard::fileContents(const QString &, ShaderType shaderType) const
|
||||
QString GlslFileWizard::fileContents(const QString &, ShaderType shaderType) const
|
||||
{
|
||||
QString contents;
|
||||
QTextStream str(&contents);
|
||||
|
||||
switch (shaderType) {
|
||||
case GLSLFileWizard::VertexShaderES:
|
||||
case GlslFileWizard::VertexShaderES:
|
||||
str << QLatin1String("attribute highp vec4 qt_Vertex;\n")
|
||||
<< QLatin1String("attribute highp vec4 qt_MultiTexCoord0;\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("}\n");
|
||||
break;
|
||||
case GLSLFileWizard::FragmentShaderES:
|
||||
case GlslFileWizard::FragmentShaderES:
|
||||
str << QLatin1String("uniform sampler2D qt_Texture0;\n")
|
||||
<< QLatin1String("varying highp vec4 qt_TexCoord0;\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("}\n");
|
||||
break;
|
||||
case GLSLFileWizard::VertexShaderDesktop:
|
||||
case GlslFileWizard::VertexShaderDesktop:
|
||||
str << QLatin1String("attribute vec4 qt_Vertex;\n")
|
||||
<< QLatin1String("attribute vec4 qt_MultiTexCoord0;\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("}\n");
|
||||
break;
|
||||
case GLSLFileWizard::FragmentShaderDesktop:
|
||||
case GlslFileWizard::FragmentShaderDesktop:
|
||||
str << QLatin1String("uniform sampler2D qt_Texture0;\n")
|
||||
<< QLatin1String("varying vec4 qt_TexCoord0;\n")
|
||||
<< QLatin1String("\n")
|
||||
@@ -120,11 +122,11 @@ QString GLSLFileWizard::fileContents(const QString &, ShaderType shaderType) con
|
||||
return contents;
|
||||
}
|
||||
|
||||
Core::BaseFileWizard *GLSLFileWizard::create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const
|
||||
BaseFileWizard *GlslFileWizard::create(QWidget *parent, const WizardDialogParameters ¶meters) const
|
||||
{
|
||||
Core::BaseFileWizard *wizard = new Core::BaseFileWizard(parent);
|
||||
BaseFileWizard *wizard = new BaseFileWizard(parent);
|
||||
wizard->setWindowTitle(tr("New %1").arg(displayName()));
|
||||
Utils::FileWizardPage *page = new Utils::FileWizardPage;
|
||||
FileWizardPage *page = new FileWizardPage;
|
||||
page->setPath(parameters.defaultPath());
|
||||
wizard->addPage(page);
|
||||
|
||||
@@ -133,18 +135,20 @@ Core::BaseFileWizard *GLSLFileWizard::create(QWidget *parent, const Core::Wizard
|
||||
return wizard;
|
||||
}
|
||||
|
||||
QString GLSLFileWizard::preferredSuffix(ShaderType shaderType) const
|
||||
QString GlslFileWizard::preferredSuffix(ShaderType shaderType) const
|
||||
{
|
||||
switch (shaderType) {
|
||||
case GLSLFileWizard::VertexShaderES:
|
||||
case GlslFileWizard::VertexShaderES:
|
||||
return QLatin1String("vsh");
|
||||
case GLSLFileWizard::FragmentShaderES:
|
||||
case GlslFileWizard::FragmentShaderES:
|
||||
return QLatin1String("fsh");
|
||||
case GLSLFileWizard::VertexShaderDesktop:
|
||||
case GlslFileWizard::VertexShaderDesktop:
|
||||
return QLatin1String("vert");
|
||||
case GLSLFileWizard::FragmentShaderDesktop:
|
||||
case GlslFileWizard::FragmentShaderDesktop:
|
||||
return QLatin1String("frag");
|
||||
default:
|
||||
return QLatin1String("glsl");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace GlslEditor
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
namespace GLSLEditor {
|
||||
|
||||
class GLSLFileWizard: public Core::BaseFileWizardFactory
|
||||
class GlslFileWizard: public Core::BaseFileWizardFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
FragmentShaderDesktop
|
||||
};
|
||||
|
||||
explicit GLSLFileWizard(ShaderType shaderType);
|
||||
explicit GlslFileWizard(ShaderType shaderType);
|
||||
|
||||
private:
|
||||
QString fileContents(const QString &baseName, ShaderType shaderType) const;
|
||||
|
||||
@@ -38,24 +38,23 @@
|
||||
|
||||
#include <QTextCursor>
|
||||
|
||||
using namespace GLSLEditor;
|
||||
using namespace GLSLEditor::Internal;
|
||||
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 true;
|
||||
return false;
|
||||
return qobject_cast<GlslEditor *>(editor) != 0;
|
||||
}
|
||||
|
||||
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 (! 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()))
|
||||
setToolTip(Qt::escape(toolTip()));
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace GLSLEditor
|
||||
|
||||
@@ -41,12 +41,12 @@ namespace TextEditor { class BaseTextEditor; }
|
||||
namespace GLSLEditor {
|
||||
namespace Internal {
|
||||
|
||||
class GLSLHoverHandler : public TextEditor::BaseHoverHandler
|
||||
class GlslHoverHandler : public TextEditor::BaseHoverHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GLSLHoverHandler(QObject *parent = 0);
|
||||
virtual ~GLSLHoverHandler();
|
||||
GlslHoverHandler(QObject *parent = 0);
|
||||
virtual ~GlslHoverHandler();
|
||||
|
||||
private:
|
||||
virtual bool acceptEditor(Core::IEditor *editor);
|
||||
|
||||
@@ -39,27 +39,24 @@
|
||||
#include <QTextBlock>
|
||||
#include <QTextCursor>
|
||||
|
||||
using namespace GLSLEditor;
|
||||
using namespace Internal;
|
||||
namespace GLSLEditor {
|
||||
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('{') ||
|
||||
ch == QLatin1Char('}') ||
|
||||
ch == QLatin1Char(':') ||
|
||||
ch == QLatin1Char('#')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ch == QLatin1Char('{')
|
||||
|| ch == QLatin1Char('}')
|
||||
|| ch == QLatin1Char(':')
|
||||
|| ch == QLatin1Char('#');
|
||||
}
|
||||
|
||||
void GLSLIndenter::indentBlock(QTextDocument *doc,
|
||||
void GlslIndenter::indentBlock(QTextDocument *doc,
|
||||
const QTextBlock &block,
|
||||
const QChar &typedChar,
|
||||
const TextEditor::TabSettings &tabSettings)
|
||||
@@ -75,8 +72,8 @@ void GLSLIndenter::indentBlock(QTextDocument *doc,
|
||||
int padding;
|
||||
codeFormatter.indentFor(block, &indent, &padding);
|
||||
|
||||
// only reindent the current line when typing electric characters if the
|
||||
// indent is the same it would be if the line were empty
|
||||
// Only reindent the current line when typing electric characters if the
|
||||
// indent is the same it would be if the line were empty.
|
||||
if (isElectricCharacter(typedChar)) {
|
||||
int newlineIndent;
|
||||
int newlinePadding;
|
||||
@@ -88,7 +85,7 @@ void GLSLIndenter::indentBlock(QTextDocument *doc,
|
||||
tabSettings.indentLine(block, indent + padding, padding);
|
||||
}
|
||||
|
||||
void GLSLIndenter::indent(QTextDocument *doc,
|
||||
void GlslIndenter::indent(QTextDocument *doc,
|
||||
const QTextCursor &cursor,
|
||||
const QChar &typedChar,
|
||||
const TextEditor::TabSettings &tabSettings)
|
||||
@@ -117,3 +114,6 @@ void GLSLIndenter::indent(QTextDocument *doc,
|
||||
indentBlock(doc, cursor.block(), typedChar, tabSettings);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace GLSLEditor
|
||||
|
||||
@@ -35,11 +35,11 @@
|
||||
namespace GLSLEditor {
|
||||
namespace Internal {
|
||||
|
||||
class GLSLIndenter : public TextEditor::Indenter
|
||||
class GlslIndenter : public TextEditor::Indenter
|
||||
{
|
||||
public:
|
||||
GLSLIndenter();
|
||||
virtual ~GLSLIndenter();
|
||||
GlslIndenter();
|
||||
virtual ~GlslIndenter();
|
||||
|
||||
virtual bool isElectricCharacter(const QChar &ch) const;
|
||||
virtual void indentBlock(QTextDocument *doc,
|
||||
|
||||
Reference in New Issue
Block a user