Vuo  2.0.3
VuoNodeClassListItemHighlighter.cc
Go to the documentation of this file.
1 
11 
12 const QRegExp VuoNodeClassListItemHighlighter::nodeNameTokenDelimiter = QRegExp("\\s+");
13 const QRegExp VuoNodeClassListItemHighlighter::nodeClassNameTokenDelimiter = QRegExp("\\.");
14 
19  QSyntaxHighlighter(parent)
20 {
21  nodeClassNameStartIndex = 0;
22 }
23 
28 {
29  QTextCharFormat highlightedTextFormat;
30  highlightedTextFormat.setFontWeight(QFont::Bold);
31 
32  for (vector<QString>::iterator term = targetTerms.begin(); term != targetTerms.end(); ++term)
33  {
34  int length = (*term).length();
35  QStringMatcher textFilterPattern((*term), Qt::CaseInsensitive);
36  int index = textFilterPattern.indexIn(text);
37 
38  while (index >= 0)
39  {
40  // Only highlight matches that begin at token boundaries within the displayed node name.
41  QRegExp currentDelimiter = (index < nodeClassNameStartIndex? nodeNameTokenDelimiter:nodeClassNameTokenDelimiter);
42  if ((index == 0) ||
43  (index == nodeClassNameStartIndex) ||
44  (currentDelimiter.exactMatch(text.at(index-1))) ||
45  ((index > nodeClassNameStartIndex) &&
46  // Transitions from lowercase to uppercase within the class name may be considered token boundaries.
47  (QRegExp("([a-z0-9])").exactMatch(text.at(index-1)) && QRegExp("([A-Z])").exactMatch(text.at(index)))))
48  setFormat(index, length, highlightedTextFormat);
49 
50  index = textFilterPattern.indexIn(text, index + length);
51  }
52  }
53 }
54 
59 {
60  targetTerms.push_back(term);
61 }
62 
69 {
70  nodeClassNameStartIndex = index;
71 }