NetworkAccess* http();
}
-GSuggestCompletion::GSuggestCompletion(QLineEdit *parent): QObject(parent), editor(parent) {
+GSuggestCompletion::GSuggestCompletion(QWidget *parent, QLineEdit *editor):
+ QObject(parent), buddy(parent), editor(editor) {
+
+ enabled = true;
popup = new QListWidget;
popup->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
connect(popup, SIGNAL(itemClicked(QListWidgetItem*)),
SLOT(doneCompletion()));
- connect(popup, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
- SLOT(currentItemChanged(QListWidgetItem *)));
+ // connect(popup, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
+ // SLOT(currentItemChanged(QListWidgetItem *)));
// mouse hover
- connect(popup, SIGNAL(itemEntered(QListWidgetItem*)),
- SLOT(currentItemChanged(QListWidgetItem *)));
+ // connect(popup, SIGNAL(itemEntered(QListWidgetItem*)),
+ // SLOT(currentItemChanged(QListWidgetItem *)));
popup->setWindowFlags(Qt::Popup);
popup->setFocusPolicy(Qt::NoFocus);
timer = new QTimer(this);
timer->setSingleShot(true);
- timer->setInterval(100);
+ timer->setInterval(300);
connect(timer, SIGNAL(timeout()), SLOT(autoSuggest()));
connect(editor, SIGNAL(textEdited(QString)), timer, SLOT(start()));
popup->setUpdatesEnabled(true);
int h = popup->sizeHintForRow(0) * choices.count() + 4;
- popup->resize(popup->width(), h);
+ popup->resize(buddy->width(), h);
+
+ popup->move(buddy->mapToGlobal(QPoint(0, buddy->height())));
- popup->move(editor->mapToGlobal(QPoint(0, editor->height()+4)));
popup->setFocus();
popup->show();
}
void GSuggestCompletion::preventSuggest() {
timer->stop();
+ enabled = false;
+ popup->hide();
+}
+
+void GSuggestCompletion::enableSuggest() {
+ enabled = true;
}
void GSuggestCompletion::autoSuggest() {
+ if (!enabled) return;
+
QString query = editor->text();
originalText = query;
qDebug() << "originalText" << originalText;
}
void GSuggestCompletion::handleNetworkData(QByteArray response) {
+ if (!enabled) return;
QStringList choices;