2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Allow selecting country in passport.

This commit is contained in:
John Preston
2018-04-10 15:26:21 +04:00
parent 62389f5ef7
commit e4e05a14b7
11 changed files with 417 additions and 32 deletions

View File

@@ -203,6 +203,22 @@ CountrySelectBox::CountrySelectBox(QWidget*)
: _select(this, st::contactsMultiSelect, langFactory(lng_country_ph)) {
}
CountrySelectBox::CountrySelectBox(QWidget*, const QString &iso, Type type)
: _type(type)
, _select(this, st::contactsMultiSelect, langFactory(lng_country_ph)) {
lastValidISO = iso;
}
QString CountrySelectBox::NameByISO(const QString &iso) {
if (_countriesByISO2.isEmpty()) {
initCountries();
}
const auto i = _countriesByISO2.constFind(iso);
return (i == _countriesByISO2.cend())
? QString()
: QString::fromUtf8((*i)->name);
}
void CountrySelectBox::prepare() {
setTitle(langFactory(lng_country_select));
@@ -210,7 +226,10 @@ void CountrySelectBox::prepare() {
_select->setQueryChangedCallback([this](const QString &query) { onFilterUpdate(query); });
_select->setSubmittedCallback([this](Qt::KeyboardModifiers) { onSubmit(); });
_inner = setInnerWidget(object_ptr<Inner>(this), st::countriesScroll, _select->height());
_inner = setInnerWidget(
object_ptr<Inner>(this, _type),
st::countriesScroll,
_select->height());
addButton(langFactory(lng_close), [this] { closeBox(); });
@@ -256,10 +275,16 @@ void CountrySelectBox::setInnerFocus() {
_select->setInnerFocus();
}
CountrySelectBox::Inner::Inner(QWidget *parent) : TWidget(parent)
CountrySelectBox::Inner::Inner(QWidget *parent, Type type)
: TWidget(parent)
, _type(type)
, _rowHeight(st::countryRowHeight) {
setAttribute(Qt::WA_OpaquePaintEvent);
if (countriesNames.isEmpty()) {
initCountries();
}
CountriesByISO2::const_iterator l = _countriesByISO2.constFind(lastValidISO);
bool seenLastValid = false;
int already = countriesAll.size();
@@ -341,9 +366,11 @@ void CountrySelectBox::Inner::paintEvent(QPaintEvent *e) {
p.setPen(st::countryRowNameFg);
p.drawTextLeft(st::countryRowPadding.left(), y + st::countryRowPadding.top(), width(), name);
p.setFont(st::countryRowCodeFont);
p.setPen(selected ? st::countryRowCodeFgOver : st::countryRowCodeFg);
p.drawTextLeft(st::countryRowPadding.left() + nameWidth + st::countryRowPadding.right(), y + st::countryRowPadding.top(), width(), code);
if (_type == Type::Phones) {
p.setFont(st::countryRowCodeFont);
p.setPen(selected ? st::countryRowCodeFgOver : st::countryRowCodeFg);
p.drawTextLeft(st::countryRowPadding.left() + nameWidth + st::countryRowPadding.right(), y + st::countryRowPadding.top(), width(), code);
}
}
} else {
p.fillRect(r, st::boxBg);

View File

@@ -56,7 +56,15 @@ class CountrySelectBox : public BoxContent {
Q_OBJECT
public:
enum class Type {
Phones,
Countries,
};
CountrySelectBox(QWidget*);
CountrySelectBox(QWidget*, const QString &iso, Type type);
static QString NameByISO(const QString &iso);
signals:
void countryChosen(const QString &iso);
@@ -74,6 +82,7 @@ private slots:
private:
void onFilterUpdate(const QString &query);
Type _type = Type::Phones;
object_ptr<Ui::MultiSelect> _select;
class Inner;
@@ -86,7 +95,7 @@ class CountrySelectBox::Inner : public TWidget {
Q_OBJECT
public:
Inner(QWidget *parent);
Inner(QWidget *parent, Type type);
void updateFilter(QString filter = QString());
@@ -120,7 +129,8 @@ private:
void updateRow(int index);
void setPressed(int pressed);
int _rowHeight;
Type _type = Type::Phones;
int _rowHeight = 0;
int _selected = -1;
int _pressed = -1;

View File

@@ -35,8 +35,12 @@ int LinkButton::naturalWidth() const {
void LinkButton::paintEvent(QPaintEvent *e) {
Painter p(this);
auto &font = (isOver() ? _st.overFont : _st.font);
auto &pen = (isOver() ? _st.overColor : _st.color);
const auto &font = (isOver() ? _st.overFont : _st.font);
const auto pen = _textFgOverride.has_value()
? QPen(*_textFgOverride)
: isOver()
? _st.overColor
: _st.color;
p.setFont(font);
p.setPen(pen);
const auto left = _st.padding.left();
@@ -56,6 +60,11 @@ void LinkButton::setText(const QString &text) {
update();
}
void LinkButton::setColorOverride(base::optional<QColor> textFg) {
_textFgOverride = textFg;
update();
}
void LinkButton::onStateChanged(State was, StateChangeSource source) {
update();
}

View File

@@ -24,6 +24,7 @@ public:
int naturalWidth() const override;
void setText(const QString &text);
void setColorOverride(base::optional<QColor> textFg);
protected:
void paintEvent(QPaintEvent *e) override;
@@ -34,6 +35,7 @@ private:
const style::LinkButton &_st;
QString _text;
int _textWidth = 0;
base::optional<QColor> _textFgOverride;
};