File: about_sponsored_box.cpp

package info (click to toggle)
telegram-desktop 4.6.5%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 53,300 kB
  • sloc: cpp: 605,857; python: 3,978; ansic: 1,636; sh: 965; makefile: 841; objc: 652; javascript: 187; xml: 165
file content (68 lines) | stat: -rw-r--r-- 2,067 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.

For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "boxes/about_sponsored_box.h"

#include "core/file_utilities.h"
#include "lang/lang_keys.h"
#include "ui/layers/generic_box.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
#include "styles/style_boxes.h"
#include "styles/style_layers.h"

namespace Ui {
namespace {

constexpr auto kUrl = "https://promote.telegram.org"_cs;

} // namespace

void AboutSponsoredBox(not_null<Ui::GenericBox*> box) {
	box->setTitle(tr::lng_sponsored_title());
	box->setWidth(st::boxWideWidth);
	box->addButton(tr::lng_box_ok(), [=] { box->closeBox(); });

	const auto addUrl = [&] {
		const auto &st = st::sponsoredUrlButton;
		const auto row = box->addRow(object_ptr<RpWidget>(box));
		row->resize(0, st.height + st.padding.top() + st.padding.bottom());
		const auto button = Ui::CreateChild<RoundButton>(
			row,
			rpl::single<QString>(kUrl.utf8()),
			st);
		button->setBrushOverride(Qt::NoBrush);
		button->setPenOverride(QPen(st::historyLinkInFg));
		button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
		rpl::combine(
			row->sizeValue(),
			button->sizeValue()
		) | rpl::start_with_next([=](
				const QSize &rowSize,
				const QSize &buttonSize) {
			button->moveToLeft(
				(rowSize.width() - buttonSize.width()) / 2,
				(rowSize.height() - buttonSize.height()) / 2);
		}, row->lifetime());
		button->addClickHandler([=] {
			File::OpenUrl(kUrl.utf8());
		});
	};

	const auto &stLabel = st::aboutLabel;
	const auto info1 = box->addRow(object_ptr<FlatLabel>(box, stLabel));
	info1->setText(tr::lng_sponsored_info_description1(tr::now));

	box->addSkip(st::sponsoredUrlButtonSkip);
	addUrl();
	box->addSkip(st::sponsoredUrlButtonSkip);

	const auto info2 = box->addRow(object_ptr<FlatLabel>(box, stLabel));
	info2->setText(tr::lng_sponsored_info_description2(tr::now));
}

} // namespace Ui