1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Fixes in inline completion + enter completed text with left arrow key.

This commit is contained in:
nowrep 2013-05-11 00:17:38 +02:00
parent 77aa5b0f07
commit 49ed4d05c4
5 changed files with 35 additions and 8 deletions

View File

@ -54,6 +54,11 @@ bool LocationCompleter::showingMostVisited() const
return m_showingMostVisited; return m_showingMostVisited;
} }
bool LocationCompleter::isPopupSelected() const
{
return s_view->currentIndex().isValid();
}
bool LocationCompleter::isPopupVisible() const bool LocationCompleter::isPopupVisible() const
{ {
return s_view->isVisible(); return s_view->isVisible();

View File

@ -38,6 +38,7 @@ public:
QString domainCompletion() const; QString domainCompletion() const;
bool showingMostVisited() const; bool showingMostVisited() const;
bool isPopupSelected() const;
bool isPopupVisible() const; bool isPopupVisible() const;
void closePopup(); void closePopup();

View File

@ -89,11 +89,6 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
} }
break; break;
case Qt::Key_Left:
case Qt::Key_Right:
close();
break;
case Qt::Key_Escape: case Qt::Key_Escape:
close(); close();
return false; return false;

View File

@ -55,6 +55,7 @@ LocationBar::LocationBar(QupZilla* mainClass)
, m_loadProgress(0) , m_loadProgress(0)
, m_progressVisible(false) , m_progressVisible(false)
, m_forcePaintEvent(false) , m_forcePaintEvent(false)
, m_inlineCompletionVisible(false)
, m_drawCursor(true) , m_drawCursor(true)
, m_popupClosed(false) , m_popupClosed(false)
{ {
@ -135,6 +136,8 @@ void LocationBar::updatePlaceHolderText()
void LocationBar::showCompletion(const QString &newText) void LocationBar::showCompletion(const QString &newText)
{ {
m_inlineCompletionVisible = false;
LineEdit::setText(newText); LineEdit::setText(newText);
// Move cursor to the end // Move cursor to the end
@ -143,6 +146,7 @@ void LocationBar::showCompletion(const QString &newText)
void LocationBar::completionPopupClosed() void LocationBar::completionPopupClosed()
{ {
m_inlineCompletionVisible = false;
m_popupClosed = true; m_popupClosed = true;
m_drawCursor = true; m_drawCursor = true;
} }
@ -163,8 +167,7 @@ QUrl LocationBar::createUrl()
} }
} }
// Is inline domain completion active? if (m_inlineCompletionVisible) {
if (m_completer.isPopupVisible() && !m_completer.domainCompletion().isEmpty()) {
urlToLoad = WebView::guessUrlFromString(text() + m_completer.domainCompletion()); urlToLoad = WebView::guessUrlFromString(text() + m_completer.domainCompletion());
} }
@ -211,6 +214,7 @@ void LocationBar::textEdit()
{ {
if (!text().isEmpty()) { if (!text().isEmpty()) {
m_completer.complete(text()); m_completer.complete(text());
m_inlineCompletionVisible = true;
} }
else { else {
m_completer.closePopup(); m_completer.closePopup();
@ -453,6 +457,27 @@ void LocationBar::keyPressEvent(QKeyEvent* event)
m_completer.complete(text()); m_completer.complete(text());
break; 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: case Qt::Key_Escape:
m_webView->setFocus(); m_webView->setFocus();
showUrl(m_webView->url()); showUrl(m_webView->url());
@ -600,7 +625,7 @@ void LocationBar::paintEvent(QPaintEvent* event)
QTextOption opt; QTextOption opt;
opt.setWrapMode(QTextOption::NoWrap); opt.setWrapMode(QTextOption::NoWrap);
if (hasFocus() && m_completer.isPopupVisible()) { if (hasFocus() && m_inlineCompletionVisible) {
// Draw inline domain completion if available // Draw inline domain completion if available
const QString &completionText = m_completer.domainCompletion(); const QString &completionText = m_completer.domainCompletion();

View File

@ -125,6 +125,7 @@ private:
QColor m_progressColor; QColor m_progressColor;
bool m_forcePaintEvent; bool m_forcePaintEvent;
bool m_inlineCompletionVisible;
bool m_drawCursor; bool m_drawCursor;
bool m_popupClosed; bool m_popupClosed;
}; };