summaryrefslogtreecommitdiff
path: root/client/widgets/lineedit.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/widgets/lineedit.cc')
-rw-r--r--client/widgets/lineedit.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/client/widgets/lineedit.cc b/client/widgets/lineedit.cc
index 97fb92b..d6aa619 100644
--- a/client/widgets/lineedit.cc
+++ b/client/widgets/lineedit.cc
@@ -32,6 +32,9 @@
#include <QEvent>
#include <QKeyEvent>
+#include <QCompleter>
+#include <QStringListModel>
+
#include "common.h"
#include "debug.h"
@@ -62,6 +65,13 @@ LineEdit::LineEdit(QDomNode &node, MacroWindow *macrowindow)
connect(lineedit, SIGNAL(textEdited(QString)), this, SLOT(user_changed()));
lineedit->installEventFilter(this); // Detect keyboard input.
+
+ QCompleter *comp = new QCompleter();
+ comp->setCaseSensitivity(Qt::CaseInsensitive);
+ QStringListModel *mdl = new QStringListModel();
+ comp->setModel(mdl);
+ // comp->popup()->setWindowOpacity(0.3);
+ lineedit->setCompleter(comp);
}
LineEdit::~LineEdit()
@@ -71,6 +81,7 @@ LineEdit::~LineEdit()
void LineEdit::changed()
{
+ // if(lineedit->completer()->popup()->isVisible()) return;
emit eventOnChange();
}
@@ -133,3 +144,32 @@ void LineEdit::setWdgValid(bool valid)
lineedit->setPalette(palette);
}
+
+void LineEdit::clearSuggestions()
+{
+ QCompleter *comp = lineedit->completer();
+ QStringListModel *mdl = (QStringListModel *)comp->model();
+ suggestions.clear();
+ mdl->setStringList(suggestions);
+}
+
+void LineEdit::addSuggestion(QString suggestion)
+{
+ suggestions << suggestion;
+ suggestions.sort();
+
+ QCompleter *comp = lineedit->completer();
+ QStringListModel *mdl = (QStringListModel *)comp->model();
+ mdl->setStringList(suggestions);
+}
+
+bool LineEdit::isSuggested(QString val)
+{
+ return suggestions.contains(val);
+}
+
+void LineEdit::showSuggestions()
+{
+ QCompleter *comp = lineedit->completer();
+ comp->complete();
+}