/***************************************************************************
 *   Copyright (C) 2004, 2007 by Kraschinski Arnold                        *
 *   arnold.kra67@gmx.de                                                   *
 *                                                                         *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
 ***************************************************************************/
#ifndef FORMSTRAINER_H
#define FORMSTRAINER_H

#include <QList>

#include "trainer.h"
#include "ui_formsinput.h"

class QLabel;
class QLineEdit;
class QLearning;
class Verb;
 
/**
 * The user gets the infinitiv of a verb and a tense as task information and he
 * has to enter all the personal forms.
 *
 * @short a class to train the forms of a verb and a given tense
 * @author Kraschinski Arnold <arnold.kra67@gmx.de>
 * @version 2.00.00
 */
class FormsTrainer : public Trainer, Ui::FormsInput
{
Q_OBJECT
public:
    FormsTrainer(QWidget *parent = 0);

    ~FormsTrainer();
    
    /** Prepares everything for an exercise. Chooses a verb and a tense. Displays the
      * tense and the infinitive of the verb for the user. Sets the input focus to 
      * the first QLineEdit. Activates necessary lineedits and sets other inactive.
      * Sets the mode to EXPECTING_INPUT.
      *
      * @return true if the exercise is set, false if something went wrong
      */
    bool setExercise();
    
    /** The function creates a list of interer values. This integers are the numbers
      * of the tenses that should be trained. The numbers of the tenses correspond to
      * the numbers in Verbdata::TENSEINFO. Which tenses should be traines is obtained
      * from KVerbosSettings. Some numbers are more than one time in the list. How often 
      * a tense occurs in the list depends on KVerbosSettings::simpleTenses(),
      * KVerbosSettings::composedTenses() and KVerbosSettings::continuousTenses(). This
      * asures the proportion between the kinds of tenses.
      *
      * @return true if there is at least one tense to train, false if no tense has been selected
      */
    bool prepareTenseList();
    
    /** Sets the lists of verbs. The one with the verbs that should be trained.
      * And another list with verbs, that are blocked at the moment.
      *
      * @param untrained a QList with the verbs that can be used for the training
      * @param trained a QList with the verbs that are blocked at the moment
      */
    void setVerbLists(QList<Verb*> untrained, QList<Verb*> trained);
    
    /** is called from qlearning when the user pressed the next button */
    virtual void next();
    
public slots:
    /** receive one of the special characters ñ, á, é, í, ó, ú from
      * the button line. The character will be added to the active lineInput
      */
    virtual void slotChar(QString ch);
    
    /** This slot is call when one of the QlineEdit in the third column is changed.
      * In this column is the gerund or particip form so in all QlineEdit of this
      * column is the same text. It is duplicated in this slot.
      */
    void slotDuplicate(QString text);
    
    /** When the user changes one of the QLineEdits */
    void slotTextEdited(QString);
    
    /** When the user enters the return button on the lineedits a signal reaches here */
    void slotReturnPressed();

private:
    /** Add a given tense-number to the list m_tenses, the proportion describes
      * how often the tense should be in the list. The function will only be used
      * by the prepareTenseList function.
      *
      * @param tense the number of the tense acording to Verbdata::tenseInfo
      * @param proportion how often the tense should be in the list
      */
    void addTense(int tense, int proportion);
    
    /** The text in all QLineEdit-Children is set to ""
      */
    void clearLineEdit();
    
    QLearning*          m_learning;
    
    /** The palettes used for the QLineEdit */
    QPalette            m_oldPalette;
    QPalette            m_redPalette;
    
    /** The QLineEdits from the .ui file are mapped to an array for easier use */
    QLineEdit*          m_formEdit[3][6];
    /** The widget that should get the focus first in the tab-chain */
    QLineEdit*          m_firstFocusWidget;
    /** The widget that is the last in the tab chain */
    QLineEdit*          m_lastFocusWidget;
    
    QList<Verb*>        m_untrainedVerbs;
    QList<Verb*>        m_trainedVerbs;
    QList<int>          m_tenses;
    
    /** the tense for the active exercise */
    int                 m_tense;
    
    /** the pointer to the verb for the active verb */
    Verb*               m_verb;
    
    /** When the user input is corrected the points the user got are stored here.
      * When the user corrects some forms afterwards and there is another correction
      * the amount of alredy obtained points is substracted.
      */
    int                 m_givenPoints;
    
    /** is true if the user didn't solve everything correctly and the program showed the solution */
    bool                m_solution;
    
    /** m_mode tells what we are doing at the moment. */
    int                 m_mode;
    static const int    EXPECTING_INPUT;
    static const int    CORRECTED;
    static const int    CORRECT_FORMS;
    static const int    SOLVED;
};

#endif  // FORMSTRAINER_H
