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