From 49ed4d05c4e605ffcc4e2a9ef9e1761598a646ed Mon Sep 17 00:00:00 2001 From: nowrep Date: Sat, 11 May 2013 00:17:38 +0200 Subject: [PATCH] Fixes in inline completion + enter completed text with left arrow key. --- .../completer/locationcompleter.cpp | 5 +++ .../navigation/completer/locationcompleter.h | 1 + .../completer/locationcompleterview.cpp | 5 --- src/lib/navigation/locationbar.cpp | 31 +++++++++++++++++-- src/lib/navigation/locationbar.h | 1 + 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/lib/navigation/completer/locationcompleter.cpp b/src/lib/navigation/completer/locationcompleter.cpp index 0055a0b72..91ca8dcc9 100644 --- a/src/lib/navigation/completer/locationcompleter.cpp +++ b/src/lib/navigation/completer/locationcompleter.cpp @@ -54,6 +54,11 @@ bool LocationCompleter::showingMostVisited() const return m_showingMostVisited; } +bool LocationCompleter::isPopupSelected() const +{ + return s_view->currentIndex().isValid(); +} + bool LocationCompleter::isPopupVisible() const { return s_view->isVisible(); diff --git a/src/lib/navigation/completer/locationcompleter.h b/src/lib/navigation/completer/locationcompleter.h index 7bf436ef1..53482be28 100644 --- a/src/lib/navigation/completer/locationcompleter.h +++ b/src/lib/navigation/completer/locationcompleter.h @@ -38,6 +38,7 @@ public: QString domainCompletion() const; bool showingMostVisited() const; + bool isPopupSelected() const; bool isPopupVisible() const; void closePopup(); diff --git a/src/lib/navigation/completer/locationcompleterview.cpp b/src/lib/navigation/completer/locationcompleterview.cpp index 9ed805fed..ee41a2db7 100644 --- a/src/lib/navigation/completer/locationcompleterview.cpp +++ b/src/lib/navigation/completer/locationcompleterview.cpp @@ -89,11 +89,6 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event) } break; - case Qt::Key_Left: - case Qt::Key_Right: - close(); - break; - case Qt::Key_Escape: close(); return false; diff --git a/src/lib/navigation/locationbar.cpp b/src/lib/navigation/locationbar.cpp index f5ec16d52..a49314c8c 100644 --- a/src/lib/navigation/locationbar.cpp +++ b/src/lib/navigation/locationbar.cpp @@ -55,6 +55,7 @@ LocationBar::LocationBar(QupZilla* mainClass) , m_loadProgress(0) , m_progressVisible(false) , m_forcePaintEvent(false) + , m_inlineCompletionVisible(false) , m_drawCursor(true) , m_popupClosed(false) { @@ -135,6 +136,8 @@ void LocationBar::updatePlaceHolderText() void LocationBar::showCompletion(const QString &newText) { + m_inlineCompletionVisible = false; + LineEdit::setText(newText); // Move cursor to the end @@ -143,6 +146,7 @@ void LocationBar::showCompletion(const QString &newText) void LocationBar::completionPopupClosed() { + m_inlineCompletionVisible = false; m_popupClosed = true; m_drawCursor = true; } @@ -163,8 +167,7 @@ QUrl LocationBar::createUrl() } } - // Is inline domain completion active? - if (m_completer.isPopupVisible() && !m_completer.domainCompletion().isEmpty()) { + if (m_inlineCompletionVisible) { urlToLoad = WebView::guessUrlFromString(text() + m_completer.domainCompletion()); } @@ -211,6 +214,7 @@ void LocationBar::textEdit() { if (!text().isEmpty()) { m_completer.complete(text()); + m_inlineCompletionVisible = true; } else { m_completer.closePopup(); @@ -453,6 +457,27 @@ void LocationBar::keyPressEvent(QKeyEvent* event) m_completer.complete(text()); break; + case Qt::Key_End: + case Qt::Key_Right: + if (m_inlineCompletionVisible) { + m_inlineCompletionVisible = false; + + setText(text() + m_completer.domainCompletion()); + setCursorPosition(text().size()); + m_completer.closePopup(); + } + + if (m_completer.isPopupVisible()) { + m_completer.closePopup(); + } + break; + + case Qt::Key_Left: + if (m_completer.isPopupVisible()) { + m_completer.closePopup(); + } + break; + case Qt::Key_Escape: m_webView->setFocus(); showUrl(m_webView->url()); @@ -600,7 +625,7 @@ void LocationBar::paintEvent(QPaintEvent* event) QTextOption opt; opt.setWrapMode(QTextOption::NoWrap); - if (hasFocus() && m_completer.isPopupVisible()) { + if (hasFocus() && m_inlineCompletionVisible) { // Draw inline domain completion if available const QString &completionText = m_completer.domainCompletion(); diff --git a/src/lib/navigation/locationbar.h b/src/lib/navigation/locationbar.h index 74e44c675..e9bffa97a 100644 --- a/src/lib/navigation/locationbar.h +++ b/src/lib/navigation/locationbar.h @@ -125,6 +125,7 @@ private: QColor m_progressColor; bool m_forcePaintEvent; + bool m_inlineCompletionVisible; bool m_drawCursor; bool m_popupClosed; };