This commit is contained in:
2017-12-17 00:06:24 +01:00
parent 86ae71f674
commit f36d346a4f
3 changed files with 22 additions and 10 deletions

View file

@ -31,28 +31,38 @@ int MessageRef::getHeight() const
}
// return true if redraw is required
bool MessageRef::layout(int width)
bool MessageRef::layout(int width, float dpiMultiplyer)
{
bool layoutRequired = false;
// check if width changed
const bool widthChanged = width != this->currentLayoutWidth;
bool widthChanged = width != this->currentLayoutWidth;
layoutRequired |= widthChanged;
this->currentLayoutWidth = width;
// check if emotes changed
const bool imagesChanged = this->emoteGeneration != EmoteManager::instance->getGeneration();
bool imagesChanged = this->emoteGeneration != EmoteManager::instance->getGeneration();
layoutRequired |= imagesChanged;
this->emoteGeneration = EmoteManager::instance->getGeneration();
// check if text changed
const bool textChanged = this->fontGeneration != FontManager::getInstance().getGeneration();
bool textChanged = this->fontGeneration != FontManager::getInstance().getGeneration();
layoutRequired |= textChanged;
this->fontGeneration = FontManager::getInstance().getGeneration();
// check if work mask changed
const bool wordMaskChanged =
bool wordMaskChanged =
this->currentWordTypes != SettingsManager::getInstance().getWordTypeMask();
layoutRequired |= wordMaskChanged;
this->currentWordTypes = SettingsManager::getInstance().getWordTypeMask();
// check if dpi changed
bool dpiChanged = this->dpiMultiplyer != dpiMultiplyer;
layoutRequired |= dpiChanged;
this->dpiMultiplyer = dpiMultiplyer;
imagesChanged |= dpiChanged;
textChanged |= dpiChanged;
// update word sizes if needed
if (imagesChanged) {
this->updateImageSizes();
@ -213,7 +223,8 @@ void MessageRef::updateTextSizes()
continue;
QFontMetrics &metrics = word.getFontMetrics();
word.setSize(metrics.width(word.getText()), metrics.height());
word.setSize((int)(metrics.width(word.getText()) * this->dpiMultiplyer),
(int)(metrics.height() * this->dpiMultiplyer));
}
}
@ -221,7 +232,7 @@ void MessageRef::updateImageSizes()
{
const int mediumTextLineHeight =
FontManager::getInstance().getFontMetrics(FontManager::Medium).height();
const qreal emoteScale = SettingsManager::getInstance().emoteScale.get();
const qreal emoteScale = SettingsManager::getInstance().emoteScale.get() * this->dpiMultiplyer;
const bool scaleEmotesByLineHeight =
SettingsManager::getInstance().scaleEmotesByLineHeight.get();

View file

@ -22,7 +22,7 @@ public:
Message *getMessage();
int getHeight() const;
bool layout(int width);
bool layout(int width, float dpiMultiplyer);
const std::vector<WordPart> &getWordParts() const;
@ -43,6 +43,7 @@ private:
int currentLayoutWidth = -1;
int fontGeneration = -1;
int emoteGeneration = -1;
float dpiMultiplyer = -1;
Word::Type currentWordTypes = Word::None;

View file

@ -127,7 +127,7 @@ void ChannelView::actuallyLayoutMessages()
for (size_t i = start; i < messages.getLength(); ++i) {
auto message = messages[i];
redrawRequired |= message->layout(layoutWidth);
redrawRequired |= message->layout(layoutWidth, this->getDpiMultiplier());
y += message->getHeight();
@ -143,7 +143,7 @@ void ChannelView::actuallyLayoutMessages()
for (std::size_t i = messages.getLength() - 1; i > 0; i--) {
auto *message = messages[i].get();
message->layout(layoutWidth);
message->layout(layoutWidth, this->getDpiMultiplier());
h -= message->getHeight();