2 * This file is part of NixNote/NeighborNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\r
8 * Software distributed under the License is distributed
\r
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
10 * express or implied. See the GPL for the specific language
\r
11 * governing rights and limitations.
\r
13 * You should have received a copy of the GPL along with this
\r
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
15 * or write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
19 package cx.fbn.nevernote.gui;
\r
21 import java.util.ArrayList;
\r
22 import java.util.List;
\r
24 import com.evernote.edam.type.Tag;
\r
25 import com.trolltech.qt.core.Qt.CaseSensitivity;
\r
26 import com.trolltech.qt.gui.QCompleter;
\r
27 import com.trolltech.qt.gui.QStringListModel;
\r
29 public class TagLineCompleter extends QCompleter {
\r
30 private List<Tag> tags;
\r
31 private List<String> currentTags;
\r
32 private QStringListModel model;
\r
33 private final TagLineEdit editor;
\r
34 private String currentText;
\r
36 public TagLineCompleter(TagLineEdit e) {
\r
39 // editor.setCompleter(this);
\r
40 currentTags = new ArrayList<String>();
\r
41 setTagList(new ArrayList<Tag>());
\r
42 setCaseSensitivity(CaseSensitivity.CaseInsensitive);
\r
45 public List<String> getTagList(){
\r
49 public void update(List<String> t, String prefix) {
\r
54 setCompletionPrefix(prefix);
\r
55 if (!prefix.trim().equals(""))
\r
59 public List<Tag> getTags() {
\r
63 private List<String> buildModelList() {
\r
65 model = (QStringListModel) model();
\r
66 if (model == null) {
\r
67 model = new QStringListModel();
\r
70 for (int i=0; i<model.rowCount(); i++)
\r
73 List<String> newTagList = new ArrayList<String>();
\r
75 for (int i=0; i<tags.size(); i++) {
\r
76 boolean found=false;
\r
77 for (int j=0; j<currentTags.size() && !found; j++) {
\r
78 if (currentTags.get(j).trim().equalsIgnoreCase(tags.get(i).getName())) {
\r
83 newTagList.add(tags.get(i).getName());
\r
86 model.setStringList(newTagList);
\r
90 public void setTagList(List<Tag> t) {
\r
94 // model = new QStringListModel(buildModelList(), this);
\r
98 public void resetList() {
\r
99 currentTags.clear();
\r
103 public String currentText() {
\r
104 return currentText;
\r
107 public void reset() {
\r