Added ability to fill chat participant statuses with custom widgets.

This commit is contained in:
23rd 2023-01-29 19:39:57 +03:00 committed by John Preston
parent 8688a68115
commit 642554828c

View file

@ -207,16 +207,36 @@ ChatRestrictions DisabledByAdminRights(not_null<PeerData*> peer) {
: Flag::ChangeInfo); : Flag::ChangeInfo);
} }
not_null<Ui::Checkbox*> AddDefaultCheckbox(
not_null<Ui::VerticalLayout*> container,
const QString &text,
bool toggled,
bool locked) {
auto toggle = std::make_unique<Ui::ToggleView>(
st::rightsToggle,
toggled);
toggle->setLocked(locked);
return container->add(
object_ptr<Ui::Checkbox>(
container,
text,
st::rightsCheckbox,
std::move(toggle)),
st::rightsToggleMargin);
};
template < template <
typename Flags, typename Flags,
typename DisabledMessagePairs, typename DisabledMessagePairs,
typename FlagLabelPairs> typename FlagLabelPairs,
typename CheckboxFactory>
[[nodiscard]] EditFlagsControl<Flags, Ui::RpWidget> CreateEditFlags( [[nodiscard]] EditFlagsControl<Flags, Ui::RpWidget> CreateEditFlags(
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
rpl::producer<QString> header, rpl::producer<QString> header,
Flags checked, Flags checked,
const DisabledMessagePairs &disabledMessagePairs, const DisabledMessagePairs &disabledMessagePairs,
const FlagLabelPairs &flagLabelPairs) { const FlagLabelPairs &flagLabelPairs,
CheckboxFactory checkboxFactory) {
const auto checkboxes = container->lifetime( const auto checkboxes = container->lifetime(
).make_state<std::map<Flags, QPointer<Ui::Checkbox>>>(); ).make_state<std::map<Flags, QPointer<Ui::Checkbox>>>();
@ -255,17 +275,11 @@ template <
? std::make_optional(lockedIt->second) ? std::make_optional(lockedIt->second)
: std::nullopt; : std::nullopt;
const auto toggled = ((checked & flags) != 0); const auto toggled = ((checked & flags) != 0);
auto toggle = std::make_unique<Ui::ToggleView>( const auto control = checkboxFactory(
st::rightsToggle, container,
toggled); text,
toggle->setLocked(locked.has_value()); toggled,
const auto control = container->add( locked.has_value());
object_ptr<Ui::Checkbox>(
container,
text,
st::rightsCheckbox,
std::move(toggle)),
st::rightsToggleMargin);
control->checkedChanges( control->checkedChanges(
) | rpl::start_with_next([=](bool checked) { ) | rpl::start_with_next([=](bool checked) {
if (locked.has_value()) { if (locked.has_value()) {
@ -740,7 +754,8 @@ EditFlagsControl<ChatRestrictions, Ui::RpWidget> CreateEditRestrictions(
header, header,
NegateRestrictions(restrictions), NegateRestrictions(restrictions),
disabledMessages, disabledMessages,
RestrictionLabels(options)); RestrictionLabels(options),
AddDefaultCheckbox);
result.widget = std::move(widget); result.widget = std::move(widget);
result.value = [original = std::move(result.value)]{ result.value = [original = std::move(result.value)]{
return NegateRestrictions(original()); return NegateRestrictions(original());
@ -764,7 +779,8 @@ EditFlagsControl<ChatAdminRights, Ui::RpWidget> CreateEditAdminRights(
header, header,
rights, rights,
disabledMessages, disabledMessages,
AdminRightLabels(options)); AdminRightLabels(options),
AddDefaultCheckbox);
result.widget = std::move(widget); result.widget = std::move(widget);
return result; return result;
} }