mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-04 05:17:55 +00:00
Implement SingleChoiceBox using Ui::GenericBox.
This commit is contained in:
parent
eb11185de7
commit
cb2d77d386
@ -16,56 +16,42 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_layers.h"
|
||||
|
||||
SingleChoiceBox::SingleChoiceBox(
|
||||
QWidget*,
|
||||
rpl::producer<QString> title,
|
||||
const std::vector<QString> &optionTexts,
|
||||
int initialSelection,
|
||||
Fn<void(int)> callback,
|
||||
const style::Checkbox *st,
|
||||
const style::Radio *radioSt)
|
||||
: _title(std::move(title))
|
||||
, _optionTexts(optionTexts)
|
||||
, _initialSelection(initialSelection)
|
||||
, _callback(callback)
|
||||
, _st(st ? *st : st::defaultBoxCheckbox)
|
||||
, _radioSt(radioSt ? *radioSt : st::defaultRadio) {
|
||||
}
|
||||
void SingleChoiceBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
SingleChoiceBoxArgs &&args) {
|
||||
box->setTitle(std::move(args.title));
|
||||
|
||||
void SingleChoiceBox::prepare() {
|
||||
setTitle(std::move(_title));
|
||||
box->addButton(tr::lng_box_ok(), [=] { box->closeBox(); });
|
||||
|
||||
addButton(tr::lng_box_ok(), [=] { closeBox(); });
|
||||
const auto group = std::make_shared<Ui::RadiobuttonGroup>(
|
||||
args.initialSelection);
|
||||
|
||||
const auto group = std::make_shared<Ui::RadiobuttonGroup>(_initialSelection);
|
||||
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
content->add(object_ptr<Ui::FixedHeightWidget>(
|
||||
content,
|
||||
const auto layout = box->verticalLayout();
|
||||
layout->add(object_ptr<Ui::FixedHeightWidget>(
|
||||
layout,
|
||||
st::boxOptionListPadding.top() + st::autolockButton.margin.top()));
|
||||
auto &&ints = ranges::view::ints(0, ranges::unreachable);
|
||||
for (const auto &[i, text] : ranges::view::zip(ints, _optionTexts)) {
|
||||
content->add(
|
||||
for (const auto &[i, text] : ranges::view::zip(ints, args.options)) {
|
||||
layout->add(
|
||||
object_ptr<Ui::Radiobutton>(
|
||||
content,
|
||||
layout,
|
||||
group,
|
||||
i,
|
||||
text,
|
||||
_st,
|
||||
_radioSt),
|
||||
args.st ? *args.st : st::defaultBoxCheckbox,
|
||||
args.radioSt ? *args.radioSt : st::defaultRadio),
|
||||
QMargins(
|
||||
st::boxPadding.left() + st::boxOptionListPadding.left(),
|
||||
0,
|
||||
st::boxPadding.right(),
|
||||
st::boxOptionListSkip));
|
||||
}
|
||||
const auto callback = args.callback.value();
|
||||
group->setChangedCallback([=](int value) {
|
||||
const auto weak = Ui::MakeWeak(this);
|
||||
_callback(value);
|
||||
const auto weak = Ui::MakeWeak(box);
|
||||
callback(value);
|
||||
if (weak) {
|
||||
closeBox();
|
||||
box->closeBox();
|
||||
}
|
||||
});
|
||||
setDimensionsToContent(st::boxWidth, content);
|
||||
}
|
||||
|
||||
|
@ -7,38 +7,26 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "boxes/abstract_box.h"
|
||||
#include <vector>
|
||||
|
||||
namespace Ui {
|
||||
class Radiobutton;
|
||||
} // namespace Ui
|
||||
#include "ui/layers/generic_box.h"
|
||||
#include "base/required.h"
|
||||
|
||||
namespace style {
|
||||
struct Checkbox;
|
||||
struct Radio;
|
||||
} // namespace style
|
||||
|
||||
class SingleChoiceBox : public Ui::BoxContent {
|
||||
public:
|
||||
SingleChoiceBox(
|
||||
QWidget*,
|
||||
rpl::producer<QString> title,
|
||||
const std::vector<QString> &optionTexts,
|
||||
int initialSelection,
|
||||
Fn<void(int)> callback,
|
||||
const style::Checkbox *st = nullptr,
|
||||
const style::Radio *radioSt = nullptr);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
|
||||
private:
|
||||
rpl::producer<QString> _title;
|
||||
std::vector<QString> _optionTexts;
|
||||
int _initialSelection = 0;
|
||||
Fn<void(int)> _callback;
|
||||
const style::Checkbox &_st;
|
||||
const style::Radio &_radioSt;
|
||||
struct SingleChoiceBoxArgs {
|
||||
template <typename T>
|
||||
using required = base::required<T>;
|
||||
|
||||
required<rpl::producer<QString>> title;
|
||||
const std::vector<QString> &options;
|
||||
int initialSelection = 0;
|
||||
required<Fn<void(int)>> callback;
|
||||
const style::Checkbox *st = nullptr;
|
||||
const style::Radio *radioSt = nullptr;
|
||||
};
|
||||
|
||||
void SingleChoiceBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
SingleChoiceBoxArgs &&args);
|
||||
|
@ -124,11 +124,14 @@ void Calls::setupContent() {
|
||||
call->setCurrentVideoDevice(deviceId);
|
||||
}
|
||||
});
|
||||
Ui::show(Box<SingleChoiceBox>(
|
||||
tr::lng_settings_call_camera(),
|
||||
options,
|
||||
currentOption,
|
||||
save));
|
||||
Ui::show(Box([=](not_null<Ui::GenericBox*> box) {
|
||||
SingleChoiceBox(box, {
|
||||
.title = tr::lng_settings_call_camera(),
|
||||
.options = options,
|
||||
.initialSelection = currentOption,
|
||||
.callback = save,
|
||||
});
|
||||
}));
|
||||
});
|
||||
const auto bubbleWrap = content->add(object_ptr<Ui::RpWidget>(content));
|
||||
const auto bubble = content->lifetime().make_state<::Calls::VideoBubble>(
|
||||
@ -366,7 +369,7 @@ QString CurrentAudioInputName() {
|
||||
: tr::lng_settings_call_device_default(tr::now);
|
||||
}
|
||||
|
||||
object_ptr<SingleChoiceBox> ChooseAudioOutputBox(
|
||||
object_ptr<Ui::GenericBox> ChooseAudioOutputBox(
|
||||
Fn<void(QString id, QString name)> chosen,
|
||||
const style::Checkbox *st,
|
||||
const style::Radio *radioSt) {
|
||||
@ -390,16 +393,19 @@ object_ptr<SingleChoiceBox> ChooseAudioOutputBox(
|
||||
Core::App().calls().setCurrentAudioDevice(false, deviceId);
|
||||
chosen(deviceId, options[option]);
|
||||
};
|
||||
return Box<SingleChoiceBox>(
|
||||
tr::lng_settings_call_output_device(),
|
||||
options,
|
||||
currentOption,
|
||||
save,
|
||||
st,
|
||||
radioSt);
|
||||
return Box([=](not_null<Ui::GenericBox*> box) {
|
||||
SingleChoiceBox(box, {
|
||||
.title = tr::lng_settings_call_output_device(),
|
||||
.options = options,
|
||||
.initialSelection = currentOption,
|
||||
.callback = save,
|
||||
.st = st,
|
||||
.radioSt = radioSt,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
object_ptr<SingleChoiceBox> ChooseAudioInputBox(
|
||||
object_ptr<Ui::GenericBox> ChooseAudioInputBox(
|
||||
Fn<void(QString id, QString name)> chosen,
|
||||
const style::Checkbox *st,
|
||||
const style::Radio *radioSt) {
|
||||
@ -423,16 +429,19 @@ object_ptr<SingleChoiceBox> ChooseAudioInputBox(
|
||||
Core::App().calls().setCurrentAudioDevice(true, deviceId);
|
||||
chosen(deviceId, options[option]);
|
||||
};
|
||||
return Box<SingleChoiceBox>(
|
||||
tr::lng_settings_call_input_device(),
|
||||
options,
|
||||
currentOption,
|
||||
save,
|
||||
st,
|
||||
radioSt);
|
||||
return Box([=](not_null<Ui::GenericBox*> box) {
|
||||
SingleChoiceBox(box, {
|
||||
.title = tr::lng_settings_call_input_device(),
|
||||
.options = options,
|
||||
.initialSelection = currentOption,
|
||||
.callback = save,
|
||||
.st = st,
|
||||
.radioSt = radioSt,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//object_ptr<SingleChoiceBox> ChooseAudioBackendBox(
|
||||
//
|
||||
//object_ptr<Ui::GenericBox> ChooseAudioBackendBox(
|
||||
// const style::Checkbox *st,
|
||||
// const style::Radio *radioSt) {
|
||||
// const auto &settings = Core::App().settings();
|
||||
@ -451,13 +460,16 @@ object_ptr<SingleChoiceBox> ChooseAudioInputBox(
|
||||
// Core::App().saveSettings();
|
||||
// App::restart();
|
||||
// };
|
||||
// return Box<SingleChoiceBox>(
|
||||
// rpl::single<QString>("Calls audio backend"),
|
||||
// options,
|
||||
// currentOption,
|
||||
// save,
|
||||
// st,
|
||||
// radioSt);
|
||||
// return Box([=](not_null<Ui::GenericBox*> box) {
|
||||
// SingleChoiceBox(box, {
|
||||
// .title = rpl::single<QString>("Calls audio backend"),
|
||||
// .options = options,
|
||||
// .initialSelection = currentOption,
|
||||
// .callback = save,
|
||||
// .st = st,
|
||||
// .radioSt = radioSt,
|
||||
// });
|
||||
// });
|
||||
//}
|
||||
|
||||
} // namespace Settings
|
||||
|
@ -22,14 +22,13 @@ class Call;
|
||||
|
||||
namespace Ui {
|
||||
class LevelMeter;
|
||||
class GenericBox;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Webrtc {
|
||||
class AudioInputTester;
|
||||
} // namespace Webrtc
|
||||
|
||||
class SingleChoiceBox;
|
||||
|
||||
namespace Settings {
|
||||
|
||||
class Calls : public Section {
|
||||
@ -61,17 +60,17 @@ inline constexpr auto kMicTestAnimationDuration = crl::time(200);
|
||||
|
||||
[[nodiscard]] QString CurrentAudioOutputName();
|
||||
[[nodiscard]] QString CurrentAudioInputName();
|
||||
[[nodiscard]] object_ptr<SingleChoiceBox> ChooseAudioOutputBox(
|
||||
[[nodiscard]] object_ptr<Ui::GenericBox> ChooseAudioOutputBox(
|
||||
Fn<void(QString id, QString name)> chosen,
|
||||
const style::Checkbox *st = nullptr,
|
||||
const style::Radio *radioSt = nullptr);
|
||||
[[nodiscard]] object_ptr<SingleChoiceBox> ChooseAudioInputBox(
|
||||
[[nodiscard]] object_ptr<Ui::GenericBox> ChooseAudioInputBox(
|
||||
Fn<void(QString id, QString name)> chosen,
|
||||
const style::Checkbox *st = nullptr,
|
||||
const style::Radio *radioSt = nullptr);
|
||||
[[nodiscard]] object_ptr<SingleChoiceBox> ChooseAudioBackendBox(
|
||||
const style::Checkbox *st = nullptr,
|
||||
const style::Radio *radioSt = nullptr);
|
||||
//[[nodiscard]] object_ptr<Ui::GenericBox> ChooseAudioBackendBox(
|
||||
// const style::Checkbox *st = nullptr,
|
||||
// const style::Radio *radioSt = nullptr);
|
||||
|
||||
} // namespace Settings
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user