1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Fix #102 (Greentext only lines with ">")

This commit is contained in:
apprb 2014-08-14 18:55:04 +07:00
parent c4f83d60dd
commit 5f4c282215

View File

@ -185,8 +185,6 @@ void ChatForm::addMessage(QString author, QString message, QString date)
void ChatForm::addMessage(QLabel* author, QLabel* message, QLabel* date) void ChatForm::addMessage(QLabel* author, QLabel* message, QLabel* date)
{ {
QPalette greentext;
greentext.setColor(QPalette::WindowText, QColor(61,204,61));
QScrollBar* scroll = chatArea->verticalScrollBar(); QScrollBar* scroll = chatArea->verticalScrollBar();
lockSliderToBottom = scroll && scroll->value() == scroll->maximum(); lockSliderToBottom = scroll && scroll->value() == scroll->maximum();
author->setAlignment(Qt::AlignTop | Qt::AlignRight); author->setAlignment(Qt::AlignTop | Qt::AlignRight);
@ -214,8 +212,23 @@ void ChatForm::addMessage(QLabel* author, QLabel* message, QLabel* date)
} }
else if (curRow)// onSaveLogClicked expects 0 or 3 QLabel per line else if (curRow)// onSaveLogClicked expects 0 or 3 QLabel per line
author->setText(""); author->setText("");
if (message->text()[0] == '>')
message->setPalette(greentext); QColor greentext(61,204,61);
QString fontTemplate = "<font color='%1'>%2</font>";
QString finalMessage;
QStringList messageLines = message->text().split("\n");
for (QString& s : messageLines)
{
if (QRegExp("^[ ]*>.*").exactMatch(s))
finalMessage += fontTemplate.arg(greentext.name(), s.replace(" ", "&nbsp;"));
else
finalMessage += s.replace(" ", "&nbsp;");
finalMessage += "<br>";
}
message->setText(finalMessage.left(finalMessage.length()-4));
message->setTextFormat(Qt::RichText);
mainChatLayout->addWidget(author, curRow, 0); mainChatLayout->addWidget(author, curRow, 0);
mainChatLayout->addWidget(message, curRow, 1); mainChatLayout->addWidget(message, curRow, 1);
mainChatLayout->addWidget(date, curRow, 3); mainChatLayout->addWidget(date, curRow, 3);