MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / initButtons

Method initButtons

Telegram/SourceFiles/ui/chat/choose_theme_controller.cpp:289–374  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287}
288
289void ChooseThemeController::initButtons() {
290 const auto controls = _wrap->add(object_ptr<RpWidget>(_wrap.get()));
291 const auto apply = CreateChild<RoundButton>(
292 controls,
293 tr::lng_chat_theme_apply(),
294 st::defaultLightButton);
295 const auto choose = CreateChild<RoundButton>(
296 controls,
297 tr::lng_chat_theme_change_wallpaper(),
298 st::defaultLightButton);
299
300 const auto &margin = st::chatThemeButtonMargin;
301 controls->resize(
302 margin.left() + choose->width() + margin.right(),
303 margin.top() + choose->height() + margin.bottom());
304 rpl::combine(
305 controls->widthValue(),
306 apply->widthValue(),
307 choose->widthValue(),
308 _chosen.value()
309 ) | rpl::on_next([=](
310 int outer,
311 int applyWidth,
312 int chooseWidth,
313 QString chosen) {
314 const auto was = _peer->themeToken();
315 const auto now = (chosen == kDisableElement()) ? QString() : chosen;
316 const auto changed = (now != was);
317 apply->setVisible(changed);
318 choose->setVisible(!changed);
319 const auto shown = changed ? apply : choose;
320 const auto shownWidth = changed ? applyWidth : chooseWidth;
321 const auto inner = margin.left() + shownWidth + margin.right();
322 const auto left = (outer - inner) / 2;
323 shown->moveToLeft(left, margin.top());
324 }, controls->lifetime());
325
326 const auto setTheme = crl::guard(apply, [=](
327 const QString &token,
328 const std::shared_ptr<Ui::ChatTheme> &theme) {
329 SetPeerTheme(_controller, _peer, token, theme);
330 _controller->toggleChooseChatTheme(_peer);
331 });
332 const auto confirmTakeGiftTheme = crl::guard(apply, [=](
333 const QString &token,
334 const std::shared_ptr<Ui::ChatTheme> &theme,
335 not_null<PeerData*> nowHasTheme) {
336 _controller->show(Box([=](not_null<Ui::GenericBox*> box) {
337 const auto confirmed = [=](Fn<void()> close) {
338 setTheme(token, theme);
339 close();
340 };
341 Ui::ConfirmBox(box, {
342 .text = tr::lng_chat_theme_gift_replace(
343 lt_name,
344 rpl::single(tr::bold(nowHasTheme->shortName())),
345 tr::marked),
346 .confirmed = confirmed,

Callers

nothing calls this directly

Calls 15

SetPeerThemeFunction · 0.85
resizeMethod · 0.80
moveToLeftMethod · 0.80
shortNameMethod · 0.80
QStringClass · 0.50
BoxClass · 0.50
ConfirmBoxFunction · 0.50
addMethod · 0.45
getMethod · 0.45
widthMethod · 0.45
topMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected