void
line_edit_autocomplete::show_completions()
{
  if (!m_completer_enabled)
    return;

  QString prefix; // substring on which the completion is to be based

  int pos = cursorPosition();
  int start = get_prefix_pos(text(), pos);
  if (start>=0) {
    prefix=text().mid(start, pos-start);
  }

  if (prefix.isEmpty()) {
    // nothing to complete
    if (popup->isVisible()) {
      popup->clear();
      popup->hide();
    }
  }
  else {
    QList<QString> completions = get_completions(prefix);
    redisplay_popup(completions);
  }
}
void
line_edit_autocomplete::completion_chosen(QListWidgetItem* item)
{
  if (!item) return;
  QString text= this->text();
  int pos = get_prefix_pos(text, this->cursorPosition());
  QString before = text.mid(0, pos);
  QString after = text.mid(this->cursorPosition());
  this->setText(before + item->text() + after);
}
示例#3
0
void
email_completer::completion_chosen(QListWidgetItem* item)
{
  if (!item) return;
  QString text= lineedit->text();
  int pos = get_prefix_pos(text, lineedit->cursorPosition());
  QString before = text.mid(0, pos);
  QString after = text.mid(lineedit->cursorPosition());
  lineedit->setText(before + item->text() + after);
}