- Fix display name with UTF32 emojis.

- Allow to change family fonts on avatar.
This commit is contained in:
Julien Wadel 2023-02-07 08:31:07 +01:00
parent 209ee49724
commit bd6290cd19
6 changed files with 27 additions and 12 deletions

View file

@ -121,6 +121,25 @@ QString Utils::getDisplayName(const QString& address){
return getDisplayName(interpretUrl(address));
}
QString Utils::getInitials(const QString& username){
if(username.isEmpty()) return "";
QRegularExpression regex("[\\s\\.]+");
QStringList words = username.split(regex, Qt::SkipEmptyParts);
QStringList initials;
auto str32 = words[0].toStdU32String();
std::u32string char32;
char32 += str32[0];
initials << QString::fromStdU32String(char32);
if(words.size() > 1){
str32 = words[1].toStdU32String();
char32[0] = str32[0];
initials << QString::fromStdU32String(char32);
}
return initials.join("");
}
QString Utils::toString(const LinphoneEnums::TunnelMode& mode){
switch(mode){
case LinphoneEnums::TunnelMode::TunnelModeEnable :

View file

@ -59,6 +59,7 @@ public:
Q_INVOKABLE static QString toTimeString(QDateTime date, const QString& format = "hh:mm:ss");
Q_INVOKABLE static QString toDateString(QDateTime date);
Q_INVOKABLE static QString getDisplayName(const QString& address);
Q_INVOKABLE static QString getInitials(const QString& username); // Support UTF32
Q_INVOKABLE static QString toString(const LinphoneEnums::TunnelMode& mode);
Q_INVOKABLE static bool isMe(const QString& address);
Q_INVOKABLE static bool isAnimatedImage(const QString& path);

View file

@ -33,17 +33,7 @@ Item {
}
function _computeInitials () {
// Do not use charAt from string because it doesn't support all UTF8 characters.
var result = username.match(_initialsRegex)
if (!result) {
var usernameArray = Array.from(username)
return usernameArray.length > 0 ? usernameArray[0].toUpperCase() : ''
}
return Array.from(result[1])[0].toUpperCase() + (
result.length > 1 && result[2].length > 0
? Array.from(result[2])[0].toUpperCase()
: ''
)
return UtilsCpp.getInitials(username);
}
// ---------------------------------------------------------------------------
@ -67,6 +57,7 @@ Item {
id: initialsText
anchors.centerIn: parent
color: isDarkMode ? AvatarStyle.initials.darkModeColor : AvatarStyle.initials.color
font.family: SettingsModel.textMessageFont.family
font.pointSize: {
var width

View file

@ -37,6 +37,7 @@ Column {
property string fullText
anchors.horizontalCenter: (horizontalTextAlignment == Text.AlignHCenter ? parent.horizontalCenter : undefined)
color: titleColor
font.family: SettingsModel.textMessageFont.family
font.weight: contactDescriptionStyle.title.weight
font.pointSize: contactDescriptionStyle.title.pointSize
horizontalAlignment: horizontalTextAlignment
@ -52,6 +53,7 @@ Column {
Text{// Workaround to get implicitWidth from text without eliding
id: titleImplicitWidthWorkaround
text: title.fullText
font.family: SettingsModel.textMessageFont.family
font.weight: title.font.weight
font.pointSize: title.font.pointSize
visible: false
@ -89,6 +91,7 @@ Column {
property string fullText
anchors.horizontalCenter: (horizontalTextAlignment == Text.AlignHCenter ? parent.horizontalCenter : undefined)
color: subtitleColor
font.family: SettingsModel.textMessageFont.family
font.weight: contactDescriptionStyle.subtitle.weight
font.pointSize: contactDescriptionStyle.subtitle.pointSize
horizontalAlignment: horizontalTextAlignment

View file

@ -132,6 +132,7 @@ ColumnLayout {
forceFocus: true
readOnly: !_edition
text: avatar.username
font.family: SettingsModel.textMessageFont.family
onEditingFinished: Logic.setUsername(text)
onReadOnlyChanged: {

View file

@ -289,7 +289,7 @@ ColumnLayout {
bold: true
pointSize: ContactsStyle.contact.username.pointSize
}
font.family: SettingsModel.textMessageFont.family
text: $modelData.vcard.username
verticalAlignment: Text.AlignVCenter
}