From 6feac4a315574b9cc037a328018e6ba9398a77d5 Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Thu, 3 Jun 2010 07:38:59 +0000 Subject: Theme Editor: Added syntax highlighting git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26506 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/skinhighlighter.cpp | 132 ++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 utils/themeeditor/skinhighlighter.cpp (limited to 'utils/themeeditor/skinhighlighter.cpp') diff --git a/utils/themeeditor/skinhighlighter.cpp b/utils/themeeditor/skinhighlighter.cpp new file mode 100644 index 0000000000..4b8de9a804 --- /dev/null +++ b/utils/themeeditor/skinhighlighter.cpp @@ -0,0 +1,132 @@ +#include "skinhighlighter.h" + +SkinHighlighter::SkinHighlighter(QColor comment, QColor tag, QColor conditional, + QColor escaped, QTextDocument* doc) + :QSyntaxHighlighter(doc), + escaped(escaped), tag(tag), + conditional(conditional), comment(comment) +{ + +} + +SkinHighlighter::~SkinHighlighter() +{ + +} + +void SkinHighlighter::highlightBlock(const QString& text) +{ + for(int i = 0; i < text.length(); i++) + { + QChar c = text[i]; + + /* Checking for delimiters */ + if(c == ARGLISTOPENSYM + || c == ARGLISTCLOSESYM + || c == ARGLISTSEPERATESYM) + setFormat(i, 1, tag); + + if(c == ENUMLISTOPENSYM + || c == ENUMLISTCLOSESYM + || c == ENUMLISTSEPERATESYM) + setFormat(i, 1, conditional); + + /* Checking for comments */ + if(c == COMMENTSYM) + { + setFormat(i, text.length() - i, comment); + return; + } + + if(c == TAGSYM) + { + if(text.length() - i < 2) + return; + + if(find_escape_character(text[i + 1].toAscii())) + { + /* Checking for escaped characters */ + + setFormat(i, 2, escaped); + i++; + } + else if(text[i + 1] != CONDITIONSYM) + { + /* Checking for normal tags */ + + char lookup[3]; + struct tag_info* found = 0; + + /* First checking for a two-character tag name */ + lookup[2] = '\0'; + + if(text.length() - i >= 3) + { + lookup[0] = text[i + 1].toAscii(); + lookup[1] = text[i + 2].toAscii(); + + found = find_tag(lookup); + } + + if(found) + { + setFormat(i, 3, tag); + i += 2; + } + else + { + lookup[1] = '\0'; + lookup[0] = text[i + 1].toAscii(); + found = find_tag(lookup); + + if(found) + { + setFormat(i, 2, tag); + i++; + } + } + + } + else if(text[i + 1] == CONDITIONSYM) + { + /* Checking for conditional tags */ + + if(text.length() - i < 3) + return; + + char lookup[3]; + struct tag_info* found = 0; + + lookup[2] = '\0'; + + if(text.length() - i >= 4) + { + lookup[0] = text[i + 2].toAscii(); + lookup[1] = text[i + 3].toAscii(); + + found = find_tag(lookup); + } + + if(found) + { + setFormat(i, 4, conditional); + i += 3; + } + else + { + lookup[1] = '\0'; + lookup[0] = text[i + 2].toAscii(); + + found = find_tag(lookup); + + if(found) + { + setFormat(i, 3, conditional); + i += 2; + } + } + + } + } + } +} -- cgit v1.2.3