From bc65a0a03826c94ef3ce5b3b74c0eaf1d60e8889 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Thu, 8 Jun 2017 13:08:38 +0200 Subject: [PATCH] Add RemoveItemFocusDelegate and use it in SearchEnginesDialog --- src/lib/opensearch/searchenginesdialog.cpp | 7 +++-- src/lib/tools/removeitemfocusdelegate.cpp | 30 ++++++++++++++++++++ src/lib/tools/removeitemfocusdelegate.h | 32 ++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/lib/tools/removeitemfocusdelegate.cpp create mode 100644 src/lib/tools/removeitemfocusdelegate.h diff --git a/src/lib/opensearch/searchenginesdialog.cpp b/src/lib/opensearch/searchenginesdialog.cpp index 0c2253c11..ec1c88df9 100644 --- a/src/lib/opensearch/searchenginesdialog.cpp +++ b/src/lib/opensearch/searchenginesdialog.cpp @@ -1,6 +1,6 @@ /* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca +* QupZilla - Qt web browser +* Copyright (C) 2010-2017 David Rosca * * 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 @@ -19,6 +19,8 @@ #include "ui_searchenginesdialog.h" #include "editsearchengine.h" #include "mainapplication.h" +#include "removeitemfocusdelegate.h" + #include SearchEnginesDialog::SearchEnginesDialog(QWidget* parent) @@ -40,6 +42,7 @@ SearchEnginesDialog::SearchEnginesDialog(QWidget* parent) connect(ui->treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(editEngine())); + ui->treeWidget->setItemDelegate(new RemoveItemFocusDelegate(ui->treeWidget)); ui->treeWidget->sortByColumn(-1); reloadEngines(); } diff --git a/src/lib/tools/removeitemfocusdelegate.cpp b/src/lib/tools/removeitemfocusdelegate.cpp new file mode 100644 index 000000000..e2117ac94 --- /dev/null +++ b/src/lib/tools/removeitemfocusdelegate.cpp @@ -0,0 +1,30 @@ +/* ============================================================ +* QupZilla - Qt web browser +* Copyright (C) 2017 David Rosca +* +* 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 +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#include "removeitemfocusdelegate.h" + +RemoveItemFocusDelegate::RemoveItemFocusDelegate(QObject *parent) + : QStyledItemDelegate(parent) +{ +} + +void RemoveItemFocusDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index) const +{ + QStyleOptionViewItem opt = option; + opt.state &= ~QStyle::State_HasFocus; + QStyledItemDelegate::paint(painter, opt, index); +} diff --git a/src/lib/tools/removeitemfocusdelegate.h b/src/lib/tools/removeitemfocusdelegate.h new file mode 100644 index 000000000..6700d2f6d --- /dev/null +++ b/src/lib/tools/removeitemfocusdelegate.h @@ -0,0 +1,32 @@ +/* ============================================================ +* QupZilla - Qt web browser +* Copyright (C) 2017 David Rosca +* +* 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 +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* ============================================================ */ +#ifndef REMOVEITEMFOCUSDELEGATE_H +#define REMOVEITEMFOCUSDELEGATE_H + +#include + +class RemoveItemFocusDelegate : public QStyledItemDelegate +{ +public: + explicit RemoveItemFocusDelegate(QObject *parent = nullptr); + +private: + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; +}; + +#endif // REMOVEITEMFOCUSDELEGATE_H