[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/work/soc-parley/parley/src/practice
From: David Capel <wot.narg () gmail ! com>
Date: 2008-07-10 17:38:48
Message-ID: 1215711528.597554.31614.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 830526 by capel:
Starting mixed letters
The code all works except that the letters are put in the wrong position. I need a \
mapToScene somewhere...
M +1 -1 TODO
M +2 -0 input.cpp
M +1 -2 input.h
M +62 -5 parleypracticemainwindow.cpp
M +1 -0 parleypracticemainwindow.h
M +64 -0 prompt.cpp
M +20 -1 prompt.h
--- branches/work/soc-parley/parley/src/practice/TODO #830525:830526
@@ -21,7 +21,7 @@
Modes to remake:
- * Mixed Letters
+ * Mixed Letters *----
* Multiple choice ****-
* Written *****
* Example
--- branches/work/soc-parley/parley/src/practice/input.cpp #830525:830526
@@ -50,6 +50,8 @@
QRect bounds = m_renderer->boundsOnElement(elementId).toRect();
setGeometry(view->mapToScene(bounds).boundingRect().toRect());
+
+ connect(this, SIGNAL(textChanged(const QString&)), this, \
SIGNAL(answerChanged(const QString&))); }
void TextualInput::slotEmitAnswer()
--- branches/work/soc-parley/parley/src/practice/input.h #830525:830526
@@ -41,10 +41,9 @@
void slotClear();
void slotShowSolution(const QString& solution);
void slotEmitAnswer();
-
signals:
void signalAnswer(const QString& answer);
-
+ void signalAnswerChanged(const QString& answer);
private:
KSvgRenderer* m_renderer;
};
--- branches/work/soc-parley/parley/src/practice/parleypracticemainwindow.cpp \
#830525:830526 @@ -53,7 +53,7 @@
ParleyPracticeMainWindow::ParleyPracticeMainWindow(QWidget *parent)
: KXmlGuiWindow(parent)
{
- setupBase("mc.desktop");
+ setupBase("default.desktop");
setupActions();
setupModeSpecifics();
@@ -214,14 +214,24 @@
// here is where we'll add new modes
void ParleyPracticeMainWindow::setupModeSpecifics()
{
- if (m_mode == Prefs::EnumTestType::WrittenTest)
+ switch (m_mode)
+ {
+ case Prefs::EnumTestType::WrittenTest:
setupWritten();
- else if (m_mode == Prefs::EnumTestType::MultipleChoiceTest)
+ break;
+ case Prefs::EnumTestType::MultipleChoiceTest:
setupMultipleChoice();
- else if (m_mode == Prefs::EnumTestType::ArticleTest)
+ break;
+ case Prefs::EnumTestType::ArticleTest:
setupArticle();
- else
+ break;
+ case Prefs::EnumTestType::MixedLettersTest:
+ setupMixedLetters();
+ break;
+ default:
kDebug() << "unhandled practice mode " << m_mode << " selected.";
+ break;
+ }
}
@@ -467,3 +477,50 @@
connect(mapper, SIGNAL(mapped(int)), input, SLOT(slotShortcutTriggered(int)));
}
+
+void ParleyPracticeMainWindow::setupMixedLetters()
+{
+
+ MixedLettersPrompt * prompt = new MixedLettersPrompt(m_renderer, m_view, \
"practice_text_background"); + connect(m_manager, SIGNAL(signalNewText(const \
QString&)), prompt, SLOT(slotSetText(const QString&))); +
+ TextualInput * input = new TextualInput(m_renderer, m_view, \
"practice_text_translation_background"); + m_scene->addWidget(input);
+ connect(input, SIGNAL(signalAnswer(const QString&)), this, \
SLOT(slotCheckAnswer(const QString&))); + connect(input, \
SIGNAL(signalAnswerChanged(const QString&)), prompt, SLOT(slotAnswerChanged(const \
QString&))); + connect(this, SIGNAL(signalShowSolution(const QString&, int)), \
input, SLOT(slotShowSolution(const QString&))); + \
connect(actionCollection()->action("check answer"), SIGNAL(triggered()), input, \
SLOT(slotEmitAnswer())); + connect(actionCollection()->action("continue"), \
SIGNAL(triggered()), input, SLOT(slotClear())); +
+ SvgBarStatistics * barstats = new SvgBarStatistics(m_renderer, "bar", \
"bar_background"); + m_scene->addItem(barstats);
+ connect(m_stats, SIGNAL(signalUpdateDisplay(Statistics*)), barstats, \
SLOT(slotUpdateDisplay(Statistics*))); +
+ StdButton * stdbutton = new StdButton(i18n("Check Answer"), m_renderer, m_view, \
"check_answer_and_continue_button"); + m_scene->addWidget(stdbutton);
+ connect(input, SIGNAL(returnPressed()), stdbutton, SLOT(slotActivated()));
+ connect(this, SIGNAL(signalCheckAnswerContinueActionsToggled(int)), stdbutton, \
SLOT(slotToggleText(int))); + connect(stdbutton, SIGNAL(signalCheckAnswer()), \
actionCollection()->action("check answer"), SIGNAL(triggered())); + \
connect(stdbutton, SIGNAL(signalContinue()), actionCollection()->action("continue"), \
SIGNAL(triggered())); + stdbutton->setVisible(true); // enable for now
+
+
+ Hint * hint = new Hint(this);
+ connect(actionCollection()->action("hint"), SIGNAL(triggered()), hint, \
SLOT(slotShowHint())); + // this is the hint for now :)
+ connect(hint, SIGNAL(signalShowHint()), actionCollection()->action("show \
solution"), SIGNAL(triggered())); + connect(hint, \
SIGNAL(signalAnswerTainted(Statistics::TaintReason)), m_stats, \
SLOT(slotTaintAnswer(Statistics::TaintReason))); +
+
+ if (Prefs::practiceTimeout() && Prefs::practiceTimeoutTimePerAnswer()) // \
timeout can't be 0 + {
+ kDebug() << "timer" << Prefs::practiceTimeout() << \
Prefs::practiceTimeoutTimePerAnswer(); + InvisibleTimer * timer = new \
InvisibleTimer(this); + \
timer->setLength(Prefs::practiceTimeoutTimePerAnswer()*1000); // seconds -> \
milliseconds + // when the timer triggers, it will assume their current input \
is their answer + connect(timer, SIGNAL(signalTimeout()), \
actionCollection()->action("check answer"), SIGNAL(triggered())); + \
connect(m_manager, SIGNAL(signalNewEntry()), timer, SLOT(slotStart())); + \
connect(input, SIGNAL(signalInput(const QString&)), timer, SLOT(slotStop())); + }
+
+}
--- branches/work/soc-parley/parley/src/practice/parleypracticemainwindow.h \
#830525:830526 @@ -58,6 +58,7 @@
void setupWritten();
void setupMultipleChoice();
void setupArticle();
+ void setupMixedLetters();
public slots:
void slotCheckAnswer(const QString& input);
void slotShowSolution();
--- branches/work/soc-parley/parley/src/practice/prompt.cpp #830525:830526
@@ -20,6 +20,8 @@
#include <KDebug>
#include <kio/netaccess.h>
+#include <KRandomSequence>
+#include <KRandom>
TextualPrompt::TextualPrompt ( KSvgRenderer * renderer, const QString& elementId ) :
m_renderer ( renderer )
@@ -148,3 +150,65 @@
}
setPixmap ( m_pic );
}
+
+
+MixedLettersPrompt::MixedLettersPrompt(KSvgRenderer * renderer, QGraphicsView * \
view, const QString& elementId, QWidget * parent) +: QWidget(parent), \
m_renderer(renderer), m_scene(view->scene()), m_view(view) +{
+ if (!renderer->elementExists(elementId))
+ {
+ setVisible(false);
+ kDebug() << "!! Element id doesn't exist:";
+ kDebug() << elementId << ":" << renderer->elementExists(elementId);
+ }
+
+ m_backgroundRect = renderer->boundsOnElement ( elementId );
+};
+
+void MixedLettersPrompt::slotSetText (const QString& solution )
+{
+ m_solution = solution;
+
+ // remove old items
+ foreach ( QGraphicsItem* item, m_letters) {
+ m_scene->removeItem(item);
+ delete item;
+ }
+ m_letters.clear();
+
+
+ QList<int> positions;
+ for ( int i = 0; i < solution.length(); i++ )
+ {
+ positions.append((m_backgroundRect.width()-20) * i/solution.length() + 10 \
); + }
+
+ KRandomSequence random;
+ for ( int i = 0; i < solution.length(); i++ )
+ {
+ QGraphicsTextItem* letter = new QGraphicsTextItem( QString(solution[i]) );
+ letter->translate(positions.takeAt( random.getLong(positions.size())),
+ m_backgroundRect.height()/4 - 5 + random.getLong( \
m_backgroundRect.height()/2 ) ); + m_letters.append(letter);
+ m_scene->addItem(letter);
+ letter->setPos(m_view->mapToScene(letter->x(), letter->y()));
+ }
+}
+
+void MixedLettersPrompt::slotAnswerChanged(const QString& answer)
+{
+ for ( int i = 0; i < m_solution.length(); i++ ) {
+ if ( answer[i] == m_solution[i] ) {
+ m_letters[i]->setHtml("<b><font color=\"#188C18\">" + m_solution[i] + \
"</font></b>"); + } else {
+// if ( i >= answerLineEdit->text().length() ) {
+ // no input yet
+ m_letters[i]->setHtml(QString(m_solution[i]));
+// } else {
+ // wrong
+// m_answerTextItems[i]->setHtml("<b><font color=\"#FF0000\">" + \
solution[i] + "</font></b>"); +// }
+ }
+ }
+}
+
--- branches/work/soc-parley/parley/src/practice/prompt.h #830525:830526
@@ -69,7 +69,7 @@
class ImagePrompt : public QLabel
{
- Q_OBJECT
+ Q_OBJECT
public:
@@ -85,5 +85,24 @@
};
+class MixedLettersPrompt : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ MixedLettersPrompt(KSvgRenderer * renderer, QGraphicsView * view, const \
QString& elementId, QWidget * parent = 0); + QStringList scramble(const \
QString& input); + public slots:
+ void slotSetText(const QString& solution);
+ void slotAnswerChanged(const QString& answer);
+ private:
+ KSvgRenderer * m_renderer;
+ QRectF m_backgroundRect;
+ QGraphicsScene* m_scene;
+ QGraphicsView* m_view;
+ QList<QGraphicsTextItem*> m_letters;
+ QString m_solution;
+};
+
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic