Improve passport styles.

This commit is contained in:
John Preston 2018-06-08 22:26:08 +03:00
parent d0ed75f3b5
commit 2a110f0d3e
8 changed files with 96 additions and 32 deletions

View File

@ -494,8 +494,9 @@ void TopBarWidget::updateControlsGeometry() {
buttonsWidth += buttonsLeft + st::topBarActionSkip * 3; buttonsWidth += buttonsLeft + st::topBarActionSkip * 3;
auto widthLeft = qMin(width() - buttonsWidth, -2 * st::defaultActiveButton.width); auto widthLeft = qMin(width() - buttonsWidth, -2 * st::defaultActiveButton.width);
_forward->setFullWidth(-(widthLeft / 2)); auto buttonFullWidth = qMin(-(widthLeft / 2), 0);
_delete->setFullWidth(-(widthLeft / 2)); _forward->setFullWidth(buttonFullWidth);
_delete->setFullWidth(buttonFullWidth);
selectedButtonsTop += (height() - _forward->height()) / 2; selectedButtonsTop += (height() - _forward->height()) / 2;

View File

@ -34,6 +34,7 @@ passportErrorLabel: FlatLabel(passportPasswordLabel) {
textFg: boxTextFgError; textFg: boxTextFgError;
} }
passportVerifyErrorLabel: FlatLabel(passportErrorLabel) { passportVerifyErrorLabel: FlatLabel(passportErrorLabel) {
minWidth: 128px;
align: align(topleft); align: align(topleft);
} }
@ -169,10 +170,11 @@ passportDetailsField: InputField(defaultInputField) {
font: normalFont; font: normalFont;
} }
passportDetailsDateField: InputField(passportDetailsField) { passportDetailsDateField: InputField(passportDetailsField) {
textMargins: margins(2px, 8px, 2px, 0px);
border: 0px; border: 0px;
borderActive: 0px; borderActive: 0px;
heightMin: 30px; heightMin: 30px;
placeholderFont: font(semibold 14px); placeholderFont: semiboldFont;
placeholderFgActive: placeholderFgActive; placeholderFgActive: placeholderFgActive;
} }
passportDetailsSeparator: FlatLabel(passportPasswordLabelBold) { passportDetailsSeparator: FlatLabel(passportPasswordLabelBold) {
@ -189,7 +191,7 @@ passportDetailsFieldLeft: 116px;
passportDetailsFieldTop: 2px; passportDetailsFieldTop: 2px;
passportDetailsFieldSkipMin: 12px; passportDetailsFieldSkipMin: 12px;
passportDetailsSkip: 30px; passportDetailsSkip: 30px;
passportDetailsGenderSkip: 30px; passportDetailsGenderSkip: 20px;
passportRequestTypeSkip: 16px; passportRequestTypeSkip: 16px;

View File

@ -67,7 +67,7 @@ EditDocumentScheme GetDocumentScheme(
if (value.isEmpty() || value.size() > kMaxNameSize) { if (value.isEmpty() || value.size() > kMaxNameSize) {
return QString(); return QString();
} else if (!QRegularExpression( } else if (!QRegularExpression(
"^[a-zA-Z\\- ]+$" "^[a-zA-Z0-9\\.,/&\\-' ]+$"
).match(value).hasMatch()) { ).match(value).hasMatch()) {
return lang(lng_passport_bad_name); return lang(lng_passport_bad_name);
} }

View File

@ -78,6 +78,7 @@ public:
AbstractTextRow( AbstractTextRow(
QWidget *parent, QWidget *parent,
const QString &label, const QString &label,
int maxLabelWidth,
const QString &value, const QString &value,
int limit); int limit);
@ -101,6 +102,7 @@ public:
QWidget *parent, QWidget *parent,
not_null<PanelController*> controller, not_null<PanelController*> controller,
const QString &label, const QString &label,
int maxLabelWidth,
const QString &value); const QString &value);
rpl::producer<QString> value() const override; rpl::producer<QString> value() const override;
@ -152,7 +154,11 @@ private:
class DateRow : public PanelDetailsRow { class DateRow : public PanelDetailsRow {
public: public:
DateRow(QWidget *parent, const QString &label, const QString &value); DateRow(
QWidget *parent,
const QString &label,
int maxLabelWidth,
const QString &value);
bool setFocusFast() override; bool setFocusFast() override;
rpl::producer<QString> value() const override; rpl::producer<QString> value() const override;
@ -206,6 +212,7 @@ public:
GenderRow( GenderRow(
QWidget *parent, QWidget *parent,
const QString &label, const QString &label,
int maxLabelWidth,
const QString &value); const QString &value);
rpl::producer<QString> value() const override; rpl::producer<QString> value() const override;
@ -247,9 +254,10 @@ template <typename Input>
AbstractTextRow<Input>::AbstractTextRow( AbstractTextRow<Input>::AbstractTextRow(
QWidget *parent, QWidget *parent,
const QString &label, const QString &label,
int maxLabelWidth,
const QString &value, const QString &value,
int limit) int limit)
: PanelDetailsRow(parent, label) : PanelDetailsRow(parent, label, maxLabelWidth)
, _field(this, st::passportDetailsField, nullptr, value) , _field(this, st::passportDetailsField, nullptr, value)
, _value(value) { , _value(value) {
_field->setMaxLength(limit); _field->setMaxLength(limit);
@ -299,8 +307,9 @@ CountryRow::CountryRow(
QWidget *parent, QWidget *parent,
not_null<PanelController*> controller, not_null<PanelController*> controller,
const QString &label, const QString &label,
int maxLabelWidth,
const QString &value) const QString &value)
: PanelDetailsRow(parent, label) : PanelDetailsRow(parent, label, maxLabelWidth)
, _controller(controller) , _controller(controller)
, _link(this, CountryString(value), st::boxLinkButton) , _link(this, CountryString(value), st::boxLinkButton)
, _value(value) { , _value(value) {
@ -505,8 +514,9 @@ void DateInput::correctValue(
DateRow::DateRow( DateRow::DateRow(
QWidget *parent, QWidget *parent,
const QString &label, const QString &label,
int maxLabelWidth,
const QString &value) const QString &value)
: PanelDetailsRow(parent, label) : PanelDetailsRow(parent, label, maxLabelWidth)
, _day( , _day(
this, this,
st::passportDetailsDateField, st::passportDetailsDateField,
@ -726,25 +736,26 @@ int DateRow::resizeInner(int left, int top, int width) {
const auto right = left + width; const auto right = left + width;
const auto &_st = st::passportDetailsDateField; const auto &_st = st::passportDetailsDateField;
const auto &font = _st.placeholderFont; const auto &font = _st.placeholderFont;
const auto addToWidth = st::passportDetailsSeparatorPadding.left();
const auto dayWidth = _st.textMargins.left() const auto dayWidth = _st.textMargins.left()
+ _st.placeholderMargins.left() + _st.placeholderMargins.left()
+ font->width(lang(lng_date_input_day)) + font->width(lang(lng_date_input_day))
+ _st.placeholderMargins.right() + _st.placeholderMargins.right()
+ _st.textMargins.right() + _st.textMargins.right()
+ st::lineWidth; + addToWidth;
const auto monthWidth = _st.textMargins.left() const auto monthWidth = _st.textMargins.left()
+ _st.placeholderMargins.left() + _st.placeholderMargins.left()
+ font->width(lang(lng_date_input_month)) + font->width(lang(lng_date_input_month))
+ _st.placeholderMargins.right() + _st.placeholderMargins.right()
+ _st.textMargins.right() + _st.textMargins.right()
+ st::lineWidth; + addToWidth;
_day->setGeometry(left, top, dayWidth, _day->height()); _day->setGeometry(left, top, dayWidth, _day->height());
left += dayWidth - st::lineWidth; left += dayWidth - addToWidth;
_separator1->resizeToNaturalWidth(width); _separator1->resizeToNaturalWidth(width);
_separator1->move(left, top); _separator1->move(left, top);
left += _separator1->width(); left += _separator1->width();
_month->setGeometry(left, top, monthWidth, _month->height()); _month->setGeometry(left, top, monthWidth, _month->height());
left += monthWidth - st::lineWidth; left += monthWidth - addToWidth;
_separator2->resizeToNaturalWidth(width); _separator2->resizeToNaturalWidth(width);
_separator2->move(left, top); _separator2->move(left, top);
left += _separator2->width(); left += _separator2->width();
@ -829,8 +840,9 @@ void DateRow::startBorderAnimation() {
GenderRow::GenderRow( GenderRow::GenderRow(
QWidget *parent, QWidget *parent,
const QString &label, const QString &label,
int maxLabelWidth,
const QString &value) const QString &value)
: PanelDetailsRow(parent, label) : PanelDetailsRow(parent, label, maxLabelWidth)
, _group(StringToGender(value).has_value() , _group(StringToGender(value).has_value()
? std::make_shared<Ui::RadioenumGroup<Gender>>(*StringToGender(value)) ? std::make_shared<Ui::RadioenumGroup<Gender>>(*StringToGender(value))
: std::make_shared<Ui::RadioenumGroup<Gender>>()) : std::make_shared<Ui::RadioenumGroup<Gender>>())
@ -938,8 +950,10 @@ void GenderRow::errorAnimationCallback() {
PanelDetailsRow::PanelDetailsRow( PanelDetailsRow::PanelDetailsRow(
QWidget *parent, QWidget *parent,
const QString &label) const QString &label,
: _label(label) { int maxLabelWidth)
: _label(label)
, _maxLabelWidth(maxLabelWidth) {
} }
object_ptr<PanelDetailsRow> PanelDetailsRow::Create( object_ptr<PanelDetailsRow> PanelDetailsRow::Create(
@ -947,6 +961,7 @@ object_ptr<PanelDetailsRow> PanelDetailsRow::Create(
Type type, Type type,
not_null<PanelController*> controller, not_null<PanelController*> controller,
const QString &label, const QString &label,
int maxLabelWidth,
const QString &value, const QString &value,
const QString &error, const QString &error,
int limit) { int limit) {
@ -956,20 +971,35 @@ object_ptr<PanelDetailsRow> PanelDetailsRow::Create(
return object_ptr<AbstractTextRow<Ui::InputField>>( return object_ptr<AbstractTextRow<Ui::InputField>>(
parent, parent,
label, label,
maxLabelWidth,
value, value,
limit); limit);
case Type::Postcode: case Type::Postcode:
return object_ptr<AbstractTextRow<PostcodeInput>>( return object_ptr<AbstractTextRow<PostcodeInput>>(
parent, parent,
label, label,
maxLabelWidth,
value, value,
limit); limit);
case Type::Country: case Type::Country:
return object_ptr<CountryRow>(parent, controller, label, value); return object_ptr<CountryRow>(
parent,
controller,
label,
maxLabelWidth,
value);
case Type::Gender: case Type::Gender:
return object_ptr<GenderRow>(parent, label, value); return object_ptr<GenderRow>(
parent,
label,
maxLabelWidth,
value);
case Type::Date: case Type::Date:
return object_ptr<DateRow>(parent, label, value); return object_ptr<DateRow>(
parent,
label,
maxLabelWidth,
value);
default: default:
Unexpected("Type in PanelDetailsRow::Create."); Unexpected("Type in PanelDetailsRow::Create.");
} }
@ -981,13 +1011,19 @@ object_ptr<PanelDetailsRow> PanelDetailsRow::Create(
return result; return result;
} }
int PanelDetailsRow::LabelWidth(const QString &label) {
return st::semiboldFont->width(label);
}
bool PanelDetailsRow::setFocusFast() { bool PanelDetailsRow::setFocusFast() {
return false; return false;
} }
int PanelDetailsRow::resizeGetHeight(int newWidth) { int PanelDetailsRow::resizeGetHeight(int newWidth) {
const auto padding = st::passportDetailsPadding; const auto padding = st::passportDetailsPadding;
const auto inputLeft = padding.left() + st::passportDetailsFieldLeft; const auto inputLeft = padding.left() + std::max(
st::passportDetailsFieldLeft,
_maxLabelWidth + st::passportDetailsFieldSkipMin);
const auto inputTop = st::passportDetailsFieldTop; const auto inputTop = st::passportDetailsFieldTop;
const auto inputRight = padding.right(); const auto inputRight = padding.right();
const auto inputWidth = std::max(newWidth - inputLeft - inputRight, 0); const auto inputWidth = std::max(newWidth - inputLeft - inputRight, 0);
@ -997,6 +1033,7 @@ int PanelDetailsRow::resizeGetHeight(int newWidth) {
+ (_error ? _error->height() : 0) + (_error ? _error->height() : 0)
+ padding.bottom(); + padding.bottom();
if (_error) { if (_error) {
_error->resizeToWidth(inputWidth);
_error->moveToLeft(inputLeft, result - _error->height()); _error->moveToLeft(inputLeft, result - _error->height());
} }
return result; return result;

View File

@ -37,16 +37,19 @@ public:
PanelDetailsRow( PanelDetailsRow(
QWidget *parent, QWidget *parent,
const QString &label); const QString &label,
int maxLabelWidth);
static object_ptr<PanelDetailsRow> Create( static object_ptr<PanelDetailsRow> Create(
QWidget *parent, QWidget *parent,
Type type, Type type,
not_null<PanelController*> controller, not_null<PanelController*> controller,
const QString &label, const QString &label,
int maxLabelWidth,
const QString &value, const QString &value,
const QString &error, const QString &error,
int limit = 0); int limit = 0);
static int LabelWidth(const QString &label);
virtual bool setFocusFast(); virtual bool setFocusFast();
virtual rpl::producer<QString> value() const = 0; virtual rpl::producer<QString> value() const = 0;
@ -69,6 +72,7 @@ private:
void startErrorAnimation(bool shown); void startErrorAnimation(bool shown);
QString _label; QString _label;
int _maxLabelWidth = 0;
object_ptr<Ui::SlideWrap<Ui::FlatLabel>> _error = { nullptr }; object_ptr<Ui::SlideWrap<Ui::FlatLabel>> _error = { nullptr };
bool _errorShown = false; bool _errorShown = false;
bool _errorHideSubscription = false; bool _errorHideSubscription = false;

View File

@ -326,24 +326,42 @@ not_null<Ui::RpWidget*> PanelEditDocument::setupContent(
return ValueField(); return ValueField();
}; };
for (auto i = 0, count = int(_scheme.rows.size()); i != count; ++i) { const auto enumerateRows = [&](auto &&callback) {
const auto &row = _scheme.rows[i]; for (auto i = 0, count = int(_scheme.rows.size()); i != count; ++i) {
auto fields = (row.valueClass == Scheme::ValueClass::Fields) const auto &row = _scheme.rows[i];
? &data auto fields = (row.valueClass == Scheme::ValueClass::Fields)
: scanData; ? &data
if (!fields) { : scanData;
continue; if (!fields) {
continue;
}
callback(i, row, *fields);
} }
const auto current = valueOrEmpty(*fields, row.key); };
auto maxLabelWidth = 0;
enumerateRows([&](
int i,
const EditDocumentScheme::Row &row,
const ValueMap &fields) {
accumulate_max(
maxLabelWidth,
PanelDetailsRow::LabelWidth(row.label));
});
enumerateRows([&](
int i,
const EditDocumentScheme::Row &row,
const ValueMap &fields) {
const auto current = valueOrEmpty(fields, row.key);
_details.emplace(i, inner->add(PanelDetailsRow::Create( _details.emplace(i, inner->add(PanelDetailsRow::Create(
inner, inner,
row.inputType, row.inputType,
_controller, _controller,
row.label, row.label,
maxLabelWidth,
current.text, current.text,
current.error, current.error,
row.lengthLimit))); row.lengthLimit)));
} });
inner->add( inner->add(
object_ptr<Ui::FixedHeightWidget>(inner, st::passportDetailsSkip)); object_ptr<Ui::FixedHeightWidget>(inner, st::passportDetailsSkip));

View File

@ -326,7 +326,7 @@ void PanelForm::updateControlsGeometry() {
_topShadow->moveToLeft(0, 0); _topShadow->moveToLeft(0, 0);
_bottomShadow->resizeToWidth(width()); _bottomShadow->resizeToWidth(width());
_bottomShadow->moveToLeft(0, submitTop - st::lineWidth); _bottomShadow->moveToLeft(0, submitTop - st::lineWidth);
_submit->resizeToWidth(width()); _submit->setFullWidth(width());
_submit->moveToLeft(0, submitTop); _submit->moveToLeft(0, submitTop);
_scroll->updateBars(); _scroll->updateBars();

View File

@ -281,7 +281,9 @@ QString RoundButton::computeFullText() const {
void RoundButton::resizeToText() { void RoundButton::resizeToText() {
int innerWidth = contentWidth(); int innerWidth = contentWidth();
if (_fullWidthOverride < 0) { if (_fullWidthOverride > 0) {
resize(_fullWidthOverride, _st.height + _st.padding.top() + _st.padding.bottom());
} else if (_fullWidthOverride < 0) {
resize(innerWidth - _fullWidthOverride, _st.height + _st.padding.top() + _st.padding.bottom()); resize(innerWidth - _fullWidthOverride, _st.height + _st.padding.top() + _st.padding.bottom());
} else if (_st.width <= 0) { } else if (_st.width <= 0) {
resize(innerWidth - _st.width + _st.padding.left() + _st.padding.right(), _st.height + _st.padding.top() + _st.padding.bottom()); resize(innerWidth - _st.width + _st.padding.left() + _st.padding.right(), _st.height + _st.padding.top() + _st.padding.bottom());