39 lines
904 B
C++
39 lines
904 B
C++
|
#include "chainhightlighter.h"
|
||
|
#include <QDebug>
|
||
|
|
||
|
using namespace Enhancement;
|
||
|
|
||
|
ChainHightlighter::ChainHightlighter(QObject *parent)
|
||
|
: QSyntaxHighlighter(parent), parse_core(nullptr)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
void ChainHightlighter::reset(Parse::Result::DocCore *base)
|
||
|
{
|
||
|
this->parse_core = base;
|
||
|
}
|
||
|
|
||
|
void ChainHightlighter::highlightBlock(const QString &text)
|
||
|
{
|
||
|
if(parse_core == nullptr)
|
||
|
return;
|
||
|
|
||
|
QTextCharFormat unknowns;
|
||
|
unknowns.setForeground(QBrush(Qt::red));
|
||
|
|
||
|
QTextCharFormat generate;
|
||
|
generate.setForeground(QBrush(Qt::blue));
|
||
|
|
||
|
auto block = currentBlock();
|
||
|
auto words = parse_core->getWords(block.blockNumber());
|
||
|
for(auto &w : words){
|
||
|
if(w->host() == parse_core->unknowns()){
|
||
|
setFormat(w->column()-1, w->toString().length(), unknowns);
|
||
|
}
|
||
|
else{
|
||
|
setFormat(w->column()-1, w->toString().length(), generate);
|
||
|
}
|
||
|
}
|
||
|
}
|