当前位置: 首页>>代码示例>>C++>>正文


C++ setCurrentBlockState函数代码示例

本文整理汇总了C++中setCurrentBlockState函数的典型用法代码示例。如果您正苦于以下问题:C++ setCurrentBlockState函数的具体用法?C++ setCurrentBlockState怎么用?C++ setCurrentBlockState使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了setCurrentBlockState函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的setCurrentBlockState函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。