From e80a7907a9f5d04e23de97fa586fd7c768e389fc Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 2 Sep 2021 21:55:36 +0300 Subject: [PATCH] Removed Q_OBJECT from CountryInput. --- Telegram/SourceFiles/intro/intro_phone.cpp | 5 +- Telegram/SourceFiles/ui/countryinput.cpp | 57 +++++++++++++++++----- Telegram/SourceFiles/ui/countryinput.h | 7 ++- 3 files changed, 51 insertions(+), 18 deletions(-) diff --git a/Telegram/SourceFiles/intro/intro_phone.cpp b/Telegram/SourceFiles/intro/intro_phone.cpp index 665ee26bc..ec9a3086f 100644 --- a/Telegram/SourceFiles/intro/intro_phone.cpp +++ b/Telegram/SourceFiles/intro/intro_phone.cpp @@ -51,10 +51,11 @@ PhoneWidget::PhoneWidget( _code->startErasing(e); }, _code->lifetime()); - connect(_country, &CountryInput::codeChanged, [=](const QString &code) { + _country->codeChanged( + ) | rpl::start_with_next([=](const QString &code) { _code->codeSelected(code); _phone->chooseCode(code); - }); + }, _country->lifetime()); _code->codeChanged( ) | rpl::start_with_next([=](const QString &code) { _country->onChooseCode(code); diff --git a/Telegram/SourceFiles/ui/countryinput.cpp b/Telegram/SourceFiles/ui/countryinput.cpp index 962bfc5be..f1f790185 100644 --- a/Telegram/SourceFiles/ui/countryinput.cpp +++ b/Telegram/SourceFiles/ui/countryinput.cpp @@ -35,7 +35,11 @@ CountryInput::CountryInput(QWidget *parent, const style::InputField &st) //auto metrics = QFontMetrics(placeholderFont); auto placeholder = QString();// metrics.elidedText(tr::lng_country_fake_ph(tr::now), Qt::ElideRight, availableWidth); if (!placeholder.isNull()) { - _placeholderPath.addText(0, QFontMetrics(placeholderFont).ascent(), placeholderFont, placeholder); + _placeholderPath.addText( + 0, + QFontMetrics(placeholderFont).ascent(), + placeholderFont, + placeholder); } } @@ -47,10 +51,21 @@ void CountryInput::paintEvent(QPaintEvent *e) { p.fillRect(r, _st.textBg); } if (_st.border) { - p.fillRect(0, height() - _st.border, width(), _st.border, _st.borderFg); + p.fillRect( + 0, + height() - _st.border, + width(), + _st.border, + _st.borderFg); } - st::introCountryIcon.paint(p, width() - st::introCountryIcon.width() - st::introCountryIconPosition.x(), st::introCountryIconPosition.y(), width()); + st::introCountryIcon.paint( + p, + width() + - st::introCountryIcon.width() + - st::introCountryIconPosition.x(), + st::introCountryIconPosition.y(), + width()); p.setFont(_st.font); p.setPen(_st.textFg); @@ -60,15 +75,27 @@ void CountryInput::paintEvent(QPaintEvent *e) { p.save(); p.setClipRect(r); - auto placeholderTop = anim::interpolate(0, _st.placeholderShift, placeholderShiftDegree); + const auto placeholderTop = anim::interpolate( + 0, + _st.placeholderShift, + placeholderShiftDegree); - QRect r(rect().marginsRemoved(_st.textMargins + _st.placeholderMargins)); + auto r = QRect(rect() - (_st.textMargins + _st.placeholderMargins)); r.moveTop(r.top() + placeholderTop); - if (rtl()) r.moveLeft(width() - r.left() - r.width()); + if (rtl()) { + r.moveLeft(width() - r.left() - r.width()); + } - auto placeholderScale = 1. - (1. - _st.placeholderScale) * placeholderShiftDegree; - auto placeholderFg = anim::color(_st.placeholderFg, _st.placeholderFgActive, 0.); - placeholderFg = anim::color(placeholderFg, _st.placeholderFgError, 0.); + const auto placeholderScale = 1. + - (1. - _st.placeholderScale) * placeholderShiftDegree; + auto placeholderFg = anim::color( + _st.placeholderFg, + _st.placeholderFgActive, + 0.); + placeholderFg = anim::color( + placeholderFg, + _st.placeholderFgError, + 0.); PainterHighQualityEnabler hq(p); p.setPen(Qt::NoPen); @@ -170,10 +197,16 @@ void CountryInput::chooseCountry( int codeIndex) { _chosenIso = LastValidISO = info->iso2; setText(info->name); - codeChanged(info->codes[codeIndex].callingCode); + _codeChanged.fire_copy(info->codes[codeIndex].callingCode); update(); } -void CountryInput::setText(const QString &newText) { - _text = _st.font->elided(newText, width() - _st.textMargins.left() - _st.textMargins.right()); +rpl::producer CountryInput::codeChanged() const { + return _codeChanged.events(); +} + +void CountryInput::setText(const QString &newText) { + _text = _st.font->elided( + newText, + width() - _st.textMargins.left() - _st.textMargins.right()); } diff --git a/Telegram/SourceFiles/ui/countryinput.h b/Telegram/SourceFiles/ui/countryinput.h index 5e7069935..511ed4c2f 100644 --- a/Telegram/SourceFiles/ui/countryinput.h +++ b/Telegram/SourceFiles/ui/countryinput.h @@ -24,7 +24,6 @@ class RippleAnimation; } // namespace Ui class CountryInput : public Ui::RpWidget { - Q_OBJECT public: CountryInput(QWidget *parent, const style::InputField &st); @@ -34,11 +33,9 @@ public: } bool chooseCountry(const QString &country); -public Q_SLOTS: void onChooseCode(const QString &code); -Q_SIGNALS: - void codeChanged(const QString &code); + rpl::producer codeChanged() const; protected: void paintEvent(QPaintEvent *e) override; @@ -57,4 +54,6 @@ private: QString _chosenIso; QPainterPath _placeholderPath; + rpl::event_stream _codeChanged; + };