From 65846fe1c712c767c185ded93ab0a4dc70f3337c Mon Sep 17 00:00:00 2001 From: fourtf Date: Wed, 23 May 2018 13:31:55 +0200 Subject: [PATCH] scaling emotes and badges --- src/messages/image.cpp | 6 +++-- .../layouts/messagelayoutcontainer.cpp | 10 +++++++- .../layouts/messagelayoutcontainer.hpp | 1 + src/messages/messageelement.cpp | 4 ++-- src/singletons/settingsmanager.cpp | 2 ++ src/widgets/settingspages/appearancepage.cpp | 23 +++++++++++++++++++ 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/messages/image.cpp b/src/messages/image.cpp index aec60a572..ce92e815b 100644 --- a/src/messages/image.cpp +++ b/src/messages/image.cpp @@ -240,7 +240,8 @@ int Image::getWidth() const int Image::getScaledWidth() const { - return static_cast(this->getWidth() * this->scale); + return static_cast(this->getWidth() * this->scale * + getApp()->settings->emoteScale.getValue()); } int Image::getHeight() const @@ -253,7 +254,8 @@ int Image::getHeight() const int Image::getScaledHeight() const { - return static_cast(this->getHeight() * this->scale); + return static_cast(this->getHeight() * this->scale * + getApp()->settings->emoteScale.getValue()); } } // namespace messages diff --git a/src/messages/layouts/messagelayoutcontainer.cpp b/src/messages/layouts/messagelayoutcontainer.cpp index dbb1ee9c1..e5e3b474b 100644 --- a/src/messages/layouts/messagelayoutcontainer.cpp +++ b/src/messages/layouts/messagelayoutcontainer.cpp @@ -36,6 +36,9 @@ void MessageLayoutContainer::begin(int _width, float _scale, Message::MessageFla this->width = _width; this->scale = _scale; this->flags = _flags; + auto mediumFontMetrics = getApp()->fonts->getFontMetrics(FontStyle::ChatMedium, _scale); + this->textLineHeight = mediumFontMetrics.height(); + this->spaceWidth = mediumFontMetrics.width(' '); } void MessageLayoutContainer::clear() @@ -129,6 +132,11 @@ void MessageLayoutContainer::breakLine() yExtra = (COMPACT_EMOTES_OFFSET / 2) * this->scale; } + // if (element->getCreator().getFlags() & MessageElement::Badges) { + if (element->getRect().height() < this->textLineHeight) { + yExtra -= (this->textLineHeight - element->getRect().height()) / 2; + } + element->setPosition(QPoint(element->getRect().x() + xOffset + this->margin.left, element->getRect().y() + this->lineHeight + yExtra)); } @@ -151,7 +159,7 @@ void MessageLayoutContainer::breakLine() this->height = this->currentY + (this->margin.bottom * this->scale); this->lineHeight = 0; this->line++; -} +} // namespace layouts bool MessageLayoutContainer::atStartOfLine() { diff --git a/src/messages/layouts/messagelayoutcontainer.hpp b/src/messages/layouts/messagelayoutcontainer.hpp index 6400b789d..b55c1427c 100644 --- a/src/messages/layouts/messagelayoutcontainer.hpp +++ b/src/messages/layouts/messagelayoutcontainer.hpp @@ -100,6 +100,7 @@ private: size_t lineStart = 0; int lineHeight = 0; int spaceWidth = 4; + int textLineHeight = 0; std::vector> elements; std::vector lines; diff --git a/src/messages/messageelement.cpp b/src/messages/messageelement.cpp index 4aa90c52e..d53a6a2e4 100644 --- a/src/messages/messageelement.cpp +++ b/src/messages/messageelement.cpp @@ -70,8 +70,8 @@ ImageElement::ImageElement(Image *_image, MessageElement::Flags flags) void ImageElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags) { if (_flags & this->getFlags()) { - QSize size(this->image->getWidth() * this->image->getScale() * container.getScale(), - this->image->getHeight() * this->image->getScale() * container.getScale()); + QSize size(this->image->getScaledWidth() * this->image->getScale() * container.getScale(), + this->image->getScaledHeight() * this->image->getScale() * container.getScale()); container.addElement( (new ImageLayoutElement(*this, this->image, size))->setLink(this->getLink())); diff --git a/src/singletons/settingsmanager.cpp b/src/singletons/settingsmanager.cpp index 2516df09a..7c3cbee36 100644 --- a/src/singletons/settingsmanager.cpp +++ b/src/singletons/settingsmanager.cpp @@ -41,6 +41,8 @@ void SettingManager::initialize() auto app = getApp(); app->windows->layoutVisibleChatWidgets(); }); + + this->emoteScale.connect([](auto, auto) { getApp()->windows->layoutVisibleChatWidgets(); }); } MessageElement::Flags SettingManager::getWordFlags() diff --git a/src/widgets/settingspages/appearancepage.cpp b/src/widgets/settingspages/appearancepage.cpp index 383af4dfe..0209f031c 100644 --- a/src/widgets/settingspages/appearancepage.cpp +++ b/src/widgets/settingspages/appearancepage.cpp @@ -110,6 +110,29 @@ AppearancePage::AppearancePage() emotes.append(this->createCheckBox("Enable emojis", app->settings->enableEmojis)); emotes.append( this->createCheckBox("Enable animations", app->settings->enableGifAnimations)); + + auto scaleBox = emotes.emplace(); + { + scaleBox.emplace("Emote scale:"); + + auto emoteScale = scaleBox.emplace(Qt::Horizontal); + emoteScale->setMinimum(5); + emoteScale->setMaximum(50); + + auto scaleLabel = scaleBox.emplace("1.0"); + scaleLabel->setFixedWidth(100); + QObject::connect(*emoteScale, &QSlider::valueChanged, [scaleLabel](int value) mutable { + float f = (float)value / 10.f; + scaleLabel->setText(QString::number(f)); + + getApp()->settings->emoteScale.setValue(f); + }); + + emoteScale->setValue(std::max( + 5, std::min(50, (int)(app->settings->emoteScale.getValue() * 10.f)))); + + scaleLabel->setText(QString::number(app->settings->emoteScale.getValue())); + } } layout->addStretch(1);