1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
/***************************************************************************
* ktouchcolorscheme.cpp *
* --------------------- *
* Copyright (C) 2003-2006 by Andreas Nicolai *
* *
* 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. *
***************************************************************************/
#include "ktouchcolorscheme.h"
#include <tqfile.h>
#include <tqtextstream.h>
#include <tqdom.h>
#include <kdebug.h>
#include <klocale.h>
#include <ktempfile.h>
#include <kio/netaccess.h>
#define WRITE_COLOR(z,x,y) e = doc.createElement(x); \
n = doc.createTextNode( (y).name() ); \
e.appendChild(n); \
z.appendChild(e);
#define READ_COLOR(x,y) c = n.namedItem(x); \
if (!c.isNull()) y = TQColor(c.firstChild().nodeValue());
TQValueVector<KTouchColorScheme> KTouchColorScheme::m_colorSchemes;
void KTouchColorScheme::clear() {
// the default scheme is the classic one
m_teacherTextColor = TQColor("#000032");
m_teacherBackground = TQColor("#BEBEFF");
m_studentTextColor = TQColor("#003200");
m_studentBackground = TQColor("#9FFF9F");
m_errorTextColor = TQt::white;
m_errorBackground = TQColor("#AC0000");
m_frame = TQt::black;
m_background[0] = TQColor(255,238, 7); m_background[4] = TQColor(247,138,247);
m_background[1] = TQColor( 14,164,239); m_background[5] = TQColor(158,255,155);
m_background[2] = TQColor(158,255,155); m_background[6] = TQColor( 14,164,239);
m_background[3] = TQColor(252,138,138); m_background[7] = TQColor(255,238, 7);
m_text = TQt::black;
m_backgroundH = TQt::darkBlue;
m_textH = TQt::white;
m_cBackground = TQt::gray;
m_cText = TQt::black;
m_cBackgroundH = TQt::white;
m_cTextH = TQt::black;
m_default = false;
}
// ----------------------------------------------------------------------------
bool KTouchColorScheme::read(const TQDomNode& node) {
// kdDebug() << "[KTouchColorScheme::read] " << endl;
TQDomNode name = node.namedItem("Name");
if (name.isNull()) m_name = i18n("untitled color scheme");
else m_name = name.firstChild().nodeValue();
// kdDebug() << " Reading scheme = " << m_name << endl;
TQDomNode n = node.namedItem("LineColors");
if (!n.isNull()) {
TQDomNode c;
READ_COLOR("TeacherTextColor", m_teacherTextColor);
READ_COLOR("TeacherBackground", m_teacherBackground);
READ_COLOR("StudentTextColor", m_studentTextColor);
READ_COLOR("StudentBackground", m_studentBackground);
READ_COLOR("ErrorTextColor", m_errorTextColor);
READ_COLOR("ErrorBackground", m_errorBackground);
}
n = node.namedItem("KeyboardColors");
if (!n.isNull()) {
TQDomNode c;
READ_COLOR("KeyFrame", m_frame);
for (unsigned int i=0; i<8; ++i) {
READ_COLOR(TQString("KeyBack_%1").tqarg(i), m_background[i]);
}
READ_COLOR("KeyText", m_text);
READ_COLOR("KeyBackHigh", m_backgroundH);
READ_COLOR("KeyTextHigh", m_textH);
READ_COLOR("KeyBackControl", m_cBackground);
READ_COLOR("KeyTextControl", m_cText);
READ_COLOR("KeyBackControlHigh", m_cBackgroundH);
READ_COLOR("KeyTextControlHigh", m_cTextH);
}
return true;
}
// ----------------------------------------------------------------------------
void KTouchColorScheme::write(TQDomDocument& doc, TQDomElement& root) const {
//kdDebug() << "[KTouchColorScheme::write] " << endl;
TQDomElement element = doc.createElement("KTouchColorScheme");
// append name of color scheme
TQDomElement name = doc.createElement("Name");
TQDomText name_text;
if (m_name.isEmpty()) name_text = doc.createTextNode( i18n("untitled color scheme") );
else name_text = doc.createTextNode(m_name);
name.appendChild(name_text);
element.appendChild(name);
// store slide line colors
TQDomElement line_colors = doc.createElement("LineColors");
TQDomElement e;
TQDomText n;
WRITE_COLOR(line_colors, "TeacherTextColor", m_teacherTextColor);
WRITE_COLOR(line_colors, "TeacherBackground", m_teacherBackground);
WRITE_COLOR(line_colors, "StudentTextColor", m_studentTextColor);
WRITE_COLOR(line_colors, "StudentBackground", m_studentBackground);
WRITE_COLOR(line_colors, "ErrorTextColor", m_errorTextColor);
WRITE_COLOR(line_colors, "ErrorBackground", m_errorBackground);
element.appendChild(line_colors);
// done with slide line colors
// write key drawing colors
TQDomElement key_colors = doc.createElement("KeyboardColors");
WRITE_COLOR(key_colors, "KeyFrame", m_frame);
for (unsigned int i=0; i<8; ++i) {
WRITE_COLOR(key_colors, TQString("KeyBack_%1").tqarg(i), m_background[i]);
}
WRITE_COLOR(key_colors, "KeyText", m_text);
WRITE_COLOR(key_colors, "KeyBackHigh", m_backgroundH);
WRITE_COLOR(key_colors, "KeyTextHigh", m_textH);
WRITE_COLOR(key_colors, "KeyBackControl", m_cBackground);
WRITE_COLOR(key_colors, "KeyTextControl", m_cText);
WRITE_COLOR(key_colors, "KeyBackControlHigh", m_cBackgroundH);
WRITE_COLOR(key_colors, "KeyTextControlHigh", m_cTextH);
element.appendChild(key_colors);
root.appendChild(element);
}
// ----------------------------------------------------------------------------
bool KTouchColorScheme::readList(TQWidget * window, const KURL& url) {
if (url.isEmpty()) return false;
//kdDebug() << "[KTouchColorScheme::readList] " << endl;
//kdDebug() << " url = '" << url.url() << "'" << endl;
TQString tmp_file;
bool result = KIO::NetAccess::download(url, tmp_file, window);
if (result) {
// Ok, that was successful, try to parse the XML doc now
TQFile infile(tmp_file);
if ( !infile.open( IO_ReadOnly ) ) {
KIO::NetAccess::removeTempFile(tmp_file);
return false; // Bugger it... couldn't open it...
}
TQDomDocument doc;
doc.setContent( &infile );
// read the document
TQDomNodeList schemes = doc.elementsByTagName("KTouchColorScheme");
int num = schemes.count();
if (num > 0) {
//kdDebug() << " reading " << schemes.count() << " color maps..." << endl;
for (int i=0; i<num; ++i) {
KTouchColorScheme scheme;
if (scheme.read(schemes.item(i)))
m_colorSchemes.append(scheme);
}
}
}
KIO::NetAccess::removeTempFile(tmp_file);
return result;
}
// ----------------------------------------------------------------------------
bool KTouchColorScheme::writeList(TQWidget * window, const KURL& url) {
// create the XML document and root node
TQDomDocument doc;
TQDomElement root = doc.createElement( "KTouchColorSchemeCollection" );
doc.appendChild(root);
// write all the non-default color schemes
for (TQValueVector<KTouchColorScheme>::const_iterator it = m_colorSchemes.constBegin();
it != m_colorSchemes.constEnd(); ++it)
{
if (!it->m_default) it->write(doc, root);
}
// and save it
TQString tmp_file;
KTempFile *temp=0;
if (url.isLocalFile())
tmp_file=url.path(); // for local files the path is sufficient
else {
temp=new KTempFile; // for remote files create a temporary file first
temp->setAutoDelete(true); // so we don't have to delete the file ourselves
tmp_file=temp->name();
}
TQFile outfile(tmp_file);
if ( !outfile.open( IO_WriteOnly ) ) {
if (temp) delete temp;
kdDebug() << "Error creating tmp file '"+tmp_file+"' for writing color map!" << endl;
return false;
}
TQTextStream out( &outfile );
out << doc.toString();
outfile.close();
// if we have a temporary file, we still need to upload it
if (temp) {
KIO::NetAccess::upload(tmp_file, url, window);
delete temp;
}
return true;
}
// ----------------------------------------------------------------------------
void KTouchColorScheme::createDefaults() {
m_colorSchemes.clear();
KTouchColorScheme color;
color.m_default = true;
color.m_name = i18n("Black & White");
color.m_teacherTextColor = TQt::black;
color.m_teacherBackground = TQt::white;
color.m_studentTextColor = TQt::black;
color.m_studentBackground = TQt::white;
color.m_errorTextColor = TQt::white;
color.m_errorBackground = TQt::black;
color.m_frame = TQt::black;
for (int i=0; i<8; ++i)
color.m_background[i] = TQt::white;
color.m_text = TQt::black;
color.m_backgroundH = TQt::black;
color.m_textH = TQt::white;
color.m_cBackground = TQt::gray;
color.m_cText = TQt::black;
color.m_cBackgroundH = TQt::white;
color.m_cTextH = TQt::black;
m_colorSchemes.push_back(color);
color.m_name = i18n("Classic");
color.m_teacherTextColor = TQColor("#000032");
color.m_teacherBackground = TQColor("#BEBEFF");
color.m_studentTextColor = TQColor("#003200");
color.m_studentBackground = TQColor("#9FFF9F");
color.m_errorTextColor = TQt::white;
color.m_errorBackground = TQColor("#AC0000");
color.m_frame = TQt::black;
color.m_background[0] = TQColor(255,238, 7); color.m_background[4] = TQColor(247,138,247);
color.m_background[1] = TQColor( 14,164,239); color.m_background[5] = TQColor(158,255,155);
color.m_background[2] = TQColor(158,255,155); color.m_background[6] = TQColor( 14,164,239);
color.m_background[3] = TQColor(252,138,138); color.m_background[7] = TQColor(255,238, 7);
color.m_text = TQt::black;
color.m_backgroundH = TQt::darkBlue;
color.m_textH = TQt::white;
color.m_cBackground = TQt::gray;
color.m_cText = TQt::black;
color.m_cBackgroundH = TQt::white;
color.m_cTextH = TQt::black;
m_colorSchemes.push_back(color);
color.m_name = i18n("Deep Blue");
color.m_teacherTextColor = TQt::white;
color.m_teacherBackground = TQColor( 0, 39, 80);
color.m_studentTextColor = TQt::white;
color.m_studentBackground = TQColor( 39, 59,127);
color.m_errorTextColor = TQColor("#B5CFFF");
color.m_errorBackground = TQColor("#640000");
color.m_frame = TQColor(220,220,220);
color.m_background[0] = TQColor( 0, 39, 80); color.m_background[4] = TQColor( 24, 19, 72);
color.m_background[1] = TQColor( 39, 59,127); color.m_background[5] = TQColor( 8, 44,124);
color.m_background[2] = TQColor( 4, 39, 53); color.m_background[6] = TQColor( 10, 82,158);
color.m_background[3] = TQColor( 40, 32,121); color.m_background[7] = TQColor( 43, 60,124);
color.m_text = TQt::white;
color.m_backgroundH = TQColor(125,180,255);
color.m_textH = TQt::darkBlue;
color.m_cBackground = TQt::black;
color.m_cText = TQt::white;
color.m_cBackgroundH = TQColor(111,121,73);
color.m_cTextH = TQt::white;
m_colorSchemes.push_back(color);
color.m_name = i18n("Stripy");
color.m_teacherTextColor = TQt::white;
color.m_teacherBackground = TQColor( 39, 70, 227);
color.m_studentTextColor = TQt::white;
color.m_studentBackground = TQColor( 39, 70, 127);
color.m_errorTextColor = TQt::white;
color.m_errorBackground = TQt::darkGray;
color.m_frame = TQt::black;
for (int i=0; i<8; i=i+2)
color.m_background[i] = TQColor( 39, 70, 127);
for (int i=1; i<8; i=i+2)
color.m_background[i] = TQt::darkGray;
color.m_text = TQt::black;
color.m_backgroundH = TQColor( 39, 70, 227);
color.m_textH = TQt::white;
color.m_cBackground = TQt::gray;
color.m_cText = TQt::black;
color.m_cBackgroundH = TQColor( 39, 70, 227);
color.m_cTextH = TQt::black;
m_colorSchemes.push_back(color);
}
// ----------------------------------------------------------------------------
|