From d6629ad5c4f9a450a13a8b89dde7838d3e69a050 Mon Sep 17 00:00:00 2001 From: Reto Zingg Date: Thu, 18 Mar 2010 01:05:14 +0200 Subject: [PATCH] TinyVocTrainer --- TinyVocTrainer/TinyVocTrainer.pro | 16 ++++ TinyVocTrainer/main.cpp | 10 ++ TinyVocTrainer/tinyvoctrainer.cpp | 153 ++++++++++++++++++++++++++++++ TinyVocTrainer/tinyvoctrainer.h | 43 +++++++++ 4 files changed, 222 insertions(+) create mode 100644 TinyVocTrainer/TinyVocTrainer.pro create mode 100644 TinyVocTrainer/main.cpp create mode 100644 TinyVocTrainer/tinyvoctrainer.cpp create mode 100644 TinyVocTrainer/tinyvoctrainer.h diff --git a/TinyVocTrainer/TinyVocTrainer.pro b/TinyVocTrainer/TinyVocTrainer.pro new file mode 100644 index 0000000..2f330f9 --- /dev/null +++ b/TinyVocTrainer/TinyVocTrainer.pro @@ -0,0 +1,16 @@ +# ------------------------------------------------- +# Project created by QtCreator 2010-03-17T19:16:34 +# ------------------------------------------------- +TARGET = TinyVocTrainer +TEMPLATE = app +LIBS += -L/home/rzingg/kedu/git/lib \ + -lkeduvocdocument +DEPENDPATH += . \ + /home/rzingg/kedu/git/lib +INCLUDEPATH += . \ + /home/rzingg/kedu/git/lib +QMAKE_LFLAGS += -Wl,-rpath,/home/rzingg/kedu/git/lib +SOURCES += main.cpp \ + tinyvoctrainer.cpp +HEADERS += tinyvoctrainer.h +FORMS += diff --git a/TinyVocTrainer/main.cpp b/TinyVocTrainer/main.cpp new file mode 100644 index 0000000..703a4c4 --- /dev/null +++ b/TinyVocTrainer/main.cpp @@ -0,0 +1,10 @@ +#include +#include "tinyvoctrainer.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + TinyVocTrainer w; + w.show(); + return a.exec(); +} diff --git a/TinyVocTrainer/tinyvoctrainer.cpp b/TinyVocTrainer/tinyvoctrainer.cpp new file mode 100644 index 0000000..6c28f8e --- /dev/null +++ b/TinyVocTrainer/tinyvoctrainer.cpp @@ -0,0 +1,153 @@ +#include "tinyvoctrainer.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + +TinyVocTrainer::TinyVocTrainer(QWidget *parent) + : QWidget(parent) +{ + srand(time(NULL)); + + QVBoxLayout *vbox = new QVBoxLayout(); + QHBoxLayout *hbox_less = new QHBoxLayout(); + QHBoxLayout *hbox_question_lang = new QHBoxLayout(); + QHBoxLayout *hbox_answer_lang = new QHBoxLayout(); + QHBoxLayout *hbox_buttons = new QHBoxLayout(); + QHBoxLayout *hbox_label = new QHBoxLayout(); + + QPushButton *button = new QPushButton("Next"); + + hbox_buttons->addWidget(button); + + connect(button, SIGNAL(clicked(bool)), this, SLOT(slotNext(bool))); + + bgroup_lesson = new QButtonGroup(); + bgroup_question_lang = new QButtonGroup(); + bgroup_answer_lang = new QButtonGroup(); + + QuestionLabel = new QLabel(); + QuestionLabel->setText("Here comes..."); + hbox_label->addWidget(QuestionLabel); + + + questionID = 0; + answerID = 0; + lessonID = 0; + + QLabel *label_question = new QLabel("Question:"); + hbox_question_lang->addWidget(label_question); + + QLabel *label_answer = new QLabel("Answer:"); + hbox_answer_lang->addWidget(label_answer); + + QLabel *label_lesson = new QLabel("Lesson:"); + hbox_less->addWidget(label_lesson); + + QStringList args = QApplication::arguments(); + args.removeFirst(); + + KEduVocDocument *docRead = new KEduVocDocument(); + docRead->open(args.at(0)); + + lessons = docRead->lesson()->childContainers(); + + for (int i = 0; i < docRead->identifierCount(); ++i) + { + QRadioButton *radio_question_lang = new QRadioButton(docRead->identifier(i).name()); + QRadioButton *radio_answer_lang = new QRadioButton(docRead->identifier(i).name()); + + bgroup_question_lang->addButton(radio_question_lang); + bgroup_answer_lang->addButton(radio_answer_lang); + + bgroup_question_lang->setId(radio_question_lang, i); + bgroup_answer_lang->setId(radio_answer_lang, i); + + hbox_question_lang->addWidget(radio_question_lang); + hbox_answer_lang->addWidget(radio_answer_lang); + + connect(radio_question_lang, SIGNAL(toggled(bool)), this, SLOT(reactToToggleQuestionLang(bool))); + connect(radio_answer_lang, SIGNAL(toggled(bool)), this, SLOT(reactToToggleAnswerLang(bool))); + } + + int lessonId = 0; + foreach(KEduVocContainer * c, lessons) { + if (c->containerType() == KEduVocLesson::Lesson) { + lessonsList.append( static_cast(c) ); + KEduVocLesson *m_lesson; + m_lesson = lessonsList.last() ; + qDebug () << "Lesson: " << m_lesson->name(); + QRadioButton *radio_less = new QRadioButton(m_lesson->name()); + + bgroup_lesson->addButton(radio_less); + bgroup_lesson->setId(radio_less, lessonId); + + hbox_less->addWidget(radio_less); + + connect(radio_less, SIGNAL(toggled(bool)), this, SLOT(reactToToggleLesson(bool))); + +// qDebug() << "Return rand Entry: " << getAnyEntryFromLesson(m_lesson,1); + } + ++lessonId; + } + + vbox->addLayout(hbox_less); + vbox->addLayout(hbox_question_lang); + vbox->addLayout(hbox_answer_lang); + vbox->addLayout(hbox_label); + vbox->addLayout(hbox_buttons); + setLayout(vbox); + +} + +TinyVocTrainer::~TinyVocTrainer() +{ + +} + +QString TinyVocTrainer::getAnyEntryFromLesson(KEduVocLesson *lesson, int language) +{ + int random_int = ( rand() % ( lesson->entries().size() - 1 ) ) + 0; + qDebug() << "random_int: " << random_int << "Lesson Size: " << lesson->entries().size(); + return lesson->entry(random_int)->translation(language)->text(); +} + + + +void TinyVocTrainer::reactToToggleQuestionLang(bool checked) +{ + if(checked){ + qDebug() << "bgroup_question_lang: " << bgroup_question_lang->checkedId(); + questionID = bgroup_question_lang->checkedId(); + } +} + + +void TinyVocTrainer::reactToToggleAnswerLang(bool checked) +{ + if(checked){ + qDebug() << "bgroup_answer_lang: " << bgroup_answer_lang->checkedId(); + answerID = bgroup_answer_lang->checkedId(); + } +} + + +void TinyVocTrainer::reactToToggleLesson(bool checked) +{ + if(checked){ + qDebug() << "bgroup_lesson: " << bgroup_lesson->checkedId(); + lessonID = bgroup_lesson->checkedId(); + } +} + +void TinyVocTrainer::slotNext(bool clicked){ + qDebug() << "lessonsList count: " << lessonsList.count(); + qDebug() << "lessonsList Name: " << lessonsList.at(lessonID)->name(); + QuestionLabel->setText( getAnyEntryFromLesson(lessonsList.at(lessonID), questionID) ); +} diff --git a/TinyVocTrainer/tinyvoctrainer.h b/TinyVocTrainer/tinyvoctrainer.h new file mode 100644 index 0000000..af58cdb --- /dev/null +++ b/TinyVocTrainer/tinyvoctrainer.h @@ -0,0 +1,43 @@ +#ifndef TINYVOCTRAINER_H +#define TINYVOCTRAINER_H + +#include +#include +#include +#include + +#include "keduvocdocument.h" +#include "keduvoclesson.h" +#include "keduvocexpression.h" +#include "keduvocleitnerbox.h" + +class TinyVocTrainer : public QWidget +{ + Q_OBJECT + +public: + TinyVocTrainer(QWidget *parent = 0); + ~TinyVocTrainer(); + QString getAnyEntryFromLesson(KEduVocLesson *lesson = 0, int language = 0); + + QButtonGroup *bgroup_lesson; + QButtonGroup *bgroup_question_lang; + QButtonGroup *bgroup_answer_lang; + QList lessons; + QList lessonsList; + KEduVocDocument *docRead; + QLabel *QuestionLabel; + + int questionID; + int answerID; + int lessonID; + +private slots: + void reactToToggleQuestionLang(bool checked = 0); + void reactToToggleAnswerLang(bool checked = 0); + void reactToToggleLesson(bool checked = 0); + void slotNext(bool clicked = 0); + +}; + +#endif // TINYVOCTRAINER_H -- 2.47.3