Fix colors in typing display, when username contains emoji
This commit is contained in:
parent
79e4e2e6e1
commit
c95f4d8276
@ -19,7 +19,8 @@ Rectangle {
|
|||||||
|
|
||||||
Text {
|
Text {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
text: String.fromCodePoint(displayName.codePointAt(0))
|
text: chat.model.escapeEmoji(String.fromCodePoint(displayName.codePointAt(0)))
|
||||||
|
textFormat: Text.RichText
|
||||||
color: colors.text
|
color: colors.text
|
||||||
font.pixelSize: avatar.height/2
|
font.pixelSize: avatar.height/2
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
@ -206,6 +206,7 @@ Item {
|
|||||||
|
|
||||||
id: typingDisplay
|
id: typingDisplay
|
||||||
text: chat.model ? chat.model.formatTypingUsers(chat.model.typingUsers, chatFooter.color) : ""
|
text: chat.model ? chat.model.formatTypingUsers(chat.model.typingUsers, chatFooter.color) : ""
|
||||||
|
textFormat: Text.RichText
|
||||||
color: colors.windowText
|
color: colors.windowText
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ utils::replaceEmoji(const QString &body)
|
|||||||
QSettings settings;
|
QSettings settings;
|
||||||
QString userFontFamily = settings.value("user/emoji_font_family", "emoji").toString();
|
QString userFontFamily = settings.value("user/emoji_font_family", "emoji").toString();
|
||||||
|
|
||||||
bool insideFontBlock = true;
|
bool insideFontBlock = false;
|
||||||
for (auto &code : utf32_string) {
|
for (auto &code : utf32_string) {
|
||||||
// TODO: Be more precise here.
|
// TODO: Be more precise here.
|
||||||
if ((code >= 0x2600 && code <= 0x27bf) || (code >= 0x1f300 && code <= 0x1f3ff) ||
|
if ((code >= 0x2600 && code <= 0x27bf) || (code >= 0x1f300 && code <= 0x1f3ff) ||
|
||||||
@ -57,6 +57,9 @@ utils::replaceEmoji(const QString &body)
|
|||||||
}
|
}
|
||||||
fmtBody += QString::fromUcs4(&code, 1);
|
fmtBody += QString::fromUcs4(&code, 1);
|
||||||
}
|
}
|
||||||
|
if (insideFontBlock) {
|
||||||
|
fmtBody += "</font>";
|
||||||
|
}
|
||||||
|
|
||||||
return fmtBody;
|
return fmtBody;
|
||||||
}
|
}
|
||||||
|
@ -1406,9 +1406,34 @@ TimelineModel::formatTypingUsers(const std::vector<QString> &users, QColor bg)
|
|||||||
QStringList uidWithoutLast;
|
QStringList uidWithoutLast;
|
||||||
|
|
||||||
auto formatUser = [this, bg](const QString &user_id) -> QString {
|
auto formatUser = [this, bg](const QString &user_id) -> QString {
|
||||||
return QString("<font color=\"%1\">%2</font>")
|
auto uncoloredUsername = escapeEmoji(displayName(user_id).toHtmlEscaped());
|
||||||
.arg(userColor(user_id, bg).name())
|
QString prefix = QString("<font color=\"%1\">").arg(userColor(user_id, bg).name());
|
||||||
.arg(escapeEmoji(displayName(user_id).toHtmlEscaped()));
|
|
||||||
|
// color only parts that don't have a font already specified
|
||||||
|
QString coloredUsername;
|
||||||
|
int index = 0;
|
||||||
|
do {
|
||||||
|
auto startIndex = uncoloredUsername.indexOf("<font", index);
|
||||||
|
|
||||||
|
if (startIndex - index != 0)
|
||||||
|
coloredUsername +=
|
||||||
|
prefix +
|
||||||
|
uncoloredUsername.midRef(
|
||||||
|
index, startIndex > 0 ? startIndex - index : -1) +
|
||||||
|
"</font>";
|
||||||
|
|
||||||
|
auto endIndex = uncoloredUsername.indexOf("</font>", startIndex);
|
||||||
|
if (endIndex > 0)
|
||||||
|
endIndex += sizeof("</font>") - 1;
|
||||||
|
|
||||||
|
if (endIndex - startIndex != 0)
|
||||||
|
coloredUsername +=
|
||||||
|
uncoloredUsername.midRef(startIndex, endIndex - startIndex);
|
||||||
|
|
||||||
|
index = endIndex;
|
||||||
|
} while (index > 0 && index < uncoloredUsername.size());
|
||||||
|
|
||||||
|
return coloredUsername;
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i + 1 < users.size(); i++) {
|
for (size_t i = 0; i + 1 < users.size(); i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user