summaryrefslogtreecommitdiffstats
path: root/kgeography/src/boxasker.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce599e4f9f94b4eb00c1b5edb85bce5431ab3df2 (patch)
treed3bb9f5d25a2dc09ca81adecf39621d871534297 /kgeography/src/boxasker.cpp
downloadtdeedu-ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2.tar.gz
tdeedu-ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeedu@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kgeography/src/boxasker.cpp')
-rw-r--r--kgeography/src/boxasker.cpp128
1 files changed, 128 insertions, 0 deletions
diff --git a/kgeography/src/boxasker.cpp b/kgeography/src/boxasker.cpp
new file mode 100644
index 00000000..0634c622
--- /dev/null
+++ b/kgeography/src/boxasker.cpp
@@ -0,0 +1,128 @@
+/***************************************************************************
+ * Copyright (C) 2004-2005 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 <stdlib.h> // for RAND_MAX
+
+#include <kaccelmanager.h>
+#include <kapplication.h>
+#include <klocale.h>
+#include <kpushbutton.h>
+
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qradiobutton.h>
+#include <qvbuttongroup.h>
+
+#include "boxasker.h"
+#include "map.h"
+
+boxAsker::boxAsker(QWidget *parent, KGmap *m, QWidget *w, uint count) : askWidget(parent, m, w, count)
+{
+ p_lay = new QVBoxLayout(this);
+
+ QVButtonGroup *bg = new QVButtonGroup(this);
+ p_label = new QLabel(this);
+ p_rb = new QRadioButton*[4];
+ for(int i = 0; i < 4; i++)
+ {
+ p_rb[i] = new QRadioButton(bg);
+ p_rb[i]->setFocusPolicy(QWidget::StrongFocus);
+ }
+ p_accept = new KPushButton(this);
+
+ p_lay -> addWidget(p_label);
+ p_lay -> addWidget(bg, 1);
+ p_lay -> addWidget(p_accept);
+ KAcceleratorManager::setNoAccel(this);
+}
+
+boxAsker::~boxAsker()
+{
+ delete[] p_rb;
+}
+
+void boxAsker::setQuestion(const QString &q)
+{
+ p_label -> setText(q);
+}
+
+void boxAsker::keyReleaseEvent(QKeyEvent *e)
+{
+ if (e -> key() == Qt::Key_Return || e -> key() == Qt::Key_Enter) checkAnswer();
+ else askWidget::keyReleaseEvent(e);
+}
+
+void boxAsker::nextQuestionHook(const QString &division)
+{
+ QString otherDivision;
+ QStringList auxList;
+ int i;
+
+ setFocus();
+ for (i = 0; i < 4; i++) p_rb[i] -> setChecked(false);
+
+ auxList << division;
+
+ // we put the division in a random place
+ p_position = (int)((float)4 * kapp -> random() / (RAND_MAX + 1.0));
+ nextBoxAskerQuestionHook(division, p_position, true);
+
+ // we put other 3 names
+ i = 0;
+ while (i < 4)
+ {
+ // false because boxaskers never are clickOnDivision
+ otherDivision = p_map -> getRandomDivision(false);
+ while (auxList.find(otherDivision) != auxList.end()) otherDivision = p_map -> getRandomDivision(false);
+ if (i == p_position) i++;
+ if (i < 4 && nextBoxAskerQuestionHook(otherDivision, i, false)) i++;
+ auxList << otherDivision;
+ }
+}
+
+void boxAsker::checkAnswer()
+{
+ bool any, correct;
+ int i;
+
+ correct = false;
+ any = false;
+ i = 0;
+ while(!any && i < 4)
+ {
+ if (p_rb[i] -> isChecked())
+ {
+ any = true;
+ correct = (i == p_position);
+ }
+ else i++;
+ }
+
+ if (any)
+ {
+ setAnswerHook(i);
+ questionAnswered(correct);
+ nextQuestion();
+ }
+}
+
+void boxAsker::init()
+{
+ p_accept -> setText(i18n("&Accept"));
+
+ resetAnswers();
+ clearAsked();
+ nextQuestion();
+
+ p_accept -> disconnect();
+ connect(p_accept, SIGNAL(clicked()), this, SLOT(checkAnswer()));
+}
+
+#include "boxasker.moc"