summaryrefslogtreecommitdiff
path: root/client/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'client/widgets')
-rw-r--r--client/widgets/lineedit.cc40
-rw-r--r--client/widgets/lineedit.h8
2 files changed, 48 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();
+}
diff --git a/client/widgets/lineedit.h b/client/widgets/lineedit.h
index 90fac75..8159aad 100644
--- a/client/widgets/lineedit.h
+++ b/client/widgets/lineedit.h
@@ -27,6 +27,8 @@
#ifndef __PRACRO_LINEEDIT_H__
#define __PRACRO_LINEEDIT_H__
+#include <QStringList>
+
#include "widget.h"
class QLineEdit;
@@ -43,6 +45,11 @@ public:
void setWdgValid(bool valid);
+ void clearSuggestions();
+ void addSuggestion(QString suggestion);
+ bool isSuggested(QString value);
+ void showSuggestions();
+
public slots:
void changed();
void user_changed();
@@ -54,6 +61,7 @@ private:
bool eventFilter(QObject *, QEvent *event);
QLineEdit *lineedit;
+ QStringList suggestions;
};
#endif/*__PRACRO_LINEEDIT_H__*/