>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

@ -14,6 +14,8 @@ RSTextBrowser::RSTextBrowser(QWidget *parent) :
mImageBlockWidget = NULL;
mLinkClickActive = true;
highliter = new RsSyntaxHighlighter(this);
connect(this, SIGNAL(anchorClicked(QUrl)), this, SLOT(linkClicked(QUrl)));
}

View File

@ -2,6 +2,7 @@
#define RSTEXTBROWSER_H
#include <QTextBrowser>
#include "util/RsSyntaxHighlighter.h"
class RSImageBlockWidget;
@ -35,6 +36,7 @@ private:
bool mShowImages;
RSImageBlockWidget *mImageBlockWidget;
bool mLinkClickActive;
RsSyntaxHighlighter *highliter;
};
#endif // RSTEXTBROWSER_H

View File

@ -523,7 +523,8 @@ HEADERS += rshare.h \
gui/groups/CreateGroup.h \
gui/GetStartedDialog.h \
gui/settings/WebuiPage.h \
gui/statistics/BWGraph.h
gui/statistics/BWGraph.h \
util/RsSyntaxHighlighter.h
# gui/ForumsDialog.h \
# gui/forums/ForumDetails.h \
@ -871,7 +872,8 @@ SOURCES += main.cpp \
gui/statistics/StatisticsWindow.cpp \
gui/statistics/BwCtrlWindow.cpp \
gui/statistics/RttStatistics.cpp \
gui/statistics/BWGraph.cpp
gui/statistics/BWGraph.cpp \
util/RsSyntaxHighlighter.cpp
# gui/ForumsDialog.cpp \
# gui/forums/ForumDetails.cpp \

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