mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Adapt edit topic box to General.
This commit is contained in:
parent
d0ae07f3c2
commit
5e20c15c20
1 changed files with 65 additions and 27 deletions
|
@ -194,6 +194,39 @@ bool DefaultIconEmoji::readyInDefaultState() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] not_null<Ui::AbstractButton*> GeneralIconPreview(
|
||||||
|
not_null<QWidget*> parent) {
|
||||||
|
using namespace Info::Profile;
|
||||||
|
struct State {
|
||||||
|
QImage frame;
|
||||||
|
};
|
||||||
|
const auto tag = Data::CustomEmojiManager::SizeTag::Large;
|
||||||
|
const auto size = EditIconSize();
|
||||||
|
const auto result = Ui::CreateChild<Ui::AbstractButton>(parent.get());
|
||||||
|
result->show();
|
||||||
|
result->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
const auto state = result->lifetime().make_state<State>();
|
||||||
|
|
||||||
|
rpl::single(rpl::empty) | rpl::then(
|
||||||
|
style::PaletteChanged()
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
state->frame = Data::ForumTopicGeneralIconFrame(
|
||||||
|
st::largeForumTopicIcon.size,
|
||||||
|
st::windowSubTextFg);
|
||||||
|
result->update();
|
||||||
|
}, result->lifetime());
|
||||||
|
|
||||||
|
result->resize(size, size);
|
||||||
|
result->paintRequest(
|
||||||
|
) | rpl::start_with_next([=](QRect clip) {
|
||||||
|
auto p = QPainter(result);
|
||||||
|
const auto skip = (size - st::largeForumTopicIcon.size) / 2;
|
||||||
|
p.drawImage(skip, skip, state->frame);
|
||||||
|
}, result->lifetime());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
struct IconSelector {
|
struct IconSelector {
|
||||||
Fn<bool(not_null<Ui::RpWidget*>)> paintIconFrame;
|
Fn<bool(not_null<Ui::RpWidget*>)> paintIconFrame;
|
||||||
rpl::producer<DocumentId> iconIdValue;
|
rpl::producer<DocumentId> iconIdValue;
|
||||||
|
@ -404,14 +437,16 @@ void EditForumTopicBox(
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto paintIconFrame = [=](not_null<Ui::RpWidget*> widget) {
|
const auto paintIconFrame = [=](not_null<Ui::RpWidget*> widget) {
|
||||||
return state->paintIconFrame(widget);
|
return state->paintIconFrame && state->paintIconFrame(widget);
|
||||||
};
|
};
|
||||||
const auto icon = EditIconButton(
|
const auto icon = (topic && topic->isGeneral())
|
||||||
title->parentWidget(),
|
? GeneralIconPreview(title->parentWidget())
|
||||||
controller,
|
: EditIconButton(
|
||||||
state->defaultIcon.value(),
|
title->parentWidget(),
|
||||||
state->iconId.value(),
|
controller,
|
||||||
paintIconFrame);
|
state->defaultIcon.value(),
|
||||||
|
state->iconId.value(),
|
||||||
|
paintIconFrame);
|
||||||
|
|
||||||
title->geometryValue(
|
title->geometryValue(
|
||||||
) | rpl::start_with_next([=](QRect geometry) {
|
) | rpl::start_with_next([=](QRect geometry) {
|
||||||
|
@ -444,27 +479,29 @@ void EditForumTopicBox(
|
||||||
};
|
};
|
||||||
}, box->lifetime());
|
}, box->lifetime());
|
||||||
|
|
||||||
Settings::AddDividerText(
|
if (!topic || !topic->isGeneral()) {
|
||||||
top,
|
Settings::AddDividerText(
|
||||||
tr::lng_forum_choose_title_and_icon());
|
top,
|
||||||
|
tr::lng_forum_choose_title_and_icon());
|
||||||
|
|
||||||
box->setScrollStyle(st::reactPanelScroll);
|
box->setScrollStyle(st::reactPanelScroll);
|
||||||
|
|
||||||
auto selector = AddIconSelector(
|
auto selector = AddIconSelector(
|
||||||
box,
|
box,
|
||||||
icon,
|
icon,
|
||||||
controller,
|
controller,
|
||||||
state->defaultIcon.value(),
|
state->defaultIcon.value(),
|
||||||
top->heightValue(),
|
top->heightValue(),
|
||||||
state->iconId.current(),
|
state->iconId.current(),
|
||||||
[&](object_ptr<Ui::RpWidget> footer) {
|
[&](object_ptr<Ui::RpWidget> footer) {
|
||||||
top->add(std::move(footer)); });
|
top->add(std::move(footer)); });
|
||||||
state->paintIconFrame = std::move(selector.paintIconFrame);
|
state->paintIconFrame = std::move(selector.paintIconFrame);
|
||||||
std::move(
|
std::move(
|
||||||
selector.iconIdValue
|
selector.iconIdValue
|
||||||
) | rpl::start_with_next([=](DocumentId iconId) {
|
) | rpl::start_with_next([=](DocumentId iconId) {
|
||||||
state->iconId = (iconId != kDefaultIconId) ? iconId : 0;
|
state->iconId = (iconId != kDefaultIconId) ? iconId : 0;
|
||||||
}, box->lifetime());
|
}, box->lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
const auto create = [=] {
|
const auto create = [=] {
|
||||||
const auto channel = forum->peer->asChannel();
|
const auto channel = forum->peer->asChannel();
|
||||||
|
@ -508,7 +545,8 @@ void EditForumTopicBox(
|
||||||
const auto api = &forum->session().api();
|
const auto api = &forum->session().api();
|
||||||
const auto weak = Ui::MakeWeak(box.get());
|
const auto weak = Ui::MakeWeak(box.get());
|
||||||
state->requestId = api->request(MTPchannels_EditForumTopic(
|
state->requestId = api->request(MTPchannels_EditForumTopic(
|
||||||
MTP_flags(Flag::f_title | Flag::f_icon_emoji_id),
|
MTP_flags(Flag::f_title
|
||||||
|
| (topic->isGeneral() ? Flag() : Flag::f_icon_emoji_id)),
|
||||||
topic->channel()->inputChannel,
|
topic->channel()->inputChannel,
|
||||||
MTP_int(rootId),
|
MTP_int(rootId),
|
||||||
MTP_string(title->getLastText().trimmed()),
|
MTP_string(title->getLastText().trimmed()),
|
||||||
|
|
Loading…
Add table
Reference in a new issue