From bd6290cd191d3f0e27fd040ec76591e626c40799 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Tue, 7 Feb 2023 08:31:07 +0100 Subject: [PATCH] - Fix display name with UTF32 emojis. - Allow to change family fonts on avatar. --- linphone-app/src/utils/Utils.cpp | 19 +++++++++++++++++++ linphone-app/src/utils/Utils.hpp | 1 + .../ui/modules/Linphone/Contact/Avatar.qml | 13 ++----------- .../Linphone/Contact/ContactDescription.qml | 3 +++ .../ui/views/App/Main/ContactEdit.qml | 1 + linphone-app/ui/views/App/Main/Contacts.qml | 2 +- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/linphone-app/src/utils/Utils.cpp b/linphone-app/src/utils/Utils.cpp index fbb44d8db..723dcf507 100644 --- a/linphone-app/src/utils/Utils.cpp +++ b/linphone-app/src/utils/Utils.cpp @@ -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 : diff --git a/linphone-app/src/utils/Utils.hpp b/linphone-app/src/utils/Utils.hpp index 4c117bcd2..75c4862df 100644 --- a/linphone-app/src/utils/Utils.hpp +++ b/linphone-app/src/utils/Utils.hpp @@ -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); diff --git a/linphone-app/ui/modules/Linphone/Contact/Avatar.qml b/linphone-app/ui/modules/Linphone/Contact/Avatar.qml index 4ef43bc6b..604815928 100644 --- a/linphone-app/ui/modules/Linphone/Contact/Avatar.qml +++ b/linphone-app/ui/modules/Linphone/Contact/Avatar.qml @@ -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 diff --git a/linphone-app/ui/modules/Linphone/Contact/ContactDescription.qml b/linphone-app/ui/modules/Linphone/Contact/ContactDescription.qml index 1b5c71930..a64846d72 100644 --- a/linphone-app/ui/modules/Linphone/Contact/ContactDescription.qml +++ b/linphone-app/ui/modules/Linphone/Contact/ContactDescription.qml @@ -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 diff --git a/linphone-app/ui/views/App/Main/ContactEdit.qml b/linphone-app/ui/views/App/Main/ContactEdit.qml index 2c2d33f8e..d627e24f4 100644 --- a/linphone-app/ui/views/App/Main/ContactEdit.qml +++ b/linphone-app/ui/views/App/Main/ContactEdit.qml @@ -132,6 +132,7 @@ ColumnLayout { forceFocus: true readOnly: !_edition text: avatar.username + font.family: SettingsModel.textMessageFont.family onEditingFinished: Logic.setUsername(text) onReadOnlyChanged: { diff --git a/linphone-app/ui/views/App/Main/Contacts.qml b/linphone-app/ui/views/App/Main/Contacts.qml index 136f005dd..ad63af0cb 100644 --- a/linphone-app/ui/views/App/Main/Contacts.qml +++ b/linphone-app/ui/views/App/Main/Contacts.qml @@ -289,7 +289,7 @@ ColumnLayout { bold: true pointSize: ContactsStyle.contact.username.pointSize } - + font.family: SettingsModel.textMessageFont.family text: $modelData.vcard.username verticalAlignment: Text.AlignVCenter }