summaryrefslogtreecommitdiff
path: root/client/widgets/lineedit.cc
diff options
context:
space:
mode:
authordeva <deva>2011-03-14 11:38:48 +0000
committerdeva <deva>2011-03-14 11:38:48 +0000
commit97d32901efc2b6cbec3ab41f78fa409d2ce78804 (patch)
tree9cfae8667285d7a271ad928514b203f299abb2ae /client/widgets/lineedit.cc
parent1ad461c0bb7d687fb604d40456a0aea336c9e6bd (diff)
Some more changes to LineEdit lua methods to make medicine macro (db looked up suggestions to lineedit) work as expected.
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();
+}