Use special plane icon for login QR.

This commit is contained in:
John Preston 2019-11-26 15:56:07 +03:00
parent 7dbba75776
commit ba7762305e
5 changed files with 52 additions and 30 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -162,9 +162,9 @@ introBackButton: IconButton(defaultIconButton) {
} }
} }
introQrTop: 0px; introQrTop: -6px;
introQrPixel: 50px; // large enough introQrPixel: 50px; // large enough
introQrMaxSize: 170px; introQrMaxSize: 180px;
introQrLabelsWidth: 292px; introQrLabelsWidth: 292px;
introQrTitle: FlatLabel(defaultFlatLabel) { introQrTitle: FlatLabel(defaultFlatLabel) {
textFg: introTitleFg; textFg: introTitleFg;
@ -179,3 +179,5 @@ introQrStep: defaultFlatLabel;
introQrStepsTop: 232px; introQrStepsTop: 232px;
introQrStepMargins: margins(0px, 8px, 0px, 0px); introQrStepMargins: margins(0px, 8px, 0px, 0px);
introQrSkipTop: 360px; introQrSkipTop: 360px;
introQrCenterSize: 44px;
introQrPlane: icon {{ "intro_qr_plane", activeButtonFg }};

View File

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/wrap/vertical_layout.h" #include "ui/wrap/vertical_layout.h"
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/image/image_prepare.h" #include "ui/image/image_prepare.h"
#include "ui/painter.h"
#include "main/main_account.h" #include "main/main_account.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "core/application.h" #include "core/application.h"
@ -26,35 +27,26 @@ namespace Intro {
namespace details { namespace details {
namespace { namespace {
[[nodiscard]] QImage TelegramLogoImage(int size) { [[nodiscard]] QImage TelegramLogoImage() {
constexpr auto kScale = 0.8; const auto size = QSize(st::introQrCenterSize, st::introQrCenterSize);
const auto used = int(size * kScale); auto result = QImage(
const auto adjusted = used + ((used % 2) + (size % 2)) % 2; size * style::DevicePixelRatio(),
const auto image = Core::App().logo().scaled( QImage::Format_ARGB32_Premultiplied);
adjusted,
adjusted,
Qt::KeepAspectRatio,
Qt::SmoothTransformation);
auto result = QImage(size, size, QImage::Format_ARGB32_Premultiplied);
result.fill(Qt::transparent); result.fill(Qt::transparent);
result.setDevicePixelRatio(style::DevicePixelRatio());
{ {
QPainter p(&result); auto p = QPainter(&result);
p.drawImage( auto hq = PainterHighQualityEnabler(p);
QRect( p.setBrush(st::activeButtonBg);
(size - adjusted) / 2, p.setPen(Qt::NoPen);
(size - adjusted) / 2, p.drawEllipse(QRect(QPoint(), size));
adjusted, st::introQrPlane.paintInCenter(p, QRect(QPoint(), size));
adjusted),
image);
} }
return result; return result;
} }
[[nodiscard]] QImage TelegramQrExact(const Qr::Data &data, int pixel) { [[nodiscard]] QImage TelegramQrExact(const Qr::Data &data, int pixel) {
return Qr::Generate(data, pixel, st::windowFg->c); return Qr::Generate(data, pixel, st::windowFg->c);
//Qr::ReplaceCenter(
// Qr::Generate(data, pixel),
// TelegramLogoImage(Qr::ReplaceSize(data, pixel)));
} }
[[nodiscard]] QImage TelegramQr(const Qr::Data &data, int pixel, int max = 0) { [[nodiscard]] QImage TelegramQr(const Qr::Data &data, int pixel, int max = 0) {
@ -74,25 +66,53 @@ namespace {
) | rpl::map([](const QByteArray &code) { ) | rpl::map([](const QByteArray &code) {
return Qr::Encode(code, Qr::Redundancy::Quartile); return Qr::Encode(code, Qr::Redundancy::Quartile);
}); });
auto palettes = rpl::single(
rpl::empty_value()
) | rpl::then(
style::PaletteChanged()
);
auto result = Ui::CreateChild<Ui::RpWidget>(parent.get()); auto result = Ui::CreateChild<Ui::RpWidget>(parent.get());
auto current = result->lifetime().make_state<QImage>(); const auto current = result->lifetime().make_state<QImage>();
const auto center = result->lifetime().make_state<QImage>();
result->resize(st::introQrMaxSize, st::introQrMaxSize);
rpl::combine( rpl::combine(
std::move(qrs), std::move(qrs),
rpl::single(rpl::empty_value()) | rpl::then(style::PaletteChanged()) rpl::duplicate(palettes)
) | rpl::map([](const Qr::Data &code, const auto &) { ) | rpl::map([](const Qr::Data &code, const auto &) {
return TelegramQr(code, st::introQrPixel, st::introQrMaxSize); return TelegramQr(code, st::introQrPixel, st::introQrMaxSize);
}) | rpl::start_with_next([=](QImage &&image) { }) | rpl::start_with_next([=](QImage &&image) {
result->resize(image.size() / cIntRetinaFactor());
*current = std::move(image); *current = std::move(image);
result->update(); result->update();
}, result->lifetime()); }, result->lifetime());
std::move(
palettes
) | rpl::map([] {
return TelegramLogoImage();
}) | rpl::start_with_next([=](QImage &&image) {
*center = std::move(image);
}, result->lifetime());
result->paintRequest( result->paintRequest(
) | rpl::filter([=] { ) | rpl::filter([=] {
return !current->isNull(); return !center->isNull();
}) | rpl::start_with_next([=](QRect clip) { }) | rpl::start_with_next([=](QRect clip) {
QPainter(result).drawImage( auto p = QPainter(result);
QRect(QPoint(), current->size() / cIntRetinaFactor()), p.drawImage(
*current); QRect(
(result->width() - st::introQrCenterSize) / 2,
(result->height() - st::introQrCenterSize) / 2,
st::introQrCenterSize,
st::introQrCenterSize),
*center);
if (current) {
const auto size = current->size() / cIntRetinaFactor();
p.drawImage(
QRect(
(result->width() - size.width()) / 2,
(result->height() - size.height()) / 2,
size.width(),
size.height()),
*current);
}
}, result->lifetime()); }, result->lifetime());
return result; return result;
} }