Make a generic NumberInput from PortInput.

This commit is contained in:
John Preston 2021-01-19 10:21:27 +04:00
parent 912f0b48a6
commit a5fb993721
2 changed files with 18 additions and 8 deletions

View file

@ -4010,18 +4010,20 @@ PasswordInput::PasswordInput(
setEchoMode(QLineEdit::Password); setEchoMode(QLineEdit::Password);
} }
PortInput::PortInput( NumberInput::NumberInput(
QWidget *parent, QWidget *parent,
const style::InputField &st, const style::InputField &st,
rpl::producer<QString> placeholder, rpl::producer<QString> placeholder,
const QString &val) const QString &value,
: MaskedInputField(parent, st, std::move(placeholder), val) { int limit)
if (!val.toInt() || val.toInt() > 65535) { : MaskedInputField(parent, st, std::move(placeholder), value)
, _limit(limit) {
if (!value.toInt() || (limit > 0 && value.toInt() > limit)) {
setText(QString()); setText(QString());
} }
} }
void PortInput::correctValue( void NumberInput::correctValue(
const QString &was, const QString &was,
int wasCursor, int wasCursor,
QString &now, QString &now,
@ -4039,7 +4041,7 @@ void PortInput::correctValue(
if (!newText.toInt()) { if (!newText.toInt()) {
newText = QString(); newText = QString();
newPos = 0; newPos = 0;
} else if (newText.toInt() > 65535) { } else if (_limit > 0 && newText.toInt() > _limit) {
newText = was; newText = was;
newPos = wasCursor; newPos = wasCursor;
} }

View file

@ -695,9 +695,14 @@ public:
}; };
class PortInput : public MaskedInputField { class NumberInput : public MaskedInputField {
public: public:
PortInput(QWidget *parent, const style::InputField &st, rpl::producer<QString> placeholder, const QString &val); NumberInput(
QWidget *parent,
const style::InputField &st,
rpl::producer<QString> placeholder,
const QString &value,
int limit);
protected: protected:
void correctValue( void correctValue(
@ -706,6 +711,9 @@ protected:
QString &now, QString &now,
int &nowCursor) override; int &nowCursor) override;
private:
int _limit = 0;
}; };
class HexInput : public MaskedInputField { class HexInput : public MaskedInputField {