rockbox/utils/themeeditor/skinhighlighter.cpp
Robert Bieber 53b619c6e8 Theme Editor: Added a preferences dialog and allowed modification of the syntax highlighting and editor colors
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26640 a1c6a512-1295-4272-9138-f99709370657
2010-06-07 03:25:40 +00:00

172 lines
4.7 KiB
C++

/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2010 Robert Bieber
*
* 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.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "skinhighlighter.h"
#include <QSettings>
SkinHighlighter::SkinHighlighter(QTextDocument* doc)
:QSyntaxHighlighter(doc)
{
loadSettings();
}
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;
}
}
}
}
}
}
void SkinHighlighter::loadSettings()
{
QSettings settings;
settings.beginGroup("SkinHighlighter");
/* Loading the highlighting colors */
tag = settings.value("tagColor", QColor(180,0,0)).value<QColor>();
conditional = settings.value("conditionalColor",
QColor(0, 0, 180)).value<QColor>();
escaped = settings.value("escapedColor",
QColor(120,120,120)).value<QColor>();
comment = settings.value("commentColor",
QColor(0, 180, 0)).value<QColor>();
settings.endGroup();
rehighlight();
}