Moved out making of "new" badges to single place.

This commit is contained in:
23rd 2023-12-17 06:55:55 +03:00
parent cd5a6025f6
commit 82d73e2396
5 changed files with 98 additions and 59 deletions

View File

@ -47,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/wrap/padding_wrap.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/new_badges.h"
#include "ui/painter.h"
#include "ui/power_saving.h"
#include "ui/vertical_list.h"
@ -951,31 +952,8 @@ void Premium::setupContent() {
descriptionPadding);
description->setAttribute(Qt::WA_TransparentForMouseEvents);
const auto badge = entry.newBadge
? Ui::CreateChild<Ui::PaddingWrap<Ui::FlatLabel>>(
content,
object_ptr<Ui::FlatLabel>(
content,
tr::lng_premium_summary_new_badge(),
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());
label->geometryValue(
) | rpl::start_with_next([=](QRect geometry) {
badge->move(st::settingsPremiumNewBadgePosition
+ QPoint(label->x() + label->width(), label->y()));
}, badge->lifetime());
if (entry.newBadge) {
Ui::NewBadge::AddAfterLabel(content, label);
}
const auto dummy = Ui::CreateChild<Ui::AbstractButton>(content);
dummy->setAttribute(Qt::WA_TransparentForMouseEvents);

View File

@ -0,0 +1,69 @@
/*
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 "ui/new_badges.h"
#include "lang/lang_keys.h"
#include "ui/painter.h"
#include "ui/widgets/labels.h"
#include "styles/style_window.h"
#include "styles/style_settings.h"
namespace Ui::NewBadge {
namespace {
[[nodiscard]] not_null<Ui::RpWidget*> CreateNewBadge(
not_null<Ui::RpWidget*> parent,
rpl::producer<QString> text) {
const auto badge = Ui::CreateChild<Ui::PaddingWrap<Ui::FlatLabel>>(
parent.get(),
object_ptr<Ui::FlatLabel>(
parent,
std::move(text),
st::settingsPremiumNewBadge),
st::settingsPremiumNewBadgePadding);
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());
return badge;
}
} // namespace
void AddToRight(not_null<Ui::RpWidget*> parent) {
const auto badge = CreateNewBadge(parent, tr::lng_bot_side_menu_new());
parent->sizeValue(
) | rpl::start_with_next([=](QSize size) {
badge->moveToRight(
st::mainMenuButton.padding.right(),
(size.height() - badge->height()) / 2,
size.width());
}, badge->lifetime());
}
void AddAfterLabel(
not_null<Ui::RpWidget*> parent,
not_null<Ui::RpWidget*> label) {
const auto badge = CreateNewBadge(
parent,
tr::lng_premium_summary_new_badge());
label->geometryValue(
) | rpl::start_with_next([=](QRect geometry) {
badge->move(st::settingsPremiumNewBadgePosition
+ QPoint(label->x() + label->width(), label->y()));
}, badge->lifetime());
}
} // namespace Ui::NewBadge

View File

@ -0,0 +1,21 @@
/*
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
*/
#pragma once
namespace Ui {
class RpWidget;
} // namespace Ui
namespace Ui::NewBadge {
void AddToRight(not_null<Ui::RpWidget*> parent);
void AddAfterLabel(
not_null<Ui::RpWidget*> parent,
not_null<Ui::RpWidget*> label);
} // namespace Ui::NewBadge

View File

@ -15,22 +15,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/controls/userpic_button.h"
#include "ui/effects/snowflakes.h"
#include "ui/effects/toggle_arrow.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/popup_menu.h"
#include "ui/widgets/scroll_area.h"
#include "ui/widgets/shadow.h"
#include "ui/widgets/tooltip.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/text/text_utilities.h"
#include "ui/text/text_options.h"
#include "ui/new_badges.h"
#include "ui/painter.h"
#include "ui/empty_userpic.h"
#include "ui/vertical_list.h"
#include "ui/unread_badge_paint.h"
#include "inline_bots/bot_attach_web_view.h"
#include "mainwindow.h"
#include "storage/localstorage.h"
#include "storage/storage_account.h"
#include "support/support_templates.h"
@ -50,7 +46,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "calls/calls_box_controller.h"
#include "lang/lang_keys.h"
#include "core/click_handler_types.h"
#include "core/core_settings.h"
#include "core/application.h"
#include "main/main_session.h"
#include "main/main_session_settings.h"
@ -66,7 +61,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwidget.h"
#include "styles/style_chat.h" // popupMenuExpandedSeparator
#include "styles/style_window.h"
#include "styles/style_widgets.h"
#include "styles/style_settings.h"
#include "styles/style_info.h" // infoTopBarMenu
#include "styles/style_layers.h"
@ -301,33 +295,8 @@ void SetupMenuBots(
}
}, button->lifetime());
const auto badge = bots->showMainMenuNewBadge(bot)
? Ui::CreateChild<Ui::PaddingWrap<Ui::FlatLabel>>(
button,
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());
if (bots->showMainMenuNewBadge(bot)) {
Ui::NewBadge::AddToRight(button);
}
}
wrap->resizeToWidth(width);

View File

@ -377,6 +377,8 @@ PRIVATE
ui/empty_userpic.h
ui/grouped_layout.cpp
ui/grouped_layout.h
ui/new_badges.cpp
ui/new_badges.h
ui/power_saving.cpp
ui/power_saving.h
ui/vertical_list.cpp