Commit f1bd8fc4 authored by Laurent Montel's avatar Laurent Montel 😁

Merge branch 'master' of git://anongit.kde.org/messagelib

parents f359d455 26440e1d
......@@ -39,8 +39,24 @@ void AdBlockAutomaticRulesListWidget::updateItem(QListWidgetItem *item)
{
const bool itemIsChecked = (item->checkState() & Qt::Checked);
QFont font = item->font();
font.setItalic(!itemIsChecked);
item->setFont(font);
const QString rule = item->text();
if (itemIsChecked) {
font.setItalic(false);
item->setFont(font);
if (rule.contains(QRegularExpression(QStringLiteral("^@@.*")))) {
item->setTextColor(Qt::magenta);
} else if (rule.contains(QRegularExpression(QStringLiteral("^\\[.*")))) {
item->setTextColor(Qt::red);
} else if (rule.contains(QRegularExpression(QStringLiteral(".*##.*")))) {
item->setTextColor(Qt::blue);
} else {
item->setTextColor(Qt::black);
}
} else {
font.setItalic(true);
item->setFont(font);
item->setTextColor(Qt::gray);
}
}
void AdBlockAutomaticRulesListWidget::setDisabledRules(const QStringList &disabledRules)
......@@ -64,19 +80,12 @@ void AdBlockAutomaticRulesListWidget::createItem(const QString &rule)
if (rule.startsWith(QLatin1Char('!')) || rule.startsWith(QLatin1Char('['))) {
//Comment
subItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
subItem->setTextColor(Qt::gray);
} else {
subItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
const bool checkState = mDisabledRules.contains(rule);
subItem->setCheckState(checkState ? Qt::Unchecked : Qt::Checked);
updateItem(subItem);
if (rule.contains(QRegularExpression(QStringLiteral("^@@.*")))) {
subItem->setTextColor(Qt::magenta);
} else if (rule.contains(QRegularExpression(QStringLiteral("^\\[.*")))) {
subItem->setTextColor(Qt::red);
} else if (rule.contains(QRegularExpression(QStringLiteral(".*##.*")))) {
subItem->setTextColor(Qt::blue);
}
}
}
......
......@@ -19,10 +19,10 @@
#define ADBLOCKAUTOMATICRULESLISTWIDGET_H
#include <QListWidget>
#include "messageviewer_export.h"
namespace MessageViewer
{
class AdBlockAutomaticRulesListWidget : public QListWidget
class MESSAGEVIEWER_EXPORT AdBlockAutomaticRulesListWidget : public QListWidget
{
Q_OBJECT
public:
......
......@@ -11,4 +11,4 @@ set( adblockautomaticruleslistwidgettest_SRCS adblockautomaticruleslistwidgettes
add_executable( adblockautomaticruleslistwidgettest ${adblockautomaticruleslistwidgettest_SRCS})
add_test(adblockautomaticruleslistwidgettest adblockautomaticruleslistwidgettest)
ecm_mark_as_test(adblockautomaticruleslistwidgettest)
target_link_libraries( adblockautomaticruleslistwidgettest Qt5::Test Qt5::Widgets)
target_link_libraries( adblockautomaticruleslistwidgettest Qt5::Test Qt5::Widgets KF5::MessageViewer)
......@@ -16,6 +16,7 @@
*/
#include "adblockautomaticruleslistwidget_gui.h"
#include "../common/adblockautomaticruleslistwidget.h"
#include <KAboutData>
......@@ -24,12 +25,20 @@
#include <QHBoxLayout>
#include <QApplication>
#include <QStandardPaths>
#include <QFileDialog>
AdBlockAutomaticRulesListWidgetTest::AdBlockAutomaticRulesListWidgetTest(QWidget *parent)
AdBlockAutomaticRulesListWidgetTest::AdBlockAutomaticRulesListWidgetTest(const QString &fileName, QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *lay = new QVBoxLayout;
QVBoxLayout *lay = new QVBoxLayout(this);
QFile localFile(fileName);
QString adblockList;
if (localFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
adblockList = QString::fromLatin1(localFile.readAll());
}
MessageViewer::AdBlockAutomaticRulesListWidget *list = new MessageViewer::AdBlockAutomaticRulesListWidget(this);
list->setRules(adblockList);
lay->addWidget(list);
}
AdBlockAutomaticRulesListWidgetTest::~AdBlockAutomaticRulesListWidgetTest()
......@@ -46,12 +55,25 @@ int main(int argc, char **argv)
KAboutData::setApplicationData(aboutData);
parser.addVersionOption();
parser.addHelpOption();
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("+[url]"), i18n("URL of adblock file list")));
aboutData.setupCommandLine(&parser);
parser.process(app);
aboutData.processCommandLine(&parser);
AdBlockAutomaticRulesListWidgetTest *w = new AdBlockAutomaticRulesListWidgetTest();
QString fileName;
if (parser.positionalArguments().count()) {
fileName = parser.positionalArguments().at(0);
} else {
fileName = QFileDialog::getOpenFileName(0, QString(), QString(), i18n("Adblock File (*)"));
}
if (fileName.isEmpty()) {
return 0;
}
AdBlockAutomaticRulesListWidgetTest *w = new AdBlockAutomaticRulesListWidgetTest(fileName);
w->resize(800, 600);
w->show();
......
......@@ -24,7 +24,7 @@ class AdBlockAutomaticRulesListWidgetTest : public QWidget
{
Q_OBJECT
public:
explicit AdBlockAutomaticRulesListWidgetTest(QWidget *parent = Q_NULLPTR);
explicit AdBlockAutomaticRulesListWidgetTest(const QString &fileName, QWidget *parent = Q_NULLPTR);
~AdBlockAutomaticRulesListWidgetTest();
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment