[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-edu-devel
Subject:    Re: [kde-edu-devel] Another patch for flashKard
From:       Scott Wheeler <wheeler () kde ! org>
Date:       2002-05-14 10:37:36
[Download RAW message or body]

Ok, just got back around to this.  I committed something with similar 
functionality, but is more OOP Friendly (tm).  :-)

I added a virtual function to the abstract class QuizWidget to call 
completeMessage() to get the message at the message signifying completion of 
the deck.  The default implementation just contains the message from before 
so that that will be the default for other possible (future) quiz modes.  But 
since it is virtual, if a GuessWidget is being worked with, it actually calls 
the implementation in GuessWidget.  So I kept all of the implementation for  
a "percentage correct" in GuessWidget where it should be.

I'm attaching what I just committed.  Also, remember that any time that you 
add strings that they must be i18n()'d for translation purposes.

-Scott

On Sunday 21 April 2002 08:41 pm, cfaun wrote:
> It is attached

["flashkard-number-correct.patch" (text/x-diff)]

Index: guesswidget.cpp
===================================================================
RCS file: /home/kde/kdeedu/flashkard/flashkard/guesswidget.cpp,v
retrieving revision 1.6
diff -u -3 -p -r1.6 guesswidget.cpp
--- guesswidget.cpp	2002/05/13 14:20:08	1.6
+++ guesswidget.cpp	2002/05/14 10:21:15
@@ -14,6 +14,7 @@
 ***************************************************************************/
 
 #include <klocale.h>
+#include <kdebug.h>
 
 #include <qlayout.h>
 #include <qvbox.h>
@@ -32,6 +33,7 @@ GuessWidget::GuessWidget(KStatusBar *sta
 {
   random = randomQuiz;
   answer = QString::null;
+  numberCorrect = 0;
 
   showFeedbackLabel();
   setupLayout();
@@ -59,6 +61,17 @@ bool GuessWidget::hasSelectedText()
 } 
 
 ////////////////////////////////////////////////////////////////////////////////
+// protected members
+////////////////////////////////////////////////////////////////////////////////
+
+QString GuessWidget::completeMessage()
+{
+  QString message = i18n("Restarting the deck.\n") + QString::number(int(100 * \
numberCorrect / numberOfCards())) + i18n("% Correct!"); +  numberCorrect = 0;
+  return(message);
+}
+
+////////////////////////////////////////////////////////////////////////////////
 // private members
 ////////////////////////////////////////////////////////////////////////////////
 
@@ -110,6 +123,7 @@ void GuessWidget::showCard(Card card)
 void GuessWidget::checkAnswer()
 {
   if(guessLineEdit->text() == answer) {
+    numberCorrect++;
     setFeedbackMessage(i18n("Correct!"));
     getCard(random);
     guessLineEdit->setFocus();
Index: guesswidget.h
===================================================================
RCS file: /home/kde/kdeedu/flashkard/flashkard/guesswidget.h,v
retrieving revision 1.3
diff -u -3 -p -r1.3 guesswidget.h
--- guesswidget.h	2002/05/13 14:20:08	1.3
+++ guesswidget.h	2002/05/14 10:21:15
@@ -37,11 +37,15 @@ public: 
   virtual void copy();
   virtual bool hasSelectedText();
 
+protected:
+  virtual QString completeMessage();
+
 private:
   void setupLayout();
   virtual void showCard(Card card);
   
   bool random;
+  int numberCorrect;
   QString answer;
   QLabel *cardLabel;
   KLineEdit *guessLineEdit;
Index: quizwidget.cpp
===================================================================
RCS file: /home/kde/kdeedu/flashkard/flashkard/quizwidget.cpp,v
retrieving revision 1.5
diff -u -3 -p -r1.5 quizwidget.cpp
--- quizwidget.cpp	2002/04/20 03:33:08	1.5
+++ quizwidget.cpp	2002/05/14 10:21:15
@@ -97,7 +97,7 @@ Card QuizWidget::getCard(bool random)
 {
   if(!completeCardList->isEmpty()) {
     if(remainingCardList.isEmpty()) {
-      KMessageBox::information( this, i18n("Restarting the deck."), \
i18n("FlashKard")); +      KMessageBox::information( this, completeMessage(), \
i18n("FlashKard"));  remainingCardList = *completeCardList;
     }
     
@@ -139,6 +139,19 @@ bool QuizWidget::eventFilter(QObject *ob
   return(QWidget::eventFilter(object, event));
 }
 
+QString QuizWidget::completeMessage()
+{
+  return(i18n("Restarting the deck."));
+}
+
+int QuizWidget::numberOfCards()
+{
+  if(completeCardList)
+    return(completeCardList->size());
+  else
+    return(0);
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // private members
 ////////////////////////////////////////////////////////////////////////////////
@@ -155,7 +168,7 @@ void QuizWidget::setupLayout()
     feedbackLabel->setFixedWidth(100);
     mainStatusBar->addWidget(feedbackLabel, 1);
     showFeedbackLabel(false);
-
+    
     progressBar = new KProgress(mainStatusBar);
     progressBar->setMaximumHeight(mainStatusBar->height() - 12);
     mainStatusBar->addWidget(progressBar, 3);
Index: quizwidget.h
===================================================================
RCS file: /home/kde/kdeedu/flashkard/flashkard/quizwidget.h,v
retrieving revision 1.3
diff -u -3 -p -r1.3 quizwidget.h
--- quizwidget.h	2002/04/20 03:33:08	1.3
+++ quizwidget.h	2002/05/14 10:21:15
@@ -47,6 +47,8 @@ protected:
   QFont labelFont();
   QBoxLayout *layout();
   bool eventFilter(QObject *object, QEvent *event);
+  virtual QString completeMessage();
+  int numberOfCards();
 
 private:
   void setupLayout();


_______________________________________________
kde-edu-devel mailing list
kde-edu-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-edu-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic