Esempio n. 1
0
void FlatTextarea::updatePlaceholder() {
	bool vis = (getLastText().size() <= _phAfter);
	if (vis == _phVisible) return;

	a_phLeft.start(vis ? 0 : _st.phShift);
	a_phAlpha.start(vis ? 1 : 0);
	_a_appearance.start();

	_phVisible = vis;
}
Esempio n. 2
0
void FlatTextarea::updatePlaceholder() {
    bool vis = getLastText().isEmpty();
    if (vis == _phVisible) return;

    a_phLeft.start(vis ? 0 : _st.phShift);
    a_phAlpha.start(vis ? 1 : 0);
    anim::start(this);

    _phVisible = vis;
}
Esempio n. 3
0
void SentCodeField::fix() {
	if (_fixing) return;

	_fixing = true;
	auto newText = QString();
	auto now = getLastText();
	auto oldPos = textCursor().position();
	auto newPos = -1;
	auto oldLen = now.size();
	auto digitCount = 0;
	for_const (auto ch, now) {
		if (ch.isDigit()) {
			++digitCount;
		}
	}

	if (_autoSubmitLength > 0 && digitCount > _autoSubmitLength) {
		digitCount = _autoSubmitLength;
	}
	auto strict = (_autoSubmitLength > 0 && digitCount == _autoSubmitLength);

	newText.reserve(oldLen);
	int i = 0;
	for_const (auto ch, now) {
		if (i++ == oldPos) {
			newPos = newText.length();
		}
		if (ch.isDigit()) {
			if (!digitCount--) {
				break;
			}
			newText += ch;
			if (strict && !digitCount) {
				break;
			}
		}
	}
	if (newPos < 0) {
		newPos = newText.length();
	}
	if (newText != now) {
		now = newText;
		setText(now);
		setCursorPosition(newPos);
	}
	_fixing = false;

	if (_changedCallback) {
		_changedCallback();
	}
	if (strict && _submitCallback) {
		_submitCallback();
	}
}
Esempio n. 4
0
void FlatTextarea::setPlaceholder(const QString &ph, int32 afterSymbols) {
	_ph = ph;
	if (_phAfter != afterSymbols) {
		_phAfter = afterSymbols;
		updatePlaceholder();
	}
	_phelided = _st.font->elided(_ph, width() - _st.textMrg.left() - _st.textMrg.right() - _st.phPos.x() - 1 - (_phAfter ? _st.font->width(getLastText().mid(0, _phAfter)) : 0));
	if (_phVisible) update();
}
Esempio n. 5
0
void FlatTextarea::paintEvent(QPaintEvent *e) {
	QPainter p(viewport());
	QRect r(rect().intersected(e->rect()));
	p.fillRect(r, _st.bgColor->b);
	bool phDraw = _phVisible;
	if (_a_appearance.animating()) {
		p.setOpacity(a_phAlpha.current());
		phDraw = true;
	}
	if (phDraw) {
		p.save();
		p.setClipRect(r);
		p.setFont(_st.font);
		p.setPen(a_phColor.current());
		if (_st.phAlign == style::al_topleft && _phAfter > 0) {
			p.drawText(_st.textMrg.left() - _fakeMargin + a_phLeft.current() + _st.font->width(getLastText().mid(0, _phAfter)), _st.textMrg.top() - _fakeMargin - st::lineWidth + _st.font->ascent, _ph);
		} else {
			QRect phRect(_st.textMrg.left() - _fakeMargin + _st.phPos.x() + a_phLeft.current(), _st.textMrg.top() - _fakeMargin + _st.phPos.y(), width() - _st.textMrg.left() - _st.textMrg.right(), height() - _st.textMrg.top() - _st.textMrg.bottom());
			p.drawText(phRect, _ph, QTextOption(_st.phAlign));
		}
		p.restore();
		p.setOpacity(1);
	}
	QTextEdit::paintEvent(e);
}