本文整理汇总了C++中setCurrentBlockState函数的典型用法代码示例。如果您正苦于以下问题:C++ setCurrentBlockState函数的具体用法?C++ setCurrentBlockState怎么用?C++ setCurrentBlockState使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setCurrentBlockState函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: expression
void HEMSyntaxHighlighter::highlightBlock(const QString &text)
{
for (const HighlightingRule &rule : highlightingRules) {
QRegExp expression(rule.pattern);
int index = expression.indexIn(text);
while (index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, rule.format);
index = expression.indexIn(text, index + length);
}
}
setCurrentBlockState(STATE_NORMAL);
int startIndex = 0;
QRegExp include("\\binclude\\b"), newline("\\r?\\n");
int ilength = QString("include").length(); // 7
if (previousBlockState() != STATE_INCLUDE)
startIndex = include.indexIn(text) + ilength;
while (startIndex >= ilength) {
int endIndex = newline.indexIn(text);
int includeLength;
if (endIndex == -1) {
setCurrentBlockState(STATE_INCLUDE);
includeLength = text.length() - startIndex;
} else {
includeLength = endIndex - startIndex
+ newline.matchedLength();
}
setFormat(startIndex, includeLength, includeFileFormat);
startIndex = include.indexIn(text, startIndex + includeLength);
}
}
开发者ID:hyst329,项目名称:mathproject,代码行数:33,代码来源:hemsyntaxhighlighter.cpp
示例2: setCurrentBlockState
void CodeHighlighter::highlightCommentBlocks(const QString &text)
{
const QList<LexemeAppearance *> &lexemes = m_theme->blockLexemes();
for (const LexemeAppearance *lexeme : lexemes) {
const QRegExp &startPattern = lexeme->pattern();
const QRegExp &endPattern = lexeme->endPattern();
setCurrentBlockState(0);
int startIndex = 0;
if (previousBlockState() != 1)
startIndex = startPattern.indexIn(text);
while (startIndex >= 0) {
int endIndex = endPattern.indexIn(text, startIndex);
int commentLength;
if (endIndex == -1) {
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
commentLength = endIndex - startIndex + endPattern.matchedLength();
}
setFormat(startIndex, commentLength, *lexeme->format());
startIndex = startPattern.indexIn(text, startIndex + commentLength);
}
}
}
开发者ID:yudjin87,项目名称:carousel,代码行数:29,代码来源:CodeHighlighter.cpp
示例3: setCurrentBlockState
// Overrides the function from QSyntaxHighlighter;
// gets called by QTextEditor whenever
// a block (line of text) needs to be repainted
void XHTMLHighlighter::highlightBlock(const QString &text)
{
// By default, all block states are -1;
// in our implementation regular text is state == 1
if (previousBlockState() == -1) {
setCurrentBlockState(State_Text);
}
// Propagate previous state; needed for state tracking
else {
setCurrentBlockState(previousBlockState());
}
if (text.isEmpty()) {
return;
}
SettingsStore settings;
m_enableSpellCheck = settings.spellCheck();
// Run spell check over the text.
if (m_enableSpellCheck && m_checkSpelling) {
CheckSpelling(text);
}
// The order of these operations is important
// because some states format text over previous states!
HighlightLine(text, State_Entity);
HighlightLine(text, State_CSS);
HighlightLine(text, State_HTML);
HighlightLine(text, State_CSSComment);
HighlightLine(text, State_HTMLComment);
HighlightLine(text, State_DOCTYPE);
}
开发者ID:AmesianX,项目名称:Sigil,代码行数:36,代码来源:XHTMLHighlighter.cpp
示例4: delimiter
bool Highlighter::matchMultiline(const QString& text, const ::HighlightingRule& rule)
{
QRegExp delimiter(rule.pattern);
int start = 0;
int add = 0;
int end = 0;
int length = 0;
if (previousBlockState() != rule.index)
{
start = delimiter.indexIn(text);
add = delimiter.matchedLength();
}
while (start >= 0)
{
end = delimiter.indexIn(text, start + add);
if (end >= add)
{
length = end - start + add + delimiter.matchedLength();
setCurrentBlockState(0);
}
else
{
setCurrentBlockState(rule.index);
length = text.length() - start + add;
}
QTextCharFormat fmt;
if (m_Formats.contains(rule.t))
fmt = m_Formats[rule.t];
setFormat(start, length, fmt);
start = delimiter.indexIn(text, start + length);
}
return currentBlockState() == rule.index;
}
开发者ID:a1ext,项目名称:labeless,代码行数:34,代码来源:highlighter.cpp
示例5: foreach
foreach (HighlightingRule rule, m_highlightingRules) {
if(!rule.block) {
QRegExp expression(rule.expression);
int index = text.indexOf(expression);
while (index >= 0) {
int length = expression.matchedLength();
/*IntervallWithFormat temp;
temp.index = index;
temp.length = length;
temp.format = rule.format;
keywords.append(temp);*/
//setFormat(index, length, rule.format);
applyFormat(index, length, rule.format);
index = text.indexOf(expression, index + length);
}
} else {
// mathMode
setCurrentBlockState(0);
int startIndex = 0;
if (previousBlockState() != 1)
//startIndex = text.indexOf(mathModeStartExpression);
startIndex = text.indexOf(rule.startExpression);
while (startIndex >= 0) {
//int endIndex = text.indexOf(mathModeEndExpression, startIndex+1);
int endIndex = text.indexOf(rule.endExpression, startIndex+1);
int mathModeLength;
if (endIndex == -1) {
setCurrentBlockState(1);
mathModeLength = text.length() - startIndex;
} else {
/*mathModeLength = endIndex - startIndex
+ mathModeEndExpression.matchedLength();*/
mathModeLength = endIndex - startIndex
+ rule.endExpression.matchedLength();
}
/*IntervallWithFormat temp;
temp.index = startIndex;
temp.length = mathModeLength;
temp.format = m_mathModeFormat;
mathModes.append(temp);*/
//setFormat(startIndex, mathModeLength, m_mathModeFormat);
applyFormat(startIndex, mathModeLength, m_mathModeFormat);
/*startIndex = text.indexOf(mathModeStartExpression,
startIndex + mathModeLength);*/
startIndex = text.indexOf(rule.startExpression,
startIndex + mathModeLength);
}
}
}
开发者ID:BackupTheBerlios,项目名称:qtex-svn,代码行数:51,代码来源:highlighter.cpp
示例6: setCurrentBlockState
void Highlighter::highlightBlock(const QString &text)
{
if (!m_syntaxer) return;
if (text.isEmpty()) {
setCurrentBlockState(previousBlockState());
return;
}
setCurrentBlockState(0);
int startCommentIndex = -1;
int startStringIndex = -1;
const CommentInfo * currentCommentInfo = NULL;
int pbs = previousBlockState();
if (pbs <= 0) {
m_syntaxer->matchCommentStart(text, 0, startCommentIndex, currentCommentInfo);
}
else if (pbs >= COMMENTOFFSET) {
currentCommentInfo = m_syntaxer->getCommentInfo(previousBlockState() - COMMENTOFFSET);
startCommentIndex = 0;
}
else if (pbs == STRINGOFFSET) {
startStringIndex = 0;
}
QString noComment = text;
while (startCommentIndex >= 0) {
int endIndex = currentCommentInfo->m_multiLine ? text.indexOf(currentCommentInfo->m_end, startCommentIndex, currentCommentInfo->m_caseSensitive) : text.length();
int commentLength;
if (endIndex == -1) {
setCurrentBlockState(currentCommentInfo->m_index + COMMENTOFFSET);
commentLength = text.length() - startCommentIndex;
}
else {
commentLength = endIndex - startCommentIndex + currentCommentInfo->m_end.length();
}
noComment.replace(startCommentIndex, commentLength, QString(commentLength, ' '));
QTextCharFormat * cf = m_styleFormats.value("Comment", NULL);
if (cf != NULL) {
setFormat(startCommentIndex, commentLength, *cf);
}
m_syntaxer->matchCommentStart(text, startCommentIndex + commentLength, startCommentIndex, currentCommentInfo);
}
highlightStrings(startStringIndex, noComment);
highlightTerms(noComment);
}
开发者ID:honsey,项目名称:fztaxedit,代码行数:48,代码来源:highlighter.cpp
示例7: currentBlockState
// Clears the requested state for the current text block
void XHTMLHighlighter::ClearState(int state)
{
int current_state = currentBlockState();
// Remove the current state from the list
current_state = current_state & ~state;
setCurrentBlockState(current_state);
}
开发者ID:AmesianX,项目名称:Sigil,代码行数:8,代码来源:XHTMLHighlighter.cpp
示例8: while
void SmkMarkHighlighter::highlightBlock(const QString& text)
{
// highlight with regrxp
for(int i=0; i<format_.size(); i++) {
int index = regexp_[i].indexIn(text);
while(index >= 0) {
int length = regexp_[i].matchedLength();
this->setFormat(index, length, format_[i]);
index = regexp_[i].indexIn(text, index + length);
}
}
// code block and latex block highlight
if(currentBlockState() == -1)
setCurrentBlockState(0);
QTextCharFormat codeFormat;
codeFormat.setForeground(QColor(qSmkApp()->option("color.code")));
_aux_multiBlockMatch(text, "`", "`", codeFormat, 0x0001);
// _aux_multiBlockMatch(text, "``", "``", codeFormat, 0x0002);
// _aux_multiBlockMatch(text, "```", "```", codeFormat, 0x004);
QTextCharFormat latexFormat;
latexFormat.setForeground(QColor(qSmkApp()->option("color.latex")));
_aux_multiBlockMatch(text, "${", "}$", latexFormat, 0x1000);
_aux_multiBlockMatch(text, "$$", "$$", latexFormat, 0x2000);
}
开发者ID:ShawnXUNJU,项目名称:Smark,代码行数:27,代码来源:SmkMarkHighlighter.cpp
示例9: setCurrentBlockState
void QtScriptHighlighter::onBlockEnd(int state, int firstNonSpace)
{
typedef TextEditor::TextBlockUserData TextEditorBlockData;
setCurrentBlockState((m_braceDepth << 8) | state);
// Set block data parentheses. Force creation of block data unless empty
TextEditorBlockData *blockData = 0;
if (QTextBlockUserData *userData = currentBlockUserData())
blockData = static_cast<TextEditorBlockData *>(userData);
if (!blockData && !m_currentBlockParentheses.empty()) {
blockData = new TextEditorBlockData;
setCurrentBlockUserData(blockData);
}
if (blockData) {
blockData->setParentheses(m_currentBlockParentheses);
blockData->setClosingCollapseMode(TextEditor::TextBlockUserData::NoClosingCollapse);
blockData->setCollapseMode(TextEditor::TextBlockUserData::NoCollapse);
}
if (!m_currentBlockParentheses.isEmpty()) {
QTC_ASSERT(blockData, return);
int collapse = Parenthesis::collapseAtPos(m_currentBlockParentheses);
if (collapse >= 0) {
if (collapse == firstNonSpace)
blockData->setCollapseMode(TextEditor::TextBlockUserData::CollapseThis);
else
blockData->setCollapseMode(TextEditor::TextBlockUserData::CollapseAfter);
}
if (Parenthesis::hasClosingCollapse(m_currentBlockParentheses))
blockData->setClosingCollapseMode(TextEditor::TextBlockUserData::NoClosingCollapse);
}
开发者ID:ramons03,项目名称:qt-creator,代码行数:33,代码来源:qtscripthighlighter.cpp
示例10: setFormat
void Highlighter::highlightBlock(const QString &text)
{
QTextCharFormat fmt;
fmt.setFont(QFont(m_Palette->mainFont, m_Palette->mainFontPointSize));
setFormat(0, text.length(), fmt);
foreach(const ::HighlightingRule& rule, kHighlightingRules.rules)
{
QRegExp expression(rule.pattern);
int index = expression.indexIn(text);
while (index >= 0)
{
index = expression.pos(rule.index);
int length = expression.cap(rule.index).length();
if (m_Formats.contains(rule.t))
{
fmt = m_Formats[rule.t];
setFormat(index, length, fmt);
}
index = expression.indexIn(text, index + length);
}
}
setCurrentBlockState(0);
bool isMultiline = matchMultiline(text, kHighlightingRules.triSingle);
if (!isMultiline)
isMultiline = matchMultiline(text, kHighlightingRules.triDouble);
}
开发者ID:a1ext,项目名称:labeless,代码行数:29,代码来源:highlighter.cpp
示例11: QRegExp
void EMailQuoteHighlighter::highlightBlock( const QString &text )
{
QString simplified = text;
simplified = simplified.remove( QRegExp( QLatin1String( "\\s" ) ) ).
replace( QLatin1Char( '|' ), QLatin1Char( '>' ) );
while ( simplified.startsWith( QLatin1String( ">>>>" ) ) ) {
simplified = simplified.mid( 3 );
}
if ( simplified.startsWith( QLatin1String( ">>>" ) ) ) {
setFormat( 0, text.length(), d->col3 );
} else if ( simplified.startsWith( QLatin1String( ">>" ) ) ) {
setFormat( 0, text.length(), d->col2 );
} else if ( simplified.startsWith( QLatin1String( ">" ) ) ) {
setFormat( 0, text.length(), d->col1 );
} else if ( d->parent->isLineQuoted( text ) ) {
setFormat( 0, text.length(), d->col1 ); // FIXME: custom quote prefix
// can't handle multiple levels
} else {
if ( d->spellCheckingEnabled && checkerEnabledByDefault() ) {
Highlighter::highlightBlock( text );
}
}
setCurrentBlockState( 0 );
}
开发者ID:pvuorela,项目名称:kcalcore,代码行数:26,代码来源:emailquotehighlighter.cpp
示例12: foreach
foreach (const MultilineHighlightingRule &rule, multilineHighlightingRules)
{
QRegExp startExpression(rule.patternStart);
QRegExp endExpression(rule.patternEnd);
int startIndex = 0;
if (previousBlockState() != rule.statusCode)
{
startIndex = startExpression.indexIn(text);
}
while (startIndex >= 0)
{
int endIndex = endExpression.indexIn(text, startIndex);
int matchLength;
if (endIndex == -1)
{
setCurrentBlockState(rule.statusCode);
matchLength = text.length() - startIndex;
}
else
{
matchLength = endIndex - startIndex + endExpression.matchedLength();
}
setFormat(startIndex, matchLength, rule.format);
startIndex = rule.patternStart.indexIn(text, startIndex + matchLength);
}
}
开发者ID:lodacom,项目名称:EditeurWeb,代码行数:30,代码来源:Highlighter.cpp
示例13: FindElements
logical OSyntaxHighlighter :: FindElements (QString qsText, int32 &riStart )
{
logical term = NO;
int iEnd = 0
,iStart = riStart
,iLength = 0;
std::vector<SyntaxElement>::iterator it;
BEGINSEQ
if(qsText.isEmpty()) ERROR
for ( it = elements.begin(); it != elements.end() && !term; ++it ){
iStart = riStart;
while ( iStart >= 0 )
if(FindElement(qsText,iStart,(*it).rxStart)){
iLength = (*it).rxStart.cap(0).length();
iEnd = iStart+iLength;
if((*it).isBlock)
if(FindElement(qsText,iEnd,(*it).rxEnd)){ //highlight the block to the end of line
iLength = (iEnd + (*it).rxStart.cap(0).length()) - iStart;
}else{ // remember that the block doesnt end here
iLength = qsText.length() - iStart;
setCurrentBlockState(GetSyntaxElementIndex((*it)));
}
AddFormatRange((*it).syntaxclass,iStart,iLength);
iStart+=iLength;
}
}
RECOVER
term = YES;
ENDSEQ
return term;
}
开发者ID:BackupTheBerlios,项目名称:openaqua-svn,代码行数:34,代码来源:OSyntaxHighlighter.cpp
示例14: while
bool BashHighlighter::matchMultiline(const QString& text,
const QRegExp& delimiter,
const int inState,
const QTextCharFormat& style) {
int start = -1;
int add = -1;
int end = -1;
int length = 0;
// If inside triple-single quotes, start at 0
if ( previousBlockState() == inState ) {
start = 0;
add = 0;
}
// Otherwise, look for the delimiter on this line
else {
start = delimiter.indexIn(text);
// Move past this match
add = delimiter.matchedLength();
}
// As long as there's a delimiter match on this line...
while ( start >= 0 ) {
// Look for the ending delimiter
end = delimiter.indexIn(text, start + add);
// Ending delimiter on this line?
if ( end >= add ) {
length = end - start + add + delimiter.matchedLength();
setCurrentBlockState(0);
}
// No; multi-line string
else {
setCurrentBlockState(inState);
length = text.length() - start + add;
}
// Apply formatting and look for next
setFormat(start, length, style);
start = delimiter.indexIn(text, start + length);
}
// Return True if still inside a multi-line string, False otherwise
if ( currentBlockState() == inState )
return true;
else
return false;
}
开发者ID:ovsm-dev,项目名称:sdp,代码行数:47,代码来源:bashhighlighter.cpp
示例15: type
void QMLHighlighter::highlightBlock(const QString &text)
{
QTextCharFormat keywordFormat;
keywordFormat.setForeground(QColor("#d7ffaf")); // Identifier
QTextCharFormat typeFormat;
typeFormat.setForeground(QColor("#afffff")); // Type
QTextCharFormat commentFormat;
commentFormat.setForeground(QColor("#8a8a8a")); // Comment
QTextCharFormat numericConstantFormat;
numericConstantFormat.setForeground(QColor("#ffffd7")); // Constant
QTextCharFormat stringConstantFormat;
stringConstantFormat.setForeground(QColor("#ffffd7"));
QRegExp type("\\b[A-Z][A-Za-z]+\\b");
QRegExp numericConstant("[0-9]+\\.?[0-9]*");
QRegExp stringConstant("['\"].*['\"]");//Not multiline strings, but they're rare
QRegExp lineComment("//[^\n]*");
QRegExp startComment("/\\*");
QRegExp endComment("\\*/");
applyBasicHighlight(text, type, typeFormat);
applyBasicHighlight(text, numericConstant, numericConstantFormat);
applyBasicHighlight(text, stringConstant, stringConstantFormat);
applyBasicHighlight(text, lineComment, commentFormat);
setCurrentBlockState(0);
int startIndex = 0;
if (previousBlockState() != 1)
startIndex = text.indexOf(startComment);
while (startIndex >= 0) {
int endIndex = text.indexOf(endComment, startIndex);
int commentLength;
if (endIndex == -1) {
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
commentLength = endIndex - startIndex
+ endComment.matchedLength();
}
setFormat(startIndex, commentLength, commentFormat);
startIndex = text.indexOf(startComment,
startIndex + commentLength);
}
}
开发者ID:TanNgocDo,项目名称:terrarium-app,代码行数:47,代码来源:qmlhighlighter.cpp
示例16: previousBlockState
void SyntaxHighlighter::highlightBlock(const QString& str)
{
int nState = previousBlockState();
int nStart = 0;
for(int i = 0; i < str.length(); ++i) {
if(nState == InsideCStyleComment) {
if(str.mid(i, 2) == "*/") {
nState = NormalState;
setFormat(nStart, i - nStart + 2, Qt::darkGray);
i++;
}
}
else if(nState == InsideCString) {
if (str.mid(i, 1) == "\"" || str.mid(i, 1) == "\'") {
if (str.mid(i - 1, 2) != "\\\"" && str.mid(i - 1, 2) != "\\\'") {
nState = NormalState;
setFormat(nStart, i - nStart + 1, Qt::cyan);
}
}
}
else {
if (str.mid(i, 2) == "//") {
setFormat(i, str.length() - i, Qt::darkGray);
break;
}
else if (str.mid(i, 1) == "#") {
setFormat(i, str.length() - i, Qt::green);
break;
}
else if (str.at(i).isNumber()) {
setFormat(i, 1, Qt::cyan);
}
else if (str.mid(i, 2) == "/*") {
nStart = i;
nState = InsideCStyleComment;
}
else if (str.mid(i, 1) == "\"" || str.mid(i, 1) == "\'") {
nStart = i;
nState = InsideCString;
}
else {
QString strKeyword = getKeyword(i, str);
if (!strKeyword.isEmpty()) {
setFormat(i, strKeyword.length(), Qt::white);
i += strKeyword.length() - 1;
}
}
}
}
if (nState == InsideCStyleComment) {
setFormat(nStart, str.length() - nStart, Qt::darkGray);
}
if (nState == InsideCString) {
setFormat(nStart, str.length() - nStart, Qt::cyan);
}
setCurrentBlockState(nState);
}
开发者ID:Mark5137,项目名称:homework,代码行数:59,代码来源:syntaxhighlighter.cpp
示例17: expression
void CodeSyntaxHighlither::highlightBlock(const QString& text)
{
for(const CodeSyntaxHighlightRule& rule : m_CodeHighlightingRules)
{
QRegExp expression(rule.m_Pattern);
int32_t index = expression.indexIn(text);
while(index >= 0)
{
int32_t length = expression.matchedLength();
setFormat(index, length, rule.m_Format);
index = expression.indexIn(text, index + length);
}
}
setCurrentBlockState(0);
int32_t startIndex = 0;
if(previousBlockState() != 1)
{
startIndex = m_CommentStartExpression.indexIn(text);
}
while(startIndex >= 0)
{
int32_t endIndex = m_CommentEndExpression.indexIn(text, startIndex);
int32_t commentLength = 0;
if(endIndex == -1)
{
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
}
else
{
commentLength = endIndex - startIndex + m_CommentEndExpression.matchedLength();
}
setFormat(startIndex, commentLength, m_MultiLineCommentFormat);
startIndex = m_CommentStartExpression.indexIn(text, startIndex + commentLength);
}
}
开发者ID:dtbinh,项目名称:Arenal-Engine,代码行数:45,代码来源:CodeSyntaxHighlighter.cpp
示例18: searchInputForAutocompleteRules
void SyntaxHighlighter::highlightBlock(const QString &text)
{
if(languageSet)
{
// stops syntax highlight code running when searching for reg exp query
// search line for any autocomplete suggestions
autoCompleteSuggestions += searchInputForAutocompleteRules(text);
foreach (const SyntaxHighlightingRuleSet::HighlightingRule rule, ruleSet->highlightingRules) {
QRegExp expression(rule.pattern);
int index = expression.indexIn(text);
while (index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, rule.format);
index = expression.indexIn(text, index + length);
}
}
setCurrentBlockState(0);
int startIndex = 0;
if (previousBlockState() != 1)
startIndex = ruleSet->commentStartExpression.indexIn(text);
while (startIndex >= 0) {
int endIndex = ruleSet->commentEndExpression.indexIn(text, startIndex);
int commentLength;
if (endIndex == -1) {
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
commentLength = endIndex - startIndex
+ ruleSet->commentEndExpression.matchedLength();
}
setFormat(startIndex, commentLength, ruleSet->multiLineCommentFormat);
startIndex = ruleSet->commentStartExpression.indexIn(text, startIndex + commentLength);
}
// if the search box is populated with an expression
if(searchExpression.pattern() != "")
{
highlightSearchExpression(searchExpression, text);
}
}
}
开发者ID:JacobPlaster,项目名称:Able,代码行数:45,代码来源:syntaxhighlighter.cpp
示例19: setFormat
void MercurialSubmitHighlighter::highlightBlock(const QString &text)
{
// figure out current state
State state = static_cast<State>(previousBlockState());
if (text.startsWith(QLatin1String("HG:"))) {
setFormat(0, text.size(), formatForCategory(Format_Comment));
setCurrentBlockState(state);
return;
}
if (state == None) {
if (text.isEmpty()) {
setCurrentBlockState(state);
return;
}
state = Header;
} else if (state == Header) {
state = Other;
}
setCurrentBlockState(state);
// Apply format.
switch (state) {
case None:
break;
case Header: {
QTextCharFormat charFormat = format(0);
charFormat.setFontWeight(QFont::Bold);
setFormat(0, text.size(), charFormat);
break;
}
case Other:
// Format key words ("Task:") italic
if (m_keywordPattern.indexIn(text, 0, QRegExp::CaretAtZero) == 0) {
QTextCharFormat charFormat = format(0);
charFormat.setFontItalic(true);
setFormat(0, m_keywordPattern.matchedLength(), charFormat);
}
break;
}
}
开发者ID:acacid,项目名称:qt-creator,代码行数:42,代码来源:mercurialcommitwidget.cpp
示例20: while
void LatexFileType::highlightBlock(const QString &text)
{
//comments
int comInd = text.indexOf('%');
while (comInd > 0 && text.at(comInd - 1) == '\\')
comInd = text.indexOf('%', comInd + 1);
clearCurrentBlockSkipSegments();
addCurrentBlockSkipSegment(comInd);
if (comInd >= 0)
setFormat(comInd, text.length() - comInd, QColor(Qt::darkGray));
QString ntext = text.left(comInd);
//commands
QRegExp rx("(\\\\[a-zA-Z]*|\\\\#|\\\\\\$|\\\\%|\\\\&|\\\\_|\\\\\\{|\\\\\\})+");
int pos = rx.indexIn(ntext);
while (pos >= 0) {
int len = rx.matchedLength();
setFormat(pos, len, QColor(Qt::red).lighter(70));
pos = rx.indexIn(ntext, pos + len);
}
//multiline (math mode)
setCurrentBlockState(!ntext.isEmpty() ? 0 : previousBlockState());
int startIndex = 0;
bool firstIsStart = false;
if (previousBlockState() != 1) {
startIndex = indexOf(ntext, "$");
firstIsStart = true;
}
while (startIndex >= 0)
{
int endIndex = indexOf(ntext, "$", startIndex + (firstIsStart ? 1 : 0));
int commentLength;
if (endIndex == -1) {
setCurrentBlockState(1);
commentLength = ntext.length() - startIndex;
} else {
commentLength = endIndex - startIndex + 1;
}
setFormat(startIndex, commentLength, QColor(Qt::darkGreen));
startIndex = indexOf(ntext, "$", startIndex + commentLength);
}
}
开发者ID:ololoepepe,项目名称:TeX-Creator,代码行数:41,代码来源:latexfiletype.cpp
注:本文中的setCurrentBlockState函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论