Hide multiple answers if only quiz is allowed.

This commit is contained in:
John Preston 2020-01-18 16:02:56 +03:00
parent 43d8dedec4
commit c3b01d8573
1 changed files with 29 additions and 21 deletions

View File

@ -839,13 +839,17 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
st::defaultCheckbox), st::defaultCheckbox),
st::createPollCheckboxMargin) st::createPollCheckboxMargin)
: nullptr; : nullptr;
const auto multiple = container->add( const auto hasMultiple = !(_chosen & PollData::Flag::Quiz)
|| !(_disabled & PollData::Flag::Quiz);
const auto multiple = hasMultiple
? container->add(
object_ptr<Ui::Checkbox>( object_ptr<Ui::Checkbox>(
container, container,
tr::lng_polls_create_multiple_choice(tr::now), tr::lng_polls_create_multiple_choice(tr::now),
(_chosen & PollData::Flag::MultiChoice), (_chosen & PollData::Flag::MultiChoice),
st::defaultCheckbox), st::defaultCheckbox),
st::createPollCheckboxMargin); st::createPollCheckboxMargin)
: nullptr;
const auto quiz = container->add( const auto quiz = container->add(
object_ptr<Ui::Checkbox>( object_ptr<Ui::Checkbox>(
container, container,
@ -854,26 +858,29 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
st::defaultCheckbox), st::defaultCheckbox),
st::createPollCheckboxMargin); st::createPollCheckboxMargin);
quiz->setDisabled(_disabled & PollData::Flag::Quiz); quiz->setDisabled(_disabled & PollData::Flag::Quiz);
if (multiple) {
multiple->setDisabled((_disabled & PollData::Flag::MultiChoice) multiple->setDisabled((_disabled & PollData::Flag::MultiChoice)
|| (_chosen & PollData::Flag::Quiz)); || (_chosen & PollData::Flag::Quiz));
using namespace rpl::mappers;
quiz->checkedChanges(
) | rpl::start_with_next([=](bool checked) {
if (checked && multiple->checked()) {
multiple->setChecked(false);
}
multiple->setDisabled(checked
|| (_disabled & PollData::Flag::MultiChoice));
options->enableChooseCorrect(checked);
}, quiz->lifetime());
multiple->events( multiple->events(
) | rpl::filter([=](not_null<QEvent*> e) { ) | rpl::filter([=](not_null<QEvent*> e) {
return (e->type() == QEvent::MouseButtonPress) && quiz->checked(); return (e->type() == QEvent::MouseButtonPress) && quiz->checked();
}) | rpl::start_with_next([=] { }) | rpl::start_with_next([=] {
Ui::Toast::Show("Quiz has only one right answer."); Ui::Toast::Show("Quiz has only one right answer.");
}, multiple->lifetime()); }, multiple->lifetime());
}
using namespace rpl::mappers;
quiz->checkedChanges(
) | rpl::start_with_next([=](bool checked) {
if (multiple) {
if (checked && multiple->checked()) {
multiple->setChecked(false);
}
multiple->setDisabled(checked
|| (_disabled & PollData::Flag::MultiChoice));
}
options->enableChooseCorrect(checked);
}, quiz->lifetime());
const auto isValidQuestion = [=] { const auto isValidQuestion = [=] {
const auto text = question->getLastText().trimmed(); const auto text = question->getLastText().trimmed();
@ -896,9 +903,10 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
result.question = question->getLastText().trimmed(); result.question = question->getLastText().trimmed();
result.answers = options->toPollAnswers(); result.answers = options->toPollAnswers();
const auto publicVotes = (anonymous && !anonymous->checked()); const auto publicVotes = (anonymous && !anonymous->checked());
const auto multiChoice = (multiple && multiple->checked());
result.setFlags(Flag(0) result.setFlags(Flag(0)
| (publicVotes ? Flag::PublicVotes : Flag(0)) | (publicVotes ? Flag::PublicVotes : Flag(0))
| (multiple->checked() ? Flag::MultiChoice : Flag(0)) | (multiChoice ? Flag::MultiChoice : Flag(0))
| (quiz->checked() ? Flag::Quiz : Flag(0))); | (quiz->checked() ? Flag::Quiz : Flag(0)));
return result; return result;
}; };