Make RadioBox API simpler
This commit is contained in:
parent
f4d5f31f2a
commit
a618181120
3 changed files with 23 additions and 43 deletions
|
|
@ -23,12 +23,14 @@ RadioBox::RadioBox(
|
||||||
QWidget*,
|
QWidget*,
|
||||||
const QString &title,
|
const QString &title,
|
||||||
int currentValue,
|
int currentValue,
|
||||||
const QMap<int, QString> &options,
|
int valueCount,
|
||||||
|
Fn<QString(int)> labelGetter,
|
||||||
Fn<void(int)> saveCallback,
|
Fn<void(int)> saveCallback,
|
||||||
bool warnRestart)
|
bool warnRestart)
|
||||||
: _title(title)
|
: _title(title)
|
||||||
, _startValue(currentValue)
|
, _startValue(currentValue)
|
||||||
, _options(options)
|
, _valueCount(valueCount)
|
||||||
|
, _labelGetter(labelGetter)
|
||||||
, _saveCallback(std::move(saveCallback))
|
, _saveCallback(std::move(saveCallback))
|
||||||
, _warnRestart(warnRestart) {
|
, _warnRestart(warnRestart) {
|
||||||
}
|
}
|
||||||
|
|
@ -38,13 +40,15 @@ RadioBox::RadioBox(
|
||||||
const QString &title,
|
const QString &title,
|
||||||
const QString &description,
|
const QString &description,
|
||||||
int currentValue,
|
int currentValue,
|
||||||
const QMap<int, QString> &options,
|
int valueCount,
|
||||||
|
Fn<QString(int)> labelGetter,
|
||||||
Fn<void(int)> saveCallback,
|
Fn<void(int)> saveCallback,
|
||||||
bool warnRestart)
|
bool warnRestart)
|
||||||
: _title(title)
|
: _title(title)
|
||||||
, _description(description)
|
, _description(description)
|
||||||
, _startValue(currentValue)
|
, _startValue(currentValue)
|
||||||
, _options(options)
|
, _valueCount(valueCount)
|
||||||
|
, _labelGetter(labelGetter)
|
||||||
, _saveCallback(std::move(saveCallback))
|
, _saveCallback(std::move(saveCallback))
|
||||||
, _warnRestart(warnRestart) {
|
, _warnRestart(warnRestart) {
|
||||||
}
|
}
|
||||||
|
|
@ -69,13 +73,13 @@ void RadioBox::prepare() {
|
||||||
|
|
||||||
_group = std::make_shared<Ui::RadiobuttonGroup>(_startValue);
|
_group = std::make_shared<Ui::RadiobuttonGroup>(_startValue);
|
||||||
|
|
||||||
for (auto i = _options.constBegin(); i != _options.constEnd(); ++i) {
|
for (auto i = 0; i != _valueCount; ++i) {
|
||||||
content->add(
|
content->add(
|
||||||
object_ptr<Ui::Radiobutton>(
|
object_ptr<Ui::Radiobutton>(
|
||||||
this,
|
this,
|
||||||
_group,
|
_group,
|
||||||
i.key(),
|
i,
|
||||||
i.value(),
|
_labelGetter(i),
|
||||||
st::autolockButton),
|
st::autolockButton),
|
||||||
style::margins(
|
style::margins(
|
||||||
st::boxPadding.left(),
|
st::boxPadding.left(),
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ namespace Kotato {
|
||||||
|
|
||||||
class RadioBox : public Ui::BoxContent {
|
class RadioBox : public Ui::BoxContent {
|
||||||
public:
|
public:
|
||||||
RadioBox(QWidget* parent, const QString &title, int currentValue, const QMap<int, QString> &options, Fn<void(int)> saveCallback, bool warnRestart = false);
|
RadioBox(QWidget* parent, const QString &title, int currentValue, int valueCount, Fn<QString(int)> labelGetter, Fn<void(int)> saveCallback, bool warnRestart = false);
|
||||||
RadioBox(QWidget* parent, const QString &title, const QString &description, int currentValue, const QMap<int, QString> &options, Fn<void(int)> saveCallback, bool warnRestart = false);
|
RadioBox(QWidget* parent, const QString &title, const QString &description, int currentValue, int valueCount, Fn<QString(int)> labelGetter, Fn<void(int)> saveCallback, bool warnRestart = false);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
|
|
@ -31,7 +31,8 @@ private:
|
||||||
QString _title;
|
QString _title;
|
||||||
QString _description;
|
QString _description;
|
||||||
int _startValue;
|
int _startValue;
|
||||||
QMap<int, QString> _options;
|
int _valueCount;
|
||||||
|
Fn<QString(int)> _labelGetter;
|
||||||
Fn<void(int)> _saveCallback;
|
Fn<void(int)> _saveCallback;
|
||||||
bool _warnRestart = false;
|
bool _warnRestart = false;
|
||||||
std::shared_ptr<Ui::RadiobuttonGroup> _group;
|
std::shared_ptr<Ui::RadiobuttonGroup> _group;
|
||||||
|
|
|
||||||
|
|
@ -250,13 +250,6 @@ void SetupKotatoChats(
|
||||||
Ui::show(Box<FontsBox>());
|
Ui::show(Box<FontsBox>());
|
||||||
});
|
});
|
||||||
|
|
||||||
const QMap<int, QString> userpicRoundOptions = {
|
|
||||||
{ 0, UserpicRoundingLabel(0) },
|
|
||||||
{ 1, UserpicRoundingLabel(1) },
|
|
||||||
{ 2, UserpicRoundingLabel(2) },
|
|
||||||
{ 3, UserpicRoundingLabel(3) }
|
|
||||||
};
|
|
||||||
|
|
||||||
AddButtonWithLabel(
|
AddButtonWithLabel(
|
||||||
container,
|
container,
|
||||||
tr::ktg_settings_userpic_rounding(),
|
tr::ktg_settings_userpic_rounding(),
|
||||||
|
|
@ -267,7 +260,8 @@ void SetupKotatoChats(
|
||||||
tr::ktg_settings_userpic_rounding(tr::now),
|
tr::ktg_settings_userpic_rounding(tr::now),
|
||||||
tr::ktg_settings_userpic_rounding_desc(tr::now),
|
tr::ktg_settings_userpic_rounding_desc(tr::now),
|
||||||
cUserpicCornersType(),
|
cUserpicCornersType(),
|
||||||
userpicRoundOptions,
|
4,
|
||||||
|
UserpicRoundingLabel,
|
||||||
[=] (int value) {
|
[=] (int value) {
|
||||||
cSetUserpicCornersType(value);
|
cSetUserpicCornersType(value);
|
||||||
::Kotato::JsonSettings::Write();
|
::Kotato::JsonSettings::Write();
|
||||||
|
|
@ -389,13 +383,6 @@ void SetupKotatoNetwork(not_null<Ui::VerticalLayout*> container) {
|
||||||
AddSkip(container);
|
AddSkip(container);
|
||||||
AddSubsectionTitle(container, tr::ktg_settings_network());
|
AddSubsectionTitle(container, tr::ktg_settings_network());
|
||||||
|
|
||||||
const QMap<int, QString> netBoostOptions = {
|
|
||||||
{ 0, NetBoostLabel(0) },
|
|
||||||
{ 1, NetBoostLabel(1) },
|
|
||||||
{ 2, NetBoostLabel(2) },
|
|
||||||
{ 3, NetBoostLabel(3) }
|
|
||||||
};
|
|
||||||
|
|
||||||
AddButtonWithLabel(
|
AddButtonWithLabel(
|
||||||
container,
|
container,
|
||||||
tr::ktg_settings_net_speed_boost(),
|
tr::ktg_settings_net_speed_boost(),
|
||||||
|
|
@ -406,7 +393,8 @@ void SetupKotatoNetwork(not_null<Ui::VerticalLayout*> container) {
|
||||||
tr::ktg_net_speed_boost_title(tr::now),
|
tr::ktg_net_speed_boost_title(tr::now),
|
||||||
tr::ktg_net_speed_boost_desc(tr::now),
|
tr::ktg_net_speed_boost_desc(tr::now),
|
||||||
cNetSpeedBoost(),
|
cNetSpeedBoost(),
|
||||||
netBoostOptions,
|
4,
|
||||||
|
NetBoostLabel,
|
||||||
[=] (int value) {
|
[=] (int value) {
|
||||||
SetNetworkBoost(value);
|
SetNetworkBoost(value);
|
||||||
::Kotato::JsonSettings::Write();
|
::Kotato::JsonSettings::Write();
|
||||||
|
|
@ -530,15 +518,6 @@ void SetupKotatoSystem(
|
||||||
}, container->lifetime());
|
}, container->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
const QMap<int, QString> trayIconOptions = {
|
|
||||||
{ 0, TrayIconLabel(0) },
|
|
||||||
{ 1, TrayIconLabel(1) },
|
|
||||||
{ 2, TrayIconLabel(2) },
|
|
||||||
{ 3, TrayIconLabel(3) },
|
|
||||||
{ 4, TrayIconLabel(4) },
|
|
||||||
{ 5, TrayIconLabel(5) },
|
|
||||||
};
|
|
||||||
|
|
||||||
auto trayIconText = rpl::single(
|
auto trayIconText = rpl::single(
|
||||||
rpl::empty_value()
|
rpl::empty_value()
|
||||||
) | rpl::then(
|
) | rpl::then(
|
||||||
|
|
@ -557,7 +536,8 @@ void SetupKotatoSystem(
|
||||||
tr::ktg_settings_tray_icon(tr::now),
|
tr::ktg_settings_tray_icon(tr::now),
|
||||||
tr::ktg_settings_tray_icon_desc(tr::now),
|
tr::ktg_settings_tray_icon_desc(tr::now),
|
||||||
cCustomAppIcon(),
|
cCustomAppIcon(),
|
||||||
trayIconOptions,
|
6,
|
||||||
|
TrayIconLabel,
|
||||||
[=] (int value) {
|
[=] (int value) {
|
||||||
cSetCustomAppIcon(value);
|
cSetCustomAppIcon(value);
|
||||||
controller->session().data().notifyUnreadBadgeChanged();
|
controller->session().data().notifyUnreadBadgeChanged();
|
||||||
|
|
@ -575,12 +555,6 @@ void SetupKotatoOther(not_null<Ui::VerticalLayout*> container) {
|
||||||
|
|
||||||
SettingsMenuCSwitch(ktg_settings_show_phone_number, ShowPhoneInDrawer);
|
SettingsMenuCSwitch(ktg_settings_show_phone_number, ShowPhoneInDrawer);
|
||||||
|
|
||||||
const QMap<int, QString> chatIdOptions = {
|
|
||||||
{ 0, ChatIdLabel(0) },
|
|
||||||
{ 1, ChatIdLabel(1) },
|
|
||||||
{ 2, ChatIdLabel(2) },
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto chatIdButton = container->add(
|
const auto chatIdButton = container->add(
|
||||||
object_ptr<Button>(
|
object_ptr<Button>(
|
||||||
container,
|
container,
|
||||||
|
|
@ -603,7 +577,8 @@ void SetupKotatoOther(not_null<Ui::VerticalLayout*> container) {
|
||||||
tr::ktg_settings_chat_id(tr::now),
|
tr::ktg_settings_chat_id(tr::now),
|
||||||
tr::ktg_settings_chat_id_desc(tr::now),
|
tr::ktg_settings_chat_id_desc(tr::now),
|
||||||
cShowChatId(),
|
cShowChatId(),
|
||||||
chatIdOptions,
|
3,
|
||||||
|
ChatIdLabel,
|
||||||
[=] (int value) {
|
[=] (int value) {
|
||||||
cSetShowChatId(value);
|
cSetShowChatId(value);
|
||||||
::Kotato::JsonSettings::Write();
|
::Kotato::JsonSettings::Write();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue