From 97d32901efc2b6cbec3ab41f78fa409d2ce78804 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 14 Mar 2011 11:38:48 +0000 Subject: Some more changes to LineEdit lua methods to make medicine macro (db looked up suggestions to lineedit) work as expected. --- client/widgets/lineedit.cc | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'client/widgets/lineedit.cc') 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 #include +#include +#include + #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(); +} -- cgit v1.2.3