2019-01-05 11:08:02 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
2021-03-23 16:06:59 +00:00
|
|
|
#include "ui/boxes/single_choice_box.h"
|
2019-01-05 11:08:02 +00:00
|
|
|
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "ui/widgets/checkbox.h"
|
2019-01-21 06:37:31 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
|
|
|
#include "ui/wrap/padding_wrap.h"
|
2019-01-05 11:08:02 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2019-01-05 11:08:02 +00:00
|
|
|
|
2021-02-01 13:51:01 +00:00
|
|
|
void SingleChoiceBox(
|
|
|
|
not_null<Ui::GenericBox*> box,
|
|
|
|
SingleChoiceBoxArgs &&args) {
|
|
|
|
box->setTitle(std::move(args.title));
|
2019-01-05 11:08:02 +00:00
|
|
|
|
2021-02-01 13:51:01 +00:00
|
|
|
box->addButton(tr::lng_box_ok(), [=] { box->closeBox(); });
|
2019-01-05 11:08:02 +00:00
|
|
|
|
2021-02-01 13:51:01 +00:00
|
|
|
const auto group = std::make_shared<Ui::RadiobuttonGroup>(
|
|
|
|
args.initialSelection);
|
2019-01-21 06:37:31 +00:00
|
|
|
|
2021-02-01 13:51:01 +00:00
|
|
|
const auto layout = box->verticalLayout();
|
|
|
|
layout->add(object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
layout,
|
2019-01-21 06:37:31 +00:00
|
|
|
st::boxOptionListPadding.top() + st::autolockButton.margin.top()));
|
2021-03-13 12:12:08 +00:00
|
|
|
auto &&ints = ranges::views::ints(0, ranges::unreachable);
|
2021-09-08 10:53:54 +00:00
|
|
|
for (const auto [i, text] : ranges::views::zip(ints, args.options)) {
|
2021-02-01 13:51:01 +00:00
|
|
|
layout->add(
|
2019-01-21 06:37:31 +00:00
|
|
|
object_ptr<Ui::Radiobutton>(
|
2021-02-01 13:51:01 +00:00
|
|
|
layout,
|
2019-01-21 06:37:31 +00:00
|
|
|
group,
|
|
|
|
i,
|
|
|
|
text,
|
2021-02-01 13:51:01 +00:00
|
|
|
args.st ? *args.st : st::defaultBoxCheckbox,
|
|
|
|
args.radioSt ? *args.radioSt : st::defaultRadio),
|
2019-01-21 06:37:31 +00:00
|
|
|
QMargins(
|
|
|
|
st::boxPadding.left() + st::boxOptionListPadding.left(),
|
|
|
|
0,
|
|
|
|
st::boxPadding.right(),
|
|
|
|
st::boxOptionListSkip));
|
2019-01-05 11:08:02 +00:00
|
|
|
}
|
2021-11-11 11:44:12 +00:00
|
|
|
const auto callback = args.callback.value();
|
2019-01-11 10:07:56 +00:00
|
|
|
group->setChangedCallback([=](int value) {
|
2021-02-01 13:51:01 +00:00
|
|
|
const auto weak = Ui::MakeWeak(box);
|
|
|
|
callback(value);
|
2019-01-11 10:07:56 +00:00
|
|
|
if (weak) {
|
2021-02-01 13:51:01 +00:00
|
|
|
box->closeBox();
|
2019-01-11 10:07:56 +00:00
|
|
|
}
|
2019-01-05 11:08:02 +00:00
|
|
|
});
|
|
|
|
}
|