1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

Possibility to delete history entries from address bar popup completion.

- with Delete key
This commit is contained in:
nowrep 2012-05-05 16:06:24 +02:00
parent 90649f59e1
commit b1b27a434e
4 changed files with 38 additions and 16 deletions

View File

@ -17,6 +17,7 @@
* ============================================================ */
#include "locationcompleterdelegate.h"
#include "locationcompleterview.h"
#include "locationcompletermodel.h"
#include "iconprovider.h"
#include <QPainter>
@ -78,7 +79,7 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
const int leftTitleEdge = leftPosition + 2;
const int rightTitleEdge = rightPosition - m_padding;
QRect titleRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height());
QString title(titleMetrics.elidedText(index.data(Qt::UserRole).toString(), Qt::ElideRight, titleRect.width()));
QString title(titleMetrics.elidedText(index.data(LocationCompleterModel::TitleRole).toString(), Qt::ElideRight, titleRect.width()));
painter->setFont(titleFont);
style->drawItemText(painter, titleRect, Qt::AlignLeft | Qt::TextSingleLine, opt.palette, true, title, colorRole);
@ -90,7 +91,7 @@ void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewI
style->drawItemText(painter, linkRect, Qt::TextSingleLine | Qt::AlignLeft, opt.palette, true, link, colorLinkRole);
// Draw star to bookmark items
if (index.data(Qt::UserRole + 1).toBool()) {
if (index.data(LocationCompleterModel::BookmarkRole).toBool()) {
const QPixmap starPixmap = qIconProvider->bookmarkIcon();
QSize starSize = starPixmap.size();
QPoint pos(rightPosition - starSize.width(), opt.rect.top() + m_padding);

View File

@ -47,7 +47,7 @@ void LocationCompleterModel::refreshCompletions(const QString &string)
QList<QUrl> urlList;
QSqlQuery query;
query.prepare("SELECT url, title, icon FROM bookmarks WHERE title LIKE ? OR url LIKE ? LIMIT ?");
query.prepare("SELECT id, url, title, icon FROM bookmarks WHERE title LIKE ? OR url LIKE ? LIMIT ?");
query.addBindValue(searchString);
query.addBindValue(searchString);
query.addBindValue(limit);
@ -55,20 +55,20 @@ void LocationCompleterModel::refreshCompletions(const QString &string)
while (query.next()) {
QStandardItem* item = new QStandardItem();
const QUrl &url = query.value(0).toUrl();
const QUrl &url = query.value(1).toUrl();
item->setIcon(qIconProvider->iconFromImage(QImage::fromData(query.value(2).toByteArray())));
item->setIcon(qIconProvider->iconFromImage(QImage::fromData(query.value(3).toByteArray())));
item->setText(url.toEncoded());
item->setData(query.value(1), Qt::UserRole);
item->setData(QVariant(true), Qt::UserRole + 1); // From bookmarks
item->setData(query.value(0), IdRole);
item->setData(query.value(2), TitleRole);
item->setData(QVariant(true), BookmarkRole);
appendRow(item);
urlList.append(url);
}
limit -= query.size();
query.prepare("SELECT url, title FROM history WHERE title LIKE ? OR url LIKE ? ORDER BY count DESC LIMIT ?");
query.prepare("SELECT id, url, title FROM history WHERE title LIKE ? OR url LIKE ? ORDER BY count DESC LIMIT ?");
query.addBindValue(searchString);
query.addBindValue(searchString);
query.addBindValue(limit);
@ -76,7 +76,7 @@ void LocationCompleterModel::refreshCompletions(const QString &string)
while (query.next()) {
QStandardItem* item = new QStandardItem();
const QUrl &url = query.value(0).toUrl();
const QUrl &url = query.value(1).toUrl();
if (urlList.contains(url)) {
continue;
@ -84,8 +84,9 @@ void LocationCompleterModel::refreshCompletions(const QString &string)
item->setIcon(_iconForUrl(url));
item->setText(url.toEncoded());
item->setData(query.value(1), Qt::UserRole);
item->setData(QVariant(false), Qt::UserRole + 1);
item->setData(query.value(0), IdRole);
item->setData(query.value(2), TitleRole);
item->setData(QVariant(false), BookmarkRole);
appendRow(item);
}
@ -96,16 +97,17 @@ void LocationCompleterModel::showMostVisited()
clear();
QSqlQuery query;
query.exec("SELECT url, title FROM history ORDER BY count DESC LIMIT 15");
query.exec("SELECT id, url, title FROM history ORDER BY count DESC LIMIT 15");
while (query.next()) {
QStandardItem* item = new QStandardItem();
const QUrl &url = query.value(0).toUrl();
const QUrl &url = query.value(1).toUrl();
item->setIcon(_iconForUrl(url));
item->setText(url.toEncoded());
item->setData(query.value(1), Qt::UserRole);
item->setData(QVariant(false), Qt::UserRole + 1);
item->setData(query.value(0), IdRole);
item->setData(query.value(2), TitleRole);
item->setData(QVariant(false), BookmarkRole);
appendRow(item);
}

View File

@ -23,6 +23,11 @@
class LocationCompleterModel : public QStandardItemModel
{
public:
enum Role {
TitleRole = Qt::UserRole + 1,
BookmarkRole = Qt::UserRole + 2,
IdRole = Qt::UserRole + 3
};
explicit LocationCompleterModel(QObject* parent = 0);
void refreshCompletions(const QString &string);

View File

@ -16,6 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "locationcompleterview.h"
#include "locationcompletermodel.h"
#include "mainapplication.h"
#include "history.h"
#include <QKeyEvent>
#include <QApplication>
@ -116,6 +119,17 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event)
}
return false;
case Qt::Key_Delete:
if (viewport()->rect().contains(visualRect(curIndex)) &&
!curIndex.data(LocationCompleterModel::BookmarkRole).toBool()) {
int id = curIndex.data(LocationCompleterModel::IdRole).toInt();
model()->removeRow(curIndex.row(), curIndex.parent());
mApp->history()->deleteHistoryEntry(id);
return true;
}
break;
case Qt::Key_PageUp:
case Qt::Key_PageDown:
return false;