A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 172 lines 4.8 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2010 Robert Bieber 11 * 12 * This program is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; either version 2 15 * of the License, or (at your option) any later version. 16 * 17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 * KIND, either express or implied. 19 * 20 ****************************************************************************/ 21 22#include "skinhighlighter.h" 23 24#include <QSettings> 25 26SkinHighlighter::SkinHighlighter(QTextDocument* doc) 27 :QSyntaxHighlighter(doc) 28{ 29 loadSettings(); 30} 31 32SkinHighlighter::~SkinHighlighter() 33{ 34 35} 36 37void SkinHighlighter::highlightBlock(const QString& text) 38{ 39 for(int i = 0; i < text.length(); i++) 40 { 41 QChar c = text[i]; 42 43 /* Checking for delimiters */ 44 if(c == ARGLISTOPENSYM 45 || c == ARGLISTCLOSESYM 46 || c == ARGLISTSEPARATESYM) 47 setFormat(i, 1, tag); 48 49 if(c == ENUMLISTOPENSYM 50 || c == ENUMLISTCLOSESYM 51 || c == ENUMLISTSEPARATESYM) 52 setFormat(i, 1, conditional); 53 54 /* Checking for comments */ 55 if(c == COMMENTSYM) 56 { 57 setFormat(i, text.length() - i, comment); 58 return; 59 } 60 61 if(c == TAGSYM) 62 { 63 if(text.length() - i < 2) 64 return; 65 66 if(find_escape_character(text[i + 1].toLatin1())) 67 { 68 /* Checking for escaped characters */ 69 70 setFormat(i, 2, escaped); 71 i++; 72 } 73 else if(text[i + 1] != CONDITIONSYM) 74 { 75 /* Checking for normal tags */ 76 77 char lookup[3]; 78 const struct tag_info* found = 0; 79 80 /* First checking for a two-character tag name */ 81 lookup[2] = '\0'; 82 83 if(text.length() - i >= 3) 84 { 85 lookup[0] = text[i + 1].toLatin1(); 86 lookup[1] = text[i + 2].toLatin1(); 87 88 found = find_tag(lookup); 89 } 90 91 if(found) 92 { 93 setFormat(i, 3, tag); 94 i += 2; 95 } 96 else 97 { 98 lookup[1] = '\0'; 99 lookup[0] = text[i + 1].toLatin1(); 100 found = find_tag(lookup); 101 102 if(found) 103 { 104 setFormat(i, 2, tag); 105 i++; 106 } 107 } 108 109 } 110 else if(text[i + 1] == CONDITIONSYM) 111 { 112 /* Checking for conditional tags */ 113 114 if(text.length() - i < 3) 115 return; 116 117 char lookup[3]; 118 const struct tag_info* found = 0; 119 120 lookup[2] = '\0'; 121 122 if(text.length() - i >= 4) 123 { 124 lookup[0] = text[i + 2].toLatin1(); 125 lookup[1] = text[i + 3].toLatin1(); 126 127 found = find_tag(lookup); 128 } 129 130 if(found) 131 { 132 setFormat(i, 4, conditional); 133 i += 3; 134 } 135 else 136 { 137 lookup[1] = '\0'; 138 lookup[0] = text[i + 2].toLatin1(); 139 140 found = find_tag(lookup); 141 142 if(found) 143 { 144 setFormat(i, 3, conditional); 145 i += 2; 146 } 147 } 148 149 } 150 } 151 } 152} 153 154void SkinHighlighter::loadSettings() 155{ 156 QSettings settings; 157 158 settings.beginGroup("SkinHighlighter"); 159 160 /* Loading the highlighting colors */ 161 tag = settings.value("tagColor", QColor(180,0,0)).value<QColor>(); 162 conditional = settings.value("conditionalColor", 163 QColor(0, 0, 180)).value<QColor>(); 164 escaped = settings.value("escapedColor", 165 QColor(120,120,120)).value<QColor>(); 166 comment = settings.value("commentColor", 167 QColor(0, 180, 0)).value<QColor>(); 168 169 settings.endGroup(); 170 171 rehighlight(); 172}