summaryrefslogtreecommitdiffstats
path: root/kgeography/src/answer.cpp
blob: 428ceb20d131de342d4287612c4f5b1740eb8a3d (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
/***************************************************************************
 *   Copyright (C) 2004 by Albert Astals Cid                               *
 *   tsdgeos@terra.es                                                      *
 *                                                                         *
 *   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 <tqimage.h>
#include <tqlabel.h>
#include <tqlayout.h>

#include <kdialog.h>

#include "answer.h"

userAnswer::userAnswer()
{
}

userAnswer::userAnswer(const userAnswer &r)
{
	p_question = r.p_question;
	p_answer = r.p_answer;
	p_correctAnswer = r.p_correctAnswer;
	p_correct = r.p_correct;
}

userAnswer &userAnswer::operator=(const userAnswer &r)
{
	p_question = r.p_question;
	p_answer = r.p_answer;
	p_correctAnswer = r.p_correctAnswer;
	p_correct = r.p_correct;
	return *this;
}

void userAnswer::setQuestion(TQVariant question)
{
	p_question = question;
}

void userAnswer::setAnswer(TQVariant answer)
{
	p_answer = answer;
}

void userAnswer::setAnswerCorrect(bool correct)
{
	p_correct = correct;
}

void userAnswer::setCorrectAnswer(TQVariant correctAnswer)
{
	p_correctAnswer = correctAnswer;
}

void userAnswer::putWidgets(TQWidget *w, TQGridLayout *lay, int row) const
{
	TQWidget *widgets[3];
	const TQVariant *v;
	
	for (int i = 0; i < 3; i++)
	{
		if (i == 0) v = &p_question;
		else if (i == 1) v = &p_answer;
		else v = &p_correctAnswer;
		
		if (v -> type() == TQVariant::String)
		{
			TQLabel *l;
			l = new TQLabel(w);
			l -> setText(v -> toString());
			l -> setMargin(KDialog::marginHint() / 2);
			widgets[i] = l;
		}
		else if (v -> type() == TQVariant::Color)
		{
			TQWidget *aux = new TQWidget(w);
			TQHBoxLayout *lay = new TQHBoxLayout(aux);
			
			TQFrame *inner = new TQFrame(aux);
			lay -> addWidget(inner);
			inner -> setBackgroundColor(v -> toColor());
			inner -> setLineWidth(1);
			lay -> setMargin(KDialog::marginHint() / 2);
			widgets[i] = aux;
		}
		else if (v -> type() == TQVariant::Image)
		{
			TQLabel *l;
			l = new TQLabel(w);
			l -> setPixmap(v -> toImage());
			l -> tqsetAlignment(TQt::AlignHCenter);
			l -> setMargin(KDialog::marginHint() / 2);
			widgets[i] = l;
		}
		
		lay -> addWidget(widgets[i], row, i + 1);
	}
	
	if (!p_correct)
	{
		TQColor back, fore;
		back = widgets[0] -> tqcolorGroup().highlight();
		fore = widgets[0] -> tqcolorGroup().highlightedText();
		for (int i = 0; i < 3; i++)
		{
			widgets[i] -> setPaletteBackgroundColor(back);
			widgets[i] -> setPaletteForegroundColor(fore);
		}
	}
}