payments_reaction_box.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "payments/ui/payments_reaction_box.h"
  8. #include "base/qt/qt_compare.h"
  9. #include "lang/lang_keys.h"
  10. #include "ui/boxes/boost_box.h" // MakeBoostFeaturesBadge.
  11. #include "ui/controls/who_reacted_context_action.h"
  12. #include "ui/effects/premium_bubble.h"
  13. #include "ui/layers/generic_box.h"
  14. #include "ui/text/text_utilities.h"
  15. #include "ui/widgets/buttons.h"
  16. #include "ui/widgets/checkbox.h"
  17. #include "ui/widgets/continuous_sliders.h"
  18. #include "ui/widgets/popup_menu.h"
  19. #include "ui/wrap/slide_wrap.h"
  20. #include "ui/dynamic_image.h"
  21. #include "ui/painter.h"
  22. #include "ui/vertical_list.h"
  23. #include "styles/style_chat.h"
  24. #include "styles/style_chat_helpers.h"
  25. #include "styles/style_credits.h"
  26. #include "styles/style_layers.h"
  27. #include "styles/style_media_player.h"
  28. #include "styles/style_premium.h"
  29. #include "styles/style_settings.h"
  30. namespace Settings {
  31. [[nodiscard]] not_null<Ui::RpWidget*> AddBalanceWidget(
  32. not_null<Ui::RpWidget*> parent,
  33. rpl::producer<StarsAmount> balanceValue,
  34. bool rightAlign,
  35. rpl::producer<float64> opacityValue = nullptr);
  36. } // namespace Settings
  37. namespace Ui {
  38. namespace {
  39. constexpr auto kMaxTopPaidShown = 3;
  40. struct TopReactorKey {
  41. std::shared_ptr<DynamicImage> photo;
  42. int count = 0;
  43. QString name;
  44. friend inline auto operator<=>(
  45. const TopReactorKey &,
  46. const TopReactorKey &) = default;
  47. friend inline bool operator==(
  48. const TopReactorKey &,
  49. const TopReactorKey &) = default;
  50. };
  51. struct Discreter {
  52. Fn<int(float64)> ratioToValue;
  53. Fn<float64(int)> valueToRatio;
  54. };
  55. [[nodiscard]] Discreter DiscreterForMax(int max) {
  56. Expects(max >= 2);
  57. // 1/8 of width is 1..10
  58. // 1/3 of width is 1..100
  59. // 2/3 of width is 1..1000
  60. auto thresholds = base::flat_map<float64, int>();
  61. thresholds.emplace(0., 1);
  62. if (max <= 40) {
  63. thresholds.emplace(1., max);
  64. } else if (max <= 300) {
  65. thresholds.emplace(1. / 4, 10);
  66. thresholds.emplace(1., max);
  67. } else if (max <= 600) {
  68. thresholds.emplace(1. / 8, 10);
  69. thresholds.emplace(1. / 2, 100);
  70. thresholds.emplace(1., max);
  71. } else if (max <= 1900) {
  72. thresholds.emplace(1. / 8, 10);
  73. thresholds.emplace(1. / 3, 100);
  74. thresholds.emplace(1., max);
  75. } else {
  76. thresholds.emplace(1. / 8, 10);
  77. thresholds.emplace(1. / 3, 100);
  78. thresholds.emplace(2. / 3, 1000);
  79. thresholds.emplace(1., max);
  80. }
  81. const auto ratioToValue = [=](float64 ratio) {
  82. ratio = std::clamp(ratio, 0., 1.);
  83. const auto j = thresholds.lower_bound(ratio);
  84. if (j == begin(thresholds)) {
  85. return 1;
  86. }
  87. const auto i = j - 1;
  88. const auto progress = (ratio - i->first) / (j->first - i->first);
  89. const auto value = i->second + (j->second - i->second) * progress;
  90. return int(base::SafeRound(value));
  91. };
  92. const auto valueToRatio = [=](int value) {
  93. value = std::clamp(value, 1, max);
  94. auto i = begin(thresholds);
  95. auto j = i + 1;
  96. while (j->second < value) {
  97. i = j++;
  98. }
  99. const auto progress = (value - i->second)
  100. / float64(j->second - i->second);
  101. return i->first + (j->first - i->first) * progress;
  102. };
  103. return {
  104. .ratioToValue = ratioToValue,
  105. .valueToRatio = valueToRatio,
  106. };
  107. }
  108. void PaidReactionSlider(
  109. not_null<VerticalLayout*> container,
  110. int current,
  111. int max,
  112. Fn<void(int)> changed) {
  113. Expects(current >= 1 && current <= max);
  114. const auto slider = container->add(
  115. object_ptr<MediaSlider>(container, st::paidReactSlider),
  116. st::boxRowPadding + QMargins(0, st::paidReactSliderTop, 0, 0));
  117. slider->resize(slider->width(), st::paidReactSlider.seekSize.height());
  118. const auto discreter = DiscreterForMax(max);
  119. slider->setAlwaysDisplayMarker(true);
  120. slider->setDirection(ContinuousSlider::Direction::Horizontal);
  121. slider->setValue(discreter.valueToRatio(current));
  122. slider->setAdjustCallback([=](float64 ratio) {
  123. return discreter.valueToRatio(discreter.ratioToValue(ratio));
  124. });
  125. const auto ratioToValue = discreter.ratioToValue;
  126. slider->setChangeProgressCallback([=](float64 value) {
  127. changed(ratioToValue(value));
  128. });
  129. slider->setChangeFinishedCallback([=](float64 value) {
  130. changed(ratioToValue(value));
  131. });
  132. }
  133. [[nodiscard]] QImage GenerateBadgeImage(int count) {
  134. return GenerateSmallBadgeImage(
  135. Lang::FormatCountDecimal(count),
  136. st::paidReactTopStarIcon,
  137. st::creditsBg3->c,
  138. st::premiumButtonFg->c);
  139. }
  140. void AddArrowDown(not_null<RpWidget*> widget) {
  141. const auto arrow = CreateChild<RpWidget>(widget);
  142. const auto icon = &st::paidReactChannelArrow;
  143. const auto skip = st::lineWidth * 4;
  144. const auto size = icon->width() + skip * 2;
  145. arrow->resize(size, size);
  146. widget->widthValue() | rpl::start_with_next([=](int width) {
  147. const auto left = (width - st::paidReactTopUserpic) / 2;
  148. arrow->moveToRight(left - skip, -st::lineWidth, width);
  149. }, widget->lifetime());
  150. arrow->paintRequest() | rpl::start_with_next([=] {
  151. Painter p(arrow);
  152. auto hq = PainterHighQualityEnabler(p);
  153. p.setBrush(st::activeButtonBg);
  154. p.setPen(st::activeButtonFg);
  155. const auto rect = arrow->rect();
  156. const auto line = st::lineWidth;
  157. p.drawEllipse(rect.marginsRemoved({ line, line, line, line }));
  158. icon->paint(p, skip, (size - icon->height()) / 2 + line, size);
  159. }, widget->lifetime());
  160. arrow->setAttribute(Qt::WA_TransparentForMouseEvents);
  161. arrow->show();
  162. }
  163. [[nodiscard]] not_null<RpWidget*> MakeTopReactor(
  164. not_null<QWidget*> parent,
  165. const PaidReactionTop &data,
  166. Fn<void()> selectShownPeer) {
  167. const auto result = CreateChild<AbstractButton>(parent);
  168. result->show();
  169. if (data.click && !data.my) {
  170. result->setClickedCallback(data.click);
  171. } else if (data.click && selectShownPeer) {
  172. result->setClickedCallback(selectShownPeer);
  173. AddArrowDown(result);
  174. } else {
  175. result->setAttribute(Qt::WA_TransparentForMouseEvents);
  176. }
  177. struct State {
  178. QImage badge;
  179. Text::String name;
  180. };
  181. const auto state = result->lifetime().make_state<State>();
  182. state->name.setText(st::defaultTextStyle, data.name);
  183. const auto count = data.count;
  184. const auto photo = data.photo->clone();
  185. photo->subscribeToUpdates([=] {
  186. result->update();
  187. });
  188. style::PaletteChanged(
  189. ) | rpl::start_with_next([=] {
  190. state->badge = QImage();
  191. }, result->lifetime());
  192. result->paintRequest() | rpl::start_with_next([=] {
  193. auto p = Painter(result);
  194. const auto left = (result->width() - st::paidReactTopUserpic) / 2;
  195. p.drawImage(left, 0, photo->image(st::paidReactTopUserpic));
  196. if (state->badge.isNull()) {
  197. state->badge = GenerateBadgeImage(count);
  198. }
  199. const auto bwidth = state->badge.width()
  200. / state->badge.devicePixelRatio();
  201. p.drawImage(
  202. (result->width() - bwidth) / 2,
  203. st::paidReactTopBadgeSkip,
  204. state->badge);
  205. p.setPen(st::windowFg);
  206. const auto skip = st::normalFont->spacew;
  207. const auto nameTop = st::paidReactTopNameSkip;
  208. const auto available = result->width() - skip * 2;
  209. state->name.draw(p, skip, nameTop, available, style::al_top);
  210. }, result->lifetime());
  211. return result;
  212. }
  213. void SelectShownPeer(
  214. std::shared_ptr<QPointer<PopupMenu>> menu,
  215. not_null<QWidget*> parent,
  216. const std::vector<PaidReactionTop> &mine,
  217. uint64 selected,
  218. Fn<void(uint64)> callback) {
  219. if (*menu) {
  220. (*menu)->hideMenu();
  221. }
  222. (*menu) = CreateChild<PopupMenu>(
  223. parent,
  224. st::paidReactChannelMenu);
  225. struct Entry {
  226. not_null<Ui::WhoReactedEntryAction*> action;
  227. std::shared_ptr<Ui::DynamicImage> userpic;
  228. };
  229. auto actions = std::make_shared<std::vector<Entry>>();
  230. actions->reserve(mine.size());
  231. for (const auto &entry : mine) {
  232. auto action = base::make_unique_q<WhoReactedEntryAction>(
  233. (*menu)->menu(),
  234. nullptr,
  235. (*menu)->menu()->st(),
  236. Ui::WhoReactedEntryData());
  237. const auto index = int(actions->size());
  238. actions->push_back({ action.get(), entry.photo->clone() });
  239. const auto id = entry.barePeerId;
  240. const auto updateUserpic = [=] {
  241. const auto size = st::defaultWhoRead.photoSize;
  242. actions->at(index).action->setData({
  243. .text = entry.name,
  244. .type = ((id == selected)
  245. ? Ui::WhoReactedType::RefRecipientNow
  246. : Ui::WhoReactedType::RefRecipient),
  247. .userpic = actions->at(index).userpic->image(size),
  248. .callback = [=] { callback(id); },
  249. });
  250. };
  251. actions->back().userpic->subscribeToUpdates(updateUserpic);
  252. (*menu)->addAction(std::move(action));
  253. updateUserpic();
  254. }
  255. (*menu)->popup(QCursor::pos());
  256. }
  257. void FillTopReactors(
  258. not_null<VerticalLayout*> container,
  259. std::vector<PaidReactionTop> top,
  260. rpl::producer<int> chosen,
  261. rpl::producer<uint64> shownPeer,
  262. Fn<void(uint64)> changeShownPeer) {
  263. container->add(
  264. MakeBoostFeaturesBadge(
  265. container,
  266. tr::lng_paid_react_top_title(),
  267. [](QRect) { return st::creditsBg3->b; }),
  268. st::boxRowPadding + st::paidReactTopTitleMargin);
  269. const auto height = st::paidReactTopNameSkip + st::normalFont->height;
  270. const auto wrap = container->add(
  271. object_ptr<SlideWrap<FixedHeightWidget>>(
  272. container,
  273. object_ptr<FixedHeightWidget>(container, height),
  274. st::paidReactTopMargin));
  275. const auto parent = wrap->entity();
  276. using Key = TopReactorKey;
  277. struct State {
  278. base::flat_map<Key, not_null<RpWidget*>> cache;
  279. std::vector<not_null<RpWidget*>> widgets;
  280. rpl::event_stream<> updated;
  281. std::optional<int> initialChosen;
  282. bool chosenChanged = false;
  283. };
  284. const auto state = wrap->lifetime().make_state<State>();
  285. const auto menu = std::make_shared<QPointer<Ui::PopupMenu>>();
  286. rpl::combine(
  287. std::move(chosen),
  288. std::move(shownPeer)
  289. ) | rpl::start_with_next([=](int chosen, uint64 barePeerId) {
  290. if (!state->initialChosen) {
  291. state->initialChosen = chosen;
  292. } else if (*state->initialChosen != chosen) {
  293. state->chosenChanged = true;
  294. }
  295. auto mine = std::vector<PaidReactionTop>();
  296. auto list = std::vector<PaidReactionTop>();
  297. list.reserve(kMaxTopPaidShown + 1);
  298. for (const auto &entry : top) {
  299. if (!entry.my) {
  300. list.push_back(entry);
  301. } else if (entry.barePeerId == barePeerId) {
  302. auto copy = entry;
  303. if (state->chosenChanged) {
  304. copy.count += chosen;
  305. }
  306. list.push_back(copy);
  307. }
  308. if (entry.my && entry.barePeerId) {
  309. mine.push_back(entry);
  310. }
  311. }
  312. ranges::stable_sort(
  313. list,
  314. ranges::greater(),
  315. &PaidReactionTop::count);
  316. while (list.size() > kMaxTopPaidShown
  317. || (!list.empty() && !list.back().count)) {
  318. list.pop_back();
  319. }
  320. auto selectShownPeer = (mine.size() < 2)
  321. ? Fn<void()>()
  322. : [=] { SelectShownPeer(
  323. menu,
  324. parent,
  325. mine,
  326. barePeerId,
  327. changeShownPeer); };
  328. if (list.empty()) {
  329. wrap->hide(anim::type::normal);
  330. } else {
  331. for (const auto &widget : state->widgets) {
  332. widget->hide();
  333. }
  334. state->widgets.clear();
  335. for (const auto &entry : list) {
  336. const auto key = Key{
  337. .photo = entry.photo,
  338. .count = entry.count,
  339. .name = entry.name,
  340. };
  341. const auto i = state->cache.find(key);
  342. const auto widget = (i != end(state->cache))
  343. ? i->second
  344. : MakeTopReactor(parent, entry, selectShownPeer);
  345. state->widgets.push_back(widget);
  346. widget->show();
  347. }
  348. for (const auto &[k, widget] : state->cache) {
  349. if (widget->isHidden()) {
  350. delete widget;
  351. }
  352. }
  353. wrap->show(anim::type::normal);
  354. }
  355. state->updated.fire({});
  356. }, wrap->lifetime());
  357. wrap->finishAnimating();
  358. rpl::combine(
  359. state->updated.events_starting_with({}),
  360. wrap->widthValue()
  361. ) | rpl::start_with_next([=](auto, int width) {
  362. const auto single = width / 4;
  363. if (single <= st::paidReactTopUserpic) {
  364. return;
  365. }
  366. const auto count = int(state->widgets.size());
  367. auto left = (width - single * count) / 2;
  368. for (const auto &widget : state->widgets) {
  369. widget->setGeometry(left, 0, single, height);
  370. left += single;
  371. }
  372. }, wrap->lifetime());
  373. }
  374. } // namespace
  375. void PaidReactionsBox(
  376. not_null<GenericBox*> box,
  377. PaidReactionBoxArgs &&args) {
  378. Expects(!args.top.empty());
  379. args.max = std::max(args.max, 2);
  380. args.chosen = std::clamp(args.chosen, 1, args.max);
  381. box->setWidth(st::boxWideWidth);
  382. box->setStyle(st::paidReactBox);
  383. box->setNoContentMargin(true);
  384. struct State {
  385. rpl::variable<int> chosen;
  386. rpl::variable<uint64> shownPeer;
  387. uint64 savedShownPeer = 0;
  388. };
  389. const auto state = box->lifetime().make_state<State>();
  390. state->chosen = args.chosen;
  391. const auto changed = [=](int count) {
  392. state->chosen = count;
  393. };
  394. const auto initialShownPeer = ranges::find(
  395. args.top,
  396. true,
  397. &PaidReactionTop::my
  398. )->barePeerId;
  399. state->shownPeer = initialShownPeer;
  400. state->savedShownPeer = ranges::find_if(args.top, [](
  401. const PaidReactionTop &entry) {
  402. return entry.my && entry.barePeerId != 0;
  403. })->barePeerId;
  404. const auto content = box->verticalLayout();
  405. AddSkip(content, st::boxTitleClose.height + st::paidReactBubbleTop);
  406. const auto valueToRatio = DiscreterForMax(args.max).valueToRatio;
  407. auto bubbleRowState = state->chosen.value() | rpl::map([=](int value) {
  408. const auto full = st::boxWideWidth
  409. - st::boxRowPadding.left()
  410. - st::boxRowPadding.right();
  411. const auto marker = st::paidReactSlider.seekSize.width();
  412. const auto start = marker / 2;
  413. const auto inner = full - marker;
  414. const auto correct = start + inner * valueToRatio(value);
  415. return Premium::BubbleRowState{
  416. .counter = value,
  417. .ratio = correct / full,
  418. };
  419. });
  420. Premium::AddBubbleRow(
  421. content,
  422. st::boostBubble,
  423. BoxShowFinishes(box),
  424. std::move(bubbleRowState),
  425. Premium::BubbleType::Credits,
  426. nullptr,
  427. &st::paidReactBubbleIcon,
  428. st::boxRowPadding);
  429. const auto already = ranges::find(
  430. args.top,
  431. true,
  432. &PaidReactionTop::my)->count;
  433. PaidReactionSlider(content, args.chosen, args.max, changed);
  434. box->addTopButton(st::boxTitleClose, [=] { box->closeBox(); });
  435. box->addRow(
  436. object_ptr<FlatLabel>(
  437. box,
  438. tr::lng_paid_react_title(),
  439. st::boostCenteredTitle),
  440. st::boxRowPadding + QMargins(0, st::paidReactTitleSkip, 0, 0));
  441. const auto labelWrap = box->addRow(
  442. object_ptr<RpWidget>(box),
  443. (st::boxRowPadding
  444. + QMargins(0, st::lineWidth, 0, st::boostBottomSkip)));
  445. const auto label = CreateChild<FlatLabel>(
  446. labelWrap,
  447. (already
  448. ? tr::lng_paid_react_already(
  449. lt_count,
  450. rpl::single(already) | tr::to_count(),
  451. Text::RichLangValue)
  452. : tr::lng_paid_react_about(
  453. lt_channel,
  454. rpl::single(Text::Bold(args.channel)),
  455. Text::RichLangValue)),
  456. st::boostText);
  457. labelWrap->widthValue() | rpl::start_with_next([=](int width) {
  458. label->resizeToWidth(width);
  459. }, label->lifetime());
  460. label->heightValue() | rpl::start_with_next([=](int height) {
  461. const auto min = 2 * st::normalFont->height;
  462. const auto skip = std::max((min - height) / 2, 0);
  463. labelWrap->resize(labelWrap->width(), 2 * skip + height);
  464. label->moveToLeft(0, skip);
  465. }, label->lifetime());
  466. FillTopReactors(
  467. content,
  468. std::move(args.top),
  469. state->chosen.value(),
  470. state->shownPeer.value(),
  471. [=](uint64 barePeerId) {
  472. state->shownPeer = state->savedShownPeer = barePeerId;
  473. });
  474. const auto named = box->addRow(object_ptr<CenterWrap<Checkbox>>(
  475. box,
  476. object_ptr<Checkbox>(
  477. box,
  478. tr::lng_paid_react_show_in_top(tr::now),
  479. state->shownPeer.current() != 0)));
  480. named->entity()->checkedValue(
  481. ) | rpl::start_with_next([=](bool show) {
  482. state->shownPeer = show ? state->savedShownPeer : 0;
  483. }, named->lifetime());
  484. const auto button = box->addButton(rpl::single(QString()), [=] {
  485. args.send(state->chosen.current(), state->shownPeer.current());
  486. });
  487. box->boxClosing() | rpl::filter([=] {
  488. return state->shownPeer.current() != initialShownPeer;
  489. }) | rpl::start_with_next([=] {
  490. args.send(0, state->shownPeer.current());
  491. }, box->lifetime());
  492. {
  493. const auto buttonLabel = CreateChild<FlatLabel>(
  494. button,
  495. rpl::single(QString()),
  496. st::creditsBoxButtonLabel);
  497. args.submit(
  498. state->chosen.value()
  499. ) | rpl::start_with_next([=](const TextWithContext &text) {
  500. buttonLabel->setMarkedText(
  501. text.text,
  502. text.context);
  503. }, buttonLabel->lifetime());
  504. buttonLabel->setTextColorOverride(
  505. box->getDelegate()->style().button.textFg->c);
  506. button->sizeValue(
  507. ) | rpl::start_with_next([=](const QSize &size) {
  508. buttonLabel->moveToLeft(
  509. (size.width() - buttonLabel->width()) / 2,
  510. (size.height() - buttonLabel->height()) / 2);
  511. }, buttonLabel->lifetime());
  512. buttonLabel->setAttribute(Qt::WA_TransparentForMouseEvents);
  513. }
  514. box->widthValue(
  515. ) | rpl::start_with_next([=](int width) {
  516. const auto &padding = st::paidReactBox.buttonPadding;
  517. button->resizeToWidth(width
  518. - padding.left()
  519. - padding.right());
  520. button->moveToLeft(padding.left(), button->y());
  521. }, button->lifetime());
  522. {
  523. const auto balance = Settings::AddBalanceWidget(
  524. content,
  525. std::move(args.balanceValue),
  526. false);
  527. rpl::combine(
  528. balance->sizeValue(),
  529. box->widthValue()
  530. ) | rpl::start_with_next([=] {
  531. balance->moveToLeft(
  532. st::creditsHistoryRightSkip * 2,
  533. st::creditsHistoryRightSkip);
  534. balance->update();
  535. }, balance->lifetime());
  536. }
  537. }
  538. object_ptr<BoxContent> MakePaidReactionBox(PaidReactionBoxArgs &&args) {
  539. return Box(PaidReactionsBox, std::move(args));
  540. }
  541. QImage GenerateSmallBadgeImage(
  542. QString text,
  543. const style::icon &icon,
  544. QColor bg,
  545. QColor fg,
  546. const style::RoundCheckbox *borderSt) {
  547. const auto length = st::chatSimilarBadgeFont->width(text);
  548. const auto contents = st::chatSimilarLockedIconPosition.x()
  549. + icon.width()
  550. + st::paidReactTopStarSkip
  551. + length;
  552. const auto badge = QRect(
  553. st::chatSimilarBadgePadding.left(),
  554. st::chatSimilarBadgePadding.top(),
  555. contents,
  556. st::chatSimilarBadgeFont->height);
  557. const auto rect = badge.marginsAdded(st::chatSimilarBadgePadding);
  558. const auto add = borderSt ? borderSt->width : 0;
  559. const auto ratio = style::DevicePixelRatio();
  560. auto result = QImage(
  561. (rect + QMargins(add, add, add, add)).size() * ratio,
  562. QImage::Format_ARGB32_Premultiplied);
  563. result.setDevicePixelRatio(ratio);
  564. result.fill(Qt::transparent);
  565. auto q = QPainter(&result);
  566. const auto &font = st::chatSimilarBadgeFont;
  567. const auto textTop = badge.y() + font->ascent;
  568. const auto position = st::chatSimilarLockedIconPosition;
  569. auto hq = PainterHighQualityEnabler(q);
  570. q.translate(add, add);
  571. q.setBrush(bg);
  572. if (borderSt) {
  573. q.setPen(QPen(borderSt->border->c, borderSt->width));
  574. } else {
  575. q.setPen(Qt::NoPen);
  576. }
  577. const auto radius = rect.height() / 2.;
  578. const auto shift = add / 2.;
  579. q.drawRoundedRect(
  580. QRectF(rect) + QMarginsF(shift, shift, shift, shift),
  581. radius,
  582. radius);
  583. auto textLeft = 0;
  584. icon.paint(
  585. q,
  586. badge.x() + position.x(),
  587. badge.y() + position.y(),
  588. rect.width());
  589. textLeft += position.x() + icon.width() + st::paidReactTopStarSkip;
  590. q.setFont(font);
  591. q.setPen(fg);
  592. q.drawText(textLeft, textTop, text);
  593. q.end();
  594. return result;
  595. }
  596. } // namespace Ui