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.
20 #include <qradiobutton.h>
22 #include <kiconloader.h>
24 #include <knotifyclient.h>
26 #include "kwordquiz.h"
27 #include "multipleview.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
)
45 void MultipleView::init()
48 m_score
->setQuestionCount(m_quiz
->questionCount());
49 m_score
->setAsPercent(Prefs::percent());
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());
69 lblPreviousQuestionHeader
->clear();
70 lblPreviousQuestion
->clear();
71 lblYourAnswerHeader
->clear();
72 lblYourAnswer
->clear();
73 lblCorrectHeader
->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);
88 void MultipleView::slotCheck()
90 KWordQuizApp
*win
=(KWordQuizApp
*) parent();
91 if (win
->actionCollection()->action("quiz_check")->isEnabled())
95 bool oneIsChecked
= false;
97 if (opt1
->isChecked())
99 ans
= opt1
->text().mid(3, opt1
->text().length());
103 if (opt2
->isChecked())
105 ans
= opt2
->text().mid(3, opt2
->text().length());
109 if (opt3
->isChecked())
111 ans
= opt3
->text().mid(3, opt3
->text().length());
118 bool fIsCorrect
= m_quiz
->checkAnswer(m_question
, ans
);
123 picYourAnswer
->setPixmap(KGlobal::iconLoader()->loadIcon("check", KIcon::Panel
));
124 lblCorrectHeader
->clear();
125 picCorrectAnswer
->clear();
127 m_score
->countIncrement(WQScore::cdCorrect
);
129 KNotifyClient::event(winId(), "QuizCorrect", i18n("Your answer was correct!"));
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
);
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
);
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();
171 picQuestion
->setPixmap(KGlobal::iconLoader()->loadIcon("kwordquiz", KIcon::Panel
));
177 void MultipleView::slotOpt1Clicked()
179 if (Prefs::autoCheck())
183 opt2
->setChecked(false);
184 opt3
->setChecked(false);
188 void MultipleView::slotOpt2Clicked()
190 if (Prefs::autoCheck())
194 opt1
->setChecked(false);
195 opt3
->setChecked(false);
199 void MultipleView::slotOpt3Clicked()
201 if (Prefs::autoCheck())
205 opt1
->setChecked(false);
206 opt2
->setChecked(false);
210 void MultipleView::slotRestart()
212 m_quiz
->activateBaseList();
216 void MultipleView::slotRepeat()
218 m_quiz
->activateErrorList();
222 void MultipleView::updateScore()
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
);
232 picAnswered
->setPixmap(KGlobal::iconLoader()->loadIcon("question", KIcon::Panel
));
234 s
= m_score
->correctText();
235 lblScoreCorrect
->setText(s
);
237 picCorrect
->setPixmap(KGlobal::iconLoader()->loadIcon("check", KIcon::Panel
));
239 s
= m_score
->errorText();
240 lblScoreError
->setText(s
);
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
);
267 for(QStringList::Iterator it
= sl
.begin(); it
!= sl
.end(); ++it
)
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());
290 #include "multipleview.moc"