mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-29 06:08:48 +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();
|
isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool();
|
||||||
theme_ = settings.value("user/theme", "light").toString();
|
theme_ = settings.value("user/theme", "light").toString();
|
||||||
font_ = settings.value("user/font_family", "default").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();
|
baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble();
|
||||||
|
|
||||||
applyTheme();
|
applyTheme();
|
||||||
|
@ -70,6 +71,13 @@ UserSettings::setFontFamily(QString family)
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UserSettings::setEmojiFontFamily(QString family)
|
||||||
|
{
|
||||||
|
emojiFont_ = family;
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UserSettings::setTheme(QString theme)
|
UserSettings::setTheme(QString theme)
|
||||||
{
|
{
|
||||||
|
@ -115,6 +123,8 @@ UserSettings::save()
|
||||||
settings.setValue("desktop_notifications", hasDesktopNotifications_);
|
settings.setValue("desktop_notifications", hasDesktopNotifications_);
|
||||||
settings.setValue("theme", theme());
|
settings.setValue("theme", theme());
|
||||||
settings.setValue("font_family", font_);
|
settings.setValue("font_family", font_);
|
||||||
|
settings.setValue("emoji_font_family", emojiFont_);
|
||||||
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,22 +240,41 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
fontSizeOptionLayout->addWidget(fontSizeCombo_, 0, Qt::AlignRight);
|
fontSizeOptionLayout->addWidget(fontSizeCombo_, 0, Qt::AlignRight);
|
||||||
|
|
||||||
auto fontFamilyOptionLayout = new QHBoxLayout;
|
auto fontFamilyOptionLayout = new QHBoxLayout;
|
||||||
|
auto emojiFontFamilyOptionLayout = new QHBoxLayout;
|
||||||
fontFamilyOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
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);
|
fontFamilyLabel->setFont(font);
|
||||||
fontSelectionCombo_ = new QComboBox(this);
|
emojiFamilyLabel->setFont(font);
|
||||||
|
fontSelectionCombo_ = new QComboBox(this);
|
||||||
|
emojiFontSelectionCombo_ = new QComboBox(this);
|
||||||
QFontDatabase fontDb;
|
QFontDatabase fontDb;
|
||||||
auto fontFamilies = fontDb.families();
|
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) {
|
for (const auto &family : fontFamilies) {
|
||||||
fontSelectionCombo_->addItem(family);
|
fontSelectionCombo_->addItem(family);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto &family : emojiFamilies) {
|
||||||
|
emojiFontSelectionCombo_->addItem(family);
|
||||||
|
}
|
||||||
|
|
||||||
int fontIndex = fontSelectionCombo_->findText(settings_->font());
|
int fontIndex = fontSelectionCombo_->findText(settings_->font());
|
||||||
fontSelectionCombo_->setCurrentIndex(fontIndex);
|
fontSelectionCombo_->setCurrentIndex(fontIndex);
|
||||||
|
|
||||||
|
fontIndex = emojiFontSelectionCombo_->findText(settings_->emojiFont());
|
||||||
|
emojiFontSelectionCombo_->setCurrentIndex(fontIndex);
|
||||||
|
|
||||||
fontFamilyOptionLayout->addWidget(fontFamilyLabel);
|
fontFamilyOptionLayout->addWidget(fontFamilyLabel);
|
||||||
fontFamilyOptionLayout->addWidget(fontSelectionCombo_, 0, Qt::AlignRight);
|
fontFamilyOptionLayout->addWidget(fontSelectionCombo_, 0, Qt::AlignRight);
|
||||||
|
|
||||||
|
emojiFontFamilyOptionLayout->addWidget(emojiFamilyLabel);
|
||||||
|
emojiFontFamilyOptionLayout->addWidget(emojiFontSelectionCombo_, 0, Qt::AlignRight);
|
||||||
|
|
||||||
auto themeOptionLayout_ = new QHBoxLayout;
|
auto themeOptionLayout_ = new QHBoxLayout;
|
||||||
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
|
||||||
auto themeLabel_ = new QLabel(tr("Theme"), this);
|
auto themeLabel_ = new QLabel(tr("Theme"), this);
|
||||||
|
@ -346,11 +375,14 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
#if defined(Q_OS_MAC)
|
#if defined(Q_OS_MAC)
|
||||||
scaleFactorLabel->hide();
|
scaleFactorLabel->hide();
|
||||||
scaleFactorCombo_->hide();
|
scaleFactorCombo_->hide();
|
||||||
|
emojiFamilyLabel->hide();
|
||||||
|
emojiFontSelectionCombo_->hide();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mainLayout_->addLayout(scaleFactorOptionLayout);
|
mainLayout_->addLayout(scaleFactorOptionLayout);
|
||||||
mainLayout_->addLayout(fontSizeOptionLayout);
|
mainLayout_->addLayout(fontSizeOptionLayout);
|
||||||
mainLayout_->addLayout(fontFamilyOptionLayout);
|
mainLayout_->addLayout(fontFamilyOptionLayout);
|
||||||
|
mainLayout_->addLayout(emojiFontFamilyOptionLayout);
|
||||||
mainLayout_->addWidget(new HorizontalLine(this));
|
mainLayout_->addWidget(new HorizontalLine(this));
|
||||||
mainLayout_->addLayout(themeOptionLayout_);
|
mainLayout_->addLayout(themeOptionLayout_);
|
||||||
mainLayout_->addWidget(new HorizontalLine(this));
|
mainLayout_->addWidget(new HorizontalLine(this));
|
||||||
|
@ -393,6 +425,9 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
||||||
connect(fontSelectionCombo_,
|
connect(fontSelectionCombo_,
|
||||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
||||||
[this](const QString &family) { settings_->setFontFamily(family.trimmed()); });
|
[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) {
|
connect(trayToggle_, &Toggle::toggled, this, [this](bool isDisabled) {
|
||||||
settings_->setTray(!isDisabled);
|
settings_->setTray(!isDisabled);
|
||||||
if (isDisabled) {
|
if (isDisabled) {
|
||||||
|
|
|
@ -56,6 +56,7 @@ public:
|
||||||
|
|
||||||
void setFontSize(double size);
|
void setFontSize(double size);
|
||||||
void setFontFamily(QString family);
|
void setFontFamily(QString family);
|
||||||
|
void setEmojiFontFamily(QString family);
|
||||||
|
|
||||||
void setGroupView(bool state)
|
void setGroupView(bool state)
|
||||||
{
|
{
|
||||||
|
@ -93,6 +94,8 @@ public:
|
||||||
bool hasDesktopNotifications() const { return hasDesktopNotifications_; }
|
bool hasDesktopNotifications() const { return hasDesktopNotifications_; }
|
||||||
double fontSize() const { return baseFontSize_; }
|
double fontSize() const { return baseFontSize_; }
|
||||||
QString font() const { return font_; }
|
QString font() const { return font_; }
|
||||||
|
QString emojiFont() const { return emojiFont_; }
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void groupViewStateChanged(bool state);
|
void groupViewStateChanged(bool state);
|
||||||
|
@ -107,6 +110,8 @@ private:
|
||||||
bool hasDesktopNotifications_;
|
bool hasDesktopNotifications_;
|
||||||
double baseFontSize_;
|
double baseFontSize_;
|
||||||
QString font_;
|
QString font_;
|
||||||
|
QString emojiFont_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class HorizontalLine : public QFrame
|
class HorizontalLine : public QFrame
|
||||||
|
@ -160,6 +165,7 @@ private:
|
||||||
QComboBox *scaleFactorCombo_;
|
QComboBox *scaleFactorCombo_;
|
||||||
QComboBox *fontSizeCombo_;
|
QComboBox *fontSizeCombo_;
|
||||||
QComboBox *fontSelectionCombo_;
|
QComboBox *fontSelectionCombo_;
|
||||||
|
QComboBox *emojiFontSelectionCombo_;
|
||||||
|
|
||||||
int sideMargin_ = 0;
|
int sideMargin_ = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
#include "emoji/ItemDelegate.h"
|
#include "emoji/ItemDelegate.h"
|
||||||
|
|
||||||
|
@ -43,9 +44,17 @@ ItemDelegate::paint(QPainter *painter,
|
||||||
|
|
||||||
auto emoji = index.data(Qt::UserRole).toString();
|
auto emoji = index.data(Qt::UserRole).toString();
|
||||||
|
|
||||||
|
QSettings settings;
|
||||||
|
|
||||||
QFont font;
|
QFont font;
|
||||||
font.setFamily("emoji");
|
QString userFontFamily = settings.value("user/emoji_font_family", "emoji").toString();
|
||||||
font.setPixelSize(48);
|
if (!userFontFamily.isEmpty()) {
|
||||||
|
font.setFamily(userFontFamily);
|
||||||
|
} else {
|
||||||
|
font.setFamily("emoji");
|
||||||
|
}
|
||||||
|
|
||||||
|
font.setPixelSize(36);
|
||||||
painter->setFont(font);
|
painter->setFont(font);
|
||||||
if (option.state & QStyle::State_MouseOver) {
|
if (option.state & QStyle::State_MouseOver) {
|
||||||
painter->setBackgroundMode(Qt::OpaqueMode);
|
painter->setBackgroundMode(Qt::OpaqueMode);
|
||||||
|
|
|
@ -727,7 +727,7 @@ TimelineItem::generateUserName(const QString &user_id, const QString &displaynam
|
||||||
|
|
||||||
userName_ = new QLabel(this);
|
userName_ = new QLabel(this);
|
||||||
userName_->setFont(usernameFont);
|
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_->setToolTip(user_id);
|
||||||
userName_->setToolTipDuration(1500);
|
userName_->setToolTipDuration(1500);
|
||||||
userName_->setAttribute(Qt::WA_Hover);
|
userName_->setAttribute(Qt::WA_Hover);
|
||||||
|
@ -780,11 +780,15 @@ TimelineItem::replaceEmoji(const QString &body)
|
||||||
|
|
||||||
QVector<uint> utf32_string = body.toUcs4();
|
QVector<uint> utf32_string = body.toUcs4();
|
||||||
|
|
||||||
|
QSettings settings;
|
||||||
|
QString userFontFamily = settings.value("user/emoji_font_family", "emoji").toString();
|
||||||
|
|
||||||
for (auto &code : utf32_string) {
|
for (auto &code : utf32_string) {
|
||||||
// TODO: Be more precise here.
|
// TODO: Be more precise here.
|
||||||
if (code > 9000)
|
if (code > 9000)
|
||||||
fmtBody += QString("<span style=\"font-family: emoji;\">") +
|
fmtBody +=
|
||||||
QString::fromUcs4(&code, 1) + "</span>";
|
QString("<span style=\"font-family: " + userFontFamily + ";\">") +
|
||||||
|
QString::fromUcs4(&code, 1) + "</span>";
|
||||||
else
|
else
|
||||||
fmtBody += QString::fromUcs4(&code, 1);
|
fmtBody += QString::fromUcs4(&code, 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue