Improve pattern wallpaper preview in Settings.

This commit is contained in:
John Preston 2021-08-20 16:14:09 +03:00
parent 1e8e163bb1
commit aaf0015be4

View file

@ -57,6 +57,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "facades.h" #include "facades.h"
#include "styles/style_settings.h" #include "styles/style_settings.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
#include "styles/style_window.h"
namespace Settings { namespace Settings {
namespace { namespace {
@ -581,26 +582,28 @@ void BackgroundRow::updateImage() {
} }
const auto &prepared = background->prepared(); const auto &prepared = background->prepared();
if (!prepared.isNull()) { if (!prepared.isNull()) {
const auto sx = (prepared.width() > prepared.height()) const auto pattern = background->paper().isPattern();
? ((prepared.width() - prepared.height()) / 2) const auto w = prepared.width();
: 0; const auto h = prepared.height();
const auto sy = (prepared.height() > prepared.width()) const auto use = [&] {
? ((prepared.height() - prepared.width()) / 2) if (!pattern) {
: 0; return std::min(w, h);
const auto s = (prepared.width() > prepared.height()) }
? prepared.height() const auto scaledw = w * st::windowMinHeight / h;
: prepared.width(); const auto result = (w * size) / scaledw;
return std::min({ result, w, h });
}();
p.drawImage( p.drawImage(
QRect(0, 0, size, size), QRect(0, 0, size, size),
prepared, prepared,
QRect(sx, sy, s, s)); QRect((w - use) / 2, (h - use) / 2, use, use));
} }
if (!gradient.isNull() if (!gradient.isNull()
&& !prepared.isNull() && !prepared.isNull()
&& patternOpacity < 0. && patternOpacity < 0.
&& patternOpacity > -1.) { && patternOpacity > -1.) {
p.setCompositionMode(QPainter::CompositionMode_SourceOver); p.setCompositionMode(QPainter::CompositionMode_SourceOver);
p.setOpacity(patternOpacity); p.setOpacity(1. + patternOpacity);
p.fillRect(QRect(0, 0, size, size), Qt::black); p.fillRect(QRect(0, 0, size, size), Qt::black);
} }
} }