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 <jakis128@gmail.com>
This commit is contained in:
pajlada 2021-04-26 00:25:23 +02:00 committed by GitHub
parent 3ad1f109ac
commit d1f81ab50b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 63 additions and 0 deletions

View file

@ -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)

View file

@ -164,6 +164,10 @@ int Application::run(QApplication &qtApp)
this->windows->forceLayoutChannelViews();
});
getSettings()->removeSpacesBetweenEmotes.connect([this] {
this->windows->forceLayoutChannelViews();
});
return qtApp.exec();
}

View file

@ -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<MessageLayoutElement>(element));

View file

@ -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;

View file

@ -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

View file

@ -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};

View file

@ -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<int>(
"Show info on hover", {"Don't show", "Always show", "Hold shift"},
s.emotesTooltipPreview,