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:
DeepBlueV7.X 2020-05-23 01:00:35 +02:00 committed by GitHub
commit 33ba81a2e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 71 additions and 19 deletions

View file

@ -26,6 +26,7 @@ Page {
category: "user" category: "user"
property bool avatar_circles: true property bool avatar_circles: true
property string emoji_font_family: "default" property string emoji_font_family: "default"
property double font_size: Qt.application.font.pointSize
} }
Settings { Settings {
@ -33,6 +34,7 @@ Page {
category: "user/timeline" category: "user/timeline"
property bool buttons: true property bool buttons: true
property bool message_hover_highlight: false property bool message_hover_highlight: false
property bool enlarge_emoji_only_msg: false
} }
Menu { Menu {

View file

@ -6,4 +6,5 @@ MatrixText {
width: parent ? parent.width : undefined width: parent ? parent.width : undefined
height: isReply ? Math.min(chat.height / 8, implicitHeight) : undefined height: isReply ? Math.min(chat.height / 8, implicitHeight) : undefined
clip: true clip: true
font.pointSize: (timelineSettings.enlarge_emoji_only_msg && model.data.isOnlyEmoji > 0 && model.data.isOnlyEmoji < 4) ? settings.font_size * 3 : settings.font_size
} }

View file

@ -58,6 +58,8 @@ UserSettings::load()
isButtonsInTimelineEnabled_ = settings.value("user/timeline/buttons", true).toBool(); isButtonsInTimelineEnabled_ = settings.value("user/timeline/buttons", true).toBool();
isMessageHoverHighlightEnabled_ = isMessageHoverHighlightEnabled_ =
settings.value("user/timeline/message_hover_highlight", false).toBool(); 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(); isMarkdownEnabled_ = settings.value("user/markdown_enabled", true).toBool();
isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool(); isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool();
sortByImportance_ = settings.value("user/sort_by_unread", true).toBool(); sortByImportance_ = settings.value("user/sort_by_unread", true).toBool();
@ -168,6 +170,7 @@ UserSettings::save()
settings.beginGroup("timeline"); settings.beginGroup("timeline");
settings.setValue("buttons", isButtonsInTimelineEnabled_); settings.setValue("buttons", isButtonsInTimelineEnabled_);
settings.setValue("message_hover_highlight", isMessageHoverHighlightEnabled_); settings.setValue("message_hover_highlight", isMessageHoverHighlightEnabled_);
settings.setValue("enlarge_emoji_only_msg", isEnlargeEmojiOnlyMessagesEnabled_);
settings.endGroup(); settings.endGroup();
settings.setValue("avatar_circles", avatarCircles_); settings.setValue("avatar_circles", avatarCircles_);
@ -239,6 +242,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
timelineButtonsToggle_ = new Toggle{this}; timelineButtonsToggle_ = new Toggle{this};
typingNotifications_ = new Toggle{this}; typingNotifications_ = new Toggle{this};
messageHoverHighlight_ = new Toggle{this}; messageHoverHighlight_ = new Toggle{this};
enlargeEmojiOnlyMessages_ = new Toggle{this};
sortByImportance_ = new Toggle{this}; sortByImportance_ = new Toggle{this};
readReceipts_ = new Toggle{this}; readReceipts_ = new Toggle{this};
markdownEnabled_ = 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("Send messages as Markdown"), markdownEnabled_);
boxWrap(tr("Desktop notifications"), desktopNotifications_); boxWrap(tr("Desktop notifications"), desktopNotifications_);
boxWrap(tr("Highlight message on hover"), messageHoverHighlight_); boxWrap(tr("Highlight message on hover"), messageHoverHighlight_);
boxWrap(tr("Large Emoji in timeline"), enlargeEmojiOnlyMessages_);
formLayout_->addRow(uiLabel_); formLayout_->addRow(uiLabel_);
formLayout_->addRow(new HorizontalLine{this}); formLayout_->addRow(new HorizontalLine{this});
@ -472,6 +477,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
settings_->setMessageHoverHighlight(!isDisabled); settings_->setMessageHoverHighlight(!isDisabled);
}); });
connect(enlargeEmojiOnlyMessages_, &Toggle::toggled, this, [this](bool isDisabled) {
settings_->setEnlargeEmojiOnlyMessages(!isDisabled);
});
connect( connect(
sessionKeysImportBtn, &QPushButton::clicked, this, &UserSettingsPage::importSessionKeys); sessionKeysImportBtn, &QPushButton::clicked, this, &UserSettingsPage::importSessionKeys);
@ -505,6 +514,7 @@ UserSettingsPage::showEvent(QShowEvent *)
markdownEnabled_->setState(!settings_->isMarkdownEnabled()); markdownEnabled_->setState(!settings_->isMarkdownEnabled());
desktopNotifications_->setState(!settings_->hasDesktopNotifications()); desktopNotifications_->setState(!settings_->hasDesktopNotifications());
messageHoverHighlight_->setState(!settings_->isMessageHoverHighlightEnabled()); messageHoverHighlight_->setState(!settings_->isMessageHoverHighlightEnabled());
enlargeEmojiOnlyMessages_->setState(!settings_->isEnlargeEmojiOnlyMessagesEnabled());
deviceIdValue_->setText(QString::fromStdString(http::client()->device_id())); deviceIdValue_->setText(QString::fromStdString(http::client()->device_id()));
deviceFingerprintValue_->setText( deviceFingerprintValue_->setText(

View file

@ -49,6 +49,11 @@ public:
isMessageHoverHighlightEnabled_ = state; isMessageHoverHighlightEnabled_ = state;
save(); save();
} }
void setEnlargeEmojiOnlyMessages(bool state)
{
isEnlargeEmojiOnlyMessagesEnabled_ = state;
save();
}
void setTray(bool state) void setTray(bool state)
{ {
isTrayEnabled_ = state; isTrayEnabled_ = state;
@ -124,6 +129,10 @@ public:
QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; } QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; }
bool isMessageHoverHighlightEnabled() const { return isMessageHoverHighlightEnabled_; } bool isMessageHoverHighlightEnabled() const { return isMessageHoverHighlightEnabled_; }
bool isEnlargeEmojiOnlyMessagesEnabled() const
{
return isEnlargeEmojiOnlyMessagesEnabled_;
}
bool isTrayEnabled() const { return isTrayEnabled_; } bool isTrayEnabled() const { return isTrayEnabled_; }
bool isStartInTrayEnabled() const { return isStartInTrayEnabled_; } bool isStartInTrayEnabled() const { return isStartInTrayEnabled_; }
bool isGroupViewEnabled() const { return isGroupViewEnabled_; } bool isGroupViewEnabled() const { return isGroupViewEnabled_; }
@ -151,6 +160,7 @@ private:
: "system"; : "system";
QString theme_; QString theme_;
bool isMessageHoverHighlightEnabled_; bool isMessageHoverHighlightEnabled_;
bool isEnlargeEmojiOnlyMessagesEnabled_;
bool isTrayEnabled_; bool isTrayEnabled_;
bool isStartInTrayEnabled_; bool isStartInTrayEnabled_;
bool isGroupViewEnabled_; bool isGroupViewEnabled_;
@ -211,6 +221,7 @@ private:
Toggle *timelineButtonsToggle_; Toggle *timelineButtonsToggle_;
Toggle *typingNotifications_; Toggle *typingNotifications_;
Toggle *messageHoverHighlight_; Toggle *messageHoverHighlight_;
Toggle *enlargeEmojiOnlyMessages_;
Toggle *sortByImportance_; Toggle *sortByImportance_;
Toggle *readReceipts_; Toggle *readReceipts_;
Toggle *markdownEnabled_; Toggle *markdownEnabled_;

View file

@ -51,6 +51,14 @@ utils::localUser()
return QString::fromStdString(http::client()->user_id().to_string()); 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 QString
utils::replaceEmoji(const QString &body) utils::replaceEmoji(const QString &body)
{ {
@ -63,9 +71,7 @@ utils::replaceEmoji(const QString &body)
bool insideFontBlock = false; bool insideFontBlock = false;
for (auto &code : utf32_string) { for (auto &code : utf32_string) {
// TODO: Be more precise here. if (utils::codepointIsEmoji(code)) {
if ((code >= 0x2600 && code <= 0x27bf) || (code >= 0x1f300 && code <= 0x1f3ff) ||
(code >= 0x1f000 && code <= 0x1faff)) {
if (!insideFontBlock) { if (!insideFontBlock) {
fmtBody += QString("<font face=\"" + userFontFamily + "\">"); fmtBody += QString("<font face=\"" + userFontFamily + "\">");
insideFontBlock = true; insideFontBlock = true;

View file

@ -36,6 +36,9 @@ namespace utils {
using TimelineEvent = mtx::events::collections::TimelineEvents; using TimelineEvent = mtx::events::collections::TimelineEvents;
bool
codepointIsEmoji(uint code);
QString QString
replaceEmoji(const QString &body); replaceEmoji(const QString &body);

View file

@ -207,6 +207,7 @@ TimelineModel::roleNames() const
{Section, "section"}, {Section, "section"},
{Type, "type"}, {Type, "type"},
{TypeString, "typeString"}, {TypeString, "typeString"},
{IsOnlyEmoji, "isOnlyEmoji"},
{Body, "body"}, {Body, "body"},
{FormattedBody, "formattedBody"}, {FormattedBody, "formattedBody"},
{UserId, "userId"}, {UserId, "userId"},
@ -272,6 +273,22 @@ TimelineModel::data(const QString &id, int role) const
return QVariant(toRoomEventType(event)); return QVariant(toRoomEventType(event));
case TypeString: case TypeString:
return QVariant(toRoomEventTypeString(event)); 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: case Body:
return QVariant(utils::replaceEmoji(QString::fromStdString(body(event)))); return QVariant(utils::replaceEmoji(QString::fromStdString(body(event))));
case FormattedBody: { 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[Section], data(id, static_cast<int>(Section)));
m.insert(names[Type], data(id, static_cast<int>(Type))); m.insert(names[Type], data(id, static_cast<int>(Type)));
m.insert(names[TypeString], data(id, static_cast<int>(TypeString))); 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[Body], data(id, static_cast<int>(Body)));
m.insert(names[FormattedBody], data(id, static_cast<int>(FormattedBody))); m.insert(names[FormattedBody], data(id, static_cast<int>(FormattedBody)));
m.insert(names[UserId], data(id, static_cast<int>(UserId))); m.insert(names[UserId], data(id, static_cast<int>(UserId)));

View file

@ -140,6 +140,7 @@ public:
Section, Section,
Type, Type,
TypeString, TypeString,
IsOnlyEmoji,
Body, Body,
FormattedBody, FormattedBody,
UserId, UserId,