summaryrefslogtreecommitdiffstats
path: root/quanta/components/csseditor/qmyhighlighter.cpp
blob: 431bf6a51e3c7f0e8a5d7f189ef8c534c3e5a594 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/***************************************************************************
                          bashhighlighter.cpp  -  description
                             -------------------
    begin                : dom mar 16 2003
    copyright            : (C) 2003 by Emiliano Gulmini
    email                : emi_barbarossa@yahoo.it
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "qmyhighlighter.h"
#include <qregexp.h>
QMyHighlighter::QMyHighlighter(QTextEdit* Qtxt):QSyntaxHighlighter(Qtxt){
}
/*****************************************************************************/
QMyHighlighter::~QMyHighlighter(){
}

/*****************************************************************************/
int QMyHighlighter::highlightParagraph( const QString & text, int /*endStateOfLastPara*/ )
{
  //QRegExp pattern("\\s*\\{([\\w\\s\\d:;-\"]*)\\}\\s*");
  QRegExp pattern("([#:\\.\\w]*)\\s*\\{");
  int pos=pattern.search(text,0);
  int l=int(pattern.cap(1).length());

  setFormat(pos,l,QColor("red"));

  if( pos== -1)
    pos = 0;

  const int npos = pos+l;

  pattern.setPattern("\\s*([\\s\\w\\d-]*)\\s*:");
  pos=npos;
  while ( pos >= 0 ) {
        pos = pattern.search( text, pos );
        if ( pos > -1 ) {
            l = pattern.matchedLength();

            setFormat(pos,l,QColor("mediumvioletred"));
            pos  += pattern.matchedLength();
        }
    }
  pattern.setPattern(":\\s*([\\.\\#\\w\\s\\d-\\(\\)\",%/]*)\\s*;");
  pattern.setPattern(":\\s*([\\W\\w]*)\\s*;");
  pos=npos;
  while ( pos >= 0 ) {
        pos = pattern.search( text, pos );
        if ( pos > -1 ) {
            l = pattern.cap(1).length();
            setFormat(pos + 2 ,l,QColor("steelblue"));
            pos  += pattern.matchedLength();
        }
    }
   return 0;
}