From f36d346a4f2845ccc931198afb1c9178115154c5 Mon Sep 17 00:00:00 2001
From:  <tf.four@gmail.com>
Date: Sun, 17 Dec 2017 00:06:24 +0100
Subject: [PATCH] dpi

---
 src/messages/messageref.cpp        | 25 ++++++++++++++++++-------
 src/messages/messageref.hpp        |  3 ++-
 src/widgets/helper/channelview.cpp |  4 ++--
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/messages/messageref.cpp b/src/messages/messageref.cpp
index 8eb847ad1..49da574cf 100644
--- a/src/messages/messageref.cpp
+++ b/src/messages/messageref.cpp
@@ -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();
 
diff --git a/src/messages/messageref.hpp b/src/messages/messageref.hpp
index 83de6b9db..76032761e 100644
--- a/src/messages/messageref.hpp
+++ b/src/messages/messageref.hpp
@@ -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;
 
diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp
index 551092048..e93fc703d 100644
--- a/src/widgets/helper/channelview.cpp
+++ b/src/widgets/helper/channelview.cpp
@@ -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();