Removed Q_OBJECT from CountryInput.

This commit is contained in:
23rd 2021-09-02 21:55:36 +03:00 committed by John Preston
parent 48f7d715d6
commit e80a7907a9
3 changed files with 51 additions and 18 deletions

View file

@ -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);

View file

@ -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<QString> CountryInput::codeChanged() const {
return _codeChanged.events();
}
void CountryInput::setText(const QString &newText) {
_text = _st.font->elided(
newText,
width() - _st.textMargins.left() - _st.textMargins.right());
}

View file

@ -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<QString> codeChanged() const;
protected:
void paintEvent(QPaintEvent *e) override;
@ -57,4 +54,6 @@ private:
QString _chosenIso;
QPainterPath _placeholderPath;
rpl::event_stream<QString> _codeChanged;
};