1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
// -*- mode: c++; c-basic-offset: 4 -*-
/*
Copyright (C) 2006 Daniele Galdi <[email protected]>
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 2 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, write to the Free Software Foundation, Inc., 51
Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "adblock.h"
#include "adblockdialogue.h"
#include <kdebug.h>
#include <kpopupmenu.h>
#include <klocale.h>
#include <qcursor.h>
#include <qlabel.h>
#include <qvbox.h>
#include <qlineedit.h>
#include <qcolor.h>
#include <qfont.h>
#include <qpainter.h>
AdBlockDlg::AdBlockDlg(QWidget *parent, AdElementList &elements) :
KDialogBase( parent, "Adblock dialogue", true, "Adblock - able Items", Ok|Cancel, Ok, true )
{
QVBox *page = makeVBoxMainWidget();
m_label1 = new QLabel( i18n("All blockable items in this page:"), page, "label1" );
m_list = new QListView(page);
m_list->setAllColumnsShowFocus( true );
m_list->addColumn( i18n("Source") );
m_list->addColumn( i18n("Category") );
m_list->addColumn( i18n("Node Name") );
m_list->setColumnWidthMode(0, QListView::Manual);
m_list->setColumnWidthMode(1, QListView::Manual);
m_list->setColumnWidthMode(2, QListView::Manual);
m_list->setColumnWidth(0, 600);
m_list->setColumnWidth(1, 90);
m_list->setColumnWidth(2, 90);
AdElementList::iterator it;
for ( it = elements.begin(); it != elements.end(); ++it )
{
AdElement &element = (*it);
QString url = element.url();
ListViewItem *item = new ListViewItem( m_list, url, element.category(), element.type() );
item->setBlocked(element.isBlocked());
}
m_label2 = new QLabel( i18n("New filter (use * as a wildcard):"), page, "label2" );
m_filter = new QLineEdit( "", page, "lineedit" );
connect(this, SIGNAL( okClicked() ), this, SLOT( validateFilter() ));
connect(m_list, SIGNAL( doubleClicked(QListViewItem *, const QPoint &, int) ), this, SLOT(updateFilter(QListViewItem *)) );
m_menu = new KPopupMenu(this);
m_menu->insertItem(i18n("Filter this item"), this, SLOT(filterItem()));
m_menu->insertItem(i18n("Filter all items at same path"), this, SLOT(filterPath()));
connect(m_list,
SIGNAL( contextMenuRequested( QListViewItem *, const QPoint& , int ) ),
this,
SLOT( showContextMenu(QListViewItem *, const QPoint &) ) );
}
void AdBlockDlg::updateFilter(QListViewItem *selected)
{
ListViewItem *item = dynamic_cast<ListViewItem *>(selected);
if (item->isBlocked())
{
m_filter->setText("");
return;
}
m_filter->setText( item->text(0) );
}
void AdBlockDlg::validateFilter()
{
const QString text = m_filter->text().stripWhiteSpace();
if (!text.isEmpty())
emit notEmptyFilter(text);
delayedDestruct();
}
void AdBlockDlg::showContextMenu(QListViewItem *item, const QPoint &point)
{
if (!item) return;
m_menu->popup(point);
}
void AdBlockDlg::filterItem()
{
QListViewItem* item = m_list->selectedItem();
m_filter->setText( item->text(0) );
}
void AdBlockDlg::filterPath()
{
QListViewItem* item = m_list->selectedItem();
QString value = item->text(0);
m_filter->setText( value.section( '/', 0, -2 ).append("/*") );
}
AdBlockDlg::~AdBlockDlg()
{
delete m_label1;
delete m_label2;
delete m_filter;
delete m_list;
}
// ----------------------------------------------------------------------------
void ListViewItem::paintCell(QPainter *p, const QColorGroup & cg, int column, int width, int align)
{
p->save();
QColorGroup g( cg );
if ( isBlocked() )
{
g.setColor(QColorGroup::Text, red);
QFont font;
font.setItalic(true);
p->setFont(font);
}
QListViewItem::paintCell(p, g, column, width, align);
p->restore();
}
inline bool ListViewItem::isBlocked()
{
return m_blocked;
}
inline void ListViewItem::setBlocked(bool blocked)
{
m_blocked = blocked;
}
#include "adblockdialogue.moc"
|