Exemple #1
0
void UsernameBox::showAll() {
	_username.show();
	_save.show();
	_cancel.show();
	updateLinkText();

	AbstractBox::showAll();
}
Exemple #2
0
void UsernameBox::prepare() {
	_goodText = App::self()->username.isEmpty() ? QString() : lang(lng_username_available);

	setTitle(langFactory(lng_username_title));

	addButton(langFactory(lng_settings_save), [this] { onSave(); });
	addButton(langFactory(lng_cancel), [this] { closeBox(); });

	connect(_username, SIGNAL(changed()), this, SLOT(onChanged()));
	connect(_username, SIGNAL(submitted(bool)), this, SLOT(onSave()));
	connect(_link, SIGNAL(clicked()), this, SLOT(onLinkClick()));

	_about.setRichText(st::usernameTextStyle, lang(lng_username_about));
	setDimensions(st::boxWidth, st::usernamePadding.top() + _username->height() + st::usernameSkip + _about.countHeight(st::boxWidth - st::usernamePadding.left()) + 3 * st::usernameTextStyle.lineHeight + st::usernamePadding.bottom());

	_checkTimer->setSingleShot(true);
	connect(_checkTimer, SIGNAL(timeout()), this, SLOT(onCheck()));

	updateLinkText();
}
void UsernameBox::prepare() {
	_goodText = App::self()->username.isEmpty() ? QString() : lang(lng_username_available);

	setTitle(langFactory(lng_username_title));

	addButton(langFactory(lng_settings_save), [=] { save(); });
	addButton(langFactory(lng_cancel), [=] { closeBox(); });

	connect(_username, &Ui::MaskedInputField::changed, [=] { changed(); });
	connect(_username, &Ui::MaskedInputField::submitted, [=] { save(); });
	_link->addClickHandler([=] { linkClick(); });

	_about.setRichText(st::usernameTextStyle, lang(lng_username_about));
	setDimensions(st::boxWidth, st::usernamePadding.top() + _username->height() + st::usernameSkip + _about.countHeight(st::boxWidth - st::usernamePadding.left()) + 3 * st::usernameTextStyle.lineHeight + st::usernamePadding.bottom());

	_checkTimer->setSingleShot(true);
	connect(_checkTimer, &QTimer::timeout, [=] { check(); });

	updateLinkText();
}
Exemple #4
0
void UsernameBox::onChanged() {
	updateLinkText();
	QString name = getName();
	if (name.isEmpty()) {
		if (!_errorText.isEmpty() || !_goodText.isEmpty()) {
			_copiedTextLink = _errorText = _goodText = QString();
			update();
		}
		_checkTimer.stop();
	} else {
		int32 i, len = name.size();
		for (int32 i = 0; i < len; ++i) {
			QChar ch = name.at(i);
			if ((ch < 'A' || ch > 'Z') && (ch < 'a' || ch > 'z') && (ch < '0' || ch > '9') && ch != '_' && (ch != '@' || i > 0)) {
				if (_errorText != lang(lng_username_bad_symbols) || !_copiedTextLink.isEmpty()) {
					_copiedTextLink = QString();
					_errorText = lang(lng_username_bad_symbols);
					update();
				}
				_checkTimer.stop();
				return;
			}
		}
		if (name.size() < MinUsernameLength) {
			if (_errorText != lang(lng_username_too_short) || !_copiedTextLink.isEmpty()) {
				_copiedTextLink = QString();
				_errorText = lang(lng_username_too_short);
				update();
			}
			_checkTimer.stop();
		} else {
			if (!_errorText.isEmpty() || !_goodText.isEmpty() || !_copiedTextLink.isEmpty()) {
				_copiedTextLink = _errorText = _goodText = QString();
				update();
			}
			_checkTimer.start(UsernameCheckTimeout);
		}
	}
}