From 697f2851b0625ae784e405e7fc596d1629e8668a Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 18 Jul 2020 19:15:05 +0300 Subject: [PATCH] Added ability to pass rpl::producer to Checkbox constructors. --- ui/widgets/checkbox.cpp | 51 +++++++++++++++++++++++++++++++++++++++-- ui/widgets/checkbox.h | 17 ++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/ui/widgets/checkbox.cpp b/ui/widgets/checkbox.cpp index d921e51..3822d50 100644 --- a/ui/widgets/checkbox.cpp +++ b/ui/widgets/checkbox.cpp @@ -394,7 +394,37 @@ Checkbox::Checkbox( const style::Toggle &toggleSt) : Checkbox( parent, - text, + rpl::single(text), + st, + std::make_unique( + toggleSt, + checked)) { +} + +Checkbox::Checkbox( + QWidget *parent, + rpl::producer &&text, + bool checked, + const style::Checkbox &st, + const style::Check &checkSt) +: Checkbox( + parent, + std::move(text), + st, + std::make_unique( + checkSt, + checked)) { +} + +Checkbox::Checkbox( + QWidget *parent, + rpl::producer &&text, + bool checked, + const style::Checkbox &st, + const style::Toggle &toggleSt) +: Checkbox( + parent, + std::move(text), st, std::make_unique( toggleSt, @@ -406,17 +436,34 @@ Checkbox::Checkbox( const QString &text, const style::Checkbox &st, std::unique_ptr check) +: Checkbox( + parent, + rpl::single(text), + st, + std::move(check)) { +} + +Checkbox::Checkbox( + QWidget *parent, + rpl::producer &&text, + const style::Checkbox &st, + std::unique_ptr check) : RippleButton(parent, st.ripple) , _st(st) , _check(std::move(check)) , _text( _st.style, - text, + QString(), _checkboxOptions, countTextMinWidth()) { _check->setUpdateCallback([=] { update(); }); resizeToText(); setCursor(style::cur_pointer); + std::move( + text + ) | rpl::start_with_next([=](QString &&value) { + setText(std::move(value)); + }, lifetime()); } int Checkbox::countTextMinWidth() const { diff --git a/ui/widgets/checkbox.h b/ui/widgets/checkbox.h index d12121e..7c0d7de 100644 --- a/ui/widgets/checkbox.h +++ b/ui/widgets/checkbox.h @@ -146,11 +146,28 @@ public: bool checked, const style::Checkbox &st, const style::Toggle &toggleSt); + Checkbox( + QWidget *parent, + rpl::producer &&text, + bool checked = false, + const style::Checkbox &st = st::defaultCheckbox, + const style::Check &checkSt = st::defaultCheck); + Checkbox( + QWidget *parent, + rpl::producer &&text, + bool checked, + const style::Checkbox &st, + const style::Toggle &toggleSt); Checkbox( QWidget *parent, const QString &text, const style::Checkbox &st, std::unique_ptr check); + Checkbox( + QWidget *parent, + rpl::producer &&text, + const style::Checkbox &st, + std::unique_ptr check); void setText(const QString &text, bool rich = false); void setCheckAlignment(style::align alignment);