diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2015-09-21 16:51:39 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-09-23 14:15:22 -0700 |
commit | fdd28fddf2303d6cf2c51383c87195af3774a91c (patch) | |
tree | 2306e1b62e6886fbba23e9b5f25bfdea6ab1beab /qt-ui/locationinformation.cpp | |
parent | c4c7e7a7f4d462490e8f0fea846f13bff6076845 (diff) | |
download | subsurface-fdd28fddf2303d6cf2c51383c87195af3774a91c.tar.gz |
Start to handle keypresses
Keypress management is one of the main functions of the completer, so we
must create an event filter and hook things up properly.
key esq / enter should close the popup (and not leave us with a popup open
and no way to close it - it breaks X)
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/locationinformation.cpp')
-rw-r--r-- | qt-ui/locationinformation.cpp | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 27cbc61a3..468212c44 100644 --- a/qt-ui/locationinformation.cpp +++ b/qt-ui/locationinformation.cpp @@ -419,12 +419,41 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) proxy->setSourceModel(model); proxy->setFilterKeyColumn(DiveLocationModel::NAME); + view->setModel(proxy); view->setModelColumn(DiveLocationModel::NAME); view->setItemDelegate(new LocationFilterDelegate()); + view->setEditTriggers(QAbstractItemView::NoEditTriggers); + view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + view->setSelectionBehavior(QAbstractItemView::SelectRows); + view->setSelectionMode(QAbstractItemView::SingleSelection); + view->setParent(0, Qt::Popup); + view->installEventFilter(this); + view->setFocusProxy(this); + connect(this, &QLineEdit::textEdited, this, &DiveLocationLineEdit::setTemporaryDiveSiteName); } +bool DiveLocationLineEdit::eventFilter(QObject *o, QEvent *e) +{ + if(e->type() == QEvent::KeyPress) { + QKeyEvent *keyEv = (QKeyEvent*) e; + + qDebug() << view->focusProxy()->objectName(); + + if (keyEv->key() == Qt::Key_Escape) { + view->hide(); + return true; + } + + if(keyEv->key() == Qt::Key_Return) { + view->hide(); + return false; + } + } + return false; +} + void DiveLocationLineEdit::refreshDiveSiteCache() { model->resetModel(); @@ -462,12 +491,17 @@ void DiveLocationLineEdit::setTemporaryDiveSiteName(const QString& s) void DiveLocationLineEdit::keyPressEvent(QKeyEvent *ev) { - QLineEdit::keyPressEvent(ev); - if(ev->key() != Qt::Key_Left && ev->key() != Qt::Key_Right && !view->isVisible()) { - qDebug() << "Showing popup"; + qDebug() << "Pressing key" << ev->key(); + if(ev->key() != Qt::Key_Left && + ev->key() != Qt::Key_Right && + ev->key() != Qt::Key_Escape && + ev->key() != Qt::Key_Return && + !view->isVisible()) { showPopup(); + } else if (ev->key() == Qt::Key_Escape) { + view->hide(); } else { - qDebug() << "Not showing popup"; + QLineEdit::keyPressEvent(ev); } } @@ -505,8 +539,10 @@ void DiveLocationLineEdit::showPopup() view->setGeometry(pos.x(), pos.y(), w, h); - if (!view->isVisible()) + if (!view->isVisible()) { view->show(); + view->setFocus(); + } } DiveLocationListView::DiveLocationListView(QWidget *parent) |