mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Removed Q_OBJECT from CountryInput.
This commit is contained in:
parent
48f7d715d6
commit
e80a7907a9
3 changed files with 51 additions and 18 deletions
|
@ -51,10 +51,11 @@ PhoneWidget::PhoneWidget(
|
||||||
_code->startErasing(e);
|
_code->startErasing(e);
|
||||||
}, _code->lifetime());
|
}, _code->lifetime());
|
||||||
|
|
||||||
connect(_country, &CountryInput::codeChanged, [=](const QString &code) {
|
_country->codeChanged(
|
||||||
|
) | rpl::start_with_next([=](const QString &code) {
|
||||||
_code->codeSelected(code);
|
_code->codeSelected(code);
|
||||||
_phone->chooseCode(code);
|
_phone->chooseCode(code);
|
||||||
});
|
}, _country->lifetime());
|
||||||
_code->codeChanged(
|
_code->codeChanged(
|
||||||
) | rpl::start_with_next([=](const QString &code) {
|
) | rpl::start_with_next([=](const QString &code) {
|
||||||
_country->onChooseCode(code);
|
_country->onChooseCode(code);
|
||||||
|
|
|
@ -35,7 +35,11 @@ CountryInput::CountryInput(QWidget *parent, const style::InputField &st)
|
||||||
//auto metrics = QFontMetrics(placeholderFont);
|
//auto metrics = QFontMetrics(placeholderFont);
|
||||||
auto placeholder = QString();// metrics.elidedText(tr::lng_country_fake_ph(tr::now), Qt::ElideRight, availableWidth);
|
auto placeholder = QString();// metrics.elidedText(tr::lng_country_fake_ph(tr::now), Qt::ElideRight, availableWidth);
|
||||||
if (!placeholder.isNull()) {
|
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);
|
p.fillRect(r, _st.textBg);
|
||||||
}
|
}
|
||||||
if (_st.border) {
|
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.setFont(_st.font);
|
||||||
p.setPen(_st.textFg);
|
p.setPen(_st.textFg);
|
||||||
|
@ -60,15 +75,27 @@ void CountryInput::paintEvent(QPaintEvent *e) {
|
||||||
p.save();
|
p.save();
|
||||||
p.setClipRect(r);
|
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);
|
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;
|
const auto placeholderScale = 1.
|
||||||
auto placeholderFg = anim::color(_st.placeholderFg, _st.placeholderFgActive, 0.);
|
- (1. - _st.placeholderScale) * placeholderShiftDegree;
|
||||||
placeholderFg = anim::color(placeholderFg, _st.placeholderFgError, 0.);
|
auto placeholderFg = anim::color(
|
||||||
|
_st.placeholderFg,
|
||||||
|
_st.placeholderFgActive,
|
||||||
|
0.);
|
||||||
|
placeholderFg = anim::color(
|
||||||
|
placeholderFg,
|
||||||
|
_st.placeholderFgError,
|
||||||
|
0.);
|
||||||
|
|
||||||
PainterHighQualityEnabler hq(p);
|
PainterHighQualityEnabler hq(p);
|
||||||
p.setPen(Qt::NoPen);
|
p.setPen(Qt::NoPen);
|
||||||
|
@ -170,10 +197,16 @@ void CountryInput::chooseCountry(
|
||||||
int codeIndex) {
|
int codeIndex) {
|
||||||
_chosenIso = LastValidISO = info->iso2;
|
_chosenIso = LastValidISO = info->iso2;
|
||||||
setText(info->name);
|
setText(info->name);
|
||||||
codeChanged(info->codes[codeIndex].callingCode);
|
_codeChanged.fire_copy(info->codes[codeIndex].callingCode);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CountryInput::setText(const QString &newText) {
|
rpl::producer<QString> CountryInput::codeChanged() const {
|
||||||
_text = _st.font->elided(newText, width() - _st.textMargins.left() - _st.textMargins.right());
|
return _codeChanged.events();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CountryInput::setText(const QString &newText) {
|
||||||
|
_text = _st.font->elided(
|
||||||
|
newText,
|
||||||
|
width() - _st.textMargins.left() - _st.textMargins.right());
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ class RippleAnimation;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
||||||
class CountryInput : public Ui::RpWidget {
|
class CountryInput : public Ui::RpWidget {
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CountryInput(QWidget *parent, const style::InputField &st);
|
CountryInput(QWidget *parent, const style::InputField &st);
|
||||||
|
@ -34,11 +33,9 @@ public:
|
||||||
}
|
}
|
||||||
bool chooseCountry(const QString &country);
|
bool chooseCountry(const QString &country);
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void onChooseCode(const QString &code);
|
void onChooseCode(const QString &code);
|
||||||
|
|
||||||
Q_SIGNALS:
|
rpl::producer<QString> codeChanged() const;
|
||||||
void codeChanged(const QString &code);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
@ -57,4 +54,6 @@ private:
|
||||||
QString _chosenIso;
|
QString _chosenIso;
|
||||||
QPainterPath _placeholderPath;
|
QPainterPath _placeholderPath;
|
||||||
|
|
||||||
|
rpl::event_stream<QString> _codeChanged;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue