summaryrefslogtreecommitdiff
path: root/utils/themeeditor/parsetreenode.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor/parsetreenode.cpp')
-rw-r--r--utils/themeeditor/parsetreenode.cpp228
1 files changed, 177 insertions, 51 deletions
diff --git a/utils/themeeditor/parsetreenode.cpp b/utils/themeeditor/parsetreenode.cpp
index 77ec897dd7..ccfac615be 100644
--- a/utils/themeeditor/parsetreenode.cpp
+++ b/utils/themeeditor/parsetreenode.cpp
@@ -1,74 +1,200 @@
1#include "parsetreenode.h" 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 ****************************************************************************/
2 21
3ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent, 22extern "C"
4 bool tree)
5{ 23{
24#include "symbols.h"
25}
6 26
7 if(tree) 27#include "parsetreenode.h"
8 { 28
9 while(data) 29/* Root element constructor */
10 { 30ParseTreeNode::ParseTreeNode(struct skin_element* data)
11 appendChild(new ParseTreeNode(data, this, false)); 31 : parent(0), element(0), param(0), children()
12 data = data->next; 32{
13 } 33 while(data)
14 parentLink = 0;
15 }
16 else
17 { 34 {
18 element = data; 35 children.append(new ParseTreeNode(data, this));
19 parentLink = parent; 36 data = data->next;
20 } 37 }
21
22} 38}
23 39
24ParseTreeNode::ParseTreeNode(struct skin_tag_parameter* param, 40/* Normal element constructor */
25 ParseTreeNode* parent) 41ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent)
26 :parentLink(parent), element(0), param(param) 42 : parent(parent), element(data), param(0), children()
27{ 43{
44 switch(element->type)
45 {
28 46
29} 47 case TAG:
48 for(int i = 0; i < element->params_count; i++)
49 {
50 if(element->params[i].type == skin_tag_parameter::CODE)
51 children.append(new ParseTreeNode(element->params[i].data.code,
52 this));
53 else
54 children.append(new ParseTreeNode(&element->params[i], this));
55 }
56 break;
30 57
58 /* CONDITIONAL and SUBLINES fall through to the same code */
59 case CONDITIONAL:
60 case SUBLINES:
61 for(int i = 0; i < element->children_count; i++)
62 {
63 children.append(new ParseTreeNode(data->children[i], this));
64 }
65 break;
31 66
32ParseTreeNode::~ParseTreeNode() 67 case LINE:
33{ 68 for(struct skin_element* current = data->children[0]; current;
34 qDeleteAll(children); 69 current = current->next)
35} 70 {
71 children.append(new ParseTreeNode(current, this));
72 }
73 break;
36 74
37void ParseTreeNode::appendChild(ParseTreeNode* child) 75 default:
38{ 76 break;
39 children.append(child); 77 }
40} 78}
41 79
42ParseTreeNode* ParseTreeNode::child(int row) 80/* Parameter constructor */
81ParseTreeNode::ParseTreeNode(skin_tag_parameter *data, ParseTreeNode *parent)
82 : parent(parent), element(0), param(data), children()
43{ 83{
44 return children[row];
45}
46 84
47int ParseTreeNode::childCount() const
48{
49 return children.count();
50} 85}
51 86
52int ParseTreeNode::columnCount() const 87QString ParseTreeNode::genCode() const
53{ 88{
54 return 2; 89 QString buffer = "";
55}
56 90
57QVariant ParseTreeNode::data(int column) const 91 if(element)
58{ 92 {
59 if(column == 0) 93 switch(element->type)
60 return element->type; 94 {
95 case LINE:
96 for(int i = 0; i < children.count(); i++)
97 {
98 /*
99 Adding a % in case of tag, because the tag rendering code
100 doesn't insert its own
101 */
102 if(children[i]->element->type == TAG)
103 buffer.append(TAGSYM);
104 buffer.append(children[i]->genCode());
105 }
106 break;
107
108 case SUBLINES:
109 for(int i = 0; i < children.count(); i++)
110 {
111 buffer.append(children[i]->genCode());
112 if(i != children.count() - 1)
113 buffer.append(MULTILINESYM);
114 }
115 break;
116
117 case CONDITIONAL:
118 /* Inserts a %?, the tag renderer doesn't deal with the TAGSYM */
119 buffer.append(TAGSYM);
120 buffer.append(CONDITIONSYM);
121 buffer.append(children[0]->genCode());
122
123 /* Inserting the sublines */
124 buffer.append(ENUMLISTOPENSYM);
125 for(int i = 1; i < children.count(); i++)
126 {
127 buffer.append(children[i]->genCode());
128 if(i != children.count() - 1)
129 buffer.append(ENUMLISTSEPERATESYM);
130 }
131 buffer.append(ENUMLISTCLOSESYM);
132 break;
133
134 case TAG:
135 /* When generating code, we DO NOT insert the leading TAGSYM, leave
136 * the calling functions to handle that
137 */
138 buffer.append(element->name);
139
140 if(element->params_count > 0)
141 {
142 /* Rendering parameters if there are any */
143 buffer.append(ARGLISTOPENSYM);
144 for(int i = 0; i < children.count(); i++)
145 {
146 buffer.append(children[i]->genCode());
147 if(i != children.count() - 1)
148 buffer.append(ARGLISTSEPERATESYM);
149 }
150 buffer.append(ARGLISTCLOSESYM);
151 }
152 break;
153
154 case NEWLINE:
155 buffer.append('\n');
156 break;
157
158 case TEXT:
159 buffer.append(element->text);
160 break;
161
162 case COMMENT:
163 buffer.append(COMMENTSYM);
164 buffer.append(element->text);
165 break;
166 }
167 }
168 else if(param)
169 {
170 switch(param->type)
171 {
172 case skin_tag_parameter::STRING:
173 buffer.append(param->data.text);
174 break;
175
176 case skin_tag_parameter::NUMERIC:
177 buffer.append(QString::number(param->data.numeric, 10));
178 break;
179
180 case skin_tag_parameter::DEFAULT:
181 buffer.append(DEFAULTSYM);
182 break;
183
184 }
185 }
61 else 186 else
62 return element->line; 187 {
63} 188 for(int i = 0; i < children.count(); i++)
64int ParseTreeNode::row() const 189 buffer.append(children[i]->genCode());
65{ 190 }
66 if(parentLink)
67 return parentLink->children.indexOf(const_cast<ParseTreeNode*>(this));
68 return 0;
69}
70 191
71ParseTreeNode* ParseTreeNode::parent() 192 return buffer;
72{
73 return parentLink;
74} 193}
194/*
195ParseTreeNode* child(int row);
196int numChildren() const;
197QVariant data(int column) const;
198int getRow() const;
199ParseTreeNode* getParent();
200*/