scaling emotes and badges

This commit is contained in:
fourtf 2018-05-23 13:31:55 +02:00
parent 75627bc037
commit 65846fe1c7
6 changed files with 41 additions and 5 deletions

View file

@ -240,7 +240,8 @@ int Image::getWidth() const
int Image::getScaledWidth() const
{
return static_cast<int>(this->getWidth() * this->scale);
return static_cast<int>(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<int>(this->getHeight() * this->scale);
return static_cast<int>(this->getHeight() * this->scale *
getApp()->settings->emoteScale.getValue());
}
} // namespace messages

View file

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

View file

@ -100,6 +100,7 @@ private:
size_t lineStart = 0;
int lineHeight = 0;
int spaceWidth = 4;
int textLineHeight = 0;
std::vector<std::unique_ptr<MessageLayoutElement>> elements;
std::vector<Line> lines;

View file

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

View file

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

View file

@ -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<QHBoxLayout>();
{
scaleBox.emplace<QLabel>("Emote scale:");
auto emoteScale = scaleBox.emplace<QSlider>(Qt::Horizontal);
emoteScale->setMinimum(5);
emoteScale->setMaximum(50);
auto scaleLabel = scaleBox.emplace<QLabel>("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<int>(
5, std::min<int>(50, (int)(app->settings->emoteScale.getValue() * 10.f))));
scaleLabel->setText(QString::number(app->settings->emoteScale.getValue()));
}
}
layout->addStretch(1);