popup->installEventFilter(this);
popup->setWindowFlags(Qt::Popup);
popup->setFocusPolicy(Qt::NoFocus);
- popup->setFocusProxy(parent);
+ popup->setFocusProxy(buddy);
connect(popup, SIGNAL(itemClicked(QListWidgetItem*)), SLOT(doneCompletion()));
timer->setSingleShot(true);
timer->setInterval(600);
connect(timer, SIGNAL(timeout()), SLOT(autoSuggest()));
-#ifdef APP_MAC
- connect(parent, SIGNAL(textChanged(QString)), timer, SLOT(start()));
-#else
- connect(editor, SIGNAL(textEdited(QString)), timer, SLOT(start()));
-#endif
+ connect(buddy, SIGNAL(textChanged(QString)), timer, SLOT(start()));
}
if (obj != popup)
return false;
+ if (ev->type() == QEvent::FocusOut) {
+ popup->hide();
+ buddy->setFocus();
+ return true;
+ }
+
if (ev->type() == QEvent::MouseButtonPress) {
popup->hide();
- editor->setFocus();
+ buddy->setFocus();
editor->setText(originalText);
return true;
}
doneCompletion();
consumed = true;
} else {
- editor->setFocus();
+ buddy->setFocus();
editor->event(ev);
popup->hide();
}
break;
case Qt::Key_Escape:
- editor->setFocus();
+ buddy->setFocus();
editor->setText(originalText);
popup->hide();
consumed = true;
default:
// qDebug() << keyEvent->text();
- editor->setFocus();
+ buddy->setFocus();
editor->event(ev);
popup->hide();
break;
popup->move(buddy->mapToGlobal(QPoint(0, buddy->height())));
- // popup->setFocus();
+ popup->setFocus();
popup->show();
}
void AutoComplete::doneCompletion() {
timer->stop();
popup->hide();
- editor->setFocus();
+ buddy->setFocus();
QListWidgetItem *item = popup->currentItem();
if (item) {
editor->setText(item->text());
void AutoComplete::autoSuggest() {
if (!enabled) return;
+ if (!buddy->hasFocus()) return;
QString query = editor->text();
originalText = query;
// qDebug() << "originalText" << originalText;
if (query.isEmpty()) {
popup->hide();
+ buddy->setFocus();
return;
}