Ejemplo n.º 1
0
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;
    }
}
Ejemplo n.º 2
0
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;
    }
}
Ejemplo n.º 3
0
// <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);
        }
    }

}
Ejemplo n.º 4
0
void KDiffTextEdit::applySyntaxHighlight()
{
  // the diff has been loaded so we apply a simple highlighting
  static QColor cAdded( 190, 190, 237);
  static QColor cRemoved( 190, 237, 190 );

  if ( !_highlight )
    return;

  int paragCount = paragraphs();
  for ( int i = 0; i < paragCount; ++i ) {
    QString txt = text( i );
    if ( txt.length() > 0 ) {
      if ( txt.startsWith( "+" ) || txt.startsWith( ">" ) ) {
        setParagraphBackgroundColor( i, cAdded );
      } else if ( txt.startsWith( "-" ) || txt.startsWith( "<" ) ) {
        setParagraphBackgroundColor( i, cRemoved );
      }
    }
  }
}
Ejemplo n.º 5
0
int MsgView::setMsgBgColor(unsigned long uin, unsigned long id, unsigned long rgb, int start)
{
    QString pat;
    pat.sprintf("<a href=\"msg://%lu.%lu", uin, id);
    for (int n = start; n < paragraphs(); n++){
        if (text(n).find(pat) < 0) continue;
        pat = "<a href=\"msg://";
        for (n++; n < paragraphs(); n++){
            if (text(n).isEmpty()) break;
            if (text(n).find(pat) >= 0) break;
            setParagraphBackgroundColor(n, QColor(rgb));
        }
        return n;
    }
    log(L_WARN, "Message bg color not found");
    return paragraphs();
}