diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 6bd49058..1ac3f738 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -51,6 +51,7 @@ UserSettings::load() isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool(); theme_ = settings.value("user/theme", "light").toString(); font_ = settings.value("user/font_family", "default").toString(); + emojiFont_ = settings.value("user/emoji_font_family", "default").toString(); baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble(); applyTheme(); @@ -70,6 +71,13 @@ UserSettings::setFontFamily(QString family) save(); } +void +UserSettings::setEmojiFontFamily(QString family) +{ + emojiFont_ = family; + save(); +} + void UserSettings::setTheme(QString theme) { @@ -115,6 +123,8 @@ UserSettings::save() settings.setValue("desktop_notifications", hasDesktopNotifications_); settings.setValue("theme", theme()); settings.setValue("font_family", font_); + settings.setValue("emoji_font_family", emojiFont_); + settings.endGroup(); } @@ -230,22 +240,41 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge fontSizeOptionLayout->addWidget(fontSizeCombo_, 0, Qt::AlignRight); auto fontFamilyOptionLayout = new QHBoxLayout; + auto emojiFontFamilyOptionLayout = new QHBoxLayout; fontFamilyOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); - auto fontFamilyLabel = new QLabel(tr("Font Family"), this); + emojiFontFamilyOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); + auto fontFamilyLabel = new QLabel(tr("Font Family"), this); + auto emojiFamilyLabel = new QLabel(tr("Emoji Font Famly"), this); fontFamilyLabel->setFont(font); - fontSelectionCombo_ = new QComboBox(this); + emojiFamilyLabel->setFont(font); + fontSelectionCombo_ = new QComboBox(this); + emojiFontSelectionCombo_ = new QComboBox(this); QFontDatabase fontDb; auto fontFamilies = fontDb.families(); + // TODO: Is there a way to limit to just emojis, rather than + // all emoji fonts? + auto emojiFamilies = fontDb.families(QFontDatabase::Symbol); + for (const auto &family : fontFamilies) { fontSelectionCombo_->addItem(family); } + for (const auto &family : emojiFamilies) { + emojiFontSelectionCombo_->addItem(family); + } + int fontIndex = fontSelectionCombo_->findText(settings_->font()); fontSelectionCombo_->setCurrentIndex(fontIndex); + fontIndex = emojiFontSelectionCombo_->findText(settings_->emojiFont()); + emojiFontSelectionCombo_->setCurrentIndex(fontIndex); + fontFamilyOptionLayout->addWidget(fontFamilyLabel); fontFamilyOptionLayout->addWidget(fontSelectionCombo_, 0, Qt::AlignRight); + emojiFontFamilyOptionLayout->addWidget(emojiFamilyLabel); + emojiFontFamilyOptionLayout->addWidget(emojiFontSelectionCombo_, 0, Qt::AlignRight); + auto themeOptionLayout_ = new QHBoxLayout; themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin); auto themeLabel_ = new QLabel(tr("Theme"), this); @@ -346,11 +375,14 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge #if defined(Q_OS_MAC) scaleFactorLabel->hide(); scaleFactorCombo_->hide(); + emojiFamilyLabel->hide(); + emojiFontSelectionCombo_->hide(); #endif mainLayout_->addLayout(scaleFactorOptionLayout); mainLayout_->addLayout(fontSizeOptionLayout); mainLayout_->addLayout(fontFamilyOptionLayout); + mainLayout_->addLayout(emojiFontFamilyOptionLayout); mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addLayout(themeOptionLayout_); mainLayout_->addWidget(new HorizontalLine(this)); @@ -393,6 +425,9 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge connect(fontSelectionCombo_, static_cast(&QComboBox::activated), [this](const QString &family) { settings_->setFontFamily(family.trimmed()); }); + connect(emojiFontSelectionCombo_, + static_cast(&QComboBox::activated), + [this](const QString &family) { settings_->setEmojiFontFamily(family.trimmed()); }); connect(trayToggle_, &Toggle::toggled, this, [this](bool isDisabled) { settings_->setTray(!isDisabled); if (isDisabled) { diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index 900f57e4..8b782213 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -56,6 +56,7 @@ public: void setFontSize(double size); void setFontFamily(QString family); + void setEmojiFontFamily(QString family); void setGroupView(bool state) { @@ -93,6 +94,8 @@ public: bool hasDesktopNotifications() const { return hasDesktopNotifications_; } double fontSize() const { return baseFontSize_; } QString font() const { return font_; } + QString emojiFont() const { return emojiFont_; } + signals: void groupViewStateChanged(bool state); @@ -107,6 +110,8 @@ private: bool hasDesktopNotifications_; double baseFontSize_; QString font_; + QString emojiFont_; + }; class HorizontalLine : public QFrame @@ -160,6 +165,7 @@ private: QComboBox *scaleFactorCombo_; QComboBox *fontSizeCombo_; QComboBox *fontSelectionCombo_; + QComboBox *emojiFontSelectionCombo_; int sideMargin_ = 0; }; diff --git a/src/emoji/ItemDelegate.cpp b/src/emoji/ItemDelegate.cpp index 304ab023..890e334a 100644 --- a/src/emoji/ItemDelegate.cpp +++ b/src/emoji/ItemDelegate.cpp @@ -17,6 +17,7 @@ #include #include +#include #include "emoji/ItemDelegate.h" @@ -43,9 +44,17 @@ ItemDelegate::paint(QPainter *painter, auto emoji = index.data(Qt::UserRole).toString(); + QSettings settings; + QFont font; - font.setFamily("emoji"); - font.setPixelSize(48); + QString userFontFamily = settings.value("user/emoji_font_family", "emoji").toString(); + if (!userFontFamily.isEmpty()) { + font.setFamily(userFontFamily); + } else { + font.setFamily("emoji"); + } + + font.setPixelSize(36); painter->setFont(font); if (option.state & QStyle::State_MouseOver) { painter->setBackgroundMode(Qt::OpaqueMode); diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp index 22bdaaa2..cf5d68c6 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp @@ -727,7 +727,7 @@ TimelineItem::generateUserName(const QString &user_id, const QString &displaynam userName_ = new QLabel(this); userName_->setFont(usernameFont); - userName_->setText(fm.elidedText(sender, Qt::ElideRight, 500)); + userName_->setText(replaceEmoji(fm.elidedText(sender, Qt::ElideRight, 500))); userName_->setToolTip(user_id); userName_->setToolTipDuration(1500); userName_->setAttribute(Qt::WA_Hover); @@ -780,11 +780,15 @@ TimelineItem::replaceEmoji(const QString &body) QVector utf32_string = body.toUcs4(); + QSettings settings; + QString userFontFamily = settings.value("user/emoji_font_family", "emoji").toString(); + for (auto &code : utf32_string) { // TODO: Be more precise here. if (code > 9000) - fmtBody += QString("") + - QString::fromUcs4(&code, 1) + ""; + fmtBody += + QString("") + + QString::fromUcs4(&code, 1) + ""; else fmtBody += QString::fromUcs4(&code, 1); }