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-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2019-01-05 11:08:02 +00:00
|
|
|
|
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,
|
2020-11-29 18:26:49 +00:00
|
|
|
Fn<void(int)> callback,
|
|
|
|
const style::Checkbox *st,
|
|
|
|
const style::Radio *radioSt)
|
2019-06-18 15:00:55 +00:00
|
|
|
: _title(std::move(title))
|
2019-01-11 10:07:56 +00:00
|
|
|
, _optionTexts(optionTexts)
|
|
|
|
, _initialSelection(initialSelection)
|
2020-11-29 18:26:49 +00:00
|
|
|
, _callback(callback)
|
|
|
|
, _st(st ? *st : st::defaultBoxCheckbox)
|
|
|
|
, _radioSt(radioSt ? *radioSt : st::defaultRadio) {
|
2019-01-11 10:07:56 +00:00
|
|
|
}
|
|
|
|
|
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()));
|
2019-09-10 02:03:18 +00:00
|
|
|
auto &&ints = ranges::view::ints(0, ranges::unreachable);
|
2019-01-21 06:37:31 +00:00
|
|
|
for (const auto &[i, text] : ranges::view::zip(ints, _optionTexts)) {
|
|
|
|
content->add(
|
|
|
|
object_ptr<Ui::Radiobutton>(
|
|
|
|
content,
|
|
|
|
group,
|
|
|
|
i,
|
|
|
|
text,
|
2020-11-29 18:26:49 +00:00
|
|
|
_st,
|
|
|
|
_radioSt),
|
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
|
|
|
}
|
2019-01-11 10:07:56 +00:00
|
|
|
group->setChangedCallback([=](int value) {
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto weak = Ui::MakeWeak(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
|
|
|
}
|
|
|
|
|