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

LocationCompleter: Show bookmark as first suggestion when found with keyword

This commit is contained in:
David Rosca 2018-01-27 14:34:22 +01:00
parent e23edd7420
commit 5bcffae242
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
2 changed files with 22 additions and 8 deletions

View File

@ -21,6 +21,7 @@
#include "iconprovider.h"
#include "qzsettings.h"
#include "mainapplication.h"
#include "bookmarkitem.h"
#include <algorithm>
@ -80,9 +81,14 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
LocationBar::LoadAction loadAction;
bool isWebSearch = isSearchSuggestion;
BookmarkItem *bookmark = static_cast<BookmarkItem*>(index.data(LocationCompleterModel::BookmarkItemRole).value<void*>());
if (isVisitSearchItem) {
loadAction = LocationBar::loadAction(m_originalText);
isWebSearch = loadAction.type == LocationBar::LoadAction::Search;
if (!m_forceVisitItem) {
bookmark = loadAction.bookmark;
}
}
// Draw icon
@ -93,8 +99,8 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
if (isSearchSuggestion || (isVisitSearchItem && isWebSearch)) {
pixmap = QIcon::fromTheme(QSL("edit-find"), QIcon(QSL(":icons/menu/search-icon.svg"))).pixmap(iconSize, iconMode);
}
if (loadAction.type == LocationBar::LoadAction::Bookmark) {
pixmap = IconProvider::instance()->bookmarkIcon().pixmap(iconSize, iconMode);
if (isVisitSearchItem && bookmark) {
pixmap = bookmark->icon().pixmap(iconSize, iconMode);
} else if (loadAction.type == LocationBar::LoadAction::Search) {
if (loadAction.searchEngine.name != LocationBar::searchEngine().name) {
pixmap = loadAction.searchEngine.icon.pixmap(iconSize, iconMode);
@ -105,7 +111,7 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
// Draw star to bookmark items
int starPixmapWidth = 0;
if (index.data(LocationCompleterModel::BookmarkRole).toBool()) {
if (bookmark) {
const QIcon icon = IconProvider::instance()->bookmarkIcon();
const QSize starSize(16, 16);
starPixmapWidth = starSize.width();
@ -115,9 +121,6 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
}
QString searchText = index.data(LocationCompleterModel::SearchStringRole).toString();
if (index.data(LocationCompleterModel::VisitSearchItemRole).toBool()) {
searchText.clear();
}
// Draw title
leftPosition += 2;
@ -126,8 +129,10 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
painter->setFont(opt.font);
if (isVisitSearchItem) {
title = m_originalText.trimmed();
if (searchText == title) {
if (bookmark) {
title = bookmark->title();
} else {
title = m_originalText.trimmed();
searchText.clear();
}
}
@ -159,6 +164,10 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
}
}
if (bookmark) {
link = bookmark->url().toString();
}
// Draw separator
if (!link.isEmpty()) {
QChar separator = QL1C('-');

View File

@ -156,6 +156,11 @@ void LocationCompleterRefreshJob::completeFromHistory()
foreach (BookmarkItem* bookmark, bookmarks) {
Q_ASSERT(bookmark->isUrl());
// Keyword bookmark replaces visit/search item
if (bookmark->keyword() == m_searchString) {
continue;
}
QStandardItem* item = new QStandardItem();
item->setText(bookmark->url().toEncoded());
item->setData(-1, LocationCompleterModel::IdRole);