diff --git a/src/lib/navigation/locationbar.cpp b/src/lib/navigation/locationbar.cpp index 495b4bf56..2d8565340 100644 --- a/src/lib/navigation/locationbar.cpp +++ b/src/lib/navigation/locationbar.cpp @@ -149,6 +149,17 @@ QUrl LocationBar::createUrl() return urlToLoad; } +QString LocationBar::convertUrlToText(const QUrl &url) const +{ + QString stringUrl = qz_urlEncodeQueryString(url); + + if (stringUrl == QLatin1String("qupzilla:speeddial") || stringUrl == QLatin1String("about:blank")) { + stringUrl = ""; + } + + return stringUrl; +} + void LocationBar::urlEnter() { if (m_completerBookmarkId != -1) { @@ -241,11 +252,7 @@ void LocationBar::showUrl(const QUrl &url) return; } - QString stringUrl = qz_urlEncodeQueryString(url); - - if (stringUrl == QLatin1String("qupzilla:speeddial") || stringUrl == QLatin1String("about:blank")) { - stringUrl = ""; - } + const QString &stringUrl = convertUrlToText(url); if (stringUrl == text()) { return; @@ -356,6 +363,18 @@ void LocationBar::contextMenuEvent(QContextMenuEvent* event) m_menu->popup(p); } +void LocationBar::focusInEvent(QFocusEvent* event) +{ + const QString &stringUrl = convertUrlToText(m_webView->url()); + + // Text has been edited, let's show go button + if (stringUrl != text()) { + showGoButton(); + } + + LineEdit::focusInEvent(event); +} + void LocationBar::dropEvent(QDropEvent* event) { if (event->mimeData()->hasUrls()) { @@ -388,10 +407,12 @@ void LocationBar::dropEvent(QDropEvent* event) QLineEdit::dropEvent(event); } -void LocationBar::focusOutEvent(QFocusEvent* e) +void LocationBar::focusOutEvent(QFocusEvent* event) { - QLineEdit::focusOutEvent(e); - if (e->reason() == Qt::PopupFocusReason || (!selectedText().isEmpty() && e->reason() != Qt::TabFocusReason)) { + QLineEdit::focusOutEvent(event); + + if (event->reason() == Qt::PopupFocusReason + || (!selectedText().isEmpty() && event->reason() != Qt::TabFocusReason)) { return; } diff --git a/src/lib/navigation/locationbar.h b/src/lib/navigation/locationbar.h index 6682d24c6..3adddc975 100644 --- a/src/lib/navigation/locationbar.h +++ b/src/lib/navigation/locationbar.h @@ -79,7 +79,8 @@ private slots: private: void contextMenuEvent(QContextMenuEvent* event); - void focusOutEvent(QFocusEvent* e); + void focusInEvent(QFocusEvent* event); + void focusOutEvent(QFocusEvent* event); void mouseDoubleClickEvent(QMouseEvent* event); void mousePressEvent(QMouseEvent* event); void keyPressEvent(QKeyEvent* event); @@ -87,6 +88,7 @@ private: void dropEvent(QDropEvent* event); QUrl createUrl(); + QString convertUrlToText(const QUrl &url) const; void showGoButton(); void hideGoButton();