diff options
Diffstat (limited to 'utils/themeeditor/gui/syntaxcompleter.cpp')
-rw-r--r-- | utils/themeeditor/gui/syntaxcompleter.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/utils/themeeditor/gui/syntaxcompleter.cpp b/utils/themeeditor/gui/syntaxcompleter.cpp new file mode 100644 index 0000000000..0b4f05f487 --- /dev/null +++ b/utils/themeeditor/gui/syntaxcompleter.cpp | |||
@@ -0,0 +1,83 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Robert Bieber | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <QFile> | ||
23 | #include <QTreeWidgetItem> | ||
24 | |||
25 | #include "syntaxcompleter.h" | ||
26 | |||
27 | SyntaxCompleter::SyntaxCompleter(QWidget *parent) : | ||
28 | QTreeWidget(parent) | ||
29 | { | ||
30 | setHeaderHidden(true); | ||
31 | |||
32 | setWordWrap(true); | ||
33 | setColumnCount(2); | ||
34 | |||
35 | QFile fin(":/resources/tagdb"); | ||
36 | fin.open(QFile::ReadOnly | QFile::Text); | ||
37 | |||
38 | while(!fin.atEnd()) | ||
39 | { | ||
40 | QString line(fin.readLine()); | ||
41 | if(line.trimmed().length() == 0 || line.trimmed()[0] == '#') | ||
42 | continue; | ||
43 | |||
44 | QStringList split = line.split(":"); | ||
45 | QStringList tag; | ||
46 | tag.append(split[0].trimmed()); | ||
47 | tag.append(split[1].trimmed()); | ||
48 | tags.insert(split[0].trimmed().toLower(), tag); | ||
49 | } | ||
50 | |||
51 | filter(""); | ||
52 | |||
53 | resizeColumnToContents(0); | ||
54 | setColumnWidth(0, columnWidth(0) + 10); // Auto-resize is too small | ||
55 | |||
56 | } | ||
57 | |||
58 | void SyntaxCompleter::filter(QString text) | ||
59 | { | ||
60 | clear(); | ||
61 | |||
62 | for(QMap<QString, QStringList>::iterator i = tags.begin() | ||
63 | ; i != tags.end(); i++) | ||
64 | { | ||
65 | if(text.length() == 1) | ||
66 | { | ||
67 | if(text[0].toLower() != i.key()[0]) | ||
68 | continue; | ||
69 | } | ||
70 | else if(text.length() == 2) | ||
71 | { | ||
72 | if(text[0].toLower() != i.key()[0] || i.key().length() < 2 | ||
73 | || text[1].toLower() != i.key()[1]) | ||
74 | continue; | ||
75 | } | ||
76 | else if(text.length() > 2) | ||
77 | { | ||
78 | hide(); | ||
79 | } | ||
80 | |||
81 | addTopLevelItem(new QTreeWidgetItem(i.value())); | ||
82 | } | ||
83 | } | ||