mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Merge pull request #204 from lkito/master
Added an optional feature to show bigger emoji-only messages with 3 or less emoji
This commit is contained in:
commit
33ba81a2e6
8 changed files with 71 additions and 19 deletions
|
@ -26,6 +26,7 @@ Page {
|
|||
category: "user"
|
||||
property bool avatar_circles: true
|
||||
property string emoji_font_family: "default"
|
||||
property double font_size: Qt.application.font.pointSize
|
||||
}
|
||||
|
||||
Settings {
|
||||
|
@ -33,6 +34,7 @@ Page {
|
|||
category: "user/timeline"
|
||||
property bool buttons: true
|
||||
property bool message_hover_highlight: false
|
||||
property bool enlarge_emoji_only_msg: false
|
||||
}
|
||||
|
||||
Menu {
|
||||
|
|
|
@ -6,4 +6,5 @@ MatrixText {
|
|||
width: parent ? parent.width : undefined
|
||||
height: isReply ? Math.min(chat.height / 8, implicitHeight) : undefined
|
||||
clip: true
|
||||
font.pointSize: (timelineSettings.enlarge_emoji_only_msg && model.data.isOnlyEmoji > 0 && model.data.isOnlyEmoji < 4) ? settings.font_size * 3 : settings.font_size
|
||||
}
|
||||
|
|
|
@ -58,6 +58,8 @@ UserSettings::load()
|
|||
isButtonsInTimelineEnabled_ = settings.value("user/timeline/buttons", true).toBool();
|
||||
isMessageHoverHighlightEnabled_ =
|
||||
settings.value("user/timeline/message_hover_highlight", false).toBool();
|
||||
isEnlargeEmojiOnlyMessagesEnabled_ =
|
||||
settings.value("user/timeline/enlarge_emoji_only_msg", false).toBool();
|
||||
isMarkdownEnabled_ = settings.value("user/markdown_enabled", true).toBool();
|
||||
isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool();
|
||||
sortByImportance_ = settings.value("user/sort_by_unread", true).toBool();
|
||||
|
@ -168,6 +170,7 @@ UserSettings::save()
|
|||
settings.beginGroup("timeline");
|
||||
settings.setValue("buttons", isButtonsInTimelineEnabled_);
|
||||
settings.setValue("message_hover_highlight", isMessageHoverHighlightEnabled_);
|
||||
settings.setValue("enlarge_emoji_only_msg", isEnlargeEmojiOnlyMessagesEnabled_);
|
||||
settings.endGroup();
|
||||
|
||||
settings.setValue("avatar_circles", avatarCircles_);
|
||||
|
@ -239,6 +242,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
|||
timelineButtonsToggle_ = new Toggle{this};
|
||||
typingNotifications_ = new Toggle{this};
|
||||
messageHoverHighlight_ = new Toggle{this};
|
||||
enlargeEmojiOnlyMessages_ = new Toggle{this};
|
||||
sortByImportance_ = new Toggle{this};
|
||||
readReceipts_ = new Toggle{this};
|
||||
markdownEnabled_ = new Toggle{this};
|
||||
|
@ -350,6 +354,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
|||
boxWrap(tr("Send messages as Markdown"), markdownEnabled_);
|
||||
boxWrap(tr("Desktop notifications"), desktopNotifications_);
|
||||
boxWrap(tr("Highlight message on hover"), messageHoverHighlight_);
|
||||
boxWrap(tr("Large Emoji in timeline"), enlargeEmojiOnlyMessages_);
|
||||
formLayout_->addRow(uiLabel_);
|
||||
formLayout_->addRow(new HorizontalLine{this});
|
||||
|
||||
|
@ -472,6 +477,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
|
|||
settings_->setMessageHoverHighlight(!isDisabled);
|
||||
});
|
||||
|
||||
connect(enlargeEmojiOnlyMessages_, &Toggle::toggled, this, [this](bool isDisabled) {
|
||||
settings_->setEnlargeEmojiOnlyMessages(!isDisabled);
|
||||
});
|
||||
|
||||
connect(
|
||||
sessionKeysImportBtn, &QPushButton::clicked, this, &UserSettingsPage::importSessionKeys);
|
||||
|
||||
|
@ -505,6 +514,7 @@ UserSettingsPage::showEvent(QShowEvent *)
|
|||
markdownEnabled_->setState(!settings_->isMarkdownEnabled());
|
||||
desktopNotifications_->setState(!settings_->hasDesktopNotifications());
|
||||
messageHoverHighlight_->setState(!settings_->isMessageHoverHighlightEnabled());
|
||||
enlargeEmojiOnlyMessages_->setState(!settings_->isEnlargeEmojiOnlyMessagesEnabled());
|
||||
deviceIdValue_->setText(QString::fromStdString(http::client()->device_id()));
|
||||
|
||||
deviceFingerprintValue_->setText(
|
||||
|
|
|
@ -49,6 +49,11 @@ public:
|
|||
isMessageHoverHighlightEnabled_ = state;
|
||||
save();
|
||||
}
|
||||
void setEnlargeEmojiOnlyMessages(bool state)
|
||||
{
|
||||
isEnlargeEmojiOnlyMessagesEnabled_ = state;
|
||||
save();
|
||||
}
|
||||
void setTray(bool state)
|
||||
{
|
||||
isTrayEnabled_ = state;
|
||||
|
@ -124,6 +129,10 @@ public:
|
|||
|
||||
QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; }
|
||||
bool isMessageHoverHighlightEnabled() const { return isMessageHoverHighlightEnabled_; }
|
||||
bool isEnlargeEmojiOnlyMessagesEnabled() const
|
||||
{
|
||||
return isEnlargeEmojiOnlyMessagesEnabled_;
|
||||
}
|
||||
bool isTrayEnabled() const { return isTrayEnabled_; }
|
||||
bool isStartInTrayEnabled() const { return isStartInTrayEnabled_; }
|
||||
bool isGroupViewEnabled() const { return isGroupViewEnabled_; }
|
||||
|
@ -151,6 +160,7 @@ private:
|
|||
: "system";
|
||||
QString theme_;
|
||||
bool isMessageHoverHighlightEnabled_;
|
||||
bool isEnlargeEmojiOnlyMessagesEnabled_;
|
||||
bool isTrayEnabled_;
|
||||
bool isStartInTrayEnabled_;
|
||||
bool isGroupViewEnabled_;
|
||||
|
@ -211,6 +221,7 @@ private:
|
|||
Toggle *timelineButtonsToggle_;
|
||||
Toggle *typingNotifications_;
|
||||
Toggle *messageHoverHighlight_;
|
||||
Toggle *enlargeEmojiOnlyMessages_;
|
||||
Toggle *sortByImportance_;
|
||||
Toggle *readReceipts_;
|
||||
Toggle *markdownEnabled_;
|
||||
|
|
|
@ -51,6 +51,14 @@ utils::localUser()
|
|||
return QString::fromStdString(http::client()->user_id().to_string());
|
||||
}
|
||||
|
||||
bool
|
||||
utils::codepointIsEmoji(uint code)
|
||||
{
|
||||
// TODO: Be more precise here.
|
||||
return (code >= 0x2600 && code <= 0x27bf) || (code >= 0x1f300 && code <= 0x1f3ff) ||
|
||||
(code >= 0x1f000 && code <= 0x1faff);
|
||||
}
|
||||
|
||||
QString
|
||||
utils::replaceEmoji(const QString &body)
|
||||
{
|
||||
|
@ -63,9 +71,7 @@ utils::replaceEmoji(const QString &body)
|
|||
|
||||
bool insideFontBlock = false;
|
||||
for (auto &code : utf32_string) {
|
||||
// TODO: Be more precise here.
|
||||
if ((code >= 0x2600 && code <= 0x27bf) || (code >= 0x1f300 && code <= 0x1f3ff) ||
|
||||
(code >= 0x1f000 && code <= 0x1faff)) {
|
||||
if (utils::codepointIsEmoji(code)) {
|
||||
if (!insideFontBlock) {
|
||||
fmtBody += QString("<font face=\"" + userFontFamily + "\">");
|
||||
insideFontBlock = true;
|
||||
|
|
|
@ -36,6 +36,9 @@ namespace utils {
|
|||
|
||||
using TimelineEvent = mtx::events::collections::TimelineEvents;
|
||||
|
||||
bool
|
||||
codepointIsEmoji(uint code);
|
||||
|
||||
QString
|
||||
replaceEmoji(const QString &body);
|
||||
|
||||
|
|
|
@ -207,6 +207,7 @@ TimelineModel::roleNames() const
|
|||
{Section, "section"},
|
||||
{Type, "type"},
|
||||
{TypeString, "typeString"},
|
||||
{IsOnlyEmoji, "isOnlyEmoji"},
|
||||
{Body, "body"},
|
||||
{FormattedBody, "formattedBody"},
|
||||
{UserId, "userId"},
|
||||
|
@ -272,6 +273,22 @@ TimelineModel::data(const QString &id, int role) const
|
|||
return QVariant(toRoomEventType(event));
|
||||
case TypeString:
|
||||
return QVariant(toRoomEventTypeString(event));
|
||||
case IsOnlyEmoji: {
|
||||
QString qBody = QString::fromStdString(body(event));
|
||||
|
||||
QVector<uint> utf32_string = qBody.toUcs4();
|
||||
int emojiCount = 0;
|
||||
|
||||
for (auto &code : utf32_string) {
|
||||
if (utils::codepointIsEmoji(code)) {
|
||||
emojiCount++;
|
||||
} else {
|
||||
return QVariant(0);
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant(emojiCount);
|
||||
}
|
||||
case Body:
|
||||
return QVariant(utils::replaceEmoji(QString::fromStdString(body(event))));
|
||||
case FormattedBody: {
|
||||
|
@ -374,6 +391,7 @@ TimelineModel::data(const QString &id, int role) const
|
|||
// m.insert(names[Section], data(id, static_cast<int>(Section)));
|
||||
m.insert(names[Type], data(id, static_cast<int>(Type)));
|
||||
m.insert(names[TypeString], data(id, static_cast<int>(TypeString)));
|
||||
m.insert(names[IsOnlyEmoji], data(id, static_cast<int>(IsOnlyEmoji)));
|
||||
m.insert(names[Body], data(id, static_cast<int>(Body)));
|
||||
m.insert(names[FormattedBody], data(id, static_cast<int>(FormattedBody)));
|
||||
m.insert(names[UserId], data(id, static_cast<int>(UserId)));
|
||||
|
|
|
@ -140,6 +140,7 @@ public:
|
|||
Section,
|
||||
Type,
|
||||
TypeString,
|
||||
IsOnlyEmoji,
|
||||
Body,
|
||||
FormattedBody,
|
||||
UserId,
|
||||
|
|
Loading…
Reference in a new issue