From 01e9c372b16ebd903b6e1e0367237ec156d3813b Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Sun, 12 Sep 2010 20:30:29 +0200 Subject: - Modifiers are now correctly handled after Esc - Keep the focus when enter is pressed if the urlbar is empty --- src/urlbar/urlbar.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index c8aa43ff..c2b84d21 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -89,9 +89,6 @@ UrlBar::UrlBar(QWidget *parent) // doesn't show the clear button setClearButtonShown(false); - // trap Key_Enter & Key_Return events, while emitting the returnPressed signal - setTrapReturnKey(true); - // insert decoded URLs setUrlDropsEnabled(true); @@ -116,9 +113,6 @@ UrlBar::UrlBar(QWidget *parent) // bookmark icon connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(const QString &, const QString &)), this, SLOT(onBookmarksChanged())); - // load typed urls - connect(this, SIGNAL(returnPressed(const QString &)), this, SLOT(loadTyped(const QString &))); - _suggestionTimer->setSingleShot(true); connect(_suggestionTimer, SIGNAL(timeout()), this, SLOT(suggest())); @@ -241,7 +235,8 @@ void UrlBar::keyPressEvent(QKeyEvent *event) // this handles the Modifiers + Return key combinations QString currentText = text().trimmed(); if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) - && !currentText.startsWith(QL1S("http://"), Qt::CaseInsensitive)) + && !currentText.startsWith(QL1S("http://"), Qt::CaseInsensitive) + && event->modifiers() != Qt::NoModifier) { QString append; if (event->modifiers() == Qt::ControlModifier) @@ -257,19 +252,28 @@ void UrlBar::keyPressEvent(QKeyEvent *event) append = QL1S(".net"); } - QUrl url(QL1S("http://www.") + currentText); - QString host = url.host(); - if (!host.endsWith(append, Qt::CaseInsensitive)) + if (!append.isEmpty()) { - host += append; - url.setHost(host); + QUrl url(QL1S("http://www.") + currentText); + QString host = url.host(); + if (!host.endsWith(append, Qt::CaseInsensitive)) + { + host += append; + url.setHost(host); + } + + // now, load it! + activated(url); } + } - // now, load it! - activated(url); + else if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) + && !currentText.isEmpty()) + { + loadTyped(currentText); } - if (event->key() == Qt::Key_Escape) + else if (event->key() == Qt::Key_Escape) { clearFocus(); event->accept(); -- cgit v1.2.1