From 35008195e8e429d7dfbad1cbfcedb8129953b44c Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Wed, 31 Mar 2021 22:05:08 +0300 Subject: [PATCH] Possibility to add description to radio options --- .../kotato/customboxes/radio_box.cpp | 57 ++++++++++++++++++- .../kotato/customboxes/radio_box.h | 39 ++++++++++++- 2 files changed, 93 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/kotato/customboxes/radio_box.cpp b/Telegram/SourceFiles/kotato/customboxes/radio_box.cpp index 6d1502c55..9b03b7f58 100644 --- a/Telegram/SourceFiles/kotato/customboxes/radio_box.cpp +++ b/Telegram/SourceFiles/kotato/customboxes/radio_box.cpp @@ -53,6 +53,44 @@ RadioBox::RadioBox( , _warnRestart(warnRestart) { } +RadioBox::RadioBox( + QWidget*, + const QString &title, + int currentValue, + int valueCount, + Fn labelGetter, + Fn descriptionGetter, + Fn saveCallback, + bool warnRestart) +: _title(title) +, _startValue(currentValue) +, _valueCount(valueCount) +, _labelGetter(labelGetter) +, _descriptionGetter(descriptionGetter) +, _saveCallback(std::move(saveCallback)) +, _warnRestart(warnRestart) { +} + +RadioBox::RadioBox( + QWidget*, + const QString &title, + const QString &description, + int currentValue, + int valueCount, + Fn labelGetter, + Fn descriptionGetter, + Fn saveCallback, + bool warnRestart) +: _title(title) +, _description(description) +, _startValue(currentValue) +, _valueCount(valueCount) +, _labelGetter(labelGetter) +, _descriptionGetter(descriptionGetter) +, _saveCallback(std::move(saveCallback)) +, _warnRestart(warnRestart) { +} + void RadioBox::prepare() { setTitle(rpl::single(_title)); @@ -74,6 +112,10 @@ void RadioBox::prepare() { _group = std::make_shared(_startValue); for (auto i = 0; i != _valueCount; ++i) { + const auto description = _descriptionGetter + ? _descriptionGetter(i) + : QString(); + content->add( object_ptr( this, @@ -85,7 +127,20 @@ void RadioBox::prepare() { st::boxPadding.left(), st::boxPadding.bottom(), st::boxPadding.right(), - st::boxPadding.bottom())); + description.isEmpty() ? st::boxPadding.bottom() : 0)); + if (!description.isEmpty()) { + content->add( + object_ptr(this, description, st::boxDividerLabel), + style::margins( + st::boxPadding.left() + + st::autolockButton.margin.left() + + st::autolockButton.margin.right() + + st::defaultToggle.width + + st::defaultToggle.border * 2, + 0, + st::boxPadding.right(), + st::boxPadding.bottom())); + } } setDimensionsToContent(st::boxWidth, content); diff --git a/Telegram/SourceFiles/kotato/customboxes/radio_box.h b/Telegram/SourceFiles/kotato/customboxes/radio_box.h index 680c2ca92..ab7dc559e 100644 --- a/Telegram/SourceFiles/kotato/customboxes/radio_box.h +++ b/Telegram/SourceFiles/kotato/customboxes/radio_box.h @@ -19,8 +19,42 @@ namespace Kotato { class RadioBox : public Ui::BoxContent { public: - RadioBox(QWidget* parent, const QString &title, int currentValue, int valueCount, Fn labelGetter, Fn saveCallback, bool warnRestart = false); - RadioBox(QWidget* parent, const QString &title, const QString &description, int currentValue, int valueCount, Fn labelGetter, Fn saveCallback, bool warnRestart = false); + RadioBox( + QWidget* parent, + const QString &title, + int currentValue, + int valueCount, + Fn labelGetter, + Fn saveCallback, + bool warnRestart = false); + RadioBox( + QWidget* parent, + const QString &title, + const QString &description, + int currentValue, + int valueCount, + Fn labelGetter, + Fn saveCallback, + bool warnRestart = false); + RadioBox( + QWidget* parent, + const QString &title, + int currentValue, + int valueCount, + Fn labelGetter, + Fn descriptionGetter, + Fn saveCallback, + bool warnRestart = false); + RadioBox( + QWidget* parent, + const QString &title, + const QString &description, + int currentValue, + int valueCount, + Fn labelGetter, + Fn descriptionGetter, + Fn saveCallback, + bool warnRestart = false); protected: void prepare() override; @@ -33,6 +67,7 @@ private: int _startValue; int _valueCount; Fn _labelGetter; + Fn _descriptionGetter; Fn _saveCallback; bool _warnRestart = false; std::shared_ptr _group;