mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-09-03 16:05:57 +00:00
Refactor Ui::Radiobutton. Add Ui::Radioenum<Enum>.
Now group of Ui::Radiobutton instances share Ui::RadiobuttonGroup. All value management is done through the group instance, not through separate radio buttons. Also a template for groups over enums added.
This commit is contained in:
@@ -90,7 +90,7 @@ std::unique_ptr<PrivacyExceptionsBoxController::Row> PrivacyExceptionsBoxControl
|
||||
|
||||
class EditPrivacyBox::OptionWidget : public TWidget {
|
||||
public:
|
||||
OptionWidget(QWidget *parent, const std::shared_ptr<Ui::RadiobuttonGroup> &group, int value, const QString &text, const QString &description);
|
||||
OptionWidget(QWidget *parent, const std::shared_ptr<Ui::RadioenumGroup<Option>> &group, Option value, const QString &text, const QString &description);
|
||||
|
||||
QMargins getMargins() const override {
|
||||
return _option->getMargins();
|
||||
@@ -100,12 +100,12 @@ protected:
|
||||
int resizeGetHeight(int newWidth) override;
|
||||
|
||||
private:
|
||||
object_ptr<Ui::Radiobutton> _option;
|
||||
object_ptr<Ui::Radioenum<Option>> _option;
|
||||
object_ptr<Ui::FlatLabel> _description;
|
||||
|
||||
};
|
||||
|
||||
EditPrivacyBox::OptionWidget::OptionWidget(QWidget *parent, const std::shared_ptr<Ui::RadiobuttonGroup> &group, int value, const QString &text, const QString &description) : TWidget(parent)
|
||||
EditPrivacyBox::OptionWidget::OptionWidget(QWidget *parent, const std::shared_ptr<Ui::RadioenumGroup<Option>> &group, Option value, const QString &text, const QString &description) : TWidget(parent)
|
||||
, _option(this, group, value, text, st::defaultBoxCheckbox)
|
||||
, _description(this, description, Ui::FlatLabel::InitType::Simple, st::editPrivacyLabel) {
|
||||
}
|
||||
@@ -178,15 +178,14 @@ int EditPrivacyBox::resizeGetHeight(int newWidth) {
|
||||
|
||||
int EditPrivacyBox::countDefaultHeight(int newWidth) {
|
||||
auto height = 0;
|
||||
auto fakeGroup = std::make_shared<Ui::RadiobuttonGroup>(0);
|
||||
auto fakeGroup = std::make_shared<Ui::RadioenumGroup<Option>>(Option::Everyone);
|
||||
auto optionHeight = [this, newWidth, &fakeGroup](Option option, const QString &label) {
|
||||
auto description = _controller->optionDescription(option);
|
||||
if (description.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto value = static_cast<int>(Option::Everyone);
|
||||
auto fake = object_ptr<OptionWidget>(nullptr, fakeGroup, value, label, description);
|
||||
auto fake = object_ptr<OptionWidget>(nullptr, fakeGroup, Option::Everyone, label, description);
|
||||
fake->resizeToNaturalWidth(newWidth - st::editPrivacyOptionMargin.left() - st::editPrivacyOptionMargin.right());
|
||||
return st::editPrivacyOptionMargin.top() + fake->heightNoMargins() + st::editPrivacyOptionMargin.bottom();
|
||||
};
|
||||
@@ -296,20 +295,19 @@ void EditPrivacyBox::createOption(Option option, object_ptr<OptionWidget> &widge
|
||||
auto description = _controller->optionDescription(option);
|
||||
auto selected = (_option == option);
|
||||
if (!description.isEmpty() || selected) {
|
||||
auto value = static_cast<int>(option);
|
||||
widget.create(this, _optionGroup, value, label, description);
|
||||
widget.create(this, _optionGroup, option, label, description);
|
||||
}
|
||||
}
|
||||
|
||||
void EditPrivacyBox::createWidgets() {
|
||||
_loading.destroy();
|
||||
|
||||
_optionGroup = std::make_shared<Ui::RadiobuttonGroup>(static_cast<int>(_option));
|
||||
_optionGroup = std::make_shared<Ui::RadioenumGroup<Option>>(_option);
|
||||
createOption(Option::Everyone, _everyone, lang(lng_edit_privacy_everyone));
|
||||
createOption(Option::Contacts, _contacts, lang(lng_edit_privacy_contacts));
|
||||
createOption(Option::Nobody, _nobody, lang(lng_edit_privacy_nobody));
|
||||
_optionGroup->setChangedCallback([this](int value) {
|
||||
_option = static_cast<Option>(value);
|
||||
_optionGroup->setChangedCallback([this](Option value) {
|
||||
_option = value;
|
||||
_alwaysLink->toggleAnimated(showExceptionLink(Exception::Always));
|
||||
_neverLink->toggleAnimated(showExceptionLink(Exception::Never));
|
||||
});
|
||||
|
Reference in New Issue
Block a user