void MsgViewBase::setBackground(unsigned n) { QColor c; bool bSet = false; for (unsigned i = n; i < (unsigned)paragraphs(); i++){ QString s = text(i); int n = s.find(MSG_HREF); if (n < 0){ if (bSet){ setParagraphBackgroundColor(i, c); }else{ clearParagraphBackground(i); } continue; } clearParagraphBackground(i); s = s.mid(n + strlen(MSG_HREF)); int p = s.find('\"'); if (p >= 0) s = s.left(p); getToken(s, ','); s = getToken(s, ','); if (s.isEmpty()){ bSet = false; continue; } c = QColor(atol(s.latin1())); bSet = true; } }
void MsgViewBase::setBackground(unsigned n) { QColor c; bool bSet = false; bool bSetColor = false; for (unsigned i = n; i < (unsigned)paragraphs(); i++){ QString s = text(i); int n = s.find(MSG_ANCHOR); if (n >= 0){ QString t = s.mid(n + strlen(MSG_BEGIN)); int p = t.find('\"'); if (p >= 0) t = t.left(p); getToken(t, ','); t = getToken(t, ','); if (t.isEmpty()){ bSet = false; }else{ c = QColor(atol(t.latin1())); bSet = true; } bSetColor = false; } n = s.find(MSG_BEGIN); if (n >= 0) bSetColor = true; if (bSet && bSetColor){ setParagraphBackgroundColor(i, c); }else{ clearParagraphBackground(i); } bSetColor = false; } }
void KDiffTextEdit::clearSyntaxHighlight() { int paragCount = paragraphs(); for ( int i = 0; i < paragCount; ++i ) { clearParagraphBackground( i ); } }
// <hack> // We have to use this function since Qt has no tag to set background color per-paragraph // from within HTML. See matching hack in MsgViewBase::messageText. void MsgViewBase::setBackground(unsigned n) { QColor bgcolor; bool bInMsg = false; bool bSet = false; QString sAnchor = QString::fromLatin1(MSG_ANCHOR), sBegin = QString::fromLatin1(MSG_BEGIN); int i; for (i = n; i >= 0; i--){ QString s = text(i); if (s.find(sAnchor) >= 0) break; } for (; i < paragraphs(); i++){ QString s = text(i); int anchorPos = s.find(sAnchor); if (anchorPos >= 0) { bInMsg = false; bSet = false; // This code could be a bit faster by making assumptions. // However, I prefer to be correct HTML-parser-wise. int idStart = anchorPos + sAnchor.length(); int idEnd = s.find('\"', idStart); if ((idStart >= 0) && (idEnd >= 0)) { QString id = s.mid(idStart, idEnd - idStart); // Parse the message id (msgId,backgroundColor,...) int bgcolorStart = id.find(','); if (bgcolorStart >= 0) { QString sBgcolor = id.mid(bgcolorStart + 1); int bgcolorEnd = sBgcolor.find(','); if (bgcolorEnd > 0) sBgcolor = sBgcolor.left(bgcolorEnd); if (!sBgcolor.isEmpty()) bgcolor = QColor(sBgcolor.toULong(&bSet)); } } } if (s.find(sBegin) >= 0) bInMsg = true; if (bInMsg && bSet){ setParagraphBackgroundColor(i, bgcolor); }else{ clearParagraphBackground(i); } } }