From d1f81ab50bbd56b9ba77cb0713cb7fbd0d161161 Mon Sep 17 00:00:00 2001 From: pajlada Date: Mon, 26 Apr 2021 00:25:23 +0200 Subject: [PATCH] Add an option to remove spaces between emotes (#2684) This feature is disabled by default and can be enabled in the settings. Co-authored-by: Mm2PL --- CHANGELOG.md | 1 + src/Application.cpp | 4 ++ .../layouts/MessageLayoutContainer.cpp | 41 +++++++++++++++++++ src/messages/layouts/MessageLayoutElement.cpp | 10 +++++ src/messages/layouts/MessageLayoutElement.hpp | 3 ++ src/singletons/Settings.hpp | 2 + src/widgets/settingspages/GeneralPage.cpp | 2 + 7 files changed, 63 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4e78e084..b890047b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Minor: Added image links to the badge context menu. (#2667) - Minor: Added a setting to hide Twitch Predictions badges. (#2668) +- Minor: Optionally remove spaces between emotes, originally made for Mm2PL/Dankerino. (#2651) - Bugfix: Added missing Copy/Open link context menu entries to emotes in Emote Picker. (#2670) - Bugfix: Fixed visual glitch with smooth scrolling. (#2084) diff --git a/src/Application.cpp b/src/Application.cpp index 3371469fd..843f39f86 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -164,6 +164,10 @@ int Application::run(QApplication &qtApp) this->windows->forceLayoutChannelViews(); }); + getSettings()->removeSpacesBetweenEmotes.connect([this] { + this->windows->forceLayoutChannelViews(); + }); + return qtApp.exec(); } diff --git a/src/messages/layouts/MessageLayoutContainer.cpp b/src/messages/layouts/MessageLayoutContainer.cpp index 6c0096b50..c4cc4fa02 100644 --- a/src/messages/layouts/MessageLayoutContainer.cpp +++ b/src/messages/layouts/MessageLayoutContainer.cpp @@ -93,6 +93,37 @@ void MessageLayoutContainer::_addElement(MessageLayoutElement *element, return; } + // This lambda contains the logic for when to step one 'space width' back for compact x emotes + auto shouldRemoveSpaceBetweenEmotes = [this]() -> bool { + if (this->elements_.empty()) + { + // No previous element found + return false; + } + + const auto &lastElement = this->elements_.back(); + + if (!lastElement) + { + return false; + } + + if (!lastElement->hasTrailingSpace()) + { + // Last element did not have a trailing space, so we don't need to do anything. + return false; + } + + if (lastElement->getLine() != this->line_) + { + // Last element was not on the same line as us + return false; + } + + // Returns true if the last element was an emote image + return lastElement->getFlags().has(MessageElementFlag::EmoteImages); + }; + // top margin if (this->elements_.size() == 0) { @@ -133,11 +164,21 @@ void MessageLayoutContainer::_addElement(MessageLayoutElement *element, yOffset -= (this->margin.top * this->scale_); } + if (getSettings()->removeSpacesBetweenEmotes && + element->getFlags().hasAny({MessageElementFlag::EmoteImages}) && + shouldRemoveSpaceBetweenEmotes()) + { + // Move cursor one 'space width' to the left to combine hug the previous emote + this->currentX_ -= this->spaceWidth_; + } + // set move element element->setPosition( QPoint(this->currentX_ + xOffset, this->currentY_ - element->getRect().height() + yOffset)); + element->setLine(this->line_); + // add element this->elements_.push_back(std::unique_ptr(element)); diff --git a/src/messages/layouts/MessageLayoutElement.cpp b/src/messages/layouts/MessageLayoutElement.cpp index f6b91c3b6..62b9e16db 100644 --- a/src/messages/layouts/MessageLayoutElement.cpp +++ b/src/messages/layouts/MessageLayoutElement.cpp @@ -47,6 +47,16 @@ bool MessageLayoutElement::hasTrailingSpace() const return this->trailingSpace; } +int MessageLayoutElement::getLine() const +{ + return this->line_; +} + +void MessageLayoutElement::setLine(int line) +{ + this->line_ = line; +} + MessageLayoutElement *MessageLayoutElement::setTrailingSpace(bool value) { this->trailingSpace = value; diff --git a/src/messages/layouts/MessageLayoutElement.hpp b/src/messages/layouts/MessageLayoutElement.hpp index fd711af88..2695eabfe 100644 --- a/src/messages/layouts/MessageLayoutElement.hpp +++ b/src/messages/layouts/MessageLayoutElement.hpp @@ -29,6 +29,8 @@ public: MessageElement &getCreator() const; void setPosition(QPoint point); bool hasTrailingSpace() const; + int getLine() const; + void setLine(int line); MessageLayoutElement *setTrailingSpace(bool value); MessageLayoutElement *setLink(const Link &link_); @@ -54,6 +56,7 @@ private: QRect rect_; Link link_; MessageElement &creator_; + int line_{}; }; // IMAGE diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 2283135c4..bd636848e 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -176,6 +176,8 @@ public: QStringSetting emojiSet = {"/emotes/emojiSet", "Twitter"}; BoolSetting stackBits = {"/emotes/stackBits", false}; + BoolSetting removeSpacesBetweenEmotes = { + "/emotes/removeSpacesBetweenEmotes", false}; /// Links BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false}; diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 7c7c1ad25..3d64c2151 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -307,6 +307,8 @@ void GeneralPage::initLayout(GeneralPageView &layout) return fuzzyToFloat(args.value, 1.f); }); + layout.addCheckbox("Remove spaces between emotes", + s.removeSpacesBetweenEmotes); layout.addDropdown( "Show info on hover", {"Don't show", "Always show", "Hold shift"}, s.emotesTooltipPreview,