about_sponsored_box.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "boxes/about_sponsored_box.h"
  8. #include "core/file_utilities.h"
  9. #include "lang/lang_keys.h"
  10. #include "ui/layers/generic_box.h"
  11. #include "ui/widgets/buttons.h"
  12. #include "ui/widgets/labels.h"
  13. #include "styles/style_boxes.h"
  14. #include "styles/style_layers.h"
  15. namespace Ui {
  16. namespace {
  17. constexpr auto kUrl = "https://promote.telegram.org"_cs;
  18. } // namespace
  19. void AboutSponsoredBox(not_null<Ui::GenericBox*> box) {
  20. box->setTitle(tr::lng_sponsored_title());
  21. box->setWidth(st::boxWideWidth);
  22. box->addButton(tr::lng_box_ok(), [=] { box->closeBox(); });
  23. const auto addUrl = [&] {
  24. const auto &st = st::sponsoredUrlButton;
  25. const auto row = box->addRow(object_ptr<RpWidget>(box));
  26. row->resize(0, st.height + st.padding.top() + st.padding.bottom());
  27. const auto button = Ui::CreateChild<RoundButton>(
  28. row,
  29. rpl::single<QString>(kUrl.utf8()),
  30. st);
  31. button->setBrushOverride(Qt::NoBrush);
  32. button->setPenOverride(QPen(st::historyLinkInFg));
  33. button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
  34. rpl::combine(
  35. row->sizeValue(),
  36. button->sizeValue()
  37. ) | rpl::start_with_next([=](
  38. const QSize &rowSize,
  39. const QSize &buttonSize) {
  40. button->moveToLeft(
  41. (rowSize.width() - buttonSize.width()) / 2,
  42. (rowSize.height() - buttonSize.height()) / 2);
  43. }, row->lifetime());
  44. button->addClickHandler([=] {
  45. File::OpenUrl(kUrl.utf8());
  46. });
  47. };
  48. const auto &stLabel = st::aboutLabel;
  49. const auto info1 = box->addRow(object_ptr<FlatLabel>(box, stLabel));
  50. info1->setText(tr::lng_sponsored_info_description1(tr::now));
  51. box->addSkip(st::sponsoredUrlButtonSkip);
  52. addUrl();
  53. box->addSkip(st::sponsoredUrlButtonSkip);
  54. const auto info2 = box->addRow(object_ptr<FlatLabel>(box, stLabel));
  55. info2->setText(tr::lng_sponsored_info_description2(tr::now));
  56. }
  57. } // namespace Ui