-
Notifications
You must be signed in to change notification settings - Fork 2
/
completinglineedit.cpp
47 lines (40 loc) · 1.22 KB
/
completinglineedit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (C) 2016 Orgad Shaneh <[email protected]>.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "completinglineedit.h"
#include <QAbstractItemView>
#include <QCompleter>
#include <QEvent>
#include <QKeyEvent>
namespace GUI {
CompletingLineEdit::CompletingLineEdit(QWidget *parent)
: QLineEdit(parent)
{}
auto CompletingLineEdit::event(QEvent *e) -> bool
{
// workaround for QTCREATORBUG-9453
if (e->type() == QEvent::ShortcutOverride) {
if (QCompleter *comp = completer()) {
if (comp->popup() && comp->popup()->isVisible()) {
auto *ke = static_cast<QKeyEvent *>(e);
if (ke->key() == Qt::Key_Escape && !ke->modifiers()) {
ke->accept();
return true;
}
}
}
}
return QLineEdit::event(e);
}
void CompletingLineEdit::keyPressEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_Down && !e->modifiers()) {
if (QCompleter *comp = completer()) {
if (!comp->popup()->isVisible()) {
comp->complete();
return;
}
}
}
QLineEdit::keyPressEvent(e);
}
} // namespace GUI