moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kwordquiz / src / multipleview.cpp
blobed48e3b4a372f8e43f9c15deacd75f5ea3ebbd99
1 /* This file is part of KWordQuiz
2 Copyright (C) 2003 Peter Hedlund <peter@peterandlinda.com>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.
19 #include <qlabel.h>
20 #include <qradiobutton.h>
22 #include <kiconloader.h>
23 #include <klocale.h>
24 #include <knotifyclient.h>
26 #include "kwordquiz.h"
27 #include "multipleview.h"
28 #include "prefs.h"
30 MultipleView::MultipleView(QWidget *parent, const char *name, WFlags f)
31 : MultipleViewBase(parent, name, f)
33 m_score = new WQScore();
37 MultipleView::~MultipleView()
40 void MultipleView::setQuiz(WQQuiz *quiz)
42 m_quiz = quiz;
45 void MultipleView::init()
48 m_score ->setQuestionCount(m_quiz->questionCount());
49 m_score ->setAsPercent(Prefs::percent());
50 m_question = 0;
51 m_error = 0;
53 opt1->show();
54 opt2->show();
55 opt3->show();
57 lblQuestion -> setFont(Prefs::editorFont());
58 lblPreviousQuestion -> setFont(Prefs::editorFont());
59 lblYourAnswer -> setFont(Prefs::editorFont());
60 lblCorrect -> setFont(Prefs::editorFont());
61 opt1->setFont(Prefs::editorFont());
62 opt2->setFont(Prefs::editorFont());
63 opt3->setFont(Prefs::editorFont());
65 picAnswered->clear();
66 picCorrect->clear();
67 picError->clear();
69 lblPreviousQuestionHeader->clear();
70 lblPreviousQuestion->clear();
71 lblYourAnswerHeader->clear();
72 lblYourAnswer->clear();
73 lblCorrectHeader->clear();
74 lblCorrect->clear();
76 picPrevious->clear();
77 picYourAnswer->clear();
78 picCorrectAnswer->clear();
80 KWordQuizApp *win=(KWordQuizApp *) parent();
81 win->actionCollection()->action("quiz_check")->setEnabled(true);
82 win->actionCollection()->action("quiz_repeat_errors")->setEnabled(false);
84 updateScore();
85 showQuestion(0);
88 void MultipleView::slotCheck()
90 KWordQuizApp *win=(KWordQuizApp *) parent();
91 if (win->actionCollection()->action("quiz_check")->isEnabled())
94 QString ans;
95 bool oneIsChecked = false;
97 if (opt1->isChecked())
99 ans = opt1->text().mid(3, opt1->text().length());
100 oneIsChecked = true;
103 if (opt2->isChecked())
105 ans = opt2->text().mid(3, opt2->text().length());
106 oneIsChecked = true;
109 if (opt3->isChecked())
111 ans = opt3->text().mid(3, opt3->text().length());
112 oneIsChecked = true;
115 if (!oneIsChecked)
116 return;
118 bool fIsCorrect = m_quiz->checkAnswer(m_question, ans);
120 if (fIsCorrect)
123 picYourAnswer->setPixmap(KGlobal::iconLoader()->loadIcon("check", KIcon::Panel));
124 lblCorrectHeader->clear();
125 picCorrectAnswer->clear();
126 lblCorrect->clear();
127 m_score->countIncrement(WQScore::cdCorrect);
128 updateScore();
129 KNotifyClient::event(winId(), "QuizCorrect", i18n("Your answer was correct!"));
131 else
133 m_error++;
135 picYourAnswer->setPixmap(KGlobal::iconLoader()->loadIcon("error", KIcon::Panel));
137 lblCorrect->setText(m_quiz->answer(m_question));
138 //lblCorrect->setFont(m_quiz->fontAnswer(m_question));
139 picCorrectAnswer->setPixmap(KGlobal::iconLoader()->loadIcon("check", KIcon::Panel));
140 lblCorrectHeader->setText(i18n("Correct Answer"));
141 m_score->countIncrement(WQScore::cdError);
142 updateScore();
143 KNotifyClient::event(winId(), "QuizError", i18n("Your answer was incorrect."));
146 lblPreviousQuestionHeader->setText(i18n("Previous Question"));
147 lblPreviousQuestion->setText(m_quiz->question(m_question));
148 //lblPreviousQuestion->setFont(m_quiz->fontQuestion(m_question));
149 picPrevious->setPixmap(KGlobal::iconLoader()->loadIcon("question", KIcon::Panel));
151 lblYourAnswerHeader->setText(i18n("Your Answer"));
152 lblYourAnswer->setText(m_quiz->yourAnswer(m_question, ans));
153 //lblYourAnswer->setFont(m_quiz->fontAnswer(m_question));
155 if (++m_question < m_quiz->questionCount())
157 showQuestion(m_question);
159 else
161 m_quiz->finish();
162 win->actionCollection()->action("quiz_check")->setEnabled(false);
163 win->actionCollection()->action("quiz_repeat_errors")->setEnabled((m_error > 0));
165 lblQuestionLanguage->setText(i18n("Summary"));
166 lblQuestion->clear();
167 lblAnswerLanguage->clear();
168 opt1->hide();
169 opt2->hide();
170 opt3->hide();
171 picQuestion->setPixmap(KGlobal::iconLoader()->loadIcon("kwordquiz", KIcon::Panel));
172 picAnswer->clear();
177 void MultipleView::slotOpt1Clicked()
179 if (Prefs::autoCheck())
180 slotCheck();
181 else
183 opt2->setChecked(false);
184 opt3->setChecked(false);
188 void MultipleView::slotOpt2Clicked()
190 if (Prefs::autoCheck())
191 slotCheck();
192 else
194 opt1->setChecked(false);
195 opt3->setChecked(false);
199 void MultipleView::slotOpt3Clicked()
201 if (Prefs::autoCheck())
202 slotCheck();
203 else
205 opt1->setChecked(false);
206 opt2->setChecked(false);
210 void MultipleView::slotRestart()
212 m_quiz->activateBaseList();
213 init();
216 void MultipleView::slotRepeat()
218 m_quiz->activateErrorList();
219 init();
222 void MultipleView::updateScore()
224 QString s;
225 s = s.setNum(m_quiz->questionCount(), 10);
226 lblScoreCount->setText(s);
227 picCount->setPixmap(KGlobal::iconLoader()->loadIcon("kwordquiz", KIcon::Panel));
229 s = m_score->answerText();
230 lblScoreAnswered->setText(s);
231 if (!s.isEmpty())
232 picAnswered->setPixmap(KGlobal::iconLoader()->loadIcon("question", KIcon::Panel));
234 s = m_score->correctText();
235 lblScoreCorrect->setText(s);
236 if (!s.isEmpty())
237 picCorrect->setPixmap(KGlobal::iconLoader()->loadIcon("check", KIcon::Panel));
239 s = m_score->errorText();
240 lblScoreError->setText(s);
241 if (!s.isEmpty())
242 picError->setPixmap(KGlobal::iconLoader()->loadIcon("error", KIcon::Panel));
247 \fn MultipleView::showQuestion(int i)
249 void MultipleView::showQuestion(int i)
252 lblQuestionLanguage -> setText(m_quiz ->langQuestion(i));
253 lblQuestion -> setText(m_quiz ->question(i));
254 //lblQuestion -> setFont(m_quiz->fontQuestion(i));
256 picQuestion->setPixmap(KGlobal::iconLoader()->loadIcon(m_quiz->quizIcon(i, WQQuiz::qiLeftCol), KIcon::Panel));
258 lblAnswerLanguage -> setText(m_quiz ->langAnswer(i));
260 //opt1->setFont(m_quiz->fontAnswer(i));
261 //opt2->setFont(m_quiz->fontAnswer(i));
262 //opt3->setFont(m_quiz->fontAnswer(i));
264 QStringList sl = m_quiz->multiOptions(i);
265 QString s[10];
266 int j = 0;
267 for(QStringList::Iterator it = sl.begin(); it != sl.end(); ++it)
269 s[j] = *it;
270 j++;
273 opt1->setText("&1 " + s[0]);
274 opt2->setText("&2 " + s[1]);
275 opt3->setText("&3 " + s[2]);
277 opt1->setChecked(false);
278 opt2->setChecked(false);
279 opt3->setChecked(false);
281 picAnswer->setPixmap(KGlobal::iconLoader()->loadIcon(m_quiz->quizIcon(i, WQQuiz::qiRightCol), KIcon::Panel));
284 void MultipleView::slotApplySettings( )
286 m_score ->setAsPercent(Prefs::percent());
287 updateScore();
290 #include "multipleview.moc"