new_badges.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 "ui/new_badges.h"
  8. #include "lang/lang_keys.h"
  9. #include "ui/painter.h"
  10. #include "ui/widgets/labels.h"
  11. #include "styles/style_window.h"
  12. #include "styles/style_settings.h"
  13. namespace Ui::NewBadge {
  14. not_null<Ui::RpWidget*> CreateNewBadge(
  15. not_null<Ui::RpWidget*> parent,
  16. rpl::producer<QString> text) {
  17. const auto badge = Ui::CreateChild<Ui::PaddingWrap<Ui::FlatLabel>>(
  18. parent.get(),
  19. object_ptr<Ui::FlatLabel>(
  20. parent,
  21. std::move(text),
  22. st::settingsPremiumNewBadge),
  23. st::settingsPremiumNewBadgePadding);
  24. badge->show();
  25. badge->setAttribute(Qt::WA_TransparentForMouseEvents);
  26. badge->paintRequest() | rpl::start_with_next([=] {
  27. auto p = QPainter(badge);
  28. auto hq = PainterHighQualityEnabler(p);
  29. p.setPen(Qt::NoPen);
  30. p.setBrush(st::windowBgActive);
  31. const auto r = st::settingsPremiumNewBadgePadding.left();
  32. p.drawRoundedRect(badge->rect(), r, r);
  33. }, badge->lifetime());
  34. return badge;
  35. }
  36. void AddToRight(not_null<Ui::RpWidget*> parent) {
  37. const auto badge = CreateNewBadge(parent, tr::lng_bot_side_menu_new());
  38. parent->sizeValue(
  39. ) | rpl::start_with_next([=](QSize size) {
  40. badge->moveToRight(
  41. st::mainMenuButton.padding.right(),
  42. (size.height() - badge->height()) / 2,
  43. size.width());
  44. }, badge->lifetime());
  45. }
  46. void AddAfterLabel(
  47. not_null<Ui::RpWidget*> parent,
  48. not_null<Ui::RpWidget*> label) {
  49. const auto badge = CreateNewBadge(
  50. parent,
  51. tr::lng_premium_summary_new_badge());
  52. label->geometryValue(
  53. ) | rpl::start_with_next([=](QRect geometry) {
  54. badge->move(st::settingsPremiumNewBadgePosition
  55. + QPoint(label->x() + label->width(), label->y()));
  56. }, badge->lifetime());
  57. }
  58. } // namespace Ui::NewBadge