void FlatTextarea::onDocumentContentsChanged() { if (_replacingEmojis) return; if (!_insertions.isEmpty()) { if (document()->availableRedoSteps() > 0) { _insertions.clear(); } else { _replacingEmojis = true; do { Insertion i = _insertions.front(); _insertions.pop_front(); if (i.second > 0) { processDocumentContentsChange(i.first, i.second); } } while (!_insertions.isEmpty()); _replacingEmojis = false; } } QString curText(getText()); if (_oldtext != curText) { _oldtext = curText; emit changed(); } updatePlaceholder(); if (App::wnd()) App::wnd()->updateGlobalMenu(); }
void FlatInput::onTextEdited() { QString was(_oldtext); correctValue(_kev, was); _oldtext = text(); if (was != _oldtext) emit changed(); updatePlaceholder(); }
void PhoneInput::addedToNumber(const QString &added) { setFocus(); QString was(text()); setText(added + text()); setCursorPosition(added.length()); correctValue(0, was); updatePlaceholder(); }
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(); }
void PortInput::correctValue(QKeyEvent *e, const QString &was) { QString oldText(text()), newText(oldText); newText.replace(QRegularExpression(qsl("[^\\d]")), QString()); if (!newText.toInt()) { newText = QString(); } else if (newText.toInt() > 65535) { newText = was; } if (newText != oldText) { setText(newText); updatePlaceholder(); } }
void FlatTextarea::onDocumentContentsChanged() { if (_correcting) return; QString curText(getText()); _correcting = true; correctValue(_oldtext, curText); _correcting = false; if (_oldtext != curText) { _oldtext = curText; emit changed(); checkContentHeight(); } updatePlaceholder(); if (App::wnd()) App::wnd()->updateGlobalMenu(); }
void FlatInput::keyPressEvent(QKeyEvent *e) { QString was(text()); _kev = e; if (_customUpDown && (e->key() == Qt::Key_Up || e->key() == Qt::Key_Down)) { e->ignore(); } else { QLineEdit::keyPressEvent(e); } if (was == text()) { // call correct manually correctValue(_kev, was); _oldtext = text(); if (was != _oldtext) emit changed(); updatePlaceholder(); } if (e->key() == Qt::Key_Escape) { emit cancelled(); } else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { emit accepted(); } _kev = 0; }
void PhoneInput::onChooseCode(const QString &code) { pattern = phoneNumberParse(code); if (!pattern.isEmpty() && pattern.at(0) == code.size()) { pattern.pop_front(); } else { pattern.clear(); } if (pattern.isEmpty()) { setPlaceholder(lang(lng_phone_ph)); } else { QString ph; ph.reserve(20); for (int i = 0, l = pattern.size(); i < l; ++i) { ph.append(' '); ph.append(QString(QChar(0x2212)).repeated(pattern.at(i))); } setPlaceholder(ph); } correctValue(0, text()); setPlaceholderFast(!pattern.isEmpty()); updatePlaceholder(); }