diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index fdb919018..2cf0e1edf 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -1908,11 +1908,8 @@ void ChatWidget::updateCMPreview() void ChatWidget::quote() { - QString text = ui->textBrowser->textCursor().selection().toPlainText(); - QStringList sl = text.split(QRegExp("[\r\n]"), QString::SkipEmptyParts); - text = sl.join("\n> "); - text.replace(QChar(-4), " "); // Char used when image on text. - emit ui->chatTextEdit->append(QString("> ") + text); + QString text = RsHtml::makeQuotedText(ui->textBrowser); + emit ui->chatTextEdit->append(text); } void ChatWidget::dropPlacemark() diff --git a/retroshare-gui/src/gui/common/MimeTextEdit.h b/retroshare-gui/src/gui/common/MimeTextEdit.h index fc449fa64..9c47cac23 100644 --- a/retroshare-gui/src/gui/common/MimeTextEdit.h +++ b/retroshare-gui/src/gui/common/MimeTextEdit.h @@ -31,6 +31,7 @@ class MimeTextEdit : public RSTextEdit Q_OBJECT Q_PROPERTY(QColor textColorQuote READ textColorQuote WRITE setTextColorQuote) + Q_PROPERTY(QVariant textColorQuotes READ textColorQuotes WRITE setTextColorQuotes) public: MimeTextEdit(QWidget *parent = 0); @@ -48,12 +49,14 @@ public: void addContextMenuAction(QAction *action); QColor textColorQuote() const { return highliter->textColorQuote();} + QVariant textColorQuotes() const { return highliter->textColorQuotes();} bool onlyPlainText() const {return mOnlyPlainText;} void setMaxBytes(int limit) {mMaxBytes = limit;} public slots: void setTextColorQuote(QColor textColorQuote) { highliter->setTextColorQuote(textColorQuote);} + void setTextColorQuotes(QVariant textColorQuotes) { highliter->setTextColorQuotes(textColorQuotes);} void setOnlyPlainText(bool bOnlyPlainText) {mOnlyPlainText = bOnlyPlainText;} signals: diff --git a/retroshare-gui/src/gui/common/RSTextBrowser.h b/retroshare-gui/src/gui/common/RSTextBrowser.h index 1434bbb72..1f4cafd52 100644 --- a/retroshare-gui/src/gui/common/RSTextBrowser.h +++ b/retroshare-gui/src/gui/common/RSTextBrowser.h @@ -34,6 +34,7 @@ class RSTextBrowser : public QTextBrowser Q_OBJECT Q_PROPERTY(QColor textColorQuote READ textColorQuote WRITE setTextColorQuote) + Q_PROPERTY(QVariant textColorQuotes READ textColorQuotes WRITE setTextColorQuotes) public: explicit RSTextBrowser(QWidget *parent = 0); @@ -52,11 +53,13 @@ public: virtual QVariant loadResource(int type, const QUrl &name); QColor textColorQuote() const { return highlighter->textColorQuote();} + QVariant textColorQuotes() const { return highlighter->textColorQuotes();} bool getShowImages() const { return mShowImages; } public slots: void showImages(); void setTextColorQuote(QColor textColorQuote) { highlighter->setTextColorQuote(textColorQuote);} + void setTextColorQuotes(QVariant textColorQuotes) { highlighter->setTextColorQuotes(textColorQuotes);} private slots: void linkClicked(const QUrl &url); diff --git a/retroshare-gui/src/qss/qdarkstyle-v2.qss b/retroshare-gui/src/qss/qdarkstyle-v2.qss index 843fdc316..a40067388 100644 --- a/retroshare-gui/src/qss/qdarkstyle-v2.qss +++ b/retroshare-gui/src/qss/qdarkstyle-v2.qss @@ -2149,3 +2149,8 @@ GxsChannelDialog GroupTreeWidget QTreeWidget#treeWidget::item{ /*padding: 20px;*/ } +RSTextBrowser, MimeTextEdit +{ + /*qproperty-textColorQuote: rgb(125, 125, 255);*/ + /*qproperty-textColorQuotes: ColorList(#0000ff #00ff00 #00ffff #ff0000 #ff00ff #ffff00 #ffffff);*/ +} diff --git a/retroshare-gui/src/util/HandleRichText.cpp b/retroshare-gui/src/util/HandleRichText.cpp index c500a6bb9..d8870eb50 100644 --- a/retroshare-gui/src/util/HandleRichText.cpp +++ b/retroshare-gui/src/util/HandleRichText.cpp @@ -1215,8 +1215,10 @@ QString RsHtml::makeQuotedText(RSTextBrowser *browser) } QStringList sl = text.split(QRegExp("[\r\n]"),QString::SkipEmptyParts); text = sl.join("\n> "); + text.replace("\n> >","\n>>"); // Don't add space for already quotted lines. text.replace(QChar(-4)," ");//Char used when image on text. - return QString("> ") + text; + QString quote = (text.left(1) == ">") ? QString(">") : QString("> "); + return quote + text; } void RsHtml::insertSpoilerText(QTextCursor cursor) diff --git a/retroshare-gui/src/util/RsSyntaxHighlighter.cpp b/retroshare-gui/src/util/RsSyntaxHighlighter.cpp index 9de76aaa3..ed05b702c 100644 --- a/retroshare-gui/src/util/RsSyntaxHighlighter.cpp +++ b/retroshare-gui/src/util/RsSyntaxHighlighter.cpp @@ -23,35 +23,90 @@ RsSyntaxHighlighter::RsSyntaxHighlighter(QTextEdit *parent) : QSyntaxHighlighter(parent) { - + quotationFormats.append(QTextCharFormat()); } - -void RsSyntaxHighlighter::highlightBlock(const QString &text) +QColor RsSyntaxHighlighter::textColorQuote () const { - 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); - } - } + return quotationFormats.at(0).foreground().color(); +} +QVariant RsSyntaxHighlighter::textColorQuotes() const +{ + QList l; + foreach(auto i, quotationFormats) + l.append(QVariant(i.foreground().color())); + + return QVariant(l); } void RsSyntaxHighlighter::setTextColorQuote(QColor textColorQuote) { - quotationFormat.setForeground(textColorQuote); + quotationFormats[0].setForeground(textColorQuote); this->rehighlight(); } +void RsSyntaxHighlighter::setTextColorQuotes(QVariant textColorQuotes) +{ + QStringList parList = textColorQuotes.toStringList(); + if ((parList.size() == 2) && (parList.at(0).toLower() == "colorlist")) + { + QStringList colList = parList.at(1).split(" "); + quotationFormats.clear(); + for(int i = 0; i < colList.size(); i++) + { + quotationFormats.append(QTextCharFormat()); + quotationFormats[i].setForeground(QColor(colList[i])); + } + } + + this->rehighlight(); +} + +void RsSyntaxHighlighter::highlightBlock(const QString &text) +{ + if (text == "") return; + + QRegExp endl("[\\r\\n\\x2028]"); //Usually 0x2028 character is used for newline, no idea why + int index = 0; + QStringList lines = text.split(endl); + foreach (const QString &cLine, lines) { + QString line =cLine; + line.replace(QChar::Nbsp,QChar::Space); + int count = 0; + for( int i=0; i' ) + count++; + else if( line[i] != QChar::Space ) + break; + } + //Make it work with the compact chat style + int start = line.indexOf(": >"); + if( start != -1 ) + start += 2; // Start at ">" not ":" + else + start = 0; + + if(count && start > count ) { + // Found but already quotted + start = 0; + } else { + if (start && !count) { + // Start to count after name: > + for(int i=start; i' ) + count++; + else if( line[i] != QChar::Space ) + break; + } + } + } + + if(count) { + setFormat(index + start, line.length() - start, quotationFormats.at(qMin(count-1,quotationFormats.size()-1))); + } + index += line.length() + 1; + } +} + //Dumping the raw unicode string into the console in Base64 encoding /* QByteArray uniline; diff --git a/retroshare-gui/src/util/RsSyntaxHighlighter.h b/retroshare-gui/src/util/RsSyntaxHighlighter.h index 4d01a37d9..4955401e4 100644 --- a/retroshare-gui/src/util/RsSyntaxHighlighter.h +++ b/retroshare-gui/src/util/RsSyntaxHighlighter.h @@ -30,22 +30,22 @@ class RsSyntaxHighlighter : public QSyntaxHighlighter Q_OBJECT Q_PROPERTY(QColor textColorQuote READ textColorQuote WRITE setTextColorQuote) + Q_PROPERTY(QVariant textColorQuotes READ textColorQuotes WRITE setTextColorQuotes) public: RsSyntaxHighlighter(QTextEdit *parent = 0); - QColor textColorQuote() const { return quotationFormat.foreground().color(); }; + QColor textColorQuote () const; + QVariant textColorQuotes() const; + +public slots: + void setTextColorQuote (QColor textColorQuote); + void setTextColorQuotes(QVariant textColorQuotes); protected: void highlightBlock(const QString &text); private: - QTextCharFormat quotationFormat; - -signals: - -public slots: - void setTextColorQuote(QColor textColorQuote); - + QList quotationFormats; }; #endif // RSSYNTAXHIGHLIGHTER_H