Exemplo n.º 1
0
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();
    }
}
Exemplo n.º 2
0
void RangeImpl::updateSplitInfo(TextImpl* oldNode, TextImpl* startNode, unsigned int offset)
{
    if (startNode == null) return;

    DOM_Text oldText(oldNode);
    DOM_Text newText(startNode);

    if (fStartContainer == oldText && fStartOffset > offset) {
        fStartOffset = fStartOffset - offset;
        fStartContainer = newText;
    }

    if (fEndContainer == oldText && fEndOffset > offset) {
        fEndContainer = newText;
        fEndOffset = fEndOffset - offset;
    }
}
Exemplo n.º 3
0
void CountryCodeInput::correctValue(QKeyEvent *e, const QString &was) {
	QString oldText(text()), newText, addToNumber;
	int oldPos(cursorPosition()), newPos(-1), oldLen(oldText.length()), start = 0, digits = 5;
	newText.reserve(oldLen + 1);
	newText += '+';
	if (oldLen && oldText[0] == '+') {
		++start;
	}
	for (int i = start; i < oldLen; ++i) {
		QChar ch(oldText[i]);
		if (ch.isDigit()) {
			if (!digits || !--digits) {
				addToNumber += ch;
			} else {
				newText += ch;
			}
		}
		if (i == oldPos) {
			newPos = newText.length();
		}
	}
	if (!addToNumber.isEmpty()) {
		QString validCode = findValidCode(newText.mid(1));
		addToNumber = newText.mid(1 + validCode.length()) + addToNumber;
		newText = '+' + validCode;
	}
	if (newPos < 0 || newPos > newText.length()) {
		newPos = newText.length();
	}
	if (newText != oldText) {
		setText(newText);
		if (newPos != oldPos) {
			setCursorPosition(newPos);
		}
	}
	if (!_nosignal && was != newText) {
		emit codeChanged(newText.mid(1));
	}
	if (!addToNumber.isEmpty()) {
		emit addedToNumber(addToNumber);
	}
}
Exemplo n.º 4
0
void QLineEdit::setText( const char *text )
{
    QString oldText( tbuf );
    oldText.detach();
    tbuf = text ? text : "";
    if ( (int)tbuf.length() > maxLen ) {
	tbuf.resize( maxLen+1 );
	tbuf[maxLen] = '\0';
    }
    offset    = 0;
    cursorPos = 0;
    markAnchor = 0;
    markDrag = 0;
    end( FALSE );
    if ( validator() )
	(void)validator()->validate( tbuf, cursorPos );
    d->pmDirty = TRUE;
    repaint( FALSE );
    if ( oldText != tbuf )
	emit textChanged( tbuf );
}
Exemplo n.º 5
0
void CodeInput::correctValue(QKeyEvent *e, const QString &was) {
	QString oldText(text()), newText;
	int oldPos(cursorPosition()), newPos(-1), oldLen(oldText.length()), digitCount = 0;
	for (int i = 0; i < oldLen; ++i) {
		if (oldText[i].isDigit()) {
			++digitCount;
		}
	}
	if (digitCount > 5) digitCount = 5;
	bool strict = (digitCount == 5);

	newText.reserve(oldLen);
	for (int i = 0; i < oldLen; ++i) {
		QChar ch(oldText[i]);
		if (ch.isDigit()) {
			if (!digitCount--) {
				break;
			}
			newText += ch;
			if (strict && !digitCount) {
				break;
			}
		}
		if (i == oldPos) {
			newPos = newText.length();
		}
	}
	if (newPos < 0) {
		newPos = newText.length();
	}
	if (newText != oldText) {
		setText(newText);
		if (newPos != oldPos) {
			setCursorPosition(newPos);
		}
	}

	if (strict) emit codeEntered();
}
Exemplo n.º 6
0
void UsernameInput::correctValue(QKeyEvent *e, const QString &was) {
	QString oldText(text()), newText;
	int32 newPos = cursorPosition(), from, len = oldText.size();
	for (from = 0; from < len; ++from) {
		if (!oldText.at(from).isSpace()) {
			break;
		}
		if (newPos > 0) --newPos;
	}
	len -= from;
	if (len > MaxUsernameLength) len = MaxUsernameLength + (oldText.at(from) == '@' ? 1 : 0);
	for (int32 to = from + len; to > from;) {
		--to;
		if (!oldText.at(to).isSpace()) {
			break;
		}
		--len;
	}
	newText = oldText.mid(from, len);
	if (newText != oldText) {
		setText(newText);
		setCursorPosition(newPos);
	}
}
Exemplo n.º 7
0
void PhoneInput::correctValue(QKeyEvent *e, const QString &was) {
    if (e && e->key() == Qt::Key_Backspace && !was.length()) {
        emit voidBackspace(e);
        return;
    }
    QString oldText(text()), newText;
    int oldPos(cursorPosition()), newPos(-1), oldLen(oldText.length()), digitCount = 0;
    for (int i = 0; i < oldLen; ++i) {
        if (oldText[i].isDigit()) {
            ++digitCount;
        }
    }
    if (digitCount > MaxPhoneTailLength) digitCount = MaxPhoneTailLength;

    bool inPart = !pattern.isEmpty();
    int curPart = -1, leftInPart = 0;
    newText.reserve(oldLen);
    for (int i = 0; i < oldLen; ++i) {
        if (i == oldPos && newPos < 0) {
            newPos = newText.length();
        }

        QChar ch(oldText[i]);
        if (ch.isDigit()) {
            if (!digitCount--) {
                break;
            }
            if (inPart) {
                if (leftInPart) {
                    --leftInPart;
                } else {
                    newText += ' ';
                    ++curPart;
                    inPart = curPart < pattern.size();
                    leftInPart = inPart ? (pattern.at(curPart) - 1) : 0;

                    ++oldPos;
                }
            }
            newText += ch;
        } else if (ch == ' ' || ch == '-' || ch == '(' || ch == ')') {
            if (inPart) {
                if (leftInPart) {
                } else {
                    newText += ch;
                    ++curPart;
                    inPart = curPart < pattern.size();
                    leftInPart = inPart ? pattern.at(curPart) : 0;
                }
            } else {
                newText += ch;
            }
        }
    }
    int32 newlen = newText.size();
    while (newlen > 0 && newText.at(newlen - 1).isSpace()) {
        --newlen;
    }
    if (newlen < newText.size()) newText = newText.mid(0, newlen);
    if (newPos < 0) {
        newPos = newText.length();
    }
    if (newText != oldText) {
        setText(newText);
        setCursorPosition(newPos);
    }
}