From 931fa01337198357c7533d1aeb937935681dd121 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 7 Sep 2024 11:34:55 +0300 Subject: [PATCH] Added premium gradient to box for share of QR code. --- .../SourceFiles/ui/boxes/profile_qr_box.cpp | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/ui/boxes/profile_qr_box.cpp b/Telegram/SourceFiles/ui/boxes/profile_qr_box.cpp index 7d8c6eaba..86a8ad1e6 100644 --- a/Telegram/SourceFiles/ui/boxes/profile_qr_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/profile_qr_box.cpp @@ -270,36 +270,56 @@ void FillProfileQrBox( } Ui::AddSkip(themesContainer); Ui::AddSkip(themesContainer); - Ui::AddSkip(themesContainer); - Ui::AddSkip(themesContainer); struct State { Colors colors; QImage image; }; constexpr auto kMaxInRow = 4; + constexpr auto kMaxColors = 4; auto row = (Ui::RpWidget*)(nullptr); auto counter = 0; const auto spacing = (0 + (box->width() - rect::m::sum::h(st::boxRowPadding)) - (kMaxInRow * size)) / (kMaxInRow + 1); - for (const auto &cloudTheme : cloudThemes) { + auto colorsCollection = ranges::views::all( + cloudThemes + ) | ranges::views::transform([](const auto &cloudTheme) -> Colors { const auto it = cloudTheme.settings.find( Data::CloudThemeType::Light); if (it == end(cloudTheme.settings)) { - continue; + return Colors(); } const auto colors = it->second.paper ? it->second.paper->backgroundColors() - : std::vector(); - if (colors.size() != 4) { - continue; + : Colors(); + if (colors.size() != kMaxColors) { + return Colors(); } + return colors; + }) | ranges::views::filter([](const Colors &colors) { + return !colors.empty(); + }) | ranges::to_vector; + colorsCollection.push_back(Colors{ + st::premiumButtonBg1->c, + st::premiumButtonBg1->c, + st::premiumButtonBg2->c, + st::premiumButtonBg3->c, + }); + // colorsCollection.push_back(Colors{ + // st::creditsBg1->c, + // st::creditsBg2->c, + // st::creditsBg1->c, + // st::creditsBg2->c, + // }); + + for (const auto &colors : colorsCollection) { if (state->bgs.current().empty()) { state->bgs = colors; } if (counter % kMaxInRow == 0) { + Ui::AddSkip(themesContainer); row = themesContainer->add( object_ptr(themesContainer)); row->resize(size, size); @@ -313,7 +333,7 @@ void FillProfileQrBox( state->animation.start([=](float64 value) { const auto was = state->bgs.current(); const auto now = colors; - if (was.size() == now.size(); was.size() == 4) { + if (was.size() == now.size(); was.size() == kMaxColors) { state->bgs = Colors({ anim::color(was[0], now[0], value), anim::color(was[1], now[1], value), @@ -391,10 +411,10 @@ void FillProfileQrBox( st::roundRadiusLarge + activewidth * 4.2); } }, widget->lifetime()); - if ((++counter) >= kMaxInRow) { - Ui::AddSkip(themesContainer); - } + counter++; } + Ui::AddSkip(themesContainer); + Ui::AddSkip(themesContainer); themesContainer->resizeToWidth(box->width()); };