Commit ecf4baec authored by Rhys Weatherley's avatar Rhys Weatherley
Browse files

Better icons for the GLSL code completer

parent 9af44368
......@@ -76,7 +76,7 @@ Symbol *Scope::lookup(const QString &name) const
return 0;
}
QStringList Scope::members() const
QList<Symbol *> Scope::members() const
{
return QStringList();
return QList<Symbol *>();
}
......@@ -73,7 +73,7 @@ public:
Symbol *lookup(const QString &name) const;
virtual QStringList members() const;
virtual QList<Symbol *> members() const;
virtual void add(Symbol *symbol) = 0;
virtual Symbol *find(const QString &name) const = 0;
......
......@@ -54,9 +54,9 @@ Block::Block(Scope *enclosingScope)
{
}
QStringList Block::members() const
QList<Symbol *> Block::members() const
{
return _members.keys();
return _members.values();
}
void Block::add(Symbol *symbol)
......@@ -100,9 +100,9 @@ Namespace::~Namespace()
qDeleteAll(_overloadSets);
}
QStringList Namespace::members() const
QList<Symbol *> Namespace::members() const
{
return _members.keys();
return _members.values();
}
void Namespace::add(Symbol *symbol)
......@@ -116,6 +116,7 @@ void Namespace::add(Symbol *symbol)
} else if (Function *firstFunction = sym->asFunction()) {
OverloadSet *o = new OverloadSet(this);
_overloadSets.append(o);
o->setName(symbol->name());
o->addFunction(firstFunction);
o->addFunction(fun);
sym = o;
......
......@@ -70,7 +70,7 @@ class GLSL_EXPORT Block: public Scope
public:
Block(Scope *enclosingScope = 0);
virtual QStringList members() const;
virtual QList<Symbol *> members() const;
virtual void add(Symbol *symbol);
virtual Block *asBlock() { return this; }
......@@ -92,7 +92,7 @@ public:
virtual Namespace *asNamespace() { return this; }
virtual QStringList members() const;
virtual QList<Symbol *> members() const;
virtual const Type *type() const;
virtual Symbol *find(const QString &name) const;
......
......@@ -331,12 +331,12 @@ bool ArrayType::isLessThan(const Type *other) const
return elementType() < array->elementType();
}
QStringList Struct::members() const
QList<Symbol *> Struct::members() const
{
QStringList m;
QList<Symbol *> m;
foreach (Symbol *s, _members) {
if (! s->name().isEmpty())
m.append(s->name());
m.append(s);
}
return m;
}
......@@ -438,12 +438,12 @@ bool Function::isLessThan(const Type *other) const
return false;
}
QStringList Function::members() const
QList<Symbol *> Function::members() const
{
QStringList m;
QList<Symbol *> m;
foreach (Argument *arg, _arguments) {
if (! arg->name().isEmpty())
m.append(arg->name());
m.append(arg);
}
return m;
}
......
......@@ -131,7 +131,7 @@ public:
const Type *elementType() const { return indexElementType(); }
int dimension() const { return _dimension; }
QStringList members() const { return _members.keys(); }
QList<Symbol *> members() const { return _members.values(); }
virtual void add(Symbol *symbol);
virtual Symbol *find(const QString &name) const;
......@@ -193,7 +193,7 @@ public:
Struct(Scope *scope = 0)
: Scope(scope) {}
QStringList members() const;
QList<Symbol *> members() const;
virtual void add(Symbol *member);
virtual Symbol *find(const QString &name) const;
......@@ -238,7 +238,7 @@ public:
virtual Symbol *find(const QString &name) const;
virtual QStringList members() const;
virtual QList<Symbol *> members() const;
virtual void add(Symbol *symbol) {
if (! symbol)
return;
......
......@@ -95,37 +95,6 @@ static bool checkStartOfIdentifier(const QString &word)
return false;
}
// 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",
......@@ -519,9 +488,13 @@ CodeCompletion::CodeCompletion(QObject *parent)
: ICompletionCollector(parent),
m_editor(0),
m_startPosition(-1),
m_restartCompletion(false)
m_restartCompletion(false),
m_varIcon(":/glsleditor/images/var.png"),
m_functionIcon(":/glsleditor/images/func.png"),
m_typeIcon(":/glsleditor/images/type.png"),
m_otherIcon(":/glsleditor/images/other.png")
{
const QIcon keywordIcon = iconForColor(Qt::darkYellow);
const QIcon keywordIcon(QLatin1String(":/glsleditor/images/keyword.png"));
for (const char **it = glsl_keywords; *it; ++it) {
TextEditor::CompletionItem item(this);
item.text = QString::fromLatin1(*it);
......@@ -599,9 +572,7 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
CPlusPlus::ExpressionUnderCursor expressionUnderCursor;
GLSLTextEditor *edit = qobject_cast<GLSLTextEditor *>(editor->widget());
const QIcon symbolIcon = iconForColor(Qt::darkCyan);
QStringList members;
QList<GLSL::Symbol *> members;
QStringList specialMembers;
bool functionCall = (ch == QLatin1Char('(') && pos == editor->position() - 1);
......@@ -705,11 +676,18 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
m_completions += m_keywordCompletions;
}
foreach (const QString &s, members) {
foreach (GLSL::Symbol *s, members) {
TextEditor::CompletionItem item(this);
item.icon = symbolIcon;
item.text = s;
if (specialMembers.contains(s))
if (s->asVariable() || s->asArgument())
item.icon = m_varIcon;
else if (s->asFunction() || s->asOverloadSet())
item.icon = m_functionIcon;
else if (s->asStruct())
item.icon = m_typeIcon;
else
item.icon = m_otherIcon;
item.text = s->name();
if (specialMembers.contains(item.text))
item.order = SpecialMemberOrder;
m_completions.append(item);
}
......
......@@ -106,6 +106,11 @@ private:
QPointer<FunctionArgumentWidget> m_functionArgumentWidget;
static bool glslCompletionItemLessThan(const TextEditor::CompletionItem &l, const TextEditor::CompletionItem &r);
QIcon m_varIcon;
QIcon m_functionIcon;
QIcon m_typeIcon;
QIcon m_otherIcon;
};
} // namespace Internal
......
......@@ -2,5 +2,10 @@
<qresource prefix="/glsleditor">
<file>GLSLEditor.mimetypes.xml</file>
<file>images/glslfile.png</file>
<file>images/keyword.png</file>
<file>images/var.png</file>
<file>images/func.png</file>
<file>images/type.png</file>
<file>images/other.png</file>
</qresource>
</RCC>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment