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
|
|
|
|
*/
|
|
|
|
#include "boxes/single_choice_box.h"
|
|
|
|
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "storage/localstorage.h"
|
|
|
|
#include "mainwindow.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-01-11 10:07:56 +00:00
|
|
|
SingleChoiceBox::SingleChoiceBox(
|
|
|
|
QWidget*,
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> title,
|
2019-01-11 10:07:56 +00:00
|
|
|
const std::vector<QString> &optionTexts,
|
|
|
|
int initialSelection,
|
|
|
|
Fn<void(int)> callback)
|
2019-06-18 15:00:55 +00:00
|
|
|
: _title(std::move(title))
|
2019-01-11 10:07:56 +00:00
|
|
|
, _optionTexts(optionTexts)
|
|
|
|
, _initialSelection(initialSelection)
|
|
|
|
, _callback(callback) {
|
|
|
|
}
|
|
|
|
|
2019-01-05 11:08:02 +00:00
|
|
|
void SingleChoiceBox::prepare() {
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(std::move(_title));
|
2019-01-05 11:08:02 +00:00
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_box_ok(), [=] { closeBox(); });
|
2019-01-05 11:08:02 +00:00
|
|
|
|
2019-01-11 10:07:56 +00:00
|
|
|
const auto group = std::make_shared<Ui::RadiobuttonGroup>(_initialSelection);
|
2019-01-21 06:37:31 +00:00
|
|
|
|
|
|
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
|
|
content->add(object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
content,
|
|
|
|
st::boxOptionListPadding.top() + st::autolockButton.margin.top()));
|
|
|
|
auto &&ints = ranges::view::ints(0);
|
|
|
|
for (const auto &[i, text] : ranges::view::zip(ints, _optionTexts)) {
|
|
|
|
content->add(
|
|
|
|
object_ptr<Ui::Radiobutton>(
|
|
|
|
content,
|
|
|
|
group,
|
|
|
|
i,
|
|
|
|
text,
|
|
|
|
st::defaultBoxCheckbox),
|
|
|
|
QMargins(
|
|
|
|
st::boxPadding.left() + st::boxOptionListPadding.left(),
|
|
|
|
0,
|
|
|
|
st::boxPadding.right(),
|
|
|
|
st::boxOptionListSkip));
|
2019-01-05 11:08:02 +00:00
|
|
|
}
|
2019-01-11 10:07:56 +00:00
|
|
|
group->setChangedCallback([=](int value) {
|
|
|
|
const auto weak = make_weak(this);
|
2019-01-05 11:08:02 +00:00
|
|
|
_callback(value);
|
2019-01-11 10:07:56 +00:00
|
|
|
if (weak) {
|
|
|
|
closeBox();
|
|
|
|
}
|
2019-01-05 11:08:02 +00:00
|
|
|
});
|
2019-01-21 06:37:31 +00:00
|
|
|
setDimensionsToContent(st::boxWidth, content);
|
2019-01-05 11:08:02 +00:00
|
|
|
}
|
|
|
|
|