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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
/***************************************************************************
base class for query dialogs
-----------------------------------------------------------------------
begin : Wed Feb 16 20:50:53 MET 2000
copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
(C) 2001 The KDE-EDU team
(C) 2005 Peter Hedlund <peter.hedlund@kdemail.net>
-----------------------------------------------------------------------
***************************************************************************
***************************************************************************
* *
* 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 "QueryDlgBase.h"
#include <tqlineedit.h>
#include <tqmultilineedit.h>
#include <tqradiobutton.h>
#include <LineList.h>
#include <klocale.h>
QueryDlgBase::QueryDlgBase(const TQString & caption, TQWidget *tqparent, const char *name, bool modal)
: KDialogBase(Swallow, caption, User1|User2, NoDefault, tqparent, name, modal, false,
KGuiItem(i18n("&Stop Query")), KGuiItem(i18n("&Edit Expression...")))
{
kv_doc = 0;
kv_exp = 0;
//type_timeout = kvq_notimeout;
}
QueryDlgBase::~QueryDlgBase ()
{
}
void QueryDlgBase::initFocus() const
{
//
}
bool QueryDlgBase::smartCompare (const TQString& s1, const TQString &s2,
int ) const
{
return s1.stripWhiteSpace() == s2.stripWhiteSpace();
}
bool QueryDlgBase::verifyField(TQLineEdit *field, const TQString &really)
{
if (!field->isEnabled() )
return true;
TQColorGroup u_normal = field->tqcolorGroup();
u_normal.setColor(TQColorGroup::Text, TQColor(0xff, 0x00, 0x00));
TQColorGroup k_normal = field->tqcolorGroup();
k_normal.setColor(TQColorGroup::Text, TQColor(0x00, 0x80, 0x00));
TQPalette known_pal( field->palette());
TQPalette unknown_pal( field->palette());
TQFont ft = field->font();
if (ft.weight() != TQFont::Bold) {
ft.setWeight(TQFont::Bold);
field->setFont(ft);
}
bool ret = false;
if (smartCompare(really, field->text(), 0) ) {
ret = true;
if ( known_pal.inactive() != k_normal
|| known_pal.active() != k_normal) {
// replace text colors
known_pal.setActive(k_normal);
known_pal.setInactive(k_normal);
field->setPalette( known_pal );
}
}
else
if ( unknown_pal.inactive() != u_normal
|| unknown_pal.active() != u_normal) {
// replace text colors
unknown_pal.setActive(u_normal);
unknown_pal.setInactive(u_normal);
field->setPalette( unknown_pal );
}
return ret;
}
void QueryDlgBase::resetField(TQLineEdit *field)
{
if (!field->isEnabled() )
return;
TQColorGroup normal = field->tqcolorGroup();
normal.setColor(TQColorGroup::Text, TQColor(0x00, 0x00, 0x00));
TQPalette pal( field->palette());
// replace text colors
if ( pal.inactive() != normal
|| pal.active() != normal) {
pal.setActive(normal);
pal.setInactive(normal);
field->setPalette( pal );
}
TQFont ft = field->font();
if (ft.weight() != TQFont::Normal) {
ft.setWeight(TQFont::Normal);
field->setFont(ft);
}
}
bool QueryDlgBase::verifyField(TQMultiLineEdit *field, const TQString &really, bool mixed)
{
if (!field->isEnabled())
return true;
TQColorGroup u_normal = field->tqcolorGroup();
u_normal.setColor(TQColorGroup::Text, TQColor(0xff, 0x00, 0x00));
TQColorGroup k_normal = field->tqcolorGroup();
k_normal.setColor(TQColorGroup::Text, TQColor(0x00, 0x80, 0x00));
TQPalette known_pal( field->palette());
TQPalette unknown_pal( field->palette());
TQFont ft = field->font();
if (ft.weight() != TQFont::Bold) {
ft.setWeight(TQFont::Bold);
field->setFont(ft);
}
bool ret = false;
bool equal = false;
LineList answerlist (really);
LineList inputlist (field->text());
if (!mixed) // no tolerance
equal = smartCompare(answerlist.allLines(), inputlist.allLines(), 0);
else {
bool all = true;
for (int ai = 0; ai < (int) answerlist.count(); ai++) {
bool found = false;
for (int ii = 0; ii < (int) inputlist.count(); ii++) {
if (answerlist.getLine (ai) == inputlist.getLine(ii) ) {
found = true;
break;
}
}
if (!found)
all = false;
}
if (all)
equal = true;
}
if (equal) {
ret = true;
if (known_pal.inactive() != k_normal
|| known_pal.active() != k_normal) {
// replace text colors
known_pal.setActive(k_normal);
known_pal.setInactive(k_normal);
field->setPalette( known_pal );
}
}
else
if ( unknown_pal.inactive() != u_normal
|| unknown_pal.active() != u_normal) {
// replace text colors
unknown_pal.setActive(u_normal);
unknown_pal.setInactive(u_normal);
field->setPalette( unknown_pal );
}
return ret;
}
void QueryDlgBase::resetField(TQMultiLineEdit *field)
{
if (!field->isEnabled() )
return;
TQColorGroup normal = field->tqcolorGroup();
normal.setColor(TQColorGroup::Text, TQColor(0x00, 0x00, 0x00));
TQPalette pal( field->palette());
// replace text colors
if ( pal.inactive() != normal
|| pal.active() != normal) {
pal.setActive(normal);
pal.setInactive(normal);
field->setPalette( pal );
}
TQFont ft = field->font();
if (ft.weight() != TQFont::Normal) {
ft.setWeight(TQFont::Normal);
field->setFont(ft);
}
}
void QueryDlgBase::verifyButton(TQRadioButton *radio, bool is_ok, TQWidget *widget2)
{
if (!radio->isEnabled() )
return;
TQColorGroup u_normal = radio->tqcolorGroup();
u_normal.setColor(TQColorGroup::Foreground, TQColor(0xff, 0x00, 0x00));
TQColorGroup k_normal = radio->tqcolorGroup();
k_normal.setColor(TQColorGroup::Foreground, TQColor(0x00, 0x80, 0x00));
TQPalette known_pal( radio->palette());
TQPalette unknown_pal( radio->palette());
// replace text colors
TQFont ft = radio->font();
if (ft.weight() != TQFont::Bold) {
ft.setWeight(TQFont::Bold);
radio->setFont(ft);
}
if (widget2 != 0) {
ft = widget2->font();
if (ft.weight() != TQFont::Bold) {
ft.setWeight(TQFont::Bold);
widget2->setFont(ft);
}
}
if (is_ok) {
if ( known_pal.inactive() != k_normal
|| known_pal.active() != k_normal) {
known_pal.setActive(k_normal);
known_pal.setInactive(k_normal);
radio->setPalette( known_pal );
if (widget2 != 0)
widget2->setPalette( known_pal );
}
}
else {
if ( unknown_pal.inactive() != u_normal
|| unknown_pal.active() != u_normal) {
unknown_pal.setActive(u_normal);
unknown_pal.setInactive(u_normal);
radio->setPalette( unknown_pal );
if (widget2 != 0)
widget2->setPalette( unknown_pal );
}
}
}
void QueryDlgBase::resetButton(TQRadioButton *radio, TQWidget *widget2)
{
if (!radio->isEnabled() )
return;
TQColorGroup normal = radio->tqcolorGroup();
normal.setColor(TQColorGroup::Foreground, TQColor(0x00, 0x00, 0x00));
TQPalette pal(radio->palette());
// replace text colors, avoid flickering
if ( pal.inactive() != normal
|| pal.active() != normal) {
pal.setActive(normal);
pal.setInactive(normal);
radio->setPalette( pal );
if (widget2 != 0)
widget2->setPalette( pal );
}
TQFont ft = radio->font();
if (ft.weight() != TQFont::Normal) {
ft.setWeight(TQFont::Normal);
radio->setFont(ft);
}
if (widget2 != 0) {
ft = widget2->font();
if (ft.weight() != TQFont::Normal) {
ft.setWeight(TQFont::Normal);
widget2->setFont(ft);
}
}
}
TQString QueryDlgBase::getOKComment(int percent_done)
{
return i18n("Well done, you knew the correct answer. %1% done.").tqarg(percent_done);
}
TQString QueryDlgBase::getTimeoutComment(int percent_done)
{
return i18n("You waited too long to enter the correct answer. %1% done.").tqarg(percent_done);
}
TQString QueryDlgBase::getNOKComment(int percent_done)
{
return i18n("Your answer was wrong. %1% done.").tqarg(percent_done);
}
void QueryDlgBase::closeEvent(TQCloseEvent * /*e*/)
{
emit sigQueryChoice(StopIt);
}
void QueryDlgBase::slotUser1()
{
emit sigQueryChoice(StopIt);
}
#include "QueryDlgBase.moc"
|