1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

AdBlock: Option to delete rule with Del key

- fixed setting color of newly added rule according to its type
This commit is contained in:
nowrep 2012-07-01 14:44:42 +02:00
parent 1b000812b9
commit 066600ff10
2 changed files with 15 additions and 1 deletions

View File

@ -20,6 +20,7 @@
#include <QMenu> #include <QMenu>
#include <QTimer> #include <QTimer>
#include <QKeyEvent>
#include <QInputDialog> #include <QInputDialog>
AdBlockTreeWidget::AdBlockTreeWidget(AdBlockSubscription* subscription, QWidget* parent) AdBlockTreeWidget::AdBlockTreeWidget(AdBlockSubscription* subscription, QWidget* parent)
@ -114,7 +115,8 @@ void AdBlockTreeWidget::addRule()
return; return;
} }
int offset = m_subscription->addRule(AdBlockRule(newRule)); AdBlockRule rule(newRule);
int offset = m_subscription->addRule(rule);
QTreeWidgetItem* item = new QTreeWidgetItem(); QTreeWidgetItem* item = new QTreeWidgetItem();
item->setText(0, newRule); item->setText(0, newRule);
@ -126,6 +128,8 @@ void AdBlockTreeWidget::addRule()
m_itemChangingBlock = true; m_itemChangingBlock = true;
m_topItem->addChild(item); m_topItem->addChild(item);
m_itemChangingBlock = false; m_itemChangingBlock = false;
adjustItemColor(item, rule);
} }
void AdBlockTreeWidget::removeRule() void AdBlockTreeWidget::removeRule()
@ -172,6 +176,15 @@ void AdBlockTreeWidget::adjustItemColor(QTreeWidgetItem* item, const AdBlockRule
} }
} }
void AdBlockTreeWidget::keyPressEvent(QKeyEvent* event)
{
if (event->key() == Qt::Key_Delete) {
removeRule();
}
TreeWidget::keyPressEvent(event);
}
void AdBlockTreeWidget::refresh() void AdBlockTreeWidget::refresh()
{ {
m_itemChangingBlock = true; m_itemChangingBlock = true;

View File

@ -47,6 +47,7 @@ private slots:
private: private:
void adjustItemColor(QTreeWidgetItem* item, const AdBlockRule &rule); void adjustItemColor(QTreeWidgetItem* item, const AdBlockRule &rule);
void keyPressEvent(QKeyEvent* event);
AdBlockSubscription* m_subscription; AdBlockSubscription* m_subscription;
QTreeWidgetItem* m_topItem; QTreeWidgetItem* m_topItem;