From 7dbba7577656c8296cfaeaae86059c289426d891 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 26 Nov 2019 14:39:54 +0300 Subject: [PATCH] Make login QR follow the color theme. --- Telegram/SourceFiles/intro/intro.style | 1 + Telegram/SourceFiles/intro/intro_qr.cpp | 29 +++++++++++----------- Telegram/SourceFiles/intro/introwidget.cpp | 21 +++++++++++----- Telegram/SourceFiles/intro/introwidget.h | 2 +- Telegram/lib_qr | 2 +- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/Telegram/SourceFiles/intro/intro.style b/Telegram/SourceFiles/intro/intro.style index 95af195b77..8491d5b146 100644 --- a/Telegram/SourceFiles/intro/intro.style +++ b/Telegram/SourceFiles/intro/intro.style @@ -75,6 +75,7 @@ introHeight: 406px; introStepTopMin: 76px; introStepWidth: 380px; introNextTop: 266px; +introNextSlide: 200px; introStepHeight: 384px; introContentTopAdd: 30px; introStepHeightFull: 590px; diff --git a/Telegram/SourceFiles/intro/intro_qr.cpp b/Telegram/SourceFiles/intro/intro_qr.cpp index a7b6c1679e..fe6971903f 100644 --- a/Telegram/SourceFiles/intro/intro_qr.cpp +++ b/Telegram/SourceFiles/intro/intro_qr.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/fade_wrap.h" #include "ui/wrap/vertical_layout.h" #include "ui/text/text_utilities.h" +#include "ui/image/image_prepare.h" #include "main/main_account.h" #include "boxes/confirm_box.h" #include "core/application.h" @@ -50,9 +51,10 @@ namespace { } [[nodiscard]] QImage TelegramQrExact(const Qr::Data &data, int pixel) { - return Qr::ReplaceCenter( - Qr::Generate(data, pixel), - TelegramLogoImage(Qr::ReplaceSize(data, pixel))); + 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) { @@ -64,21 +66,20 @@ namespace { return TelegramQrExact(data, pixel * style::DevicePixelRatio()); } -[[nodiscard]] QImage TelegramQr(const QString &text, int pixel, int max) { - return TelegramQr( - Qr::Encode(text, Qr::Redundancy::Quartile), - pixel, - max); -} - [[nodiscard]] not_null PrepareQrWidget( not_null parent, rpl::producer codes) { - auto result = Ui::CreateChild(parent.get()); - auto current = result->lifetime().make_state(); - std::move( + auto qrs = std::move( codes ) | rpl::map([](const QByteArray &code) { + return Qr::Encode(code, Qr::Redundancy::Quartile); + }); + auto result = Ui::CreateChild(parent.get()); + auto current = result->lifetime().make_state(); + rpl::combine( + std::move(qrs), + rpl::single(rpl::empty_value()) | rpl::then(style::PaletteChanged()) + ) | rpl::map([](const Qr::Data &code, const auto &) { return TelegramQr(code, st::introQrPixel, st::introQrMaxSize); }) | rpl::start_with_next([=](QImage &&image) { result->resize(image.size() / cIntRetinaFactor()); @@ -102,7 +103,7 @@ QrWidget::QrWidget( QWidget *parent, not_null account, not_null data) - : Step(parent, account, data) +: Step(parent, account, data) , _refreshTimer([=] { refreshCode(); }) { setTitleText(rpl::single(QString())); setDescriptionText(rpl::single(QString())); diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index c183069f68..98b6d55244 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -48,7 +48,12 @@ Widget::Widget(QWidget *parent, not_null account) this, tr::lng_menu_settings(), st::defaultBoxButton)) -, _next(this, nullptr, st::introNextButton) { +, _next( + this, + object_ptr( + this, + nullptr, + st::introNextButton)) { getData()->country = Platform::SystemCountry(); _back->entity()->setClickedCallback([=] { @@ -56,7 +61,7 @@ Widget::Widget(QWidget *parent, not_null account) }); _back->hide(anim::type::instant); - _next->setClickedCallback([this] { getStep()->submit(); }); + _next->entity()->setClickedCallback([this] { getStep()->submit(); }); _settings->entity()->setClickedCallback([] { App::wnd()->showSettings(); }); @@ -475,8 +480,8 @@ void Widget::showTerms(Fn callback) { void Widget::showControls() { getStep()->show(); - _next->show(); setupNextButton(); + _next->show(anim::type::instant); _nextShownAnimation.stop(); _connecting->setForceHidden(false); auto hasCover = getStep()->hasCover(); @@ -496,7 +501,7 @@ void Widget::showControls() { } void Widget::setupNextButton() { - _next->setText(getStep()->nextButtonText( + _next->entity()->setText(getStep()->nextButtonText( ) | rpl::filter([](const QString &text) { return !text.isEmpty(); })); @@ -507,6 +512,7 @@ void Widget::setupNextButton() { std::move( visible ) | rpl::start_with_next([=](bool visible) { + _next->toggle(visible, anim::type::normal); _nextShown = visible; _nextShownAnimation.start( [=] { updateControlsGeometry(); }, @@ -518,7 +524,7 @@ void Widget::setupNextButton() { void Widget::hideControls() { getStep()->hide(); - _next->hide(); + _next->hide(anim::type::instant); _connecting->setForceHidden(true); _settings->hide(anim::type::instant); if (_update) _update->hide(anim::type::instant); @@ -605,7 +611,10 @@ void Widget::updateControlsGeometry() { auto nextTopTo = getStep()->contentTop() + st::introNextTop; auto nextTop = anim::interpolate(_nextTopFrom, nextTopTo, shown); const auto shownAmount = _nextShownAnimation.value(_nextShown ? 1. : 0.); - const auto realNextTop = anim::interpolate(height(), nextTop, shownAmount); + const auto realNextTop = anim::interpolate( + nextTop + st::introNextSlide, + nextTop, + shownAmount); _next->moveToLeft((width() - _next->width()) / 2, realNextTop); if (_changeLanguage) { _changeLanguage->moveToLeft((width() - _changeLanguage->width()) / 2, _next->y() + _next->height() + _changeLanguage->height()); diff --git a/Telegram/SourceFiles/intro/introwidget.h b/Telegram/SourceFiles/intro/introwidget.h index 4d2f69411b..f56f984dfe 100644 --- a/Telegram/SourceFiles/intro/introwidget.h +++ b/Telegram/SourceFiles/intro/introwidget.h @@ -145,7 +145,7 @@ private: object_ptr> _update = { nullptr }; object_ptr> _settings; - object_ptr _next; + object_ptr> _next; object_ptr> _changeLanguage = { nullptr }; object_ptr> _resetAccount = { nullptr }; object_ptr> _terms = { nullptr }; diff --git a/Telegram/lib_qr b/Telegram/lib_qr index 4b0a1d5fb5..1efe65125d 160000 --- a/Telegram/lib_qr +++ b/Telegram/lib_qr @@ -1 +1 @@ -Subproject commit 4b0a1d5fb546af4671048aeeec9c355a67a12a01 +Subproject commit 1efe65125ddca2a4a663c004380f31befd22ea76