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()
{
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()

View File

@ -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:

View File

@ -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);

View File

@ -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);*/
}

View File

@ -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)

View File

@ -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<QVariant> 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<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
/*
QByteArray uniline;

View File

@ -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<QTextCharFormat> quotationFormats;
};
#endif // RSSYNTAXHIGHLIGHTER_H