Use Qt's High-DPI scaling on Windows (#4868)
This commit is contained in:
@@ -155,8 +155,8 @@ void EmoteElement::addToContainer(MessageLayoutContainer &container,
|
||||
{
|
||||
if (flags.has(MessageElementFlag::EmoteImages))
|
||||
{
|
||||
auto image =
|
||||
this->emote_->images.getImageOrLoaded(container.getScale());
|
||||
auto image = this->emote_->images.getImageOrLoaded(
|
||||
container.getImageScale());
|
||||
if (image->isEmpty())
|
||||
{
|
||||
return;
|
||||
@@ -210,7 +210,7 @@ void LayeredEmoteElement::addToContainer(MessageLayoutContainer &container,
|
||||
{
|
||||
if (flags.has(MessageElementFlag::EmoteImages))
|
||||
{
|
||||
auto images = this->getLoadedImages(container.getScale());
|
||||
auto images = this->getLoadedImages(container.getImageScale());
|
||||
if (images.empty())
|
||||
{
|
||||
return;
|
||||
@@ -364,7 +364,7 @@ void BadgeElement::addToContainer(MessageLayoutContainer &container,
|
||||
if (flags.hasAny(this->getFlags()))
|
||||
{
|
||||
auto image =
|
||||
this->emote_->images.getImageOrLoaded(container.getScale());
|
||||
this->emote_->images.getImageOrLoaded(container.getImageScale());
|
||||
if (image->isEmpty())
|
||||
{
|
||||
return;
|
||||
@@ -798,7 +798,7 @@ void ScalingImageElement::addToContainer(MessageLayoutContainer &container,
|
||||
if (flags.hasAny(this->getFlags()))
|
||||
{
|
||||
const auto &image =
|
||||
this->images_.getImageOrLoaded(container.getScale());
|
||||
this->images_.getImageOrLoaded(container.getImageScale());
|
||||
if (image->isEmpty())
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -74,7 +74,8 @@ int MessageLayout::getWidth() const
|
||||
|
||||
// Layout
|
||||
// return true if redraw is required
|
||||
bool MessageLayout::layout(int width, float scale, MessageElementFlags flags,
|
||||
bool MessageLayout::layout(int width, float scale, float imageScale,
|
||||
MessageElementFlags flags,
|
||||
bool shouldInvalidateBuffer)
|
||||
{
|
||||
// BenchmarkGuard benchmark("MessageLayout::layout()");
|
||||
@@ -106,6 +107,8 @@ bool MessageLayout::layout(int width, float scale, MessageElementFlags flags,
|
||||
// check if dpi changed
|
||||
layoutRequired |= this->scale_ != scale;
|
||||
this->scale_ = scale;
|
||||
layoutRequired |= this->imageScale_ != imageScale;
|
||||
this->imageScale_ = imageScale;
|
||||
|
||||
if (!layoutRequired)
|
||||
{
|
||||
@@ -148,7 +151,8 @@ void MessageLayout::actuallyLayout(int width, MessageElementFlags flags)
|
||||
bool hideSimilar = getSettings()->hideSimilar;
|
||||
bool hideReplies = !flags.has(MessageElementFlag::RepliedMessage);
|
||||
|
||||
this->container_.beginLayout(width, this->scale_, messageFlags);
|
||||
this->container_.beginLayout(width, this->scale_, this->imageScale_,
|
||||
messageFlags);
|
||||
|
||||
for (const auto &element : this->message_->elements)
|
||||
{
|
||||
@@ -288,16 +292,11 @@ QPixmap *MessageLayout::ensureBuffer(QPainter &painter, int width)
|
||||
}
|
||||
|
||||
// Create new buffer
|
||||
#if defined(Q_OS_MACOS) || defined(Q_OS_LINUX)
|
||||
this->buffer_ = std::make_unique<QPixmap>(
|
||||
int(width * painter.device()->devicePixelRatioF()),
|
||||
int(this->container_.getHeight() *
|
||||
painter.device()->devicePixelRatioF()));
|
||||
this->buffer_->setDevicePixelRatio(painter.device()->devicePixelRatioF());
|
||||
#else
|
||||
this->buffer_ = std::make_unique<QPixmap>(
|
||||
width, std::max(16, this->container_.getHeight()));
|
||||
#endif
|
||||
|
||||
this->bufferValid_ = false;
|
||||
DebugCount::increase("message drawing buffers");
|
||||
|
||||
@@ -56,8 +56,8 @@ public:
|
||||
|
||||
MessageLayoutFlags flags;
|
||||
|
||||
bool layout(int width, float scale_, MessageElementFlags flags,
|
||||
bool shouldInvalidateBuffer);
|
||||
bool layout(int width, float scale_, float imageScale,
|
||||
MessageElementFlags flags, bool shouldInvalidateBuffer);
|
||||
|
||||
// Painting
|
||||
MessagePaintResult paint(const MessagePaintContext &ctx);
|
||||
@@ -128,6 +128,7 @@ private:
|
||||
int currentLayoutWidth_ = -1;
|
||||
int layoutState_ = -1;
|
||||
float scale_ = -1;
|
||||
float imageScale_ = -1.F;
|
||||
MessageElementFlags currentWordFlags_;
|
||||
|
||||
#ifdef FOURTF
|
||||
|
||||
@@ -30,7 +30,7 @@ constexpr const QMargins MARGIN{8, 4, 8, 4};
|
||||
namespace chatterino {
|
||||
|
||||
void MessageLayoutContainer::beginLayout(int width, float scale,
|
||||
MessageFlags flags)
|
||||
float imageScale, MessageFlags flags)
|
||||
{
|
||||
this->elements_.clear();
|
||||
this->lines_.clear();
|
||||
@@ -45,6 +45,7 @@ void MessageLayoutContainer::beginLayout(int width, float scale,
|
||||
this->width_ = width;
|
||||
this->height_ = 0;
|
||||
this->scale_ = scale;
|
||||
this->imageScale_ = imageScale;
|
||||
this->flags_ = flags;
|
||||
auto mediumFontMetrics =
|
||||
getIApp()->getFonts()->getFontMetrics(FontStyle::ChatMedium, scale);
|
||||
@@ -526,6 +527,11 @@ float MessageLayoutContainer::getScale() const
|
||||
return this->scale_;
|
||||
}
|
||||
|
||||
float MessageLayoutContainer::getImageScale() const
|
||||
{
|
||||
return this->imageScale_;
|
||||
}
|
||||
|
||||
bool MessageLayoutContainer::isCollapsed() const
|
||||
{
|
||||
return this->isCollapsed_;
|
||||
|
||||
@@ -32,7 +32,8 @@ struct MessageLayoutContainer {
|
||||
* This will reset all line calculations, and will be considered incomplete
|
||||
* until the accompanying end function has been called
|
||||
*/
|
||||
void beginLayout(int width_, float scale_, MessageFlags flags_);
|
||||
void beginLayout(int width, float scale, float imageScale,
|
||||
MessageFlags flags);
|
||||
|
||||
/**
|
||||
* Finish the layout process of this message
|
||||
@@ -146,6 +147,11 @@ struct MessageLayoutContainer {
|
||||
*/
|
||||
float getScale() const;
|
||||
|
||||
/**
|
||||
* Returns the image scale
|
||||
*/
|
||||
float getImageScale() const;
|
||||
|
||||
/**
|
||||
* Returns true if this message is collapsed
|
||||
*/
|
||||
@@ -270,6 +276,10 @@ private:
|
||||
|
||||
// variables
|
||||
float scale_ = 1.F;
|
||||
/**
|
||||
* Scale factor for images
|
||||
*/
|
||||
float imageScale_ = 1.F;
|
||||
int width_ = 0;
|
||||
MessageFlags flags_{};
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user