Commit 13abc88e authored by Andreas Traczyk's avatar Andreas Traczyk

unicode: support above U+007F in for avatars and display names

Change-Id: I6921efe201324b2819f2c141c24465d8807b1f43
parent 6c7c4541
...@@ -131,15 +131,15 @@ AccountItemDelegate::paint(QPainter* painter, ...@@ -131,15 +131,15 @@ AccountItemDelegate::paint(QPainter* painter,
QVariant name = index.data(static_cast<int>(AccountListModel::Role::Alias)); QVariant name = index.data(static_cast<int>(AccountListModel::Role::Alias));
if (name.isValid()) if (name.isValid())
{ {
fontPrimary.setItalic(false);
fontPrimary.setBold(false);
pen.setColor(RingTheme::lightBlack_); pen.setColor(RingTheme::lightBlack_);
painter->setPen(pen); painter->setPen(pen);
painter->setFont(fontPrimary); QFont emojiMsgFont(QStringLiteral("Segoe UI Emoji"));
QFontMetrics fontMetrics(fontPrimary); emojiMsgFont.setPointSize(scalingRatio > 1.0 ? fontSize_ - 2 : fontSize_);
QString nameStr = fontMetrics.elidedText(name.value<QString>(), Qt::ElideRight, painter->setFont(emojiMsgFont);
QString nameStr = QFontMetrics(emojiMsgFont).elidedText(name.value<QString>(), Qt::ElideRight,
rectTexts.width() - avatarSize_ - leftPadding_ - rightPadding_ * 2); rectTexts.width() - avatarSize_ - leftPadding_ - rightPadding_ * 2);
painter->drawText(rectTexts, Qt::AlignVCenter | Qt::AlignLeft, nameStr); painter->drawText(rectTexts, Qt::AlignVCenter | Qt::AlignLeft, nameStr);
painter->setFont(fontPrimary);
} }
// Display the secondary ID under the name // Display the secondary ID under the name
......
...@@ -960,16 +960,9 @@ CallWidget::setupChatView(const lrc::api::conversation::Info& convInfo) ...@@ -960,16 +960,9 @@ CallWidget::setupChatView(const lrc::api::conversation::Info& convInfo)
} }
} catch (...) {} } catch (...) {}
ui->imNameLabel->setText(QString(tr("%1", "%1 is the contact username")) ui->imNameLabel->setText(displayName);
.arg(displayName)); ui->imIdLabel->setText(displayId);
ui->imIdLabel->setVisible(isRINGAccount && displayName != displayId);
if (isRINGAccount && displayName != displayId) {
ui->imIdLabel->show();
ui->imIdLabel->setText(QString(tr("%1", "%1 is the contact unique identifier"))
.arg(displayId));
} else {
ui->imIdLabel->hide();
}
bool shouldShowSendContactRequestBtn = !isContact && isRINGAccount; bool shouldShowSendContactRequestBtn = !isContact && isRINGAccount;
ui->sendContactRequestButton->setVisible(shouldShowSendContactRequestBtn); ui->sendContactRequestButton->setVisible(shouldShowSendContactRequestBtn);
...@@ -1355,6 +1348,7 @@ CallWidget::connectAccount(const std::string& accountId) ...@@ -1355,6 +1348,7 @@ CallWidget::connectAccount(const std::string& accountId)
default: default:
break; break;
} }
ui->smartList->update(); ui->smartList->update();
}); });
QObject::disconnect(contactAddedConnection_); QObject::disconnect(contactAddedConnection_);
......
...@@ -1833,16 +1833,19 @@ Copy and share it with your friends! ...@@ -1833,16 +1833,19 @@ Copy and share it with your friends!
</property> </property>
<property name="font"> <property name="font">
<font> <font>
<family>Segoe UI Emoji</family>
<pointsize>11</pointsize> <pointsize>11</pointsize>
<weight>50</weight> <weight>50</weight>
<italic>false</italic>
<bold>false</bold> <bold>false</bold>
<kerning>true</kerning>
</font> </font>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">color: rgb(63,63,63);</string> <string notr="true">color: rgb(63,63,63);</string>
</property> </property>
<property name="text"> <property name="text">
<string/> <string>namelabel</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
...@@ -1850,6 +1853,9 @@ Copy and share it with your friends! ...@@ -1850,6 +1853,9 @@ Copy and share it with your friends!
<property name="wordWrap"> <property name="wordWrap">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="indent">
<number>-1</number>
</property>
</widget> </widget>
</item> </item>
<item> <item>
...@@ -1875,11 +1881,14 @@ Copy and share it with your friends! ...@@ -1875,11 +1881,14 @@ Copy and share it with your friends!
<string notr="true">color: rgb(192,192,192);</string> <string notr="true">color: rgb(192,192,192);</string>
</property> </property>
<property name="text"> <property name="text">
<string/> <string>idlabel</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property> </property>
<property name="indent">
<number>2</number>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
...@@ -2053,7 +2062,7 @@ Copy and share it with your friends! ...@@ -2053,7 +2062,7 @@ Copy and share it with your friends!
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="MessageWebView" name="messageView" native="true"> <widget class="MessageWebView" name="messageView">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
...@@ -2114,6 +2123,16 @@ Copy and share it with your friends! ...@@ -2114,6 +2123,16 @@ Copy and share it with your friends!
<extends>QWidget</extends> <extends>QWidget</extends>
<header location="global">QtWebEngineWidgets/QWebEngineView</header> <header location="global">QtWebEngineWidgets/QWebEngineView</header>
</customwidget> </customwidget>
<customwidget>
<class>RingContactLineEdit</class>
<extends>QLineEdit</extends>
<header>ringcontactlineedit.h</header>
</customwidget>
<customwidget>
<class>SmartListView</class>
<extends>QTreeView</extends>
<header>smartlistview.h</header>
</customwidget>
<customwidget> <customwidget>
<class>VideoView</class> <class>VideoView</class>
<extends>QWidget</extends> <extends>QWidget</extends>
...@@ -2130,16 +2149,6 @@ Copy and share it with your friends! ...@@ -2130,16 +2149,6 @@ Copy and share it with your friends!
<extends>QWebEngineView</extends> <extends>QWebEngineView</extends>
<header>messagewebview.h</header> <header>messagewebview.h</header>
</customwidget> </customwidget>
<customwidget>
<class>RingContactLineEdit</class>
<extends>QLineEdit</extends>
<header>ringcontactlineedit.h</header>
</customwidget>
<customwidget>
<class>SmartListView</class>
<extends>QTreeView</extends>
<header>smartlistview.h</header>
</customwidget>
<customwidget> <customwidget>
<class>ConversationsFilterWidget</class> <class>ConversationsFilterWidget</class>
<extends>QWidget</extends> <extends>QWidget</extends>
......
...@@ -223,13 +223,14 @@ ConversationItemDelegate::paintConversationItem(QPainter* painter, ...@@ -223,13 +223,14 @@ ConversationItemDelegate::paintConversationItem(QPainter* painter,
// The name is displayed at the avatar's right // The name is displayed at the avatar's right
QString nameStr = index.data(static_cast<int>(SmartListModel::Role::DisplayName)).value<QString>(); QString nameStr = index.data(static_cast<int>(SmartListModel::Role::DisplayName)).value<QString>();
if (!nameStr.isNull()) { if (!nameStr.isNull()) {
font.setItalic(false);
font.setBold(false);
pen.setColor(RingTheme::lightBlack_); pen.setColor(RingTheme::lightBlack_);
painter->setPen(pen); painter->setPen(pen);
painter->setFont(font); QFont emojiMsgFont(QStringLiteral("Segoe UI Emoji"));
QString elidedNameStr = fontMetrics.elidedText(nameStr, Qt::ElideRight, rectName1.width()); emojiMsgFont.setPointSize(scalingRatio > 1.0 ? fontSize_ - 2 : fontSize_);
QString elidedNameStr = QFontMetrics(emojiMsgFont).elidedText(nameStr, Qt::ElideRight, rectName1.width());
painter->setFont(emojiMsgFont);
painter->drawText(rectName1, Qt::AlignVCenter | Qt::AlignLeft, elidedNameStr); painter->drawText(rectName1, Qt::AlignVCenter | Qt::AlignLeft, elidedNameStr);
painter->setFont(font);
} }
// Display the ID under the name // Display the ID under the name
...@@ -307,11 +308,8 @@ ConversationItemDelegate::paintConversationItem(QPainter* painter, ...@@ -307,11 +308,8 @@ ConversationItemDelegate::paintConversationItem(QPainter* painter,
} }
} }
interactionStr = QString::fromUcs4(&emojiless.at(0), emojiless.size()); interactionStr = QString::fromUcs4(&emojiless.at(0), emojiless.size());
} } else {
else {
QFont emojiMsgFont(QStringLiteral("Segoe UI Emoji")); QFont emojiMsgFont(QStringLiteral("Segoe UI Emoji"));
emojiMsgFont.setItalic(false);
emojiMsgFont.setBold(false);
emojiMsgFont.setPointSize(scalingRatio > 1.0 ? fontSize_ - 2 : fontSize_); emojiMsgFont.setPointSize(scalingRatio > 1.0 ? fontSize_ - 2 : fontSize_);
rectInfo2.setTop(rectInfo2.top() - 6); rectInfo2.setTop(rectInfo2.top() - 6);
painter->setOpacity(0.7); painter->setOpacity(0.7);
...@@ -366,12 +364,12 @@ ConversationItemDelegate::paintInvitationItem(QPainter* painter, ...@@ -366,12 +364,12 @@ ConversationItemDelegate::paintInvitationItem(QPainter* painter,
// The name is displayed at the avatar's right // The name is displayed at the avatar's right
QString nameStr = index.data(static_cast<int>(SmartListModel::Role::DisplayName)).value<QString>(); QString nameStr = index.data(static_cast<int>(SmartListModel::Role::DisplayName)).value<QString>();
if (!nameStr.isNull()) { if (!nameStr.isNull()) {
font.setItalic(false);
font.setBold(false);
pen.setColor(RingTheme::lightBlack_); pen.setColor(RingTheme::lightBlack_);
painter->setPen(pen); painter->setPen(pen);
painter->setFont(font); QFont emojiMsgFont(QStringLiteral("Segoe UI Emoji"));
QString elidedNameStr = fontMetrics.elidedText(nameStr, Qt::ElideRight, rectName1.width()); emojiMsgFont.setPointSize(scalingRatio > 1.0 ? fontSize_ - 2 : fontSize_);
QString elidedNameStr = QFontMetrics(emojiMsgFont).elidedText(nameStr, Qt::ElideRight, rectName1.width());
painter->setFont(emojiMsgFont);
painter->drawText(rectName1, Qt::AlignVCenter | Qt::AlignLeft, elidedNameStr); painter->drawText(rectName1, Qt::AlignVCenter | Qt::AlignLeft, elidedNameStr);
} }
......
...@@ -143,25 +143,22 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e) ...@@ -143,25 +143,22 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e)
style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter); style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter);
// define and set the two fonts // define and set the two fonts
QFont fontPrimary = painter.font(); QFont fontPrimary = QFont(QStringLiteral("Segoe UI Emoji"));
QFont fontSecondary = painter.font(); QFont fontSecondary = painter.font();
fontPrimary.setWeight(QFont::ExtraLight); fontPrimary.setWeight(QFont::ExtraLight);
auto scalingRatio = MainWindow::instance().getCurrentScalingRatio(); auto scalingRatio = MainWindow::instance().getCurrentScalingRatio();
if (scalingRatio > 1.0) { fontPrimary.setPointSize(scalingRatio > 1.0 ? 10 : 11);
fontPrimary.setPointSize(10); fontSecondary.setPointSize(scalingRatio > 1.0 ? 9 : 10);
fontSecondary.setPointSize(9);
} else {
fontPrimary.setPointSize(11);
fontSecondary.setPointSize(10);
}
QFontMetrics fontMetricPrimary(fontPrimary); QFontMetrics fontMetricPrimary(fontPrimary);
QFontMetrics fontMetricSecondary(fontSecondary); QFontMetrics fontMetricSecondary(fontSecondary);
painter.drawPixmap(avatarTopLeft, currentAccountAvatarImage_); painter.drawPixmap(avatarTopLeft, currentAccountAvatarImage_);
auto& accInfo = LRCInstance::getCurrentAccountInfo();
// fill in presence indicator if account is registered // fill in presence indicator if account is registered
auto accountStatus = LRCInstance::getCurrentAccountInfo().status; auto accountStatus = accInfo.status;
if (accountStatus == lrc::api::account::Status::REGISTERED) { if (accountStatus == lrc::api::account::Status::REGISTERED) {
// paint the presence indicator circle // paint the presence indicator circle
QPainterPath outerCircle, innerCircle; QPainterPath outerCircle, innerCircle;
...@@ -181,14 +178,14 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e) ...@@ -181,14 +178,14 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e)
avatarSize_ - 10); // [screen awareness] avatarSize_ - 10); // [screen awareness]
// write primary and secondary account identifiers to combobox label // write primary and secondary account identifiers to combobox label
QString primaryAccountID = QString::fromStdString(Utils::bestNameForAccount(LRCInstance::getCurrentAccountInfo())); QString primaryAccountID = QString::fromStdString(Utils::bestNameForAccount(accInfo));
painter.setFont(fontPrimary); painter.setFont(fontPrimary);
painter.setPen(RingTheme::lightBlack_); painter.setPen(RingTheme::lightBlack_);
primaryAccountID = fontMetricPrimary.elidedText(primaryAccountID, Qt::ElideRight, primaryAccountID = fontMetricPrimary.elidedText(primaryAccountID, Qt::ElideRight,
comboBoxRect.width() - elidConst - (popupPresent ? 0 : 2 * gearSize_ + 2 * voicemailSize_)); comboBoxRect.width() - elidConst - (popupPresent ? 0 : 2 * gearSize_ + 2 * voicemailSize_));
painter.drawText(comboBoxRect, Qt::AlignLeft, primaryAccountID); painter.drawText(comboBoxRect, Qt::AlignLeft, primaryAccountID);
QString secondaryAccountID = QString::fromStdString(Utils::secondBestNameForAccount(LRCInstance::getCurrentAccountInfo())); QString secondaryAccountID = QString::fromStdString(Utils::secondBestNameForAccount(accInfo));
secondaryAccountID = fontMetricSecondary.elidedText(secondaryAccountID, Qt::ElideRight, secondaryAccountID = fontMetricSecondary.elidedText(secondaryAccountID, Qt::ElideRight,
comboBoxRect.width() - elidConst - 2 - (popupPresent ? 0 : 2 * gearSize_ + 2 * voicemailSize_)); // [screen awareness] comboBoxRect.width() - elidConst - 2 - (popupPresent ? 0 : 2 * gearSize_ + 2 * voicemailSize_)); // [screen awareness]
......
...@@ -616,11 +616,27 @@ Utils::fallbackAvatar(const QSize size, const QString& canonicalUriStr, const QS ...@@ -616,11 +616,27 @@ Utils::fallbackAvatar(const QSize size, const QString& canonicalUriStr, const QS
QString letterStrCleaned(letterStr); QString letterStrCleaned(letterStr);
letterStrCleaned.remove(QRegExp("[\\n\\t\\r]")); letterStrCleaned.remove(QRegExp("[\\n\\t\\r]"));
if (!letterStr.isEmpty()) { if (!letterStr.isEmpty()) {
auto letter = letterStr.at(0).toUpper().toLatin1(); auto unicode = letterStr.toUcs4().at(0);
QFont font("Arial", avatar.height() / 2.66667, QFont::Medium); if (unicode >= 0x1F000 && unicode <= 0x1FFFF) { // is Emoticon
painter.setFont(font); auto letter = QString::fromUcs4(&unicode, 1);
painter.setPen(Qt::white); QFont font(QStringLiteral("Segoe UI Emoji"), avatar.height() / 2.66667, QFont::Medium);
painter.drawText(avatar.rect(), QString(letter), QTextOption(Qt::AlignCenter)); painter.setFont(font);
QRect emojiRect(avatar.rect());
emojiRect.moveTop(-6);
painter.drawText(emojiRect, letter, QTextOption(Qt::AlignCenter));
} else if (unicode >= 0x0000 && unicode <= 0x00FF) { // is Basic Latin
auto letter = letterStr.at(0).toUpper();
QFont font("Arial", avatar.height() / 2.66667, QFont::Medium);
painter.setFont(font);
painter.setPen(Qt::white);
painter.drawText(avatar.rect(), QString(letter), QTextOption(Qt::AlignCenter));
} else {
auto letter = QString::fromUcs4(&unicode, 1);
QFont font("Arial", avatar.height() / 2.66667, QFont::Medium);
painter.setFont(font);
painter.setPen(Qt::white);
painter.drawText(avatar.rect(), QString(letter), QTextOption(Qt::AlignCenter));
}
} else { } else {
QRect overlayRect = avatar.rect(); QRect overlayRect = avatar.rect();
qreal margin = (0.05 * overlayRect.width()); qreal margin = (0.05 * overlayRect.width());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment