mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 22:25:04 -04:00
>greentext
This commit is contained in:
parent
4b38b66937
commit
1dd0a2acd1
5 changed files with 73 additions and 2 deletions
|
@ -14,6 +14,8 @@ RSTextBrowser::RSTextBrowser(QWidget *parent) :
|
||||||
mImageBlockWidget = NULL;
|
mImageBlockWidget = NULL;
|
||||||
mLinkClickActive = true;
|
mLinkClickActive = true;
|
||||||
|
|
||||||
|
highliter = new RsSyntaxHighlighter(this);
|
||||||
|
|
||||||
connect(this, SIGNAL(anchorClicked(QUrl)), this, SLOT(linkClicked(QUrl)));
|
connect(this, SIGNAL(anchorClicked(QUrl)), this, SLOT(linkClicked(QUrl)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define RSTEXTBROWSER_H
|
#define RSTEXTBROWSER_H
|
||||||
|
|
||||||
#include <QTextBrowser>
|
#include <QTextBrowser>
|
||||||
|
#include "util/RsSyntaxHighlighter.h"
|
||||||
|
|
||||||
class RSImageBlockWidget;
|
class RSImageBlockWidget;
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ private:
|
||||||
bool mShowImages;
|
bool mShowImages;
|
||||||
RSImageBlockWidget *mImageBlockWidget;
|
RSImageBlockWidget *mImageBlockWidget;
|
||||||
bool mLinkClickActive;
|
bool mLinkClickActive;
|
||||||
|
RsSyntaxHighlighter *highliter;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RSTEXTBROWSER_H
|
#endif // RSTEXTBROWSER_H
|
||||||
|
|
|
@ -523,7 +523,8 @@ HEADERS += rshare.h \
|
||||||
gui/groups/CreateGroup.h \
|
gui/groups/CreateGroup.h \
|
||||||
gui/GetStartedDialog.h \
|
gui/GetStartedDialog.h \
|
||||||
gui/settings/WebuiPage.h \
|
gui/settings/WebuiPage.h \
|
||||||
gui/statistics/BWGraph.h
|
gui/statistics/BWGraph.h \
|
||||||
|
util/RsSyntaxHighlighter.h
|
||||||
|
|
||||||
# gui/ForumsDialog.h \
|
# gui/ForumsDialog.h \
|
||||||
# gui/forums/ForumDetails.h \
|
# gui/forums/ForumDetails.h \
|
||||||
|
@ -871,7 +872,8 @@ SOURCES += main.cpp \
|
||||||
gui/statistics/StatisticsWindow.cpp \
|
gui/statistics/StatisticsWindow.cpp \
|
||||||
gui/statistics/BwCtrlWindow.cpp \
|
gui/statistics/BwCtrlWindow.cpp \
|
||||||
gui/statistics/RttStatistics.cpp \
|
gui/statistics/RttStatistics.cpp \
|
||||||
gui/statistics/BWGraph.cpp
|
gui/statistics/BWGraph.cpp \
|
||||||
|
util/RsSyntaxHighlighter.cpp
|
||||||
|
|
||||||
# gui/ForumsDialog.cpp \
|
# gui/ForumsDialog.cpp \
|
||||||
# gui/forums/ForumDetails.cpp \
|
# gui/forums/ForumDetails.cpp \
|
||||||
|
|
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