2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Create and edit proxy box.

This commit is contained in:
John Preston
2018-04-28 19:58:22 +04:00
parent a7c77682d7
commit 9935a36c3d
7 changed files with 433 additions and 23 deletions

View File

@@ -3944,6 +3944,33 @@ void PortInput::correctValue(
setCorrectedText(now, nowCursor, newText, newPos);
}
HexInput::HexInput(QWidget *parent, const style::InputField &st, base::lambda<QString()> placeholderFactory, const QString &val) : MaskedInputField(parent, st, std::move(placeholderFactory), val) {
if (!QRegularExpression("^[a-fA-F0-9]+$").match(val).hasMatch()) {
setText(QString());
}
}
void HexInput::correctValue(
const QString &was,
int wasCursor,
QString &now,
int &nowCursor) {
QString newText;
newText.reserve(now.size());
auto newPos = nowCursor;
for (auto i = 0, l = now.size(); i < l; ++i) {
const auto ch = now[i];
if ((ch >= '0' && ch <= '9')
|| (ch >= 'a' && ch <= 'f')
|| (ch >= 'A' && ch <= 'F')) {
newText.append(ch);
} else if (i < nowCursor) {
--newPos;
}
}
setCorrectedText(now, nowCursor, newText, newPos);
}
UsernameInput::UsernameInput(QWidget *parent, const style::InputField &st, base::lambda<QString()> placeholderFactory, const QString &val, bool isLink) : MaskedInputField(parent, st, std::move(placeholderFactory), val) {
setLinkPlaceholder(isLink ? Messenger::Instance().createInternalLink(QString()) : QString());
}

View File

@@ -906,6 +906,19 @@ protected:
};
class HexInput : public MaskedInputField {
public:
HexInput(QWidget *parent, const style::InputField &st, base::lambda<QString()> placeholderFactory, const QString &val);
protected:
void correctValue(
const QString &was,
int wasCursor,
QString &now,
int &nowCursor) override;
};
class UsernameInput : public MaskedInputField {
public:
UsernameInput(QWidget *parent, const style::InputField &st, base::lambda<QString()> placeholderFactory, const QString &val, bool isLink);

View File

@@ -164,8 +164,8 @@ void VerticalLayout::removeChild(RpWidget *child) {
auto prev = it - 1;
return prev->widget->bottomNoMargins() + prev->margin.bottom();
}() - margins.top();
for (auto next = it + 1; it != end; ++it) {
auto &row = *it;
for (auto next = it + 1; next != end; ++next) {
auto &row = *next;
auto margin = row.margin;
auto widget = row.widget.data();
widget->moveToLeft(
@@ -175,6 +175,7 @@ void VerticalLayout::removeChild(RpWidget *child) {
+ widget->heightNoMargins()
+ margin.bottom();
}
it->widget = nullptr;
_rows.erase(it);
resize(width(), margins.top() + top + margins.bottom());