From 9e4d47dcc07d1890576452c5fe58c0aaa6db140a Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 2 Jun 2022 01:21:26 +0300 Subject: [PATCH] Slightly improved style of box for premium accounts limits. Added an icon for the info bubble. Added a gradient color to selected account. Respected an order of accounts from settings. --- Telegram/Resources/icons/limits/accounts.png | Bin 0 -> 663 bytes .../Resources/icons/limits/accounts@2x.png | Bin 0 -> 1219 bytes .../Resources/icons/limits/accounts@3x.png | Bin 0 -> 1895 bytes Telegram/SourceFiles/boxes/boxes.style | 1 + .../SourceFiles/boxes/premium_limits_box.cpp | 13 +++-- .../settings/settings_information.cpp | 46 +++++++++--------- .../settings/settings_information.h | 5 ++ .../ui/effects/premium_graphics.cpp | 16 ++++-- .../SourceFiles/ui/effects/round_checkbox.cpp | 32 +++++++++--- .../SourceFiles/ui/effects/round_checkbox.h | 8 ++- 10 files changed, 77 insertions(+), 44 deletions(-) create mode 100644 Telegram/Resources/icons/limits/accounts.png create mode 100644 Telegram/Resources/icons/limits/accounts@2x.png create mode 100644 Telegram/Resources/icons/limits/accounts@3x.png diff --git a/Telegram/Resources/icons/limits/accounts.png b/Telegram/Resources/icons/limits/accounts.png new file mode 100644 index 0000000000000000000000000000000000000000..84205fe9bacb56b307a4348c01235ae074b34b81 GIT binary patch literal 663 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1SIoCSFHz9jKx9jP7LeL$-D$|Tv8)E(|mmy zw18|52FCVG1{RPKAeI7R1_tH@j10^`nh_+nfC(-uv49!D1}S`GTDq2jfr-)6#WBP} z@az=pen&@<<2Q32`I-nhIoW8nhAo`z5wND%bv;F`s!=dT)*d4 zd$l|>?j#sI`TX}tGe_;D0x$&BuI^KsVJE|A zr|fBE^}fF8_S;ogv(|>)e*azNd5P84*I#SemiL|&-g5u_?6YZRxf>(cni&~4-PG}I zF?LeqeEzYbg0EVUK}D*!Ej{F9$|Q%+KVw|}Se<@4DWTJ)DN+7S^KYjVfe9RUjz4y6 zYWgs<ebv%P05mh|${=dB#eH@0gA7$$$GVX1pk|I<~L_=>GGka~yx1{PVR+ zw^eE4i42o0v)LBEL$pMB*p~8$E=pU{^}nPw$$qxj@*OvG3L;zT<@%3%Ej5zi6Yp+~ zT3fdJ?!o|#xqi`W!x|m!Z{=*e{Z`GTuE$4BdCj5#jT85xSh|lcYIs^?8OZgFL8||F zgV)kYXH3Mkrk_3_63w#Y{B!5x#0RR6T9k~%x)&w~)*W4zYEhIJ`~COct64`M7cRbd z;*r{9&eGiNw|7jQeDX=Zj!(1gqPXRkJFhaeZ@8N`v-g?P;#1T7KdwA#xoP>dyRkM~ l@8*g7>)I+`+;{)fPqs52Z}MsaO6)<2!qe5yWt~$(695`L88!d_ literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/limits/accounts@2x.png b/Telegram/Resources/icons/limits/accounts@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..7b5dc52061e2c108b09c59573cbabee67fa234e5 GIT binary patch literal 1219 zcmV;!1U&nRP)Px#L}ge>W=%~1DgXcg2mk?xX#fNO00031000^Q000001E2u_0{{R30RRC20H6W@ z1ONa40RR91FrWhf1ONa40RR91FaQ7m0NXcg3;+NGElET{R9Fe^SlKIWQ5fG2Qi_nF zYl^%W;uN7sL>`T=^5B8+fb)lt@%$TRx>6`ZDCJR6C~l@qAw%3>XJ4zm)?U*-yX)zk z7i)dP@B8hw*7vP%F^teJv;yu{Ak2-s$Ky##O8OP}eSLlX3H+|FuRlLO-M~8b&CbsD z`Fv|@Ywz#x;KBUf-riPMR|f_Lva+%qLpyb-tE=1I-ewp`rdwNEwY9ZQqiER|6%{Qm zE=pocR0|6Wg@uJ$VKj|;dwaRNBO$@4;NIQctr<>c77-EQ_xl<2pr_;G;{cS!lk4Cd z^frk|&(F_?hlk7K3bhjx6CzwU^3l;zVMvLhr>DnFRJm_gSC=F-M}?%&ImJ&;Px#!D zl9HI1nAq6Z($Z2a>htrnoDH<7Rr&e(oWLRx5>*L$baa%L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T_><^k{trZ zI0?vz`3goBQX%!MuCB&@lW2vRn>TM-fd7ICoHvOtF^K{RYHMqeBlGgaHxl*r_0%Zm z)vH(j{{FlK#o^&6E$;xcrN_s|D=RC}+Ei%SAbv&l0fmE!i3u~JWYFE+EnGpMCz>o8 z<9@@DYiMXtSR#CTg-=%yLm+d(f&c~aCk`Y6f21u6-&vx1g%4M8dZ8+dF#5wF=0ZG4 z-9-}fGd{uuIIdbhw=K0+RZ{EW%~48Xm; zz33(@97q8X#m|@mGwjcpm>Bp51hV*{+zlUKx(rPJP=HUQQ8vTxzwr+R3aVOPSuJ3- hfYkz43!JY7{s9~1=m_m$4SfIr002ovPDHLkV1h=HU2XsX literal 0 HcmV?d00001 diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index 5470a25cb..5a1b70ae2 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -1096,6 +1096,7 @@ premiumIconFolders: icon {{ "limits/folders", settingsIconFg }}; premiumIconGroups: icon {{ "limits/groups", settingsIconFg }}; premiumIconLinks: icon {{ "limits/links", settingsIconFg }}; premiumIconPins: icon {{ "limits/pins", settingsIconFg }}; +premiumIconAccounts: icon {{ "limits/accounts", settingsIconFg }}; premiumAccountsCheckbox: RoundImageCheckbox(defaultPeerListCheckbox) { imageRadius: 27px; diff --git a/Telegram/SourceFiles/boxes/premium_limits_box.cpp b/Telegram/SourceFiles/boxes/premium_limits_box.cpp index 9b529ee1d..bbbd7f43b 100644 --- a/Telegram/SourceFiles/boxes/premium_limits_box.cpp +++ b/Telegram/SourceFiles/boxes/premium_limits_box.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "lang/lang_keys.h" #include "settings/settings_common.h" +#include "settings/settings_information.h" // Settings::OrderedAccounts(). #include "settings/settings_premium.h" #include "base/unixtime.h" #include "apiwrap.h" @@ -888,7 +889,7 @@ void AccountsLimitBox( const auto defaultLimit = Main::Domain::kMaxAccounts; const auto premiumLimit = Main::Domain::kPremiumMaxAccounts; - const auto &accounts = session->domain().accounts(); + const auto accounts = Settings::OrderedAccounts(); const auto current = int(accounts.size()); auto text = tr::lng_accounts_limit1( @@ -909,7 +910,7 @@ void AccountsLimitBox( current, (current == premiumLimit) ? premiumLimit : (current * 2), std::nullopt, - &st::premiumIconFiles); + &st::premiumIconAccounts); Settings::AddSkip(top, st::premiumLineTextSkip); Ui::Premium::AddLimitRow(top, 0, std::nullopt, defaultLimit); Settings::AddSkip(top, st::premiumInfographicPadding.bottom()); @@ -935,9 +936,8 @@ void AccountsLimitBox( box->addButton(tr::lng_continue(), [=]() mutable { const auto ref = QString(); - const auto &accounts = session->domain().accounts(); const auto wasAccount = &session->account(); - const auto nowAccount = accounts[group->value()].account.get(); + const auto nowAccount = accounts[group->value()]; if (wasAccount == nowAccount) { Settings::ShowPremium(session, ref); return; @@ -967,9 +967,8 @@ void AccountsLimitBox( auto &&entries = ranges::views::all( accounts - ) | ranges::views::transform([&]( - const Main::Domain::AccountWithIndex &d) { - const auto user = d.account->session().user(); + ) | ranges::views::transform([&](not_null account) { + const auto user = account->session().user(); return Args::Entry{ user->name, PaintUserpicCallback(user, false) }; }); diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index 7820b7029..a878f05e8 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -619,29 +619,6 @@ void SetupAccountsWrap( return result; } -[[nodiscard]] std::vector> OrderedAccounts() { - using namespace Main; - - const auto order = Core::App().settings().accountsOrder(); - auto accounts = ranges::views::all( - Core::App().domain().accounts() - ) | ranges::views::transform([](const Domain::AccountWithIndex &a) { - return not_null{ a.account.get() }; - }) | ranges::to_vector; - ranges::stable_sort(accounts, [&]( - not_null a, - not_null b) { - const auto aIt = a->sessionExists() - ? ranges::find(order, a->session().uniqueId()) - : end(order); - const auto bIt = b->sessionExists() - ? ranges::find(order, b->session().uniqueId()) - : end(order); - return aIt < bIt; - }); - return accounts; -} - AccountsList::AccountsList( not_null container, not_null controller) @@ -853,6 +830,29 @@ AccountsEvents SetupAccounts( }; } +std::vector> OrderedAccounts() { + using namespace Main; + + const auto order = Core::App().settings().accountsOrder(); + auto accounts = ranges::views::all( + Core::App().domain().accounts() + ) | ranges::views::transform([](const Domain::AccountWithIndex &a) { + return not_null{ a.account.get() }; + }) | ranges::to_vector; + ranges::stable_sort(accounts, [&]( + not_null a, + not_null b) { + const auto aIt = a->sessionExists() + ? ranges::find(order, a->session().uniqueId()) + : end(order); + const auto bIt = b->sessionExists() + ? ranges::find(order, b->session().uniqueId()) + : end(order); + return aIt < bIt; + }); + return accounts; +} + Dialogs::Ui::UnreadBadgeStyle BadgeStyle() { auto result = Dialogs::Ui::UnreadBadgeStyle(); result.font = st::mainMenuBadgeFont; diff --git a/Telegram/SourceFiles/settings/settings_information.h b/Telegram/SourceFiles/settings/settings_information.h index fea72a8de..39f4de08a 100644 --- a/Telegram/SourceFiles/settings/settings_information.h +++ b/Telegram/SourceFiles/settings/settings_information.h @@ -13,6 +13,10 @@ namespace Dialogs::Ui { struct UnreadBadgeStyle; } // namespace Dialogs::Ui +namespace Main { +class Account; +} // namespace Main + namespace Settings { class Information : public Section { @@ -35,6 +39,7 @@ AccountsEvents SetupAccounts( not_null container, not_null controller); +[[nodiscard]] std::vector> OrderedAccounts(); [[nodiscard]] Dialogs::Ui::UnreadBadgeStyle BadgeStyle(); struct UnreadBadge { diff --git a/Telegram/SourceFiles/ui/effects/premium_graphics.cpp b/Telegram/SourceFiles/ui/effects/premium_graphics.cpp index 967fac26c..33f3b8294 100644 --- a/Telegram/SourceFiles/ui/effects/premium_graphics.cpp +++ b/Telegram/SourceFiles/ui/effects/premium_graphics.cpp @@ -683,7 +683,7 @@ void AddAccountsRow( const auto width = widget->width(); const auto photoLeft = (width - (imageRadius * 2)) / 2; const auto photoTop = checkSelectWidth; - auto &account = state->accounts[index]; + const auto &account = state->accounts[index]; account.checkbox.paint(p, photoLeft, photoTop, width); const auto &badgeSize = account.badge.size() @@ -719,10 +719,18 @@ void AddAccountsRow( const auto count = state->accounts.size(); const auto columnWidth = size.width() / count; for (auto i = 0; i < count; i++) { - state->accounts[i].widget->resize(columnWidth, size.height()); + auto &account = state->accounts[i]; + account.widget->resize(columnWidth, size.height()); const auto left = columnWidth * i; - state->accounts[i].widget->moveToLeft(left, 0); - state->accounts[i].badge = cacheBadge(left + columnWidth / 2); + account.widget->moveToLeft(left, 0); + account.badge = cacheBadge(left + columnWidth / 2); + + const auto photoWidth = ((imageRadius + checkSelectWidth) * 2); + account.checkbox.setColorOverride(QBrush( + ComputeGradient( + container, + left + (columnWidth - photoWidth) / 2, + photoWidth))); } }, container->lifetime()); } diff --git a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp index bab09d8d6..3ab51c436 100644 --- a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp +++ b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp @@ -258,7 +258,7 @@ RoundCheckbox::RoundCheckbox(const style::RoundCheckbox &st, Fn updateCa , _updateCallback(updateCallback) { } -void RoundCheckbox::paint(Painter &p, int x, int y, int outerWidth, float64 masterScale) { +void RoundCheckbox::paint(Painter &p, int x, int y, int outerWidth, float64 masterScale) const { if (!_st.size || (!_checkedProgress.animating() && !_checked @@ -361,7 +361,7 @@ RoundImageCheckbox::RoundImageCheckbox(const style::RoundImageCheckbox &st, Fnp; - pen.setWidth(_st.selectWidth); + const auto pen = QPen( + _fgOverride ? (*_fgOverride) : _st.selectFg->b, + _st.selectWidth); p.setPen(pen); p.drawEllipse(style::rtlrect(x, y, _st.imageRadius * 2, _st.imageRadius * 2, outerWidth)); p.setOpacity(1.); @@ -416,7 +414,21 @@ void RoundImageCheckbox::setChecked(bool newChecked, anim::type animated) { } if (animated == anim::type::normal) { prepareWideCache(); - _selection.start(_updateCallback, checked() ? 0 : 1, checked() ? 1 : 0, _st.selectDuration, anim::bumpy(1.25)); + const auto from = checked() ? 0. : 1.; + const auto to = checked() ? 1. : 0.; + _selection.start( + [=](float64 value) { + if (_updateCallback) { + _updateCallback(); + } + if (value == to) { + _wideCache = QPixmap(); + } + }, + from, + to, + _st.selectDuration, + anim::bumpy(1.25)); } else { _selection.stop(); } @@ -439,4 +451,8 @@ void RoundImageCheckbox::prepareWideCache() { } } +void RoundImageCheckbox::setColorOverride(std::optional fg) { + _fgOverride = fg; +} + } // namespace Ui diff --git a/Telegram/SourceFiles/ui/effects/round_checkbox.h b/Telegram/SourceFiles/ui/effects/round_checkbox.h index ec74fc506..30008581d 100644 --- a/Telegram/SourceFiles/ui/effects/round_checkbox.h +++ b/Telegram/SourceFiles/ui/effects/round_checkbox.h @@ -16,7 +16,7 @@ class RoundCheckbox { public: RoundCheckbox(const style::RoundCheckbox &st, Fn updateCallback); - void paint(Painter &p, int x, int y, int outerWidth, float64 masterScale = 1.); + void paint(Painter &p, int x, int y, int outerWidth, float64 masterScale = 1.) const; void setDisplayInactive(bool displayInactive); bool checked() const { @@ -47,9 +47,11 @@ public: using PaintRoundImage = Fn; RoundImageCheckbox(const style::RoundImageCheckbox &st, Fn updateCallback, PaintRoundImage &&paintRoundImage); - void paint(Painter &p, int x, int y, int outerWidth); + void paint(Painter &p, int x, int y, int outerWidth) const; float64 checkedAnimationRatio() const; + void setColorOverride(std::optional fg); + bool checked() const { return _check.checked(); } @@ -73,6 +75,8 @@ private: RoundCheckbox _check; + std::optional _fgOverride; + }; } // namespace Ui