aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-06-10 16:07:02 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-06-10 16:07:02 +0200
commit6dd716bba6d7ed41463473ead9f3b50246ab657a (patch)
treee0c6d838bc72e72a9960b371235603d3ec3e3bce /lib
parentProfileEditor: apply http settings when they're changed (diff)
downloadsmolbote-6dd716bba6d7ed41463473ead9f3b50246ab657a.tar.xz
Completer: double clicking on an item activates it
- Completer now has NoEditTriggers set
Diffstat (limited to 'lib')
-rw-r--r--lib/addressbar/completer.cpp14
-rw-r--r--lib/addressbar/completer.h3
-rw-r--r--lib/addressbar/urllineedit.cpp16
3 files changed, 20 insertions, 13 deletions
diff --git a/lib/addressbar/completer.cpp b/lib/addressbar/completer.cpp
index 6c04775..1c1c728 100644
--- a/lib/addressbar/completer.cpp
+++ b/lib/addressbar/completer.cpp
@@ -14,6 +14,12 @@ Completer::Completer(QWidget *parent)
{
setObjectName("Completer");
setWindowFlags(Qt::ToolTip);
+ setEditTriggers(QAbstractItemView::NoEditTriggers);
+
+ connect(this, &Completer::activated, [=](const QModelIndex &index) {
+ hide();
+ emit completionActivated(index.data().toString());
+ });
}
bool Completer::updateItems(const QStringList &list)
@@ -61,8 +67,14 @@ bool Completer::keyPressed(QKeyEvent *event)
hide();
break;
- default:
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
+ hide();
+ emit completionActivated(currentIndex.data().toString());
break;
+
+ default:
+ return false;
}
return true;
diff --git a/lib/addressbar/completer.h b/lib/addressbar/completer.h
index 03ff317..2d3b21d 100644
--- a/lib/addressbar/completer.h
+++ b/lib/addressbar/completer.h
@@ -25,6 +25,9 @@ public:
bool keyPressed(QKeyEvent *event);
+signals:
+ void completionActivated(const QString &url);
+
private:
QStringListModel *completionModel = nullptr;
};
diff --git a/lib/addressbar/urllineedit.cpp b/lib/addressbar/urllineedit.cpp
index 21f88eb..33bc9dc 100644
--- a/lib/addressbar/urllineedit.cpp
+++ b/lib/addressbar/urllineedit.cpp
@@ -22,6 +22,8 @@ UrlLineEdit::UrlLineEdit(QWidget *parent)
setPlaceholderText(tr("Enter address"));
m_listView->setVisible(false);
+ connect(m_listView, &Completer::completionActivated, this, &UrlLineEdit::setText);
+
auto *addressbar = qobject_cast<AddressBar *>(parent);
Q_CHECK_PTR(addressbar);
@@ -120,18 +122,8 @@ void UrlLineEdit::focusOutEvent(QFocusEvent *event)
void UrlLineEdit::keyPressEvent(QKeyEvent *event)
{
if(m_listView->keyPressed(event)) {
- int key = event->key();
- QModelIndex currentIndex = m_listView->currentIndex();
-
- if(key == Qt::Key::Key_Enter || key == Qt::Key_Return) {
-
- if(currentIndex.isValid()) {
- setText(currentIndex.data().toString());
- }
- m_listView->hide();
- event->accept();
- return;
- }
+ event->accept();
+ return;
} else if(event->key() == Qt::Key::Key_Escape) {
clearFocus();
event->accept();