mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-12 11:02:30 -04:00
>greentext
This commit is contained in:
parent
4b38b66937
commit
1dd0a2acd1
5 changed files with 73 additions and 2 deletions
39
retroshare-gui/src/util/RsSyntaxHighlighter.cpp
Normal file
39
retroshare-gui/src/util/RsSyntaxHighlighter.cpp
Normal 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;
|
||||
*/
|
26
retroshare-gui/src/util/RsSyntaxHighlighter.h
Normal file
26
retroshare-gui/src/util/RsSyntaxHighlighter.h
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue