mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-24 12:46:35 +01:00
LocationCompleter: Allow to force loading typed text with Shift+Enter
Allow to ignore the suggested search action and instead just try to load the typed text as url.
This commit is contained in:
parent
eae11b9a9a
commit
51b4a39399
@ -254,7 +254,11 @@ void LocationCompleter::indexShiftActivated(const QModelIndex &index)
|
||||
emit clearCompletion();
|
||||
|
||||
// Load request
|
||||
loadRequest(createLoadRequest(index));
|
||||
if (index.data(LocationCompleterModel::VisitSearchItemRole).toBool()) {
|
||||
loadRequest(LoadRequest(QUrl(m_originalText)));
|
||||
} else {
|
||||
loadRequest(createLoadRequest(index));
|
||||
}
|
||||
}
|
||||
|
||||
void LocationCompleter::indexDeleteRequested(const QModelIndex &index)
|
||||
|
@ -33,7 +33,6 @@ LocationCompleterDelegate::LocationCompleterDelegate(QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
, m_rowHeight(0)
|
||||
, m_padding(0)
|
||||
, m_drawSwitchToTab(true)
|
||||
{
|
||||
}
|
||||
|
||||
@ -143,7 +142,7 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
|
||||
}
|
||||
|
||||
if (isVisitSearchItem || isSearchSuggestion) {
|
||||
if (!isSearchSuggestion && !isWebSearch) {
|
||||
if (isVisitSearchItem && (!isWebSearch || m_forceVisitItem)) {
|
||||
link = tr("Visit");
|
||||
} else if (opt.state.testFlag(QStyle::State_Selected) || opt.state.testFlag(QStyle::State_MouseOver)) {
|
||||
QString searchEngineName = loadAction.searchEngine.name;
|
||||
@ -173,7 +172,7 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
|
||||
// Draw url (or switch to tab)
|
||||
int tabPos = index.data(LocationCompleterModel::TabPositionTabRole).toInt();
|
||||
|
||||
if (drawSwitchToTab() && tabPos != -1) {
|
||||
if (qzSettings->showSwitchTab && !m_forceVisitItem && tabPos != -1) {
|
||||
const QIcon tabIcon = QIcon(QSL(":icons/menu/tab.svg"));
|
||||
QRect iconRect(linkRect);
|
||||
iconRect.setX(iconRect.x());
|
||||
@ -215,9 +214,9 @@ QSize LocationCompleterDelegate::sizeHint(const QStyleOptionViewItem &option, co
|
||||
return QSize(200, m_rowHeight);
|
||||
}
|
||||
|
||||
void LocationCompleterDelegate::setShowSwitchToTab(bool enable)
|
||||
void LocationCompleterDelegate::setForceVisitItem(bool enable)
|
||||
{
|
||||
m_drawSwitchToTab = enable;
|
||||
m_forceVisitItem = enable;
|
||||
}
|
||||
|
||||
void LocationCompleterDelegate::setOriginalText(const QString &originalText)
|
||||
@ -225,11 +224,6 @@ void LocationCompleterDelegate::setOriginalText(const QString &originalText)
|
||||
m_originalText = originalText;
|
||||
}
|
||||
|
||||
bool LocationCompleterDelegate::drawSwitchToTab() const
|
||||
{
|
||||
return qzSettings->showSwitchTab && m_drawSwitchToTab;
|
||||
}
|
||||
|
||||
static bool sizeBiggerThan(const QString &s1, const QString &s2)
|
||||
{
|
||||
return s1.size() > s2.size();
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -30,19 +30,17 @@ public:
|
||||
void paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
||||
void setShowSwitchToTab(bool enable);
|
||||
void setForceVisitItem(bool enable);
|
||||
void setOriginalText(const QString &originalText);
|
||||
|
||||
private:
|
||||
bool drawSwitchToTab() const;
|
||||
|
||||
int viewItemDrawText(QPainter *p, const QStyleOptionViewItem *option, const QRect &rect,
|
||||
const QString &text, const QColor &color,
|
||||
const QString &searchText = QString()) const;
|
||||
|
||||
mutable int m_rowHeight;
|
||||
mutable int m_padding;
|
||||
bool m_drawSwitchToTab;
|
||||
bool m_forceVisitItem = false;
|
||||
QString m_originalText;
|
||||
};
|
||||
|
||||
|
@ -316,13 +316,9 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
|
||||
break;
|
||||
|
||||
case Qt::Key_Shift:
|
||||
// don't switch if there is no hovered or selected index to not disturb typing
|
||||
if (idx != visitSearchIdx || underMouse()) {
|
||||
m_delegate->setShowSwitchToTab(false);
|
||||
m_view->viewport()->update();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
m_delegate->setForceVisitItem(true);
|
||||
m_view->viewport()->update();
|
||||
return true;
|
||||
} // switch (keyEvent->key())
|
||||
|
||||
if (focusProxy()) {
|
||||
@ -336,7 +332,7 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
|
||||
|
||||
switch (keyEvent->key()) {
|
||||
case Qt::Key_Shift:
|
||||
m_delegate->setShowSwitchToTab(true);
|
||||
m_delegate->setForceVisitItem(false);
|
||||
m_view->viewport()->update();
|
||||
return true;
|
||||
}
|
||||
@ -379,7 +375,7 @@ void LocationCompleterView::close()
|
||||
{
|
||||
hide();
|
||||
m_view->verticalScrollBar()->setValue(0);
|
||||
m_delegate->setShowSwitchToTab(true);
|
||||
m_delegate->setForceVisitItem(false);
|
||||
m_forceResize = true;
|
||||
|
||||
emit closed();
|
||||
|
Loading…
Reference in New Issue
Block a user