2022-11-18 05:43:27 +00:00
|
|
|
#include "keywordshightlighter.h"
|
2022-11-17 08:26:05 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
2022-11-17 08:42:37 +00:00
|
|
|
using namespace Parse;
|
2022-11-17 08:26:05 +00:00
|
|
|
using namespace Enhancement;
|
|
|
|
|
2022-11-18 05:43:27 +00:00
|
|
|
KeywordsHightlighter::KeywordsHightlighter(QObject *parent)
|
2022-11-17 08:26:05 +00:00
|
|
|
: QSyntaxHighlighter(parent), parse_core(nullptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-18 05:43:27 +00:00
|
|
|
void KeywordsHightlighter::reset(Parse::Result::DocCore *base)
|
2022-11-17 08:26:05 +00:00
|
|
|
{
|
|
|
|
this->parse_core = base;
|
|
|
|
}
|
|
|
|
|
2022-11-18 05:43:27 +00:00
|
|
|
void KeywordsHightlighter::highlightBlock(const QString &text)
|
2022-11-17 08:26:05 +00:00
|
|
|
{
|
|
|
|
if(parse_core == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QTextCharFormat unknowns;
|
2022-11-17 08:42:37 +00:00
|
|
|
unknowns.setForeground(QBrush(Qt::gray));
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
|
|
QTextCharFormat generate;
|
2022-11-17 08:52:37 +00:00
|
|
|
generate.setForeground(QBrush(Qt::blue));
|
2022-11-17 08:42:37 +00:00
|
|
|
|
|
|
|
QTextCharFormat error;
|
|
|
|
error.setForeground(QBrush(Qt::red));
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
|
|
auto block = currentBlock();
|
|
|
|
auto words = parse_core->getWords(block.blockNumber());
|
|
|
|
for(auto &w : words){
|
2022-11-17 08:42:37 +00:00
|
|
|
QList<ErrorMessage> xerrors;
|
|
|
|
|
2022-11-17 08:26:05 +00:00
|
|
|
if(w->host() == parse_core->unknowns()){
|
2022-11-29 03:47:12 +00:00
|
|
|
unknowns.setUnderlineStyle(QTextCharFormat::UnderlineStyle::WaveUnderline);
|
|
|
|
unknowns.setUnderlineColor(QColor(Qt::red));
|
|
|
|
|
2022-11-17 08:26:05 +00:00
|
|
|
setFormat(w->column()-1, w->toString().length(), unknowns);
|
|
|
|
}
|
2022-11-17 08:42:37 +00:00
|
|
|
else if(!w->host()->check(xerrors)){
|
|
|
|
setFormat(w->column()-1, w->toString().length(), error);
|
|
|
|
}
|
2022-11-17 08:26:05 +00:00
|
|
|
else{
|
|
|
|
setFormat(w->column()-1, w->toString().length(), generate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|