mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-29 14:18:49 +03:00
Add emoji text selection option for non-mac
This commit is contained in:
parent
78ed78c410
commit
778921be8a
4 changed files with 61 additions and 7 deletions
|
@ -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<UserSettings> settings, QWidge
|
|||
fontSizeOptionLayout->addWidget(fontSizeCombo_, 0, Qt::AlignRight);
|
||||
|
||||
auto fontFamilyOptionLayout = new QHBoxLayout;
|
||||
auto emojiFontFamilyOptionLayout = new QHBoxLayout;
|
||||
fontFamilyOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
||||
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);
|
||||
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<UserSettings> 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<UserSettings> settings, QWidge
|
|||
connect(fontSelectionCombo_,
|
||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
||||
[this](const QString &family) { settings_->setFontFamily(family.trimmed()); });
|
||||
connect(emojiFontSelectionCombo_,
|
||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
||||
[this](const QString &family) { settings_->setEmojiFontFamily(family.trimmed()); });
|
||||
connect(trayToggle_, &Toggle::toggled, this, [this](bool isDisabled) {
|
||||
settings_->setTray(!isDisabled);
|
||||
if (isDisabled) {
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QSettings>
|
||||
|
||||
#include "emoji/ItemDelegate.h"
|
||||
|
||||
|
@ -43,9 +44,17 @@ ItemDelegate::paint(QPainter *painter,
|
|||
|
||||
auto emoji = index.data(Qt::UserRole).toString();
|
||||
|
||||
QSettings settings;
|
||||
|
||||
QFont font;
|
||||
QString userFontFamily = settings.value("user/emoji_font_family", "emoji").toString();
|
||||
if (!userFontFamily.isEmpty()) {
|
||||
font.setFamily(userFontFamily);
|
||||
} else {
|
||||
font.setFamily("emoji");
|
||||
font.setPixelSize(48);
|
||||
}
|
||||
|
||||
font.setPixelSize(36);
|
||||
painter->setFont(font);
|
||||
if (option.state & QStyle::State_MouseOver) {
|
||||
painter->setBackgroundMode(Qt::OpaqueMode);
|
||||
|
|
|
@ -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,10 +780,14 @@ TimelineItem::replaceEmoji(const QString &body)
|
|||
|
||||
QVector<uint> 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("<span style=\"font-family: emoji;\">") +
|
||||
fmtBody +=
|
||||
QString("<span style=\"font-family: " + userFontFamily + ";\">") +
|
||||
QString::fromUcs4(&code, 1) + "</span>";
|
||||
else
|
||||
fmtBody += QString::fromUcs4(&code, 1);
|
||||
|
|
Loading…
Reference in a new issue