本文整理汇总了C++中QChar类的典型用法代码示例。如果您正苦于以下问题:C++ QChar类的具体用法?C++ QChar怎么用?C++ QChar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QChar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lex
int QuazaaCssScanner_Generated::lex()
{
lexemStart = pos;
lexemLength = 0;
int lastAcceptingPos = -1;
int token = -1;
QChar ch;
// initial state
ch = next();
if(ch.unicode() >= 9 && ch.unicode() <= 10)
{
goto state_1;
}
if(ch.unicode() >= 12 && ch.unicode() <= 13)
{
goto state_1;
}
if(ch.unicode() == 32)
{
goto state_1;
}
if(ch.unicode() == 33)
{
token = QuazaaCss::EXCLAMATION_SYM;
goto found;
}
if(ch.unicode() == 34)
{
goto state_3;
}
if(ch.unicode() == 35)
{
goto state_4;
}
if(ch.unicode() == 39)
{
goto state_5;
}
if(ch.unicode() == 40)
{
token = QuazaaCss::LPAREN;
goto found;
}
if(ch.unicode() == 41)
{
token = QuazaaCss::RPAREN;
goto found;
}
if(ch.unicode() == 42)
{
token = QuazaaCss::STAR;
goto found;
}
if(ch.unicode() == 43)
{
goto state_9;
}
if(ch.unicode() == 44)
{
goto state_10;
}
if(ch.unicode() == 45)
{
goto state_11;
}
if(ch.unicode() == 46)
{
goto state_12;
}
if(ch.unicode() == 47)
{
goto state_13;
}
if(ch.unicode() >= 48 && ch.unicode() <= 57)
{
goto state_14;
}
if(ch.unicode() == 58)
{
token = QuazaaCss::COLON;
goto found;
}
if(ch.unicode() == 59)
{
token = QuazaaCss::SEMICOLON;
goto found;
}
if(ch.unicode() == 60)
{
goto state_17;
}
if(ch.unicode() == 61)
{
token = QuazaaCss::EQUAL;
goto found;
}
if(ch.unicode() == 62)
{
goto state_19;
//.........这里部分代码省略.........
示例2: replaceTextMacros
QString Page::replaceTextMacros(const QString& s) const
{
QString d;
for (int i = 0, n = s.size(); i < n; ++i) {
QChar c = s[i];
if (c == '$' && (i < (n-1))) {
QChar c = s[i+1];
switch(c.toLatin1()) {
case 'p': // not on first page 1
if (_no) // FALLTHROUGH
case 'N': // on page 1 only if there are multiple pages
if ( (score()->npages() + score()->pageNumberOffset()) > 1 ) // FALLTHROUGH
case 'P': // on all pages
{
int no = _no + 1 + score()->pageNumberOffset();
if (no > 0 )
d += QString("%1").arg(no);
}
break;
case 'n':
d += QString("%1").arg(score()->npages() + score()->pageNumberOffset());
break;
case 'f':
d += masterScore()->fileInfo()->completeBaseName().toHtmlEscaped();
break;
case 'F':
d += masterScore()->fileInfo()->absoluteFilePath().toHtmlEscaped();
break;
case 'd':
d += QDate::currentDate().toString(Qt::DefaultLocaleShortDate);
break;
case 'D':
{
QString creationDate = score()->metaTag("creationDate");
if (creationDate.isNull())
d += masterScore()->fileInfo()->created().date().toString(Qt::DefaultLocaleShortDate);
else
d += QDate::fromString(creationDate, Qt::ISODate).toString(Qt::DefaultLocaleShortDate);
}
break;
case 'm':
if ( score()->dirty() )
d += QTime::currentTime().toString(Qt::DefaultLocaleShortDate);
else
d += masterScore()->fileInfo()->lastModified().time().toString(Qt::DefaultLocaleShortDate);
break;
case 'M':
if ( score()->dirty() )
d += QDate::currentDate().toString(Qt::DefaultLocaleShortDate);
else
d += masterScore()->fileInfo()->lastModified().date().toString(Qt::DefaultLocaleShortDate);
break;
case 'C': // only on first page
if (!_no) // FALLTHROUGH
case 'c':
d += score()->metaTag("copyright").toHtmlEscaped();
break;
case '$':
d += '$';
break;
case ':':
{
QString tag;
int k = i+2;
for (; k < n; ++k) {
if (s[k].toLatin1() == ':')
break;
tag += s[k];
}
if (k != n) { // found ':' ?
d += score()->metaTag(tag).toHtmlEscaped();
i = k-1;
}
}
break;
default:
d += '$';
d += c;
break;
}
++i;
}
else
d += c;
}
return d;
}
示例3: qIsAlnum
static bool qIsAlnum(QChar ch)
{
uint u = uint(ch.unicode());
// matches [a-zA-Z0-9_]
return u - 'a' < 26 || u - 'A' < 26 || u - '0' < 10 || u == '_';
}
示例4: isContinuationChar
bool ProFileCompletionAssistProvider::isContinuationChar(const QChar &c) const
{
return c.isLetterOrNumber() || c == QLatin1Char('_');
}
示例5: stream
bool QDeclarativeDirParser::parse()
{
if (_isParsed)
return true;
_isParsed = true;
_errors.clear();
_plugins.clear();
_components.clear();
QTextStream stream(&_source);
int lineNumber = 0;
forever {
++lineNumber;
const QString line = stream.readLine();
if (line.isNull())
break;
QString sections[3];
int sectionCount = 0;
int index = 0;
const int length = line.length();
while (index != length) {
const QChar ch = line.at(index);
if (ch.isSpace()) {
do { ++index; }
while (index != length && line.at(index).isSpace());
} else if (ch == QLatin1Char('#')) {
// recognized a comment
break;
} else {
const int start = index;
do { ++index; }
while (index != length && !line.at(index).isSpace());
const QString lexeme = line.mid(start, index - start);
if (sectionCount >= 3) {
reportError(lineNumber, start, QLatin1String("unexpected token"));
} else {
sections[sectionCount++] = lexeme;
}
}
}
if (sectionCount == 0) {
continue; // no sections, no party.
} else if (sections[0] == QLatin1String("plugin")) {
if (sectionCount < 2) {
reportError(lineNumber, -1,
QString::fromUtf8("plugin directive requires 2 arguments, but %1 were provided").arg(sectionCount + 1));
continue;
}
const Plugin entry(sections[1], sections[2]);
_plugins.append(entry);
} else if (sections[0] == QLatin1String("internal")) {
if (sectionCount != 3) {
reportError(lineNumber, -1,
QString::fromUtf8("internal types require 2 arguments, but %1 were provided").arg(sectionCount + 1));
continue;
}
Component entry(sections[1], sections[2], -1, -1);
entry.internal = true;
_components.append(entry);
} else if (sectionCount == 2) {
// No version specified (should only be used for relative qmldir files)
const Component entry(sections[0], sections[1], -1, -1);
_components.append(entry);
} else if (sectionCount == 3) {
const QString &version = sections[1];
const int dotIndex = version.indexOf(QLatin1Char('.'));
if (dotIndex == -1) {
reportError(lineNumber, -1, QLatin1String("expected '.'"));
} else if (version.indexOf(QLatin1Char('.'), dotIndex + 1) != -1) {
reportError(lineNumber, -1, QLatin1String("unexpected '.'"));
} else {
bool validVersionNumber = false;
const int majorVersion = version.left(dotIndex).toInt(&validVersionNumber);
if (validVersionNumber) {
const int minorVersion = version.mid(dotIndex + 1).toInt(&validVersionNumber);
if (validVersionNumber) {
const Component entry(sections[0], sections[2], majorVersion, minorVersion);
//.........这里部分代码省略.........
示例6: lex
int RegExpTokenizer::lex()
{
lexemStart = pos;
lexemLength = 0;
int lastAcceptingPos = -1;
int token = -1;
QChar ch;
// initial state
ch = next();
if (ch.unicode() >= 1 && ch.unicode() <= 33)
goto state_1;
if (ch.unicode() == 34)
goto state_2;
if (ch.unicode() >= 35 && ch.unicode() <= 39)
goto state_1;
if (ch.unicode() == 40) {
token = RE2NFA::TOK_LPAREN;
goto found;
}
if (ch.unicode() == 41) {
token = RE2NFA::TOK_RPAREN;
goto found;
}
if (ch.unicode() == 42) {
token = RE2NFA::TOK_STAR;
goto found;
}
if (ch.unicode() == 43) {
token = RE2NFA::TOK_PLUS;
goto found;
}
if (ch.unicode() == 44) {
token = RE2NFA::TOK_COMMA;
goto found;
}
if (ch.unicode() == 45)
goto state_1;
if (ch.unicode() == 46) {
token = RE2NFA::TOK_DOT;
goto found;
}
if (ch.unicode() >= 47 && ch.unicode() <= 62)
goto state_1;
if (ch.unicode() == 63) {
token = RE2NFA::TOK_QUESTION;
goto found;
}
if (ch.unicode() >= 64 && ch.unicode() <= 90)
goto state_1;
if (ch.unicode() == 91)
goto state_10;
if (ch.unicode() == 92)
goto state_11;
if (ch.unicode() >= 93 && ch.unicode() <= 122)
goto state_1;
if (ch.unicode() == 123) {
token = RE2NFA::TOK_LBRACE;
goto found;
}
if (ch.unicode() == 124) {
token = RE2NFA::TOK_OR;
goto found;
}
if (ch.unicode() == 125) {
token = RE2NFA::TOK_RBRACE;
goto found;
}
if (ch.unicode() >= 126)
goto state_1;
goto out;
state_1:
lastAcceptingPos = pos;
token = RE2NFA::TOK_STRING;
goto out;
state_2:
lastAcceptingPos = pos;
token = RE2NFA::TOK_STRING;
ch = next();
if (ch.unicode() >= 1 && ch.unicode() <= 33)
goto state_15;
if (ch.unicode() == 34)
goto state_16;
if (ch.unicode() >= 35)
goto state_15;
goto out;
state_10:
ch = next();
if (ch.unicode() >= 1 && ch.unicode() <= 91)
goto state_17;
if (ch.unicode() == 92)
goto state_18;
if (ch.unicode() == 93)
goto state_19;
if (ch.unicode() >= 94)
goto state_17;
goto out;
state_11:
lastAcceptingPos = pos;
token = RE2NFA::TOK_STRING;
//.........这里部分代码省略.........
示例7: while
/*
Returns the recommended indent for the bottom line of yyProgram,
assuming it's a continuation line.
We're trying to align the continuation line against some parenthesis
or other bracked left opened on a previous line, or some interesting
operator such as '='.
*/
int QmlJSIndenter::indentForContinuationLine()
{
int braceDepth = 0;
int delimDepth = 0;
bool leftBraceFollowed = *yyLeftBraceFollows;
for (int i = 0; i < SmallRoof; i++) {
int hook = -1;
int j = yyLine->length();
while (j > 0 && hook < 0) {
j--;
QChar ch = yyLine->at(j);
switch (ch.unicode()) {
case ')':
delimDepth++;
break;
case ']':
braceDepth++;
break;
case '}':
braceDepth++;
break;
case '(':
delimDepth--;
/*
An unclosed delimiter is a good place to align at,
at least for some styles (including Qt's).
*/
if (delimDepth == -1)
hook = j;
break;
case '[':
braceDepth--;
/*
An unclosed delimiter is a good place to align at,
at least for some styles (including Qt's).
*/
if (braceDepth == -1)
hook = j;
break;
case '{':
braceDepth--;
/*
A left brace followed by other stuff on the same
line is typically for an enum or an initializer.
Such a brace must be treated just like the other
delimiters.
*/
if (braceDepth == -1) {
if (j < yyLine->length() - 1) {
hook = j;
} else {
return 0; // shouldn't happen
}
}
break;
case '=':
/*
An equal sign is a very natural alignment hook
because it's usually the operator with the lowest
precedence in statements it appears in. Case in
point:
int x = 1 +
2;
However, we have to beware of constructs such as
default arguments and explicit enum constant
values:
void foo(int x = 0,
int y = 0);
And not
void foo(int x = 0,
int y = 0);
These constructs are caracterized by a ',' at the
end of the unfinished lines or by unbalanced
parentheses.
*/
Q_ASSERT(j - 1 >= 0);
if (QString::fromLatin1("!=<>").indexOf(yyLine->at(j - 1)) == -1 &&
j + 1 < yyLine->length() && yyLine->at(j + 1) != '=') {
if (braceDepth == 0 && delimDepth == 0 &&
j < yyLine->length() - 1 &&
//.........这里部分代码省略.........
示例8: applySimpleProperty
// Apply a simple variant type to a DOM property
static bool applySimpleProperty(const QVariant &v, bool translateString, DomProperty *dom_prop)
{
switch (v.type()) {
case QVariant::String: {
DomString *str = new DomString();
str->setText(v.toString());
if (!translateString)
str->setAttributeNotr(QLatin1String("true"));
dom_prop->setElementString(str);
}
return true;
case QVariant::ByteArray:
dom_prop->setElementCstring(QString::fromUtf8(v.toByteArray()));
return true;
case QVariant::Int:
dom_prop->setElementNumber(v.toInt());
return true;
case QVariant::UInt:
dom_prop->setElementUInt(v.toUInt());
return true;
case QVariant::LongLong:
dom_prop->setElementLongLong(v.toLongLong());
return true;
case QVariant::ULongLong:
dom_prop->setElementULongLong(v.toULongLong());
return true;
case QVariant::Double:
dom_prop->setElementDouble(v.toDouble());
return true;
case QVariant::Bool:
dom_prop->setElementBool(v.toBool() ? QFormBuilderStrings::instance().trueValue : QFormBuilderStrings::instance().falseValue);
return true;
case QVariant::Char: {
DomChar *ch = new DomChar();
const QChar character = v.toChar();
ch->setElementUnicode(character.unicode());
dom_prop->setElementChar(ch);
}
return true;
case QVariant::Point: {
DomPoint *pt = new DomPoint();
const QPoint point = v.toPoint();
pt->setElementX(point.x());
pt->setElementY(point.y());
dom_prop->setElementPoint(pt);
}
return true;
case QVariant::PointF: {
DomPointF *ptf = new DomPointF();
const QPointF pointf = v.toPointF();
ptf->setElementX(pointf.x());
ptf->setElementY(pointf.y());
dom_prop->setElementPointF(ptf);
}
return true;
case QVariant::Color: {
DomColor *clr = new DomColor();
const QColor color = qvariant_cast<QColor>(v);
clr->setElementRed(color.red());
clr->setElementGreen(color.green());
clr->setElementBlue(color.blue());
const int alphaChannel = color.alpha();
if (alphaChannel != 255)
clr->setAttributeAlpha(alphaChannel);
dom_prop->setElementColor(clr);
}
return true;
case QVariant::Size: {
DomSize *sz = new DomSize();
const QSize size = v.toSize();
sz->setElementWidth(size.width());
sz->setElementHeight(size.height());
dom_prop->setElementSize(sz);
}
return true;
case QVariant::SizeF: {
DomSizeF *szf = new DomSizeF();
const QSizeF sizef = v.toSizeF();
szf->setElementWidth(sizef.width());
szf->setElementHeight(sizef.height());
dom_prop->setElementSizeF(szf);
}
return true;
case QVariant::Rect: {
DomRect *rc = new DomRect();
//.........这里部分代码省略.........
示例9: previousBlockState
void Highlighter::highlightBlock(const QString &text)
{
int state = previousBlockState();
int len = text.length();
int start = 0;
int pos = 0;
while (pos < len) {
switch (state) {
case State_Text:
default:
while (pos < len) {
QChar ch = text.at(pos);
if (ch == '<') {
if (text.mid(pos, 4) == "<!--") {
state = State_Comment;
} else {
if (text.mid(pos, 9).toUpper() == "<!DOCTYPE")
state = State_DocType;
else
state = State_TagStart;
}
break;
} else if (ch == '&') {
start = pos;
while (pos < len
&& text.at(pos++) != ';')
;
setFormat(start, pos - start, m_colors[Entity]);
} else {
++pos;
}
}
break;
case State_Comment:
start = pos;
while (pos < len) {
if (text.mid(pos, 3) == "-->") {
pos += 3;
state = State_Text;
break;
} else {
++pos;
}
}
setFormat(start, pos - start, m_colors[Comment]);
break;
case State_DocType:
start = pos;
while (pos < len) {
QChar ch = text.at(pos);
++pos;
if (ch == '>') {
state = State_Text;
break;
}
}
setFormat(start, pos - start, m_colors[DocType]);
break;
// at '<' in e.g. "<span>foo</span>"
case State_TagStart:
start = pos + 1;
while (pos < len) {
QChar ch = text.at(pos);
++pos;
if (ch == '>') {
state = State_Text;
break;
}
if (!ch.isSpace()) {
--pos;
state = State_TagName;
break;
}
}
break;
// at 'b' in e.g "<blockquote>foo</blockquote>"
case State_TagName:
start = pos;
while (pos < len) {
QChar ch = text.at(pos);
++pos;
if (ch.isSpace()) {
--pos;
state = State_InsideTag;
break;
}
if (ch == '>') {
state = State_Text;
break;
}
}
//.........这里部分代码省略.........
示例10: QLatin1Char
void MessageHighlighter::highlightBlock(const QString &text)
{
static const QLatin1Char tab = QLatin1Char('\t');
static const QLatin1Char space = QLatin1Char(' ');
static const QLatin1Char amp = QLatin1Char('&');
static const QLatin1Char endTag = QLatin1Char('>');
static const QLatin1Char quot = QLatin1Char('"');
static const QLatin1Char apos = QLatin1Char('\'');
static const QLatin1Char semicolon = QLatin1Char(';');
static const QLatin1Char equals = QLatin1Char('=');
static const QLatin1Char percent = QLatin1Char('%');
static const QLatin1String startComment = QLatin1String("<!--");
static const QLatin1String endComment = QLatin1String("-->");
static const QLatin1String endElement = QLatin1String("/>");
int state = previousBlockState();
int len = text.length();
int start = 0;
int pos = 0;
while (pos < len) {
switch (state) {
case NormalState:
default:
while (pos < len) {
QChar ch = text.at(pos);
if (ch == QLatin1Char('<')) {
if (text.mid(pos, 4) == startComment) {
state = InComment;
} else {
state = InTag;
start = pos;
while (pos < len && text.at(pos) != space
&& text.at(pos) != endTag
&& text.at(pos) != tab
&& text.mid(pos, 2) != endElement)
++pos;
if (text.mid(pos, 2) == endElement)
++pos;
setFormat(start, pos - start,
m_formats[Tag]);
break;
}
break;
} else if (ch == amp && pos + 1 < len) {
// Default is Accelerator
if (text.at(pos + 1).isLetterOrNumber())
setFormat(pos + 1, 1, m_formats[Accelerator]);
// When a semicolon follows assume an Entity
start = pos;
ch = text.at(++pos);
while (pos + 1 < len && ch != semicolon && ch.isLetterOrNumber())
ch = text.at(++pos);
if (ch == semicolon)
setFormat(start, pos - start + 1, m_formats[Entity]);
} else if (ch == percent) {
start = pos;
// %[1-9]*
for (++pos; pos < len && text.at(pos).isDigit(); ++pos) {}
// %n
if (pos < len && pos == start + 1 && text.at(pos) == QLatin1Char('n'))
++pos;
setFormat(start, pos - start, m_formats[Variable]);
} else {
// No tag, comment or entity started, continue...
++pos;
}
}
break;
case InComment:
start = pos;
while (pos < len) {
if (text.mid(pos, 3) == endComment) {
pos += 3;
state = NormalState;
break;
} else {
++pos;
}
}
setFormat(start, pos - start, m_formats[Comment]);
break;
case InTag:
QChar quote = QChar::Null;
while (pos < len) {
QChar ch = text.at(pos);
if (quote.isNull()) {
start = pos;
if (ch == apos || ch == quot) {
quote = ch;
} else if (ch == endTag) {
++pos;
setFormat(start, pos - start, m_formats[Tag]);
state = NormalState;
break;
} else if (text.mid(pos, 2) == endElement) {
pos += 2;
setFormat(start, pos - start, m_formats[Tag]);
state = NormalState;
//.........这里部分代码省略.........
示例11: setType
// Function tries to split given datatype (type) into a number of
// ui widgets (type, scale and precision). If it is unable to do
// that - custom style (pure edit text widget) is used
void toDatatype::setType(const QString &type)
{
try
{
// Intentionally not using the SQL parser for this
enum
{
Initial,
AtType,
AtSize,
AtPrecision,
AtEnd
} state = Initial;
int startType = -1;
int endType = -1;
int size = -1;
int precision = -1;
bool valid = !PreferCustom;
bool endoftoken = false;
if (valid)
{
for (int pos = 0; pos < type.length(); pos++)
{
QChar c = type.at(pos);
if (c.isSpace())
{
endoftoken = true;
continue;
}
switch (state)
{
case Initial:
state = AtType;
startType = pos;
endoftoken = false;
break;
case AtType:
if (c == '(')
{
state = AtSize;
endoftoken = false;
}
else if (endoftoken)
{
valid = false;
}
else
endType = pos;
break;
case AtSize:
if (c.isDigit() && (!endoftoken || size == -1))
{
if (size == -1)
size = (c.toAscii()) - '0';
else
size = size * 10 + (c.toAscii()) - '0';
endoftoken = false;
}
else if (size == -1)
valid = false;
else if (c == ')')
{
endoftoken = false;
state = AtEnd;
}
else if (c == ',')
{
endoftoken = false;
state = AtPrecision;
}
else
valid = false;
break;
case AtPrecision:
if (c.isDigit() && (!endoftoken || precision == -1))
{
if (precision == -1)
precision = (c.toAscii()) - '0';
else
precision = precision * 10 + (c.toAscii()) - '0';
endoftoken = false;
}
else if (precision == -1)
valid = false;
else if (c == ')')
{
endoftoken = false;
state = AtEnd;
}
else
valid = false;
break;
case AtEnd:
valid = false;
break;
}
if (!valid)
//.........这里部分代码省略.........
示例12: if
QString TextUtil::rich2plain(const QString &in, bool collapseSpaces)
{
QString out;
for(int i = 0; i < (int)in.length(); ++i) {
// tag?
if(in[i] == '<') {
// find end of tag
++i;
int n = in.indexOf('>', i);
if(n == -1)
break;
QString str = in.mid(i, (n-i));
i = n;
QString tagName;
n = str.indexOf(' ');
if(n != -1)
tagName = str.mid(0, n);
else
tagName = str;
if(tagName == "br")
out += '\n';
// handle output of Qt::convertFromPlainText() correctly
if((tagName == "p" || tagName == "/p" || tagName == "div") && out.length() > 0)
out += '\n';
}
// entity?
else if(in[i] == '&') {
// find a semicolon
++i;
int n = in.indexOf(';', i);
if(n == -1)
break;
QString type = in.mid(i, (n-i));
i = n; // should be n+1, but we'll let the loop increment do it
if(type == "amp")
out += '&';
else if(type == "lt")
out += '<';
else if(type == "gt")
out += '>';
else if(type == "quot")
out += '\"';
else if(type == "apos")
out += '\'';
}
else if(in[i].isSpace()) {
if(in[i] == QChar::Nbsp)
out += ' ';
else if(in[i] != '\n') {
if(!collapseSpaces || i == 0 || out.length() == 0)
out += ' ';
else {
QChar last = out.at(out.length()-1);
bool ok = true;
if(last.isSpace() && last != '\n')
ok = false;
if(ok)
out += ' ';
}
}
}
else {
out += in[i];
}
}
return out;
}
示例13: if
bool QTextHtmlImporter::appendNodeText()
{
const int initialCursorPosition = cursor.position();
QTextCharFormat format = currentNode->charFormat;
if(wsm == QTextHtmlParserNode::WhiteSpacePre || wsm == QTextHtmlParserNode::WhiteSpacePreWrap)
compressNextWhitespace = PreserveWhiteSpace;
QString text = currentNode->text;
QString textToInsert;
textToInsert.reserve(text.size());
for (int i = 0; i < text.length(); ++i) {
QChar ch = text.at(i);
if (ch.isSpace()
&& ch != QChar::Nbsp
&& ch != QChar::ParagraphSeparator) {
if (compressNextWhitespace == CollapseWhiteSpace)
compressNextWhitespace = RemoveWhiteSpace; // allow this one, and remove the ones coming next.
else if(compressNextWhitespace == RemoveWhiteSpace)
continue;
if (wsm == QTextHtmlParserNode::WhiteSpacePre
|| textEditMode
) {
if (ch == QLatin1Char('\n')) {
if (textEditMode)
continue;
} else if (ch == QLatin1Char('\r')) {
continue;
}
} else if (wsm != QTextHtmlParserNode::WhiteSpacePreWrap) {
compressNextWhitespace = RemoveWhiteSpace;
if (wsm == QTextHtmlParserNode::WhiteSpaceNoWrap)
ch = QChar::Nbsp;
else
ch = QLatin1Char(' ');
}
} else {
compressNextWhitespace = PreserveWhiteSpace;
}
if (ch == QLatin1Char('\n')
|| ch == QChar::ParagraphSeparator) {
if (!textToInsert.isEmpty()) {
cursor.insertText(textToInsert, format);
textToInsert.clear();
}
QTextBlockFormat fmt = cursor.blockFormat();
if (fmt.hasProperty(QTextFormat::BlockBottomMargin)) {
QTextBlockFormat tmp = fmt;
tmp.clearProperty(QTextFormat::BlockBottomMargin);
cursor.setBlockFormat(tmp);
}
fmt.clearProperty(QTextFormat::BlockTopMargin);
appendBlock(fmt, cursor.charFormat());
} else {
if (!namedAnchors.isEmpty()) {
if (!textToInsert.isEmpty()) {
cursor.insertText(textToInsert, format);
textToInsert.clear();
}
format.setAnchor(true);
format.setAnchorNames(namedAnchors);
cursor.insertText(ch, format);
namedAnchors.clear();
format.clearProperty(QTextFormat::IsAnchor);
format.clearProperty(QTextFormat::AnchorName);
} else {
textToInsert += ch;
}
}
}
if (!textToInsert.isEmpty()) {
cursor.insertText(textToInsert, format);
}
return cursor.position() != initialCursorPosition;
}
示例14: QString
void KeyEvent::fromScriptValue(const QScriptValue& object, KeyEvent& event) {
event.isValid = false; // assume the worst
event.isMeta = object.property("isMeta").toVariant().toBool();
event.isControl = object.property("isControl").toVariant().toBool();
event.isAlt = object.property("isAlt").toVariant().toBool();
event.isKeypad = object.property("isKeypad").toVariant().toBool();
event.isAutoRepeat = object.property("isAutoRepeat").toVariant().toBool();
QScriptValue key = object.property("key");
if (key.isValid()) {
event.key = key.toVariant().toInt();
event.text = QString(QChar(event.key));
event.isValid = true;
} else {
QScriptValue text = object.property("text");
if (text.isValid()) {
event.text = object.property("text").toVariant().toString();
// if the text is a special command, then map it here...
// TODO: come up with more elegant solution here, a map? is there a Qt function that gives nice names for keys?
if (event.text.toUpper() == "F1") {
event.key = Qt::Key_F1;
} else if (event.text.toUpper() == "F2") {
event.key = Qt::Key_F2;
} else if (event.text.toUpper() == "F3") {
event.key = Qt::Key_F3;
} else if (event.text.toUpper() == "F4") {
event.key = Qt::Key_F4;
} else if (event.text.toUpper() == "F5") {
event.key = Qt::Key_F5;
} else if (event.text.toUpper() == "F6") {
event.key = Qt::Key_F6;
} else if (event.text.toUpper() == "F7") {
event.key = Qt::Key_F7;
} else if (event.text.toUpper() == "F8") {
event.key = Qt::Key_F8;
} else if (event.text.toUpper() == "F9") {
event.key = Qt::Key_F9;
} else if (event.text.toUpper() == "F10") {
event.key = Qt::Key_F10;
} else if (event.text.toUpper() == "F11") {
event.key = Qt::Key_F11;
} else if (event.text.toUpper() == "F12") {
event.key = Qt::Key_F12;
} else if (event.text.toUpper() == "UP") {
event.key = Qt::Key_Up;
event.isKeypad = true;
} else if (event.text.toUpper() == "DOWN") {
event.key = Qt::Key_Down;
event.isKeypad = true;
} else if (event.text.toUpper() == "LEFT") {
event.key = Qt::Key_Left;
event.isKeypad = true;
} else if (event.text.toUpper() == "RIGHT") {
event.key = Qt::Key_Right;
event.isKeypad = true;
} else if (event.text.toUpper() == "SPACE") {
event.key = Qt::Key_Space;
} else if (event.text.toUpper() == "ESC") {
event.key = Qt::Key_Escape;
} else if (event.text.toUpper() == "TAB") {
event.key = Qt::Key_Tab;
} else if (event.text.toUpper() == "DELETE") {
event.key = Qt::Key_Delete;
} else if (event.text.toUpper() == "BACKSPACE") {
event.key = Qt::Key_Backspace;
} else if (event.text.toUpper() == "SHIFT") {
event.key = Qt::Key_Shift;
} else if (event.text.toUpper() == "ALT") {
event.key = Qt::Key_Alt;
} else if (event.text.toUpper() == "CONTROL") {
event.key = Qt::Key_Control;
} else if (event.text.toUpper() == "META") {
event.key = Qt::Key_Meta;
} else if (event.text.toUpper() == "PAGE DOWN") {
event.key = Qt::Key_PageDown;
} else if (event.text.toUpper() == "PAGE UP") {
event.key = Qt::Key_PageUp;
} else if (event.text.toUpper() == "HOME") {
event.key = Qt::Key_Home;
} else if (event.text.toUpper() == "END") {
event.key = Qt::Key_End;
} else if (event.text.toUpper() == "HELP") {
event.key = Qt::Key_Help;
} else if (event.text.toUpper() == "CAPS LOCK") {
event.key = Qt::Key_CapsLock;
} else {
// Key values do not distinguish between uppercase and lowercase
// and use the uppercase key value.
event.key = event.text.toUpper().at(0).unicode();
}
event.isValid = true;
}
}
QScriptValue isShifted = object.property("isShifted");
if (isShifted.isValid()) {
event.isShifted = isShifted.toVariant().toBool();
} else {
//.........这里部分代码省略.........
示例15: load
/*!
Load, parse, and process a qdoc configuration file. This
function is only called by the other load() function, but
this one is recursive, i.e., it calls itself when it sees
an \c{include} statement in the qdog configuration file.
*/
void Config::load(Location location, const QString& fileName)
{
QRegExp keySyntax("\\w+(?:\\.\\w+)*");
#define SKIP_CHAR() \
do { \
location.advance(c); \
++i; \
c = text.at(i); \
cc = c.unicode(); \
} while (0)
#define SKIP_SPACES() \
while (c.isSpace() && cc != '\n') \
SKIP_CHAR()
#define PUT_CHAR() \
word += c; \
SKIP_CHAR();
if (location.depth() > 16)
location.fatal(tr("Too many nested includes"));
QFile fin(fileName);
if (!fin.open(QFile::ReadOnly | QFile::Text)) {
fin.setFileName(fileName + ".qdoc");
if (!fin.open(QFile::ReadOnly | QFile::Text))
location.fatal(tr("Cannot open file '%1': %2").arg(fileName).arg(fin.errorString()));
}
QTextStream stream(&fin);
stream.setCodec("UTF-8");
QString text = stream.readAll();
text += QLatin1String("\n\n");
text += QChar('\0');
fin.close();
location.push(fileName);
location.start();
int i = 0;
QChar c = text.at(0);
uint cc = c.unicode();
while (i < (int) text.length()) {
if (cc == 0)
++i;
else if (c.isSpace()) {
SKIP_CHAR();
}
else if (cc == '#') {
do {
SKIP_CHAR();
} while (cc != '\n');
}
else if (isMetaKeyChar(c)) {
Location keyLoc = location;
bool plus = false;
QString stringValue;
QStringList stringListValue;
QString word;
bool inQuote = false;
bool prevWordQuoted = true;
bool metWord = false;
MetaStack stack;
do {
stack.process(c, location);
SKIP_CHAR();
} while (isMetaKeyChar(c));
QStringList keys = stack.getExpanded(location);
SKIP_SPACES();
if (keys.count() == 1 && keys.first() == "include") {
QString includeFile;
if (cc != '(')
location.fatal(tr("Bad include syntax"));
SKIP_CHAR();
SKIP_SPACES();
while (!c.isSpace() && cc != '#' && cc != ')') {
includeFile += c;
SKIP_CHAR();
}
SKIP_SPACES();
if (cc != ')')
location.fatal(tr("Bad include syntax"));
SKIP_CHAR();
SKIP_SPACES();
if (cc != '#' && cc != '\n')
location.fatal(tr("Trailing garbage"));
/*
Here is the recursive call.
//.........这里部分代码省略.........