2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-01 15:15:13 +00:00

Improve main menu bots disclaimer acceptance.

This commit is contained in:
John Preston
2023-09-08 21:55:28 +04:00
parent 229f7a2c15
commit ef969df86e
8 changed files with 205 additions and 121 deletions

View File

@@ -211,15 +211,19 @@ void SetupMenuBots(
) | rpl::then(
bots->attachBotsUpdates()
) | rpl::start_with_next([=] {
const auto width = wrap->widthNoMargins();
wrap->clear();
for (const auto &bot : bots->attachBots()) {
if (!bot.inMainMenu) {
continue;
}
const auto button = Settings::AddButton(
container,
wrap,
rpl::single(bot.name),
st::mainMenuButton);
const auto menu = button->lifetime().make_state<
base::unique_qptr<Ui::PopupMenu>
>();
const auto icon = Ui::CreateChild<InlineBots::MenuBotIcon>(
button.get(),
bot.media);
@@ -229,12 +233,57 @@ void SetupMenuBots(
st::mainMenuButton.iconLeft,
(height - icon->height()) / 2);
}, button->lifetime());
button->setClickedCallback([=] {
bots->requestSimple(controller, bot.user, {
.fromMainMenu = true,
});
});
const auto user = bot.user;
button->setAcceptBoth(true);
button->clicks(
) | rpl::start_with_next([=](Qt::MouseButton which) {
if (which == Qt::LeftButton) {
bots->requestSimple(controller, user, {
.fromMainMenu = true,
});
} else {
(*menu) = nullptr;
(*menu) = base::make_unique_q<Ui::PopupMenu>(
button,
st::popupMenuWithIcons);
(*menu)->addAction(
tr::lng_bot_remove_from_menu(tr::now),
[=] { bots->removeFromMenu(user); },
&st::menuIconDelete);
(*menu)->popup(QCursor::pos());
}
}, button->lifetime());
const auto badge = bots->showingDisclaimer(bot)
? Ui::CreateChild<Ui::PaddingWrap<Ui::FlatLabel>>(
button.get(),
object_ptr<Ui::FlatLabel>(
button,
tr::lng_bot_side_menu_new(),
st::settingsPremiumNewBadge),
st::settingsPremiumNewBadgePadding)
: nullptr;
if (badge) {
badge->setAttribute(Qt::WA_TransparentForMouseEvents);
badge->paintRequest() | rpl::start_with_next([=] {
auto p = QPainter(badge);
auto hq = PainterHighQualityEnabler(p);
p.setPen(Qt::NoPen);
p.setBrush(st::windowBgActive);
const auto r = st::settingsPremiumNewBadgePadding.left();
p.drawRoundedRect(badge->rect(), r, r);
}, badge->lifetime());
button->sizeValue(
) | rpl::start_with_next([=](QSize size) {
badge->moveToRight(
st::mainMenuButton.padding.right(),
(size.height() - badge->height()) / 2,
size.width());
}, badge->lifetime());
}
}
wrap->resizeToWidth(width);
}, wrap->lifetime());
}