mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Add custom host input that replaces commas with dots
This commit is contained in:
parent
4c2779bbaf
commit
8d5e356733
1 changed files with 46 additions and 4 deletions
|
@ -41,6 +41,48 @@ constexpr auto kSaveSettingsDelayedTimeout = crl::time(1000);
|
||||||
|
|
||||||
using ProxyData = MTP::ProxyData;
|
using ProxyData = MTP::ProxyData;
|
||||||
|
|
||||||
|
class HostInput : public Ui::MaskedInputField {
|
||||||
|
public:
|
||||||
|
HostInput(
|
||||||
|
QWidget *parent,
|
||||||
|
const style::InputField &st,
|
||||||
|
rpl::producer<QString> placeholder,
|
||||||
|
const QString &val);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void correctValue(
|
||||||
|
const QString &was,
|
||||||
|
int wasCursor,
|
||||||
|
QString &now,
|
||||||
|
int &nowCursor) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
HostInput::HostInput(
|
||||||
|
QWidget *parent,
|
||||||
|
const style::InputField &st,
|
||||||
|
rpl::producer<QString> placeholder,
|
||||||
|
const QString &val)
|
||||||
|
: MaskedInputField(parent, st, std::move(placeholder), val) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void HostInput::correctValue(
|
||||||
|
const QString &was,
|
||||||
|
int wasCursor,
|
||||||
|
QString &now,
|
||||||
|
int &nowCursor) {
|
||||||
|
QString newText;
|
||||||
|
int newCursor = nowCursor;
|
||||||
|
newText.reserve(now.size());
|
||||||
|
for (auto i = 0, l = now.size(); i < l; ++i) {
|
||||||
|
if (now[i] == ',') {
|
||||||
|
newText.append('.');
|
||||||
|
} else {
|
||||||
|
newText.append(now[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setCorrectedText(now, nowCursor, newText, newCursor);
|
||||||
|
}
|
||||||
|
|
||||||
class Base64UrlInput : public Ui::MaskedInputField {
|
class Base64UrlInput : public Ui::MaskedInputField {
|
||||||
public:
|
public:
|
||||||
Base64UrlInput(
|
Base64UrlInput(
|
||||||
|
@ -209,7 +251,7 @@ private:
|
||||||
std::shared_ptr<Ui::RadioenumGroup<Type>> _type;
|
std::shared_ptr<Ui::RadioenumGroup<Type>> _type;
|
||||||
|
|
||||||
QPointer<Ui::SlideWrap<>> _aboutSponsored;
|
QPointer<Ui::SlideWrap<>> _aboutSponsored;
|
||||||
QPointer<Ui::InputField> _host;
|
QPointer<HostInput> _host;
|
||||||
QPointer<Ui::PortInput> _port;
|
QPointer<Ui::PortInput> _port;
|
||||||
QPointer<Ui::InputField> _user;
|
QPointer<Ui::InputField> _user;
|
||||||
QPointer<Ui::PasswordInput> _password;
|
QPointer<Ui::PasswordInput> _password;
|
||||||
|
@ -767,12 +809,12 @@ ProxyBox::ProxyBox(
|
||||||
void ProxyBox::prepare() {
|
void ProxyBox::prepare() {
|
||||||
setTitle(tr::lng_proxy_edit());
|
setTitle(tr::lng_proxy_edit());
|
||||||
|
|
||||||
connect(_host.data(), &Ui::InputField::changed, [=] {
|
connect(_host.data(), &HostInput::changed, [=] {
|
||||||
Ui::PostponeCall(_host, [=] {
|
Ui::PostponeCall(_host, [=] {
|
||||||
const auto host = _host->getLastText().trimmed();
|
const auto host = _host->getLastText().trimmed();
|
||||||
static const auto mask = u"^\\d+\\.\\d+\\.\\d+\\.\\d+:(\\d*)$"_q;
|
static const auto mask = u"^\\d+\\.\\d+\\.\\d+\\.\\d+:(\\d*)$"_q;
|
||||||
const auto match = QRegularExpression(mask).match(host);
|
const auto match = QRegularExpression(mask).match(host);
|
||||||
if (_host->textCursor().position() == host.size()
|
if (_host->cursorPosition() == host.size()
|
||||||
&& match.hasMatch()) {
|
&& match.hasMatch()) {
|
||||||
const auto port = match.captured(1);
|
const auto port = match.captured(1);
|
||||||
_port->setText(port);
|
_port->setText(port);
|
||||||
|
@ -881,7 +923,7 @@ void ProxyBox::setupSocketAddress(const ProxyData &data) {
|
||||||
_content,
|
_content,
|
||||||
st::connectionHostInputField.heightMin),
|
st::connectionHostInputField.heightMin),
|
||||||
st::proxyEditInputPadding);
|
st::proxyEditInputPadding);
|
||||||
_host = Ui::CreateChild<Ui::InputField>(
|
_host = Ui::CreateChild<HostInput>(
|
||||||
address,
|
address,
|
||||||
st::connectionHostInputField,
|
st::connectionHostInputField,
|
||||||
tr::lng_connection_host_ph(),
|
tr::lng_connection_host_ph(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue