>greentext

This commit is contained in:
hunbernd 2015-12-06 21:11:47 +01:00
parent 4b38b66937
commit 1dd0a2acd1
5 changed files with 73 additions and 2 deletions

View file

@ -0,0 +1,39 @@
#include "RsSyntaxHighlighter.h"
RsSyntaxHighlighter::RsSyntaxHighlighter(QTextEdit *parent)
: QSyntaxHighlighter(parent)
{
quotationFormat.setForeground(QColor(120,153,34));
}
void RsSyntaxHighlighter::highlightBlock(const QString &text)
{
QRegExp endl("[\\r\\n\\x2028]"); //Usually 0x2028 cahracter is used for newline, no idea why
int index = 0;
QStringList lines = text.split(endl);
foreach (const QString &line, lines) {
if(line.trimmed().startsWith('>')) {
setFormat(index, line.length(), quotationFormat);
}
index += line.length() + 1;
}
//Make it work with the compact chat style
if(lines.length() > 0){
int i = lines[0].indexOf(": >");
if(i != -1) {
setFormat(i+2, lines[0].length()-i-2, quotationFormat);
}
}
}
//Dumping the raw unicode string into the console in Base64 encoding
/*
QByteArray uniline;
const QChar* qca = line.unicode();
for(int i=0; qca[i]!='\0' ;++i)
{
uniline.append(qca[i].row());
uniline.append(qca[i].cell());
}
std::cout << "Line: " << uniline.toBase64().toStdString() << std::endl;
*/

View file

@ -0,0 +1,26 @@
#ifndef RSSYNTAXHIGHLIGHTER_H
#define RSSYNTAXHIGHLIGHTER_H
#include <QObject>
#include <QSyntaxHighlighter>
#include <QTextEdit>
class RsSyntaxHighlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
RsSyntaxHighlighter(QTextEdit *parent = 0);
protected:
void highlightBlock(const QString &text) Q_DECL_OVERRIDE;
private:
QTextCharFormat quotationFormat;
signals:
public slots:
};
#endif // RSSYNTAXHIGHLIGHTER_H