mirror of https://github.com/procxx/kepka.git
Hide multiple answers if only quiz is allowed.
This commit is contained in:
parent
43d8dedec4
commit
c3b01d8573
|
@ -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)
|
||||||
object_ptr<Ui::Checkbox>(
|
|| !(_disabled & PollData::Flag::Quiz);
|
||||||
container,
|
const auto multiple = hasMultiple
|
||||||
tr::lng_polls_create_multiple_choice(tr::now),
|
? container->add(
|
||||||
(_chosen & PollData::Flag::MultiChoice),
|
object_ptr<Ui::Checkbox>(
|
||||||
st::defaultCheckbox),
|
container,
|
||||||
st::createPollCheckboxMargin);
|
tr::lng_polls_create_multiple_choice(tr::now),
|
||||||
|
(_chosen & PollData::Flag::MultiChoice),
|
||||||
|
st::defaultCheckbox),
|
||||||
|
st::createPollCheckboxMargin)
|
||||||
|
: nullptr;
|
||||||
const auto quiz = container->add(
|
const auto quiz = container->add(
|
||||||
object_ptr<Ui::Checkbox>(
|
object_ptr<Ui::Checkbox>(
|
||||||
container,
|
container,
|
||||||
|
@ -854,27 +858,30 @@ 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);
|
||||||
multiple->setDisabled((_disabled & PollData::Flag::MultiChoice)
|
if (multiple) {
|
||||||
|| (_chosen & PollData::Flag::Quiz));
|
multiple->setDisabled((_disabled & PollData::Flag::MultiChoice)
|
||||||
|
|| (_chosen & PollData::Flag::Quiz));
|
||||||
|
multiple->events(
|
||||||
|
) | rpl::filter([=](not_null<QEvent*> e) {
|
||||||
|
return (e->type() == QEvent::MouseButtonPress) && quiz->checked();
|
||||||
|
}) | rpl::start_with_next([=] {
|
||||||
|
Ui::Toast::Show("Quiz has only one right answer.");
|
||||||
|
}, multiple->lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
using namespace rpl::mappers;
|
using namespace rpl::mappers;
|
||||||
quiz->checkedChanges(
|
quiz->checkedChanges(
|
||||||
) | rpl::start_with_next([=](bool checked) {
|
) | rpl::start_with_next([=](bool checked) {
|
||||||
if (checked && multiple->checked()) {
|
if (multiple) {
|
||||||
multiple->setChecked(false);
|
if (checked && multiple->checked()) {
|
||||||
|
multiple->setChecked(false);
|
||||||
|
}
|
||||||
|
multiple->setDisabled(checked
|
||||||
|
|| (_disabled & PollData::Flag::MultiChoice));
|
||||||
}
|
}
|
||||||
multiple->setDisabled(checked
|
|
||||||
|| (_disabled & PollData::Flag::MultiChoice));
|
|
||||||
options->enableChooseCorrect(checked);
|
options->enableChooseCorrect(checked);
|
||||||
}, quiz->lifetime());
|
}, quiz->lifetime());
|
||||||
|
|
||||||
multiple->events(
|
|
||||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
|
||||||
return (e->type() == QEvent::MouseButtonPress) && quiz->checked();
|
|
||||||
}) | rpl::start_with_next([=] {
|
|
||||||
Ui::Toast::Show("Quiz has only one right answer.");
|
|
||||||
}, multiple->lifetime());
|
|
||||||
|
|
||||||
const auto isValidQuestion = [=] {
|
const auto isValidQuestion = [=] {
|
||||||
const auto text = question->getLastText().trimmed();
|
const auto text = question->getLastText().trimmed();
|
||||||
return !text.isEmpty() && (text.size() <= kQuestionLimit);
|
return !text.isEmpty() && (text.size() <= kQuestionLimit);
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue