Exemplo n.º 1
0
int FontLock::highlightParagraph(const QString & text, int block) {
    ColorizerList list;
    if(block>0) {
        BlockPattern p = m_blocks[block-1];
        if(p.matchEnd(text)) {
            m_nested.pop();
            list = p.end().getColors();
        } else if(! p.matchMiddle(text)) { //error, emergency exit
            m_nested.pop();
            return highlightParagraph(text, m_nested.isEmpty() ? 0 : m_nested.top());
        } else {
            list = p.middle().getColors();
        }
    }

    int index = 0;
    for(QValueList<BlockPattern>::Iterator it = m_blocks.begin(); it != m_blocks.end(); ++it, ++index)
        if((*it).matchBegin(text)) {
            list += (*it).begin().getColors();
            m_nested.push(index+1);
        }

    for(QValueList<Pattern>::Iterator it = m_lines.begin(); it != m_lines.end(); ++it)
        if((*it).match(text))
            list += (*it).getColors();

    list = list.simplify();

    for(ColorizerList::const_iterator it = list.begin(); it != list.end(); ++it) {
        setFormat((*it).start(), (*it).length(), (*it).face().font(), (*it).face().color());
    }

    return m_nested.isEmpty() ? 0 : m_nested.top();
}
Exemplo n.º 2
0
void ContentsView::gotoReference() {
	model()->removeAllMarks();
	const size_t selected = currentTextViewParagraph();
	highlightParagraph(selected);
	gotoParagraph(selected);
	scrollPage(false, ZLTextView::SCROLL_PERCENTAGE, 40);
}
Exemplo n.º 3
0
QString EMailQuoteHighlighter::highlightText( const QString &text,
                                              const QColor &quoteDepth1,
                                              const QColor &quoteDepth2,
                                              const QColor &quoteDepth3 )
{
  const QStringList splitList = text.split( QLatin1Char( '\n' ) );
  QString result;
  QStringList::const_iterator it = splitList.constBegin();
  QStringList::const_iterator end = splitList.constEnd();
  while ( it != end ) {
    result.append( highlightParagraph( ( *it ) + QLatin1Char( '\n' ),
                                       quoteDepth1, quoteDepth2, quoteDepth3 ) );
    ++it;
  }
  return result;
}
Exemplo n.º 4
0
void CollectionView::selectBook(BookDescriptionPtr book) {
	mySelectedBook = book;

	if (myDoUpdateModel) {
		shared_ptr<ZLTextModel> oldModel = model();
		setModel(0, "");
		((CollectionModel&)*oldModel).update();
		setModel(oldModel, "");
		myDoUpdateModel = false;
	}

	if (!book.isNull()) {
		collectionModel().removeAllMarks();
		const std::vector<int> &toSelect = collectionModel().paragraphIndicesByBook(book);
		for (std::vector<int>::const_iterator it = toSelect.begin(); it != toSelect.end(); ++it) {
			highlightParagraph(*it);
		}
		if (!toSelect.empty()) {
			preparePaintInfo();
			gotoParagraph(toSelect[toSelect.size() - 1]);
			scrollPage(false, ZLTextView::SCROLL_PERCENTAGE, 40);
		}
	}
}