Merge pull request #1930 from PhenomRetroShare/Add_MoreQuoteColors

Add more color for quotted text.
This commit is contained in:
defnax 2020-05-12 14:09:09 +02:00 committed by GitHub
commit d8ca92da1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 99 additions and 34 deletions

View File

@ -1908,11 +1908,8 @@ void ChatWidget::updateCMPreview()
void ChatWidget::quote() void ChatWidget::quote()
{ {
QString text = ui->textBrowser->textCursor().selection().toPlainText(); QString text = RsHtml::makeQuotedText(ui->textBrowser);
QStringList sl = text.split(QRegExp("[\r\n]"), QString::SkipEmptyParts); emit ui->chatTextEdit->append(text);
text = sl.join("\n> ");
text.replace(QChar(-4), " "); // Char used when image on text.
emit ui->chatTextEdit->append(QString("> ") + text);
} }
void ChatWidget::dropPlacemark() void ChatWidget::dropPlacemark()

View File

@ -31,6 +31,7 @@ class MimeTextEdit : public RSTextEdit
Q_OBJECT Q_OBJECT
Q_PROPERTY(QColor textColorQuote READ textColorQuote WRITE setTextColorQuote) Q_PROPERTY(QColor textColorQuote READ textColorQuote WRITE setTextColorQuote)
Q_PROPERTY(QVariant textColorQuotes READ textColorQuotes WRITE setTextColorQuotes)
public: public:
MimeTextEdit(QWidget *parent = 0); MimeTextEdit(QWidget *parent = 0);
@ -48,12 +49,14 @@ public:
void addContextMenuAction(QAction *action); void addContextMenuAction(QAction *action);
QColor textColorQuote() const { return highliter->textColorQuote();} QColor textColorQuote() const { return highliter->textColorQuote();}
QVariant textColorQuotes() const { return highliter->textColorQuotes();}
bool onlyPlainText() const {return mOnlyPlainText;} bool onlyPlainText() const {return mOnlyPlainText;}
void setMaxBytes(int limit) {mMaxBytes = limit;} void setMaxBytes(int limit) {mMaxBytes = limit;}
public slots: public slots:
void setTextColorQuote(QColor textColorQuote) { highliter->setTextColorQuote(textColorQuote);} void setTextColorQuote(QColor textColorQuote) { highliter->setTextColorQuote(textColorQuote);}
void setTextColorQuotes(QVariant textColorQuotes) { highliter->setTextColorQuotes(textColorQuotes);}
void setOnlyPlainText(bool bOnlyPlainText) {mOnlyPlainText = bOnlyPlainText;} void setOnlyPlainText(bool bOnlyPlainText) {mOnlyPlainText = bOnlyPlainText;}
signals: signals:

View File

@ -34,6 +34,7 @@ class RSTextBrowser : public QTextBrowser
Q_OBJECT Q_OBJECT
Q_PROPERTY(QColor textColorQuote READ textColorQuote WRITE setTextColorQuote) Q_PROPERTY(QColor textColorQuote READ textColorQuote WRITE setTextColorQuote)
Q_PROPERTY(QVariant textColorQuotes READ textColorQuotes WRITE setTextColorQuotes)
public: public:
explicit RSTextBrowser(QWidget *parent = 0); explicit RSTextBrowser(QWidget *parent = 0);
@ -52,11 +53,13 @@ public:
virtual QVariant loadResource(int type, const QUrl &name); virtual QVariant loadResource(int type, const QUrl &name);
QColor textColorQuote() const { return highlighter->textColorQuote();} QColor textColorQuote() const { return highlighter->textColorQuote();}
QVariant textColorQuotes() const { return highlighter->textColorQuotes();}
bool getShowImages() const { return mShowImages; } bool getShowImages() const { return mShowImages; }
public slots: public slots:
void showImages(); void showImages();
void setTextColorQuote(QColor textColorQuote) { highlighter->setTextColorQuote(textColorQuote);} void setTextColorQuote(QColor textColorQuote) { highlighter->setTextColorQuote(textColorQuote);}
void setTextColorQuotes(QVariant textColorQuotes) { highlighter->setTextColorQuotes(textColorQuotes);}
private slots: private slots:
void linkClicked(const QUrl &url); void linkClicked(const QUrl &url);

View File

@ -2149,3 +2149,8 @@ GxsChannelDialog GroupTreeWidget QTreeWidget#treeWidget::item{
/*padding: 20px;*/ /*padding: 20px;*/
} }
RSTextBrowser, MimeTextEdit
{
/*qproperty-textColorQuote: rgb(125, 125, 255);*/
/*qproperty-textColorQuotes: ColorList(#0000ff #00ff00 #00ffff #ff0000 #ff00ff #ffff00 #ffffff);*/
}

View File

@ -1215,8 +1215,10 @@ QString RsHtml::makeQuotedText(RSTextBrowser *browser)
} }
QStringList sl = text.split(QRegExp("[\r\n]"),QString::SkipEmptyParts); QStringList sl = text.split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
text = sl.join("\n> "); 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. 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) void RsHtml::insertSpoilerText(QTextCursor cursor)

View File

@ -23,35 +23,90 @@
RsSyntaxHighlighter::RsSyntaxHighlighter(QTextEdit *parent) RsSyntaxHighlighter::RsSyntaxHighlighter(QTextEdit *parent)
: QSyntaxHighlighter(parent) : QSyntaxHighlighter(parent)
{ {
quotationFormats.append(QTextCharFormat());
} }
QColor RsSyntaxHighlighter::textColorQuote () const
void RsSyntaxHighlighter::highlightBlock(const QString &text)
{ {
QRegExp endl("[\\r\\n\\x2028]"); //Usually 0x2028 cahracter is used for newline, no idea why return quotationFormats.at(0).foreground().color();
int index = 0; }
QStringList lines = text.split(endl); QVariant RsSyntaxHighlighter::textColorQuotes() const
foreach (const QString &line, lines) { {
if(line.trimmed().startsWith('>')) { QList<QVariant> l;
setFormat(index, line.length(), quotationFormat); foreach(auto i, quotationFormats)
} l.append(QVariant(i.foreground().color()));
index += line.length() + 1;
} return QVariant(l);
//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);
}
}
} }
void RsSyntaxHighlighter::setTextColorQuote(QColor textColorQuote) void RsSyntaxHighlighter::setTextColorQuote(QColor textColorQuote)
{ {
quotationFormat.setForeground(textColorQuote); quotationFormats[0].setForeground(textColorQuote);
this->rehighlight(); 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<line.length(); i++ ){
if( line[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<line.length(); i++){
if( line[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 //Dumping the raw unicode string into the console in Base64 encoding
/* /*
QByteArray uniline; QByteArray uniline;

View File

@ -30,22 +30,22 @@ class RsSyntaxHighlighter : public QSyntaxHighlighter
Q_OBJECT Q_OBJECT
Q_PROPERTY(QColor textColorQuote READ textColorQuote WRITE setTextColorQuote) Q_PROPERTY(QColor textColorQuote READ textColorQuote WRITE setTextColorQuote)
Q_PROPERTY(QVariant textColorQuotes READ textColorQuotes WRITE setTextColorQuotes)
public: public:
RsSyntaxHighlighter(QTextEdit *parent = 0); 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: protected:
void highlightBlock(const QString &text); void highlightBlock(const QString &text);
private: private:
QTextCharFormat quotationFormat; QList<QTextCharFormat> quotationFormats;
signals:
public slots:
void setTextColorQuote(QColor textColorQuote);
}; };
#endif // RSSYNTAXHIGHLIGHTER_H #endif // RSSYNTAXHIGHLIGHTER_H