summaryrefslogtreecommitdiffstats
path: root/kverbos/kverbos/kverbosview.cpp
blob: ba277ead0739de6576a6c6543da1487c91605e70 (plain)
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/***************************************************************************
                          kverbosview.cpp  -  description
                             -------------------
    begin                : Die Mai  1 21:39:04 CEST 2001
    copyright            : (C) 2001 by Arnold Kraschinski
    email                : arnold.k67@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 <cstdlib>
 
// include files for TQt
#include <tqprinter.h>
#include <tqpainter.h>
#include <tqpushbutton.h>
#include <tqlabel.h>
#include <tqlineedit.h>
#include <tqprogressbar.h>


// application specific includes
#include "kverbosview.h"
#include "kverbosdoc.h"

#include "verbspanish.h"


KVerbosView::KVerbosView(TQWidget *tqparent, const char *name) : QLernen/*TQWidget*/(tqparent, name)
{
  // Hier wird gesetzt, wie der Hintergrund des Fensters zu zeichnen ist.
  setBackgroundMode(PaletteBackground);
  // Die gesamten Zeiger auf TQLineEdit in ein Feld umwandeln
  formEdit[0][0] = EditYo1;
  formEdit[1][0] = EditTu1;
  formEdit[2][0] = EditEl1;
  formEdit[3][0] = EditNosotros1;
  formEdit[4][0] = EditVosotros1;
  formEdit[5][0] = EditEllos1;
  formEdit[0][1] = EditYo2;
  formEdit[1][1] = EditTu2;
  formEdit[2][1] = EditEl2;
  formEdit[3][1] = EditNosotros2;
  formEdit[4][1] = EditVosotros2;
  formEdit[5][1] = EditEllos2;
  formEdit[0][2] = EditYo3;
  formEdit[1][2] = EditTu3;
  formEdit[2][2] = EditEl3;
  formEdit[3][2] = EditNosotros3;
  formEdit[4][2] = EditVosotros3;
  formEdit[5][2] = EditEllos3;
  // einige Schalterbezeichnungen müssen richtiggestellt werden.
  ButtonN->setText("ñ");
  ButtonA->setText("á");
  ButtonE->setText("é");
  ButtonI->setText("í");
  ButtonO->setText("ó");
  ButtonU->setText("ú");
  TextTu->setText("tú");
  EditAleman->setFocus();
  // Es muss ein Verb aus dem Dokument geholt werden, das dann in dem Fenster dargestellt
  // werden kann, wenn es ein Verb gibt. Ansonsten bleibt das Fenster leer.
  zeigeVerb();
  enteredCorrect = 0;
  verbsTrained = 0;
}

KVerbosView::~KVerbosView()
{
}

KVerbosDoc* KVerbosView::getDocument() const
{
  KVerbosApp *theApp=(KVerbosApp *) parentWidget();

  return theApp->getDocument();
}

void KVerbosView::print(TQPrinter *pPrinter)
{
  TQPainter printpainter;
  printpainter.begin(pPrinter);

  // TODO: add your printing code here

  printpainter.end();
}

// This funktion erases all accents from the letters of a string
TQString KVerbosView::deleteAccents(const TQString& s) const
{
  TQString s2 = s.simplifyWhiteSpace();
  if (!s2.isEmpty())
  {
    for (unsigned int i=0; i<s2.length(); i++)
    {
      TQString t = s2.mid(i, 1);
      if (t == "á") s2.tqreplace(i, 1, "a");
      if (t == "é") s2.tqreplace(i, 1, "e");
      if (t == "í") s2.tqreplace(i, 1, "i");
      if (t == "ó") s2.tqreplace(i, 1, "o");
      if (t == "ú") s2.tqreplace(i, 1, "u");
      if (t == "ñ") s2.tqreplace(i, 1, "n");
    };
  };
  return s2;
}

void KVerbosView::slotN()
{
  TQLineEdit* pl = dynamic_cast<TQLineEdit*>(tqfocusWidget());
  if (pl)
  {
    pl->insert("ñ");
  };
}

void KVerbosView::slotA()
{
  TQLineEdit* pl = dynamic_cast<TQLineEdit*>(tqfocusWidget());
  if (pl)
  {
    pl->insert("á");
  };
}

void KVerbosView::slotE()
{
  TQLineEdit* pl = dynamic_cast<TQLineEdit*>(tqfocusWidget());
  if (pl)
  {
    pl->insert("é");
  };
}

void KVerbosView::slotI()
{
  TQLineEdit* pl = dynamic_cast<TQLineEdit*>(tqfocusWidget());
  if (pl)
  {
    pl->insert("í");
  };
}

void KVerbosView::slotO()
{
  TQLineEdit* pl = dynamic_cast<TQLineEdit*>(tqfocusWidget());
  if (pl)
  {
    pl->insert("ó");
  };
}

void KVerbosView::slotU()
{
  TQLineEdit* pl = dynamic_cast<TQLineEdit*>(tqfocusWidget());
  if (pl)
  {
    pl->insert("ú");
  };
}

// Alle Eingabefelder werden gelöscht, dabei muss auch die Schrift auf normal
// gesetzt werden, damit die korrigierten Felder wieder die normale Schrift erhalten.
void KVerbosView::slotClearAll()
{
	TQFont fontNormal = EditVerbo->font();
	TQPalette palette = EditVerbo->palette();
	EditAleman->clear();	
	EditAleman->setFont(fontNormal);
	EditAleman->setPalette(palette);
	for (int i=0; i<6; i++)
		for (int j=0; j<3; j++)
		{
			formEdit[i][j]->clear();
			formEdit[i][j]->setFont(fontNormal);
			formEdit[i][j]->setPalette(palette);
		};
}

// Die Ansicht wird aufgefordert das aktuelle Verb vom Dokument zu holen und es in dem
// Fenster zur Ansicht zu bringen. Dabei wird von dem Dokument nur ein Zeiger auf das
// Verb übergeben und die entsprechende Zeit, die gelernt werden soll.
void KVerbosView::zeigeVerb()
{
	// einen Zeiger auf das Dokument besorgen und ein Verb und seine Formen besorgen.
	KVerbosDoc* pDoc = getDocument();
	pDoc->getAuswahl(formen, zeitAuswahl);
	slotClearAll();
	// Die spanische Form der Verbes zur Anzeige bringen
	EditVerbo->setText(formen[6][0]);
	// Die Übungszeit zur Anzeige bringen.
	TextTiempo->setText(verbSpanish::timeNames[zeitAuswahl]);
	// Wenn kein reflexives Verb vorliegt, werden die Felder deaktiviert
	if (formen[0][0].isEmpty())
	{
		for (int i = yo; i<=ellos; i++)
			formEdit[i][0]->setEnabled(false);
	}
	else
	{
		for (int i = yo; i<=ellos; i++)
			formEdit[i][0]->setEnabled(true);
	};
	// Wenn eine einfache, nicht zusammengesetzte Form vorliegt, werden die
	// Felder deaktiviert.
	if (formen[0][1].isEmpty())
	{
		for (int i = yo; i<=ellos; i++)
			formEdit[i][1]->setEnabled(false);
	}
	else
	{
		for (int i = yo; i<=ellos; i++)
			formEdit[i][1]->setEnabled(true);
	};
	EditAleman->setFocus();
	corrected = false;
}

// Es soll das nächste Verb zur Anzeige gebracht werden.
void KVerbosView::slotWeiter()
{
	if (corrected)
	{
		verbsTrained++;
		emit numberTrainedChanged(verbsTrained);
		ProgressBar->setProgress(enteredCorrect*100/verbsTrained);
		zeigeVerb();
	}
	else
	{
		slotCorregir();
	};
}

// Die Eingaben in den Eingabefeldern sollen geprüft werden.
void KVerbosView::slotCorregir()
{
	bool richtig = true;
	TQFont fontNormal = EditVerbo->font();
	TQFont fontBold = EditVerbo->font();
	fontBold.setUnderline(true);
	TQPalette palette = EditVerbo->palette();
	palette.setColor(TQColorGroup::Text, red);
	palette.setColor(TQColorGroup::Base, white);
	if ( 0 > formen[6][1].tqfind(EditAleman->text().simplifyWhiteSpace(), 0))
	{
		EditAleman->setFont(fontBold);
		EditAleman->setPalette(palette);
		richtig = false;
	};
	// die Formen vergleichen
	KVerbosApp* kApp = dynamic_cast<KVerbosApp*>(tqparent());
	if (!kApp) {
		return;
	}
	for (int j=0; j<3; j++)
	{
		if (!formen[0][j].isEmpty())
		{
			for (int i=0; i<6; i++)
				if (kApp->doitStrict())
				{
					if (formEdit[i][j]->text().simplifyWhiteSpace() != formen[i][j])
					{
						formEdit[i][j]->setFont(fontBold);
						formEdit[i][j]->setPalette(palette);
						richtig = false;
					};
				}
				else
				{
					TQString s1 = formEdit[i][j]->text().simplifyWhiteSpace();
					TQString s2 = formen[i][j];
					if (deleteAccents(s1) != deleteAccents(s2))
					{
						formEdit[i][j]->setFont(fontBold);
						formEdit[i][j]->setPalette(palette);
						richtig = false;
					};
				};
		};
	};
	// Die Statistik muss angepasst werden.
	if (!corrected)
	{
		getDocument()->solved(richtig);
		if (richtig)
		{
			enteredCorrect++;
			emit numberCorrectChanged(enteredCorrect);
			emit informKFeeder(1);
			// Show the German expression. So the user can see the other German meanings
			// if there are some.
			EditAleman->setText(formen[6][1]);
		};
	};
	corrected = true;
}

// Die Lösung soll in dem Fenster präsentiert werden.
void KVerbosView::slotSolution()
{
	TQFont fontNormal = EditVerbo->font();
	EditAleman->setFont(fontNormal);
	EditAleman->setPalette(EditVerbo->palette());
	EditAleman->setText(formen[6][1]);		
	//
	for (int i=0; i<6; i++)
	  for (int j=0; j<3; j++)
	  {
		formEdit[i][j]->setFont(fontNormal);
		formEdit[i][j]->setPalette(EditVerbo->palette());
		formEdit[i][j]->setText(formen[i][j]);
	  };
	corrected = true;
}

// Wird bei einem bereits korrigiertem Verb eine weitere Eingabe gamacht, muss die
// Markierung, Unterstreichen oder Fettdruck, rückgängig gemacht und wieder der
// normale Font gesetzt werden.
void KVerbosView::slotFont()
{
	if (corrected)
	{
		TQFont fontNormal = EditVerbo->font();	
		TQLineEdit* pl = dynamic_cast<TQLineEdit*>(tqfocusWidget());
		if (0 != pl)
		{
			pl->setFont(fontNormal);
			pl->setPalette(EditVerbo->palette());
		};
	};
}

// Weil bei den Gerund- bzw. Perfektformen das eingeben der für alle Personen
// gleichen Formen langweilig ist und es auch nicht gut ist, wenn man sechs mal
// die falsche Form eingibt, wird die Form aus dem yo-Eingabefeld in die anderen
// kopiert.
void KVerbosView::slotCopyText()
{
	// erst prüfen, ob so eine Zeitform vorliegt.
  if (zeitAuswahl >= MAX_TIEMPOS)
	{
  	TQString	s = formEdit[0][2]->text();
		for (int i=1; i<6; i++)
		{
			formEdit[i][2]->setText(s);
			if (corrected)
			{
    		TQFont fontNormal = EditVerbo->font();	
		    formEdit[i][2]->setFont(fontNormal);
			};
		};
	};
}

// tell the view that the user has changed. Training results are deleted and set to the
// initial values. A new verb is chosen. The function returns the training result of the
// old user.
int KVerbosView::userChanged(int& r1, int& r2)
{
		r1 = 0;
		r2 = verbsTrained;
		if (verbsTrained !=0)
			r1 = enteredCorrect*100/verbsTrained;
		enteredCorrect = 0;
		verbsTrained = 0;
		ProgressBar->setProgress(0);	
		emit numberTrainedChanged(verbsTrained);
		emit numberCorrectChanged(enteredCorrect);
		return r1;
}

#include "kverbosview.moc"