From 081166fab0d2dc4a6dc8d4c466cf218a780f1339 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 19 Nov 2010 15:15:12 +0100 Subject: [PATCH] Add the identifiers to the completion box. Well, this is just a temporary hack :) --- src/plugins/glsleditor/glslcodecompletion.cpp | 45 +++++++++++++++++++++++++++ src/plugins/glsleditor/glsleditor.cpp | 8 +++++ src/plugins/glsleditor/glsleditor.h | 4 +++ 3 files changed, 57 insertions(+) diff --git a/src/plugins/glsleditor/glslcodecompletion.cpp b/src/plugins/glsleditor/glslcodecompletion.cpp index 359e483520..79e7b1548d 100644 --- a/src/plugins/glsleditor/glslcodecompletion.cpp +++ b/src/plugins/glsleditor/glslcodecompletion.cpp @@ -28,10 +28,43 @@ **************************************************************************/ #include "glslcodecompletion.h" #include "glsleditor.h" +#include +#include #include using namespace GLSLEditor; +// Temporary workaround until we have proper icons for QML completion items +static QIcon iconForColor(const QColor &color) +{ + QPixmap pix(6, 6); + + int pixSize = 20; + QBrush br(color); + + QPixmap pm(2 * pixSize, 2 * pixSize); + QPainter pmp(&pm); + pmp.fillRect(0, 0, pixSize, pixSize, Qt::lightGray); + pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::lightGray); + pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::darkGray); + pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::darkGray); + pmp.fillRect(0, 0, 2 * pixSize, 2 * pixSize, color); + br = QBrush(pm); + + QPainter p(&pix); + int corr = 1; + QRect r = pix.rect().adjusted(corr, corr, -corr, -corr); + p.setBrushOrigin((r.width() % pixSize + pixSize) / 2 + corr, (r.height() % pixSize + pixSize) / 2 + corr); + p.fillRect(r, br); + + p.fillRect(r.width() / 4 + corr, r.height() / 4 + corr, + r.width() / 2, r.height() / 2, + QColor(color.rgb())); + p.drawRect(pix.rect().adjusted(0, 0, -1, -1)); + + return pix; +} + static const char *glsl_keywords[] = { // ### TODO: get the keywords from the lexer "attribute", @@ -163,9 +196,11 @@ CodeCompletion::CodeCompletion(QObject *parent) m_startPosition(-1), m_restartCompletion(false) { + const QIcon keywordIcon = iconForColor(Qt::darkYellow); for (const char **it = glsl_keywords; *it; ++it) { TextEditor::CompletionItem item(this); item.text = QString::fromLatin1(*it); + item.icon = keywordIcon; m_keywordCompletions.append(item); } } @@ -207,8 +242,18 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor) while (ch.isLetterOrNumber()) ch = editor->characterAt(--pos); + const QIcon symbolIcon = iconForColor(Qt::darkCyan); m_completions += m_keywordCompletions; + if (GLSLTextEditor *ed = qobject_cast(m_editor->widget())) { + foreach (const QString &id, ed->identifiers()) { + TextEditor::CompletionItem item(this); + item.text = id; + item.icon = symbolIcon; + m_completions.append(item); + } + } + m_startPosition = pos + 1; return m_startPosition; } diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp index 69e4933c05..586894d99c 100644 --- a/src/plugins/glsleditor/glsleditor.cpp +++ b/src/plugins/glsleditor/glsleditor.cpp @@ -124,6 +124,11 @@ bool GLSLTextEditor::isOutdated() const return false; } +QSet GLSLTextEditor::identifiers() const +{ + return m_identifiers; +} + Core::IEditor *GLSLEditorEditable::duplicate(QWidget *parent) { GLSLTextEditor *newEditor = new GLSLTextEditor(parent); @@ -285,4 +290,7 @@ void GLSLTextEditor::updateDocumentNow() // ### process the ast (void) ast; + + // refresh the identifiers. + m_identifiers = engine.identifiers(); } diff --git a/src/plugins/glsleditor/glsleditor.h b/src/plugins/glsleditor/glsleditor.h index 67da79a168..f1847802ee 100644 --- a/src/plugins/glsleditor/glsleditor.h +++ b/src/plugins/glsleditor/glsleditor.h @@ -37,6 +37,7 @@ #include #include +#include QT_BEGIN_NAMESPACE class QComboBox; @@ -62,6 +63,8 @@ public: int editorRevision() const; bool isOutdated() const; + QSet identifiers() const; + public slots: virtual void setFontSettings(const TextEditor::FontSettings &); @@ -82,6 +85,7 @@ private: QTimer *m_updateDocumentTimer; QComboBox *m_outlineCombo; + QSet m_identifiers; }; } // namespace GLSLEditor -- 2.11.0