diff --git a/retroshare-gui/src/gui/common/RSTextBrowser.cpp b/retroshare-gui/src/gui/common/RSTextBrowser.cpp index 5e0237d0f..930c506ac 100644 --- a/retroshare-gui/src/gui/common/RSTextBrowser.cpp +++ b/retroshare-gui/src/gui/common/RSTextBrowser.cpp @@ -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))); } diff --git a/retroshare-gui/src/gui/common/RSTextBrowser.h b/retroshare-gui/src/gui/common/RSTextBrowser.h index 945dfbeaa..47fbd5d9b 100644 --- a/retroshare-gui/src/gui/common/RSTextBrowser.h +++ b/retroshare-gui/src/gui/common/RSTextBrowser.h @@ -2,6 +2,7 @@ #define RSTEXTBROWSER_H #include +#include "util/RsSyntaxHighlighter.h" class RSImageBlockWidget; @@ -35,6 +36,7 @@ private: bool mShowImages; RSImageBlockWidget *mImageBlockWidget; bool mLinkClickActive; + RsSyntaxHighlighter *highliter; }; #endif // RSTEXTBROWSER_H diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index 32dc37b2c..5f421702d 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -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 \ diff --git a/retroshare-gui/src/util/RsSyntaxHighlighter.cpp b/retroshare-gui/src/util/RsSyntaxHighlighter.cpp new file mode 100644 index 000000000..a7c39ae72 --- /dev/null +++ b/retroshare-gui/src/util/RsSyntaxHighlighter.cpp @@ -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; + */ diff --git a/retroshare-gui/src/util/RsSyntaxHighlighter.h b/retroshare-gui/src/util/RsSyntaxHighlighter.h new file mode 100644 index 000000000..43ea0e511 --- /dev/null +++ b/retroshare-gui/src/util/RsSyntaxHighlighter.h @@ -0,0 +1,26 @@ +#ifndef RSSYNTAXHIGHLIGHTER_H +#define RSSYNTAXHIGHLIGHTER_H + +#include +#include +#include + +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