Improved padding in box for share QR box on different scales.

This commit is contained in:
23rd 2024-09-10 10:30:23 +03:00
parent 8c915e6dc3
commit f6b9cc5ce1
2 changed files with 24 additions and 12 deletions

View file

@ -1126,3 +1126,4 @@ profileQrCenterSize: 34px;
profileQrBackgroundRadius: 12px; profileQrBackgroundRadius: 12px;
profileQrIcon: icon{{ "qr_mini", windowActiveTextFg }}; profileQrIcon: icon{{ "qr_mini", windowActiveTextFg }};
profileQrBackgroundMargins: margins(36px, 12px, 36px, 12px); profileQrBackgroundMargins: margins(36px, 12px, 36px, 12px);
profileQrBackgroundPadding: margins(0px, 24px, 0px, 24px);

View file

@ -101,7 +101,6 @@ void Paint(
int photoSize) { int photoSize) {
const auto usualSize = 41; const auto usualSize = 41;
const auto pixel = std::clamp(qrMaxSize / usualSize, 1, qrPixel); const auto pixel = std::clamp(qrMaxSize / usualSize, 1, qrPixel);
const auto size = (qrImage.size() / style::DevicePixelRatio());
auto hq = PainterHighQualityEnabler(p); auto hq = PainterHighQualityEnabler(p);
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
p.setBrush(Qt::white); p.setBrush(Qt::white);
@ -206,10 +205,19 @@ void Paint(
state->backgroundColors = backgroundColors; state->backgroundColors = backgroundColors;
state->text = username.text.toUpper(); state->text = username.text.toUpper();
state->textWidth = font->width(state->text); state->textWidth = font->width(state->text);
state->qrImage = TelegramQr( {
Qr::Encode(link.toUtf8(), Qr::Redundancy::Default), const auto remainder = qrMaxSize % st::introQrPixel;
st::introQrPixel, const auto downTo = remainder
qrMaxSize); ? qrMaxSize - remainder
: qrMaxSize;
state->qrImage = TelegramQr(
Qr::Encode(link.toUtf8(), Qr::Redundancy::Default),
st::introQrPixel,
downTo).scaled(
Size(qrMaxSize * style::DevicePixelRatio()),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation);
}
const auto qrWidth = state->qrImage.width() const auto qrWidth = state->qrImage.width()
/ style::DevicePixelRatio(); / style::DevicePixelRatio();
const auto lines = int(state->textWidth / qrWidth) + 1; const auto lines = int(state->textWidth / qrWidth) + 1;
@ -217,8 +225,8 @@ void Paint(
result->resize( result->resize(
qrMaxSize + rect::m::sum::h(state->backgroundMargins), qrMaxSize + rect::m::sum::h(state->backgroundMargins),
qrMaxSize qrMaxSize
+ rect::m::sum::v(state->backgroundMargins) + rect::m::sum::v(state->backgroundMargins) // White.
+ state->backgroundMargins.bottom() + rect::m::sum::v(st::profileQrBackgroundPadding) // Gray.
+ state->textMaxHeight + state->textMaxHeight
+ state->photoSize); + state->photoSize);
@ -240,7 +248,7 @@ void Paint(
size); size);
p.translate( p.translate(
0, 0,
st::profileQrBackgroundMargins.top() + state->photoSize / 2); st::profileQrBackgroundPadding.top() + state->photoSize / 2);
Paint( Paint(
p, p,
font, font,
@ -463,8 +471,9 @@ void FillPeerQrBox(
state->animation.stop(); state->animation.stop();
state->animation.start([=](float64 value) { state->animation.start([=](float64 value) {
const auto was = state->bgs.current(); const auto was = state->bgs.current();
const auto now = colors; const auto &now = colors;
if (was.size() == now.size(); was.size() == kMaxColors) { if (was.size() == now.size()
&& was.size() == kMaxColors) {
state->bgs = Colors({ state->bgs = Colors({
anim::color(was[0], now[0], value), anim::color(was[0], now[0], value),
anim::color(was[1], now[1], value), anim::color(was[1], now[1], value),
@ -704,7 +713,9 @@ void FillPeerQrBox(
- rect::m::sum::h(boxRowPadding) - rect::m::sum::h(boxRowPadding)
- rect::m::sum::h(backgroundMargins); - rect::m::sum::h(backgroundMargins);
const auto photoSize = userpicToggled const auto photoSize = userpicToggled
? style::ConvertScale(st::defaultUserpicButton.photoSize, scale) ? style::ConvertScale(
st::defaultUserpicButton.photoSize / divider,
scale)
: 0; : 0;
const auto font = createFont(scale); const auto font = createFont(scale);
@ -739,7 +750,7 @@ void FillPeerQrBox(
+ rect::m::sum::v(backgroundMargins) + rect::m::sum::v(backgroundMargins)
+ textMaxHeight + textMaxHeight
+ (photoSize + (photoSize
? (backgroundMargins.bottom() + photoSize) ? (backgroundMargins.bottom() * 3 + photoSize)
: 0)); : 0));
const auto qrImageSize = qrImage.size() const auto qrImageSize = qrImage.size()