13#include <boost/algorithm/string.hpp>
18 : QLineEdit(parent), m_hints(
std::move(hints)), m_dontComplete(false) {
26 m_hintLabel->setForegroundRole(QPalette::ToolTipText);
27 m_hintLabel->setBackgroundRole(QPalette::ToolTipBase);
30 connect(
this, SIGNAL(textEdited(
const QString &)),
this, SLOT(
updateHints(
const QString &)));
31 connect(
this, SIGNAL(editingFinished()),
this, SLOT(
hideHints()));
41 m_dontComplete = (e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete || e->key() == Qt::Key_Space);
43 if (e->key() == Qt::Key_Up) {
48 if (e->key() == Qt::Key_Down) {
52 QLineEdit::keyPressEvent(e);
61 const size_t curPos = (size_t)cursorPosition();
62 const std::string line = text.toStdString();
65 std::string prefix = line.substr(0, curPos);
68 std::size_t startPos = prefix.find_last_of(
",");
69 if (startPos != std::string::npos)
70 prefix = prefix.substr(startPos + 1, prefix.size() - (startPos + 1));
95 auto &hintWord = hint.word();
96 return hintWord.length() >= m_currentPrefix.length() &&
97 hintWord.substr(0, m_currentPrefix.length()) == m_currentPrefix;
106 hintList +=
"<b>" + QString::fromStdString(match.word()) +
"</b><br />\n";
107 if (!match.description().empty())
108 hintList += QString::fromStdString(match.description()) +
"<br />\n";
111 if (!hintList.trimmed().isEmpty()) {
127 QString line = text();
128 const int curPos = cursorPosition();
131 if (curPos + 1 < line.size() && line[curPos + 1].isLetterOrNumber())
135 line = line.left(curPos) + QString::fromStdString((*m_match).word()).mid(
static_cast<int>(
m_currentPrefix.size())) +
139 setSelection(curPos,
static_cast<int>((*m_match).word().size()));
144 if (!hasSelectedText())
148 QString line = text();
149 line = line.left(selectionStart()) + line.mid(selectionStart() + selectedText().length());