Add rpl interface to RadiobuttonGroup.

This commit is contained in:
John Preston 2024-02-23 13:29:17 +04:00
parent e05eb63476
commit f85c3c88f7
22 changed files with 50 additions and 46 deletions

View file

@ -1018,7 +1018,7 @@ void SetupChannelBox::prepare() {
cancel); cancel);
connect(_link, &Ui::MaskedInputField::changed, [=] { handleChange(); }); connect(_link, &Ui::MaskedInputField::changed, [=] { handleChange(); });
_link->setVisible(_privacyGroup->value() == Privacy::Public); _link->setVisible(_privacyGroup->current() == Privacy::Public);
_privacyGroup->setChangedCallback([=](Privacy value) { _privacyGroup->setChangedCallback([=](Privacy value) {
privacyChanged(value); privacyChanged(value);
@ -1063,7 +1063,7 @@ void SetupChannelBox::updateMaxHeight() {
: 0) : 0)
+ st::newGroupPadding.bottom(); + st::newGroupPadding.bottom();
if (!_channel->isMegagroup() if (!_channel->isMegagroup()
|| _privacyGroup->value() == Privacy::Public) { || _privacyGroup->current() == Privacy::Public) {
newHeight += st::newGroupLinkPadding.top() newHeight += st::newGroupLinkPadding.top()
+ _link->height() + _link->height()
+ st::newGroupLinkPadding.bottom(); + st::newGroupLinkPadding.bottom();
@ -1264,7 +1264,7 @@ void SetupChannelBox::save() {
}; };
if (_saveRequestId) { if (_saveRequestId) {
return; return;
} else if (_privacyGroup->value() == Privacy::Private) { } else if (_privacyGroup->current() == Privacy::Private) {
closeBox(); closeBox();
} else { } else {
const auto link = _link->text().trimmed(); const auto link = _link->text().trimmed();

View file

@ -81,9 +81,9 @@ void AutoLockBox::prepare() {
const auto timeInput = Ui::CreateChild<Ui::TimeInput>( const auto timeInput = Ui::CreateChild<Ui::TimeInput>(
this, this,
(group->value() == kCustom) (group->current() == kCustom
? TimeString(currentTime) ? TimeString(currentTime)
: kDefaultCustom.utf8(), : kDefaultCustom.utf8()),
st::autolockTimeField, st::autolockTimeField,
st::autolockDateField, st::autolockDateField,
st::scheduleTimeSeparator, st::scheduleTimeSeparator,
@ -115,7 +115,9 @@ void AutoLockBox::prepare() {
}); });
rpl::merge( rpl::merge(
boxClosing() | rpl::filter([=] { return group->value() == kCustom; }), boxClosing() | rpl::filter(
[=] { return group->current() == kCustom; }
),
timeInput->submitRequests() timeInput->submitRequests()
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
if (const auto result = collect()) { if (const auto result = collect()) {

View file

@ -717,7 +717,7 @@ void ProxiesBox::refreshProxyForCalls() {
return; return;
} }
_proxyForCalls->toggle( _proxyForCalls->toggle(
(_proxySettings->value() == ProxyData::Settings::Enabled (_proxySettings->current() == ProxyData::Settings::Enabled
&& _currentProxySupportsCallsId != 0), && _currentProxySupportsCallsId != 0),
anim::type::normal); anim::type::normal);
} }
@ -864,7 +864,7 @@ void ProxyBox::refreshButtons() {
addButton(tr::lng_settings_save(), [=] { save(); }); addButton(tr::lng_settings_save(), [=] { save(); });
addButton(tr::lng_cancel(), [=] { closeBox(); }); addButton(tr::lng_cancel(), [=] { closeBox(); });
const auto type = _type->value(); const auto type = _type->current();
if (type == Type::Socks5 || type == Type::Mtproto) { if (type == Type::Socks5 || type == Type::Mtproto) {
addLeftButton(tr::lng_proxy_share(), [=] { share(); }); addLeftButton(tr::lng_proxy_share(), [=] { share(); });
} }
@ -885,7 +885,7 @@ void ProxyBox::share() {
ProxyData ProxyBox::collectData() { ProxyData ProxyBox::collectData() {
auto result = ProxyData(); auto result = ProxyData();
result.type = _type->value(); result.type = _type->current();
result.host = _host->getLastText().trimmed(); result.host = _host->getLastText().trimmed();
result.port = _port->getLastText().trimmed().toInt(); result.port = _port->getLastText().trimmed().toInt();
result.user = (result.type == Type::Mtproto) result.user = (result.type == Type::Mtproto)
@ -1053,7 +1053,7 @@ void ProxyBox::setupControls(const ProxyData &data) {
handleType(type); handleType(type);
refreshButtons(); refreshButtons();
}); });
handleType(_type->value()); handleType(_type->current());
} }
void ProxyBox::addLabel( void ProxyBox::addLabel(

View file

@ -44,7 +44,9 @@ void DownloadPathBox::prepare() {
setTitle(tr::lng_download_path_header()); setTitle(tr::lng_download_path_header());
_group->setChangedCallback([this](Directory value) { radioChanged(value); }); _group->setChangedCallback([this](Directory value) {
radioChanged(value);
});
_pathLink->addClickHandler([=] { editPath(); }); _pathLink->addClickHandler([=] { editPath(); });
if (!_path.isEmpty() && _path != FileDialog::Tmp()) { if (!_path.isEmpty() && _path != FileDialog::Tmp()) {
@ -54,7 +56,7 @@ void DownloadPathBox::prepare() {
} }
void DownloadPathBox::updateControlsVisibility() { void DownloadPathBox::updateControlsVisibility() {
auto custom = (_group->value() == Directory::Custom); auto custom = (_group->current() == Directory::Custom);
_pathLink->setVisible(custom); _pathLink->setVisible(custom);
auto newHeight = st::boxOptionListPadding.top() + (_default ? _default->getMargins().top() + _default->heightNoMargins() : 0) + st::boxOptionListSkip + _temp->heightNoMargins() + st::boxOptionListSkip + _dir->heightNoMargins(); auto newHeight = st::boxOptionListPadding.top() + (_default ? _default->getMargins().top() + _default->heightNoMargins() : 0) + st::boxOptionListSkip + _temp->heightNoMargins() + st::boxOptionListSkip + _dir->heightNoMargins();
@ -122,7 +124,7 @@ void DownloadPathBox::editPath() {
void DownloadPathBox::save() { void DownloadPathBox::save() {
#ifndef OS_WIN_STORE #ifndef OS_WIN_STORE
auto value = _group->value(); auto value = _group->current();
auto computePath = [this, value] { auto computePath = [this, value] {
if (value == Directory::Custom) { if (value == Directory::Custom) {
return _path; return _path;

View file

@ -582,7 +582,7 @@ void EditMessagesPrivacyBox(
box->addButton(tr::lng_settings_save(), [=] { box->addButton(tr::lng_settings_save(), [=] {
if (controller->session().premium()) { if (controller->session().premium()) {
privacy->updateNewRequirePremium( privacy->updateNewRequirePremium(
group->value() == kOptionPremium); group->current() == kOptionPremium);
box->closeBox(); box->closeBox();
} else { } else {
showToast(); showToast();

View file

@ -386,7 +386,7 @@ void GiftBox(
state->buttonText.events(), state->buttonText.events(),
Ui::Premium::GiftGradientStops(), Ui::Premium::GiftGradientStops(),
[=] { [=] {
const auto value = group->value(); const auto value = group->current();
return (value < options.size() && value >= 0) return (value < options.size() && value >= 0)
? options[value].botUrl ? options[value].botUrl
: QString(); : QString();
@ -665,7 +665,7 @@ void GiftsBox(
} }
auto invoice = api->invoice( auto invoice = api->invoice(
users.size(), users.size(),
api->monthsFromPreset(group->value())); api->monthsFromPreset(group->current()));
invoice.purpose = Payments::InvoicePremiumGiftCodeUsers{ users }; invoice.purpose = Payments::InvoicePremiumGiftCodeUsers{ users };
state->confirmButtonBusy = true; state->confirmButtonBusy = true;

View file

@ -840,7 +840,7 @@ void EditRestrictedBox::createUntilGroup() {
void EditRestrictedBox::createUntilVariants() { void EditRestrictedBox::createUntilVariants() {
auto addVariant = [&](int value, const QString &text) { auto addVariant = [&](int value, const QString &text) {
if (!canSave() && _untilGroup->value() != value) { if (!canSave() && _untilGroup->current() != value) {
return; return;
} }
_untilVariants.emplace_back( _untilVariants.emplace_back(

View file

@ -25,7 +25,7 @@ void EditPeerHistoryVisibilityBox(
box->setTitle(tr::lng_manage_history_visibility_title()); box->setTitle(tr::lng_manage_history_visibility_title());
box->addButton(tr::lng_settings_save(), [=] { box->addButton(tr::lng_settings_save(), [=] {
savedCallback(historyVisibility->value()); savedCallback(historyVisibility->current());
box->closeBox(); box->closeBox();
}); });
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });

View file

@ -76,7 +76,7 @@ public:
} }
[[nodiscard]] Privacy getPrivacy() const { [[nodiscard]] Privacy getPrivacy() const {
return _controls.privacy->value(); return _controls.privacy->current();
} }
[[nodiscard]] bool noForwards() const { [[nodiscard]] bool noForwards() const {
@ -238,7 +238,7 @@ void Controller::createContent() {
}, wrap->lifetime()); }, wrap->lifetime());
} else { } else {
_controls.whoSendWrap->toggle( _controls.whoSendWrap->toggle(
(_controls.privacy->value() == Privacy::HasUsername), (_controls.privacy->current() == Privacy::HasUsername),
anim::type::instant); anim::type::instant);
} }
auto joinToWrite = _controls.joinToWrite auto joinToWrite = _controls.joinToWrite
@ -299,7 +299,7 @@ void Controller::createContent() {
if (_linkOnly) { if (_linkOnly) {
_controls.inviteLinkWrap->show(anim::type::instant); _controls.inviteLinkWrap->show(anim::type::instant);
} else { } else {
if (_controls.privacy->value() == Privacy::NoUsername) { if (_controls.privacy->current() == Privacy::NoUsername) {
checkUsernameAvailability(); checkUsernameAvailability();
} }
const auto forShowing = _dataSavedValue const auto forShowing = _dataSavedValue
@ -474,7 +474,7 @@ object_ptr<Ui::RpWidget> Controller::createUsernameEdit() {
&Ui::UsernameInput::changed, &Ui::UsernameInput::changed,
[this] { usernameChanged(); }); [this] { usernameChanged(); });
const auto shown = (_controls.privacy->value() == Privacy::HasUsername); const auto shown = (_controls.privacy->current() == Privacy::HasUsername);
result->toggle(shown, anim::type::instant); result->toggle(shown, anim::type::instant);
return result; return result;
@ -539,7 +539,7 @@ void Controller::checkUsernameAvailability() {
if (!_controls.usernameInput) { if (!_controls.usernameInput) {
return; return;
} }
const auto initial = (_controls.privacy->value() != Privacy::HasUsername); const auto initial = (_controls.privacy->current() != Privacy::HasUsername);
const auto checking = initial const auto checking = initial
? u".bad."_q ? u".bad."_q
: getUsernameInput(); : getUsernameInput();
@ -573,11 +573,11 @@ void Controller::checkUsernameAvailability() {
_controls.privacy->setValue(Privacy::NoUsername); _controls.privacy->setValue(Privacy::NoUsername);
} else if (type == u"CHANNELS_ADMIN_PUBLIC_TOO_MUCH"_q) { } else if (type == u"CHANNELS_ADMIN_PUBLIC_TOO_MUCH"_q) {
_usernameState = UsernameState::TooMany; _usernameState = UsernameState::TooMany;
if (_controls.privacy->value() == Privacy::HasUsername) { if (_controls.privacy->current() == Privacy::HasUsername) {
askUsernameRevoke(); askUsernameRevoke();
} }
} else if (initial) { } else if (initial) {
if (_controls.privacy->value() == Privacy::HasUsername) { if (_controls.privacy->current() == Privacy::HasUsername) {
showUsernameEmpty(); showUsernameEmpty();
setFocusUsername(); setFocusUsername();
} }

View file

@ -1142,7 +1142,7 @@ void AccountsLimitBox(
const auto ref = QString(); const auto ref = QString();
const auto wasAccount = &session->account(); const auto wasAccount = &session->account();
const auto nowAccount = accounts[group->value()]; const auto nowAccount = accounts[group->current()];
if (wasAccount == nowAccount) { if (wasAccount == nowAccount) {
Settings::ShowPremium(session, ref); Settings::ShowPremium(session, ref);
return; return;

View file

@ -327,7 +327,7 @@ void RingtonesBox(
box->setWidth(st::boxWideWidth); box->setWidth(st::boxWideWidth);
box->addButton(tr::lng_settings_save(), [=] { box->addButton(tr::lng_settings_save(), [=] {
const auto value = state->group->value(); const auto value = state->group->current();
auto sound = (value == kDefaultValue) auto sound = (value == kDefaultValue)
? Data::NotifySound() ? Data::NotifySound()
: (value == kNoSoundValue) : (value == kNoSoundValue)

View file

@ -95,7 +95,7 @@ void SelfDestructionBox::showContent() {
clearButtons(); clearButtons();
addButton(tr::lng_settings_save(), [=] { addButton(tr::lng_settings_save(), [=] {
const auto value = _ttlGroup->value(); const auto value = _ttlGroup->current();
switch (_type) { switch (_type) {
case Type::Account: case Type::Account:
_session->api().selfDestruct().updateAccountTTL(value); _session->api().selfDestruct().updateAccountTTL(value);

View file

@ -78,7 +78,7 @@ void ChooseFormatBox(
addFormatOption( addFormatOption(
tr::lng_export_option_html_and_json(tr::now), tr::lng_export_option_html_and_json(tr::now),
Format::HtmlAndJson); Format::HtmlAndJson);
box->addButton(tr::lng_settings_save(), [=] { done(group->value()); }); box->addButton(tr::lng_settings_save(), [=] { done(group->current()); });
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
} }

View file

@ -630,9 +630,9 @@ void CreateGiveawayBox(
const auto createCallback = [=](GiveawayType type) { const auto createCallback = [=](GiveawayType type) {
return [=] { return [=] {
const auto was = membersGroup->value(); const auto was = membersGroup->current();
membersGroup->setValue(type); membersGroup->setValue(type);
const auto now = membersGroup->value(); const auto now = membersGroup->current();
if (was == now) { if (was == now) {
base::call_delayed( base::call_delayed(
st::defaultRippleAnimation.hideDuration, st::defaultRippleAnimation.hideDuration,
@ -990,7 +990,7 @@ void CreateGiveawayBox(
if (state->confirmButtonBusy.current()) { if (state->confirmButtonBusy.current()) {
return; return;
} }
const auto type = typeGroup->value(); const auto type = typeGroup->current();
const auto isSpecific = (type == GiveawayType::SpecificUsers); const auto isSpecific = (type == GiveawayType::SpecificUsers);
const auto isRandom = (type == GiveawayType::Random); const auto isRandom = (type == GiveawayType::Random);
if (!isSpecific && !isRandom) { if (!isSpecific && !isRandom) {
@ -1003,7 +1003,7 @@ void CreateGiveawayBox(
prepaid prepaid
? prepaid->months ? prepaid->months
: state->apiOptions.monthsFromPreset( : state->apiOptions.monthsFromPreset(
durationGroup->value())); durationGroup->current()));
if (isSpecific) { if (isSpecific) {
if (state->selectedToAward.empty()) { if (state->selectedToAward.empty()) {
return; return;
@ -1029,7 +1029,7 @@ void CreateGiveawayBox(
.countries = state->countriesValue.current(), .countries = state->countriesValue.current(),
.additionalPrize = state->additionalPrize.current(), .additionalPrize = state->additionalPrize.current(),
.untilDate = state->dateValue.current(), .untilDate = state->dateValue.current(),
.onlyNewSubscribers = (membersGroup->value() .onlyNewSubscribers = (membersGroup->current()
== GiveawayType::OnlyNewMembers), == GiveawayType::OnlyNewMembers),
.showWinners = state->showWinners.current(), .showWinners = state->showWinners.current(),
}; };

View file

@ -140,7 +140,7 @@ void RequestTypeBox::setupControls(
_height = y; _height = y;
_submit = [=] { _submit = [=] {
const auto value = group->hasValue() ? group->value() : -1; const auto value = group->hasValue() ? group->current() : -1;
if (value >= 0) { if (value >= 0) {
submit(value); submit(value);
} }

View file

@ -503,7 +503,7 @@ QPointer<Ui::RpWidget> Business::createPinnedToBottom(
std::move(buttonText), std::move(buttonText),
std::nullopt, std::nullopt,
[=, options = session->api().premium().subscriptionOptions()] { [=, options = session->api().premium().subscriptionOptions()] {
const auto value = _radioGroup->value(); const auto value = _radioGroup->current();
return (value < options.size() && value >= 0) return (value < options.size() && value >= 0)
? options[value].botUrl ? options[value].botUrl
: QString(); : QString();

View file

@ -607,7 +607,7 @@ void ChooseMediaDeviceBox(
button->finishAnimating(); button->finishAnimating();
button->clicks( button->clicks(
) | rpl::filter([=] { ) | rpl::filter([=] {
return (group->value() == index); return (group->current() == index);
}) | rpl::start_with_next([=] { }) | rpl::start_with_next([=] {
choose(id); choose(id);
}, button->lifetime()); }, button->lifetime());

View file

@ -294,7 +294,7 @@ void GlobalTTL::rebuildButtons(TimeId currentTTL) const {
rpl::single(ttlText)), rpl::single(ttlText)),
st::settingsButtonNoIcon)); st::settingsButtonNoIcon));
button->setClickedCallback([=] { button->setClickedCallback([=] {
if (_group->value() == ttl) { if (_group->current() == ttl) {
return; return;
} }
if (!ttl) { if (!ttl) {
@ -357,7 +357,7 @@ void GlobalTTL::setupContent() {
show->showBox(Box(TTLMenu::TTLBox, TTLMenu::Args{ show->showBox(Box(TTLMenu::TTLBox, TTLMenu::Args{
.show = show, .show = show,
.startTtl = _group->value(), .startTtl = _group->current(),
.callback = [=](TimeId ttl, Fn<void()>) { showSure(ttl, true); }, .callback = [=](TimeId ttl, Fn<void()>) { showSure(ttl, true); },
.hideDisable = true, .hideDisable = true,
})); }));

View file

@ -1190,7 +1190,7 @@ QPointer<Ui::RpWidget> Premium::createPinnedToBottom(
std::move(buttonText), std::move(buttonText),
std::nullopt, std::nullopt,
[=, options = session->api().premium().subscriptionOptions()] { [=, options = session->api().premium().subscriptionOptions()] {
const auto value = _radioGroup->value(); const auto value = _radioGroup->current();
return (value < options.size() && value >= 0) return (value < options.size() && value >= 0)
? options[value].botUrl ? options[value].botUrl
: QString(); : QString();

View file

@ -598,7 +598,7 @@ object_ptr<Ui::RpWidget> PhoneNumberPrivacyController::setupMiddleWidget(
_saveAdditional = [=] { _saveAdditional = [=] {
controller->session().api().userPrivacy().save( controller->session().api().userPrivacy().save(
Api::UserPrivacy::Key::AddedByPhone, Api::UserPrivacy::Key::AddedByPhone,
Api::UserPrivacy::Rule{ .option = group->value() }); Api::UserPrivacy::Rule{ .option = group->current() });
}; };
return widget; return widget;

View file

@ -1063,7 +1063,7 @@ void AddAccountsRow(
}); });
const auto index = int(state->accounts.size()) - 1; const auto index = int(state->accounts.size()) - 1;
state->accounts[index].checkbox.setChecked( state->accounts[index].checkbox.setChecked(
index == group->value(), index == group->current(),
anim::type::instant); anim::type::instant);
widget->paintRequest( widget->paintRequest(
@ -1303,7 +1303,7 @@ void AddGiftOptions(
int nowIndex = 0; int nowIndex = 0;
Ui::Animations::Simple animation; Ui::Animations::Simple animation;
}; };
const auto wasGroupValue = group->value(); const auto wasGroupValue = group->current();
const auto animation = parent->lifetime().make_state<Animation>(); const auto animation = parent->lifetime().make_state<Animation>();
animation->nowIndex = wasGroupValue; animation->nowIndex = wasGroupValue;
@ -1324,7 +1324,7 @@ void AddGiftOptions(
const auto &stCheckbox = st::defaultBoxCheckbox; const auto &stCheckbox = st::defaultBoxCheckbox;
auto radioView = std::make_unique<GradientRadioView>( auto radioView = std::make_unique<GradientRadioView>(
st::defaultRadio, st::defaultRadio,
(group->hasValue() && group->value() == index)); (group->hasValue() && group->current() == index));
const auto radioViewRaw = radioView.get(); const auto radioViewRaw = radioView.get();
const auto radio = Ui::CreateChild<Ui::Radiobutton>( const auto radio = Ui::CreateChild<Ui::Radiobutton>(
row, row,
@ -1468,7 +1468,7 @@ void AddGiftOptions(
row->setClickedCallback([=, duration = st::defaultCheck.duration] { row->setClickedCallback([=, duration = st::defaultCheck.duration] {
group->setValue(index); group->setValue(index);
animation->nowIndex = group->value(); animation->nowIndex = group->current();
animation->animation.stop(); animation->animation.stop();
animation->animation.start( animation->animation.start(
[=] { parent->update(); }, [=] { parent->update(); },

View file

@ -498,7 +498,7 @@ bool CloudList::insertTillLimit(
void CloudList::insert(int index, const Data::CloudTheme &theme) { void CloudList::insert(int index, const Data::CloudTheme &theme) {
const auto id = theme.id; const auto id = theme.id;
const auto value = groupValueForId(id); const auto value = groupValueForId(id);
const auto checked = _group->hasValue() && (_group->value() == value); const auto checked = _group->hasValue() && (_group->current() == value);
auto check = std::make_unique<CloudListCheck>(checked); auto check = std::make_unique<CloudListCheck>(checked);
const auto raw = check.get(); const auto raw = check.get();
auto button = std::make_unique<Ui::Radiobutton>( auto button = std::make_unique<Ui::Radiobutton>(