/***************************************************************************
 *   Copyright (C) 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 Steet, Fifth Floor, Boston, MA 02110-1301, USA.           *
 ***************************************************************************/
#ifndef QLEARNING_H
#define QLEARNING_H

#include <QWidget>

class QKeyEvent;
class QStackedLayout;
class QScrollArea;
class Jigsaw;
class VerbViewTrainer;
class FormsTrainer;
class GapTrainer;
class CharButtonsH;
class QTimerView;
class QCounterView;
class Kverbos;
class ControlLine;
class Trainer;

/**
 *  The class is the learning platform of the program. It has several
 *  child widgets like a counter for the time, a widget with the result,
 *  a widget with a puttle that is solved during the progress of the
 *  learning person, a trainer widget that offers different kind of 
 *  exercises and a widget with buttons for special characters that
 *  are used in the Spanish language.
 * 
 * @short the class is the learning platform
 * @author Kraschinski Arnold <arnold.kra67@gmx.de>
 * @version 2.00.00
 */
class QLearning : public QWidget
{
    Q_OBJECT

public:
    QLearning(QWidget *parent = 0);
    ~QLearning();

    /** Pay attention to some settings like showCharButtons. This function
      * is called after the user has used the settings dialog to apply 
      * changes in the settings.
      */
    void applySettings();
    
    /** Some trainers need to change the text for the next button. This function
      * estalishes the necessary connections.
      */
    void connectTrainerControlline(ControlLine* controlline);

    /** According to the parameter trainer the right Trainer class is 
      * raised in the QStackedLayout m_stackedLayout. Exercise is the
      * name of a file or a description of the exercise that should
      * be done. The exercise is prepared in this function. If everything
      * is alright the function returns true. If there is a problem so that
      * the exercise cannot be done the function returns false.
      *
      * @param trainer the name of the trainer class
      * @param exercise describe the exercise or the name of a exercise file
      * @return true if the exercise is clear and can be started otherwise flase
      */
    bool startExercise(QString trainer, QString exercise);

    /** This is the end of the exercise, that means the timer is stopped, and the 
      * exercise result can be obtained.
      */
    void stopExercise();

    /** tells if an exercise is running at the moment.
      */
    bool learning() { return (m_activeTrainer != 0); };

private:
    /** Select an image for the jigsaw. Select one that is in the KVerbosSettings::imageList().
      * if the list is empty, select the rose that comes with kverbos.
      */
    void prepareJigsaw();

public slots:
    /** The slot is called by the jigsaw when a picture is solved. The slot opens
      * a Widget so that the user can see the complete jigsaw. 
      */
    void slotJigsawSolved();
    
    /** The slot is connected to the next button in the controlline
      */
    void slotNext();
    
    /** The slot is called from a trainer when all exercises are dont
      */
    void slotAllExercisesAreDone();
    
signals:
    void signalSetNextText( QString text );
    
    void stopLearning();

private:
    Kverbos*            m_parent;
    QStackedLayout*     m_stackedLayout;
    QScrollArea*        m_scrollArea;
    Jigsaw*             m_jigsaw;
    QTimerView*         m_timer;
    QCounterView*       m_counter;
    VerbViewTrainer*    m_verbViewTrainer;
    FormsTrainer*       m_formsTrainer;
    GapTrainer*         m_gapTrainer;
    CharButtonsH*       m_charButtons;

    /** true if the exercise is started otherwise false */
    Trainer*            m_activeTrainer;
};

#endif  // QLEARNING_H
