diff options
Diffstat (limited to 'Telegram/SourceFiles/payments/ui/payments_edit_card.cpp')
-rw-r--r-- | Telegram/SourceFiles/payments/ui/payments_edit_card.cpp | 193 |
1 files changed, 84 insertions, 109 deletions
diff --git a/Telegram/SourceFiles/payments/ui/payments_edit_card.cpp b/Telegram/SourceFiles/payments/ui/payments_edit_card.cpp index 7d5918e9f1..8d647a174f 100644 --- a/Telegram/SourceFiles/payments/ui/payments_edit_card.cpp +++ b/Telegram/SourceFiles/payments/ui/payments_edit_card.cpp @@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "payments/ui/payments_edit_card.h" #include "payments/ui/payments_panel_delegate.h" -#include "passport/ui/passport_details_row.h" +#include "payments/ui/payments_field.h" #include "ui/widgets/scroll_area.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" @@ -52,16 +52,24 @@ EditCard::EditCard( void EditCard::setFocus(CardField field) { _focusField = field; - if (const auto control = controlForField(field)) { - _scroll->ensureWidgetVisible(control); + if (const auto control = lookupField(field)) { + _scroll->ensureWidgetVisible(control->widget()); + control->setFocus(); + } +} + +void EditCard::setFocusFast(CardField field) { + _focusField = field; + if (const auto control = lookupField(field)) { + _scroll->ensureWidgetVisible(control->widget()); control->setFocusFast(); } } void EditCard::showError(CardField field) { - if (const auto control = controlForField(field)) { - _scroll->ensureWidgetVisible(control); - control->showError(QString()); + if (const auto control = lookupField(field)) { + _scroll->ensureWidgetVisible(control->widget()); + control->showError(); } } @@ -95,102 +103,69 @@ not_null<RpWidget*> EditCard::setupContent() { const auto showBox = [=](object_ptr<BoxContent> box) { _delegate->panelShowBox(std::move(box)); }; - using Type = Passport::Ui::PanelDetailsType; - auto maxLabelWidth = 0; - accumulate_max( - maxLabelWidth, - Row::LabelWidth("Card Number")); - accumulate_max( - maxLabelWidth, - Row::LabelWidth("CVC")); - accumulate_max( - maxLabelWidth, - Row::LabelWidth("MM/YY")); + const auto add = [&](FieldConfig &&config) { + auto result = std::make_unique<Field>(inner, std::move(config)); + inner->add(result->ownedWidget(), st::paymentsFieldPadding); + return result; + }; + _number = add({ + .type = FieldType::CardNumber, + .placeholder = tr::lng_payments_card_number(), + .required = true, + }); if (_native.needCardholderName) { - accumulate_max( - maxLabelWidth, - Row::LabelWidth("Cardholder Name")); - } - if (_native.needCountry) { - accumulate_max( - maxLabelWidth, - Row::LabelWidth("Billing Country")); - } - if (_native.needZip) { - accumulate_max( - maxLabelWidth, - Row::LabelWidth("Billing Zip")); + _name = add({ + .type = FieldType::CardNumber, + .placeholder = tr::lng_payments_card_holder(), + .required = true, + }); } - _number = inner->add( - Row::Create( - inner, - showBox, - QString(), - Type::Text, - "Card Number", - maxLabelWidth, - QString(), - QString(), - 1024)); - _cvc = inner->add( - Row::Create( - inner, - showBox, - QString(), - Type::Text, - "CVC", - maxLabelWidth, - QString(), - QString(), - 1024)); - _expire = inner->add( - Row::Create( + auto container = inner->add( + object_ptr<FixedHeightWidget>( inner, - showBox, - QString(), - Type::Text, - "MM/YY", - maxLabelWidth, - QString(), - QString(), - 1024)); - if (_native.needCardholderName) { - _name = inner->add( - Row::Create( + _number->widget()->height()), + st::paymentsFieldPadding); + _expire = std::make_unique<Field>(container, FieldConfig{ + .type = FieldType::CardExpireDate, + .placeholder = rpl::single(u"MM / YY"_q), + .required = true, + }); + _cvc = std::make_unique<Field>(container, FieldConfig{ + .type = FieldType::CardCVC, + .placeholder = rpl::single(u"CVC"_q), + .required = true, + }); + container->widthValue( + ) | rpl::start_with_next([=](int width) { + const auto left = (width - st::paymentsExpireCvcSkip) / 2; + const auto right = width - st::paymentsExpireCvcSkip - left; + _expire->widget()->resizeToWidth(left); + _cvc->widget()->resizeToWidth(right); + _expire->widget()->moveToLeft(0, 0, width); + _cvc->widget()->moveToRight(0, 0, width); + }, container->lifetime()); + if (_native.needCountry || _native.needZip) { + inner->add( + object_ptr<Ui::FlatLabel>( inner, - showBox, - QString(), - Type::Text, - "Cardholder Name", - maxLabelWidth, - QString(), - QString(), - 1024)); + tr::lng_payments_billing_address(), + st::paymentsBillingInformationTitle), + st::paymentsBillingInformationTitlePadding); } if (_native.needCountry) { - _country = inner->add( - Row::Create( - inner, - showBox, - QString(), - Type::Country, - "Billing Country", - maxLabelWidth, - QString(), - QString())); + _country = add({ + .type = FieldType::Country, + .placeholder = tr::lng_payments_billing_country(), + .required = true, + }); } if (_native.needZip) { - _zip = inner->add( - Row::Create( - inner, - showBox, - QString(), - Type::Postcode, - "Billing Zip Code", - maxLabelWidth, - QString(), - QString(), - kMaxPostcodeSize)); + _zip = add({ + .type = FieldType::Text, + .placeholder = tr::lng_payments_billing_zip_code(), + .maxLength = kMaxPostcodeSize, + .required = true, + }); } return inner; } @@ -200,7 +175,7 @@ void EditCard::resizeEvent(QResizeEvent *e) { } void EditCard::focusInEvent(QFocusEvent *e) { - if (const auto control = controlForField(_focusField)) { + if (const auto control = lookupField(_focusField)) { control->setFocusFast(); } } @@ -218,27 +193,27 @@ void EditCard::updateControlsGeometry() { _scroll->updateBars(); } -auto EditCard::controlForField(CardField field) const -> Row* { +auto EditCard::lookupField(CardField field) const -> Field* { switch (field) { - case CardField::Number: return _number; - case CardField::CVC: return _cvc; - case CardField::ExpireDate: return _expire; - case CardField::Name: return _name; - case CardField::AddressCountry: return _country; - case CardField::AddressZip: return _zip; + case CardField::Number: return _number.get(); + case CardField::CVC: return _cvc.get(); + case CardField::ExpireDate: return _expire.get(); + case CardField::Name: return _name.get(); + case CardField::AddressCountry: return _country.get(); + case CardField::AddressZip: return _zip.get(); } Unexpected("Unknown field in EditCard::controlForField."); } UncheckedCardDetails EditCard::collect() const { return { - .number = _number ? _number->valueCurrent() : QString(), - .cvc = _cvc ? _cvc->valueCurrent() : QString(), - .expireYear = _expire ? ExtractYear(_expire->valueCurrent()) : 0, - .expireMonth = _expire ? ExtractMonth(_expire->valueCurrent()) : 0, - .cardholderName = _name ? _name->valueCurrent() : QString(), - .addressCountry = _country ? _country->valueCurrent() : QString(), - .addressZip = _zip ? _zip->valueCurrent() : QString(), + .number = _number ? _number->value() : QString(), + .cvc = _cvc ? _cvc->value() : QString(), + .expireYear = _expire ? ExtractYear(_expire->value()) : 0, + .expireMonth = _expire ? ExtractMonth(_expire->value()) : 0, + .cardholderName = _name ? _name->value() : QString(), + .addressCountry = _country ? _country->value() : QString(), + .addressZip = _zip ? _zip->value() : QString(), }; } |