1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Robert Bieber
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #include <QTreeWidgetItem>
25 #include "syntaxcompleter.h"
26 #include "codeeditor.h"
28 SyntaxCompleter::SyntaxCompleter(CodeEditor
*parent
) :
31 setHeaderHidden(true);
32 setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded
);
37 QObject::connect(this, SIGNAL(activated(QModelIndex
)),
38 parent
, SLOT(insertTag()));
40 QFile
fin(":/resources/tagdb");
41 fin
.open(QFile::ReadOnly
| QFile::Text
);
45 QString
line(fin
.readLine());
46 if(line
.trimmed().length() == 0 || line
.trimmed()[0] == '#')
49 QStringList split
= line
.split(":");
51 tag
.append(split
[0].trimmed());
52 tag
.append(split
[1].trimmed());
53 tags
.insertMulti(split
[0].trimmed().toLower(), tag
);
60 void SyntaxCompleter::filter(QString text
)
64 for(QMap
<QString
, QStringList
>::iterator i
= tags
.begin()
65 ; i
!= tags
.end(); i
++)
67 if(text
.length() == 1)
69 if(text
[0].toLower() != i
.key()[0].toLower())
72 else if(text
.length() == 2)
74 if(text
[0].toLower() != i
.key()[0].toLower() || i
.key().length() < 2
75 || text
[1].toLower() != i
.key()[1].toLower())
78 else if(text
.length() > 2)
83 addTopLevelItem(new QTreeWidgetItem(i
.value()));
86 if(topLevelItemCount() > 0)
87 setCurrentIndex(indexFromItem(topLevelItem(0)));
89 resizeColumnToContents(0);
90 setColumnWidth(0, columnWidth(0) + 10); // Auto-resize is too small
91 resizeColumnToContents(1);